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

Move MathJax inlineMath configuration from element to page

GitOrigin-RevId: f17af484a0df517d6006ee1d42bde01d9c1fed08
This commit is contained in:
Tim Down 2022-12-08 12:27:59 +00:00 committed by Copybot
parent f9aaa4d5de
commit d420c247e1
3 changed files with 8 additions and 40 deletions

View file

@ -1,4 +1,3 @@
import _ from 'lodash'
/* global MathJax */ /* global MathJax */
import App from '../base' import App from '../base'
@ -8,23 +7,6 @@ export default App.directive('mathjax', function ($compile, $parse) {
link(scope, element, attrs) { link(scope, element, attrs) {
if (!(MathJax && MathJax.Hub)) return 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(() => { setTimeout(() => {
MathJax.Hub.Queue(['Typeset', MathJax.Hub, element.get(0)]) MathJax.Hub.Queue(['Typeset', MathJax.Hub, element.get(0)])
}, 0) }, 0)

View file

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

View file

@ -1,5 +1,4 @@
/* global MathJax */ /* global MathJax */
import _ from 'lodash'
import { configureMathJax } from './configure' import { configureMathJax } from './configure'
import { mathJaxLoaded } from './util' import { mathJaxLoaded } from './util'
@ -7,25 +6,6 @@ function render(el) {
if (!mathJaxLoaded()) return if (!mathJaxLoaded()) return
configureMathJax() 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(() => { setTimeout(() => {
MathJax.Hub.Queue(['Typeset', MathJax.Hub, el]) MathJax.Hub.Queue(['Typeset', MathJax.Hub, el])
}, 0) }, 0)