How to write math equations in Markdown
Try it — edit the markdown and watch the preview
Result
Markdown has no maths of its own. What it has instead is a convention, borrowed from LaTeX and made popular by GitHub in 2022, that is now supported nearly everywhere maths is written: put LaTeX between dollar signs and let the renderer draw it.
Inline and display
Two forms, and the difference is where the equation sits rather than what it can contain.
Inline: the variance is $\sigma^2$ and the mean is $\mu$.
Display:
$$
\bar{x} = \frac{1}{n}\sum_{i=1}^{n} x_i
$$
Inline maths stays in the flow of the sentence and is set at the size of the surrounding text. Display maths is centred on its own line and is set larger, with sums and integrals given room to breathe. The rule of thumb is the same one prose uses for quotations: if it is short enough to read without stopping, keep it inline.
Put the $$ on lines of their own. Some renderers accept them on the same line
as the equation and some do not, and the version that always works is the one
worth typing.
Dollar signs that are just money
The obvious objection to this syntax is that $ already means something. The
delimiters here are deliberately narrow to keep that from mattering:
- a
$followed by a space never opens an equation, so “costs $ 5” is safe; - a closing
$followed by a digit never closes one, so “$5 and $10” is safe; - an escaped
\$is always literal.
Between them, ordinary prose about prices is left alone. What is not safe is a sentence with exactly two unescaped dollar signs and no spaces after them — “between $5and $10” — which is a shape that essentially does not occur.
What renders it here
The equations on this page are MathML, drawn by your browser rather than by a maths engine. That matters more than it sounds:
- It is text. You can select an equation, copy it, search the page for a variable in it, and a screen reader can read it aloud. An equation rendered as an image is none of those things.
- Nothing is downloaded to display it. No maths fonts, no rendering server — the LaTeX is converted in your tab and your browser draws the result with a font it already has.
- It scales. MathML is vector text, so it stays sharp when printed or exported to PDF.
The conversion runs only when a document actually contains a $, so nothing is
fetched for the documents that have no maths in them, which is most of them.
Where it works, and where it does not
| Where | Inline $…$ | Display $$…$$ |
|---|---|---|
| Here | Yes | Yes |
| GitHub | Yes | Yes |
| GitLab | Yes | Yes |
| Obsidian | Yes | Yes |
| Jupyter and Quarto | Yes | Yes |
| Notion | Its own equation block | Its own equation block |
| Slack, Discord, Teams | No | No |
| A strict CommonMark parser | No | No |
Where it does not work, your LaTeX appears as literal text between dollar signs. That is ugly but it is not lossy — the equation is still readable to anyone who knows LaTeX, which is most people who would be reading it.
What is not supported
The mathematical half of LaTeX is here; the document half is not. \section,
\usepackage, \begin{document}, bibliographies, cross-references and custom
macros all belong to LaTeX as a typesetting system rather than to LaTeX as a
notation for equations.
If the document itself wants to be LaTeX rather than to contain some, that is a different job — Markdown to LaTeX is the page for it.
Common questions
- How do I write a math equation in Markdown?
- Put LaTeX between dollar signs. One dollar on each side keeps the equation inline with your sentence — $E = mc^2$ — and two on each side makes it a display equation on its own line. This is GitHub's syntax, adopted in 2022, and it is what most renderers that support maths now use.
- Is math part of standard Markdown?
- No. CommonMark has no maths and neither does the GitHub Flavored Markdown specification. GitHub added it as a feature, and it is now supported by GitLab, Obsidian, Jupyter, Quarto, and this editor. A renderer that does not know it shows your LaTeX as literal text between dollar signs.
- Will a dollar sign in my prose turn into an equation?
- Not here. A dollar followed by a space is ignored, and a closing dollar followed by a digit is ignored, so "it costs $5 and $10" stays as written. If you want a literal dollar next to something that would otherwise parse, escape it as \$.
- Which LaTeX commands are supported?
- The mathematical subset — fractions, roots, sums, integrals, matrices, Greek letters, accents, operators and the common environments. What is not supported is the document half of LaTeX: sections, packages, bibliographies and anything that needs a preamble. Those belong in a LaTeX document rather than in a Markdown one.
- Why does the equation look different from LaTeX?
- Because it is MathML, drawn by your browser with whatever maths font your system has, rather than an image rendered by a LaTeX engine. It is real text, so it can be selected, copied, searched and read aloud by a screen reader — which an image of an equation cannot be.
- Does the math render on GitHub?
- Yes, in READMEs, issues, pull requests and discussions, using the same dollar-sign syntax. Two differences worth knowing: GitHub also accepts $`…`$ as an inline form, and its display maths must have the $$ on their own lines, which is the safer habit everywhere.