Random Tech Thoughts

The title above is not random

LaTeX and CJK, How to Use the TrueType Fonts

First I should tell you that I am using teTeX 3.0 and I am not sure whether the steps I discribed below works for other TeX distribution. You may change something to get things work correct.

  1. Get the TrueType fonts.(May be you have done this.) This shouldn’t be difficult. You can find some free TT fonts on CTAN. One thing should be noticed is that if you want to get Unicode support, you should get the Cyberbit.ttf(it’s free, more details about Unicode and CJK, click here, I didn’t use it since it’s a little troublesome, when needed I use iconv to convert).

  2. Download gbkfonts.(Other versions, see here, thanks to the authors) I think it should also be able to work on other TT fonts other than Chinese TT fonts. I didn’t test it. If it doesn’t work on other TT fonts like Korean, Japanese TT fonts, you may have to use ttf2afm and some other programs. Read the pdfTeX manual for details.

  3. Uncompress gbkfonts you just downloaded. Copy the file “go“, “gbkfonts-glibc” to /usr/local/bin, change the file name “gbkfonts-glibc” to “gbkfonts“. Edit the script go, find these lines like “gbkfonts ${opts[*]} $dir/FZSongTi.ttf song“, change it to the fonts name you want use. Then “cd /usr/local/share/texmf”(if you run the program in your locale texmf directory, you need to move less files later), type “go yourfonts directory“(need to have the write right in this directory), wait… and the program will create the afm, tfm, type1, enc files and some other configuration files for divpdfm, pdftex and dvips.

ADDED ON JULY 31st, 2006.

I installed TeXLive on Arch and reinstalled the CJK fonts. This time I find that in teTeX 3.0 the map files should be put in TEXMF/fonts/map, while enc files should also put in TEXMF/fonts/enc, so what I’ve written in the past is right though I don’t know this yet at that time. Maybe I’ve read the texmf.cnf that time so I know where to put these files. I can’t remeber now.

gbkfonts shoud be modified to accomadate these changes. May be I can have a try?

ADDED ON DEC 11st, 2006. Other people have already noted this long time before, why didn’t I found these articles at that time? Wast so many time on this problem … :–( A summary for font path change in teTeX 3.0

dvipdfm/config/*.map –> fonts/map/dvipdfm/*.map dvips/cjk.map –> fonts/map/dvips/cjk.map pdftex/config/*.map –> fonts/map/pdftex/*.map ttf2pk/ttfonts.map –> fonts/map/ttf2pk/ttfonts.map dvips/chinese/*/*.enc –> fonts/enc/dvips/chinese/*/*.enc pdftex/enc/* –> fonts/enc/pdftex/*

See 何勃亮’s website for more information. He also have modified gbkfonts to accormodate these changes and simplify the procedure for generating files needed to use with CJK. I’ve visited 薛瑞妮’s website many times but ignored things about teTeX 3.0 … You will also find some information there.

  1. Some articles talking about using CJK and TrueType fonts stops here. Of course you need “mktexlsr”, but things just don’t work on my system. You can now make some test, if things don’t work, read on. Below are additional steps I did on my system to get things work. I had a look at my texmf.cfg(in TEXMF/web2c, you may need to change the variable TEXMF to let TeX search local TEXMF first) and check out some path on my TeX system. Then first create the map files directory: “mkdir /usr/local/texmf/fonts/map/{dvips,dvipdfm,pdftex}”(using bash), mv all the map files gbkfonts created to the corresponding direcrory. Then create the enc files directory “mkdir /usr/local/texmf/fonts/enc/dvips“, mv the directory which contains enc files in the directory “dvips” just created here. You should keep the directory structure and TeX will search these directories recursively.

  2. If you use “updmap” to mantain the font map information, I suggest you just add one line in updmap.cfg(also in TEXMF/web2c) “Map cjk.map“. Run “mktexlsr”(If you don’t run this, updmap will not find the map file you just created) and then “updmap” to update the font map information. You can have a look at cjk.map, it contains a lot of lines ending with *.pfb, so this is in fact using Type1 fonts gbkfonts just created.( In Type1 directory. ) dvipdfm, dvips and pdftex all supports Type1 fonts, this works well. You should be able to get things works correctly now. Make some test?

ADDED ON JULY 31st, 2006. For dvipdfmx to use TT fonts directory, add “f cid-x.map” in TEXMF/dvipdfm/dvipdfmx.cfg. The cid-x.map is created by gbkfonts. If you use other map files created be gbkfonts in the dvipdfm directory, dvipdfmx still can’t create pdf files that support searching Chinese.

One more thing is that dvipdfm and dvips do read the map files specified in the config file. ( TEXMF/dvipdfm/config/config and TEXMF/dvips/config/config.ps respectfully.) But I don’t know which is the config file for pdftex, so to make pdftex use the TT fonts or Type 1 fonts, you still need to append the map file to pdftex.map manually. For dvipdfm and dvips, you can just add some line to the config file to tell the program to include the map file.

  1. But there is still some problem. I use dvipdfmx to create pdf files which can be searched even it contains CJK fonts, but it should be configured to use TT fonts directly. The problem with updmap is that it updates font map information for the three program at the same time using the same map files :–( That’s not what I wanted, but I am not able to modify the script now so I use the stupid method—add font map manully. “cd /var/lib/texmf/fonts/map”, keep dvipdfm untouched. “cd to dvips/updmap“, append cjk.map to psfonts_t1.map.(the file which symbolic link psfonts.map points to) Then “cd pdftex/updmap”, append all the map files in the directory pdftex which was created by gbkfonts to pdftex.map.(this is also a symbolic link, you can directly edit the file it points to) For dvipdfm(x), you just need to mv cid.map and some other map files created by gbkfonts to /usr/local/share/texmf/fonts/map/dvipdfm. Then dvipdfm(x) and pdftex will both use TT fonts directly, while dvips uses Type1 fonts. That’s all.

So many words… I do think these artiles stops at step 3 are right, and I don’t need to write so many words. I don’t know why :–( After running gbkfonts we get the map files and the configuration files, if pdftex and dvips read these configuration files, then we can just stop at step 3. But I didn’t find pdftex.cfg in /usr/share/texmf/pdftex/config, in fact there is no such directory at all! So I wonder whether pdftex read the configuration file.(This seems not likely to happen, but the brutal fact makes me think so) There is the file config.ps in /usr/share/texmf/dvips/config, but it also seems that dvips also didn’t read it because unless I manully add cjk.map to psfonts_t1.map it won’t wok, though I have added “p +cjk.map” in config.ps. But it’s strange thar dvipdfm(x) read the configuration files since I keep it’s font map files in /var/lib… untouched. I will ask for help about this problem later. It is very likely that it is because I made some mistakes. If you know, please tell me, I do appreciate!