Wiki: TeXLive 2007 CJK Chinese Howto(zz)

Reference from Yue Wang(yulewang \at gmail \dot com)


In TeXLive 2007, there is no need to use CJK package anymore, XeTeX is good enough to handle Chinese and Open/TrueType fonts. and the key problem of XeTeX, i.e. the font switching problem, is tend to be fixed in the next release of XeTeX. But many old documents are written using macropackages/styles based on CJK or CCT, some of them are still widely used today, so, in some cases it is essential to install these fonts.

Install TeXLive

First, install TeXLive.

mount -o loop texlive2007-live-20070212.iso /mnt
cd /mnt
sudo ./install-tl

press I to install.

Setup System Path

Set the path. Take debian GNU/Linux as example, modify your /etc/environment like this and make a reboot:


Copy The Files Needed

make a dir called font, copy the font here.

mkdir ~/font
cd ~/font
cp /media/sda/windows/Fonts/simhei.ttf .

copy all the files needed.

sudo apt-get install fontforge
cp /usr/local/texlive/2007/texmf-dist/source/latex/CJK/utils/subfonts/* ~/font/
cp /usr/local/texlive/2007/texmf/fonts/sfd/*.sfd ~/font/

Generate Font

Then, make the font. It is a good way to test how fast your computer is :) it takes me 3 minutes to generate the fonts[Core Duo 2].

Some one complain that the procedure take them 1 hours to do so, this is because you use the new version of fontforge. so be sure to use fontforge 2005.

time fontforge -script simhei.ttf hei Unicode.sfd

create a file name makemap like this:

for i in *.tfm
cat >> << EOF
${i%.tfm} ${i%.tfm} < ${i%.tfm}.pfb

Make map file:

chmod +x makemap

create a file name c70hei.fd for CJK package:

% This is c70hei.fd for CJK package.
% created by Edward G.J. Lee
% modify by Yue Wang
\DeclareFontFamily{C70}{hei}{\hyphenchar \font\m@ne}
\DeclareFontShape{C70}{hei}{m}{n}{<-> CJK * hei}{}
\DeclareFontShape{C70}{hei}{bx}{n}{<-> CJKb * hei}{\CJKbold}

Copy Fonts into TEXMF

create the local directory to save the font

cd ~/.texlive2007
cd texmf-var
mkdir -p fonts/map/dvips/CJK
mkdir -p fonts/tfm/CJK/hei
mkdir -p fonts/type1/CJK/hei
mkdir -p tex/latex/CJK/UTF8
cp ~/font/ fonts/map/dvips/CJK/
cp ~/font/*.tfm fonts/tfm/CJK/hei
cp ~/font/*.pfb fonts/type1/CJK/hei
cp ~/font/c70hei.fd tex/latex/CJK/UTF8

Update The System and Test

Just run:
updmap --enable Map

create a test file to test your work.

latex test.tex
xdvi test.dvi
dvipdfm test.dvi
xpdf test.pdf
pdflatex test.pdf

Virtual GBK Font(Not Essential)

The main goal of virtual fonts is to make one font for various encoding systems. We still take simhei as an example to tell the reader how to create one UTF8 font for UTF8 and GBK encodings.

First, Let's suggest that you have finished the task of creating a utf8 heiti font for LaTeX and you are still in the ~/font directory with all the fonts and scripts undeleted. you also copy all the utf8 fonts into your ~/.texlive2007 directory and they are working with no problem.

run these commands. if you do not delete something , *.tfm and are still in your ~/font dir.

perl hei UGBK.sfd gbkhei gbk
mkdir ~/.texlive2007/texmf-var/fonts/tfm/CJK/gbkhei
mv gbkhei*.tfm ~/.texlive2007/texmf-var/fonts/tfm/CJK/gbkhei
mkdir ~/.texlive2007/texmf-var/fonts/vf
mv gbkhei*.vf ~/.texlive2007/texmf-var/fonts/vf
mkdir ~/.texlive2007/texmf-var/tex/latex/CJK/GBK

create a file named c19hei.fd just like the c70hei.fd in ~/.texlive2007/texmf-var/tex/latex/CJK/GBK

% This is c19hei.fd for CJK package.
% created by Edward G.J. Lee
\DeclareFontFamily{C19}{hei}{\hyphenchar \font\m@ne}
\DeclareFontShape{C19}{hei}{m}{n}{<-> CJK * gbkhei}{}
\DeclareFontShape{C19}{hei}{bx}{n}{<-> CJKb * gbkhei}{\CJKbold}

make a test file in GBK encoding like this:


if you are lucky, you will get the good outputs without problem (no texhash or updmap needed)

Use ttf directedly in pdftex/dvipdfmx[not recommended]

Well, our pdflatex/dvipdfmx can also use ttf directedly.
create ~/.texlive2007/texmf-var/fonts/map/dvipdfm/

gbkhei@UGBK@ UniGB-UCS2-H :0:simhei.ttf
hei@Unicode@ unicode :0:simhei.ttf

move the font simhei.ttf to the truetype directory:

mkdir ~/.texlive2007/texmf-var/fonts/truetype
cp simhei.tff ~/.texlive2007/texmf-var/fonts/truetype

create the map generating file makemap-enc

for i in hei*.tfm
cat >> << EOF
${i%.tfm} < ${i%.tfm}.enc < simhei.ttf

generate the map:

chmod +x makemap-enc

copy all the file needed

cp ~/.texlive2007/texmf-var/fonts/map/pdftex/CJK/
mkdir -p ~/.texlive2007/texmf-var/fonts/enc/CJK/hei
cp hei*.enc ~/.texlive2007/texmf-var/fonts/enc/CJK/hei

copy the adobe font:

sudo mkdir ~/.texlive2007/texmf-var/fonts/cmap
sudo apt-get install cmap-adobe-*
cp -a /usr/share/fonts/cmap/* ~/.texlive2007/texmf-var/fonts/cmap

test that it works:

  • The UTF8 encoding test file:
  • The GBK encoding test file(save it in gbk first!):

Install Ctex macro package

There are two versions of ctex macro package, one for GBK and one for UTF-8.
First, be sure to install all the chinese fonts using simsun.ttf(If you use
simsun.ttc, break it) simhei.ttf, simli.ttf, simkai.ttf, simfang.ttf,
simyou.ttf just follow the example of simhei before.

then, copy all the macropackages in Liangzi's CTeXLive-2005

sudo mount -o loop CTeXLive2005 /mnt
cp -a /mnt/2005/texmf-local/tex/latex/ctex ~/.texlive2007/texmf-var/tex/latex
cp -a /mnt/2005/texmf-local/tex/latex/ctexutf8
cp -a /mnt/2005/texmf-local/tex/latex/ccmap ~/.texlive2007/texmf-var/tex/latex

modify all the fd files there.
for those fd file in ctexutf8 directory, use song,fang ... instead of unisong,
unifang, unisongsl,unifangsl....., for those fd files in ctex directory, use
gbksong instead of gbksongsl, gbkfang instead of gbkfangsl....
And dont use \CJKbold , use hei instead.

an example file should like:

  • in utf8 directory
    [2006/06/09 v0.8 ctex
    font definition file]
    \DeclareFontFamily{C70}{rm}{\hyphenchar \font\m@ne}
    \DeclareFontShape{C70}{rm}{m}{n}{<-> CJK * song}{}
    \DeclareFontShape{C70}{rm}{bx}{n}{<-> CJK * hei}{}
    \DeclareFontShape{C70}{rm}{m}{sl}{<-> CJK * song}{}
  • in ctex directory
    [2006/06/09 v0.8 ctex
    font definition file]
    \DeclareFontFamily{C19}{sf}{\hyphenchar \font\m@ne}
    \DeclareFontShape{C19}{sf}{m}{n}{<-> CJK * gbkyou}{}
    \DeclareFontShape{C19}{sf}{bx}{n}{<-> CJKb * gbkhei}{}
    \DeclareFontShape{C19}{sf}{m}{sl}{<-> CJK * gbkyou}{}
    \DeclareFontShape{C19}{sf}{bx}{sl}{<-> CJKb * gbkhei}{}
    \DeclareFontShape{C19}{sf}{m}{it}{<-> CJK * gbkyou}{}
    \DeclareFontShape{C19}{sf}{bx}{it}{<-> CJKb * gbkhei}{}

Last,run texhash and test the files.

  • Utf8 test file
  • GBK test file