The Physics Package: Sergio C. de La Barrera December 12, 2012

Download as pdf or txt
Download as pdf or txt
You are on page 1of 8

The physics package

Sergio C. de la Barrera
[email protected]
December 12, 2012
Contents
1 Before you start 1
1.1 The purpose of this package . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
1.2 Other required packages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
1.3 Using physics in your L
A
T
E
X document . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
2 List of commands 2
2.1 Automatic bracing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
2.2 Vector notation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
2.3 Operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
2.4 Quick quad text . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
2.5 Derivatives . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
2.6 Dirac bra-ket notation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
2.7 Matrix macros . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
1 Before you start
1.1 The purpose of this package
The goal of this package is to make typesetting equations for physics simpler, faster, and more human-
readable. 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-dened set of shortcuts for accessing the long-form of each of
these commands. The commands listed below are therefore dened 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 Other required packages
The physics package requires xparse and amsmath to work properly in your L
A
T
E
X document. The amsmath
package comes standard with most L
A
T
E
X 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 dening L
A
T
E
Xmacros,
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
1
without worrying about it. Many modern L
A
T
E
Xcompilers will locate and oer to download missing packages
for you.
1.3 Using physics in your L
A
T
E
X document
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 List of commands
2.1 Automatic bracing
\quantity \qty(\typical) ( ) automatic ( ) braces
\qty(\tall)
_ _
\qty(\grande)
_ _
\qty[\typical] [ ] automatic [ ] braces
\qty|\typical| [ [ automatic [ [ braces
\qty{\typical} automatic braces
\qty\big{}
__
manual sizing (works with any of the
above bracket types)
\qty\Big{}
__
\qty\bigg{}
__
\qty\Bigg{}
__
\pqty{} \qty() alternative syntax; robust and more
L
A
T
E
X-friendly \bqty{} \qty[]
\vqty{} \qty||
\Bqty{} \qty{}
\absolutevalue \abs{a} [a[ automatic sizing; equivalent to \qty|a|
\abs\Big{a}

inherits manual sizing syntax from \qty


\abs*{\grande} [ [ star for no resize
\norm \norm{a} |a| automatic sizing
\norm\Big{a}
_
_
_a
_
_
_ manual sizing
\norm*{\grande} | | star for no resize
\evaluated \eval{x}_0^\infty x

0
vertical bar for evaluation limits
2
\eval(x|_0^\infty
_
x

0
alternate form
\eval[x|_0^\infty
_
x

0
alternate form
\eval[\venti|_0^\infty
_

0
automatic sizing
\eval*[\venti|_0^\infty
_

0
star for no resize
\order \order{x^2} O
_
x
2
_
order symbol; automatic sizing and
space handling
\order\Big{x^2} O
_
x
2
_
manual sizing
\order*{\grande} O( ) star for no resize
\commutator \comm{A}{B} [A, B] automatic sizing
\comm\Big{A}{B}
_
A, B
_
manual sizing
\comm*{A}{\grande} [A, ] star for no resize
\anticommutator \acomm{A}{B} A, B same as \poissonbracket
\poissonbracket \pb{A}{B} A, B same as \anticommutator
2.2 Vector notation
The default del symbol used in physics vector notation can be switched to appear with an arrow

by
including the option arrowdel in the document preamble \usepackage[arrowdel]{physics}.
\vectorbold \vb{a} a upright/no Greek
\vb*{a}, \vb*{\theta} a, italic/Greek
\vectorarrow \va{a} a upright/no Greek
\va*{a}, \va*{\theta} a,

italic/Greek
\vectorunit \vu{a} a upright/no Greek
\vu*{a}, \vu*{\theta} a,

italic/Greek
\dotproduct \vdot as in a b note: \dp is a protected T
E
X primitive
\crossproduct \cross as in a b alternate name
\cp as in a b shorthand name
\gradient \grad
\grad{\Psi} default mode
\grad(\Psi+\tall)
_
+
_
long-form (like \qty but also handles
spacing)
\grad[\Psi+\tall]
_
+
_
\divergence \div note: amsmath symbol renamed
\divisionsymbol
\div{\vb{a}} a default mode
\div(\vb{a}+\tall)
_
a +
_
long-form
\div[\vb{a}+\tall]
_
a +
_
\curl \curl
\curl{\vb{a}} a default mode
\curl(\vb{a}+\tall)
_
a +
_
long-form
3
\curl[\vb{a}+\tall]
_
a +
_
\laplacian \laplacian
2
\laplacian{\Psi}
2
default mode
\laplacian(\Psi+\tall)
2
_
+
_
long-form
\laplacian[\Psi+\tall]
2
_
+
_
2.3 Operators
The standard set of trig functions is redened in physics to provide automatic braces that behave like
\qty(). In addition, an optional power argument is provided. This behavior can be switched o by including
the option notrig in the preamble \usepackage[notrig]{physics}.
Example trig redenitions:
\sin \sin(\grande) sin
_ _
automatic braces; old \sin renamed \sine
\sin[2](x) sin
2
(x) optional power
\sin x sin x can still use without an argument
The full set of available trig functions in physics includes:
\sin(x) \sinh(x) \arcsin(x) \asin(x)
\cos(x) \cosh(x) \arccos(x) \acos(x)
\tan(x) \tanh(x) \arctan(x) \atan(x)
\csc(x) \csch(x) \arccsc(x) \acsc(x)
\sec(x) \sech(x) \arcsec(x) \asec(x)
\cot(x) \coth(x) \arccot(x) \acot(x)

sin(x) sinh(x) arcsin(x) asin(x)


cos(x) cosh(x) arccos(x) acos(x)
tan(x) tanh(x) arctan(x) atan(x)
csc(x) csch(x) arccsc(x) acsc(x)
sec(x) sech(x) arcsec(x) asec(x)
cot(x) coth(x) arccot(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 \hypsine \arcsine \asine
\cosine \hypcosine \arccosine \acosine
\tangent \hyptangent \arctangent \atangent
\cosecant \hypcosecant \arccosecant \acosecant
\secant \hypsecant \arcsecant \asecant
\cotangent \hypcotangent \arccotangent \acotangent
Similar behavior has also been extended to the following functions:
\exp(\tall) exp
_ _
\exponential
\log(\tall) log
_ _
\logarithm
\ln(\tall) ln
_ _
old denitions \naturallogarithm
\det(\tall) det
_ _
\determinant
\Pr(\tall) Pr
_ _
\Probability
New operators:
\trace or \tr \tr\rho tr also \tr(\tall) tr
_ _
trace; same bracing as trig functions
\Trace or \Tr \Tr\rho Tr alternate
\rank \rank M rank M matrix rank
\erf \erf(x)erf(x) Gauss error function
\Res \Res[f(z)]Res[f(z)] residue; same bracing as trig functions
\principalvalue \pv{\int f(z) \dd{z}}T
_
f(z) dz Cauchy principal value
\PV{\int f(z) \dd{z}}P.V.
_
f(z) dz alternate
4
\Re \Re{z} Rez old \Re renamed to \real 1
\Im \Im{z} Imz old \Im renamed to \imaginary
2.4 Quick quad text
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{} general quick quad text with argument
\qq{word or phrase} word or phrase normal mode; left and right \quad
\qq*{word or phrase} word or phrase starred mode; right \quad only
Special macros:
\qcomma or \qc , right \quad only
\qcc c.c. complex conjugate; left and right \quad unless starred \qcc* c.c.
\qif if left and right \quad unless starred \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 dierential 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 \dd d
\dd x dx no spacing (not recommended)
\dd{x} dx automatic spacing based on neighbors
\dd[3]{x} d
3
x optional power
\dd(\cos\theta) d(cos ) long-form; automatic braces
\derivative \dv{x}
d
dx
one argument
\dv{f}{x}
df
dx
two arguments
\dv[n]{f}{x}
d
n
f
dx
n
optional power
\dv{x}(\grande)
d
dx
_ _
long-form; automatic braces, spacing
\dv*{f}{x} df/dx inline form using \flatfrac
\partialderivative \pderivative{x}

x
alternate name
\pdv{x}

x
shorthand name
\pdv{f}{x}
f
x
two arguments
\pdv[n]{f}{x}

n
f
x
n
optional power
5
\pdv{x}(\grande)

x
_ _
long-form
\pdv{f}{x}{y}

2
f
xy
mixed partial
\pdv*{f}{x} f/x inline form using \flatfrac
\variation \var{F[g(x)]} F[g(x)] functional variation (works like \dd)
\var(E-TS) (E TS) long-form
\functionalderivative \fdv{g}

g
functional derivative (works like \dv)
\fdv{F}{g}
F
g
\fdv{V}(E-TS)

V
(E TS) long-form
\fdv*{F}{x} F/x inline form using \flatfrac
2.6 Dirac bra-ket notation
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 correctly
1
\bra{\phi}\ket{\psi} [ as opposed to [ [
whereas a similar construction with higher-level macros will not contract in a robust manner
\bra{\phi}\dyad{\psi}{\xi} [ [[ .
On the other hand, the correct output can be generated by sticking to the fundamental commands,
\bra{\phi}\ket{\psi}\bra{\xi} [ [
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.
\ket \ket{\tall}

_
automatic sizing
\ket*{\tall} [ no resize
\bra \bra{\tall}
_

automatic sizing
\bra*{\tall} [ no resize
\bra{\phi}\ket{\psi} [ automatic contraction
\bra{\phi}\ket{\tall}
_

_
contraction inherits automatic sizing
\bra{\phi}\ket*{\tall} [ a star on either term in the contraction
prohibits resizing \bra*{\phi}\ket{\tall} [
\bra*{\phi}\ket*{\tall} [
\innerproduct \braket{a}{b} a[b two-argument braket
\braket{a} a[a 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 nd the corresponding
ket and form a contraction.
6
\braket{a}{\tall}
_
a

_
automatic sizing
\braket*{a}{\tall} a[ no resize
\ip{a}{b} a[b shorthand name
\outerproduct \dyad{a}{b} [ab[ two-argument dyad
\dyad{a} [aa[ one-argument (projector)
\dyad{a}{\tall}

a
__

automatic sizing
\dyad*{a}{\tall} [a [ no resize
\ketbra{a}{b} [ab[ alternative name
\op{a}{b} [ab[ shorthand name
\expectationvalue \expval{A} A implicit form
\expval{A}{\Psi} [A[ explicit form
\ev{A}{\Psi} [A[ shorthand name
\ev{\grande}{\Psi} [ [ default sizing ignores middle argument
\ev*{\grande}{\tall} [ [ single star does no resizing whatsoever
\ev**{\grande}{\Psi}
_

_
double star resizes based on all parts
\matrixelement \matrixel{n}{A}{m} n[A[m requires all three arguments
\mel{n}{A}{m} n[A[m shorthand name
\mel{n}{\grande}{m} n[ [m default sizing ignores middle argument
\mel*{n}{\grande}{\tall} n[ [ single star does no resizing whatsoever
\mel**{n}{\grande}{m}
_
n

m
_
double star resizes based on all parts
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
1 0
0 1
without braces or
grouping. This allows the command to also be used within another matrix, as in:
\begin{pmatrix}
\imat{2} \\ a & b
\end{pmatrix}

_
_
1 0
0 1
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 eectively convert \imat{2} into a single matrix element of a larger matrix:
\begin{pmatrix}
\mqty{\imat{2}} & \mqty{a\\b} \\ \mqty{c & d} & e
\end{pmatrix}

_
_
1 0
0 1
a
b
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:
\mqty(\mqty{\imat{2}} & \mqty{a\\b} \\ \mqty{c & d} & e)
_
_
1 0
0 1
a
b
c d e
_
_
7
\matrixquantity \mqty{a & b \\ c & d}
a b
c d
groups a set of matrix elements into a
single object
\mqty(a & b \\ c & d)
_
a b
c d
_
parentheses
\mqty*(a & b \\ c & d)
_

_
a b
c d
_

_ alternate parentheses
\mqty[a & b \\ c & d]
_
a b
c d
_
square brackets
\mqty|a & b \\ c & d|

a b
c d

vertical bars
\pmqty{} \mqty() alternative syntax; robust and more
L
A
T
E
X-friendly \Pmqty{} \mqty*()
\bmqty{} \mqty[]
\vmqty{} \mqty||
\smallmatrixquantity \smqty{a & b \\ c & d}
a b
c d
the smallmatrix form of \mqty
\smqty() or \spmqty{} small version of \mqty()
\smqty*() or \sPmqty{} small version of \mqty*()
\smqty[] or \sbmqty{} small version of \mqty[]
\smqty|| or \svmqty{} small version of \mqty||
\matrixdeterminant \mdet{a & b \\ c & d}

a b
c d

matrix determinant
\smdet{a & b \\ c & d}

a b
c d

small matrix determinant


\identitymatrix \imat{n} elements of n n identity matrix
\smqty(\imat{3})
_
1 0 0
0 1 0
0 0 1
_
formatted with \mqty or \smqty
\xmatrix \xmat{x}{n}{m} elements of n m matrix lled with x
\smqty(\xmat{1}{2}{3}) (
1 1 1
1 1 1
) formatted with \mqty or \smqty
\smqty(\xmat*{a}{3}{3})
_
a11 a12 a13
a21 a22 a23
a31 a32 a33
_
star for element indices
\smqty(\xmat*{a}{3}{1})
_
a1
a2
a3
_
as a vector with indices
\smqty(\xmat*{a}{1}{3}) (
a1 a2 a3 )
\zeromatrix \zmat{n}{m} n m matrix lled with zeros
\smqty(\zmat{2}{2}) (
0 0
0 0
) equivalent to \xmat{0}{n}{m}
\paulimatrix \pmat{n} n
th
Pauli matrix
\smqty(\pmat{0}) (
1 0
0 1
) n 0, 1, 2, 3 or x, y, z
\smqty(\pmat{1}) (
0 1
1 0
)
\smqty(\pmat{2})
_
0 i
i 0
_
\smqty(\pmat{3})
_
1 0
0 1
_
\diagonalmatrix \dmat{a,b,c,...} specify up to eight diagonal or block di-
agonal elements
\mqty(\dmat{1,2,3})
_
_
1
2
3
_
_
\mqty(\dmat[0]{1,2})
_
1 0
0 2
_
optional argument to ll spaces
\mqty(\dmat{1,2&3\\4&5})
_
_
1
2 3
4 5
_
_
enter matrix elements for each block as
a single diagonal element
\antidiagonalmatrix \admat{a,b,c,...} same as syntax as \dmat
\mqty(\admat{1,2,3})
_
_
1
2
3
_
_
8

You might also like