Skip to content

Commit 952f611

Browse files
committed
Move setDef and setEnv to TeX jax, and use them for \DeclareMathOperator and \Newextarrow so they can be localized via the begingroup extension. Resolves issue #1876
1 parent f5daa00 commit 952f611

File tree

5 files changed

+39
-56
lines changed

5 files changed

+39
-56
lines changed

unpacked/extensions/TeX/AMSmath.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ MathJax.Hub.Register.StartupHook("TeX Jax Ready",function () {
224224
if (cs.charAt(0) == "\\") {cs = cs.substr(1)}
225225
var op = this.GetArgument(name);
226226
op = op.replace(/\*/g,'\\text{*}').replace(/-/g,'\\text{-}');
227-
TEX.Definitions.macros[cs] = ['Macro','\\mathop{\\rm '+op+'}'+limits];
227+
this.setDef(cs, ['Macro', '\\mathop{\\rm '+op+'}'+limits]);
228228
},
229229

230230
HandleOperatorName: function (name) {

unpacked/extensions/TeX/begingroup.js

Lines changed: 30 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -193,9 +193,9 @@ MathJax.Hub.Register.StartupHook("TeX Jax Ready",function () {
193193
macros: {
194194
begingroup: "BeginGroup",
195195
endgroup: "EndGroup",
196-
global: ["Extension","newcommand"],
197-
gdef: ["Extension","newcommand"]
198-
}
196+
global: "Global",
197+
gdef: ["Macro","\\global\\def"]
198+
}
199199
},null,true);
200200

201201
TEX.Parse.Augment({
@@ -232,8 +232,34 @@ MathJax.Hub.Register.StartupHook("TeX Jax Ready",function () {
232232
},
233233
envFindName: function (name) {
234234
return (TEX.eqnStack.Find(name,"environments") || TEX.rootStack.Find(name,"environments"));
235-
}
235+
},
236+
237+
//
238+
// Modify the way macros and environments are defined
239+
// to make them go into the equation namespace stack
240+
//
241+
setDef: function (name,value) {
242+
value.isUser = true;
243+
TEX.eqnStack.Def(name,value,"macros",this.stack.env.isGlobal);
244+
delete this.stack.env.isGlobal;
245+
},
246+
setEnv: function (name,value) {
247+
value.isUser = true;
248+
TEX.eqnStack.Def(name,value,"environments")
249+
},
236250

251+
//
252+
// Implement \global (for \global\let, \global\def and \global\newcommand)
253+
//
254+
Global: function (name) {
255+
var i = this.i; var cs = this.GetCSname(name); this.i = i;
256+
if (cs !== "let" && cs !== "def" && cs !== "newcommand" &&
257+
cs !== "DeclareMathOperator" && cs !== "Newextarrow") {
258+
TEX.Error(["GlobalNotFollowedBy",
259+
"%1 not followed by \\let, \\def, or \\newcommand",name]);
260+
}
261+
this.stack.env.isGlobal = true;
262+
}
237263
});
238264

239265
/****************************************************/
@@ -259,49 +285,6 @@ MathJax.Hub.Register.StartupHook("TeX Jax Ready",function () {
259285

260286
/*********************************************************/
261287

262-
MathJax.Hub.Register.StartupHook("TeX newcommand Ready",function () {
263-
264-
//
265-
// Add the commands that depend on the newcommand code
266-
//
267-
TEXDEF.Add({
268-
macros: {
269-
global: "Global",
270-
gdef: ["Macro","\\global\\def"]
271-
}
272-
},null,true);
273-
274-
TEX.Parse.Augment({
275-
//
276-
// Modify the way macros and environments are defined
277-
// to make them go into the equation namespace stack
278-
//
279-
setDef: function (name,value) {
280-
value.isUser = true;
281-
TEX.eqnStack.Def(name,value,"macros",this.stack.env.isGlobal);
282-
delete this.stack.env.isGlobal;
283-
},
284-
setEnv: function (name,value) {
285-
value.isUser = true;
286-
TEX.eqnStack.Def(name,value,"environments")
287-
},
288-
289-
//
290-
// Implement \global (for \global\let, \global\def and \global\newcommand)
291-
//
292-
Global: function (name) {
293-
var i = this.i; var cs = this.GetCSname(name); this.i = i;
294-
if (cs !== "let" && cs !== "def" && cs !== "newcommand") {
295-
TEX.Error(["GlobalNotFollowedBy",
296-
"%1 not followed by \\let, \\def, or \\newcommand",name]);
297-
}
298-
this.stack.env.isGlobal = true;
299-
}
300-
301-
});
302-
303-
});
304-
305288
MathJax.Hub.Startup.signal.Post("TeX begingroup Ready");
306289

307290
});

unpacked/extensions/TeX/extpfeil.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ MathJax.Hub.Register.StartupHook("TeX Jax Ready",function () {
9292
);
9393
}
9494
cs = cs.substr(1); space = space.split(","); chr = parseInt(chr);
95-
TEXDEF.macros[cs] = ['xArrow',chr,parseInt(space[0]),parseInt(space[1])];
95+
this.setDef(cs, ['xArrow', chr, parseInt(space[0]), parseInt(space[1])]);
9696
}
9797
});
9898

unpacked/extensions/TeX/newcommand.js

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -130,13 +130,6 @@ MathJax.Hub.Register.StartupHook("TeX Jax Ready",function () {
130130
this.setDef(cs,macro);
131131
},
132132

133-
/*
134-
* Routines to set the macro and environment definitions
135-
* (overridden by begingroup to make localized versions)
136-
*/
137-
setDef: function (name,value) {value.isUser = true; TEXDEF.macros[name] = value},
138-
setEnv: function (name,value) {value.isUser = true; TEXDEF.environment[name] = value},
139-
140133
/*
141134
* Get a CS name or give an error
142135
*/

unpacked/jax/input/TeX/jax.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2158,6 +2158,13 @@
21582158
return MML.mtext(MML.chars(text)).With(def);
21592159
},
21602160

2161+
/*
2162+
* Routines to set the macro and environment definitions
2163+
* (overridden by begingroup to make localized versions)
2164+
*/
2165+
setDef: function (name,value) {value.isUser = true; TEXDEF.macros[name] = value},
2166+
setEnv: function (name,value) {value.isUser = true; TEXDEF.environment[name] = value},
2167+
21612168
/*
21622169
* Replace macro parameters with their values
21632170
*/

0 commit comments

Comments
 (0)