How to enable markdown mathematical formula rendering in hexo blog

How to enable markdown mathematical formula rendering in hexo blog

After you build your personal blog with hexo, you may not notice that it cannot render mathematical formulas in markdown file normally. But you always run into this problem after a few posts. I will tell you how to enable this formula rendering function.

Replace Hexo’s markdown rendering engine

The default rendering engine hexo-renderer-marked has some bugs, so it is best to uninstall it and replace it with a more stable one.

npm uninstall hexo-renderer-marked –save
npm install hexo-renderer-kramed –save

Modify the node_modules\kramed\lib\rules\inline.js file

There are still some bugs in the rendering engine that we need to fix.

1
2
//  escape: /^\\([\\`*{}\[\]()#$+\-.!_>])/,
escape: /^\\([`*\[\]()#$+\-.!_>])/,
1
2
//  em: /^\b_((?:__|[\s\S])+?)_\b|^\*((?:\*\*|[\s\S])+?)\*(?!\*)/,
em: /^\*((?:\*\*|[\s\S])+?)\*(?!\*)/,

Modify the _config.yml file of your theme

Find the math switch in the _config.yml file of your theme, and turn it on.

Redeploy hexo

1
2
hexo clean 
hexo g -d

Reference

https://runninggump.github.io/2018/12/05/%E6%88%90%E5%8A%9F%E8%A7%A3%E5%86%B3%E5%9C%A8hexo%E4%B8%AD%E6%97%A0%E6%B3%95%E6%98%BE%E7%A4%BA%E6%95%B0%E5%AD%A6%E5%85%AC%E5%BC%8F%E7%9A%84%E9%97%AE%E9%A2%98/


How to enable markdown mathematical formula rendering in hexo blog
http://example.com/2024/07/24/How-to-enable-markdown-mathematical-formula-rendering-in-hexo-blog/
Author
John Doe
Posted on
July 24, 2024
Licensed under