需求来源
最近开发一款做题app的时候,遇到了需要解析数学公式的需求,无疑我们应该选择简单而又强大的mathJax。github地址:https://github.com/mathjax/MathJax
,截止目前最新版为3.2.0
,下面采用3.2.0
演示。3.2.0下载地址:https://github.com/mathjax/MathJax/releases/tag/3.2.0
一、uniapp中使用mathJax
项目下载:https://download.csdn.net/download/Y00010010/84989721
<template>
<view class="content">
<view>极限$\lim\limits _{x \rightarrow 1} \frac{x^{2}-1}{x-1} $的值为:()</view>
</view>
</template>
<script>
export default {
data() {
return {
}
},
onLoad() {
},
methods: {
}
}
</script>
<script module="test" lang="renderjs">
export default {
mounted() {
window.MathJax = {
tex: {
inlineMath: [['$', '$'], ['\\(', '\\)']],
},
svg:{
scale: 1.2
}
};
(function () {
var script = document.createElement('script')
script.id = 'MathJax-script'
script.async = true
// script.src = 'https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-chtml.js' // cdn引入比较慢
script.src = 'static/tex-svg.js'; // 下载源码导入比较快,svg比chtml视觉上比较好
// script.src = 'static/tex-chtml.js';
document.head.appendChild(script)
})();
}
}
</script>
二、普通网页中使用mathJax
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>MathJax数学公式</title>
</head>
<body>
<div>
极限$\lim\limits _{x \rightarrow 1} \frac{x^{2}-1}{x-1} $的值为:()
</div>
<script>
MathJax = {
tex: {inlineMath: [['$', '$'], ['\\(', '\\)']]},
svg: {fontCache: 'global'}
};
</script>
<script
id="MathJax-script"
async
src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js"
></script>
</body>
</html>
祝大家生活愉快。