Skip to main content
โšก Calmops

Mathematical Typesetting in LaTeX: A Comprehensive Guide

LaTeX is the gold standard for mathematical typesetting. This comprehensive guide covers everything from basic equations to complex mathematical structures, theorem environments, and professional formatting.

Getting Started with Math Mode

Inline vs Display Math

LaTeX provides two modes for mathematical content:

% Inline math - embedded in text
This is inline math: $E = mc^2$ and more text.

% Display math - centered, on its own line
\[
E = mc^2
\]

% Alternative display math environments
\begin{equation}
E = mc^2
\end{equation}

Key differences:

  • Inline math uses smaller fonts and fits within text lines
  • Display math is centered and uses larger symbols
  • Equation numbers are only available in display environments

Required Packages

% Essential math packages
\usepackage{amsmath}      % Core math environments
\usepackage{amssymb}      % Additional symbols
\usepackage{amsfonts}     % Additional fonts (blackboard, script)
\usepackage{mathtools}    % Enhancements to amsmath
\usepackage{commath}      % Differential operators

% Optional but recommended
\usepackage{xfrac}        % Slanted fractions
\usepackage{physics}      # Physics notation shortcuts

Basic Mathematical Structures

Fractions

% Simple fractions
\frac{a}{b}               % a/b
\frac{a + b}{c + d}       % (a+b)/(c+d)

% Nested fractions
\frac{\frac{a}{b}}{c}     % (a/b)/c
\frac{a}{\frac{b}{c}}     % a/(b/c)

% Alternative notation (xfrac package)
\sfrac{a}{b}              % Slanted fraction

% Display style fractions
\displaystyle \frac{a}{b} % Larger, display-style
\textstyle \frac{a}{b}    % Smaller, text-style

Roots and Exponents

% Square roots
\sqrt{x}                  % โˆšx
\sqrt{x^2 + y^2}          % โˆš(xยฒ + yยฒ)

% nth roots
\sqrt[n]{x}               % nth root of x

% Nested roots
\sqrt{\sqrt{x}}           % โˆšโˆšx
\sqrt[n]{\sqrt[m]{x}}     % Nested nth and mth roots

% Exponents
x^{2}                     % xยฒ
x^{a+b}                   % x^(a+b)
e^{-x^2}                  % e^(-xยฒ)

% Combined
x^{2n}_{i,j}              % Subscript and superscript

Greek Letters

% Lowercase Greek
\alpha, \beta, \gamma, \delta, \epsilon
\varepsilon, \zeta, \eta, \theta, \vartheta
\iota, \kappa, \lambda, \mu, \nu, \xi
\pi, \varpi, \rho, \varrho, \sigma, \varsigma
\tau, \upsilon, \phi, \varphi, \chi, \psi, \omega

% Uppercase Greek
\Gamma, \Delta, \Theta, \Lambda, \Xi, \Pi
\Sigma, \Upsilon, \Phi, \Psi, \Omega

Mathematical Symbols

% Operators
\pm, \mp                  % ยฑ, โˆ“
\times, \cdot            % ร—, ยท
\oplus, \ominus           % โŠ•, โŠ–
\otimes, \oslash          % โŠ—, โŠ˜
\sum, \prod, \int         % ฮฃ, โˆ, โˆซ
\partial                 % โˆ‚
\nabla                   % โˆ‡

% Relations
=, \neq, \approx, \equiv % =, โ‰ , โ‰ˆ, โ‰ก
<, >, \leq, \geq         % <, >, โ‰ค, โ‰ฅ
\subseteq, \subset      % โІ, โŠ‚
\in, \notin               % โˆˆ, โˆ‰
\sim, \simeq             % โˆผ, โ‰ƒ
\Rightarrow, \Leftarrow  % โ‡’, โ‡
\iff                     % โŸบ

% Arrows
\rightarrow, \leftarrow  % โ†’, โ†
\mapsto                   % โ†ฆ
\Longrightarrow          % โŸน
\leftrightarrow          % โ†”

% Set theory
\cup, \cap                % โˆช, โˆฉ
\cupdot, \capdot          % โŠ, โŠ
\emptyset                 % โˆ…
\mathbb{R}, \mathbb{N}    % โ„, โ„• (requires amsfonts)

% Logic
\forall, \exists         % โˆ€, โˆƒ
\neg, \lor, \land        % ยฌ, โˆจ, โˆง
\top, \bot               % โŠค, โŠฅ

