LaTeX is renowned for its superior mathematical typesetting. This guide will take you from basic equations to advanced mathematical expressions.
Fun fact : LaTeX’s math rendering is so good that even Microsoft Word now uses a LaTeX-like syntax for its equation editor!
Why LaTeX for Math?
Compare these approaches to writing the quadratic formula:
Plain text : x = (-b +/- sqrt(b^2 - 4ac)) / 2a
LaTeX result : x = − b ± b 2 − 4 a c 2 a x = \frac{-b \pm \sqrt{b^2 - 4ac}}{2a} x = 2 a − b ± b 2 − 4 a c
The difference is clear – LaTeX produces publication-quality mathematics.
Math Modes
LaTeX has two math modes:
1. Inline Math Mode
For math within text, use $...$
or \(...\)
:
The famous equation $ E = mc^ 2 $ was
discovered by Einstein. We can also
write \( a^ 2 + b^ 2 = c^ 2 \) for the
Pythagorean theorem.
2. Display Math Mode
For centered equations on their own line, use \[...\]
or equation
environment:
The quadratic formula is:
\[ x = \frac{-b \pm \sqrt{b^ 2 - 4 ac}}{ 2 a} \]
For numbered equations, use:
\begin { equation }
\int _ 0 ^ \infty e^{-x^ 2 } dx = \frac{\sqrt{ \pi }}{ 2 }
\end { equation }
Use \[...\]
for important formulas you want to highlight. Use $...$
for variables and simple expressions within sentences.
Basic Math Elements
Superscripts and Subscripts
super-subscripts.tex
Output
% Superscripts with ^
$ x^ 2 $ , $ x^{ 10 } $ , $ x^{n+ 1 } $
% Subscripts with _
$ x_ 1 $ , $ x_{ 10 } $ , $ x_{i,j} $
% Combined
$ x_ 1 ^ 2 $ , $ a_n^{k+ 1 } $
% Chemical formulas
$ \text{H}_ 2 \text{O} $ , $ \text{CO}_ 2 $
Fractions
% Simple fractions
$ \frac{ 1 }{ 2 } $ , $ \frac{a}{b} $
% Nested fractions
$ \frac{ 1 }{ 1 + \frac{ 1 }{ 2 }} $
% Display style in inline math
$ \displaystyle\frac{a+b}{c+d} $
% Alternative notation
$ a/b $ or $ ^a/_b $
Roots
% Square root
$ \sqrt{ 2 } $ , $ \sqrt{x^ 2 + y^ 2 } $
% nth root
$ \sqrt[ 3 ]{ 8 } $ , $ \sqrt[n]{x} $
% Nested roots
$ \sqrt{ 2 + \sqrt{ 3 }} $
Common Math Symbols
Greek Letters
% Lowercase
$ \alpha , \beta , \gamma , \delta , \epsilon $
$ \theta , \lambda , \mu , \pi , \sigma , \phi $
% Uppercase
$ \Gamma , \Delta , \Theta , \Lambda , \Sigma , \Phi $
% Variants
$ \epsilon $ vs $ \varepsilon $
$ \phi $ vs $ \varphi $
Operators and Relations
% Basic operators
$ a + b - c \times d \div e $
% Comparison
$ a < b \leq c = d \geq e > f $
$ a \neq b \approx c \equiv d $
% Set operations
$ A \cup B \cap C \subset D $
$ x \in A, y \notin B $
% Logic
$ p \land q \lor r \implies s $
$ \forall x \exists y $
Arrows
% Basic arrows
$ \rightarrow , \leftarrow , \leftrightarrow $
$ \Rightarrow , \Leftarrow , \Leftrightarrow $
% Long arrows
$ \longrightarrow , \longleftarrow $
% Special arrows
$ \uparrow , \downarrow , \updownarrow $
$ \nearrow , \searrow , \swarrow , \nwarrow $
Functions and Operators
Standard Functions
% Trigonometric
$ \sin \theta , \cos \theta , \tan \theta $
% Logarithms
$ \log x, \ln x, \log_ 2 x $
% Limits
$ \lim_{x \to 0 } \frac{\sin x}{x} = 1 $
% Min/Max
$ \min(a,b), \max(a,b) $
Sums and Products
% Summation
$ \sum _{i= 1 }^{n} i = \frac{n(n+ 1 )}{ 2 } $
% Product
$ \prod _{i= 1 }^{n} i = n! $
% Multiple lines
$ \sum _{\substack{i= 1 \\ i \neq j}}^{n} a_i $
Integrals and Derivatives
% Derivatives
$ f'(x), f''(x), f^{(n)}(x) $
$ \frac{df}{dx}, \frac{d^ 2 f}{dx^ 2 } $
$ \frac{ \partial f}{ \partial x} $
% Integrals
$ \int f(x) \, dx $
$ \int _a^b f(x) \, dx $
$ \iint_D f(x,y) \, dx \, dy $
% Special notation
$ \oint _C F \cdot dr $
Matrices and Arrays
Basic Matrices
% Using pmatrix (parentheses)
$ \begin { pmatrix }
a & b \\
c & d
\end { pmatrix } $
% Using bmatrix (brackets)
$ \begin { bmatrix }
1 & 2 & 3 \\
4 & 5 & 6 \\
7 & 8 & 9
\end { bmatrix } $
% Using vmatrix (determinant)
$ \begin { vmatrix }
a & b \\
c & d
\end { vmatrix } = ad - bc $
Advanced Arrays
% Custom arrays
$ \left[
\begin { array }{cc|c}
1 & 2 & 3 \\
4 & 5 & 6
\end { array }
\right] $
% Cases (piecewise functions)
$ f(x) = \begin { cases }
x^ 2 & \text{if } x \geq 0 \\
-x & \text{if } x < 0
\end { cases } $
Spacing in Math Mode
% Default spacing
$ a b $ vs $ ab $
% Manual spacing
$ a \, b $ % thin space
$ a \: b $ % medium space
$ a \; b $ % thick space
$ a\quad b $ % quad space
$ a\qquad b $ % double quad
% Negative space
$ a \! b $ % negative thin space
Use \,
before differentials in integrals: \int f(x)\,dx
looks better than \int f(x)dx
.
Advanced Features
Theorem Environments
\documentclass { article }
\usepackage { amsthm }
\newtheorem {theorem}{Theorem}
\newtheorem {lemma}{Lemma}
\newtheorem {proof}{Proof}
\begin { document }
\begin { theorem }[Pythagoras]
For a right triangle with legs $ a $ and $ b $
and hypotenuse $ c $ , we have $ a^ 2 + b^ 2 = c^ 2 $ .
\end { theorem }
\begin { proof }
Consider a square with side length $ a + b $ ...
\end { proof }
\end { document }
Aligning Equations
\begin { align }
2 x + 3 y & = 7 \\
x - y & = 1
\end { align }
% Multi-line derivation
\begin { align }
(x + y)^ 2 & = (x + y)(x + y) \\
& = x^ 2 + xy + yx + y^ 2 \\
& = x^ 2 + 2 xy + y^ 2
\end { align }
Common Mistakes to Avoid
1. Forgetting braces for multi-character super/subscripts
Wrong: $x^10$
→ x¹0
Right: $x^{10}$
→ x¹⁰
2. Using text in math mode
Wrong: $x = speed * time$
Right: $x = \text{speed} \times \text{time}$
3. Incorrect fraction syntax
Wrong: $\frac{1/2}$
Right: $\frac{1}{2}$
Math Packages
Essential packages for advanced mathematics:
\usepackage { amsmath } % Advanced math environments
\usepackage { amssymb } % Additional symbols
\usepackage { mathtools } % Enhanced amsmath
\usepackage { physics } % Physics notation
\usepackage { siunitx } % SI units
Practice Exercises
Try typesetting these formulas:
Euler’s Identity : e i π + 1 = 0 e^{i\pi} + 1 = 0 e iπ + 1 = 0
Gaussian Integral : ∫ − ∞ ∞ e − x 2 d x = π \int_{-\infty}^{\infty} e^{-x^2} dx = \sqrt{\pi} ∫ − ∞ ∞ e − x 2 d x = π
Binomial Theorem : ( x + y ) n = ∑ k = 0 n ( n k ) x n − k y k (x+y)^n = \sum_{k=0}^{n} \binom{n}{k} x^{n-k} y^k ( x + y ) n = ∑ k = 0 n ( k n ) x n − k y k
Maxwell’s Equation : ∇ × E = − ∂ B ∂ t \nabla \times \mathbf{E} = -\frac{\partial \mathbf{B}}{\partial t} ∇ × E = − ∂ t ∂ B
Quick Reference
Feature Syntax Example Inline math $...$
$x^2$
Display math \[...\]
\[x^2\]
Fraction \frac{num}{den}
$\frac{a}{b}$
Square root \sqrt{x}
$\sqrt{2}$
Subscript _
$x_1$
Superscript ^
$x^2$
Greek letter \alpha
$\alpha$
Sum \sum
$\sum_{i=1}^n$
Integral \int
$\int_a^b$
Next Steps
Ready to create beautiful mathematical documents? You now have the foundation to typeset any mathematical expression in LaTeX!