Skip to content

Commit 4db3f74

Browse files
authored
Merge pull request #1565 from dpvc/issue1563
Fix problems with defining \ (control-space). #1563 and #1564
2 parents f5e818c + 0037d6b commit 4db3f74

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

unpacked/extensions/TeX/newcommand.js

+10-7
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,12 @@ MathJax.Hub.Register.StartupHook("TeX Jax Ready",function () {
5151
* Implement \newcommand{\name}[n][default]{...}
5252
*/
5353
NewCommand: function (name) {
54-
var cs = this.trimSpaces(this.GetArgument(name)),
54+
var CS = this.GetArgument(name), cs = this.trimSpaces(CS),
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 += " "}
5960
if (!cs.match(/^(.|[a-z]+)$/i)) {
6061
TEX.Error(["IllegalControlSequenceName",
6162
"Illegal control sequence name for %1",name]);
@@ -120,10 +121,11 @@ MathJax.Hub.Register.StartupHook("TeX Jax Ready",function () {
120121
name = this.GetCSname(name);
121122
macro = this.csFindMacro(name);
122123
if (!macro) {
123-
if (TEXDEF.mathchar0mi[name]) {macro = ["csMathchar0mi",TEXDEF.mathchar0mi[name]]} else
124-
if (TEXDEF.mathchar0mo[name]) {macro = ["csMathchar0mo",TEXDEF.mathchar0mo[name]]} else
125-
if (TEXDEF.mathchar7[name]) {macro = ["csMathchar7",TEXDEF.mathchar7[name]]} else
126-
if (TEXDEF.delimiter["\\"+name] != null) {macro = ["csDelimiter",TEXDEF.delimiter["\\"+name]]}
124+
if (TEXDEF.mathchar0mi[name]) {macro = ["csMathchar0mi",TEXDEF.mathchar0mi[name]]} else
125+
if (TEXDEF.mathchar0mo[name]) {macro = ["csMathchar0mo",TEXDEF.mathchar0mo[name]]} else
126+
if (TEXDEF.mathchar7[name]) {macro = ["csMathchar7",TEXDEF.mathchar7[name]]} else
127+
if (TEXDEF.delimiter["\\"+name] != null) {macro = ["csDelimiter",TEXDEF.delimiter["\\"+name]]} else
128+
return;
127129
}
128130
} else {macro = ["Macro",c]; this.i++}
129131
this.setDef(cs,macro);
@@ -145,8 +147,9 @@ MathJax.Hub.Register.StartupHook("TeX Jax Ready",function () {
145147
TEX.Error(["MissingCS",
146148
"%1 must be followed by a control sequence", cmd])
147149
}
148-
var cs = this.trimSpaces(this.GetArgument(cmd));
149-
return cs.substr(1);
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);
150153
},
151154

152155
/*

0 commit comments

Comments
 (0)