From 1e219b4304f5b1cf34c911989219e49a7a1d2d1f Mon Sep 17 00:00:00 2001 From: "Davide P. Cervone" Date: Wed, 10 Sep 2014 22:05:03 -0400 Subject: [PATCH] Get linebreaking size correct for zoom boxes, and do a better job of managing the width for full-width tables (only make the box as wide as necessary). Resolves issue #834. --- unpacked/jax/output/HTML-CSS/autoload/mtable.js | 5 +++-- unpacked/jax/output/HTML-CSS/jax.js | 10 ++++++++-- unpacked/jax/output/SVG/autoload/mtable.js | 3 +++ unpacked/jax/output/SVG/jax.js | 7 +++++-- 4 files changed, 19 insertions(+), 6 deletions(-) diff --git a/unpacked/jax/output/HTML-CSS/autoload/mtable.js b/unpacked/jax/output/HTML-CSS/autoload/mtable.js index f144376dc..b08af5443 100644 --- a/unpacked/jax/output/HTML-CSS/autoload/mtable.js +++ b/unpacked/jax/output/HTML-CSS/autoload/mtable.js @@ -443,8 +443,9 @@ MathJax.Hub.Register.StartupHook("HTML-CSS Jax Ready",function () { 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} - span.style.minWidth = span.bbox.minWidth = HTMLCSS.Em(Math.max(0,mw+shift)); - eqn.style.minWidth = eqn.bbox.minWidth = HTMLCSS.Em(Math.max(0,(mw+shift)/HTMLCSS.scale)); + 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); } // // Finish the table diff --git a/unpacked/jax/output/HTML-CSS/jax.js b/unpacked/jax/output/HTML-CSS/jax.js index 0c8fbde31..e17665109 100644 --- a/unpacked/jax/output/HTML-CSS/jax.js +++ b/unpacked/jax/output/HTML-CSS/jax.js @@ -771,15 +771,19 @@ this.em = MML.mbase.prototype.em = em; this.outerEm = em / jax.HTMLCSS.scale; emex.parentNode.removeChild(emex); + this.scale = jax.HTMLCSS.scale; + this.linebreakWidth = jax.HTMLCSS.lineWidth; + this.cwidth = jax.HTMLCSS.cwidth; this.zoomScale = parseInt(HUB.config.menuSettings.zscale) / 100; this.idPostfix = "-zoom"; jax.root.toHTML(span,span); this.idPostfix = ""; this.zoomScale = 1; - var width = jax.root.HTMLspanElement().bbox.width; + var bbox = jax.root.HTMLspanElement().bbox, width = bbox.width; if (width) { // Handle full-width displayed equations - // FIXME: this is a hack for now + if (bbox.tw) {Mw = bbox.tw*em} + if (bbox.w*em < Mw) {Mw = bbox.w*em} span.style.width = Math.floor(Mw-1.5*HTMLCSS.em)+"px"; span.style.display="inline-block"; var id = (jax.root.id||"MathJax-Span-"+jax.root.spanID)+"-zoom"; var child = document.getElementById(id).firstChild; @@ -1203,6 +1207,7 @@ } span.style.width = bbox.width; } + if (bbox.tw) {BBOX.tw = bbox.tw} } }, alignBox: function (span,align,y,dx) { @@ -1752,6 +1757,7 @@ 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; BBOX.minWidth = bbox.minWidth} + if (bbox.tw) {BBOX.tw = bbox.tw} if (bbox.ic) {BBOX.ic = bbox.ic} else {delete BBOX.ic} if (BBOX.exactW && !bbox.exactW) {delete BBOX.exactW} }, diff --git a/unpacked/jax/output/SVG/autoload/mtable.js b/unpacked/jax/output/SVG/autoload/mtable.js index 0f72d5a28..fcac4a5a2 100644 --- a/unpacked/jax/output/SVG/autoload/mtable.js +++ b/unpacked/jax/output/SVG/autoload/mtable.js @@ -324,6 +324,7 @@ MathJax.Hub.Register.StartupHook("SVG Jax Ready",function () { // Place the labels, if any // if (C[LABEL]) { + svg.tw = Math.max(svg.w,svg.r) - Math.min(0,svg.l); 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} @@ -339,6 +340,8 @@ MathJax.Hub.Register.StartupHook("SVG Jax Ready",function () { svg.w = svg.r = SVG.cwidth; svg.hasIndent = true; svg.Align(C[LABEL],CALIGN[LABEL],labelshift,0); svg.Align(eqn,indent.indentalign,0,0,shift); + svg.tw += C[LABEL].w + shift + + (indent.indentalign === MML.INDENTALIGN.CENTER ? 8 : 4)*labelshift; } this.SVGsaveData(svg); diff --git a/unpacked/jax/output/SVG/jax.js b/unpacked/jax/output/SVG/jax.js index 4df6c3f44..d8180788f 100644 --- a/unpacked/jax/output/SVG/jax.js +++ b/unpacked/jax/output/SVG/jax.js @@ -431,12 +431,13 @@ // var emex = span.appendChild(this.ExSpan.cloneNode(true)); var ex = emex.firstChild.offsetHeight/60; - this.em = MML.mbase.prototype.em = ex / SVG.TeX.x_height * 1000; - this.cwidth = .85*SVG.defaultWidth/this.em * 1000; + this.em = MML.mbase.prototype.em = ex / SVG.TeX.x_height * 1000; this.ex = ex; + this.linebreakWidth = jax.SVG.lineWidth; this.cwidth = jax.SVG.cwidth; emex.parentNode.removeChild(emex); span.appendChild(this.textSVG); this.mathDIV = span; this.zoomScale = parseInt(HUB.config.menuSettings.zscale) / 100; + var tw = jax.root.data[0].SVGdata.tw; if (tw && tw < this.cwidth) this.cwidth = tw; this.idPostfix = "-zoom"; jax.root.toSVG(span,span); this.idPostfix = ""; this.zoomScale = 1; span.removeChild(this.textSVG); @@ -879,6 +880,7 @@ delete svg.element; } if (svg.hasIndent) {this.hasIndent = svg.hasIndent} + if (svg.tw != null) {this.tw = svg.tw} if (svg.d - svg.y > this.d) {this.d = svg.d - svg.y; if (this.d > this.D) {this.D = this.d}} if (svg.y + svg.h > this.h) {this.h = svg.y + svg.h; if (this.h > this.H) {this.H = this.h}} if (svg.D - svg.y > this.D) {this.D = svg.D - svg.y} @@ -1094,6 +1096,7 @@ this.SVGdata.h = svg.h, this.SVGdata.d = svg.d; if (svg.y) {this.SVGdata.h += svg.y; this.SVGdata.d -= svg.y} if (svg.X != null) {this.SVGdata.X = svg.X} + if (svg.tw != null) {this.SVGdata.tw = svg.tw} if (svg.skew) {this.SVGdata.skew = svg.skew} if (svg.ic) {this.SVGdata.ic = svg.ic} if (this["class"]) {svg.removeable = false; SVG.Element(svg.element,{"class":this["class"]})}