amsmath / AMSFonts

\usepackage{amsmath} is not a line that only adds things. It also takes things away. The moment amsmath is loaded, LaTeX’s \[ is replaced by the equation* environment, equation and cases are redefined, the plain-TeX \pmatrix stops working with an error, and \over starts producing a warning. It is not a box of conveniences but a change of house style for mathematical typesetting. This page covers what that change consists of, and the commands that work across every environment — \DeclareMathOperator, \text, \intertext, \substack, \dfrac. The alignment environments themselves have their own page.

What loading amsmath actually changes

First, amsmath is not one package but a bundle. Near the top of amsmath.sty sit three \RequirePackage lines, pulling in amstext (the \text command for words inside a formula), amsbsy (bold math via \boldsymbol) and amsopn (\DeclareMathOperator and the machinery for operator names). One line therefore brings every command on this page with it.

latex
\usepackage{amsmath}

Then the substitutions. The last two lines of amsmath.sty are \DeclareRobustCommand{\[}{\begin{equation*}} and \DeclareRobustCommand{\]}{\end{equation*}} — the basic display commands themselves are swapped for an amsmath environment. Elsewhere in the same file equation, cases, matrix and pmatrix are all put through \renewenvironment, and \nonumber is redefined too. It is precisely because of these substitutions that \tag, \qedhere and the automatic dodging of equation numbers work at all. Conversely, writing $$$$ bypasses that layer, and all of amsmath’s machinery goes with it.

Some things are taken away. Bring plain-TeX habits along and they stop. $\pmatrix{a&b\cr c&d\cr}$ gives ! Package amsmath Error: Old form \pmatrix should be \begin{pmatrix}., and \cases{…} is scolded in the same terms. 1 \over 2 still compiles, but with Package amsmath Warning: Foreign command \over; \frac or \genfrac should be used instead. These three are the first messages you meet when converting an old manuscript, and all three say the same thing: move to the newer form.

amsmath is allowed to intervene this heavily because it is classified as a required LaTeX package. The README shipped with it states that maintenance of amsmath passed from the AMS to the LaTeX Project effective 2016 — the copyright notice in amsmath.sty reads “2016–2023 LaTeX Project and American Mathematical Society” and names the LaTeX Project as current maintainer. In practice it is part of LaTeX itself, which is exactly why it may replace standard commands.

\DeclareMathOperator: why an operator name must not be italic

In math mode letters are variables, so typing rank A gives the product of r, a, n, k and A. LaTeX predefines \sin, \log, \lim and a few dozen other operator names, but rank is not among them. You might think that switching off the italic with \mathit{rank} fixes it. It does not: correcting the shape does not correct the spacing. Measure it. \operatorname{rank} A leaves a 1.66pt gap between rank and A. \mathit{rank} A leaves 1.07pt — that is the italic correction alone, with no operator space at all. And \mathrm{log} x comes out as “logx”, glued together.

Open amsopn.sty and one line explains it. \operatorname expands to \mathop{…\operator@font…}. An operator name is therefore not merely an upright string but is registered as an Op atom in TeX’s scheme of symbol classes. TeX’s spacing table puts \thinmuskip (3mu) between an Op and an Ord — and that is where the gap between “log” and “x” in \log x comes from. \mathrm changes only the shape of the letters; the atom stays an Ord, so no space appears. \DeclareMathOperator is not a cosmetic tool but a way of declaring meaning.

latex
% in the preamble
\DeclareMathOperator{\rank}{rank}
\DeclareMathOperator*{\argmax}{arg\,max}

% in the body
\[
  \rank A \le n, \qquad
  \hat{x} = \argmax_{x \in S} f(x)
\]

For a one-off, \operatorname{rank} A is enough; for an operator you use repeatedly, give it a name in the preamble. The star changes where the subscript goes. Without it, the subscript sits at the lower right, as on \log; with it, directly underneath, as on \lim, \sup and \max, whenever you are in display style. Measured on the example above, the x ∈ S of \argmax_{x \in S} sits centred under “arg max”, while the k of \rank_{k} sits at the lower right of “rank”. Note that \DeclareMathOperator is preamble-only: use it in the body and you get ! LaTeX Error: Can be used only in preamble. followed by an ! Undefined control sequence. for the command that was never defined.

If the \, in the definition looks odd, look at how the AMS writes its own. amsopn.sty defines \limsup as lim\,sup, \liminf as lim\,inf, and \injlim as inj\,lim. Joining the two words of an operator name with a thin space is the AMS house rule, and arg\,max merely follows it. \operatorname has a second, hidden job as well: it temporarily rewrites the math codes of -, ., :, / and * inside its argument so that a hyphen prints as a real hyphen rather than a minus sign. Measured, \operatorname{ess-sup} comes out as the single word “ess-sup”, whereas \mathrm{ess-sup} f comes out as “ess − sup f”, with 2.22pt of binary-operator space on each side of a minus sign — a different meaning as well as a different picture.

\text, \mathrm or \mbox: choosing between three uprights

There are three ways to get upright letters into a formula, and they answer different questions. \text{…} (from amstext) inserts prose. Its contents are set in the body font with body spacing, and typed spaces survive — the trailing space of \text{for all } really appears in the output. \mathrm{…} sets mathematical symbols upright. Inside it you are still in math mode, so spaces vanish; it is for upright symbols such as the \mathrm{d}x of a differential, or a unit. \mbox{…} is the general-purpose “put this in a box” and was never designed for mathematics.

latex
\[
  f(x) = x^2 \quad \text{for all } x \in \mathbb{R},
  \qquad v_{\text{max}} = 3,
  \qquad \int f(x)\,\mathrm{d}x.
\]

What makes \text better than \mbox is that it follows the size of its surroundings. Its definition in amstext.sty uses \mathchoice to give a separate size to each of the four contexts: display, text, script and scriptscript. The “max” of v_{\text{max}} above measures 6.19pt tall — script size — whereas \mbox{max} measures 8.85pt and sits in the subscript at full body size. There is a second practical property: \text falls back to \mbox when it is called in text mode, which makes it safe inside a macro that may be expanded in either mode.

\intertext and \substack: interrupting without breaking the alignment

You want a line of explanation in the middle of an align — and if you close the environment, write the sentence and reopen it, the alignment before and after no longer matches. \intertext{…} solves this. Measured, in an align split by an \intertext both = signs land at horizontal position 291.11pt, while the interjected sentence is set as an ordinary paragraph starting at the left margin. The mechanism is simple: in amsmath.sty, \intertext emits “below-display space, a \vbox holding the text, above-display space” from inside a \noalign. The text therefore never leaves the alignment, and the columns keep their positions. Used outside an alignment environment it gives ! Package amsmath Error: Invalid use of \intertext.

latex
\begin{align}
  A &= B + C \\
  \intertext{expanding $C$ gives}
  A &= B + D + E
\end{align}

\[
  \sum_{\substack{0 \le i \le m \\ 0 < j < n}} a_{ij}
\]

\substack{…} is a smaller tool with the same instinct. It stacks several lines of conditions under a big operator such as a sum or product, with lines separated by \\. In the example above, “0 ≤ i ≤ m” and “0 < j < n” become two rows, and measurement confirms both are centred beneath the summation sign. The inside is still math mode, so relations such as \le work as usual. When you want the lines aligned rather than centred, the near-identical subarray environment takes an alignment letter such as l.

\dfrac, \binom, \boldsymbol: writing that ignores the context

\frac is standard LaTeX, but its size is decided by the context it lands in. amsmath adds versions that ignore the context: \dfrac{…}{…} is always display style (large) and \tfrac{…}{…} always text style (small). Use \dfrac when a fraction in running text has to be readable, \tfrac when one part of a display should shrink. For continued fractions there is \cfrac{…}{…}, which keeps every level legible however deep the nesting. Binomial coefficients are \binom{n}{k}, with \dbinom and \tbinom as the style-fixed pair.

latex
\[
  \binom{n}{k} = \dfrac{n!}{k!\,(n-k)!},
  \qquad \boldsymbol{\nabla} \cdot \boldsymbol{E} = \rho / \varepsilon_0.
\]

There is a reason \boldsymbol appears in the same section. Physics and vector analysis often want bold letters, but \mathbf{E} gives an upright bold and does nothing to Greek letters. \boldsymbol{E}, from amsbsy (which amsmath brings along), keeps the italic and adds the weight, and works on symbols too, as in \boldsymbol{\nabla}. If your field writes vectors as bold italic, use \boldsymbol; if it writes matrices and tensors as upright bold, use \mathbf. Choose by the convention of the field. \numberwithin{equation}{section}, which ties equation numbers to section numbers, is also an amsmath command, but numbering belongs to the “Displayed, aligned and numbered equations” page.

amssymb and AMSFonts: the companion that adds symbols

The division of labour is clean: amsmath adds typesetting machinery, amssymb adds symbols you can write. amssymb defines every symbol in the AMS symbol fonts msam and msbm, putting hundreds of glyphs absent from standard LaTeX within reach — \leqslant and \geqslant (slanted inequalities), \nleq and \subsetneq, \therefore and \because, \square and \blacksquare, \varnothing. It loads amsfonts internally, so you never need to name amsfonts yourself.

latex
\usepackage{amssymb}

\[
  \mathbb{R} \subset \mathbb{C}, \qquad
  \mathfrak{g} = \operatorname{Lie}(G)
\]

AMSFonts also brings in two math alphabets: blackboard bold through \mathbb{…} and Fraktur through \mathfrak{…}. Here lies a pitfall that fails silently. Blackboard bold has capitals only — and \mathbb{k} does not raise an error. Look in amssymb.sty and slot "6B of the AMSb font is assigned to \daleth; compile it and out comes not a lowercase k but the Hebrew letter daleth, ℸ. If you need a blackboard bold k, use the purpose-built \Bbbk. Fraktur, by contrast, has both cases, so \mathfrak{g} for a Lie algebra and \mathfrak{p} for a prime ideal are both available.

The three lines that belong in your preamble

For any document containing mathematics, put these three lines together: amsmath (the typesetting machinery), amssymb (symbols, plus blackboard bold and Fraktur), and amsthm for theorems and proofs. The order is largely free, but amsthm goes after amsmath, because features such as \qedhere reach into amsmath’s display structures.

document.tex
\documentclass{article}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{amsthm}
\begin{document}
\[
  \zeta(s) = \sum_{n=1}^{\infty} \frac{1}{n^{s}}, \qquad s \in \mathbb{C}
\]
\end{document}
PackageRoleWhat it provides
amsmathmath typesetting machineryalignment environments, \text, \operatorname, \dfrac, \binom, \boldsymbol
amssymbsymbols and math alphabetshundreds of msam and msbm symbols, \mathbb, \mathfrak (loads amsfonts itself)
amsfontsfonts only\mathbb and \mathfrak, with no extra symbols
amsthmtheorem and proof environments\newtheorem, the proof environment, \theoremstyle, \qedhere

amsmath also provides the matrix environments (pmatrix, bmatrix and the rest) and auto-sized delimiters, but those belong to the “Matrices and arrays” and “Sums, integrals and big operators” pages. One last thing. Because amsmath’s display environments read their contents as a delimited macro argument, a blank line inside one is an error. The AMS technical notes say that the multi-pass algorithms behind this were inherited from Michael Spivak’s amstex.tex — 1980s AMS-TeX survives today in the form of a rule against blank lines.