index.js 821 B

12345678910111213141516171819202122232425262728293031323334
  1. /* global MathJax */
  2. import _ from 'lodash'
  3. import { configureMathJax } from './configure'
  4. import { mathJaxLoaded } from './util'
  5. function render(el) {
  6. if (!mathJaxLoaded()) return
  7. configureMathJax()
  8. if (!el.hasAttribute('data-ol-no-single-dollar')) {
  9. const inlineMathConfig =
  10. MathJax.Hub.config &&
  11. MathJax.Hub.config.tex2jax &&
  12. MathJax.Hub.config.tex2jax.inlineMath
  13. const alreadyConfigured = _.find(
  14. inlineMathConfig,
  15. c => c[0] === '$' && c[1] === '$'
  16. )
  17. if (!alreadyConfigured) {
  18. MathJax.Hub.Config({
  19. tex2jax: {
  20. inlineMath: inlineMathConfig.concat([['$', '$']]),
  21. },
  22. })
  23. }
  24. }
  25. setTimeout(() => {
  26. MathJax.Hub.Queue(['Typeset', MathJax.Hub, el])
  27. }, 0)
  28. }
  29. document.querySelectorAll('[data-ol-mathjax]').forEach(render)