commit 7cbea14c7506283189d8e417dd638cf5ab4e2893
parent 24f0388bda426319ca60448d6aa1a082fe8bb233
Author: Davide P. Cervone <dpvc@union.edu>
Date: Thu, 30 Jul 2015 09:25:25 -0400
Handle braces properly in text mode when looking for matching math delimiters. Resolves 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 === '') {