Search code examples
fontsmathjax

How do I get MathJax (CDN) to use Latin-Modern instead of STIX?


I am able to get the STIX font mathematical symbols to show by putting

<script type="text/javascript"src="http://cdn.mathjax.org/mathjax/latest/MathJax.js"></script>

in the head of app/views/application.html.erb.

However, I want it to use the Latin-Modern font. In my application.js file, I added

MathJax.Hub.Config({
  "HTML-CSS": {
    preferredFont: "Latin-Modern"
    }
});

But, Latin-Modern doesn't render on the page.

Note: I am able to render mathematical symbols and equations with MacTex and I have installed 'latinmodern-math.otf' from http://www.gust.org.pl/projects/e-foundry/lm-math


Solution

  • The preferredFont tells MathJax which of the local font (from the availableFonts list) to used, if it is available. It is unlikely that your users will have the MathJax versions of the Latin-Modern fonts installed locally. Instead, if you want to force Latin-Modern, you will need to prevent the use of local fonts, and tell MathJax to use the Latin-Modern web font. Use

    MathJax.Hub.Config({
      "HTML-CSS": {
        availableFonts: [],
        preferredFont: null,
        webFont: "Latin-Modern"
      }
    });
    

    There is also a newer (and not well documented) method of setting all three at once using the fonts property. This gives an array of fonts to look for locally, with the first one being preferred, and the first used as the web font if none is found locally. So

    MathJax.Hub.Config({
      "HTML-CSS": {
        fonts: ["Latin-Modern"]
      }
    });
    

    should also do it.