【杂谈】设置博客支持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 delimiterscjk_width: 0.9 # relative CJK char widthnormal_width: 0.6 # relative normal (monospace) widthappend_css: true # add CSS to pages rendered by MathJaxevery_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-texcopy_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


本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!

相关文章

立即
投稿

微信公众账号

微信扫一扫加关注

返回
顶部