Add Latex Support for Minimal Mistakes

If you are seeing the latex name below, it means latex works for this site:


Set Markdown Engine to Kramdown

Check jekyll documentations for this step’s instructions.

Include Scripts

Check MathJax Documentation for this step’s instructions. Note that you might need config=TeX-MML-AM_CHTML at the end of your src value separated by a question mark in the following form to enable predefined configurations. Add the following into your website, it will load the latest MathJax library.

<script type="text/javascript" async

And usually, if you are using a jekyll theme, this include line should go to a file in the _includes/ folder. In my case, I put it into the scripts.html file. You can also create a file for doing this, a file named custom.html for an example.

Adding configurations to scripts.html

(Thanks to Abhijit S., I forgot to put this part into this blog.)
We have included the MathJax library, and next we need to add some configurations and make it actually work pretty on our website. The goal is that we want the website to be able to recognize all normal Latex symbols for math equations and symbols: $$ and \[\]. To do that, add the following code into scripts.html:

<script type="text/x-mathjax-config">
     extensions: ["tex2jax.js"],
     jax: ["input/TeX", "output/HTML-CSS"],
     tex2jax: {
       inlineMath: [ ['$','$'], ["\\(","\\)"] ],
       displayMath: [ ['$$','$$'], ["\\[","\\]"] ],
       processEscapes: true
     "HTML-CSS": { availableFonts: ["TeX"] }

The meaning of this code is rather straight forward. You can add any symbols you want to enrich the ways MathJax pick up math equations.

Putting Math Equations on Your Webpage

If everything goes fine, you should get a working site with Mathjax. For usages of writing mathematics on page, check MathJax Doc. Use my blog as an example:
Math code:

\[p(\theta) = \mathbf{\prod}_{i,c}p(\mathbf{\theta}^i(c))\]


$$ E = mc^2 $$

Will be rendered to:

[ p(\theta) = \mathbf{\prod}_{i,c}p(\mathbf{\theta}^i(c)) ]


Note that, in my case, it seems like you better leave blank lines in your markdown file around a Latex Code Block to make it be centered after generated.

Using Katex instead of Mathjax

Katex is faster than Mathjax. To migrate, first check kramdown doc. You need JQuery, Katex and an automatic rendering script. Check Katex on Github and Auto render. After doing these, you should have a working site with Katex.


Leave a Comment