Skip to content

Commit 08f566c

Browse files
authored
Merge pull request #413 from mathjax/develop
Version 2.1.1
2 parents a3c7182 + e9a6f00 commit 08f566c

33 files changed

+643
-518
lines changed

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ node_js:
44
- '7'
55
- '8'
66
- '9'
7+
- '10'
78
- stable
89
sudo: false
910
script:

lib/main.js

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -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
9192
var queue = []; // queue of typesetting requests of the form [data,callback]
9293
var data, callback, originalData; // the current queue item
9394
var errors = []; // errors collected durring the typesetting
95+
var sErrors = []; // errors collected durring MathJax startup
9496
var 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(/^(.*?)(\.js)?$/);
534543
window.MathJax.extensions.push(matches[1] + '.js');
@@ -730,7 +739,7 @@ function GetSVG(result) {
730739
//
731740
function 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

Comments
 (0)