vuepress配置博客支持数学公式

Posted by     "谢文进" on Wednesday, March 9, 2022

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

步骤

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

head部分添加下面的代码:

['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. 更新提交后,就大功告成了。