Math and KaTeX
Write equations beside the explanation that makes them useful. MDash uses KaTeX to typeset inline expressions and display equations from LaTeX-style source. You can write delimiters directly or use Insert Equation to check a live preview before inserting.
The Markdown Guide covers the surrounding prose and block syntax.
Table of Contents
Insert or Edit an Equation
- Place the cursor where the equation belongs and choose Insert Equation in the toolbar or command palette.
- Choose a template, such as Fraction, Matrix, or Aligned Steps, or enter an expression such as
\frac{1}{2}in LaTeX Source. Leave out$and$. The dialog adds them. - Choose Inline for an expression within a sentence or Display for a separate equation.
- Check Live Preview and correct any syntax error. On a compact screen, open the Preview tab to see it.
- Choose Insert Equation, or press
Ctrl/⌘ + Enter.
To edit an existing equation, place the cursor inside it and choose Insert Equation. Change the expression or switch between Inline and Display, then choose Update Equation.
Inline Math
Wrap in single dollar signs:
Markdown Source
Pythagoras: $a^2 + b^2 = c^2$.
Rendered Result
Pythagoras: $a^2 + b^2 = c^2$.
Display Math
Wrap in double dollar signs on their own lines:
Markdown Source
$
\int_{-\infty}^{\infty} e^{-x^2}\,dx = \sqrt{\pi}
$
Rendered Result
$ \int_{-\infty}^{\infty} e^{-x^2},dx = \sqrt{\pi} $
Starting $ on its own line is the clearest form. MDash also accepts an opening delimiter immediately after prose, such as Text $, when a standalone closing $ follows. Display delimiters inside fenced code remain code.
How Much Time Is Left?
A 25-minute countdown has been running for 7 minutes and 35 seconds. Convert both times to seconds, subtract the elapsed time, then convert the result back to minutes and seconds. The aligned environment lines up the equals signs, and \text{} keeps the labels and units readable.
Markdown Source
$
\begin{aligned}
t_{\text{total}} &= 25 \times 60 = 1500\,\text{s} \\
t_{\text{elapsed}} &= 7 \times 60 + 35 = 455\,\text{s} \\
t_{\text{left}} &= 1500 - 455 = 1045\,\text{s} \\
&= 17\,\text{min}\;25\,\text{s}
\end{aligned}
$
Rendered Result
$ \begin{aligned} t_{\text{total}} &= 25 \times 60 = 1500,\text{s} \ t_{\text{elapsed}} &= 7 \times 60 + 35 = 455,\text{s} \ t_{\text{left}} &= 1500 - 455 = 1045,\text{s} \ &= 17,\text{min};25,\text{s} \end{aligned} $
There are 17 minutes and 25 seconds left. State the result in prose as well so readers can follow the conclusion without relying on the equation layout.
Greek Letters
| Letter | Source | Result |
|---|---|---|
| Alpha | \alpha | $\alpha$ |
| Delta | \delta | $\delta$ |
| Theta | \theta | $\theta$ |
| Lambda | \lambda | $\lambda$ |
| Pi | \pi | $\pi$ |
| Sigma | \sigma | $\sigma$ |
| Phi | \phi | $\phi$ |
| Omega | \omega | $\omega$ |
Capitalize the command for supported uppercase forms, such as \Delta, \Theta, \Lambda, \Pi, \Sigma, \Phi, or \Omega.
Fractions, Roots, Powers
Markdown Source
$
\frac{1}{1 + e^{-x}}, \quad
\sqrt[3]{\frac{a^2}{b}}, \quad
x^n, \quad x_n
$
Rendered Result
$ \frac{1}{1 + e^{-x}}, \quad \sqrt[3]{\frac{a^2}{b}}, \quad x^n, \quad x_n $
Sums, Products, Integrals
Markdown Source
$
\sum_{n=1}^{\infty} \frac{1}{n^2} = \frac{\pi^2}{6}, \qquad
\prod_{i=1}^{n} i = n!, \qquad
\int_a^b f(x)\,dx
$
Rendered Result
$ \sum_{n=1}^{\infty} \frac{1}{n^2} = \frac{\pi^2}{6}, \qquad \prod_{i=1}^{n} i = n!, \qquad \int_a^b f(x),dx $
Matrices
Markdown Source
$
A = \begin{pmatrix} 1 & 2 \\ 3 & 4 \end{pmatrix}, \qquad
B = \begin{bmatrix} a & b \\ c & d \end{bmatrix}, \qquad
\det = \begin{vmatrix} a & b \\ c & d \end{vmatrix}
$
Rendered Result
$ A = \begin{pmatrix} 1 & 2 \ 3 & 4 \end{pmatrix}, \qquad B = \begin{bmatrix} a & b \ c & d \end{bmatrix}, \qquad \det = \begin{vmatrix} a & b \ c & d \end{vmatrix} $
Aligned Equations
Markdown Source
$
\begin{aligned}
y &= mx + b \\
m &= \frac{y_2 - y_1}{x_2 - x_1}
\end{aligned}
$
Rendered Result
$ \begin{aligned} y &= mx + b \ m &= \frac{y_2 - y_1}{x_2 - x_1} \end{aligned} $
Functions, Text, and Cases
Use named functions such as \sin, \cos, \log, \ln, and \lim so KaTeX applies mathematical spacing and typography.
Markdown Source
$
\sin^2(x) + \cos^2(x) = 1
$
Rendered Result
$ \sin^2(x) + \cos^2(x) = 1 $
Use \text{...} for words inside an expression. Here, $d$ is distance and $t$ is elapsed time.
Markdown Source
Average speed: $v = \frac{d}{t} \quad \text{where } t > 0$.
Rendered Result
Average speed: $v = \frac{d}{t} \quad \text{where } t > 0$.
A cases environment is useful for piecewise definitions:
Markdown Source
$
f(x) =
\begin{cases}
x^2, & x \ge 0 \\
-x, & x < 0
\end{cases}
$
Rendered Result
$ f(x) = \begin{cases} x^2, & x \ge 0 \ -x, & x < 0 \end{cases} $
Accents and Delimiters
| Purpose | Source | Result |
|---|---|---|
| Vector | \vec{v} | $\vec{v}$ |
| Hat | \hat{x} | $\hat{x}$ |
| Bar | \bar{x} | $\bar{x}$ |
| Paired delimiters | \left(\frac{a}{b}\right) | $\left(\frac{a}{b}\right)$ |
| Absolute value | \left\lvert x\right\rvert | $\left\lvert x\right\rvert$ |
Use \,, \:, \;, and \quad when an expression needs intentional spacing. Ordinary spaces in LaTeX-style math are usually ignored.
Common Operators
| Symbol | Code |
|---|---|
| $\le$ | \le |
| $\ge$ | \ge |
| $\neq$ | \neq |
| $\approx$ | \approx |
| $\pm$ | \pm |
| $\times$ | \times |
| $\div$ | \div |
| $\infty$ | \infty |
| $\partial$ | \partial |
| $\nabla$ | \nabla |
| $\rightarrow$ | \rightarrow |
| $\Rightarrow$ | \Rightarrow |
| $\in$ | \in |
| $\notin$ | \notin |
| $\subset$ | \subset |
| $\cup$ | \cup |
| $\cap$ | \cap |
Dollar Signs and Plain Text
Escape dollar signs in prices when a pair of them could be mistaken for inline math.
Markdown Source
Pay \$25 now or \$30 later.
Rendered Result
Pay $25 now or $30 later.
Math delimiters should contain a complete expression. A single unmatched dollar sign remains ordinary text. An unmatched $ also remains visible rather than treating the rest of the document as an equation.
Code fences and inline code are the best way to show math source without rendering it.
Accessibility
Introduce an important expression in words and explain the conclusion after it. KaTeX includes MathML alongside its visual output, which gives compatible assistive technology a mathematical representation, but surrounding prose still provides the clearest context.
Avoid using an equation as the only label for an action or section. Define uncommon variables close to the expression, keep logical reading order in the source, and break very long derivations into smaller steps.
Review exported HTML and PDF in the tools your audience uses. HTML retains the structured KaTeX output, while PDF accessibility depends on the browser print engine and the reader used to open the file.
Limitations and Errors
KaTeX supports a large, practical subset of LaTeX, but it is not a full TeX engine. Document layout commands, custom packages, and some uncommon macros are not available.
If an expression fails, simplify it until the error disappears, then add commands back one at a time. Also check braces, environment names, and backslash escaping.