@@ -179,10 +179,14 @@ var inlineMath = [['$', '$'], ['\\(', '\\)']];
179
179
function texToSVG ( _texString , _config , _callback ) {
180
180
var MathJaxVersion = parseInt (
181
181
( MathJax . version || '' ) . split ( '.' ) [ 0 ]
182
- ) || - 1 ;
182
+ ) ;
183
183
184
- if ( ! MathJaxVersion ) {
184
+ if (
185
+ MathJaxVersion !== 2 &&
186
+ MathJaxVersion !== 3
187
+ ) {
185
188
Lib . warn ( 'No MathJax version:' , MathJax . version ) ;
189
+ return ;
186
190
}
187
191
188
192
var originalRenderer ,
@@ -191,45 +195,44 @@ function texToSVG(_texString, _config, _callback) {
191
195
noOriginalInlineMath ,
192
196
tmpDiv ;
193
197
194
- var setConfig = function ( ) {
195
- if ( MathJaxVersion < 3 ) {
196
- originalConfig = Lib . extendDeepAll ( { } , MathJax . Hub . config ) ;
198
+ var setConfig2 = function ( ) {
199
+ originalConfig = Lib . extendDeepAll ( { } , MathJax . Hub . config ) ;
197
200
198
- originalProcessSectionDelay = MathJax . Hub . processSectionDelay ;
199
- if ( MathJax . Hub . processSectionDelay !== undefined ) {
200
- // MathJax 2.5+ but not 3+
201
- MathJax . Hub . processSectionDelay = 0 ;
202
- }
201
+ originalProcessSectionDelay = MathJax . Hub . processSectionDelay ;
202
+ if ( MathJax . Hub . processSectionDelay !== undefined ) {
203
+ // MathJax 2.5+ but not 3+
204
+ MathJax . Hub . processSectionDelay = 0 ;
205
+ }
203
206
204
- return MathJax . Hub . Config ( {
205
- messageStyle : 'none' ,
206
- tex2jax : {
207
- inlineMath : inlineMath
208
- } ,
209
- displayAlign : 'left' ,
210
- } ) ;
211
- } else {
212
- originalConfig = Lib . extendDeepAll ( { } , MathJax . config ) ;
207
+ return MathJax . Hub . Config ( {
208
+ messageStyle : 'none' ,
209
+ tex2jax : {
210
+ inlineMath : inlineMath
211
+ } ,
212
+ displayAlign : 'left' ,
213
+ } ) ;
214
+ } ;
213
215
214
- if ( ! MathJax . config . tex . inlineMath ) {
215
- MathJax . config . tex . inlineMath = inlineMath ;
216
- noOriginalInlineMath = true ;
217
- }
216
+ var setConfig3 = function ( ) {
217
+ originalConfig = Lib . extendDeepAll ( { } , MathJax . config ) ;
218
+
219
+ if ( ! MathJax . config . tex . inlineMath ) {
220
+ MathJax . config . tex . inlineMath = inlineMath ;
221
+ noOriginalInlineMath = true ;
218
222
}
219
223
} ;
220
224
221
- var setRenderer = function ( ) {
222
- // Get original renderer
223
- if ( MathJaxVersion < 3 ) {
224
- originalRenderer = MathJax . Hub . config . menuSettings . renderer ;
225
- if ( originalRenderer !== 'SVG' ) {
226
- return MathJax . Hub . setRenderer ( 'SVG' ) ;
227
- }
228
- } else {
229
- originalRenderer = MathJax . config . startup . output ;
230
- if ( originalRenderer !== 'svg' ) {
231
- MathJax . config . startup . output = 'svg' ;
232
- }
225
+ var setRenderer2 = function ( ) {
226
+ originalRenderer = MathJax . Hub . config . menuSettings . renderer ;
227
+ if ( originalRenderer !== 'SVG' ) {
228
+ return MathJax . Hub . setRenderer ( 'SVG' ) ;
229
+ }
230
+ } ;
231
+
232
+ var setRenderer3 = function ( ) {
233
+ originalRenderer = MathJax . config . startup . output ;
234
+ if ( originalRenderer !== 'svg' ) {
235
+ MathJax . config . startup . output = 'svg' ;
233
236
}
234
237
} ;
235
238
@@ -246,14 +249,14 @@ function texToSVG(_texString, _config, _callback) {
246
249
247
250
var tmpNode = tmpDiv . node ( ) ;
248
251
249
- return MathJaxVersion < 3 ?
252
+ return MathJaxVersion === 2 ?
250
253
MathJax . Hub . Typeset ( tmpNode ) :
251
254
MathJax . typeset ( [ tmpNode ] ) ;
252
255
} ;
253
256
254
257
var finalizeMathJax = function ( ) {
255
258
var sel = tmpDiv . select (
256
- MathJaxVersion < 3 ? '.MathJax_SVG' : '.MathJax'
259
+ MathJaxVersion === 2 ? '.MathJax_SVG' : '.MathJax'
257
260
) ;
258
261
259
262
var node = ! sel . empty ( ) && tmpDiv . select ( 'svg' ) . node ( ) ;
@@ -263,7 +266,7 @@ function texToSVG(_texString, _config, _callback) {
263
266
} else {
264
267
var nodeBBox = node . getBoundingClientRect ( ) ;
265
268
var glyphDefs ;
266
- if ( MathJaxVersion < 3 ) {
269
+ if ( MathJaxVersion === 2 ) {
267
270
glyphDefs = d3 . select ( 'body' ) . select ( '#MathJax_SVG_glyphs' ) ;
268
271
} else {
269
272
glyphDefs = sel . select ( 'defs' ) ;
@@ -274,53 +277,53 @@ function texToSVG(_texString, _config, _callback) {
274
277
tmpDiv . remove ( ) ;
275
278
} ;
276
279
277
- var resetRenderer = function ( ) {
278
- if ( MathJaxVersion < 3 ) {
279
- if ( originalRenderer !== 'SVG' ) {
280
- return MathJax . Hub . setRenderer ( originalRenderer ) ;
281
- }
282
- } else {
283
- if ( originalRenderer !== 'svg' ) {
284
- MathJax . config . startup . output = originalRenderer ;
285
- }
280
+ var resetRenderer2 = function ( ) {
281
+ if ( originalRenderer !== 'SVG' ) {
282
+ return MathJax . Hub . setRenderer ( originalRenderer ) ;
286
283
}
287
284
} ;
288
285
289
- var resetConfig = function ( ) {
290
- if ( MathJaxVersion < 3 ) {
291
- if ( originalProcessSectionDelay !== undefined ) {
292
- MathJax . Hub . processSectionDelay = originalProcessSectionDelay ;
293
- }
294
- return MathJax . Hub . Config ( originalConfig ) ;
286
+ var resetRenderer3 = function ( ) {
287
+ if ( originalRenderer !== 'svg' ) {
288
+ MathJax . config . startup . output = originalRenderer ;
289
+ }
290
+ } ;
291
+
292
+ var resetConfig2 = function ( ) {
293
+ if ( originalProcessSectionDelay !== undefined ) {
294
+ MathJax . Hub . processSectionDelay = originalProcessSectionDelay ;
295
+ }
296
+ return MathJax . Hub . Config ( originalConfig ) ;
297
+ } ;
298
+
299
+ var resetConfig3 = function ( ) {
300
+ if ( noOriginalInlineMath ) {
301
+ delete MathJax . config . tex . inlineMath ;
295
302
} else {
296
- if ( noOriginalInlineMath ) {
297
- delete MathJax . config . tex . inlineMath ;
298
- } else {
299
- MathJax . config . tex . inlineMath = originalConfig . tex . inlineMath ;
300
- }
303
+ MathJax . config . tex . inlineMath = originalConfig . tex . inlineMath ;
301
304
}
302
305
} ;
303
306
304
- if ( MathJaxVersion < 3 ) {
307
+ if ( MathJaxVersion === 2 ) {
305
308
MathJax . Hub . Queue (
306
- setConfig ,
307
- setRenderer ,
309
+ setConfig2 ,
310
+ setRenderer2 ,
308
311
initiateMathJax ,
309
312
finalizeMathJax ,
310
- resetRenderer ,
311
- resetConfig
313
+ resetRenderer2 ,
314
+ resetConfig2
312
315
) ;
313
- } else {
314
- setConfig ( ) ;
315
- setRenderer ( ) ;
316
+ } else if ( MathJaxVersion === 3 ) {
317
+ setConfig3 ( ) ;
318
+ setRenderer3 ( ) ;
316
319
MathJax . startup . defaultReady ( ) ;
317
320
318
321
MathJax . startup . promise . then ( function ( ) {
319
322
initiateMathJax ( ) ;
320
323
finalizeMathJax ( ) ;
321
324
322
- resetRenderer ( ) ;
323
- resetConfig ( ) ;
325
+ resetRenderer3 ( ) ;
326
+ resetConfig3 ( ) ;
324
327
} ) ;
325
328
}
326
329
}
0 commit comments