KaTeX math rendering

LaTeX Math in Markdown — Live Preview

Write equations with $...$ and $$...$$ and see them typeset as you type. Below the editor: a complete, copy-ready KaTeX cheat sheet.

Jump to the cheat sheet
161 words1,145 chars29 lines

How to write math in Markdown

Two delimiters cover almost everything: single dollars for math inside a sentence, double dollars for an equation on its own line.

Inline math

The area of a circle is $A = \pi r^2$.
The area of a circle is A=πr2A = \pi r^2.

Display math

$$
\int_0^1 x^2\,dx = \frac{1}{3}
$$
∫01x2 dx=13\int_0^1 x^2\,dx = \frac{1}{3}
Which math delimiters work where
SyntaxUseGitHubVS CodeObsidianThis site
$...$Inline math
$$...$$Display (block) math
$`...`$Inline math containing Markdown characters——
```math … ```Display math as a code block——
\( ... \) \[ ... \]LaTeX-style delimiters————

KaTeX cheat sheet

Every symbol below is rendered by KaTeX — the same engine as the previewer — so if it shows here, it works in your Markdown. Copy a command and paste it between dollar signs.

Greek letters

Capitalize the command for uppercase: \delta → δ, \Delta → Δ. Uppercase letters that look Latin (A, B, E…) are just typed as letters.

α\alpha
\alpha
β\beta
\beta
γ\gamma
\gamma
δ\delta
\delta
ϵ\epsilon
\epsilon
ε\varepsilon
\varepsilon
ζ\zeta
\zeta
η\eta
\eta
θ\theta
\theta
ϑ\vartheta
\vartheta
ι\iota
\iota
κ\kappa
\kappa
λ\lambda
\lambda
μ\mu
\mu
ν\nu
\nu
ξ\xi
\xi
π\pi
\pi
ϖ\varpi
\varpi
ρ\rho
\rho
ϱ\varrho
\varrho
σ\sigma
\sigma
ς\varsigma
\varsigma
τ\tau
\tau
υ\upsilon
\upsilon
ϕ\phi
\phi
φ\varphi
\varphi
χ\chi
\chi
ψ\psi
\psi
ω\omega
\omega
Γ\Gamma
\Gamma
Δ\Delta
\Delta
Θ\Theta
\Theta
Λ\Lambda
\Lambda
Ξ\Xi
\Xi
Π\Pi
\Pi
Σ\Sigma
\Sigma
Υ\Upsilon
\Upsilon
Φ\Phi
\Phi
Ψ\Psi
\Psi
Ω\Omega
\Omega

Binary operators

±\pm
\pm
∓\mp
\mp
×\times
\times
÷\div
\div
⋅\cdot
\cdot
∗\ast
\ast
⋆\star
\star
∘\circ
\circ
∙\bullet
\bullet
⊕\oplus
\oplus
⊗\otimes
\otimes
∩\cap
\cap
∪\cup
\cup
∖\setminus
\setminus
∧\wedge
\wedge
∨\vee
\vee
¬\neg
\neg

Relations

≠\neq
\neq
≈\approx
\approx
≡\equiv
\equiv
∼\sim
\sim
≃\simeq
\simeq
≅\cong
\cong
∝\propto
\propto
≤\leq
\leq
≥\geq
\geq
≪\ll
\ll
≫\gg
\gg
⊂\subset
\subset
⊃\supset
\supset
⊆\subseteq
\subseteq
⊇\supseteq
\supseteq
∈\in
\in
∉\notin
\notin
∋\ni
\ni
⊥\perp
\perp
∥\parallel
\parallel
∣\mid
\mid

Arrows

→\to
\to
←\gets
\gets
→\rightarrow
\rightarrow
←\leftarrow
\leftarrow
⇒\Rightarrow
\Rightarrow
⇐\Leftarrow
\Leftarrow
↔\leftrightarrow
\leftrightarrow
⇔\Leftrightarrow
\Leftrightarrow
  ⟹  \implies
