How can i use fonts other than gbsn/gkai for CJK Chinese?

Control sequences and packages about font

(plain) TeX level control sequences about font

There are several control sequences (or say command) about font in the original TeX (TeX primitive and/or plain TeX level command).

  • \/, can be used to regulate the space after italic characters (see the difference between {\itshape italic} normal and {\itshape italic}\/ normal in LaTeX).
  • \font is the original command to call a font. In TeX and pdfTeX, \font can only read tfm files; in XeTeX, it can read TrueType, AAT or OpenType font files; in LuaTeX, \font can only read tfm files too, however, having a build-in library named callback, LuaTeX could use as many kinds of font files as XeTeX does.
  • \fam can be used to define math fonts. In original TeX, only 16 kinds of math font can be defined (no limit in XeTeX).
  • \fontname will return the name of font.
  • \nullfont provides a font has no character.

pdfTeX and LuaTeX can generate PDF file directly, by using pre-defined pdfTeX.map who map a tfm font to a Type1 or TrueType font.

  • \pdfmapline: Taken as an example, \pdfmapline{cmr10 CMR10 <cmr10.pfb} will embed cmr10.pfb into the PDF file if someone is trying to use cmr10.tfm.
  • \pdfpkresolution: If there is no .pfb file, .pk file comes to be an alternative. This command is designed to tune the resolution ratio of PK font.

LaTeX and NFSS

NFSS is short for 'New Font Selection Scheme' (see here). For the reason that the seven control sequences are quite boring for user, NFSS define five features of font---encoding,family,series,shape and size. Indeed, macros of NFSS use those seven commands as basement.

Although NFSS provides an easier way for users to select font, using NFSS directly could be labeled as obscurity. Another disadvantage of NFSS is that NFSS is designed for western chars.

Packages

Fortunately, we have package osf (ConTeXt style like, see here) and package fontspec (under XeTeX and LuaTeX, see here).

Package xeCJK (with XeTeX) and package LuaTeX-ja (with LuaTeX, see here) extend the functionality of fontspec and handle prohibitions and punctuation compression better.

Since the process of setting up fonts for the package CJK/CJKutf8 is VERY tedious, I strongly recommend you to use XeTeX with the package xeCJK or use LuaTeX with the package LuaTeX-ja.


Using the engine TeX/pdfTeX (original LaTeX and pdfLaTeX)

The CJK package

The 8-bits TeX system suppose that only 256 (2**8) kinds of char would be contained in a .tex file. As a result, the .tfm font file can have no more than 256 chars. Now, something bad happened---how can an Aisa chars set who, you know, has much more chars, be included in such a file!

Pioneers of TeX divided an Aisa chars set and encoding table into many partitions, and each of them has only 256 chars. Consequently, every index of a single char has two parts: the first part let TeX know which partition should be loaded, and the second part tells TeX the index of the specific char in that partition. And this is what CJK did.

The process

When you are compiling the following code, what will happen?

\documentclass{article}
\usepackage{CJK}

\begin{document}
\begin{CJK}{GBK}{song}
汉字
\end{CJK}
\end{document}

When TeX is reading \begin{CJK}{GBK}{song}, it will load UGBK.sfg. UGBK.sfg gives the correspondence of Unicode and GBK, since most Chinese fonts use Unicode inside.

Now, TeX meets '汉字'. These two chars in CJK are \CJKchar[GBK]{"BA}{"BA}\CJKchar[GBK]{"D7}{"D6}. Here '汉' in GBK is 0xBABA, and '字' is OxD7D6.

