Skip to main content

How to Write Math in Markdown

LaTeX equations between dollar signs, GitHub's two extra forms, a symbol cheat sheet, and a table of which platforms render math and which print the dollar signs.

Short answer

Write $x^2$ for inline math and put display math between $$ lines. That works on GitHub, GitLab, Obsidian, VS Code, Jupyter, Typora and Pandoc. Notion uses $$...$$ for inline. Discord, Slack and Reddit render no math at all.

Inline Math

Put LaTeX between single dollar signs to set math inside a sentence. Keep the dollar signs tight against the formula: most parsers will not start math on $ with a space after it.

Inline formula
The area of a circle is $\pi r^2$.
Rendered
The area of a circle is πr2.
Exponents in a sentence
By Pythagoras, $a^2 + b^2 = c^2$.
Rendered
By Pythagoras, a2+b2=c2.

Block (Display) Math

Double dollar signs on their own lines make a centered display equation. Fractions are full size and the limits of sums and integrals move above and below the symbol. Do not leave a blank line inside the block.

Quadratic formula
$$
x = \frac{-b \pm \sqrt{b^2 - 4ac}}{2a}
$$
Rendered
x=−b±b2−4ac2a
Sum with limits
$$
\sum_{n=1}^{\infty} \frac{1}{n^2} = \frac{\pi^2}{6}
$$
Rendered
∑n=1∞1n2=π26
Integral
$$
\int_0^1 x^2 \, dx = \frac{1}{3}
$$
Rendered
∫01x2dx=13
Matrix
$$
A = \begin{pmatrix} a & b \\ c & d \end{pmatrix}
$$
Rendered
A=(abcd)
Multi-line, aligned on =
$$
\begin{aligned}
(a+b)^2 &= (a+b)(a+b) \\
        &= a^2 + 2ab + b^2
\end{aligned}
$$
Rendered
(a+b)2=(a+b)(a+b)=a2+2ab+b2

GitHub Math

GitHub renders math with MathJax everywhere Markdown renders: README files, issues, pull requests, discussions and wikis. On top of the dollar-sign forms it adds two that cannot collide with Markdown, which matters when a formula contains * or _.

Inline, backtick formGitHub, GitLab
The theorem says $`a^2 + b^2 = c^2`$.
Rendered
The theorem says a2+b2=c2.
Display, math code blockGitHub, GitLab
```math
\sum_{i=1}^{n} i = \frac{n(n+1)}{2}
```
Rendered
∑i=1ni=n(n+1)2
Literal dollar signsGitHub
This costs <span>$</span>4 and the root is $`\sqrt{\$4}`$.
Rendered
This costs $4 and the root is $4.
The dollar-sign trap. Two prices in one paragraph, like $5 and $10, can pair up and render as math. GitHub's fix is <span>$</span> outside math and \$ inside it. Math also works as a text color workaround on GitHub: $\color{red}{\text{red}}$. More GFM detail is on the GitHub Markdown guide.

LaTeX Math Syntax Cheat Sheet

Everything between the dollar signs is LaTeX. These commands work in both MathJax and KaTeX, so they are safe on every platform in the support table.

LaTeX math syntax for common structures
You wantWriteNote
Superscript / powerx^2 x^{10}Braces for more than one character
Subscripta_1 a_{ij}Combine: x_i^2
Fraction\frac{a}{b}\dfrac forces display size inline
Square / nth root\sqrt{x} \sqrt[3]{x}
Sum\sum_{i=1}^{n} iLimits sit above and below in display math
Product\prod_{i=1}^{n} x_i
Integral\int_0^1 x^2 \, dx\, adds the thin space before dx
Limit\lim_{x \to 0} f(x)
Text inside math\text{if } x > 0Keeps words upright with real spaces
Upright letters\mathrm{H_2O}For units and chemistry
Bold vector\mathbf{v}
Growing brackets\left( \frac{a}{b} \right)Brackets stretch to fit the content
Matrix\begin{pmatrix} a & b \\ c & d \end{pmatrix}bmatrix for square brackets
Cases\begin{cases} 1 & x > 0 \\ 0 & \text{else} \end{cases}Piecewise functions
Aligned lines\begin{aligned} a &= b \\ &= c \end{aligned}aligned works in MathJax and KaTeX
Color\color{red}{x}Works on GitHub, a common text-color hack

Markdown Math Symbols

The LaTeX command goes inside the dollar signs: $\alpha \leq \beta$. Capitalize a Greek command for the uppercase letter where one exists.

Greek letters

LaTeX commands for Greek letters
CommandSymbol
\alphaα
\betaβ
\gamma \Gammaγ Γ
\delta \Deltaδ Δ
\epsilon \varepsilonϵ ε
\theta \Thetaθ Θ
\lambda \Lambdaλ Λ
\muμ
\pi \Piπ Π
\sigma \Sigmaσ Σ
\phi \varphiϕ φ
\omega \Omegaω Ω

Operators

LaTeX commands for math operators
CommandSymbol
\pm \mp± ∓
\times×
\div÷
\cdot⋅
\sqrt{x}√x
\sum∑
\prod∏
\int \iint \oint∫ ∬ ∮
\partial∂
\nabla∇
\infty∞
\circ∘

Relations

LaTeX commands for relation symbols
CommandSymbol
\neq≠
\leq \geq≤ ≥
\ll \gg≪ ≫
\approx≈
\equiv≡
\sim \simeq∼ ≃
\propto∝
\in \notin∈ ∉
\subset \subseteq⊂ ⊆
\cup \cap∪ ∩
\forall \exists∀ ∃
\emptyset∅

