mathjax.js 831 B

123456789101112131415161718192021222324252627282930313233
  1. import _ from 'lodash'
  2. /* global MathJax */
  3. import App from '../base'
  4. export default App.directive('mathjax', function ($compile, $parse) {
  5. return {
  6. link(scope, element, attrs) {
  7. if (!(MathJax && MathJax.Hub)) return
  8. if (attrs.delimiter !== 'no-single-dollar') {
  9. const inlineMathConfig =
  10. MathJax.Hub.config && MathJax.Hub.config.tex2jax.inlineMath
  11. const alreadyConfigured = _.find(
  12. inlineMathConfig,
  13. c => c[0] === '$' && c[1] === '$'
  14. )
  15. if (!alreadyConfigured) {
  16. MathJax.Hub.Config({
  17. tex2jax: {
  18. inlineMath: inlineMathConfig.concat([['$', '$']]),
  19. },
  20. })
  21. }
  22. }
  23. setTimeout(() => {
  24. MathJax.Hub.Queue(['Typeset', MathJax.Hub, element.get(0)])
  25. }, 0)
  26. },
  27. }
  28. })