When TeX meets \end{CJK}, it will read UGBK.sfg and find that '汉' is in the 43rd partition (#199), say subfont, and '字' is in the 65th partition (#105). As a result, '汉字' will be converted to (C19 in CJK means GBK):

\C19/song/m/n/10/43 ╟\C19/song/m/n/10/65 i

Note that, in extended ASCII, is 199 and i is 105. \C19/song/m/n/10/ means GBK encoding, font name song, (m)edium (not blod) and upright (not italic).

In C19song.fd (fd is short for 'font description'), you can see:

\DeclareFontShape{C19}{song}{m}{n}{<-> CJK * gbksong}{}

Consequently, \C19/song/m/n/10/43 ╟\C19/song/m/n/10/65 i will set:

{\font\1="gbksong43"\1\char199}{\font\1="gbksong65"\1\char105}

Files

  • .sfg: Give the correspondence of two encoding.
  • .fd: Declare which font should be used.
  • .tfm: Define the abstract part, such as ligature and kern, of a font.
  • .pk: Define the graphic part, the glyph of a font.
  • .map: Font mapping.
  • .pfb: Type1 font style's file.

If you want to use CJK/CJKutf8, you have to generated/copy SOOOOOOOOOO many kinds of file. So, again, do not use it.

Install new font

See here, by [email protected].

The zhmCJK package

See here, by LeoLiu.


Using the engine XeTeX

Warning: The following text described how to use XeLaTeX with package xeCJK and ctex, as the OP asked me to do, however, it is a little offtopic.

The job typesetting an article or book with Chinese characters can be splitted into three parts---select font, handle prohibitions and layout style. XeLaTeX with the package xeCJK solved the first two parts, and ctex (case sensitive) package/documentclass settled the last one perfectly.

XeLaTeX with xeCJK

Follow these steps to get correct output:

  1. Open system terminal and type fc-list :lang=zh-cn (or fc-list :lang=zh-tw if you are in Taiwan).
  2. One line of that result may look like: C:/WINDOWS/fonts/SIMLI.TTF: LiSu,隶书:style=Regular---separated by two colons into three parts. While the first part shows where you can find the specific font file, the second part shows <file name> (partitioned by comma(s)), and the last one tells you font style.
  3. Select one font, and put its <file name> into \setCJKmainfont{<file name>} (case sensitive, see example below).
  4. Save it as encoding UTF-8 with filename 'main.tex', and then, compile it using XeLaTeX by xelatex main.tex.

Example:

%!TEX program = xelatex
\documentclass{article}
\usepackage{metalogo} % for the logo of XeLaTeX
\usepackage{showframe} % for showing page frames
\usepackage{xeCJK}
\setCJKmainfont{LiSu}
\begin{document}
这里是中文,这是隶书。我在使用\XeLaTeX 结合xeCJK排版中文。
\end{document}

This is the output: enter image description here

Tips:

  • You do not need to add ~ between CJK character and western character to regulate the space between them, as you always did in CJK/CJKutf8.
  • With the engine XeTeX, CJK character can be used as a command, so you must leave a space after any command, if it is followed by any CJK character, or an Undefined control sequence error will be reported.

ctex package/documentclass

This package provides you features, such as set \parindent to EXACTLY two times of the width of Chinese character (2\ccwd), to simplify your layout settings. See its documentation of the latest version.

This package set SimSun/KaiTi, provided by china-e(中易中标电子信息技术有限公司), as default fonts for user in China mainland, using Windows OS, CN-Simp version. If you have installed these fonts correctly, typesetting Chinese becomes quite easily.

%!TEX program = xelatex
\documentclass[UTF8]{ctexart} % instead of `article'
% `ctexbook' for `book', and `ctexrep' for `report'
\begin{document}
这里是中文。\\
段首缩进两个字符宽度。

这里是默认字体,中易宋体。\textit{这里是楷书},\texttt{还有仿宋}。
\end{document}

If you do not have these fonts, using the nofonts option and selecting fonts manually will be a good choice. Here's a example (without text body):

%!TEX program = xelatex
\documentclass[UTF8, nofonts]{ctexart} 
% select fonts for western chars
\setmainfont{Minion Pro}
\setsansfont{Myriad Pro}
% select fonts for CJK chars
\setCJKmainfont[BoldFont={Adobe Heiti Std},ItalicFont={华文楷体}]
  {华文中宋}
\setCJKsansfont{Adobe Heiti Std}
\setCJKmonofont{华文仿宋}

For more information about this issue, see here.

Documentations online

The package fontspec (xeCJK is based on it): http://texdoc.net/texmf-dist/doc/latex/fontspec/fontspec.pdf

The package xeCJK: http://texdoc.net/texmf-dist/doc/xelatex/xecjk/xeCJK.pdf

The package/documentclass ctex: http://texdoc.net/texmf-dist/doc/latex/ctex/ctex.pdf


The easiest solution for you, I guess, is to copy the Windows Chinese fonts

simsun.ttc
simfang.ttf
simkai.ttf
simhei.ttf
simli.ttf  (optional)
simyou.ttf (optional)

to the working directory (if you have bought a Windows copy), and use:

% Compile with pdflatex or latex+dvipdfmx
\documentclass{article}

\usepackage{CJKutf8}
\usepackage{CJKspace}

% for font mapping
\usepackage{atbegshi}
\AtBeginShipoutFirst{\input{zhwinfonts}}

\begin{document}
\begin{CJK*}{UTF8}{zhsong}

中文排版。

\clearpage\end{CJK*}
\end{document}

If you don't have a Windows copy, you may need to use some other Chinese fonts in TrueType format. However, the SinoType (华文) fonts preinstalled in Mac OS X cannot be used. See https://code.google.com/p/ctex-kit/issues/detail?id=81

Tags:

Fonts

Unicode

Cjk