diff --git a/services/web/frontend/js/directives/mathjax.js b/services/web/frontend/js/directives/mathjax.js index eac5422e00..25627035ad 100644 --- a/services/web/frontend/js/directives/mathjax.js +++ b/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) diff --git a/services/web/frontend/js/features/mathjax/configure.js b/services/web/frontend/js/features/mathjax/configure.js index 8a3104487e..a1446cb1d2 100644 --- a/services/web/frontend/js/features/mathjax/configure.js +++ b/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: [ ['$$', '$$'], ['\\[', '\\]'], diff --git a/services/web/frontend/js/features/mathjax/index.js b/services/web/frontend/js/features/mathjax/index.js index f780b1bff4..fbf8734cd2 100644 --- a/services/web/frontend/js/features/mathjax/index.js +++ b/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)