overleaf/services/web/frontend/js/features/mathjax/index.js
Jakob Ackermann 40a1c302f9 Merge pull request #5071 from overleaf/jpa-web-learn-de-ng
[web] de-ng learn wiki page

GitOrigin-RevId: defb1c1c90fe17e843f36253e81c2455b7dddfb1
2021-09-16 08:03:43 +00:00

34 lines
821 B
JavaScript

/* global MathJax */
import _ from 'lodash'
import { configureMathJax } from './configure'
import { mathJaxLoaded } from './util'
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)
}
document.querySelectorAll('[data-ol-mathjax]').forEach(render)