Skip to content

Commit 1e9f423

Browse files
authored
Merge pull request #1587 from dpvc/issue1586
Make sure trimSpaces() doesn't remove tailing space in '\ '. #1586
2 parents 814045a + 172e8a8 commit 1e9f423

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

unpacked/extensions/TeX/newcommand.js

+3-5
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,11 @@ MathJax.Hub.Register.StartupHook("TeX Jax Ready",function () {
5151
* Implement \newcommand{\name}[n][default]{...}
5252
*/
5353
NewCommand: function (name) {
54-
var CS = this.GetArgument(name), cs = this.trimSpaces(CS),
54+
var cs = this.trimSpaces(this.GetArgument(name)),
5555
n = this.GetBrackets(name),
5656
opt = this.GetBrackets(name),
5757
def = this.GetArgument(name);
5858
if (cs.charAt(0) === "\\") {cs = cs.substr(1)}
59-
if (cs === "" && CS.substr(CS.length-1,1) === " ") {cs += " "}
6059
if (!cs.match(/^(.|[a-z]+)$/i)) {
6160
TEX.Error(["IllegalControlSequenceName",
6261
"Illegal control sequence name for %1",name]);
@@ -147,9 +146,8 @@ MathJax.Hub.Register.StartupHook("TeX Jax Ready",function () {
147146
TEX.Error(["MissingCS",
148147
"%1 must be followed by a control sequence", cmd])
149148
}
150-
var cs = this.GetArgument(cmd), CS = this.trimSpaces(cs);
151-
if (CS == "\\" && cs.substr(cs.length-1,1) === " ") {CS += " "}
152-
return CS.substr(1);
149+
var cs = this.trimSpaces(this.GetArgument(cmd));
150+
return cs.substr(1);
153151
},
154152

155153
/*

unpacked/jax/input/TeX/jax.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -1877,7 +1877,9 @@
18771877
*/
18781878
trimSpaces: function (text) {
18791879
if (typeof(text) != 'string') {return text}
1880-
return text.replace(/^\s+|\s+$/g,'');
1880+
var TEXT = text.replace(/^\s+|\s+$/g,'');
1881+
if (TEXT.match(/\\$/) && text.match(/ $/)) TEXT += " ";
1882+
return TEXT;
18811883
},
18821884

18831885
/*

0 commit comments

Comments
 (0)