Japanese Text With LaTeX!

November 23rd, 2008 Pekk

Okay when I did this I was really only looking for Japanese. The simplest way to do this (and I’m on a MacX machine using TeXShop) was to use XaLaTeX, and use the fontspec and xunicode packages.

I found a PDF file online that was actually just like a tex input file, but in pdf format (probably so that the fonts would be visible without any encoding issues).

First thing it said you need are these two lines:


%!TEX TS-program = xelatex
%!TEX encoding = UTF-8 Unicode

The first one is to force TeXShop to use XaLaTeX, and the second is to force it to save the tex files in utf-8 format.

Somewhere after the document class we add the following


\usepackage{fontspec,xunicode}
\defaultfontfeatures{Mapping=tex-text} %% !!IMPORTANT!! This preserves out fancy tex text like ` for left quote -- for en dashes, etc.
\newfontfamily{\J}[Scale=0.85]{Osaka} %%this is our macro for changing to japanese font mode, enclode all jp text with {\J Whatever}

The scaling on the japanese text is totally optional, personally i kind of like it without, but i have noticed that the Osaka font is more bold.
Now we can apply the japanese text anywhere in our document:


Word. {\J ????????? ???????}

Since I’m so sure the encoding on that got clobbered (I don’t know why though, this blog used to be UTF-8 Friendly…) I’ve included a sample file. So check the Japanese Text in TeX Example out. Make sure your browser is set to UTF-8, or just right-click Save (Link, Target) As… Check out the resulting Japanese Text in TeX Example PDF File.

The basic idea of the technique is just to switch fonts to a system font that will have japanese character support :) Osaka is one of them. Mac users can check the Font Book application to scour for more.

Posted in General | No Comments »