Skip to end of metadata
Go to start of metadata

Making LaTex support CJK (Chinese, Japanese, Korean) characters is always a pain process. When I used Ubuntu, I used CJK LaTex package. It needs to compile and install fonts (e.g. cyberbit) which is not a straightforward task. When I migrate to Mac OS X, I found a lot people recommend XeTex to deal with CJK documents which does not need to install fonts, instead it uses system fonts.

Here is a summary log about how I made XeTex work on Snow Leopard (precisely I used XeLaTex). I hope this can help the one who also need to use CJK characters in LaTex under Mac OS X.

  1. Install XeTex.
    XeTex is part of TexLive which is included in MacTex. A full installation of MacTex will have XeTex installed.
    Since MacTex is very big, sometimes the installation may failed and you do not know. I encountered a problem telling me that ifpdf.sty could not be found. I googled and found it belongs to oberdiek package. In the Tex Live Utility(Under Application->Tex folder) it shows oberdiek is installed but in detail info there are no files. By reinstalling the whole MacTex, I solved this problem.
  2. Write a small micro package to set the fonts. Save the following in zhfontcfg.sty in the folder where your tex files located.
    % xelatex 字体设定宏包(xelatex font settings for Chinese)
    % Tested under Mac OS X Snow Leopard(10.6.7) 
    \defaultfontfeatures{Mapping=tex-text} %如果没有它,会有一些 tex 特殊字符无法正常使用,比如连字符。
    % 中文断行(line break for Chinese)
    \XeTeXlinebreaklocale "zh"
    \XeTeXlinebreakskip = 0pt plus 1pt minus 0.1pt
    % You can use fc-list command to find what font are available in your system.
    \newcommand\fontnamehei{Heiti SC}
    \setmainfont{\fontnameroman} % set default font
    %\setmainfont[BoldFont=\fontnamehei]{\fontnamesong} %如果正文以中文为主,设置文档正文字体为宋体
    \newcommand{\song}[1]{{\SONG #1}}
    \newcommand{\kai}[1]{{\KAI #1}}
    \newcommand{\hei}[1]{{\HEI #1}}
    \newcommand{\en}[1]{\,{\ENF #1}\,}

    newfontinstance is deprecated


    Some posts on the Internet use \newfontinstance which is deprecated and will cause error; please use \newfontfamily or \newfontface instead.



    The package times or mathptmx will overwrite settings like \setmainfont in the zhfontcfg.sty, make sure load zhfontcfg after loading those packages.

    Use correct fonts in your system




    in shell to check what fonts are installed in your system and use them instead of the fonts I listed above("Heiti SC","STSong", and so on).

  3. Edit xelatexChineseTest.tex
    Hello world! 你好!(Default font)\\
    \song{Hello world! 你好!(宋体,Song)}\\
    \kai{Hello world! 你好!(楷体,Kai)}\\
    \hei{Hello world! 你好!(黑体,Hei)}\\
    \en{Hello world! (Roman)}\\
  4. Compile the tex file and see results.
     xelatex xelatexChineseTest.tex 
      File Modified
    May 28, 2011 by Shu, Anhei
    May 28, 2011 by Shu, Anhei
  • No labels