Debian Codegraph @

texmf-dist/tex/latex/cite/chapterbib.sty

raw
1 % chapterbib.sty Version 1.17 (18-Sep-2010) Donald Arseneau
2 %
3 % Allow multiple bibliographies in a LaTeX document, including items
4 % \cite'd in more than one bibliography.
5 %
6 % Copyright (C) 1989-2010 by Donald Arseneau and Niel Kempson
7 % These macros may be freely transmitted, reproduced, or modified
8 % provided that this notice is left intact.
9 %
10 % Instructions are below, after \endinput.
11 %
12 %====================== BEGIN MACROS ===========================
13
14 \newenvironment{cbunit}%
15 {\global\advance\c@inputfile\@ne \xdef\the@ipfilectr{@-\the\c@inputfile}%
16 \@namedef{b@*\@extra@b@citeb}{}%
17 \@CB@writeContext}%
18 {\gdef\the@ipfilectr{}\@CB@writeContext}
19
20 \def\@CB@writeContext{\if@filesw\begingroup
21 \edef\@tempa{\string\gdef\string\@extra@binfo{\@extra@b@citeb}}%
22 \immediate\write\@auxout{\@tempa\@CB@wtoc{toc}\@CB@wtoc{lof}\@CB@wtoc{lot}}%
23 \endgroup\fi}
24 \def\@CB@wtoc#1{\string\@writefile{#1}{\gdef
25 \string\the@ipfilectr{\@extra@b@citeb}}}%
26
27 \let\cb@include\include
28 \def\include#1{\clearpage \cbunit \xdef\@currentipfile{#1}%
29 \cb@include{#1}\global\let\@currentipfile\@savedjobname\endcbunit}
30
31 \newcommand\cb@input[1]{\cbunit \xdef\@currentipfile{#1}%
32 \input{#1}\global\let\@currentipfile\@savedjobname\endcbunit}
33 \let\cbinput\cb@input
34
35 \@ifundefined{@extra@binfo}{% if not defined by compatible package
36 % \@ifundefined{@safe@activestrue}{}{% babel is loaded
37 \@ifundefined{org@bibcite}{%
38 \let\bibcite@iii\bibcite
39 \def\bibcite#1{\bibcite@iii{#1\@extra@binfo}}%
40 }{% and will clobber us
41 \let\bibcite@iii\org@bibcite
42 \def\org@bibcite#1{\bibcite@iii{#1\@extra@binfo}}%
43 }%}
44 }{}%
45
46 \@ifundefined{@extra@b@citeb}{% if not defined by compatible package
47 \def\@citex[#1]#2{% Add \@extra@b@citeb to \cite
48 \leavevmode \let\@citea\@empty
49 \@cite{\@for\@citeb:=#2\do
50 {\@citea\let\@citea\citepunct
51 \edef\@citeb{\expandafter\@firstofone\@citeb\@empty}%
52 \if@filesw\immediate\write\@auxout{\string\citation{\@citeb}}\fi
53 \@ifundefined{b@\@citeb \@extra@b@citeb}{\hbox{\reset@font\bfseries ?}%
54 \G@refundefinedtrue
55 \@latex@warning{Citation `\@citeb' in file `\@currentipfile'
56 on page \thepage \space undefined}}%
57 {\@cite@ofmt{\citeform{\csname b@\@citeb
58 \@extra@b@citeb\endcsname}}}}}{#1}}
59 }{}%
60
61 % Test if \@extra@b@citeb hook needs to be added to \nocite
62 \setbox\@tempboxa\hbox{\let\@onlypreamble\document%
63 \def\@extra@b@citeb{\global\let\@gtempa\relax}\@extra@b@citeb
64 \def\@ifundefined#1#2#3{\global\let\@gtempa\@empty #1}%
65 \@fileswfalse \nocite{x}}
66
67 \ifx\@gtempa\@empty % define \nocite with hook
68 \def\nocite#1{\@bsphack % Add \@extra@b@citeb to \nocite
69 \ifx\@onlypreamble\document
70 \@for\@citeb:=#1\do{%
71 \edef\@citeb{\expandafter\@firstofone\@citeb\@empty}%
72 \if@filesw\immediate\write\@auxout{\string\citation{\@citeb}}\fi
73 \@ifundefined{b@\@citeb\@extra@b@citeb}{\G@refundefinedtrue\@latex@warning
74 {Citation `\@citeb' in file `\@currentipfile' undefined}}%
75 {}}%
76 \else
77 \@latex@error{Cannot be used in preamble}\@eha
78 \fi
79 \@esphack}
80 \fi
81
82 \@ifundefined{@cite@ofmt}{\let\@cite@ofmt\hbox}{}
83 \@ifundefined{citeform}{\let\citeform\@empty}{}
84 \@ifundefined{citepunct}{\def\citepunct{,\penalty\@m\ }}{}
85
86 \xdef\@savedjobname{\jobname}% save root file name as a macro
87 \let\@currentipfile\@savedjobname
88 \gdef\the@ipfilectr{}
89 \def\@extra@b@citeb{\the@ipfilectr}
90 \newcount\c@inputfile \global\c@inputfile=0
91
92 \gdef\@extra@binfo{} % in case .aux files are left from old run.
93
94 \let\cb@bibliographystyle\bibliographystyle
95 \def\bibliographystyle#1{\if\cb@roottest\cb@bibliographystyle{#1}\fi}
96 \def\cb@roottest{11}% for [rootbib]: {2\ifx\the@ipfilectr\@empty 1\else2\fi}
97
98 \def\bibliography#1{\if\cb@roottest
99 \if@filesw\immediate\write\@auxout{\string\bibdata{#1}}\fi
100 \fi
101 \begingroup % localize hooks into \@bibitem
102 \ifx\@CitationPrefix\@empty\else \ifx\the@ipfilectr\@empty\else
103 \@cb@insertprefix
104 \fi\fi
105 \cb@dobiblio{\@currentipfile.bbl}%
106 \endgroup}
107
108 \let\cb@dobiblio\@input@
109
110 \def\FinalBibPrefix{\bibname\space for\space}%
111 \def\@auto@bibname{Bibliography}
112
113 \def\sectionbib#1#2{% Macro to convert \thebibliography command
114 \@ifundefined{bibsection}{% Regular -- patch \thebibliography
115 \long\def\@tempa##1##{% to parse beginning of old def -> \@tempc
116 \long\def\@tempa####1\endthebibliography{}\def\@tempc{##1}\@tempa}%
117 \expandafter\@tempa\thebibliography{}{}\endthebibliography
118 \def\@tempa{\chapter*}%
119 \begingroup
120 \toks@{#1}%\showthe\toks@\show\@tempa\show\@tempc
121 \ifx\@tempa\@tempc\expandafter\PackageInfo\else \expandafter\PackageWarning\fi
122 {chapterbib}{The sectionbib option changes \string"\expandafter
123 \strip@prefix\meaning\@tempc\string" to \string"\the\toks@\string" %
124 in \string\thebibliography}%
125 \endgroup
126 \let\cb@thebibliography\thebibliography
127 \def\thebibliography{\let\@currentlabel\@empty
128 \ifx\the@ipfilectr\@empty \else
129 \expandafter\expandafter\expandafter\cb@sectionbib\fi
130 \cb@thebibliography}%
131 \expandafter\def\expandafter\cb@sectionbib\@tempc##1{#1{\bibname}%
132 \ifx\@currentlabel\@empty \begingroup \c@secnumdepth\m@ne
133 \addcontentsline{toc}{#2}{\bibname}% local: * -> no num
134 \csname#2mark\endcsname{\bibname}\endgroup\fi
135 \@ifnextchar\@mkboth{\@gobblethree}{}}%
136 }{% Some package or class has \bibsection -- patch that.
137 \long\def\@tempa##1##{% to parse beginning of old def
138 \long\def\@tempa####1\endthebibliography{}\def\@tempc{##1}\@tempa}%
139 \expandafter\@tempa\bibsection{}{}\endthebibliography
140 \def\@tempa{\chapter*}%
141 \begingroup
142 \toks@{#1}%
143 \ifx\@tempa\@tempc\expandafter\PackageInfo\else \expandafter\PackageWarning\fi
144 {chapterbib}{The sectionbib option changes \string"\expandafter
145 \strip@prefix\meaning\@tempc\string" to \string"\the\toks@\string" %
146 in \string\thebibliography}%
147 \endgroup
148 \let\cb@bibsection\bibsection
149 \def\bibsection{\let\@currentlabel\@empty
150 \ifx\the@ipfilectr\@empty \else
151 \expandafter\expandafter\expandafter\cb@sectionbib\fi
152 \cb@bibsection}%
153 \expandafter\def\expandafter\cb@sectionbib\@tempc{#1}%
154 }}
155
156 \long\def\@gobblethree#1#2#3{}%
157 \@ifundefined{bibname}{\def\bibname{Bibliography}}{}
158
159 % The following very messy hacking is to apply a prefix to each
160 % cite value, shown in the cites and the bibitems, and active
161 % with hyperref. The user should declare something like:
162 % \CitationPrefix{\thechapter.}
163 % Because this hooking-in is so tricky and specific, it is best
164 % to regard this feature as perpetually "experimental".
165 %
166 \let\@cb@use@prefix\@empty
167 \let\@CitationPrefix\@empty
168 %
169 \newcommand\CitationPrefix[1]{%
170 \def\@CitationPrefix{#1}%
171 \@ifundefined{cb@emptytoks}{\newtoks\cb@emptytoks}{}\cb@emptytoks={}%
172 \def\@cb@use@prefix{% Performed at the first \bibitem of each (sub-)bibliography
173 \let\value\@cb@valuehack
174 \def\@itemlabel{\@biblabel {\the\value\@listctr}}%
175 \let\@cb@use@prefix\@empty}%
176 \def\@cb@valuehack##1{% hook into "\the\value\@listctr"
177 \ifx\@listctr##1% only affect "\value\@listctr"
178 \cb@emptytoks % use up the preceding \the
179 \@CitationPrefix % insert the prefix text
180 \the % restore \the
181 \fi
182 \csname c@\@listctr\endcsname}% regular \value
183 }
184
185 % redefine \@lbibitem to use prefixed number; set hook (through \value)
186 % to use prefix in \@bibitem also. This \@cb@insertprefix is executed
187 % by \bibliography.
188 \def\@cb@insertprefix{%
189 \let\@cborg@lbibitem\@lbibitem \let\@cborg@bibitem\@bibitem
190 \def\@bibitem{\@cb@use@prefix\@cborg@bibitem}%
191 \def\@lbibitem[##1]{\@cb@use@prefix\@cborg@lbibitem[\@CitationPrefix##1]}%
192 \let\@cb@insertprefix\@empty % ensure no recursive use
193 }
194
195 \ProvidesPackage{chapterbib}[2010/09/18 \space v 1.17]
196 \DeclareOption{sectionbib}{\AtBeginDocument{\sectionbib{\section*}{section}}%
197 \let\FinalBibPrefix\@empty
198 \providecommand\StartFinalBibs{\chapter*{\bibname}%
199 \begingroup \c@secnumdepth\m@ne
200 \addcontentsline{toc}{chapter}{\bibname}%
201 \chaptermark{\bibname}\endgroup
202 \def\bibname{\@auto@bibname}}}%
203 \DeclareOption{draft}{\let\cbinput=\include}
204 \DeclareOption{rootbib}{\def\cb@roottest{2\ifx\the@ipfilectr\@empty2\else1\fi}}
205 \DeclareOption{duplicate}{\gdef\cb@biblist{}\let\cb@sub@input\@input@}
206 \DeclareOption{gather}{\gdef\cb@biblist{}\let\cb@sub@input\@gobble}
207 \ProcessOptions
208
209 \@ifundefined{chapter}%
210 {\@ifundefined{section}%
211 {\providecommand\CBMainSectioning{page}}% silly default to prevent errors
212 {\providecommand\CBMainSectioning{section}}%
213 }{\providecommand\CBMainSectioning{chapter}}%
214
215
216 \ifx\cb@sub@input\@input@ % For [duplicate]
217 \def\cb@dofinalbibs{\if@filesw
218 \toks@{\let\cb@bc\bibcite\let\bibcite\@gobbletwo}%
219 \immediate\write\@auxout{\the\toks@}\fi
220 \let\cb@elt\cb@dogatherbib \cb@biblist
221 \if@filesw\immediate\write\@auxout{\let\string\bibcite\string\cb@bc}\fi}%
222 \fi
223
224 \ifx\cb@sub@input\@gobble % For [gather]
225 \def\cb@dofinalbibs{\let\cb@elt\cb@dogatherbib \cb@biblist}%
226 \fi
227
228 \ifx\cb@biblist\@empty % duplicate or gather declared
229 \providecommand\StartFinalBibs{\def\bibname{\@auto@bibname}}%
230 \def\cb@dobiblio#1{% defined to save local context for later "dofinalbibs"
231 \begingroup\makeatletter
232 \ifx\the@ipfilectr\@empty % in root
233 \StartFinalBibs \cb@dofinalbibs
234 \else % in chapter, or section; append to \cb@biblist
235 \let\cb@elt\relax % list \cb@elt{title}{input#}{file}{citeprefix}
236 \let\@ifchapapp\@secondoftwo % provide a *possible* title
237 \expandafter\ifx\csname the\CBMainSectioning\endcsname\thechapter
238 \@ifundefined{@chapapp}{}{\let\@ifchapapp\@firstoftwo}\fi
239 \@ifundefined{FinalBibTitles}{\def\FinalBibTitles % locally
240 {\FinalBibPrefix
241 \@ifchapapp{\@chapapp}{\csname the\CBMainSectioning\endcsname}\space
242 \csname the\CBMainSectioning\endcsname}}{}%
243 \protected@xdef\cb@biblist{\cb@biblist\cb@elt
244 {\FinalBibTitles}{\the\c@inputfile}{\@currentipfile}{\@CitationPrefix}}%
245 \cb@sub@input{#1}%
246 \fi\endgroup}% end \cb@dobiblio
247 \def\cb@dogatherbib#1#2#3#4{% Title, count, fname, prefix
248 \begingroup
249 \protected@edef\@auto@bibname{#1}%
250 \def\@CitationPrefix{#4}%
251 \ifx\@CitationPrefix\@empty\else \@cb@insertprefix \fi
252 \global\c@inputfile#2\global\advance\c@inputfile\m@ne
253 \IfFileExists{#3.bbl}{\cb@input{#3.bbl}}{}%
254 \endgroup}
255 \fi
256
257 \AtBeginDocument{\let\sectionbib\undefined}
258
259 \endinput
260
261 %====================== BEGIN INSTRUCTIONS ===========================
262
263
264 chapterbib.sty Version
265 ~~~~~~~~~~~~~~ 1.17 (18-SEP-2010) DA Fix errors introduced in prev
266 1.16 (05-SEP-2010) DA \CitationPrefix with [gather], drop 2.09
267 1.15 (30-JUL-2009) DA (typo \CitationPrefix)
268 1.14 (31-MAR-2009) DA (\nocite*, \CitationPrefix, etc)
269 1.13 (11-DEC-2007) DA (new final-bib titling)
270 1.12 (21-MAR-2004) DA
271 1.11 (29-FEB-2004) DA (allow \nocite check)
272 1.10 (23-JUN-2003) DA (\bibsection \CBMainSectioning)
273 1.9 (19-SEP-2001) DA (sectionbib change; babel)
274 1.8 (29-APR-1999) DA (gather, duplicate, toc)
275 1.7 (21-JUL-1997) DA (sectionbib, \nocite)
276 1.6 (08-FEB-1997) Donald Arseneau (more sectionbib)
277 1.5 (09-OCT-1995) Donald Arseneau (rootbib)
278 1.4 (11-MAR-1995) Donald Arseneau (sectionbib)
279 1.3 (04-JUL-1994) Donald Arseneau (2e, cbunit)
280 1.2 (21-MAY-1993) Donald Arseneau (bug fix)
281 1.1 (24-MAR-1993) Donald Arseneau
282 1.0 (23-NOV-1988) Niel Kempson
283
284 Allow multiple bibliographies in a LaTeX document, including items
285 \cite'd in more than one bibliography. Despite the name "chapterbib",
286 the BIBLIOGRAPHIES ARE FOR EACH INCLUDED FILE, not necessarily for each
287 chapter. The main point is to allow you to use BibTeX: Each included
288 file should have its own \bibliographystyle and \bibliography commands,
289 and you should run BibTeX on each included file separately rather than
290 on the root file.
291
292 There are also the commands \begin{cbunit}, \end{cbunit}, and \cbinput
293 to allow multiple bibliographies without using \include (see item 4).
294 There are two added hooks, \citeform and \citepunct, which you can
295 redefine to customise the formatting of each entry in a citation list,
296 and the declaration \CitationPrefix to use in preference to \citeform
297 for numbering-by-chapter.
298
299 Usage, Restrictions, and Options
300 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
301
302 1. Normal use: Put \bibliographystyle and \bibliography commands in
303 each \include'd file. Run LaTeX; run BibTeX on each included file;
304 run LaTeX; run LaTeX.
305
306 2. The \bibliography and \bibliographystyle commands are not normally used
307 in the root file, only in files that have been \include'd. To have a
308 whole-document bibliography, see items 6-9, depending on which style of
309 whole-document bib.
310
311 3. If you can't use \include because a new section must start below the
312 preceding bibliography on the same page (odd format!), then you can
313 use \begin{cbunit}...\end{cbunit} or \cbinput, with a {thebibliography}
314 environment in each unit or input file. To use BibTeX: input separate
315 files using \cbinput; at first use the package or global option [draft],
316 run LaTeX on the document, then BibTeX on each file that was \cbinput;
317 finally, remove the [draft] option and run LaTeX again (maybe twice to
318 get page references right). The [draft] option only affects the treatment
319 of \cbinput, not \include or \begin{cbunit}.
320 With old LaTeX, do the preliminary run using \include commands, and
321 change these to \cbinput for the final run(s).
322
323 4. Your preferred citation style (xxx.sty) may not work with chapterbib at
324 first, but it is easy to make it compatible: In `xxx.sty' change every
325 "@\@citeb" to "@\@citeb\@extra@b@citeb", and insert the line
326 \@ifundefined{@extra@b@citeb}{\def\@extra@b@citeb{}}{}
327 somewhere (but not as a comment or as part of another definition!).
328
329 If the package also redefines \bibcite then you should change that
330 definition, replacing "@#1" with "@#1\@extra@binfo", and insert
331 \gdef\@extra@binfo{}
332 somewhere in the file. If the package defines a command that acts
333 similarly to \bibcite (being written to the aux file), then it should
334 have "\@extra@binfo" inserted the same way.
335 Some citation packages deviate quite far from LaTeX's own method
336 of organizing cite tags using "b@\@citeb". The instructions above
337 catch such extensions as "Y@\@citeb", but not more radical differences.
338 In such cases, try contacting the author of the citation package.
339 If a citation style does not define "\nocite", then that command
340 would not be converted when you make the patches to "@\@citeb".
341 Chapterbib will try to detect the hook in "\nocite", but if this fails
342 you may need to redefine "\nocite" (with any "@\@citeb" changed to
343 "@\@citeb\@extra@b@citeb") in that sty file.
344
345 5. The report and book document classes usually treat the bibliography as
346 an unnumbered chapter (\chapter*), which is not so good for bibliographies
347 IN a chapter. You can specify
348 \usepackage[sectionbib]{chapterbib}
349 to convert your bibliographies from \chapter* to \section*, with an
350 entry in the table of contents and the page-header. A bibliography in
351 the root file remains as a \chapter*. The [sectionbib] option modifies
352 the existing thebibliography environment (or the \bibsection command, if
353 present already), so the other formatting in the bibliography should
354 remain unchanged. On the other hand, if you already have a non-standard
355 bibliography defined, or if you want them numbered, it may be easier to
356 redefine \thebibliography directly, without any trickery.
357 Alternatively, you can use the \sectionbib command directly in the
358 document preamble. It takes two parameters: the sectioning command, and
359 the name of the sectioning level. For instance, the [sectionbib] option
360 does \sectionbib{\section*}{section}. Again, for the most control, it is
361 better to redefine \thebibliography entirely.
362
363 6. If you want a completely unrelated bibliography in the root file, perhaps
364 for a general reading list, you can provide your own bibliography there
365 using the thebibliography environment. I don't suppose this will appeal
366 to BibTeX users!
367
368 7. To have a cohesive bibliography for the whole document, plus individual
369 bibs in the chapters, put \bibliography commands in the included chapters
370 plus in the root file. Make sure the \bibliographystyle for the overall
371 bibliography appears FIRST, before any chapters are included. Run LaTeX;
372 run BibTeX on the root file; run BibTeX on each included file; run LaTeX;
373 run LaTeX. This produces an independent `overall' bibliography which only
374 makes sense for various `named' bibliography styles; a numbered style, or
375 one with any type of automatic enumeration (like Me2007a, Me2007b) will
376 give unrelated numbers in each bibliography and lead to confusion.
377 Bibtex will complain about multiple \bibdata commands when it makes
378 the whole bibliography, but it should obey the first. If you don't
379 want to see any error messages from bibtex, or if you don't want to put
380 the main \bibliographystyle command first in the document, then use
381 \usepackage[rootbib]{chapterbib} when you run LaTeX first; run BibTeX
382 on the root file; change to \usepackage{chapterbib}; run LaTeX; run
383 BibTeX on each included file; run LaTeX; run LaTeX.
384
385 8. To have a bibliography-by-chapter at the end instead of separate bibs
386 in the chapters, use \usepackage[gather]{chapterbib}, put \bibliography
387 commands in each file, and at the end of the main file. Run LaTeX as
388 in item 1. You can control the titling of the final bibliographies by
389 defining \FinalBibTitles, such as
390
391 \newcommand\FinalBibTitles{References for Chapter \thechapter}
392
393 A similar effect may be achived by RE-defining \FinalBibPrefix as
394
395 \renewcommand\FinalBibPrefix{References for }
396
397 Even more control is achieved by redefining \StartFinalBibs.
398 The default definition is (like)
399
400 \newcommand{\StartFinalBibs}{%
401 \renewcommand{\bibname}{Bibliography for chapter n}}
402
403 normally, but when using the [sectionbib] option it becomes
404
405 \newcommand{\StartFinalBibs}{\chapter*{\bibname}%
406 \addcontentsline{toc}{chapter}{\bibname}\@mkboth{\bibname}{\bibname}%
407 \renewcommand{\bibname}{Chapter n}}
408
409 where the \bibname text is now provided by \@auto@bibname, which
410 relies on bookkeeping and \FinalBibPrefix.
411
412 If your document class has neither section nor chapter, then you must
413 define \StartFinalBibs and also indicate the sectioning: for example,
414 if the main sectioning command in your document class is \motif:
415 \newcommand\CBMainSectioning{motif}
416
417 9. To have bibliographies in each chapter PLUS a bibliography-by-chapter at
418 the end, follow item 8, but declare \usepackage[duplicate]{chapterbib}
419 (or \usepackage[duplicate,sectionbib]{chapterbib}).
420
421 10. If you use Babel, load chapterbib before babel.
422
423 \citeform, \citepunct and \CitationPrefix:
424 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
425 Normally, the citations are formatted as given, but you can define \citeform
426 (with one parameter) to reformat every citation. Some possibilities:
427 \renewcommand\citeform[1]{\romannumeral 0#1}% roman numerals: [iv,x]
428 \renewcommand\citeform[1]{(#1)} % parentheses: [(3),(4),(7)]
429 If you change \citeform, you should probably define \@biblabel to match.
430
431 Another not-so-good example to provide a chapter-number prefix is
432 \renewcommand\citeform[1]{\thechapter.#1} % number by chapter.
433 This partially works, but has only limited applicability: it does not
434 work with cites in the front-matter (TOC, LOF) or with hyperref.
435 Instead, there is a \CitationPrefix command to apply a prefix to the
436 citation numbers (or names) in the bibliographies and \cite commands
437 for the included files. Use it by declaring something like
438 \CitationPrefix{\thechapter.}
439 in the preamble. The prefix will be applied to all the chapter-bibs
440 but will not be used in an overall (root) bibliography, if you have one.
441 (The \CitationPrefix mechanism is likely to break often if it conflicts
442 with other packages.)
443
444 \citepunct gives the punctuation (comma-penalty-space) between items
445 in the \cite list.
446
447 %====================== END INSTRUCTIONS ===========================
448 %
449 % -----------------Implementation notes---------------
450 %
451 % LaTeX normally uses command names in the form \b@TAG to associate a mnemonic
452 % TAG with the citation name or number. Chapterbib changes this to a command
453 % like \b@TAG@-nn where nn is a number identifying which included file is in
454 % effect.
455 %
456 % Tags indicating the citations and/or the input files:
457 % ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
458 % \c@inputfile = counter counting included files
459 % \the@ipfilectr = (empty) when typesetting from the root file,
460 % = @-\the\c@inputfile when typesetting from an included file
461 % \@extra@b@citeb = \the@ipfilectr (just an alias)
462 % \@extra@binfo = the value of \@extra@b@citeb as saved in .aux files
463 %
464 % \b@FOO:
465 % ~~~~~~~
466 % In the root file, the citation number (or name) is given by \b@FOO
467 % just like regular LaTeX, but in an \include'd file it is given by
468 % \b@FOO@-number. Any definition of \cite (\@citex) should refer
469 % to this using \csname b@\@citeb\@extra@b@citeb \endcsname.
470 %
471 % \include \cbinput and \cbunit:
472 % ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
473 % Redefine the \include macro so that when a file is \include'd...
474 % Increment the file number, (globally) update \the@ipfilectr to be
475 % @-number, and write \gdef\@extra@binfo{@-number} in the (main) .aux
476 % file, and do regular \include. When the \include'd file is finished,
477 % write \gdef\@extra@binfo{} in the (main) .aux file. Globally reset
478 % \the@ipfilectr to {}. Provide similar \cbunit and \cbinput.
479 %
480 % \cite:
481 % ~~~~~~
482 % Redefine \cite (\@citex actually) and \bibcite to use the file number
483 % tag along with the specified tag. \@citex also uses \citeform as a hook
484 % to reformat each individual citation.
485 % Only do the redefinitions if no citation style that supports chapterbib
486 % has been loaded--as indicated by existence of filename tags.
487 %
488 % \nocite:
489 % ~~~~~~~~
490 % A while ago LaTeX changed its \nocite so it checks the validity of the
491 % (no)citation tags. This necessitated adding the "\@extra@b@citeb" hook
492 % to \nocite. At first, I only redefined \nocite when redefining \cite,
493 % but there existed citation packages that supported chapterbib by putting
494 % \@extra@b@citeb into \cite but which did not define \nocite at all!
495 % These then gave warning messages for every \nocite. With version 1.7,
496 % I now try exercising the \nocite command with some functions disabled:
497 % (1) .aux file output is locally switched off; (2) The \@ifundefined
498 % command is hacked to merely typeset the text of the tag; (3) this is
499 % done in a disappearing \hbox so it generates no output. This detects
500 % (by setting a global flag \@gtempa) a \nocite command that executes
501 % \@ifundefined but not \@extra@b@citeb. In such cases, \nocite must
502 % be redefined.
503 %
504 % \citepunct and \citeform:
505 % ~~~~~~~~~~~~~~~~~~~~~~~~~
506 % These customization hooks are present in cite.sty; others (\citemid,
507 % \citeleft, \citeright) are not defined here because \@cite is not redefined.
508 % LaTeX has now adopted \@cite@ofmt, which is normally \hbox, so use both.
509 %
510 % We redefine \@testdef so that it properly checks whether the
511 % \cite labels have changed.
512 %
513 % Table of contents etc:
514 % ~~~~~~~~~~~~~~~~~~~~~~
515 % As of version 1.8, definitions of \@extra@b@citeb are written to the
516 % toc, lot, and lof files to avoid undefined citation tags in those tables.
517 % This is actually a problem in regular LaTeX with bibTeX -- cites that
518 % appear in those tables get numbered starting with 1, but they should
519 % be sequenced by where they originated -- but the problem was worse with
520 % chapterbib.
521 %
522 % \CitationPrefix:
523 % ~~~~~~~~~~~~~~~~
524 % This is a really ugly hack, but \citeform worked poorly for putting
525 % a chapter-identifier on each cite. It locally redefines both
526 % \@bibitem and \@lbibitem at each \bibliography. The insertion
527 % of the prefix is straightforward for \@lbibitem, but for \@bibitem
528 % the prefix is inserted by a redefined \value macro (eeek!). It has
529 % a deficiency in not being sorted as a simple number by cite.sty.
530 %
531 %---------------------------------------------------------------
532 %
533 % Authors Niel Kempson (original)
534 % ~~~~~~~ Donald Arseneau <[email protected]> March 1993 - Sept 2010
535 %
536 % Changes with ver 1.17: Fix errors made dropping ancient support;
537 % Make [sectionbib] give warn or info always.
538 % Changes with ver 1.16: Propagate prefix info to final bibs;
539 % drop support for ancient LaTeX versions
540 % Changes with ver 1.15: Fix typo \bibitemPrefix -> \CitationPrefix
541 % Changes with ver 1.14: No warning from \nocite* in chapters, \CitationPrefix
542 % Changes with ver 1.13: Rewrite final-bibs titling
543 % Changes with ver 1.12: Update \@citex \bfseries
544 % Changes with ver 1.11: Follow LaTeX's barring \nocite from preamble
545 % Changes with ver 1.10: \CBMainSectioning; \bibsection hook
546 % Changes with ver 1.9: sectionbib remove \@mkboth
547 % Changes with ver 1.8: options gather and duplicate; babel workarounds; toc
548 % Changes with ver 1.7: Change the \sectionbib command re. headings.
549 % Update \nocite and alter \citeform
550 % Changes with ver 1.6: Change the \sectionbib command to take arguments.
551 % Changes with ver 1.5: rootbib option; item 8 in instructions.
552 % Changes with ver 1.4: sectionbib and draft options
553 % Changes with ver 1.3: rewrite:
554 % The filename tag is defined in each .aux file by \include, not as an
555 % extra parameter to \bibcite. \@bibitem & \@lbibitem are left alone. Add
556 % \citeform and \citepunct. Add \cbunit and \cbinput for use without \include.
557 %