【杂谈】设置博客支持LaTeX公式

问题:

在本地好好的LaTeX公式部署到博客上后, 无法正常显示.

原因:

hexo默认支持的hexo-renderer-marked渲染器不支持latex公式.

解决方法:
  1. 打开git bash或者用管理员身份打开命令管理器(个人推荐后者), 输入如下命令以卸载hexo-math和hexo-renderer-marked渲染引擎:

    npm un hexo-math
    npm un hexo-renderer-marked
    
  2. 输入如下命令以安装hexo-renderer-pandoc渲染器:

    npm i hexo-renderer-pandoc

  3. 输入如下命令以安装mathjax公式引擎:

    npm install hexo-filter-mathjax

  4. 修改Blog根目录下的_config.yaml文件, 在文件最后添加如下代码:

    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
    
  5. 修改Blog\themes\next目录下的_config.yaml文件:

    注意,per_page设为true表示对每一篇文章都支持LaTeX公式, 否则需要在文章标题栏中加mathjax: true.

    # 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
    
  6. 安装pandoc, 否则在hexo g时会报错: pandoc exited with code null.

    可以去官网下载, 但是不翻墙速度很慢, 同时下到3/4左右会不允许下载, 痛的回忆. 所以这里直接给出下载链接: 下载地址

  7. 部署到云端即可.

    如果发现仍然不能正常显示并且per_page已经设置为true, 那就在文章标题栏中加mathjax: true可以解决问题.

ps:

这是一个测试公式:
1 + 1 = 2 1+1=2 1+1=2

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值