commit 16476f8d4436062652efde6c3aea0ae9863d0966
parent 24f0388bda426319ca60448d6aa1a082fe8bb233
Author: Davide P. Cervone <dpvc@union.edu>
Date: Sun, 2 Aug 2015 08:55:38 -0400
Merge branch 'issue1224' into develop. Issue #1224
Diffstat:
1 file changed, 14 insertions(+), 7 deletions(-)
diff --git a/unpacked/jax/input/TeX/jax.js b/unpacked/jax/input/TeX/jax.js
@@ -2020,31 +2020,38 @@
*/
InternalMath: function (text,level) {
var def = (this.stack.env.font ? {mathvariant: this.stack.env.font} : {});
- var mml = [], i = 0, k = 0, c, match = '';
+ var mml = [], i = 0, k = 0, c, match = '', braces = 0;
if (text.match(/\\?[${}\\]|\\\(|\\(eq)?ref\s*\{/)) {
while (i < text.length) {
c = text.charAt(i++);
if (c === '$') {
- if (match === '$') {
+ if (match === '$' && braces === 0) {
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 === '{' && match !== '') {
+ braces++;
+ } else if (c === '}') {
+ if (match === '}' && braces === 0) {
+ mml.push(MML.TeXAtom(TEX.Parse(text.slice(k,i),{}).mml().With(def)));
+ match = ''; k = i;
+ } else if (match !== '') {
+ if (braces) braces--;
+ }
} else if (c === '\\') {
if (match === '' && text.substr(i).match(/^(eq)?ref\s*\{/)) {
+ var len = RegExp["$&"].length;
if (k < i-1) mml.push(this.InternalText(text.slice(k,i-1),def));
- match = '}'; k = i-1;
+ match = '}'; k = i-1; i += len;
} 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 === ')') {
+ } else if (c === ')' && match === ')' && braces === 0) {
mml.push(MML.TeXAtom(TEX.Parse(text.slice(k,i-2),{}).mml().With(def)));
match = ''; k = i;
} else if (c.match(/[${}\\]/) && match === '') {