Markdown math and LaTeX equations

Put LaTeX between single dollar signs for inline math and double dollar signs for a centred equation. Renderers like GitHub use MathJax or KaTeX to draw it.

Einstein: $E = mc^2$

The quadratic formula:

$$
x = \frac{-b \pm \sqrt{b^2 - 4ac}}{2a}
$$

A sum: $\sum_{i=1}^{n} i = \frac{n(n+1)}{2}$

Inline and display math

$…$ renders math inside a sentence; $$…$$ on its own lines renders a centred display equation. GitHub also accepts a fenced block with the language math, and an alternative inline form $`…`$ when the formula contains characters Markdown would otherwise interpret.

Where it works

GitHub (since 2022, using MathJax), GitLab, Obsidian, Jupyter notebooks, Typora, VS Code’s preview, Pandoc and this site’s editor and preview (using KaTeX). Plain CommonMark renderers show the dollar signs literally.

Quick LaTeX reference

  • Superscript and subscript: x^2, a_{ij}
  • Fractions: \frac{a}{b}
  • Roots: \sqrt{x}, \sqrt[3]{x}
  • Greek: \alpha \beta \pi \Omega
  • Sums and integrals: \sum_{i=1}^n, \int_0^\infty
  • Relations: \le \ge \ne \approx
  • Matrices: \begin{pmatrix} a & b \\ c & d \end{pmatrix}

Dollar signs that aren’t math

Prices like “$5 and $10” can be mistaken for an inline formula. Escape them as \$5. Most renderers also require no space right after the opening $.

Exporting math

Math renders in the editor, the viewer and PDF export. For LaTeX output, the Markdown to LaTeX converter keeps the formulas as source.

Quick answers

How do I write equations in Markdown?
Use LaTeX inside dollar signs: $x^2$ inline, or $$…$$ on separate lines for a display equation.
Does GitHub support Markdown math?
Yes, in READMEs, issues, discussions and wikis since May 2022, rendered with MathJax.
Why is my dollar amount rendering as math?
Two dollar signs in one paragraph can form an inline formula. Escape them with a backslash: \$5.