keywords:hugo, KaTex, Math Equation, Mathematics

Steps:

  • Create a partial under /layouts/partials/math.html.
  • Within this partial reference the Auto-render Extension or host these scripts locally.
    e.g. in /layouts/partials/math.html:

    
    
    
  • Add source in your your templates, e.g. theme's header.html:

    {{ if or .Params.math .Site.Params.math }}
    {{ partial "math.html" . }}
    {{ end }}
  • Enable math in your content files.

    markup= "mmark"
    math= "true"

Then KaTex would works, Testing:

$$\varphi = 1+\frac{1} {1+\frac{1} {1+\frac{1} {1+\cdots} } }$$

\[\varphi = 1+\frac{1} {1+\frac{1} {1+\frac{1} {1+\cdots} } }\]

Reference

Supported Functions
https://katex.org/docs/supported.html

Math Typesetting
https://github.com/gohugoio/hugoBasicExample/blob/master/content/post/math-typesetting.mmark


我曾想把梅西打造为世界最佳球员,但梅西却把我送上了世界最佳教练的宝座上。 ——瓜迪奥拉