Skip to content

Commit ed932ec

Browse files
committed
Properly handle the width of math and mtd elements by explicitly setting the width from the child mrow (works around FF bug that gets these widths wrong). Resolves issue #558.
1 parent 02261ae commit ed932ec

File tree

1 file changed

+24
-6
lines changed
  • unpacked/jax/output/NativeMML

1 file changed

+24
-6
lines changed

unpacked/jax/output/NativeMML/jax.js

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,8 @@
120120
}
121121
},
122122
settings: HUB.config.menuSettings,
123-
ex: 1, // filled in later
123+
ex: 1, scale: 1, // filled in later
124+
adjustWidths: [], // array of elements to have their widths adjusted
124125

125126
Config: function () {
126127
this.SUPER(arguments).Config.call(this);
@@ -258,7 +259,7 @@
258259
if (ex === 0 || ex === "NaN") {ex = this.defaultEx; mex = this.defaultMEx}
259260
scale = (mex > 1 ? ex/mex : 1) * this.config.scale;
260261
scale = Math.floor(Math.max(this.config.minScaleAdjust/100,scale));
261-
jax.NativeMML.ex = ex;
262+
jax.NativeMML.ex = ex; jax.NativeMML.scale = scale/100;
262263
} else {scale = 100}
263264
jax.NativeMML.fontSize = scale+"%";
264265
}
@@ -287,6 +288,7 @@
287288
container = span.firstChild, mspan = container.firstChild;
288289
span.style.fontSize = jax.NativeMML.fontSize;
289290
this.ex = jax.NativeMML.ex || this.defaultEx;
291+
this.scale = jax.NativeMML.scale || 1;
290292
//
291293
// Convert to MathML (if restarted, remove any partial math)
292294
//
@@ -814,11 +816,14 @@
814816
toNativeMML: function (parent) {
815817
var tag = parent.appendChild(this.NativeMMLelement(this.type));
816818
this.NativeMMLattributes(tag);
817-
if (nMML.widthBug) {tag = tag.appendChild(this.NativeMMLelement("mrow"))}
819+
if (nMML.mtdWidthBug) {
820+
nMML.adjustWidths.push(tag);
821+
tag = tag.appendChild(this.NativeMMLelement("mrow"));
822+
}
818823
for (var i = 0, m = this.data.length; i < m; i++) {
819824
if (this.data[i]) {this.data[i].toNativeMML(tag)}
820825
else {tag.appendChild(this.NativeMMLelement("mrow"))}
821-
}
826+
}
822827
}
823828
});
824829

@@ -890,6 +895,7 @@
890895
MML.math.Augment({
891896
toNativeMML: function (parent) {
892897
var tag = this.NativeMMLelement(this.type), math = tag;
898+
nMML.adjustWidths = [];
893899
//
894900
// Some browsers don't seem to add the xmlns attribute, so do it by hand.
895901
//
@@ -936,12 +942,22 @@
936942
// parent element to match. Even if we set the <math> width properly,
937943
// it doesn't seem to propagate up to the <span> correctly.
938944
//
939-
if (nMML.widthBug && !mtable.nMMLforceWidth && mtable.nMMLlaMatch) {
945+
if (nMML.widthBug &&
946+
!(mtable.nMMLhasLabels && (mtable.nMMLforceWidth || !mtable.nMMLlaMatch))) {
940947
//
941948
// Convert size to ex's so that it scales properly if the print media
942949
// has a different font size.
943950
//
944-
parent.style.width = (math.firstChild.scrollWidth/nMML.ex).toFixed(3) + "ex";
951+
parent.style.width = (math.firstChild.scrollWidth/nMML.ex/nMML.scale).toFixed(3) + "ex";
952+
}
953+
for (var i = 0, m = nMML.adjustWidths.length; i < m; i++) {
954+
var tag = nMML.adjustWidths[i];
955+
var style = tag.getAttribute("style") || "";
956+
if (!style.match(/(^|;)\s*width:/)) {
957+
var width = tag.scrollWidth/nMML.ex;
958+
if (style !== "") {style += "; "}
959+
tag.setAttribute("style",style+"width:"+width+"ex");
960+
}
945961
}
946962
}
947963
});
@@ -1131,6 +1147,8 @@
11311147
// correctly and thus the element is displayed incorrectly in <mtable>.
11321148
nMML.spaceWidthBug = !browser.versionAtLeast("20.0");
11331149

1150+
nMML.mtdWidthBug = true; // <mtd> widths not properly determined
1151+
11341152
nMML.tableSpacingBug = true; // mtable@rowspacing/mtable@columnspacing not
11351153
// supported.
11361154
nMML.tableLabelBug = true; // mlabeledtr is not implemented.

0 commit comments

Comments
 (0)