Skip to content

Commit 8d610e7

Browse files
committed
Create tmpDiv on the Queue just before Typesetting
This avoids race condition where an external typesetting operation is in progress (or already on the Queue) at the start `texToSVG` function. With this change, we no longer need to set `skipStartupTypeset` to true, which alters the global default MathJax behavior of typesetting the full page automatically on startup. Other utilities, such as nbconvert, have not worked properly with plotly because they rely on this default behavior
1 parent 9569648 commit 8d610e7

File tree

2 files changed

+12
-10
lines changed

2 files changed

+12
-10
lines changed

Diff for: src/fonts/mathjax_config.js

-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ if(typeof MathJax !== 'undefined') {
1818

1919
MathJax.Hub.Config({
2020
messageStyle: 'none',
21-
skipStartupTypeset: true,
2221
displayAlign: 'left',
2322
tex2jax: {
2423
inlineMath: [['$', '$'], ['\\(', '\\)']]

Diff for: src/lib/svg_text_utils.js

+12-9
Original file line numberDiff line numberDiff line change
@@ -163,22 +163,25 @@ function cleanEscapesForTex(s) {
163163
}
164164

165165
function texToSVG(_texString, _config, _callback) {
166-
var randomID = 'math-output-' + Lib.randstr({}, 64);
167-
var tmpDiv = d3.select('body').append('div')
168-
.attr({id: randomID})
169-
.style({visibility: 'hidden', position: 'absolute'})
170-
.style({'font-size': _config.fontSize + 'px'})
171-
.text(cleanEscapesForTex(_texString));
172-
173-
var originalRenderer;
166+
167+
var originalRenderer,
168+
tmpDiv;
174169
MathJax.Hub.Queue(function() {
175170
// Get original renderer
176171
originalRenderer = MathJax.Hub.config.menuSettings.renderer;
177172
if(originalRenderer !== 'SVG') {
178173
return MathJax.Hub.setRenderer('SVG');
179174
}
180175
},
181-
['Typeset', MathJax.Hub, tmpDiv.node()],
176+
function() {
177+
var randomID = 'math-output-' + Lib.randstr({}, 64);
178+
tmpDiv = d3.select('body').append('div')
179+
.attr({id: randomID})
180+
.style({visibility: 'hidden', position: 'absolute'})
181+
.style({'font-size': _config.fontSize + 'px'})
182+
.text(cleanEscapesForTex(_texString));
183+
return MathJax.Hub.Typeset(tmpDiv.node());
184+
},
182185
function() {
183186

184187
var glyphDefs = d3.select('body').select('#MathJax_SVG_glyphs');

0 commit comments

Comments
 (0)