Posts Tagged ‘latex’

很高兴!Chinese in TeX

Thursday, August 4th, 2011

Recently, good things have kept on coming my ways (see my previous posts).

One issue that’s been nagging me for quite a while is outputting simplifed Chinese in .tex files. Given all the information I had collected I knew I was really close but it never completely worked… until I got Japanese working in TeX.

From then on, it was a matter of changing some fonts and trying.

In the end, I found even two ways to produce Chinese in tex files:

The first:

1) Download this template for Japanese in TeX:
http://pastebin.com/tasDkhZ3

2) Replace the following lines:
\newenvironment{Japanese}{%
with
\newenvironment{Chinese}{%

and
\CJKfamily{min}%
with
\CJKfamily{gkai}%

and the tags \begin{Japanese} and \end{Japanese} must also be
replaced with \begin{Chinese} and \end{Chinese}

3) Install the following packages:
latex-cjk-common
latex-cjk-chinese
latex-cjk-chinese-arphic-gkai00mp

4) Compile using pdflatex <file.tex>

Then, compiling with pdflatex works provided you have the packages

Note:
For some reasons, the CJKfamily “bkai” does not contain all the
simplified Chinese characters, so “gkai” (or an equivalent font
alternative) is required.

The second:

1) Download this sample file:
http://scripts.sil.org/cms/scripts/render_download.php?&format=file&media_id=xetex_chinese_sample&filename=xetex_chinese_sample.zip

Unfortunately, the uploader created it on a mac where the fonts are
different. However, in XeTeX you can specify fonts that are available in
other programs and system-wide so you can just pick a nice font in
LibreOffice and specify that one.

2) Change the fonts in the .tex file to some different font. Use the complete name of the font as you can see it in LibreOffice’s font selection e.g. “AR PL UKai CN”.

3) Compile using “xetex <file>.tex”

4) Rejoice!

To be honest, this second template file is most likely a total overkill for a simple papers or some exercices as the output comes in vertical columns and must be read from right to left. But it’s awesome to see that such a thing is even possible in TeX!

大成功! Japanese in LaTeX

Friday, July 29th, 2011

Urgh… today is a proud day for finally I got Japanese working in LaTeX files! Can’t believe I got to live to see this day!

If you need to get this working, too, follow these simple steps in Ubuntu:

1) Install the following packages:
texlive
texlive-latex-extra
latex-cjk-common
latex-cjk-japanese-wadalab

2) Download this tex example file:
http://pastebin.com/tasDkhZ3

3) Compile the using the following command:
pdflatex <file>.tex

4) Rejoice!

Some explanations:
texlive is of course the basic TeX distribution. The additional packages provide stylesheet files required by the example file (e.g. ucs.sty). Trying to compile without the package latex-cjk-japanese-wadalab results in the following messages in the log file:

LaTeX Font Warning: Font shape `C70/min/m/n’ undefined
(Font)              using `C70/song/m/n’ instead on input line 20.

! Undefined control sequence.
try@size@range …extract@rangefontinfo font@info
<-*>@nil <@nnil

Reason is, tex cannot find an appropriate font. Thus, the last package latex-cjk-japanese-wadalab must be installed which provides additional fonts for Japanese in tex.

One neat trick I learned during the process is the following:
If you get some warnings or error message about missing files in a tex log file, you can search for these file names on the Ubuntu packages page. Make sure you search in the content of packages! Sometimes this helps you to find which additional packages have to be installed!

But is it really worth it? Check out the following screenshot:

Comparison between TeX and PDF from LibreOffice

The pdf in the back is the compiled tex file, the one in front is a pdf file exported from LibreOffice. To be honest, the Japanese part look absolutely the same to me. Ergo: If you don’t have to deal with large documents and mixed texts, LO should do the trick as well.

Many thanks to Lucas for his help and the link to the example file! His article on TeX can be read in the 50th issue of the Ubuntu magazine “Full Circle
Thanks also to Simon whose help on TeX is always invaluable.