LaTeX Math Mode Explained: Inline vs. Display ($ vs $$ vs \[ \])
Master LaTeX math mode: learn the difference between inline and display math, why $$ is deprecated in modern LaTeX, and how to align multi-line equations.
When authoring scientific documents, academic papers, or engineering homework, mathematical typesetting is where LaTeX truly shines. However, newcomers frequently stumble over its distinct operational states, inconsistent legacy syntax, and misplaced delimiters.
Unlike standard word processors, LaTeX operates in two fundamentally different typographic regimes: Text Mode and Math Mode. Understanding how these modes behave—and mastering the difference between inline and display equations—is the key to producing flawless mathematical typography.
1. Why LaTeX Has a Dedicated “Math Mode”
In standard Text Mode, LaTeX prioritizes linguistic typography: words are hyphenated according to grammatical rules, characters are spaced using font metrics, ligatures (like “fi” and “fl”) are substituted automatically, and multiple spaces in source code collapse into a single space.
When you switch into Math Mode, LaTeX activates Donald Knuth’s specialized mathematical typesetting engine:
- Automatic Italicization: Letters are treated as individual mathematical variables ($x$, $y$, $\alpha$), typesetting them in math italics rather than text italics.
- Ignored Source Whitespace: Spaces typed in your
.texsource file have zero effect on rendered output. TeX calculates spacing algorithmically based on character classifications: ordinary symbols, binary operators ($+$), relations ($=$), and punctuation. - Special Operators and Delimiters: Subscripts (
_), superscripts (^), fractions (\frac), radicals (\sqrt), and Greek symbols become directly operational.
% In Text Mode: spaces matter, letters are upright
The variable x equals 5.
% In Math Mode: spaces are ignored, variables are italicized
$The variable x equals 5$ % Warning: renders as "Thevariablexequals5" with math spacing!
2. Inline Math Mode: $...$ and \(...\)
Inline math embeds mathematical formulas directly within running sentences without interrupting paragraph flow or introducing vertical line breaks.
Basic Inline Usage
Wrap your expression in either single dollar signs $...$ or the official LaTeX2e delimiters \( ... \):
Consider a quadratic polynomial $f(x) = ax^2 + bx + c$, where $a \neq 0$.
The discriminant is given by $\Delta = b^2 - 4ac$.
In the compiled output, the formula flows naturally alongside adjacent text, maintaining uniform line height.
$...$ vs. \(...\): Which Should You Use?
While $ ... $ is universal across TeX engines due to its brevity, the official LaTeX syntax is \( ... \):
- Clearer Error Diagnostics: Because
$is symmetric, forgetting to close a dollar sign can cause LaTeX to interpret the rest of your document as math, triggering confusing cascade errors hundreds of lines downstream. The asymmetric\(and\)syntax enables compilers to pinpoint unmatched delimiters immediately. - Compatibility: Modern LaTeX linters, syntax highlighters, and accessibility screen-readers parse
\( ... \)with greater structural reliability.
Inline Math Caveats: Fractions & Large Operators
To prevent inline equations from distorting regular line spacing, LaTeX automatically scales down fractions and relocates operator limits:
- Fraction Sizing: In inline mode,
\frac{a}{b}renders in a compact format. If you strictly require full-size display fractions, use\dfrac{a}{b}(from theamsmathpackage) or prefix the expression with\displaystyle:
% Compact inline fraction (default):
The ratio is $\frac{x + y}{z}$.
% Full display fraction inside paragraph (use cautiously):
The ratio is $\dfrac{x + y}{z}$.
- Summations & Integrals: In inline mode, indices for
\sum_{i=1}^nare placed as subscripts and superscripts beside the symbol ($\sum_{i=1}^n$) rather than stacked above and below.
Embedding Regular Text Inside Formulas
If you need plain English words or units inside math mode, never write raw letters. TeX will interpret them as a product of single-letter variables:
% Incorrect: renders with variable spacing and italics
$Force = mass \times acceleration$
% Correct: use \text{...} from the amsmath package
$\text{Force} = \text{mass} \times \text{acceleration}$
3. Display Math Mode: Why You Must Never Use $$...$$ in LaTeX
Display math mode pulls your equation out of the paragraph stream, centers it horizontally, and renders it as an isolated typographic block with dedicated vertical breathing room.
The Pitfall: $$ ... $$ Is Deprecated
A widespread habit among self-taught LaTeX users is enclosing standalone equations between double dollar signs:
% AVOID THIS IN MODERN LATEX:
$$ E = mc^2 $$
While $$ was standard in 1982 Plain TeX, it is deprecated in standard LaTeX2e and must not be used. Here is why:
- Ignores Class Options: Document classes often feature layout options such as
fleqn(flush-left equations, standard in many physics journals). Delimiters like\[ ... \]automatically align equations to the left whenfleqnis active;$$ ... $$ignores this flag and stubbornly centers the formula. - Corrupted Vertical Spacing:
$$ ... $$directly bypasses LaTeX’s internal spacing registers (\abovedisplayskipand\belowdisplayskip), often causing uneven gaps around paragraph boundaries, list environments, and section headings. - Breaks AMS Tools: Modern packages like
amsmathand equation cross-referencing tools cannot hook cleanly into raw$$primitives.
The Modern Standard: \[ ... \]
The clean, standardized syntax for unnumbered display math is \[ ... \]:
The Gaussian probability density function is defined as:
\[
f(x) = \frac{1}{\sigma \sqrt{2\pi}} \exp\left( -\frac{(x - \mu)^2}{2\sigma^2} \right)
\]
where $\mu$ represents the mean and $\sigma^2$ is the variance.
4. Numbered Equations & Cross-Referencing
For academic papers, research theses, and technical publications, important equations must be numbered and cited in the prose.
The equation Environment
Use the equation environment to automatically assign a sequential equation number:
\begin{equation}
\oint_{\partial \Omega} \mathbf{E} \cdot d\mathbf{l} = -\frac{\partial}{\partial t} \iint_{\Omega} \mathbf{B} \cdot d\mathbf{A}
\label{eq:faraday}
\end{equation}
Referencing Equations in Prose
Always label your equations with descriptive tags (\label{eq:...}). When referring to them in text, use \eqref{...} from amsmath:
% Good practice: \eqref automatically adds parentheses "(1)"
Faraday's law of induction, given in \eqref{eq:faraday}, describes how a time-varying magnetic field induces an electromotive force.
% Avoid manual formatting:
Faraday's law of induction, given in Eq.~(\ref{eq:faraday})...
The \eqref command guarantees that equation references consistently match publisher citation styles without manual parentheses.
5. Multi-Line Alignment with amsmath
A frequent limitation of the basic equation environment is that it only supports a single line. Inserting line breaks (\\) inside \begin{equation} throws an immediate compilation error.
To typeset multi-line mathematical proofs or derivations, use the align (numbered) or align* (unnumbered) environment from \usepackage{amsmath}.
How Alignment Works
- Anchor Point (
&): Place an ampersand immediately preceding the symbol you want horizontally aligned (most commonly the equals sign&=). - Line Break (
\\): End each line with\\. - Golden Rule: Never place
\\on the final line of analignenvironment. Doing so generates an empty extra row and a phantom equation number.
Step-by-Step Derivation Example
\begin{align*}
f(x) &= (2x + 3)(x^2 - 4x + 1) \\
&= 2x(x^2 - 4x + 1) + 3(x^2 - 4x + 1) \\
&= 2x^3 - 8x^2 + 2x + 3x^2 - 12x + 3 \\
&= 2x^3 - 5x^2 - 10x + 3
\end{align*}
Each row is neatly aligned at the = character, producing professional mathematical layout suitable for publication.
6. Math Mode Delimiter Cheat Sheet
Use this reference table to choose the appropriate syntax for every mathematical context:
| Delimiter Syntax | Mode | Numbered? | Recommended Use Case | Status |
|---|---|---|---|---|
$ ... $ |
Inline | No | Quick inline expressions and variables | Standard TeX |
\( ... \) |
Inline | No | Running prose formulas with robust error tracking | Official LaTeX2e |
\[ ... \] |
Display | No | Centered, unnumbered standalone formulas | Recommended Standard |
$$ ... $$ |
Display | No | Centered standalone math | Deprecated (Do not use) |
\begin{equation} |
Display | Yes | Formal equations cited elsewhere in document | Standard |
\begin{align*} |
Display | No | Multi-step mathematical derivations | Standard (amsmath) |
\begin{align} |
Display | Yes | Multi-step derivations with per-line numbering | Standard (amsmath) |
7. Pro Tips for Flawless Math Typesetting
- Include Grammatical Punctuation Inside Math: Display equations are grammatically part of your sentences. If an equation terminates a sentence, place the period inside the display environment:
The relationship between energy and mass is \[ E = mc^2. \] - Auto-Scale Delimiters with
\leftand\right: Standard parentheses do not scale to match tall expressions like matrices or fractions. Pair opening and closing brackets with\left(and\right):% Parentheses automatically stretch to encapsulate the fraction: \[ \left( \frac{x^2 + 1}{y^2 - 1} \right)^n \] - Use Named Roman Operators: Never type
$sin(x)$or$log(x)$as raw letters. TeX will treat them as multiplied variables ($s \cdot i \cdot n \cdot x$). Always use standard backslash functions:- Trigonometric:
\sin,\cos,\tan,\sec,\csc,\cot - Calculus & Limits:
\lim_{x \to 0},\max,\min,\sup,\inf - Logarithms:
\log,\ln,\exp
- Trigonometric:
- Draft and Verify in Live Equation Studios: Complex equations with nested fractions, subscripts, and matrices are easiest to build with immediate feedback. Use our interactive LaTeX Equation Editor to preview equations in real time with sub-5ms latency and export production-ready MathML and vector SVG assets in one click.