
Since I discovered LaTeX, I have become a real fan of this typesetting system. Yet, something bothered me very much: I could not use easily Japanese with LaTeX using a normal encoding, that is to say using UTF-8. Using CJK is not too difficult, but getting CJKutf8 to work is much harder. I just couldn't resign myself to use some strange encoding popular in Japan, mostly for Windows Addicts...
But I just found how to do it. Since it is not so easy, I want to do a copy-paste how-to explaining precisely how to install UTF-8 Japanese support in MacTeX. So, just follow the guide...
Updated
- Friday, November 14, 2008: updated for MacTeX 2008 support on Leopard; small "bugfix" of the tutorial.
- Monday, December 1, 2008: replaced wget by curl -O.
Of course, installing MacTeX is a prerequisite. This how-to has been tested on Mac OS X 10.5 (Leopard) with both versions 2007 and 2008 of MacTeX, and it is just the adaptation of a procedure described in a Debian Readme file (/usr/share/doc/latex-cjk-common/README.Debian.gz in Debian Etch)...
The problem when we want to type Japanese directly in UTF-8 encoding in a LaTeX document is that we have to use the package CJKutf8 instead of CJK, and by default, there is no font with Japanese symbols adapted for UTF-8 typesetting in LaTeX. Therefore, the main goal of this how-to is to install the font Cyberbit into your LaTeX distribution. Please, be sure to acknowledge the font's license.
First, in a terminal, download and unzip the font file:
% curl -O ftp://ftp.netscape.com/pub/communicator/extras/fonts/windows/Cyberbit.ZIP
% unzip Cyberbit.ZIP
% rm -f Cyberbit.ZIP
Then, we need to become root in order to prepare some directories and files:
% sudo -s
# mkdir -p /usr/local/share/fonts/truetype/bitstream/
# mv Cyberbit.ttf /usr/local/share/fonts/truetype/bitstream/cyberbit.ttf
# mkdir -p /usr/src/cyberbit-fonts/
# exit
% sudo chown "$USER":staff /usr/src/cyberbit-fonts/
% cd /usr/src/cyberbit-fonts/
/usr/src/cyberbit-fonts/ will be our build directory. We now must prepare some more files in this directory:
% ln -s /usr/local/share/fonts/truetype/bitstream/cyberbit.ttfYou mustn't forget the final ".", since it means the working directory. Then, you have to run the following command:
% cp /Library/TeX/Root/texmf-dist/source/latex/CJK/utils/subfonts/subfonts.pe .
% fontforge -script subfonts.pe cyberbit.ttf cyberbit \
/Library/TeX/Root/texmf/fonts/sfd/Unicode.sfd
This will take a very long time, probably several hours, so if you have something else to do, go for it! Then you must generate a file called cyberbit.map:
% touch cyberbit.map
% for i in *.pfb
do
echo "$(basename $i .pfb) $(basename $i .pfb)" >> cyberbit.map
done
Then, we need root's priviledges for almost all the things left to do, so type the following command:
% sudo -s
in order to become root, and type your password. Then do the following:
# mkdir -p /usr/local/texlive/texmf-local/fonts/map/dvips/cyberbit/
# mkdir -p /usr/local/texlive/texmf-local/fonts/{afm,type1,tfm}/cyberbit/
# cp cyberbit.map /usr/local/texlive/texmf-local/fonts/map/dvips/cyberbit/
# cp *.afm /usr/local/texlive/texmf-local/fonts/afm/cyberbit/
# cp *.pfb /usr/local/texlive/texmf-local/fonts/type1/cyberbit/
# cp *.tfm /usr/local/texlive/texmf-local/fonts/tfm/cyberbit/
# echo "Map cyberbit.map" >> /Library/TeX/Root/texmf-var/web2c/updmap.cfg
# cd ..
# export PATH="/usr/texbin:$PATH"
# texhash
# updmap
# updmap-sys
Then you have to replace a file of the distribution MacTeX by another one:
# rm -f /Library/TeX/Root/texmf-dist/tex/latex/CJK/UTF8/c70song.fd
# mkdir -p /usr/local/texlive/texmf-local/tex/latex/CJK/UTF-8/
# cd /usr/local/texlive/texmf-local/tex/latex/CJK/UTF-8/
# touch c70song.fd && chmod -R go+w .
# open -a TextEdit c70song.fd
Now, a new TextEdit window should have opened, with an empty file. Copy-paste the following text into the empty file:
/usr/local/texlive/texmf-local/tex/latex/CJK/UTF-8/c70song.fd
%%%%%%
% This is the file c70song.fd of the CJK package
% for using Asian logographs (Chinese/Japanese/Korean) with LaTeX2e
%
% created by Werner Lemberg
%
% Version 4.6.0 (11-Aug-2005)
\def\fileversion{4.6.0}
\def\filedate{2005/08/11}
\ProvidesFile{c70song.fd}[\filedate\space\fileversion]
% character set: Unicode U+0080 - U+FFFD
% font encoding: Unicode
\DeclareFontFamily{C70}{song}{\hyphenchar \font\m@ne}
\DeclareFontShape{C70}{song}{m}{n}{<-> CJK * cyberbit}{}
\DeclareFontShape{C70}{song}{bx}{n}{<-> CJKb * cyberbit}{\CJKbold}
\endinput
%%%%%%
Then save the file. Lastly, run:
# chown -R root:wheel . && chmod -R go-w .
# texhash
That's it! You should now be able to compile with pdflatex such a file (encoded in UTF-8, check out in your LaTeX editor's preferences):
Example.tex
\documentclass[a4paper,12pt]{article}
%%%%%%%%%%%%%%%%%%%%%%%
% Encodings, fonts... %
%%%%%%%%%%%%%%%%%%%%%%%
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Oriental languages specificic options %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\usepackage[T1]{CJKutf8}
\usepackage[overlap,CJK]{ruby} % Furigana support
\renewcommand{\rubysize}{0.5} % Furigana size
\renewcommand{\rubysep}{-0.3ex} % Spacing between Furigana and Kanji
%%%%%%%%%%%%%%%%%
% Title, author %
%%%%%%%%%%%%%%%%%
\title{Japanese in UTF-8 with \LaTeX}
\author{Joel \textsc{Lopes Da Silva}}
\begin{document}
\begin{CJK}{UTF8}{song}
\maketitle
\thispagestyle{empty}
\section{タイトル}
おめでとうございます。\ruby{自分}{じぶん}でできましたね。
\bigskip
これから、日本語で \LaTeX の\ruby{資料}{しりょう}を\ruby{書}{か}けます。
\section{Another title}
You can even use English words within a 日本語の\ruby{資料}{しりょう}
~(document in Japanese).
\bigskip
Have fun!
\end{CJK}
\end{document}Compiling this basic LaTeX document with pdflatex should result in such a file. Enjoy!






