Documentation
Home · Docs · Markdown · LaTeX math in Markdown

LaTeX math in Markdown

How to write LaTeX math in Markdown with single and double dollar signs, where it renders, and common fraction, power, and symbol patterns.

To write LaTeX math in Markdown, wrap a TeX expression in single dollar signs ($...$) for inline math, or in double dollar signs ($$...$$) for a centered block equation. Math is not part of core Markdown, so a renderer such as MathJax or KaTeX draws the final output, and the syntax works only where a math engine is present.

LaTeX math in Markdown syntax reference

Goal Syntax
Inline math $E = mc^2$
Block (display) math $$ E = mc^2 $$
Block math (code fence) ```math then the expression
Literal dollar sign \$

LaTeX math in Markdown key facts

  • Wrap an expression in single dollar signs for inline math and double dollar signs for a centered block equation.
  • Math is not part of core Markdown, so it renders only where a math engine such as MathJax or KaTeX is present.
  • GitHub has rendered $...$ and $$...$$ math, plus fenced math code blocks, using MathJax since May 2022.
  • Pandoc and MultiMarkdown support dollar-sign math, while CommonMark and classic Markdown Extra define no math syntax.
  • The opening $ needs a non-space character right after it and the closing $ a non-space right before it, which stops currency amounts from parsing as math.
  • Escape a literal dollar sign in prose as \$ to avoid accidental math parsing.

Confirm the math delimiter and rendering engine

Mathematical notation is an extension, not core Markdown. $...$ and $$...$$ are common delimiters, but some systems use \(...\), fenced math blocks, or renderer-specific rules. The output may be produced by MathJax, KaTeX, Pandoc, or another engine with different command support.

Use inline math for short expressions and display math for equations that need their own line. Avoid placing currency values next to dollar-delimited math without checking how the parser resolves the ambiguity. When portability matters, document the required renderer and test equations, labels, line breaks, and unsupported LaTeX commands before publishing.

Basic syntax

To write inline math, surround a TeX expression with single dollar signs. To write a centered block equation, put the expression on its own lines between double dollar signs.

Markdown

The mass-energy relation is $E = mc^2$.

$$
E = mc^2
$$

Rendered output

The mass-energy relation is $E = mc^2$.

$$ E = mc^2 $$

HTML output

<p>The mass-energy relation is <span class="math inline">\(E = mc^2\)</span>.</p>
<p class="math display">\[E = mc^2\]</p>

The exact HTML depends on the renderer. MathJax and KaTeX typically emit a container element (such as a <span> or <div>) holding the delimited TeX, then replace it with rendered markup (SVG, MathML, or styled HTML) in the browser. The \(...\) and \[...\] delimiters shown above are the standard math delimiters that many processors normalize dollar-sign math into.

Inline math

Inline math sits within a line of text. The opening $ should be followed immediately by a non-space character, and the closing $ should be preceded immediately by a non-space character. This rule stops ordinary currency amounts from being parsed as math.

Markdown

The area of a circle is $A = \pi r^2$, where $r$ is the radius.

Rendered output

The area of a circle is $A = \pi r^2$, where $r$ is the radius.

HTML output

<p>The area of a circle is <span class="math inline">\(A = \pi r^2\)</span>,
where <span class="math inline">\(r\)</span> is the radius.</p>

Block (display) math

Block math, also called display math, renders on its own line and is usually centered. Put the expression between $$ delimiters, ideally on their own lines so the source stays readable.

Markdown

$$
\int_{a}^{b} f(x)\,dx = F(b) - F(a)
$$

Rendered output

$$ \int_{a}^{b} f(x)\,dx = F(b) - F(a) $$

HTML output

<p class="math display">\[\int_{a}^{b} f(x)\,dx = F(b) - F(a)\]</p>

Block math with a code fence

Some renderers, including GitHub, accept a fenced code block with the math info string as an alternative to $$. This avoids delimiter clashes when an expression itself contains dollar signs.

Markdown

```math
\frac{-b \pm \sqrt{b^2 - 4ac}}{2a}
```

Rendered output

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

HTML output

<p class="math display">\[\frac{-b \pm \sqrt{b^2 - 4ac}}{2a}\]</p>

On platforms that do not support the math info string, this renders as a plain code block showing the literal TeX instead of a formula.

Common expressions

LaTeX math supports the full range of TeX notation. A few frequently used constructs:

Markdown

Fractions: $\frac{a}{b}$

Subscripts and superscripts: $x_i^2$

Greek letters: $\alpha, \beta, \gamma, \Delta$

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

Square root: $\sqrt{x^2 + y^2}$

Rendered output

Fractions: $\frac{a}{b}$

Subscripts and superscripts: $x_i^2$

Greek letters: $\alpha, \beta, \gamma, \Delta$

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

Square root: $\sqrt{x^2 + y^2}$

Escaping dollar signs

Because $ is the math delimiter, a literal dollar sign in prose can be misread as the start of an expression. Escape it with a backslash (\$) to force it to render as a currency symbol.

Markdown

The ticket costs \$20 and the book costs \$30.

Rendered output

The ticket costs \$20 and the book costs \$30.

HTML output

<p>The ticket costs $20 and the book costs $30.</p>

Pandoc handles the common case automatically: a $ immediately followed by a digit, as in $20, is not treated as a math delimiter, so many currency amounts already render correctly without escaping.

Flavor differences

LaTeX math is not part of any core Markdown specification. It is a renderer feature, so support depends on whether the tool ships a math engine such as MathJax or KaTeX and which delimiters it recognizes.

Flavor Math support Notes
CommonMark No The spec defines no math syntax. $...$ is plain text unless an extension adds it.
GitHub Flavored Markdown (GFM) Partial GitHub renders $...$, $$...$$, and ```math blocks via MathJax. This is a GitHub renderer feature, not part of the formal GFM spec, so it is not guaranteed in other GFM parsers.
MultiMarkdown Yes Supports $...$ inline and $$...$$ display math, designed to pair with a MathJax engine.
Markdown Extra No Classic Markdown Extra defines no math syntax.
Pandoc Yes Native tex_math_dollars: $...$ inline and $$...$$ display. Renders to MathJax, MathML, KaTeX, and more.

