vuepress配置博客支持数学公式

主要参考vuepress-theme-reco设置math公式

步骤

  1. 定位到博客的根目录下,安装库
1
npm i markdown-it-texmath
  1. 安装markdown-it
1
npm install markdown-it --save
  1. 安装katex
1
npm install katex
  1. 修改.vuepress/config.js文件
1
2
3
4
5
6
7
markdown: {
lineNumbers: true,
anchor: { permalink: false },
toc: {includeLevel: [1,2]},
extendMarkdown: md => {
md.use(require('markdown-it-texmath'))
}

head部分添加下面的代码:

1
2
3
4
5
['link', {"rel":'stylesheet', "href":'https://cdn.jsdelivr.net/npm/katex@0.15.1/dist/katex.min.css'}],
['link', {"rel":'stylesheet', "href":'https://gitcdn.xyz/cdn/goessner/markdown-it-texmath/master/texmath.css'}],
['script', {"src": 'https://github.com/markdown-it/markdown-it/blob/master/bin/markdown-it.js'}],
['script', {"src": 'https://gitcdn.xyz/cdn/goessner/markdown-it-texmath/master/texmath.js'}],
['script', {"src": 'https://cdn.jsdelivr.net/npm/katex@0.15.1/dist/katex.min.js'}]
  1. 更新提交后,就大功告成了。