# Strange spacing with ruby (furigana) package

If I use the ruby package to supply furigana for a kanji character, it seems to glue the characters right adjacent to the kanji closely together and preventing line breaks, creating odd and possibly excess spacing.

Is this a bug in the package and can I somehow fix it? Are there alternatives? (I found pxrubrica but that seems to be for platex only.)

\documentclass[12pt]{standalone}

\usepackage{setspace}

\usepackage{xeCJK}
\setCJKmainfont{Hiragino Mincho Pro}
%\setCJKmainfont{VL Gothic}

\usepackage{ruby}
\renewcommand\rubysep{-0.7em}

\begin{document}
\fbox{
\parbox{25em}{
\doublespacing
\ruby{青}{あお}いスーツ、\ruby{白}{しろ}いシャツ、\ruby{赤}{あか}いネクタイが\ruby{男}{だん}\ruby{性}{せい}\ruby{従}{じゆう}\ruby{業}{ぎよう}\ruby{員}{いん}\ruby{全
}{ぜん}\ruby{員}{いん}の\ruby{必}{ひつ}\ruby{需}{じゆ}\ruby{品}{ひん}だ。
}}
\end{document}


• I'm not surprised that hyphenation isn't possible when furigana is used. TeX hyphenates words, not sequences of boxes. – egreg Oct 12 '14 at 12:23
• Tht ruby package is not fully compatible with xeCJK. Actually, the luatexja package is much better than xeCJK in Japanese typesetting. luatexja contains an addon package luatexja-ruby. It provides functionality of furigana annotation. You can check their manuals for details. – Qing Lee Oct 12 '14 at 14:07

ruby package is not implemented correct. I think this code piece will solve the problem:
\usepackage{ruby}

• It is tricky. luatexja-ruby is more powerful. – Qing Lee Oct 12 '14 at 14:30
• FWIW, in addition to your monkeypatch, I had to supply the package with the nooverlap option for proper rendering. Previously nooverlap and overlap did not seem to have much effect. – oals Oct 12 '14 at 15:24
• @QingLee: Indeed. But luatexja-ruby requires LuaTeX. It would be nice if some Japanese developer (e.g. 八登崇之) could provide a better solution for XeTeX. – Leo Liu Oct 12 '14 at 15:40