Mathematics

Formulas inline and displayed, amsmath's environments, alphabets, and the packages built on them.

Formulas are written as in LaTeX and set with TeX's rules, using the measurements in an OpenType mathematics font: New Computer Modern Math by default.

Writing formulas

The identity $e^{i\pi} + 1 = 0$ links five constants, and
\[
  \int_{-\infty}^{\infty} e^{-x^2}\,dx = \sqrt{\pi}.
\]

Inline formulas

$...$ and \(...\) set a formula inside a line. A fraction, sum or limit inline is set smaller, with its limits to the side, as TeX sets them, so the line keeps its spacing.

Displayed formulas

\[...\] and $$...$$ set a formula on its own line, centred. The equation block does the same and numbers it.

Text inside a formula

\text{...} sets words in the text's face inside a formula, as in \text{if } x \ge 0.


amsmath

Most of amsmath is part of mLaTeX and works whether or not the package is loaded.

align

align sets several equations lined up at their &, each numbered unless marked \notag. \\ ends a line:

\begin{align}
  \partial_t u + (u\cdot\nabla)u - \nu\Delta u + \nabla p &= f, \label{eq:momentum}\\
  \nabla\cdot u &= 0. \notag
\end{align}
By \eqref{eq:momentum}, \dots

alignat lines up several columns with the spacing you give, and flalign spreads its columns to the margins.

gather and multline

gather centres several equations without lining them up. multline breaks one long equation over lines: the first to the left, the last to the right.

\begin{gather}
  a = b + c \\
  d = e
\end{gather}
\begin{multline}
  a + b + c + d + e + f \\
  + g + h + i
\end{multline}

Blocks inside a formula

aligned, gathered and split line up equations inside a larger formula, sharing one number. cases sets a choice:

\[
  |x| = \begin{cases}
    x  & \text{if } x \ge 0,\\
    -x & \text{otherwise.}
  \end{cases}
\]

Matrices

BlockBrackets
matrixNone
pmatrixParentheses
bmatrixSquare brackets
BmatrixBraces
vmatrixVertical bars
VmatrixDouble vertical bars
smallmatrixNone, at text size
\[
  A = \begin{pmatrix} 1 & 2 \\ 3 & 4 \end{pmatrix}, \qquad
  \det A = \begin{vmatrix} 1 & 2 \\ 3 & 4 \end{vmatrix}
\]

LaTeX's own array block works too, with a column type for each column.

Fractions and binomials

  • \frac{a}{b} is a fraction; \dfrac is always display-sized and \tfrac always text-sized.
  • \binom{n}{k} is a binomial coefficient, with \dbinom and \tbinom.
  • TeX's \over, \atop and \choose work as in TeX.

Operators

\operatorname{name} sets an operator name upright with an operator's spacing. \DeclareMathOperator{\tr}{tr} in the preamble makes it a command. Unlike most of amsmath, it needs the package loaded:

\usepackage{amsmath}
\DeclareMathOperator{\tr}{tr}
$\tr A = \operatorname{rank} B$

Stacking and arrows

  • \overset{above}{symbol} and \underset{below}{symbol} stack a small formula over or under a symbol.
  • \substack{i < n \\ j < m} sets several lines under a sum.
  • \sideset puts marks at the corners of a large operator.
  • \xrightarrow{f} and \xleftarrow{g} are arrows that stretch to their labels.

Wide equations

A displayed equation too wide for its number moves left, or puts its number on the line below, as amsmath does.


Symbols and alphabets

Symbols

Greek letters, relations, arrows, operators, delimiters and dots are all there, with the names LaTeX and amssymb give them. amssymb, amsfonts, mathrsfs, bm, dsfont and bbm are accepted; their symbols are already in the mathematics font.

Delimiters that grow

\left and \right grow a pair of delimiters to fit what is between them, and \middle grows one in between. \bigl, \Bigl, \biggl and \Biggl, with their r partners, choose a size by hand:

\[
  \left( \frac{a}{b} \middle| c \right) \qquad \Bigl[ x \Bigr]
\]

Alphabets

CommandAlphabetExample
\mathbbBlackboard bold\mathbb{R}
\mathcalCalligraphic\mathcal{L}
\mathscrScript\mathscr{F}
\mathfrakFraktur\mathfrak{g}
\mathrmUpright\mathrm{d}x
\mathsfSans serif\mathsf{P}
\mathttTypewriter\mathtt{x}
\mathitItalic\mathit{ab}
\mathbfBold upright\mathbf{v}

Bold italic, for vectors and Greek letters, comes from \boldsymbol or bm's \bm.

Accents

Accents sit over a symbol, and the wide ones stretch over what they cover: \hat, \widehat, \tilde, \widetilde, \vec, \overrightarrow, \bar, \overline, \dot, \ddot and \mathring.

Braces over and under

\overbrace, \underbrace, \overbracket and \underbracket set a brace with a label above or below:

\[
  \underbrace{1 + 2 + \cdots + n}_{n \text{ terms}} = \frac{n(n+1)}{2}
\]

Numbering

Numbered and unnumbered

Equations are numbered by equation, align and gather, and not by their starred forms (equation*, align*, gather*) or by lines marked \notag or \nonumber.

Referring to equations

\label{name} after an equation names it, and \eqref{name} refers to it with the number in parentheses. See References and Links.

Numbering within sections

\numberwithin{equation}{section} numbers equations 2.1, 2.2 and so on, starting again in each section.

Tags

\tag{*} gives a line a tag of your own in place of its number, and \tag*{(A)} sets a tag without parentheses added.


Packages built on mathematics

PackageWhat it adds
mathtoolsamsmath's fixes and additions; loads amsmath
physicsDerivatives, brackets and the notations physicists write every line
braket, diracDirac's bras and kets
cancelTerms struck through: \cancel, \bcancel, \xcancel, \cancelto
mhchemChemical formulas and equations: \ce{2H2 + O2 -> 2H2O}
siunitxNumbers and units, set as maths
esintIntegrals over surfaces and volumes
stmaryrdSt Mary's Road symbols, double brackets among them
nicefrac, xfracSmall slashed fractions: \nicefrac{1}{2}, \sfrac{1}{2}
commath, derivativeShort forms for calculus
unicode-math\setmathfont, and the \sym alphabets

Choosing the mathematics font

unicode-math

\setmathfont chooses the font formulas are set in:

\usepackage{unicode-math}
\setmathfont{STIX Two Math}

The fonts to choose from

mLaTeX carries New Computer Modern Math, STIX Two Math, Fira Math, Asana Math and the TeX Gyre Bonum, DejaVu, Pagella, Schola and Termes maths. \setmathfont picks the nearest of them to the name given.