Skip to content

Commit 242c935

Browse files
committed
Put off moving math in containers with display:none from the hidden div where they are typeset to their proper locations until AFTER they have been remeasured. Resolves issue mathjax#1179.
1 parent 9995bf3 commit 242c935

File tree

1 file changed

+13
-6
lines changed
  • unpacked/jax/output/HTML-CSS

1 file changed

+13
-6
lines changed

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

+13-6
Original file line numberDiff line numberDiff line change
@@ -539,7 +539,7 @@
539539
},
540540

541541
preTranslate: function (state) {
542-
var scripts = state.jax[this.id], i, m = scripts.length,
542+
var scripts = state.jax[this.id], i, m = scripts.length, n,
543543
script, prev, span, div, test, jax, ex, em, scale, maxwidth, relwidth = false, cwidth,
544544
linebreak = this.config.linebreaks.automatic, width = this.config.linebreaks.width;
545545
if (linebreak) {
@@ -590,7 +590,10 @@
590590
//
591591
// Determine the scaling factors for each script
592592
// (this only requires one reflow rather than a reflow for each equation)
593+
// Record any that need to be hidden (don't move them now, since that
594+
// would cause reflows).
593595
//
596+
var hidden = [];
594597
for (i = 0; i < m; i++) {
595598
script = scripts[i]; if (!script.parentNode) continue;
596599
test = script.previousSibling; div = test.previousSibling;
@@ -601,8 +604,7 @@
601604
if (relwidth) {maxwidth = cwidth}
602605
if (ex === 0 || ex === "NaN") {
603606
// can't read width, so move to hidden div for processing
604-
// (this will cause a reflow for each math element that is hidden)
605-
this.hiddenDiv.appendChild(div);
607+
hidden.push(div);
606608
jax.HTMLCSS.isHidden = true;
607609
ex = this.defaultEx; em = this.defaultEm; cwidth = this.defaultWidth;
608610
if (relwidth) {maxwidth = cwidth}
@@ -614,6 +616,10 @@
614616
jax.HTMLCSS.cwidth = cwidth/this.em;
615617
jax.HTMLCSS.lineWidth = (linebreak ? this.length2em(width,1,maxwidth/this.em) : 1000000);
616618
}
619+
for (i = 0, n = hidden.length; i < n; i++) {
620+
this.hiddenDiv.appendChild(hidden[i]);
621+
this.addElement(this.hiddenDiv,"br");
622+
}
617623
//
618624
// Remove the test spans used for determining scales and linebreak widths
619625
//
@@ -676,9 +682,8 @@
676682
}
677683
this.restorePreview(script);
678684
//
679-
// Put it in place, remove the processing marker, and signal the new math
685+
// Remove the processing marker, and signal the new math pending
680686
//
681-
if (jax.HTMLCSS.isHidden) {script.parentNode.insertBefore(div,script)}
682687
div.className = div.className.split(/ /)[0] + " MathJax_Processed";
683688
HUB.signal.Post(["New Math Pending",jax.inputID]); // FIXME: wait for this? (i.e., restart if returns uncalled callback)
684689
//
@@ -732,7 +737,8 @@
732737
for (i = state.HTMLCSSlast, m = state.HTMLCSSeqn; i < m; i++) {
733738
script = scripts[i];
734739
if (script && script.MathJax.elementJax) {
735-
script.previousSibling.className = script.previousSibling.className.split(/ /)[0];
740+
var div = script.MathJax.elementJax.HTMLCSS.div;
741+
div.className = div.className.split(/ /)[0];
736742
if (script.MathJax.preview) {script.MathJax.preview.innerHTML = ""}
737743
}
738744
}
@@ -757,6 +763,7 @@
757763
//
758764
jax = script.MathJax.elementJax; this.getMetrics(jax);
759765
jax.root.toHTML(jax.HTMLCSS.span,jax.HTMLCSS.div,this.PHASE.III);
766+
if (jax.HTMLCSS.isHidden) script.parentNode.insertBefore(jax.HTMLCSS.div,script);
760767
delete jax.HTMLCSS.span; delete jax.HTMLCSS.div;
761768
//
762769
// The math is now fully processed

0 commit comments

Comments
 (0)