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.
Rendered Output The famous equation E = m c 2 E = mc^2 E = m c 2 was discovered by Einstein. We can also write a 2 + b 2 = c 2 a^2 + b^2 = c^2 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 }
Rendered Output The quadratic formula is: 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 For numbered equations: \int_0^\infty e^{-x^2} dx = \frac{\sqrt{\pi}}{2} \tag{1}
Use \[...\] for important formulas you want to highlight. Use $...$ for variables and simple expressions within sentences.
Basic Math Elements
Superscripts and Subscripts
% 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 $
Rendered Output Superscripts: x 2 x^2 x 2 , x 10 x^{10} x 10 , x n + 1 x^{n+1} x n + 1 Subscripts: x 1 x_1 x 1 , x 10 x_{10} x 10 , x i , j x_{i,j} x i , j Combined: x 1 2 x_1^2 x 1 2 , a n k + 1 a_n^{k+1} a n k + 1 Chemical formulas: H 2 O \text{H}_2\text{O} H 2 O , CO 2 \text{CO}_2 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 $
Rendered Output Simple fractions: 1 2 \frac{1}{2} 2 1 , a b \frac{a}{b} b a Nested fractions: 1 1 + 1 2 \frac{1}{1 + \frac{1}{2}} 1 + 2 1 1 Display style: a + b c + d \displaystyle\frac{a+b}{c+d} c + d a + b Alternative notation: a / b a/b a / b or a / b ^a/_b 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 }} $
Rendered Output Square root: 2 \sqrt{2} 2 , x 2 + y 2 \sqrt{x^2 + y^2} x 2 + y 2 nth root: 8 3 \sqrt[3]{8} 3 8 , x n \sqrt[n]{x} n x Nested roots: 2 + 3 \sqrt{2 + \sqrt{3}} 2 + 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 $
Rendered Output Lowercase: α , β , γ , δ , ϵ \alpha, \beta, \gamma, \delta, \epsilon α , β , γ , δ , ϵ and θ , λ , μ , π , σ , ϕ \theta, \lambda, \mu, \pi, \sigma, \phi θ , λ , μ , π , σ , ϕ Uppercase: Γ , Δ , Θ , Λ , Σ , Φ \Gamma, \Delta, \Theta, \Lambda, \Sigma, \Phi Γ , Δ , Θ , Λ , Σ , Φ Variants: ϵ \epsilon ϵ vs ε \varepsilon ε and ϕ \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 $
Rendered Output Basic operators: a + b − c × d ÷ e a + b - c \times d \div e a + b − c × d ÷ e Comparison: a < b ≤ c = d ≥ e > f a < b \leq c = d \geq e > f a < b ≤ c = d ≥ e > f and a ≠ b ≈ c ≡ d a \neq b \approx c \equiv d a = b ≈ c ≡ d Set operations: A ∪ B ∩ C ⊂ D A \cup B \cap C \subset D A ∪ B ∩ C ⊂ D and x ∈ A , y ∉ B x \in A, y \notin B x ∈ A , y ∈ / B Logic: p ∧ q ∨ r ⟹ s p \land q \lor r \implies s p ∧ q ∨ r ⟹ s and ∀ x ∃ y \forall x \exists y ∀ x ∃ y
Arrows
% Basic arrows
$ \rightarrow , \leftarrow , \leftrightarrow $
$ \Rightarrow , \Leftarrow , \Leftrightarrow $
% Long arrows
$ \longrightarrow , \longleftarrow $
% Special arrows
$ \uparrow , \downarrow , \updownarrow $
$ \nearrow , \searrow , \swarrow , \nwarrow $
Rendered Output Basic arrows: → , ← , ↔ \rightarrow, \leftarrow, \leftrightarrow → , ← , ↔ and ⇒ , ⇐ , ⇔ \Rightarrow, \Leftarrow, \Leftrightarrow ⇒ , ⇐ , ⇔ Long arrows: ⟶ , ⟵ \longrightarrow, \longleftarrow ⟶ , ⟵ Special arrows: ↑ , ↓ , ↕ \uparrow, \downarrow, \updownarrow ↑ , ↓ , ↕ and ↗ , ↘ , ↙ , ↖ \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) $
Rendered Output Trigonometric: sin θ , cos θ , tan θ \sin\theta, \cos\theta, \tan\theta sin θ , cos θ , tan θ Logarithms: log x , ln x , log 2 x \log x, \ln x, \log_2 x log x , ln x , log 2 x Limits: lim x → 0 sin x x = 1 \displaystyle\lim_{x \to 0} \frac{\sin x}{x} = 1 x → 0 lim x sin x = 1 Min/Max: min ( a , b ) , max ( a , b ) \min(a,b), \max(a,b) 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 $
Rendered Output Summation: ∑ i = 1 n i = n ( n + 1 ) 2 \displaystyle\sum_{i=1}^{n} i = \frac{n(n+1)}{2} i = 1 ∑ n i = 2 n ( n + 1 ) Product: ∏ i = 1 n i = n ! \displaystyle\prod_{i=1}^{n} i = n! i = 1 ∏ n i = n ! Multiple lines: ∑ i = 1 i ≠ j n a i \displaystyle\sum_{\substack{i=1 \\ i \neq j}}^{n} a_i i = 1 i = 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 $
Rendered Output Derivatives: f ′ ( x ) , f ′ ′ ( x ) , f ( n ) ( x ) f'(x), f''(x), f^{(n)}(x) f ′ ( x ) , f ′′ ( x ) , f ( n ) ( x ) and d f d x , d 2 f d x 2 \frac{df}{dx}, \frac{d^2f}{dx^2} d x df , d x 2 d 2 f and ∂ f ∂ x \frac{\partial f}{\partial x} ∂ x ∂ f Integrals: ∫ f ( x ) d x \displaystyle\int f(x)\,dx ∫ f ( x ) d x and ∫ a b f ( x ) d x \displaystyle\int_a^b f(x)\,dx ∫ a b f ( x ) d x and ∬ D f ( x , y ) d x d y \displaystyle\iint_D f(x,y)\,dx\,dy ∬ D f ( x , y ) d x d y Special notation: ∮ C F ⋅ d r \displaystyle\oint_C F \cdot dr ∮ C F ⋅ d r
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 $
Rendered Output pmatrix (parentheses): ( a b c d ) \begin{pmatrix} a & b \\ c & d \end{pmatrix} ( a c b d ) bmatrix (brackets): [ 1 2 3 4 5 6 7 8 9 ] \begin{bmatrix} 1 & 2 & 3 \\ 4 & 5 & 6 \\ 7 & 8 & 9 \end{bmatrix} 1 4 7 2 5 8 3 6 9 vmatrix (determinant): ∣ a b c d ∣ = a d − b c \begin{vmatrix} a & b \\ c & d \end{vmatrix} = ad - bc a c b d = a d − b c
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 } $
Rendered Output Custom arrays: [ 1 2 3 4 5 6 ] \left[ \begin{array}{cc|c} 1 & 2 & 3 \\ 4 & 5 & 6 \end{array} \right] [ 1 4 2 5 3 6 ] Cases (piecewise functions): f ( x ) = { x 2 if x ≥ 0 − x if x < 0 f(x) = \begin{cases} x^2 & \text{if } x \geq 0 \\ -x & \text{if } x < 0 \end{cases} f ( x ) = { x 2 − x if x ≥ 0 if x < 0
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
Rendered Output Default: a b a b ab vs a b ab ab Thin space: a b a\,b a b | Medium space: a b a\:b a b | Thick space: a b a\;b a b Quad space: a b a\quad b a b | Double quad: a b a\qquad b a b Negative space: a b a\!b a b
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!