%%
%% This is file `bibunits.sty',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% bibunits.dtx  (with options: `package')
%%
%% IMPORTANT NOTICE:
%%
%% This work may be distributed and/or modified under the conditions of
%% the LaTeX Project Public License, either version 1.3 of this license
%% or any later version. The latest version of this license is in
%% http://www.latex-project.org/lppl.txt and version 1.3 or later is
%% part of all distributions of LaTeX version 2003/12/01 or
%% later.
%%
%% This work has the LPPL maintenance status "maintained". The Current
%% Maintainer of this work is Thorsten Hansen.
%%
%% Any modified versions of this file must be renamed with new filenames
%% distinct from bibunits.sty.
%%
%% This is a generated file. It may not be distributed without the
%% original source file bibunits.dtx.
%%
%% To produce the documentation run bibunits.dtx through LaTeX.
%%
%%
%% Package `bibunits' to use with LaTeX2e.
%%
%% Copyright (C) 1999--2005 Thorsten Hansen
%%
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{bibunits}
          [2004/05/12 v2.4 Multiple bibliographies in one document.]
\newif\iflabelstoglobalaux \labelstoglobalauxfalse
\DeclareOption{labelstoglobalaux}{\labelstoglobalauxtrue}
\newif\ifglobalcitecopy
\globalcitecopyfalse
\DeclareOption{globalcitecopy}{\globalcitecopytrue}
\DeclareOption{sectionbib}{%
  \AtBeginDocument{%
    \let\stdthebibliography\thebibliography
    \def\thebibliography{%
      \let\chapter\section
      \stdthebibliography}}}
\DeclareOption{subsectionbib}{%
  \AtBeginDocument{%
    \let\stdthebibliography\thebibliography
    \def\thebibliography{%
      \let\chapter\subsection
      \let\section\subsection
      \stdthebibliography}}}
\ProcessOptions
\newwrite\@bibunitaux
\newcount\@bibunitauxcnt \@bibunitauxcnt=0
\def\@bibunitname{bu\the\@bibunitauxcnt}
\newif\if@starredversion
\let\std@cite\cite
\DeclareRobustCommand\bu@cite{%
  \@ifstar
    {\@starredversiontrue\std@cite}%
    {\@starredversionfalse\std@cite}%
}
\AtBeginDocument{%
  \@ifpackageloaded{natbib}%
  {%
    \NAT@set@cites \let\std@@citex\@citex
    \def\bu@@citex[#1][#2]#3{%
      \@startbibunitorrelax
      \leavevmode
      \begingroup\let\@auxout\@bibunitaux\std@@citex[#1][#2]{#3}\endgroup
      \ifglobalcitecopy
        \std@nocite{#3}%
      \fi
    }%
  }%
  {%
    \@ifpackageloaded{cite}%
    {%
      \let\std@@citew\@citew
      \def\bu@@citew#1{%
        \@startbibunitorrelax
        \leavevmode
        {\let\@auxout\@bibunitaux \std@@citew{#1}}%
        \ifglobalcitecopy
          \@nocite{#1}%
        \else
          \if@starredversion
            \@nocite{#1}%
          \fi
        \fi
      }
      \let\std@@citex\@citex
      \def\bu@@citex[#1]#2{%
        \@startbibunitorrelax
        \leavevmode
        {\let\@auxout\@bibunitaux \std@@citex[#1]{#2}}%
        \ifglobalcitecopy
          \@nocite{#2}%
        \else
          \if@starredversion
            \@nocite{#2}%
          \fi
        \fi
      }
    }%
    {%
      \@ifpackageloaded{overcite}%
      {%
        \PackageWarningNoLine{bibunits}%
          {Obsolete package overcite loaded. Use package cite which
            option [superscript] instead}%
        \let\std@@citew\@citew
        \def\bu@@citew#1{%
          \@startbibunitorrelax
          \leavevmode
          {\let\@auxout\@bibunitaux \std@@citew{#1}}%
          \ifglobalcitecopy
            \@nocite{#1}%
          \else
            \if@starredversion
              \@nocite{#1}%
            \fi
          \fi
        }
        \let\std@@citex\@citex
        \def\bu@@citex[#1]#2{%
          \@startbibunitorrelax
          \leavevmode
          {\let\@auxout\@bibunitaux \std@@citex[#1]{#2}}%
          \ifglobalcitecopy
            \@nocite{#2}%
          \else
            \if@starredversion
              \@nocite{#2}%
            \fi
          \fi
        }
      }%
      {%
        \@ifpackageloaded{jurabib}%
        {%
           \let\std@@citex\@citex
          \def\bu@@citex[#1][#2]#3{%
            \@startbibunitorrelax
            \leavevmode
            {\let\@auxout\@bibunitaux \std@@citex[#1][#2]{#3}}%
            \ifglobalcitecopy
              \std@nocite{#3}%
            \else
              \if@starredversion
                \std@nocite{#3}%
              \fi
            \fi
          }%
        }%
        {%
          \let\std@@citex\@citex
          \def\bu@@citex[#1]#2{%
            \@startbibunitorrelax
            \leavevmode
            {\let\@auxout\@bibunitaux \std@@citex[#1]{#2}}%
            \ifglobalcitecopy
              \std@nocite{#2}%
            \else
              \if@starredversion
                \std@nocite{#2}%
              \fi
            \fi
          }%
        }%
      }%
    }%
  }%
}%
\let\std@nocite\nocite
\def\bu@nocite{%
  \@ifstar
    {\@starredversiontrue\@bu@nocite}%
    {\@starredversionfalse\@bu@nocite}%
}
\def\@bu@nocite#1{%
  \@startbibunitorrelax
  {\let\@auxout\@bibunitaux \std@nocite{#1}}%
  \ifglobalcitecopy
    \std@nocite{#1}%
  \else
    \if@starredversion
      \std@nocite{#1}%
    \fi
  \fi
}
\def\bu@bibdata{\jobname}
\AtBeginDocument{%
  \iflabelstoglobalaux
  \else
    \let\orig@bibliography\bibliography
    \def\bibliography#1{%
      \if@filesw
        \immediate\openout\@bibunitaux bu.aux
        \immediate\write\@mainaux{\string\@input{bu.aux}}%
      \fi
      \orig@bibliography{#1}%
      \if@filesw
        \immediate\closeout\@bibunitaux
      \fi
    }%
  \fi
  \let\std@bibliography\bibliography
}
\def\bu@bibliography{%
  \@ifstar
    {\@starredversiontrue\@bu@bibliography}%
    {\@starredversionfalse\@bu@bibliography}%
}
\def\@bu@bibliography#1{%
  \defaultbibliography{#1}%
  \if@starredversion
  \else
    \std@bibliography{#1}%
  \fi
}
\def\defaultbibliography#1{%
  \if@filesw
    \immediate\write\@auxout{\string\gdef\string\bu@bibdata{#1}}%
  \fi
  \gdef\bu@bibdata{#1}%
}
\def\bu@bibstyle{plain}
\let\std@bibliographystyle\bibliographystyle
\def\bu@bibliographystyle{%
  \@ifstar
    {\@starredversiontrue\@bu@bibliographystyle}%
    {\@starredversionfalse\@bu@bibliographystyle}%
}
\def\@bu@bibliographystyle#1{%
  \defaultbibliographystyle{#1}%
  \if@starredversion
  \else
    \std@bibliographystyle{#1}%
  \fi
}
\def\defaultbibliographystyle#1{%
  \if@filesw
    \immediate\write\@auxout{\string\gdef\string\bu@bibstyle{#1}}%
  \fi
  \gdef\bu@bibstyle{#1}%
}
\def\bibunit{%
  \global\let\cite\bu@cite
  \global\let\@citex\bu@@citex
  \global\let\@citew\bu@@citew
  \global\let\nocite\bu@nocite
  \global\let\@startbibunitorrelax\@startbibunit
  \global\let\@finishbibunit\relax
  \@ifnextchar[{\@bibunitx}{\@bibunitx[\bu@bibstyle]}%
}
\def\@bibunitx[#1]{\gdef\@localbibstyle{#1}}
\def\endbibunit{%
  \global\let\cite\std@cite
  \global\let\@citex\std@@citex
  \global\let\@citew\std@@citew
  \global\let\nocite\std@nocite
  \@finishbibunit
  \@input{bu.aux}%
}
\def\@startbibunit{%
  \global\let\@startbibunitorrelax\relax
  \global\let\@finishbibunit\@finishstartedbibunit
  \global\advance\@bibunitauxcnt 1
  \if@filesw
    {\endlinechar-1
    \@input{\@bibunitname.aux}}%
    \immediate\openout\@bibunitaux\@bibunitname.aux
    \immediate\write\@bibunitaux{\string\bibstyle{\@localbibstyle}}%
  \fi
}
\let\@finishbibunit\relax
\def\@finishstartedbibunit{%
  \if@filesw
    \immediate\closeout\@bibunitaux
  \fi
  \ifx\bibunits@rerun@warning\@empty
    \if@filesw
       {\endlinechar-1
       \let\@namedef\@xtestdef
       \@input{\@bibunitname.aux}}%
    \fi
  \fi
}
\let\bibunits@rerun@warning\@empty
\AtEndDocument\bibunits@rerun@warning
\def\@xtestdef #1#2{%
  \def\reserved@a{#2}%
  \expandafter\ifx\csname#1\endcsname\reserved@a
  \else
    \gdef\bibunits@rerun@warning{%
      \PackageWarningNoLine{bibunits}{Label(s) may have changed.
        Rerun to get cross-references right}}%
  \fi
}
\let\old@bibunit\@gobble
\def\@bibunit{\endbibunit\bibunit\old@bibunit}
\def\@endbibunit{}
\def\bibliographyunit{%
  \@endbibunit
  \@ifnextchar[{\@bibliographyunit}{%
    \global\let\old@bibunit\@gobble
    \global\let\bibliography\std@bibliography
    \global\let\bibliographystyle\std@bibliographystyle
    \endbibunit
    \gdef\@endbibunit{}}%
}
\def\@bibliographyunit[#1]{%
  \global\let\bibliography\bu@bibliography
  \global\let\bibliographystyle\bu@bibliographystyle
  \global\let\old@bibunit#1
  \global\let#1\@bibunit
  \gdef\@endbibunit{\global\let#1\old@bibunit}%
}
\def\putbib{\@ifnextchar[{\@putbib}{\@putbib[\bu@bibdata]}}
\def\@putbib[#1]{%
  \@startbibunitorrelax
  \if@filesw
    \immediate\write\@bibunitaux{\string\bibdata{#1}}%
  \fi
  \@input@{\@bibunitname.bbl}%
}
\AtBeginDocument{%
  \iflabelstoglobalaux
  \else
    \let\std@bibitem\@bibitem
    \let\std@lbibitem\@lbibitem
    \def\@bibitem#1{%
      \let\temp@auxout\@auxout
      \let\@auxout\@bibunitaux
      \std@bibitem{#1}%
      \let\@auxout\temp@auxout
    }
    \def\@lbibitem[#1]#2{%
      \let\temp@auxout\@auxout
      \let\@auxout\@bibunitaux
      \std@lbibitem[#1]{#2}%
      \let\@auxout\temp@auxout
    }
  \fi
}
\def\remequivalent#1\from#2{%
  \let\given=#1%
  \ifx#2\empty
  \else
    \edef#2{\expandafter\plugh#2\plugh}%
  \fi
}
\def\plugh\do#1#2{%
  \ifx#1\given
  \else
    \noexpand\do\noexpand#1%
  \fi
  \ifx#2\plugh
    \hgulp\fi\plugh#2%
}
\def\hgulp\fi\plugh\plugh{\fi}
\remequivalent\bibcite\from\@preamblecmds
\AtBeginDocument{%
  \@ifpackageloaded{natbib}%
    {\renewcommand\bibcite[2]{\global\@namedef{b@#1\@extra@binfo}{#2}}}%
    {\renewcommand\bibcite[2]{\global\@namedef{b@#1}{#2}}}%
}
\AtBeginDocument{%
  \@ifundefined{bbl@redefine}%
  {}%
  {%
    \bbl@redefine\@input#1{%
      \@safe@activestrue\org@@input{#1}\@safe@activesfalse}%
    \@ifpackageloaded{natbib}%
    {%
      \bbl@redefine\std@@citex[#1][#2]#3{%
        \@safe@activestrue\org@std@@citex[#1][#2]{#3}\@safe@activesfalse}%
      \bbl@redefine\bu@@citex[#1][#2]#3{%
        \@safe@activestrue\org@bu@@citex[#1][#2]{#3}\@safe@activesfalse}%
    }%
    {
      \@ifpackageloaded{jurabib}%
      {%
        \bbl@redefine\std@@citex[#1][#2]#3{%
          \@safe@activestrue\org@std@@citex[#1][#2]{#3}\@safe@activesfalse}%
        \bbl@redefine\bu@@citex[#1][#2]#3{%
          \@safe@activestrue\org@bu@@citex[#1][#2]{#3}\@safe@activesfalse}%
      }%
      {% neither natbib nor jurabib loaded
        \bbl@redefine\std@@citex[#1]#2{%
          \@safe@activestrue\org@std@@citex[#1]{#2}\@safe@activesfalse}%
      }%
    }%
  }%
}
\endinput
%%
%% End of file `bibunits.sty'.
