Skip to content

Commit 1332145

Browse files
committed
Merge branch 'issue993' into develop. Issue #993.
2 parents 4adc572 + 1b8811b commit 1332145

File tree

1 file changed

+26
-5
lines changed
  • unpacked/jax/output/NativeMML

1 file changed

+26
-5
lines changed

unpacked/jax/output/NativeMML/jax.js

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,24 @@
357357
//
358358
MMLnamespace: "http://www.w3.org/1998/Math/MathML",
359359

360+
isFullWidth: function (node) {
361+
if (!node) return;
362+
var width = node.getAttribute("width") ||
363+
(String(node.getAttribute("style")).match(/(?:^| )width: *([^; ]*)/)||[])[1];
364+
if (width) return !!width.match(/%/);
365+
if (node.nodeName.match(/^(semantics|math|mstyle)$/)) {
366+
width = this.isFullWidth(node.firstChild);
367+
} else if (node.nodeName.toLowerCase() === "mrow") {
368+
for (var i = 0, m = node.childNodes.length; i < m && !width; i++)
369+
width = this.isFullWidth(node.childNodes[i]);
370+
}
371+
if (width) {
372+
var style = "width:100%; "+(node.getAttribute("style")||"");
373+
node.setAttribute("style",style.replace(/ +$/,""));
374+
}
375+
return width;
376+
},
377+
360378
//
361379
// For MSIE, we must overlay the MathPlayer object to trap the events
362380
// (since they can't be cancelled when the events are on the <math> tag
@@ -954,15 +972,14 @@
954972
}
955973
//
956974
// Look for a top-level mtable and if it has labels
957-
// Make sure the containers have 100% width, when needed
975+
// Make sure the containers have 100% width, when needed.
958976
// If the label is on the same side as alignment,
959977
// override the margin set by the stylesheet.
960978
//
961-
var mtable = ((this.data[0]||[]).data[0]||{});
979+
var mtable = ((this.data[0]||{data:[]}).data[0]||{});
962980
if (mtable.nMMLhasLabels) {
963981
if (mtable.nMMLforceWidth || !mtable.nMMLlaMatch) {
964982
tag.setAttribute("style","width:100%") // mrow node
965-
parent.style.width = parent.parentNode.style.width="100%";
966983
if (annotate) tag.parentNode.setAttribute("style","width:100%"); // semantics node
967984
};
968985
if (mtable.nMMLlaMatch) {
@@ -973,6 +990,11 @@
973990
}
974991
}
975992
//
993+
// Check if container must have width set to 100%
994+
//
995+
var fullWidth = nMML.isFullWidth(math);
996+
if (fullWidth) {parent.style.width = parent.parentNode.style.width = "100%"}
997+
//
976998
// Add the math to the page
977999
//
9781000
parent.appendChild(math);
@@ -982,8 +1004,7 @@
9821004
// parent element to match. Even if we set the <math> width properly,
9831005
// it doesn't seem to propagate up to the <span> correctly.
9841006
//
985-
if (nMML.widthBug &&
986-
!(mtable.nMMLhasLabels && (mtable.nMMLforceWidth || !mtable.nMMLlaMatch))) {
1007+
if (nMML.widthBug &&!fullWidth) {
9871008
//
9881009
// Convert size to ex's so that it scales properly if the print media
9891010
// has a different font size.

0 commit comments

Comments
 (0)