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