数学公式困扰我很久,试过很多方法:
- next 主题自带的,发现 mathjax 不好使,
- hexo-renderer-kramed 不好使
- hexo-math 可以但是对$$ 无效,对$$ $$有效
- 试了Katex 显示公式重复。
最后是 hexo-math 加 hexo-renderer-pandoc 有效的。
使用这个 renderer 之前请确保你已经安装了 Pandoc,然后卸载 Hexo 自带的 renderer,安装 pandoc renderer:1 2 3
| npm uninstall hexo-renderer-marked --save npm install hexo-math --save npm install hexo-renderer-pandoc --save
|
hexo 配置添加
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
| math: engine: 'mathjax' mathjax: src: "//cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML" config: tex2jax: inlineMath: [ ['$','$'], ["\\(","\\)"] ] skipTags: ['script', 'noscript', 'style', 'textarea', 'pre', 'code'] processEscapes: true TeX: equationNumbers: autoNumber: "AMS" katex: css: "https://cdnjs.cloudflare.com/ajax/libs/KaTeX/0.5.1/katex.min.css" js: "https://cdnjs.cloudflare.com/ajax/libs/KaTeX/0.5.1/katex.min.js" config: throwOnError: false, errorColor: "#cc0000"
|
主题配置文件添加:
1 2 3
| mathjax: enable: true cdn: //cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML
|
如果你使用这款 Pandoc renderer,那么你书写 Markdown 时候需要遵循 Pandoc 对 Markdown 的规定。有一些比较明显的需要注意的事项:正常的文字后面如果跟的是 list, table 或者 quotation,文字后面需要空一行,如果不空行,这些环境将不能被 Pandoc renderer 正常渲染。