%% directory.sty
%% Copyright 1998-2004 Christophe Geuzaine <geuz@geuz.org>
%
% $Id: directory.sty,v 1.10 2004/02/11 16:17:29 geuzaine Exp $
%
% 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'
% 
\newif\if@break\@breakfalse
\newif\if@german\@germanfalse
\newif\if@french\@frenchfalse
\newif\if@longdates\@longdatesfalse
%
\DeclareOption{split}{
  \typeout{^^JWarning: the `split' option is obsolete! Redefine `Dirheader' instead.^^J}
}
\DeclareOption{break}{\@breaktrue}
\DeclareOption{german}{\@germantrue}
\DeclareOption{french}{\@frenchtrue}
\DeclareOption{longdates}{\@longdatestrue}
%
\ProcessOptions*
%
\RequirePackage{url}
%
% ------------------------------------------------------------ 
%  N E W   D I M E N S I O N S
% ------------------------------------------------------------ 
% 
\newlength{\dirindent}     \setlength{\dirindent}    {3em}
\newlength{\dirsep}        \setlength{\dirsep}       {3ex}
\newlength{\dirparindent}  \setlength{\dirparindent} {0em}
\newlength{\dirtablewidth} \setlength{\dirtablewidth}{0.5\textwidth}
%
% ------------------------------------------------------------ 
%  C U S T O M I Z A T I O N   C O M M A N D S 
% ------------------------------------------------------------ 
% 
\if@german
%
% German localization
%
  \newcommand{\dirsymbol}         {}
  \newcommand{\dirbirthday}       {$\star$~}
  \newcommand{\dirnote}           {$\triangleright$~}
  \newcommand{\dirnickname}       {}
  \newcommand{\diraddress}        {}
  \newcommand{\dirand}            {\normalfont{und}}
  \newcommand{\dirprivate}        {\emph{p}~}
  \newcommand{\dirresidence}      {\emph{z}~} % 'Zweiter Wohnsitz'
  \newcommand{\dirwork}           {\emph{b}~} % 'Beruf'
  \newcommand{\dirphone}          {Tel.~} 
  \newcommand{\dircellular}       {Mobil~}
  \newcommand{\dirfax}            {Fax~}
  \newcommand{\diremail}          {}
  \newcommand{\dirurl}            {}
  \newcommand{\diraccount}        {}
  \newcommand{\dirtitle}          {}
  \newcommand{\dirname}           {}
  \if@longdates
    \newcommand{\Dirbirthday}[2]  {{\number#1}.~{\ifcase #2\or Januar\or Februar\or%
                                   M\"arz\or April\or Mai\or Juni\or Juli\or%
                                   August\or September\or Oktober\or November\or%
                                   Dezember\fi}}
    \newcommand{\Dirbirthyear}[1] {~{#1}}
  \else
    \newcommand{\Dirbirthday}[2]  {{\number#1}.{\number#2}.}
    \newcommand{\Dirbirthyear}[1] {{#1}}
  \fi
  \newcommand{\DirbirthyearAlone}[1]{{#1}}
  \newcommand{\Dirnickname}[1]    {(alias \emph{#1})}
\else
\if@french
%
% French localization
%
  \newcommand{\dirsymbol}         {}
  \newcommand{\dirbirthday}       {$\star$~}
  \newcommand{\dirnote}           {$\triangleright$~}
  \newcommand{\dirnickname}       {}
  \newcommand{\diraddress}        {}
  \newcommand{\dirand}            {\normalfont{et}}
  \newcommand{\dirprivate}        {\emph{p}~}
  \newcommand{\dirresidence}      {\emph{r}~}
  \newcommand{\dirwork}           {\emph{b}~} % 'bureau'
  \newcommand{\dirphone}          {t\'el: }
  \newcommand{\dircellular}       {gsm: }
  \newcommand{\dirfax}            {fax: }
  \newcommand{\diremail}          {}
  \newcommand{\dirurl}            {}
  \newcommand{\diraccount}        {cpte: }
  \newcommand{\dirtitle}          {}
  \newcommand{\dirname}           {}
  \if@longdates
    \newcommand{\Dirbirthday}[2]  {{\ifnum #1=1 1er\else\number#1\fi}~%
                                   {\ifcase #2\or janvier\or f\'evrier\or mars\or%
                                   avril\or mai\or juin\or juillet\or ao\^ut\or%
                                   septembre\or octobre\or novembre\or d\'ecembre\fi}}
   \newcommand{\Dirbirthyear}[1]  {~{#1}}
  \else
    \newcommand{\Dirbirthday}[2]  {{\number#1}/{\number#2}}
    \newcommand{\Dirbirthyear}[1] {/{#1}}
  \fi
  \newcommand{\DirbirthyearAlone}[1]{{#1}}
  \newcommand{\Dirnickname}[1]    {(dit \emph{#1})}
\else
%
% Default localization (English)
%
  \newcommand{\dirsymbol}         {}
  \newcommand{\dirbirthday}       {$\star$~}
  \newcommand{\dirnote}           {$\triangleright$~}
  \newcommand{\dirnickname}       {}
  \newcommand{\diraddress}        {}
  \newcommand{\dirand}            {\normalfont{and}}
  \newcommand{\dirprivate}        {\emph{p}~}
  \newcommand{\dirresidence}      {\emph{r}~}
  \newcommand{\dirwork}           {\emph{w}~}
  \newcommand{\dirphone}          {tel: }
  \newcommand{\dircellular}       {mobile: }
  \newcommand{\dirfax}            {fax: }
  \newcommand{\diremail}          {}
  \newcommand{\dirurl}            {}
  \newcommand{\diraccount}        {acc: }
  \newcommand{\dirtitle}          {}
  \newcommand{\dirname}           {}
  \if@longdates
    \newcommand{\Dirbirthday}[2]  {{\ifcase #2\or January\or February\or March\or%
                                   April\or May\or June\or July\or August\or%
                                   September\or October\or November\or December\fi}%
                                   {\space\ifnum #1=1 1st\else\number#1\fi}}
   \newcommand{\Dirbirthyear}[1]  {, {#1}}
  \else
    \newcommand{\Dirbirthday}[2]  {{\number#2}/{\number#1}}
    \newcommand{\Dirbirthyear}[1] {/{#1}}
  \fi
  \newcommand{\DirbirthyearAlone}[1]{{#1}}
  \newcommand{\Dirnickname}[1]    {(aka \emph{#1})}
\fi
\fi

\newcommand{\dirpaddress}       {\diraddress}
\newcommand{\dirraddress}       {\diraddress}
\newcommand{\dirwaddress}       {\diraddress}
\newcommand{\dirpphone}         {\dirphone}
\newcommand{\dirrphone}         {\dirphone}
\newcommand{\dirwphone}         {\dirphone}
\newcommand{\dirpcellular}      {\dircellular}
\newcommand{\dirrcellular}      {\dircellular}
\newcommand{\dirwcellular}      {\dircellular}
\newcommand{\dirpfax}           {\dirfax}
\newcommand{\dirrfax}           {\dirfax}
\newcommand{\dirwfax}           {\dirfax}
\newcommand{\dirpemail}         {\diremail}
\newcommand{\dirremail}         {\diremail}
\newcommand{\dirwemail}         {\diremail}
\newcommand{\dirpurl}           {\dirurl}
\newcommand{\dirrurl}           {\dirurl}
\newcommand{\dirwurl}           {\dirurl}
\newcommand{\dirpaccount}       {\diraccount}
\newcommand{\dirraccount}       {\diraccount}
\newcommand{\dirwaccount}       {\diraccount}
\newcommand{\Dirlabel}[1]       {\textbf{#1}}
%\newcommand{\Dirheader}[1]{\newpage\markboth{\MakeUppercase{#1}}{\MakeUppercase{#1}}}
\newcommand{\Dirheader}[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{\Dircellular}[1]    {{#1}}
\newcommand{\Dirpcellular}[1]   {\Dircellular{#1}}
\newcommand{\Dirrcellular}[1]   {\Dircellular{#1}}
\newcommand{\Dirwcellular}[1]   {\Dircellular{#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}{@{}p{\dirtablewidth}@{}}}
\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@break
   \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
% ------------------------------------------------------------ 
%
\def\dirlastletter{-}
\def\dircheck#1{\if#1\dirlastletter\else\def\dirlastletter{#1}\Dirheader{#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\dircela#1{\dircellular\Dircellular{#1}} 
  \def\dirpcela#1{\dirpcellular\Dirpcellular{#1}} 
  \def\dirrcela#1{\dirrcellular\Dirrcellular{#1}} 
  \def\dirwcela#1{\dirwcellular\Dirwcellular{#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}}
%