- 3 minutes read
\KaTeX is a JavaScript library to render formulas in Mathematics, Physics, and Chemistry, and probably several related realms. It shows how much technology has evolved since I wrote my diploma thesis. At the time (well, 1996), I wrote the text in the LaTeX language. Before I could see the result, I had to compile it. That took several minutes. Nowadays, \KaTeX would probably display render the whole text in a few seconds.

Only it wouldn't. \KaTeX renders HTML pages, but it doesn't render an entire document. I didn't find support for page numbers or chapters, nor did I find \tableofcontents command in the list of supported functions. It doesn't support commutative diagrams yet. If you need these diagrams, have a look at MathJax and tikzcd.

Mathematical formulas

Here's a small collections of mathematical formulas rendered by \KaTeX:

f(x) = \int_{-\infty}^\infty\hat f(\xi)\,e^{2 \pi i \xi x}\,d\xi


\frac{1}{\Bigl(\sqrt{\phi \sqrt{5}}-\phi\Bigr) e^{\frac25 \pi}} = 1+\frac{e^{-2\pi}} {1+\frac{e^{-4\pi}} {1+\frac{e^{-6\pi}} {1+\frac{e^{-8\pi}} {1+\cdots} } } }

I've found these examples at tiddlywiki.com. That page also has several more examples.

Chemical formulas

\KaTeX ships with the mhchem extension, so it also renders chemical formulas:

\ce{H+ + OH- <=> H2O}



\ce{Zn^2+ <=>[+ 2OH-][+ 2H+] $\underset{\text{amphoteres Hydroxid}}{\ce{Zn(OH)2 v}}$ <=>[+ 2OH-][+ 2H+] $\underset{\text{Hydroxozikat}}{\ce{[Zn(OH)4]^2-}}$}

You can find many more examples at mhchem.github.io/MathJax-mhchem/.

Angular, React.js, Vue.js, and node.js

There are wrapper libraries for Angular, React, Vue, and several others. You can also use \KaTeX in node.js on the server side. See the full list of extensions on the \KaTeX documentation pages. However, it's also very easy to use the core library, as this page demonstrates.


Comments