GitHub added math rendering in May 2022 using MathJax, covering Markdown files, issues, discussions, pull requests, and wikis. Pandoc has long supported dollar-sign math through its tex_math_dollars extension and can convert it to many output formats. MultiMarkdown supports dollar-sign math syntax designed to pair with a MathJax engine. CommonMark and classic Markdown Extra have no built-in math, so on those you need an extension or a math-aware renderer for $...$ to become a formula rather than literal text.

Other platforms (Notion, Obsidian, Slack, Discord)

  • Notion: supports inline math with $$...$$ inline equation blocks and a dedicated block equation type, powered by KaTeX.
  • Obsidian: renders $...$ inline and $$...$$ block math with MathJax.
  • Slack and Discord: do not render LaTeX math natively. Dollar-delimited expressions appear as literal text unless an app or bot adds rendering.

For the full comparison of how flavors differ across all elements, see Markdown flavors.

How Markdific renders it

Markdific renders LaTeX math. Inline $...$ expressions render within the surrounding text, and block $$...$$ expressions render as centered display equations.

Standard TeX constructs such as fractions, subscripts, superscripts, Greek letters, integrals, and summations are supported.

Try it in the Markdific online editor.

Common mistakes and gotchas

  • Spaces just inside the delimiters. $ x + y $ fails in strict parsers. The opening $ needs a non-space right after it and the closing $ a non-space right before it.
  • Unescaped currency amounts. In a math-aware renderer, $5 and $10 can be read as one inline expression. Escape with \$ or rely on the digit rule where the renderer supports it.
  • Assuming universal support. $...$ is plain text in CommonMark and classic Markdown Extra. Do not rely on math in portable documents unless the target renders it.
  • Mismatched delimiters. Opening with $ and closing with $$ (or leaving one delimiter unclosed) breaks parsing and often swallows following text.
  • Markdown inside math. Content between math delimiters is TeX, not Markdown. Asterisks and underscores are TeX operators there, not emphasis.
  • Block math on one line. Some renderers need the $$ delimiters and the expression on separate lines to treat it as display rather than inline math.

