Debian Codegraph @

texmf-dist/source/latex/base/ltbibl.dtx

raw
1 % \iffalse meta-comment
2 %
3 % Copyright (C) 1993-2025
4 % The LaTeX Project and any individual authors listed elsewhere
5 % in this file.
6 %
7 % This file is part of the LaTeX base system.
8 % -------------------------------------------
9 %
10 % It may be distributed and/or modified under the
11 % conditions of the LaTeX Project Public License, either version 1.3c
12 % of this license or (at your option) any later version.
13 % The latest version of this license is in
14 % https://www.latex-project.org/lppl.txt
15 % and version 1.3c or later is part of all distributions of LaTeX
16 % version 2008 or later.
17 %
18 % This file has the LPPL maintenance status "maintained".
19 %
20 % The list of all files belonging to the LaTeX base distribution is
21 % given in the file `manifest.txt'. See also `legal.txt' for additional
22 % information.
23 %
24 % The list of derived (unpacked) files belonging to the distribution
25 % and covered by LPPL is defined by the unpacking scripts (with
26 % extension .ins) which are part of the distribution.
27 %
28 % \fi
29 % \iffalse
30 %%% From File: ltbibl.dtx
31 %
32 %<*driver>
33 % \fi
34 \ProvidesFile{ltbibl.dtx}
35 [2022/03/10 v1.1t LaTeX Kernel (Bibliography)]
36 % \iffalse
37 \documentclass{ltxdoc}
38 \GetFileInfo{ltbibl.dtx}
39 \title{\filename}
40 \date{\filedate}
41 \author{%
42 Johannes Braams\and
43 David Carlisle\and
44 Alan Jeffrey\and
45 Leslie Lamport\and
46 Frank Mittelbach\and
47 Chris Rowley\and
48 Rainer Sch\"opf}
49
50 \begin{document}
51 \MaintainedByLaTeXTeam{latex}
52 \maketitle
53 \DocInput{\filename}
54 \end{document}
55 %</driver>
56 % \fi
57 %
58 %
59 % \section{Bibliography Generation}
60 %
61 % A bibliography is created by the |thebibliography| environment, which
62 % generates a title such as ``References'', and a list of entries.
63 % The BIB\TeX{} program will create a file containing such an
64 % environment, which will be read in by the |\bibliography| command.
65 % With BIB\TeX, the following commands will be used.
66 %
67 % \DescribeMacro{\bibliography}
68 % |\bibliography|\marg{file1,file2, \ldots ,filen} : specifies
69 % the bibdata files. Writes a |\bibdata| entry on the |.aux| file
70 % and tries to read in |mainfile.bbl|.
71 %
72 % \DescribeMacro{\bibliographystyle}
73 % |\bibliographystyle|\marg{style} :
74 % Writes a |\bibstyle| entry on the |.aux| file.
75 %
76 % \DescribeEnv{thebibliography}
77 % The |thebibliography| environment is a list environment. To save the
78 % use of an extra counter, it should use |enumiv| as the item
79 % counter.
80 % Instead of using |\item|, items in the bibliography are produced by
81 % the following commands:\\
82 % |\bibitem|\marg{name} : Produces a numbered entry cited as
83 % \meta{name}.\\
84 % |\bibitem|\oarg{label}\marg{name} : Produces an entry labeled by
85 % \meta{Label} and cited by \meta{name}.
86 %
87 % The former is used for bibliographies with citations like [1], [2],
88 % etc.;
89 % the latter is used for citations like [Knuth82].
90 %
91 % The document class must define the thebibliography environment. This
92 % environment has a single argument, which is the widest bibliography
93 % label-- e.g., if the [Knuth67] is the widest entry, then this
94 % argument will be Knuth67. The |\thebibliography| command must begin
95 % a list environment, which the |\endthebibliography| command ends.
96 %
97 % \DescribeMacro{\cite}
98 % Entries are cited by the command |\cite|\marg{name}.
99 %
100 % \DescribeMacro{\nocite}
101 % |\nocite|\marg{citations}
102 % puts information on the |.aux| file that causes
103 % \BibTeX{} to include the \marg{citations} list in the bibliography,
104 % but puts nothing in the text.
105 %
106 % |\nocite{*}| is special: it tells \BibTeX{} to put the whole of a
107 % collection of references into the bibliography.
108 %
109 % \MaybeStop{}
110 %
111 %
112 % \changes{v1.0a}{1994/03/31}{Initial version of ltidxbib.dtx,
113 % split from ltherest.dtx}
114 % \changes{v1.1a}{1994/05/19}{Initial version of ltbibl.dtx,
115 % split from ltidxbib.dtx}
116 % \changes{v1.1b}{1994/05/21}{Use new warning commands}
117 % \changes{v1.1c}{1994/11/10}{Fix \cs{nocite}\texttt{\char`\{*\char`\}}}
118 %
119 % \begin{macrocode}
120 %<*2ekernel>
121 \message{bibliography,}
122 % \end{macrocode}
123 %
124 %
125 % \begin{oldcomments}
126 % PARAMETERS
127 %
128 % \@cite : A macro such that \@cite{LABEL1,LABEL2}{NOTE}
129 % produces the output for a \cite[NOTE]{FOO1,FOO2} command,
130 % where entry FOOi is defined by \bibitem[LABELi]{FOOi}.
131 % The switch @tempswa is true if the optional NOTE argument
132 % is present.
133 % The default definition is :
134 % \@cite{LABELS}{NOTE} ==
135 % BEGIN [LABELS
136 % IF @tempswa = T THEN , NOTE FI
137 % ]
138 % END
139 %
140 % \@biblabel : A macro to produce the label in the bibliography
141 % entry. For \bibitem[LABEL]{NAME}, the label is
142 % generated by \@biblabel{LABEL}. It has the default
143 % definition \@biblabel{LABEL} -> [LABEL].
144 % CONVENTION
145 %
146 % \b@FOO : The name or number of the reference created by \cite{FOO}
147 % E.g., if \cite{FOO} -> [17] , then \b@FOO -> 17.
148 %
149 % \end{oldcomments}
150 %
151 % \begin{macro}{\bibitem}
152 % \changes{v1.1g}{1995/05/08}{Removed unnecessary braces}
153 % \begin{macrocode}
154 \def\bibitem{\@ifnextchar[\@lbibitem\@bibitem}
155 % \end{macrocode}
156 % \end{macro}
157 %
158 % \begin{macro}{\@lbibitem}
159 % \changes{LaTeX2.09}{1992/02/26}{Added \cs{hfill} to restore
160 % left-alignment of bibliography labels in alpha style}
161 % \begin{macrocode}
162 \def\@lbibitem[#1]#2{\item[\@biblabel{#1}\hfill]\if@filesw
163 {\let\protect\noexpand
164 \immediate
165 \write\@auxout{\string\bibcite{#2}{#1}}}\fi\ignorespaces}
166 % \end{macrocode}
167 % \end{macro}
168 %
169 %
170 % \begin{macro}{\@bibitem}
171 % \changes{LaTeX2.09}{1991/11/13}{Changed counter enumi to enumiv,
172 % as it says in the comment above}
173 % \changes{LaTeX2.09}{1992/01/10}{Changed \cs{c@enumiv} to \cs{value}
174 % of \cs{@listctr}}
175 % \begin{macrocode}
176 \def\@bibitem#1{\item\if@filesw \immediate\write\@auxout
177 {\string\bibcite{#1}{\the\value{\@listctr}}}\fi\ignorespaces}
178 % \end{macrocode}
179 % \end{macro}
180 %
181 % \begin{macro}{\bibcite}
182 % \changes{v1.1f}{1995/04/24}
183 % {Make \cs{@onlypreamble} /1388.}
184 % \changes{v1.1h}{1995/06/19}
185 % {Call \cs{@newl@bel} so repeated keys produce better warning.}
186 % \changes{v1.1i}{1995/07/14}
187 % {Remove \cs{@onlypreamble} so still defined in new \cs{enddocument}}
188 % \begin{macrocode}
189 \def\bibcite{\@newl@bel b}
190 % \end{macrocode}
191 % \end{macro}
192 %
193 % \begin{macro}{\citation}
194 % \begin{macrocode}
195 \let\citation\@gobble
196 % \end{macrocode}
197 % \end{macro}
198 %
199 % \begin{macro}{\cite}
200 % \changes{v1.1j}{1995/10/16}{(DPC) Make robust}
201 % \begin{macrocode}
202 %</2ekernel>
203 %<*2ekernel|latexrelease>
204 %<latexrelease>\IncludeInRelease{2022/06/01}%
205 %<latexrelease> {\cite}{check for blank}%
206 \DeclareRobustCommand\cite{%
207 \@ifnextchar [{\@tempswatrue\@citex@checkblank}{\@tempswafalse\@citex@checkblank[]}}
208 % \end{macrocode}
209 % Due to the way \cs{@for} as used in \cs{@citex} behaves an empty
210 % argument to \cs{cite} did not produce any warning for a missing
211 % citation. So we now inject a command before calling \cs{@citex} that
212 % does the checking for us. It is not done in \cs{@citex} directly,
213 % because that command is altered by a number of packages/classes
214 % and this way it is more likely that the check survives.
215 % \changes{v1.1t}{2022/03/10}{Ensure that an empty argument generates
216 % a warning (gh/790)}
217 % \begin{macrocode}
218 \def\@citex@checkblank[#1]#2{%
219 \IfBlankTF {#2}%
220 {\@citex[#1]{\space}}%
221 {\@citex[#1]{#2}}%
222 }
223 %</2ekernel|latexrelease>
224 % \end{macrocode}
225 %
226 % \begin{macrocode}
227 %<latexrelease>\EndIncludeInRelease
228 %<latexrelease>\IncludeInRelease{0000/00/00}%
229 %<latexrelease> {\cite}{check for blank}%
230 %<latexrelease>
231 %<latexrelease>\DeclareRobustCommand\cite{%
232 %<latexrelease> \@ifnextchar [{\@tempswatrue\@citex}{\@tempswafalse\@citex[]}}
233 %<latexrelease>\let\@citex@checkblank\@undefined
234 %<latexrelease>
235 %<latexrelease>\EndIncludeInRelease
236 %<*2ekernel>
237 % \end{macrocode}
238 % \end{macro}
239 %
240 % \begin{macro}{\@citex}
241 % |\penalty\@m| added to definition of |\@citex| to allow a line
242 % break after the `,' in citations like [Jones80,Smith77]
243 % (Added 23 Oct 86)
244 %
245 % space added after the `,' (21 Nov 87)
246 %
247 % \changes{LaTeX2.09}{1991/10/25}
248 % {added \cs{reset@font}, suggested by Bernd Raichle.}
249 % \changes{LaTeX2.09}{1991/11/06}
250 % {added code to remove a leading blank}
251 % \changes{LaTeX2.09}{1992/08/14}
252 % {added missing argument braces around \cs{hbox},
253 % found by Ed Sznyter}
254 % \changes{LaTeX2.09}{1992/08/17}
255 % {simplified code for removing leading blanks in
256 % citation key (proposed by Frank Jensen and
257 % Kresten Krab Thorup)}
258 % \changes{LaTeX2.09}{1993/08/06}
259 % {Moved writing to .aux file in loop over citation keys
260 % so that leading blanks are removed there as well.}
261 % \changes{v1.0c}{1994/05/05}{Set switch for warning and end of run.}
262 % \changes{v1.1e}{1995/04/24}
263 % {Add \cs{mbox} to undefined case: latex/1239.}
264 % \changes{v1.1g}{1995/05/08}{Use \cs{@firstofone}}
265 % \changes{v1.1k}{1995/10/20}{Removed refundefined flag}
266 % \changes{v1.1l}{1995/12/07}{Restored name of \cs{G@refundefinedtrue}}
267 % \changes{v1.1m}{1997/04/24}{\cs{@empty} to avoid primitive
268 % error on empty cite keys. latex/2432}
269 % \changes{v1.1n}{2002/12/13}{Added \cs{leavevmode} in case citation
270 % is at start of paragraph (pr/3486)}
271 % \begin{macrocode}
272 \def\@citex[#1]#2{\leavevmode
273 \let\@citea\@empty
274 \@cite{\@for\@citeb:=#2\do
275 {\@citea\def\@citea{,\penalty\@m\ }%
276 \edef\@citeb{\expandafter\@firstofone\@citeb\@empty}%
277 \if@filesw\immediate\write\@auxout{\string\citation{\@citeb}}\fi
278 % \end{macrocode}
279 % Using |\hbox| instead of |\mbox| is fine because of the
280 % |\leavevmode| above. In fact the use of a box around the citation
281 % contents is more than questionable in my view (FMi), but within
282 % 2e I have to keep that for compatibility reasons as it would
283 % probably change too many existing documents. Its main reason is
284 % to avoid hyphenation of labels such as [FOOB89] into [FOO- B89]
285 % so in certain styles it makes sense; but, for example, in author
286 % year citations it becomes more than questionable.
287 %
288 % So Chris added yet another hook here, as suggested by, at least,
289 % Donald Arseneau. Note that this one is inside the first argument
290 % of the |\@cite| hook.
291 % This decouples the top-level typesetting of the citation from
292 % the details of the other business conducted here. All this really
293 % needs a complete rethink to get the right modularity.
294 %
295 % \changes{v1.1q}{2004/02/15}{Changed to use a hook with default
296 % value \cs{hbox}}
297 % \begin{macrocode}
298 \@ifundefined{b@\@citeb}{\hbox{\reset@font\bfseries ?}%
299 \G@refundefinedtrue
300 \@latex@warning
301 {Citation `\@citeb' on page \thepage \space undefined}}%
302 {\@cite@ofmt{\csname b@\@citeb\endcsname}}}}{#1}}
303 % \end{macrocode}
304 % \end{macro}
305 %
306 %
307 % \begin{macro}{\bibdata}
308 % \begin{macro}{\bibstyle}
309 % \begin{macrocode}
310 \let\bibdata=\@gobble
311 \let\bibstyle=\@gobble
312 % \end{macrocode}
313 % \end{macro}
314 % \end{macro}
315 %
316 %
317 % \begin{macro}{\bibliography}
318 % \changes{LaTeX2e}{1994/01/18}
319 % {Use \cs{@input@} so include files are listed.}
320 % \changes{LaTeX2e}{2018/11/09}
321 % {Zap spaces in the argument as BibTeX doesn't support them (github/88)}
322 % \begin{macrocode}
323 \def\bibliography#1{%
324 \if@filesw
325 \immediate\write\@auxout{\string\bibdata{\zap@space#1 \@empty}}%
326 \fi
327 \@input@{\jobname.bbl}}
328 % \end{macrocode}
329 % \end{macro}
330 %
331 % \begin{macro}{\bibliographystyle}
332 % \changes{v1.1d}{1994/12/09}{(DPC) Allow use in preamble.}
333 % \begin{macrocode}
334 \def\bibliographystyle#1{%
335 \ifx\@begindocumenthook\@undefined\else
336 \expandafter\AtBeginDocument
337 \fi
338 {\if@filesw
339 \immediate\write\@auxout{\string\bibstyle{#1}}%
340 \fi}}
341 % \end{macrocode}
342 % \end{macro}
343 %
344 %
345 % \begin{macro}{\nocite}
346 % (Added 14 Jun 85)
347 % \changes{v1.1c}{1994/11/10}{Fix \cs{nocite}\texttt{\char`\{*\char`\}}}
348 %
349 % This puts information on the |.aux| file that causes
350 % \BibTeX{} to include the citation list in the bibliography,
351 % but puts nothing in the text.
352 %
353 % RmS 93/08/06: Made loop for |\nocite| like that for |\@citex|,
354 % to get rid of leading spaces.
355 % \changes{v1.0b}{1994/05/03}{Make \cs{nocite} issue a warning
356 % for an undefined citation key.}
357 % \changes{v1.0c}{1994/05/05}{Do not write page number in
358 % \cs{nocite} warning message.}
359 % \changes{v1.0c}{1994/05/05}{Set switch for warning and end of run.}
360 % \changes{v1.1g}{1995/05/08}{Use \cs{@firstofone}}
361 % \changes{v1.1k}{1995/10/20}{Removed refundefined flag}
362 % \begin{macrocode}
363 %</2ekernel>
364 %<*2ekernel|latexrelease>
365 %<latexrelease>\IncludeInRelease{2021/06/01}%
366 %<latexrelease> {\nocite}{Allow nocite in preamble}%
367 \def\nocite#1{\@bsphack
368 % \end{macrocode}
369 % With the implementation designed already in \LaTeX\,2.09 the
370 % |\nocite| command will not work before |\begin{document}| since
371 % it tries to write to the |.aux| file which is not open before
372 % that point. As a result the ``reference'' will appear on the
373 % terminal and nothing else will happen.
374 %
375 % [This would be easy to fix, but then a document using the fix will
376 % silently fail on an older release of \LaTeX{}, missing all
377 % citations done with |\nocite|. Thus we do only generate an error
378 % message and leave the fix for a \LaTeXe{} successor.]
379 %
380 % Given that we are now a quarter century into using \LaTeXe{}
381 % there is no good reason any more do limit ourself to 2.09
382 % considerations. So we now simply delay the \cs{nocite} if it is
383 % issued in the preamble.
384 %
385 % \changes{v1.1o}{2003/05/18}{Check if we are after \cs{document}}
386 % \changes{v1.1p}{2004/01/04}{Changed error message}
387 % \begin{macrocode}
388 \ifx\@onlypreamble\document
389 % \end{macrocode}
390 % Since we are after |\begin{document}| we can do the citations:
391 % \begin{macrocode}
392 \@for\@citeb:=#1\do{%
393 \edef\@citeb{\expandafter\@firstofone\@citeb}%
394 \if@filesw\immediate\write\@auxout{\string\citation{\@citeb}}\fi
395 \@ifundefined{b@\@citeb}{\G@refundefinedtrue
396 \@latex@warning{Citation `\@citeb' undefined}}{}}%
397 \else
398 % \end{macrocode}
399 % But before |\begin{document}| we raised an error message in the
400 % past but as of 2021/05 not any longer.
401 % \begin{macrocode}
402 % \@latex@error{Cannot be used in preamble}\@eha
403 % \end{macrocode}
404 % Instead we delay the declaration to the start of the document.
405 % We have to use a late hook for this, so that it comes after the
406 % \texttt{.aux} file is open for writing and after
407 % \cs{@preamblecmds} was executed to change the above
408 % test. Therefore \cs{AtBeginDocument} would still be too early.
409 % \changes{v1.1s}{2020/12/10}{Delay any \cs{nocite} in the preamble
410 % instead of raising an error}
411 % \begin{macrocode}
412 \AddToHook{begindocument/end}[kernel]{\nocite{#1}}%
413 \fi
414 \@esphack}
415 %</2ekernel|latexrelease>
416 %<latexrelease>\EndIncludeInRelease
417 % \end{macrocode}
418 %
419 % \begin{macrocode}
420 %<latexrelease>\IncludeInRelease{0000/00/00}%
421 %<latexrelease> {\nocite}{Allow nocite in preamble}%
422 %<latexrelease>
423 %<latexrelease>\def\nocite#1{\@bsphack
424 %<latexrelease> \ifx\@onlypreamble\document
425 %<latexrelease> \@for\@citeb:=#1\do{%
426 %<latexrelease> \edef\@citeb{\expandafter\@firstofone\@citeb}%
427 %<latexrelease> \if@filesw\immediate\write\@auxout{\string\citation{\@citeb}}\fi
428 %<latexrelease> \@ifundefined{b@\@citeb}{\G@refundefinedtrue
429 %<latexrelease> \@latex@warning{Citation `\@citeb' undefined}}{}}%
430 %<latexrelease> \else
431 %<latexrelease> \@latex@error{Cannot be used in preamble}\@eha
432 %<latexrelease> \fi
433 %<latexrelease> \@esphack}
434 %<latexrelease>
435 %<latexrelease>\EndIncludeInRelease
436 %<*2ekernel>
437 % \end{macrocode}
438 %
439 % Since |\nocite{*}| should not produce a warning about undefined
440 % citation keys (see PR 557), we need to set the control sequence
441 % `|\b@*|' to something other than |\relax|. As a result |\cite{*}|
442 % will not warn either (but that never worked with \BibTeX{} in the
443 % first place).
444 % \begin{macrocode}
445 \expandafter\let\csname b@*\endcsname\@empty
446 % \end{macrocode}
447 % \end{macro}
448 %
449 %
450 % \subsection{Default definitions}
451 %
452 % This hook determines the `relative formatting' of the two logical
453 % parts of a citation with comment.
454 % \begin{macro}{\@cite}
455 % \begin{macrocode}
456 \def\@cite#1#2{[{#1\if@tempswa , #2\fi}]}
457 % \end{macrocode}
458 % \end{macro}
459 %
460 % \begin{macro}{\@cite@ofmt}
461 % \changes{v1.1q}{2004/02/15}{Added hook with default value \cs{hbox}}
462 % This is, in general, a command that appears to have one argument
463 % whose value is, in the kernel, a single cs whose name is the
464 % expansion of |b@\@citeb|; the expansion of this cs will
465 % typically be some hmode material that produces the detailed
466 % typeset form of just the citations themselves.
467 % \begin{macrocode}
468 \let\@cite@ofmt\hbox
469 % \end{macrocode}
470 % \end{macro}
471 %
472 % \begin{macro}{\@biblabel}
473 % \changes{LaTeX2.09}{1992/01/14}{removed \cs{hfill}}
474 % \begin{macrocode}
475 \def\@biblabel#1{[#1]}
476 %</2ekernel>
477 % \end{macrocode}
478 % \end{macro}
479 %
480 % \Finale
481 %