Skip to content

Commit a356f66

Browse files
authored
Merge pull request #271 from mathjax/issue175
Prevent the color extension from auto-loading
2 parents e8828e4 + 24bd266 commit a356f66

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed

lib/main.js

+14
Original file line numberDiff line numberDiff line change
@@ -426,6 +426,20 @@ function ConfigureMathJax() {
426426

427427
});
428428

429+
//
430+
// Reset the color extension after `autoload-all`
431+
//
432+
if (MathJax.AuthorConfig.extensions.indexOf("TeX/color.js") == -1) {
433+
MathJax.Hub.Register.StartupHook("TeX autoload-all Ready",function () {
434+
var macros = MathJax.InputJax.TeX.Definitions.macros;
435+
macros.color = "Color";
436+
delete macros.textcolor;
437+
delete macros.colorbox;
438+
delete macros.fcolorbox;
439+
delete macros.definecolor;
440+
});
441+
}
442+
429443
//
430444
// Start the typesetting queue when MathJax is ready
431445
// (reseting the counters so that the initial math doesn't affect them)

test/issue175.js

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
var tape = require('tape');
2+
var mjAPI = require("../lib/main.js");
3+
var jsdom = require('jsdom').jsdom;
4+
5+
tape('color extension should be reset', function(t) {
6+
t.plan(3);
7+
mjAPI.start();
8+
var tex = '\\colorbox{green}{x}';
9+
var tex2 = '\\color{red}{x}x';
10+
11+
mjAPI.typeset({
12+
math: tex,
13+
format: "TeX",
14+
mml: true
15+
}, function(data) {
16+
t.ok(data.errors, 'Color extension disabled');
17+
});
18+
mjAPI.typeset({
19+
math: tex2,
20+
format: "TeX",
21+
mml: true
22+
}, function(data) {
23+
var document = jsdom(data.mml);
24+
var mstyle = document.defaultView.document.querySelector('mstyle');
25+
t.ok(document.defaultView.document.querySelectorAll('mi')[0].parentNode === mstyle, 'Color macro behaves correctly (1 of 2)');
26+
t.notOk(document.defaultView.document.querySelectorAll('mi')[1].parentNode === mstyle, 'Color macro behaves correctly (2 of 2)');
27+
});
28+
});

0 commit comments

Comments
 (0)