Fix the auto rendering issue of Mathjax with LaTex

Recently, I build my own About website with blog posts based on al-folio. However, I find the Kramdown cannot render the conventional LaTex math code, like inline math $ $ or \( \) and display math $$ $$ and \[ \].

The default setting of the kramdown renders the inline and display math with $$ $$, which is different with LaTex and markdown. Mathjax Docs gives the solution to add the single dollar configuration. You only need to add below codes to _includes/mathjax.html:

1
2
3
4
5
6
7
8
9
tex: {
tags: 'ams',
inlineMath: [['$', '$'], ['\\(', '\\)']],
displayMath: [ ['$$','$$'], ["\\[","\\]"] ],
processEscapes: true
},
svg: {
fontCache: 'global'
}

Then you can use the inline math $ $ and display math $$ $$ in your posts.

Then you can use LaTex code to render your post.

Here is an example:

1
$$R_{i t}=\beta_{i}^{\prime} \lambda_{t}+\alpha_{i t}, \quad i=1,2, \cdots, N$$
It shows on the website:

\[ R_{i t}=\beta_{i}^{\prime} \lambda_{t}+\alpha_{i t}, \quad i=1,2, \cdots, N \]

Here is another example of inline math $R_{i t}=\beta_{i}^{\prime} \lambda_{t}+\alpha_{i t}, \quad i=1,2, \cdots, N$.

It will be rendered as \(R_{i t}=\beta_{i}^{\prime} \lambda_{t}+\alpha_{i t}, \quad i=1,2, \cdots, N\).


Fix the auto rendering issue of Mathjax with LaTex
https://www.pengjiaxin.com/2022/08/11/Mathjax/
Author
Peng Jiaxin
Posted on
August 11, 2022
Licensed under