0%

Hexo-Next支持Latex公式

书接Hexo-Next样式美化,本篇记录hexo-next组合对于LaTeX公式的支持。

Latex渲染插件配置

具体的在theme-next Math docs中写的很清楚,有MathJax和Katex两种公式渲染方式。这里经过实际操作,选择MathJax。

  1. 安装hexo-renderer-pandoc,也尝试过hexo-renderer-kramed,但是没效果,具体愿意没有细察

    1
    2
    npm uninstall hexo-renderer-marked
    npm install hexo-renderer-pandoc # or hexo-renderer-kramed

  2. 配置next/_config.yml, 打开mathjax

    1
    2
    3
    4
    math:
    per_page: false
    mathjax:
    enable: true

  3. CDN

    1
    2
    3
    vendors:
    # MathJax
    mathjax: //cdn.jsdelivr.net/npm/mathjs@14.5.2/lib/browser/math.min.js

  4. 生成,需要clean

    1
    2
    hexo clean && hexo g
    # or hexo clean && hexo s

  5. 示例

    e = mc2

Github CI

hexo-renderer-pandoc依赖pandoc工具,在ci的环境中,需要系统安装了pandoc。在Hexo-Next搭建记录中ci脚本的基础上,修改相应的步骤。要是我自己写,可能要费点劲,还好有大佬做了相关的工作,Github Actions部署安装pandoc,拿来主义了,感谢分享。

  1. 添加安装pandoc的步骤

    1
    2
    - name: Install pandoc
    run: curl -s -L https://github.com/jgm/pandoc/releases/download/2.18/pandoc-2.18-linux-amd64.tar.gz | tar xvzf - -C $RUNNER_TOOL_CACHE/

  2. 生成步骤中,把pandoc的路径加入到环境变量

    1
    2
    3
    4
    5
    - name: Build
    run: |
    # add pandoc to PATH
    export PATH="$PATH:$RUNNER_TOOL_CACHE/pandoc-2.18/bin"
    npm run build

参考

  1. Hexo显示latex公式
  2. Github Actions部署安装pandoc