配置MathJax

参考:

数学公式

Math Equations

配置NexT主题支持数学公式,分为两步

  1. 打开NexT内部数学公式渲染引擎
  2. 打开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属性enabletrue

打开hexo渲染器

参考:sun11/hexo-renderer-kramed

进入网站根目录

$ 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

修改11escape变量

// escape: /^\\([\\`*{}\[\]()#$+\-.!_>])/,
escape: /^\\([`*\[\]()#$+\-.!_>])/,

修改20em变量

// em: /^\b_((?:__|[\s\S])+?)_\b|^\*((?:\*\*|[\s\S])+?)\*(?!\*)/,
em: /^\*((?:\*\*|[\s\S])+?)\*(?!\*)/,

重新生成即可

注意:如果使用CI进行编译生成,需要在编译之前进行修改,比如文件替换