Просмотр исходного кода

引入MathJax渲染数学公式

cfort 1 год назад
Родитель
Сommit
f459b53631
2 измененных файлов с 49 добавлено и 1 удалено
  1. 1 1
      public/index.html
  2. 48 0
      src/utils/MathJax.js

+ 1 - 1
public/index.html

@@ -35,7 +35,6 @@
     <script src="lib/luckysheet/plugins/js/plugin.js"></script>
     <script src="lib/luckysheet/luckysheet.umd.js"></script>
 
-
     <title><%= VUE_APP_TITLE %></title>
 	<script type="text/javascript" src="http://dev1.local/word/web-apps/apps/api/documents/api.js"></script>
     <style>
@@ -73,6 +72,7 @@
             </div>
         </div>
     </div>
+    <script type="text/javascript" async src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-MML-AM_CHTML"></script>
     <!-- 使用 CDN 加速的 JS 文件,配置在 vue.config.js 下 -->
     <% for (var i in htmlWebpackPlugin.options.cdn&&htmlWebpackPlugin.options.cdn.js) { %>
       <script src="<%= htmlWebpackPlugin.options.cdn.js[i] %>"></script>

+ 48 - 0
src/utils/MathJax.js

@@ -0,0 +1,48 @@
+// 用于标识是否配置
+let isMathjaxConfig = false
+const initMathjaxConfig = () => {
+    if (!window.MathJax) {
+        return
+    }
+    window.MathJax.Hub.Config({
+        // 关闭js加载过程信息
+        showProcessingMessages: false,
+        // 不显示信息
+        messageStyle: 'none',
+        jax: ['input/TeX', 'output/HTML-CSS'],
+        tex2jax: {
+            // 行内公式选择符
+            inlineMath: [
+                ['$', '$'],
+                ['\\(', '\\)']
+            ],
+            // 段内公式选择符
+            displayMath: [
+                ['$$', '$$'],
+                ['\\[', '\\]']
+            ],
+            // 避开某些标签
+            skipTags: ['script', 'noscript', 'style', 'textarea', 'pre', 'code', 'a']
+        },
+        'HTML-CSS': {
+            // 可选字体
+            availableFonts: ['STIX', 'TeX'],
+            // 关闭右击菜单显示
+            showMathMenu: false
+        }
+    })
+    // 配置完成,改为true
+    isMathjaxConfig = true
+}
+const MathQueue = function (elementId) {
+    if (!window.MathJax) {
+        return
+    }
+    window.MathJax.Hub.Queue(['Typeset', window.MathJax.Hub, document.getElementById(elementId)])
+}
+
+export default {
+    isMathjaxConfig,
+    initMathjaxConfig,
+    MathQueue
+}