Skip to content
These are the docs for Clay 4.x. Go to the latest version (5.x)
On this page

Math

Write formulas in LaTeX between dollar signs. Clay typesets them with KaTeX when it builds the site, so pages show them right away, without JavaScript.

#Inline and on their own line

One dollar sign on each side puts a formula into the text:

The area of a circle is $A = \pi r^2$.

The area of a circle is A=πr2A = \pi r^2.

Two dollar signs on lines of their own set a formula apart, centered:

$$
\sum_{i=1}^{n} i = \frac{n(n+1)}{2}
$$
∑i=1ni=n(n+1)2\sum_{i=1}^{n} i = \frac{n(n+1)}{2}

#More examples

$$
\begin{pmatrix} a & b \\ c & d \end{pmatrix}
\begin{pmatrix} x \\ y \end{pmatrix}
=
\begin{pmatrix} ax + by \\ cx + dy \end{pmatrix}
$$
(abcd)(xy)=(ax+bycx+dy)\begin{pmatrix} a & b \\ c & d \end{pmatrix} \begin{pmatrix} x \\ y \end{pmatrix} = \begin{pmatrix} ax + by \\ cx + dy \end{pmatrix}
$$
f(x) = \begin{cases} x^2 & \text{if } x \ge 0 \\ -x & \text{otherwise} \end{cases}
$$
f(x)={x2if x≥0−xotherwisef(x) = \begin{cases} x^2 & \text{if } x \ge 0 \\ -x & \text{otherwise} \end{cases}

KaTeX lists every command it knows in its documentation.

#Dollar signs in text

Prices stay text. A dollar sign only starts a formula when no space follows it, and only ends one when no space comes before it and no digit after it: “It costs $5 and $10” is text. To write a dollar sign that would start a formula, put a backslash before it: \$.

#Mistakes

A formula KaTeX cannot read is shown in red with its source, instead of failing the build, so you see it on the page: \frac{1.

#Accessibility and size

  • Every formula is also written as MathML, which screen readers read out.
  • Wide formulas scroll sideways on small screens instead of widening the page.
  • The fonts for formulas only load on pages that have math.