\implies
  ⟺  \iff
\iff
↦\mapsto
\mapsto
⟶\longrightarrow
\longrightarrow
↪\hookrightarrow
\hookrightarrow
↑\uparrow
\uparrow
↓\downarrow
\downarrow
↗\nearrow
\nearrow

Sums, integrals & calculus

Use _{…} for lower limits and ^{…} for upper limits.

∑i=1nxi\sum_{i=1}^{n} x_i
\sum_{i=1}^{n} x_i
∏i=1nai\prod_{i=1}^{n} a_i
\prod_{i=1}^{n} a_i
∫abf(x) dx\int_{a}^{b} f(x)\,dx
\int_{a}^{b} f(x)\,dx
∬Df dA\iint_{D} f\,dA
\iint_{D} f\,dA
∮CF⋅dr\oint_{C} F \cdot dr
\oint_{C} F \cdot dr
lim⁡x→0sin⁡xx\lim_{x \to 0} \frac{\sin x}{x}
\lim_{x \to 0} \frac{\sin x}{x}
ddxf(x)\frac{d}{dx} f(x)
\frac{d}{dx} f(x)
f′(x)f'(x)
f'(x)
∂f∂x\frac{\partial f}{\partial x}
\frac{\partial f}{\partial x}
∇f\nabla f
\nabla f
∞\infty
\infty
Δx\Delta x
\Delta x

Fractions, roots & exponents

Group with braces: x^{10} — without them only the first character is raised (x^10 → x¹0).

ab\frac{a}{b}
\frac{a}{b}
ab\dfrac{a}{b}
\dfrac{a}{b}
ab\tfrac{a}{b}
\tfrac{a}{b}
x\sqrt{x}
\sqrt{x}
xn\sqrt[n]{x}
\sqrt[n]{x}
x2x^{2}
x^{2}
xix_{i}
x_{i}
xi2x_i^{2}
x_i^{2}
eiπe^{i\pi}
e^{i\pi}
(nk)\binom{n}{k}
\binom{n}{k}
10−310^{-3}
10^{-3}

Accents & decorations

x^\hat{x}
\hat{x}
xˉ\bar{x}
\bar{x}
AB‾\overline{AB}
\overline{AB}
v⃗\vec{v}
\vec{v}
x˙\dot{x}
\dot{x}
x¨\ddot{x}
\ddot{x}
x~\tilde{x}
\tilde{x}
xy^\widehat{xy}
\widehat{xy}
x‾\underline{x}
\underline{x}
a+b⏞n\overbrace{a+b}^{n}
\overbrace{a+b}^{n}
a+b⏟n\underbrace{a+b}_{n}
\underbrace{a+b}_{n}

Brackets & delimiters

\left and \right make brackets grow to fit their content.

(x)(x)
(x)
[x][x]
[x]
{x}\{x\}
\{x\}
⟨x⟩\langle x \rangle
\langle x \rangle
∣x∣|x|
|x|
∥x∥\|x\|
\|x\|
⌊x⌋\lfloor x \rfloor
\lfloor x \rfloor
⌈x⌉\lceil x \rceil
\lceil x \rceil
(ab)\left( \frac{a}{b} \right)
\left( \frac{a}{b} \right)

Functions

Use \sin, \log, … so names are upright; \operatorname{name} for your own.

sin⁡x\sin x
\sin x
cos⁡x\cos x
\cos x
tan⁡x\tan x
\tan x
log⁡x\log x
\log x
ln⁡x\ln x
\ln x
exp⁡x\exp x
\exp x
max⁡iai\max_{i} a_i
\max_{i} a_i
min⁡iai\min_{i} a_i
\min_{i} a_i
arg max⁡xf(x)\operatorname*{arg\,max}_{x} f(x)
\operatorname*{arg\,max}_{x} f(x)
det⁡A\det A
\det A
gcd⁡(a,b)\gcd(a, b)
\gcd(a, b)

Sets & logic

