summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/doc/latex/physics/physics.tex
blob: 34081efbc5eb427b24844b2459475e3e7a435a7c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
\documentclass{article}
\usepackage{fullpage}
\usepackage{parskip}
\usepackage{physics}
\usepackage{amssymb}
\usepackage{xcolor}
\usepackage[colorlinks,urlcolor=blue]{hyperref}
\usepackage{array}
\usepackage{longtable}
\usepackage{multirow}

\newcolumntype{M}{>{$\displaystyle}c<{$}}
\newcolumntype{L}{>{$\displaystyle}l<{$}}

\newcommand\Vtextvisiblespace[1][.3em]
{%
	\mbox{\kern.06em\vrule height.3ex}%
	\vbox{\hrule width#1}%
	\hbox{\vrule height.3ex}
}

\newcommand{\cbox}[2][cyan]
{\mathchoice
	{\setlength{\fboxsep}{0pt}\colorbox{#1}{$\displaystyle#2$}}
	{\setlength{\fboxsep}{0pt}\colorbox{#1}{$\textstyle#2$}}
	{\setlength{\fboxsep}{0pt}\colorbox{#1}{$\scriptstyle#2$}}
	{\setlength{\fboxsep}{0pt}\colorbox{#1}{$\scriptscriptstyle#2$}}
}

\newcommand{\typical}{\cbox{\phantom{A}}}
\newcommand{\tall}{\cbox{\phantom{A^{\vphantom{x^x}}_x}}}
\newcommand{\grande}{\cbox{\phantom{\frac{1}{xx}}}}
\newcommand{\venti}{\cbox{\phantom{\sum_x^x}}}

% physics 1.30
\title{The \texttt{physics} package}
\author{Sergio C. de la Barrera \\ \texttt{physics.tex@gmail.com}}

\begin{document}
\maketitle

\tableofcontents

\section{Before you start}
\subsection{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 \texttt{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.

\subsection{Other required packages}
The \texttt{physics} package requires \texttt{xparse} and \texttt{amsmath} to work properly in your \LaTeX~document. The \texttt{amsmath} package comes standard with most \LaTeX~distributions and is loaded by \texttt{physics} for your convenience. You may also already have \texttt{xparse} installed on your system as it is a popular package for defining \LaTeX macros, however, if you are unsure you can either install it again using your local package manager (comes with most distributions) or by visiting the \href{http://www.ctan.org/}{CTAN} online package database, or you could even just try to use \texttt{physics} without worrying about it. Many modern \LaTeX compilers will locate and offer to download missing packages for you.
\subsection{Using \texttt{physics} in your \LaTeX~document}
To use the \texttt{physics} package, simply insert \verb|\usepackage{physics}| in the preamble of your document, before \verb|\begin{document}| and after \verb|\documentclass{class}|:
\begin{verbatim}
\documentclass{class}
...
\usepackage{physics}
...
\begin{document}
	content...
\end{document}
\end{verbatim}

\section{List of commands}
\subsection{Automatic bracing}
\begin{longtable}[l]{ l l p{6cm} }
\verb|\quantity| & \verb|\qty(\typical)| $\displaystyle\rightarrow \qty(\typical)$ & automatic $\qty(\;)$ braces \\
& \verb|\qty(\tall)| $\displaystyle\rightarrow \qty(\tall)$ & \\
& \verb|\qty(\grande)| $\displaystyle\rightarrow \qty(\grande)$ & \\
& \verb|\qty[\typical]| $\rightarrow \qty[\typical]$ & automatic $\qty[\;]$ braces \\
& \verb+\qty|\typical|+ $\rightarrow \qty|\typical|$ & automatic $\qty|\;|$ braces \\
& \verb|\qty{\typical}| $\rightarrow \qty{\typical}$ & automatic $\qty{\;}$ braces \\
& \verb|\qty\big{}| $\rightarrow \qty\big{}$ & \multirow{2}{*}{\parbox{6cm}{manual sizing (works with any of the above bracket types)}} \\
& \verb|\qty\Big{}| $\rightarrow \qty\Big{}$ & \\
& \verb|\qty\bigg{}| $\rightarrow \qty\bigg{}$ & \\
& \verb|\qty\Bigg{}| $\rightarrow \qty\Bigg{}$ & \\
& \verb|\pqty{}| $\leftrightarrow$ \verb|\qty()| & \multirow{2}{*}{\parbox{6cm}{alternative syntax; robust and more \LaTeX-friendly}} \\
& \verb|\bqty{}| $\leftrightarrow$ \verb|\qty[]| & \\
& \verb+\vqty{}+ $\leftrightarrow$ \verb+\qty||+ & \\
& \verb|\Bqty{}| $\leftrightarrow$ \verb|\qty{}| & \\
\verb|\absolutevalue| & \verb|\abs{a}| $\rightarrow \abs{a}$ & automatic sizing; equivalent to \verb|\qty| \!\!\texttt{|a|} \\
& \verb|\abs\Big{a}| $\rightarrow \abs\Big{a}$ & inherits manual sizing syntax from \verb|\qty| \\
& \verb|\abs*{\grande}| $\displaystyle\rightarrow \abs*{\grande}$ & star for no resize \\
\verb|\norm| & \verb|\norm{a}| $\rightarrow \norm{a}$ & automatic sizing \\
& \verb|\norm\Big{a}| $\rightarrow \norm\Big{a}$ & manual sizing \\
& \verb|\norm*{\grande}| $\displaystyle\rightarrow \norm*{\grande}$ & star for no resize \\
\verb|\evaluated| & \verb|\eval{x}_0^\infty| $\displaystyle\rightarrow \eval{x}_0^\infty$ & vertical bar for evaluation limits \\
& \verb|\eval(x| \!\!\texttt{|}\!\! \verb|_0^\infty| $\displaystyle\rightarrow \eval(x|_0^\infty$ & alternate form \\
& \verb|\eval[x| \!\!\texttt{|}\!\! \verb|_0^\infty| $\displaystyle\rightarrow \eval[x|_0^\infty$ & alternate form \\
& \verb|\eval[\venti| \!\!\texttt{|}\!\! \verb|_0^\infty| $\displaystyle\rightarrow \eval[\venti|_0^\infty$ & automatic sizing\\
& \verb|\eval*[\venti| \!\!\texttt{|}\!\! \verb|_0^\infty| $\displaystyle\rightarrow \eval*[\venti|_0^\infty$ & star for no resize \\
\verb|\order| & \verb|\order{x^2}| $\rightarrow \order{x^2}$ & order symbol; automatic sizing and space handling \\
& \verb|\order\Big{x^2}| $\rightarrow \order\Big{x^2}$ & manual sizing \\
& \verb|\order*{\grande}| $\displaystyle\rightarrow \order*{\grande}$ & star for no resize \\
\verb|\commutator| & \verb|\comm{A}{B}| $\rightarrow \comm{A}{B}$ & automatic sizing \\
& \verb|\comm\Big{A}{B}| $\rightarrow \comm\Big{A}{B}$ & manual sizing \\
& \verb|\comm*{A}{\grande}| $\displaystyle\rightarrow \comm*{A}{\grande}$ & star for no resize \\
\verb|\anticommutator| & \verb|\acomm{A}{B}| $\rightarrow \acomm{A}{B}$ & same as \verb|\poissonbracket| \\
%& \verb|\acommutator{A}{B}| $\rightarrow \acommutator{A}{B}$ & alternate name \\
\verb|\poissonbracket| & \verb|\pb{A}{B}| $\rightarrow \pb{A}{B}$ & same as \verb|\anticommutator|
\end{longtable}

\subsection{Vector notation}
The default del symbol $\vnabla$ used in \texttt{physics} vector notation can be switched to appear with an arrow $\vec{\vnabla}$ by including the option \texttt{arrowdel} in the document preamble $\rightarrow$ \verb|\usepackage[arrowdel]{physics}|.
\begin{longtable}[l]{ l l p{6cm} }
\verb|\vectorbold| & \verb|\vb{a}| $\rightarrow \vb{a}$ & upright/no Greek \\
& \verb|\vb*{a}|, \verb|\vb*{\theta}| $\rightarrow \vb*{a}$, $\vb*{\theta}$ & italic/Greek \\
\verb|\vectorarrow| & \verb|\va{a}| $\rightarrow \va{a}$ & upright/no Greek \\
& \verb|\va*{a}|, \verb|\va*{\theta}| $\rightarrow \va*{a}$, $\va*{\theta}$ & italic/Greek \\
\verb|\vectorunit| & \verb|\vu{a}| $\rightarrow \vu{a}$ & upright/no Greek \\
& \verb|\vu*{a}|, \verb|\vu*{\theta}| $\rightarrow \vu*{a}$, $\vu*{\theta}$ & italic/Greek \\
\verb|\dotproduct| & \verb|\vdot| $\rightarrow \vdot$ as in $\vb{a} \vdot \vb{b}$ & note: \verb|\dp| is a protected \TeX\ primitive \\
\verb|\crossproduct| & \verb|\cross| $\rightarrow \cross$ as in $\vb{a} \cross \vb{b}$ & alternate name \\
& \verb|\cp| $\rightarrow \cp$ as in $\vb{a} \cp \vb{b}$ & shorthand name \\
\verb|\gradient| & \verb|\grad| $\rightarrow \grad$ & \\
& \verb|\grad{\Psi}| $\rightarrow \grad{\Psi}$ & default mode \\
& \verb|\grad(\Psi+\tall)| $\displaystyle\rightarrow \grad(\Psi+\tall)$ & long-form (like \verb|\qty| but also handles spacing) \\
& \verb|\grad[\Psi+\tall]| $\displaystyle\rightarrow \grad[\Psi+\tall]$ & \\
\verb|\divergence| & \verb|\div| $\rightarrow \div$ & note: \texttt{amsmath} symbol $\divisionsymbol$ renamed \verb|\divisionsymbol| \\
& \verb|\div{\vb{a}}| $\rightarrow \div{\vb{a}}$ & default mode \\
& \verb|\div(\vb{a}+\tall)| $\displaystyle\rightarrow \div(\vb{a}+\tall)$ & long-form \\
& \verb|\div[\vb{a}+\tall]| $\displaystyle\rightarrow \div[\vb{a}+\tall]$ & \\
\verb|\curl| & \verb|\curl| $\rightarrow \curl$ & \\
& \verb|\curl{\vb{a}}| $\rightarrow \curl{\vb{a}}$ & default mode \\
& \verb|\curl(\vb{a}+\tall)| $\displaystyle\rightarrow \curl(\vb{a}+\tall)$ & long-form \\
& \verb|\curl[\vb{a}+\tall]| $\displaystyle\rightarrow \curl[\vb{a}+\tall]$ & \\
\verb|\laplacian| & \verb|\laplacian| $\rightarrow \laplacian$ & \\
& \verb|\laplacian{\Psi}| $\rightarrow \laplacian{\Psi}$ & default mode \\
& \verb|\laplacian(\Psi+\tall)| $\displaystyle\rightarrow \laplacian(\Psi+\tall)$ & long-form \\
& \verb|\laplacian[\Psi+\tall]| $\displaystyle\rightarrow \laplacian[\Psi+\tall]$ &
\end{longtable}

\subsection{Operators}
The standard set of trig functions is redefined in \texttt{physics} to provide automatic braces that behave like \verb|\qty()|. In addition, an optional power argument is provided. This behavior can be switched off by including the option \texttt{notrig} in the preamble $\rightarrow$ \verb|\usepackage[notrig]{physics}|.

\begin{tabular}[l]{ l l p{8cm} }
\multicolumn{3}{l}{Example trig redefinitions:} \\
\verb|\sin| & \verb|\sin(\grande)| $\displaystyle\rightarrow \sin(\grande)$ & automatic braces; old \verb|\sin| renamed \verb|\sine| \\
& \verb|\sin[2](x)| $\rightarrow \sin[2](x)$ & optional power \\
& \verb|\sin x| $\rightarrow \sin x$ & can still use without an argument
\end{tabular}

The full set of available trig functions in \texttt{physics} includes:

\begin{tabular}{llll}
\verb|\sin(x)| & \verb|\sinh(x)| & \verb|\arcsin(x)| & \verb|\asin(x)| \\
\verb|\cos(x)| & \verb|\cosh(x)| & \verb|\arccos(x)| & \verb|\acos(x)| \\
\verb|\tan(x)| & \verb|\tanh(x)| & \verb|\arctan(x)| & \verb|\atan(x)| \\
\verb|\csc(x)| & \verb|\csch(x)| & \verb|\arccsc(x)| & \verb|\acsc(x)| \\
\verb|\sec(x)| & \verb|\sech(x)| & \verb|\arcsec(x)| & \verb|\asec(x)| \\
\verb|\cot(x)| & \verb|\coth(x)| & \verb|\arccot(x)| & \verb|\acot(x)|
\end{tabular}$\Rightarrow$
\begin{tabular}{MMMM}
\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)
\end{tabular}

The standard trig functions (plus a few that are missing in \texttt{amsmath}) are available without any automatic bracing under a new set of longer names:

\begin{tabular}{llll}
\verb|\sine| & \verb|\hypsine| & \verb|\arcsine| & \verb|\asine| \\
\verb|\cosine| & \verb|\hypcosine| & \verb|\arccosine| & \verb|\acosine| \\
\verb|\tangent| & \verb|\hyptangent| & \verb|\arctangent| & \verb|\atangent| \\
\verb|\cosecant| & \verb|\hypcosecant| & \verb|\arccosecant| & \verb|\acosecant| \\
\verb|\secant| & \verb|\hypsecant| & \verb|\arcsecant| & \verb|\asecant| \\
\verb|\cotangent| & \verb|\hypcotangent| & \verb|\arccotangent| & \verb|\acotangent|
\end{tabular}

Similar behavior has also been extended to the following functions:

\begin{tabular}{l>{$}l<{$}ll}
\verb|\exp(\tall)| & \exp(\tall) & & \verb|\exponential| \\
\verb|\log(\tall)| & \log(\tall) & & \verb|\logarithm| \\
\verb|\ln(\tall)| & \ln(\tall) & old definitions $\Rightarrow$ & \verb|\naturallogarithm| \\
\verb|\det(\tall)| & \det(\tall) & & \verb|\determinant| \\
\verb|\Pr(\tall)| & \Pr(\tall) & & \verb|\Probability|
\end{tabular}

\begin{longtable}[l]{ l l p{8cm} }
\multicolumn{3}{l}{New operators:} \\
\verb|\trace| or \verb|\tr| & \verb|\tr\rho| $\rightarrow \tr\rho$ also \verb|\tr(\tall)| $\rightarrow \tr(\tall)$  & trace; same bracing as trig functions \\
\verb|\Trace| or \verb|\Tr| & \verb|\Tr\rho| $\rightarrow \Tr\rho$ & alternate \\
\verb|\rank| & \verb|\rank M| $\rightarrow \rank M$ & matrix rank \\
\verb|\erf| & \verb|\erf(x)|$\rightarrow \erf(x)$ & Gauss error function \\
\verb|\Res| & \verb|\Res[f(z)]|$\rightarrow \Res[f(z)]$ & residue; same bracing as trig functions \\
\verb|\principalvalue| & \verb|\pv{\int f(z) \dd{z}}|$\rightarrow \pv{\int f(z) \dd{z}}$ & Cauchy principal value \\
& \verb|\PV{\int f(z) \dd{z}}|$\rightarrow \PV{\int f(z) \dd{z}}$ & alternate \\
\verb|\Re| & \verb|\Re{z}| $\rightarrow \Re{z}$ & old \verb|\Re| renamed to \verb|\real| $\rightarrow \real$ \\
\verb|\Im| & \verb|\Im{z}| $\rightarrow \Im{z}$ & old \verb|\Im| renamed to \verb|\imaginary| $\rightarrow \imaginary$
\end{longtable}

\subsection{Quick quad text}
This set of commands produces text in math-mode padded by \verb|\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 \verb|\quad| for use in aligned environments such as \texttt{cases}.

\begin{tabular}[l]{ l l p{6cm} }
General text: & & \\
\verb|\qqtext| & \verb|\qq{}| & general quick quad text with argument \\
& \verb|\qq{word or phrase}| $\rightarrow$\Vtextvisiblespace[1em]$\text{word or phrase}$\Vtextvisiblespace[1em] & normal mode; left and right \verb|\quad| \\
& \verb|\qq*{word or phrase}| $\rightarrow \text{word or phrase}$\Vtextvisiblespace[1em] & starred mode; right \verb|\quad| only
\end{tabular}

\begin{longtable}[l]{ l l }
Special macros: & \\
\verb|\qcomma| or \verb|\qc| $\rightarrow ,$\Vtextvisiblespace[1em] & right \verb|\quad| only \\
\verb|\qcc| $\rightarrow$\Vtextvisiblespace[1em]$\text{c.c.}$\Vtextvisiblespace[1em] & complex conjugate; left and right \verb|\quad| unless starred \verb|\qcc*| $\rightarrow \text{c.c.}$\Vtextvisiblespace[1em] \\
\verb|\qif| $\rightarrow$\Vtextvisiblespace[1em]$\text{if}$\Vtextvisiblespace[1em] & left and right \verb|\quad| unless starred \verb|\qif*| $\rightarrow \text{if}$\Vtextvisiblespace[1em]
\end{longtable}
\begin{longtable}[l]{ l }
Similar to \verb|\qif|: \\
\verb|\qthen|, \verb|\qelse|, \verb|\qotherwise|, \verb|\qunless|, \verb|\qgiven|, \verb|\qusing|, \verb|\qassume|, \verb|\qsince|, \\
\verb|\qlet|, \verb|\qfor|, \verb|\qall|, \verb|\qeven|, \verb|\qodd|, \verb|\qinteger|, \verb|\qand|, \verb|\qor|, \verb|\qas|, \verb|\qin|
\end{longtable}

\subsection{Derivatives}
The default differential symbol $\dd$ which is used in \verb|\differential| and \verb|\derivative| can be switched to an italic form $d$ by including the option \texttt{italicdiff} in the preamble $\rightarrow$ \verb|\usepackage[italicdiff]{physics}|.
\begin{longtable}[l]{ l l p{6cm} }
\verb|\differential| & \verb|\dd| $\rightarrow \dd$ & \\
& \verb|\dd x| $\rightarrow \dd x$ & no spacing (not recommended) \\
& \verb|\dd{x}| $\rightarrow$ \textvisiblespace\,$\dd{x}$\textvisiblespace & automatic spacing based on neighbors \\
& \verb|\dd[3]{x}| $\rightarrow \dd[3]{x}$ & optional power \\
& \verb|\dd(\cos\theta)| $\rightarrow \dd(\cos\theta)$ & long-form; automatic braces \\
\verb|\derivative| & \verb|\dv{x}| $\displaystyle\rightarrow \dv{x}$ & one argument \\
& \verb|\dv{f}{x}| $\displaystyle\rightarrow \dv{f}{x}$ & two arguments \\
& \verb|\dv[n]{f}{x}| $\displaystyle\rightarrow \dv[n]{f}{x}$ & optional power \\
& \verb|\dv{x}(\grande)| $\displaystyle\rightarrow \dv{x}(\grande)$ & long-form; automatic braces, spacing \\
& \verb|\dv*{f}{x}| $\displaystyle\rightarrow \dv*{f}{x}$ & inline form using \verb|\flatfrac| \\
\verb|\partialderivative| & \verb|\pderivative{x}| $\displaystyle\rightarrow \pderivative{x}$ & alternate name \\
& \verb|\pdv{x}| $\displaystyle\rightarrow \pdv{x}$ & shorthand name \\
& \verb|\pdv{f}{x}| $\displaystyle\rightarrow \pdv{f}{x}$ & two arguments \\
& \verb|\pdv[n]{f}{x}| $\displaystyle\rightarrow \pdv[n]{f}{x}$ & optional power \\
& \verb|\pdv{x}(\grande)| $\displaystyle\rightarrow \pdv{x}(\grande)$ & long-form \\
& \verb|\pdv{f}{x}{y}| $\displaystyle\rightarrow \pdv{f}{x}{y}$ & mixed partial \\
& \verb|\pdv*{f}{x}| $\displaystyle\rightarrow \pdv*{f}{x}$ & inline form using \verb|\flatfrac| \\
\verb|\variation| & \verb|\var{F[g(x)]}| $\rightarrow \var{F[g(x)]}$ & functional variation (works like \verb|\dd|) \\
& \verb|\var(E-TS)| $\rightarrow \var(E-TS)$ & long-form \\
\verb|\functionalderivative| & \verb|\fdv{g}| $\displaystyle\rightarrow \fdv{g}$ & functional derivative (works like \verb|\dv|) \\
& \verb|\fdv{F}{g}| $\displaystyle\rightarrow \fdv{F}{g}$ & \\
& \verb|\fdv{V}(E-TS)| $\displaystyle\rightarrow \fdv{V}(E-TS)$ & long-form \\
& \verb|\fdv*{F}{x}| $\displaystyle\rightarrow \fdv*{F}{x}$ & inline form using \verb|\flatfrac|
\end{longtable}

\subsection{Dirac bra-ket notation}
The following collection of macros for Dirac notation contains two fundamental commands, \verb|\bra| and \verb|\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 \texttt{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\footnote{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.}
\begin{displaymath}
\verb|\bra{\phi}\ket{\psi}| \rightarrow \bra{\phi}\ket{\psi} \qq{as opposed to} \bra{\phi} \ket{\psi}
\end{displaymath}
whereas a similar construction with higher-level macros will not contract in a robust manner
\begin{displaymath}
\verb|\bra{\phi}\dyad{\psi}{\xi}| \rightarrow \bra{\phi}\dyad{\psi}{\xi}.
\end{displaymath}
On the other hand, the correct output can be generated by sticking to the fundamental commands,
\begin{displaymath}
\verb|\bra{\phi}\ket{\psi}\bra{\xi}| \rightarrow \bra{\phi}\ket{\psi}\bra{\xi}
\end{displaymath}
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.
\begin{longtable}[l]{ l L p{6cm} }
\verb|\ket| & \verb|\ket{\tall}| \rightarrow \ket{\tall} & automatic sizing \\
& \verb|\ket*{\tall}| \rightarrow \ket*{\tall} & no resize \\
\verb|\bra| & \verb|\bra{\tall}| \rightarrow \bra{\tall} & automatic sizing \\
& \verb|\bra*{\tall}| \rightarrow \bra*{\tall} & no resize \\
& \verb|\bra{\phi}\ket{\psi}| \rightarrow \bra{\phi}\ket{\psi} & automatic contraction \\
& \verb|\bra{\phi}\ket{\tall}| \rightarrow \bra{\phi}\ket{\tall} & contraction inherits automatic sizing \\
& \verb|\bra{\phi}\ket*{\tall}| \rightarrow \bra{\phi}\ket*{\tall} & \multirow{2}{*}{\parbox{6cm}{a star on either term in the contraction prohibits resizing}} \\
& \verb|\bra*{\phi}\ket{\tall}| \rightarrow \bra*{\phi}\ket{\tall} & \\
& \verb|\bra*{\phi}\ket*{\tall}| \rightarrow \bra*{\phi}\ket*{\tall} & \\
\verb|\innerproduct| & \verb|\braket{a}{b}| \rightarrow \braket{a}{b} & two-argument braket \\
& \verb|\braket{a}| \rightarrow \braket{a} & one-argument (norm) \\
& \verb|\braket{a}{\tall}| \rightarrow \braket{a}{\tall} & automatic sizing \\
& \verb|\braket*{a}{\tall}| \rightarrow \braket*{a}{\tall} & no resize \\
& \verb|\ip{a}{b}| \rightarrow \ip{a}{b} & shorthand name \\
\verb|\outerproduct| & \verb|\dyad{a}{b}| \rightarrow \dyad{a}{b} & two-argument dyad \\
& \verb|\dyad{a}| \rightarrow \dyad{a} & one-argument (projector) \\
& \verb|\dyad{a}{\tall}| \rightarrow \dyad{a}{\tall} & automatic sizing \\
& \verb|\dyad*{a}{\tall}| \rightarrow \dyad*{a}{\tall} & no resize \\
& \verb|\ketbra{a}{b}| \rightarrow \ketbra{a}{b} & alternative name \\
& \verb|\op{a}{b}| \rightarrow \op{a}{b} & shorthand name \\
\verb|\expectationvalue| & \verb|\expval{A}| \rightarrow \expval{A} & implicit form \\
& \verb|\expval{A}{\Psi}| \rightarrow \expval{A}{\Psi} & explicit form \\
& \verb|\ev{A}{\Psi}| \rightarrow \ev{A}{\Psi} & shorthand name \\
& \verb|\ev{\grande}{\Psi}| \rightarrow \ev{\grande}{\Psi} & default sizing ignores middle argument \\
& \verb|\ev*{\grande}{\tall}| \rightarrow \ev*{\grande}{\tall} & single star does no resizing whatsoever \\
& \verb|\ev**{\grande}{\Psi}| \rightarrow \ev**{\grande}{\Psi} & double star resizes based on all parts \\
\verb|\matrixelement| & \verb|\matrixel{n}{A}{m}| \rightarrow \matrixel{n}{A}{m} & requires all three arguments \\
& \verb|\mel{n}{A}{m}| \rightarrow \mel{n}{A}{m} & shorthand name \\
& \verb|\mel{n}{\grande}{m}| \rightarrow \mel{n}{\grande}{m} & default sizing ignores middle argument \\
& \verb|\mel*{n}{\grande}{\tall}| \rightarrow \mel*{n}{\grande}{\tall} & single star does no resizing whatsoever \\
& \verb|\mel**{n}{\grande}{m}| \rightarrow \mel**{n}{\grande}{m} & double star resizes based on all parts
\end{longtable}

\subsection{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 \verb|\identitymatrix{2}| which has also has the shortcut \verb|\imat{2}| produces the elements of a $2 \times 2$ identity matrix $\smqty{\imat{2}}$ without braces or grouping. This allows the command to also be used within another matrix, as in:

\begin{minipage}{3cm}
\begin{verbatim}
\begin{pmatrix}
\imat{2} \\ a & b
\end{pmatrix}
\end{verbatim}
\end{minipage}
\begin{minipage}{6cm}
\begin{displaymath}
\Rightarrow\qquad
\begin{pmatrix}
\imat{2} \\ a & b
\end{pmatrix}
\end{displaymath}
\end{minipage}

To specify elements on the right of left sides of our \verb|\imat{2}| sub-matrix we use the grouping command \verb|\matrixquantity| or \verb|\mqty| to effectively convert \verb|\imat{2}| into a single matrix element of a larger matrix:

\begin{minipage}{9cm}
\begin{verbatim}
\begin{pmatrix}
\mqty{\imat{2}} & \mqty{a\\b} \\ \mqty{c & d} & e
\end{pmatrix}
\end{verbatim}
\end{minipage}
\begin{minipage}{6cm}
\begin{displaymath}
\Rightarrow\qquad
\begin{pmatrix}
\mqty{\imat{2}} & \mqty{a\\b} \\ \mqty{c & d} & e
\end{pmatrix}
\end{displaymath}
\end{minipage}

The extra \verb|\mqty| groups were required in this case in order to get the $a$ and $b$ elements to behave as a single element, since \verb|\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 \texttt{pmatrix} environment could have also been replaced with the \texttt{physics} macro \verb|\mqty()|, allowing the above example to be written on one line:

\begin{minipage}{9cm}
\begin{verbatim}
\mqty(\mqty{\imat{2}} & \mqty{a\\b} \\ \mqty{c & d} & e)
\end{verbatim}
\end{minipage}
\begin{minipage}{6cm}
\begin{displaymath}
\Rightarrow\qquad
\mqty(\mqty{\imat{2}} & \mqty{a\\b} \\ \mqty{c & d} & e)
\end{displaymath}
\end{minipage}

\begin{longtable}[l]{ l L p{6cm} }
\verb|\matrixquantity| & \verb|\mqty{a & b \\ c & d}| \rightarrow \mqty{a & b \\ c & d} & groups a set of matrix elements into a single object \\
& \verb|\mqty(a & b \\ c & d)| \rightarrow {\mqty(a & b \\ c & d)} & parentheses \\
& \verb|\mqty*(a & b \\ c & d)| \rightarrow {\mqty*(a & b \\ c & d)} & alternate parentheses \\
& \verb|\mqty[a & b \\ c & d]| \rightarrow {\mqty[a & b \\ c & d]} & square brackets \\
& \verb|\mqty| \texttt{|} \verb|a & b \\ c & d| \texttt{|} \rightarrow {\mqty|a & b \\ c & d|} & vertical bars \\
& \verb|\pmqty{}| \leftrightarrow \verb|\mqty()| & \multirow{2}{*}{\parbox{6cm}{alternative syntax; robust and more \LaTeX-friendly}} \\
& \verb|\Pmqty{}| \leftrightarrow \verb|\mqty*()| & \\
& \verb|\bmqty{}| \leftrightarrow \verb|\mqty[]| & \\
& \verb|\vmqty{}| \leftrightarrow \verb+\mqty||+ & \\
\verb|\smallmatrixquantity| & \verb|\smqty{a & b \\ c & d}| \rightarrow \smqty{a & b \\ c & d} & the \texttt{smallmatrix} form of \verb|\mqty| \\
& \verb|\smqty()| \qor \verb|\spmqty{}| & small version of \verb|\mqty()| \\
& \verb|\smqty*()| \qor \verb|\sPmqty{}| & small version of \verb|\mqty*()|\\
& \verb|\smqty[]| \qor \verb|\sbmqty{}| & small version of \verb|\mqty[]| \\
& \verb+\smqty||+ \qor \verb|\svmqty{}| & small version of \verb+\mqty||+ \\
\verb|\matrixdeterminant| & \verb|\mdet{a & b \\ c & d}| \rightarrow {\mdet{a & b \\ c & d}} & matrix determinant \\
& \verb|\smdet{a & b \\ c & d}| \rightarrow {\smdet{a & b \\ c & d}} & small matrix determinant \\
\verb|\identitymatrix| & \verb|\imat{n}| & elements of $n \times n$ identity matrix \\
& \verb|\smqty(\imat{3})| \rightarrow \smqty(\imat{3}) & formatted with \verb|\mqty| or \verb|\smqty| \\
\verb|\xmatrix| & \verb|\xmat{x}{n}{m}| & elements of $n \times m$ matrix filled with $x$ \\
& \verb|\smqty(\xmat{1}{2}{3})| \rightarrow \smqty(\xmat{1}{2}{3}) & formatted with \verb|\mqty| or \verb|\smqty| \\
& \verb|\smqty(\xmat*{a}{3}{3})| \rightarrow \smqty(\xmat*{a}{3}{3}) & star for element indices \\
& \verb|\smqty(\xmat*{a}{3}{1})| \rightarrow \smqty(\xmat*{a}{3}{1}) & as a vector with indices \\
& \verb|\smqty(\xmat*{a}{1}{3})| \rightarrow \smqty(\xmat*{a}{1}{3}) & \\
\verb|\zeromatrix| & \verb|\zmat{n}{m}| & $n \times m$ matrix filled with zeros \\
& \verb|\smqty(\zmat{2}{2})| \rightarrow \smqty(\zmat{2}{2}) & equivalent to \verb|\xmat{0}{n}{m}| \\
\verb|\paulimatrix| & \verb|\pmat{n}| & $n^\text{th}$ Pauli matrix \\
& \verb|\smqty(\pmat{0})| \rightarrow \smqty(\pmat{0}) & $n\in \lbrace 0,1,2,3$ or $x,y,z \rbrace$ \\
& \verb|\smqty(\pmat{1})| \rightarrow \smqty(\pmat{1}) & \\
& \verb|\smqty(\pmat{2})| \rightarrow \smqty(\pmat{2}) & \\
& \verb|\smqty(\pmat{3})| \rightarrow \smqty(\pmat{3}) & \\
\verb|\diagonalmatrix| & \verb|\dmat{a,b,c,...}| & \multirow{2}{*}{\parbox{6cm}{specify up to eight diagonal or block diagonal elements}} \\
& \verb|\mqty(\dmat{1,2,3})| \rightarrow \mqty(\dmat{1,2,3}) & \\
& \verb|\mqty(\dmat[0]{1,2})| \rightarrow \mqty(\dmat[0]{1,2}) & optional argument to fill spaces \\
& \verb|\mqty(\dmat{1,2&3\\4&5})| \rightarrow \mqty(\dmat{1,2&3\\4&5}) & \parbox{6cm}{enter matrix elements for each block as a single diagonal element} \\
\verb|\antidiagonalmatrix| & \verb|\admat{a,b,c,...}| & same as syntax as \verb|\dmat| \\
& \verb|\mqty(\admat{1,2,3})| \rightarrow \mqty(\admat{1,2,3}) & \\
\end{longtable}

\end{document}