When it comes to Chinese characters, I am unable to get the Front End of Mathematica to use the fonts of my choice. How can I get it to use the fonts I need?
Here I provide two screenshots to show the problem, one from Word (top), the other from Mathematica on WinXP, both displaying the same string. Note that Mathematica uses several different fonts (I guess it uses font substitution when the font it tries to use first doesn't contain a glyph---however the font I specified contains all glyphs I need!). Here I use the font Microsoft YaHei, which comes with Win7, but is downloadable for XP too.
EDIT: Here's some test code:
str = "肖诮陗俏削帩消峭捎绡莦弰悄焇琑逍㲖㲵䏴哨娋宵屑綃梢痟睄筲艄萷销䇌䘯趙揱旓硝稍踃輎矟䌃箾蛸誚榍蕱銷鞘潲碿糏霄䴛韒髾鮹鞩魈颵"
Style[str, Large, FontFamily -> "SimSun"]
(SimSun comes with XP and should contain all these characters too, although not sure if in all versions.)
EDIT 2: I am on Windows XP (with East Asian language support enabled), I wonder if the results are different on other OSs.
Summary: It appears that the behaviour depends on the particular OS and the fonts installed, and unfortunately there seems to be no way to make the fonts uniform (even if there exists a single font containing all the glyphs).
It could be mathematica is replacing your Font-Family
setting with a neighbouring font. Running
Options[$FrontEnd, FontSubstitutions]
will give you the replacement list mathematica uses.
Font family names are not equivalent to system font files names. You can read those font names by the way below.
This is the easy way to get the right font family name is
- Firstly, type some text, e.g."我们", edit to your "target font" using the Mathematica menu.
- Secondly, add
//InputForm
. After running the cell, you will get the right font name. In my computer, the fontfamily name for "楷体" is "¿ [Not]Ìå_GB2312". Awesome.
For your first edit, some SimSun font may not cover enough CJK range (some of the characters in str belong to CJK Unified Ideographs Extension A). There is a wonderful site summarized the covering ranges of many East Asian Unicode fonts.
For your second edit, I think maybe you would like to use
"\[CapitalIHat]\[Cent]\[CapitalEGrave]\[IAcute]\[CapitalNTilde]\[CapitalARing]\.ba\[CapitalUAcute]"
as the FontFamily, which is actually a Unicode representation of the fontname's ChineseSimplified version:
FromCharacterCode[ToCharacterCode["微软雅黑", "CP936"]]
It works fine for on my Windows 7 English version.
And I think, at least for English version Mathematica, the FrontEnd always tries to interpret a CJK character as a Japanese character first, if failed (which means the character does not appear in the # Japanese section of UnicodeLanguageFontMapping.tr), lookup the # Chinese simplified section. Then the default fonts for different languages are defined in UnicodeFontMapping.tr(there is even a Klingon entry LOL), which links to @JohnFultz 's suggestion.