As a (retired) mathematician, I want to write mathematical notation on my blog, and since LaTeX is the least evil to do so, I want to have LaTeX support on my blog.

The simplest way to do so seems to be KaTeX; altough please tell me if you know something better!

Including KaTeX in my blog - The simple way

That’s the way I am currently working with. Just add the following lines to my your head.html partial:

<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/katex@0.16.0/dist/katex.min.css" integrity="sha384-Xi8rHCmBmhbuyyhbI88391ZKP2dmfnOl4rT9ZfRI7mLTdk1wblIUnrIq35nqwEvC" crossorigin="anonymous">
<script defer src="https://cdn.jsdelivr.net/npm/katex@0.16.0/dist/katex.min.js" integrity="sha384-X/XCfMm41VSsqRNQgDerQczD69XqmjOOOwYQvr/uuC+j4OPoNhVgjdGFwhvN02Ja" crossorigin="anonymous"></script>
<script defer src="https://cdn.jsdelivr.net/npm/katex@0.16.0/dist/contrib/auto-render.min.js" integrity="sha384-+XBljXPPiv+OzfbB3cVmLHf4hdUFHlWNZN5spNQ7rmHTXpd7WvJum6fIACpNNfIR" crossorigin="anonymous"></script>
<script>
    document.addEventListener("DOMContentLoaded", function() {
        renderMathInElement(document.body, {
        // customised options
        // • auto-render specific keys, e.g.:
        delimiters: [
            {left: '$$', right: '$$', display: true},
            {left: '$', right: '$', display: false},
            {left: '\\(', right: '\\)', display: false},
            {left: '\\[', right: '\\]', display: true}
        ],
        // • rendering keys, e.g.:
        throwOnError : false
        });
    });
</script>

And that’s all, you are good to go!

A note of caution

If you want to do a multiline something, you have to escape backslashes.

The following KaTeX rendering:

$$ 42 \\ 43 $$

… looks like that:

$$ 42 \\\\ 43 $$

Potential improvements

  • I would prefer my website to be self-contained. Hence I should probably host KaTeX next to my own files. This is not there yet, but an improvement I am planning to do.
  • Also, I would like to keep on the latest version of KaTeX. This might be doable with Renovate, altough I don’t yet know how…
    There will be an update if I find out.
  • In the future, I might only include the KaTeX style only on sites where math occurs, making the blog load faster.