A JavaScript-free Hakyll site

Compiling with KaTeX

November 20, 2018,
keywords: haskell, hakyll, katex

Wanted a Hakyll generated site which prerendered LaTeX\LaTeX so that no JavaScript runs on the client. Hacked this together over a few days and it somehow works!

Inline math looks like this: x+yx+y, and display math looks like the following. i=1npi+qi\prod_{i=1}^{n} p_i + q_i

The unfortunate part is that I still need some JavaScript on the server side. The blog posts are prerendered using KaTeX\KaTeX and relies on the katex binary which got added to my path when I did npm install katex -g.

The KaTeX\KaTeX compiler activates if there is a katex metadata field. The idea is to only enable KaTeX\KaTeX selectively when heavy LaTeX\LaTeX is needed and just use plain pandoc LaTeX\LaTeX otherwise. The KaTeX\KaTeX files are somewhat slow to compile since we spin up a new katex process for each LaTeX\LaTeX expression.

Most of the magic happens in the KaTeX.KaTeXify module. The file ended up being somewhat small since Pandoc suppies most of the functions needed out of the box. In particular, Pandoc provides the walkM function which walks a Pandoc parse tree bottom up.