Make sure trimSpaces() doesn't remove tailing space in '\ '. Resolves issue #1586 (and handles #1563 better).

This commit is contained in:
Davide P. Cervone 2016-08-17 13:44:42 -04:00
parent d3eec1386a
commit 172e8a8727
2 changed files with 6 additions and 6 deletions

View File

@ -51,12 +51,11 @@ MathJax.Hub.Register.StartupHook("TeX Jax Ready",function () {
* Implement \newcommand{\name}[n][default]{...} * Implement \newcommand{\name}[n][default]{...}
*/ */
NewCommand: function (name) { NewCommand: function (name) {
var CS = this.GetArgument(name), cs = this.trimSpaces(CS), var cs = this.trimSpaces(this.GetArgument(name)),
n = this.GetBrackets(name), n = this.GetBrackets(name),
opt = this.GetBrackets(name), opt = this.GetBrackets(name),
def = this.GetArgument(name); def = this.GetArgument(name);
if (cs.charAt(0) === "\\") {cs = cs.substr(1)} if (cs.charAt(0) === "\\") {cs = cs.substr(1)}
if (cs === "" && CS.substr(CS.length-1,1) === " ") {cs += " "}
if (!cs.match(/^(.|[a-z]+)$/i)) { if (!cs.match(/^(.|[a-z]+)$/i)) {
TEX.Error(["IllegalControlSequenceName", TEX.Error(["IllegalControlSequenceName",
"Illegal control sequence name for %1",name]); "Illegal control sequence name for %1",name]);
@ -147,9 +146,8 @@ MathJax.Hub.Register.StartupHook("TeX Jax Ready",function () {
TEX.Error(["MissingCS", TEX.Error(["MissingCS",
"%1 must be followed by a control sequence", cmd]) "%1 must be followed by a control sequence", cmd])
} }
var cs = this.GetArgument(cmd), CS = this.trimSpaces(cs); var cs = this.trimSpaces(this.GetArgument(cmd));
if (CS == "\\" && cs.substr(cs.length-1,1) === " ") {CS += " "} return cs.substr(1);
return CS.substr(1);
}, },
/* /*

View File

@ -1877,7 +1877,9 @@
*/ */
trimSpaces: function (text) { trimSpaces: function (text) {
if (typeof(text) != 'string') {return text} if (typeof(text) != 'string') {return text}
return text.replace(/^\s+|\s+$/g,''); var TEXT = text.replace(/^\s+|\s+$/g,'');
if (TEXT.match(/\\$/) && text.match(/ $/)) TEXT += " ";
return TEXT;
}, },
/* /*