Handle linebreaking in msubsup.

This commit is contained in:
Davide P. Cervone 2015-04-01 12:11:19 -04:00
parent 2b3cb0cb0d
commit 6d637bb391
2 changed files with 35 additions and 27 deletions

View File

@ -273,8 +273,8 @@ MathJax.Hub.Register.StartupHook("CommonHTML Jax Ready",function () {
var last = state.last; state.last = false; var last = state.last; state.last = false;
while (i < j) { while (i < j) {
if (this.data[i]) { if (this.data[i]) {
if (start.length <= 1) {this.data[i].CHTMLmoveNode(node,state,values)} if (start.length <= 1) this.data[i].CHTMLmoveNode(node,state,values);
else {this.data[i].CHTMLmoveSlice(start.slice(1),[],node,state,values,"marginLeft")} else this.data[i].CHTMLmoveSlice(start.slice(1),[],node,state,values,"marginLeft");
} }
i++; state.first = false; start = []; i++; state.first = false; start = [];
} }
@ -284,8 +284,8 @@ MathJax.Hub.Register.StartupHook("CommonHTML Jax Ready",function () {
// //
state.last = last; state.last = last;
if (this.data[i]) { if (this.data[i]) {
if (end.length <= 1) {this.data[i].CHTMLmoveNode(node,state,values)} if (end.length <= 1) this.data[i].CHTMLmoveNode(node,state,values);
else {this.data[i].CHTMLmoveSlice([],end.slice(1),node,state,values,"marginRight")} else this.data[i].CHTMLmoveSlice([],end.slice(1),node,state,values,"marginRight");
} }
} }
}, },
@ -357,8 +357,8 @@ MathJax.Hub.Register.StartupHook("CommonHTML Jax Ready",function () {
node.style.marginLeft = ""; this.CHTML.L = 0; node.style.marginLeft = ""; this.CHTML.L = 0;
node.className = node.className.replace(/ MJXc-space\d/,""); node.className = node.className.replace(/ MJXc-space\d/,"");
} }
if (state.first && this.CHTML.w === 0) {state.nextIsFirst = true} if (state.first && this.CHTML.w === 0) state.nextIsFirst = true;
else {delete state.nextIsFirst} else delete state.nextIsFirst;
// //
// Update bounding box // Update bounding box
// //
@ -433,8 +433,8 @@ MathJax.Hub.Register.StartupHook("CommonHTML Jax Ready",function () {
var last = state.last; state.last = false; var k = this.dataI[i]; var last = state.last; state.last = false; var k = this.dataI[i];
while (i < j) { while (i < j) {
if (this.data[k]) { if (this.data[k]) {
if (start.length <= 1) {this.data[k].CHTMLmoveNode(node,state,values)} if (start.length <= 1) this.data[k].CHTMLmoveNode(node,state,values);
else {this.data[k].CHTMLmoveSlice(start.slice(1),[],node,state,values,"marginLeft")} else this.data[k].CHTMLmoveSlice(start.slice(1),[],node,state,values,"marginLeft");
} }
i++; k = this.dataI[i]; state.first = false; start = []; i++; k = this.dataI[i]; state.first = false; start = [];
} }
@ -443,8 +443,8 @@ MathJax.Hub.Register.StartupHook("CommonHTML Jax Ready",function () {
// //
state.last = last; state.last = last;
if (this.data[k]) { if (this.data[k]) {
if (end.length <= 1) {this.data[k].CHTMLmoveNode(node,state,values)} if (end.length <= 1) this.data[k].CHTMLmoveNode(node,state,values);
else {this.data[k].CHTMLmoveSlice([],end.slice(1),node,state,values,"marginRight")} else this.data[k].CHTMLmoveSlice([],end.slice(1),node,state,values,"marginRight");
} }
} }
} }
@ -491,28 +491,35 @@ MathJax.Hub.Register.StartupHook("CommonHTML Jax Ready",function () {
// Move the proper part of the base // Move the proper part of the base
// //
if (this.data[this.base]) { if (this.data[this.base]) {
var base = HTML.addElement(node,"mjx-base");
if (start.length > 1) { if (start.length > 1) {
this.data[this.base].CHTMLmoveSlice(start.slice(1),end.slice(1),node,state,values,"marginLeft"); this.data[this.base].CHTMLmoveSlice(start.slice(1),end.slice(1),base,state,values,"marginLeft");
} else { } else {
if (end.length <= 1) {this.data[this.base].CHTMLmoveNode(node,state,values)} if (end.length <= 1) this.data[this.base].CHTMLmoveNode(base,state,values);
else {this.data[this.base].CHTMLmoveSlice([],end.slice(1),node,state,values,"marginRight")} else this.data[this.base].CHTMLmoveSlice([],end.slice(1),base,state,values,"marginRight");
} }
} }
// //
// If this is the end, check for super and subscripts, and move those // If this is the end, check for super and subscripts, and move those
// by moving the stack that contains them, and shifting by the amount of the // by moving the elements that contains them. Adjust the bounding box
// base that has been removed. Remove the empty base box from the stack. // to include the super and subscripts.
// //
if (end.length === 0) { if (end.length === 0) {
var s = this.data[this.sup] || this.data[this.sub]; var NODE = this.CHTMLnodeElement(),
if (s && this.CHTMLnotEmpty(s)) { stack = NODE.getElementsByTagName("mjx-stack")[0],
var box = s.CHTMLnodeElement().parentNode, stack = box.parentNode; sup = NODE.getElementsByTagName("mjx-sup")[0],
if (this.data[this.base]) stack.removeChild(stack.firstChild); sub = NODE.getElementsByTagName("mjx-sub")[0];
for (box = stack.firstChild; box; box = box.nextSibling) if (stack) node.appendChild(stack);
{box.style.left = CHTML.Em(CHTML.unEm(box.style.left)-this.CHTML.baseW)} else if (sup) node.appendChild(sup);
// stack.bbox.w -= this.CHTML.baseW; stack.style.width = CHTML.Em(stack.bbox.w); else if (sub) node.appendChild(sub);
// this.HTMLcombineBBoxes(stack,span.bbox); var w = state.bbox.w, bbox;
node.appendChild(stack); if (sup) {
bbox = this.data[this.sup].CHTML;
state.bbox.combine(bbox,w,bbox.Y);
}
if (sub) {
bbox = this.data[this.sub].CHTML;
state.bbox.combine(bbox,w,bbox.Y);
} }
} }
} }
@ -595,8 +602,8 @@ MathJax.Hub.Register.StartupHook("CommonHTML Jax Ready",function () {
if (start.length > 1) { if (start.length > 1) {
this.data[this.base].CHTMLmoveSlice(start.slice(1),end.slice(1),node,state,values,"marginLeft"); this.data[this.base].CHTMLmoveSlice(start.slice(1),end.slice(1),node,state,values,"marginLeft");
} else { } else {
if (end.length <= 1) {this.data[this.base].CHTMLmoveNode(node,state,values)} if (end.length <= 1) this.data[this.base].CHTMLmoveNode(node,state,values);
else {this.data[this.base].CHTMLmoveSlice([],end.slice(1),node,state,values,"marginRight")} else this.data[this.base].CHTMLmoveSlice([],end.slice(1),node,state,values,"marginRight");
} }
} }
// //

View File

@ -1167,6 +1167,7 @@
if (this.R) this.R *= scale; if (this.R) this.R *= scale;
}, },
combine: function (cbox,x,y) { combine: function (cbox,x,y) {
cbox.X = x; cbox.Y = y; // save for use with line breaking
scale = cbox.rscale; scale = cbox.rscale;
if (x + scale*cbox.r > this.r) this.r = x + scale*cbox.r; if (x + scale*cbox.r > this.r) this.r = x + scale*cbox.r;
if (x + scale*cbox.l < this.l) this.l = x + scale*cbox.l; if (x + scale*cbox.l < this.l) this.l = x + scale*cbox.l;