Skip to content
mdbin
Documentation menu

docs/math

Math

Write math in LaTeX between dollar signs and it is typeset with KaTeX when the document is read — the same syntax HedgeDoc and HackMD use, so documents written there render the same here.

Inline math

Wrap an expression in single dollar signs to typeset it inside a sentence:

Einstein's $E = mc^2$ relates mass and energy.

Display math

Put $$ on a line of its own above and below an expression to show it as a centred block:

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

A short block can sit on one line: $$x^2 + y^2 = z^2$$.

  • A block may not contain blank lines.
  • A $$ with no closing $$ (before a blank line, a code fence or the end of a list item or quote) stays plain text, and everything after it renders as normal.
  • $$…$$ in the middle of a sentence is shown as a centred block too.

Dollar signs that stay dollars

Ordinary dollar signs are left alone:

  • A closing $ directly followed by a digit or letter is never a delimiter, so prices like $5 and $10 and shell variables like $HOME/$PATH stay text.
  • Code is not math: `$x$` and fenced code blocks show their dollar signs as written — as long as no $ earlier on the line opens math that runs into the code span.
  • Write \$ for a literal dollar sign anywhere.

A dollar sign followed by a space is read as an opening delimiter, so $ 5 and $ 10 becomes math. Escape those as \$ 5 and \$ 10.

Math in tables

A | splits a table cell, even inside math. Use \vert or \mid instead:

| Set | Definition |
| --- | --- |
| Evens | $\{ n \mid n \bmod 2 = 0 \}$ |

What's supported

Everything in KaTeX's list of supported functions: fractions, roots, sums and integrals, matrices, aligned environments, Greek letters, accents, colours and the rest. A few things are deliberately off:

  • \href, \url, \includegraphics and the \html… commands are disabled — they show in red as unsupported — so math can never become a link or markup.
  • There is no ```math fence, and \(…\) and \[…\] are not delimiters.
  • A \def lasts only for the expression it is written in.

Errors

An expression KaTeX can't parse is shown in red, with the problem as its hover text. The rest of the document renders as normal.

Limits

To keep a single document from slowing every reader's browser:

  • A document typesets at most 1,000 expressions, of up to 10,000 characters each and 50,000 in total. Math past those limits is shown as its source.
  • Extreme sizes — a \kern, \raisebox or similar beyond about 50em — are shown as source, and any length above 10em is capped.

Where it renders

Math is typeset on the document page and in the editor's preview. Raw, .md and link previews show the source, and comments don't render math.