XeTeX and How to make LaTeX (teTeX) handle unicode and CJK in MacOSX
If you want to use Unicode LaTeX, I recommend XeTeX, which is more robust than many other hacks, including some in the seconf half of this page. I would not recommend the hacks unless (1) you have no choice but to run an older version of latex that needs to be retrofitted (2) you need to typeset CJK text vertically. In these cases, you can follow the instructions below after the XeTeX section.
XeTeX
XeTeX works with unicode and the PDF fonts on your system. If you use one of the existing setups, it is usually pretty easy, but you need to define the font name that is available on your system.
\usepackage{fontspec}
\usepackage{xeCJK}
Depending on your platform, you need to set the main font names. For Roman text, you can do
For CJK Text, you should pick a font name that is present on your system. This may lose cross-platform compatiblity but is easy to fix.
-
For Windows, you can use, for example,
\setCJKmainfont{標楷體}
% for brush stroke on Windows
-
For MacOSX, the equivalent one would be
\setCJKmainfont{BiauKai}
% for brush stroke on MacOSX
- Note: if you use STKaiti, some of your traditional characters (e.g., 角) might look wrong (i.e, with a 用 below)
For line breaking, do
\XeTeXlinebreaklocale "zh"
\XeTeXlinebreakskip = 0pt plus 1pt
(pdf)LaTeX
This document assumes you know what LaTeX, pdflatex, etc. are, and want to typeset non-Roman text by hacking your existing installation without XeTeX. Another possible use is if you want to typeset CJK text vertically, XeTeX currently does not quite work, but the hacks here supports the CJKvert package. The steps here works on MacOSX and should work for other platforms, though I have no tested them.
-
Installation of UCS Package
-
Download "ucs" package from :
http://www.unruh.de/DniQ/latex/unicode/unicode.tgz
(actually you'll get unicode.gtar)
- uncompress/untar the file
-
move the whole "ucs" directory to an appropriate directory on your local
TeX-tree (I move it to the path
I-Installer:
/usr/local/teTeX/share/texmf.local/tex/latex/ucs,
or
Fink:
/sw/share/texmf-local/tex/latex/ucs/)
-
Pai's note: most of the time you need to sudo the
mkdir
and
mv
command, if part of the path does not exist. for example, if you don't have a "latex" directory along the path, then you may have to do this:
%
sudo mkdir
/usr/local/teTeX/share/texmf.local/tex/latex
%
sudo mv
ucs /usr/local/teTeX/share/texmf.local/tex/latex
-
Installation of CJK Package
-
download "cjk" package from :
http://cjk.ffii.org/cjk-4.8.1.tar.gz
(previously, it was http://cjk.ffii.org/cjk-4.5.2.tar.gz)
- uncompress/untar the "cjk-4.8.1.tar.gz" file
-
move the whole directory to an appropriate directory on your local TeX-tree (I move it to the path
I-Installer:
/usr/local/teTeX/share/texmf.local/tex/latex/cjk/
or
Fink:
/sw/share/texmf-local/tex/latex/cjk/)
-
Installation of Unicode True Type font (Cyberbit).
-
download "Cyberbit.ZIP" file from :
ftp://ftp.netscape.com/pub/communicator/extras/fonts/windows/Cyberbit.ZIP
Actually there are several .zip files in that directory. uncompress them and you'll get .ttf fonts. But I think all you need is just one.
-
Rename
Cyberbit.ttf
to lower case (cyberbit.ttf) or else LaTeX might get confused because it is case sensitive.
-
Install the
.tfm
and
.enc
files.
-
There are two ways to get those files:
-
Generate the file yourself:
-
download "Unicode.sfd" file from :
http://delloye.free.fr/Unicode.sfd
-
make sure "Cyberbit.ttf" file and "Unicode.sfd" files are in the same directory
-
from the terminal, go to that directory and run
%
ttf2tfmcyberbit.ttf
-w cyberbit@Unicode@
, in order to create ".tfm" and ".enc" files.
-
Download: If you cannot run
ttf2tfm
,
you can download the
.tfm
and
.enc
files that I generated.
-
move all the ".tfm" files to an appropriate directory on your local TeX-tree (I put them in I-
Installer:
/usr/local/teTeX/share/texmf.local/fonts/tfm/bitstream/cyberbit/,
or
Fink:
/sw/share/texmf-local/fonts/tfm/bitstream/cyberbit/)
-
move all the ".enc" files to an appropriate directory on your local
TeX-tree (I put them in
I-Installer:
/usr/local/teTeX/share/texmf.local/pdftex/enc/;
or
Fink:
/sw/share/texmf-dist/fonts/enc/pdftex/)
- Install "cyberbit.map" file
-
download from :
http://delloye.free.fr/cyberbit.map
-
move it to an appropriate directory on your local TeX-tree (I put it in
I-Installer:
/usr/local/teTeX/share/texmf.local/pdftex/config/;
or
Fink:
/sw/share/texmf-dist/fonts/map/pdftex/updmap/
-
Install "c70cyberbit.fd" (and optionally
.fdv)
-
file from :
http://delloye.free.fr/c70cyberbit.fd
Pai's comment: If you want vertical typesetting, you need a file named
c70cyberbit.fdv.
-- use this at your own risk! I basically pasted
c00bsmi.fdv
into the
c70cyberbit.fd
file to create it.
-
move it (or both) to an appropriate directory on your local TeX-tree (I put it in
I-Installer:
/usr/local/teTeX/share/texmf.local/tex/misc/,
or
Fink:
/sw/share/texmf-local/tex/misc/)
-
move the "Cyberbit.ttf" (should be renamed
cyberbit.ttf
-- lower case!!) to an appropriate directory on your local TeX-tree
(I put it in I-Installer:
/usr/local/teTeX/share/texmf.local/fonts/truetype/,
or Fink:
/sw/share/texmf-local/fonts/truetype/)
Pai's comment: The following should not be a concern, but if it doesn't work:
(check in your
I-Installer:
/usr/local/teTeX/share/texmf/web2c/texmf.cnf;
or
Fink:
/sw/share/texmf/web2c/texmf.cnf
file the "%TrueType outline fonts" line and the "TTFONTS" value to make sure it includes the path where your
cybebrbit.ttf
file is located.)
-
Declaration of the new font to pdfTeX
- open the "pdftex.cfg" file
(I-Installer:
/usr/local/teTeX/share/texmf.local/pdftex/config/pdftex.cfg;
or
Fink:
/sw/share/texmf-local/pdftex/config/pdftex.cfg
-- though I think if you use Fink, you should use the alternative instruction in part
4.b
instead) and add this line
map +cyberbit.map
at the end of the file.
Note: You may have permission problems saving this file. If you know how to use the
vi
(or
pico
,
probably easier, or
emacs
)
text editor from the command line, your best bet is to
cd
into that directory and
%
sudo vi
pdftex.cfg
Otherwise, copy this file to a directory you can save, edit, and
sudo mv
it back to its directory.
- If you are running TeXLive 2004, you might have to do the following step:
-
(sudo) edit the file
/usr/local/teTeX/share/texmf.local/web2c/updmap.cfg
-
add the following line
Map cyberbit.map
to the end of the file, save;
If you are running Fink's distribution, add
Map Cyberbit.map
to the file
/sw/share/texmf-dist/web2c/updmap.cfg
-
type the command
%
sudo updmap
This should re-read all the map files and generate the output files for ps2pk, dvips, pdftex, dvipdfm and run texhash for you. (so you can skip step 4.c)
-
Update the
ls-R
files by the command
%
sudo mktexlsr
-
Using the new environment in LaTeX
You just need to include the three following lines in the preamble :
\usepackage[encapsulated]{CJK}
\usepackage{ucs}
\usepackage[utf8]{inputenc}
(for
TexLive 2004, use
[utf8x]
instead of
[utf8])
It may also be convenient to create a new command :
\newcommand{\cntext}[1]{\begin{CJK}{UTF8}{cyberbit}#1\end{CJK}}
Now, when you want to type CJK text, you just have to use the command :
\cntext{enter your CJK text here}
To do vertical typesetting, just do
\usepackage
{CJKvert}
and CJK characters will be rotated 90 degrees for the vertical orientation.
Pai's comment: Make sure you use an editor such as TeXShop which can save in UTF-8 encoding. Vim also works if you do
:set encoding=utf-8
inside vim or in the file ".vimrc" (without colon).
The TrueType unicode font will be embedded for a very smooth looking PDF document.
%
pdflatex
yourfile.tex
Troubleshooting