From 83387dd3f11a377164b13c865c88e3030749a888 Mon Sep 17 00:00:00 2001 From: "Davide P. Cervone" Date: Thu, 28 Jul 2016 07:23:42 -0400 Subject: [PATCH 1/2] Treat control sequences as a unit when matching a macro template. Resolves both issues for #1568. --- unpacked/extensions/TeX/newcommand.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/unpacked/extensions/TeX/newcommand.js b/unpacked/extensions/TeX/newcommand.js index a449b1698..6dfc42b3c 100644 --- a/unpacked/extensions/TeX/newcommand.js +++ b/unpacked/extensions/TeX/newcommand.js @@ -234,12 +234,17 @@ MathJax.Hub.Register.StartupHook("TeX Jax Ready",function () { if (param == null) {return this.GetArgument(name)} var i = this.i, j = 0, hasBraces = 0; while (this.i < this.string.length) { - if (this.string.charAt(this.i) === '{') { + var c = this.string.charAt(this.i); + if (c === '{') { if (this.i === i) {hasBraces = 1} this.GetArgument(name); j = this.i - i; } else if (this.MatchParam(param)) { if (hasBraces) {i++; j -= 2} return this.string.substr(i,j); + } else if (c === "\\") { + this.i++; j++; hasBraces = 0; + var match = this.string.substr(this.i).match(/[a-z]+|./i); + if (match) {this.i += match[0].length; j = this.i - i} } else { this.i++; j++; hasBraces = 0; } @@ -254,6 +259,8 @@ MathJax.Hub.Register.StartupHook("TeX Jax Ready",function () { */ MatchParam: function (param) { if (this.string.substr(this.i,param.length) !== param) {return 0} + if (param.match(/\\[a-z]+/i) && + this.string.charAt(this.i+param.length).match(/[a-z]/i)) {return 0} this.i += param.length; return 1; } From c5b61d4f32d028d5b910ee897e515325595b956e Mon Sep 17 00:00:00 2001 From: "Davide P. Cervone" Date: Thu, 28 Jul 2016 07:28:00 -0400 Subject: [PATCH 2/2] Make sure we test only control sequences at the END of the parameter. --- unpacked/extensions/TeX/newcommand.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/unpacked/extensions/TeX/newcommand.js b/unpacked/extensions/TeX/newcommand.js index 6dfc42b3c..89b1ee51a 100644 --- a/unpacked/extensions/TeX/newcommand.js +++ b/unpacked/extensions/TeX/newcommand.js @@ -259,7 +259,7 @@ MathJax.Hub.Register.StartupHook("TeX Jax Ready",function () { */ MatchParam: function (param) { if (this.string.substr(this.i,param.length) !== param) {return 0} - if (param.match(/\\[a-z]+/i) && + if (param.match(/\\[a-z]+$/i) && this.string.charAt(this.i+param.length).match(/[a-z]/i)) {return 0} this.i += param.length; return 1;