Hugo KaTeX Module

Hugo KaTeX Module

KaTeX is the fastest math typesetting library for the web, this module integrates KaTeX with Hugo.

Module
github.com/hugomods/katex
GitHub Stars Used By Used By Used By Used By

Installation

1. Import Module

hugo.yaml

1module:
2  imports:
3  - path: github.com/hugomods/katex

hugo.toml

1[module]
2[[module.imports]]
3    path = 'github.com/hugomods/katex'

hugo.json

1{
2   "module": {
3      "imports": [
4         {
5            "path": "github.com/hugomods/katex"
6         }
7      ]
8   }
9}

Please skip this step if your theme supports HugoPress.

1{{ partial "katex/assets/css" . }}

Please skip this step if your theme supports HugoPress.

1{{ partial "katex/assets/js" . }}

Usage

Using KaTeX via Code Block

1```katex
2FORMULA HERE
3```
$$\tag*{(1)} P(E) = {n \choose k} p^k (1-p)^{n-k}$$
$$f(x) = \int_{-\infty}^\infty\hat f(\xi)\,e^{2 \pi i \xi x}\,d\xi$$

Using KaTeX via Shortcode

ParameterPositionTypeRequiredDefaultDescription
formula#0string--The formula, required when using inline shortcode.
inline#1boolean-falseWhether display inline.

Inline shortcode

1{{< katex [formula] [inline] />}}

Or use closing shortcode

1{{< katex >}}
2FORMULA HERE
3{{< /katex >}}

KaTeX Shortcode Examples

KaTeX Inline Shortcode Example
1Inline formulas: {{< katex formula="a^n" inline=true />}}, {{< katex "a^2+b^2=c^2" true />}}.

Inline formulas: \(a^n\) , \(a^2+b^2=c^2\) .

KaTeX Closing Shortcode Example
1{{< katex >}}
2\begin{array}{l}
3E*{o 1}=\frac{1}{2}\left( { target }*{o 1}- { out }_{o 1}\right)^{2}=\frac{1}{2}(0.01-0.75136507)^{2}=0.274811083 \\
4E_{o 2}=0.023560026 \\
5E*{ {total }}=E*{o 1}+E\_{o 2}=0.274811083+0.023560026=0.298371109
6\end{array}
7{{< /katex >}}
$$ \begin{array}{l} E*{o 1}=\frac{1}{2}\left( { target }*{o 1}- { out }_{o 1}\right)^{2}=\frac{1}{2}(0.01-0.75136507)^{2}=0.274811083 \\ E_{o 2}=0.023560026 \\ E*{ {total }}=E*{o 1}+E\_{o 2}=0.274811083+0.023560026=0.298371109 \end{array} $$