Skip to content

Commit 98549a9

Browse files
authored
Merge pull request #2006 from dpvc/issue1982
Avoid line breaks for inline math in in WebKit. #1982
2 parents 3627e80 + c4f9f77 commit 98549a9

File tree

3 files changed

+172
-93
lines changed

3 files changed

+172
-93
lines changed

unpacked/jax/output/CommonHTML/jax.js

Lines changed: 44 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,6 @@
166166
".MJXc-processed": {display:"none"},
167167

168168
".mjx-test": {
169-
display: "block",
170169
"font-style": "normal",
171170
"font-weight": "normal",
172171
"font-size": "100%",
@@ -178,13 +177,36 @@
178177
overflow: "hidden",
179178
height: "1px"
180179
},
181-
".mjx-ex-box-test": {
180+
".mjx-test.mjx-test-display": {
181+
display: "table!important"
182+
},
183+
".mjx-test.mjx-test-inline": {
184+
display: "inline!important",
185+
"margin-right": "-1px"
186+
},
187+
".mjx-test.mjx-test-default": {
188+
display: "block!important",
189+
clear: "both"
190+
},
191+
".mjx-ex-box": {
192+
display: "inline-block!important",
182193
position: "absolute",
183194
overflow: "hidden",
195+
"min-height": 0, "max-height":"none",
196+
padding:0, border: 0, margin: 0,
184197
width:"1px", height:"60ex"
185198
},
186-
".mjx-line-box-test": {display: "table!important"},
187-
".mjx-line-box-test span": {
199+
".mjx-test-inline .mjx-left-box": {
200+
display: "inline-block",
201+
width: 0,
202+
float:"left"
203+
},
204+
".mjx-test-inline .mjx-right-box": {
205+
display: "inline-block",
206+
width: 0,
207+
float:"right"
208+
},
209+
".mjx-test-display .mjx-right-box": {
188210
display: "table-cell!important",
189211
width: "10000em!important",
190212
"min-width":0, "max-width":"none",
@@ -251,12 +273,8 @@
251273
//
252274
// Used in preTranslate to get scaling factors and line width
253275
//
254-
this.TestSpan = CHTML.Element("mjx-test",{style:{left:"1em"}},[["mjx-ex-box-test"]]);
255-
256-
//
257-
// Used in preTranslate to get linebreak width
258-
//
259-
this.linebreakSpan = HTML.Element("span",{className:"mjx-line-box-test"},[["span"]]);
276+
this.TestSpan = CHTML.Element("mjx-test",{style:{left:"1em"}},
277+
[["mjx-left-box"],["mjx-ex-box"],["mjx-right-box"]]);
260278

261279
//
262280
// Set up styles and preload web fonts
@@ -285,13 +303,12 @@
285303
//
286304
// Get the default sizes (need styles in place to do this)
287305
//
288-
document.body.appendChild(this.TestSpan);
289-
document.body.appendChild(this.linebreakSpan);
290-
this.defaultEm = this.getFontSize(this.TestSpan);
291-
this.defaultEx = this.TestSpan.firstChild.offsetHeight/60;
292-
this.defaultWidth = this.linebreakSpan.firstChild.offsetWidth;
293-
document.body.removeChild(this.linebreakSpan);
294-
document.body.removeChild(this.TestSpan);
306+
var test = document.body.appendChild(this.TestSpan.cloneNode(true));
307+
test.className += " mjx-test-inline mjx-test-default";
308+
this.defaultEm = this.getFontSize(test);
309+
this.defaultEx = test.childNodes[1].offsetHeight/60;
310+
this.defaultWidth = Math.max(0,test.lastChild.offsetLeft-test.firstChild.offsetLeft-2);
311+
document.body.removeChild(test);
295312
},
296313
getFontSize: (window.getComputedStyle ?
297314
function (node) {
@@ -395,7 +412,7 @@
395412

396413
preTranslate: function (state) {
397414
var scripts = state.jax[this.id], i, m = scripts.length,
398-
script, prev, node, test, span, jax, ex, em, scale;
415+
script, prev, node, test, jax, ex, em, scale;
399416
//
400417
// Get linebreaking information
401418
//
@@ -450,10 +467,11 @@
450467
node.className += " MJXc-processing";
451468
script.parentNode.insertBefore(node,script);
452469
//
453-
// Add test nodes for determineing scales and linebreak widths
470+
// Add test nodes for determining scales and linebreak widths
454471
//
455-
script.parentNode.insertBefore(this.linebreakSpan.cloneNode(true),script);
456-
script.parentNode.insertBefore(this.TestSpan.cloneNode(true),script);
472+
test = this.TestSpan.cloneNode(true);
473+
test.className += " mjx-test-" + (jax.CHTML.display ? "display" : "inline");
474+
script.parentNode.insertBefore(test,script);
457475
}
458476
//
459477
// Determine the scaling factors for each script
@@ -464,12 +482,14 @@
464482
test = script.previousSibling;
465483
jax = script.MathJax.elementJax; if (!jax) continue;
466484
em = CHTML.getFontSize(test);
467-
ex = test.firstChild.offsetHeight/60;
468-
cwidth = Math.max(0,test.previousSibling.firstChild.offsetWidth-2);
485+
ex = test.childNodes[1].offsetHeight/60;
486+
cwidth = Math.max(0, jax.CHTML.display ? test.lastChild.offsetWidth - 1:
487+
test.lastChild.offsetLeft - test.firstChild.offsetLeft - 2);
469488
if (ex === 0 || ex === "NaN") {
470489
ex = this.defaultEx;
471490
cwidth = this.defaultWidth;
472491
}
492+
if (cwidth === 0) cwidth = this.defaultWidth;
473493
if (relwidth) maxwidth = cwidth;
474494
scale = (this.config.matchFontHeight ? ex/this.TEX.x_height/em : 1);
475495
scale = Math.floor(Math.max(this.config.minScaleAdjust/100,scale)*this.config.scale);
@@ -483,11 +503,8 @@
483503
//
484504
for (i = 0; i < m; i++) {
485505
script = scripts[i]; if (!script.parentNode) continue;
486-
test = script.previousSibling;
487-
span = test.previousSibling;
488506
jax = script.MathJax.elementJax; if (!jax) continue;
489-
span.parentNode.removeChild(span);
490-
test.parentNode.removeChild(test);
507+
script.parentNode.removeChild(script.previousSibling);
491508
if (script.MathJax.preview) script.MathJax.preview.style.display = "";
492509
}
493510
state.CHTMLeqn = state.CHTMLlast = 0; state.CHTMLi = -1;

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

Lines changed: 69 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -332,26 +332,62 @@
332332
},
333333
".MathJax_Processed": {display:"none!important"},
334334

335-
".MathJax_ExBox": {
336-
display:"block!important", overflow:"hidden",
337-
width:"1px", height:"60ex",
338-
"min-height": 0, "max-height":"none"
339-
},
340-
".MathJax .MathJax_EmBox": {
341-
display:"block!important", overflow:"hidden",
342-
width:"1px", height:"60em",
343-
"min-height": 0, "max-height":"none"
335+
".MathJax_test": {
336+
"font-style": "normal",
337+
"font-weight": "normal",
338+
"font-size": "100%",
339+
"font-size-adjust":"none",
340+
"text-indent": 0,
341+
"text-transform": "none",
342+
"letter-spacing": "normal",
343+
"word-spacing": "normal",
344+
overflow: "hidden",
345+
height: "1px"
344346
},
345-
".MathJax_LineBox": {
347+
".MathJax_test.mjx-test-display": {
346348
display: (oldIE ? "block" : "table") + "!important"
347349
},
348-
".MathJax_LineBox span": {
350+
".MathJax_test.mjx-test-inline": {
351+
display: "inline!important",
352+
"margin-right": "-1px"
353+
},
354+
".MathJax_test.mjx-test-default": {
355+
display: "block!important",
356+
clear: "both"
357+
},
358+
".MathJax_ex_box": {
359+
display: "inline-block!important",
360+
position: "absolute",
361+
overflow: "hidden",
362+
"min-height": 0, "max-height":"none",
363+
padding:0, border: 0, margin: 0,
364+
width:"1px", height:"60ex"
365+
},
366+
".MathJax_em_box": {
367+
display: "inline-block!important",
368+
position: "absolute",
369+
overflow: "hidden",
370+
"min-height": 0, "max-height":"none",
371+
padding:0, border: 0, margin: 0,
372+
width:"1px", height:"60em"
373+
},
374+
".mjx-test-inline .MathJax_left_box": {
375+
display: "inline-block",
376+
width: 0,
377+
float:"left"
378+
},
379+
".mjx-test-inline .MathJax_right_box": {
380+
display: "inline-block",
381+
width: 0,
382+
float:"right"
383+
},
384+
".mjx-test-display .MathJax_right_box": {
349385
display: (oldIE ? "block" : "table-cell") + "!important",
350386
width: (oldIE ? "100%" : "10000em") + "!important",
351387
"min-width":0, "max-width":"none",
352388
padding:0, border:0, margin:0
353389
},
354-
390+
355391
".MathJax .MathJax_HitBox": {
356392
cursor: "text",
357393
background: "white",
@@ -491,19 +527,16 @@
491527
}
492528

493529
// Used in preTranslate to get scaling factors
494-
this.EmExSpan = this.Element("span",
495-
{style:{position:"absolute","font-size-adjust":"none"}},
530+
this.TestSpan = this.Element("span",
531+
{className:"MathJax_test"},
496532
[
497-
["span",{className:"MathJax_ExBox"}],
498-
["span",{className:"MathJax"},
499-
[["span",{className:"MathJax_EmBox"}]]
500-
]
533+
["span",{className:"MathJax_left_box"}],
534+
["span",{className:"MathJax_ex_box"}],
535+
["span",{className:"MathJax_em_box"}],
536+
["span",{className:"MathJax_right_box"}]
501537
]
502538
);
503539

504-
// Used in preTranslate to get linebreak width
505-
this.linebreakSpan = MathJax.HTML.Element("span",{className:"MathJax_LineBox"},[["span"]]);
506-
507540
// Set up styles and preload web fonts
508541
return AJAX.Styles(this.config.styles,["InitializeHTML",this]);
509542
},
@@ -554,13 +587,12 @@
554587
//
555588
// Get the default sizes (need styles in place to do this)
556589
//
557-
document.body.appendChild(this.EmExSpan);
558-
document.body.appendChild(this.linebreakSpan);
559-
this.defaultEx = this.EmExSpan.firstChild.offsetHeight/60;
560-
this.defaultEm = this.EmExSpan.lastChild.firstChild.offsetHeight/60;
561-
this.defaultWidth = this.linebreakSpan.firstChild.offsetWidth;
562-
document.body.removeChild(this.linebreakSpan);
563-
document.body.removeChild(this.EmExSpan);
590+
var test = document.body.appendChild(this.TestSpan.cloneNode(true));
591+
test.className += " mjx-test-inline mjx-test-default";
592+
this.defaultEx = test.childNodes[1].offsetHeight/60;
593+
this.defaultEm = test.childNodes[2].offsetHeight/60;
594+
this.defaultWidth = Math.max(0,test.lastChild.offsetLeft-test.firstChild.offsetLeft-2);
595+
document.body.removeChild(test);
564596
},
565597

566598
preTranslate: function (state) {
@@ -614,8 +646,9 @@
614646
//
615647
// Add the test span for determining scales and linebreak widths
616648
//
617-
script.parentNode.insertBefore(this.EmExSpan.cloneNode(true),script);
618-
div.parentNode.insertBefore(this.linebreakSpan.cloneNode(true),div)
649+
test = this.TestSpan.cloneNode(true);
650+
test.className += " mjx-test-" + (jax.HTMLCSS.display ? "display" : "inline");
651+
script.parentNode.insertBefore(test,script);
619652
}
620653
//
621654
// Determine the scaling factors for each script
@@ -628,15 +661,17 @@
628661
script = scripts[i]; if (!script.parentNode) continue;
629662
test = script.previousSibling; div = test.previousSibling;
630663
jax = script.MathJax.elementJax; if (!jax) continue;
631-
ex = test.firstChild.offsetHeight/60;
632-
em = test.lastChild.firstChild.offsetHeight/60;
633-
cwidth = Math.max(0,div.previousSibling.firstChild.offsetWidth - 2);
664+
ex = test.childNodes[1].offsetHeight/60;
665+
em = test.childNodes[2].offsetHeight/60;
666+
cwidth = Math.max(0, jax.HTMLCSS.display ? test.lastChild.offsetWidth - 1:
667+
test.lastChild.offsetLeft - test.firstChild.offsetLeft - 2);
634668
if (ex === 0 || ex === "NaN") {
635669
// can't read width, so move to hidden div for processing
636670
hidden.push(div);
637671
jax.HTMLCSS.isHidden = true;
638672
ex = this.defaultEx; em = this.defaultEm; cwidth = this.defaultWidth;
639673
}
674+
if (cwidth === 0) cwidth = this.defaultWidth;
640675
if (relwidth) {maxwidth = cwidth}
641676
scale = (this.config.matchFontHeight ? ex/this.TeX.x_height/em : 1);
642677
scale = Math.floor(Math.max(this.config.minScaleAdjust/100,scale)*this.config.scale);
@@ -654,12 +689,8 @@
654689
//
655690
for (i = 0; i < m; i++) {
656691
script = scripts[i]; if (!script.parentNode) continue;
657-
test = scripts[i].previousSibling;
658692
jax = scripts[i].MathJax.elementJax; if (!jax) continue;
659-
span = test.previousSibling;
660-
if (!jax.HTMLCSS.isHidden) {span = span.previousSibling}
661-
span.parentNode.removeChild(span);
662-
test.parentNode.removeChild(test);
693+
script.parentNode.removeChild(script.previousSibling);
663694
if (script.MathJax.preview) script.MathJax.preview.style.display = "";
664695
}
665696
//

0 commit comments

Comments
 (0)