Skip to content

Prevent the color extension from auto-loading #271

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 2, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,20 @@ function ConfigureMathJax() {

});

//
// Reset the color extension after `autoload-all`
//
if (MathJax.AuthorConfig.extensions.indexOf("TeX/color.js") == -1) {
MathJax.Hub.Register.StartupHook("TeX autoload-all Ready",function () {
var macros = MathJax.InputJax.TeX.Definitions.macros;
macros.color = "Color";
delete macros.textcolor;
delete macros.colorbox;
delete macros.fcolorbox;
delete macros.definecolor;
});
}

//
// Start the typesetting queue when MathJax is ready
// (reseting the counters so that the initial math doesn't affect them)
Expand Down
28 changes: 28 additions & 0 deletions test/issue175.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
var tape = require('tape');
var mjAPI = require("../lib/main.js");
var jsdom = require('jsdom').jsdom;

tape('color extension should be reset', function(t) {
t.plan(3);
mjAPI.start();
var tex = '\\colorbox{green}{x}';
var tex2 = '\\color{red}{x}x';

mjAPI.typeset({
math: tex,
format: "TeX",
mml: true
}, function(data) {
t.ok(data.errors, 'Color extension disabled');
});
mjAPI.typeset({
math: tex2,
format: "TeX",
mml: true
}, function(data) {
var document = jsdom(data.mml);
var mstyle = document.defaultView.document.querySelector('mstyle');
t.ok(document.defaultView.document.querySelectorAll('mi')[0].parentNode === mstyle, 'Color macro behaves correctly (1 of 2)');
t.notOk(document.defaultView.document.querySelectorAll('mi')[1].parentNode === mstyle, 'Color macro behaves correctly (2 of 2)');
});
});