Skip to content
Peter Krautzberger edited this page Jul 23, 2013 · 3 revisions

This is a draft

A MathJax Q&A -- fonts

A topic that comes up regularly on the MathJax user group, on Twitter or through email is fonts. Fonts (for the web) are in themselves a complicated topic and the added complexities of MathJax’s typesetting makes this not as easy to explain as you might think.

The basic question: which fonts can you use with MathJax?

MathJax currently only supports two sets of fonts

  • MathJax fonts (based on Computer Modern)
  • STIX fonts

You can imagine that we would love to offer a wider support of fonts. However, the technological and legal restrictions make this difficult.

The next question: do I have to install these?

That’s the best part: No.

MathJax is designed to “just work” -- no visitor to a website using MathJax is expected to have anything installed (well, ok, we do expect a reasonably modern browser ;) ).

How is that possible?

MathJax will dynamically download the MathJax fonts from the server that hosts MathJax. These fonts will be downloaded in a so-called webfont format. There are different such formats and MathJax will choose the one that’s suitable for the browser. Thankfully, WOFF is now an official W3C recommendation, so in the future, webfonts will simply equal WOFF.

So I shouldn’t install these fonts?

It’s perfectly alright to install these fonts locally. MathJax will recognize their presence and use the locally installed fonts.

This has a practical benefit, too: when you visit a page using MathJax, MathJax will not have to download the fonts which will give you a small to medium performance boost.

(It’s not that big a boost for two reasons: 1) your browser will cache the webfonts after the first download 2) downloads are not the big performance hit, our beautiful typesetting is)

How would I install them if I wanted to?

  • An experimental Windows installer for MathJax, STIX and Asana fonts: https://developer.mozilla.org/@api/deki/files/6388/=MathML-fonts.msi -- only tested on a 32-bits Windows 7 virtual machine, feedback is appreciated.
  • Mac OSX will come with STIX fonts preinstalled.
  • most Linux distributions have a package for STIX fonts and even MathJax fonts.

See also

https://github.com/fred-wang/Mathzilla/blob/master/mathml-fonts/MSI/MathML-fonts.wxs https://bugzilla.mozilla.org/show_bug.cgi?id=767725

Why can’t I get the STIX fonts as webfonts?

The STIX fonts are currently not available in a webfonts format. We’re working with the STIX group to create webfonts.

Why can’t I just use an arbitrary font like Arial or Comic Sans?

There are very few fonts that contain mathematical characters so typesetting mathematical content is not possible with almost all fonts.

Ok, but why can’t I just use any of the fonts that contain mathematical characters?

MathJax achieves the highest typesetting quality available on the web -- our goal is LaTeX-quality typesetting after all. This level of typesetting requires a lot of complicated computation of character placements so that the mathematical content fitssmoothly into the surrounding text.

To be able to position the characters well, MathJax needs to have very specific knowledge of the dimensions of each character in the fonts.

These dimensions can’t be calculated on the fly as javascript cannot access that kind of information of a font file -- so we collect that information in our development process.

Ok, so why don’t you add support for those fonts that contain mathematical characters?

We’re working on it. The problem is that there are few free fonts and even fewer open-source fonts with mathematical characters out there.

In addition, to fully support a font, we usually have to modify the font in two ways:

  • add special characters to the font.
    • These are used to circumvent the problematic behavior of some browsers with respect to webfonts.
  • create webfont versions of the font
    • This includes breaking up the font into a several pieces. To improve performance, MathJax will only load those “webfont-pieces” that contain characters actually used in a page.

In other words, to fully support a font (webfonts and even ship it), it needs to be available under a very flexible license, e.g., an open source license.

Will you support non-libre fonts?

We would like to do so but licensing restrictions will most likely prevent us from supporting them fully.

Most likely, supporting locally installed fonts is the best we will be able to do. This would be enough for apps that know fonts are available for sure.

Ok, let’s do specifics. Will you support Cambria Math?

As far as we know, we will not be able to. This might surprise you, but there’s a really odd problem with Cambria Math: it stores mathematical characters outside the usual unicode range and its tables are not linking correctly. This means we cannot address these characters in javascript -- at all.

So how good are your fonts, what kind of character coverage can I expect?

The MathJax fonts may appear incomplete, but that's by design. Mathjax itself can easily compensate for certain characters by combining multiple characters on the fly. For example, there's no quadruple integral sign in the fonts, but MathJax builds it out of two double integrals. This means MathJax+MathJax fonts is missing only a handful of rather rare symbols.

What happens when a character isn't covered by the fonts?

In this case, the browser will try to locate a font in your system that covers that character. This usually has some repercussions on the typesetting quality as MathJax needs to know the fonts to typeset.

Also, as author you can specify a fallback font, see our documentation

Clone this wiki locally