Skip to main content
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±b24ac2ax = \frac{-b \pm \sqrt{b^2 - 4ac}}{2a} 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 \(...\):
inline-math.tex
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=mc2E = mc^2 was discovered by Einstein. We can also write a2+b2=c2a^2 + b^2 = c^2 for the Pythagorean theorem.

2. Display Math Mode

For centered equations on their own line, use \[...\] or equation environment:
display-math.tex
The quadratic formula is:
\[x = \frac{-b \pm \sqrt{b^2 - 4ac}}{2a}\]

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±b24ac2ax = \frac{-b \pm \sqrt{b^2 - 4ac}}{2a}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

super-subscripts.tex
% 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: x2x^2, x10x^{10}, xn+1x^{n+1}Subscripts: x1x_1, x10x_{10}, xi,jx_{i,j}Combined: x12x_1^2, ank+1a_n^{k+1}Chemical formulas: H2O\text{H}_2\text{O}, CO2\text{CO}_2

Fractions

fractions.tex
% 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: 12\frac{1}{2}, ab\frac{a}{b}Nested fractions: 11+12\frac{1}{1 + \frac{1}{2}}Display style: a+bc+d\displaystyle\frac{a+b}{c+d}Alternative notation: a/ba/b or a/b^a/_b

Roots

roots.tex
% 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}, x2+y2\sqrt{x^2 + y^2}nth root: 83\sqrt[3]{8}, xn\sqrt[n]{x}Nested roots: 2+3\sqrt{2 + \sqrt{3}}

Common Math Symbols

Greek Letters

greek-letters.tex
% 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, \phiUppercase: Γ,Δ,Θ,Λ,Σ,Φ\Gamma, \Delta, \Theta, \Lambda, \Sigma, \PhiVariants: ϵ\epsilon vs ε\varepsilon and ϕ\phi vs φ\varphi

Operators and Relations

operators.tex
% 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+bc×d÷ea + b - c \times d \div eComparison: a<bc=de>fa < b \leq c = d \geq e > f and abcda \neq b \approx c \equiv dSet operations: ABCDA \cup B \cap C \subset D and xA,yBx \in A, y \notin BLogic: pqr    sp \land q \lor r \implies s and xy\forall x \exists y

Arrows

arrows.tex
% 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, \LeftrightarrowLong arrows: ,\longrightarrow, \longleftarrowSpecial arrows: ,,\uparrow, \downarrow, \updownarrow and ,,,\nearrow, \searrow, \swarrow, \nwarrow

Functions and Operators

Standard Functions

functions.tex
% 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\thetaLogarithms: logx,lnx,log2x\log x, \ln x, \log_2 xLimits: limx0sinxx=1\displaystyle\lim_{x \to 0} \frac{\sin x}{x} = 1Min/Max: min(a,b),max(a,b)\min(a,b), \max(a,b)

Sums and Products

sums-products.tex
% 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=1ni=n(n+1)2\displaystyle\sum_{i=1}^{n} i = \frac{n(n+1)}{2}Product: i=1ni=n!\displaystyle\prod_{i=1}^{n} i = n!Multiple lines: i=1ijnai\displaystyle\sum_{\substack{i=1 \\ i \neq j}}^{n} a_i

Integrals and Derivatives

calculus.tex
% Derivatives
$f'(x), f''(x), f^{(n)}(x)$
$\frac{df}{dx}, \frac{d^2f}{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) and dfdx,d2fdx2\frac{df}{dx}, \frac{d^2f}{dx^2} and fx\frac{\partial f}{\partial x}Integrals: f(x)dx\displaystyle\int f(x)\,dx and abf(x)dx\displaystyle\int_a^b f(x)\,dx and Df(x,y)dxdy\displaystyle\iint_D f(x,y)\,dx\,dySpecial notation: CFdr\displaystyle\oint_C F \cdot dr

Matrices and Arrays

Basic Matrices

matrices.tex
% 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): (abcd)\begin{pmatrix} a & b \\ c & d \end{pmatrix}bmatrix (brackets): [123456789]\begin{bmatrix} 1 & 2 & 3 \\ 4 & 5 & 6 \\ 7 & 8 & 9 \end{bmatrix}vmatrix (determinant): abcd=adbc\begin{vmatrix} a & b \\ c & d \end{vmatrix} = ad - bc

Advanced Arrays

arrays.tex
% 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: [123456]\left[ \begin{array}{cc|c} 1 & 2 & 3 \\ 4 & 5 & 6 \end{array} \right]Cases (piecewise functions): f(x)={x2if x0xif x<0f(x) = \begin{cases} x^2 & \text{if } x \geq 0 \\ -x & \text{if } x < 0 \end{cases}

Spacing in Math Mode

math-spacing.tex
% 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: aba b vs ababThin space: aba\,b | Medium space: aba\:b | Thick space: a  ba\;bQuad space: aba\quad b | Double quad: aba\qquad bNegative space: a ⁣ba\!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}
2x + 3y &= 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 + 2xy + 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:
  1. Euler’s Identity: eiπ+1=0e^{i\pi} + 1 = 0
  2. Gaussian Integral: ex2dx=π\int_{-\infty}^{\infty} e^{-x^2} dx = \sqrt{\pi}
  3. Binomial Theorem: (x+y)n=k=0n(nk)xnkyk(x+y)^n = \sum_{k=0}^{n} \binom{n}{k} x^{n-k} y^k
  4. Maxwell’s Equation: ×E=Bt\nabla \times \mathbf{E} = -\frac{\partial \mathbf{B}}{\partial t}

Quick Reference

FeatureSyntaxExample
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!