# CJK-LaTeX Support

This post will document my adventure in getting Japanese support to work with LaTeX.

To begin, make sure you are using the latest version of LaTeX, at this time it would be TeXLive-2007/2008. I had to remove the old tetex installation which is explained in the TeXLive Migration Guide on the Gentoo project site. Just make sure that the cjk USE flag is enabled and that you have also added ja_JP ja to your LINGUAS var in /etc/make.conf which will then compile the TeXLive system with CJK and Japanese support included. Beware its a very large set of packages so it may take a while to download on a slow connection.

## Install Cyberbit for X11

These steps are optional.

Download the Cyberbit font from Cyberbit.ZIP then unzip it to /tmp/ directory.

Execute the following commands:

sudo mkdir /usr/share/fonts/ttf-cyberbit
sudo chown root:root /usr/share/fonts/ttf-cyberbit
sudo cp /tmp/Cyberbit.ttf /usr/share/fonts/ttf-cyberbit/cyberbit.ttf
sudo mkfontdir /usr/share/fonts/ttf-cyberbit


Update the /etc/X11/xorg.conf to include the new font directory.

Restart the X11 server.

Finally update the font cache via sudo fc-cache -vf command.

## Prepare Cyberbit for installation

Create a temponary folder in /tmp/ directory and copy the cyberbit.ttf font from the previous step into that folder and rename it to cyberb.ttf.

Copy the subfonts.pe file, which can be found in the /usr/share/textmf/scripts/subfonts/ directory, to the temponary directory that was made in the previous step.

Download the Unicode.sfd file from the post in which the author has extended the file’s Unicode listing to support more characters. Rename the .obj extension of the file to .bz2 then bunzip the file to the temponary directory made earlier.

To generate all of the needed files for LaTeX fontforge must be installed. To install it execute emerge media-gfx/fontforge.

Once fontforge has been installed execute this command to generate all of the needed files, however be aware that depending on the computer’s speed it could take several hours!

fontforge -script subfont.pe cyberb.ttf cyberb Unicode.sfd


Once all of the needed files has been generated by fontforge, create the cyberb.map file by executing these command:

for i in *.pfb
do
echo "$(basename$i .pfb) $(basename$i .pfb) <$i" >> cyberb.map done  This step involves the creation of several directories, so here’s the list of directories to generate: mkdir -p ~/texmf/fonts/{afm, tfm, type1}/cyberb mkdir -p ~/texmf/fonts/map/dvips/cyberb  Now copy all of the files generated by fontforge into the proper directory: cd cp *.afm ~/texmf/fonts/afm/cyberb/ cp *.tfm ~/texmf/fonts/tfm/cyberb/ cp *.pfb ~/texmf/fonts/type1/cyberb/ cp cyberb.map ~/texmf/fonts/map/dvips/cyberb/  Create a ls-R database in the ~/texmf/ directory so that LaTeX can find all the files that it needs to by executing texhash Finally update the maps by executing updmap --edit which will open the mapfile in your $EDITOR which in my case is vim. Once the mapfile is opened in the \$EDITOR add at the bottom of the file “Map cyberb.map” without the quotation then save the file and the command should automatically generate/update the mapping database.

Create a testing CJK LaTeX file to ensure that everything has been setup and installed properly, here’s an example:

\documentclass{article}
\usepackage{CJKutf8}
\begin{document}
\begin{CJK*}{UTF8}{song}
オバマわたし
\end{CJK*} (this is a test)
\end{document}


Execute pdflatex on the test LaTeX file to generate a pdf, then open the pdf to see if the CJK characters were generated properly and are rendering properly in the pdf file. There should be no error on the output.

## Optional

If the ~/texmf/ in the home directory is bothersome, or if its desired to have CJK-LaTeX support for all of the users on the system, then the only part that has to be changed is to replace the ~ with /usr/share/texmf-site/ which is the site-specific directory for all of the extra TeXLive files that are specific to this computer. And also will need to execute the texhash and replace the updmap --edit command with updmap-sys --edit and run both command as root.

## Update

There has been some new information on how to do it properly in the Gentoo way, and it is instead executing texhash, and running updmap --edit, or updmap-sys --edit. It is better to instead create a new file named texlive-custom.cfg in the /etc/texmf/updmap.d/ directory and put “Map cyberb.map” in that said file then run texmf-update which will take care of generating all of the ls-R files, and updating the font map.

However one issue is that for the site wide settings to work it will be needed to wipe the .texmf-config/ and .texmf-var/ directory out of the user’s home directory to make LaTeX pick up on the new system-wide settings.

### Resources

Japanese in LaTeX documents and in Unicode with MacTeX
http://www.joel.lopes-da-silva.com/2008/05/10/japanese-in-latex-documents-in-unicode-with-mactex/
cjk-latexでCyberbitフォントを利用してPDFを作成するテスト
http://d.hatena.ne.jp/kakurasan/20070914/p2