@@ -13,7 +13,33 @@ var LINE_SPACING = require('../constants/alignment').LINE_SPACING;
13
13
14
14
var FIND_TEX = / ( [ ^ $ ] * ) ( [ $ ] + [ ^ $ ] * [ $ ] + ) ( [ ^ $ ] * ) / ;
15
15
16
+ var inlineMath = [ [ '$' , '$' ] , [ '\\(' , '\\)' ] ] ;
17
+
16
18
exports . convertToTspans = function ( _context , gd , _callback ) {
19
+ if ( ! window . MathJax ) {
20
+ // configure & load MathJax v3 if not defined
21
+ window . MathJax = {
22
+ tex : {
23
+ inlineMath : inlineMath
24
+ }
25
+ } ;
26
+
27
+ var script = document . createElement ( 'script' ) ;
28
+ script . async = true ;
29
+ document . head . appendChild ( script ) ;
30
+
31
+ // open and send a synchronous request
32
+ var xhrObj = new XMLHttpRequest ( ) ;
33
+ xhrObj . open ( 'GET' , 'https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-svg.js' , false ) ;
34
+ xhrObj . send ( '' ) ;
35
+
36
+ // add the returned content to a newly created script tag
37
+ var script = document . createElement ( 'script' ) ;
38
+ script . type = "text/javascript" ;
39
+ script . text = xhrObj . responseText ;
40
+ document . getElementsByTagName ( 'head' ) [ 0 ] . appendChild ( script ) ;
41
+ }
42
+
17
43
var str = _context . text ( ) ;
18
44
19
45
// Until we get tex integrated more fully (so it can be used along with non-tex)
@@ -173,8 +199,6 @@ function cleanEscapesForTex(s) {
173
199
. replace ( GT_MATCH , '\\gt ' ) ;
174
200
}
175
201
176
- var inlineMath = [ [ '$' , '$' ] , [ '\\(' , '\\)' ] ] ;
177
-
178
202
function texToSVG ( _texString , _config , _callback ) {
179
203
var MathJaxVersion = parseInt (
180
204
( MathJax . version || '' ) . split ( '.' ) [ 0 ]
0 commit comments