Equation Environments

Single Line Equations

% equation - numbered
\begin{equation}
f(x) = x^2 + 2x + 1
\end{equation}

% equation* - unnumbered (starred)
\begin{equation*}
f(x) = x^2 + 2x + 1
\end{equation*}

% \[ ... \] - unnumbered (shortcut)
\[
f(x) = x^2 + 2x + 1
\]

Multi-line Equations

% gather - multiple equations, separate numbering
\begin{gather}
a = b + c \\
d = e + f
\end{gather}

% gather* - unnumbered
\begin{gather*}
a = b + c \\
d = e + f
\end{gather*}

% align - aligned equations, shared numbering
\begin{align}
a &= b + c \\
d &= e + f
\end{align}

% align - with multiple alignment points
\begin{align}
x^2 + y^2 &= 1 \\
x &= \cos\theta \\
y &= \sin\theta
\end{align}

% split - sub-numbering within equation
\begin{equation}
\begin{aligned}
a &= b + c \\
  &= d + e + f
\end{aligned}
\end{equation}

Cases and Piecewise Functions

% cases environment
f(x) = 
\begin{cases}
x^2 & \text{if } x > 0 \\
0   & \text{if } x = 0 \\
-x^2 & \text{if } x < 0
\end{cases}

% With numcases (requires numcases package)
\begin{numcases}{f(x)=}
x^2 & for $x > 0$
\end{numcases}

% rcases - cases on the right side
\[
\begin{rcases}
a = b \\
c = d
\end{rcases}
\implies e = f
\]

Matrices

% Basic matrix (no delimiters)
\begin{matrix}
a & b \\
c & d
\end{matrix}

% Parentheses
\begin{pmatrix}
a & b \\
c & d
\end{pmatrix}

% Brackets
\begin{bmatrix}
a & b \\
c & d
\end{bmatrix}

% Braces
\begin{Bmatrix}
a & b \\
c & d
\end{Bmatrix}

% Pipes (determinant)
\begin{vmatrix}
a & b \\
c & d
\end{vmatrix}

% Double pipes (norm)
\begin{Vmatrix}
a & b \\
c & d
\end{Vmatrix}

% Small matrix (inline)
$\begin{smallmatrix}
a & b \\ c & d
\end{smallmatrix}$

% With dots
\begin{pmatrix}
a_{11} & a_{12} & \dots \\
a_{21} & a_{22} & \dots \\
\vdots & \vdots & \ddots
\end{pmatrix}

Vectors

% Row vector
\vec{v} = \begin{pmatrix} v_1 & v_2 & v_3 \end{pmatrix}

% Column vector
\vec{v} = \begin{pmatrix} v_1 \\ v_2 \\ v_3 \end{pmatrix}

% Arrow notation
\overrightarrow{AB}

% Bold notation
\mathbf{v}

% Hat notation (unit vectors)
\hat{v}, \hat{i}, \hat{j}, \hat{k}

Theorem Environments

Setting Up Theorems

\usepackage{amsthm}

% Define theorem styles
\theoremstyle{plain}       % Italic, bold header
\theoremstyle{definition} % Roman, bold header
\theoremstyle{remark}     % Roman, italic body

% Define new theorem environments
\newtheorem theorem}{Theorem}
\newtheorem*{theorem*}{Theorem}     % Unnumbered

\newtheoremlemma}{Lemma}
\newtheoremdefinition}{Definition}
\newtheoremproposition}{Proposition}
\newtheoremcorollary}{Corollary}
\newtheoremproof}{Proof}

% Numbering by section
\newtheorem{section}{Section}
\newtheorem{exercise}{Exercise}[section]

Using Theorem Environments

\begin{Theorem}[Pythagorean Theorem]
For a right triangle with legs $a$ and $b$ and hypotenuse $c$,
\[
a^2 + b^2 = c^2
\]
\end{Theorem}

\begin{Definition}
A \emph{prime number} is a natural number greater than 1 
that has no positive divisors other than 1 and itself.
\end{Definition}

\begin{Lemma}
If $n$ is even, then $n^2$ is even.
\end{Lemma}

\begin{Proof}
Suppose $n = 2k$ for some integer $k$. Then
\[
n^2 = (2k)^2 = 4k^2 = 2(2k^2)
\]
which is even. \qed
\end{Proof}

Custom Theorem Styles

