Math 数学
不要在标题里使用 mathjax 语法,toc 目录不一定能正确显示 mathjax,可能显示 mathjax 代码
建议使用 KaTex 获得更好的效果,下文有介绍!
修改 主题配置文件
:
1 | mathjax: |
如果
per_page
设为true
,则每一页都会加载Mathjax
服务。
设为false
,则需要在文章Front-matter
添加mathjax: true
,对应的文章才会加载Mathjax
服务。然后你需要修改一下默认的
markdown
渲染引擎来实现MathJax
的效果。
查看: hexo-renderer-kramed
以下操作在你 hexo 博客的目录下 (不是 Butterfly 的目录):
安装插件
1 | npm uninstall hexo-renderer-marked --save |
效果:
不要在标题里使用
KaTeX
语法,toc 目录
不能正确显示KaTeX
。
首先禁用MathJax
(如果你配置过 MathJax 的话),然后修改你的主题配置文件以便加载katex.min.css
:
1 | katex: |
你不需要添加
katex.min.js
来渲染数学方程。
相应的你需要卸载你之前的hexo
的markdown
渲染器,然后安装其它插件。
卸载掉 marked 插件,安装 hexo-renderer-markdown-it
1 | npm un hexo-renderer-marked --save # 如果有安装这个的话,卸载 |
在 hexo 的根目录的 _config.yml 中配置
1 | markdown: |
如需配置其它参数,请参考 katex 官网
注意,此方法生成的 katex 没有斜体
卸载掉 marked
插件,然后安装新的hexo-renderer-markdown-it-plus
:
1 | # 替换 `hexo-renderer-kramed` 或者 `hexo-renderer-marked` 等hexo的markdown渲染器 |
注意到 hexo-renderer-markdown-it-plus已经无人持续维护,
所以我们使用 @upupming/hexo-renderer-markdown-it-plus。
这份 fork 的代码使用了 @neilsustc/markdown-it-katex
同时它也是 VSCode 的插件 Markdown All in One所使用的,
所以我们可以获得最新的 KaTex 功能例如 \tag{}。
你还可以通过 @neilsustc/markdown-it-katex控制 KaTeX 的设置,
所有可配置的选项参见 https://katex.org/docs/options.html
比如你想要禁用掉 KaTeX 在命令行上输出的宂长的警告信息,
你可以在根目录的 _config.yml 中使用下面的配置将 strict 设置为 false:
1 | markdown_it_plus: |
当然,你还可以利用这个特性来定义一些自己常用的 macros。
因为 KaTeX 更快更轻量,因此没有 MathJax 的功能多(比如右键菜单)。
为那些使用 MathJax 的用户,主题也内置了 katex 的 复制 功能。