The physics package
Shortens physics notation: derivatives with \dv and \pdv, Dirac notation with \bra and \ket, brackets that size themselves with \qty, and vector operators such as \grad.
Loading the package
\usepackage{physics}A derivative written by hand is \frac{\mathrm{d}f}{\mathrm{d}x}; with physics it is \dv{f}{x}. The package has such short forms for ordinary and partial derivatives, bras and kets, expectation values, commutators, bold vectors, and gradient, divergence and curl.
physics loads amsmath. It also redefines existing commands: \div becomes the divergence, \Re and \Im print "Re" and "Im", and \sin, \cos and similar functions size the parentheses that follow them.
Main commands
\dv{f}{x} | Derivative df/dx with upright d; \dv[2]{f}{x} is the second derivative. |
\pdv{f}{x}{y} | Partial derivative; with three arguments the mixed derivative. |
\qty(\frac{a}{b}) | Parentheses sized to their content; \qty[...], \qty|...| and \qty{...} give square brackets, bars and braces. |
\abs{x}, \norm{v} | Absolute value and norm with bars that size themselves. |
\bra{\phi}, \ket{\psi}, \braket{\phi}{\psi} | Dirac notation: bra, ket and inner product. |
\expval{H}{\psi} | Expectation value of H in the state psi. |
\vb{F} | Upright bold vector; \vb*{\alpha} is bold italic and also works for Greek letters. |
\grad, \div, \curl | Gradient, divergence and curl, written with a bold nabla. |
Complete example
\documentclass{article}
\usepackage{physics}
\begin{document}
\[
\dv{x}{t} = v, \qquad
\pdv{u}{t} = \alpha \pdv[2]{u}{x}
\]
\[
\vb{F} = -\grad V, \qquad
\div \vb{B} = 0
\]
\[
\braket{\phi}{\psi}, \qquad
\expval{H}{\psi}, \qquad
\qty(\frac{a}{b})^2, \qquad
\abs{\frac{x}{2}}
\]
\end{document}Compiled with pdfLaTeX from TeX Live 2023.
Pitfalls
\qtycollides withsiunitxversion 3. When both packages are loaded,siunitxleaves its own\qtyundefined and\qty{3}{\meter}fails. Write quantities with\SI{3}{\meter}in such a document.\divno longer prints the division sign.physicskeeps it as\divisionsymbol.\sin(x)and the other function names scale the parentheses with\leftand\right. Write\sin{(x)}to keep the parentheses in normal size, or load the package with the optionnotrig.
Related pages
- How-to Derivatives and partial derivatives in LaTeX
- How-to Vectors in LaTeX
- How-to Absolute value and norm in LaTeX
- Package
siunitx - Package
amsmath