From b9e428e2cf40c883f742f5c604b92c82d8a63fc1 Mon Sep 17 00:00:00 2001 From: "Davide P. Cervone" Date: Sat, 11 Jul 2015 16:23:17 -0400 Subject: [PATCH 1/3] Don't allow labels to overlap the equations in SVG mode. Resolves issue #596. Some situations still may not be optimal. --- unpacked/jax/output/SVG/autoload/mtable.js | 32 ++++++++++++++++------ 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/unpacked/jax/output/SVG/autoload/mtable.js b/unpacked/jax/output/SVG/autoload/mtable.js index 6cb657132..4f85381db 100644 --- a/unpacked/jax/output/SVG/autoload/mtable.js +++ b/unpacked/jax/output/SVG/autoload/mtable.js @@ -331,17 +331,33 @@ MathJax.Hub.Register.StartupHook("SVG Jax Ready",function () { if (indent.indentshiftfirst !== MML.INDENTSHIFT.INDENTSHIFT) {indent.indentshift = indent.indentshiftfirst} if (indent.indentshift === "auto" || indent.indentshift === "") {indent.indentshift = "0"} var shift = SVG.length2em(indent.indentshift,mu,SVG.cwidth); - var labelshift = SVG.length2em(values.minlabelspacing,mu,SVG.cwidth); - if (this.displayIndent !== "0") { - var dIndent = SVG.length2em(this.displayIndent,mu,SVG.cwidth); - shift += (indent.indentAlign === MML.INDENTALIGN.RIGHT ? -dIndent: dIndent); + var labelspace = SVG.length2em(values.minlabelspacing,mu,SVG.cwidth); + var labelW = labelspace + C[LABEL].w, labelshift = 0, tw = svg.w; + var dIndent = SVG.length2em(this.displayIndent,mu,SVG.cwidth); + var s = (CALIGN[LABEL] === MML.INDENTALIGN.RIGHT ? -1 : 1); + if (indent.indentalign === MML.INDENTALIGN.CENTER) { + var dx = (SVG.cwidth-tw)/2; shift += dIndent; + if (labelW + s*labelshift > dx + s*shift) { + indent.indentalign = CALIGN[LABEL]; + shift = s*(labelW + s*labelshift); tw += labelW + Math.max(0,shift); + } + } 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 { + shift -= s*dIndent; + if (tw - s*shift + labelW > SVG.cwidth) { + shift = s*(tw + labelW - SVG.cwidth); + if (s*shift > 0) {tw = SVG.cwidth + s*shift; shift = 0} + } } var eqn = svg; svg = this.SVG(); - svg.w = svg.r = SVG.cwidth; svg.hasIndent = true; - svg.Align(C[LABEL],CALIGN[LABEL],labelshift,0); + svg.hasIndent = true; + svg.w = svg.r = Math.max(tw,SVG.cwidth); + svg.Align(C[LABEL],CALIGN[LABEL],0,0,labelshift); svg.Align(eqn,indent.indentalign,0,0,shift); - svg.tw += C[LABEL].w + shift + - (indent.indentalign === MML.INDENTALIGN.CENTER ? 8 : 4)*labelshift; + svg.tw = tw; } this.SVGsaveData(svg); From bcdb2f104842371920e70ff4a6aa822f0ae4becc Mon Sep 17 00:00:00 2001 From: "Davide P. Cervone" Date: Mon, 13 Jul 2015 10:52:04 -0400 Subject: [PATCH 2/3] 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. --- .../jax/output/HTML-CSS/autoload/mtable.js | 29 ++++++++++++------- unpacked/jax/output/HTML-CSS/jax.js | 4 +-- 2 files changed, 20 insertions(+), 13 deletions(-) diff --git a/unpacked/jax/output/HTML-CSS/autoload/mtable.js b/unpacked/jax/output/HTML-CSS/autoload/mtable.js index 855a08e7d..3e6759fae 100644 --- a/unpacked/jax/output/HTML-CSS/autoload/mtable.js +++ b/unpacked/jax/output/HTML-CSS/autoload/mtable.js @@ -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.indentshift === "auto") {indent.indentshift = "0"} var shift = HTMLCSS.length2em(indent.indentshift,mu,HTMLCSS.cwidth); - var labelshift = HTMLCSS.length2em(values.minlabelspacing,mu,HTMLCSS.cwidth); - if (this.displayIndent !== "0") { - var dIndent = HTMLCSS.length2em(this.displayIndent,mu,HTMLCSS.cwidth); - shift += (indent.indentAlign === MML.INDENTALIGN.RIGHT ? -dIndent: dIndent); + var labelspace = HTMLCSS.length2em(values.minlabelspacing,mu,HTMLCSS.cwidth); + var labelW = labelspace + C[LABEL].bbox.w, labelshift = 0, tw = mw; + var dIndent = HTMLCSS.length2em(this.displayIndent,mu,HTMLCSS.cwidth); + 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%"); HTMLCSS.addBox(eqn,stack); HTMLCSS.alignBox(stack,indent.indentalign,0,shift); - 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(labelshift); - if (indent.indentalign === MML.INDENTALIGN.CENTER) {mw += 4*labelshift + 2*C[LABEL].bbox.w} - else if (indent.indentalign !== CALIGN[LABEL]) {mw += 2*labelshift + C[LABEL].bbox.w} - mw = Math.max(0,mw+shift); span.bbox.tw = mw + 2*labelshift; - span.style.minWidth = span.bbox.minWidth = HTMLCSS.Em(mw); - eqn.style.minWidth = eqn.bbox.minWidth = HTMLCSS.Em(mw/HTMLCSS.scale); + C[LABEL].style[s === 1 ? "marginLeft" : "marginRight"] = HTMLCSS.Em(s*labelshift); + span.bbox.tw = tw; + span.style.minWidth = span.bbox.minWidth = HTMLCSS.Em(tw); + eqn.style.minWidth = eqn.bbox.minWidth = HTMLCSS.Em(tw/scale); } // // Finish the table diff --git a/unpacked/jax/output/HTML-CSS/jax.js b/unpacked/jax/output/HTML-CSS/jax.js index b4888426c..2250af1d4 100644 --- a/unpacked/jax/output/HTML-CSS/jax.js +++ b/unpacked/jax/output/HTML-CSS/jax.js @@ -2936,10 +2936,10 @@ node.style.textAlign = values.indentalign; // ### FIXME: make percentage widths respond to changes in container if (shift) { - shift *= HTMLCSS.em/HTMLCSS.outerEm; + shift *= HTMLCSS.scale; HUB.Insert(span.style,({ 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)} })[values.indentalign]); // From d70612a519144a18599cdff0741a9fa8587c4a66 Mon Sep 17 00:00:00 2001 From: "Davide P. Cervone" Date: Tue, 14 Jul 2015 14:35:02 -0400 Subject: [PATCH 3/3] Don't need to add extra mtd for tags any longer. --- unpacked/extensions/TeX/AMSmath.js | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/unpacked/extensions/TeX/AMSmath.js b/unpacked/extensions/TeX/AMSmath.js index 5bcaeba21..06c3e4fb7 100644 --- a/unpacked/extensions/TeX/AMSmath.js +++ b/unpacked/extensions/TeX/AMSmath.js @@ -571,22 +571,8 @@ MathJax.Hub.Register.StartupHook("TeX Jax Ready",function () { var def = { side: TEX.config.TagSide, minlabelspacing: TEX.config.TagIndent, - columnalign: mml.displayAlign, displaystyle: "inherit" // replaced by TeX input jax Translate() function with actual value }; - if (mml.displayAlign === MML.INDENTALIGN.LEFT) { - def.width = "100%"; - if (mml.displayIndent !== "0") { - def.columnwidth = mml.displayIndent + " fit"; def.columnspacing = "0" - row = [row[0],MML.mtd(),row[1]]; - } - } else if (mml.displayAlign === MML.INDENTALIGN.RIGHT) { - def.width = "100%"; - if (mml.displayIndent !== "0") { - def.columnwidth = "fit "+mml.displayIndent; def.columnspacing = "0" - row[2] = MML.mtd(); - } - } mml = MML.mtable(MML.mlabeledtr.apply(MML,row)).With(def); } return STACKITEM.mml(mml);