∅\emptyset
\emptyset
∅\varnothing
\varnothing
N\mathbb{N}
\mathbb{N}
Z\mathbb{Z}
\mathbb{Z}
Q\mathbb{Q}
\mathbb{Q}
R\mathbb{R}
\mathbb{R}
C\mathbb{C}
\mathbb{C}
∀\forall
\forall
∃\exists
\exists
∄\nexists
\nexists
∴\therefore
\therefore
∵\because
\because
⊤\top
\top
⊥\bot
\bot

Fonts & text

x\mathbf{x}
\mathbf{x}
x\mathit{x}
\mathit{x}
dx\mathrm{d}x
\mathrm{d}x
L\mathcal{L}
\mathcal{L}
g\mathfrak{g}
\mathfrak{g}
A\mathsf{A}
\mathsf{A}
x\mathtt{x}
\mathtt{x}
α\boldsymbol{\alpha}
\boldsymbol{\alpha}
if x>0\text{if } x > 0
\text{if } x > 0
x\color{red}{x}
\color{red}{x}

Spacing

Math mode ignores normal spaces; add space explicitly.

a ⁣ba\!b
a\!b
a ba\,b
a\,b
a;ba;b
a;b
aba\quad b
a\quad b
aba\qquad b
a\qquad b

Matrices, cases & alignment

Use these in display math ($$…$$). & separates columns, \\ starts a new row.

