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.

Latex
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.

Latex
$$
\int_{-\infty}^{\infty} e^{-x^2} dx = \sqrt{\pi}
$$

$$
\sum_{n=1}^{\infty} \frac{1}{n^2} = \frac{\pi^2}{6}
$$

Basic operations

Fractions

Latex
$\frac{a}{b}$             — simple fraction
$\dfrac{a}{b}$            — display-style fraction (larger)
$\tfrac{a}{b}$            — text-style fraction (smaller)

Exponents and subscripts

Latex
$x^2$               — superscript
$x_i$               — subscript
$x_i^2$             — both
$x^{2n+1}$          — grouped superscript
$a_{ij}$             — grouped subscript

Roots

Latex
$\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.

Latex
$\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

Latex
$$\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

Latex
$$\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.

Latex
$$
\begin{pmatrix}
a & b \\
c & d
\end{pmatrix}
$$
  • pmatrix — parentheses ( )
  • bmatrix — square brackets [ ]
  • Bmatrix — curly braces
  • vmatrix — vertical bars (determinant)
  • matrix — no brackets

Example: 3x3 Matrix

Latex
$$
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.

Latex
$$
\begin{aligned}
f(x) &= (x+1)^2 \\
     &= x^2 + 2x + 1
\end{aligned}
$$

Common symbols

SymbolCodeDescription
+/-\pmPlus-minus
x\timesMultiplication
/\divDivision
!=\neqNot equal
<=\leqLess than or equal
>=\geqGreater than or equal
~\approxApproximately
inf\inftyInfinity
in\inElement of
not in\notinNot element of
subset\subsetSubset
forall\forallFor all
exists\existsThere exists
->\to or \rightarrowRight arrow
=>\RightarrowImplies

Practical examples

Euler's Identity

Latex
$$e^{i\pi} + 1 = 0$$

Binomial theorem

Latex
$$(x + y)^n = \sum_{k=0}^{n} \binom{n}{k} x^{n-k} y^k$$

Maxwell's Equations

Latex
$$\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.

Try it yourself

Ready to write Markdown with real-time preview, diagrams and math?

Open CodeInk editor