@@ -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//
@@ -519,11 +520,15 @@ function ConfigureMathJax() {
519520 MathJax . Hub . Register . StartupHook ( "End" , function ( ) {
520521 if ( MathJax . OutputJax . SVG . resetGlyphs ) MathJax . OutputJax . SVG . resetGlyphs ( true ) ;
521522 MathJax . ElementJax . mml . ID = 0 ;
522- serverState = STATE . READY ;
523- MathJax . Hub . Queue (
523+ if ( serverState === STATE . RESTART ) {
524+ setTimeout ( RestartMathJax , 100 ) ;
525+ } else {
526+ serverState = STATE . READY ;
527+ MathJax . Hub . Queue (
524528 function ( ) { sErrors = errors } ,
525529 StartQueue
526530 ) ;
531+ }
527532 } ) ;
528533 }
529534 } ;
@@ -947,9 +952,17 @@ exports.typeset = function (data, callback) {
947952
948953//
949954// Manually start MathJax (this is done automatically
950- // when the first typeset() call is made)
951- //
952- 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+ }
953966
954967//
955968// Configure MathJax and the API
0 commit comments