LaTeX Math Syntax Guide
LaTeX is the standard for typesetting mathematical expressions in academic and technical writing. In Markdown, you can embed LaTeX math using dollar sign delimiters — $...$ for inline math and $$...$$ for display (block) math. MD Viewer renders math using KaTeX, a fast and accurate math typesetting library. This guide covers the most commonly used LaTeX commands.
Inline vs. Display Math
There are two ways to include math in your Markdown documents:
Inline math: The formula $E = mc^2$ appears within text.
Display math (centered on its own line):
$$
\int_0^\infty e^{-x^2} dx = \frac{\sqrt{\pi}}{2}
$$Inline math flows with your text and is useful for referencing variables or short expressions. Display math is centered and given its own vertical space, ideal for important equations you want to stand out.
Basic Arithmetic & Operators
| Description | LaTeX | Output |
|---|---|---|
| Addition | a + b | a + b |
| Subtraction | a - b | a - b |
| Multiplication | a \times b | a × b |
| Division | a \div b | a ÷ b |
| Plus-minus | \pm | ± |
| Not equal | \neq | ≠ |
| Less than or equal | \leq | ≤ |
| Greater than or equal | \geq | ≥ |
| Approximately | \approx | ≈ |
Fractions
Use \frac{numerator}{denominator} to create fractions:
$\frac{1}{2}$ — Simple fraction
$\frac{x+1}{x-1}$ — Expression fraction
$\frac{\partial f}{\partial x}$ — Partial derivative
$\cfrac{1}{1+\cfrac{1}{2}}$ — Continued fractionFor inline fractions that appear too large, you can use \tfrac (text-style fraction) to keep them compact.
Superscripts and Subscripts
Use ^ for superscripts and _ for subscripts. Wrap multi-character expressions in curly braces:
$x^2$ — x squared
$x^{n+1}$ — Multi-character exponent
$a_i$ — Subscript
$a_{i,j}$ — Multi-character subscript
$x_i^2$ — Both subscript and superscript
${}_nC_r$ — Leading subscriptGreek Letters
| Lowercase | LaTeX | Uppercase | LaTeX |
|---|---|---|---|
| α | \alpha | A | A |
| β | \beta | B | B |
| γ | \gamma | Γ | \Gamma |
| δ | \delta | Δ | \Delta |
| ε | \epsilon | E | E |
| θ | \theta | Θ | \Theta |
| λ | \lambda | Λ | \Lambda |
| μ | \mu | M | M |
| π | \pi | Π | \Pi |
| σ | \sigma | Σ | \Sigma |
| φ | \phi | Φ | \Phi |
| ω | \omega | Ω | \Omega |
Sums, Products, and Integrals
$$\sum_{i=1}^{n} x_i$$ — Summation
$$\prod_{i=1}^{n} x_i$$ — Product
$$\int_a^b f(x)\,dx$$ — Definite integral
$$\iint_D f(x,y)\,dA$$ — Double integral
$$\oint_C \vec{F} \cdot d\vec{r}$$ — Line integral
$$\lim_{x \to \infty} f(x)$$ — LimitThe \, adds a thin space before dx, which is standard typographic practice in integrals.
Matrices
Create matrices with different bracket styles using environment commands:
$$\begin{pmatrix} a & b \\ c & d \end{pmatrix}$$ — Round brackets
$$\begin{bmatrix} a & b \\ c & d \end{bmatrix}$$ — Square brackets
$$\begin{vmatrix} a & b \\ c & d \end{vmatrix}$$ — Determinant (pipes)
$$\begin{matrix} a & b \\ c & d \end{matrix}$$ — No bracketsUse & to separate columns and \\ to start a new row. For larger matrices, you can use \cdots, \vdots, and \ddots for ellipses.
Common Functions
LaTeX provides named functions that render in upright (Roman) font rather than italic:
\sin, \cos, \tan, \cot, \sec, \csc
\arcsin, \arccos, \arctan
\ln, \log, \exp
\min, \max, \sup, \inf
\det, \dim, \ker, \gcdExample usage: $\sin^2\theta + \cos^2\theta = 1$
Roots and Radicals
$\sqrt{x}$ — Square root
$\sqrt[3]{x}$ — Cube root
$\sqrt[n]{x}$ — nth root
$\sqrt{x^2 + y^2}$ — Complex expression under radicalBrackets and Delimiters
Use \left and \right for auto-sizing brackets that grow with their content:
$\left( \frac{x}{y} \right)$ — Parentheses
$\left[ \frac{x}{y} \right]$ — Square brackets
$\left\{ \frac{x}{y} \right\}$ — Curly braces
$\left| \frac{x}{y} \right|$ — Absolute value
$\left\langle x, y \right\rangle$ — Angle bracketsAligned Equations
Use the aligned environment for multi-line equations aligned at a specific point (usually the equals sign):
$$
\begin{aligned}
f(x) &= x^2 + 2x + 1 \\
&= (x + 1)^2
\end{aligned}
$$The & marks the alignment point, and \\ creates a new line.
Cases (Piecewise Functions)
$$
f(x) = \begin{cases}
x^2 & \text{if } x \geq 0 \\
-x & \text{if } x < 0
\end{cases}
$$Arrows and Notation
| Symbol | LaTeX | Symbol | LaTeX |
|---|---|---|---|
| → | \rightarrow | ← | \leftarrow |
| ⇒ | \Rightarrow | ⇐ | \Leftarrow |
| ↔ | \leftrightarrow | ⇔ | \Leftrightarrow |
| ↦ | \mapsto | ∞ | \infty |
| ∇ | \nabla | ∂ | \partial |
| ∈ | \in | ∉ | \notin |
| ⊂ | \subset | ⊆ | \subseteq |
| ∪ | \cup | ∩ | \cap |
| ∀ | \forall | ∃ | \exists |
Accents and Decorations
$\hat{x}$ — Hat (unit vector)
$\bar{x}$ — Bar (mean)
$\vec{x}$ — Vector arrow
$\dot{x}$ — Single dot (time derivative)
$\ddot{x}$ — Double dot (acceleration)
$\tilde{x}$ — Tilde
$\overline{AB}$ — Overline (segment)
$\overbrace{x+y}^{\text{sum}}$ — Overbrace with labelCommon Formulas Quick Reference
Quadratic formula:
$$x = \frac{-b \pm \sqrt{b^2 - 4ac}}{2a}$$
Euler's identity:
$$e^{i\pi} + 1 = 0$$
Binomial theorem:
$$(x + y)^n = \sum_{k=0}^{n} \binom{n}{k} x^{n-k} y^k$$
Taylor series:
$$f(x) = \sum_{n=0}^{\infty} \frac{f^{(n)}(a)}{n!}(x-a)^n$$
Gaussian integral:
$$\int_{-\infty}^{\infty} e^{-x^2} dx = \sqrt{\pi}$$Try LaTeX math live — write equations in the MD Viewer editor or use our dedicated LaTeX editor for focused math work.
Open LaTeX Editor