LaTeX

$\KaTeX$ is used for rendering LaTeX math expressions. It can be enabled per page by setting math to true in the page front matter.

page.md
---
title: "My Page with LaTeX"
math: true
---

When enabled, the scripts, stylesheets and fonts from KaTeX will be included automatically in your site. You can start using LaTeX math expressions in your Markdown content.

Example

Both inline and separate paragraph LaTeX math expressions are supported in the Markdown content.

Inline

page.md
This $\sigma(z) = \frac{1}{1 + e^{-z}}$ is inline.

This $\sigma(z) = \frac{1}{1 + e^{-z}}$ is inline.

Separate Paragraph

page.md
$$F(\omega) = \int_{-\infty}^{\infty} f(t) e^{-j\omega t} \, dt$$

will be rendered as:

$$F(\omega) = \int_{-\infty}^{\infty} f(t) e^{-j\omega t} , dt$$

Important

Please enable and configure the passthrough extension in the Hugo configuration file. It preserves raw content within the delimiters to avoid rendering issues for complex expressions.

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

For example, using the aligned environment:

page.md
$$
\begin{aligned}
  \nabla \cdot \mathbf{E} &= \frac{\rho}{\varepsilon_0} \\
  \nabla \cdot \mathbf{B} &= 0 \\
  \nabla \times \mathbf{E} &= -\frac{\partial \mathbf{B}}{\partial t} \\
  \nabla \times \mathbf{B} &= \mu_0 \left( \mathbf{J} + \varepsilon_0 \frac{\partial \mathbf{E}}{\partial t} \right)
\end{aligned}
$$

will be rendered as:

$$ \begin{aligned} \nabla \cdot \mathbf{E} &= \frac{\rho}{\varepsilon_0} \ \nabla \cdot \mathbf{B} &= 0 \ \nabla \times \mathbf{E} &= -\frac{\partial \mathbf{B}}{\partial t} \ \nabla \times \mathbf{B} &= \mu_0 \left( \mathbf{J} + \varepsilon_0 \frac{\partial \mathbf{E}}{\partial t} \right) \end{aligned} $$

Supported Functions

For a list of supported functions, see KaTeX supported functions.

Chemistry

Chemistry expressions are supported via mhchem extension.

Inline: $\ce{H2O}$ is water.

Separate paragraph:

page.md
$$\ce{Hg^2+ ->[I-] HgI2 ->[I-] [Hg^{II}I4]^2-}$$

$$\ce{Hg^2+ ->[I-] HgI2 ->[I-] [Hg^{II}I4]^2-}$$