0%

Hexo-Next支持Latex公式

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

Latex渲染插件配置

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

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

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

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

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

  3. 配置’hexo/_config.yml’ pandoc参数

    1
    2
    3
    4
    5
    6
    # config of hexo-renderer-pandoc
    pandoc:
    args:
    - --mathjax # a must arg
    # - --webtex # with it, each equation be in one line
    # - --standalone # $...$ become \(\), but affect html style
    mathjax参数
    1
    2
    3
    4
    5
    6
    7
    8
    9
    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
    packages: # extra packages to load
    extension_options: {}
    Note 这里every_page: false,需要在文件头添加mathjax: true

  4. CDN

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

  5. 生成,需要clean

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

  6. 示例

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. 彻底解决-Hexo-的数学公式渲染问题
  3. hexo-filter-mathjax options
  4. Math Equations配置
  5. MD with Latex to HTML with MathJax with Pandoc
  6. Could not convert TeX math
  7. Github Actions部署安装pandoc