ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/matt_papers/my_CV/bibunits/bibunits.dtx
Revision: 337
Committed: Thu Mar 13 20:09:19 2003 UTC (21 years, 4 months ago) by mmeineke
File size: 57833 byte(s)
Log Message:
*** empty log message ***

File Contents

# User Rev Content
1 mmeineke 337 % \CheckSum{499}
2     %
3     % \iffalse
4     %% Package `bibunits' to use with LaTeX2e.
5     %% Copyright (C) 1999, 2000 by Thorsten Hansen. All rights reserved.
6     %%
7     %
8     %<*dtx>
9     \ProvidesFile{bibunits.dtx}
10     %</dtx>
11     %<package>\NeedsTeXFormat{LaTeX2e}
12     %<package>\ProvidesPackage{bibunits}
13     %<driver>\ProvidesFile{bibunits.drv}
14     % \fi
15     % \ProvidesFile{bibunits.dtx}
16     [2000/10/10 v2.2 Multiple bibliographies in one document.]
17     %
18     % \iffalse
19     %<*driver>
20     \documentclass{ltxdoc}
21     \usepackage{ifthen}
22     %
23     % Sort `General´ before macros starting with `@'.
24     %
25     \makeatletter
26     \def\changes@#1#2#3{%
27     \protected@edef\@tempa{\noexpand\glossary{#1\levelchar
28     \ifx\saved@macroname\@empty
29     \space
30     \actualchar
31     \generalname
32     \else
33     \space % <-- \space added
34     \expandafter\@gobble
35     \saved@macroname
36     \actualchar
37     \string\verb\quotechar*%
38     \verbatimchar\saved@macroname
39     \verbatimchar
40     \fi
41     :\levelchar #3}}%
42     \@tempa\endgroup\@esphack}
43     \makeatother
44     %
45     %
46     %
47     \CodelineIndex
48     \RecordChanges
49     \OnlyDescription
50     \begin{document}
51     \DocInput{bibunits.dtx}
52     \end{document}
53     %</driver>
54     % \fi
55     %
56     % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
57     %
58     % \newcommand{\class}[1]{\textsf{#1}}
59     % \renewcommand*\descriptionlabel[1]{\hspace\labelsep\option{#1}}
60     % \newcommand{\komascript}{KOMA-\textsc{Script}}
61     % \newcommand{\macrott}[1]{\texttt{\symbol{'134}#1}}
62     % \newcommand{\option}[1]{\textsf{#1}}
63     % \newcommand{\package}[1]{\textsf{#1}}
64     %
65     % ^^A
66     % ^^A Rules to separate figures from the text. (Modified from bibtopic.dtx).
67     % ^^A
68     % \newcommand\toprule[1][]{^^A
69     % \ifthenelse{\equal{#1}{}}{^^A
70     % \noindent{\makebox[\textwidth][t]{\hrulefill}}^^A
71     % }{%
72     % \noindent{\makebox[\textwidth][t]{\hrulefill^^A
73     % \raisebox{-.5ex}{ \small\ttfamily#1 }\hrulefill}}^^A
74     % }%
75     % \par\noindent}
76     %
77     % \newcommand\bottomrule{\noindent\rule[\baselineskip]{\textwidth}{.6pt}}
78     %
79     % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
80     %
81     % \hyphenation{bib-lio-gra-phy bib-lio-gra-phies bib-unit bib-units}
82     %
83     % \GetFileInfo{bibunits.dtx}
84     % \title{The \package{bibunits} Package}
85     % \author{Thorsten Hansen\\
86     % \normalsize hansen@neuro.informatik.uni-ulm.de}
87     % \date{\fileversion\quad \filedate}
88     % \maketitle
89     %
90     % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
91     %
92     % \GlossaryPrologue{\section*{{Change History}}%
93     % \markboth{{Change History}}{{Change History}}%
94     % Version 1.0 by Jos\'e Alberto Fern\'andez, Version 1.0a till 2.1
95     % by Thorsten Hansen. Version numbers suffixed with characters have
96     % not been released. Since v2.1, each new version has a `General'
97     % item describing the new feature or the fixed problem,
98     % and local items describing the changes of the code.}
99     %
100     % \changes{v1.0}{1991/09/07}{Initial \LaTeX\ 2.09 version.}
101     % \changes{v1.0a}{1998/10/30}{The same cited item can occur in more than one
102     % bibliography.}
103     % \changes{v1.0b}{1998/11/09}{Auxiliary files are created only for bibunits
104     % which contain cite commands.}
105     % \changes{v1.0c}{1998/11/15}{Extra spaces are no longer introduced,
106     % upgrade to \LaTeXe.}
107     % \changes{v2.0}{1999/07/22}{Documentation.}
108     % \changes{v2.1a}{1999/11/15}{Add bibliography name to table of
109     % contents for compatibility with \komascript\ classes using the option
110     % \option{bibtotoc}.}
111     % \changes{v2.1b}{1999/11/24}{Fixed problem with cite command after
112     % \macrott{paragraph}.}
113     % \changes{v2.1c}{1999/11/24}{New option \option{labelstoglobalaux}.}
114     % \changes{v2.1d}{2000/01/27}{Global labels are no longer overwritten by
115     % local bibunit labels for the same cited item.}
116     % \changes{v2.1e}{2000/03/28}{Compatibility with \package{babel} using
117     % the option \option{frenchb}.}
118     % \changes{v2.1f}{2000/04/02}{Streamlined implementation of starting
119     % bibunits by cite commands.}
120     % \changes{v2.1g}{2000/07/31}{Compatibility with \package{mparhack}.}
121     % \changes{v2.1h}{2000/08/06}{New implementation: global labels are no
122     % longer overwritten by local bibunit labels for the same cited item.}
123     % \changes{v2.1i}{2000/09/30}{Allow \macrott{putbib} to appear before
124     % the first occurrence of a cite within a bibunit.}
125     % \changes{v2.1j}{2000/10/02}{Rename \macrott{@localcite} to
126     % \macrott{@starredversion}, delete macro \macrott{@localcitedefault}.}
127     % \changes{v2.1k}{2000/10/02}{Ignore spaces in arguments for starred
128     % version of \macrott{cite}.}
129     % \changes{v2.1l}{2000/10/03}{New option \option{globalcitecopy}.}
130     % \changes{v2.1m}{2000/10/05}{Compatibility with \package{natbib} and
131     % \package{babel} using the option \option{frenchb}.}
132     % \changes{v2.1n}{2000/10/08}{\package{jurabib} compatibility.}
133     % \changes{v2.1o}{2000/10/09}{Use of \macrott{@input} and
134     % \macrott{@input@} consistent with \LaTeX\ base implementation.}
135     % \changes{v2.2}{2000/10/10}{Documentation.}
136     %
137     % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
138     %
139     %
140     % \begin{abstract}
141     % The \package{bibunits} package allows separate bibliographies for
142     % different units or parts of the text. The units can be chapters,
143     % sections or \texttt{bibunit} environments. The package separates
144     % the citations of each unit of text into a local auxiliary file to
145     % be processed by \BibTeX. The same cited item can occur in more
146     % than one bibliography. A global bibliography can also appear in
147     % the document and citations can be placed in both at the same time.
148     % The package is compatible with a wide variety of packages,
149     % including, but not limited to, \textsf{natbib}, \textsf{overcite}
150     % and \komascript\ classes. It is based on the \package{bibunits}
151     % style by Jos\'e Alberto Fern\'andez.
152     % \end{abstract}
153     %
154     %
155     %
156     % \section{Introduction}
157     %
158     % Suppose, you have different units or parts within your document, and
159     % each unit should have its own bibliography. In this case, you can
160     % use the \package{bibunits} package to do the work.
161     %
162     %
163     % Let's first consider a simple example to see how \package{bibunits}
164     % works (see Fig.~\ref{fig:Example}). We specify two bibunits using the
165     % \textsf{bibunit} environment. The optional parameter specifies the
166     % bibliography style to be used within the bibunits bibliography, in
167     % this case \textsf{plain} for the first and \textsf{alpha} for the
168     % second bibunit. Citations can be made as usual. Similar to the
169     % |\bibliography| command, you have to specify where the bibliography
170     % should appear within a bibunit. This is done using |\putbib|. The
171     % optional parameter specifies the \BibTeX\ files to be used for
172     % generating the bibunits bibliography, in this case \texttt{lit}.
173     %
174     % \begin{figure}[h]
175     % \hspace*{-25mm}\begin{minipage}[t]{0.6\textwidth}
176     % \toprule
177     % {\let\small\footnotesize
178     % \begin{verbatim}
179     % \documentclass{article}
180     % \usepackage{bibunits}
181     %
182     % \begin{document}
183     % \begin{bibunit}[plain]
184     % References to the \TeX book \cite{Knuth:1991}
185     % and to Lamport's \LaTeX\ book, which appears
186     % only in the references\nocite{Lamport:1994}.
187     % \putbib[lit]
188     % \end{bibunit}
189     %
190     % \begin{bibunit}[alpha]
191     % A new bibunit with a different style and a cite
192     % of a Postscript tutorial \cite{Adobe:1985}.
193     % \putbib[lit]
194     % \end{bibunit}
195     %
196     % \end{document}
197     % \end{verbatim}}
198     % \bottomrule
199     % \end{minipage}
200     % \hspace{5mm}
201     % \begin{minipage}[t]{0.65\textwidth}
202     % \toprule
203     % \leftmargini1mm
204     % \begin{quote}
205     % \footnotesize
206     % References to the \TeX book [1]
207     % and to Lamport's \LaTeX\ book, which appears
208     % only in the references.
209     % \let\section\subsubsection
210     % \vspace{-3mm}
211     % \begin{thebibliography}{1}
212     % \bibitem{Knuth:1991}
213     % Donald~E. Knuth.
214     % \newblock {\em The {\TeX} book}.
215     % \newblock Addison-Wesley, Reading, Massachusetts, 1991.
216     % \bibitem{Lamport:1994}
217     % Leslie Lamport.
218     % \newblock {\em {\LaTeX:} A Document Preparation System}.
219     % \newblock Addison-Wesley, Reading, Massachusetts, 2 edition, 1994.
220     % \end{thebibliography}
221     %
222     % A new bibunit with a different style and a cite
223     % of a Postscript tutorial [Ado85].
224     % \vspace{-3mm}
225     % \begin{thebibliography}{{Ado}85}
226     % \bibitem[{Ado}85]{Adobe:1985}
227     % {Adobe {S}ystem {I}ncorporated}.
228     % \newblock {\em Postscript Language Tutorial and Cookbook}.
229     % \newblock Addison-Wesley, Reading, Massachusetts, 1985.
230     % \end{thebibliography}
231     %
232     % \end{quote}
233     % \vspace{2.25mm}
234     % \bottomrule
235     % \end{minipage}
236     % \caption{Example input and output.}
237     % \label{fig:Example}
238     % \end{figure}
239     %
240     % For each bibunit,
241     % there is now a separate auxiliary file |bu|\meta{i}|.aux| to be
242     % processed by \BibTeX. In this example, we have two bibunits with
243     % auxiliary files |bu1.aux| and |bu2.aux|. To process your document,
244     % three runs of \LaTeX\ and two runs of \BibTeX\ are required.
245     %
246     % \vbox{%
247     % \begin{verbatim}
248     % latex mydoc
249     % bibtex bu1
250     % bibtex bu2
251     % latex mydoc
252     % latex mydoc
253     % \end{verbatim}}
254     %
255     % This example should give a pretty good impression of what
256     % principally can be
257     % done with \package{bibunits} and how it can be done. But
258     % \package{bibunits} allows for many more features, e.g., bibunits
259     % can be specified by |\sections|, a global bibliography can be used,
260     % and cite command can be placed in both the local and the global
261     % bibliography at the same time, among other features. All these
262     % features and associated commands are described in the next section.
263     %
264     %
265     %
266     %
267     % \section{Usage Notes}
268     %
269     % There are two ways to specify the units for which a bibliography is
270     % generated. You can either define your own \textsf{bibunit}
271     % environment, or you can specify bibunits for the \LaTeX\ units
272     % |\chapter| or |\section|. Both ways are mutually exclusive, meaning
273     % that you can choose only one and cannot mix them.
274     %
275     % \DescribeEnv{bibunit} Use the environment
276     % |\begin{bibunit}|\oarg{style} to create a bibunit. The optional
277     % argument \meta{style} specifies a bibliography style. If the optional
278     % argument \meta{style} is omitted, the default style is used. How to
279     % define a default style is explained below within this section.
280     %
281     % \DescribeMacro{\bibliographyunit}
282     % Alternatively, use |\bibliographyunit|\oarg{unit}, where \meta{unit} can be
283     % |\chapter| or |\section| to specify for which document unit
284     % a bibliography is generated, namely for every chapter or for every
285     % section. Use |\bibliographyunit| with no arguments to deactivate
286     % bibliography units. By default |\bibliographyunit| is deactivated.
287     % The command |\bibliographyunit| has to be issued
288     % after |\begin{document}|.
289     %
290     % \DescribeMacro{\cite*}
291     % \DescribeMacro{\nocite*}
292     % You can create a global bibliography as usual with the commands\\
293     % |\bibliography|\oarg{BibTeX files} and |\bibliographystyle|\oarg{style}.
294     % Use |\cite| and |\nocite| to generate citations that appear in the
295     % local bibliography. Use |\cite*| and |\nocite*| inside a unit
296     % to generate citations for both the local and global bibliography.
297     %
298     % \DescribeMacro{\putbib}
299     % Use |\putbib|\oarg{BibTeX files} to specify where the
300     % bibliography should appear within a bibunit. If the optional
301     % argument is omitted, |\putbib| uses the default \BibTeX\ files. How to
302     % define a default files is explained below within this section.
303     %
304     % If |\bibliographyunit| is active, default \BibTeX\ styles and files
305     % can be defined by |\bibliography| and |\bibliographystyle| and
306     % their starred versions |\bibliography*| and |\bibliographystyle*| as
307     % detailed below.
308     %
309     % \DescribeMacro{\bibliography} \DescribeMacro{\bibliographystyle}
310     % If |\bibliographyunit| is active, the commands
311     % |\bibliography|\oarg{BibTeX files} and
312     % |\bibliographystyle|\oarg{style} also specify the
313     % \BibTeX\ files and style to be used by default in the local units.
314     % The commands |\bibliography| and |\bibliographystyle| have to be issued
315     % after |\begin{document}|.
316     %
317     % \DescribeMacro{\bibliography*}
318     % \DescribeMacro{\bibliographystyle*}
319     % If |\bibliographyunit| is active, you can use starred
320     % forms\\ |\bibliography*|\marg{BibTeX files} and
321     % |\bibliographystyle*|\marg{style} to specify the defaults for
322     % the local units only. These commands do not generate a global
323     % bibliography or any information for the global bibliography.
324     % The commands |\bibliography*| and |\bibliographystyle*| have to be issued
325     % after |\begin{document}|.
326     %
327     % Note that default style and \BibTeX\ files can only be specified while\\
328     % |\bibliographyunit| is active. Thus, if you do want default styles
329     % but \textsf{bibunit} environments instead of |\bibliographyunit|s,
330     % you have to issue a dummy |\bibliographyunit[\section]|, then
331     % specify defaults\\ |\bibliography*|\marg{BibTeX files} and
332     % |\bibliographystyle*|\marg{style} and finally switch off the
333     % generation of bibunits by sections using |\bibliographyunit|.
334     % Examples can be found in Sec.~\ref{sec:Examples}.
335     %
336     %
337     %
338     % \subsection{Package options}
339     % \begin{description}
340     % \item[globalcitecopy] Create an entry in the global bibliography for
341     % each cite command within a bibunit. Default is to create an entry
342     % only for the local bibliography.
343     % \item[labelstoglobalaux] Write the replacement text for a label
344     % inside a bibunit to the global auxiliary file.
345     % Default is to write the labels to the local auxiliary file. The
346     % option \option{labelstoglobalaux} is useful in some situations, e.g.,
347     % \begin{itemize}
348     % \item to resolve the references when a bibunit bibliography is
349     % |\include|d.
350     % \item to resolve citations within a moving argument like
351     % |\section|, which otherwise would result in an `Undefined
352     % reference' error.
353     % \end{itemize}
354     % Note that this option results in wrong labels for numerical
355     % reference schemes if the same cited item appears at different
356     % positions in more than one bibliography
357     % (cf.~Sec.~\ref{sec:Limitations}).
358     % \end{description}
359     %
360     %
361     %
362     % \subsection{\textnormal{\BibTeX} processing}
363     %
364     % For each bibunit, in sequence, there is now a corresponding file
365     % |bu|\meta{i}|.aux| that needs to be compiled through \BibTeX. Suppose
366     % your document has \meta{n} different bibunits, you must now invoke
367     % \BibTeX\ on |bu1|, \dots , |bu|\meta{n}. This can be done by a
368     % csh-script.
369     % \begin{verbatim}
370     % #!/bin/csh
371     % foreach auxfile (bu*.aux)
372     % echo bibtex `basename $auxfile .aux`
373     % bibtex `basename $auxfile .aux`
374     % end
375     % \end{verbatim}
376     %
377     % I you don't have the |basename| command, you can use an alternative
378     % script where the suffix |.aux| is removed using |sed|.
379     % \begin{verbatim}
380     % #!/bin/csh
381     % foreach auxfile (bu*.aux)
382     % set auxfilebasename = `echo $auxfile | sed s/.aux//`
383     % echo bibtex $auxfilebasename
384     % bibtex $auxfilebasename
385     % end
386     % \end{verbatim}
387     %
388     % If by some strange coincidence you have named some of your files
389     % |bu|\meta{i}|.aux|, you have to redefine the internal command
390     % |\@bibunitname|, otherwise your files will be overwritten. To get
391     % for your document |foo.tex| filenames |foo.|\meta{i}|.aux| as for
392     % the first version of \package{bibunits}, you can redefine the
393     % internal macro |\@bibunitname|.
394     % \begin{verbatim}
395     % \makeatletter
396     % \renewcommand{\@bibunitname}{\jobname.\the\@bibunitauxcnt}
397     % \makeatother
398     % \end{verbatim}
399     %
400     % If you also want a global bibliography for your document |foo.tex|,
401     % the file |foo.aux| needs to be compiled through \BibTeX\ as well.
402     %
403     %
404     %
405     %
406     % \subsection{Limitations}
407     % \label{sec:Limitations}
408     %
409     % \begin{itemize}
410     % \item A citation within a moving argument in a bibunit cannot be
411     % resolved outside this bibunit, because the label is local to the
412     % bibunit. This occurs, e.g., for a |\cite| within |\section|, which is
413     % undefined in the table of contents. You can use the option
414     % \option{labelstoglobalaux} to resolve the citations, but this
415     % has two side effects.
416     % \begin{itemize}
417     % \item Since the cite command also appears globally in the table of
418     % contents, it generates a |\citation| command for the
419     % \emph{global} auxiliary file. As a result, another \BibTeX\ run
420     % causes this previously local reference to creep into the global
421     % bibliography.
422     % \item Since the replacement text for all cited items is now
423     % global, the same cited item has always the same replacement
424     % text, regardless whether it appears at different positions within
425     % different bibunits. This results in wrong labels for numerical
426     % reference schemes if the same cited item appears at different
427     % positions within the bibliographies.
428     % \end{itemize}
429     % \item When using \package{natbib}, |\cite*| has the
430     % meaning as defined by \package{natbib}, namely to force full
431     % citation of multiple authors. To get the behavior as defined
432     % by \package{bibunits} (without \package{natbib}), use an
433     % accompanying |\nocite| outside of a bibunit. Alternatively, if
434     % you want \emph{every} local item to appear also in the global
435     % bibliography, you can use \package{bibunits} with option
436     % \option{globalcitecopy}.
437     % \item With \package{natbib}, you cannot use numerical and
438     % author-year reference schemes together. Typographically, this
439     % is regarded bad style anyway.
440     % \end{itemize}
441     %
442     %
443     %
444     %
445     % \section{Examples}
446     % \label{sec:Examples}
447     %
448     %
449     %
450     % \subsection{Bibunits by the \texttt{bibunit} environment}
451     %
452     % In the first example, two bibliographies are generated, the first
453     % using the \BibTeX\ file |texlit.bib| and the style |plain|, the
454     % second using the \BibTeX\ file |lit.bib| and the style |abbrv|.
455     % %
456     % \begin{verbatim}
457     % \documentclass{article}
458     % \usepackage{bibunits}
459     %
460     % \begin{document}
461     % \begin{bibunit}[plain]
462     % some text \cite{lamport:1994} more text more citations
463     % \putbib[texlit]
464     % \end{bibunit}
465     % some text between the units
466     % \begin{bibunit}[abbrv]
467     % some text \cite{gnu:1998} more text more citations
468     % \putbib[lit]
469     % \end{bibunit}
470     % \end{document}
471     % \end{verbatim}
472     %
473     % If all bibunits use the same \BibTeX\ files and style, you can
474     % specify defaults and omit the optional arguments of the |bibunit|
475     % environment and the |\putbib| macro. In the second example, a
476     % default \BibTeX\ file |texlit.bib| and a default style |abbrv| is
477     % defined. Note that you have to activate bibliography units with the
478     % command |\bibliographyunit[\section]| (|\chapter| would also work)
479     % before you can specify the defaults, and afterwards you have to
480     % deactivate bibliography units with the command |\bibliographyunit|
481     % before you can use the |bibunit| environment.
482     % %
483     % \begin{verbatim}
484     % : same as in the previous example
485     %
486     % \begin{document}
487     % \bibliographyunit[\section]
488     % \bibliography*{texlit}
489     % \bibliographystyle*{plain}
490     % \bibliographyunit
491     %
492     % \begin{bibunit}
493     % some text \cite{lamport:1994} more text more citations
494     % \putbib
495     % \end{bibunit}
496     % some text between the units
497     % \begin{bibunit}
498     % some text \cite{knuth:1991} more text more citations
499     % \putbib
500     % \end{bibunit}
501     % \end{document}
502     % \end{verbatim}
503     %
504     % If you use the class |article|, the heading of the bibliography has
505     % the same font size as a section, which might be too large, especially if
506     % you have bibunits \emph{within} sections or even subsections. In
507     % this case you may want to change the bibliography heading to have
508     % the same appearance as a subsection.
509     % %
510     % \begin{verbatim}
511     % \let\stdthebibliography\thebibliography
512     % \renewcommand{\thebibliography}{%
513     % \let\section\subsection
514     % \stdthebibliography}
515     % \end{verbatim}
516     %
517     % Note that other classes may use other formatting instead of section for
518     % the bibliography heading. In this case the definition has to be changed
519     % accordingly, e.g., for the |book| class, where bibliography headings
520     % appear at the chapter level, let |\chapter| to |\subsection|.
521     % %
522     % \begin{verbatim}
523     % \let\stdthebibliography\thebibliography
524     % \renewcommand{\thebibliography}{%
525     % \let\chapter\subsection
526     % \stdthebibliography}
527     % \end{verbatim}
528     %
529     %
530     %
531     % \subsection{Bibunits by chapters or sections}
532     %
533     % You can also define bibliographies for every chapter or section. In
534     % this case, the redefinition of |\thebibliography| is essential for
535     % the proper behavior of the \package{bibunits} package. The reason is
536     % quite simple: if you create bibliographies for every section,
537     % and |\thebibliography| also appears at the section level, a new
538     % unit is opened by |\thebibliography|, and the information of the
539     % previous unit is no longer available. (More technically: The
540     % auxiliary file of the previous unit is closed, and the
541     % replacement text for the citation which is generated inside
542     % |\thebibliography| cannot be written to this file. Instead, it is
543     % written to the global |.aux| file.)
544     %
545     % The next example corresponds to the first example of the previous
546     % section with different \BibTeX\ files and styles. Note that you have
547     % to specify the |\bibliographystyle*| \emph{before} the corresponding
548     % section.
549     % %
550     % \begin{verbatim}
551     % \documentclass{article}
552     % \usepackage{bibunits}
553     %
554     % \let\stdthebibliography\thebibliography
555     % \renewcommand{\thebibliography}{%
556     % \let\section\subsection
557     % \stdthebibliography}
558     %
559     % \begin{document}
560     % \bibliographyunit[\section]
561     % \bibliographystyle*{plain}
562     %
563     % \section{First section}
564     % some text \cite{lamport:1994} more text more citations
565     % \putbib[texlit]
566     % some text between the units
567     % \bibliographystyle*{abbrv}
568     % \section{Second and last section}
569     % some text \cite{gnu:1998} more text more citations
570     % \putbib[lit]
571     % \end{document}
572     % \end{verbatim}
573     %
574     % You can also use the same \BibTeX\ file and style for all units.
575     % %
576     % \begin{verbatim}
577     % : same as in the previous example
578     %
579     % \begin{document}
580     % \bibliographyunit[\section]
581     % \bibliography*{texlit}
582     % \bibliographystyle*{plain}
583     %
584     % \section{First section}
585     % some text \cite{lamport:1994} more text more citations
586     % \putbib
587     % some text between the units
588     % \section{Second and last section}
589     % some text \cite{knuth:1991} more text more citations
590     % \putbib
591     % \end{document}
592     % \end{verbatim}
593     %
594     % In all four examples, one can specify a global
595     % bibliography and its style with the usual \LaTeX\ commands.
596     % Citations for the global bibliography are entered using |\cite| and
597     % |\nocite| commands while outside a unit or using |\cite*| and
598     % |\nocite*| while inside a unit. The starred forms generate citations
599     % also for the local unit. Thus it is not possible to generate
600     % citations \emph{only} for the global bibliography while inside a
601     % unit (which seems to be a reasonable restriction). Note that if
602     % |\bibliographyunit| is active, \emph{and} you use a global
603     % bibliography, \emph{and} you use the same \BibTeX\ file and style
604     % for all (local as well as global) bibliographies, \emph{then} the
605     % |\bibliography*| and |\bibliographystyle*| commands are not
606     % necessary. In this case proper defaults for the local bibliographies
607     % are specified by the commands
608     % |\bibliography| and |\bibliographystyle|, too. Note that a second
609     % run of \LaTeX\ is necessary before \BibTeX\ processing, in case that
610     % the global bibliography has its usual place at the end of the
611     % document.
612     %
613     %
614     %
615     %
616     % \section{Acknowledgments}
617     %
618     % The author thanks Jos\'e Alberto Fern\'andez for the coding of
619     % \package{bibunits} v1.0. Further, contributions from various people
620     % are gratefully acknowledged (in alphabetical order): Battista
621     % Benciolini for the patch to allow |putbib| to appear before the
622     % first occurrence of a cite within a bibunit; Jason Harrison for an
623     % alternative script to call \BibTeX\ for each local auxiliary file;
624     % Werner J\"urgens for the hint on how to suppress unwanted spaces;
625     % Andrew E.\ Schulman for an early version of the \package{natbib}
626     % compatibility patch; Stefan Ullrich for an early version of the
627     % \package{jurabib} compatibility patch (communicated by Jens Berger)
628     % and the \package{mparhack} compatibility patch. Finally, the author
629     % acknowledges the contributions of numerous people, whose questions,
630     % suggestions and bug reports have helped to improve \package{bibunits}.
631     %
632     %
633     % \StopEventually{}
634     %
635     %
636     %
637     %
638     % \section{The Macros}
639     %
640     % \begin{macrocode}
641     %<*package>
642     % \end{macrocode}
643     %
644     %
645     % \subsection{Allocation}
646     %
647     % \begin{macro}{\@bu@tempcnta}
648     % \changes{v2.1m}{2000/10/05}{Counter removed.}
649     %
650     % [Allocation of counter removed.]
651     % \end{macro}
652     %
653     %
654     %
655     % \subsection{Option handling}
656     %
657     %
658     % \begin{macro}{\iflabelstoglobalaux}
659     % \changes{v2.1c}{1999/11/24}{Add code for option processing and option
660     % \option{labelstoglobalaux}.}
661     %
662     % Define a new if to switch between global definition of labels
663     % within a bibliography and local labels (default). Global labels
664     % can be activated with option \option{labelstoglobalaux}.
665     % \begin{macrocode}
666     \newif\iflabelstoglobalaux \labelstoglobalauxfalse
667     \DeclareOption{labelstoglobalaux}{\labelstoglobalauxtrue}
668     % \end{macrocode}
669     % \end{macro}
670     %
671     %
672     % \begin{macro}{\ifglobalcitecopy}
673     % \changes{v2.1l}{2000/10/03}{Add code for option \option{globalcitecopy}.}
674     %
675     % Define a new if to switch between entering of cite commands
676     % within a bibunit also to the global bibliography or only to the local
677     % bibliography (default). Entering of cite commands also to the
678     % global bibliography can be activated with
679     % option \option{globalcitecopy}.
680     %
681     % \begin{macrocode}
682     \newif\ifglobalcitecopy
683     \globalcitecopyfalse
684     \DeclareOption{globalcitecopy}{\globalcitecopytrue}
685     % \end{macrocode}
686     % \end{macro}
687     %
688     %
689     % \noindent Finally, process all package options.
690     %
691     % \begin{macrocode}
692     \ProcessOptions
693     % \end{macrocode}
694     %
695     %
696     %
697     % \subsection{An auxiliary file for each bibunit is provided}
698     %
699     %
700     % \begin{macro}{\@bibunitaux}
701     % Define the file descriptor |\@bibunitaux| of the auxiliary file that is
702     % generated for each bibunit.
703     % \begin{macrocode}
704     \newwrite\@bibunitaux
705     % \end{macrocode}
706     % \end{macro}
707     %
708     %
709     % \begin{macro}{\@bibunitauxcnt}
710     % Define the counter for the bibunits and initialize it with zero.
711     % \begin{macrocode}
712     \newcount\@bibunitauxcnt \@bibunitauxcnt=0
713     % \end{macrocode}
714     % \end{macro}
715     %
716     %
717     % \begin{macro}{\@bibunitname}
718     % \changes{v1.0d}{1998/11/15}{New name
719     % \mbox{\texttt{bu}\string\meta{i}\texttt{.aux}} for the
720     % auxiliary files that are created for each bibunit.}
721     %
722     % The command |\@bibunitname| sets the basename of the auxiliary files
723     % that are created for each bibunit to |bu| (|bu| for
724     % |b|ib|u|nits), followed by the current number of the bibunit,
725     % |\the\@bibunitauxcnt|. (In version 1.0 of \package{bibunits} there
726     % was no such command, and the command sequence
727     % |\jobname.\the\@bibunitauxcnt| was directly used.)
728     % \begin{macrocode}
729     \def\@bibunitname{bu\the\@bibunitauxcnt}
730     % \end{macrocode}
731     % \end{macro}
732     %
733     %
734     %
735     % \subsection{New cite commands}
736     %
737     % The main idea is to save the old meaning of the command and then
738     % to redefine it. At the beginning of a bibunit, the new commands are
739     % activated, at the end of a bibunit, the old commands are restored.
740     %
741     % \begin{macro}{\if@localcite}
742     % \changes{v2.1j}{2000/10/02}{Rename \macrott{@localcite} to
743     % \macrott{@starredversion}.}
744     %
745     % Define a new if to store if a macro is evoked with or without a
746     % star. This is used by cite commands to switch between local and
747     % global cites, i.e., cites of references that occur in the local
748     % or also in the global bibliography. The is also a starred version
749     % of |\bibliopography| and |\bibliopographystyle| to enter
750     % default \BibTeX\ data files and styles for the bibunits only.
751     %
752     % \begin{macrocode}
753     \newif\if@starredversion
754     % \end{macrocode}
755     % \end{macro}
756     %
757     %
758     % \begin{macro}{\@localcitedefault}
759     % \changes{v2.1j}{2000/10/02}{Macro removed.}
760     %
761     % [Macro deleted.]
762     % \end{macro}
763     %
764     %
765     % \begin{macro}{\std@cite}
766     % \begin{macro}{\bu@cite}
767     % \changes{v2.0c}{1999/09/27}{Macro declared robust.}
768     % \changes{v2.1j}{2000/10/02}{Rename \macrott{@localcite} to
769     % \macrott{@starredversion} and switch false and true.}
770     %
771     % \begin{macrocode}
772     \let\std@cite\cite
773     \DeclareRobustCommand\bu@cite{%
774     \@ifstar
775     {\@starredversiontrue\std@cite}%
776     {\@starredversionfalse\std@cite}%
777     }
778     % \end{macrocode}
779     % \end{macro}
780     % \end{macro}
781     %
782     %
783     % \begin{macro}{\std@@citex}
784     % \begin{macro}{\bu@@citex}
785     % \changes{v2.0a}{1999/06/02}{\package{natbib} v6.5 compatibility.}
786     % \changes{v2.0b}{1999/07/06}{Implementation streamlined.}
787     % \changes{v2.0f}{1999/10/05}{\package{overcite} compatibility.}
788     % \changes{v2.0g}{1999/10/22}{\package{natbib} v7.0 compatibility.}
789     % \changes{v2.1b}{1999/11/24}{\macrott{leavevmode} added.}
790     % \changes{v2.1f}{2000/04/02}{\macrott{@startbibunitorrelax} added,
791     % definition of standard version for all \package{natbib} cite
792     % commands removed.}
793     % \changes{v2.1j}{2000/10/02}{Rename \macrott{@localcite} to
794     % \macrott{@starredversion} and switch if branches,
795     % delete \macrott{@localcitedefault}.}
796     % \changes{v2.1k}{2000/10/02}{For standard definition (without
797     % \package{bibunits} or \package{overcite}), replace direct
798     % writing to \macrott{@bibunitaux} by use of \macrott{std@nocite}.}
799     % \changes{v2.1l}{2000/10/03}{Handling of option
800     % \option{globalcitecopy} added.}
801     % \changes{v2.1n}{2000/10/08}{\package{jurabib} compatibility.}
802     %
803     % Define the \package{bibunits} macro |\bu@@citex| replacing the
804     % internal macro |\@citex|. Macro |\@citex| is evoked by the |\cite|
805     % and its various derivatives defined by other packages. Basically,
806     % |\bu@@citex| the following actions take place. The macro
807     % |\startbibunitorrelax| ensures that auxiliary files are created
808     % only for non-empty bibunits. The macro |\leavevmode| are added to
809     % fix a problem that occurs in some special situations when a
810     % |\paragraph| within a bibunit is immediately followed by a cite
811     % command, as explained below. Next, the standard version of
812     % |\@citex|, namely |\std@@citex| is evoked with |\@auxout| locally
813     % changed, so that citations are written to the local auxiliary
814     % file of each bibunit. Finally, if option \option{globalcitecopy}
815     % is active or the starred form of the cite command is evoked,
816     % i.e., |\if@starredversion| is true, citations are
817     % \emph{also} written to the global auxiliary file, so that
818     % citations appear in both the local as well as the global
819     % bibliography at the same time.
820     %
821     % After this general description, the use of |\leavevmode| is
822     % further detailed. The |\leavevmode| commands are added to fix a
823     % problem that occurs when a |\paragraph| within a bibunit is
824     % immediately followed by a cite command, and within |\paragraph|
825     % something is written to |\@auxout|, e.g., an entry for the table
826     % of contents or the index. In this cases, the entry go to the
827     % local auxiliary file of the corresponding bibunit instead of the
828     % standard auxiliary file |\@auxout|. The reason is that the
829     % argument of |\paragraph| is stored in an |\everypar|, which is
830     % evaluated later. In case of a cite command that immediately
831     % follows |\paragraph|, the evaluation occurs within the scope of
832     % the cite, where the |\@auxout| is let to the local auxiliary file
833     % of the corresponding bibunit. Consequently, the entry is written
834     % to the wrong, i.e., local, auxiliary file. We add an
835     % |\leavevmode| to evaluate |\everypar| before |\@auxout| is
836     % redefined. Alternatively, the typesetting of |\paragraph| in
837     % |\@xsect| of the \LaTeX\ kernel might be revised.
838     %
839     % Additional to the new standard definition of |\@citex|, different
840     % versions have to be defined depending other packages loaded,
841     % namely \package{natbib}, \package{overcite} and
842     % \package{jurabib}. These packages are mutually exclusive, with
843     % the priority as defined by their order in the previous sentence.
844     % That means, e.g., if you have chosen \package{natbib} together
845     % with \package{bibunits}, you cannot use \package{overcite} or
846     % \package{jurabib}.
847     %
848     % All definitions are done |\AtBeginDocument| so that packages
849     % loaded after \package{bibunits} can be discovered.
850     %
851     % \begin{macrocode}
852     \AtBeginDocument{%
853     % \end{macrocode}
854     %
855     % Several modifications and additions are necessary if package
856     % \package{natbib} is loaded: First macro |\NAT@set@cites| is used
857     % to invoke \package{natbib}'s cite commands. This is only
858     % necessary if these commands have not been set, i.e. in case
859     % \package{bibunits} is evoked before \package{natbib}, but does
860     % not do any harm otherwise. Second macro |\bu@@citex| is changed
861     % as described below, and the various versions of
862     % \package{natbib}'s cite commands are save in a |\std|\dots version.
863     %
864     % The definition of |\bu@@citex| is changed in the following ways:
865     % i) the |\let| of |\@auxout| is encapsulated using |\begingroup|
866     % and |\endgroup| instead of braces, since braces results in an
867     % error; ii) macro |\std@@citex| has two optional
868     % arguments instead of one; iii) the code of |\if@starredversion| is
869     % skipped in favor of the meaning of a starred cite in
870     % \package{natbib}, namely to force full listing of multiple
871     % authors.
872     %
873     % \begin{macrocode}
874     \@ifpackageloaded{natbib}%
875     {%
876     \NAT@set@cites \let\std@@citex\@citex
877     \def\bu@@citex[#1][#2]#3{%
878     \@startbibunitorrelax
879     \leavevmode
880     \begingroup\let\@auxout\@bibunitaux\std@@citex[#1][#2]{#3}\endgroup
881     \ifglobalcitecopy
882     \std@nocite{#3}%
883     \fi
884     }%
885     }%
886     % \end{macrocode}
887     %
888     % If \package{natbib} is not loaded, we check for
889     % \package{overcite}. In this case, an additional command
890     % |\@citew| has to be redefined which handles |\cite| without an
891     % argument. Further, an internal command of \package{overcite},
892     % namely |\@nocite| is used to write to the standard auxiliary file.
893     %
894     % \begin{macrocode}
895     {%
896     \@ifpackageloaded{overcite}%
897     {%
898     \let\std@@citew\@citew
899     \def\bu@@citew#1{%
900     \@startbibunitorrelax
901     \leavevmode
902     {\let\@auxout\@bibunitaux \std@@citew{#1}}%
903     \ifglobalcitecopy
904     \@nocite{#1}%
905     \else
906     \if@starredversion
907     \@nocite{#1}%
908     \fi
909     \fi
910     }
911     \let\std@@citex\@citex
912     \def\bu@@citex[#1]#2{%
913     \@startbibunitorrelax
914     \leavevmode
915     {\let\@auxout\@bibunitaux \std@@citex[#1]{#2}}%
916     \ifglobalcitecopy
917     \@nocite{#2}%
918     \else
919     \if@starredversion
920     \@nocite{#2}%
921     \fi
922     \fi
923     }
924     }%
925     % \end{macrocode}
926     %
927     % If neither \package{natbib} nor \package{overcite} are loaded, we
928     % check for \package{jurabib}. In this case, the definition of
929     % |\std@@citex| differs from the default version by a second
930     % optional argument, similar to \package{natbib}.
931     %
932     % \begin{macrocode}
933     {%
934     \@ifpackageloaded{jurabib}%
935     {%
936     \let\std@@citex\@citex
937     \def\bu@@citex[#1][#2]#3{%
938     \@startbibunitorrelax
939     \leavevmode
940     {\let\@auxout\@bibunitaux \std@@citex[#1][#2]{#3}}%
941     \ifglobalcitecopy
942     \std@nocite{#3}%
943     \else
944     \if@starredversion
945     \std@nocite{#3}%
946     \fi
947     \fi
948     }%
949     }%
950     % \end{macrocode}
951     %
952     % Finally, the default definition.
953     %
954     % \begin{macrocode}
955     {%
956     \let\std@@citex\@citex
957     \def\bu@@citex[#1]#2{%
958     \@startbibunitorrelax
959     \leavevmode
960     {\let\@auxout\@bibunitaux \std@@citex[#1]{#2}}%
961     \ifglobalcitecopy
962     \std@nocite{#2}%
963     \else
964     \if@starredversion
965     \std@nocite{#2}%
966     \fi
967     \fi
968     }%
969     }%
970     }%
971     }%
972     }%
973     % \end{macrocode}
974     % \end{macro}
975     % \end{macro}
976     %
977     %
978     % \begin{macro}{\std@nocite}
979     % \begin{macro}{\bu@nocite}
980     % \changes{v2.1j}{2000/10/02}{Rename \macrott{@localcite} to
981     % \macrott{@starredversion} and switch false and true.}
982     %
983     % \begin{macrocode}
984     \let\std@nocite\nocite
985     \def\bu@nocite{%
986     \@ifstar
987     {\@starredversiontrue\@bu@nocite}%
988     {\@starredversionfalse\@bu@nocite}%
989     }
990     % \end{macrocode}
991     % \end{macro}
992     % \end{macro}
993     %
994     %
995     % \begin{macro}{\@bu@nocite}
996     % \changes{v2.1f}{2000/04/02}{\macrott{@startbibunitorrelax} added.}
997     % \changes{v2.1j}{2000/10/02}{Rename \macrott{@localcite} to
998     % \macrott{@starredversion} and switch if branches,
999     % delete \macrott{@localcitedefault}.}
1000     % \changes{v2.1k}{2000/10/02}{Replace direct writing to
1001     % \macrott{@bibunitaux} by \macrott{std@nocite} within scope
1002     % of redefined \macrott{@auxout}, \macrott{@bsphack} and
1003     % \macrott{@esphack} removed.}
1004     % \changes{v2.1l}{2000/10/03}{Handling of option
1005     % \option{globalcitecopy} added.}
1006     %
1007     % \begin{macrocode}
1008     \def\@bu@nocite#1{%
1009     \@startbibunitorrelax
1010     {\let\@auxout\@bibunitaux \std@nocite{#1}}%
1011     \ifglobalcitecopy
1012     \std@nocite{#1}%
1013     \else
1014     \if@starredversion
1015     \std@nocite{#1}%
1016     \fi
1017     \fi
1018     }
1019     % \end{macrocode}
1020     % \end{macro}
1021     %
1022     %
1023     %
1024     % \subsection{New bibliography and bibliographystyle commands}
1025     %
1026     % \changes{v1.0e}{1998/11/30}{Global definition of bibunit data and style.}
1027     %
1028     % In this paragraph no general description is given, rather an
1029     % explanation why in the following two macros |\@bu@bibliography| and
1030     % |\@bu@bibliographystyle| the command |\gdef\bu@bibdata| and
1031     % |\gdef\bu@bibstyle| are written to the auxiliary file and are directly
1032     % executed, too. The execution through the auxiliary file has been left
1033     % for compatibility to older versions of \package{bibunits}: if you
1034     % also have a global bibliography, you can specify \BibTeX\ styles and
1035     % files for the global bibliography (using |\bibliography| and
1036     % |\bibliographystyle|, usually at the end of the document). In this
1037     % case, writing the execution of |\gdef| to the auxiliary file ensures
1038     % that in subsequent runs of \LaTeX defaults for the local
1039     % bibliographies are generated as well. Without this, the user would
1040     % have to explicitly specify \BibTeX\ files and styles for the local
1041     % bibliographies using the starred forms |\bibliography*| and
1042     % |\bibliographystyle*|. On the other hand, with the direct execution
1043     % of the |\gdef| commands, the starred forms specify defaults which can be
1044     % used already in the first run of \LaTeX\, if put before the first bibunit.
1045     %
1046     %
1047     %
1048     % \begin{macro}{\bu@bibdata}
1049     % Define data files store.
1050     % \begin{macrocode}
1051     \def\bu@bibdata{}
1052     % \end{macrocode}
1053     % \end{macro}
1054     %
1055     %
1056     % \begin{macro}{\orig@bibliography}
1057     % \begin{macro}{\bibliography}
1058     % \begin{macro}{\std@bibliography}
1059     % \changes{v2.1h}{2000/08/06}{New definition of
1060     % \macrott{bibliography} to open \texttt{bu.aux}, write to
1061     % \macrott{@mainaux} and close \texttt{bu.aux}.}
1062     %
1063     % If |\labelstoglobalaux| is false, define a new version of
1064     % |\bibliography| where the replacement text for the labels is
1065     % written to a new file |bu.aux|. This file is input at the
1066     % end of each bibunit to restore the global labels which are
1067     % overwritten if a global item is also cited within a bibunit.
1068     % Input of the main auxiliary file is not appropriate, because this
1069     % file contains additional material which should not be input more
1070     % than once, e.g., commands which generate entries for the table of
1071     % contents.
1072     %
1073     % The definition of |\std@bibliography| is used to define a
1074     % version of |\bibliography| with enhanced functionality
1075     % |\bu@bibliography|.
1076     %
1077     % \begin{macrocode}
1078     \AtBeginDocument{%
1079     \iflabelstoglobalaux
1080     \else
1081     \let\orig@bibliography\bibliography
1082     \def\bibliography#1{%
1083     \if@filesw
1084     \immediate\openout\@bibunitaux bu.aux
1085     \immediate\write\@mainaux{\string\@input{bu.aux}}%
1086     \fi
1087     \orig@bibliography{#1}%
1088     \if@filesw
1089     \immediate\closeout\@bibunitaux
1090     \fi
1091     }%
1092     \fi
1093     \let\std@bibliography\bibliography
1094     }
1095     % \end{macrocode}
1096     % \end{macro}
1097     % \end{macro}
1098     % \end{macro}
1099     %
1100     %
1101     % \begin{macro}{\bu@bibliography}
1102     % \changes{v2.1j}{2000/10/02}{Rename \macrott{@localcite} to
1103     % \macrott{@starredversion}.}
1104     %
1105     % \begin{macrocode}
1106     \def\bu@bibliography{%
1107     \@ifstar
1108     {\@starredversiontrue\@bu@bibliography}%
1109     {\@starredversionfalse\@bu@bibliography}%
1110     }
1111     % \end{macrocode}
1112     % \end{macro}
1113     %
1114     %
1115     % \begin{macro}{\@bu@bibliography}
1116     % \changes{v2.1j}{2000/10/02}{Rename \macrott{@localcite} to
1117     % \macrott{@starredversion}, delete \macrott{@localcitedefault}.}
1118     %
1119     % \begin{macrocode}
1120     \def\@bu@bibliography#1{%
1121     \if@filesw
1122     \immediate\write\@auxout{\string\gdef\string\bu@bibdata{#1}}%
1123     \fi
1124     \gdef\bu@bibdata{#1}%
1125     \if@starredversion
1126     \else
1127     \std@bibliography{#1}%
1128     \fi
1129     }
1130     % \end{macrocode}
1131     % \end{macro}
1132     %
1133     %
1134     % \begin{macro}{\bu@bibstyle}
1135     % Define style store.
1136     % \begin{macrocode}
1137     \def\bu@bibstyle{}
1138     % \end{macrocode}
1139     % \end{macro}
1140     %\
1141     %
1142     % \begin{macro}{\std@bibliographystyle}
1143     % \begin{macro}{\bu@bibliographystyle}
1144     % \changes{v2.1j}{2000/10/02}{Rename \macrott{@localcite} to
1145     % \macrott{@starredversion}.}
1146     %
1147     % \begin{macrocode}
1148     \let\std@bibliographystyle\bibliographystyle
1149     \def\bu@bibliographystyle{%
1150     \@ifstar
1151     {\@starredversiontrue\@bu@bibliographystyle}%
1152     {\@starredversionfalse\@bu@bibliographystyle}%
1153     }
1154     % \end{macrocode}
1155     % \end{macro}
1156     % \end{macro}
1157     %
1158     %
1159     % \begin{macro}{\@bu@bibliographystyle}
1160     % \changes{v2.1j}{2000/10/02}{Rename \macrott{@localcite} to
1161     % \macrott{@starredversion}, delete \macrott{@localcitedefault}.}
1162     %
1163     % \begin{macrocode}
1164     \def\@bu@bibliographystyle#1{%
1165     \if@filesw
1166     \immediate\write\@auxout{\string\gdef\string\bu@bibstyle{#1}}%
1167     \fi
1168     \gdef\bu@bibstyle{#1}%
1169     \if@starredversion
1170     \else
1171     \std@bibliographystyle{#1}%
1172     \fi
1173     }
1174     % \end{macrocode}
1175     % \end{macro}
1176     %
1177     %
1178     %
1179     % \subsection{Bibunits}
1180     %
1181     %
1182     % \subsubsection{Bibunits by an extra environment}
1183     %
1184     % The starting of a bibunit is a two-step process: in the first step
1185     % (macro |\bibunit|), all cite commands are redefined to trigger the
1186     % second step, namely the actual starting of a bibunit (macro
1187     % |\@startbibunit|). This may seem weird on the first sight, but has
1188     % the advantage that no auxiliary files are created if a bibunit
1189     % contains no |\cite|, |\cite*|, |\nocite| or |\nocite*| commands. To
1190     % handle citations of the same reference in different bibliographies,
1191     % the local auxiliary file is input at the beginning of each bibunit
1192     % (in macro |\@startbibunit|), and the replacement text is also
1193     % written to the \emph{local} auxiliary file (in macro |\@putbib|).
1194     %
1195     %
1196     % \begin{macro}{\bibunit}
1197     % \changes{v2.0g}{1999/10/22}{\package{natbib} v7.0 compatibility.}
1198     % \changes{v2.1f}{2000/04/02}{Evoking of \package{bibunits} version
1199     % of cite commands, let \macrott{@startbibunitorrelax} to
1200     % \macrott{@startbibunit} added.}
1201     %
1202     % At the beginning of a bibunit, all cite command are set to
1203     % their initializing versions, and |\@finishbibunit| can relax,
1204     % because currently no citation has appeared. Hence no local
1205     % auxiliary file has been opened for the current bibunit, which has to
1206     % be closed at the end of the bibunit.
1207     % \begin{macrocode}
1208     \def\bibunit{%
1209     \global\let\cite\bu@cite
1210     \global\let\@citex\bu@@citex
1211     \global\let\@citew\bu@@citew
1212     \global\let\nocite\bu@nocite
1213     \global\let\@startbibunitorrelax\@startbibunit
1214     \global\let\@finishbibunit\relax
1215     \@ifnextchar[{\@bibunitx}{\@bibunitx[\bu@bibstyle]}%
1216     }
1217     % \end{macrocode}
1218     % \end{macro}
1219     %
1220     %
1221     % \begin{macro}{\@bibunitx}
1222     % If the current bibunit has an extra bibstyle, it is saved in
1223     % |\@localbibstyle|. (In version 1.0a |\bibstyle| command has been
1224     % directly written to the local auxiliary file. This is now done in
1225     % |\@startbibunit|.)
1226     % \begin{macrocode}
1227     \def\@bibunitx[#1]{\gdef\@localbibstyle{#1}}
1228     % \end{macrocode}
1229     % \end{macro}
1230     %
1231     %
1232     % \begin{macro}{\endbibunit}
1233     % \changes{v2.0f}{1999/10/05}{\package{overcite} compatibility.}
1234     % \changes{v2.0g}{1999/10/22}{\package{natbib} v7.0 compatibility.}
1235     % \changes{v2.1f}{2000/04/02}{Restoration of standard versions of
1236     % \package{natbib} cite commands removed.}
1237     % \changes{v2.1h}{2000/08/06}{Input \texttt{bu.aux}.}
1238     % \changes{v2.1o}{2000/10/09}{Use \macrott{@input} instead of
1239     % \macrott{@input@} for reading \texttt{bu.aux}.}
1240     %
1241     % At the end of the bibunit, all cite commands are restored to
1242     % their former meaning (|\@citew| is used by package
1243     % \package{overcite}). Also the local auxiliary file is closed if
1244     % it has been opened. Finally, the replacement text for the global
1245     % citation labels (if exists) are restored using |\@input|.
1246     % \begin{macrocode}
1247     \def\endbibunit{%
1248     \global\let\cite\std@cite
1249     \global\let\@citex\std@@citex
1250     \global\let\@citew\std@@citew
1251     \global\let\nocite\std@nocite
1252     \@finishbibunit
1253     \@input{bu.aux}%
1254     }
1255     % \end{macrocode}
1256     % \end{macro}
1257     %
1258     %
1259     % \begin{macro}{\@startbibunit}
1260     % \changes{v2.0f}{1999/10/05}{\package{overcite} compatibility.}
1261     % \changes{v2.0g}{1999/10/22}{\package{natbib} v7.0 compatibility.}
1262     % \changes{v2.1d}{2000/01/27}{Remove enclosing braces around input
1263     % of local auxiliary file and restore catcodes and endlinechar.}
1264     % \changes{v2.1e}{2000/03/28}{Change catcode of `:'.}
1265     % \changes{v2.1f}{2000/04/02}{Evoking of \package{bibunit} version
1266     % of cite commands moved to \macrott{bibunit}, restoration of
1267     % standard versions of \package{natbib} cite commands removed,
1268     % let \macrott{@startbibunitorrelax} to \macrott{relax}.
1269     % added.}
1270     % \changes{v2.1m}{2000/10/05}{Change of catcode of `:' removed;
1271     % encapsulate setting of \macrott{endlinechar} by braces.}
1272     %
1273     % This command does all the necessary initialization for a bibunit:
1274     % New versions of the cite commands are activated (|\@citew| is
1275     % used by package \package{overcite}), the macro |\@finishbibunit|
1276     % which is called by |\endbibunit| is let to close the local
1277     % auxiliary file, the number of the bibunits is incremented. Most
1278     % important, the local auxiliary file is read, so that citations of
1279     % the same reference in different bibliographies are handled
1280     % correctly for numerical citation schemes. Finally, the bibstyle
1281     % is written to the local auxiliary file.
1282     % \begin{macrocode}
1283     \def\@startbibunit{%
1284     \global\let\@startbibunitorrelax\relax
1285     \global\let\@finishbibunit\@finishstartedbibunit
1286     \global\advance\@bibunitauxcnt 1
1287     \if@filesw
1288     % \end{macrocode}
1289     % Input the local auxiliary file and prevent the creation of
1290     % unwanted spaces by setting |\endlinechar-1| (|\catcode`\^^M=9|
1291     % would also work here).
1292     % \begin{macrocode}
1293     {\endlinechar-1
1294     \@input{\@bibunitname.aux}}%
1295     \immediate\openout\@bibunitaux\@bibunitname.aux
1296     \immediate\write\@bibunitaux{\string\bibstyle{\@localbibstyle}}%
1297     \fi
1298     }
1299     % \end{macrocode}
1300     % \end{macro}
1301     %
1302     %
1303     % \noindent When bibunits are specified by chapters or sections, a new
1304     % chapter or section marks both the end of the old and the start of the
1305     % new bibunit by calling |\endbibunit|. For the first chapter or section,
1306     % the command |\@finishbibunit| has to be defined (to do nothing),
1307     % which is done here.
1308     % \begin{macrocode}
1309     \let\@finishbibunit\relax
1310     % \end{macrocode}
1311     %
1312     %
1313     % \begin{macro}{\@finishstartedbibunit}
1314     % Close the local auxiliary file.
1315     % \begin{macrocode}
1316     \def\@finishstartedbibunit{%
1317     \if@filesw
1318     \immediate\closeout\@bibunitaux
1319     \fi
1320     }
1321     % \end{macrocode}
1322     % \end{macro}
1323     %
1324     %
1325     % \subsubsection{Bibunits by chapters or sections}
1326     %
1327     % |\chapter| or |\section| substituting definition.
1328     %
1329     % \begin{macro}{\old@bibunit}
1330     % \begin{macro}{\@bibunit}
1331     % \begin{macro}{\@endbibunit}
1332     % \begin{macrocode}
1333     \let\old@bibunit\@gobble
1334     \def\@bibunit{\endbibunit\bibunit\old@bibunit}
1335     \def\@endbibunit{}
1336     % \end{macrocode}
1337     % \end{macro}
1338     % \end{macro}
1339     % \end{macro}
1340     %
1341     %
1342     % \begin{macro}{\bibliographyunit}
1343     % \begin{macrocode}
1344     \def\bibliographyunit{%
1345     \@endbibunit
1346     \@ifnextchar[{\@bibliographyunit}{%
1347     \global\let\old@bibunit\@gobble
1348     \global\let\bibliography\std@bibliography
1349     \global\let\bibliographystyle\std@bibliographystyle
1350     \endbibunit
1351     \gdef\@endbibunit{}}%
1352     }
1353     % \end{macrocode}
1354     % \end{macro}
1355     %
1356     %
1357     % \begin{macro}{\@bibliographyunit}
1358     % \begin{macrocode}
1359     \def\@bibliographyunit[#1]{%
1360     \global\let\bibliography\bu@bibliography
1361     \global\let\bibliographystyle\bu@bibliographystyle
1362     \global\let\old@bibunit#1
1363     \global\let#1\@bibunit
1364     \gdef\@endbibunit{\global\let#1\old@bibunit}%
1365     }
1366     % \end{macrocode}
1367     % \end{macro}
1368     %
1369     %
1370     %
1371     % \subsection{Insert a local bibliography}
1372     %
1373     % \begin{macro}{\putbib}
1374     % If the \BibTeX\ data file is given as an optional argument, evoke
1375     % |\@putbib| which uses this argument, otherwise call |\@putbib|
1376     % with the default \BibTeX\ data file stored in |\bu@bibdata|.
1377     %
1378     % \begin{macrocode}
1379     \def\putbib{\@ifnextchar[{\@putbib}{\@putbib[\bu@bibdata]}}
1380     % \end{macrocode}
1381     % \end{macro}
1382     %
1383     %
1384     % \begin{macro}{\@putbib}
1385     % \changes{v2.1a}{1999/11/15}{Set \macrott{temp@auxout} and activate
1386     % \macrott{bu@addtocontents}.}
1387     % \changes{v2.1c}{1999/11/24}{Change to respond to option
1388     % \option{labelstoglobalaux}.}
1389     % \changes{v2.1g}{2000/07/31}{Add activation of
1390     % \macrott{bu@bibitem} and \macrott{bu@lbibitem}, remove activation of
1391     % \macrott{bu@addtocontents} and redefinition of \macrott{@auxout}.}
1392     % \changes{v2.1h}{2000/08/07}{Remove code for \option{labelstoglobalaux}
1393     % and activation of \macrott{bu@bibitem} and
1394     % \macrott{bu@lbibitem}.}
1395     % \changes{v2.1i}{2000/09/30}{\macrott{@startbibunitorrelax} added.}
1396     % \changes{v2.1o}{2000/10/09}{Add local .bbl files to
1397     % \macrott{@filelist} by using \macrott{@input@} instead of
1398     % \macrott{@input}.}
1399     %
1400     % Similar to |\bibliography|, |\@putbib| writes the \BibTeX\ data
1401     % and |\@input|s the typeset bibliography |\@bibunitname.bbl|. Macro
1402     % |\@startbibunitorrelax| triggers a new bibunit and allows
1403     % |\putbib| to be issued before the first cite command within a
1404     % bibunit.
1405     %
1406     % \begin{macrocode}
1407     \def\@putbib[#1]{%
1408     \@startbibunitorrelax
1409     \if@filesw
1410     \immediate\write\@bibunitaux{\string\bibdata{#1}}%
1411     \fi
1412     \@input@{\@bibunitname.bbl}%
1413     }
1414     % \end{macrocode}
1415     % \end{macro}
1416     %
1417     %
1418     % \begin{macro}{\bu@addtocontents}
1419     % \changes{v2.1a}{1999/11/15}{Add macro.}
1420     % \changes{v2.1g}{2000/07/31}{Remove macro.}
1421     %
1422     % [Macro removed.]
1423     % \end{macro}
1424     %
1425     %
1426     % \noindent The package allows the same cited item to occur in more than one
1427     % bibliography. Therefore the text which actually replaces the |\cite|
1428     % has to be kept locally, too. This can be switched off using
1429     % \option{labelstoglobalaux}.
1430     %
1431     % The text which replaces the |\cite| is created by the |\bibitem|
1432     % commands in the |.bbl| file which is |\@input|ed in |\@putbib|. The
1433     % |\bibitem| macro invokes macros |\@lbibitem| or |\@bibitem| which
1434     % write to |\@auxout|. By default, i.e., without option
1435     % \option{labelstoglobalaux} these commands are replaced by
1436     % \package{bibunits} version to write to the local auxiliary file of the
1437     % bibunit. The former meaning of |\@auxout| is saved in |\temp@auxout|
1438     % to be restored afterwards.
1439     %
1440     % Note that some packages, like \package{mparhack} or \komascript\
1441     % classes like \class{scrartcl} with option \option{bibtotoc} also write
1442     % material to |\@auxout| while inside |\thebibliography| within the
1443     % |.bbl| file. Therefore, redefining |\@auxout| in |\putbib| would
1444     % result in erroneously writing this material to the local auxiliary
1445     % file. Therefore, only the commands which actually write, i.e.,
1446     % |\@bibitem| and |\@lbibitem|, are redefined to write to the local
1447     % auxiliary file.
1448     %
1449     % Note that the redefined command |\bibliography| which generates a global
1450     % bibliography uses the same mechanism to write the replacement text
1451     % for the cite commands to |bu.aux|.
1452     %
1453     %
1454     % \begin{macro}{\std@bibitem}
1455     % \begin{macro}{\std@lbibitem}
1456     % \begin{macro}{\@bibitem}
1457     % \begin{macro}{\@lbibitem}
1458     % \changes{v2.1g}{2000/07/31}{Add macros.}
1459     % \changes{v2.1h}{2000/08/07}{Direct redefinition of
1460     % \macrott{@bibitem} and \macrott{@lbibitem} instead of
1461     % definition of local \macrott{bu} versions, but only if
1462     % \macrott{labelstoglobalaux} is false. Setting of
1463     % \macrott{temp@auxout} added.}
1464     %
1465     % Define new versions of |\@bibitem| and |\@lbibitem| which write
1466     % to |\bibunitaux| instead of |\@auxout|.
1467     % Encapsulation with braces instead of the two |let|s results in
1468     % |\@noitemerr| for the \textsf{thebibliography} environment.
1469     % \begin{macrocode}
1470     \AtBeginDocument{%
1471     \iflabelstoglobalaux
1472     \else
1473     \let\std@bibitem\@bibitem
1474     \let\std@lbibitem\@lbibitem
1475     \def\@bibitem#1{%
1476     \let\temp@auxout\@auxout
1477     \let\@auxout\@bibunitaux
1478     \std@bibitem{#1}%
1479     \let\@auxout\temp@auxout
1480     }
1481     \def\@lbibitem[#1]#2{%
1482     \let\temp@auxout\@auxout
1483     \let\@auxout\@bibunitaux
1484     \std@lbibitem[#1]{#2}%
1485     \let\@auxout\temp@auxout
1486     }
1487     \fi
1488     }
1489     % \end{macrocode}
1490     % \end{macro}
1491     % \end{macro}
1492     % \end{macro}
1493     % \end{macro}
1494     %
1495     %
1496     %
1497     % \subsection{Allow commands to be used not only in preamble}
1498     %
1499     % \changes{v1.0f}{1998/12/29}{Remove \macrott{bibcite} from
1500     % the list of preamble commands.}
1501     %
1502     % To handle citations of the same cited item in more than one
1503     % bibliography, replacement text for the citation is written to the
1504     % local auxiliary file. In subsequent runs of \LaTeX, this file is
1505     % read at the beginning of the bibunit.
1506     %
1507     %
1508     % \begin{macro}{\remequivalent}
1509     % \begin{macro}{\plugh}
1510     % \begin{macro}{\hgulp}
1511     % The local auxiliary file contains |\bibcite| commands, which can be
1512     % used only in the preamble in some older version of \LaTeX. For
1513     % compatibility with these versions, macros to remove an item from
1514     % a list are provided (see the \TeX book, p.\ 380; the only change
1515     % is the separator |\do| instead of |\\|).
1516     % \begin{macrocode}
1517     \def\remequivalent#1\from#2{%
1518     \let\given=#1%
1519     \ifx#2\empty
1520     \else
1521     \edef#2{\expandafter\plugh#2\plugh}%
1522     \fi
1523     }
1524     \def\plugh\do#1#2{%
1525     \ifx#1\given
1526     \else
1527     \noexpand\do\noexpand#1%
1528     \fi
1529     \ifx#2\plugh
1530     \hgulp\fi\plugh#2%
1531     }
1532     \def\hgulp\fi\plugh\plugh{\fi}
1533     % \end{macrocode}
1534     % \end{macro}
1535     % \end{macro}
1536     % \end{macro}
1537     %
1538     %
1539     % Now we are ready to remove |\bibcite| from the |\@preamblecmds| list.
1540     % \begin{macrocode}
1541     \remequivalent\bibcite\from\@preamblecmds
1542     % \end{macrocode}
1543     %
1544     %
1545     % \medskip
1546     % The command |\bibcite| calls |\@newl@bel| to create new
1547     % labels. This is by default only allowed as a preamble command and
1548     % would cause a `Can be used only in preamble' warning. Instead of
1549     % removing |\@newl@bel| from the list of preamble command (like
1550     % |\bibcite|), we redefine |\bibcite| to directly call |\@namedef| and
1551     % issue no warning. We decided not to give even an info, because
1552     % multiple cited references should be perfectly normal to
1553     % \package{bibunits}. Similarly, we modify \package{natbib}'s
1554     % |\bibcite|.
1555     %
1556     %
1557     % \begin{macro}{\bibcite}
1558     % \changes{v2.0a}{1999/06/02}{\package{natbib} compatibility.}
1559     % \changes{v2.0d}{1999/09/27}{Implementation streamlined.}
1560     % \changes{v2.1d}{2000/01/27}{\macrott{@namedef} not defined
1561     % \macrott{global}.}
1562     % \changes{v2.1h}{2000/08/06}{\macrott{@namedef} again defined
1563     % \macrott{global}.}
1564     %
1565     % \begin{macrocode}
1566     \AtBeginDocument{%
1567     \@ifpackageloaded{natbib}%
1568     {\renewcommand\bibcite[2]{\global\@namedef{b@#1\@extra@binfo}{#2}}}%
1569     {\renewcommand\bibcite[2]{\global\@namedef{b@#1}{#2}}}%
1570     }
1571     % \end{macrocode}
1572     % \end{macro}
1573     %
1574     %
1575     %
1576     % \subsection{Package \package{babel} compatibility}
1577     %
1578     % \begin{macro}{\@input}
1579     % \begin{macro}{\std@@citex}
1580     % \begin{macro}{\bu@@citex}
1581     % \changes{v2.1m}{2000/10/05}{Redefinition of \macrott{std@@citex},
1582     % \macrott{@input} and, if \package{bibunits} is loaded, of
1583     % \macrott{bu@@citex}.}
1584     %
1585     % If \package{babel} with options \option{frenchb} is loaded, some
1586     % characters like the colon `:' are made active. Since a colon
1587     % frequently appears within a cite key, active characters have to
1588     % be switched off for various commands. This can be done using
1589     % |\bbl@redefine|.
1590     %
1591     % First, check if \package{babel} is loaded, by checking if |\bbl@redefine|
1592     % is defined. In this case, |\bbl@redefine| commands.
1593     % \begin{macrocode}
1594     \AtBeginDocument{%
1595     \@ifundefined{bbl@redefine}%
1596     {}%
1597     {%
1598     \bbl@redefine\@input#1{%
1599     \@safe@activestrue\org@@input{#1}\@safe@activesfalse}%
1600     \@ifpackageloaded{natbib}%
1601     {%
1602     \bbl@redefine\std@@citex[#1][#2]#3{%
1603     \@safe@activestrue\org@std@@citex[#1][#2]{#3}\@safe@activesfalse}%
1604     \bbl@redefine\bu@@citex[#1][#2]#3{%
1605     \@safe@activestrue\org@bu@@citex[#1][#2]{#3}\@safe@activesfalse}%
1606     }%
1607     {% natbib not loaded
1608     \bbl@redefine\std@@citex[#1]#2{%
1609     \@safe@activestrue\org@std@@citex[#1]{#2}\@safe@activesfalse}%
1610     }%
1611     }%
1612     }
1613     % \end{macrocode}
1614     % \end{macro}
1615     % \end{macro}
1616     % \end{macro}
1617     %
1618     %
1619     % \begin{macrocode}
1620     %</package>
1621     % \end{macrocode}
1622     %
1623     % \PrintIndex
1624     % \PrintChanges
1625     % \Finale
1626     %