% Save file as: BIBPERINCLUDE.STY      Source: FILESERV@SHSU.BITNET  
% Note: This style originally appeared in:
% TeXhax Digest    Saturday,  August 10, 1991  Volume 91 : Issue 034
%
% bibperinclude.sty                             25 Jun 91
%------------------------------------------------------------
% Copyright 1991 by Joachim Schrod. <xitijsch@ddathd21.bitnet>
%
% Allows multiple \bibliography tags in one document.
% Usable for collections, journals etc.
% Each tag must be in an include file, but there a \bibliography tag was not
%       functionable anyhow. (Note: include means \include, not \input!)
% This does not work with nested \include's, when \bibliography is
%       called after \include within a part.
%
% NOTE: This is a kludge !!
%       Check for changes in latex.tex !!
%       Of course, the whole stuff should be handled more generally
%               in LaTeX/BibTeX (it would be VERY easy) !!
%
% This program is free software; you can redistribute it and/or modify
% it under the terms of the GNU General Public License as published by
% the Free Software Foundation; either version 1, or (at your option)
% any later version.
%
% This program is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
% GNU General Public License for more details.
%
% You should have received a copy of the GNU General Public License
% along with this program; if not, write to the Free Software
% Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
%
% js:   Joachim Schrod          <xitijsch@ddathd21.bitnet>
%
% 25 Jun 91 js: first release
%
% CONCEPT OVERVIEW:
%
% If a \bibliography tag is given in an include file, a \bibdata tag
% is written to the aux file of this included part. BibTeX will run on
% this aux file and produce a bbl file. But the \bibliography tag will
% try to read the bbl file \jobname.bbl -- which, of course, will not
% exist.
%    This leads to a trivial change: \bibliography now reads the file
% BibTeX produces.
%
%
%               Changing software?
%               ``When in doubt, use brute force''  [D. Ritchie]
%
% The implementation here is problematic as internal macros of LaTeX
% are changed (\bibliography and \@include). The original definitions
% are cited below, they were taken from the latex.tex version as of
% January 14, 1991.
%     You are warned.
%
% btw, please note: the percents in the code below are not there by
% accident, they are needed (and you will not need more...) Furthermore
% I think the code is now more readable ;-)
%
% \bibliography now does not read \jobname.bbl any more but \@bblfile.
% The default binding for \@bblfile is \@mainbblfile, i.e., \jobname.bbl.
% We don't need a blank in the name as it is read with \@input which
% appends a \relax.

\def\@mainbblfile{\jobname.bbl}
\let\@bblfile=\@mainbblfile

%%%%%%%%%%%%%%%% original definition
%%%
% \def\bibliography#1{\if@filesw\immediate\write\@auxout{\string\bibdata{#1}}\fi
%   \@input{\jobname.bbl}}
%%%
%%%%%%%%%%%%%%%%

\def\bibliography#1{%
    \if@filesw
        \immediate\write\@auxout{\string\bibdata{#1}}%
    \fi
    \@input{\@bblfile}%                         %%%% change
    }

% \@include (called by \include) now defines \@bblfile before it inputs
% the document part. It is redefined again later.

%%%%%%%%%%%%%%%% original definition
%%%
%%% \def\@include#1 {\clearpage
%%% \if@filesw \immediate\write\@mainaux{\string\@input{#1.aux}}\fi
%%% \@tempswatrue\if@partsw \@tempswafalse\edef\@tempb{#1}\@for
%%% \@tempa:=\@partlist\do{\ifx\@tempa\@tempb\@tempswatrue\fi}\fi
%%% \if@tempswa \if@filesw \let\@auxout=\@partaux
%%% \immediate\openout\@partaux #1.aux
%%% \immediate\write\@partaux{\relax}\fi\@input{#1.tex}\clearpage
%%% \@writeckpt{#1}\if@filesw \immediate\closeout\@partaux \fi
%%% \let\@auxout=\@mainaux\else\@nameuse{cp@#1}\fi}
%%%
%%%%%%%%%%%%%%%%

\def\@include#1 {%
   \clearpage
   \if@filesw
       \immediate\write\@mainaux{\string\@input{#1.aux}}%
   \fi
   \@tempswatrue
   \if@partsw
       \@tempswafalse
       \edef\@tempb{#1}%
       \@for \@tempa:=\@partlist \do{%
           \ifx \@tempa\@tempb \@tempswatrue \fi
           }%
    \fi
    \if@tempswa
        \if@filesw
            \let\@auxout\@partaux
            \immediate\openout\@partaux #1.aux          % Blank!
            \immediate\write\@partaux{\relax}%
        \fi
        \def\@bblfile{#1.bbl}%                          %%%% change
        \@input{#1.tex}%
        \clearpage
        \let\@bblfile\@mainbblfile                      %%%% change
        \@writeckpt{#1}%
        \if@filesw
            \immediate\closeout\@partaux
        \fi
        \let\@auxout\@mainaux
    \else
        \@nameuse{cp@#1}%
    \fi
    }
\endinput
