\documentclass{article}
\usepackage{fullpage}
\usepackage{parskip}
\usepackage{physics}
\usepackage[colorlinks,urlcolor=blue]{hyperref}
\usepackage{array}
\usepackage{longtable}
\usepackage{multirow}

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

% physics 1.20
\title{The \texttt{physics} package}
\author{Sergio C. de la Barrera}

\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(a+b)| $\rightarrow \qty(a+b)$ & automatic $\qty(\;)$ braces \\
& \verb|\qty[a+b]| $\rightarrow \qty[a+b]$ & automatic $\qty[\;]$ braces \\
& \verb|\qty| \!\!\texttt{|}\!\! \verb|a+b| \!\!\texttt{|} $\rightarrow \qty|a+b|$ & automatic $\qty|\;|$ braces \\
& \verb|\qty{a+b}| $\rightarrow \qty{a+b}$ & 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|\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|\norm| & \verb|\norm{a}| $\rightarrow \norm{a}$ & automatic sizing \\
& \verb|\norm\Big{a}| $\rightarrow \norm\Big{a}$ & manual sizing \\
\verb|\evaluated| & \verb|\eval{x}_0^\infty| $\displaystyle\rightarrow \eval{x}_0^\infty$ & automatic right vertical bar for evaluation limits \\
& \verb|\eval(x)_y| $\displaystyle\rightarrow \eval(x)_y$ & parenthetical form for holding values constant \\
\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|\commutator| & \verb|\comm{A}{B}| $\rightarrow \comm{A}{B}$ & automatic sizing \\
\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}
\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 that \verb|\dp| is a protected \TeX\ primitive \\
\verb|\crossproduct| & \verb|\cross| $\rightarrow \cross$ as in $\vb{a} \cross \vb{b}$ & \\
& \verb|\cp| $\rightarrow \cp$ as in $\vb{a} \cp \vb{b}$ & alternate name \\
\verb|\vnabla| &  \verb|\vnabla| $\rightarrow \vnabla$ versus $\nabla$ & low-level macro for bold version \\
\verb|\gradient| & \verb|\grad| $\rightarrow \grad$ & \\
& \verb|\grad{\Psi}| $\rightarrow \grad{\Psi}$ & default mode \\
& \verb|\grad(\Psi+\Phi)| $\rightarrow \grad(\Psi+\Phi)$ & long-form (like \verb|\qty| but also handles spacing) \\
& \verb|\grad[\Psi+\Phi]| $\rightarrow \grad[\Psi+\Phi]$ & \\
\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}+\vb{b})| $\rightarrow \div(\vb{a}+\vb{b})$ & long-form \\
& \verb|\div[\vb{a}+\vb{b}]| $\rightarrow \div[\vb{a}+\vb{b}]$ & \\
\verb|\curl| & \verb|\curl| $\rightarrow \curl$ & \\
& \verb|\curl{\vb{a}}| $\rightarrow \curl{\vb{a}}$ & default mode \\
& \verb|\curl(\vb{a}+\vb{b}})| $\rightarrow \curl(\vb{a}+\vb{b})$ & long-form \\
& \verb|\curl[\vb{a}+\vb{b}]| $\rightarrow \curl[\vb{a}+\vb{b}]$ & \\
\verb|\laplacian| & \verb|\laplacian| $\rightarrow \laplacian$ & \\
& \verb|\laplacian{\Psi}| $\rightarrow \laplacian{\Psi}$ & default mode \\
& \verb|\laplacian(\Psi+\Phi)| $\rightarrow \laplacian(\Psi+\Phi)$ & long-form \\
& \verb|\laplacian[\Psi+\Phi]| $\rightarrow \laplacian[\Psi+\Phi]$ &
\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. The old definition of each trig function is stored in a long form version as in \verb|\sin| $\rightarrow$ \verb|\sine|, \verb|\cos| $\rightarrow$ \verb|\cosine|, and so on.
\begin{longtable}[l]{ l l p{8cm} }
\multicolumn{3}{l}{Trig redefinitions:} \\
\verb|\sin| & \verb|\sin(x)| $\rightarrow \sin(x)$ & automatic braces; old \verb|\sin| renamed \verb|\sine| \\
& \verb|\sin[2](x)| $\rightarrow \sin[2](x)$ & optional power \\
\verb|\cos| & \verb|\cos(x)| $\rightarrow \cos(x)$ & works with all trig functions \\
\verb|\tan| & \verb|\tan x| $\rightarrow \tan x$ & can still use without an argument \\
$\quad\vdots$ & & $\qquad\vdots$ \\
\multicolumn{3}{l}{New operators:} \\
\verb|\tr| & \verb|\tr\rho| $\rightarrow \tr\rho$ & trace \\
\verb|\rank| & \verb|\rank M| $\rightarrow \rank M$ & matrix rank \\
\verb|\erf| & \verb|\erf(x)|$\rightarrow \erf(x)$ & Gauss error function
\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{longtable}[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{longtable}
\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}
\begin{longtable}[l]{ l l p{6cm} }
\verb|\differential| & \verb|\dd| $\rightarrow \dd$ & \\
& \verb|\dd x| $\rightarrow \dd x$ & no spacing; use in braces, fractions \\
& \verb|\dd{x}| $\rightarrow \dd{x}$\!\textvisiblespace & proper spacing for typical equations \\
& \verb|\dd[3]{x}| $\rightarrow \dd[3]{x}$\!\textvisiblespace & 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}(x^2+x)| $\displaystyle\rightarrow \dv{x}(x^2+x)$ & long-form; automatic braces, spacing \\
\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}(x+y)| $\displaystyle\rightarrow \pdv{x}(x+y)$ & long-form \\
& \verb|\pdv{f}{x}{y}| $\displaystyle\rightarrow \pdv{f}{x}{y}$ & mixed partial \\
\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
\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{\psi}| $\rightarrow \ket{\psi}$ & automatic sizing \\
& \verb|\ket*{\psi}| $\rightarrow \ket*{\psi}$ & complex conjugate (looks like \verb|\bra| but does not inherit contraction) \\
\verb|\bra| & \verb|\bra{\psi}| $\rightarrow \bra{\psi}$ & automatic sizing \\
& \verb|\bra*{\psi}| $\rightarrow \bra*{\psi}$ & complex conjugate (looks like \verb|\ket| but does not inherit contraction) \\
& \verb|\bra{\phi}\ket{\psi}| $\rightarrow \bra{\phi}\ket{\psi}$ & automatic contraction \\
\verb|\innerproduct| & \verb|\braket{a}{b}| $\rightarrow \braket{a}{b}$ & two-argument contraction; automatic sizing \\
& \verb|\braket{a}| $\rightarrow \braket{a}$ & single-argument; produces norm \\
& \verb|\braket*{a}{b}| $\rightarrow \braket*{a}{b}$ & complex conjugate; swaps arguments \\
& \verb|\ip{a}{b}| $\rightarrow \ip{a}{b}$ & shorthand name \\
\verb|\outerproduct| & \verb|\dyad{a}{b}| $\rightarrow \dyad{a}{b}$ & two-argument dyad; automatic sizing \\
& \verb|\dyad{a}| $\rightarrow \dyad{a}$ & single-argument; produces projector \\
& \verb|\dyad*{a}{b}| $\rightarrow \dyad*{a}{b}$ & complex conjugate; swaps arguments \\
& \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|\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 \\
\end{longtable}
\end{document}