eiπ=1e^{i\pi} = -1

数学支持对于个人博客来说我觉得至关重要,但是默认的Hexo渲染Markdown的引擎 hexo-render-marked 却不支持。本文讲述如何通过更换Hexo的Markdown渲染引擎的方式让你的博客支持数学。

警告:在开始本指南之前,请确保您位于 hexo 主目录中。

默认的 Hexo 安装将包括一个使用 marked 的 Markdown renderer(渲染器)插件,因此如果要更换,例如更换成本教程使用的 hexo-renderer-markdown-it ,你应该先卸载它。

1
$ npm un hexo-renderer-marked --save

如果您已经删除了默认renderer以及您可能添加的其他renderer,现在可以安全地安装 hexo-renderer-markdown-it

1
$ npm i hexo-renderer-markdown-it --save

安装 markdown-it 数学插件:

1
$ npm install katex @renbaoshuo/markdown-it-katex

_config.yml 中添加下列配置:

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
30
markdown:
preset: 'default'
render:
html: true
xhtmlOut: false
langPrefix: 'language-'
breaks: true
linkify: true
typographer: true
quotes: '“”‘’'
enable_rules:
disable_rules:
plugins:
- name: '@renbaoshuo/markdown-it-katex'
options:
skipDelimitersCheck: true
anchors:
level: 2
collisionSuffix: ''
permalink: false
permalinkClass: 'header-anchor'
permalinkSide: 'left'
permalinkSymbol: '¶'
case: 0
separator: '-'
images:
lazyload: false
prepend_root: false
post_asset: false
inline: false # https://markdown-it.github.io/markdown-it/#MarkdownIt.renderInline

可选的,你可能需要去你的主题设置里,添加 KaTeX 样式表:

1
2
3
4
<link
rel="stylesheet"
href="https://cdn.jsdelivr.net/npm/katex/dist/katex.min.css"
/>

关于 hexo-renderer-markdown-it 的其他说明,请参考 https://github.com/hexojs/hexo-renderer-markdown-it