Hexo写博客编辑公式相关问题

安装hexo-math

hexo-math的github有详细的教程,主要就是两点。

一是安装

npm install hexo-math --save

二是在站点_config.yml中配置

1
2
3
4
5
6
7
8
9
10
11
math:
engine: 'mathjax' # or 'katex'
mathjax:
src: custom_mathjax_source
config:
# MathJax config
katex:
css: custom_css_source
js: custom_js_source # not used
config:
# KaTeX config

值得一提的是,如果你是用的是Next主题,那么你还需要在\themes\next\下的_config.yml中配置启用mathjax,否则是不会生效的。(我这里弄了好久,还以为各种装错了,最是还是看了参考链接才找到问题)

mathjax:
  enable: true

多行公式

如果使用的是hexo-math,写多行公式要使用

{% math %}
\begin{align} 
\end{align}
{% endmath %}

的方式。Latex语法\\换行,&打在等号前进行对齐。特别需要注意的是,换行时要写\\\\,因为\\会被认为是转义字符\。 如

{% math %}
\begin{align} 
y &= x_1+x_2 \\\\
&=1+2 \\\\
&=3
\end{align}
{% endmath %}

的显示效果是

$$\begin{align} y & = x_1+x_2 \\\\ & =1+2 \\\\ & =3 \end{align}$$
-------------End. Thank u for reading.-------------
0%