> ## Documentation Index
> Fetch the complete documentation index at: https://resources.latex-cloud-studio.com/llms.txt
> Use this file to discover all available pages before exploring further.

# How to Write Beautiful Math in LaTeX - Complete Guide

> Master LaTeX math typesetting with this comprehensive guide. Learn equations, symbols, matrices, and advanced formatting to create publication-quality mathematical documents.

LaTeX produces the world's most beautiful mathematical typography. From simple equations to complex multi-line derivations, this guide teaches you to create publication-quality mathematics.

## Getting Started with Math Mode

LaTeX has two main math modes:

### Inline Math

Use `$...$` for math within text:

```latex theme={null}
The equation $E = mc^2$ revolutionized physics.
```

**Output:** The equation *E = mc²* revolutionized physics.

### Display Math

Use `\[...\]` for centered, standalone equations:

```latex theme={null}
The quadratic formula is:
\[
    x = \frac{-b \pm \sqrt{b^2 - 4ac}}{2a}
\]
```

<Tip>
  **Essential package:** Add `\usepackage{amsmath}` to your preamble for access to advanced math features.
</Tip>

## Essential Setup

```latex theme={null}
\documentclass{article}

% Math packages
\usepackage{amsmath}   % Essential math features
\usepackage{amssymb}   % Extra symbols
\usepackage{amsthm}    % Theorem environments
\usepackage{mathtools} % Extensions to amsmath

\begin{document}
% Your math here
\end{document}
```

***

## Basic Mathematical Notation

### Superscripts and Subscripts

```latex theme={null}
% Superscripts (powers)
$x^2$           % x squared
$x^{10}$        % x to the 10th (use braces for multi-digit)
$e^{i\pi}$      % e to the i*pi

% Subscripts
$x_1$           % x sub 1
$x_{n+1}$       % x sub (n+1)
$a_{ij}$        % a sub ij

% Combined
$x_1^2$         % x sub 1, squared
$a_{i}^{n}$     % a sub i, to the n
${x^2}^3$       % (x²)³ - nested powers
```

### Fractions

```latex theme={null}
% Inline fractions
$\frac{1}{2}$           % Half
$\frac{a+b}{c+d}$       % Complex fraction
$\frac{\partial f}{\partial x}$  % Partial derivative

% Display fractions (larger)
\[
    \frac{a}{b} \quad \dfrac{a}{b}
\]

% Continued fractions
\[
    \cfrac{1}{1+\cfrac{1}{1+\cfrac{1}{1+x}}}
\]

% Small fractions in text
Use $\tfrac{1}{2}$ for compact fractions.
```

### Roots

```latex theme={null}
$\sqrt{x}$          % Square root
$\sqrt[3]{x}$       % Cube root
$\sqrt[n]{x}$       % nth root
$\sqrt{a^2 + b^2}$  % Pythagorean
```

***

## Greek Letters

### Lowercase Greek

| Letter | Command    | Letter | Command    |
| ------ | ---------- | ------ | ---------- |
| α      | `\alpha`   | ν      | `\nu`      |
| β      | `\beta`    | ξ      | `\xi`      |
| γ      | `\gamma`   | π      | `\pi`      |
| δ      | `\delta`   | ρ      | `\rho`     |
| ε      | `\epsilon` | σ      | `\sigma`   |
| ζ      | `\zeta`    | τ      | `\tau`     |
| η      | `\eta`     | υ      | `\upsilon` |
| θ      | `\theta`   | φ      | `\phi`     |
| ι      | `\iota`    | χ      | `\chi`     |
| κ      | `\kappa`   | ψ      | `\psi`     |
| λ      | `\lambda`  | ω      | `\omega`   |
| μ      | `\mu`      |        |            |

### Uppercase Greek

```latex theme={null}
$\Gamma$    $\Delta$    $\Theta$    $\Lambda$
$\Xi$       $\Pi$       $\Sigma$    $\Upsilon$
$\Phi$      $\Psi$      $\Omega$
```

### Variant Forms

```latex theme={null}
$\varepsilon$  % ε variant (common in analysis)
$\varphi$      % φ variant (common in physics)
$\vartheta$    % θ variant
$\varrho$      % ρ variant
$\varsigma$    % ς (final sigma)
```

***

## Operators and Relations

### Arithmetic Operators

