@@ -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//
@@ -518,8 +519,12 @@ function ConfigureMathJax() {
518519 MathJax . Hub . Register . StartupHook ( "End" , function ( ) {
519520 if ( MathJax . OutputJax . SVG . resetGlyphs ) MathJax . OutputJax . SVG . resetGlyphs ( true ) ;
520521 MathJax . ElementJax . mml . ID = 0 ;
521- serverState = STATE . READY ;
522- MathJax . Hub . Queue ( StartQueue ) ;
522+ if ( serverState === STATE . RESTART ) {
523+ setTimeout ( RestartMathJax , 100 ) ;
524+ } else {
525+ serverState = STATE . READY ;
526+ MathJax . Hub . Queue ( StartQueue ) ;
527+ }
523528 } ) ;
524529 }
525530 } ;
@@ -943,9 +948,17 @@ exports.typeset = function (data, callback) {
943948
944949//
945950// Manually start MathJax (this is done automatically
946- // when the first typeset() call is made)
947- //
948- exports . start = function ( ) { RestartMathJax ( ) }
951+ // when the first typeset() call is made), but delay
952+ // restart if we are already starting up (prevents
953+ // multiple calls to start() from causing confusion).
954+ //
955+ exports . start = function ( ) {
956+ if ( serverState === STATE . STARTED ) {
957+ serverState = STATE . RESTART ;
958+ } else if ( serverState !== STATE . ABORT ) {
959+ RestartMathJax ( ) ;
960+ }
961+ }
949962
950963//
951964// Configure MathJax and the API
0 commit comments