LoveIt主题支持MathJax

警告
本文最后更新于 2022-02-23,文中内容可能已过时。

1.将config.toml中的KaTeX数学公式支持修改为false

1
2
[params.page.math]
      enable = false

2.新建themes\LoveIt\layouts\partials\math.html文件,添加一下内容

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
<script type="text/x-mathjax-config">
    MathJax.Hub.Config({
        tex2jax: {
            inlineMath: [['$','$'], ['\\(','\\)']],
            displayMath: [['$$','$$'], ['\[','\]']],
            processEscapes: true,
            processEnvironments: true,
            skipTags: ['script', 'noscript', 'style', 'textarea', 'pre'],
            TeX: {
                equationNumbers: { autoNumber: "AMS" },
                extensions: ["AMSmath.js", "AMSsymbols.js"]
            }
        }
    });
</script>
<script type="text/javascript" async src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-MML-AM_CHTML"></script>

<style>
code.has-jax {
    font: inherit;
    font-size: 100%;
    background: inherit;
    border: inherit;
    color: #515151;
}
</style>

<script>
    document.addEventListener("DOMContentLoaded", function() {
        renderMathInElement(document.body, {
            delimiters: [
              {left: "$$", right: "$$", display: true},
              {left: "$", right: "$", display: false}
            ]
        });
    });
</script>

3.在themes\LoveIt\layouts\partials\header.html中的最后添加下列内容

1
2
3
{{ if or .Params.math .Site.Params.math }}
    {{ partial "math.html" . }}
{{ end }}

4.在每篇文章最开始的Front Matter中使用math: true表示启用MathJax公式支持