@@ -74,7 +74,8 @@ var STATE = {
74
74
STOPPED : 1 , // no DOM or MathJax available
75
75
STARTED : 2 , // DOM loaded, MathJax starting up
76
76
READY : 3 , // MathJax initialized and ready to process math
77
- BUSY : 4 // MathJax currently processing math
77
+ BUSY : 4 , // MathJax currently processing math
78
+ RESTART : 5 , // start() called while MathJax is starting up
78
79
} ;
79
80
80
81
//
@@ -91,6 +92,7 @@ var document, window, content, html; // the DOM elements
91
92
var queue = [ ] ; // queue of typesetting requests of the form [data,callback]
92
93
var data , callback , originalData ; // the current queue item
93
94
var errors = [ ] ; // errors collected durring the typesetting
95
+ var sErrors = [ ] ; // errors collected durring MathJax startup
94
96
var ID = 0 ; // id for this SVG element
95
97
96
98
//
@@ -518,8 +520,15 @@ function ConfigureMathJax() {
518
520
MathJax . Hub . Register . StartupHook ( "End" , function ( ) {
519
521
if ( MathJax . OutputJax . SVG . resetGlyphs ) MathJax . OutputJax . SVG . resetGlyphs ( true ) ;
520
522
MathJax . ElementJax . mml . ID = 0 ;
521
- serverState = STATE . READY ;
522
- MathJax . Hub . Queue ( StartQueue ) ;
523
+ if ( serverState === STATE . RESTART ) {
524
+ setTimeout ( RestartMathJax , 100 ) ;
525
+ } else {
526
+ serverState = STATE . READY ;
527
+ MathJax . Hub . Queue (
528
+ function ( ) { sErrors = errors } ,
529
+ StartQueue
530
+ ) ;
531
+ }
523
532
} ) ;
524
533
}
525
534
} ;
@@ -528,7 +537,7 @@ function ConfigureMathJax() {
528
537
//
529
538
// Parse added extensions list and add to standard ones
530
539
//
531
- var extensionList = extensions . split ( / s * , \s * / ) ;
540
+ var extensionList = extensions . split ( / \ s* , \s * / ) ;
532
541
for ( var i = 0 ; i < extensionList . length ; i ++ ) {
533
542
var matches = extensionList [ i ] . match ( / ^ ( .* ?) ( \. j s ) ? $ / ) ;
534
543
window . MathJax . extensions . push ( matches [ 1 ] + '.js' ) ;
@@ -730,7 +739,7 @@ function GetSVG(result) {
730
739
//
731
740
function StartQueue ( ) {
732
741
data = callback = originalData = null ; // clear existing equation, if any
733
- errors = [ ] ; // clear any errors
742
+ errors = sErrors ; sErrors = [ ] ; // clear any errors
734
743
if ( ! queue . length ) return ; // return if nothing to do
735
744
736
745
serverState = STATE . BUSY ;
@@ -943,9 +952,17 @@ exports.typeset = function (data, callback) {
943
952
944
953
//
945
954
// Manually start MathJax (this is done automatically
946
- // when the first typeset() call is made)
947
- //
948
- exports . start = function ( ) { RestartMathJax ( ) }
955
+ // when the first typeset() call is made), but delay
956
+ // restart if we are already starting up (prevents
957
+ // multiple calls to start() from causing confusion).
958
+ //
959
+ exports . start = function ( ) {
960
+ if ( serverState === STATE . STARTED ) {
961
+ serverState = STATE . RESTART ;
962
+ } else if ( serverState !== STATE . ABORT ) {
963
+ RestartMathJax ( ) ;
964
+ }
965
+ }
949
966
950
967
//
951
968
// Configure MathJax and the API
0 commit comments