\theoremstyle{mystyle}
\newtheoremstyle{break}
  {\topsep}{\topsep}%
  {\itshape}{}%
  {\bfseries}{}%
  {\newline}{}%
\theoremstyle{break}
\newtheorem{breaktheorem}{Theorem}

Calculus and Analysis

Derivatives

% Basic derivatives
\frac{dy}{dx}             % dy/dx
\frac{d^2y}{dx^2}         % dยฒy/dxยฒ

% Partial derivatives
\frac{\partial f}{\partial x}
\frac{\partial^2 f}{\partial x^2}

% With upright 'd' (comdiag package)
\dd{x}, \dd[2]{x}         % dx, dยฒx

% Using physics package
\dv{x}                    % dx
\dv[n]{x}                 % d^n x
\pdv{x}                   % โˆ‚x
\pdv{f}{x}                % โˆ‚f/โˆ‚x

% Leibniz notation
\left.\frac{dy}{dx}\right|_{x=0}

Integrals

% Basic integrals
\int f(x) \,dx            % โˆซ f(x) dx
\int_a^b f(x) \,dx        % โˆซโ‚แต‡ f(x) dx

% Multiple integrals
\iint f(x,y) \,dx\,dy    % โˆฌ f(x,y) dx dy
\iiint f(x,y,z) \,dx\,dy\,dz  % โˆญ
\oint f(z) \,dz          % โˆฎ

% Limits
\lim_{x \to \infty} f(x)
\liminf_{n \to \infty} a_n
\limsup_{n \to \infty} a_n

% Subscripts and superscripts
\int_{\partial M} \omega  % Integral over boundary
\int_{0}^{\infty}         % From 0 to infinity

Series and Sequences

% Summation
\sum_{i=1}^{n} a_i       % ฮฃแตขโ‚Œโ‚โฟ aแตข
\sum_{i \in I} a_i       % Sum over set
\sum_{n=1}^{\infty}      % Infinite sum

% Product
\prod_{i=1}^{n} a_i      % โˆแตขโ‚Œโ‚โฟ aแตข

% Limits
\lim_{n \to \infty} a_n  % Limit
\varliminf_{n} a_n       % Liminf
\varlimsup_{n} a_n       % Limsup

% O-notation
O(n^2)                   % Big O
o(n)                     % Small o
\Theta(n)                % Theta
\Omega(n)                % Omega
\omega(n)                % Small omega

Linear Algebra

Vector Spaces

% Vector notation
\vec{v} \in \mathbb{R}^n
\mathbf{v} \in \mathbf{R}^n

% Span
\operatorname{span}\{v_1, v_2\}
\span\{v_1, v_2\}

% Inner product
\langle u, v \rangle      % โŸจu, vโŸฉ
(u, v)                    % Alternative
\u \cdot \v               % Dot product

% Norm
\|v\|                     % โ€–vโ€–
\lVert v \rVert           % Alternative
\|v\|_2                   % L2 norm
\|v\|_\infty              % Infinity norm

Matrices

% Matrix notation
A \in \mathbb{R}^{m \times n}
B \in \mathbb{R}^{n \times p}

% Matrix operations
A^T                      % Transpose
A^{-1}                   % Inverse
A^*                      % Adjoint/Hermitian
\det(A)                  % Determinant
\operatorname{tr}(A)     % Trace
\operatorname{rank}(A)  % Rank

% Block matrices
\begin{pmatrix}
A & B \\
C & D
\end{pmatrix}

Special Matrices

% Identity matrix
I_n                      % nร—n identity
\mathbf{I}

% Zero matrix
\mathbf{0}

% Diagonal
\operatorname{diag}(a_1, a_2, \dots, a_n)

% Pauli matrices
\sigma_1 = \begin{pmatrix} 0 & 1 \\ 1 & 0 \end{pmatrix}
\sigma_2 = \begin{pmatrix} 0 & -i \\ i & 0 \end{pmatrix}
\sigma_3 = \begin{pmatrix} 1 & 0 \\ 0 & -1 \end{pmatrix}

Number Theory

% Divisibility
a \mid b                 % a divides b
a \nmid b                % a does not divide b

% Congruences
a \equiv b \pmod{n}     % a โ‰ก b (mod n)
a \equiv b \mod n       % Alternative
a \equiv b \equiv c \pmod{n}  % Chained

% GCD and LCM
\gcd(a, b)              % gcd(a,b)
\operatorname{lcm}(a,b) % lcm(a,b)

