Hugo does not support \(\LaTeX\) natively, and MMark
has been deprecated, the reason why I choose \( \KaTeX \) is because Mathjax is a bit slower when rendering compared to \( \KaTeX \). (KaTeX)
This post is a tutorial shows how to add \( \KaTeX \) support to your Hugo blog system.
Create Math Partial in themes folder
First create a partial layout named math.html
in Hugo themes
folder, and in this file add:
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/katex@0.12.0/dist/katex.min.css"
integrity="sha384-AfEj0r4/OFrOo5t7NnNe46zW/tFgW6x/bCJG8FqQCEo3+Aro6EYUG4+cU+KJWu/X" crossorigin="anonymous">
<script defer src="https://cdn.jsdelivr.net/npm/katex@0.12.0/dist/katex.min.js"
integrity="sha384-g7c+Jr9ZivxKLnZTDUhnkOnsh30B4H0rpLUpJ4jAIKs4fnJI+sEnkvrMWph2EDg4"
crossorigin="anonymous"></script>
<script defer src="https://cdn.jsdelivr.net/npm/katex@0.12.0/dist/contrib/auto-render.min.js"
integrity="sha384-mll67QQFJfxn0IYznZYonOWZ644AWYC+Pt2cHqMaRhXVrursRwvLnLaebdGIlYNa" crossorigin="anonymous"
onload="renderMathInElement(document.body);"></script>
Use Math Partial
In themes/theme_name/layouts/posts/single.html
(in my case: /themes/PaperMod/layouts/_default/single.html
), add:
{{ if or .Params.math .Site.Params.math }}
{{ partial "math.html" . }}
{{ end }}
Add LaTeX to posts
Add math: true
to your posts, and then done.
To use \(\LaTeX\), $$ your formula $$
, for in line \(\LaTeX\): \\( your formula \\)
.
Reference: Equations with KaTeX in Hugo