Printdown

Math in Markdown: write LaTeX equations and export to PDF

By ·

Markdown has no math syntax of its own, but most editors that handle formulas share one convention: LaTeX between dollar signs. The Markdown to PDF editor follows it and typesets every formula with KaTeX in your browser, with no TeX installation. Here is the syntax it understands, a cheat sheet to copy from, how to keep prices from turning into math, and how to get equations onto paper cleanly.

Inline and display math

Single dollar signs keep a formula inside a sentence; double dollar signs give it a centered line of its own:

The area of a circle is $A = \pi r^2$ and its circumference is $C = 2\pi r$.

$$
\int_0^1 x^2\,dx = \frac{1}{3}
$$

A few rules decide whether a dollar sign starts a formula:

  • Display math goes on its own lines. Put $$ on the lines before and after the formula, or everything on one line: $$ a^2 + b^2 = c^2 $$. A $$…$$ pair in mid-sentence still becomes a separate block and splits the paragraph.
  • No letter or digit right after the closing dollar. $n$th stays as plain text; write $n$-th or $n^{\text{th}}$. Punctuation is fine: ($x$) and $x$, both work.
  • Only dollar signs count. The \(…\) and \[…\] delimiters of LaTeX, also common in text copied from AI assistants, show up as plain brackets, and a fenced ```math block in GitHub style appears as code. Change them to $…$ and $$…$$.
  • Markdown stays out. Underscores and asterisks inside a formula never turn into italics or bold.

Cheat sheet

Everything below goes between dollar signs. Group anything longer than one character with braces: x^{10}, because x^10 raises only the 1.

You wantYou type
Superscript, subscriptx^2, a_n, x_{i,j}^{2k}
Fraction\frac{a+b}{2}, or \dfrac for full size in a sentence
Roots\sqrt{x}, \sqrt[3]{x}
Greek letters\alpha \beta \gamma \theta \lambda \pi \sigma \omega \Delta \Sigma \Omega
Sum and product\sum_{i=1}^{n} i, \prod_{k=1}^{n} k
Integrals\int_a^b f(x)\,dx, \iint_D, \oint_C
Limit\lim_{x \to 0} \frac{\sin x}{x}
Derivativesf'(x), \frac{dy}{dx}, \frac{\partial f}{\partial x}
Relations, operators\le \ge \ne \approx \equiv \pm \times \cdot \div \infty
Logic and sets\forall \exists \in \notin \subset \cup \cap \Rightarrow \iff
Number sets\mathbb{R}, \{ x \mid x > 0 \}
Brackets that grow\left( \frac{a}{b} \right)
Absolute value, norm\lvert x \rvert, \lVert v \rVert
Bold, accents\mathbf{v}, \boldsymbol{\alpha}, \hat{x} \bar{x} \vec{v}
Functions\sin x, \log_2 n, \operatorname{rank} A
Words in a formula\text{if } x > 0
Spacinga\,b, a \quad b, a \qquad b
Percent, dollar, degrees5\%, \$5, 90^\circ
Binomial\binom{n}{k}

Matrices

$$
A = \begin{pmatrix} 1 & 2 \\ 3 & 4 \end{pmatrix}
\qquad
\det A = \begin{vmatrix} 1 & 2 \\ 3 & 4 \end{vmatrix} = -2
$$

& separates columns and \\ ends a row. pmatrix, bmatrix, vmatrix and matrix give parentheses, square brackets, determinant bars or no brackets.

Multi-line equations

Use aligned for a derivation: & marks where the lines line up, usually just before the equals sign, and \\ starts a new line.

$$
\begin{aligned}
(a+b)^2 &= (a+b)(a+b) \\
        &= a^2 + 2ab + b^2
\end{aligned}
$$

aligned and align* are unnumbered. align, gather and equation number their lines automatically, (1), (2), (3) through the whole document, and \tag{2.1} sets a number by hand. There is no \label or \eqref: refer to equations by their number.

Piecewise functions

$$
\lvert x \rvert =
\begin{cases}
  x  & \text{if } x \ge 0 \\
  -x & \text{if } x < 0
\end{cases}
$$

Wrap the conditions in \text{}: in math mode, typed spaces are ignored and letters are set as italic variables.

Dollar amounts that are not math

The editor tries hard not to read prices as formulas. A dollar sign opens a formula only if no letter or digit comes right before it, and closes one only if no letter or digit comes right after it. So Tickets cost $5, $10 or $20. prints as written, and US$ 20 is safe too.

Trouble starts when the symbol follows the number: in Costs 5 $ today and 10 $ tomorrow. the two dollar signs pair up, and “today and 10” turns into run-together italics. Two fixes:

  • Escape the sign with a backslash, which doesn’t appear in the output: Costs 5 \$ today and 10 \$ tomorrow.
  • Or put the amount in inline code, `$5`, at the cost of a different font.

Inside a formula, \$ also gives a dollar sign: $\text{total} = \$12 \times n$.

KaTeX is not full LaTeX

KaTeX implements LaTeX’s math mode, not the whole typesetting system. Formulas from a .tex file usually work unchanged; what belongs to the document rather than the formula does not:

  • No preamble, no packages. \documentclass, \usepackage and \begin{document} mean nothing here, and package commands such as \SI (siunitx), \ce (mhchem) or \DeclareMathOperator are unavailable. Write units as text, 9.8\ \text{m/s}^2, simple chemistry as \mathrm{H_2O} and custom operators with \operatorname{argmax}.
  • Some environments are missing. aligned, align, gather, cases, array and the matrices work; multline, eqnarray and tabular don’t. Use aligned, or a Markdown table for tabular data, and keep align, gather and equation in $$ blocks.
  • No cross-references, links or images. \label, \ref, \eqref, \href, \url and \includegraphics show up in red; put links and images in the surrounding Markdown.
  • Macros last one formula. \newcommand and \def work, but each formula starts fresh, so define a shortcut in the block that uses it:
    $$
    \newcommand{\abs}[1]{\left\lvert #1 \right\rvert}
    \abs{x - 1} < \abs{x + 1}
    $$

When in doubt, check KaTeX’s supported functions or its alphabetical support table.

Getting equations onto paper

  • Size. Formulas follow the Font size setting in the Style panel and are drawn slightly larger than the text. Subscripts become hard to read first, so keep math-heavy pages at 11 pt or more.
  • Fonts. Math uses KaTeX’s Computer Modern–style fonts in every theme, in the theme’s text color. The serif themes, Classic and Editorial, match it best.
  • Width. Display equations never wrap. One wider than the text column gets a scrollbar in the preview and is cut off at the right edge of the PDF, so split it with aligned or choose Narrow margins. Inline formulas can wrap after an equals or plus sign, like text.
  • Page breaks. The browser keeps each display equation in one piece, even a ten-line aligned block; if it doesn’t fit, it moves to the next page and leaves a gap. To choose where pages end, put <!-- pagebreak -->, \pagebreak or \newpage alone on a line, outside any formula.
  • Export. Click Download PDF and choose Save as PDF: math prints as text and vector lines, crisp at any zoom. Skip More → Quick PDF for math; it saves pages as images, so formulas lose sharpness and an equation on a page boundary can be cut in two.

Homework, lecture notes and paper drafts

For a problem set, give each problem a ## heading with its solution below, and a page break between problems:

# Problem set 3 — Calculus I

**Name:** Sam Lee · **Due:** March 14

## Problem 1

Find $\displaystyle\lim_{x \to 0} \frac{\sin 3x}{x}$.

**Solution.** Substitute $u = 3x$:

$$
\lim_{x \to 0} \frac{\sin 3x}{x} = 3 \lim_{u \to 0} \frac{\sin u}{u} = 3
$$

<!-- pagebreak -->

## Problem 2

\displaystyle sets an inline limit or sum at full size, with its limits underneath. If your lecture notes live in Obsidian or Notion, the guide to exporting notes to PDF shows how to bring them over; formulas between dollar signs survive the trip.

For a paper draft, the editor is a fast way to send readable equations to a coauthor or advisor. When the final version needs a journal template, a bibliography or numbered cross-references, move to a full LaTeX setup; your formulas come along almost unchanged, because they already are LaTeX.

Troubleshooting

  • The whole formula is red source code. KaTeX couldn’t parse it; hover over it to read the error. Usual causes: a missing }, a \begin{…} without its \end{…}, an & outside an alignment environment, or an environment KaTeX lacks.
  • One command is red, the rest renders. KaTeX doesn’t know it: check the spelling (\alpah) or replace the package command.
  • Dollar signs show up as text. The delimiters didn’t pair: look for a letter or digit right after the closing $, a formula inside backticks, or \(…\). The first formula can also take a moment, because the math engine is downloaded only when a document needs it.
  • A table cell breaks apart. In a Markdown table, | ends the cell even inside a formula; write \lvert x \rvert instead of |x|.
  • Half the formula is missing. % starts a comment in LaTeX, so $50% of x$ shows only “50”. Write \%.

Everything, math rendering included, happens in your browser, so homework and unpublished research never leave your device. For the rest of the syntax, see the Markdown guide.

More guides