%% directory.sty
%% Copyright 1999 Christophe Geuzaine
%
% This program can be redistributed and/or modified under the terms
% of the LaTeX Project Public License distributed from CTAN
% archives in directory macros/latex/base/lppl.txt; either
% version 1 of the License, or (at your option) any later version.
%
% LaTeX style file `directory.sty'
%
% For use in conjunction with 'address.bst', 'phone.bst', 
% 'email.bst', 'birthday.bst', 'letter.bst'
% 
% Christophe.Geuzaine@advalvas.be
%
% Last modified 26/08/1999
% 
\newif\if@splitversion\@splitversionfalse
\newif\if@breakversion\@breakversionfalse
%
\DeclareOption{split}{\@splitversiontrue}
\DeclareOption{break}{\@breakversiontrue}
%
\ProcessOptions*
%
\RequirePackage{url}
\newdimen\dirindent
\newdimen\dirsep
\newdimen\dirparindent
%
% ------------------------------------------------------------ 
%  C U S T O M I Z A T I O N   C O M M A N D S 
% ------------------------------------------------------------ 
% 
\setlength{\dirindent}            {3em}
\setlength{\dirparindent}         {0em}
\setlength{\dirsep}               {3ex}
\newcommand{\dirand}              {and}
\newcommand{\dirsymbol}           {}
\newcommand{\dirbirthday}         {$\star$~}
\newcommand{\dirprivate}          {\emph{p}~}
\newcommand{\dirresidence}        {\emph{r}~}
\newcommand{\dirwork}             {\emph{w}~}
\newcommand{\dirnote}             {$\triangleright$~}
\newcommand{\dirnickname}         {}
\newcommand{\diraddress}          {}
  \newcommand{\dirpaddress}       {\diraddress}
  \newcommand{\dirraddress}       {\diraddress}
  \newcommand{\dirwaddress}       {\diraddress}
\newcommand{\dirphone}            {phn: }
  \newcommand{\dirpphone}         {\dirphone}
  \newcommand{\dirrphone}         {\dirphone}
  \newcommand{\dirwphone}         {\dirphone}
\newcommand{\dirfax}              {fax: }
  \newcommand{\dirpfax}           {\dirfax}
  \newcommand{\dirrfax}           {\dirfax}
  \newcommand{\dirwfax}           {\dirfax}
\newcommand{\diremail}            {}
  \newcommand{\dirpemail}         {\diremail}
  \newcommand{\dirremail}         {\diremail}
  \newcommand{\dirwemail}         {\diremail}
\newcommand{\dirurl}              {}
  \newcommand{\dirpurl}           {\dirurl}
  \newcommand{\dirrurl}           {\dirurl}
  \newcommand{\dirwurl}           {\dirurl}
\newcommand{\diraccount}          {acc: }
  \newcommand{\dirpaccount}       {\diraccount}
  \newcommand{\dirraccount}       {\diraccount}
  \newcommand{\dirwaccount}       {\diraccount}
\newcommand{\dirtitle}            {}
\newcommand{\dirname}             {}
\newcommand{\Dirlabel}[1]         {\textbf{#1}}
\newcommand{\Dirheader}[1]        {\newpage\markboth{\MakeUppercase{#1}}{\MakeUppercase{#1}}}
\newcommand{\Dirbirthday}[2]      {{\number#1}/{\number#2}}
\newcommand{\Dirbirthyear}[1]     {/{#1}}
\newcommand{\DirbirthyearAlone}[1]{{#1}}
\newcommand{\Dirnickname}[1]      {(aka {#1})}
\newcommand{\Diraddress}[1]       {{#1}}
  \newcommand{\Dirpaddress}[1]    {\Diraddress{#1}}
  \newcommand{\Dirraddress}[1]    {\Diraddress{#1}}
  \newcommand{\Dirwaddress}[1]    {\Diraddress{#1}}
\newcommand{\Dirphone}[1]         {{#1}}
  \newcommand{\Dirpphone}[1]      {\Dirphone{#1}}
  \newcommand{\Dirrphone}[1]      {\Dirphone{#1}}
  \newcommand{\Dirwphone}[1]      {\Dirphone{#1}}
\newcommand{\Dirfax}[1]           {{#1}}
  \newcommand{\Dirpfax}[1]        {\Dirfax{#1}}
  \newcommand{\Dirrfax}[1]        {\Dirfax{#1}}
  \newcommand{\Dirwfax}[1]        {\Dirfax{#1}}
\newcommand{\Diremail}[1]         {\url{#1}}
  \newcommand{\Dirpemail}[1]      {\Diremail{#1}}
  \newcommand{\Dirremail}[1]      {\Diremail{#1}}
  \newcommand{\Dirwemail}[1]      {\Diremail{#1}}
\newcommand{\Dirurl}[1]           {\url{#1}}
  \newcommand{\Dirpurl}[1]        {\Dirurl{#1}}
  \newcommand{\Dirrurl}[1]        {\Dirurl{#1}}
  \newcommand{\Dirwurl}[1]        {\Dirurl{#1}}
\newcommand{\Diraccount}[1]       {\url{#1}}
  \newcommand{\Dirpaccount}[1]    {\Diraccount{#1}}
  \newcommand{\Dirraccount}[1]    {\Diraccount{#1}}
  \newcommand{\Dirwaccount}[1]    {\Diraccount{#1}}
\newcommand{\Dirtitle}[1]         {{#1}}
\newcommand{\Dirname}[1]          {{#1}}
\newcommand{\Dirnote}[1]          {{#1}}
%
% ------------------------------------------------------------ 
%  D I R E C T O R Y
% ------------------------------------------------------------ 
%
\def\dirbegin{\string\begin{tabular}{@{}l@{}}}
\def\dirnext{\string\\}
\def\dirbreak{\dirnext} %% this will be redefined for phonebooks and addressbooks
\def\dirend{\string\end{tabular}}
%
% \diritem
%
\def\diritem{\@ifnextchar[\@diritem\@ldiritem}
\def\@diritem[#1]#2{%
  \item\hspace{-\dirindent}\@dirlabel{#1}%
  \if@filesw
    {\let\protect\noexpand%
     \immediate
     \write\@auxout{\string\bibcite{#2}{#1}}}
  \fi
  \ignorespaces}
\def\@ldiritem#1#2{%
  \if@filesw
    {\let\protect\noexpand%
     \immediate
     \write\@auxout{\string\bibcite{#2}{#1}}}
  \fi
  \ignorespaces}
%
% \directory
%
\newcommand*\directory[2][bbl]{%
  \if@filesw
    \immediate\write\@auxout{\string\bibdata{#2}}%
  \fi
  \@input@{\jobname.#1}}
%
% \directorystyle
%
\def\directorystyle#1{%
  \ifx\@begindocumenthook\@undefined\else
    \expandafter\AtBeginDocument
  \fi
    {\if@filesw
        \immediate\write\@auxout{\string\bibstyle{#1}}%
     \fi}}
%
% \@dirlabel
%
\def\@dirlabel#1{\Dirlabel{#1}}
%
% \dir
%
\def\dir{\@ifnextchar [{\@tempswatrue\@directorycitex}%
  {\@tempswafalse\@directorycitex[]}}
\def\@directorycitex[#1]#2{%
  \let\@citea\@empty
  \@directorycite{\@for\@citeb:=#2\do
    {\@citea\def\@citea{,\penalty\@m\ }%
     \edef\@citeb{\expandafter\@firstofone\@citeb}%
     \if@filesw\immediate\write\@auxout{\string\citation{\@citeb}}\fi
     \@ifundefined{b@d.\@citeb}{\mbox{\reset@font\bfseries ?}%
       \G@refundefinedtrue\@latex@warning
       {Directory citation `#2' on page \thepage \space undefined}}%
