How to display math expression on the pages using Jekyll
How to render Markdown math expressions on the GitHub Pages site using Jekyll
Ensure Kramdown is the Markdown Processor: GitHub Pages uses Kramdown as the default Markdown processor, which supports LaTeX-style math syntax. Verify that the
_config.yml
file does not specify a different processor. If it does, remove or comment out themarkdown
line to use the default Kramdown processor. (alanduan.me)- Include the MathJax Script: MathJax is a JavaScript library that renders LaTeX math expressions in web pages. To include MathJax in the Jekyll site:
- Create a file named
mathjax.html
in the_includes
directory with the following content:1 2 3
<script type="text/javascript" id="MathJax-script" async src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js"> </script>
- In the
_layouts/default.html
file, include themathjax.html
file within the<head>
section:1 2 3 4 5 6
<script type="text/javascript" id="MathJax-script" async src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js"> </script>
- Create a file named
- Enable MathJax in Specific Pages: To enable MathJax on pages for math expression:
- In the front matter of the Markdown file, add:
1 2 3 4 5 6
--- layout: post title: the Post Title date: 2025-01-31 mathjax: true ---
- In the front matter of the Markdown file, add:
- Write Math Expressions: Use LaTeX syntax to write math expressions in the Markdown files:
- Inline math:
1
This is an inline math expression: $$a^2 + b^2 = c^2$$.
This is an inline math expression: \(a^2 + b^2 = c^2\).
- Display math:
1 2
This is a display math expression: \begin{equation}\int_{a}^{b} f(x) \, dx\end{equation}
This is a display math expression: \begin{equation}\int_{a}^{b} f(x) \, dx\end{equation} (jojozhuang.github.io)
- Inline math:
- Handle Potential Conflicts: Be aware that some Markdown processors may interfere with MathJax rendering. If issues exist, consider using the
raw
andendraw
tags to prevent the processor from interpreting math syntax:1
$$a^2 + b^2 = c^2$$
This post is licensed under CC BY 4.0 by the author.