Best practices

  • Use $...$ for inline math and $$...$$ for standalone equations.
  • Put block $$ delimiters on their own lines so the source is easy to scan and edit.
  • Escape literal dollar signs in prose as \$ to avoid accidental math parsing.
  • Prefer the ```math code fence on GitHub when an expression contains dollar signs.
  • Confirm your target renders math before relying on it, since it is a renderer feature, not core Markdown.
  • Keep complex multi-line derivations in block math with \\ line breaks and alignment environments for readability.

HTML equivalent

Markdown math compiles to renderer-specific HTML. A common pattern wraps inline math in a <span> and display math in a <div> or <p>, holding the normalized TeX, which the math engine then converts to SVG, MathML, or styled HTML in the browser.

Markdown

Inline $a^2 + b^2 = c^2$ and a block below.

$$
a^2 + b^2 = c^2
$$

HTML output

<p>Inline <span class="math inline">\(a^2 + b^2 = c^2\)</span> and a block below.</p>
<p class="math display">\[a^2 + b^2 = c^2\]</p>

FAQ

How do you write math in Markdown? Wrap a TeX expression in single dollar signs for inline math ($E = mc^2$) or double dollar signs for a centered block equation ($$ E = mc^2 $$). A math renderer such as MathJax or KaTeX draws the result.

Does GitHub render LaTeX math? Yes. Since May 2022, GitHub renders $...$ inline math, $$...$$ block math, and fenced ```math blocks using MathJax, across Markdown files, issues, discussions, pull requests, and wikis.

Does Pandoc support dollar-sign math? Yes. Pandoc supports $...$ for inline math and $$...$$ for display math through its built-in tex_math_dollars extension and can convert it to MathJax, MathML, KaTeX, and other outputs.

Is LaTeX math part of standard Markdown? No. Math is not in the CommonMark specification or classic Markdown Extra. It is a renderer feature, so it works only where the tool ships a math engine or an extension enables it.

What is the difference between inline and block math? Inline math with $...$ flows within a line of text. Block math with $$...$$ renders on its own line and is usually centered as a display equation.

How do I show a literal dollar sign? Escape it with a backslash as \$. In Pandoc, a dollar sign immediately followed by a digit, like $20, is already treated as currency rather than a math delimiter.

Do MathJax and KaTeX produce the same result? They render the same TeX input into similar visual output but differ in speed and coverage. KaTeX is faster and covers most common notation, while MathJax supports a broader range of TeX and output formats.

How do you write a fraction in Markdown math? Use the TeX \frac command inside math delimiters, as in $\frac{a}{b}$ for an inline fraction or the same expression between $$ for a display fraction. The first group is the numerator and the second is the denominator.

How do you write an exponent or subscript in Markdown math? Inside math delimiters, use a caret for a superscript and an underscore for a subscript, as in $x^2$ and $x_i$. Wrap multi-character exponents or indices in braces, for example $x^{10}$ and $a_{ij}$.

Why is my Markdown math not rendering? The most common causes are a renderer with no math engine, a space just inside the delimiters, or mismatched delimiters such as opening with $ and closing with $$. Confirm the target renders math and that each expression opens and closes with the same delimiter.

Does Notion or Obsidian support LaTeX math? Yes. Notion renders inline and block equations with KaTeX, and Obsidian renders $...$ inline and $$...$$ block math with MathJax.

Sources and compatibility references

Use these primary references for syntax rules. Renderer behaviour can still vary by version and configuration, so preview important documents in their final destination.