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

Merge pull request #10785 from overleaf/ae-mathjax-inline-single-dollar

Move MathJax inlineMath configuration from element to page

GitOrigin-RevId: f17af484a0df517d6006ee1d42bde01d9c1fed08
Tim Down 3 лет назад
Родитель
Сommit
d420c247e1

+ 0 - 18
services/web/frontend/js/directives/mathjax.js

@@ -1,4 +1,3 @@
-import _ from 'lodash'
 /* global MathJax */
 
 import App from '../base'
@@ -8,23 +7,6 @@ export default App.directive('mathjax', function ($compile, $parse) {
     link(scope, element, attrs) {
       if (!(MathJax && MathJax.Hub)) return
 
-      if (attrs.delimiter !== 'no-single-dollar') {
-        const inlineMathConfig =
-          MathJax.Hub.config && MathJax.Hub.config.tex2jax.inlineMath
-        const alreadyConfigured = _.find(
-          inlineMathConfig,
-          c => c[0] === '$' && c[1] === '$'
-        )
-
-        if (!alreadyConfigured) {
-          MathJax.Hub.Config({
-            tex2jax: {
-              inlineMath: inlineMathConfig.concat([['$', '$']]),
-            },
-          })
-        }
-      }
-
       setTimeout(() => {
         MathJax.Hub.Queue(['Typeset', MathJax.Hub, element.get(0)])
       }, 0)

+ 8 - 2
services/web/frontend/js/features/mathjax/configure.js

@@ -1,6 +1,7 @@
 /* global MathJax */
 
 import { mathJaxLoaded } from './util'
+import getMeta from '../../utils/meta'
 
 let configured = false
 
@@ -8,6 +9,12 @@ export function configureMathJax() {
   if (configured) return
   if (!mathJaxLoaded()) return
 
+  const inlineMath = [['\\(', '\\)']]
+
+  if (!getMeta('ol-no-single-dollar')) {
+    inlineMath.push(['$', '$'])
+  }
+
   MathJax.Hub.Config({
     messageStyle: 'none',
     imageFont: null,
@@ -30,8 +37,7 @@ export function configureMathJax() {
     skipStartupTypeset: true,
     tex2jax: {
       processEscapes: true,
-      // Dollar delimiters are added by the mathjax directive
-      inlineMath: [['\\(', '\\)']],
+      inlineMath,
       displayMath: [
         ['$$', '$$'],
         ['\\[', '\\]'],

+ 0 - 20
services/web/frontend/js/features/mathjax/index.js

@@ -1,5 +1,4 @@
 /* global MathJax */
-import _ from 'lodash'
 import { configureMathJax } from './configure'
 import { mathJaxLoaded } from './util'
 
@@ -7,25 +6,6 @@ function render(el) {
   if (!mathJaxLoaded()) return
   configureMathJax()
 
-  if (!el.hasAttribute('data-ol-no-single-dollar')) {
-    const inlineMathConfig =
-      MathJax.Hub.config &&
-      MathJax.Hub.config.tex2jax &&
-      MathJax.Hub.config.tex2jax.inlineMath
-    const alreadyConfigured = _.find(
-      inlineMathConfig,
-      c => c[0] === '$' && c[1] === '$'
-    )
-
-    if (!alreadyConfigured) {
-      MathJax.Hub.Config({
-        tex2jax: {
-          inlineMath: inlineMathConfig.concat([['$', '$']]),
-        },
-      })
-    }
-  }
-
   setTimeout(() => {
     MathJax.Hub.Queue(['Typeset', MathJax.Hub, el])
   }, 0)