math-typesetting.mmark 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. ---
  2. author: Hugo Authors
  3. title: Math Typesetting
  4. date: 2019-03-08
  5. description: A brief guide to setup KaTeX
  6. markup: mmark
  7. math: true
  8. ---
  9. Mathematical notation in a Hugo project can be enabled by using third party JavaScript libraries.
  10. <!--more-->
  11. In this example we will be using [KaTeX](https://katex.org/)
  12. - Create a partial under `/layouts/partials/math.html`
  13. - Within this partial reference the [Auto-render Extension](https://katex.org/docs/autorender.html) or host these scripts locally.
  14. - Include the partial in your templates like so:
  15. ```
  16. {{ if or .Params.math .Site.Params.math }}
  17. {{ partial "math.html" . }}
  18. {{ end }}
  19. ```
  20. - To enable KaTex globally set the parameter `math` to `true` in a project's configuration
  21. - To enable KaTex on a per page basis include the parameter `math: true` in content files.
  22. **Note:** Use the online reference of [Supported TeX Functions](https://katex.org/docs/supported.html)
  23. {{< math.inline >}}
  24. {{ if or .Page.Params.math .Site.Params.math }}
  25. <!-- KaTeX -->
  26. <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/katex.min.css" integrity="sha384-dbVIfZGuN1Yq7/1Ocstc1lUEm+AT+/rCkibIcC/OmWo5f0EA48Vf8CytHzGrSwbQ" crossorigin="anonymous">
  27. <script defer src="https://cdn.jsdelivr.net/npm/[email protected]/dist/katex.min.js" integrity="sha384-2BKqo+exmr9su6dir+qCw08N2ZKRucY4PrGQPPWU1A7FtlCGjmEGFqXCv5nyM5Ij" crossorigin="anonymous"></script>
  28. <script defer src="https://cdn.jsdelivr.net/npm/[email protected]/dist/contrib/auto-render.min.js" integrity="sha384-kWPLUVMOks5AQFrykwIup5lo0m3iMkkHrD0uJ4H5cjeGihAutqP0yW0J6dpFiVkI" crossorigin="anonymous" onload="renderMathInElement(document.body);"></script>
  29. {{ end }}
  30. {{</ math.inline >}}
  31. ### Examples
  32. Inline math: $$ \varphi = \dfrac{1+\sqrt5}{2}= 1.6180339887… $$
  33. Block math:
  34. $$
  35. \varphi = 1+\frac{1} {1+\frac{1} {1+\frac{1} {1+\cdots} } }
  36. $$