vue简单实用mathJax
1.新建mathJax文件放到 src\utils下 src\utils\mathJax.js
let isMathjaxConfig = false; // ⽤于标识是否配置
const initMathjaxConfig = () => {if (!window.MathJax) {return;}window.MathJax = {tex: {inlineMath: [["$", "$"],["\\(", "\\)"],], // ⾏内公式选择符displayMath: [["$$", "$$"],["\\[", "\\]"],], // 段内公式选择符},options: {skipHtmlTags: ["script","noscript","style","textarea","pre","code","a",], // 避开某些标签ignoreHtmlClass: "tex2jax_ignore",processHtmlClass: "tex2jax_process",},};isMathjaxConfig = true; // 配置完成,改为true
};
const TypeSet = async function (elementId) {if (!window.MathJax) {return;}window.MathJax.startup.promise = window.MathJax.startup.promise.then(() => {return window.MathJax.typesetPromise();}).catch((err) => console.log("Typeset failed: " + err.message));return window.MathJax.startup.promise;
};
export default {isMathjaxConfig,initMathjaxConfig,TypeSet,
};
2.main.js引用挂在
import mathJax from "./utils/mathJax";
Vue.prototype.mathJax = mathJax;
3.index.html中引用mathjax包
4.页面中使用,注意,main.js挂载时候叫mathJax,代码中保持一致,如果叫globalVaribal.js,使用时也要同名,
一元二次方程 \(ax^2 + bx +c = 0\) 的求解公式为 \( x = {-b \pm \sqrt{b^2-4ac} \over 2a} \)