(abcd)\begin{pmatrix} a & b \\ c & d \end{pmatrix}
\begin{pmatrix} a & b \\ c & d \end{pmatrix}
[1001]\begin{bmatrix} 1 & 0 \\ 0 & 1 \end{bmatrix}
\begin{bmatrix} 1 & 0 \\ 0 & 1 \end{bmatrix}
∣abcd∣\begin{vmatrix} a & b \\ c & d \end{vmatrix}
\begin{vmatrix} a & b \\ c & d \end{vmatrix}
f(x)={x2x≥0−xx<0f(x) = \begin{cases} x^2 & x \geq 0 \\ -x & x < 0 \end{cases}
f(x) = \begin{cases} x^2 & x \geq 0 \\ -x & x < 0 \end{cases}
y=2x+1y=−x+4\begin{aligned} y &= 2x + 1 \\ y &= -x + 4 \end{aligned}
\begin{aligned} y &= 2x + 1 \\ y &= -x + 4 \end{aligned}
xf(x)01\begin{array}{c|c} x & f(x) \\ \hline 0 & 1 \end{array}
\begin{array}{c|c} x & f(x) \\ \hline 0 & 1 \end{array}

Why your equation isn’t rendering

These five mistakes cause most “raw LaTeX” problems in Markdown.

Using \( \) or \[ \] delimiters

Wrong
\( E = mc^2 \)
Right
$E = mc^2$

Markdown treats the backslash as an escape character, so these never reach the math renderer. Use $ and $$.

Space right inside the dollar signs

Wrong
$ x^2 + y^2 $
Right
$x^2 + y^2$

Most renderers (including GitHub) require the opening $ to be followed — and the closing $ preceded — by a non-space character.

Missing braces around multi-character exponents

Wrong
$x^10$
Right
$x^{10}$

Without braces only the first character is raised, so x^10 renders as x¹0.

Single backslash for a new matrix row

Wrong
\begin{pmatrix} a & b \ c & d \end{pmatrix}
Right
\begin{pmatrix} a & b \\ c & d \end{pmatrix}

Rows are separated by \\ (two backslashes). A single \ is an escape.

Dollar signs in normal text

Wrong
It costs $5 and $10 per user
Right
It costs \$5 and \$10 per user

Escape literal dollar signs with a backslash when a line might be read as math. On GitHub, use <span>$</span> on lines that also contain an equation.

Works here but not on GitHub? See why GitHub math doesn’t render.

KaTeX vs. MathJax

The two engines behind almost all math on the web.

KaTeX

  • Renders synchronously and very fast, no layout jumps
  • Supports a large, well-documented subset of LaTeX math
  • Used by this site, VS Code’s preview, and many docs tools

MathJax

  • Broadest LaTeX coverage, plus MathML and AsciiMath input
  • Strong accessibility extensions (speech, exploration)
  • Used by GitHub and Obsidian

Frequently asked questions

How do I write math in Markdown?

Wrap inline math in single dollar signs, like $E = mc^2$, and put display equations between double dollar signs on their own lines: $$ ... $$. Inside, use LaTeX commands such as \frac{a}{b}, \sqrt{x}, \sum_{i=1}^{n}, and Greek letters like \alpha. This page renders it live with KaTeX.

What is the difference between LaTeX and KaTeX?

LaTeX is a complete typesetting system for documents. KaTeX is a JavaScript library that renders LaTeX math notation in web pages very quickly. It supports a large subset of LaTeX math commands — everything on this page's cheat sheet — but not full documents or packages.

Does GitHub support LaTeX math?

Yes. Since 2022 GitHub renders $...$ and $`...`$ inline and $$...$$ or ```math blocks for display math, in .md files, issues, pull requests, discussions, and wikis. GitHub uses MathJax, this previewer uses KaTeX; standard notation looks the same, but a few rarely used commands are supported by only one of them.

Why is my equation showing as raw text?

Check the delimiters ($ / $$, not \( \)), remove spaces directly inside the dollar signs, and make sure braces are balanced. If one command is unsupported, KaTeX shows the source in red — look it up in the cheat sheet above.

How do I write a matrix or a piecewise function?

Use an environment inside $$...$$: \begin{pmatrix} a & b \\ c & d \end{pmatrix} for a matrix (bmatrix for square brackets, vmatrix for a determinant) and \begin{cases} ... \end{cases} for piecewise functions. Separate columns with & and rows with \\.

Can I export math to PDF?

Yes. Use Export → PDF to print the rendered document, including equations, through your browser's print dialog, or Export → HTML for a standalone page that loads the KaTeX stylesheet.

More Markdown Tools & Guides

All tools are free, run in your browser, and require no account.

Live Markdown PreviewerTool

Edit Markdown with a real-time preview, Mermaid, KaTeX math, drag-and-drop files, and one-click export.

Open the tool
GitHub Markdown PreviewTool

Load any public README, test it, and look up any GitHub syntax in the complete cheat sheet.

Open the tool
Mermaid Live EditorTool

13 diagram types with examples, live rendering, and SVG/PNG download.

Open the tool
README Template GeneratorTool

Pick sections, fill in your project, and download a GitHub-ready README.md with badges and a TOC.

Open the tool
AI Markdown ViewerTool

Paste ChatGPT, Claude, or Gemini output and read it formatted, with tables, code, and math.

Open the tool
What Is Markdown?Guide

A plain-English introduction: what Markdown and .md files are, where it came from, and where it is used.

Read the guide
Markdown in Google DocsGuide

Preview .md files in Drive, edit in Docs' Markdown mode, and paste, convert, or export Markdown.

Read the guide
Best Online Markdown ViewersGuide

Six free tools tested with the same document: rendering, privacy, and phone support compared.

Read the guide
GitHub Markdown Not Rendering?Guide

16 causes found by symptom — tables, lists, image paths, code fences, alerts, Mermaid, math — with tested fixes.

Read the guide
Markdown Preview in VS CodeGuide

Preview shortcuts, settings verified on VS Code 1.141, built-in Mermaid and math, extensions, and fixes.

Read the guide
How to Open an .md FileGuide

Open and read Markdown files formatted on Windows, Mac, Linux, iPhone, Android, Word, and Google Docs.

Read the guide
Markdown Preview in Any EditorGuide

Exact preview shortcuts for Visual Studio, JetBrains, Zed, Xcode, Sublime, Neovim, Obsidian, and more.

Read the guide
Preview Markdown in a BrowserGuide

Six free ways to read .md files in Chrome, Edge, Firefox, or Safari — compared for privacy and features.

Read the guide