Search code examples
javascriptfontsmathjax

How can I load fonts from a different location in MathJax?


MathJax enforces a directory structure based on its library design. Fonts bundled with the library are in a subdirectory alongside some Javascript configuration and other components.

I want to serve the fonts from a different location on disk but I'm not seeing any configuration values that allow me to do that. I've checked the documentation and while I'm seeing different ways to load the full library and pieces of configuration, I'm not seeing how to isolate the fonts.

How can I load fonts from a different location in MathJax?

Edit: This is a client-side solution; we're doing this in the browser. We're using the TeX-AMS_CHTML.js configuration, which uses the CommonHTML rendering strategy. In the configuration (which is minified) it looks like there's a MathJax.OutputJax.fontDir that could be edited?


Solution

  • You want to override the CommonHTML webfontDir. Try

    <script type="text/x-mathjax-config">
    MathJax.Hub.Register.StartupHook('CommonHTML Jax Ready", function () {
      MathJax.OutputJax.CommonHTML.webfontDir = 'myURL/myDontDirectory';
    });
    </script>
    

    where myURL/myFontDirectory is the full URL to the directory containing your fonts. You may need to set the access control for the fonts directory to allow cross-domain access if the URL domain is not the same as the domain of the page loading MathJax. See the MathJax documentation on shared installations for more details.