安装
pnpm install mathjax
新建文件@/util/mathjax.js
window.MathJax = {
tex: {
inlineMath: [
["$", "$"],
["\\(", "\\)"],
], // 行内公式选择符
displayMath: [
["$$", "$$"],
["\\[", "\\]"],
], // 段内公式选择符
},
startup: {
ready() {
MathJax.startup.defaultReady();
},
},
};
main.js中引入
import "@/utils/mathjax"; // 必须在引入mathjax前引入mathjax的配置文件
// 这里使用的是tex-svg.js, 样式挺好看, 参考文章中的样式不知道为什么会很奇怪, 注意下
import "mathjax/es5/tex-svg"; // 使用 tex-svg.js
代码中使用
<script setup>
onMounted(() => {
MathJax.typesetPromise()
});
</script>
<template>
<div>
$$\mathit{PRCPTOT_{j} = \sum_{i=1}^{I}RR_{ij}} $$
</div>
</template>
效果
参考: