Use Mathjax on Hugo
Tex/LaTex allows simple construction of mathematical formulae, while looking professional when printed.
Ref. Wikibook | LaTex/Mathematics
Although I wanted to write fine math formula on this page, it was a little subtle configuration to work finely.
KaTex
I firstly tried to implement KaTex. Katex
supports tidy Tex description.
Configuration
I followed a configuration in example site of Hugo LoveIt theme that embeds KaTex.
config.toml
|
|
Problem
I could write by KaTex both in inline and block code.
However, KaTex
on Hugo has some problem (for my page) that it could not render some block document especially in \bigin
and \end
block for unknown reasons.
For example, below could not be rendered.
|
|
It seems some bug related in multi-line block bug on LoveIt theme on Hugo that I’m using is fixed, I could not find right way.
MathJax
Then I found MathJax, A JavaScript display engine for mathematics.
Configuration
The instruction at Geoff Ruddock | About Blog Notebooks Icon by flaticon.com/authors/edtimRender LaTeX math expressions in Hugo with MathJax 3 was helpful.
The directory structure may depend on layout theme.
layouts/partials/plugin/mathjax_support.html (newly created)
|
|
layouts/partials/head/mathjax.html (newly created)
|
|
layouts/_default/baseof.html (updated)
|
|
Then add mathjax: true
to the YAML frontmatter of any pages to enable MathJax.
Examples
Inline
|
|
$ c = \pm\sqrt{a^2 + b^2} $
$ f(x)=\int_{-\infty}^{\infty} \hat{f}(\xi) e^{2 \pi i \xi x} d \xi $
$ \rho \frac{\mathrm{D} \mathbf{v}}{\mathrm{D} t}=\nabla \cdot \mathbb{P}+\rho \mathbf{f} $
Block
|
|
$$ \mathbf{E}=\sum_{i} \mathbf{E}_{i}=\mathbf{E}_{1}+\mathbf{E}_{2}+\mathbf{E}_{3}+\cdots $$
$$
\begin{matrix}
a & b \
c & d \
\end{matrix}
$$
$$
\begin{alignat}{2}
10&x+&3&y = 2 \\
3&x+&13&y = 4
\end{alignat}
$$
$$
\begin{gather}
a=b \\
e=b+c
\end{gather}
$$
$$
\begin{CD}
A @>a>> B \\
@VbVV @AAcA \\
C @= D
\end{CD}
$$
By chance, Github started to Support MathJax before two days