Add support for mfenced, and refactor mrow code to allow reuse of some pieces.

This commit is contained in:
Davide P. Cervone 2014-09-20 14:07:27 -04:00
parent ff970b8af0
commit b137d2e65d
2 changed files with 100 additions and 55 deletions

View File

@ -920,49 +920,58 @@ MathJax.ElementJax.mml.Augment({
close: ')',
separators: ','
},
texClass: MML.TEXCLASS.OPEN,
setTeXclass: function (prev) {
this.getPrevClass(prev);
addFakeNodes: function () {
var values = this.getValues("open","close","separators");
values.open = values.open.replace(/[ \t\n\r]/g,"");
values.close = values.close.replace(/[ \t\n\r]/g,"");
values.separators = values.separators.replace(/[ \t\n\r]/g,"");
// create a fake node for the open item
//
// Create a fake node for the open item
//
if (values.open !== "") {
this.SetData("open",MML.mo(values.open).With({
fence:true, form:MML.FORM.PREFIX, texClass:MML.TEXCLASS.OPEN
}));
//
// Clear flag for using MML spacing even though form is specified
//
this.data.open.useMMLspacing &= ~this.data.open.SPACE_ATTR.form;
prev = this.data.open.setTeXclass(prev);
}
// get the separators
//
// Create fake nodes for the separators
//
if (values.separators !== "") {
while (values.separators.length < this.data.length)
{values.separators += values.separators.charAt(values.separators.length-1)}
}
// handle the first item, if any
if (this.data[0]) {prev = this.data[0].setTeXclass(prev)}
// add fake nodes for separators and handle the following item
for (var i = 1, m = this.data.length; i < m; i++) {
if (this.data[i]) {
if (values.separators !== "") {
this.SetData("sep"+i,MML.mo(values.separators.charAt(i-1)).With({separator:true}));
prev = this.data["sep"+i].setTeXclass(prev);
}
prev = this.data[i].setTeXclass(prev);
if (this.data[i])
{this.SetData("sep"+i,MML.mo(values.separators.charAt(i-1)).With({separator:true}))}
}
}
// create fake node for the close item
//
// Create fake node for the close item
//
if (values.close !== "") {
this.SetData("close",MML.mo(values.close).With({
fence:true, form:MML.FORM.POSTFIX, texClass:MML.TEXCLASS.CLOSE
}));
//
// Clear flag for using MML spacing even though form is specified
//
this.data.close.useMMLspacing &= ~this.data.close.SPACE_ATTR.form;
prev = this.data.close.setTeXclass(prev);
}
// get the data from the open item
},
texClass: MML.TEXCLASS.OPEN,
setTeXclass: function (prev) {
this.addFakeNodes();
this.getPrevClass(prev);
if (this.data.open) {prev = this.data.open.setTeXclass(prev)}
if (this.data[0]) {prev = this.data[0].setTeXclass(prev)}
for (var i = 1, m = this.data.length; i < m; i++) {
if (this.data["sep"+i]) {prev = this.data["sep"+i].setTeXclass(prev)}
if (this.data[i]) {prev = this.data[i].setTeXclass(prev)}
}
if (this.data.close) {prev = this.data.close.setTeXclass(prev)}
this.updateTeXclass(this.data.open);
this.texClass = MML.TEXCLASS.INNER;
return prev;

View File

@ -27,7 +27,7 @@
*/
(function (HUB,AJAX,HTML,CHTML) {
(function (AJAX,HUB,HTML,CHTML) {
var MML;
/*
@ -152,7 +152,9 @@
},
Startup: function () {
//
// Set up event handling
//
EVENT = MathJax.Extension.MathEvents.Event;
TOUCH = MathJax.Extension.MathEvents.Touch;
HOVER = MathJax.Extension.MathEvents.Hover;
@ -162,14 +164,18 @@
this.Mouseout = HOVER.Mouseout;
this.Mousemove = HOVER.Mousemove;
//
// Determine pixels per inch
//
var div = HTML.addElement(document.body,"div",{style:{width:"5in"}});
this.pxPerInch = div.offsetWidth/5; div.parentNode.removeChild(div);
//
// Set up styles and preload web fonts
return AJAX.Styles(this.config.styles,["InitializeHTML",this]);
//
return AJAX.Styles(this.config.styles,["InitializeCHTML",this]);
},
InitializeHTML: function () {
InitializeCHTML: function () {
},
preTranslate: function (state) {
@ -515,12 +521,15 @@
this.CHTMLhandleStyle(span);
this.CHTMLhandleColor(span);
if (this.isToken) this.CHTMLhandleToken(span);
for (var i = 0, m = this.data.length, SPAN = span; i < m; i++) {
for (var i = 0, m = this.data.length; i < m; i++) this.CHTMLaddChild(span,i,options);
return span;
},
CHTMLaddChild: function (span,i,options) {
var child = this.data[i];
if (child) {
if (options.childSpans)
SPAN = HTML.addElement(span,"span",{className:options.className});
child.toCommonHTML(SPAN);
span = HTML.addElement(span,"span",{className:options.className});
child.toCommonHTML(span);
if (!options.noBBox) {
this.CHTML.w += child.CHTML.w + child.CHTML.l + child.CHTML.r;
if (child.CHTML.h > this.CHTML.h) this.CHTML.h = child.CHTML.h;
@ -529,8 +538,16 @@
if (child.CHTML.b > this.CHTML.b) this.CHTML.b = child.CHTML.b;
}
} else if (options.forceChild) {HTML.addElement(span,"span")}
},
CHTMLstretchChild: function (i,H,D) {
var data = this.data[i];
if (data && data.CHTMLcanStretch("Vertical",H,D)) {
var bbox = this.CHTML, dbox = data.CHTML, w = dbox.w;
data.CHTMLstretchV(H,D);
bbox.w += dbox.w - w;
if (dbox.h > bbox.h) bbox.h = dbox.h;
if (dbox.d > bbox.d) bbox.d = dbox.d;
}
return span;
},
CHTMLcreateSpan: function (span) {
@ -569,7 +586,7 @@
CHTMLhandleScriptlevel: function (span) {
// ### FIXME: Need to prevent getting too small
// ### and should keep track of scaling so it can be comensated for
// ### and should keep track of scaling so it can be compensated for
var level = this.Get("scriptlevel");
if (level) span.className += " MJXc-script";
},
@ -888,7 +905,7 @@
var values = this.getValues("linethickness","displaystyle");
if (!values.displaystyle) {
if (this.data[0]) this.data[0].CHTMLhandleScriptlevel(span.firstChild);
if (this.data[1]) this.data[0].CHTMLhandleScriptlevel(span.lastChild);
if (this.data[1]) this.data[1].CHTMLhandleScriptlevel(span.lastChild);
}
var denom = HTML.Element("span",{className:"MJXc-box",style:{"margin-top":"-.8em"}},[
["span",{className:"MJXc-denom"},[ // inline-table
@ -972,21 +989,40 @@
CHTMLlayoutRoot: MML.msqrt.prototype.CHTMLlayoutRoot
});
MML.mfenced.Augment({
toCommonHTML: function (span) {
span = this.CHTMLcreateSpan(span);
this.CHTMLhandleStyle(span);
this.CHTMLhandleColor(span);
//
// Make row of open, data, sep, ... data, close
//
this.addFakeNodes();
this.CHTMLaddChild(span,"open",{});
for (var i = 0, m = this.data.length; i < m; i++) {
this.CHTMLaddChild(span,"sep"+i,{});
this.CHTMLaddChild(span,i,{});
}
this.CHTMLaddChild(span,"close",{});
//
// Check for streching the elements
//
var H = this.CHTML.h, D = this.CHTML.d;
this.CHTMLstretchChild("open",H,D);
for (var i = 0, m = this.data.length; i < m; i++) {
this.CHTMLstretchChild("sep"+i,H,D);
this.CHTMLstretchChild(i,H,D);
}
this.CHTMLstretchChild("close",H,D);
return span;
}
});
MML.mrow.Augment({
toCommonHTML: function (span) {
span = this.CHTMLdefaultSpan(span);
var bbox = this.CHTML;
var H = bbox.h, D = bbox.d;
for (var i = 0, m = this.data.length; i < m; i++) {
var data = this.data[i];
if (data && data.CHTMLcanStretch("Vertical",H,D)) {
var dbox = data.CHTML; var w = dbox.w;
data.CHTMLstretchV(H,D);
bbox.w += dbox.w - w;
if (dbox.h > bbox.h) bbox.h = dbox.h;
if (dbox.d > bbox.d) bbox.d = dbox.d;
}
}
var H = this.CHTML.h, D = this.CHTML.d;
for (var i = 0, m = this.data.length; i < m; i++) this.CHTMLstretchChild(i,H,D);
return span;
}
});
@ -1090,4 +1126,4 @@
{AJAX.Require("[MathJax]/extensions/MathZoom.js")}
});
})(MathJax.Hub,MathJax.Ajax,MathJax.HTML,MathJax.OutputJax.CommonHTML);
})(MathJax.Ajax,MathJax.Hub,MathJax.HTML,MathJax.OutputJax.CommonHTML);