LaTeX Equations in Markdown
This page demonstrates every supported way to write and embed LaTeX math in Markdown, and explicitly shows situations where Markdown rendering or LaTeX rendering should be disabled.
1. Inline Math
Inline math is wrapped in single dollar signs $...$ and rendered on the same line as the surrounding text.
| Syntax | Example |
|---|---|
$E = mc^2$ | \(E = mc^2\) |
$a^2 + b^2 = c^2$ | \(a^2 + b^2 = c^2\) |
$\frac{1}{2}$ | \(\frac{1}{2}\) |
$\sum_{i=1}^{n} x_i$ | \(\sum_{i=1}^{n} x_i\) |
$\alpha \beta \gamma$ | \(\alpha \beta \gamma\) |
Einstein showed that \(E = mc^2\), while the Pythagorean theorem states \(a^2 + b^2 = c^2\).
2. Display Math
Display math is wrapped in double dollar signs $$...$$ and rendered as a centered block.
$$
E = mc^2
$$
$$
\int_{-\infty}^{\infty} e^{-x^2} dx = \sqrt{\pi}
$$
3. Math with Delimiters
Some renderers also support these delimiters:
| Delimiter | Type | Example |
|---|---|---|
\(...\) | Inline | \( \sin^2\theta + \cos^2\theta = 1 \) |
\[...\] | Display | [ nabla cdot mathbf{E} = frac{rho}{varepsilon_0} ] |
`...` with $ | Code-style inline | $E=mc^2$ |
$E=mc^2$
4. Common LaTeX Constructs
Fractions
Subscripts and Superscripts
Roots
Greek Letters
Sums, Products, and Limits
Integrals
Matrices
Multiline Alignment
Cases
Operators
Accents and Decorations
5. Math Inside Markdown Containers
In Admonitions
Math in a note
The quadratic formula is:
$$
x = frac{-b pm sqrt{b^2 - 4ac}}{2a}
$$
In Lists
- Inline math in a list: \(a + b = c\)
- Display math in a list:
$$
sum_{n=1}^{infty} frac{1}{n^2} = frac{pi^2}{6}
$$ - Final item with \(\LaTeX\) inline.
In Blockquotes
The Euler-Lagrange equation is
$$
frac{d}{dt}frac{partial L}{partial dot{q}} - frac{partial L}{partial q} = 0
$$
In Tables
| Operation | LaTeX | Result |
|---|---|---|
| Addition | $a + b$ | \(a + b\) |
| Multiplication | $a \cdot b$ | \(a \cdot b\) |
| Division | $\frac{a}{b}$ | \(\frac{a}{b}\) |
| Exponent | $a^b$ | \(a^b\) |
6. Escaping Dollar Signs
To show a literal dollar sign without triggering math mode, escape it with a backslash: \$50 renders as $50.
A price like $10 + $20 = $30 should not become math.
7. Where Markdown Should NOT Be Rendered
In the following places Markdown formatting must be treated as plain text.
Inside Inline Code
Backticks suppress Markdown formatting: **bold**, [link](url), $not math$.
Inside Fenced Code Blocks
# This is not a heading
**This is not bold**
[This is not a link](https://example.com)
> This is not a blockquote
Inside Code Blocks with Other Languages
# Python comment, not a Markdown heading
def hello():
print("**not bold**")
<!-- HTML comment -->
<p>**not bold**</p>
Inside Inline HTML
this is not bold
Inside URLs and Email Addresses
https://example.com/path_with_underscores should keep its underscores.
An email like user_name@example.com should not italicize _name.
8. Where LaTeX Should NOT Be Rendered
In the following places dollar signs and backslash commands must remain literal text.
Inside Inline Code
$E = mc^2$ should not render as math.
\frac{a}{b} should remain a literal backslash command.
Inside Fenced Code Blocks
$$
E = mc^2
$$
\documentclass{article}
\begin{document}
$E = mc^2$
\end{document}
# A variable named $total is just a string
price = "$10"
In Plain Text About Currency
The total cost is $50, not \(E = mc^2\).
Prices like $1.99, $20.00, and $100 should remain currency.
Inside HTML Attributes
<img alt="$price" src="image.png">
In URLs
https://example.com/$var/path should keep $var as a URL segment.
In File Paths and Shell Commands
cd $HOME
ls -la /usr/local/bin
echo "Price: $5.00"
In YAML Front Matter
---
title: "$E = mc^2$ should be literal"
price: "$10"
---
In Inline HTML Tags
\(x^2\) should not be processed as math.
9. Mixed Edge Cases
Math Next to Punctuation
The equation \(E = mc^2\), derived by Einstein, changed physics.
Multiple Inline Expressions
For \(x \in \mathbb{R}\) and \(\varepsilon > 0\), there exists \(\delta > 0\) such that \(|x - a| < \delta\) implies \(|f(x) - f(a)| < \varepsilon\).
Multi-line Display Without Alignment
10. Reference Table
| Syntax | Render Math? | Render Markdown? | Use Case |
|---|---|---|---|
$...$ | Yes | No inside | Inline math |
$$...$$ | Yes | No inside | Display math |
\(...\) | Yes (if supported) | No inside | Inline math alternative |
\[...\] | Yes (if supported) | No inside | Display math alternative |
`...` | No | No | Code / literal text |
``` | No | No | Code blocks |
| Raw HTML | No | No | HTML passthrough |
| YAML front matter | No | No | Metadata |