The Physics Package: Sergio C. de La Barrera December 12, 2012
The Physics Package: Sergio C. de La Barrera December 12, 2012
The Physics Package: Sergio C. de La Barrera December 12, 2012
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}
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)
_
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