Add mathjax support in Jekyll with MM theme
Add custom header file
To most accessible way to enable Mathjax
is through a Content Distribution Network (CDN), which you can include in your pages and use it right away.
- Create
custom.html
file atwebsite_root/_include/head/
- Add following contents to the
custom.html
. If the file already exists, attach the contents at the end of the file.
{% if page.mathjax %}
<script src="https://polyfill.io/v3/polyfill.min.js?features=es6"></script>
<script id="MathJax-script" async src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js"></script>
{% endif %}
- The first script is to include
polyfill
library for earlier browser version compatibility. - The second script is to load the latest
3.x.x
version of Mathjax from the server. - The
if
statement setsmathjax
to be a parameter inYAML Front Matter
. This is designed to fasten page loading speed for pages withoutmathjax
requirement.
Set Markdown renderer in config file
- Set
markdown: kramdown
inside_config.yml
Add mathjax
in posts
- Include
mathjax
insideYAML Front Matter
and set it totrue
---
mathjax: true
---
- Use
$$
to enclose equations- inline mode with only
$$
- inline mode with only
This is equation $$ 3^2 + 4^2 = 5^2 $$
This is equation \(3^2 + 4^2 = 5^2\)
- display mode with empty line and
$$
This is equation
$$ 3^2 + 4^2 = 5^2 $$
This is equation
\[3^2 + 4^2 = 5^2\]