Math Typesetting

Posted 2021-04-08 05:19:42 by Public ‐ 1 min read

Mathematical notation in a project can be enabled by using third party JavaScript libraries.

In this example we will be using KaTeX

  • Create a macro under /template/macros/math.html with a macro named math.
  • Within this macro reference the Auto-render Extension or host these scripts locally.
  • Import the macro in your templates like so:
{% import 'macros/math.html' as macros %}
{% if page.extra.math or section.extra.math or config.extra.math %}
{{ macros::math() }}
{% endif %}
  • To enable KaTex globally set the parameter extra.math to true in a project's configuration
  • To enable KaTex on a per page basis include the parameter extra.math = true in content files

Note:

  1. The MathJax library is the other optional choice, and you can set the parameter extra.library to mathjax in a project's configuration
  2. Use the online reference of Supported TeX Functions

Examples

Inline math: \(\varphi = \dfrac{1+\sqrt5}{2}= 1.6180339887…\)

Block math: $$ \varphi = 1+\frac{1} {1+\frac{1} {1+\frac{1} {1+\cdots} } } $$