[XeTeX] Issue with CJK in pdf build

Michiel Kamermans pomax at nihongoresources.com
Wed Nov 18 12:54:40 CET 2009


Hi Chris,
> Apart from the fact that I have no clue how I should go about doing that, I would assume that having a few CJK characters (or other non-ASCII stuff) inside a US English document is not something so outlandish that other users have not run into this problem before me and that such a package is already available (tested, stable, maintained).
>   
Basically the concept is not that you have "a few CJK characters" in 
your document, but that you have "characters that don't exist for your 
font", be they CJK or Byzantian musical symbols. As a typesetter, TeX 
now wants you to do your job and tell it what it needs to do with these 
characters.

For instance, to keep things CJK, I just wrote a book on Japanese 
grammar using xetex, but xetex only knows what you tell it to know, so I 
have to tell it which fonts to use for which characters. In general, 
forgetting to do this leads to two problems: 1) not specifying which 
font to use means (any version of ) TeX will use its default font, which 
might be a different font on different machines, and thus your output 
will differ depending on which computer you run it on. That is bad, 
because the idea is supposed to be that a TeX document looks identical 
regardless of which machine you compile it on. 2) Even if it picks the 
same default font on all machines, that font might be missing the 
unicode glyphs you use in your text Some fonts don't even carry the 
ASCII table, so things can really go horribly, horribly wrong if you're 
not explicit about what TeX should do, fontwise.

Luckily, if you can include a style file, then things become very easy, 
so let's just make one: make a file called "mystyle.sty", and in that 
file stick the following text:

\ProvidesPackage{mystuff}
\usePackage{fontspec}
\setmainfont{The Font You Want Used}
\endinput

The words "package" and "style" are effectively synonymous, they both 
mean "some (Xe)(La)TeX code that can be imported into other TeX files". 
This particular custom TeX code only does one thing, but it's crucial: 
it tells XeTeX to import fontspec, and then tells it to explicitly use 
the font of your chosing. If you like Times New Roman, then 
\setmainfont{Times New Roman}, if you want Deja Vu, \setmainfont{Deja 
Vu}, etc. The important thing to remember is that in order to guarantee 
consistent output, you must explicitly say which font to use. This also 
means that for your document, for instance, you want a font that has 
both the ASCII table, and the CJK blocks, so on windows this would be 
something like MS Mincho, and on a Mac it would be something like 
Hiragino. On *nix I have no idea what the default CJK fonts are, but you 
can download and use Ume Mincho or HAN NOM (both free).

When you've settled on a font, you can then indicate this "mystyle.sty" 
file as being the style you want included when running dblatex, using 
"dblatex --texstyle mystyle (rest of your arguments)".

Of course, this applies the same font to all your text, which is good, 
because that's what you told TeX to do. If instead you want automatic 
font switching, with one font for ASCII (or, strictly speaking, Latin) 
and another for CJK, then you'll need to stick in some more code in your 
style file to effect this, and things get more complicated (but if you 
like I can explain how to get that to work using an excellent feature in 
XeTeX, called intercharclasses, which makes life quite a bit easier if 
you need character-based fontswitching).

Hope that makes things a bit more understandable!

Regards,

- Mike "Pomax" Kamermans
nihongoresources.com


More information about the XeTeX mailing list