|
2014 | 2014 |
|
2015 | 2015 | /*
|
2016 | 2016 | * Break up a string into text and math blocks
|
2017 |
| - * @@@ FIXME: skip over braced groups? @@@ |
2018 | 2017 | * @@@ FIXME: pass environment to TEX.Parse? @@@
|
2019 | 2018 | */
|
2020 | 2019 | 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))); |
2050 | 2028 | 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 | + } |
2053 | 2051 | }
|
2054 | 2052 | }
|
2055 | 2053 | }
|
| 2054 | + if (match !== '') TEX.Error(["MathNotTerminated","Math not terminated in text box"]); |
2056 | 2055 | }
|
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; |
2060 | 2059 | return mml;
|
2061 | 2060 | },
|
2062 | 2061 | InternalText: function (text,def) {
|
|
0 commit comments