Einbindung MathJax in hugo

Page content

See https://stackoverflow.com/questions/64050359/how-to-use-markdown-syntax-to-write-math-in-hugo or here : https://bwaycer.github.io/hugo_tutorial.hugo/tutorials/mathjax/

Add these line

<script src="https://polyfill.io/v3/polyfill.min.js?features=es6"></script>
<script id="MathJax-script" async src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js"></script>

To the layout file of your hugo template. I use theme mainroad, and added the lines in themes/mainroad/layouts/_default/baseof.html, in head-section of html.

Tests

$$f_{res} = \frac{1}{2\pi\sqrt{LC}}$$

This shows as Mathjax \(a \ne b\), but this doesn’t (a \ne b)

Likewise, this shows as Mathjax

\[a \ne b\]

but this doesn’t:

[a \ne b]

$\sum_{i=0}^n i^2 = \frac{(n^2+n)(2n+1)}{6}$

$$\sum_{i=0}^n i^2 = \frac{(n^2+n)(2n+1)}{6}$$

\lt \gt \le \ge \neq <, >, ≤, ≥,≠. You can use \not to put a slash through almost anything: \not\lt ≮ but it often looks bad.

\times \div \pm \mp ×, ÷, ±, ∓. \cdot is a centered dot: x⋅y

\cup \cap \setminus \subset \subseteq \subsetneq \supset \in \notin \emptyset \varnothing ∪, ∩, ∖, ⊂, ⊆, ⊊, ⊃, ∈, ∉, ∅, ∅

{n+1 \choose 2k} or \binom{n+1}{2k} (n+12k)

\to \gets \rightarrow \leftarrow \Rightarrow \Leftarrow \mapsto \implies \iff →, ←, →, ←, ⇒, ⇐, ↦, ⟹, ⟺

\land \lor \lnot \forall \exists \top \bot \vdash \vDash ∧, ∨, ¬, ∀, ∃, ⊤, ⊥, ⊢, ⊨

\star \ast \oplus \circ \bullet ⋆, ∗, ⊕, ∘, ∙

\approx \sim \simeq \cong \equiv \prec \lhd ≈, ∼, ≃, ≅, ≡, ≺, ⊲

\infty \aleph_0 ∞ℵ0 \nabla \partial ∇, ∂ \Im \Re I, R

For modular equivalence, use \pmod like this: a\equiv b\pmod n a≡b(modn). For the binary mod operator, use \bmod like this: a\bmod 17 amod17.

Use \dots for the triple dots in a1,a2,…,an and a1+a2+⋯+an

Script lowercase l is \ell ℓ.

Matrix: $$ \begin{matrix} 1 & x & x^2 \\
1 & y & y^2 \\
1 & z & z^2 \\
\end{matrix} $$

Equation solving: $$ \begin{align} \sqrt{37} & = \sqrt{\frac{73^2-1}{12^2}} \\
& = \sqrt{\frac{73^2}{12^2}\cdot\frac{73^2-1}{73^2}} \\
& = \sqrt{\frac{73^2}{12^2}}\sqrt{\frac{73^2-1}{73^2}} \\
& = \frac{73}{12}\sqrt{1 - \frac{1}{73^2}} \\
& \approx \frac{73}{12}\left(1 - \frac{1}{2\cdot73^2}\right) \end{align} $$

Cases: $$ f(n) = \begin{cases} n/2, & \text{if $n$ is even} \\
3n+1, & \text{if $n$ is odd} \end{cases} $$

Commutative diagrams: $$ $\require{AMScd}$ \begin{CD} A @»> B @>{\text{very long label}}» C \\
@. @AAA @| \\
D @= E @«< F \end{CD} $$

Sum: $$\sum_{n=1}^\infty \frac{1}{n^2} \to \textstyle \sum_{n=1}^\infty \frac{1}{n^2} \to \displaystyle \sum_{n=1}^\infty \frac{1}{n^2}$$

Numbered equations: $$\begin{align} a &= b + c \tag{3}\label{eq3} \\
x &= yz \tag{4}\label{eq4}\\
l &= m - n \tag{5}\label{eq5} \end{align}$$

Further Reading

MathJax documentation - https://docs.mathjax.org/en/latest/index.html

Latex math - https://libguides.eur.nl/overleaf/mathematics#:~:text=To%20write%20text%20as%20a,the%20text%20in%20curly%20brackets.&text=The%20symbol%20%22%26%22%20on%20its,simply%20use%20the%20%5C%26%20command.

Tutorial and Reference - https://math.meta.stackexchange.com/questions/5020/mathjax-basic-tutorial-and-quick-reference

Rune guessing - http://detexify.kirelabs.org/classify.html