LaTeX Math Mode Mastery: From Basic Equations to Advanced Mathematical Typesetting
Mathematics is the language of science, and LaTeX is what typesets it properly. Whether you’re proving theorems or presenting results, getting comfortable with LaTeX math mode is the difference between equations that look thrown together and equations that look published. This guide covers the two math modes, the commands you’ll use daily, and the formatting tricks that separate clean output from cluttered output.
Understanding Math Modes: The Foundation
LaTeX has two primary math modes. Inline math sits inside a paragraph; display math gets its own line. Use the wrong one and your equations either cramp the text or float awkwardly. The distinction is small but it shows.
Inline Math Mode
For expressions that flow within a sentence:
The famous equation $E = mc^2$ revolutionized physics.
% Alternative syntax:
The quadratic formula is \(x = \frac{-b \pm \sqrt{b^2 - 4ac}}{2a}\). Display Math Mode
For equations that deserve their own line:
% Using \[ \] (the recommended form):
\[\int_{-\infty}^{\infty} e^{-x^2} dx = \sqrt{\pi}\]
% Using the equation environment (numbered):
\begin{equation}
\nabla \cdot \mathbf{E} = \frac{\rho}{\epsilon_0}
\end{equation} You may also see $$ ... $$ for display math. It works but predates amsmath and handles spacing slightly worse, so prefer \[ ... \] or equation.
Essential Mathematical Commands
Greek Letters and Symbols
% Lowercase Greek
$\alpha, \beta, \gamma, \delta, \epsilon, \zeta, \eta, \theta$
% Uppercase Greek
$\Gamma, \Delta, \Theta, \Lambda, \Xi, \Pi, \Sigma, \Phi, \Psi, \Omega$
% Common symbols
$\infty, \partial, \nabla, \forall, \exists, \in, \subset, \cup, \cap$ There is no \Alpha command. Uppercase alpha is just A, since it’s identical to the Latin letter. The same goes for uppercase beta, epsilon, and the rest that look like Latin capitals.
Subscripts and Superscripts
% Simple
$x^2, x_i, x^{2n}, x_{i,j}$
% Combined
$x_i^2, x_{\min}^{\max}$
% Pre-scripts
${}_2^4\text{He}$ Braces group multi-character scripts. x^2n gives you x squared followed by n; x^{2n} is what you meant.
Fractions and Binomials
% Basic
$\frac{a}{b}$
% Nested
$\frac{1}{1 + \frac{1}{x}}$
% Sizing: inline fractions render small
Inline: $\frac{a}{b}$ vs forced display: $\dfrac{a}{b}$
% Binomial coefficients (needs amsmath)
$\binom{n}{k} = \frac{n!}{k!(n-k)!}$ Inline fractions shrink to fit the line. When that makes them unreadable, \dfrac forces full display size, or rewrite as a/b.
Advanced Equation Formatting
Multi-line Equations
\begin{align}
f(x) &= (x+a)(x+b) \\
&= x^2 + (a+b)x + ab
\end{align}
% Without alignment, just stacked and numbered:
\begin{gather}
a = b + c \\
x = y - z
\end{gather} The & marks the alignment point. Put it before the = on every line and your equals signs line up down the page.
Cases and Piecewise Functions
f(x) = \begin{cases}
x^2 & \text{if } x \geq 0 \\
-x^2 & \text{if } x < 0
\end{cases} Matrices and Arrays
% Basic matrix
\begin{pmatrix}
a & b \\
c & d
\end{pmatrix}
% Square brackets
\begin{bmatrix}
1 & 2 & 3 \\
4 & 5 & 6
\end{bmatrix}
% Determinant
\begin{vmatrix}
a & b \\
c & d
\end{vmatrix} = ad - bc
% Custom array with a divider
\left[
\begin{array}{c|c}
A & B \\
\hline
C & D
\end{array}
\right] The matrix environments come from amsmath. The suffix picks the delimiter: p for parentheses, b for brackets, v for vertical bars.
Professional Typography Tips
Spacing in Math Mode
LaTeX spaces math for you most of the time. When you need to override it:
$a\!b$ % Negative thin space
$a\,b$ % Thin space
$a\;b$ % Thick space
$a\quad b$ % Quad space
% Common use: thin space before the differential
$\int f(x)\,dx$
$\{x \mid x > 0\}$ The \, before dx is a small thing that readers notice subconsciously. Integrals look right with it and slightly off without.
Operator Styling
% In the preamble (needs amsmath)
\DeclareMathOperator{\sgn}{sgn}
\DeclareMathOperator*{\argmax}{arg\,max}
% Usage
$\sgn(x)$
$\argmax_{x \in X} f(x)$ Declared operators get upright type and correct spacing. The starred form puts limits underneath in display mode, which is what you want for argmax and argmin.
Text in Math Mode
% Wrong: $x > 0 for all x$ (the words render as variables)
% Right:
$x > 0 \text{ for all } x$
$x > 0 \quad \forall x$ Note the spaces inside \text{ for all }. Math mode swallows your spaces, so put them inside the \text argument.
Common Pitfalls and Solutions
The Missing $ Error
“Missing $ inserted” almost always means a math command escaped into text mode. Check for unmatched dollar signs, and for _ or ^ sitting in plain text:
% Wrong: The value x_1 is important
% Right: The value $x_1$ is important Bracket Sizing
Brackets that don’t grow to match their content look amateurish. \left and \right size them automatically:
% Cramped:
$(\frac{a}{b})$
% Right:
$\left(\frac{a}{b}\right)$
% Manual steps when you want control:
$\big( \Big( \bigg( \Bigg($ Alignment
When equations refuse to line up, the fix is usually a misplaced &:
\begin{align}
2x + 3y &= 7 \\
x - y &= 1
\end{align} Advanced Techniques
Custom Commands for Repeated Notation
% In the preamble
\newcommand{\R}{\mathbb{R}}
\newcommand{\E}[1]{\mathbb{E}\left[#1\right]}
\newcommand{\norm}[1]{\left\lVert#1\right\rVert}
% Usage
$f: \R \to \R$
$\E{X} = \mu$
$\norm{x} \leq 1$ Define your notation once. If a reviewer asks you to switch from double bars to single, you change one line instead of fifty.
Theorem Environments
% Needs amsthm
\newtheorem{theorem}{Theorem}
\newtheorem{lemma}[theorem]{Lemma}
\begin{theorem}[Fermat's Last Theorem]
No three positive integers $a$, $b$, and $c$ satisfy
$a^n + b^n = c^n$ for any integer $n > 2$.
\end{theorem} Diagrams with TikZ
% Needs tikz
\begin{tikzpicture}
\draw[->] (-2,0) -- (2,0) node[right] {$x$};
\draw[->] (0,-2) -- (0,2) node[above] {$y$};
\draw[domain=-1.5:1.5,smooth,variable=\x,blue]
plot ({\x},{\x*\x});
\node at (1.5,2) {$y = x^2$};
\end{tikzpicture} TikZ is powerful and slow. For documents with many plots, externalize them so they compile once and cache.
Notation by Field
Physics
\newcommand{\vect}[1]{\boldsymbol{#1}}
$\vect{F} = m\vect{a}$
% Lagrange equation
$\frac{d}{dt}\left(\frac{\partial L}{\partial \dot{q}_i}\right)
- \frac{\partial L}{\partial q_i} = 0$
% Bra-ket
$\langle \psi | \hat{H} | \psi \rangle = E$ Computer Science
$O(n\log n)$, $\Theta(n^2)$, $\Omega(n)$
$\forall x \in S : P(x) \implies Q(x)$ Statistics
$P(A \mid B) = \frac{P(B \mid A)P(A)}{P(B)}$
$X \sim \mathcal{N}(\mu, \sigma^2)$
$\mathrm{Var}(X) = \mathbb{E}[X^2] - (\mathbb{E}[X])^2$ Debugging Math Mode
Four errors cover most of what goes wrong:
| Error | Cause | Fix |
|---|---|---|
| “Missing \$ inserted” | Math outside math mode | Add $ or check for stray _/^ |
| “Extra }, or forgotten \$” | Mismatched braces | Count your braces |
| “Undefined control sequence” | Unknown command | Check spelling or load the package |
| “Double subscript” | Two subscripts on one base | Group with braces: x_{i_j} |
When an equation breaks, comment it out and reintroduce it piece by piece. The point where the error reappears is your culprit.
Collaborating on Mathematical Documents
Co-authoring a math-heavy paper raises a practical problem: keeping notation consistent across people. The fix is a shared preamble.
% project-math.sty
\ProvidesPackage{project-math}
\newcommand{\R}{\mathbb{R}}
\newcommand{\C}{\mathbb{C}}
\newcommand{\prob}[1]{\Pr\left[#1\right]} Everyone imports the same file and uses the same macros, so one author can’t quietly write \mathbb{R} while another writes \mathbf{R}. Label important equations and reference them by label, never by hardcoded number:
\begin{equation}\label{eq:main-result}
E = mc^2
\end{equation}
As shown in \eqref{eq:main-result}... This matters more with multiple authors editing at once. A browser-based editor like inscrive.io handles the live side of this: real-time collaborative editing with no merge conflicts, a rendered preview beside the source so you catch a broken equation as you type, and version history to rewind a formula that went wrong. The free tier (€0, no credit card) covers up to 10 active projects with unlimited collaborators and a 60-second compile window, which is plenty for most papers. It is hosted in the EU on Hetzner servers in Germany and Finland under ISO 27001 certification, and it never uses your documents to train AI models. For deeper collaboration workflows, see LaTeX Collaboration Best Practices.
Good mathematical typography is about clarity, not decoration. Pick consistent notation, space your equations properly, use the right environment for the job, and the math carries itself. For the broader fundamentals, our LaTeX beginner guide covers the rest of the document.
Writing a math-heavy paper with co-authors? Try inscrive.io for real-time collaborative LaTeX with instant equation preview, free to start.




