解决在Hexo中渲染MathJax数学公式出现的问题

由于博客被这个1公式困扰已久,之前改了一下,博客崩了,不敢改了,现在决定继续改一下

第一步:

1
2
3
npm uninstall hexo-renderer-marked --save
npm install hexo-renderer-kramed --save
//卸载一个,安装一个,找个终端或者Git Bash

第二步:

进入:

1
node_modules\kramed\lib\rules\inline.js

第三步:

修改进入的文件

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

注意缩进

第四步:

主题文件找到后,把 math 默认的 false 修改为true

1
2
3
4
5
6
7
8
9
10
11
12
13
# Math Equations Render Support
math:
enable: true

# Default(true) will load mathjax/katex script on demand
# That is it only render those page who has 'mathjax: true' in Front Matter.
# If you set it to false, it will load mathjax/katex srcipt EVERY PAGE.
per_page: true

engine: mathjax
#engine: katex


第五步:

在文章的Front-matter里打开mathjax开关,如下:

1
2
3
4
5
6
7
---
title: index.html
date: 2018-07-05 12:01:30
tags:
mathjax: true
--

接下来去改一下之前公式的渲染问题,叨扰各位