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, \curlGradient, 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}
Result
The compiled example

Open in the editor

Compiled with pdfLaTeX from TeX Live 2023.

Pitfalls

Related pages