Mathematics
One of the greatest motivating forces for Donald Knuth when he began developing the original TeX system was to create something that allowed simple construction of mathematical formulas, while looking professional when printed. The fact that he succeeded was most probably why TeX (and later on, LaTeX) became so popular within the scientific community. Typesetting mathematics is one of LaTeX's greatest strengths.
Mathematics Environments
LaTeX needs to know when the text is mathematical. This is because LaTeX typesets math notation differently from normal text. Therefore, special environments have been declared for this purpose. They can be distinguished into two categories:
- Inline (text): Formulas displayed within the body of text where it is declared (e.g., within a sentence).
- Displayed: Formulas printed on a line by themselves.
Syntax Shorthands
| Type | Environment | LaTeX Shorthand | TeX Shorthand |
|---|---|---|---|
| Inline | math | \( ... \) | $ ... $ |
| Displayed | displaymath | \[ ... \] | $$ ... $$ |
| Numbered | equation | N/A | N/A |
!WARNINGDo not use
$$ ... $$in LaTeX. It is a Plain TeX construct that breaks spacing in LaTeX and causes conflicts with AMS-LaTeX. Always use\[ ... \]for unnumbered display math, or\begin{equation}...\end{equation}for numbered equations. Using$$can produce incorrect spacing around operators and relations.
Basic Syntax & Symbols
In math mode, variables are typeset in italic, spaces are ignored, and every character is treated as a mathematical token.
Fractions and Integrals
- Fractions:
\frac{numerator}{denominator}produces . - Powers & Indices: Use
^for exponents and_for subscripts (e.g.,x_i^2produces ). - Integrals & Sums: Use
\intand\sumwith limits (e.g.,\sum_{i=1}^nproduces ).
Greek Letters
Greek letters are typed by prefixing the letter name with a backslash:
- Lowercase:
\alpha(),\beta(),\gamma(),\theta(),\lambda() - Uppercase:
\Gamma(),\Delta(),\Theta(),\Lambda()
Delimiters and Brackets
Use \left and \right to auto-size delimiters:
\left( \frac{a}{b} \right)
\left[ \sum_{i=1}^n x_i \right]
\left\{ x \in \mathbb{R} : x > 0 \right\}
Common delimiter pairs: \left( ... \right), \left[ ... \right], \left\{ ... \right\}, \left| ... \right|, \left\langle ... \right\rangle.
For manual sizing: \big, \Big, \bigg, \Bigg (each with (, ), [, ], \{, \}, |, / variants).
Math Spacing
LaTeX provides fine control over spacing in math mode:
| Command | Description | Example |
|---|---|---|
\, | Thin space (3/18 em) | |
\: | Medium space (4/18 em) | |
\; | Thick space (5/18 em) | |
\! | Negative thin space (-3/18 em) | |
\quad | 1 em space | |
\qquad | 2 em space |
Matrices
The amsmath package provides several matrix environments:
\begin{pmatrix} % parenthesized
a & b \\ c & d
\end{pmatrix}
\begin{bmatrix} % bracketed
a & b \\ c & d
\end{bmatrix}
\begin{vmatrix} % vertical bars (determinant)
a & b \\ c & d
\end{vmatrix}
\begin{Bmatrix} % curly braces
a & b \\ c & d
\end{Bmatrix}
\begin{Vmatrix} % double vertical bars
a & b \\ c & d
\end{Vmatrix}
Cases and Piecewise Functions
The cases environment is used for piecewise-defined functions:
f(x) = \begin{cases}
x^2 & \text{if } x \geq 0 \\
-x & \text{if } x < 0
\end{cases}
Advanced Math (amsmath)
For document structures containing numerous complex formulas, load amsmath or mathtools in your preamble:
\usepackage{amsmath}
This unlocks advanced alignment environments:
\begin{align}
f(x) &= (x + a)^2 \\
&= x^2 + 2ax + a^2
\end{align}
Other amsmath Environments
| Environment | Description |
|---|---|
gather | Multiple centered equations, auto-numbered |
multline | Long equations split across lines, first left-aligned, last right-aligned |
flalign | Full-length alignment (spans entire line width) |
alignat{N} | Alignment with N alignment columns |
Custom Operators
Define your own operators with \DeclareMathOperator:
\DeclareMathOperator{\Tr}{Tr} % Trace
\DeclareMathOperator{\diag}{diag} % Diagonal
\DeclareMathOperator*{\esssup}{ess\,sup} % ess sup with limits above/below
Common Math Symbols
Relations
| Symbol | Command | Description |
|---|---|---|
\leq | Less than or equal | |
\geq | Greater than or equal | |
\neq | Not equal | |
\approx | Approximately equal | |
\equiv | Equivalent | |
\sim | Similar to | |
\propto | Proportional to |
Operators
| Symbol | Command | Description |
|---|---|---|
\cup | Union | |
\cap | Intersection | |
\in | Element of | |
\subset | Subset | |
\forall | For all | |
\exists | There exists | |
\nabla | Nabla/gradient |
Arrows
| Symbol | Command | Description |
|---|---|---|
\rightarrow | Right arrow | |
\leftarrow | Left arrow | |
\leftrightarrow | Left-right arrow | |
\Rightarrow | Double right arrow | |
\Leftarrow | Double left arrow | |
\mapsto | Maps to |
The mathtools Package
The mathtools package extends amsmath with additional features:
\usepackage{mathtools}
Useful additions include:
\coloneqqfor definition arrows (:=)\DeclarePairedDelimiterfor custom delimiters\mathclapto reduce spacing in subscripts
\DeclarePairedDelimiter{\norm}{\lVert}{\rVert}
% Usage: $\norm{x}$ or $\norm*{\frac{x}{y}}$