<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">\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}{&gt;{$\displaystyle}c&lt;{$}}
\newcolumntype{L}{&gt;{$\displaystyle}l&lt;{$}}

\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| &amp; \verb|\qty(\typical)| $\displaystyle\rightarrow \qty(\typical)$ &amp; automatic $\qty(\;)$ braces \\
&amp; \verb|\qty(\tall)| $\displaystyle\rightarrow \qty(\tall)$ &amp; \\
&amp; \verb|\qty(\grande)| $\displaystyle\rightarrow \qty(\grande)$ &amp; \\
&amp; \verb|\qty[\typical]| $\rightarrow \qty[\typical]$ &amp; automatic $\qty[\;]$ braces \\
&amp; \verb+\qty|\typical|+ $\rightarrow \qty|\typical|$ &amp; automatic $\qty|\;|$ braces \\
&amp; \verb|\qty{\typical}| $\rightarrow \qty{\typical}$ &amp; automatic $\qty{\;}$ braces \\
&amp; \verb|\qty\big{}| $\rightarrow \qty\big{}$ &amp; \multirow{2}{*}{\parbox{6cm}{manual sizing (works with any of the above bracket types)}} \\
&amp; \verb|\qty\Big{}| $\rightarrow \qty\Big{}$ &amp; \\
&amp; \verb|\qty\bigg{}| $\rightarrow \qty\bigg{}$ &amp; \\
&amp; \verb|\qty\Bigg{}| $\rightarrow \qty\Bigg{}$ &amp; \\
&amp; \verb|\pqty{}| $\leftrightarrow$ \verb|\qty()| &amp; \multirow{2}{*}{\parbox{6cm}{alternative syntax; robust and more \LaTeX-friendly}} \\
&amp; \verb|\bqty{}| $\leftrightarrow$ \verb|\qty[]| &amp; \\
&amp; \verb+\vqty{}+ $\leftrightarrow$ \verb+\qty||+ &amp; \\
&amp; \verb|\Bqty{}| $\leftrightarrow$ \verb|\qty{}| &amp; \\
\verb|\absolutevalue| &amp; \verb|\abs{a}| $\rightarrow \abs{a}$ &amp; automatic sizing; equivalent to \verb|\qty| \!\!\texttt{|a|} \\
&amp; \verb|\abs\Big{a}| $\rightarrow \abs\Big{a}$ &amp; inherits manual sizing syntax from \verb|\qty| \\
&amp; \verb|\abs*{\grande}| $\displaystyle\rightarrow \abs*{\grande}$ &amp; star for no resize \\
\verb|\norm| &amp; \verb|\norm{a}| $\rightarrow \norm{a}$ &amp; automatic sizing \\
&amp; \verb|\norm\Big{a}| $\rightarrow \norm\Big{a}$ &amp; manual sizing \\
&amp; \verb|\norm*{\grande}| $\displaystyle\rightarrow \norm*{\grande}$ &amp; star for no resize \\
\verb|\evaluated| &amp; \verb|\eval{x}_0^\infty| $\displaystyle\rightarrow \eval{x}_0^\infty$ &amp; vertical bar for evaluation limits \\
&amp; \verb|\eval(x| \!\!\texttt{|}\!\! \verb|_0^\infty| $\displaystyle\rightarrow \eval(x|_0^\infty$ &amp; alternate form \\
&amp; \verb|\eval[x| \!\!\texttt{|}\!\! \verb|_0^\infty| $\displaystyle\rightarrow \eval[x|_0^\infty$ &amp; alternate form \\
&amp; \verb|\eval[\venti| \!\!\texttt{|}\!\! \verb|_0^\infty| $\displaystyle\rightarrow \eval[\venti|_0^\infty$ &amp; automatic sizing\\
&amp; \verb|\eval*[\venti| \!\!\texttt{|}\!\! \verb|_0^\infty| $\displaystyle\rightarrow \eval*[\venti|_0^\infty$ &amp; star for no resize \\
\verb|\order| &amp; \verb|\order{x^2}| $\rightarrow \order{x^2}$ &amp; order symbol; automatic sizing and space handling \\
&amp; \verb|\order\Big{x^2}| $\rightarrow \order\Big{x^2}$ &amp; manual sizing \\
&amp; \verb|\order*{\grande}| $\displaystyle\rightarrow \order*{\grande}$ &amp; star for no resize \\
\verb|\commutator| &amp; \verb|\comm{A}{B}| $\rightarrow \comm{A}{B}$ &amp; automatic sizing \\
&amp; \verb|\comm\Big{A}{B}| $\rightarrow \comm\Big{A}{B}$ &amp; manual sizing \\
&amp; \verb|\comm*{A}{\grande}| $\displaystyle\rightarrow \comm*{A}{\grande}$ &amp; star for no resize \\
\verb|\anticommutator| &amp; \verb|\acomm{A}{B}| $\rightarrow \acomm{A}{B}$ &amp; same as \verb|\poissonbracket| \\
%&amp; \verb|\acommutator{A}{B}| $\rightarrow \acommutator{A}{B}$ &amp; alternate name \\
\verb|\poissonbracket| &amp; \verb|\pb{A}{B}| $\rightarrow \pb{A}{B}$ &amp; 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| &amp; \verb|\vb{a}| $\rightarrow \vb{a}$ &amp; upright/no Greek \\
&amp; \verb|\vb*{a}|, \verb|\vb*{\theta}| $\rightarrow \vb*{a}$, $\vb*{\theta}$ &amp; italic/Greek \\
\verb|\vectorarrow| &amp; \verb|\va{a}| $\rightarrow \va{a}$ &amp; upright/no Greek \\
&amp; \verb|\va*{a}|, \verb|\va*{\theta}| $\rightarrow \va*{a}$, $\va*{\theta}$ &amp; italic/Greek \\
\verb|\vectorunit| &amp; \verb|\vu{a}| $\rightarrow \vu{a}$ &amp; upright/no Greek \\
&amp; \verb|\vu*{a}|, \verb|\vu*{\theta}| $\rightarrow \vu*{a}$, $\vu*{\theta}$ &amp; italic/Greek \\
\verb|\dotproduct| &amp; \verb|\vdot| $\rightarrow \vdot$ as in $\vb{a} \vdot \vb{b}$ &amp; note: \verb|\dp| is a protected \TeX\ primitive \\
\verb|\crossproduct| &amp; \verb|\cross| $\rightarrow \cross$ as in $\vb{a} \cross \vb{b}$ &amp; alternate name \\
&amp; \verb|\cp| $\rightarrow \cp$ as in $\vb{a} \cp \vb{b}$ &amp; shorthand name \\
\verb|\gradient| &amp; \verb|\grad| $\rightarrow \grad$ &amp; \\
&amp; \verb|\grad{\Psi}| $\rightarrow \grad{\Psi}$ &amp; default mode \\
&amp; \verb|\grad(\Psi+\tall)| $\displaystyle\rightarrow \grad(\Psi+\tall)$ &amp; long-form (like \verb|\qty| but also handles spacing) \\
&amp; \verb|\grad[\Psi+\tall]| $\displaystyle\rightarrow \grad[\Psi+\tall]$ &amp; \\
\verb|\divergence| &amp; \verb|\div| $\rightarrow \div$ &amp; note: \texttt{amsmath} symbol $\divisionsymbol$ renamed \verb|\divisionsymbol| \\
&amp; \verb|\div{\vb{a}}| $\rightarrow \div{\vb{a}}$ &amp; default mode \\
&amp; \verb|\div(\vb{a}+\tall)| $\displaystyle\rightarrow \div(\vb{a}+\tall)$ &amp; long-form \\
&amp; \verb|\div[\vb{a}+\tall]| $\displaystyle\rightarrow \div[\vb{a}+\tall]$ &amp; \\
\verb|\curl| &amp; \verb|\curl| $\rightarrow \curl$ &amp; \\
&amp; \verb|\curl{\vb{a}}| $\rightarrow \curl{\vb{a}}$ &amp; default mode \\
&amp; \verb|\curl(\vb{a}+\tall)| $\displaystyle\rightarrow \curl(\vb{a}+\tall)$ &amp; long-form \\
&amp; \verb|\curl[\vb{a}+\tall]| $\displaystyle\rightarrow \curl[\vb{a}+\tall]$ &amp; \\
\verb|\laplacian| &amp; \verb|\laplacian| $\rightarrow \laplacian$ &amp; \\
&amp; \verb|\laplacian{\Psi}| $\rightarrow \laplacian{\Psi}$ &amp; default mode \\
&amp; \verb|\laplacian(\Psi+\tall)| $\displaystyle\rightarrow \laplacian(\Psi+\tall)$ &amp; long-form \\
&amp; \verb|\laplacian[\Psi+\tall]| $\displaystyle\rightarrow \laplacian[\Psi+\tall]$ &amp;
\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| &amp; \verb|\sin(\grande)| $\displaystyle\rightarrow \sin(\grande)$ &amp; automatic braces; old \verb|\sin| renamed \verb|\sine| \\
&amp; \verb|\sin[2](x)| $\rightarrow \sin[2](x)$ &amp; optional power \\
&amp; \verb|\sin x| $\rightarrow \sin x$ &amp; 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)| &amp; \verb|\sinh(x)| &amp; \verb|\arcsin(x)| &amp; \verb|\asin(x)| \\
\verb|\cos(x)| &amp; \verb|\cosh(x)| &amp; \verb|\arccos(x)| &amp; \verb|\acos(x)| \\
\verb|\tan(x)| &amp; \verb|\tanh(x)| &amp; \verb|\arctan(x)| &amp; \verb|\atan(x)| \\
\verb|\csc(x)| &amp; \verb|\csch(x)| &amp; \verb|\arccsc(x)| &amp; \verb|\acsc(x)| \\
\verb|\sec(x)| &amp; \verb|\sech(x)| &amp; \verb|\arcsec(x)| &amp; \verb|\asec(x)| \\
\verb|\cot(x)| &amp; \verb|\coth(x)| &amp; \verb|\arccot(x)| &amp; \verb|\acot(x)|
\end{tabular}$\Rightarrow$
\begin{tabular}{MMMM}
\sin(x) &amp; \sinh(x) &amp; \arcsin(x) &amp; \asin(x) \\
\cos(x) &amp; \cosh(x) &amp; \arccos(x) &amp; \acos(x) \\
\tan(x) &amp; \tanh(x) &amp; \arctan(x) &amp; \atan(x) \\
\csc(x) &amp; \csch(x) &amp; \arccsc(x) &amp; \acsc(x) \\
\sec(x) &amp; \sech(x) &amp; \arcsec(x) &amp; \asec(x) \\
\cot(x) &amp; \coth(x) &amp; \arccot(x) &amp; \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| &amp; \verb|\hypsine| &amp; \verb|\arcsine| &amp; \verb|\asine| \\
\verb|\cosine| &amp; \verb|\hypcosine| &amp; \verb|\arccosine| &amp; \verb|\acosine| \\
\verb|\tangent| &amp; \verb|\hyptangent| &amp; \verb|\arctangent| &amp; \verb|\atangent| \\
\verb|\cosecant| &amp; \verb|\hypcosecant| &amp; \verb|\arccosecant| &amp; \verb|\acosecant| \\
\verb|\secant| &amp; \verb|\hypsecant| &amp; \verb|\arcsecant| &amp; \verb|\asecant| \\
\verb|\cotangent| &amp; \verb|\hypcotangent| &amp; \verb|\arccotangent| &amp; \verb|\acotangent|
\end{tabular}

Similar behavior has also been extended to the following functions:

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

\begin{longtable}[l]{ l l p{8cm} }
\multicolumn{3}{l}{New operators:} \\
\verb|\trace| or \verb|\tr| &amp; \verb|\tr\rho| $\rightarrow \tr\rho$ also \verb|\tr(\tall)| $\rightarrow \tr(\tall)$  &amp; trace; same bracing as trig functions \\
\verb|\Trace| or \verb|\Tr| &amp; \verb|\Tr\rho| $\rightarrow \Tr\rho$ &amp; alternate \\
\verb|\rank| &amp; \verb|\rank M| $\rightarrow \rank M$ &amp; matrix rank \\
\verb|\erf| &amp; \verb|\erf(x)|$\rightarrow \erf(x)$ &amp; Gauss error function \\
\verb|\Res| &amp; \verb|\Res[f(z)]|$\rightarrow \Res[f(z)]$ &amp; residue; same bracing as trig functions \\
\verb|\principalvalue| &amp; \verb|\pv{\int f(z) \dd{z}}|$\rightarrow \pv{\int f(z) \dd{z}}$ &amp; Cauchy principal value \\
&amp; \verb|\PV{\int f(z) \dd{z}}|$\rightarrow \PV{\int f(z) \dd{z}}$ &amp; alternate \\
\verb|\Re| &amp; \verb|\Re{z}| $\rightarrow \Re{z}$ &amp; old \verb|\Re| renamed to \verb|\real| $\rightarrow \real$ \\
\verb|\Im| &amp; \verb|\Im{z}| $\rightarrow \Im{z}$ &amp; 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: &amp; &amp; \\
\verb|\qqtext| &amp; \verb|\qq{}| &amp; general quick quad text with argument \\
&amp; \verb|\qq{word or phrase}| $\rightarrow$\Vtextvisiblespace[1em]$\text{word or phrase}$\Vtextvisiblespace[1em] &amp; normal mode; left and right \verb|\quad| \\
&amp; \verb|\qq*{word or phrase}| $\rightarrow \text{word or phrase}$\Vtextvisiblespace[1em] &amp; starred mode; right \verb|\quad| only
\end{tabular}

\begin{longtable}[l]{ l l }
Special macros: &amp; \\
\verb|\qcomma| or \verb|\qc| $\rightarrow ,$\Vtextvisiblespace[1em] &amp; right \verb|\quad| only \\
\verb|\qcc| $\rightarrow$\Vtextvisiblespace[1em]$\text{c.c.}$\Vtextvisiblespace[1em] &amp; 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] &amp; 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| &amp; \verb|\dd| $\rightarrow \dd$ &amp; \\
&amp; \verb|\dd x| $\rightarrow \dd x$ &amp; no spacing (not recommended) \\
&amp; \verb|\dd{x}| $\rightarrow$ \textvisiblespace\,$\dd{x}$\textvisiblespace &amp; automatic spacing based on neighbors \\
&amp; \verb|\dd[3]{x}| $\rightarrow \dd[3]{x}$ &amp; optional power \\
&amp; \verb|\dd(\cos\theta)| $\rightarrow \dd(\cos\theta)$ &amp; long-form; automatic braces \\
\verb|\derivative| &amp; \verb|\dv{x}| $\displaystyle\rightarrow \dv{x}$ &amp; one argument \\
&amp; \verb|\dv{f}{x}| $\displaystyle\rightarrow \dv{f}{x}$ &amp; two arguments \\
&amp; \verb|\dv[n]{f}{x}| $\displaystyle\rightarrow \dv[n]{f}{x}$ &amp; optional power \\
&amp; \verb|\dv{x}(\grande)| $\displaystyle\rightarrow \dv{x}(\grande)$ &amp; long-form; automatic braces, spacing \\
&amp; \verb|\dv*{f}{x}| $\displaystyle\rightarrow \dv*{f}{x}$ &amp; inline form using \verb|\flatfrac| \\
\verb|\partialderivative| &amp; \verb|\pderivative{x}| $\displaystyle\rightarrow \pderivative{x}$ &amp; alternate name \\
&amp; \verb|\pdv{x}| $\displaystyle\rightarrow \pdv{x}$ &amp; shorthand name \\
&amp; \verb|\pdv{f}{x}| $\displaystyle\rightarrow \pdv{f}{x}$ &amp; two arguments \\
&amp; \verb|\pdv[n]{f}{x}| $\displaystyle\rightarrow \pdv[n]{f}{x}$ &amp; optional power \\
&amp; \verb|\pdv{x}(\grande)| $\displaystyle\rightarrow \pdv{x}(\grande)$ &amp; long-form \\
&amp; \verb|\pdv{f}{x}{y}| $\displaystyle\rightarrow \pdv{f}{x}{y}$ &amp; mixed partial \\
&amp; \verb|\pdv*{f}{x}| $\displaystyle\rightarrow \pdv*{f}{x}$ &amp; inline form using \verb|\flatfrac| \\
\verb|\variation| &amp; \verb|\var{F[g(x)]}| $\rightarrow \var{F[g(x)]}$ &amp; functional variation (works like \verb|\dd|) \\
&amp; \verb|\var(E-TS)| $\rightarrow \var(E-TS)$ &amp; long-form \\
\verb|\functionalderivative| &amp; \verb|\fdv{g}| $\displaystyle\rightarrow \fdv{g}$ &amp; functional derivative (works like \verb|\dv|) \\
&amp; \verb|\fdv{F}{g}| $\displaystyle\rightarrow \fdv{F}{g}$ &amp; \\
&amp; \verb|\fdv{V}(E-TS)| $\displaystyle\rightarrow \fdv{V}(E-TS)$ &amp; long-form \\
&amp; \verb|\fdv*{F}{x}| $\displaystyle\rightarrow \fdv*{F}{x}$ &amp; 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| &amp; \verb|\ket{\tall}| \rightarrow \ket{\tall} &amp; automatic sizing \\
&amp; \verb|\ket*{\tall}| \rightarrow \ket*{\tall} &amp; no resize \\
\verb|\bra| &amp; \verb|\bra{\tall}| \rightarrow \bra{\tall} &amp; automatic sizing \\
&amp; \verb|\bra*{\tall}| \rightarrow \bra*{\tall} &amp; no resize \\
&amp; \verb|\bra{\phi}\ket{\psi}| \rightarrow \bra{\phi}\ket{\psi} &amp; automatic contraction \\
&amp; \verb|\bra{\phi}\ket{\tall}| \rightarrow \bra{\phi}\ket{\tall} &amp; contraction inherits automatic sizing \\
&amp; \verb|\bra{\phi}\ket*{\tall}| \rightarrow \bra{\phi}\ket*{\tall} &amp; \multirow{2}{*}{\parbox{6cm}{a star on either term in the contraction prohibits resizing}} \\
&amp; \verb|\bra*{\phi}\ket{\tall}| \rightarrow \bra*{\phi}\ket{\tall} &amp; \\
&amp; \verb|\bra*{\phi}\ket*{\tall}| \rightarrow \bra*{\phi}\ket*{\tall} &amp; \\
\verb|\innerproduct| &amp; \verb|\braket{a}{b}| \rightarrow \braket{a}{b} &amp; two-argument braket \\
&amp; \verb|\braket{a}| \rightarrow \braket{a} &amp; one-argument (norm) \\
&amp; \verb|\braket{a}{\tall}| \rightarrow \braket{a}{\tall} &amp; automatic sizing \\
&amp; \verb|\braket*{a}{\tall}| \rightarrow \braket*{a}{\tall} &amp; no resize \\
&amp; \verb|\ip{a}{b}| \rightarrow \ip{a}{b} &amp; shorthand name \\
\verb|\outerproduct| &amp; \verb|\dyad{a}{b}| \rightarrow \dyad{a}{b} &amp; two-argument dyad \\
&amp; \verb|\dyad{a}| \rightarrow \dyad{a} &amp; one-argument (projector) \\
&amp; \verb|\dyad{a}{\tall}| \rightarrow \dyad{a}{\tall} &amp; automatic sizing \\
&amp; \verb|\dyad*{a}{\tall}| \rightarrow \dyad*{a}{\tall} &amp; no resize \\
&amp; \verb|\ketbra{a}{b}| \rightarrow \ketbra{a}{b} &amp; alternative name \\
&amp; \verb|\op{a}{b}| \rightarrow \op{a}{b} &amp; shorthand name \\
\verb|\expectationvalue| &amp; \verb|\expval{A}| \rightarrow \expval{A} &amp; implicit form \\
&amp; \verb|\expval{A}{\Psi}| \rightarrow \expval{A}{\Psi} &amp; explicit form \\
&amp; \verb|\ev{A}{\Psi}| \rightarrow \ev{A}{\Psi} &amp; shorthand name \\
&amp; \verb|\ev{\grande}{\Psi}| \rightarrow \ev{\grande}{\Psi} &amp; default sizing ignores middle argument \\
&amp; \verb|\ev*{\grande}{\tall}| \rightarrow \ev*{\grande}{\tall} &amp; single star does no resizing whatsoever \\
&amp; \verb|\ev**{\grande}{\Psi}| \rightarrow \ev**{\grande}{\Psi} &amp; double star resizes based on all parts \\
\verb|\matrixelement| &amp; \verb|\matrixel{n}{A}{m}| \rightarrow \matrixel{n}{A}{m} &amp; requires all three arguments \\
&amp; \verb|\mel{n}{A}{m}| \rightarrow \mel{n}{A}{m} &amp; shorthand name \\
&amp; \verb|\mel{n}{\grande}{m}| \rightarrow \mel{n}{\grande}{m} &amp; default sizing ignores middle argument \\
&amp; \verb|\mel*{n}{\grande}{\tall}| \rightarrow \mel*{n}{\grande}{\tall} &amp; single star does no resizing whatsoever \\
&amp; \verb|\mel**{n}{\grande}{m}| \rightarrow \mel**{n}{\grande}{m} &amp; 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 &amp; b
\end{pmatrix}
\end{verbatim}
\end{minipage}
\begin{minipage}{6cm}
\begin{displaymath}
\Rightarrow\qquad
\begin{pmatrix}
\imat{2} \\ a &amp; 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}} &amp; \mqty{a\\b} \\ \mqty{c &amp; d} &amp; e
\end{pmatrix}
\end{verbatim}
\end{minipage}
\begin{minipage}{6cm}
\begin{displaymath}
\Rightarrow\qquad
\begin{pmatrix}
\mqty{\imat{2}} &amp; \mqty{a\\b} \\ \mqty{c &amp; d} &amp; 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}} &amp; \mqty{a\\b} \\ \mqty{c &amp; d} &amp; e)
\end{verbatim}
\end{minipage}
\begin{minipage}{6cm}
\begin{displaymath}
\Rightarrow\qquad
\mqty(\mqty{\imat{2}} &amp; \mqty{a\\b} \\ \mqty{c &amp; d} &amp; e)
\end{displaymath}
\end{minipage}

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

\end{document}</pre></body></html>