Skip to content

Commit 624572a

Browse files
committed
Handle interleaved Typeset() calls better.
1 parent d3eec13 commit 624572a

File tree

3 files changed

+22
-13
lines changed

3 files changed

+22
-13
lines changed

unpacked/jax/output/CommonHTML/jax.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,10 @@
415415
// Add the node for the math and mark it as being processed
416416
//
417417
jax = script.MathJax.elementJax; if (!jax) continue;
418-
jax.CHTML = {display: (jax.root.Get("display") === "block")}
418+
jax.CHTML = {
419+
display: (jax.root.Get("display") === "block"),
420+
preview: (jax.CHTML||{}).preview // in case typeset calls are interleaved
421+
};
419422
node = CHTML.Element("mjx-chtml",{
420423
id:jax.inputID+"-Frame", className:"MathJax_CHTML", isMathJax:true, jaxID:this.id,
421424
oncontextmenu:EVENT.Menu, onmousedown: EVENT.Mousedown,

unpacked/jax/output/HTML-CSS/jax.js

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -683,7 +683,7 @@
683683
// Get the data about the math
684684
//
685685
var jax = script.MathJax.elementJax, math = jax.root,
686-
span = document.getElementById(jax.inputID+"-Frame"),
686+
span = script.previousSibling;
687687
div = (jax.HTMLCSS.display ? (span||{}).parentNode : span);
688688
if (!div) return;
689689
//
@@ -775,7 +775,8 @@
775775
script = scripts[i];
776776
if (script && script.parentNode && script.MathJax.elementJax) {
777777
jax = script.MathJax.elementJax; this.getMetrics(jax);
778-
jax.root.toHTML(jax.HTMLCSS.span,jax.HTMLCSS.div,this.PHASE.II);
778+
if (jax.HTMLCSS.span && jax.HTMLCSS.div)
779+
jax.root.toHTML(jax.HTMLCSS.span,jax.HTMLCSS.div,this.PHASE.II);
779780
}
780781
}
781782
//
@@ -788,14 +789,16 @@
788789
// Finish the math with its measured size (toHTML phase III)
789790
//
790791
jax = script.MathJax.elementJax; this.getMetrics(jax);
791-
jax.root.toHTML(jax.HTMLCSS.span,jax.HTMLCSS.div,this.PHASE.III);
792-
if (jax.HTMLCSS.isHidden) script.parentNode.insertBefore(jax.HTMLCSS.div,script);
793-
delete jax.HTMLCSS.span; delete jax.HTMLCSS.div;
794-
//
795-
// The math is now fully processed
796-
//
797-
script.MathJax.state = jax.STATE.PROCESSED;
798-
HUB.signal.Post(["New Math",script.MathJax.elementJax.inputID]); // FIXME: wait for this? (i.e., restart if returns uncalled callback)
792+
if (jax.HTMLCSS.span && jax.HTMLCSS.div) {
793+
jax.root.toHTML(jax.HTMLCSS.span,jax.HTMLCSS.div,this.PHASE.III);
794+
if (jax.HTMLCSS.isHidden) script.parentNode.insertBefore(jax.HTMLCSS.div,script);
795+
delete jax.HTMLCSS.span; delete jax.HTMLCSS.div;
796+
//
797+
// The math is now fully processed
798+
//
799+
script.MathJax.state = jax.STATE.PROCESSED;
800+
HUB.signal.Post(["New Math",script.MathJax.elementJax.inputID]); // FIXME: wait for this? (i.e., restart if returns uncalled callback)
801+
}
799802
}
800803
}
801804
if (this.forceReflow) {

unpacked/jax/output/SVG/jax.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,10 @@
228228
// then set the role and mark it as being processed
229229
//
230230
jax = script.MathJax.elementJax; if (!jax) continue;
231-
jax.SVG = {display: (jax.root.Get("display") === "block")}
231+
jax.SVG = {
232+
display: (jax.root.Get("display") === "block"),
233+
preview: (jax.SVG||{}).preview // in case typeset calls are interleaved
234+
};
232235
span = div = HTML.Element("span",{
233236
style: {"font-size": this.config.scale+"%", display:"inline-block"},
234237
className:"MathJax_SVG", id:jax.inputID+"-Frame", isMathJax:true, jaxID:this.id,
@@ -312,7 +315,7 @@
312315
// Get the data about the math
313316
//
314317
var jax = script.MathJax.elementJax, math = jax.root,
315-
span = document.getElementById(jax.inputID+"-Frame"),
318+
span = script.previousSibling;
316319
div = (jax.SVG.display ? (span||{}).parentNode : span),
317320
localCache = (SVG.config.useFontCache && !SVG.config.useGlobalCache);
318321
if (!div) return;

0 commit comments

Comments
 (0)