%   nruby.sty	(NAIST ruby macro)
%	version 1.1	1993-12-25
%	version 2.0	1994-02-13
%		by T.Ogihara	ogihara@itc.aist-nara.ac.jp
%
%   Usage: \ruby{word}{ruby}

\typeout{`nruby' V.2.0 <13 Dec 93> by T.Ogihara.}

\def\rubysize{\tiny}

\def\ruby#1#2{\leavevmode{%
\setbox1=\hbox{#1}\setbox2=\hbox{\rubysize#2}%
\ifdim\wd1>\wd2\setbox2=\hbox to\wd1{\rubysize\sparse{#2}}%
\else\ifdim\wd1<\wd2\setbox1=\hbox to\wd2{\sparse{#1}}\fi%
\fi%
\vbox{\baselineskip.1em\hrule height.3em width0pt depth0pt\box2\box1}}}

% English mode was deleted (Ver.2.0).

\let\rubie\ruby

% To use '@' as ruby macro, you must use \useruby first.
%   Usage: @word(ruby)

\def\rubii#1(#2){\ruby{#1}{#2}}
\let\dospecialsorig\dospecials
\def\mydospecials{\def\dospecials{\dospecialsorig\makeatother}}
\catcode`\@=\active
\def\useruby{\mydospecials\catcode`\@=\active\let@=\rubii}
\catcode`\@=11
\def\nouseruby{\makeatother\let\dospecials\dospecialsorig}
\let\userubie\useruby
\let\nouserubie\nouseruby


% \boten adds emphasizing dots on each character.
%   Usage: \boten@TEXT@
%	where '@' can be any char.

\def\boten#1{\let\do@next=\boten@tail\let\endtail=#1\boten@tail}
\def\boten@tail#1#2{\setbox1=\hbox{#1}%
\vbox{\baselineskip.1em\hrule height.3em width0pt depth0pt%
\hbox to\wd1{\hfil\rubysize$\bullet$\hfil}\box1}%
\penalty\hyphenpenalty\if\endtail#2\let\do@next=\feed@One\fi\do@next#2}
\def\feed@One#1{\relax}

%	sparse
%	Usage1: \sparse[20mm]{TEXT}
%	Usage2: \sparse*[20mm]{TEXT}
%	Usage3: \sparse{TEXT}  or  \sparse*{TEXT}
%
\def\sparselist#1{\hfill\let\do@next=\do@tail\let\endtail=#1\do@tail}
\def\do@tail#1#2{#1%
  \if\endtail#2\let\do@next=\feed@one\else\hfill\fi\do@next#2}
\def\feed@one#1{\hfill}

\def\sparseList#1{\let\do@next=\do@Tail\let\endtail=#1\do@Tail}
\def\do@Tail#1#2{#1%
  \if\endtail#2\let\do@next=\feed@One\else\hfill\fi\do@next#2}
% \def\feed@One#1{\relax}
%
% Thanx to Iwakuma & Furukawa
%
\def\sparse{\@ifstar{\let\sparse@skip\relax\@sparse}
{\let\sparse@skip\hss\@sparse}}
\def\@sparse{\@ifnextchar [{\bx@sparse}{\op@sparse}}
\def\bx@sparse[#1]#2{\hbox to#1{\op@sparse{#2}}}
\def\op@sparse#1{\sparse@skip%
 \@ifundefined{jintercharskip}{%
 \kanjiskip=0pt plus 1fil\xkanjiskip=\kanjiskip #1}{%
 \jintercharskip=0pt plus 1fil\jasciikanjiskip=\jintercharskip #1}\sparse@skip}
%
\endinput