```latex theme={null}
$a + b$         % Addition
$a - b$         % Subtraction
$a \times b$    % Multiplication (×)
$a \cdot b$     % Multiplication (·)
$a \div b$      % Division
$a / b$         % Fraction bar
$\pm$           % Plus or minus
$\mp$           % Minus or plus
```

### Comparison Relations

```latex theme={null}
$a = b$         % Equals
$a \neq b$      % Not equal
$a < b$         % Less than
$a > b$         % Greater than
$a \leq b$      % Less than or equal
$a \geq b$      % Greater than or equal
$a \ll b$       % Much less than
$a \gg b$       % Much greater than
$a \approx b$   % Approximately equal
$a \sim b$      % Similar to
$a \equiv b$    % Equivalent/identical
$a \propto b$   % Proportional to
```

### Set Operations

```latex theme={null}
$A \cup B$      % Union
$A \cap B$      % Intersection
$A \setminus B$ % Set difference
$A \subset B$   % Proper subset
$A \subseteq B$ % Subset or equal
$A \supset B$   % Proper superset
$x \in A$       % Element of
$x \notin A$    % Not element of
$\emptyset$     % Empty set
$\varnothing$   % Empty set (variant)
```

### Logic Symbols

```latex theme={null}
$\forall$       % For all
$\exists$       % There exists
$\nexists$      % Does not exist (amssymb)
$\neg$          % Negation
$\land$         % Logical and
$\lor$          % Logical or
$\implies$      % Implies
$\iff$          % If and only if
$\therefore$    % Therefore
$\because$      % Because
```

***

## Large Operators

### Sums and Products

```latex theme={null}
% Sums
$\sum_{i=1}^{n} x_i$                    % Inline sum
\[
    \sum_{i=1}^{n} x_i                  % Display sum
\]

% Products
$\prod_{i=1}^{n} x_i$                   % Inline product
\[
    \prod_{k=0}^{\infty} (1+x^{2^k})    % Display product
\]

% Co-product
$\coprod_{i \in I} G_i$
```

### Integrals

```latex theme={null}
% Single integrals
$\int_a^b f(x) \, dx$                   % Definite integral
$\int f(x) \, dx$                       % Indefinite integral

% Multiple integrals
$\iint_D f(x,y) \, dA$                  % Double integral
$\iiint_V f(x,y,z) \, dV$               % Triple integral
$\oint_C \mathbf{F} \cdot d\mathbf{r}$  % Contour integral

% Display style
\[
    \int_{-\infty}^{\infty} e^{-x^2} dx = \sqrt{\pi}
\]
```

<Tip>
  **Spacing tip:** Use `\,` before `dx` for proper spacing: `\int f(x) \, dx`
</Tip>

### Limits

```latex theme={null}
% Limits
$\lim_{x \to \infty} f(x)$
$\lim_{n \to \infty} a_n$
$\lim_{x \to 0^+} \frac{1}{x}$

% Display style limits
\[
    \lim_{x \to 0} \frac{\sin x}{x} = 1
\]

% Other limit-like operators
$\limsup_{n \to \infty} a_n$
$\liminf_{n \to \infty} a_n$
$\sup_{x \in A} f(x)$
$\inf_{x \in A} f(x)$
$\max_{x} f(x)$
$\min_{x} f(x)$
```

***

## Matrices and Arrays

### Basic Matrices

```latex theme={null}
% Parentheses matrix
\[
    \begin{pmatrix}
        a & b \\
        c & d
    \end{pmatrix}
\]

% Bracket matrix
\[
    \begin{bmatrix}
        1 & 2 & 3 \\
        4 & 5 & 6 \\
        7 & 8 & 9
    \end{bmatrix}
\]

% Determinant
\[
    \begin{vmatrix}
        a & b \\
        c & d
    \end{vmatrix} = ad - bc
\]

% Curly braces
\[
    \begin{Bmatrix}
        x \\ y \\ z
    \end{Bmatrix}
\]
```

### Matrix Types Quick Reference

| Type         | Command   | Delimiters |
| ------------ | --------- | ---------- |
| Plain        | `matrix`  | None       |
| Parentheses  | `pmatrix` | ( )        |
| Brackets     | `bmatrix` | \[ ]       |
| Braces       | `Bmatrix` | { }        |
| Pipes        | `vmatrix` | \| \|      |
| Double pipes | `Vmatrix` | ‖ ‖        |

