博客添加公式系统

博客优化内容

在hexo框架下的博客中添加可以使markdown显示出数学公式的方案。

优化方案

通过添加hexo-filter-mathjax插件来实现这一功能。

  1. 安装插件
    cd到博客的根目录,输入命令:

    npm install hexo-filter-mathjax
    
  2. 配置设置
    在博客的配置文件 _config.yml 中添加:

    mathjax:
      tags: none # or 'ams' or 'all'
      single_dollars: true # enable single dollar signs as in-line math delimiters
      cjk_width: 0.9 # relative CJK char width
      normal_width: 0.6 # relative normal (monospace) width
      append_css: true # add CSS to pages rendered by MathJax
      every_page: false # if true, every page will be rendered by MathJax regardless the `mathjax` setting in Front-matter
      extension_options: {}
        # you can put your extension options here
        # see http://docs.mathjax.org/en/latest/options/input/tex.html#tex-extension-options for more detail
    
  3. 使用方式
    在使用mathjax时,需要在每篇需要使用的文章开头添加 mathjax: true 参数。插入的方式为 $[公式代码]$ ,公式的代码可以在在线latex公式编辑器进行在线编辑。

    $\lim_{x \to 0} \frac{\sin x}{x}$ 渲染的是

    也可以进行多行的输出如:

    $$
    \begin{eqnarray}
     \lim_{x \to 0} \frac{\sin x + x^2 + x^3}{x} & = & \lim_{x \to 0} \frac{\sin x }{x} + \lim_{x \to 0} \frac{x^2 }{x} + \lim_{x \to 0}\frac{x^3}{x} 
    \\\\ & = & \lim_{x \to 0}\frac{\sin x}{x} 
    \\\\ & = & 1
    \end{eqnarray}
    $$
    

    渲染为

版本信息

内容 版本
博客框架 hexo-cli_4.3.0
主题版本 NexT_8.12.0
hexo 5.4.2

参考链接

[1] hexo博客next主题添加对数学公式的支持

[2] hexo官方插件交流论坛