Adding Math Equation Support to Jekyll Theme
As someone majoring in physics and mathematics, I became to needequation support for my blog posts. When searching for Jekyll theme and equation input together, many examples come up, but they don’t distinguish between using a remote theme versus cloning the entire theme git repository. While ultimately it doesn’t matter, as a beginner using a remote theme, I couldn’t help but worry:
“If the files don’t exist, should I download them all now? What if all my current settings get overwritten in the process?”
(This post was written before deciding to get the entire repo). Fortunately, Jan Meppe’s blog clearly explained which parts need to be modified when using a remote theme, so I followed those instructions. (I excluded Step 1 from the original blog as it seemed unnecessary here.)
Step 1. Copy scripts.html
First, to change settings, you don’t need to copy all files. For remote themes, it seems to only fetch files that don’t exist in your github repository, so you just need to copy and modify the files you need. It’s similar to how we only modified the assets/css/main.scss file when initially setting up the blog’s fonts and font sizes.
Anyway, what you need is to copy the minimal-mistakes/_includes/scripts.html file from the Minimal Mistakes repo to _includes/scripts.html in your local repository.
Step 2. Modify scripts.html
Next, add the following code to the scripts.html file:
<script type="text/javascript" async
src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/latest.js?config=TeX-MML-AM_CHTML">
</script>
<script type="text/x-mathjax-config">
MathJax.Hub.Config({
extensions: ["tex2jax.js"],
jax: ["input/TeX", "output/HTML-CSS"],
tex2jax: {
inlineMath: [ ['$','$'], ["\\(","\\)"] ],
displayMath: [ ['$$','$$'], ["\\[","\\]"] ],
processEscapes: true
},
"HTML-CSS": { availableFonts: ["TeX"] }
});
</script>
Step 3. Using Latex Syntax
Now you can use Latex syntax to input equations in your Markdown files. For math mode within sentences, use the $ symbol or \\( \\). For equation mode, wrap your equations with $$ or \\[ \\].
\begin{equation} e^{i \pi} = - 1 \end{equation}
Note. Important Considerations
Since this method only changes some settings while using a remote theme, it may stop working if the theme files undergo major version changes. In such cases, you’ll need to modify the above files to match the syntax of the new version.