### Special Matrices

```latex theme={null}
% Identity matrix
\[
    I_3 = \begin{pmatrix}
        1 & 0 & 0 \\
        0 & 1 & 0 \\
        0 & 0 & 1
    \end{pmatrix}
\]

% Diagonal matrix
\[
    \text{diag}(\lambda_1, \lambda_2, \lambda_3) =
    \begin{pmatrix}
        \lambda_1 & 0 & 0 \\
        0 & \lambda_2 & 0 \\
        0 & 0 & \lambda_3
    \end{pmatrix}
\]

% Large matrix with dots
\[
    \begin{pmatrix}
        a_{11} & a_{12} & \cdots & a_{1n} \\
        a_{21} & a_{22} & \cdots & a_{2n} \\
        \vdots & \vdots & \ddots & \vdots \\
        a_{m1} & a_{m2} & \cdots & a_{mn}
    \end{pmatrix}
\]
```

### Inline Matrices

```latex theme={null}
% Small inline matrix
The matrix $\bigl(\begin{smallmatrix} a & b \\ c & d \end{smallmatrix}\bigr)$
is invertible when $ad - bc \neq 0$.
```

***

## Multi-line Equations

### The align Environment

```latex theme={null}
\begin{align}
    f(x) &= x^2 + 2x + 1 \\
         &= (x + 1)^2
\end{align}
```

The `&` marks the alignment point (usually before `=`).

### Multiple Alignment Points

```latex theme={null}
\begin{align}
    x + y &= 10 & 2x - y &= 5 \\
    3x + 2y &= 20 & x + 3y &= 15
\end{align}
```

### Unnumbered Equations

```latex theme={null}
% Single unnumbered
\begin{equation*}
    E = mc^2
\end{equation*}

% Or simply
\[
    E = mc^2
\]

% Align without numbers
\begin{align*}
    a &= b + c \\
    d &= e + f
\end{align*}

% Selectively remove numbers
\begin{align}
    a &= b \nonumber \\
    c &= d
\end{align}
```

### Gathered Equations (Centered)

```latex theme={null}
\begin{gather}
    x + y = z \\
    a + b = c \\
    1 + 2 = 3
\end{gather}
```

### Split Long Equations

```latex theme={null}
\begin{equation}
\begin{split}
    f(x) &= a + b + c + d \\
         &\quad + e + f + g \\
         &\quad + h + i + j
\end{split}
\end{equation}
```

### Cases (Piecewise Functions)

```latex theme={null}
\[
    |x| = \begin{cases}
        x  & \text{if } x \geq 0 \\
        -x & \text{if } x < 0
    \end{cases}
\]

% More complex
\[
    f(x) = \begin{cases}
        0 & x < 0 \\
        \frac{1}{2} & x = 0 \\
        1 & x > 0
    \end{cases}
\]
```

***

## Brackets and Delimiters

### Auto-sizing Delimiters

```latex theme={null}
% Automatic sizing - highly recommended!
\[
    \left( \frac{a}{b} \right)
\]

\[
    \left[ \sum_{i=1}^{n} x_i \right]
\]

\[
    \left\{ \int_0^1 f(x) \, dx \right\}
\]
```

### All Delimiter Types

```latex theme={null}
\left( ... \right)      % Parentheses
\left[ ... \right]      % Square brackets
\left\{ ... \right\}    % Curly braces
\left| ... \right|      % Absolute value
\left\| ... \right\|    % Norm
\left\langle ... \right\rangle  % Angle brackets
\left\lfloor ... \right\rfloor  % Floor
\left\lceil ... \right\rceil    % Ceiling
```

### Manual Sizing

```latex theme={null}
% When auto-sizing isn't quite right
\big( \Big( \bigg( \Bigg(

% Example
\[
    \Bigg( \bigg( \Big( \big( x \big) \Big) \bigg) \Bigg)
\]
```

### Mixed Delimiters

```latex theme={null}
% Half-open interval
\[
    \left[ 0, 1 \right)
\]

% Using \left. and \right. for "invisible" delimiter
\[
    \left. \frac{dy}{dx} \right|_{x=0}
\]
```

***

## Formatting and Spacing

### Text in Math Mode

