vue npm安装并使用mathjax渲染数学公式
·
1、安装mathjax
npm install mathjax@3
2、将\node_modules\mathjax文件夹拷贝至项目某一位置(如:\src\common\mathjax)
3、删除\common\mathjax\LICENSE文件
4、新建\src\common\mathjax\mathjax-config.js(mathjax配置文件)
window.MathJax = {
tex: {
inlineMath: [
["$", "$"],
["\\(", "\\)"],
], // 行内公式选择符
displayMath: [
["$$", "$$"],
["\\[", "\\]"],
] // 段内公式选择符
},
startup: {
ready() {
window.MathJax.startup.defaultReady() ;
}
}
} ;
5、组件中使用
// 引入资源
import '@common/mathjax/mathjax-config.js';
import '@common/mathjax/es5/tex-mml-svg.js';
// 钩子函数中调用异步执行排版
mounted() {
window.MathJax.typesetPromise() ;
},
// html中使用
<span v-html="mathJaxStr"></span>
// 或
<span>{{ mathJaxStr }}</span>
Tex
// 单行使用一个$符号,换行使用两个$符号
计算公式1:$\int_{a}^{b} x^2 dx$<br>计算公式2:$\int_{a}^{b} x^3 dx$<br>$$\int_{a}^{b} x^2 dx$$
更多推荐



所有评论(0)