使用了mathjax插件后,数学公式在本地能够渲染,但是一旦部署到github上以后,居然失效了……失效了……网上找了很多资料,都不太行,都是在本地可以,部署就不行。尝试多次以后终于解决了!!

步骤如下:
1、安装mathjax插件:

1
npm install hexo-math --save

2、在博客主目录下的_config.yml中添加:

1
2
3
4
5
6
7
math:
engine: 'mathjax'
mathjax:
src: "//cdn.bootcss.com/mathjax/2.7.0/MathJax.js?config=TeX-AMS-MML_HTMLorMML"
config:
tex2jax:
inlineMath: [ ['$','$'], ["\\(","\\)"] ]

3、在主题目录下的.\layout\_partial\head.ejs文件中<meta charset="utf-8">的后面添加:

1
2
<link rel="dns-prefetch" href="//cdn.bootcss.com" />
<link rel="dns-prefetch" href="//cdn.mathjax.org" />

在我用的主题下很快就渲染出来啦!!

4、如果还有冲突的公式,就在公式外面套上{ % math % }和{ % endmath % }即可。

例子:

公式1:换行公式
$$ F_M(x;P)=\sum_{m=1}^nβ_mh(x;a_m) $$
书写:

1
$$ F_M(x;P)=\sum_{m=1}^nβ_mh(x;a_m) $$

公式2:行间\(β_m\)
书写:

1
\\(β_m\\)

公式3:
$$G_1(x)= \begin{cases} 1,& \text{x<2.5} \\ -1,& \text{x>2.5} \end{cases}$$

书写:

1
2
3
4
5
6
7
{% math %}
G_1(x)=
\begin{cases}
1,& \text{x<2.5} \\
-1,& \text{x>2.5}
\end{cases}
{% endmath %}

作者 [Scorpio.Lu]
2017 年 11 月 30 日
转载请注明出处!