```latex theme={null}
% Wrong - letters are italicized as variables
$if x > 0 then y = 1$

% Correct
$\text{if } x > 0 \text{ then } y = 1$

% For function names
$\sin(x)$, $\cos(x)$, $\log(x)$, $\ln(x)$
$\max(a,b)$, $\min(a,b)$, $\gcd(a,b)$

% Custom operators
\DeclareMathOperator{\argmax}{arg\,max}
\DeclareMathOperator{\Tr}{Tr}
$\argmax_x f(x)$
$\Tr(A)$
```

### Mathematical Fonts

```latex theme={null}
% Bold
$\mathbf{x}$        % Bold (upright) - for vectors
$\boldsymbol{x}$    % Bold (italic) - for bold greek/symbols

% Calligraphic
$\mathcal{L}$       % Lagrangian, loss function

% Blackboard bold
$\mathbb{R}$        % Real numbers
$\mathbb{C}$        % Complex numbers
$\mathbb{Z}$        % Integers
$\mathbb{N}$        % Natural numbers
$\mathbb{Q}$        % Rationals

% Fraktur
$\mathfrak{g}$      % Lie algebras

% Roman (upright)
$\mathrm{d}x$       % Differential d
```

### Spacing Commands

```latex theme={null}
% Add space
$a \, b$        % Thin space (3/18 em)
$a \: b$        % Medium space (4/18 em)
$a \; b$        % Thick space (5/18 em)
$a \quad b$     % Quad space (1 em)
$a \qquad b$    % Double quad (2 em)

% Remove space
$a \! b$        % Negative thin space

% Common usage
$\int f(x) \, dx$       % Space before dx
$\sqrt{2} \, x$         % Space after root
$dx \, dy \, dz$        % Spaces between differentials
```

***

## Common Patterns and Examples

### Calculus

```latex theme={null}
% Derivatives
\[
    \frac{d}{dx} x^n = nx^{n-1}
\]

\[
    \frac{\partial f}{\partial x} \quad
    \frac{\partial^2 f}{\partial x^2} \quad
    \frac{\partial^2 f}{\partial x \partial y}
\]

% Integrals
\[
    \int_0^\infty e^{-x} \, dx = 1
\]

\[
    \iint_D (x^2 + y^2) \, dA = \int_0^{2\pi} \int_0^R r^3 \, dr \, d\theta
\]

% Taylor series
\[
    e^x = \sum_{n=0}^{\infty} \frac{x^n}{n!} = 1 + x + \frac{x^2}{2!} + \frac{x^3}{3!} + \cdots
\]
```

### Linear Algebra

```latex theme={null}
% Matrix multiplication
\[
    AB = \begin{pmatrix} a & b \\ c & d \end{pmatrix}
         \begin{pmatrix} e & f \\ g & h \end{pmatrix}
       = \begin{pmatrix} ae+bg & af+bh \\ ce+dg & cf+dh \end{pmatrix}
\]

% Eigenvalue equation
\[
    A\mathbf{v} = \lambda\mathbf{v}
\]

% Determinant
\[
    \det(A) = \begin{vmatrix} a & b \\ c & d \end{vmatrix} = ad - bc
\]

% Inner product
\[
    \langle \mathbf{u}, \mathbf{v} \rangle = \sum_{i=1}^{n} u_i v_i
\]
```

### Statistics and Probability

```latex theme={null}
% Expected value and variance
\[
    \mathbb{E}[X] = \int_{-\infty}^{\infty} x f(x) \, dx
\]

\[
    \text{Var}(X) = \mathbb{E}[X^2] - (\mathbb{E}[X])^2
\]

% Normal distribution
\[
    f(x) = \frac{1}{\sigma\sqrt{2\pi}} e^{-\frac{(x-\mu)^2}{2\sigma^2}}
\]

% Probability
\[
    P(A|B) = \frac{P(B|A) P(A)}{P(B)}
\]

% Binomial coefficient
\[
    \binom{n}{k} = \frac{n!}{k!(n-k)!}
\]
```

### Physics

```latex theme={null}
% Maxwell's equations
\begin{align}
    \nabla \cdot \mathbf{E} &= \frac{\rho}{\epsilon_0} \\
    \nabla \cdot \mathbf{B} &= 0 \\
    \nabla \times \mathbf{E} &= -\frac{\partial \mathbf{B}}{\partial t} \\
    \nabla \times \mathbf{B} &= \mu_0 \mathbf{J} + \mu_0 \epsilon_0 \frac{\partial \mathbf{E}}{\partial t}
\end{align}

% Schrödinger equation
\[
    i\hbar \frac{\partial}{\partial t} \Psi = \hat{H} \Psi
\]

% Einstein field equations
\[
    R_{\mu\nu} - \frac{1}{2}R g_{\mu\nu} + \Lambda g_{\mu\nu} = \frac{8\pi G}{c^4} T_{\mu\nu}
\]
```

