LaTeX Math

Write mathematical formulas with LaTeX and KaTeX

jet-w
4min

LaTeX Math

Write beautiful mathematical formulas using LaTeX syntax, rendered with KaTeX.

Inline Math

Use single $ for inline formulas:

The famous equation $E = mc^2$ changed physics.

The famous equation E=mc2E = mc^2 changed physics.

More examples:

  • Area of circle: A=πr2A = \pi r^2
  • Pythagorean theorem: a2+b2=c2a^2 + b^2 = c^2
  • Quadratic formula: x=b±b24ac2ax = \frac{-b \pm \sqrt{b^2-4ac}}{2a}

Block Math

Use double $$ for centered, block-level formulas:

$$
\int_0^\infty e^{-x^2} dx = \frac{\sqrt{\pi}}{2}
$$
0ex2dx=π2\int_0^\infty e^{-x^2} dx = \frac{\sqrt{\pi}}{2}

Basic Syntax

Superscripts and Subscripts

SyntaxResult
x^2x2x^2
x_ixix_i
x_i^2xi2x_i^2
x^{10}x10x^{10}

Fractions

$$
\frac{a}{b} \quad \frac{1}{2} \quad \frac{x+1}{y-1}
$$
ab12x+1y1\frac{a}{b} \quad \frac{1}{2} \quad \frac{x+1}{y-1}

Square Roots

$$
\sqrt{2} \quad \sqrt{x+y} \quad \sqrt[3]{8}
$$
2x+y83\sqrt{2} \quad \sqrt{x+y} \quad \sqrt[3]{8}

Greek Letters

LetterSyntaxLetterSyntax
α\alpha\alphaβ\beta\beta
γ\gamma\gammaδ\delta\delta
π\pi\piσ\sigma\sigma
θ\theta\thetaλ\lambda\lambda
Ω\Omega\OmegaΣ\Sigma\Sigma

Operators

Sums and Products

$$
\sum_{i=1}^{n} x_i \quad \prod_{i=1}^{n} x_i
$$
i=1nxii=1nxi\sum_{i=1}^{n} x_i \quad \prod_{i=1}^{n} x_i

Integrals

$$
\int_a^b f(x)dx \quad \iint_D f(x,y)dxdy \quad \oint_C f(z)dz
$$
abf(x)dxDf(x,y)dxdyCf(z)dz\int_a^b f(x)dx \quad \iint_D f(x,y)dxdy \quad \oint_C f(z)dz

Limits

$$
\lim_{x \to \infty} \frac{1}{x} = 0
$$
limx1x=0\lim_{x \to \infty} \frac{1}{x} = 0

Matrices

$$
\begin{pmatrix}
a & b \\
c & d
\end{pmatrix}
\quad
\begin{bmatrix}
1 & 2 & 3 \\
4 & 5 & 6
\end{bmatrix}
$$
(abcd)[123456]\begin{pmatrix} a & b \\ c & d \end{pmatrix} \quad \begin{bmatrix} 1 & 2 & 3 \\ 4 & 5 & 6 \end{bmatrix}

Equations

Aligned Equations

$$
\begin{aligned}
(a+b)^2 &= a^2 + 2ab + b^2 \\
(a-b)^2 &= a^2 - 2ab + b^2
\end{aligned}
$$
(a+b)2=a2+2ab+b2(ab)2=a22ab+b2\begin{aligned} (a+b)^2 &= a^2 + 2ab + b^2 \\ (a-b)^2 &= a^2 - 2ab + b^2 \end{aligned}

Cases

$$
f(x) = \begin{cases}
x^2 & \text{if } x \geq 0 \\
-x^2 & \text{if } x < 0
\end{cases}
$$
f(x)={x2if x0x2if x<0f(x) = \begin{cases} x^2 & \text{if } x \geq 0 \\ -x^2 & \text{if } x < 0 \end{cases}

Common Formulas

Statistics

Standard deviation:

σ=1Ni=1N(xiμ)2\sigma = \sqrt{\frac{1}{N}\sum_{i=1}^{N}(x_i - \mu)^2}

Calculus

Taylor series:

ex=n=0xnn!=1+x+x22!+x33!+e^x = \sum_{n=0}^{\infty} \frac{x^n}{n!} = 1 + x + \frac{x^2}{2!} + \frac{x^3}{3!} + \cdots

Physics

Maxwell’s equations:

E=ρε0\nabla \cdot \mathbf{E} = \frac{\rho}{\varepsilon_0}

Tips

Best Practices
  1. Use inline math for simple formulas in text
  2. Use block math for complex or important equations
  3. Add spacing with \quad between elements
  4. Test rendering - KaTeX doesn’t support all LaTeX
Reference

Full KaTeX syntax: katex.org/docs/supported.html


Next: Video Embedding for multimedia content.