Add min-width to displayed equations with labels so that they cause their containers to have non-zero width (like when they are in a table cell). Resolves issue #428.

This commit is contained in:
Davide P. Cervone 2013-04-29 10:48:45 -04:00
parent 9178a9af0e
commit d6b6aa8111
3 changed files with 20 additions and 9 deletions

View File

@ -24,7 +24,7 @@
*/
MathJax.Hub.Register.StartupHook("HTML-CSS Jax Ready",function () {
var VERSION = "2.1";
var VERSION = "2.1.1";
var MML = MathJax.ElementJax.mml,
HTMLCSS = MathJax.OutputJax["HTML-CSS"];
@ -419,6 +419,7 @@ MathJax.Hub.Register.StartupHook("HTML-CSS Jax Ready",function () {
// Place the labels, if any
//
if (C[LABEL]) {
var min = stack.bbox.w, dw;
var indent = this.getValues("indentalignfirst","indentshiftfirst","indentalign","indentshift");
if (indent.indentalignfirst !== MML.INDENTALIGN.INDENTALIGN) {indent.indentalign = indent.indentalignfirst}
if (indent.indentalign === MML.INDENTALIGN.AUTO) {indent.indentalign = this.displayAlign}
@ -427,14 +428,19 @@ MathJax.Hub.Register.StartupHook("HTML-CSS Jax Ready",function () {
var eqn = HTMLCSS.createStack(span,false,"100%");
HTMLCSS.addBox(eqn,stack); HTMLCSS.alignBox(stack,indent.indentalign,0);
if (indent.indentshift && indent.indentalign !== MML.INDENTALIGN.CENTER) {
stack.style[indent.indentalign] = HTMLCSS.Em(HTMLCSS.length2em(indent.indentshift,mu));
dw = HTMLCSS.length2em(indent.indentshift,mu); min += dw;
stack.style[indent.indentalign] = HTMLCSS.Em(dw);
}
C[LABEL].parentNode.parentNode.removeChild(C[LABEL].parentNode);
HTMLCSS.addBox(eqn,C[LABEL]); HTMLCSS.alignBox(C[LABEL],CALIGN[LABEL],0);
if (HTMLCSS.msieRelativeWidthBug) {stack.style.top = C[LABEL].style.top = ""}
if (hasRelativeWidth) {stack.style.width = values.width; span.bbox.width = "100%"}
C[LABEL].style.marginRight = C[LABEL].style.marginLeft =
HTMLCSS.Em(HTMLCSS.length2em(values.minlabelspacing,mu));
dw = HTMLCSS.length2em(values.minlabelspacing,mu);
C[LABEL].style.marginRight = C[LABEL].style.marginLeft = HTMLCSS.Em(dw);
if (indent.indentalign === MML.INDENTALIGN.CENTER) {min += 4*dw + 2*C[LABEL].bbox.w}
else if (indent.indentalign !== CALIGN[LABEL]) {min += 2*dw + C[LABEL].bbox.w}
span.style.minWidth = span.bbox.minWidth =
eqn.style.minWidth = eqn.bbox.minWidth = HTMLCSS.Em(min);
}
//
// Finish the table
@ -458,7 +464,8 @@ MathJax.Hub.Register.StartupHook("HTML-CSS Jax Ready",function () {
},
HTMLhandleSpace: function (span) {
span.bbox.keepPadding = true; span.bbox.exact = true;
if (!this.hasFrame) {span.style.paddingLeft = span.style.paddingRight = HTMLCSS.Em(1/6)}
if (!this.hasFrame && span.bbox.width == null)
{span.style.paddingLeft = span.style.paddingRight = HTMLCSS.Em(1/6)}
this.SUPER(arguments).HTMLhandleSpace.call(this,span);
}
});

View File

@ -24,7 +24,7 @@
MathJax.OutputJax["HTML-CSS"] = MathJax.OutputJax({
id: "HTML-CSS",
version: "2.1.2",
version: "2.1.3",
directory: MathJax.OutputJax.directory + "/HTML-CSS",
extensionDir: MathJax.OutputJax.extensionDir + "/HTML-CSS",
autoloadDir: MathJax.OutputJax.directory + "/HTML-CSS/autoload",

View File

@ -1059,7 +1059,10 @@
if (bbox.rw + x > BBOX.rw) {BBOX.rw = bbox.rw + x}
if (bbox.lw + x < BBOX.lw) {BBOX.lw = bbox.lw + x}
if (bbox.width != null && !bbox.isFixed) {
if (BBOX.width == null) {parent.style.width = BBOX.width = "100%"}
if (BBOX.width == null) {
parent.style.width = BBOX.width = "100%";
if (bbox.minWidth) {parent.style.minWidth = BBOX.minWidth = bbox.minWidth}
}
span.style.width = bbox.width;
}
}
@ -1593,7 +1596,7 @@
if (BBOX.w + bbox.rw > BBOX.rw) {BBOX.rw = BBOX.w + bbox.rw}
BBOX.w += bbox.w;
if (child.style.paddingRight) {BBOX.w += HTMLCSS.unEm(child.style.paddingRight)*(child.scale||1)}
if (bbox.width) {BBOX.width = bbox.width}
if (bbox.width) {BBOX.width = bbox.width; BBOX.minWidth = bbox.minWidth}
if (bbox.ic) {BBOX.ic = bbox.ic} else {delete BBOX.ic}
if (BBOX.exactW && !bbox.exactW) {delete BBOX.exactW}
},
@ -2636,7 +2639,8 @@
span.bbox.h *= f; span.bbox.d *= f; span.bbox.w *= f;
span.bbox.lw *= f; span.bbox.rw *= f;
if (math && math.bbox.width != null) {
stack.style.width = math.bbox.width;
span.style.minWidth = (math.bbox.minWidth || span.style.width);
span.style.width = stack.style.width = math.bbox.width;
box.style.width = "100%";
}
//