Math and LaTeX in Markdown
Put LaTeX between dollar signs to write a formula: $E = mc^2$ inside a sentence, $$ … $$ on lines of their own for a centered equation. This guide covers the syntax, common notation and where it works.
Quick answer
How do you write math in Markdown?
Wrap LaTeX in single dollar signs for a formula inside a sentence, $a^2 + b^2 = c^2$, and in double dollar signs on their own lines for a displayed equation. Math is an extension: GitHub, Obsidian, Typora, Jupyter and many editors render it with KaTeX or MathJax.
The area of a circle is $A = \pi r^2$.
$$
\int_0^1 x^2 \, dx = \frac{1}{3}
$$Result
The area of a circle is .
Math syntax and examples
Everything between the dollar signs is LaTeX math. These examples cover the notation people need most.
Common notation
Superscripts with ^, subscripts with _, fractions with \frac, roots with \sqrt and Greek letters by name. Group several characters in braces.
$x^2$, $x_i$, $e^{i\pi}$, $\frac{a}{b}$, $\sqrt{2}$, $\alpha + \beta$Result
, , , , ,
Sums, limits and integrals
Limits go in subscripts and superscripts, and display equations show them above and below.
$$
\sum_{i=1}^{n} i = \frac{n(n+1)}{2} \qquad \lim_{x \to 0} \frac{\sin x}{x} = 1
$$Result
Aligned equations
Inside an aligned block, & marks the column to line up and \\ starts a new line.
$$
\begin{aligned}
(a+b)^2 &= a^2 + 2ab + b^2 \\
(a-b)^2 &= a^2 - 2ab + b^2
\end{aligned}
$$Result
Matrices
pmatrix adds parentheses and bmatrix square brackets; & separates columns.
$$
A = \begin{pmatrix} 1 & 2 \\ 3 & 4 \end{pmatrix}
$$Result
A math code block
A fenced block marked math works like $$, which keeps long equations easy to read in the source.
```math
x = \frac{-b \pm \sqrt{b^2 - 4ac}}{2a}
```Result
GitHub's backtick form
GitHub also reads inline math written as dollar signs around backticks, which keeps Markdown symbols inside the formula safe.
$`\sqrt{x_1 * x_2}`$GitHub and GitLab only. Other Markdown apps display this differently, so there is no preview.
Math in popular apps
Math is an extension, so check that your app renders it before you rely on it.
| App | Support | Notes |
|---|---|---|
| GitHub | Supported | $…$, $$…$$ and math code blocks in files, issues and comments. |
| Obsidian | Supported | $…$ and $$…$$, rendered with MathJax. |
| Typora | Supported | $$ blocks; inline $…$ after turning on inline math in the settings. |
| Jupyter | Supported | $…$ and $$…$$ in Markdown cells. |
| Notion | Differs | A formula typed between $$ becomes an inline equation; the /math command adds a block equation. |
| Discord / Slack | Not supported | No math; the LaTeX is shown as typed. |
Questions and answers
Does GitHub support math in Markdown?
$…$ inline, and $$…$$ and ```math blocks as displayed equations, in files, issues and comments.Why does my formula show as plain text?
$ and $$, not the \( \) and \[ \] that ChatGPT often writes.How do I paste formulas from ChatGPT?
\( \) and \[ \] to dollar signs, or replace them yourself.How do I write a dollar sign without starting a formula?
\$5. See escaping characters.Which LaTeX commands work?
Can I number equations?
\tag{1} inside a displayed equation: $$ E = mc^2 \tag{1} $$. KaTeX and MathJax both support it.Do formulas survive a Word or LaTeX export?
Does Notion support LaTeX?
$$x^2$$, for an inline equation, or use the /math command for a block equation.