% Euler's totient
\phi(n)

% Summations over divisors
\sum_{d|n}               % Sum over divisors

Probability and Statistics

% Probability
\Pr(A)                   % P(A)
\Pr(A \mid B)            % P(A|B)

% Expectations
\mathbb{E}[X]            % E[X]
\mathbb{E}[X \mid Y]     % E[X|Y]

% Variance and covariance
\operatorname{Var}(X)   % Var(X)
\operatorname{Cov}(X,Y) % Cov(X,Y)

% Distributions
N(\mu, \sigma^2)        % Normal distribution
\exp(\lambda)           % Exponential
\ Poisson(\lambda)      % Poisson
\Binomial(n, p)         % Binomial

% Probability symbols
\Omega                  % Sample space
\varnothing             % Empty set
\cup, \cap              % Union, intersection

Physics Notation

% Using the physics package
\Bqty{a}                % Bracketed quantity
\quantity{a}           % Full quantity
\abs{x}                % |x|
\norm{x}               % ||x||
\conj{z}               % zฬ„ (complex conjugate)
\Re{z}                 % โ„œ(z)
\Im{z}                 % โ„‘(z)
\grad                  % โˆ‡
\div                   % โˆ‡โ‹…
\curl                  % โˆ‡ร—

% Dirac notation
\ket{\psi}             % |ฯˆโŸฉ
\bra{\psi}             % โŸจฯˆ|
\braket{\psi}{\phi}    % โŸจฯˆ|ฯ†โŸฉ

% Kronecker delta
\delta_{ij}

% Levi-Civita symbol
\epsilon_{ijk}

Custom Commands

% Define custom commands
\newcommand{\R}{\mathbb{R}}
\newcommand{\N}{\mathbb{N}}
\newcommand{\C}{\mathbb{C}}
\newcommand{\Z}{\mathbb{Z}}
\newcommand{\Q}{\mathbb{Q}}

% With arguments
\newcommand{\abs}[1]{\lvert#1\rvert}
\newcommand{\norm}[1]{\lVert#1\rVert}
\newcommand{\dd}[2]{\frac{d#1}{d#2}}

% Over macros
\DeclareMathOperator{\trace}{tr}
\DeclareMathOperator{\rank}{rank}
\DeclareMathOperator{\proj}{proj}
\DeclareMathOperator{\Span}{Span}

Formatting Tips

Spacing in Math Mode

% Thin space (normal)
a b

% Medium space
a \; b

% Thick space
a \; b

% Negative thin space
a \! b

% Quad (1em)
a \quad b

% Qquad (2em)
a \qquad b

Text in Math Mode

% Using \text
f(x) = x^2 \text{ for } x > 0

% Using \mathrm
f(x) = x^2 \mathrm{~for~} x > 0

% Using \operatorname
\operatorname{arcsin}(x)

Equation Numbering

% Subequations
\begin{subequations}
\begin{align}
a &= b \\
c &= d
\end{align}
\end{subequations}

% Custom labels
\begin{equation}
E = mc^2 \tag{*} \label{eq:einstein}
\end{equation}

% References
\eqref{eq:einstein}
\tag\ref{eq:einstein}

Common Examples

Quadratic Formula

\begin{equation}
x = \frac{-b \pm \sqrt{b^2 - 4ac}}{2a}
\end{equation}

Fourier Transform

\begin{equation}
\hat{f}(\xi) = \int_{-\infty}^{\infty} f(x) e^{-2\pi i x \xi} \,dx
\end{equation}

Taylor Series

\begin{equation}
f(x) = f(a) + f'(a)(x-a) + \frac{f''(a)}{2!}(x-a)^2 + \cdots
     = \sum_{n=0}^{\infty} \frac{f^{(n)}(a)}{n!}(x-a)^n
\end{equation}

Euler’s Identity

\begin{equation}
e^{i\pi} + 1 = 0
\end{equation}

Maxwell’s Equations

\begin{align}
\nabla \cdot \mathbf{E} &= \frac{\rho}{\varepsilon_0} \\
\nabla \times \mathbf{E} &= -\frac{\partial \mathbf{B}}{\partial t} \\
\nabla \cdot \mathbf{B} &= 0 \\
\nabla \times \mathbf{B} &= \mu_0\mathbf{J} + \mu_0\varepsilon_0\frac{\partial \mathbf{E}}{\partial t}
\end{align}

External Resources

Comments