9
$\begingroup$

I've just started using Mathematica 10 on Linux and have immediately run into problems with the fonts. Fonts on Linux are always a headache, but I had managed to find a reasonable one in "Century Schoolbook L". However, in Mathematica 10, this font and many others are being displayed with incorrect special characters and punctuation.

It seems like Mathematica is trying to assign sans-serif default (that is, not appearing in the font specified) characters when it needs to be using serif.

I have tried messing with "OperatorSubstitution" and "FontSerifed". The former can change the parentheses, but neither affects the Greek. My only current recourse is to select one of the fonts that (seemingly randomly) does not suffer this problem; "Linux Libertine O", for example.

Is this a bug? Is there a workaround?

Example of problematic text; note the Greek and parentheses

$\endgroup$
1
  • $\begingroup$ not so relevant but I have found using LaTeX fonts in Mathematica to be useful. So that when writing papers using LaTeX, your figure captions has exactly the same font (latin modern roman, which is sans-serif font). $\endgroup$
    – Yi Wang
    Commented Jul 24, 2014 at 17:27

3 Answers 3

8
$\begingroup$

The answer to this question is inspired by @DBM answering on a related issue: How to write plain Greek in a text cell

I had a similiar problem, in summary:

  1. I use Style["Some text with greek letters", FontFamily->"Some font, which includes greek letters"] and export it in pdf.
  2. As the result the greek letters are shown with Mathematica font, and the rest with the chosen font.
  3. Hence Mathematica replaces greek letters automatically into Mathematica font.

Not always a desired behaviour.

Moreover, since version 10: 1) PDF export has improved significantly, but 2) Internal fonts and encodings are stored differently.

Solution:

  1. Find the file called FontMap.tr In linux I have it in "/usr/local/Wolfram/Mathematica/10.0/SystemFiles/FrontEnd/TextResources/FontMap.tr" , in Mac OS @DBM had it in "/Applications/Mathematica.app/FontMap.tr", and in Windows it is probably in the installation folder. Make a backup copy of it, e.g. FontMapBACKUP.tr

  2. Open the file in a text editor. It contains the string CompressedData["Lots of weird characters"].

  3. Open mathematica and define FontMap=Uncompress["Lots of weird characters"] . I.e. copy-paste the string and run Uncompress on it.

  4. FontMap[[1,2]] contains character codes of the symbols, which will be replaced into Mathematica font. You can see, what characters are they exactly by running ReplacedCharacters = FromCharacterCode[#] & /@ FontMap[[1, 2]] . Furthermore, you can check, what do character codes signify by looking at http://reference.wolfram.com/language/tutorial/CharacterCodes.html .

  5. For Mathematica not to replace the characters you like, you need to remove them from the list in FontMap. For example, I want Mathematica to replace only the characters which are not unicode characters. This means I should keep the characters with the code larger than 59391 (see the character codes web page): FontMap[[1, 2]] = Cases[FontMap[[1, 2]], x_ /; 59391 < x] . Now greek letters and other unicode symbols do not get replaced.

  6. Call Compress[FontMap] , this will produce "Lots of new weird characters". Replace "Lots of weird characters" by "Lots of new weird characters" in FontMap.tr file. Restart Mathematica.

Done, now the fonts should look as they should!

Disclaimer: The above, however, solves my problem but not yours. It seems like the font you were using does not contain greek letters as a part of it. To see, which available fonts contain greek letters at all, one can go to Format-> Font and choose writing system to be Greek. The listed fonts are the ones, which include greek symbols.

$\endgroup$
5
  • $\begingroup$ It worked perfectly Alexey. A million thanks. It was driving me crazy. $\endgroup$
    – stathisk
    Commented Nov 2, 2014 at 3:06
  • $\begingroup$ @Zet: Actually, I had very similar feelings here :) $\endgroup$ Commented Nov 2, 2014 at 10:37
  • $\begingroup$ +1. Nice. Thanks to your explanations I automated the fix for this answer $\endgroup$
    – SquareOne
    Commented Sep 30, 2015 at 17:47
  • $\begingroup$ In this answer, on running step 4, does that assume that a bunch of Greek letters show up as part of the output? On my system (v10.4 over Ubuntu 15.10) there is only a smattering, even inside FromCharacterCode[#] & /@Cases[FontMap[[1, 2]], x_ /; 59391 > x]. $\endgroup$ Commented Jun 9, 2016 at 13:07
  • $\begingroup$ Yes, should come up as a part of the output. More specifically, the replaced greek letters are at "FromCharacterCode[#] & /@ Cases[FontMap[[1, 2]], x_ /; 913 <= x <= 1009]". I checked it on by v 10.4 over Ubuntu 16.04. $\endgroup$ Commented Jun 9, 2016 at 16:58
4
$\begingroup$

Just for reference, let me post about what I do here as well.

I'm using Mathematica 10.0.1 for Mac. FontMap.tr is located at /Applications/Mathematica.app/Contents/SystemFiles/FrontEnd/TextResources.

Step 5 of Alexey's solution doesn't work for me. I have to remove FontMap[[3, 2]] instead:

FontMap[[3, 2]] = {}

And instead of removing all parts of FontMap[[1, 2]] whose values are less than 59391, I only remove the first 37 entries:

FontMap[[1, 2]] = Drop[FontMap[[1, 2]], 37]

to use my own typeface for the following common characters:

Common Characters

For some reason renaming the file to FontMap-backup.tr doesn't work. I use FontMap.trbackup instead.

$\endgroup$
2
  • $\begingroup$ Thanks for this. Alexey's solution didn't work for me until I implemented your suggestions. $\endgroup$
    – Jim Belk
    Commented Sep 11, 2015 at 3:07
  • $\begingroup$ You're welcome. $\endgroup$
    – Taiki
    Commented Sep 11, 2015 at 11:52
2
$\begingroup$

Mathematica 10.0.1 makes this issue worse by eliminating altogether the Serif Mathematica font. My notebooks now have Sans symbols by default or, using the strategy suggested by Alexey Bobrick and modifying FontMap.tr, some symbols like [Phi] or [CurlyTheta] appear as small rectangles even if I use a Serif font that has greek symbols.

This, I think, is a regression of the FrontEnd editing capabilities. I even tried replacing the new 10.0.1 Fonts with the 10.0 version, but it doesn't make a difference, so it seems that the Mathematica/MathematicaSans fonts are embedded in the executable FE code.

  • Mathematica 10.0 with original FontMap.tr

Mathematica 10.0 with original FontMap.tr

  • Mathematica 10.0 with new FontMap.tr

Mathematica 10.0 with new FontMap.tr

  • Mathematica 10.0.1 with original/new FontMap.tr

Mathematica 10.0.1 with original/new FontMap.tr

$\endgroup$
1
  • $\begingroup$ One way not to get greek symbols while controlling them is to actually modify Fonts.tr in such a way that greek symbols are substituded by a preferred font. This is in complete analogy to how back in the past one had to modify Unicode.tr, I believe. $\endgroup$ Commented Oct 7, 2014 at 13:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.