Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Using ruby package to generate both furigana for Japanese and Pīnyīn for Chinese. I use individual \sf calls to individually switch each Pīnyīn from the Japanese font back to the default sans font. Is there an easier way?

(I should clarify that I understand each CJK font has roman glyphs for Pīnyīn, but I prefer the Biolinum.)

Please see MWE...its output makes my question more clear, I think:

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

\documentclass[12pt]{article}

% PACKAGES

\usepackage{fontspec}
\usepackage{xltxtra}
\usepackage{xunicode}
\defaultfontfeatures{Mapping=tex-text}
\setromanfont[Mapping=tex-text]{Linux Libertine O}
\setsansfont[Scale=MatchLowercase,Mapping=tex-text]{Linux Biolinum O}
\setmonofont[Scale=MatchLowercase]{Linux Libertine Mono O}
\usepackage{ruby}
\usepackage{setspace}

\begin{document} % ==============================================================

\newfontfamily{\J}[Scale=0.85]{Hiragino Kaku Gothic Pro}
\newfontfamily{\C}{STKaiti}

\doublespace
\Large

I'd like to include both Chinese (e.g. {\C\renewcommand\rubysep{-4.9ex}\ruby{内}{\sf nèi}\ruby{忧}{\sf yōu}\ruby{外}{\sf wǎi}\ruby{患}{\sf huàn}}) and Japanese (e.g. {\J\renewcommand\rubysep{-1.9ex}\ruby{内}{ない}\ruby{憂}{ゆう}\ruby{外}{がい}\ruby{患}{かん}}) text, \textit{inline} with English text, and with ruby text (pronunciation), as shown here.  Does there exist a convenient method for distributing the \texttt{\textbackslash sf} (or preferably \texttt{\textbackslash textsf\{\}}), across all the \texttt{\textbackslash ruby} calls to generate the Pīnyīn (the text below the Chinese)?

\end{document}
share|improve this question
    
You can define a new command with all the necessary parameters, in your case something like \newcommand{\HanZi}[2]{\ruby{#1}{\sf #2}}. Your text will be more readable: "... Chinese (e.g. {\C\renewcommand\rubysep{-4.9ex}\HanZi{内}{nèi}, \HanZi{忧}{yōu}, ...} ...". Also you can think of new commands to setup chinese and japanese ruby... The pinyin package may be helpful also. –  guillem Jan 10 '13 at 7:25
1  
While I RTFM on that, would you mind quickly answering: is there a way to permit an arbitrary number of (paired) arguments, so that my command might look like \HanZi{同}{tóng}{治}{zhì}{中}{zhōng}{興}{xīng}...? (Though it occurs to me that if such a thing were possible, ruby's authors would have implemented it.) (Also, I'm avoiding the pinyin package for the moment, since my Chinese text will be minimal, and I intend to exert positive control over each Pīnyīn anyway.) –  commonhare Jan 10 '13 at 8:31
    
Sorry, but I don't know any way to handle an arbitrary number of arguments, let alone forcing an even number of them. That's unfortunate, because I like your idea a lot. –  guillem Jan 10 '13 at 8:53
add comment

1 Answer

up vote 1 down vote accepted

I haven't tested this to see if it breaks anything, but it seems creating some new commands that pass their arguments to \ruby{}{} might work. This allows you to renew the \rubysep every time as well as apply \textsf only to the Pīnyīn. The example should make things clear.

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

\documentclass[12pt]{article}

% PACKAGES

\usepackage{fontspec}
\usepackage{xltxtra}
\defaultfontfeatures{Mapping=tex-text}
\setromanfont[Mapping=tex-text]{Linux Libertine O}
\setsansfont[Scale=MatchLowercase,Mapping=tex-text]{Linux Biolinum O}
\setmonofont[Scale=MatchLowercase]{Linux Libertine Mono O}
\usepackage{ruby}
\usepackage{setspace}

\begin{document} % ==============================================================

\newfontfamily{\jpn}[Scale=0.85]{Hiragino Kaku Gothic Pro}
\newcommand{\J}[2]{\renewcommand\rubysep{-1.9ex}{\jpn \ruby{#1}{#2}}}

\newfontfamily{\chn}{STKaiti}
\newcommand{\C}[2]{\renewcommand\rubysep{-4.9ex}{\chn \ruby{#1}{\textsf{#2}}}}

\doublespace
\Large

I'd like to include both Chinese (e.g. \C{内}{nèi}\C{忧}{yōu}\C{外}{wǎi}\C{患}{huàn}) and Japanese (e.g. \J{内}{ない}\J{憂}{ゆう}\J{外}{がい}\J{患}{かん}) text, \textit{inline} with English text, and with ruby text (pronunciation), as shown here.  Does there exist a convenient method for distributing the \texttt{\textbackslash sf} (or preferably \texttt{\textbackslash textsf\{\}}), across all the \texttt{\textbackslash ruby} calls to generate the Pīnyīn (the text below the Chinese)?

\end{document}

Note: I removed xunicode from the header because it's automatically loaded by fontspec.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.