介绍
这个博客使用的主题是archer。而archer是不支持mathjax的,因此编写有公式的文章的时候就好出现问题。这篇文章主要是为了解决这个问题,并且介绍在之后的写作过程中需要注意的问题。 这篇文章主要参考是:https://www.xudong.live/posts/62947.html。
添加mathjax的支持
在文件夹themes/archer/layout
下添加新文件mathjax.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<% if (theme.mathjax.enable){ %>
<script type="text/x-mathjax-config">
MathJax.Hub.Config({
tex2jax: {
inlineMath: [ ['$','$'], ["\\(","\\)"] ],
processEscapes: true
}
});
</script>
<script type="text/x-mathjax-config">
MathJax.Hub.Config({
tex2jax: {
skipTags: ['script', 'noscript', 'style', 'textarea', 'pre', 'code']
}
});
</script>
<script type="text/x-mathjax-config">
MathJax.Hub.Queue(function() {
var all = MathJax.Hub.getAllJax(), i;
for(i=0; i < all.length; i += 1) {
all[i].SourceElement().parentNode.className += ' has-jax';
}
});
</script>
<script type="text/javascript" src="<%- theme.mathjax.cdn %>"></script>
<% } %>
在archer文件夹下面的_config.yml
上加上 1
2
3mathjax:
enable: true
cdn: https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.6/MathJax.js?config=TeX-AMS-MML_HTMLorMML
然后在themes/archer/layout/post.ejs
的main标签中加入 1
2
3<% if (page.mathjax == true){ %>
<%- partial('mathjax') %>
<% } %>
替换markdown引擎
接下来要替换markdown的渲染引擎。 1
2npm uninstall hexo-renderer-marked --save
npm install hexo-renderer-kramed --save
使用kramed的过程中还会遇到一些解析的冲突,为了先解决这个冲突,需要修改一些内容,参考: https://abelsu7.top/2018/10/29/hexo-mathjax/
测试
使用以下这个经典公式进行测试 \[ e=m^2 \]