mathjax / MathJax-src

MathJax source code for version 3 and beyond

Home Page:https://www.mathjax.org/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Timing problem on document creation

zorkow opened this issue · comments

There is a node issue on initialisation where CONFIG.require is not set. Consider the following minimal example (working directory '/tmp').

const mj = require('mathjax');
let promise = mj.init({loader: {load: ['/tmp/node_modules/mathjax/es5/input/tex']}});

That works fine when executed in node, but not when executed with node as in node test.js.

When giving loader the require method explicitly, it works as expected. E.g.,

const mj = require('mathjax');
let promise = mj.init({
  loader: {require: require,
           load: ['/tmp/node_modules/mathjax/es5/input/tex']}});
promise.then(m => console.log(m.tex2mml('x^2')));

works fine. Not sure if this is intended.
I am also not quite sure why require is not bound to the global object when node is executed in shell mode, which could be the reason for the observed problem.

The require field was not being set properly, nor is the default mathjax path for loading components. The webpacking was affecting the results (and it seems I didn't adequately check that). These two changes should resolve the issue. The original global.require() was an attempt to avoid error messages where webpack would complain about not being able to resolve the files being required, but failed to get the right value in the web packed file. The method used in the PR listed above seems to work.

PS, it also fixes the problem with the mathjax root path, so that

const mj = require('mathjax');
let promise = mj.init({loader: {load: ['input/tex']}});

should work (no need for full path to the component).

OK, this is not yet fully fixed. It works for the mathjax npm package, but not for mathjax-full, or from the MathJax-src repository (it should work for both the es5 directory and the components/src/node-main copies).

I've made a PR to address the problem.