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.htmlfile 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
polyfilllibrary for earlier browser version compatibility. - The second script is to load the latest
3.x.xversion of Mathjax from the server. - The
ifstatement setsmathjaxto be a parameter inYAML Front Matter. This is designed to fasten page loading speed for pages withoutmathjaxrequirement.
Set Markdown renderer in config file
- Set
markdown: kramdowninside_config.yml
Add mathjax in posts
- Include
mathjaxinsideYAML Front Matterand 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\]