Typesetting Math with KaTeX

1 min read

Math is a first-class citizen on this blog. Thanks to remark-math and rehype-katex, you can write LaTeX directly in Markdown and get properly typeset output.

Inline math

Wrap an expression in single dollar signs to render it inline, like E=mc2E = mc^2 or the quadratic formula x=−b±b2−4ac2ax = \frac{-b \pm \sqrt{b^2 - 4ac}}{2a}.

Display math

For a standalone equation, put $$ on its own line:

∫abf(x) dx=F(b)−F(a)\int_{a}^{b} f(x)\,dx = F(b) - F(a)

The definition of the Gaussian integral is another classic:

∫−∞∞e−x2 dx=π\int_{-\infty}^{\infty} e^{-x^2}\,dx = \sqrt{\pi}

Matrices and summations

KaTeX handles more advanced notation too. Here is a matrix:

A=(a11a12a21a22)A = \begin{pmatrix} a_{11} & a_{12} \\ a_{21} & a_{22} \end{pmatrix}

And a summation with limits:

∑n=1∞1n2=π26\sum_{n=1}^{\infty} \frac{1}{n^2} = \frac{\pi^2}{6}

A note on escaping

Because $ is the delimiter, avoid using a lone dollar sign in prose unless you mean to open math. If you need a literal one, escape it as \$.

Math rendering happens at build time, so there is no client-side JavaScript cost — the HTML ships with the equations already typeset.

Written by

  • Fajar

    Fajar

    DevOps / Platform Engineer @ PT Mastersystem Infotama

Subscribe to the Newsletter

Get the latest posts delivered right to your inbox.

Comments

Comments