% warichu.sty 
% by Shinsaku Fujita 
% Copyright (C) S. Fujita (1995,1996,1998,1999). All rights reserved. 
% Version 1.00 1995/09/09
% Version 1.01 1996/04/07
% Version 1.02 1998/08/24
% Version 1.03 1999/12/14
%
%  作成者: 藤田眞作
%          fujitas@chem.kit.ac.jp
%
%   藤田眞作著「LaTeX本づくりの八衢」所載
%
% Version 1.02 1998/08/24
%   縦組み用の\twarichuを追加
%
%   藤田眞作著「続LaTeX2e階梯・縦組編」所載
%
% Version 1.03  1999/12/14 by S. Fujita
% ぶら下げができるように改良
%   藤田眞作著「入門・縦横文書術」所載
%
%\typeout{Option Style `warichu' by S. Fujita}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%\def\j@urnalname{warichu}
%\def\versi@ndate{August 24, 1998}
%\def\versi@nno{ver1.02}
%\def\copyrighth@lder{SF} % Shinsaku Fujita
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\def\j@urnalname{warichu}
\def\versi@ndate{December 14, 1999}
\def\versi@nno{ver1.03}
\def\copyrighth@lder{S. Fujita} % Shinsaku Fujita
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\typeout{Option Style `\j@urnalname' (\versi@nno) <\versi@ndate>\space 
[\copyrighth@lder]}
\typeout{藤田眞作著「LaTeX本づくりの八衢」所載}
\typeout{藤田眞作著「続LaTeX2e階梯・縦組編」所載}
\typeout{藤田眞作著「入門・縦横文書術」所載}
%
% pLaTeXe vs LaTeX
%
\@ifundefined{tbaselineshift}
{\tbaselineshift=0pt}{}
%
% **************************
% * warichu size selection *
% **************************
\let\warisize=\tiny
% 
% ****************************************************
% * For separating an augument list to each argument *
% ****************************************************
% delimiter == as A==B== ... ==Z
%
\long\def\@fordbleq#1:=#2\do#3{%
%  \edef\@fortmp{#2} % 1996/04/07 by Shinsaku Fujita
  \expandafter\def\expandafter\@fortmp\expandafter{#2}%
  \ifx\@fortmp\@empty \else%
    \expandafter\@dbleql@@p#2==\@nil==\@nil\@@#1{#3}\fi}
\long\def\@dbleql@@p#1==#2==#3\@@#4#5{\def#4{#1}\ifx #4\@nnil \else%
       #5\def#4{#2}\ifx #4\@nnil \else#5\@idbleql@@p #3\@@#4{#5}\fi\fi}
\long\def\@idbleql@@p#1==#2\@@#3#4{\def#3{#1}\ifx #3\@nnil%
%       \let\@nextwhile=\@fornoop \else%
       \expandafter\@fornoop \else%
%      #4\relax\let\@nextwhile=\@idbleql@@p\fi\@nextwhile#2\@@#3{#4}}
      #4\relax\expandafter\@idbleql@@p\fi#2\@@#3{#4}}
%
% \@warichu{割注文字列}
%
\newif\ifnakabu \nakabufalse
\def\warilineskip{%
 \baselineskip=-1000pt \lineskip=.1zh \lineskiplimit=\maxdimen}
\def\wariparfill{\kanjiskip=0pt plus1fil minus.1zw%
 \let\xkanjiskip=\kanjiskip%
 \parfillskip=0pt}
\let\warichuowari=\relax
%%\let\warichuowari=\wariparfill
%
\def\@warichu#1{\leavevmode%
\setbox0=\hbox{\warisize #1}%
\setbox1=\hbox{\warisize あ}%
\dimen1=.5\ht1 \dimen0=0pt \@tempcnta=\z@
\@whiledim\dimen0<\wd0\do%
{\advance\dimen0 by\wd1 \advance\@tempcnta\@ne}%
%\typeout{文字数\the\@tempcnta; 長さ\the\dimen0; 文字列長さ\the\wd0}
\dimen2=\dimen0 \advance\dimen2 -\wd0
\ifdim\dimen2<0.05pt% \typeout{OK #1; \the\@tempcnta}
 \ifodd\@tempcnta \advance\@tempcnta\@ne\fi
 \divide\@tempcnta by2\relax
 \dimen0=\the\@tempcnta \wd1\relax
\else
 \divide\dimen0 by2\relax
\fi
\ifnakabu\dimen0=\hsize\fi
 \setbox2=\vbox{\hsize=\dimen0\warilineskip
 \warisize\noindent #1\warichuowari}%
 \leavevmode\lower\dimen1\hbox{\box2}}
%
% \w@richu{前部割注==中部割注== ... ==後部割注}
%
\newif\ifwarigaki \warigakifalse
\def\w@richu#1{%
\@tempcnta=0
\@fordbleq\member:=#1\do{\global\advance\@tempcnta\@ne}%
\ifnum\@tempcnta=1\relax
\ifwarigaki
 \begingroup\let\warichuowari=\relax\@warichu{#1}%
\else
 \begingroup\let\warichuowari=\relax(\@warichu{#1})%
\fi\endgroup
\else
 \@tempcntb=0
 \@fordbleq\member:=#1\do{%
 \advance\@tempcntb\@ne
 \ifnum\@tempcntb=1
  \begingroup\let\warichuowari=\wariparfill
 \ifwarigaki
  \expandafter\@warichu{\member}%
 \else
  (\expandafter\@warichu{\member}%
 \fi\endgroup\break
 \else
  \ifnum\@tempcntb=\@tempcnta
   \begingroup \let\warichuowari=\relax
    \ifwarigaki
     \expandafter\@warichu{\member}
    \else
     \expandafter\@warichu{\member})%
    \fi\endgroup
  \else
   \begingroup\nakabutrue\let\warichuowari=\wariparfill
   \expandafter\@warichu{\member}\endgroup\break
  \fi\fi}%
 \fi}
%
% 横組み用割注命令
% \warichu{親文字}{前部割注==中部割注== ... ==後部割注}
%
\def\warichu#1#2{\warigakifalse #1\hskip.25\xkanjiskip\w@richu{#2}}
%
% 横組み用割書命令
% \warigaki{前部割注==中部割注== ... ==後部割注}
%
\def\warigaki#1{\warigakitrue\hskip.25\xkanjiskip\w@richu{#1}}
%
% 縦組み割注用括弧
% 全角括弧を二分鋳込みにしておく
%
\def\warikakkol{\hbox to.5zw{\hss\kern-.5zw（}\kern0pt}
\def\warikakkor{\kern0pt\hbox to.5zw{）\kern-.5zw\hss}}
%
% 変更
%
\def\Warikakkol{\hskip.16667zw\hbox to.33333zw{\hss\kern-.66667zw（}%
\kern0pt}
\def\Warikakkor{\kern0pt\hbox to.33333zw{）\kern-.66667zw\hss}%
\hskip.16667zw}
\newif\ifburasage\burasagefalse
%
% 縦組み用割注
%
% ぶら下げができるように改良
% 1999/12/14 by S. Fujita
%
\def\@twarichu#1{\leavevmode%
\setbox0=\hbox{\warisize #1}%
\setbox1=\hbox{\warisize あ}%
\dimen1=.5\ht1 \dimen0=0pt \@tempcnta=\z@
\@whiledim\dimen0<\wd0\do%
{\advance\dimen0 by\wd1 \advance\@tempcnta\@ne}%
%\typeout{文字数\the\@tempcnta; 長さ\the\dimen0; 文字列長さ\the\wd0}%
\dimen2=\dimen0 \advance\dimen2 -\wd0
\ifdim\dimen2<0.05pt
%{\let\。=\relax\let\、=\relax \typeout{OK #1; \the\@tempcnta}}%
 \ifodd\@tempcnta \advance\@tempcnta\@ne\fi
 \divide\@tempcnta by2\relax
 \dimen0=\the\@tempcnta \wd1\relax
%{\let\。=\relax\let\、=\relax \typeout{OK/2 #1; \the\@tempcnta}}%
\else
 \divide\dimen0 by2\relax\fi
\ifnakabu\dimen0=\hsize\fi
%%%%%
 \setbox2=\vbox{\hsize=\dimen0\warilineskip
 \warichuowari
 \warisize\noindent #1%
 \hbox to\dimen0{　\hfill}}%%全角空白
 \setbox2=\vbox{\hsize=\dimen0\unvbox2\setbox4=\lastbox}%
 \setbox2=\vbox{\hsize=\dimen0\unvbox2\unskip}%
%%%%
 \leavevmode
 \dimen3=\ht2 \divide\dimen3 by2
 \dimen4=\dimen3
 \advance\dimen3 by\tbaselineshift
 \advance\dimen3 by-.1zw
 \advance\dimen4 by-\tbaselineshift
 \advance\dimen4 by.1zw
 \dp2=\dimen4\ht2=\dimen3\box2}%
%%
%% 縦組み用割注
%%
%\def\@twarichu#1{\leavevmode%
%\setbox0=\hbox{\warisize #1}%
%\setbox1=\hbox{\warisize あ}%
%\dimen1=.5\ht1 \dimen0=0pt \@tempcnta=\z@
%\@whiledim\dimen0<\wd0\do%
%{\advance\dimen0 by\wd1 \advance\@tempcnta\@ne}%
%%\typeout{文字数\the\@tempcnta; 長さ\the\dimen0; 文字列長さ\the\wd0}
%\dimen2=\dimen0 \advance\dimen2 -\wd0
%\ifdim\dimen2<0.05pt% \typeout{OK #1; \the\@tempcnta}
% \ifodd\@tempcnta \advance\@tempcnta\@ne\fi
% \divide\@tempcnta by2\relax
% \dimen0=\the\@tempcnta \wd1\relax
%\else
% \divide\dimen0 by2\relax
%\fi
%\ifnakabu\dimen0=\hsize\fi
% \setbox2=\vbox{\hsize=\dimen0\warilineskip
% \warisize\noindent #1\warichuowari}%
%% \leavevmode\lower\dimen1\hbox{\box2}}
% \leavevmode
% \dimen3=\ht2 \divide\dimen3 by2
% \dimen4=\dimen3
% \advance\dimen3 by\tbaselineshift
% \advance\dimen3 by-.075zw
% \advance\dimen4 by-\tbaselineshift
% \advance\dimen4 by.075zw
% \dp2=\dimen4\ht2=\dimen3\box2}
%
% \tw@richu{前部割注==中部割注== ... ==後部割注}
%
\def\tw@richu#1{%
\ifwarigaki \let\warikakkol=\relax
\let\warikakkor=\relax\fi
\fboxsep=0pt
\@tempcnta=0
\@fordbleq\member:=#1\do{\global\advance\@tempcnta\@ne}%
\ifnum\@tempcnta=1\relax
%括弧を付ける
 \begingroup\let\warichuowari=\relax
  \ifx\warisize\tiny\warikakkol\else{\large\warikakkol}\fi
  \@twarichu{#1}%
	\ifburasage\kern.125zw\fi%八分アキadded 1999/12/15
  \ifx\warisize\tiny\warikakkor\else{\large\warikakkor}\fi
 \endgroup
\else
 \@tempcntb=0
 \@fordbleq\member:=#1\do{%
 \advance\@tempcntb\@ne
 \ifnum\@tempcntb=1
  \begingroup\let\warichuowari=\wariparfill
%左括弧を付ける
  \ifx\warisize\tiny\warikakkol\else{\large\warikakkol}\fi
  \expandafter\@twarichu{\member}\endgroup\break
 \else
  \ifnum\@tempcntb=\@tempcnta
   \begingroup \let\warichuowari=\relax
%右括弧を付ける
    \expandafter\@twarichu{\member}%
		\ifburasage\kern.125zw\fi%八分アキadded 1999/12/15
    \ifx\warisize\tiny\warikakkor\else{\large\warikakkor}\fi
   \endgroup
  \else
   \begingroup\nakabutrue\let\warichuowari=\wariparfill
   \expandafter\@twarichu{\member}\endgroup\break
  \fi\fi}%
 \fi}
%
%
%
%
%\def\tw@richu#1{%
%\ifwarigaki \let\warikakkol=\relax
%\let\warikakkor=\relax\fi
%\fboxsep=0pt
%\@tempcnta=0
%\@fordbleq\member:=#1\do{\global\advance\@tempcnta\@ne}%
%\ifnum\@tempcnta=1\relax
%%括弧を付ける
% \begingroup\let\warichuowari=\relax
%  \ifx\warisize\tiny\warikakkol\else{\large\warikakkol}\fi
%  \@twarichu{#1}%
%  \ifx\warisize\tiny\warikakkor\else{\large\warikakkor}\fi
% \endgroup
%\else
% \@tempcntb=0
% \@fordbleq\member:=#1\do{%
% \advance\@tempcntb\@ne
% \ifnum\@tempcntb=1
%  \begingroup\let\warichuowari=\wariparfill
%%左括弧を付ける
%  \ifx\warisize\tiny\warikakkol\else{\large\warikakkol}\fi
%  \expandafter\@twarichu{\member}\endgroup\break
% \else
%  \ifnum\@tempcntb=\@tempcnta
%   \begingroup \let\warichuowari=\relax
%%右括弧を付ける
%    \expandafter\@twarichu{\member}%
%    \ifx\warisize\tiny\warikakkor\else{\large\warikakkor}\fi
%   \endgroup
%  \else
%   \begingroup\nakabutrue\let\warichuowari=\wariparfill
%   \expandafter\@twarichu{\member}\endgroup\break
%  \fi\fi}%
% \fi}
%
%
%
% 縦組み用割注命令
% \twarichu{親文字}{前部割注==中部割注== ... ==後部割注}
%
\def\twarichu#1#2{\warigakifalse #1\hskip.25\xkanjiskip\tw@richu{#2}}
%
% 縦組み用割書命令
% \twarigaki{前部割注==中部割注== ... ==後部割注}
%
\def\twarigaki#1{\warigakitrue\hskip.25\xkanjiskip\tw@richu{#1}}
\endinput
