Markdown LaTeX: Write Math Equations in Markdown

To write math in markdown, put LaTeX between dollar signs: $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 typeYou getResult
$E = mc^2$
Inline math, inside a sentenceE=mc2E = mc^2
$$\sum_{i=1}^{n} i$$
Block math, centred on its own line∑i=1ni\sum_{i=1}^{n} i
```math
\frac{a}{b}
```
Also block math, the way GitHub writes itab\frac{a}{b}

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^2x2x^2Superscript or power
x_ixix_iSubscript
x_{i}^{2}xi2x_{i}^{2}Both, braces for more than one character
\frac{a}{b}ab\frac{a}{b}Fraction
\sqrt{x}x\sqrt{x}Square root
\sqrt[3]{x}x3\sqrt[3]{x}Cube or nth root

Greek letters

\alpha \beta \gamma \deltaαβγδ\alpha \beta \gamma \deltaLowercase: alpha, beta, gamma, delta
\theta \lambda \mu \piθλμπ\theta \lambda \mu \pitheta, lambda, mu, pi
\sigma \phi \omega \epsilonσϕωϵ\sigma \phi \omega \epsilonsigma, phi, omega, epsilon
\Delta \Sigma \Omega \GammaΔΣΩΓ\Delta \Sigma \Omega \GammaUppercase: capitalise the name

Operators and relations

a \times b \div ca×b÷ca \times b \div cTimes and divide
a \cdot ba⋅ba \cdot bDot product or multiplication dot
\pm \mp±∓\pm \mpPlus minus
\neq \approx \equiv≠≈≡\neq \approx \equivNot equal, approximately, equivalent
\leq \geq \ll \gg≤≥≪≫\leq \geq \ll \ggLess or equal, greater or equal
\infty∞\inftyInfinity
x \bmod nx mod nx \bmod nModulo

Sets and logic

x \in A \quad y \notin Bx∈Ay∉Bx \in A \quad y \notin BElement of, not an element of
A \cup B \quad A \cap BA∪BA∩BA \cup B \quad A \cap BUnion and intersection
A \subset B \quad A \subseteq BA⊂BA⊆BA \subset B \quad A \subseteq BSubset
\emptyset∅\emptysetEmpty set
\forall x \; \exists y∀x  ∃y\forall x \; \exists yFor all, there exists
\mathbb{R} \; \mathbb{N} \; \mathbb{Z}R  N  Z\mathbb{R} \; \mathbb{N} \; \mathbb{Z}Number sets

Arrows

\to \quad \rightarrow→→\to \quad \rightarrowRight arrow
\leftarrow \quad \leftrightarrow←↔\leftarrow \quad \leftrightarrowLeft and both ways
\Rightarrow \quad \Leftrightarrow⇒⇔\Rightarrow \quad \LeftrightarrowImplies, if and only if
\mapsto↦\mapstoMaps to

Calculus

\sum_{i=1}^{n} i∑i=1ni\sum_{i=1}^{n} iSum (summation)
\prod_{i=1}^{n} x_i∏i=1nxi\prod_{i=1}^{n} x_iProduct
\int_{a}^{b} f(x)\,dx∫abf(x) dx\int_{a}^{b} f(x)\,dxIntegral
\iint_D f \, dA∬Df dA\iint_D f \, dADouble integral
\lim_{x \to 0} f(x)lim⁡x→0f(x)\lim_{x \to 0} f(x)Limit
\frac{dy}{dx}dydx\frac{dy}{dx}Derivative
\frac{\partial f}{\partial x}∂f∂x\frac{\partial f}{\partial x}Partial derivative
\nabla f∇f\nabla fGradient (nabla)

Functions

\sin x \; \cos x \; \tan xsin⁡x  cos⁡x  tan⁡x\sin x \; \cos x \; \tan xTrigonometry
\log x \; \ln x \; \exp(x)log⁡x  ln⁡x  exp⁡(x)\log x \; \ln x \; \exp(x)Logarithms and exponential
\max(a, b) \; \min(a, b)max⁡(a,b)  min⁡(a,b)\max(a, b) \; \min(a, b)Max and min

Brackets

\left( \frac{a}{b} \right)(ab)\left( \frac{a}{b} \right)Brackets that grow to fit
\lvert x \rvert∣x∣\lvert x \rvertAbsolute value
\lVert v \rVert∥v∥\lVert v \rVertNorm
\lfloor x \rfloor \; \lceil x \rceil⌊x⌋  ⌈x⌉\lfloor x \rfloor \; \lceil x \rceilFloor and ceiling
\{ 1, 2, 3 \}{1,2,3}\{ 1, 2, 3 \}Curly braces, escaped

Accents and fonts

\vec{v} \; \hat{x} \; \bar{x}v⃗  x^  xˉ\vec{v} \; \hat{x} \; \bar{x}Vector, hat, bar
\dot{x} \; \ddot{x}x˙  x¨\dot{x} \; \ddot{x}Dots for time derivatives
\overline{AB}AB‾\overline{AB}Line over several characters
\mathbf{v} \; \mathcal{L}v  L\mathbf{v} \; \mathcal{L}Bold and calligraphic
x = 1 \text{ if } y > 0x=1 if y>0x = 1 \text{ if } y > 0Plain text inside math
a \, b \quad c \qquad da bcda \, b \quad c \qquad dSpaces: small, wide, wider

Multi-line equations, matrices and cases

Several lines, lined up

$$
\begin{aligned}
a &= b + c \\
  &= d
\end{aligned}
$$
a=b+c=d\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}
$$
(1234)\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}
$$
f(x)={1x>00otherwisef(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}
$$
E=mc2(1)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.

Write your first equation

Notes, homework and technical docs with math, diagrams and code in one document. No account, and your documents stay in your browser.