0%

hexo|解决博客渲染公式的问题

常用的Markdown编辑器都会集成Mathjax,用来渲染文档中的类Latex格式书写的数学公式。

更换Hexo的markdown渲染引擎

博客目录下执行:

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

在主题配置中开启mathjax开关

博客目录/themes/你用的主题/_config.yml文件中,开启math支持,enable置为true:

1
2
3
4
5
6
7
# Math Formulas Render Support
math:
enable: true
# 默认加载mathjax,katex渲染
per_page: true
# 此选项开启表示每页博客是否使用mathjax是单独指定的。
# 单独指定需要公式渲染的博客,可以提高平均的加载速率。

开启mathjax支持,enable置为true:

1
2
3
4
5
6
7
# hexo-renderer-pandoc (or hexo-renderer-kramed) required for full MathJax support.
mathjax:
enable: true
# See: https://mhchem.github.io/MathJax-mhchem/
mhchem: false
# 这个化学公式的语法支持,读者可选。 $\ce{公式}$
# a third-party extension for MathJax

开启行内公式加载

以上内容仅支持块状公式渲染,

1
$$公式$$

现在我们开启行内公式渲染,

1
对于变量$v_1$,如何如何......

博客目录\node_modules\kramed\lib\rules\inline.js中做如下变动:

1
2
// em: /^\b_((?:__|[\s\S])+?)_\b|^\*((?:\*\*|[\s\S])+?)\*(?!\*)/,
em: /^\*((?:\*\*|[\s\S])+?)\*(?!\*)/,

即可。

写博客时开启mathjax

1
2
3
4
5
6
title: 符号执行测试|概述
date: 2020-01-12 17:51:54
mathjax: true
tags:
- 软件测试
- 符号执行

写一篇需要打公式的博客,则在开头front-matter,指定mathjax:true。此选项与title、date、tags同级。如此指定后,该篇博客可以成功加载公式。

编辑公式参考语法

常用数学符号的 LaTeX 表示方法