Eastwatch

Listen to the rhythm of the falling rain.

0%

How to support Latex in Hexo

Environment: Hexo v5.4.0, NexT v7.8.0, windows 10

Install plugin

  1. Check if you have installed "hexo-math": npm list hexo-math.

  2. If true, uninstall it: npm uninstall hexo-math --save.

  3. Install "hexo-filter-mathjax": npm uninstall hexo-math --save.

  4. Check if you have successfully installed: npm list hexo-filter-mathjax

  5. Modify ./_config.yml, add the following code to support mathjax:

    1
    2
    3
    4
    5
    6
    7
    8
    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

  6. Modify ./themes/next/_config.yml to support mathjax:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    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: true

Install Renderer

  1. Check if you have installed the default renderer "hexo-renderer-marked": npm list hexo-renderer-marked.

  2. If true, uninstall it: npm uninstall hexo-renderer-marked --save.

  3. Install a new renderer "hexo-renderer-kramed": npm install hexo-renderer-kramed --save.

  4. Open \node_modules\kramed\lib\rules\inline.js and modify two lines in order to avoid some grammar conflicts:

    1
    2
    3
    4
    5
    6
    7
    //escape: /^\\([\\`*{}\[\]()#$+\-.!_>])/,
    //change to:
    escape: /^\\([`*\[\]()#$+\-.!_>])/,

    //em: /^\b_((?:__|[\s\S])+?)_\b|^\*((?:\*\*|[\s\S])+?)\*(?!\*)/,
    //change to:
    em: /^\*((?:\*\*|[\s\S])+?)\*(?!\*)/,

Finally

Add mathjax: true in the front-matter of the article on which you want to render Latex equation. The default is false.

1
2
3
4
5
---
title: blabla
data: 2021-08-25
mathjax: true
---