Mathematics is the reason most people learn LaTeX. This chapter covers everything you need for undergraduate homework and exams: inline and display math, fractions, roots, Greek letters, operators, delimiters, and the spacing rules that separate amateur typesetting from professional.
Math Modes
LaTeX has two math modes:
Inline Math
Inline math appears within a paragraph. Surround it with dollar signs or <!--M5-->:
The equation $E = mc^2$
relates energy and mass.
Alternatively: <!--M6-->.
The equation \( E = mc^2 \) relates energy and mass.
Alternatively: \( E = mc^2 \).
Tip: Both
$...$and<!--M9-->produce identical output. The<!--M10-->form is recommended by the LaTeX project because it’s easier to match paired delimiters. In practice, most people use dollar signs because they’re faster to type. Pick one and be consistent.
Display Math
Display math is centered on its own line. Use <!--M86--> or the equation environment:
The quadratic formula:
<!--M87-->
Numbered version:
\begin{equation}
x = \frac{-b \pm \sqrt{b^2-4ac}}{2a}
\end{equation}
The quadratic formula:
$$ x = \frac{-b \pm \sqrt{b^2 – 4ac}}{2a} $$
The numbered version produces the same formula with an equation number in the right margin.
Warning: Never use
<!--M1-->for display math. It’s plain TeX syntax that produces inconsistent spacing and breaks several LaTeX features. Always use<!--M88-->orequation.
Superscripts and Subscripts
$x^2$, $x_i$, $x^2_i$
$x^{n+1}$, $a_{ij}$
$x^{2^n}$ (nested)
${}_nC_r = \binom{n}{r}$
\( x^2 \), \( x_i \), \( x^2_i \) \( x^{n+1} \), \( a_{ij} \) \( x^{2^n} \) (nested) \( {}_nC_r = \binom{n}{r} \)
Warning: For multi-character superscripts or subscripts, always use braces:
x^{n+1}notx^n+1. Without braces, only the first character is raised: \( x^n+1 \) vs. \( x^{n+1} \).
Fractions
LaTeX provides three fraction commands:
% Standard (auto-sizing)
$\frac{a}{b}$ inline,
<!--M89--> display
% Display-style (always large)
$\dfrac{a}{b}$ forces
full size inline
% Text-style (always small)
<!--M90--> forces
small size in display
\( \frac{a}{b} \) inline, $$ \frac{a}{b} $$
display
\( \dfrac{a}{b} \) forces full size inline $$ \tfrac{a}{b} $$
forces small size in display
Tip: Use
\dfracwhen an inline fraction is too small to read (common with nested fractions). Use\tfracin display math when you want a compact fraction that doesn’t dominate the line.
For continued fractions, use \cfrac:
<!--M91-->
$$ \cfrac{1}{1 + \cfrac{1}{1 + \cfrac{1}{1 + \cdots}}} $$
Roots
$\sqrt{2}$
$\sqrt{x^2 + y^2}$
$\sqrt[3]{27} = 3$
$\sqrt[n]{a}$
\( \sqrt{2} \) \( \sqrt{x^2 + y^2} \) \( \sqrt[3]{27} = 3 \) \( \sqrt[n]{a} \)
Greek Letters
Greek letters are commands preceded by a backslash:
-
Lower:
\alpha| Output: \( \alpha \) | Upper:\Alpha| Output: \( A \) -
Lower:
\beta| Output: \( \beta \) | Upper:\Beta| Output: \( B \) -
Lower:
\gamma| Output: \( \gamma \) | Upper:\Gamma| Output: \( \Gamma \) -
Lower:
\delta| Output: \( \delta \) | Upper:\Delta| Output: \( \Delta \) -
Lower:
\epsilon| Output: \( \epsilon \) | Upper:\Epsilon| Output: \( E \) -
Lower:
\zeta| Output: \( \zeta \) | Upper:\Zeta| Output: \( Z \) -
Lower:
\eta| Output: \( \eta \) | Upper:\Eta| Output: \( H \) -
Lower:
\theta| Output: \( \theta \) | Upper:\Theta| Output: \( \Theta \) -
Lower:
\iota| Output: \( \iota \) | Upper:\Iota| Output: \( I \) -
Lower:
\kappa| Output: \( \kappa \) | Upper:\Kappa| Output: \( K \) -
Lower:
\lambda| Output: \( \lambda \) | Upper:\Lambda| Output: \( \Lambda \) -
Lower:
\mu| Output: \( \mu \) | Upper:\Mu| Output: \( M \) -
Lower:
\nu| Output: \( \nu \) | Upper:\Nu| Output: \( N \) -
Lower:
\xi| Output: \( \xi \) | Upper:\Xi| Output: \( \Xi \) -
Lower:
\pi| Output: \( \pi \) | Upper:\Pi| Output: \( \Pi \) -
Lower:
\rho| Output: \( \rho \) | Upper:\Rho| Output: \( P \) -
Lower:
\sigma| Output: \( \sigma \) | Upper:\Sigma| Output: \( \Sigma \) -
Lower:
\tau| Output: \( \tau \) | Upper:\Tau| Output: \( T \) -
Lower:
\phi| Output: \( \phi \) | Upper:\Phi| Output: \( \Phi \) -
Lower:
\chi| Output: \( \chi \) | Upper:\Chi| Output: \( X \) -
Lower:
\psi| Output: \( \psi \) | Upper:\Psi| Output: \( \Psi \) -
Lower:
\omega| Output: \( \omega \) | Upper:\Omega| Output: \( \Omega \)
Several letters have variant forms: -
Standard:
\epsilon| Output: \( \epsilon \) | Variant:\varepsilon| Output: \( \varepsilon \) -
Standard:
\theta| Output: \( \theta \) | Variant:\vartheta| Output: \( \vartheta \) -
Standard:
\pi| Output: \( \pi \) | Variant:\varpi| Output: \( \varpi \) -
Standard:
\rho| Output: \( \rho \) | Variant:\varrho| Output: \( \varrho \) -
Standard:
\sigma| Output: \( \sigma \) | Variant:\varsigma| Output: \( \varsigma \) -
Standard:
\phi| Output: \( \phi \) | Variant:\varphi| Output: \( \varphi \)Tip: Most mathematicians and physicists prefer
\varepsilon(\( \varepsilon \)) over\epsilon(\( \epsilon \)), and\varphi(\( \varphi \)) over\phi(\( \phi \)). Check your field’s conventions.