Arrows and logic

LaTeX commands for arrows and logic symbols
CommandSymbol
\to \rightarrow→
\leftarrow←
\leftrightarrow↔
\Rightarrow⇒
\Leftrightarrow⇔
\implies \iff⟹ ⟺
\mapsto↦
\uparrow \downarrow↑ ↓
\land \lor∧ ∨
\neg¬
\therefore∴
\ldots \cdots… ⋯

Platform Support

The dollar-sign convention is shared, but not universal. Check the inline form in particular before you paste math between platforms.

Math delimiters and rendering engine by platform
PlatformInlineBlockNotes
GitHub$...$ or $`...`$$$...$$ or ```mathMathJax. On in READMEs, issues, PRs, discussions, wikis.
GitLab$`...`$ or $...$$$...$$ or ```mathKaTeX. Only the first 1,000 inline expressions render, except in wikis and repository files.
Obsidian$...$$$...$$MathJax. On by default.
VS Code preview$...$$$...$$KaTeX, built in. Toggle with markdown.math.enabled.
Jupyter$...$$$...$$ or \begin{equation}MathJax in Markdown cells.
Notion$$...$$ or Cmd/Ctrl+Shift+E/math blockKaTeX. Note the doubled dollars for inline.
Typora$...$$$ then EnterMathJax. Inline math is a setting: Preferences > Markdown.
Pandoc / Quarto$...$$$...$$No space after the opening $, no digit after the closing $.
Hugo\(...\)\[...\] or $$...$$Off until you enable Goldmark passthrough and load MathJax or KaTeX.
Discord, Slack, RedditNoneNoneNo math rendering. Use Unicode symbols or an image.

Platform specifics live in the Obsidian, Notion and VS Code guides. AI chat apps such as ChatGPT and Claude render LaTeX in their replies, but neither documents which delimiters it accepts; Markdown for AI covers how they format output.

Common Mistakes

Almost every broken equation is one of these.

Broken

$ x^2 $

Fixed

$x^2$
Pandoc, Quarto, Typora and many other parsers refuse to treat a dollar sign followed by a space as the start of math. That rule is what keeps "$5 and $10" from turning into an equation. Keep the dollar signs tight against the formula.

Broken

$x^10$

Fixed

$x^{10}$
^ and _ only take the next single character. x^10 renders as x to the first power followed by a 0. Wrap anything longer in braces.

Broken

It costs $5, or $10 with tax.

Fixed

It costs <span>$</span>5, or <span>$</span>10 with tax.
On GitHub two dollar signs in one paragraph can pair up and italicize everything between them as math. GitHub's docs recommend wrapping a literal dollar sign in <span>; inside math, write \$ instead.

Broken

$$
x = 1

y = 2
$$

Fixed

$$
\begin{aligned}
x &= 1 \\
y &= 2
\end{aligned}
$$
A blank line ends the paragraph, so most renderers stop treating it as one display block. Use \\ for a new line inside an aligned environment.

Broken

\begin{align} ... \end{align}

Fixed

\begin{aligned} ... \end{aligned}
Notion's KaTeX rejects the top-level align environment, and other KaTeX setups vary. aligned, wrapped in $$, works in both MathJax and KaTeX.

Frequently Asked Questions

How do you write math in Markdown?

Standard Markdown has no math syntax, but GitHub, GitLab, Obsidian, VS Code, Jupyter, Typora and Pandoc all add the same LaTeX convention: put inline math between single dollar signs, $x^2$, and display math between double dollar signs on their own lines, $$...$$. The text between the delimiters is LaTeX, rendered by MathJax or KaTeX.

Does GitHub Markdown support LaTeX?

Yes. GitHub renders LaTeX with MathJax in README files, issues, pull requests, discussions and wikis. Use $...$ or $`...`$ for inline math, and $$...$$ on its own lines or a ```math code block for display math. The backtick form exists because it cannot clash with Markdown syntax inside the formula.

How do I write a dollar sign without starting math on GitHub?

Outside math, wrap it in a span: <span>$</span>5. Inside math, escape it with a backslash: $`\sqrt{\$4}`$. Both forms come from GitHub's documentation.

What is the difference between $ and $$ in Markdown?

A single pair of dollar signs is inline math: it sits inside the sentence at text size. A double pair is display math: it becomes its own centered block, with large fractions and with limits placed above and below sums and integrals. Notion is the exception: it uses $$...$$ for inline equations and /math for blocks.

Is the math LaTeX, MathJax or KaTeX?

You write LaTeX math commands. MathJax and KaTeX are the JavaScript libraries that render them. GitHub, Obsidian, Jupyter and Typora use MathJax; GitLab, VS Code and Notion use KaTeX. KaTeX is faster but supports a smaller subset, so prefer aligned over align and check less common macros.

How do I write math in Obsidian?

Type $...$ for inline math and $$...$$ for a block. Obsidian renders both with MathJax in Live Preview and Reading view, with no plugin or setting needed.

Why is my math not rendering?

The usual causes: a space right after the opening dollar sign, a blank line inside a $$ block, a platform with no math support (Discord, Slack, Reddit, and plain CommonMark sites), a static site generator where math is off by default (Hugo needs the passthrough extension and a MathJax or KaTeX script), or a KaTeX-only platform receiving a MathJax-only command.

Can I use math in Discord, Slack or Reddit?

No. None of the three renders LaTeX in messages or posts. Paste Unicode symbols such as ², √ and π for short expressions, or share an image of the rendered equation.