How to enable LaTeX formula support in Hexo

在第N次学习FOC控制原理时,打算使用Hexo记录学习过程,但是发现Hexo无法记录数学公式,该文章旨在解决此问题

下载hexo官方默认主题

  1. 在hexo根目录下! PS:clone hexo官方主题好像自动加载了代码行复制、图片引用功能功能
1
git clone https://github.com/hexojs/hexo-theme-landscape.git themes/landscape

增加MathJax脚本

  1. 在themes/landscape/layout/_partial/head.ejs
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
</head> 前加入 MathJax 脚本
<!-- MathJax for LaTeX formulas -->
<script>

MathJax = {

tex: {

inlineMath: [['$', '$'], ['\\(', '\\)']],

displayMath: [['$$', '$$'], ['\\[', '\\]']],

processEscapes: true,

processEnvironments: true

},

options: {

ignoreHtmlClass: 'tex2jax_ignore',

processHtmlClass: 'tex2jax_process'

}

};

</script>

<script src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-chtml.js" id="MathJax-script" async></script>

测试

  1. 行内公式

这是一个行内公式:$E = mc^2$

  1. 块级公式
$$ \begin{aligned} i_d &= i_\alpha \cos\theta + i_\beta \sin\theta \\ i_q &= -i_\alpha \sin\theta + i_\beta \cos\theta \end{aligned} $$