I use SystemJS
to build an Angular 2
application and I'd like to start using MathJax
in a component. I installed with:
npm install --save-dev mathjax
npm install --save @types/mathjax
MathJax is now installed in /node_modules/mathjax
. When my component does import "mathjax"
, the file /node_modules/mathjax/MathJax.js
is loaded. So far so good.
Problem is that this file then tries to load other files using paths relative to the project root instead of the MathJax install directory.
For instance, MathJax.js
tries to load
/extensions/MathMenu.js 404 Not found
/extensions/MathZoom.js 404 Not found
The correct paths are
/node_modules/mathjax/extensions/MathMenu.js
/node_modules/mathjax/extensions/MathZoom.js
A quick look inside the source files show that the URLs are referred to this way:
[MathJax]/extensions/MathMenu.js
Any idea where I should look to fix this? I know I shouldn't alter the MathJax.js
file itself since any change will be overwritten after an update. It also doesn't make sense to use htaccess
or other server-side redirects.
I'm aware that I can load a working MathJax bundle by using the CDN:
<script src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=AM_SVG"></script>
However I'm trying to learn how to integrate the library into my build setup.
Simply put, you cannot integrate MathJax like this (at this time).
MathJax inludes a custom dynamic module loader designed to work all the way down to IE6; unsurprisingly, it does not work with contemporary build tools.
But very likely you also don't want to integrate MathJax in its entirety because that comes in at a couple of dozen megabytes (compressed). Now, in practice, you don't need all components, typically developers need 1 input + 1 output + 1 set of fonts which comes down to around ~500-600KB (compressed).
If that's a feasible pay load, then you could look into building a customized single-file build (such as this one) which you should be able to integrate.
For what it's worth, compatibility with contemporary build tools is a deliverable for MathJax v3.0 next year.
Full disclosure: I'm part of the MathJax team.
来源:https://stackoverflow.com/questions/40989264/integrate-mathjax-into-systemjs-build