I am an Italian user, so I was wondering if you could allow me to translate your post in Italian. I would like to post it on a friend's blog.
Of course we would link your post here and give you all the credit, just saying that we are translating from your post.
I think it is very useful and complete, translating it would make it more useful to many friends of mine.
Please let me know if there is any problem with that, writing me at [e-mail address removed by moderator].
Thanks a lot
Mauro
/usr/local/texlive/texmf-local/fonts/map/dvips/cyberbit.map
/src/cyberbit-fonts/cyberbit.map
BTW, what level of the JLPT test did you pass? I'm guessing 4...you should check out http://http://nihongoperapera.com/ this guy passed the JLPT 2 test after 4 months of intensive study.
I am currently trying to get Japanese, English and IPA to work under Lyx...I am having some trouble getting Japanese to work, and I am wondering if it has something to do with installing Basic Tex before installing the full Mac Tex...if you have any ideas let me know.
I am pretty happy with Lyx for English and IPA, with Lyx 1.6.0rc3 I can input IPA using the IPA Unicode 5.0c IME with full character support (for English and Japanese IPA symbols at least - except for some of the less common symbols for changes in pitch, and syllabic consonants), its a lot easier than using TIPA.
The map file 'cyberbit.map' has not been found at all.
Either put the file into the right place or remove the
reference from the configuration file. An automatic way
to disable unavailable map files is to call
updmap --syncwithtrees
For manual editing, call
updmap --edit
Any ideas?