Load the packages first
Most math-heavy documents start with amsmath, which provides display environments, matrices, \text{} and most of the commands in this guide. Add amssymb for extra symbols such as \mathbb{R}, amsthm for theorem environments, and mathtools for extensions that build on amsmath. Which math packages to use, and when covers the choice in more detail.
\documentclass{article}
\usepackage{amsmath,amssymb,amsthm}
\begin{document}
% your mathematics here
\end{document}
Operators with subscripts
Operators such as \sup, \inf, \max, \min and \lim take subscripts the same way ordinary symbols do. A supremum over a set is written with an underscore:
\[
M = \sup_{x \in [0,1]} \lvert f(x) \rvert
\]
\lvert and \rvert come from amsmath and give the bars the right spacing.
Sometimes the subscript lands beside the operator when you want it underneath. \limits places it underneath, and \nolimits places it beside:
$\sup\limits_{x \in S} f(x)$ % subscript underneath, even inline
$\sum\nolimits_{i=1}^{n} a_i$ % subscript beside, even in display
For an operator that LaTeX does not provide, declare it once in the preamble with \DeclareMathOperator from amsmath. The starred form places the limits above and below the operator in display math:
\DeclareMathOperator*{\argmax}{arg\,max}
...
\[
\hat{\theta} = \argmax_{\theta \in \Theta} \ell(\theta)
\]
The subscript guide explains the underscore syntax in more detail, including braces for longer subscripts.
Fractions, roots and brackets
Larger expressions often combine fractions, roots and delimiters. In the example below, \frac builds the fraction, and \left and \right make the parentheses grow with the content:
\[
\left( \frac{a}{b} + \sqrt{c} \right)^2
\]
Each topic has its own guide:
- Fractions with frac and dfrac
- Square roots and nth roots
- Sizing brackets and parentheses
- Piecewise functions with cases
Matrices and determinants
The pmatrix, bmatrix and vmatrix environments from amsmath cover most matrices. Each uses & to separate columns and \\ to end a row. The matrix and determinant guide lists every matrix environment and shows how to write a determinant.
Multi-line derivations and labels
The align environment lines up a derivation at a chosen symbol, usually the equals sign. Each line can carry its own equation number, or none. Aligning equations with align explains the environment and its variants.
Equations can also be labeled and cited in the text with \label and \eqref. How to label an equation covers numbering, cross-references and common mistakes.
Theorems, lemmas and proofs
The amsthm package defines theorem-style environments. Declare them in the preamble:
\usepackage{amsthm}
\theoremstyle{plain}
\newtheorem{theorem}{Theorem}
\newtheorem{lemma}[theorem]{Lemma}
\theoremstyle{definition}
\newtheorem{definition}[theorem]{Definition}
\newtheorem{lemma}[theorem]{Lemma} shares the counter with theorem, so lemmas and theorems number in one sequence. The \theoremstyle command sets the font and spacing for the environments declared after it.
\begin{theorem}
Every bounded monotone sequence of real numbers converges.
\end{theorem}
Changing the name of a proof
The proof environment from amsthm prints “Proof.” before its text and adds an end mark automatically. There are two ways to change the heading:
- For one proof, give the heading in square brackets:
\begin{proof}[Solution]. The bracketed text replaces “Proof”. - For the whole document, redefine
\proofnamein the preamble:\renewcommand{\proofname}{Solution}.
If the global change does not take effect, check whether a language package such as babel is resetting the name. Writing Spanish documents with babel shows how babel sets the caption names for one language.
Sets, physics and Greek letters
Some notation comes up in many math documents:
- Number sets and set symbols, such as
\mathbb{R},\inand\subseteq, along with currency symbols. - Bra-ket and physics notation, using
\langleand\rangleor thephysicspackage. - The rho symbol, including
\rho,\varrhoand bold rho.
Where to go next
Each topic in this cluster has a focused guide:
- Set, number and currency symbols
- Matrices and determinants
- Aligning equations with align
- Bra-ket and physics notation
- Using subscripts
- Labeling equations
- The rho symbol
- Packages for mathematics
- Fractions with frac and dfrac
- Sizing brackets and parentheses
- Square roots and nth roots
- Piecewise functions with cases