The standard CJK package only provides 2 fonts for simplified Chinese, as described here.
My question is how to create more fonts for it? I'm using MacTeX 2013 and UTF8 + CJK + pdflatex is the expected environment.
There should be a way to convert fonts from, say ttf
, to fonts TeX could handle.
Best Answer
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 readtfm
files; in XeTeX, it can read TrueType, AAT or OpenType font files; in LuaTeX,\font
can only readtfm
files too, however, having a build-in library namedcallback
, 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 atfm
font to a Type1 or TrueType font.\pdfmapline
: Taken as an example,\pdfmapline{cmr10 CMR10 <cmr10.pfb}
will embedcmr10.pfb
into the PDF file if someone is trying to usecmr10.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 packagefontspec
(under XeTeX and LuaTeX, see here).Package
xeCJK
(with XeTeX) and packageLuaTeX-ja
(with LuaTeX, see here) extend the functionality offontspec
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 packagexeCJK
or use LuaTeX with the packageLuaTeX-ja
.Using the engine TeX/pdfTeX (original LaTeX and pdfLaTeX)
The
CJK
packageThe 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?
When TeX is reading
\begin{CJK}{GBK}{song}
, it will loadUGBK.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 is0xBABA
, and '字' isOxD7D6
.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 inCJK
means GBK):Note that, in extended ASCII,
╟
is 199 andi
is 105.\C19/song/m/n/10/
means GBK encoding, font namesong
, (m)edium (not blod) and upright (not italic).In
C19song.fd
(fd is short for 'font description'), you can see:Consequently,
\C19/song/m/n/10/43 ╟\C19/song/m/n/10/65 i
will set: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 xptao@bbs.ctex.org.
The
zhmCJK
packageSee here, by LeoLiu.
Using the engine XeTeX
Warning: The following text described how to use XeLaTeX with package
xeCJK
andctex
, 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, andctex
(case sensitive) package/documentclass settled the last one perfectly.XeLaTeX with
xeCJK
Follow these steps to get correct output:
fc-list :lang=zh-cn
(orfc-list :lang=zh-tw
if you are in Taiwan).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.<file name>
into\setCJKmainfont{<file name>}
(case sensitive, see example below).main.tex
', and then, compile it usingXeLaTeX
byxelatex main.tex
.Example:
This is the output:
Tips:
~
between CJK character and western character to regulate the space between them, as you always did inCJK/CJKutf8
.Undefined control sequence
error will be reported.ctex
package/documentclassThis 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.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):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.pdfThe package
xeCJK
: http://texdoc.net/texmf-dist/doc/xelatex/xecjk/xeCJK.pdfThe package/documentclass
ctex
: http://texdoc.net/texmf-dist/doc/latex/ctex/ctex.pdf