Skip to content

using extensions #143

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

Closed
Pomax opened this issue Dec 30, 2015 · 7 comments
Closed

using extensions #143

Pomax opened this issue Dec 30, 2015 · 7 comments
Labels

Comments

@Pomax
Copy link
Contributor

Pomax commented Dec 30, 2015

I'm trying to use the colors.js TeX extension, but running the following code throws a typesetting error:

var mjAPI = require("mathjax-node/lib/mj-single");
mjAPI.config({ MathJax: { TeX: { extensions: ["color.js"] }}});
mjAPI.start();

mjAPI.typeset({
  math: '{\\color{blue} E} = mc^2',
  format: "TeX",
  svg: true
}, function (data) {
  if (data.errors) return console.error("error:", data.errors);
  console.log(data.svg);
});

The result is:

Error: TEX.resetEquationNumbers is not a function

Are the 2.5 TeX extensions listed on https://docs.mathjax.org/en/v2.5-latest/tex.html supported?

@pkra
Copy link
Contributor

pkra commented Dec 30, 2015

mjApPI.config expects a string of extensions (cf. also https://github.com/mathjax/MathJax-node/blob/master/bin/tex2svg#L65; jsdom has a quirk regarding arrays).

Anyway, by default, autoload.js is loaded so the color extension should work out of the box (and your example works fine for me using e.g., bin/tex2svg).

@dpvc
Copy link
Member

dpvc commented Dec 30, 2015

@pkra, both answers are inaccurate, I'm afraid, but I don't have time to write a correction just now. Will try to do it later tonight. The real problem is that the config call wipes out the extensions specified by the library itself. If you do

mjAPI.config({ MathJax: { TeX: { extensions: ["AMSmath.js","AMSsymbols.js","autoload-all.js","color.js"] }}});

I think that should fix it. More later...

@pkra
Copy link
Contributor

pkra commented Dec 30, 2015

Ah, thanks for correcting me, @dpvc!

@Pomax
Copy link
Contributor Author

Pomax commented Dec 30, 2015

ahh, good to know, thanks @dpvc! @pkra worth changing the label over? (Since it's reproducible and a bug in the config handling?)

@dpvc
Copy link
Member

dpvc commented Dec 31, 2015

@pkra, OK, didn't get back to you last night. Here's what is going on:

The mj-single library sets up its configuration (which includes setting the TeX extensions array to load AMSmath, AMSsymbols, and autoload-all) and then applies the author-supplied configuration. In this case, that included a TeX extensions array of its own, which wiped out the one MathJax-node set up. So in particular the AMSmath extension was no longer loaded, and that is the one that defines the TeX.resetEquationNumbers() method. I suppose MathJax-node should be modified to avoid calling that if it doesn't exist.

You are right in remembering that we had problems passing arrays in the configuration, but I worked around that in a recent release, so that is no longer an issue. You are right that a string is used for the --extensions command-line-option, however, and there is an extensions option that can be passed to mjAPI.config() directly (but the one inside the MathJax block is an array, as it is in the usual MathJax configuration object).

You are right to point out the autoload-all extension, and I was going to say that because \color is already defined in MathJax's TeX input jax by default, that autoload-all would not redefine it, but I checked the code and I am wrong; \color is set to autoload the color extension. I'm not sure that is the desired behavior for MathJax-node, since that means it will operate differently from default MathJax in the browser.

@pkra
Copy link
Contributor

pkra commented Feb 18, 2016

This is currently marked expected behavior but reading the thread it's actually a bug (and we never switched the label). Actually, it seme to be two.

So in particular the AMSmath extension was no longer loaded, and that is the one that defines the TeX.resetEquationNumbers() method. I suppose MathJax-node should be modified to avoid calling that if it doesn't exist.

and

I checked the code and I am wrong; \color is set to autoload the color extension. I'm not sure that is the desired behavior for MathJax-node, since that means it will operate differently from default MathJax in the browser.

Should we separate them out?

@pkra
Copy link
Contributor

pkra commented Feb 18, 2016

Closing in favor of #175 and #176.

@pkra pkra closed this as completed Feb 18, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants