[Tex/LaTex] Japanese Problem using MacTeX 2011

mactexxecjk

The XeLaTeX Japanese examples I find on TeX.sx seem to have this issue in common on my system. I'm running MacTeX 2011, fully updated at the time of writing. The following sample

%!TEX TS-program = xelatex
\documentclass{standalone}

\usepackage{xeCJK}
\usepackage{ruby}
\setCJKmainfont{Hiragino Mincho Pro}

\begin{document}

\ruby{学}{がく}\ruby{生}{せい}

\end{document}

gives me this output

enter image description here

I checked Font Book, and the font in the example is present (this happens whatever font I try). In an ideal world I'd like to use Japanese with furigana (ruby text). Is there something wrong with my code, or something not quite right with MacTeX on this system?

Best Answer

It's an encoding issue. Tell TeXShop to use unicode, either through the preferences or a TeXShop directive shown in the following:

% !TEX TS-program = xelatex
% !TEX encoding = UTF-8 Unicode
\documentclass{standalone}

\usepackage{xeCJK}
\usepackage{ruby}
\setCJKmainfont{Hiragino Mincho Pro}

\renewcommand\rubysep{0.1ex}

\begin{document}

\ruby{学}{がく}\ruby{生}{せい}

\end{document}

I've also changed the value of \rubysep to make the spacing a little better.

enter image description here

Related Question