Setting up CJK-LaTeX on Linux


CJK-LaTeX is a LaTeX package which enables LaTeX typesetting Chinese, Japanese and Korean without running any external programs. The latest version is 4.2.0. The package and CJK fonts can be downloaded at any CTAN repository. The document coming with the package isn't up to date. Although the installation of the TEX related code/files is straightforward, it took me some time to get the fonts working. In what follows, I'll describe how I set it up on my system. I'm using Mandrake Linux 7.2 on an IBM Thinkpad 600E. The distribution comes with teTex 1.0.7. The TEX directory is /usr/share/texmf.

  1. Download the package and fonts you need. In my case, I downloaded jfs56, a Chinese GB font.
  2. Unpack the tar-ball of the package. Read the documents under ./doc, especially INSTALL, carefully.
  3. Follow the document, move the whole texinput directory to the TEX directory. In my case
      
             #ls
             README  contrib/  doc/  examples/  texinput/  utils/
             #cd texinput
             #mkdir /usr/share/texmf/tex/CJK
             #mv * /usr/share/texmf/tex/CJK/
      
      
    If you are not superuser, follow INSTALL to set up appropriate environment variables.
  4. Unpack the tar-ball of the font(s). Do a mktexlsr or texhash (the same thing). Although I don't think it's totally necessary, it's always not bad to create a new ls-R file when you add something to TEX.
  5. Compile hbf2gf in the ./utils/hbf2gf directory. IMPORTANT: when running the configure script, do put --with-kpathsea-dir in the command-line. This option does more than just telling the compiler where to find the header files, as the name suggests. It will enable hbf2gf to use kpathsea to locate config files. The thing is without this option, hbf2gf can just compile and run. Only it can't find files it needs. Mandrake 7.2 comes with kpathsea and put it under standard place (/usr/include for header files and /usr/lib for the library), so I just say
      
             #cd utils/hbf2gf
             #./configure --with-kpathsea-dir=/usr
             #make
      
      
    I didn't specify prefix and didn't do a make install. I like to copy files by myself instead of letting make mess around. Copy compiled hbf2gf to any directory in your PATH. You may need rehash if you are using tcsh.
  6. If you run the example now,
      
             %cd examples
             %latex GB.tex
             ...
             %xdvi GB.dvi
      
      
    xdvi will try to create pk files from tfm files. It does that by calling mktexpk, a shell script, which in turn calls hbf2gf. If you compiled hbf2gf with kpathsea, it should be able the find the config file (/usr/share/texmf/hbf2gf/gsfs14.cfg in my case). But it can't find the hbf file, which contains the bitmaps of characters. What I did first is to put the full path name in the hbf_header entry. It worked. But it's ugly. I read the man page of hbf2gf again and found how it uses kpathsea to locate files. hbf2gf will search for .hbf files in the path specified by the environment variable T1FONTS. This variable is defined in /usr/share/texmf/web2c/texmf.cnf. Find T1FONTS and append ;$TEXMF/hbf2gf// to it. The trailing double slashes, which tell TEX to search the subdirectory too, aren't really necessary.
  7. By now, you should have the GB font working and see GB.dvi just fine. There are a couple of things that INSTALL is out of date.