Skip to content

Commit 22c1cf4

Browse files
committed
Properly determine container width for shrink-wrapped elements in HTML-CSS, and add the CSS from handle-floats into the standard HTML-CSS. Remove the content of the handle-floats extension. Issue mathjax#1478.
1 parent 67bca32 commit 22c1cf4

File tree

2 files changed

+22
-42
lines changed

2 files changed

+22
-42
lines changed

unpacked/extensions/HTML-CSS/handle-floats.js

+3-36
Original file line numberDiff line numberDiff line change
@@ -41,42 +41,9 @@ MathJax.Extension["HTML-CSS/handle-floats"] = {
4141
};
4242

4343
//
44-
// Make the display DIV be a table-cell
45-
// Use padding to get the separation, since table cells don't do margin
46-
// Make the width large (it will shrink to fit the remaining room)
44+
// This file is now obsolete, since the HTML-CSS output already handles
45+
// floating elements properly.
4746
//
48-
MathJax.Hub.Config({
49-
"HTML-CSS": {
50-
styles: {
51-
".MathJax_Display": {
52-
display: "table-cell",
53-
padding: "1em 0 ! important",
54-
width: (MathJax.Hub.Browser.isMSIE && (document.documentMode||0) < 8 ? "100%" : "1000em")
55-
}
56-
}
57-
}
58-
});
59-
60-
//
61-
// Two consecutive equations would end up side-by-side, so force a separator
62-
// (Needed by IE8, IE9, and Firefox, at least).
63-
//
64-
MathJax.Hub.Register.StartupHook("HTML-CSS Jax Ready",function () {
65-
var HTMLCSS = MathJax.OutputJax["HTML-CSS"],
66-
TRANSLATE = HTMLCSS.Translate;
67-
HTMLCSS.Augment({
68-
Translate: function (script,state) {
69-
TRANSLATE.apply(this,arguments);
70-
if (script.MathJax.elementJax.HTMLCSS.display) {
71-
var next = script.nextSibling;
72-
if (!next || next.className !== "MathJax_MSIE_Separator") {
73-
var span = HTMLCSS.Element("span",{className:"MathJax_MSIE_Separator"});
74-
script.parentNode.insertBefore(span,next);
75-
}
76-
}
77-
}
78-
});
79-
MathJax.Hub.Startup.signal.Post("HTML-CSS handle-floats Ready");
80-
});
8147

48+
MathJax.Hub.Startup.signal.Post("HTML-CSS handle-floats Ready");
8249
MathJax.Ajax.loadComplete("[MathJax]/extensions/HTML-CSS/handle-floats.js");

unpacked/jax/output/HTML-CSS/jax.js

+19-6
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,8 @@
241241

242242
var EVENT, TOUCH, HOVER; // filled in later
243243

244+
var oldIE = MathJax.Hub.Browser.isMSIE && (document.documentMode||0) < 8;
245+
244246
HTMLCSS.Augment({
245247
config: {
246248
styles: {
@@ -278,6 +280,11 @@
278280
"min-width": 0, "min-height": 0,
279281
width: "100%"
280282
},
283+
284+
".MathJax.MathJax_FullWidth": {
285+
display: "table-cell!important",
286+
width: "10000em!important"
287+
},
281288

282289
".MathJax img, .MathJax nobr, .MathJax a": {
283290
border: 0, padding: 0, margin: 0,
@@ -331,6 +338,12 @@
331338
width:"1px", height:"60em",
332339
"min-height": 0, "max-height":"none"
333340
},
341+
".MathJax_LineBox": {
342+
display: (oldIE ? "inline-block" : "table-cell") + "!important",
343+
width: (oldIE ? "100%" : "10000em") + "!important",
344+
"min-width":0, "max-width":"none",
345+
padding:0, border:0, margin:0
346+
},
334347

335348
".MathJax .MathJax_HitBox": {
336349
cursor: "text",
@@ -340,7 +353,7 @@
340353
".MathJax .MathJax_HitBox *": {
341354
filter: "none", opacity:1, background:"transparent" // for IE
342355
},
343-
356+
344357
"#MathJax_Tooltip": {
345358
position: "absolute", left: 0, top: 0,
346359
width: "auto", height: "auto",
@@ -482,8 +495,7 @@
482495
);
483496

484497
// Used in preTranslate to get linebreak width
485-
this.linebreakSpan = this.Element("span",null,
486-
[["hr",{style: {width:"100%", size:1, padding:0, border:0, margin:0}}]]);
498+
this.linebreakSpan = MathJax.HTML.Element("span",{className:"MathJax_LineBox"});
487499

488500
// Set up styles and preload web fonts
489501
return AJAX.Styles(this.config.styles,["InitializeHTML",this]);
@@ -539,7 +551,7 @@
539551
document.body.appendChild(this.linebreakSpan);
540552
this.defaultEx = this.EmExSpan.firstChild.offsetHeight/60;
541553
this.defaultEm = this.EmExSpan.lastChild.firstChild.offsetHeight/60;
542-
this.defaultWidth = this.linebreakSpan.firstChild.offsetWidth;
554+
this.defaultWidth = this.linebreakSpan.offsetWidth;
543555
document.body.removeChild(this.linebreakSpan);
544556
document.body.removeChild(this.EmExSpan);
545557
},
@@ -609,7 +621,7 @@
609621
jax = script.MathJax.elementJax; if (!jax) continue;
610622
ex = test.firstChild.offsetHeight/60;
611623
em = test.lastChild.firstChild.offsetHeight/60;
612-
cwidth = div.previousSibling.firstChild.offsetWidth;
624+
cwidth = Math.max(0,div.previousSibling.offsetWidth - 2);
613625
if (relwidth) {maxwidth = cwidth}
614626
if (ex === 0 || ex === "NaN") {
615627
// can't read width, so move to hidden div for processing
@@ -2951,7 +2963,8 @@
29512963
if (math && math.bbox.width != null) {
29522964
span.style.minWidth = (math.bbox.minWidth || span.style.width);
29532965
span.style.width = math.bbox.width;
2954-
box.style.width = stack.style.width = SPAN.style.width = "100%";
2966+
box.style.width = stack.style.width = "100%";
2967+
SPAN.className += " MathJax_FullWidth";
29552968
}
29562969
//
29572970
// Add color (if any)

0 commit comments

Comments
 (0)