Skip to content

Commit 3beda8d

Browse files
committed
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.
1 parent 48b594a commit 3beda8d

File tree

1 file changed

+34
-35
lines changed

1 file changed

+34
-35
lines changed

unpacked/jax/input/TeX/jax.js

Lines changed: 34 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -2014,49 +2014,48 @@
20142014

20152015
/*
20162016
* Break up a string into text and math blocks
2017-
* @@@ FIXME: skip over braced groups? @@@
20182017
* @@@ FIXME: pass environment to TEX.Parse? @@@
20192018
*/
20202019
InternalMath: function (text,level) {
2021-
var def = {displaystyle: false}; if (level != null) {def.scriptlevel = level}
2022-
if (this.stack.env.font) {def.mathvariant = this.stack.env.font}
2023-
if (!text.match(/\\?[${}\\]|\\\(|\\(eq)?ref\s*\{/)) {return [this.InternalText(text,def)]}
2024-
var i = 0, k = 0, c, match = '';
2025-
var mml = [];
2026-
while (i < text.length) {
2027-
c = text.charAt(i++);
2028-
if (c === '$') {
2029-
if (match === '$') {
2030-
mml.push(MML.TeXAtom(TEX.Parse(text.slice(k,i-1),{}).mml().With(def)));
2031-
match = ''; k = i;
2032-
} else if (match === '') {
2033-
if (k < i-1) {mml.push(this.InternalText(text.slice(k,i-1),def))}
2034-
match = '$'; k = i;
2035-
}
2036-
} else if (c === '}' && match === '}') {
2037-
mml.push(MML.TeXAtom(TEX.Parse(text.slice(k,i),{}).mml().With(def)));
2038-
match = ''; k = i;
2039-
} else if (c === '\\') {
2040-
if (match === '' && text.substr(i).match(/^(eq)?ref\s*\{/)) {
2041-
if (k < i-1) {mml.push(this.InternalText(text.slice(k,i-1),def))}
2042-
match = '}'; k = i-1;
2043-
} else {
2044-
c = text.charAt(i++);
2045-
if (c === '(' && match === '') {
2046-
if (k < i-2) {mml.push(this.InternalText(text.slice(k,i-2),def))}
2047-
match = ')'; k = i;
2048-
} else if (c === ')' && match === ')') {
2049-
mml.push(MML.TeXAtom(TEX.Parse(text.slice(k,i-2),{}).mml().With(def)));
2020+
var def = (this.stack.env.font ? {mathvariant: this.stack.env.font} : {});
2021+
var mml = [], i = 0, k = 0, c, match = '';
2022+
if (text.match(/\\?[${}\\]|\\\(|\\(eq)?ref\s*\{/)) {
2023+
while (i < text.length) {
2024+
c = text.charAt(i++);
2025+
if (c === '$') {
2026+
if (match === '$') {
2027+
mml.push(MML.TeXAtom(TEX.Parse(text.slice(k,i-1),{}).mml().With(def)));
20502028
match = ''; k = i;
2051-
} else if (c.match(/[${}\\]/) && match === '') {
2052-
i--; text = text.substr(0,i-1) + text.substr(i); // remove \ from \$, \{, \}, or \\
2029+
} else if (match === '') {
2030+
if (k < i-1) mml.push(this.InternalText(text.slice(k,i-1),def));
2031+
match = '$'; k = i;
2032+
}
2033+
} else if (c === '}' && match === '}') {
2034+
mml.push(MML.TeXAtom(TEX.Parse(text.slice(k,i),{}).mml().With(def)));
2035+
match = ''; k = i;
2036+
} else if (c === '\\') {
2037+
if (match === '' && text.substr(i).match(/^(eq)?ref\s*\{/)) {
2038+
if (k < i-1) mml.push(this.InternalText(text.slice(k,i-1),def));
2039+
match = '}'; k = i-1;
2040+
} else {
2041+
c = text.charAt(i++);
2042+
if (c === '(' && match === '') {
2043+
if (k < i-2) mml.push(this.InternalText(text.slice(k,i-2),def));
2044+
match = ')'; k = i;
2045+
} else if (c === ')' && match === ')') {
2046+
mml.push(MML.TeXAtom(TEX.Parse(text.slice(k,i-2),{}).mml().With(def)));
2047+
match = ''; k = i;
2048+
} else if (c.match(/[${}\\]/) && match === '') {
2049+
i--; text = text.substr(0,i-1) + text.substr(i); // remove \ from \$, \{, \}, or \\
2050+
}
20532051
}
20542052
}
20552053
}
2054+
if (match !== '') TEX.Error(["MathNotTerminated","Math not terminated in text box"]);
20562055
}
2057-
if (match !== '')
2058-
{TEX.Error(["MathNotTerminated","Math not terminated in text box"])}
2059-
if (k < text.length) {mml.push(this.InternalText(text.slice(k),def))}
2056+
if (k < text.length) mml.push(this.InternalText(text.slice(k),def));
2057+
var mml = [MML.mstyle.apply(MML,mml).With({displaystyle:false})];
2058+
if (level != null) mml[0].scriptlevel = level;
20602059
return mml;
20612060
},
20622061
InternalText: function (text,def) {

0 commit comments

Comments
 (0)