Skip to content

Commit f4f2296

Browse files
committed
Clear user defined TeX macros from global state
1 parent 6ff4d62 commit f4f2296

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

lib/main.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -741,6 +741,13 @@ function GetState(state) {
741741
MML.SUPER.ID = ID = 0;
742742
MathJax.OutputJax.CommonHTML.ID = 0;
743743
}
744+
745+
// Clear any existing user defined macros
746+
Object.keys(TEX.Definitions.macros).forEach(function(macroName){
747+
if (TEX.Definitions.macros[macroName].isUser) {
748+
delete TEX.Definitions.macros[macroName];
749+
}
750+
});
744751
}
745752

746753
//

test/macro-state.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
var tape = require('tape');
2+
var mjAPI = require("../lib/main.js");
3+
4+
tape('macros should be cleared from global state', function(t) {
5+
t.plan(2);
6+
mjAPI.start();
7+
8+
mjAPI.typeset({
9+
math: "\\def\\mymacro{2\\pi} \\mymacro",
10+
format: "TeX",
11+
mml: true
12+
}, function(data) {
13+
t.false(data.errors, 'Defined and used macro');
14+
});
15+
16+
mjAPI.typeset({
17+
math: "\\mymacro",
18+
format: "TeX",
19+
mml: true
20+
}, function(data) {
21+
t.true(data.errors, '\\mymacro should no longer be defined');
22+
});
23+
});

0 commit comments

Comments
 (0)