Don't allow labels to overlap equations in HTML-CSS mode. Because HTML-CSS allows tables that fill 100% of the width, making this work for centered equations is sub-optimal as we have to leave space on both sides of the equation to balance the label width. Issue #596.

This commit is contained in:
Davide P. Cervone 2015-07-13 10:52:04 -04:00
parent b9e428e2cf
commit bcdb2f1048
2 changed files with 20 additions and 13 deletions

View File

@ -428,24 +428,31 @@ MathJax.Hub.Register.StartupHook("HTML-CSS Jax Ready",function () {
if (indent.indentshiftfirst !== MML.INDENTSHIFT.INDENTSHIFT) {indent.indentshift = indent.indentshiftfirst} if (indent.indentshiftfirst !== MML.INDENTSHIFT.INDENTSHIFT) {indent.indentshift = indent.indentshiftfirst}
if (indent.indentshift === "auto") {indent.indentshift = "0"} if (indent.indentshift === "auto") {indent.indentshift = "0"}
var shift = HTMLCSS.length2em(indent.indentshift,mu,HTMLCSS.cwidth); var shift = HTMLCSS.length2em(indent.indentshift,mu,HTMLCSS.cwidth);
var labelshift = HTMLCSS.length2em(values.minlabelspacing,mu,HTMLCSS.cwidth); var labelspace = HTMLCSS.length2em(values.minlabelspacing,mu,HTMLCSS.cwidth);
if (this.displayIndent !== "0") { var labelW = labelspace + C[LABEL].bbox.w, labelshift = 0, tw = mw;
var dIndent = HTMLCSS.length2em(this.displayIndent,mu,HTMLCSS.cwidth); var dIndent = HTMLCSS.length2em(this.displayIndent,mu,HTMLCSS.cwidth);
shift += (indent.indentAlign === MML.INDENTALIGN.RIGHT ? -dIndent: dIndent); var s = (CALIGN[LABEL] === MML.INDENTALIGN.RIGHT ? -1 : 1);
if (indent.indentalign === MML.INDENTALIGN.CENTER) {
tw += 2 * (labelW - s*(shift + dIndent));
shift += dIndent;
} else if (CALIGN[LABEL] === indent.indentalign) {
if (dIndent < 0) {labelshift = s*dIndent; dIndent = 0}
shift += s*dIndent; if (labelW > s*shift) shift = s*labelW; shift += labelshift;
tw += s*shift;
} else {
tw += labelW - s*shift + dIndent;
shift -= s*dIndent;
} }
var eqn = HTMLCSS.createStack(span,false,"100%"); var eqn = HTMLCSS.createStack(span,false,"100%");
HTMLCSS.addBox(eqn,stack); HTMLCSS.alignBox(stack,indent.indentalign,0,shift); HTMLCSS.addBox(eqn,stack); HTMLCSS.alignBox(stack,indent.indentalign,0,shift);
C[LABEL].parentNode.parentNode.removeChild(C[LABEL].parentNode); C[LABEL].parentNode.parentNode.removeChild(C[LABEL].parentNode);
HTMLCSS.addBox(eqn,C[LABEL]); HTMLCSS.alignBox(C[LABEL],CALIGN[LABEL],0); HTMLCSS.addBox(eqn,C[LABEL]); HTMLCSS.alignBox(C[LABEL],CALIGN[LABEL],0);
if (HTMLCSS.msieRelativeWidthBug) {stack.style.top = C[LABEL].style.top = ""} if (HTMLCSS.msieRelativeWidthBug) {stack.style.top = C[LABEL].style.top = ""}
if (hasRelativeWidth) {stack.style.width = values.width; span.bbox.width = "100%"} if (hasRelativeWidth) {stack.style.width = values.width; span.bbox.width = "100%"}
C[LABEL].style.marginRight = C[LABEL].style.marginLeft = HTMLCSS.Em(labelshift); C[LABEL].style[s === 1 ? "marginLeft" : "marginRight"] = HTMLCSS.Em(s*labelshift);
if (indent.indentalign === MML.INDENTALIGN.CENTER) {mw += 4*labelshift + 2*C[LABEL].bbox.w} span.bbox.tw = tw;
else if (indent.indentalign !== CALIGN[LABEL]) {mw += 2*labelshift + C[LABEL].bbox.w} span.style.minWidth = span.bbox.minWidth = HTMLCSS.Em(tw);
mw = Math.max(0,mw+shift); span.bbox.tw = mw + 2*labelshift; eqn.style.minWidth = eqn.bbox.minWidth = HTMLCSS.Em(tw/scale);
span.style.minWidth = span.bbox.minWidth = HTMLCSS.Em(mw);
eqn.style.minWidth = eqn.bbox.minWidth = HTMLCSS.Em(mw/HTMLCSS.scale);
} }
// //
// Finish the table // Finish the table

View File

@ -2936,10 +2936,10 @@
node.style.textAlign = values.indentalign; node.style.textAlign = values.indentalign;
// ### FIXME: make percentage widths respond to changes in container // ### FIXME: make percentage widths respond to changes in container
if (shift) { if (shift) {
shift *= HTMLCSS.em/HTMLCSS.outerEm; shift *= HTMLCSS.scale;
HUB.Insert(span.style,({ HUB.Insert(span.style,({
left: {marginLeft: HTMLCSS.Em(shift)}, left: {marginLeft: HTMLCSS.Em(shift)},
right: {marginLeft: HTMLCSS.Em(Math.max(0,span.bbox.w+shift)), marginRight: HTMLCSS.Em(-shift)}, right: {marginRight: HTMLCSS.Em(-shift)},
center: {marginLeft: HTMLCSS.Em(shift), marginRight: HTMLCSS.Em(-shift)} center: {marginLeft: HTMLCSS.Em(shift), marginRight: HTMLCSS.Em(-shift)}
})[values.indentalign]); })[values.indentalign]);
// //