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 xptao@bbs.ctex.org.
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:
- Open system terminal and type
fc-list :lang=zh-cn
(or fc-list :lang=zh-tw
if you are in Taiwan).
- 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.
- Select one font, and put its
<file name>
into \setCJKmainfont{<file name>}
(case sensitive, see example below).
- 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:
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
ctex
bundle use Chinese fonts for Windows by default. You can use the fonts installed in Mac.
% !TEX program = XeLaTeX
% !TEX encoding = UTF-8
\documentclass[UTF8,nofonts]{ctexart}
\setCJKmainfont[BoldFont=STHeiti,ItalicFont=STKaiti]{STSong}
\setCJKsansfont[BoldFont=STHeiti]{STXihei}
\setCJKmonofont{STFangsong}
\begin{document}
文章内容。
\end{document}
There is nothing much to summerize, just change the fonts following the xeCJK
manual. On Mac OS X, STSong
and other SinoType fonts are preinstlled.
Alternatively, you can also use free Fandol fonts for Chinese documents, which are preinstlled in latest TeX Live (MacTeX).
% !TEX program = XeLaTeX
% !TEX encoding = UTF-8
\documentclass[UTF8,nofonts]{ctexart}
\setCJKmainfont[BoldFont=FandolSong-Bold.otf,ItalicFont=FandolKai-Regular.otf]{FandolSong-Regular.otf}
\setCJKsansfont[BoldFont=FandolHei-Bold.otf]{FandolHei-Regular.otf}
\setCJKmonofont{FandolFang-Regular.otf}
\begin{document}
文章内容。
\end{document}
We plan to release a new version of ctex
bundle later this year, which provides more font sets for those Mac OS X and Linux users.
Best Answer
Portable, and consistent solution
Fandol fonts are not perfect: compared to the other commercial fonts, the character set of Fandol fonts is somewhat restricted, and the puncuations need to be tuned.
Luckily, Fandol is a complete series of Chinese fonts in OpenType format, and well designed for typesetting.
The problem is, most Chinese fonts are expensive commercial ones, you simply have little choice for free Chinese fonts. And what's more, Fandol font bundle is the only choice preinstalled in TeX Live (or MacTeX, MiKTeX) if you use XeTeX or LuaTeX. Therefore, it is now the only portable way to typesetting Simplified Chinese documents in TeX.
Yes there are also Arphic fonts, but only subfonts for
CJK
package in Type1 format are provided in TeX distributions. Only two families (gbsn
andgkai
) for Simplified Chinese, or two corresponding families (bsmi
andbkai
) for Traditional Chinese are provided by Arphic.Some sort of fallback option for rare glyphs?
No. We don't have enough fonts available for that.
Now we have some good free fonts for large character sets. For example the Souce Han Sans fonts. But they are pre-installed neither in TeX distributions, nor in operation systems.
Something native?
Yes it is possible. In the developer version (ver 2.x) of
ctex
package, we defined several different font sets, and the package will detect the operation system and select a native font set if you wish.And we do provide options to select Arphic and WenQuanYi fonts (
fontset=ubuntu
option), there are also options for Adobe fonts and Founder fonts.