Skip to content

Commit 1558970

Browse files
committed
Make end-of-line a valid breakpoint (so it might override earlier poor breakpoint). See #1970.
1 parent 567d6ae commit 1558970

File tree

3 files changed

+41
-8
lines changed

3 files changed

+41
-8
lines changed

unpacked/jax/output/CommonHTML/autoload/multiline.js

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,11 @@ MathJax.Hub.Register.StartupHook("CommonHTML Jax Ready",function () {
2929
var MML = MathJax.ElementJax.mml,
3030
CONFIG = MathJax.Hub.config,
3131
CHTML = MathJax.OutputJax.CommonHTML;
32-
32+
//
33+
// Fake node used for testing end-of-line potential breakpoint
34+
//
35+
var MO = MML.mo().With({CHTML: CHTML.BBOX.empty()});
36+
3337
//
3438
// Penalties for the various line breaks
3539
//
@@ -110,7 +114,7 @@ MathJax.Hub.Register.StartupHook("CommonHTML Jax Ready",function () {
110114
},
111115
broken = false;
112116

113-
while (this.CHTMLbetterBreak(end,state) &&
117+
while (this.CHTMLbetterBreak(end,state,true) &&
114118
(end.scanW >= CHTML.linebreakWidth || end.penalty === PENALTY.newline)) {
115119
this.CHTMLaddLine(stack,start,end.index,state,end.values,broken);
116120
start = end.index.slice(0); broken = true;
@@ -133,7 +137,7 @@ MathJax.Hub.Register.StartupHook("CommonHTML Jax Ready",function () {
133137
//
134138
// Locate the next linebreak that is better than the current one
135139
//
136-
CHTMLbetterBreak: function (info,state) {
140+
CHTMLbetterBreak: function (info,state,toplevel) {
137141
if (this.isToken) return false; // FIXME: handle breaking of token elements
138142
if (this.isEmbellished()) {
139143
info.embellished = this;
@@ -165,6 +169,13 @@ MathJax.Hub.Register.StartupHook("CommonHTML Jax Ready",function () {
165169
}
166170
info.index = []; i++; broken = false;
167171
}
172+
//
173+
// Check if end-of-line is a better breakpoint
174+
//
175+
if (toplevel && better) {
176+
MO.parent = this.parent; MO.inherit = this.inherit;
177+
if (MO.CHTMLbetterBreak(info,state)) {better = false; index = info.index}
178+
}
168179
if (info.nest) {info.nest--}
169180
info.index = index;
170181
if (better) {info.W = W; info.w = w}

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

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ MathJax.Hub.Register.StartupHook("HTML-CSS Jax Ready",function () {
2828
var VERSION = "2.7.4";
2929
var MML = MathJax.ElementJax.mml,
3030
HTMLCSS = MathJax.OutputJax["HTML-CSS"];
31+
//
32+
// Fake node used for testing end-of-line potential breakpoint
33+
//
34+
var MO = MML.mo().With({HTMLspanElement: function () {return {bbox: {w:0}, style: {}}}});
3135

3236
//
3337
// Penalties for the various line breaks
@@ -109,7 +113,7 @@ MathJax.Hub.Register.StartupHook("HTML-CSS Jax Ready",function () {
109113
},
110114
broken = false;
111115

112-
while (this.HTMLbetterBreak(end,state) &&
116+
while (this.HTMLbetterBreak(end,state,true) &&
113117
(end.scanW >= HTMLCSS.linebreakWidth || end.penalty === PENALTY.newline)) {
114118
this.HTMLaddLine(stack,start,end.index,state,end.values,broken);
115119
start = end.index.slice(0); broken = true;
@@ -140,7 +144,7 @@ MathJax.Hub.Register.StartupHook("HTML-CSS Jax Ready",function () {
140144
//
141145
// Locate the next linebreak that is better than the current one
142146
//
143-
HTMLbetterBreak: function (info,state) {
147+
HTMLbetterBreak: function (info,state,toplevel) {
144148
if (this.isToken) {return false} // FIXME: handle breaking of token elements
145149
if (this.isEmbellished()) {
146150
info.embellished = this;
@@ -172,6 +176,13 @@ MathJax.Hub.Register.StartupHook("HTML-CSS Jax Ready",function () {
172176
}
173177
info.index = []; i++; broken = false;
174178
}
179+
//
180+
// Check if end-of-line is a better breakpoint
181+
//
182+
if (toplevel && better) {
183+
MO.parent = this.parent; MO.inherit = this.inherit;
184+
if (MO.HTMLbetterBreak(info,state)) {better = false; index = info.index}
185+
}
175186
if (info.nest) {info.nest--}
176187
info.index = index;
177188
if (better) {info.W = W; info.w = w}

unpacked/jax/output/SVG/autoload/multiline.js

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,11 @@ MathJax.Hub.Register.StartupHook("SVG Jax Ready",function () {
2929
var MML = MathJax.ElementJax.mml,
3030
SVG = MathJax.OutputJax.SVG,
3131
BBOX = SVG.BBOX;
32-
32+
//
33+
// Fake node used for testing end-of-line potential breakpoint
34+
//
35+
var MO = MML.mo().With({SVGdata: {w: 0, x:0}});
36+
3337
//
3438
// Penalties for the various line breaks
3539
//
@@ -115,7 +119,7 @@ MathJax.Hub.Register.StartupHook("SVG Jax Ready",function () {
115119
//
116120
// Break the expression at its best line breaks
117121
//
118-
while (this.SVGbetterBreak(end,state) &&
122+
while (this.SVGbetterBreak(end,state,true) &&
119123
(end.scanW >= SVG.linebreakWidth || end.penalty === PENALTY.newline)) {
120124
this.SVGaddLine(svg,start,end.index,state,end.values,broken);
121125
start = end.index.slice(0); broken = true;
@@ -145,7 +149,7 @@ MathJax.Hub.Register.StartupHook("SVG Jax Ready",function () {
145149
//
146150
// Locate the next linebreak that is better than the current one
147151
//
148-
SVGbetterBreak: function (info,state) {
152+
SVGbetterBreak: function (info,state,toplevel) {
149153
if (this.isToken) {return false} // FIXME: handle breaking of token elements
150154
if (this.isEmbellished()) {
151155
info.embellished = this;
@@ -177,6 +181,13 @@ MathJax.Hub.Register.StartupHook("SVG Jax Ready",function () {
177181
}
178182
info.index = []; i++; broken = false;
179183
}
184+
//
185+
// Check if end-of-line is a better breakpoint
186+
//
187+
if (toplevel && better) {
188+
MO.parent = this.parent; MO.inherit = this.inherit;
189+
if (MO.SVGbetterBreak(info,state)) {better = false; index = info.index}
190+
}
180191
if (info.nest) {info.nest--}
181192
info.index = index;
182193
if (better) {info.W = W}

0 commit comments

Comments
 (0)