Writing math in Markdown with KaTeX
CodeInk supports KaTeX for rendering LaTeX math expressions directly in Markdown. KaTeX is fast, lightweight, and renders math with the same quality as LaTeX. This guide covers everything you need to write math in your Markdown documents.
Inline math
Use single dollar signs to write math inline with your text. The expression renders on the same line as the surrounding text.
The equation $E = mc^2$ changed physics forever.
The quadratic formula is $x = \frac{-b \pm \sqrt{b^2 - 4ac}}{2a}$. Inline math is perfect for referencing variables, simple formulas, or notation within a sentence.
Display math
Use double dollar signs for standalone equations that appear centered on their own line. Display math is ideal for important formulas that deserve visual emphasis.
$$
\int_{-\infty}^{\infty} e^{-x^2} dx = \sqrt{\pi}
$$
$$
\sum_{n=1}^{\infty} \frac{1}{n^2} = \frac{\pi^2}{6}
$$ Basic operations
Fractions
$\frac{a}{b}$ — simple fraction
$\dfrac{a}{b}$ — display-style fraction (larger)
$\tfrac{a}{b}$ — text-style fraction (smaller) Exponents and subscripts
$x^2$ — superscript
$x_i$ — subscript
$x_i^2$ — both
$x^{2n+1}$ — grouped superscript
$a_{ij}$ — grouped subscript Roots
$\sqrt{x}$ — square root
$\sqrt[3]{x}$ — cube root
$\sqrt[n]{x}$ — nth root Greek letters
Greek letters are frequently used in math, science, and engineering. KaTeX supports all Greek letters.
$\alpha$ $\beta$ $\gamma$ $\delta$ $\epsilon$
$\zeta$ $\eta$ $\theta$ $\iota$ $\kappa$
$\lambda$ $\mu$ $\nu$ $\xi$ $\pi$
$\rho$ $\sigma$ $\tau$ $\upsilon$ $\phi$
$\chi$ $\psi$ $\omega$ Capitalize the first letter for uppercase: $\Gamma$, $\Delta$, $\Theta$, $\Lambda$, $\Pi$, $\Sigma$, $\Phi$, $\Psi$, $\Omega$.
Common operators
Sums, products, and integrals
$$\sum_{i=1}^{n} x_i$$ — summation
$$\prod_{i=1}^{n} x_i$$ — product
$$\int_a^b f(x)\,dx$$ — definite integral
$$\iint_D f(x,y)\,dA$$ — double integral
$$\oint_C \vec{F} \cdot d\vec{r}$$ — line integral Limits
$$\lim_{x \to \infty} \frac{1}{x} = 0$$
$$\lim_{x \to 0^+} \ln(x) = -\infty$$ Matrices
KaTeX supports several matrix environments with different bracket styles.
$$
\begin{pmatrix}
a & b \\
c & d
\end{pmatrix}
$$ pmatrix— parentheses( )bmatrix— square brackets[ ]Bmatrix— curly bracesvmatrix— vertical bars (determinant)matrix— no brackets
Example: 3x3 Matrix
$$
A = \begin{bmatrix}
1 & 2 & 3 \\
4 & 5 & 6 \\
7 & 8 & 9
\end{bmatrix}
$$ Alignment and multi-line equations
Use the aligned environment to align equations at the & sign.
$$
\begin{aligned}
f(x) &= (x+1)^2 \\
&= x^2 + 2x + 1
\end{aligned}
$$ Common symbols
| Symbol | Code | Description |
|---|---|---|
| +/- | \pm | Plus-minus |
| x | \times | Multiplication |
| / | \div | Division |
| != | \neq | Not equal |
| <= | \leq | Less than or equal |
| >= | \geq | Greater than or equal |
| ~ | \approx | Approximately |
| inf | \infty | Infinity |
| in | \in | Element of |
| not in | \notin | Not element of |
| subset | \subset | Subset |
| forall | \forall | For all |
| exists | \exists | There exists |
| -> | \to or \rightarrow | Right arrow |
| => | \Rightarrow | Implies |
Practical examples
Euler's Identity
$$e^{i\pi} + 1 = 0$$ Binomial theorem
$$(x + y)^n = \sum_{k=0}^{n} \binom{n}{k} x^{n-k} y^k$$ Maxwell's Equations
$$\nabla \cdot \vec{E} = \frac{\rho}{\epsilon_0}$$
$$\nabla \times \vec{B} = \mu_0 \vec{J} + \mu_0 \epsilon_0 \frac{\partial \vec{E}}{\partial t}$$ All KaTeX expressions above work in CodeInk with real-time rendering. For more Markdown syntax, check our Markdown Cheat Sheet. To add diagrams to your documents, see the Mermaid Diagrams Guide.