在hexo中书写latex公式

昨天在写笔记的时候发现在 typora 中可以正确显示的 latex 公式 hexo 无法正确渲染。hexo 默认渲染器不支持 latex公式。需要安装插件才能使用。这里我采用了hexo-renderer-markdown-it-plus 替换默认的渲染器。其中公式渲染采用 katex 使用步骤如下:

  1. 安装依赖:

    npm uninstall hexo-renderer-marked

    npm install hexo-renderer-markdown-it-plus

    npm install markdown-it-katex

  2. 修改配置文件

    _config.yml中添加:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    markdown_it_plus:
    highlight: true
    html: true
    xhtmlOut: true
    breaks: true
    langPrefix:
    linkify: true
    typographer:
    quotes: “”‘’
    pre_class: highlight
  3. 修改主题模板:

    主题的 head 模板位于: themes/next-gux/layout/_partials/head.swig 中。将

    1
    <link href="https://cdn.bootcss.com/KaTeX/0.7.1/katex.min.css" rel="stylesheet">

    添加到head.swig文件末尾。

    完成以上步骤即可 hexo 即可正确的渲染 latex 公式。