| 1 |
%% @texfile{ |
| 2 |
%% author = "Karl Berry and Oren Patashnik", |
| 3 |
%% version = "0.99h", |
| 4 |
%% date = "24 Apr 1991", |
| 5 |
%% filename = "btxmac.tex", |
| 6 |
%% address = "Please use electronic mail", |
| 7 |
%% checksum = "812 4053 30557", |
| 8 |
%% email = "[email protected]", |
| 9 |
%% codetable = "ISO/ASCII", |
| 10 |
%% supported = "yes", |
| 11 |
%% docstring = "Defines macros that make BibTeX work with plain TeX", |
| 12 |
%% } |
| 13 |
% BibTeX-for-TeX macros, version 0.99h, for BibTeX 0.99c, TeX 3.0 or later. |
| 14 |
% Copyright (C) 1990--91 by Karl Berry and Oren Patashnik; all rights reserved. |
| 15 |
% You may copy this file provided: that it's accompanied by the |
| 16 |
% "BibTeXing" document, whose text is contained in the file `btxdoc.tex'; |
| 17 |
% that any documentation you write for these macros also gives a |
| 18 |
% reference for "BibTeXing"; and that either you make absolutely no |
| 19 |
% changes to your copy, or if you do make changes, (1) you name the file |
| 20 |
% something other than `btxmac.tex' and you remove all occurrences of |
| 21 |
% `btxmac.tex' from the file, (2) you put, somewhere in the first twenty |
| 22 |
% lines of the file, your name, along with an electronic address at which |
| 23 |
% others who might use the file may reach you, and (3) you remove each |
| 24 |
% occurrence of Oren's name and electronic address from this file. These |
| 25 |
% restrictions help ensure that all standard versions of these macros are |
| 26 |
% identical, and that Oren doesn't get deluged with inappropriate e-mail. |
| 27 |
% |
| 28 |
% This file, btxmac.tex, contains TeX macros that allow BibTeX, a |
| 29 |
% bibliography program that was originally designed for use with LaTeX, |
| 30 |
% to work with plain TeX. Please report any bugs (outright goofs, |
| 31 |
% improvable macros, misfeatures, or unclear documentation) to Oren |
| 32 |
% Patashnik ([email protected]). These macros will become |
| 33 |
% frozen shortly after BibTeX version 1.00 is released. |
| 34 |
% |
| 35 |
% To use these macros you should be familiar with how BibTeX interacts |
| 36 |
% with LaTeX, since BibTeX's interaction with TeX is very similar; that |
| 37 |
% interaction is explained in the LaTeX manual. It also helps to |
| 38 |
% have read "BibTeXing", the documentation that accompanies BibTeX. |
| 39 |
% Then, if you want, you should redefine any of the macros that begin |
| 40 |
% with `\bbl' or `\biblabel' or `\print' that you need to get formatting |
| 41 |
% different from the default (the default settings are designed to |
| 42 |
% accompany a bibliography style like BibTeX's standard style `plain'). |
| 43 |
% The macros you might want to change are described briefly a few |
| 44 |
% paragraphs hence. Finally, as long as you follow the guidelines given |
| 45 |
% by the LaTeX manual and "BibTeXing", you simply \input btxmac. |
| 46 |
% [Remember the general scheme: Running (La)TeX writes information on |
| 47 |
% the .aux (auxiliary) file; then running BibTeX reads information from |
| 48 |
% the .aux, .bst (style), and .bib (database) files, and writes |
| 49 |
% information (the bibliography) on a .bbl file; then running (La)TeX |
| 50 |
% incorporates the bibliography; then running (La)TeX once more fixes |
| 51 |
% the remaining forward references into the bibliography. Thus, to get |
| 52 |
% everything incorporated into your output, you'll have to run (La)TeX, |
| 53 |
% BibTeX, (La)TeX, (La)TeX. (Standup, sitdown, fight, fight, fight.)] |
| 54 |
% |
| 55 |
% These macros can stand alone or they can be \input into macro packages |
| 56 |
% like Eplain. If you want to try out these macros on the 0.99 version |
| 57 |
% of the xampl.bib file that's distributed with BibTeX (that version of |
| 58 |
% the file has no self-identification), you'll need to define \mbox, |
| 59 |
% which is a LaTeX command, to be \hbox. |
| 60 |
% |
| 61 |
% |
| 62 |
% HISTORY |
| 63 |
% |
| 64 |
% Karl Berry wrote the original version of these macros in 1989 and |
| 65 |
% 1990, for use in his `Eplain' package. Oren Patashnik modified them |
| 66 |
% slightly in July 1990, as part of the official BibTeX distribution. |
| 67 |
% |
| 68 |
% 1-Aug-90 Version 0.99a, not released to the general public. |
| 69 |
% 14-Aug-90 0.99b, first general release. |
| 70 |
% 26-Aug-90 0.99c, made \@undefinedmessage work with other macro packages. |
| 71 |
% 6-Sep-90 0.99d, allowed for general formatting of bibliography labels, |
| 72 |
% for general formatting of (in-text) citations, and for |
| 73 |
% changing certain catcodes while reading the .aux file. |
| 74 |
% 14-Nov-90 0.99e, changed the way \@setletters works, made some \new...'s |
| 75 |
% non-outer, and changed the way Eplain reads this file. |
| 76 |
% 12-Dec-90 0.99f, made \@resetnumerals change the `,' and `.' catcodes; and |
| 77 |
% added \biblabelextrahang, \@getoptionalarg, and \bblsc. |
| 78 |
% 11-Mar-91 0.99g, made a few minor changes required by the way Eplain reads |
| 79 |
% this file, but no functional changes. |
| 80 |
% 24-Apr-91 0.99h, inhibited the reading and writing of the .aux file if it |
| 81 |
% isn't used or if the \noauxfile macro is defined, and |
| 82 |
% removed some .aux-file-opening detritus; printed the |
| 83 |
% cite-key of undefined citations in \tt font; changed the |
| 84 |
% catcode of `_' inside \cite; and called \@resetnumerals |
| 85 |
% from inside a group. |
| 86 |
% |
| 87 |
% |
| 88 |
% The LaTeX-related commands defined in this file include (a) the four |
| 89 |
% commands that a user types (\bibliography, \bibliographystyle, \cite, |
| 90 |
% and \nocite); (b) the three commands that BibTeX looks for in the .aux |
| 91 |
% file (\bibdata, \bibstyle, and \citation---there is a fourth command |
| 92 |
% that BibTeX looks for, but that command is related to LaTeX's \include |
| 93 |
% facility, so these macros ignore that command); and (c) a LaTeX |
| 94 |
% command (\newcommand) that's written by one of the four standard |
| 95 |
% bibliography styles (alpha). The definitions here are not exactly the |
| 96 |
% same as the corresponding LaTeX definitions (those eight LaTeX |
| 97 |
% definitions depend on a significant fraction of LaTeX itself). But |
| 98 |
% the only substantial differences are with \newcommand, which here, |
| 99 |
% without complaining, lets you redefine a preexisting control sequence |
| 100 |
% (in LaTeX, \newcommand won't let you redefine a preexisting command), |
| 101 |
% and which here doesn't make the control sequences it defines \long (in |
| 102 |
% LaTeX, that happens automatically); there may also be other minor |
| 103 |
% differences. To summarize: Unless you know what you're doing, you |
| 104 |
% shouldn't define any control sequences with these eight names: |
| 105 |
% |
| 106 |
% \bibdata |
| 107 |
% \bibliography |
| 108 |
% \bibliographystyle |
| 109 |
% \bibstyle |
| 110 |
% \citation |
| 111 |
% \cite |
| 112 |
% \newcommand |
| 113 |
% \nocite |
| 114 |
% |
| 115 |
% There are three other commands written by one or more of the four |
| 116 |
% standard (plain, abbrv, alpha, unsrt) or four semistandard (acm, |
| 117 |
% apalike, ieeetr, siam) bibliography styles; they take effect only |
| 118 |
% within the bibliography, and are redefinable, as explained later: |
| 119 |
% |
| 120 |
% \em |
| 121 |
% \newblock |
| 122 |
% \sc |
| 123 |
% |
| 124 |
% There's one control sequence you might want to use (but not redefine) |
| 125 |
% in redefining \biblabelprint: |
| 126 |
% |
| 127 |
% \biblabelwidth |
| 128 |
% |
| 129 |
% There are twelve other control sequences (explained later in more detail) |
| 130 |
% that the macros of this file will use if you define them---you should |
| 131 |
% define them after the \input btxmac command but before the \bibliography |
| 132 |
% command. The first five begin with `\bbl' and affect fonts, spacing, |
| 133 |
% and perhaps other characteristics of the bibliography; the next three |
| 134 |
% begin with `\biblabel' and determine how labels are formatted in the |
| 135 |
% bibliography; and the last four begin with `\print' and determine how |
| 136 |
% the in-text citations are formatted: |
| 137 |
% |
| 138 |
% \bblem |
| 139 |
% \bblhook |
| 140 |
% \bblnewblock |
| 141 |
% \bblrm |
| 142 |
% \bblsc |
| 143 |
% \biblabelcontents |
| 144 |
% \biblabelextrahang |
| 145 |
% \biblabelprint |
| 146 |
% \printbetweencitations |
| 147 |
% \printcitefinish |
| 148 |
% \printcitenote |
| 149 |
% \printcitestart |
| 150 |
% |
| 151 |
% If it's defined before the \input btxmac command, the control sequence |
| 152 |
% below inhibits the reading and writing of the .aux file(s), and the |
| 153 |
% issuing of related warning messages. Any definition will do. This |
| 154 |
% feature might help when you're working on draft stages of a document: |
| 155 |
% |
| 156 |
% \noauxfile |
| 157 |
% |
| 158 |
% Here's another control sequence (it's described later), with an `@' |
| 159 |
% in its name, that you probably won't want to redefine unless you are |
| 160 |
% writing another macro package; if you do redefine it, however, do it |
| 161 |
% before the \input btxmac command: |
| 162 |
% |
| 163 |
% \@undefinedmessage |
| 164 |
% |
| 165 |
% And here are still more control sequences that, should you already have |
| 166 |
% them defined, might conflict with the way the btxmac.tex macros use them |
| 167 |
% (but since each of these has an `@' in its name, it's unlikely that such |
| 168 |
% conflicts will arise unless you intend them): |
| 169 |
% |
| 170 |
% \@auxfile \@auxfiledonefalse \@auxfiledonetrue |
| 171 |
% \@bracketcheck \@citation \@cite |
| 172 |
% \@citedef \@citelabel \@citewarningfalse |
| 173 |
% \@citewarningtrue \@commandname \@continuenewcommand |
| 174 |
% \@emptymarkA \@emptymarkB \@fileexistsfalse |
| 175 |
% \@fileexiststrue \@finishcitedef \@finishtestfileexistence |
| 176 |
% \@for \@forloop \@fornoop |
| 177 |
% \@fortmp \@getoptionalarg \@@getoptionalarg |
| 178 |
% \@gobble \@if@auxfiledone \if@citewarning |
| 179 |
% \@ifempty \@@ifempty \if@fileexists |
| 180 |
% \if@notfirstcitation \@iforloop \@innerdef |
| 181 |
% \@innernewcount \@innernewdimen \@innernewif |
| 182 |
% \@innernewwrite \@itemnum \@letter |
| 183 |
% \@linenumber \@newcommandwithargs \@newcommand |
| 184 |
% \@next \@nextwhile \@nil |
| 185 |
% \@nnil \@notfirstcitationfalse \@notfirstcitationtrue |
| 186 |
% \@numparams \@oldatcatcode \@onecitation |
| 187 |
% \@optionalarg \@other \@paramdef |
| 188 |
% \@readauxfile \@readbblfile \@resetnumerals |
| 189 |
% \@scfont \@setletters \@spacesub |
| 190 |
% \@startdef \@testfileexistence \@tokstostring |
| 191 |
% \@ttsA \@ttsB \@ttsmarkA |
| 192 |
% \@ttsmarkB \@undefined \@writeaux |
| 193 |
% |
| 194 |
% |
| 195 |
% So to start things off we turn `@' into a letter (category code 11), |
| 196 |
% keeping track of the old category code for future restoration. |
| 197 |
% (Simply resetting it to 12 when we leave these macros is |
| 198 |
% insufficient.) The use of `\cite' as a temporary control sequence is |
| 199 |
% a kludge, but it's a reasonably simple way to accomplish what we need |
| 200 |
% without possibly overwriting something (without an `@' in its name) |
| 201 |
% that might already be defined. |
| 202 |
% |
| 203 |
\edef\cite{\the\catcode`@}% |
| 204 |
\catcode`@ = 11 |
| 205 |
\let\@oldatcatcode = \cite |
| 206 |
\chardef\@letter = 11 |
| 207 |
\chardef\@other = 12 |
| 208 |
% |
| 209 |
% |
| 210 |
% Next come some things that will be useful later. |
| 211 |
% |
| 212 |
% Make an outer definition into an inner one (due to Chris Thompson). |
| 213 |
% The arguments should be the control sequence to be defined, and the |
| 214 |
% new of the \outer control sequence, as characters; the control |
| 215 |
% sequence #1 is defined to be just the same as \csname#2\endcsname, but |
| 216 |
% not \outer. For example, \@innerdef\innernewcount{newcount} would |
| 217 |
% define \innernewcount to be a non-outer version of \newcount. |
| 218 |
% |
| 219 |
\def\@innerdef#1#2{\edef#1{\expandafter\noexpand\csname #2\endcsname}}% |
| 220 |
% |
| 221 |
% We use \@innerdef to make some of our allocations local, because |
| 222 |
% Eplain includes our code inside a conditional. We put @'s in the |
| 223 |
% names to minimize the (already small) chance of conflicts. |
| 224 |
% |
| 225 |
\@innerdef\@innernewcount{newcount}% |
| 226 |
\@innerdef\@innernewdimen{newdimen}% |
| 227 |
\@innerdef\@innernewif{newif}% |
| 228 |
\@innerdef\@innernewwrite{newwrite}% |
| 229 |
% |
| 230 |
% |
| 231 |
% Swallow one parameter. |
| 232 |
% |
| 233 |
\def\@gobble#1{}% |
| 234 |
% |
| 235 |
% |
| 236 |
% Use TeX 3.0's \inputlineno to get the line number, for better error |
| 237 |
% messages, but if we're using an old version of TeX, don't do anything. |
| 238 |
% |
| 239 |
\ifx\inputlineno\@undefined |
| 240 |
\let\@linenumber = \empty % Pre-3.0. |
| 241 |
\else |
| 242 |
\def\@linenumber{\the\inputlineno:\space}% |
| 243 |
\fi |
| 244 |
% |
| 245 |
% |
| 246 |
% \@getoptionalarg\CS gets an optional argument from the input, enclosed |
| 247 |
% in brackets, then expands \CS. We set \@optionalarg to \empty if we |
| 248 |
% don't find one, otherwise to the text of the argument. This assumes |
| 249 |
% the brackets don't have a funny category code. |
| 250 |
% |
| 251 |
\def\@getoptionalarg#1{\let\temp = #1\futurelet\next\@bracketcheck}% |
| 252 |
\def\@bracketcheck{\begingroup |
| 253 |
\if [\next |
| 254 |
\aftergroup\@@getoptionalarg |
| 255 |
\else |
| 256 |
\global\let\@optionalarg = \empty |
| 257 |
% |
| 258 |
% We can't do the \aftergroup\temp after the \fi, because then the |
| 259 |
% \temp gets in the way of reading the optional argument from the |
| 260 |
% input, if we do have one. |
| 261 |
\aftergroup\temp |
| 262 |
\fi |
| 263 |
\endgroup}% |
| 264 |
% |
| 265 |
\def\@@getoptionalarg[#1]{% |
| 266 |
\def\@optionalarg{#1}% |
| 267 |
\temp |
| 268 |
}% |
| 269 |
% |
| 270 |
% |
| 271 |
% \@tokstostring converts its argument into a list of character tokens. |
| 272 |
% It uses no commands that are executed in the stomach, only expansions |
| 273 |
% handled in the gullet. (This is necessary for use with \edef). |
| 274 |
% |
| 275 |
% Control sequences in the argument are not expanded. Blanks become a |
| 276 |
% \spacesub. The argument shouldn't contain other special characters. |
| 277 |
% |
| 278 |
\def\@tokstostring#1{\@ttsA#1 \@ttsmarkA}% |
| 279 |
% |
| 280 |
% \@ttsA partitions a sequence of tokens into portions delimited by blanks. |
| 281 |
% |
| 282 |
\def\@ttsA#1 #2\@ttsmarkA{% |
| 283 |
\@ifempty{#1}\else |
| 284 |
\@ttsB #1\@ttsmarkB |
| 285 |
% |
| 286 |
\@ifempty{#2}\else |
| 287 |
\@spacesub\@ttsA#2\@ttsmarkA |
| 288 |
\fi |
| 289 |
\fi |
| 290 |
}% |
| 291 |
% |
| 292 |
% \@ttsB processes a sequence of tokens with no contained blanks. |
| 293 |
% |
| 294 |
\def\@ttsB#1{% |
| 295 |
\ifx #1\@ttsmarkB\else |
| 296 |
\string #1% |
| 297 |
\expandafter\@ttsB |
| 298 |
\fi |
| 299 |
}% |
| 300 |
% |
| 301 |
% This is just so \ifx won't complain about an undefined control sequence. |
| 302 |
% |
| 303 |
\def\@ttsmarkB{\@ttsmarkB}% should never be expanded |
| 304 |
% |
| 305 |
% The expansion of this macro replaces spaces. |
| 306 |
% |
| 307 |
\def\@spacesub{+}% |
| 308 |
% |
| 309 |
% |
| 310 |
% \@ifempty tests if it is given an argument. |
| 311 |
% |
| 312 |
\def\@ifempty#1{\@@ifempty #1\@emptymarkA\@emptymarkB}% |
| 313 |
\def\@@ifempty#1#2\@emptymarkB{\ifx #1\@emptymarkA}% |
| 314 |
% |
| 315 |
\def\@emptymarkA{\@emptymarkA}% Again, so \ifx won't complain. |
| 316 |
% |
| 317 |
% |
| 318 |
% From LaTeX. |
| 319 |
% |
| 320 |
\def\@nnil{\@nil}% |
| 321 |
\def\@fornoop#1\@@#2#3{}% |
| 322 |
% |
| 323 |
\def\@for#1:=#2\do#3{% |
| 324 |
\edef\@fortmp{#2}% |
| 325 |
\ifx\@fortmp\empty \else |
| 326 |
\expandafter\@forloop#2,\@nil,\@nil\@@#1{#3}% |
| 327 |
\fi |
| 328 |
}% |
| 329 |
% |
| 330 |
\def\@forloop#1,#2,#3\@@#4#5{\def#4{#1}\ifx #4\@nnil \else |
| 331 |
#5\def#4{#2}\ifx #4\@nnil \else#5\@iforloop #3\@@#4{#5}\fi\fi |
| 332 |
}% |
| 333 |
% |
| 334 |
\def\@iforloop#1,#2\@@#3#4{\def#3{#1}\ifx #3\@nnil |
| 335 |
\let\@nextwhile=\@fornoop \else |
| 336 |
#4\relax\let\@nextwhile=\@iforloop\fi\@nextwhile#2\@@#3{#4}% |
| 337 |
}% |
| 338 |
% |
| 339 |
% |
| 340 |
% This macro tests if a file \jobname.#1 exists, and sets |
| 341 |
% \if@fileexists appropriately. If an optional argument is given, it is |
| 342 |
% used as the root part of the filename instead of \jobname. |
| 343 |
% |
| 344 |
\@innernewif\if@fileexists |
| 345 |
% |
| 346 |
\def\@testfileexistence{\@getoptionalarg\@finishtestfileexistence}% |
| 347 |
\def\@finishtestfileexistence#1{% |
| 348 |
\begingroup |
| 349 |
\def\extension{#1}% |
| 350 |
\immediate\openin0 = |
| 351 |
\ifx\@optionalarg\empty\jobname\else\@optionalarg\fi |
| 352 |
\ifx\extension\empty \else .#1\fi |
| 353 |
\space |
| 354 |
\ifeof 0 |
| 355 |
\global\@fileexistsfalse |
| 356 |
\else |
| 357 |
\global\@fileexiststrue |
| 358 |
\fi |
| 359 |
\immediate\closein0 |
| 360 |
\endgroup |
| 361 |
}% |
| 362 |
% |
| 363 |
% |
| 364 |
%% [[[start of BibTeX-specific stuff]]] |
| 365 |
% |
| 366 |
% Now come the four main LaTeX commands and their associated .aux |
| 367 |
% commands. Just as in LaTeX, \bibliographystyle defines the BibTeX |
| 368 |
% style name (.bst file, that is), and \bibliography defines the |
| 369 |
% database (.bib) file(s). The corresponding .aux-file commands are |
| 370 |
% \bibstyle and \bibdata, which are there only for BibTeX's (but not |
| 371 |
% LaTeX's) use. |
| 372 |
% |
| 373 |
\def\bibliographystyle#1{% |
| 374 |
\@readauxfile |
| 375 |
\@writeaux{\string\bibstyle{#1}}% |
| 376 |
}% |
| 377 |
\let\bibstyle = \@gobble |
| 378 |
% |
| 379 |
% As well as writing the \bibdata command to tell BibTeX |
| 380 |
% which .bib files to read, we read the .bbl file that |
| 381 |
% BibTeX (or a person, conceivably) has produced. |
| 382 |
% |
| 383 |
\def\bibliography#1{% |
| 384 |
\@readauxfile |
| 385 |
\@writeaux{\string\bibdata{#1}}% |
| 386 |
\@testfileexistence{bbl}% |
| 387 |
\if@fileexists |
| 388 |
\@readbblfile |
| 389 |
\fi |
| 390 |
}% |
| 391 |
\let\bibdata = \@gobble |
| 392 |
% |
| 393 |
% The \nocite{label,label,...} command writes its argument to \@auxfile, |
| 394 |
% unless instructed not to, but produces no text in the document. Both |
| 395 |
% the \nocite and \cite commands produce \citation commands in the .aux file. |
| 396 |
% |
| 397 |
\def\nocite#1{% |
| 398 |
\@readauxfile |
| 399 |
\@writeaux{\string\citation{#1}}% |
| 400 |
}% |
| 401 |
% |
| 402 |
\@innernewif\if@notfirstcitation |
| 403 |
% |
| 404 |
% \cite[note]{label,label,...} produces the citations for the labels as |
| 405 |
% well. If the optional argument `note' is present, it's added after |
| 406 |
% the labels. Since \cite calls \nocite before doing any writing, it |
| 407 |
% doesn't need to call \@readauxfile. We change the category code of |
| 408 |
% `_' so that the dummy definition given to the citation label doesn't |
| 409 |
% include a subcript character; that would cause TeX to complain. |
| 410 |
% |
| 411 |
\def\cite{\begingroup\catcode`_ = \@letter \@getoptionalarg\@cite}% |
| 412 |
% |
| 413 |
% Typeset the citations for the labels in #1, followed by the note, if |
| 414 |
% it exists. To change the citation's format in the text, redefine one |
| 415 |
% or more `\print...' macros, whose defaults appear later in this file. |
| 416 |
% |
| 417 |
\def\@cite#1{% |
| 418 |
\nocite{#1}% |
| 419 |
% Start printing the text, beginning with a left bracket by default. |
| 420 |
% |
| 421 |
\printcitestart |
| 422 |
\@notfirstcitationfalse |
| 423 |
\@for \@citation :=#1\do |
| 424 |
{% |
| 425 |
\expandafter\@onecitation\@citation\@@ |
| 426 |
}% |
| 427 |
\ifx\empty\@optionalarg\else |
| 428 |
\printcitenote{\@optionalarg}% |
| 429 |
\fi |
| 430 |
\printcitefinish |
| 431 |
\endgroup |
| 432 |
}% |
| 433 |
% |
| 434 |
\def\@onecitation#1\@@{% |
| 435 |
\if@notfirstcitation |
| 436 |
\printbetweencitations |
| 437 |
\fi |
| 438 |
% |
| 439 |
\expandafter \ifx \csname\@citelabel{#1}\endcsname \relax |
| 440 |
\if@citewarning |
| 441 |
\message{\@linenumber Undefined citation `#1'.}% |
| 442 |
\fi |
| 443 |
% Give it a dummy definition: |
| 444 |
\expandafter\gdef\csname\@citelabel{#1}\endcsname{% |
| 445 |
{\tt \nobreak\hskip0pt#1\nobreak\hskip0pt}}% |
| 446 |
\fi |
| 447 |
% Now produce the text, whether it was undefined or not. |
| 448 |
\csname\@citelabel{#1}\endcsname |
| 449 |
\@notfirstcitationtrue |
| 450 |
}% |
| 451 |
% |
| 452 |
% Given a label `foo', the macro `\b@foo' is supposed to |
| 453 |
% hold the text that should be produced. |
| 454 |
% |
| 455 |
\def\@citelabel#1{\@tokstostring{b@#1}}% |
| 456 |
% |
| 457 |
% So, how does a citation label get defined? When we read the .bbl file |
| 458 |
% (below), a \bibitem writes out a \@citedef command. And when we read |
| 459 |
% the \@citedef, we define \@citelabel{#1}, where #1 is the user's |
| 460 |
% label. But we have to be careful when reading the \@citedef, because |
| 461 |
% the second argument might have accents or other commands with numbers |
| 462 |
% as arguments. We have given the numerals category code 11 for reading |
| 463 |
% the .aux file, and that prevents them from being recognized as TeX |
| 464 |
% <number>s. Similarly for the other characters that can be part of a |
| 465 |
% <number>. So we have to reset the category codes before reading the |
| 466 |
% second argument. We also have to reset them back to letters when we |
| 467 |
% finish reading the \@citedef's, because there might be more labels |
| 468 |
% with numerals in them defined afterwards in the .aux file, put there |
| 469 |
% by Eplain or whatever. |
| 470 |
% |
| 471 |
\def\@citedef#1{% |
| 472 |
\begingroup |
| 473 |
\@resetnumerals |
| 474 |
\@finishcitedef{#1}% |
| 475 |
}% |
| 476 |
\def\@finishcitedef#1#2{% |
| 477 |
\expandafter\gdef\csname\@citelabel{#1}\endcsname{#2}% |
| 478 |
\endgroup |
| 479 |
}% |
| 480 |
\def\@resetnumerals{% |
| 481 |
\catcode`0 = \@other \catcode`1 = \@other \catcode`2 = \@other |
| 482 |
\catcode`3 = \@other \catcode`4 = \@other \catcode`5 = \@other |
| 483 |
\catcode`6 = \@other \catcode`7 = \@other \catcode`8 = \@other |
| 484 |
\catcode`9 = \@other \catcode`" = \@other \catcode`' = \@other |
| 485 |
\catcode`` = \@other \catcode`, = \@other \catcode`. = \@other |
| 486 |
}% |
| 487 |
% |
| 488 |
% |
| 489 |
% Reading the .bbl file also produces the typeset bibliography. Please |
| 490 |
% notice, however, that we do not produce the title for the references |
| 491 |
% (e.g., `References'), as LaTeX does. The formatting and spacing of |
| 492 |
% that title, whether it should go into the headline, and so on, are all |
| 493 |
% things determined by your format. We cannot know those things in |
| 494 |
% advance. If you wish, you can define \bblhook to produce the title. |
| 495 |
% Or just do it before the \bibliography command. |
| 496 |
% |
| 497 |
\def\@readbblfile{% |
| 498 |
% Define a counter to tell us which item number we are on. |
| 499 |
\@innernewcount\@itemnum |
| 500 |
% |
| 501 |
\begingroup |
| 502 |
\def\begin##1##2{% |
| 503 |
% ##1 is just `thebibliography'. |
| 504 |
% ##2 is the widest label. |
| 505 |
% We set (new dimen) \biblabelwidth based on the widest label |
| 506 |
\setbox0 = \hbox{\biblabelcontents{##2}}% |
| 507 |
\biblabelwidth = \wd0 |
| 508 |
}% |
| 509 |
\def\end##1{}% ##1 is `thebibliography' again. |
| 510 |
% |
| 511 |
% Here we have two possibilities: |
| 512 |
% \bibitem[typesetlabel]{citationlabel} |
| 513 |
% \bibitem{citationlabel} |
| 514 |
% If we have the second of these, the citations are numbered, starting |
| 515 |
% from one; we use our own count register \@itemnum for this. |
| 516 |
% |
| 517 |
\@itemnum = 0 |
| 518 |
\def\bibitem{\futurelet\next\@bibitem}% |
| 519 |
\def\@bibitem{% |
| 520 |
\begingroup \if [\next |
| 521 |
\aftergroup\@alphabibitem |
| 522 |
\else |
| 523 |
\aftergroup\@numberedbibitem |
| 524 |
\fi \endgroup |
| 525 |
}% |
| 526 |
\def\@alphabibitem[##1]##2{% |
| 527 |
% Need \xdef here for various reasons. |
| 528 |
\expandafter \xdef\csname\@citelabel{##2}\endcsname {##1}% |
| 529 |
\@finishbibitem{##2}% |
| 530 |
}% |
| 531 |
% |
| 532 |
\def\@numberedbibitem##1{% |
| 533 |
\advance\@itemnum by 1 |
| 534 |
\expandafter \xdef\csname\@citelabel{##1}\endcsname{\number\@itemnum}% |
| 535 |
\@finishbibitem{##1}% |
| 536 |
}% |
| 537 |
% |
| 538 |
\def\@finishbibitem##1{% |
| 539 |
\biblabelprint{\csname\@citelabel{##1}\endcsname}% |
| 540 |
\@writeaux{\string\@citedef{##1}{\csname\@citelabel{##1}\endcsname}}% |
| 541 |
\ignorespaces |
| 542 |
}% |
| 543 |
% |
| 544 |
% Do the printing (we're producing the bibliography, remember). |
| 545 |
% |
| 546 |
\let\em = \bblem |
| 547 |
\let\newblock = \bblnewblock |
| 548 |
\let\sc = \bblsc |
| 549 |
% Punctuation won't affect spacing; |
| 550 |
\frenchspacing |
| 551 |
% the penalties below are from LaTeX's [article,book,report].sty; |
| 552 |
\clubpenalty = 4000 \widowpenalty = 4000 |
| 553 |
% the next two values come from LaTeX's \sloppy command; |
| 554 |
\tolerance = 10000 \hfuzz = .5pt |
| 555 |
\everypar = {\hangindent = \biblabelwidth |
| 556 |
\advance\hangindent by \biblabelextrahang}% |
| 557 |
\bblrm |
| 558 |
% the \parskip is a guess at what looks good; |
| 559 |
\parskip = 1.5ex plus .5ex minus .5ex |
| 560 |
% and the .5em matches the \enspace of \biblabelprint below. |
| 561 |
\biblabelextrahang = .5em |
| 562 |
\bblhook |
| 563 |
% |
| 564 |
\input \jobname.bbl |
| 565 |
\endgroup |
| 566 |
}% |
| 567 |
% |
| 568 |
% The widest label's width is useful for redefining \biblabelprint; you |
| 569 |
% redefine \biblabelwidth, in effect, by redefining the |
| 570 |
% \biblabelcontents macro that appears below. And \biblabelextrahang, |
| 571 |
% which is redefinable inside \bblhook, is added to \biblabelwidth to |
| 572 |
% determine the amount of hanging indentation. |
| 573 |
% |
| 574 |
\@innernewdimen\biblabelwidth |
| 575 |
\@innernewdimen\biblabelextrahang |
| 576 |
% |
| 577 |
% Now come the main macros that are related to the printing of the |
| 578 |
% bibliography. Since you might want to redefine them, they are given |
| 579 |
% default definitions outside of \@readbblfile. |
| 580 |
% |
| 581 |
% The first one controls the printing of a bibliography entry's label. |
| 582 |
% If you change it, make sure that it starts with something like |
| 583 |
% \noindent or \indent that puts TeX into horizontal mode (even if the |
| 584 |
% label itself is empty); otherwise, the hanging indentation will get |
| 585 |
% messed up in certain circumstances. |
| 586 |
% |
| 587 |
\def\biblabelprint#1{% |
| 588 |
\noindent\hbox to \biblabelwidth{\biblabelcontents{#1}\hss}\enspace}% |
| 589 |
% |
| 590 |
% By default the labels are typeset in \bblrm, and enclosed in brackets. |
| 591 |
% |
| 592 |
\def\biblabelcontents#1{\bblrm [#1]}% |
| 593 |
% |
| 594 |
% The main text, too, is typeset using \bblrm, which is \rm by default. |
| 595 |
% |
| 596 |
\def\bblrm{\rm}% |
| 597 |
% |
| 598 |
% Emphasis for producing, e.g., titles, is done with \it by default. |
| 599 |
% |
| 600 |
\def\bblem{\it}% |
| 601 |
% |
| 602 |
% Some styles use a caps-and-small-caps font for author names. LaTeX |
| 603 |
% defines an \sc command but plain TeX doesn't, so we need one here. |
| 604 |
% The definition below doesn't load the font unless it's needed, but it |
| 605 |
% tries to load only the 10pt version, because it might not exist at |
| 606 |
% other point sizes. |
| 607 |
% |
| 608 |
\def\bblsc{\ifx\@scfont\@undefined |
| 609 |
\font\@scfont = cmcsc10 |
| 610 |
\fi |
| 611 |
\@scfont |
| 612 |
}% |
| 613 |
% |
| 614 |
% The major parts of an entry are separated with \bblnewblock. The |
| 615 |
% numbers below are taken from LaTeX's `article' style. |
| 616 |
% |
| 617 |
\def\bblnewblock{\hskip .11em plus .33em minus .07em}% |
| 618 |
% |
| 619 |
% Here's where you stick any other bibliography-formatting goodies, or |
| 620 |
% redefine the values above. |
| 621 |
% |
| 622 |
\let\bblhook = \empty |
| 623 |
% |
| 624 |
% |
| 625 |
% Here are the four default definitions for formatting the in-text |
| 626 |
% citations. These are what you redefine (after your \input btxmac but |
| 627 |
% before your \bibliography) to get parens instead of brackets, or |
| 628 |
% superscripts, or footnotes, or whatever. |
| 629 |
% |
| 630 |
\def\printcitestart{[}% left bracket |
| 631 |
\def\printcitefinish{]}% right bracket |
| 632 |
\def\printbetweencitations{, }% comma, space |
| 633 |
\def\printcitenote#1{, #1}% comma, space, note (if it exists) |
| 634 |
% |
| 635 |
% That scheme is pretty flexible. For example you could use |
| 636 |
% \def\printcitestart{$^\bgroup} |
| 637 |
% \def\printcitefinish{\egroup$} |
| 638 |
% \def\printbetweencitations{,} |
| 639 |
% \def\printcitenote#1{\hbox{\sevenrm\space (#1)}} |
| 640 |
% to get superscripted in-text citations. To get something radically |
| 641 |
% different, however, you'll have to define your own \cite command. |
| 642 |
% |
| 643 |
% When we read this from the .aux file, \citation means nothing. |
| 644 |
% |
| 645 |
\let\citation = \@gobble |
| 646 |
% |
| 647 |
% |
| 648 |
% Now comes the stuff for dealing with LaTeX's \newcommand. As |
| 649 |
% mentioned earlier, this \newcommand will redefine a preexisting |
| 650 |
% command; that's different from how LaTeX's \newcommand behaves. |
| 651 |
% |
| 652 |
\@innernewcount\@numparams |
| 653 |
% |
| 654 |
% \newcommand{\foo}[n]{text} defines the control sequence \foo to have |
| 655 |
% n parameters, and replacement text `text'. |
| 656 |
% |
| 657 |
\def\newcommand#1{% |
| 658 |
\def\@commandname{#1}% |
| 659 |
\futurelet\@next\@continuenewcommand |
| 660 |
}% |
| 661 |
% |
| 662 |
% Figure out if this definition has parameters. |
| 663 |
% |
| 664 |
\def\@continuenewcommand{\begingroup |
| 665 |
\if [\@next |
| 666 |
\aftergroup\@newcommandwithargs |
| 667 |
\else |
| 668 |
\global\@numparams = 0 |
| 669 |
\aftergroup\@newcommand |
| 670 |
\fi |
| 671 |
\endgroup}% |
| 672 |
% |
| 673 |
\def\@newcommandwithargs[#1]{% |
| 674 |
\global\@numparams = #1 |
| 675 |
\@newcommand |
| 676 |
}% |
| 677 |
% |
| 678 |
% \@numparams is how many arguments this command has. The name of the |
| 679 |
% command is \@commandname. The replacement text for the new macro is #1. |
| 680 |
% |
| 681 |
\def\@newcommand#1{% |
| 682 |
\def\@startdef{\expandafter\edef\@commandname}% |
| 683 |
\ifnum\@numparams=0 |
| 684 |
\let\@paramdef = \empty |
| 685 |
\else |
| 686 |
\ifnum\@numparams>9 |
| 687 |
\errmessage{\the\@numparams\space is too many parameters}% |
| 688 |
\else |
| 689 |
\ifnum\@numparams<0 |
| 690 |
\errmessage{\the\@numparams\space is too few parameters}% |
| 691 |
\else |
| 692 |
\edef\@paramdef{% |
| 693 |
% This is disgusting, but \loop doesn't work inside \edef, |
| 694 |
% because \body isn't defined. |
| 695 |
% |
| 696 |
\ifcase\@numparams |
| 697 |
\empty No arguments. |
| 698 |
\or ####1% |
| 699 |
\or ####1####2% |
| 700 |
\or ####1####2####3% |
| 701 |
\or ####1####2####3####4% |
| 702 |
\or ####1####2####3####4####5% |
| 703 |
\or ####1####2####3####4####5####6% |
| 704 |
\or ####1####2####3####4####5####6####7% |
| 705 |
\or ####1####2####3####4####5####6####7####8% |
| 706 |
\or ####1####2####3####4####5####6####7####8####9% |
| 707 |
\fi |
| 708 |
}% |
| 709 |
\fi |
| 710 |
\fi |
| 711 |
\fi |
| 712 |
\expandafter\@startdef\@paramdef{#1}% |
| 713 |
}% |
| 714 |
% |
| 715 |
%% [[[end of BibTeX-specific stuff]]] |
| 716 |
% |
| 717 |
% |
| 718 |
% Names of references (arguments given in the \cite and \nocite |
| 719 |
% commands) and file names (arguments given in the \bibliography and |
| 720 |
% \bibliographystyle commands) are recorded in \jobname.aux, called the |
| 721 |
% \@auxfile in these macros. Here's how they get read in. |
| 722 |
% |
| 723 |
\def\@readauxfile{% |
| 724 |
\if@auxfiledone \else % remember: \@auxfiledonetrue if \noauxfile is defined |
| 725 |
\global\@auxfiledonetrue |
| 726 |
\@testfileexistence{aux}% |
| 727 |
\if@fileexists |
| 728 |
\begingroup |
| 729 |
% Because we might be in horizontal mode when \@readauxfile |
| 730 |
% is called (if it's in response to a \cite or \nocite), we |
| 731 |
% want to ignore all the would-be spaces at the ends of |
| 732 |
% lines in the aux file. Fortunately, there are never any |
| 733 |
% (non-pathological) cases where an end-of-line might |
| 734 |
% actually be desired. If you really need to do something |
| 735 |
% strange, you can redefine \@setletters to do something |
| 736 |
% besides what it does now (this is intentionally left as |
| 737 |
% being somewhat painful to do). |
| 738 |
\endlinechar = -1 |
| 739 |
\@setletters |
| 740 |
\input \jobname.aux |
| 741 |
\endgroup |
| 742 |
\else |
| 743 |
\message{\@undefinedmessage}% |
| 744 |
\global\@citewarningfalse |
| 745 |
\fi |
| 746 |
\immediate\openout\@auxfile = \jobname.aux |
| 747 |
\fi |
| 748 |
}% |
| 749 |
% |
| 750 |
% The \@readauxfile macro does all that work the first time it's called. |
| 751 |
% Since it's called once for every \cite, \nocite, \bibliography, and |
| 752 |
% \bibliographystyle command that the user issues, we need to remember |
| 753 |
% whether the work's been done. It's considered done if we're not to do |
| 754 |
% it---that is, if \noauxfile is defined. |
| 755 |
% |
| 756 |
\newif\if@auxfiledone |
| 757 |
\ifx\noauxfile\@undefined \else \@auxfiledonetrue\fi |
| 758 |
% |
| 759 |
% Since lots of characters are allowable inside reference names, and |
| 760 |
% since a reference name can get converted into a control sequence, |
| 761 |
% \@readauxfile must treat many characters as letters. It does that by |
| 762 |
% calling \@setletters, which changes the category code of all \@other |
| 763 |
% characters to \@letter. The 128/256 business arises because character |
| 764 |
% codes go up to 256 starting with TeX 3.0, but up to only 128 with |
| 765 |
% earlier versions. |
| 766 |
% |
| 767 |
\def\@setletters{% |
| 768 |
\count255 = 0 |
| 769 |
\edef\temp{\ifx\inputlineno\@undefined 128\else 256\fi}% |
| 770 |
\loop |
| 771 |
\ifnum\catcode\count255 = \@other |
| 772 |
\catcode\count255 = \@letter |
| 773 |
\fi |
| 774 |
\advance\count255 by 1 |
| 775 |
\ifnum\count255<\temp |
| 776 |
\repeat |
| 777 |
% The Eplain package uses underscores to construct the label names. |
| 778 |
\catcode`\_ = \@letter |
| 779 |
}% |
| 780 |
% |
| 781 |
% It's conceivable you'd want to change how other characters are read; |
| 782 |
% to do that, change their category code before doing \input btxmac. |
| 783 |
% |
| 784 |
% |
| 785 |
% After reading the .aux file, \@readauxfile opens it for writing. |
| 786 |
% The \@writeaux macro does the actual writing (as long as |
| 787 |
% \noauxfile is undefined). |
| 788 |
% |
| 789 |
\@innernewwrite\@auxfile |
| 790 |
\def\@writeaux#1{\ifx\noauxfile\@undefined \write\@auxfile{#1}\fi}% |
| 791 |
% |
| 792 |
% |
| 793 |
% A macro package that uses btxmac.tex might define |
| 794 |
% \@undefinedmessage (before doing an \input btxmac). |
| 795 |
% |
| 796 |
\ifx\@undefinedmessage\@undefined |
| 797 |
\def\@undefinedmessage{No .aux file; I won't give you warnings about |
| 798 |
undefined citations.}% |
| 799 |
\fi |
| 800 |
% |
| 801 |
% Even if citations are undefined, we want to complain only if |
| 802 |
% \@citewarningtrue. The default is to set \@citewarningtrue unless |
| 803 |
% \noauxfile is defined. Again, a macro package that uses |
| 804 |
% btxmac.tex might want to redefine this. |
| 805 |
% |
| 806 |
\@innernewif\if@citewarning |
| 807 |
\ifx\noauxfile\@undefined \@citewarningtrue\fi |
| 808 |
% |
| 809 |
% |
| 810 |
% Finally, before leaving we restore @'s old category code. |
| 811 |
% |
| 812 |
\catcode`@ = \@oldatcatcode |