Math in Markdown
Markdown has no math of its own, but many tools accept formulas written in LaTeX between dollar signs: GitHub, GitLab, Jupyter notebooks, Obsidian and this editor, which draws them with KaTeX. This page covers the LaTeX you need most. Each example shows the Markdown first and the result under it.
Inline and block math
Put a formula between single dollar signs to keep it in the sentence. Put it between double dollar signs on their own lines to show it centered on a line of its own.
The area of a circle is $A = \pi r^2$.
$$
E = mc^2
$$
The area of a circle is A = \pi r^2.
A ```math code block works as a block formula too, as on GitHub.
Superscripts and subscripts
^ raises and _ lowers the next character. Put longer parts in
braces: x^{10}, not x^10.
$x^2$, $x^{10}$, $a_n$, $a_{n+1}$, $e^{-x^2}$
x^2, x^{10}, a_n, a_{n+1}, e^{-x^2}
Fractions and roots
$$
x = \frac{-b \pm \sqrt{b^2 - 4ac}}{2a}
$$
A cube root: $\sqrt[3]{27} = 3$. A small fraction in text: $\tfrac{1}{2}$.
A cube root: \sqrt[3]{27} = 3. A small fraction in text: \tfrac{1}{2}.
Greek letters
Write the name after a backslash. A capital first letter gives the capital form where it differs from the Latin one.
| LaTeX | Letter | LaTeX | Letter | LaTeX | Letter |
|---|---|---|---|---|---|
\alpha |
\alpha | \theta |
\theta | \sigma |
\sigma |
\beta |
\beta | \lambda |
\lambda | \phi |
\phi |
\gamma |
\gamma | \mu |
\mu | \omega |
\omega |
\delta |
\delta | \pi |
\pi | \Delta |
\Delta |
\epsilon |
\epsilon | \rho |
\rho | \Sigma |
\Sigma |
Operators, relations and arrows
| LaTeX | Symbol | LaTeX | Symbol | LaTeX | Symbol |
|---|---|---|---|---|---|
\times |
\times | \le |
\le | \to |
\to |
\cdot |
\cdot | \ge |
\ge | \Rightarrow |
\Rightarrow |
\div |
\div | \ne |
\ne | \iff |
\iff |
\pm |
\pm | \approx |
\approx | \in |
\in |
\infty |
\infty | \equiv |
\equiv | \subseteq |
\subseteq |
Sums, products, limits and integrals
The bounds go in subscripts and superscripts. In block math they are drawn above and below the symbol.
$$
\sum_{i=1}^{n} i = \frac{n(n+1)}{2}
\qquad
\prod_{k=1}^{n} k = n!
$$
$$
\lim_{x \to 0} \frac{\sin x}{x} = 1
\qquad
\int_0^1 x^2 \, dx = \frac{1}{3}
$$
\, adds a thin space (before dx), \quad and
\qquad wider ones. Spaces you type in a formula are ignored.
Brackets that grow
Plain brackets stay small. \left( and \right) grow to fit what
is between them; this works for [ ], \{ \} and
| too.
$$
\left( \frac{a}{b} \right)^2 \quad \text{versus} \quad (\frac{a}{b})^2
$$
Matrices
Separate columns with & and rows with \\.
pmatrix uses round brackets, bmatrix square ones and
vmatrix vertical bars (a determinant).
$$
A = \begin{pmatrix} 1 & 2 \\ 3 & 4 \end{pmatrix}
\qquad
\begin{vmatrix} a & b \\ c & d \end{vmatrix} = ad - bc
$$
Aligned equations
Inside aligned, each & marks the point that lines up, and
\\ starts a new line. Use it for steps of a calculation.
$$
\begin{aligned}
(a + b)^2 &= (a + b)(a + b) \\
&= a^2 + ab + ba + b^2 \\
&= a^2 + 2ab + b^2
\end{aligned}
$$
Cases
$$
|x| =
\begin{cases}
x & \text{if } x \ge 0 \\
-x & \text{if } x < 0
\end{cases}
$$
Text and fonts in formulas
Letters in a formula are set as variables, in italics. Use \text{…} for
words, and the font commands for sets, vectors and other notation.
$\text{speed} = \frac{\text{distance}}{\text{time}}$,
$x \in \mathbb{R}$, $\vec{v}$, $\mathbf{M}$, $\overline{AB}$, $\hat{y}$
\text{speed} = \frac{\text{distance}}{\text{time}}, x \in \mathbb{R}, \vec{v}, \mathbf{M}, \overline{AB}, \hat{y}
Writing a dollar sign
Two dollar signs in one paragraph can be read as a formula. Put a backslash before a dollar sign that means money.
The ticket costs \$5, or \$12 for three.
The ticket costs $5, or $12 for three.
Mistakes and limits
A formula with a mistake, such as a missing brace or an unknown command, stays as LaTeX
source in color, and pointing at it shows what's wrong; the rest of the document still
renders. KaTeX supports most of LaTeX's math, but not whole LaTeX documents or packages.
For safety, commands that add links or load images (\href, \url,
\includegraphics) are turned off. When you export a document as HTML, its
formulas are saved as MathML, which every modern browser can show without extra files.
More guides
- Markdown guide: all the syntax on one page
- Markdown tables: alignment, formatting and merged cells
- Mermaid diagrams: flowcharts and more from text