目录

配置hexo支持latex公式

第一步: 安装Kramed

1
2
npm uninstall hexo-renderer-marked --save
npm install hexo-renderer-kramed --save

第二步:更改文件配置

打开/node_modules/hexo-renderer-kramed/lib/renderer.js,更改:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
// Change inline math rule
function formatText(text) {
    // Fit kramed's rule: $$ + \1 + $$
    return text.replace(/`\$(.*?)\$`/g, '$$$$$1$$$$');
}

直接返回text

// Change inline math rule
function formatText(text) {
    return text;
}

第三步: 停止使用 hexo-math,并安装mathjax包

1
2
npm uninstall hexo-math --save
npm install hexo-renderer-mathjax --save

第四步: 更新 Mathjax 的 配置文件

打开/node_modules/hexo-renderer-mathjax/mathjax.html ,注释掉第二个<script>

1
<script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js?config=TeX-MML-AM_CHTML"></script>

第五步: 更改默认转义规则

打开/node_modules\kramed\lib\rules\inline.js

1
2
3
4
5
6
7
escape: /^\\([\\`*{}\[\]()#$+\-.!_>])/,
更改为
escape: /^\\([`*\[\]()# +\-.!_>])/,
    
em: /^\b_((?:__|[\s\S])+?)_\b|^\*((?:\*\*|[\s\S])+?)\*(?!\*)/,
更改为
em: /^\*((?:\*\*|[\s\S])+?)\*(?!\*)/,

第六步: 开启mathjax

打开你所使用主题的_config.yml文件

1
2
mathjax:
    enable: true

最后的最后

在每个文章的开头添加

1
mathjax: true

例如:

1
2
3
4
5
6
7
8
title: tensorflow实例与线性回归
date: 2018-12-29 15:16:08
mathjax: true
tags:
	- python
	- 深度学习
	- tensorflow
categories: 深度学习