***

## Advanced Techniques

### Colored Math

```latex theme={null}
\usepackage{xcolor}

\[
    f(x) = \textcolor{blue}{a}x^2 + \textcolor{red}{b}x + \textcolor{green}{c}
\]

% With colored boxes
\[
    \boxed{E = mc^2}
\]

\[
    \colorbox{yellow}{$\displaystyle \int_0^1 x^2 \, dx$}
\]
```

### Annotated Equations

```latex theme={null}
\usepackage{mathtools}

% Overbrace/underbrace with labels
\[
    \overbrace{a + b + c}^{\text{sum}} = \underbrace{x + y}_{\text{total}}
\]

% Arrows with text
\[
    A \xrightarrow{\text{transform}} B
\]

\[
    A \xleftarrow[\text{below}]{\text{above}} B
\]
```

### Numbered Subequations

```latex theme={null}
\begin{subequations}
\begin{align}
    x + y &= 1 \label{eq:first} \\
    x - y &= 0 \label{eq:second}
\end{align}
\end{subequations}

% Produces (1a) and (1b)
```

### Custom Delimiters

```latex theme={null}
\usepackage{mathtools}

% Paired delimiters with auto-sizing
\DeclarePairedDelimiter{\abs}{\lvert}{\rvert}
\DeclarePairedDelimiter{\norm}{\lVert}{\rVert}
\DeclarePairedDelimiter{\inner}{\langle}{\rangle}

% Usage
$\abs{x}$           % |x|
$\abs*{\frac{a}{b}}$  % Auto-sized
$\norm{v}$          % ||v||
$\inner{u,v}$       % <u,v>
```

***

## Quick Reference Table

### Most Used Commands

| Description   | Command          | Output |
| ------------- | ---------------- | ------ |
| Fraction      | `\frac{a}{b}`    | a/b    |
| Square root   | `\sqrt{x}`       | √x     |
| Power         | `x^2`            | x²     |
| Subscript     | `x_i`            | xᵢ     |
| Sum           | `\sum_{i=1}^{n}` | Σ      |
| Integral      | `\int_a^b`       | ∫      |
| Infinity      | `\infty`         | ∞      |
| Not equal     | `\neq`           | ≠      |
| Less/equal    | `\leq`           | ≤      |
| Approximately | `\approx`        | ≈      |
| Times         | `\times`         | ×      |
| Dot product   | `\cdot`          | ·      |
| Arrow         | `\rightarrow`    | →      |
| Partial       | `\partial`       | ∂      |

***

## Common Mistakes to Avoid

### 1. Forgetting Math Mode

```latex theme={null}
% Wrong
The value of x^2 is 4.

% Correct
The value of $x^2$ is 4.
```

### 2. Wrong Function Names

```latex theme={null}
% Wrong (italicized like variables)
$sin(x)$, $log(x)$

% Correct (upright, proper spacing)
$\sin(x)$, $\log(x)$
```

### 3. Missing Braces

```latex theme={null}
% Wrong
$x^10$    % Produces x¹0

% Correct
$x^{10}$  % Produces x¹⁰
```

### 4. Inconsistent Sizing

```latex theme={null}
% Wrong - delimiters don't scale
$(\frac{a}{b})$

% Correct
$\left(\frac{a}{b}\right)$
```

***

## Next Steps

Now that you've mastered LaTeX math, explore:

* **Deep dive**: [Mathematical expressions reference](/learn/latex/mathematics/mathematical-expressions)
* **Practice**: Try our [math-heavy templates](/templates/article)
* **Advanced**: [TikZ for mathematical diagrams](/blog/mastering-tikz-diagrams)
* **Academic**: [LaTeX for academic writing](/blog/latex-academic-writing-guide)

<Info>
  **LaTeX Cloud Studio tip:** Our editor provides real-time math preview, so you can see your equations as you type. Try it at [latex-cloud-studio.com](https://www.latex-cloud-studio.com).
</Info>
