2020-06-23 04:45:38 -04:00
|
|
|
import _ from 'lodash'
|
2019-10-14 09:17:30 -04:00
|
|
|
/* global MathJax */
|
2018-11-05 05:06:39 -05:00
|
|
|
|
2020-05-19 05:02:56 -04:00
|
|
|
import App from '../base'
|
2019-03-18 06:24:54 -04:00
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
export default App.directive('mathjax', function ($compile, $parse) {
|
2020-05-19 05:02:56 -04:00
|
|
|
return {
|
|
|
|
link(scope, element, attrs) {
|
|
|
|
if (!(MathJax && MathJax.Hub)) return
|
2019-03-18 06:24:54 -04:00
|
|
|
|
2020-05-19 05:02:56 -04:00
|
|
|
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] === '$'
|
|
|
|
)
|
2018-11-05 05:06:39 -05:00
|
|
|
|
2020-05-19 05:02:56 -04:00
|
|
|
if (!alreadyConfigured) {
|
|
|
|
MathJax.Hub.Config({
|
|
|
|
tex2jax: {
|
|
|
|
inlineMath: inlineMathConfig.concat([['$', '$']])
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
2019-03-18 06:24:54 -04:00
|
|
|
}
|
2020-05-19 05:02:56 -04:00
|
|
|
|
|
|
|
setTimeout(() => {
|
|
|
|
MathJax.Hub.Queue(['Typeset', MathJax.Hub, element.get(0)])
|
|
|
|
}, 0)
|
2018-11-05 05:06:39 -05:00
|
|
|
}
|
2020-05-19 05:02:56 -04:00
|
|
|
}
|
2019-03-18 06:24:54 -04:00
|
|
|
})
|