前言

本来 mathjax 的渲染一直用的十分顺手,直到有一天,我打了一个超级复杂的公式,发现渲染出来的效果不太好,于是我开始了寻找解决方案。

比如:

1
2
3
4
5
6
7
8
9
10
11
12
13
\begin{bmatrix}
1 & x_0 & x_0^2 & \cdots & x_0^n \\
1 & x_1 & x_1^2 & \cdots & x_1^n \\
\vdots & \vdots & \vdots & \ddots & \vdots \\
1 & x_n & x_n^2 & \cdots & x_n^n
\end{bmatrix}
\begin{bmatrix}
a_0 \\ a_1 \\ \vdots \\ a_n
\end{bmatrix}
=
\begin{bmatrix}
y_0 \\ y_1 \\ \vdots \\ y_n
\end{bmatrix}

分析问题

hexo 常用的渲染插件为 hexo-renderer-marked,原理是将公式块渲染为一个元素,然后用 MathJax 进行渲染。

但插件会优先转义 Markdown 语法,当语法冲突时,会导致公式无法正常渲染。

解决方案

换渲染插件,使用 hexo-renderer-pandoc

如果你有下载过任何其他的渲染插件,请务必卸载,否则可能会导致渲染问题。

需要本机下载 Pandoc 并配置环境变量。

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

Github Action 自动部署

1
2
3
4
- name: 安装 Pandoc
run: |
wget https://github.com/jgm/pandoc/releases/download/2.10.1/pandoc-2.10.1-1-amd64.deb
sudo dpkg -i pandoc-2.10.1-1-amd64.deb