%    {\hbox{\csname b@d.\@citeb\endcsname}}}}{#1}}
     {{\let\nobreakspace\space\csname b@d.\@citeb\endcsname}}}}{#1}}
%
% \pdir
%
\def\pdir{\@ifnextchar [{\@tempswatrue\@pdirectorycitex}%
  {\@tempswafalse\@pdirectorycitex[]}}
\def\@pdirectorycitex[#1]#2{%
  \let\@citea\@empty
  \@directorycite{\@for\@citeb:=#2\do
    {\@citea\def\@citea{,\penalty\@m\ }%
     \edef\@citeb{\expandafter\@firstofone\@citeb}%
     \if@filesw\immediate\write\@auxout{\string\citation{\@citeb}}\fi
     \@ifundefined{b@p.\@citeb}{\mbox{\reset@font\bfseries ?}%
       \G@refundefinedtrue\@latex@warning
       {Private part of directory citation `#2' on page \thepage \space undefined% 
        (probably other directory style than 'letter.bst')}}%
     {\hbox{\csname b@p.\@citeb\endcsname}}}}{#1}}
%
% \rdir
%
\def\rdir{\@ifnextchar [{\@tempswatrue\@rdirectorycitex}%
  {\@tempswafalse\@rdirectorycitex[]}}
\def\@rdirectorycitex[#1]#2{%
  \let\@citea\@empty
  \@directorycite{\@for\@citeb:=#2\do
    {\@citea\def\@citea{,\penalty\@m\ }%
     \edef\@citeb{\expandafter\@firstofone\@citeb}%
     \if@filesw\immediate\write\@auxout{\string\citation{\@citeb}}\fi
     \@ifundefined{b@r.\@citeb}{\mbox{\reset@font\bfseries ?}%
       \G@refundefinedtrue\@latex@warning
       {Residence part of directory citation `#2' on page \thepage \space undefined%
        (probably other directory style than 'letter.bst')}}%
     {\hbox{\csname b@r.\@citeb\endcsname}}}}{#1}}
%
% \wdir
%
\def\wdir{\@ifnextchar [{\@tempswatrue\@wdirectorycitex}%
  {\@tempswafalse\@wdirectorycitex[]}}
\def\@wdirectorycitex[#1]#2{%
  \let\@citea\@empty
  \@directorycite{\@for\@citeb:=#2\do
    {\@citea\def\@citea{,\penalty\@m\ }%
     \edef\@citeb{\expandafter\@firstofone\@citeb}%
     \if@filesw\immediate\write\@auxout{\string\citation{\@citeb}}\fi
     \@ifundefined{b@w.\@citeb}{\mbox{\reset@font\bfseries ?}%
       \G@refundefinedtrue\@latex@warning
       {Work part of directory citation `#2' on page \thepage \space undefined% 
        (probably other directory style than 'letter.bst')}}%
     {\hbox{\csname b@w.\@citeb\endcsname}}}}{#1}}
%
% \nodir
%
\def\nodir#1{\@bsphack
  \@for\@citeb:=#1\do{%
    \edef\@citeb{\expandafter\@firstofone\@citeb}%
    \if@filesw\immediate\write\@auxout{\string\citation{\@citeb}}\fi
    \@ifundefined{b@\@citeb}{\G@refundefinedtrue
        \@latex@warning{Citation `\@citeb' undefined}}{}}%
  \@esphack}
\expandafter\let\csname b@*\endcsname\@empty
%
% \@directorycite
%
\def\@directorycite#1#2{\Dirlabel{#1}\dirsymbol}
%
% ------------------------------------------------------------ 
%  T H E P H O N E B O O K
% ------------------------------------------------------------ 
%
\def\thephonebook{
 \list{}{\partopsep 2ex
         \parsep 0pt
         \labelsep 0ex
         \listparindent\dirparindent 
         \labelwidth\dirindent
         \leftmargin\dirindent
         \itemsep\dirsep}
 \def\dirblock{\space}
 \def\dirgroup{\space}
 \def\direndgroup{}
 \def\dirbreak{\relax\noparindent}
 \def\dirbirf{\dirbirthday}
 \def\dirprif{\dirprivate}
 \def\dirresf{\dirresidence}
 \def\dirworf{\dirwork}
 \def\dirnotf{\dirnote}
}
\def\endthephonebook{\endlist}
%
% ------------------------------------------------------------ 
%  T H E A D D R E S S B O O K
% ------------------------------------------------------------ 
%
\def\theaddressbook{
 \list{}{\partopsep 2ex
         \parsep 0pt
         \labelsep 0ex
         \listparindent\dirparindent
         \labelwidth\dirindent
         \leftmargin\dirindent
         \itemsep\dirsep}
 \if@breakversion
   \def\dirblock{\par}
   \def\dirbreak{\par\noindent}
   \def\dirgroup{}
   \def\direndgroup{}
 \else
   \def\dirblock{\par\nopagebreak}
   \def\dirbreak{\par\nopagebreak\noindent}
   \def\dirgroup{\begingroup\samepage}
   \def\direndgroup{\endgroup}
 \fi
 \def\dirbirf{\leavevmode\llap\dirbirthday}
 \def\dirprif{\leavevmode\llap\dirprivate}
 \def\dirresf{\leavevmode\llap\dirresidence}
 \def\dirworf{\leavevmode\llap\dirwork}
 \def\dirnotf{\leavevmode\llap\dirnote}
}
\def\endtheaddressbook{\endlist}
%
% ------------------------------------------------------------ 
%  sectionning according to first letter in field
% ------------------------------------------------------------ 
%
\if@splitversion
  \def\dirlastletter{-}
  \def\dircheck#1{%
    \if#1\dirlastletter%
    \else\def\dirlastletter{#1}\Dirheader{#1}%
    \fi}
\else
  \def\dircheck#1{}
\fi
%
% ------------------------------------------------------------ 
%  define remaining bbl file commands
% ------------------------------------------------------------ 
%
\def\dirandf{\dirand}
\def\dirnica#1{\dirnickname\Dirnickname{#1}}
\def\dirbira#1#2{\Dirbirthday{#1}{#2}}
\def\dirbiya#1{\Dirbirthyear{#1}}
\def\dirbyra#1{\DirbirthyearAlone{#1}}
\def\dirnota#1{\Dirnote{#1}}
\def\diradda#1{\diraddress\Diraddress{#1}}
  \def\dirpadda#1{\dirpaddress\Dirpaddress{#1}}
  \def\dirradda#1{\dirraddress\Dirraddress{#1}}
  \def\dirwadda#1{\dirwaddress\Dirwaddress{#1}}
\def\dirphoa#1{\dirphone\Dirphone{#1}} 
  \def\dirpphoa#1{\dirpphone\Dirpphone{#1}} 
  \def\dirrphoa#1{\dirrphone\Dirrphone{#1}} 
  \def\dirwphoa#1{\dirwphone\Dirwphone{#1}} 
\def\dirfaxa#1{\dirfax\Dirfax{#1}}
  \def\dirpfaxa#1{\dirpfax\Dirpfax{#1}}   
  \def\dirrfaxa#1{\dirrfax\Dirrfax{#1}}   
  \def\dirwfaxa#1{\dirwfax\Dirwfax{#1}}   
\def\diremaa#1{\diremail\Diremail{#1}} 
  \def\dirpemaa#1{\dirpemail\Dirpemail{#1}} 
  \def\dirremaa#1{\dirremail\Dirremail{#1}} 
  \def\dirwemaa#1{\dirwemail\Dirwemail{#1}} 
\def\dirurla#1{\dirurl\Dirurl{#1}}   
  \def\dirpurla#1{\dirpurl\Dirpurl{#1}}   
  \def\dirrurla#1{\dirrurl\Dirrurl{#1}}   
  \def\dirwurla#1{\dirwurl\Dirwurl{#1}}   
\def\diracca#1{\diraccount\Diraccount{#1}}
  \def\dirpacca#1{\dirpaccount\Dirpaccount{#1}}
  \def\dirracca#1{\dirraccount\Dirraccount{#1}}
  \def\dirwacca#1{\dirwaccount\Dirwaccount{#1}}
\def\dirtita#1{\dirtitle\Dirtitle{#1}}
\def\dirnama#1{\dirname\Dirname{#1}}
%
