Properly set displaystyle and scriptlevel, and make sure the contents is enclosed in a single element. Resolves both parts of issue #1152, but at the cost of possibly redundent mstyle elements. These could be filtered out in the combineRelations() post-filter, when we can check if the displaystyle and script levels need setting.

This commit is contained in:
Davide P. Cervone 2015-04-04 08:27:17 -04:00
parent 48b594afce
commit 3beda8db4e

View File

@ -2014,49 +2014,48 @@
/*
* Break up a string into text and math blocks
* @@@ FIXME: skip over braced groups? @@@
* @@@ FIXME: pass environment to TEX.Parse? @@@
*/
InternalMath: function (text,level) {
var def = {displaystyle: false}; if (level != null) {def.scriptlevel = level}
if (this.stack.env.font) {def.mathvariant = this.stack.env.font}
if (!text.match(/\\?[${}\\]|\\\(|\\(eq)?ref\s*\{/)) {return [this.InternalText(text,def)]}
var i = 0, k = 0, c, match = '';
var mml = [];
while (i < text.length) {
c = text.charAt(i++);
if (c === '$') {
if (match === '$') {
mml.push(MML.TeXAtom(TEX.Parse(text.slice(k,i-1),{}).mml().With(def)));
match = ''; k = i;
} else if (match === '') {
if (k < i-1) {mml.push(this.InternalText(text.slice(k,i-1),def))}
match = '$'; k = i;
}
} else if (c === '}' && match === '}') {
mml.push(MML.TeXAtom(TEX.Parse(text.slice(k,i),{}).mml().With(def)));
match = ''; k = i;
} else if (c === '\\') {
if (match === '' && text.substr(i).match(/^(eq)?ref\s*\{/)) {
if (k < i-1) {mml.push(this.InternalText(text.slice(k,i-1),def))}
match = '}'; k = i-1;
} else {
c = text.charAt(i++);
if (c === '(' && match === '') {
if (k < i-2) {mml.push(this.InternalText(text.slice(k,i-2),def))}
match = ')'; k = i;
} else if (c === ')' && match === ')') {
mml.push(MML.TeXAtom(TEX.Parse(text.slice(k,i-2),{}).mml().With(def)));
var def = (this.stack.env.font ? {mathvariant: this.stack.env.font} : {});
var mml = [], i = 0, k = 0, c, match = '';
if (text.match(/\\?[${}\\]|\\\(|\\(eq)?ref\s*\{/)) {
while (i < text.length) {
c = text.charAt(i++);
if (c === '$') {
if (match === '$') {
mml.push(MML.TeXAtom(TEX.Parse(text.slice(k,i-1),{}).mml().With(def)));
match = ''; k = i;
} else if (c.match(/[${}\\]/) && match === '') {
i--; text = text.substr(0,i-1) + text.substr(i); // remove \ from \$, \{, \}, or \\
} else if (match === '') {
if (k < i-1) mml.push(this.InternalText(text.slice(k,i-1),def));
match = '$'; k = i;
}
} else if (c === '}' && match === '}') {
mml.push(MML.TeXAtom(TEX.Parse(text.slice(k,i),{}).mml().With(def)));
match = ''; k = i;
} else if (c === '\\') {
if (match === '' && text.substr(i).match(/^(eq)?ref\s*\{/)) {
if (k < i-1) mml.push(this.InternalText(text.slice(k,i-1),def));
match = '}'; k = i-1;
} else {
c = text.charAt(i++);
if (c === '(' && match === '') {
if (k < i-2) mml.push(this.InternalText(text.slice(k,i-2),def));
match = ')'; k = i;
} else if (c === ')' && match === ')') {
mml.push(MML.TeXAtom(TEX.Parse(text.slice(k,i-2),{}).mml().With(def)));
match = ''; k = i;
} else if (c.match(/[${}\\]/) && match === '') {
i--; text = text.substr(0,i-1) + text.substr(i); // remove \ from \$, \{, \}, or \\
}
}
}
}
if (match !== '') TEX.Error(["MathNotTerminated","Math not terminated in text box"]);
}
if (match !== '')
{TEX.Error(["MathNotTerminated","Math not terminated in text box"])}
if (k < text.length) {mml.push(this.InternalText(text.slice(k),def))}
if (k < text.length) mml.push(this.InternalText(text.slice(k),def));
var mml = [MML.mstyle.apply(MML,mml).With({displaystyle:false})];
if (level != null) mml[0].scriptlevel = level;
return mml;
},
InternalText: function (text,def) {