Beruflich Dokumente
Kultur Dokumente
Sergio C. de la Barrera
physics.tex@gmail.com
December 12, 2012
Contents
1 Before you start
1.1 The purpose of this package . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
1.2 Other required packages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
1.3 Using physics in your LATEX document . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
1
1
1
2
2 List
2.1
2.2
2.3
2.4
2.5
2.6
2.7
2
2
3
4
5
5
6
7
1
1.1
of commands
Automatic bracing . .
Vector notation . . . .
Operators . . . . . . .
Quick quad text . . .
Derivatives . . . . . .
Dirac bra-ket notation
Matrix macros . . . .
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
The goal of this package is to make typesetting equations for physics simpler, faster, and more humanreadable. To that end, the commands included in this package have names that make the purpose of each
command immediately obvious and remove any ambiguity while reading and editing physics code. From a
practical standpoint, it is handy to have a well-defined set of shortcuts for accessing the long-form of each of
these commands. The commands listed below are therefore defined in terms of their long-form names and
then shown explicitly in terms of the default shorthand command sequences. These shorthand commands
are meant make it easy to remember both the shorthand names and what each one represents.
1.2
The physics package requires xparse and amsmath to work properly in your LATEX document. The amsmath
package comes standard with most LATEX distributions and is loaded by physics for your convenience. You
may also already have xparse installed on your system as it is a popular package for defining LATEXmacros,
however, if you are unsure you can either install it again using your local package manager (comes with most
distributions) or by visiting the CTAN online package database, or you could even just try to use physics
without worrying about it. Many modern LATEXcompilers will locate and offer to download missing packages
for you.
1.3
To use the physics package, simply insert \usepackage{physics} in the preamble of your document, before
\begin{document} and after \documentclass{class}:
\documentclass{class}
...
\usepackage{physics}
...
\begin{document}
content...
\end{document}
2
2.1
List of commands
Automatic bracing
\quantity
\qty(\typical) ( )
automatic ( ) braces
\qty(\tall)
\qty(\grande)
\qty[\typical] [ ]
\qty|\typical| | |
\qty{\typical} { }
\qty\big{} no
automatic [ ] braces
automatic | | braces
automatic { } braces
manual sizing (works with any of the
above bracket types)
\qty\Big{}
\qty\bigg{}
()
\qty\Bigg{}
\absolutevalue
\qty()
\qty[]
\qty||
\qty{}
|a|
\abs\Big{a} a
\abs*{\grande} |
\norm
\pqty{}
\bqty{}
\vqty{}
\Bqty{}
\abs{a}
\norm{a} kak
\norm\Big{a}
a
automatic sizing
k
\eval{x}_0^\infty x
manual sizing
\norm*{\grande} k
\evaluated
x
0
\eval[x|_0^\infty x
\eval(x|_0^\infty
\order
alternate form
alternate form
\eval[\venti|_0^\infty
0
\eval*[\venti|_0^\infty
0
2
\order{x^2} O x
"
\order\Big{x^2} O x2
\order*{\grande} O(
\commutator
2.2
automatic sizing
manual sizing
\comm*{A}{\grande} [A,
\anticommutator
\poissonbracket
automatic sizing
\acomm{A}{B} {A, B}
\pb{A}{B} {A, B}
same as \poissonbracket
same as \anticommutator
Vector notation
~ by
The default del symbol used in physics vector notation can be switched to appear with an arrow
including the option arrowdel in the document preamble \usepackage[arrowdel]{physics}.
\vectorbold
\vectorarrow
\vectorunit
\dotproduct
\crossproduct
\gradient
\divergence
\curl
\vb{a} a
\vb*{a}, \vb*{\theta} a,
\va{a} ~a
\va*{a}, \va*{\theta} ~a,
\vu{a}
a
\vu*{a}, \vu*{\theta} a
,
\vdot as in a b
\cross as in a b
\cp as in a b
\grad
\grad{\Psi}
upright/no Greek
italic/Greek
upright/no Greek
italic/Greek
upright/no Greek
italic/Greek
note: \dp is a protected TEX primitive
alternate name
shorthand name
default mode
\grad(\Psi+\tall) +
h
\grad[\Psi+\tall] +
\div
\div{\vb{a}} a
\div(\vb{a}+\tall) a +
h
\div[\vb{a}+\tall] a +
\curl
\curl{\vb{a}} a
\curl(\vb{a}+\tall) a +
long-form
default mode
long-form
h
i
\curl[\vb{a}+\tall] a +
\laplacian 2
\laplacian{\Psi} 2
\laplacian(\Psi+\tall) 2 +
h
i
\laplacian[\Psi+\tall] 2 +
\laplacian
2.3
default mode
long-form
Operators
The standard set of trig functions is redefined in physics to provide automatic braces that behave like
\qty(). In addition, an optional power argument is provided. This behavior can be switched off by including
the option notrig in the preamble \usepackage[notrig]{physics}.
Example trig redefinitions:
\sin
\sin(\grande) sin
automatic braces; old \sin renamed \sine
optional power
can still use without an argument
\sinh(x)
\cosh(x)
\tanh(x)
\csch(x)
\sech(x)
\coth(x)
\arcsin(x)
\arccos(x)
\arctan(x)
\arccsc(x)
\arcsec(x)
\arccot(x)
sin(x)
\asin(x)
cos(x)
\acos(x)
tan(x)
\atan(x)
csc(x)
\acsc(x)
sec(x)
\asec(x)
cot(x)
\acot(x)
sinh(x)
cosh(x)
tanh(x)
csch(x)
sech(x)
coth(x)
arcsin(x)
arccos(x)
arctan(x)
arccsc(x)
arcsec(x)
arccot(x)
asin(x)
acos(x)
atan(x)
acsc(x)
asec(x)
acot(x)
The standard trig functions (plus a few that are missing in amsmath) are available without any automatic
bracing under a new set of longer names:
\sine
\cosine
\tangent
\cosecant
\secant
\cotangent
\hypsine
\hypcosine
\hyptangent
\hypcosecant
\hypsecant
\hypcotangent
\arcsine
\arccosine
\arctangent
\arccosecant
\arcsecant
\arccotangent
\asine
\acosine
\atangent
\acosecant
\asecant
\acotangent
following functions:
\exponential
\logarithm
\naturallogarithm
\determinant
\Probability
\Re{z} Re{z}
\Im{z} Im{z}
\Re
\Im
2.4
This set of commands produces text in math-mode padded by \quad spacing on either side. This is meant
to provide a quick way to insert simple words or phrases in a sequence of equations. Each of the following
commands includes a starred version which pads the text only on the right side with \quad for use in aligned
environments such as cases.
General text:
\qqtext
\qq{}
\qq{word or phrase} word or phrase
\qq*{word or phrase} word or phrase
Special macros:
\qcomma or \qc ,
\qcc c.c.
\qif if
Similar to \qif:
\qthen, \qelse, \qotherwise, \qunless, \qgiven, \qusing, \qassume, \qsince,
\qlet, \qfor, \qall, \qeven, \qodd, \qinteger, \qand, \qor, \qas, \qin
2.5
Derivatives
The default differential symbol d which is used in \differential and \derivative can be switched to an
italic form d by including the option italicdiff in the preamble \usepackage[italicdiff]{physics}.
\differential
\derivative
\partialderivative
\dd d
\dd x dx
\dd{x} dx
\dd[3]{x} d3 x
\dd(\cos\theta) d(cos )
d
\dv{x}
dx
df
\dv{f}{x}
dx n
d f
\dv[n]{f}{x}
dxn
d
\dv{x}(\grande)
dx
\dv*{f}{x} df /dx
\pderivative{x}
x
\pdv{x}
x
f
\pdv{f}{x}
x n
f
\pdv[n]{f}{x}
xn
x
2f
\pdv{f}{x}{y}
xy
\pdv*{f}{x} f /x
\var{F[g(x)]} F [g(x)]
\var(E-TS) (E T S)
\fdv{g}
g
F
\fdv{F}{g}
g
\fdv{V}(E-TS)
(E T S)
V
\fdv*{F}{x} F /x
\pdv{x}(\grande)
\variation
\functionalderivative
2.6
long-form
mixed partial
inline form using \flatfrac
functional variation (works like \dd)
long-form
functional derivative (works like \dv)
long-form
inline form using \flatfrac
The following collection of macros for Dirac notation contains two fundamental commands, \bra and \ket,
along with a set of more specialized macros which are essentially combinations of the fundamental pair. The
specialized macros are both useful and descriptive from the perspective of generating physics code, however,
the fundamental commands are designed to contract with one another algebraically when appropriate and
are thus suggested for general use. For instance, the following code renders correctly1
\bra{\phi}\ket{\psi} h|i
as opposed to
h| |i
whereas a similar construction with higher-level macros will not contract in a robust manner
\bra{\phi}\dyad{\psi}{\xi} h| |ih| .
On the other hand, the correct output can be generated by sticking to the fundamental commands,
\bra{\phi}\ket{\psi}\bra{\xi} h|i h|
allowing the user to type out complicated quantum mechanical expressions without worrying about bra-ket
contractions. That being said, the high-level macros do have a place in convenience and readability, as long
as the user is aware of rendering issues that may arise due to an absence of automatic contractions.
E
\ket
\ket{\tall}
automatic sizing
\bra
\innerproduct
\ket*{\tall} D | i
\bra{\tall}
no resize
\bra*{\tall} h |
\bra{\phi}\ket{\psi} h|i
D E
\bra{\phi}\ket{\tall}
no resize
automatic contraction
\bra{\phi}\ket*{\tall} h| i
\bra*{\phi}\ket{\tall} h| i
\bra*{\phi}\ket*{\tall} h| i
\braket{a}{b} ha|bi
\braket{a} ha|ai
automatic sizing
two-argument braket
one-argument (norm)
1 Note the lack of a space between the bra and ket commands. This is necessary is order for the bra to find the corresponding
ket and form a contraction.
D
\braket{a}{\tall} a
\outerproduct
\expectationvalue
automatic sizing
\braket*{a}{\tall} ha| i
\ip{a}{b} ha|bi
\dyad{a}{b} |aihb|
\dyad{a} |aiha| ED
\dyad{a}{\tall} a
no resize
shorthand name
two-argument dyad
one-argument (projector)
\dyad*{a}{\tall} |aih |
\ketbra{a}{b} |aihb|
\op{a}{b} |aihb|
\expval{A} hAi
\expval{A}{\Psi} h|A|i
\ev{A}{\Psi} h|A|i
no resize
alternative name
shorthand name
implicit form
explicit form
shorthand name
\ev{\grande}{\Psi} h|
automatic sizing
|i
\ev*{\grande}{\tall} h |
\ev**{\grande}{\Psi}
\matrixelement
| i
\matrixel{n}{A}{m} hn|A|mi
\mel{n}{A}{m} hn|A|mi
\mel{n}{\grande}{m} hn|
|mi
\mel*{n}{\grande}{\tall} hn| | i
\mel**{n}{\grande}{m} n m
2.7
Matrix macros
The following matrix macros produce unformatted rows and columns of matrix elements for use as separate
matrices as well as blocks within larger matrices. For example, the command \identitymatrix{2} which
has also has the shortcut \imat{2} produces the elements of a 2 2 identity matrix 10 01 without braces or
grouping. This allows the command to also be used within another matrix, as in:
\begin{pmatrix}
1 0
0 1
\imat{2} \\ a & b
\end{pmatrix}
a b
To specify elements on the right of left sides of our \imat{2} sub-matrix we use the grouping command
\matrixquantity or \mqty to effectively convert \imat{2} into a single matrix element of a larger matrix:
\begin{pmatrix}
1 0 a
0 1 b
\mqty{\imat{2}} & \mqty{a\\b} \\ \mqty{c & d} & e
\end{pmatrix}
c d e
The extra \mqty groups were required in this case in order to get the a and b elements to behave as a single
element, since \mqty{\imat{2}} also acts like a single matrix element (the same can be said of the grouped
c and d elements). Finally, the outermost pmatrix environment could have also been replaced with the
physics macro \mqty(), allowing the above example to be written on one line:
1 0 a
0 1 b
\mqty(\mqty{\imat{2}} & \mqty{a\\b} \\ \mqty{c & d} & e)
c d e
\matrixquantity
\smallmatrixquantity
\matrixdeterminant
\identitymatrix
a b
c d
a b
\mqty(a & b \\ c & d)
c d
a b
c d
a b
\mqty[a & b \\ c & d]
c d
a b
\mqty|a & b \\ c & d|
c d
\pmqty{} \mqty()
\Pmqty{} \mqty*()
\bmqty{} \mqty[]
\vmqty{} \mqty||
\smqty{a & b \\ c & d} ac db
\smqty() or \spmqty{}
\smqty*() or \sPmqty{}
\smqty[] or \sbmqty{}
\smqty|| or \svmqty{}
a b
\mdet{a & b \\ c & d}
c d
\smdet{a & b \\ c & d} ac db
\imat{n}
\mqty{a & b \\ c & d}
100
\xmatrix
\smqty(\imat{3}) 0 1 0
001
\xmat{x}{n}{m}
1 1 1)
\smqty(\xmat{1}{2}{3}) (
111
\smqty(\xmat*{a}{3}{3})
\zeromatrix
\paulimatrix
\diagonalmatrix
\antidiagonalmatrix
\smqty(\xmat*{a}{3}{1})
\smqty(\xmat*{a}{1}{3})
\zmat{n}{m}
\smqty(\zmat{2}{2}) ( 00 00 )
\pmat{n}
\smqty(\pmat{0}) ( 10 01 )
\smqty(\pmat{1}) ( 01 10 )
\smqty(\pmat{2}) 0i i
0
0
\smqty(\pmat{3}) 10 1
\dmat{a,b,c,...}
1
\mqty(\dmat{1,2,3}) 2
3
1 0
\mqty(\dmat[0]{1,2})
2
0
1
2 3
\mqty(\dmat{1,2&3\\4&5})
4 5
\admat{a,b,c,...}
\mqty(\admat{1,2,3}) 2
3