Writing Japanese with XeTeX

XeTeX lets you use different writing systems in the same document. If you have an OpenType font containing, for example, Japanese characters or Devanagari letters, you can put (probably) any of them into a document with XeTeX, which is something you can’t do with TeX. I find this feature very useful especially for doing language science. Yet XeTeX doesn’t know the formatting rules for Japanese documents well. Some websites give an impression that XeTeX can produce Japanese documents only by changing \XeTeXlinebreaklocale and \XeTeXlinebreakskip, but anyone who knows Japanese should be able to see easily that this is not true. Indeed, it let you put Japanese characters into a document, but XeTeX ignores the rules to the extent that it can’t be used for Japanese publications in reality. To talk about ‘CJK’ document preparation dosen’t make sense, as formatting rules of ‘C’, ‘J’ and ‘K’ are different.

If you want to make documents in Japanese only, there’s pTeX (and pLaTeX) which does a good job. And pTeX supports OpenType fonts too. But I still find the idea to use XeTeX to write Japanese useful. Why? There are several reasons. But the primary reason is that although pTeX supports the Roman alphabet, if you want to use letters which are not used in English, configurations and markup processes get pretty complicated. I write documents in English which cite non-English languages such as Classical Chinese, Finnish, Japanese, Greek and Pāli; I don’t know if it’s possible to mix their writing systems in pTeX, but even if it does, it’s too tedious (almost a nightmare) to mark up all diacritics. XeTeX, instead, can process a UTF-8 source file containing whatever writing system in addition to Japanese as long as appropriate fonts are installed in the operating system.

I’ve tried various ‘CJK’ packages for XeTeX, but none of them produced a usable Japanese document. Here ‘usable’ means that the document looks good enough in the eyes of the native speaker and that it can be used in daily work. So I did experiments to get XeTeX outputting usable Japanese documents which also (kind of) follow ‘JIS X 4051:2004 Formatting rules for Japanese documents’. I put the gist of the results below:

The Genzi XeLaTeX package (current version 2009/07/05)

I wrote a package genzi.sty for XeLaTeX as a result of my experiments. The codes are only experimental, and my purpose of showing them is only to share knowledge.

The Genzi package is mainly for adding Japanese text in documents written in English or whatever language. You can simply type in Japanese if the Japanese text is shorter than a paragraph; otherwise include text in \begin{ja}...\end{ja}. It’s recommended that you only type Japanese directly when you want to add, for example, a word or phrase within text. If you type anything longer, use the environment because it corrects indentation. Font sizes are calculated to adjust the size differeces between Latin and Japanese fonts. In principle, you can also write Japanese-only text with the package by putting the whole text in the environment.

To write numbers in Japanese, input fullwidth numbers in the source file and the result will be in halfwidth with appropriate spacing. Spaces will be inserted between Japanese and Latin letters if you don’t put any space between them in a source file.

One thing that is good about XeLaTeX when writing Japanese is that accessing alternative forms of characters is possible. I made commands itz for accessing itaizi (異体字) and kmz for getting kakomimozi (囲み文字). To write Classical Chinese with Japanese fonts (to be more precise, in the Japanese style), access to itaizi (異体字) is very useful (see a sample: sunzi.pdf   sunzi.tex (XeTeX, not LaXeTeX)).

You can download some sample files made with these packages below:

Last update: 2009-07-07

Back home

Creative Commons License
This work is licenced under a Creative Commons Licence.

Valid XHTML 1.0 Strict Valid CSS!