Markdown LaTeX: Write Math Equations in Markdown
$x^2$ for math inside a sentence, and $$...$$ on its own lines for a block equation. Markdown Preview renders it live with KaTeX, reads the same syntax GitHub does, and keeps every equation when you export to PDF. It is free and runs in your browser.Inline and block math
| You type | You get | Result |
|---|---|---|
$E = mc^2$ | Inline math, inside a sentence | |
$$\sum_{i=1}^{n} i$$ | Block math, centred on its own line | |
```math
\frac{a}{b}
``` | Also block math, the way GitHub writes it |
Dollar signs inside code are never read as math, so shell variables like $HOME stay as they are. The rest of the markdown syntax is in the markdown cheatsheet.
LaTeX math symbols cheat sheet
Type any of these between dollar signs. Each one is checked to render before it goes on this list.
Powers, fractions and roots
| x^2 | Superscript or power | |
| x_i | Subscript | |
| x_{i}^{2} | Both, braces for more than one character | |
| \frac{a}{b} | Fraction | |
| \sqrt{x} | Square root | |
| \sqrt[3]{x} | Cube or nth root |
Greek letters
| \alpha \beta \gamma \delta | Lowercase: alpha, beta, gamma, delta | |
| \theta \lambda \mu \pi | theta, lambda, mu, pi | |
| \sigma \phi \omega \epsilon | sigma, phi, omega, epsilon | |
| \Delta \Sigma \Omega \Gamma | Uppercase: capitalise the name |
Operators and relations
| a \times b \div c | Times and divide | |
| a \cdot b | Dot product or multiplication dot | |
| \pm \mp | Plus minus | |
| \neq \approx \equiv | Not equal, approximately, equivalent | |
| \leq \geq \ll \gg | Less or equal, greater or equal | |
| \infty | Infinity | |
| x \bmod n | Modulo |
Sets and logic
| x \in A \quad y \notin B | Element of, not an element of | |
| A \cup B \quad A \cap B | Union and intersection | |
| A \subset B \quad A \subseteq B | Subset | |
| \emptyset | Empty set | |
| \forall x \; \exists y | For all, there exists | |
| \mathbb{R} \; \mathbb{N} \; \mathbb{Z} | Number sets |
Arrows
| \to \quad \rightarrow | Right arrow | |
| \leftarrow \quad \leftrightarrow | Left and both ways | |
| \Rightarrow \quad \Leftrightarrow | Implies, if and only if | |
| \mapsto | Maps to |
Calculus
| \sum_{i=1}^{n} i | Sum (summation) | |
| \prod_{i=1}^{n} x_i | Product | |
| \int_{a}^{b} f(x)\,dx | Integral | |
| \iint_D f \, dA | Double integral | |
| \lim_{x \to 0} f(x) | Limit | |
| \frac{dy}{dx} | Derivative | |
| \frac{\partial f}{\partial x} | Partial derivative | |
| \nabla f | Gradient (nabla) |
Functions
| \sin x \; \cos x \; \tan x | Trigonometry | |
| \log x \; \ln x \; \exp(x) | Logarithms and exponential | |
| \max(a, b) \; \min(a, b) | Max and min |
Brackets
| \left( \frac{a}{b} \right) | Brackets that grow to fit | |
| \lvert x \rvert | Absolute value | |
| \lVert v \rVert | Norm | |
| \lfloor x \rfloor \; \lceil x \rceil | Floor and ceiling | |
| \{ 1, 2, 3 \} | Curly braces, escaped |
Accents and fonts
| \vec{v} \; \hat{x} \; \bar{x} | Vector, hat, bar | |
| \dot{x} \; \ddot{x} | Dots for time derivatives | |
| \overline{AB} | Line over several characters | |
| \mathbf{v} \; \mathcal{L} | Bold and calligraphic | |
| x = 1 \text{ if } y > 0 | Plain text inside math | |
| a \, b \quad c \qquad d | Spaces: small, wide, wider |
Multi-line equations, matrices and cases
Several lines, lined up
$$
\begin{aligned}
a &= b + c \\
&= d
\end{aligned}
$$Put & before what each line lines up on, usually the = sign, and \\ at the end of every line but the last.
Matrix
$$
\begin{pmatrix}
1 & 2 \\
3 & 4
\end{pmatrix}
$$& moves to the next column and \\ to the next row. Use bmatrix for square brackets and vmatrix for a determinant.
Cases
$$
f(x) = \begin{cases}
1 & x > 0 \\
0 & \text{otherwise}
\end{cases}
$$For a function defined piece by piece. Wrap words in \text{} so they keep their spaces.
Numbered equation
$$
E = mc^2 \tag{1}
$$\tag puts a label on the right of a block equation.
Write once, works on GitHub too
GitHub reads the same $, $$ and ```math syntax, so equations you write here show the same way in a README. To see the whole file the way GitHub will, open it in the README preview. Equations sit happily next to diagrams, too: see Mermaid in markdown.
Export math to PDF and HTML
Save the document as a PDF and every equation goes in as it looks in the preview, with no LaTeX install and no upload. The markdown to PDF guide walks through it. Export as HTML and you get a single file with the math and its fonts built in, so it renders offline too.
Try it with a sample document
Lecture notes with the quadratic formula, an aligned derivation, a matrix, cases, a GitHub-style math block, and prices that stay as text. Open it and edit any formula to see it redraw.
# Lecture notes: quadratics
The roots of $ax^2 + bx + c = 0$ are given by the quadratic formula:
$$
x = \frac{-b \pm \sqrt{b^2 - 4ac}}{2a} \tag{1}
$$
## Completing the square
$$
\begin{aligned}
x^2 + 6x + 5 &= (x + 3)^2 - 9 + 5 \\
&= (x + 3)^2 - 4
\end{aligned}
$$
## Matrix and cases
$$
A = \begin{pmatrix} 1 & 2 \\ 3 & 4 \end{pmatrix}
\qquad
\lvert x \rvert = \begin{cases} x & x \geq 0 \\ -x & x < 0 \end{cases}
$$
## GitHub style
```math
\sum_{k=1}^{n} k = \frac{n(n+1)}{2}
```
The textbook costs $25 and the workbook $10, and those stay as plain text.
Questions about LaTeX in markdown
How do I write math equations in markdown?
Put inline math between single dollar signs, like $x^2$, and block math between double dollar signs on their own lines. Inside, use LaTeX: ^ for powers, _ for subscripts, \frac{a}{b} for fractions and \sqrt{x} for roots. Markdown Preview renders it as you type.
Can markdown display math equations?
Plain markdown cannot, but many tools that render it can, including GitHub, GitLab, Jupyter, Obsidian, VS Code and Markdown Preview. They all read LaTeX between dollar signs, so the same equations work across them.
Does GitHub render LaTeX in markdown?
Yes. GitHub reads $...$ for inline math, $$...$$ for blocks, and code blocks labelled math. Markdown Preview reads all three the same way, so you can write a README with equations here and it shows the same math on GitHub.
Is MathJax just LaTeX?
No. LaTeX is the language you write the math in. MathJax and KaTeX are two programs that draw that LaTeX in a browser. They understand the same syntax for nearly every common formula. Markdown Preview uses KaTeX.
How do I write a dollar sign without starting math?
Type \$ to get a plain dollar sign. Prices are already safe on their own: a dollar sign with a space just inside it, or a closing one followed by a digit, is not read as math, so "costs $5 and $10" stays as text. Dollar signs in code blocks are never math.
How do I start a new line in a block equation?
Wrap the lines in \begin{aligned} and \end{aligned}, end each line with \\, and put & before the symbol the lines should line up on, usually the equals sign.
Why is my formula showing in red?
Red text means KaTeX could not read the formula, often a missing closing brace or a command it does not know. The rest of the document still renders, so you can fix it in place. Chemistry formulas written with \ce are not supported.
Can I export markdown with LaTeX to PDF?
Yes. Choose Export > Print / Save as PDF and pick Save as PDF. Equations go into the PDF exactly as the preview shows them, with no LaTeX install needed. HTML export keeps them too.