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, 14 November 2008: updated for MacTeX 2008 support on Leopard; small "bugfix" of the tutorial.
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:
% wget 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) <$i" >> 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!






But I would like you to give me the link of the translated tutorial when it is posted in order to create (also) myself a link to your translation on this page: it will help the Page Rank to grow!
Thanks, and see ya!
What about you? Have you already tested the JLPT?
I just received my new MacBook a few days ago; so I tried my own tutorial once more on a brand new Leopard install, but this time with MacTeX 2008. Indeed, I also experienced your issue: "The map file 'cyberbit.map' has not been found at all. "
To solve that, you just need to execute `texhash` before using `updmap`.
I also experienced another problem with permissions when using a graphical editor to input the content of the file c70song.fd; so I also changed those lines a little bit so this could work properly.
Very, very sorry, and thank you all for your feedback!
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.
Anyway, please try the following:
% sudo -s
# /usr/libexec/locate.updatedb
# locate -i cyberbit.map
Then paste me the output of this last command.
Concerning Lyx, and XeTeX and all, honestly, I never tried any of these: I am the kind of guy who writes himself his LaTeX code, and I never used a WYSIWYG editor such as Lyx for LaTeX. What I know is that writing Japanese vertically with LaTeX using UTF-8 might be impossible right now: if I remember well, the CJK and the CJKvert packages use other encodings less universal than Unicode, but CJKutf8 doesn't allow vertical writing.
Therefore, to write Japanese vertically with [anything]TeX, you have two possibilities:
- you can choose to forget Unicode and use CJKvert with LaTeX and a more specific encoding;
- you can try and see if XeTeX is a good solution.
As you must have perfectly understood, I still don't know anything about XeTeX except what I told you yesterday. I don't know wether XeTeX integrates well within Lyx, nor if you can write Japanese vertically with XeTeX. But in my opinion, XeTeX might be the best solution if vertical writing is crucial to you. However, I honestly don't have the time to look for the good answers, so you will have to look for them by yourself. But please, if you learn anything interesting, share with the community leaving a comment here.
Good luck, and see ya!
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?
> Japanese fonts, such as those freely found on the net, can be incorperated into LaTeX?
Honestly, I don't know how to do it with just LaTeX and packages such as CJK. However, a friend of mine told me about XeTeX, a fantastic alternative which could allow using any normal font installed on the system as we would do on other Text Processing programs. When I saw it, I thought it was extraordinary simple, and that I would switch from LaTeX to XeTeX sometime, but I still haven't had the time to learn how to use XeTeX properly.
But I would be glad if you could try it and explain it for us, Japanese, LaTeX, and Apple fans!