配置MathJax
参考:
配置NexT
主题支持数学公式,分为两步
- 打开
NexT
内部数学公式渲染引擎 - 打开
hexo
渲染器
打开NexT内部数学公式渲染引擎
进入themes/next/_config.yml
,找到math
配置
# Math Formulas Render Support
math:
# Default (true) will load mathjax / katex script on demand.
# That is it only render those page which has `mathjax: true` in Front-matter.
# If you set it to false, it will load mathjax / katex srcipt EVERY PAGE.
per_page: true
# hexo-renderer-pandoc (or hexo-renderer-kramed) required for full MathJax support.
mathjax:
enable: true
# See: https://mhchem.github.io/MathJax-mhchem/
mhchem: false
# hexo-renderer-markdown-it-plus (or hexo-renderer-markdown-it with markdown-it-katex plugin) required for full Katex support.
katex:
enable: false
# See: https://github.com/KaTeX/KaTeX/tree/master/contrib/copy-tex
copy_tex: false
属性per_page
表示是否自动渲染每一页,如果为true
就只渲染配置块中包含mathjax: true
的文章
---
title: Next Post
date: 2019-01-19 17:36:13
mathjax: true
---
设置mathjax
属性enable
为true
打开hexo
渲染器
进入网站根目录
$ npm uninstall hexo-renderer-marked --save
$ npm install hexo-renderer-kramed --save
数学公式如下
Simple inline $a = b + c$.
$$
\frac{\partial u}{\partial t}
= h^2 \left( \frac{\partial^2 u}{\partial x^2} +
\frac{\partial^2 u}{\partial y^2} +
\frac{\partial^2 u}{\partial z^2}\right)
$$
启动服务器
$ hexo clean && hexo generate && hexo server
行内公式渲染不完全
当前我遇到的情况是一行只能渲染一个行内公式,多个公式一起就不成功了
参考hexo Next主题中支持latex公式(转) ,渲染插件hexo-renderer-kramed
针对行内公式渲染有语义冲突,比如对于下划线等符号会转换成markdown
语法
进入node_modules/kramed/lib/rules/inline.js
修改11
行escape
变量
// escape: /^\\([\\`*{}\[\]()#$+\-.!_>])/,
escape: /^\\([`*\[\]()#$+\-.!_>])/,
修改20
行em
变量
// em: /^\b_((?:__|[\s\S])+?)_\b|^\*((?:\*\*|[\s\S])+?)\*(?!\*)/,
em: /^\*((?:\*\*|[\s\S])+?)\*(?!\*)/,
重新生成即可
注意:如果使用CI
进行编译生成,需要在编译之前进行修改,比如文件替换