commit b9e428e2cf40c883f742f5c604b92c82d8a63fc1
parent a9ab53ece81098cc0f34d54690b0b22de9c6063e
Author: Davide P. Cervone <dpvc@union.edu>
Date: Sat, 11 Jul 2015 16:23:17 -0400
Don't allow labels to overlap the equations in SVG mode. Resolves issue #596. Some situations still may not be optimal.
Diffstat:
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
@@ -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);