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 namedmath
. - 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
totrue
in a project's configuration - To enable KaTex on a per page basis include the parameter
extra.math = true
in content files
Note:
- The MathJax library is the other optional choice, and you can set the parameter
extra.library
tomathjax
in a project's configuration - 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} } } $$