@@ -74,7 +74,8 @@ var STATE = {
7474 STOPPED : 1 , // no DOM or MathJax available
7575 STARTED : 2 , // DOM loaded, MathJax starting up
7676 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
7879} ;
7980
8081//
@@ -91,6 +92,7 @@ var document, window, content, html; // the DOM elements
9192var queue = [ ] ; // queue of typesetting requests of the form [data,callback]
9293var data , callback , originalData ; // the current queue item
9394var errors = [ ] ; // errors collected durring the typesetting
95+ var sErrors = [ ] ; // errors collected durring MathJax startup
9496var ID = 0 ; // id for this SVG element
9597
9698//
@@ -518,8 +520,15 @@ function ConfigureMathJax() {
518520 MathJax . Hub . Register . StartupHook ( "End" , function ( ) {
519521 if ( MathJax . OutputJax . SVG . resetGlyphs ) MathJax . OutputJax . SVG . resetGlyphs ( true ) ;
520522 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+ }
523532 } ) ;
524533 }
525534 } ;
@@ -528,7 +537,7 @@ function ConfigureMathJax() {
528537 //
529538 // Parse added extensions list and add to standard ones
530539 //
531- var extensionList = extensions . split ( / s * , \s * / ) ;
540+ var extensionList = extensions . split ( / \ s* , \s * / ) ;
532541 for ( var i = 0 ; i < extensionList . length ; i ++ ) {
533542 var matches = extensionList [ i ] . match ( / ^ ( .* ?) ( \. j s ) ? $ / ) ;
534543 window . MathJax . extensions . push ( matches [ 1 ] + '.js' ) ;
@@ -730,7 +739,7 @@ function GetSVG(result) {
730739//
731740function StartQueue ( ) {
732741 data = callback = originalData = null ; // clear existing equation, if any
733- errors = [ ] ; // clear any errors
742+ errors = sErrors ; sErrors = [ ] ; // clear any errors
734743 if ( ! queue . length ) return ; // return if nothing to do
735744
736745 serverState = STATE . BUSY ;
@@ -943,9 +952,17 @@ exports.typeset = function (data, callback) {
943952
944953//
945954// 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+ }
949966
950967//
951968// Configure MathJax and the API
0 commit comments