Files
hextra_mirror/exampleSite/content/docs/guide/latex.md
Xin 7031718449 feat(math): add optional MathJax support (#707)
* feat: add MathJax option

* docs: move math engine note

* refactor: update LaTeX documentation and improve MathJax integration

- Adjusted LaTeX documentation for clarity and formatting.
- Enhanced MathJax configuration in the templates to support both KaTeX and MathJax rendering.
- Removed deprecated comments and streamlined the script loading process for MathJax.
- Updated the passthrough extension settings in the Hugo configuration for better compatibility with LaTeX math expressions.

* docs: simplify LaTeX documentation and clarify configuration steps

- Updated LaTeX documentation to reflect that KaTeX is enabled by default, removing the need for manual activation.
- Added examples for using LaTeX math expressions and clarified the configuration for the passthrough extension in Hugo.
- Enhanced MathJax section to emphasize its use as an alternative rendering engine.
2025-06-14 14:36:10 +01:00

2.7 KiB

title, weight
title weight
LaTeX 4

By default, (\KaTeX) is used for rendering LaTeX math expressions. No manual activation is needed, you can start using LaTeX math expressions in your Markdown content right away.

Example

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

Inline

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

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

Separate Paragraph

$$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

For example, using the aligned environment:

$$
\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}

Configuration

Important

Please enable and configure the passthrough extension in the Hugo configuration file, so that Hugo can detect LaTeX math expressions in your Markdown content.

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

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:

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

will be rendered as:

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

Math Engine

MathJax

By default, KaTeX is used for rendering LaTeX math expressions during the build process, which is preferred. Alternatively, you can use MathJax to render math expressions.

To use it instead, add the following to the configuration hugo.yaml file:

params:
  math:
    engine: mathjax