Adding mathjax

Published: Friday, 3 July 2020
  • Jurn Ho

If only some Hugo pages require MathJax then it is possible to enable this via the front matter configuration.

Edit page front matter

Decide on the front matter property name. In this case mathjax is used.

For pages that require MathJax, add mathjax: true

title: "A page needing MathJax"
date: 2015-01-21
draft: false
mathjax: true

to the front matter

Import MathJax JavaScript

Add to the <head> template

    // omitted for brevity
    {{ if .Params.MathJax }}
    <script src=""></script>
    <script id="MathJax-script" async src=""></script>
    {{ end }}

Edit page markdown

Inline Mathjax uses \( and \) to delimit expressions, but since Hugo requires \ to be escaped use \\ instead.

Avogadro's constant is \\( 6.02 * 10^{23} \\)

Block level MathJax doesn’t need to be escaped, the unescaped $$ delimiter is sufficient.