|
539 | 539 | },
|
540 | 540 |
|
541 | 541 | 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, |
543 | 543 | script, prev, span, div, test, jax, ex, em, scale, maxwidth, relwidth = false, cwidth,
|
544 | 544 | linebreak = this.config.linebreaks.automatic, width = this.config.linebreaks.width;
|
545 | 545 | if (linebreak) {
|
|
590 | 590 | //
|
591 | 591 | // Determine the scaling factors for each script
|
592 | 592 | // (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). |
593 | 595 | //
|
| 596 | + var hidden = []; |
594 | 597 | for (i = 0; i < m; i++) {
|
595 | 598 | script = scripts[i]; if (!script.parentNode) continue;
|
596 | 599 | test = script.previousSibling; div = test.previousSibling;
|
|
601 | 604 | if (relwidth) {maxwidth = cwidth}
|
602 | 605 | if (ex === 0 || ex === "NaN") {
|
603 | 606 | // 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); |
606 | 608 | jax.HTMLCSS.isHidden = true;
|
607 | 609 | ex = this.defaultEx; em = this.defaultEm; cwidth = this.defaultWidth;
|
608 | 610 | if (relwidth) {maxwidth = cwidth}
|
|
614 | 616 | jax.HTMLCSS.cwidth = cwidth/this.em;
|
615 | 617 | jax.HTMLCSS.lineWidth = (linebreak ? this.length2em(width,1,maxwidth/this.em) : 1000000);
|
616 | 618 | }
|
| 619 | + for (i = 0, n = hidden.length; i < n; i++) { |
| 620 | + this.hiddenDiv.appendChild(hidden[i]); |
| 621 | + this.addElement(this.hiddenDiv,"br"); |
| 622 | + } |
617 | 623 | //
|
618 | 624 | // Remove the test spans used for determining scales and linebreak widths
|
619 | 625 | //
|
|
676 | 682 | }
|
677 | 683 | this.restorePreview(script);
|
678 | 684 | //
|
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 |
680 | 686 | //
|
681 |
| - if (jax.HTMLCSS.isHidden) {script.parentNode.insertBefore(div,script)} |
682 | 687 | div.className = div.className.split(/ /)[0] + " MathJax_Processed";
|
683 | 688 | HUB.signal.Post(["New Math Pending",jax.inputID]); // FIXME: wait for this? (i.e., restart if returns uncalled callback)
|
684 | 689 | //
|
|
732 | 737 | for (i = state.HTMLCSSlast, m = state.HTMLCSSeqn; i < m; i++) {
|
733 | 738 | script = scripts[i];
|
734 | 739 | 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]; |
736 | 742 | if (script.MathJax.preview) {script.MathJax.preview.innerHTML = ""}
|
737 | 743 | }
|
738 | 744 | }
|
|
757 | 763 | //
|
758 | 764 | jax = script.MathJax.elementJax; this.getMetrics(jax);
|
759 | 765 | jax.root.toHTML(jax.HTMLCSS.span,jax.HTMLCSS.div,this.PHASE.III);
|
| 766 | + if (jax.HTMLCSS.isHidden) script.parentNode.insertBefore(jax.HTMLCSS.div,script); |
760 | 767 | delete jax.HTMLCSS.span; delete jax.HTMLCSS.div;
|
761 | 768 | //
|
762 | 769 | // The math is now fully processed
|
|
0 commit comments