Skip to content

Commit 97ab12e

Browse files
committed
Properly determine container width for shrink-wrapped elements in CommonHTML. Issue mathjax#1478.
1 parent 22c1cf4 commit 97ab12e

File tree

1 file changed

+26
-8
lines changed
  • unpacked/jax/output/CommonHTML

1 file changed

+26
-8
lines changed

unpacked/jax/output/CommonHTML/jax.js

+26-8
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,10 @@
7171
".mjx-chtml[tabindex]:focus, body :focus .mjx-chtml[tabindex]": {
7272
display: "inline-table" // see issues #1282 and #1338
7373
},
74+
".mjx-full-width": {
75+
display: "table-cell",
76+
width: "10000em"
77+
},
7478

7579
".mjx-math": {
7680
"display": "inline-block",
@@ -170,6 +174,12 @@
170174
position: "absolute",
171175
width:"1px", height:"60ex"
172176
},
177+
".mjx-line-box-test": {
178+
display: "table-cell!important",
179+
width: "10000em!important",
180+
"min-width":0, "max-width":"none",
181+
padding:0, border:0, margin:0
182+
},
173183

174184
"#MathJax_CHTML_Tooltip": {
175185
"background-color": "InfoBackground", color: "InfoText",
@@ -232,6 +242,11 @@
232242
//
233243
this.TestSpan = CHTML.Element("mjx-test",{style:{left:"1em"}},[["mjx-ex-box-test"]]);
234244

245+
//
246+
// Used in preTranslate to get linebreak width
247+
//
248+
this.linebreakSpan = HTML.Element("span",{className:"mjx-line-box-test"});
249+
235250
//
236251
// Set up styles and preload web fonts
237252
//
@@ -260,9 +275,11 @@
260275
// Get the default sizes (need styles in place to do this)
261276
//
262277
document.body.appendChild(this.TestSpan);
278+
document.body.appendChild(this.linebreakSpan);
263279
this.defaultEm = this.getFontSize(this.TestSpan);
264280
this.defaultEx = this.TestSpan.firstChild.offsetHeight/60;
265-
this.defaultWidth = this.TestSpan.offsetWidth;
281+
this.defaultWidth = this.linebreakSpan.offsetWidth;
282+
document.body.removeChild(this.linebreakSpan);
266283
document.body.removeChild(this.TestSpan);
267284
},
268285
getFontSize: (window.getComputedStyle ?
@@ -422,6 +439,7 @@
422439
//
423440
// Add test nodes for determineing scales and linebreak widths
424441
//
442+
script.parentNode.insertBefore(this.linebreakSpan.cloneNode(true),script);
425443
script.parentNode.insertBefore(this.TestSpan.cloneNode(true),script);
426444
}
427445
//
@@ -434,12 +452,10 @@
434452
jax = script.MathJax.elementJax; if (!jax) continue;
435453
em = CHTML.getFontSize(test);
436454
ex = test.firstChild.offsetHeight/60;
437-
if (ex === 0 || ex === "NaN") ex = this.defaultEx
438-
node = test;
439-
while (node) {
440-
cwidth = node.offsetWidth; if (cwidth) break;
441-
cwidth = CHTML.getMaxWidth(node); if (cwidth) break;
442-
node = node.parentNode;
455+
cwidth = Math.max(0,test.previousSibling.offsetWidth-2);
456+
if (ex === 0 || ex === "NaN") {
457+
ex = this.defaultEx;
458+
cwidth = this.defaultWidth;
443459
}
444460
if (relwidth) maxwidth = cwidth;
445461
scale = (this.config.matchFontHeight ? ex/this.TEX.x_height/em : 1);
@@ -455,7 +471,9 @@
455471
for (i = 0; i < m; i++) {
456472
script = scripts[i]; if (!script.parentNode) continue;
457473
test = scripts[i].previousSibling;
474+
span = test.previousSibling;
458475
jax = scripts[i].MathJax.elementJax; if (!jax) continue;
476+
span.parentNode.removeChild(span);
459477
test.parentNode.removeChild(test);
460478
}
461479
state.CHTMLeqn = state.CHTMLlast = 0; state.CHTMLi = -1;
@@ -1723,8 +1741,8 @@
17231741
var alttext = this.Get("alttext");
17241742
if (alttext && !node.getAttribute("aria-label")) node.setAttribute("aria-label",alttext);
17251743
if (this.CHTML.pwidth) {
1726-
node.parentNode.style.width = this.CHTML.pwidth;
17271744
node.parentNode.style.minWidth = this.CHTML.mwidth||CHTML.Em(this.CHTML.w);
1745+
node.parentNode.className += " mjx-full-width";
17281746
} else if (!this.isMultiline && this.Get("display") === "block") {
17291747
var values = this.getValues("indentalignfirst","indentshiftfirst","indentalign","indentshift");
17301748
if (values.indentalignfirst !== MML.INDENTALIGN.INDENTALIGN) values.indentalign = values.indentalignfirst;

0 commit comments

Comments
 (0)