Computer Modern fonts in Mathematica on Mac OS X

by Sheehan Olver


This web site demonstrates how to use Computer Modern (henceforth CM) fonts in a Mathematica graphics object, such as the result of a Plot command. The primary use for this is so that the font of the figures in a paper is the same as the font in the body of the paper. The problem is that the standard CM fonts do not map characters consistently, and a single "font" is broken up into multiple font files. For example, the period "." character is not mapped to the period glyph location in the same font as the non-italic numerals. Though this instruction is targeted at Mac OS X, it should be possible to follow on any modern operating system.

  1. Download unicode versions of the CM fonts (henceforth CMU fonts). The CMU web site has information concerning how they constructed the fonts and what glyphs are not yet correctly in place. The key is that unicode fonts contain places for all the glyphs used in CM. Hence typing a "+" or "a" will always result in the "+" or "a" glyphs, respectively, appearing on screen.

  2. Install the fonts. I recommend using the program FontBook, and to put all the CMU fonts in a single Collection. To do this, in FontBook click the plus below the list of collections, call it something like "TeX", and drag and drop the fonts to the collection. Or alternatively one can install the fonts manually in either "/Library/Fonts" (so that every user on the computer has access) or "~/Library/Fonts" (so just one account has access).

  3. Find the postscript name of the font desired. FontBook shows this after selecting "Show Font Info" from the "Preview" menu. Some import examples are: "CMUSerif-Roman", which contains the non-italic alphabet (used in text mode) and numerals (used in both text mode and math mode); and "CMUSerif-Italic", which contains the italic alphabet (used in math mode) and numerals. Note that in order to simulate math mode it is required to use the roman font for the numerals and mathematical symbols and the italic font for letters.

  4. Instruct Mathematica to use the font. To set it as the default font in all figures use the following command:

    $TextStyle = {FontFamily -> "CMUSerif-Roman", FontSlant -> "Plain", FontSize -> 20}

    The axis numbering of any plots should now appear in CM. For math mode-like variables, it is required to wrap the variables in a StyleForm. For example, the plot at the top of this article was constructed using the following command:

    Plot[x^2, {x, 0, 1},PlotLabel -> StyleForm[x^y, FontFamily -> "CMUSerif-Italic", FontSlant -> "Plain", FontSize -> 20]]

  5. Export the graphic as an EPS. This is can be done in any standard manner. For example, select the graphic in the Mathematica frontend and choosing the "Edit" menu, then "Save Selection As...", then "EPS...".

  6. Convert the graphic to a PDF. Simply drag the the .eps file onto the Preview application, and save the result. This is required for using the graphic with "pdftex". Note that we have not installed the CMU fonts in a location recognized by unix programs, so "ghostscript" will not convert the EPS file using CMU fonts, and neither will the "tex" or "latex" commands. This surely can be remedied, however I have not attempted to do so.

There are a couple issues worth mentioning. First off is that Mathematica will only use the fonts for alphanumerics: mathematical symbols will still be in Mathematica's own font. This can be worked around by manually editing the .eps file and replacing all the instances of "/Mathematica1" with "/CMUSerif-Roman". This problem also exists for greek letters, however the solution is more difficult. The problem is Mathematica has a special greek font, where, for example, "w" is mapped to omega. As a result, the .eps file will have a "w" where the omega should be. Unfortunately, I have not figured out how to specify unicode indices in the .eps format, so the only solution is to use the original CM fonts and look up the mapping. Finally, the CMU fonts can be used in other applications as well. I have used the fonts in Keynote to simulate math mode. This allowed me to quickly do math mode for simple, in text, equations, and LaTeX Equation Editor for more complicated equations.