Math Typesetting

For math typesetting in a Hugo project, you can leverage hugo’s internal KaTeX\KaTeX rendering engine.

If you want to use mathematical or chemical equations in your site, enable the Goldmark passthrough extension and define delimiters for block and inline formulae in your config file:

hugo.toml

[markup]
  [markup.goldmark]
    [markup.goldmark.extensions]
      [markup.goldmark.extensions.passthrough]
        enable = true
        [markup.goldmark.extensions.passthrough.delimiters]
          block = [['\[', '\]'], ['$$', '$$']]
          inline = [['\(', '\)']]

Afterwards you can author formulae using the standard LaTeX\LaTeX syntax:

Examples

Inline math: φ=1+52=1.6180339887\varphi = \dfrac{1+\sqrt5}{2}= 1.6180339887…

Block math:

φ=1+11+11+11+(1) \tag*{(1)} \varphi = 1+\frac{1} {1+\frac{1} {1+\frac{1} {1+\cdots}}}

Chemical equations:

ZnX2++2HX++2OHXZn(OH)X2amphoteric hydroxide+2HX++2OHX[Zn(OH)X4]X2tetrahydroxozincate(2) \tag*{(2)} \ce{Zn^2+ <=>[+ 2OH-][+ 2H+] $\underset{\text{amphoteric hydroxide}}{\ce{Zn(OH)2 v}}$ <=>[+ 2OH-][+ 2H+] $\underset{\text{tetrahydroxozincate}}{\ce{[Zn(OH)4]^2-}}$}

Note: Use the online reference of Supported TeX Functions

Mathematical formulae inside code blocks

As an alternative to the standard syntax used above, formulae can also be authored using a GLFM math block:

The probability of getting \(k\) heads when flipping \(n\) coins is:

```math
\tag*{(1)} P(E) = {n \choose k} p^k (1-p)^{n-k}
```

This math block renders to:

The probability of getting kk heads when flipping nn coins is:

P(E)=(nk)pk(1p)nk(1)\tag*{(1)} P(E) = {n \choose k} p^k (1-p)^{n-k}

Chemical equations inside code blocks

You can use a code block adorned with chem in order to render a chemical equation:

```chem
\tag*{(2)} \ce{Hg^2+ ->[I-]  $\underset{\mathrm{red}}{\ce{HgI2}}$  ->[I-]  $\underset{\mathrm{red}}{\ce{[Hg^{II}I4]^2-}$}
```

This chem block renders to:

HgX2+IXHgIX2redIX[HgXIIIX4]X2red(2)\tag*{(2)} \ce{Hg^2+ ->[I-] $\underset{\mathrm{red}}{\ce{HgI2}}$ ->[I-] $\underset{\mathrm{red}}{\ce{[Hg^{II}I4]^2-}}$}