When you set physics or quantum-mechanics formulas, the same shapes keep recurring — the derivative d/dx, the partial ∂/∂x, the vertical bars of an absolute value or a norm, bras and kets, and the stacked indices of a tensor. Writing each of these out with \frac or \left| every time is laborious. This page introduces three packages that fold such notation into memorable commands: **physics, which supplies a whole kit of derivatives and self-sizing delimiters; braket, devoted to Dirac bra–ket notation; and tensor**, which lines up upper and lower indices cleanly. They are convenient, but physics in particular has pitfalls — it silently redefines some standard commands — so we will look at both the benefits and the cautions.
What the physics package is
physics**, by Sergio C. de la Barrera, is a package for setting physics mathematics quickly and readably. You enable it with the single preamble line \usepackage{physics}. Under the hood it requires xparse and amsmath; physics loads amsmath for you, so you need not name it separately. Its aim is plain: command names that make their purpose obvious, replacing long boilerplate such as \frac{\mathrm{d}}{\mathrm{d}x} with short commands.
\usepackage{physics}The commands it offers fall into broad groups: self-sizing delimiters (\qty, \abs, \norm, \eval), vector calculus (\grad, \div, \curl, \laplacian), derivatives and differentials (\dv, \pdv, \dd), Dirac notation (\bra, \ket, \braket), and a set of matrix macros. Below we take the most everyday ones in turn. The package also has some design quirks, which we collect at the end.
Derivatives and differentials in physics
The flagship of physics is its derivatives. \dv is the ordinary derivative, and its shape changes with the number of arguments. Given one argument, as in \dv{x}, it sets the operator d/dx; given two, as in \dv{f}{x}, it sets df/dx. Higher orders go in an optional argument: \dv[2]{f}{x} is d²f/dx² and \dv[n]{f}{x} is dⁿf/dxⁿ. The d is set upright (roman) by default in both numerator and denominator; \usepackage[italicdiff]{physics} switches it to an italic d.
The partial derivative is \pdv, following the same idiom as \dv. \pdv{f}{x} sets ∂f/∂x and \pdv[2]{f}{x} sets ∂²f/∂x². A mixed partial takes three arguments: \pdv{f}{x}{y} gives ∂²f/∂x∂y. The differential element itself is \dd: \dd{x} sets dx with spacing appropriate to its neighbours, and \dd[3]{x} sets d³x (you use it inside an integral as \int f(x) \dd{x}).
\[
\dv{f}{x}, \qquad \dv[2]{f}{x}, \qquad
\pdv{f}{x}{y}, \qquad \int_0^1 f(x) \dd{x}
\]From left to right this sets df/dx, the second derivative d²f/dx², the mixed partial ∂²f/∂x∂y, and an integral from 0 to 1 with the differential element dx after the integrand. For an inline slashed fraction, the starred \dv*{f}{x} outputs df/dx in the side-by-side \flatfrac form.
Self-sizing delimiters and bra–ket in physics
physics also supplies delimiters that grow automatically to fit their contents. \abs{a} sets the absolute value |a| and \norm{a} sets the norm ‖a‖, each sized to its contents (internally doing the work of \left…\right). To fix the size by hand you can insert \big, \Big, and friends, as in \abs\Big{a}; to keep the size unchanged, use the starred \abs*{a}. The evaluation bar is \eval (\eval{x}_0^\infty gives a bar with lower and upper limits). The general-purpose delimiter is \qty(...), with \qty(...), \qty[...], and \qty{...} giving round, square, and curly braces.
\[
\abs{\frac{a}{b}}, \qquad \norm{\vb{v}}, \qquad
\eval{x^2}_0^\infty, \qquad \qty( \frac{1}{2} )
\]Here the absolute-value bars stretch to the height of the fraction a/b, the double bars of the norm envelop the vector v, the evaluation bar stands at the right with 0 and ∞, and the final round parentheses grow to the height of the fraction 1/2.
For Dirac notation the fundamental pair is \bra{\phi} and \ket{\psi}. By design, writing \bra{\phi}\ket{\psi} (with no space between them) makes the bra and ket “contract” into a single inner product ⟨φ|ψ⟩. There is also \braket{a}{b} for the inner product directly (→ ⟨a|b⟩), the one-argument \braket{a} (→ ⟨a|a⟩, a norm), and \ketbra{a}{b} for the outer product (→ |a⟩⟨b|, an alias of \dyad). Each sizes itself to its contents, and a star turns the auto-sizing off.
The vector-calculus operators are present too. \grad is the gradient ∇, \div is the divergence ∇·, \curl is the curl ∇×, and \laplacian is the Laplacian ∇². They take a function as argument, so \grad{\Psi} sets ∇Ψ. The redefinition of \div, however, calls for caution — covered in the next section.
Cautions about physics, and alternatives
physics is convenient, but because it silently redefines standard commands, it needs care. The classic example is \div. In standard LaTeX \div is the division sign ÷, but physics replaces it with the divergence ∇· and moves the original ÷ to \divisionsymbol. The trigonometric functions are likewise redefined so that \sin and the rest automatically add parentheses (you can disable this with \usepackage[notrig]{physics}, and the original definitions remain under longer names such as \sine). \Re and \Im are replaced too. If you do not know this, you will be puzzled when “the usual symbol” fails to appear.
Another well-known pitfall is that the derivatives swallow a following parenthesized group as an argument. In physics, writing a parenthesis after the derivative — as in \dv{x}(\Psi) — is defined as a “long form” in which d/dx acts on the contents of the parentheses. So \dv{f}{x}(g) pulls (g) in as an argument of \dv rather than treating it as a separate factor, giving output you did not intend. This behaviour is a recurring topic on tex.stackexchange, enough that an improved physics-patch package exists for it. To avoid it, put a space before the following factor, insert {}, or write the parentheses some other way.
There are also clashes between packages. In particular siunitx, the standard for typesetting units, introduced a quantity command \qty in recent versions, which collides by name with physics’s \qty (behaviour depends on load order). For reasons like these, a style has spread in recent years of choosing purpose-built packages rather than adopting physics wholesale. For derivatives, the **derivative package handles high-order and multi-variable cases well; for nicely set differential operators there is fixdif; and physics2** is a tidied option aimed at legacy physics users.
For self-sizing delimiters, too, there is a style of defining your own named delimiters rather than leaning on physics. With mathtools’s \DeclarePairedDelimiter a single declaration such as \DeclarePairedDelimiter{\abs}{\lvert}{\rvert} gives you your own \abs, letting you choose between \abs{x} (default size) and \abs*{x} (auto-stretched with \left…\right). Because it overwrites no standard command and behaves predictably, it is preferred in documents that value robustness (see the mathtools page for details).
The braket package
If you want only light use of Dirac notation, Donald Arseneau’s **braket** package is a handy choice. Rather than a large toolkit like physics, it is a small package confined to bra–ket and set notation, loaded with \usepackage{braket}. It offers two families of commands: the fixed-size lowercase versions \bra{ }, \ket{ }, \braket{ }, \set{ } (a constant size regardless of contents), and the auto-stretching uppercase versions \Bra{ }, \Ket{ }, \Braket{ }, \Set{ } (which envelop their contents using \left…\right internally).
The convenience of the uppercase versions is that a vertical bar | written directly inside the argument stretches along with the outer delimiters. In \Braket every interior | grows to the height of the arguments, and in \Set the first | grows. For a double bar, use \| or its local alias ||.
\Braket{ \phi | \frac{\partial^2}{\partial t^2} | \psi }
\Set{ x \in \mathbf{R}^2 | 0 < {|x|} < 5 }In this example the first sets the matrix element ⟨φ| ∂²/∂t² |ψ⟩ around a second-order partial operator, with the outer angle brackets and both interior bars stretched to the height of the operator. The second sets the set { x ∈ R² | 0 < |x| < 5 }, stretching the outer braces and the dividing bar (the inner |x| is wrapped as {|x|} to keep it at a fixed size). Note that, unlike physics, braket does not define an outer-product \ketbra; the author recommends writing \ket{ }\bra{ } instead.
The tensor package
In tensors with mixed upper and lower indices, the horizontal position and spacing of the indices carry meaning. In Γ^μ_{νρ} or R^μ_{ν}{}^ρ_σ, for instance, the upper and lower indices must line up in the correct order from the left. Writing ^ and _ naively in succession stacks them at the same position, so you cannot tell which index comes first. The package that solves this is Philip G. Ratcliffe’s **tensor** (a complete revision of Mike Piff’s original, v2.2). It requires no external packages and is loaded with \usepackage{tensor}.
There are two central commands. The lightweight \indices is placed right after the tensor body and takes just the index string. Writing M\indices{^a_b^{cd}_e}, for example, sets M followed by an upper a, lower b, upper cd, and lower e, all kept in their correct horizontal positions. Inside the index string you use ^ (superscript) and _ (subscript) directly, grouping multi-character indices with braces as in ^{cd} (\sp and \sb do the same job).
The other command, \tensor, is backward compatible with Mike Piff’s original and takes the tensor body and the index string as separate arguments. \tensor{M}{^a_b^{cd}_e} produces exactly the same output as the \indices example above. The advantage of \tensor is that it can place indices before the tensor: passing a pre-index string in the optional first argument lets you align indices both before and after the body M, as in \tensor[^a_b^c_d]{M}{^e_f^g_h}.
\[
M\indices{^a_b^{cd}_e}, \qquad
\tensor{M}{^a_b^{cd}_e}, \qquad
\tensor[^a_b^c_d]{M}{^e_f^g_h}
\]In all three, the upper and lower indices do not overlap but step out in the correct order from the left; only the last example also carries a set of indices before M. Both \indices and \tensor have starred forms: \indices* and \tensor* collapse the spacing between indices to a more standard look. Additionally, placing a * at the start of the index string left-aligns the successive upper/lower pairs (useful when you want to curb positional drift).
As a bonus, \nuclide is defined for use in both text and math mode. \nuclide[14][6]{C} sets ¹⁴₆C, placing the mass number 14 and atomic number 6 at the upper and lower left of the element symbol C (both numbers are optional). Multi-token indices must be grouped in braces, and constructs such as \mathrm must be fully enclosed too, as in \indices{_{\mathrm{H}}^x}.