Markdown Math: How to Write Equations in Markdown

LaTeX formulas, KaTeX, MathJax — inline and block math with copy-paste examples

Quick Answer

Wrap LaTeX expressions in dollar signs. Use single dollars $...$ for inline math and double dollars $$...$$ for display (block) math. The Markdown processor must support math rendering — GitHub, GitLab, Jupyter, Obsidian, and MDViewer all do.

Inline: The energy is E = mc2.

E = mc2
Inline: The energy is $E = mc^2$.

$$E = mc^2$$

Inline Math

Inline math appears within a line of text. Wrap the LaTeX expression in single dollar signs with no space after the opening $ or before the closing $:

The quadratic formula is x = (−b ± √(b2 − 4ac)) / 2a.

The quadratic formula is $x = \frac{-b \pm \sqrt{b^2 - 4ac}}{2a}$.

More inline examples:

Area of a circle: $A = \pi r^2$
Euler's identity: $e^{i\pi} + 1 = 0$
Summation: $\sum_{i=1}^{n} i = \frac{n(n+1)}{2}$

Block (Display) Math

Display math renders on its own centered line. Use double dollar signs on separate lines:

∫0∞ e−x2 dx = √π / 2
$$
\int_0^{\infty} e^{-x^2} dx = \frac{\sqrt{\pi}}{2}
$$

On GitHub, you can also use a fenced code block with the math language identifier:

```math
\int_0^{\infty} e^{-x^2} dx = \frac{\sqrt{\pi}}{2}
```

The fenced ```math syntax is GitHub-specific. For maximum portability, use $$...$$.

Common LaTeX Formulas

Copy-paste reference for frequently used math expressions in Markdown:

WhatLaTeXRenders as
Fraction\frac{a}{b}a⁄b
Square root\sqrt{x}√x
Exponentx^{2}x2
Subscriptx_{i}xi
Summation\sum_{i=1}^{n}∑i=1n
Integral\int_{a}^{b}∫ab
Greek letters\alpha, \beta, \piα, β, π
Infinity\infty∞
Not equal\neq≠
Less/greater or equal\leq, \geq≤, ≥
Matrix\begin{bmatrix} a & b \\ c & d \end{bmatrix}[a b; c d]

KaTeX vs MathJax

Two JavaScript libraries power math rendering in Markdown tools. Both take LaTeX input and produce formatted output, but they differ in speed and coverage:

KaTeXMathJax
SpeedFast (synchronous render)Slower (async, may reflow page)
LaTeX coverageMost common commandsMore complete (AMS, custom macros)
OutputHTML + CSSHTML, SVG, or MathML
Used byGitLab, Obsidian, MDViewer, Stack OverflowGitHub, Jupyter, Wikipedia

For most Markdown math — fractions, integrals, Greek letters, matrices — both engines produce identical output. KaTeX is the better choice when speed matters (documentation sites, real-time preview). MathJax is better when you need obscure LaTeX packages or custom macros.

Platform Support

PlatformInline $...$Block $$...$$Engine
GitHubYesYes + ```mathMathJax
GitLabYesYes + ```mathKaTeX
Jupyter NotebookYesYesMathJax
ObsidianYesYesMathJax
MDViewerYes (Pro)Yes (Pro)KaTeX
VS Code (preview)YesYesKaTeX
TyporaYesYesMathJax
NotionYes (inline block)YesKaTeX
SlackNoNo—
DiscordNoNo—

Common Mistakes

Spaces after opening $

On GitHub, $ E = mc^2 $ (with spaces) does not render as math. The dollar signs must touch the expression: $E = mc^2$.

Dollar signs in non-math text

A price like $10 can accidentally trigger math rendering. Escape the dollar sign with a backslash: \$10. Alternatively, use inline code: `$10`.

Missing blank lines around $$

Some processors require blank lines before and after $$ for display math to work. If the equation does not render, add blank lines:

Some text before.

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

Some text after.

Using $$ on platforms that do not support math

On Slack, Discord, and plain Markdown renderers without math support, $$...$$ is displayed as literal text with dollar signs. There is no workaround — math rendering requires a JavaScript engine.

FAQ

How do I write math in Markdown?

Wrap LaTeX expressions in dollar signs: $E = mc^2$ for inline math, $$...$$ on separate lines for display math. The Markdown processor must support math rendering — GitHub, GitLab, Jupyter, Obsidian, and MDViewer all do.

Does GitHub support math in Markdown?

Yes. Since May 2022, GitHub renders LaTeX math in Markdown files, issues, and pull requests. Use $...$ for inline and $$...$$ for display math. GitHub also supports ```math fenced blocks.

What is the difference between KaTeX and MathJax?

Both render LaTeX math in the browser. KaTeX is faster (synchronous, no page reflow) and is used by GitLab, Obsidian, MDViewer, and Stack Overflow. MathJax supports more LaTeX commands and is used by GitHub and Jupyter. For typical Markdown math, both produce identical results.

Preview Math in MDViewer

MDViewer Pro renders KaTeX math formulas natively — inline and display, with no configuration. Open any .md file from Finder and see equations rendered instantly. Also supports syntax-highlighted code blocks, tables, and Mermaid diagrams.

Download MDViewer

Requires macOS 13.0 or later. Intel and Apple Silicon.