Skip to content

Commit 5d69614

Browse files
committed
Allow linebreaks within the base of msubsup to work so that the super and subscripts stay with the last line of the base. Resolves issue #235.
1 parent 0ed5d46 commit 5d69614

File tree

4 files changed

+143
-17
lines changed

4 files changed

+143
-17
lines changed

unpacked/jax/element/mml/jax.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -912,7 +912,6 @@ MathJax.ElementJax.mml.Augment({
912912

913913
MML.msubsup = MML.mbase.Subclass({
914914
type: "msubsup", base: 0, sub: 1, sup: 2,
915-
linebreakContainer: true,
916915
isEmbellished: MML.mbase.childEmbellished,
917916
Core: MML.mbase.childCore,
918917
CoreMO: MML.mbase.childCoreMO,

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

Lines changed: 74 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
*/
2323

2424
MathJax.Hub.Register.StartupHook("HTML-CSS Jax Ready",function () {
25-
var VERSION = "2.0.3";
25+
var VERSION = "2.0.4";
2626
var MML = MathJax.ElementJax.mml,
2727
HTMLCSS = MathJax.OutputJax["HTML-CSS"];
2828

@@ -36,7 +36,7 @@ MathJax.Hub.Register.StartupHook("HTML-CSS Jax Ready",function () {
3636
badbreak: [+200],
3737
auto: [0],
3838

39-
toobig: 500,
39+
toobig: 800,
4040
nestfactor: 400,
4141
spacefactor: -100,
4242
spaceoffset: 2,
@@ -159,7 +159,7 @@ MathJax.Hub.Register.StartupHook("HTML-CSS Jax Ready",function () {
159159
better = true; index = [i].concat(info.index); W = info.W; w = info.w;
160160
if (info.penalty === PENALTY.newline) {info.index = index; info.nest--; return true}
161161
}
162-
if (!broken) {scanW = this.HTMLaddWidth(i,info,scanW)}
162+
scanW = (broken ? info.scanW : this.HTMLaddWidth(i,info,scanW));
163163
}
164164
info.index = []; i++; broken = false;
165165
}
@@ -193,7 +193,7 @@ MathJax.Hub.Register.StartupHook("HTML-CSS Jax Ready",function () {
193193
this.HTMLmoveLine(start,end,line,state,values);
194194
this.HTMLcleanBBox(line.bbox);
195195
//
196-
// Get the alignment and shift values
196+
// Get the alignment and shift values
197197
//
198198
var align = this.HTMLgetAlign(state,values),
199199
shift = this.HTMLgetShift(state,values,align);
@@ -404,7 +404,7 @@ MathJax.Hub.Register.StartupHook("HTML-CSS Jax Ready",function () {
404404
better = true; index = [i].concat(info.index); W = info.W; w = info.w;
405405
if (info.penalty === PENALTY.newline) {info.index = index; info.nest--; return true}
406406
}
407-
if (!broken) {scanW = this.HTMLaddWidth(k,info,scanW)}
407+
scanW = (broken ? info.scanW : this.HTMLaddWidth(i,info,scanW));
408408
}
409409
info.index = []; i++; broken = false;
410410
}
@@ -419,7 +419,6 @@ MathJax.Hub.Register.StartupHook("HTML-CSS Jax Ready",function () {
419419
if (i === j && start.length > 1) {
420420
//
421421
// If starting and ending in the same element move the subpiece to the new line
422-
// Add the closing fence, if present
423422
//
424423
this.data[this.dataI[i]].HTMLmoveSlice(start.slice(1),end.slice(1),span,state,values,"paddingLeft");
425424
} else {
@@ -436,8 +435,7 @@ MathJax.Hub.Register.StartupHook("HTML-CSS Jax Ready",function () {
436435
i++; k = this.dataI[i]; state.first = false; start = [];
437436
}
438437
//
439-
// If the last item is complete, move it and the closing fence,
440-
// otherwise move the first part of it up to the split
438+
// If the last item is complete, move it
441439
//
442440
state.last = last;
443441
if (this.data[k]) {
@@ -451,6 +449,74 @@ MathJax.Hub.Register.StartupHook("HTML-CSS Jax Ready",function () {
451449

452450
/**************************************************************************/
453451

452+
MML.msubsup.Augment({
453+
HTMLbetterBreak: function (info,state) {
454+
if (!this.data[this.base]) {return false}
455+
//
456+
// Get the current breakpoint position and other data
457+
//
458+
var index = info.index.slice(0), i = info.index.shift(),
459+
W, w, scanW, broken = (info.index.length > 0), better = false;
460+
if (!broken) {info.W += info.w; info.w = 0}
461+
scanW = info.scanW = info.W;
462+
//
463+
// Record the width of the base and the super- and subscripts
464+
//
465+
if (i == null) {
466+
this.HTMLbaseW = this.data[this.base].HTMLspanElement().bbox.w;
467+
this.HTMLdw = this.HTMLspanElement().bbox.w - this.HTMLbaseW;
468+
}
469+
//
470+
// Check if the base can be broken
471+
//
472+
if (this.data[this.base].HTMLbetterBreak(info,state)) {
473+
better = true; index = [this.base].concat(info.index); W = info.W; w = info.w;
474+
if (info.penalty === PENALTY.newline) {better = broken = true}
475+
}
476+
//
477+
// Add in the base if it is unbroken, and add the scripts
478+
//
479+
if (!broken) {this.HTMLaddWidth(this.base,info,scanW)}
480+
info.scanW += this.HTMLdw; info.W = info.scanW;
481+
info.index = index; if (better) {info.W = W; info.w = w}
482+
return better;
483+
},
484+
485+
HTMLmoveLine: function (start,end,span,state,values) {
486+
//
487+
// Move the proper part of the base
488+
//
489+
if (this.data[this.base]) {
490+
if (start.length > 1) {
491+
this.data[this.base].HTMLmoveSlice(start.slice(1),end.slice(1),span,state,values,"paddingLeft");
492+
} else {
493+
if (end.length <= 1) {this.data[i].HTMLmoveSpan(span,state,values)}
494+
else {this.data[this.base].HTMLmoveSlice([],end.slice(1),span,state,values,"paddingRight")}
495+
}
496+
}
497+
//
498+
// If this is the end, check for super and subscripts, and move those
499+
// by moving the stack tht contains them, and shifting by the amount of the
500+
// base that has been removed. Remove the empty base box from the stack.
501+
//
502+
if (end.length === 0) {
503+
var s = this.data[this.sup] || this.data[this.sub];
504+
if (s) {
505+
var box = s.HTMLspanElement().parentNode, stack = box.parentNode;
506+
if (this.data[this.base]) {stack.removeChild(stack.firstChild)}
507+
for (box = stack.firstChild; box; box = box.nextSibling)
508+
{box.style.left = HTMLCSS.Em(HTMLCSS.unEm(box.style.left)-this.HTMLbaseW)}
509+
stack.bbox.w -= this.HTMLbaseW; stack.style.width = HTMLCSS.Em(stack.bbox.w);
510+
this.HTMLcombineBBoxes(stack,span.bbox);
511+
span.appendChild(stack);
512+
}
513+
}
514+
}
515+
516+
});
517+
518+
/**************************************************************************/
519+
454520
MML.mo.Augment({
455521
//
456522
// Override the method for checking line breaks to properly handle <mo>

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

Lines changed: 63 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
*/
2323

2424
MathJax.Hub.Register.StartupHook("SVG Jax Ready",function () {
25-
var VERSION = "2.0.2";
25+
var VERSION = "2.0.3";
2626
var MML = MathJax.ElementJax.mml,
2727
SVG = MathJax.OutputJax.SVG,
2828
BBOX = SVG.BBOX;
@@ -37,7 +37,7 @@ MathJax.Hub.Register.StartupHook("SVG Jax Ready",function () {
3737
badbreak: [+200],
3838
auto: [0],
3939

40-
toobig: 500,
40+
toobig: 800,
4141
nestfactor: 400,
4242
spacefactor: -100,
4343
spaceoffset: 2,
@@ -162,7 +162,7 @@ MathJax.Hub.Register.StartupHook("SVG Jax Ready",function () {
162162
better = true; index = [i].concat(info.index); W = info.W; w = info.w;
163163
if (info.penalty === PENALTY.newline) {info.index = index; info.nest--; return true}
164164
}
165-
if (!broken) {scanW = this.SVGaddWidth(i,info,scanW)}
165+
scanW = (broken ? info.scanW : this.SVGaddWidth(i,info,scanW));
166166
}
167167
info.index = []; i++; broken = false;
168168
}
@@ -362,7 +362,7 @@ MathJax.Hub.Register.StartupHook("SVG Jax Ready",function () {
362362
better = true; index = [i].concat(info.index); W = info.W; w = info.w;
363363
if (info.penalty === PENALTY.newline) {info.index = index; info.nest--; return true}
364364
}
365-
if (!broken) {scanW = this.SVGaddWidth(k,info,scanW)}
365+
scanW = (broken ? info.scanW : this.SVGaddWidth(i,info,scanW));
366366
}
367367
info.index = []; i++; broken = false;
368368
}
@@ -377,7 +377,6 @@ MathJax.Hub.Register.StartupHook("SVG Jax Ready",function () {
377377
if (i === j && start.length > 1) {
378378
//
379379
// If starting and ending in the same element move the subpiece to the new line
380-
// Add the closing fence, if present
381380
//
382381
this.data[this.dataI[i]].SVGmoveSlice(start.slice(1),end.slice(1),svg,state,values,"paddingLeft");
383382
} else {
@@ -394,8 +393,7 @@ MathJax.Hub.Register.StartupHook("SVG Jax Ready",function () {
394393
i++; k = this.dataI[i]; state.first = false; start = [];
395394
}
396395
//
397-
// If the last item is complete, move it and the closing fence,
398-
// otherwise move the first part of it up to the split
396+
// If the last item is complete, move it
399397
//
400398
state.last = last;
401399
if (this.data[k]) {
@@ -409,6 +407,64 @@ MathJax.Hub.Register.StartupHook("SVG Jax Ready",function () {
409407

410408
/**************************************************************************/
411409

410+
MML.msubsup.Augment({
411+
SVGbetterBreak: function (info,state) {
412+
if (!this.data[this.base]) {return false}
413+
//
414+
// Get the current breakpoint position and other data
415+
//
416+
var index = info.index.slice(0), i = info.index.shift(),
417+
W, w, scanW, broken = (info.index.length > 0), better = false;
418+
if (!broken) {info.W += info.w; info.w = 0}
419+
scanW = info.scanW = info.W;
420+
//
421+
// Record the width of the base and the super- and subscripts
422+
//
423+
if (i == null) {this.SVGdata.dw = this.SVGdata.w - this.data[this.base].SVGdata.w}
424+
//
425+
// Check if the base can be broken
426+
//
427+
if (this.data[this.base].SVGbetterBreak(info,state)) {
428+
better = true; index = [this.base].concat(info.index); W = info.W; w = info.w;
429+
if (info.penalty === PENALTY.newline) {better = broken = true}
430+
}
431+
//
432+
// Add in the base if it is unbroken, and add the scripts
433+
//
434+
if (!broken) {this.SVGaddWidth(this.base,info,scanW)}
435+
info.scanW += this.SVGdata.dw; info.W = info.scanW;
436+
info.index = index; if (better) {info.W = W; info.w = w}
437+
return better;
438+
},
439+
440+
SVGmoveLine: function (start,end,svg,state,values) {
441+
//
442+
// Move the proper part of the base
443+
//
444+
if (this.data[this.base]) {
445+
if (start.length > 1) {
446+
this.data[this.base].SVGmoveSlice(start.slice(1),end.slice(1),svg,state,values,"paddingLeft");
447+
} else {
448+
if (end.length <= 1) {this.data[i].SVGmove(svg,state,values)}
449+
else {this.data[this.base].SVGmoveSlice([],end.slice(1),svg,state,values,"paddingRight")}
450+
}
451+
}
452+
//
453+
// If this is the end, check for super and subscripts, and move those
454+
// by moving the stack tht contains them, and shifting by the amount of the
455+
// base that has been removed. Remove the empty base box from the stack.
456+
//
457+
if (end.length === 0) {
458+
var sup = this.data[this.sup], sub = this.data[this.sub], w = svg.w;
459+
if (sup) {svg.Add(sup.toSVG(),w+(sup.SVGdata.dx||0),sup.SVGdata.dy)}
460+
if (sub) {svg.Add(sub.toSVG(),w+(sub.SVGdata.dx||0),sub.SVGdata.dy)}
461+
}
462+
}
463+
464+
});
465+
466+
/**************************************************************************/
467+
412468
MML.mo.Augment({
413469
//
414470
// Override the method for checking line breaks to properly handle <mo>

unpacked/jax/output/SVG/jax.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1827,14 +1827,16 @@
18271827
if (!sup) {
18281828
if (sub) {
18291829
v = Math.max(v,SVG.TeX.sub1*scale,sub.h-(4/5)*x_height,min.subscriptshift);
1830-
svg.Add(sub,base.w,-v);
1830+
svg.Add(sub,base.w,-v); this.data[this.sub].SVGdata.dy = -v;
18311831
}
18321832
} else {
18331833
if (!sub) {
18341834
values = this.getValues("displaystyle","texprimestyle");
18351835
p = SVG.TeX[(values.displaystyle ? "sup1" : (values.texprimestyle ? "sup3" : "sup2"))];
18361836
u = Math.max(u,p*scale,sup.d+(1/4)*x_height,min.superscriptshift);
18371837
svg.Add(sup,base.w+delta,u);
1838+
this.data[this.sup].SVGdata.dx = delta;
1839+
this.data[this.sup].SVGdata.dy = u;
18381840
} else {
18391841
v = Math.max(v,SVG.TeX.sub2*scale);
18401842
var t = SVG.TeX.rule_thickness * scale;
@@ -1845,6 +1847,9 @@
18451847
}
18461848
svg.Add(sup,base.w+delta,Math.max(u,min.superscriptshift));
18471849
svg.Add(sub,base.w,-Math.max(v,min.subscriptshift));
1850+
this.data[this.sup].SVGdata.dx = delta;
1851+
this.data[this.sup].SVGdata.dy = Math.max(u,min.superscriptshift);
1852+
this.data[this.sub].SVGdata.dy = -Math.max(v,min.subscriptshift);
18481853
}
18491854
}
18501855
svg.Clean();

0 commit comments

Comments
 (0)