Debian Codegraph @

texmf-dist/bibtex/bst/frankenstein/achicago.bst

raw
1 %^^A* legal notices
2 % \iffalse
3 %
4 % This program is part of the Frankenstein bundle for LaTeX.
5 %
6 % Copyright 1995-2001 Matt Swift <[email protected]>.
7 %
8 % This file contains both the code and documentation for the
9 % achicago BibTeX style. It will work ONLY if it is placed in a
10 % proper directory. Files called README, INSTALL, achicago.tex
11 % and achicago.ins should have also been distributed to you
12 % with this file. See them for more information on how to typeset
13 % the documentation with LaTeX and how to generate a version of this
14 % file that will work faster than this one.
15 %
16 % This program is free software; you may redistribute it and/or
17 % modify it under the conditions of the LaTeX Project Public
18 % License, either version 1.2 or (at your option) any later version.
19 % The latest version of this license is in
20 % http://www.latex-project.org/lppl.txt, and version 1.2 or later is
21 % part of all distributions of LaTeX version 1999/12/01 or later.
22 %
23 % This program is distributed in the hope that it will be useful,
24 % but without any warranty; without even the implied warranty of
25 % merchantability or fitness for a particular purpose. See the
26 % LaTeX Project Public License for more details.
27 %
28 % \fi
29 %
30 %^^A* checks
31 %
32 %^^A NOTE: The character table, with two %'s, will get written to all files.
33 %% \CharacterTable
34 %% {Upper-case \A\B\C\D\E\F\G\H\I\J\K\L\M\N\O\P\Q\R\S\T\U\V\W\X\Y\Z
35 %% Lower-case \a\b\c\d\e\f\g\h\i\j\k\l\m\n\o\p\q\r\s\t\u\v\w\x\y\z
36 %% Digits \0\1\2\3\4\5\6\7\8\9
37 %% Exclamation \! Double quote \" Hash (number) \#
38 %% Dollar \$ Percent \% Ampersand \&
39 %% Acute accent \' Left paren \( Right paren \)
40 %% Asterisk \* Plus \+ Comma \,
41 %% Minus \- Point \. Solidus \/
42 %% Colon \: Semicolon \; Less than \<
43 %% Equals \= Greater than \> Question mark \?
44 %% Commercial at \@ Left bracket \[ Backslash \\
45 %% Right bracket \] Circumflex \^ Underscore \_
46 %% Grave accent \` Left brace \{ Vertical bar \|
47 %% Right brace \} Tilde \~}
48 %
49 % \CheckSum{46}
50 %
51 %^^A** new macros
52 % \newlet \entry\WrapquotesIN
53 % \newcommand*\field [1] {{\textitswitch\WrapquotesIN{#1}}}
54 % \newlet \gvar\texttt ^^A global variable
55 % \newlet \evar\texttt ^^A entry variable
56 % \newcommand*\function [1] {\texttt{\bfseries #1}}
57 % \newcommand\stack [2] {\par{\ttfamily #1 $\mapsto$ #2}\par}
58 % \newcommand\defentrytype [3] {Required: #1\par Optional: #2\par#3}
59 % \newcommand*\builtin [1] {\code{#1}\$}
60 %
61 % \todo{explain conventions; put some in \package{compsci}}
62 %
63 %^^A** nocites
64 % \nocite{*} ^^A FIX remove for distribution
65 % \nocite {abrams:natural}
66 % \nocite {ackerley:beckett:augustine}
67 % \nocite {amiran:beckett:wandering}
68 % \nocite {bair:beckett:bio}
69 % \nocite {beckett:cspr}
70 % \nocite {beckett:godot}
71 % \nocite {beckett:letter:yellow}
72 % \nocite {beckett:notebook:krapp,beckett:notebook:godot,^^A
73 % beckett:notebook:endgame,beckett:notebook:happy}
74 % \nocite {beckett:yellow}
75 % \nocite {blake:job}
76 % \nocite {bloom:anxiety:1}
77 % \nocite {bloom:beckett:trilogyintro}
78 % \nocite {borges:ficciones}
79 % \nocite {brater:beckett:why}
80 % \nocite {bryden:beckett:god}
81 % \nocite {bryden:beckett:smiles}
82 % \nocite {buning:beckett:via}
83 % \nocite {burrows:beckett:interview}
84 % \nocite {calder:beckett:bair}
85 % \nocite {carey:beckett:introjoyce}
86 % \nocite {carey:beckett:pieta}
87 % \nocite {carroll:dante:purgatorio,dante:mandelbaum:purgatorio,%
88 % dante:ciardi:purgatorio,vernon:dante:purgatorio}
89 % \nocite {carroll:dante:purgatorio}
90 % \nocite {cassedy:group}
91 % \nocite {chambers-murray}
92 % \nocite {chicago:14}
93 % \nocite {coetzee:beckett:revisions,stevenson:beckett:lobster}
94 % \nocite {coetzee:beckett:revisions}
95 % \nocite {cohn:beckett:play}
96 % \nocite {common-prayer}
97 % \nocite {companion:mind,gleitman:psych}
98 % \nocite {companion:mind}
99 % \nocite {copleston:phil:cusa}
100 % \nocite {copleston:phil:pseudo}
101 % \nocite {cronin:beckett:modernist}
102 % \nocite {culik:beckett:math}
103 % \nocite {culik:beckett:watt}
104 % \nocite {dante:ciardi:paradiso}
105 % \nocite {dante:ciardi:purgatorio}
106 % \nocite {dante:mandelbaum:purgatorio}
107 % \nocite {dearlove:beckett:residual}
108 % \nocite {donne:paradoxes}
109 % \nocite {driver:beckett:madeleine}
110 % \nocite {ellis:beckett:surds}
111 % \nocite {ellmann:joyce}
112 % \nocite {empson:ambiguity}
113 % \nocite {euclid:elements:brit}
114 % \nocite {farrow:beckett:art}
115 % \nocite {federman:beckett:works}
116 % \nocite {fergusson:dante:purgatorio}
117 % \nocite {fletcher:beckett:art}
118 % \nocite {freud:btpp:norton}
119 % \nocite {frye:anatomy:bate}
120 % \nocite {gardner:circus:cyclic}
121 % \nocite {gascoigne:works:posies}
122 % \nocite {gates:beckett:goon}
123 % \nocite {gleitman:psych}
124 % \nocite {gontarski:beckett:undoing}
125 % \nocite {green:beckett:augustine}
126 % \nocite {green:beckett:niente}
127 % \nocite {greene:repentance}
128 % \nocite {harper:beckett:irish,zurbrugg:beckett:irish,^^A
129 % harrington:beckett:local,obrien:beckett:country}
130 % \nocite {harvey:beckett:poet}
131 % \nocite {heraclitus:kirk:cosmic}
132 % \nocite {hill:vaughan}
133 % \nocite {hobson:beckett:year}
134 % \nocite {hopkins:gardner}
135 % \nocite {iser:beckett:negativity}
136 % \nocite {israel:beckett:bair}
137 % \nocite {james:principles}
138 % \nocite {jewinski:beckett:epiphany}
139 % \nocite {jones:beckett:murphy}
140 % \nocite {joyce:kershner:portrait}
141 % \nocite {joyce:ulysses:gabler}
142 % \nocite {joyce:wake}
143 % \nocite {juliet:beckett:conversations}
144 % \nocite {jung:psych-lit}
145 % \nocite {jung:tav:3}
146 % \nocite {jung:tav}
147 % \nocite {kennedy:beckett:murphy}
148 % \nocite {kenner:beckett:study}
149 % \nocite {kenner:beckett:syntax}
150 % \nocite {knowlson:beckett:frescoes}
151 % \nocite {knowlson:beckett:life}
152 % \nocite {koffka:gestalt}
153 % \nocite {krance:beckett:physics}
154 % \nocite {kroll:beckett:bel}
155 % \nocite {lakoff:johnson,lakoff:women,johnson:body}
156 % \nocite {lees:beckett:music}
157 % \nocite {levy:beckett:conv}
158 % \nocite {lippman:beckett:noti}
159 % \nocite {lodge:beckett:ping}
160 % \nocite {marculescu:beckett:solipsism}
161 % \nocite {mchugh:wake}
162 % \nocite {mcmillan:beckett:allegory}
163 % \nocite {merwin:ladders}
164 % \nocite {milton:riverside:paralost}
165 % \nocite {miskinis:beckett:recurrrence}
166 % \nocite {montgomery:beckett:quantum}
167 % \nocite {mood:beckett:system}
168 % \nocite {murphy:beckett:criticism}
169 % \nocite {niven:numbers}
170 % \nocite {norton:english}
171 % \nocite {obrien:beckett:country}
172 % \nocite {obrien:dreamforward}
173 % \nocite {ohara:beckett:jung:jobs,ohara:beckett:freud:jobs}
174 % \nocite {ohara:beckett:valery}
175 % \nocite {opie:nursery}
176 % \nocite {ovid:loeb}
177 % \nocite {perkins:romantic}
178 % \nocite {pilling:beckett:companion}
179 % \nocite {posnock:beckett:valery}
180 % \nocite {princeton:poetics}
181 % \nocite {rabinovitz:beckett:aphorisms}
182 % \nocite {rabinovitz:beckett:development,rabinovitz:beckett:innovation}
183 % \nocite {rabinovitz:beckett:development}
184 % \nocite {rabinovitz:beckett:innovation}
185 % \nocite {rabinovitz:beckett:psych}
186 % \nocite {random,OED:2,heritage,webster:3}
187 % \nocite {random}
188 % \nocite {renaud:beckett:mag}
189 % \nocite {ricks:beckett:dying}
190 % \nocite {rudin:math:analysis}
191 % \nocite {sacks:wife}
192 % \nocite {scruton:beckett:descartes}
193 % \nocite {segre:beckett:ping}
194 % \nocite {sharp:folksongs}
195 % \nocite {shenker:beckett:moody}
196 % \nocite {shimony:newphys}
197 % \nocite {smith:beckett:aporia}
198 % \nocite {stern:beckett:inter}
199 % \nocite {stevenson:beckett:lobster}
200 % \nocite {swift:tub}
201 % \nocite {topsfield:beckett:humour}
202 % \nocite {unger:ayer:exist}
203 % \nocite {vernon:dante:purgatorio}
204 % \nocite {webster:3}
205 % \nocite {winston:beckett:footnote}
206 % \nocite {wolfson:religion:history}
207 % \nocite {wolosky:beckett:mysticism}
208 % \nocite {work:folksongs}
209 % \nocite {zeifman:beckett:religion}
210 % \nocite{acheson:beckett:murphy}
211 % \nocite{anspaugh:beckett:faith}
212 % \nocite{bair:beckett:bio}
213 % \nocite{beckett:pricks}
214 % \nocite{carey:beckett:joyce}
215 % \nocite{cohn:beckett:collection}
216 % \nocite{common-prayer}
217 % \nocite{connor:beckett:animals}
218 % \nocite{davies:beckett:ideal}
219 % \nocite{eliot:middlemarch:random}
220 % \nocite{farrow:beckett:art}
221 % \nocite{freud:btpp:norton}
222 % \nocite{harvey:beckett:poet}
223 % \nocite{joyce:dubliners}
224 % \nocite{juliet:beckett:conversations}
225 % \nocite{jung:tav}
226 % \nocite{kroll:beckett:bel}
227 % \nocite{linden:herbert}
228 % \nocite{mccarthy:beckett:essays}
229 % \nocite{mcmillan:beckett:allegory}
230 % \nocite{melville:dick:newberry}
231 % \nocite{murphy:beckett:criticism}
232 % \nocite{norton:modern}
233 % \nocite{obrien:beckett:country}
234 % \nocite{obrien:dreamforward}
235 % \nocite{pilling:beckett:before}
236 % \nocite{putnam:beckett:caravan}
237 % \nocite{rabinovitz:beckett:aphorisms}
238 % \nocite{rabinovitz:beckett:development}
239 % \nocite{rabinovitz:beckett:innovation}
240 % \nocite{random}
241 % \nocite{ricks:beckett:dying}
242 % \nocite{scruton:beckett:descartes}
243 % \nocite{stern:beckett:inter}
244 % \nocite{whitman:leaves:norton}
245 %
246 %^^A** abstract
247 % \begin{abstract}
248 % \manual bibliography style \BibTeX{} macros.
249 % \end{abstract}
250 % \tableofcontents
251 %
252 % \part{Discussion}
253 %
254 % \caveat{The dox are spotty for this bibstyle---sorry! This is a pretty
255 % stable style, however. I've included almost my entire test cases. If you're
256 % puzzled, you may compare \file{frankenstein.bib} with what you see in the
257 % References section at the end of this document. Or please write me.}
258 %
259 % Reference list ordering: alphabetical by author or whatever passes for author
260 % in the absence of one.
261 %
262 % \section{Pros and cons of this style}
263 %
264 % See a discussion in the documentation for the \package{achicago} package.
265 %
266 % \section{User documentation}
267 %
268 % \AddToCheckSum{-10} ^^A In this file we don't have the usual 5 version \defs
269 % \AddToCheckSum{-2} ^^A Subtract two more for the \initelyHavECitationS def
270 % \AddToCheckSum{-24} ^^A Sum of 17 and 7 in part-3.dtx
271 %
272 % No bibstyle is going to elgantly handle everything while using them in a way
273 % that's at all compatible with the majority of existing bibstyles out there.
274 % And it's not clear that such a bibstyle would be worth the effort to write
275 % and learn to use properly. The time would be better spent, I think, writing
276 % some macros to make inserting hand-done exceptions seamlessly into the
277 % bibliography, so that the whole process could remain clean and automatic.
278 %
279 % For the sceptical, and for your entertainment, an example. I wanted to a
280 % cite a certain paper by Freud in my dissertation. The cited paper has a
281 % title, date of first publication, and chapter number; I read this paper in a
282 % volume of Freud's papers with a title, volume editor, volume date, publisher,
283 % reprint date, and reprint publisher; this volume has a number in a series of
284 % publications (The International Psycho-Analytic Library) with a series
285 % editor; and also this volume has a volume number within a multivolume work
286 % with its own title (\book{Collected Papers}) and (supervising)
287 % translator. Readers honestly don't need all that information, but each one
288 % of those 15 pieces of information might be highly important for another
289 % citation, for which only two or three pieces of information were relevant or
290 % available. No one needs to write a bibstyle that handles it all, so at
291 % several places, the fields are assumed to be used for either one thing or
292 % another. For example, \field{series} \emph{either} contains the title of the
293 % inclusive multivolume work \emph{or} the series. When, as rarely happens, a
294 % volume is part of both at once, you have to give up one or the other.
295 %
296 % \caveat{This is a complex bibstyle and the number of potential cases is very
297 % high. Please check your output, and write me with cases that are not set
298 % according to \manual percepts. Please refer to \manual whenever
299 % possible.}
300 %
301 % \todo{star the new fields.}
302 %
303 % \newcommand\deffield [2] {#1&#2\\}
304 % \DeleteShortVerb{\|}
305 % \begin{longtable}{|lp{3.5in}|}
306 %
307 % \larger\bfseries entry type & \larger\bfseries\hfil description\\\hline\endhead
308 % \hline\caption{Entry types.} \endfoot
309 %
310 % address & Address of publisher of \emph{cited} edition, whether a reprint or
311 % not. \\
312
313 % annotation & A complete paragraph or more. \\
314
315 % author & \\
316
317 % bookauthor & Book's author whenever \field{author} is referring to the author of a
318 % part of the book. Usually an \entry{inbook} or \entry{incollection} entry refers to a
319 % book with an editor but no author, but in the case of introductions etc.\ you
320 % have an author for each.\\
321
322 % booktitle & Book's title whenever \field{title} is referring to a part of the
323 % book. \\
324
325 % chapter & The \field{title} names the \field{chapter}th part of the book. One expects to
326 % have nonempty \field{booktitle}. See also \field{type}. \\
327
328 % edition & Edition information to be given after the book's title, which is
329 % \field{booktitle} if that is nonempty and \field{title} otherwise. Example:
330 % \code{2d~ed., 2~vols. in 1~book} \\
331
332 % editor & \\
333
334 % & NOTE all f* and o* fields are only going to apply
335 % to \entry{book}, \entry{incollection}, \entry{inbook} entries.
336 % FIX: check -- booklet? etc. \\
337
338 % faddress & Address of publisher of first-published edition. Not used unless
339 % \field{fyear} is nonempty. \\
340
341 % flanguage & Language of first-published edition. Not used unless
342 % \field{translator} or \field{fyear} is nonempty. \\
343
344 % fpublisher & Publisher of first-published edition. Not used unless \field{fyear}
345 % is nonempty. \\
346
347 % ftitle & Title of first-published edition (probably in \field{flanguage}). Not
348 % used unless \field{fyear} is nonempty. \\
349
350 % fyear & Publication date of first-published edition. \\
351
352 % howpublished & \\
353
354 % illustrator & For \entry{book} entries only. When the author or editor
355 % illustrates, use a construction like \code{{the editor} and others}. \\
356
357 % institution & For thesis entries only. FIX check \\
358
359 % journal & For \entry{article} entries only. \\
360
361 % key & often default with empty author, editor, organization \\
362
363 % month & For \entry{journal} entries, also season, e.g., Winter \\
364
365 % note & Begins its own block, so capitalize. Concluding puctuation is
366 % supplied automatically if not given in the field. \\
367
368 % number & For \entry{journal} entry, number of the journal (if no \field{volume}) or
369 % number within the volume. For \entry{book} entry, number of the book in the
370 % \field{series}. Makes sense only when \field{series} is a series rather than the title
371 % of a multivolume work. \\
372
373 % oaddress & For a reprint, address of ORIGINAL publisher. \\
374
375 % opublisher & For a reprint, publisher of ORIGINAL edition. A nonempty
376 % value implies the cited edition IS a reprint (and so must have \field{oyear}). \\
377
378 % organization & \\
379
380 % oyear & For a reprint, publication date of ORIGINAL edition A nonempty
381 % value implies the cited edition IS a reprint (and so OUGHT TO have
382 % \field{opublisher}). The value will almost always differ from \field{year}. \\
383
384 % pages & \\
385
386 % publisher & Publisher of the cited edition. \\
387
388 % school & \\
389
390 % series & Series to which \field{title} belongs, or title of a multivolume work
391 % where the volumes have their own titles given in \field{booktitle} or \field{title}. \\
392
393 % seriesedition & Edition information to be given after \field{series}. Makes
394 % sense only when \field{series} is the title of a multivolume work with titled
395 % volumes. In the entry for the multivolume work, that is, when \field{series}
396 % and \field{title} are identical, use \field{seriesedition} not
397 % \field{edition}. See also \field{edition}. Consequence of disobeying last is
398 % when references are less than min-crossrefs (i.e., no separate entry for the
399 % multivolume work) you get the edition information for the multivolume work
400 % appearing after the title of the component volume. Note: you can't really
401 % get away with putting a series editor here. I think you'd have to use the
402 % \field{note} field for that; or we could make yet another field. \\
403
404 % title & \\
405
406 % translator & For \entry{book} entries only, the translator(s). See also
407 % \field{flanguage}. When the author or editor translates, use a construction like
408 % \code{{the editor} and others}. \\
409
410 % type & For \entry{inbook} entries, the value overrides \code{Chapter}. When
411 % \field{type} is empty you get \code{Chapter~<chapter> of}. FIX: CHECK: For *-thesis
412 % entries, gives thesis-type word, e.g. \code{Master's Thesis}. \\
413
414 % volume & For \entry{journal} entry, it's volume. For \entry{book} entry, its number in
415 % the \field{series}, or its volume number in a multivolume book. \\
416
417 % year & Year of publication of cited edition, whether a reprint or not. \\
418
419 % yearcomp & Year work composed. For \entry{book} entry only (so far).\\
420 % \end{longtable}
421 % \MakeShortVerb{\|}
422 %
423 % \StopEventually{}
424 %
425 % \part{Implementation}
426 %
427 % \section{Version control}
428 %
429 %
430 % ^^A NOTE: We have to compensate for the above backslashes, which are not
431 % ^^A actually in the .dtx file the author works on, by adding to the
432 % ^^A CheckSum.
433 %%
434 % \AddToCheckSum{17}^^A `dtx-update-checksum' automatically handles this.
435 % \AddToCheckSum{7}^^A The half a macrocode env. at the top is missed, however...
436 % \AddToCheckSum{10}^^A ... and so are the 5 \defs from the .dtx file
437 % ^^A that precede it.
438 % \IfCitations {%
439 % \AddToCheckSum{2}^^A When \initelyHavECitationS is defined in
440 % } ^^A the .dtx file, we need 2 more in the CheckSum.
441 %
442 % Version information:
443 % \begin{macrocode}^^A Keep the /^ %% \def\file.../ beginning exact!
444
445 %% A BibTeX bibliography style
446 %% conforming to the Chicago Manual's A style
447 %% but with B style author-date citations
448 %% by Matt Swift <[email protected]>
449 %%
450 %% \def\fileinfo{A Chicago Manual BibTeX style}
451 %% \def\DoXPackageS {longtable}
452 %% \def\initelyHavECitationS {}
453 %% \def\fileversion{v1}
454 %% \def\filedate{2001/08/31}
455 %% \def\docdate{2001/08/31}
456 %%
457
458 % \end{macrocode}
459 %
460 % \section{Implementation}
461 % \subsection{Define fields and variables}
462 %
463 % \subsubsection{Global variables}
464 %
465 % \gvar{output.state} will have one of the four scalar values
466 % \gvar{before.all}, \gvar{mid.sentence}, \gvar{after.sentence}, and
467 % \gvar{after.block}, telling us where we are in producing the entry.
468 %
469 % \bst{Achicago} uses only \term{blocks}, not \term{sentences}, to delimit
470 % units in the bibentry (some other bibstyles use both). The
471 % \package{achicago} package defines \cs\newblock to add a very small and
472 % rubber amount of horizontal space, relaxing somewhat the \cs\frenchspacing in
473 % effect. I have not removed the programming structures that distinguish
474 % sentences and blocks, but I have not concerned myself with them either;
475 % anyone wishing to revise this style to begin using them should check their
476 % work carefully.
477 % \begin{macrocode}
478 INTEGERS { output.state before.all mid.sentence after.sentence after.block }
479 % \end{macrocode}
480 %
481 % The entry variable \evar{principal-type} will have one of the five scalar
482 % values \gvar{author.ptype}, \gvar{editor.ptype}, \gvar{organization.ptype},
483 % \gvar{key.ptype}, and \gvar{emergency.ptype}, telling us what type of
484 % information is in the principal field. See also the discussion of
485 % \function{key.special.p}.
486 % \begin{macrocode}
487 INTEGERS { author.ptype editor.ptype organization.ptype key.ptype
488 emergency.ptype }
489 % \end{macrocode}
490 %
491 % These are used during the forward and reverse passes to hold information
492 % about the previously-processed record.
493 % \begin{macrocode}
494 INTEGERS { last.year.tag.num }
495 STRINGS { last.leaditem last.label.and.year following.year.label.tag }
496 % \end{macrocode}
497 %
498 % These variables are used locally within various functions or function groups,
499 % where their particular use is documented.
500 %
501 % \todo{document which if any are used in a nonlocal way}
502 %
503 % \caveat{Suspect a conflict among these scratch variables if a strange problem
504 % occurs! I think \gvar{u} is the only one that will hold its value past an
505 % \function{output}.}
506 % \begin{macrocode}
507 INTEGERS { j nameptr namesleft numnames len }
508 STRINGS { s t u v w }
509 % \end{macrocode}
510 %
511 % \subsubsection{Bibfields}
512 % The list of fields that will be examined in database records, if they exist.
513 % Fields in the \ext{bib} database not on this list will be ignored. Not every
514 % entry type makes use of every field. Each entry type function below lists
515 % its required, optional, and ignored fields. Expected use of these fields is
516 % documented above in the user documentation.
517 % \begin{macrocode}
518 ENTRY
519 { address
520 annotation
521 author
522 bookauthor
523 booktitle
524 chapter
525 edition
526 editor
527 faddress
528 flanguage
529 fpublisher
530 ftitle
531 fyear
532 howpublished
533 illustrator
534 institution
535 journal
536 key
537 month
538 note
539 number
540 oaddress
541 opublisher
542 organization
543 oyear
544 pages
545 publisher
546 school
547 series
548 seriesedition
549 title
550 translator
551 type
552 volume
553 year
554 yearcomp
555 }
556 % \end{macrocode}
557 %
558 % Entry variables have a per-record value but are not initialized from a field.
559 %
560 % The integer \evar{principal-type} will contain one of the scalars
561 % \gvar{author.ptype}, \gvar{editor.ptype}, etc.\ (see their declarations above
562 % for further information). \evar{principal-type} is set in the function
563 % \function{set.principal-field.principal-type}.
564 % \begin{macrocode}
565 { principal-type }
566 % \end{macrocode}
567 %
568 % The strings \evar{label}, \evar{year.label} and \evar{year.label.tag} are
569 % used to construct the citation (the running text at the location of the
570 % user's \cs\cite command). In most cases, \evar{label} will contain a string
571 % derived from the \evar{principal-field} (see \function{make.label}).
572 % \begin{macrocode}
573 { label
574 % \end{macrocode}
575 %
576 % \evar{year.label} will contain a string representing the date. It's not
577 % necessarily the same as \field{year} (see \function{make.year.label}).
578 % \evar{year.label.tag} will either be empty or be a lower-case letter, as
579 % determined in the forward and reverse passes.
580 % \begin{macrocode}
581 year.label year.label.tag
582 % \end{macrocode}
583 %
584 % \evar{principal-field} will contain one of the fields, depending on entry
585 % type and what fields are nonempty (see
586 % \function{set.principal-field.principal-type}).
587 %
588 % In most cases, \evar{leaditem} will contain the \evar{principal-field}
589 % properly formatted for apearance at the beginning of the bibliography entry
590 % (see \function{make.leaditem}). When it is identical to the previous entry's
591 % \evar{leaditem}, it will be wrapped in \cs\SCduplicate by the forward and
592 % reverse passes.
593 % \begin{macrocode}
594 principal-field
595 leaditem
596 }
597 % \end{macrocode}
598 %
599 % \subsection{Define macros}
600 %
601 % These are macro abbreviations required by convention in every bibstyle. The
602 % user can redefine them with \texttt{@STRING} declarations in the \ext{bib}
603 % database.
604 % \begin{macrocode}
605 MACRO {jan} {"January"}
606 MACRO {feb} {"February"}
607 MACRO {mar} {"March"}
608 MACRO {apr} {"April"}
609 MACRO {may} {"May"}
610 MACRO {jun} {"June"}
611 MACRO {jul} {"July"}
612 MACRO {aug} {"August"}
613 MACRO {sep} {"September"}
614 MACRO {oct} {"October"}
615 MACRO {nov} {"November"}
616 MACRO {dec} {"December"}
617 % \end{macrocode}
618 %
619 % \subsection{Debugging functions}
620 %
621 % \begin{macro}{debugval}
622 % \begin{macro}{debugmsg}
623 % \mbox{}
624 % \begin{macrocode}
625 FUNCTION {debugval}
626 { ": [" *
627 swap$ * %$
628 "] in " * cite$ * %$
629 top$ %$
630 }
631
632 FUNCTION {debugmsg}
633 { " in " * cite$ * top$
634 }
635 % \end{macrocode}
636 % \end{macro}
637 % \end{macro}
638 %
639 % \subsection{Initialization functions}
640 %
641 % \begin{macro}{init.scalars}
642 % This should be called before any processing begins.
643 % \begin{macrocode}
644 FUNCTION {init.scalars}
645 { #0 'before.all :=
646 #1 'mid.sentence :=
647 #2 'after.sentence :=
648 #3 'after.block :=
649
650 #0 'author.ptype :=
651 #1 'editor.ptype :=
652 #2 'organization.ptype :=
653 #3 'key.ptype :=
654 #4 'emergency.ptype :=
655 }
656 % \end{macrocode}
657 % \end{macro}
658 %
659 % \subsection{Boolean logic}
660 %
661 % \begin{macro}{not}
662 % \begin{macro}{and}
663 % \begin{macro}{or}
664 % \mbox{}
665 % \begin{macrocode}
666 FUNCTION {not}
667 { { #0
668 }
669 { #1
670 }
671 if$ %$
672 }
673
674 FUNCTION {and}
675 { 'skip$ %$
676 { pop$ %$
677 #0
678 }
679 if$ %$
680 }
681
682 FUNCTION {or}
683 { { pop$ %$
684 #1
685 }
686 'skip$ %$
687 if$ %$
688 }
689 % \end{macrocode}
690 % \end{macro}
691 % \end{macro}
692 % \end{macro}
693 %
694 % \subsection{Constant functions}
695 %
696 % \begin{macro}{comma}
697 % \begin{macro}{period}
698 % \begin{macro}{hyphen}
699 % \begin{macro}{colon}
700 % \begin{macro}{space}
701 % \begin{macro}{delimiter.name-part}
702 % \begin{macro}{delimiter.name}
703 % \begin{macro}{delimiter.sub-sortkey}
704 % \begin{macro}{tie}
705 % \begin{macro}{etal}
706 % \begin{macro}{unidentified}
707 % These definitions are made so that later functions are easier to read and so
708 % that adapting this bibstyle to another language will be simpler.
709 %
710 % The reason these are functions not macros is so the user cannot change them.
711 % \begin{macrocode}
712 FUNCTION {comma}
713 { ","
714 }
715
716 FUNCTION {period}
717 { "."
718 }
719
720 FUNCTION {hyphen}
721 { "-"
722 }
723
724 FUNCTION {colon}
725 { ":"
726 }
727
728 FUNCTION {space}
729 { " "
730 }
731
732 FUNCTION {delimiter.name-part}
733 { " "
734 }
735
736 FUNCTION {delimiter.name}
737 { " "
738 }
739
740 FUNCTION {delimiter.sub-sortkey}
741 { " "
742 }
743
744 FUNCTION {tie}
745 { "~"
746 }
747
748 FUNCTION {etal}
749 { " et~al."
750 }
751 % \end{macrocode}
752 % Below, we need to be able to set a string to a value which would never be
753 % generated from any string in a bibliography database. It's safe to assume
754 % that this string is such a one.
755 % \begin{macrocode}
756 FUNCTION {unidentified}
757 { "HiGHlY*Peco@lIEr"
758 }
759 % \end{macrocode}
760 % \end{macro}
761 % \end{macro}
762 % \end{macro}
763 % \end{macro}
764 % \end{macro}
765 % \end{macro}
766 % \end{macro}
767 % \end{macro}
768 % \end{macro}
769 %
770 % \subsection{Output functions}
771 %
772 % The \function{output} function automatically handles interunit punctuation.
773 %
774 % \function{output} should be called with a string and a punctuation mark on
775 % the stack. The punctuation mark is what should \emph{precede} the string in
776 % the case the string begins in the middle of a sentence. Strings which begin
777 % sentences are preceded by periods. Strings which begin a new block are
778 % preceded by periods and the \cs\newblock command. (It makes no sense for a
779 % string to begin at the end of a sentence.)
780 %
781 % Calls to \function{output.internal} leave the string on the stack until the
782 % next time \function{output.internal} is called, when it will get written.
783 % The function \function{output.begin} puts an empty string on the stack, and
784 % should be called before beginning any series of calls to \function{output}.
785 % \function{output.end} cleans up and should be called at the conclusion of a
786 % series of calls to \function{output}.
787 %
788 % \begin{macro}{output.begin}
789 % Prepare for a series of calls to \function{output}. Put an empty string on the
790 % stack and set \gvar{output.state} to \gvar{before.all}.
791 % \begin{macrocode}
792 FUNCTION{output.begin}
793 { ""
794 before.all 'output.state :=
795 }
796 % \end{macrocode}
797 % \end{macro}
798 %
799 % \begin{macro}{output.end}
800 % Conclude a series of calls to \function{output}. Simply calls \builtin{write}.
801 % \begin{macrocode}
802 FUNCTION {output.end}
803 { write$ %$
804 }
805 % \end{macrocode}
806 % \end{macro}
807 %
808 % \begin{macro}{new.block}
809 % Begin a new block.
810 % \begin{macrocode}
811 FUNCTION {new.block}
812 { output.state before.all =
813 'skip$ %$
814 { after.block 'output.state :=
815 }
816 if$ %$
817 }
818 % \end{macrocode}
819 % \end{macro}
820 %
821 % \begin{macro}{new.sentence}
822 % Begin a new sentence. FIX: hmm, wouldn't we want to put a TeX command here
823 % for intersentence space now? Why do we mess with the usual spacefactor for
824 % periods anyway? When in bibliogrphies are the usual TeX rules not going to
825 % be what we want, and give too much space after a period? answer: when a
826 % lowercase letter followed by period, in e.g. sec. 2 and so on. often
827 % bibstyle will put tie there, but sometimes not I think, so need to have that
828 % be not an intersentence space. well, if i start using sentences instead of
829 % blocks, I think perhaps doing the same hskip after a sentence with a new
830 % command \cs\newsentence perhaps as in \cs\newblock would be the right thing
831 % to do.
832 % \begin{macrocode}
833 FUNCTION {new.sentence}
834 { output.state before.all = output.state after.block = or
835 'skip$ %$
836 { after.sentence 'output.state :=
837 }
838 if$ %$
839 }
840 % \end{macrocode}
841 % \end{macro}
842 %
843 % \begin{macro}{output.internal}
844 % \cs\stack{punct string/entry(nonnull)}{null}
845 % \begin{macrocode}
846 FUNCTION {output.internal}
847 { 's := % s := string/entry(nonnull)
848 space * 't := % t := punctuation + space
849 output.state mid.sentence =
850 { t * write$ %$
851 }
852 { output.state after.block =
853 { add.period$ write$
854 newline$ %$
855 "\newblock " write$ %$
856 }
857 { output.state before.all =
858 'write$ %$
859 % \end{macrocode}
860 % Final case is \gvar{output.state} = `after.sentence', which means we just add a
861 % period, but no newline or \cs\newblock command.
862 % \begin{macrocode}
863 { add.period$ space * write$
864 }
865 if$ %$
866 }
867 if$ %$
868 % \end{macrocode}
869 % We are now mid-sentence, whether we were before or not.
870 % \begin{macrocode}
871 mid.sentence 'output.state :=
872 }
873 if$ %$
874 % \end{macrocode}
875 % The actual string given to `output.internal' is left on the stack here for
876 % next time we call `output.internal' or `output.end', whichever comes next.
877 % \begin{macrocode}
878 s
879 }
880 % \end{macrocode}
881 % \end{macro}
882 %
883 % \begin{macro}{output}
884 % \cs\stack{string/entry punct}{either null OR punct string/entry(nonnull)}
885 %
886 % Check if string/entry is null. If it's null do nothing. If it's nonempty
887 % call \function{output.internal} on it with the given punctuation.
888 % \begin{macrocode}
889 FUNCTION {output}
890 { swap$ duplicate$ empty$
891 { pop$
892 pop$ %$
893 }
894 'output.internal
895 if$ %$
896 }
897 % \end{macrocode}
898 % \end{macro}
899 %
900 % \begin{macro}{output.bibitem}
901 % The optional argument to \cs\bibitem will be made the definition of
902 % \cname{b@foo} where |foo| is the \builtin{cite} key. \cname{b@foo} will be
903 % executed by all the various citing commands with a definition of \cs\SCcite
904 % that is appropriate to each citing command.
905 %
906 % The \env{thebibliography} environment actually ignores the optional argument
907 % to \cs\bibitem. The environment sets the formatting so that the first part
908 % of the main entry hangs out to the left and looks like a label.
909 %
910 % The unexpandable protection is necessary, instead of a simple protection, in
911 % order to work with \package{newclude}'s \option{tag} option.
912 %
913 % I guess we use \builtin{write} for each part instead of catenating them and using a
914 % single \builtin{write} in case the catenation gets longer than \BibTeX{} can
915 % handle. I don't know, this is how I found it. It seems like catenation and
916 % a single call to \builtin{write} would be faster. FIX.
917 % \begin{macrocode}
918 FUNCTION {output.bibitem}
919 { newline$ %$
920 "\bibitem[\UnexpandableProtect\SCcite{" write$ %$
921 label write$ %$
922 "}{" write$ %$
923 year.label year.label.tag * write$ %$
924 "}]{" write$ %$
925 cite$ write$
926 "}" write$ %$
927 newline$ %$
928 }
929 % \end{macrocode}
930 % \end{macro}
931 %
932 % \subsection{Simple auxiliary functions}
933 %
934 % \begin{macro}{field.or.null}
935 % \cs\stack{field literal}{field contents or null string if the field was
936 % missing}
937 % \begin{macrocode}
938 FUNCTION {field.or.null}
939 { duplicate$ empty$
940 { pop$ %$
941 ""
942 }
943 'skip$ %$
944 if$ %$
945 }
946 % \end{macrocode}
947 % \end{macro}
948 %
949 % \begin{macro}{italicize}
950 % \cs\stack{string or entry}{string}
951 %
952 % Italicize the top string on the stack and provide italic corrections. Null
953 % goes to null. We want to explicitly italicize rather than use \cs\emph,
954 % since semantic emphasis might be indicated in some other way in the document,
955 % e.g., slanted type.
956 % \begin{macrocode}
957 FUNCTION {italicize}
958 { duplicate$ empty$
959 { pop$ %$
960 ""
961 }
962 { "\textitswitch{" swap$ * "}" * %$
963 }
964 if$ %$
965 }
966 % \end{macrocode}
967 % \end{macro}
968 %
969 % \begin{macro}{parenthesize}
970 % \cs\stack{string-or-entry:S}{"(" + S + ")"}
971 % \begin{macrocode}
972 FUNCTION {parenthesize}
973 { duplicate$ empty$
974 { pop$ %$
975 ""
976 }
977 { "(" swap$ * ")" * %$
978 }
979 if$ %$
980 }
981 % \end{macrocode}
982 % \end{macro}
983 %
984 % \begin{macro}{format.clip}
985 % \cs\stack{string}{string} FIX: the difference between \builtin{entry.max} and
986 % \builtin{global.max}: max for an entry string, max for a global string.
987 %
988 % \begin{macro}{format.clip}
989 % \cs\stack{string-S}{string-S-possibly-shortened}
990 %
991 % Clips a string down to the smaller of \builtin{entry.max} and \builtin{global.max}.
992 % \begin{macrocode}
993 FUNCTION {format.clip}
994 { #1 entry.max$ substring$
995 #1 global.max$ substring$
996 }
997 % \end{macrocode}
998 % \end{macro}
999 %
1000 % \begin{macro}{format.sortify.clip}
1001 % \builtin{purify}, downcase, and clip a string on the stack.
1002 % \cs\stack{\meta{string}}{\meta{string}}
1003 % \begin{macrocode}
1004 FUNCTION {format.sortify.clip}
1005 { % duplicate$ "sinful" debugval %$
1006 purify$ %$
1007 % duplicate$ " pure" debugval %$
1008 "l" change.case$ %$
1009 format.clip
1010 % duplicate$ "humble" debugval %$
1011 }
1012 % \end{macrocode}
1013 % \end{macro}
1014 %
1015 % \begin{macro}{check.empty}
1016 % \cs\stack{S warning}{S}
1017 % Issues warning if the string is empty.
1018 % \begin{macrocode}
1019 FUNCTION {check.empty}
1020 { 't :=
1021 duplicate$ empty$
1022 { "empty " t * " in " * cite$ * warning$
1023 }
1024 'skip$ %$
1025 if$ %$
1026 }
1027 % \end{macrocode}
1028 % \end{macro}
1029 %
1030 % \begin{macro}{multipage.p}
1031 % \cs\stack{nothing}{\#0 or \#1}
1032 %
1033 % Set \gvar{t} to \field{pages}. Look at \gvar{t} character by character for a
1034 % hyphen, comma, or plus. If we find one, return true immediately; else return
1035 % false.
1036 % \begin{macrocode}
1037 FUNCTION {multipage.p}
1038 { pages 't :=
1039 #0 'j :=
1040 % WHILE
1041 { j not
1042 t empty$ not %$
1043 and
1044 }
1045 { t #1 #1 substring$ %$
1046 duplicate$ hyphen = %$
1047 swap$ duplicate$ comma =
1048 swap$ "+" = %$
1049 or
1050 or
1051 { #1 'j :=
1052 }
1053 { t #2 global.max$ substring$ 't :=
1054 }
1055 if$
1056 }
1057 while$
1058 j
1059 }
1060 % \end{macrocode}
1061 % \end{macro}
1062 %
1063 % \begin{macro}{format.n.dashify}
1064 % \cs\stack{string}{string}
1065 %
1066 % Make single-dashes into double-dashes.
1067 % \begin{macrocode}
1068 FUNCTION {format.n.dashify}
1069 { 't :=
1070 ""
1071 % WHILE
1072 { t empty$ not } %$
1073 { t #1 #1 substring$ hyphen = %$
1074 { t #1 #2 substring$ "--" = not %$
1075 { "--" *
1076 t #2 global.max$ substring$ 't :=
1077 }
1078 { % WHILE
1079 { t #1 #1 substring$ hyphen = } %$
1080 { hyphen *
1081 t #2 global.max$ substring$ 't :=
1082 }
1083 while$ %$
1084 }
1085 if$ %$
1086 }
1087 { t #1 #1 substring$ * %$
1088 t #2 global.max$ substring$ 't :=
1089 }
1090 if$ %$
1091 }
1092 while$ %$
1093 }
1094 % \end{macrocode}
1095 % \end{macro}
1096 %
1097 % \begin{macro}{tie.or.space.connect}
1098 % \cs\stack{string string}{string}
1099 %
1100 % If the second string has less than 5 characters, the two are tied together,
1101 % otherwise they are catenated with a space between them.
1102 % \begin{macrocode}
1103 FUNCTION {tie.or.space.connect}
1104 { duplicate$ text.length$ #5 <
1105 { tie
1106 }
1107 { space
1108 }
1109 if$
1110 swap$ * *
1111 }
1112 % \end{macrocode}
1113 % \end{macro}
1114 %
1115 % \begin{macro}{either.or.check}
1116 % \cs\stack{msg field}{null}
1117 % If field is not empty, give a warning appropriate for saying this field and
1118 % an already-existing field can't be both used in the same entry.
1119 % \begin{macrocode}
1120 FUNCTION {either.or.check}
1121 { empty$
1122 'pop$
1123 { "can't use both " swap$ * " fields in " * cite$ * warning$
1124 }
1125 if$
1126 }
1127 % \end{macrocode}
1128 % \end{macro}
1129 %
1130 % \subsection{Queue functions START FIXING DOX HERE}
1131 %
1132 % Queue functions expect a string on the stack. If it is empty, and the field
1133 % for which the function is named is noempty, the string will be replaced with
1134 % that field. (e.g., \function{author.q} will put \field{author} on the stack
1135 % if \field{author} is nonempty and the \function{author.q} was passed an empty
1136 % string). A chain of queue functions must begin with something on the stack,
1137 % adn will leave the first nonempty field named in the chain on the stack.
1138 %
1139 % Queue functions also increment an integer variable, 'j, whenever they are
1140 % passed an empty string. At the end of the queue, 'j tells us which function
1141 % in the queue contributed the string that results at the end of the queue,
1142 % starting with zero for the first queue function after \function{start.a.q}.
1143 % In order for this to work, queue functions must always be called in the same
1144 % order: \field{author} ('\#0') \field{editor} (`\#1'), \field{organization}
1145 % (`\#2'), and \field{key} (`\#3'). For entry types where a certain field
1146 % should not appear in the queue, use `blank.q' in its place in the order.
1147 %
1148 % The value of \gvar{j} is consulted when setting \evar{leaditem}, but not in
1149 % other cases where queue functions are used
1150 %
1151 % \function{start.a.q} must begin a queue. It initializes \gvar{j} and passes
1152 % an empty string to the first queue function.
1153 % \begin{macro}{start.a.q}
1154 % \begin{macrocode}
1155 FUNCTION {start.a.q}
1156 { #-1 'j :=
1157 ""
1158 }
1159 % \end{macrocode}
1160 % \end{macro}
1161 %
1162 % \begin{macro}{inc.j}
1163 % \begin{macro}{key.q}
1164 % \begin{macro}{organization.q}
1165 % \begin{macro}{editor.q}
1166 % \begin{macro}{author.q}
1167 % \begin{macro}{blank.q}
1168 % \mbox{}
1169 % \begin{macrocode}
1170 FUNCTION {inc.j}
1171 { j #1 + 'j :=
1172 }
1173
1174 FUNCTION {key.q}
1175 { duplicate$ empty$
1176 { pop$ %$
1177 key field.or.null
1178 inc.j
1179 }
1180 'skip$ %$
1181 if$ %$
1182 }
1183
1184 FUNCTION {organization.q}
1185 { duplicate$ empty$
1186 { pop$ %$
1187 organization field.or.null
1188 inc.j
1189 }
1190 'skip$ %$
1191 if$ %$
1192 }
1193
1194 FUNCTION {editor.q}
1195 { duplicate$ empty$
1196 { pop$ %$
1197 editor field.or.null
1198 inc.j
1199 }
1200 'skip$ %$
1201 if$ %$
1202 }
1203
1204 FUNCTION {author.q}
1205 { duplicate$ empty$
1206 { pop$ %$
1207 author field.or.null
1208 inc.j
1209 }
1210 'skip$ %$
1211 if$ %$
1212 }
1213
1214 FUNCTION {blank.q}
1215 { duplicate$ empty$
1216 'inc.j
1217 'skip$ %$
1218 if$ %$
1219 }
1220 % \end{macrocode}
1221 % \end{macro}
1222 % \end{macro}
1223 % \end{macro}
1224 % \end{macro}
1225 % \end{macro}
1226 % \end{macro}
1227 %
1228 % \begin{macro}{check.q}
1229 % \cs\stack{string-S warning-string}{string-S}
1230 %
1231 % This should be the final queue command, though it is not a true queue
1232 % command, since an extra warning string should be on the top of the stack
1233 % above the string that has passed along the queue. The warning string should
1234 % be an English disjunctive list of the queue commands that have come before
1235 % it, so the user can tell which fields are missing. For example ``author,
1236 % organization, or key'' if the queue has been \function{author.q} 'blank.q'
1237 % `organization.q' \function{key.q}.
1238 %
1239 % If the queue string is empty, \function{check.q} issues the warning and puts on the
1240 % stack an emergency string of the \LaTeX{} key
1241 % (i.e., \builtin{cite}), which should allow \BibTeX{} to proceed.
1242 % \begin{macrocode}
1243 FUNCTION {check.q}
1244 { 't :=
1245 duplicate$ empty$
1246 { pop$ %$
1247 cite$ format.clip 'u := %$
1248 "Need " t * " in " * cite$ * "; using: " * u * warning$
1249 u
1250 inc.j
1251 }
1252 'skip$ %$
1253 if$ %$
1254 }
1255 % \end{macrocode}
1256 % \end{macro}
1257 %
1258 % \subsection{Format functions dox}
1259 %
1260 % The format functions modify a string on the stack. They make no warnings,
1261 % produce no output, and place no spaces or punctuation before or after their
1262 % string, just modify it somehow.
1263 %
1264 % \subsection{Format names functions}
1265 %
1266 % \begin{macro}{format.names.for.label}
1267 % Format string on stack it to produce something appropriate for \evar{label}.
1268 %
1269 % Comma usage examples in the \manual: ``A et al.''\ and ``A, B, et al.''
1270 %
1271 % The \manual recommends for labels: use up to 3 names, and above 3 use 1st +
1272 % etal. When this would lead to ambiguity, use one of 3 solns: use all names,
1273 % use as many as needed to disambiguate, or include a (short) title to
1274 % disambiguate: (Zipursky et al., \textitswitch{Brief Title}, 1988).
1275 %
1276 % The \manual does not appear to distinguish between ``et al.''\ and ``and
1277 % others''. It's possible to change the logic here to distinguish between the
1278 % cases where the bibstyle is truncating the list of authors, and the case
1279 % where ``and others'' appears in the \ext{bib} file. But I'm not doing that
1280 % now.
1281 %
1282 % Labels:
1283 % \begin{center}
1284 % \begin{tabular}{ll}%% FIX: this stuff not implemented yet
1285 % 1 author & Foo \\
1286 % 2 authors & Foo and Bar \\
1287 % 3 authors & Foo, Bar, and Baz \\
1288 % 4+ authors & Foo et al. \\
1289 % 1+ author ``and others'' & Foo et al. \\
1290 %^^A FIX? 1 author ``and others'' & Foo et al. \\
1291 %^^A 2 authors ``and others'' & Foo, Bar, et al. \\
1292 % \end{tabular}
1293 % \end{center}
1294 %
1295 % This function is probably more general than it needs to be, but it's a nice model.
1296 % \begin{macrocode}
1297 FUNCTION {format.names.for.label}
1298 { 's :=
1299 s num.names$ 'numnames := %$
1300 s #1 "{vv~}{ll}" format.name$ %$
1301 s numnames "{ff}{vv}{ll}{jj}" format.name$ "others" = %$
1302 numnames #3 >
1303 or
1304 % more than 3 names, or final name is "others"
1305 { etal *
1306 }
1307 { numnames #1 - 'namesleft :=
1308 #2 'nameptr :=
1309 % WHILE
1310 { namesleft #0 > }
1311 { nameptr numnames =
1312 % we're on the final name (and it's not "others")
1313 { numnames #2 >
1314 { comma *
1315 }
1316 'skip$ %$
1317 if$ %$
1318 " and " * s nameptr "{vv~}{ll}" format.name$ * %$
1319 }
1320 % we're not on the final name (in this case: 2d of 3 names)
1321 { comma * space *
1322 s nameptr "{vv~}{ll}" format.name$ * %$
1323 }
1324 if$ %$
1325 nameptr #1 + 'nameptr :=
1326 namesleft #1 - 'namesleft :=
1327 }
1328 while$ %$
1329 }
1330 if$ %$
1331 }
1332 % \end{macrocode}
1333 % \end{macro}
1334 % \end{macro}
1335 %
1336 % \begin{macro}{format.names.lastfirst}
1337 % Pop a string containing a name list. Push a string with the first author
1338 % last-name-first and subsequent authors first-name-first.
1339 % \begin{macrocode}
1340 FUNCTION {format.names.lastfirst}
1341 { 's :=
1342 s num.names$ 'numnames := % numnames = num.name$(s);
1343 numnames 'namesleft :=
1344 #1 'nameptr := % nameptr = 1;
1345 % WHILE
1346 { namesleft #0 > }
1347 { nameptr #1 =
1348 { s nameptr "{vv~}{ll}{, jj}{, ff}" format.name$ %$
1349 }
1350 { comma *
1351 s nameptr "{ff~}{vv~}{ll}{, jj}" format.name$ 't := %$
1352 nameptr numnames =
1353 % final name
1354 { t "others" =
1355 { etal *
1356 }
1357 { " and " * t *
1358 }
1359 if$ %$
1360 }
1361 % names both precede and follow this name
1362 { space * t *
1363 }
1364 if$ %$
1365 }
1366 if$ %$
1367 nameptr #1 + 'nameptr := % nameptr += 1;
1368 namesleft #1 - 'namesleft := % namesleft =- 1;
1369 }
1370 while$ %$
1371 }
1372 % \end{macrocode}
1373 % \end{macro}
1374 %
1375 % \begin{macro}{format.names.firstfirst}
1376 % Same as \function{format.names.lastfirst} but all names are first name first.
1377 % \begin{macrocode}
1378 FUNCTION {format.names.firstfirst}
1379 { 's :=
1380 s num.names$ 'numnames := % numnames = num.name$(s);
1381 numnames 'namesleft :=
1382 #1 'nameptr := % nameptr = 1;
1383 % WHILE
1384 { namesleft #0 > }
1385 { s nameptr "{ff~}{vv~}{ll}{, jj}" format.name$ 't := %$
1386 nameptr #1 =
1387 't
1388 { nameptr numnames =
1389 % final name
1390 { numnames #2 >
1391 { comma *
1392 }
1393 'skip$ %$
1394 if$ %$
1395 t "others" =
1396 { etal *
1397 }
1398 { " and " * t *
1399 }
1400 if$ %$
1401 }
1402 % names both precede and follow this name
1403 { comma * space * t *
1404 }
1405 if$ %$
1406 }
1407 if$ %$
1408 nameptr #1 + 'nameptr := % nameptr += 1;
1409 namesleft #1 - 'namesleft := % namesleft =- 1;
1410 }
1411 while$ %$
1412 }
1413 % \end{macrocode}
1414 % \end{macro}
1415 %
1416 % \subsection{Make functions}
1417 %
1418 % Make functions expect nothing on the stack, and leave one string there. Any
1419 % side effects of setting global variables are noted in the comments. If a
1420 % nonempty string cannot be made due to lack of the right fields, leave an
1421 % empty one on the stack.
1422 %
1423 % \begin{macro}{make.annotation}
1424 % Annotations can be omitted by nullifying the \env{SCannotation} environment.
1425 % \begin{macrocode}
1426 FUNCTION {make.annotation}
1427 { annotation empty$ %$
1428 { ""
1429 }
1430 { "\begin{SCannotation}"
1431 annotation *
1432 "\end{SCannotation}" *
1433 }
1434 if$ %$
1435 }
1436 % \end{macrocode}
1437 % \end{macro}
1438 %
1439 % \begin{macro}{make.edition}
1440 % We use some logic here because we want to use the \field{seriesedition} for the
1441 % \field{edition} in certain cases.
1442 % \begin{macrocode}
1443 FUNCTION {make.edition}
1444 { edition empty$ %$
1445 { seriesedition empty$ not series field.or.null title field.or.null = and %$
1446 { seriesedition
1447 }
1448 { ""
1449 }
1450 if$ %$
1451 }
1452 { edition
1453 }
1454 if$ %$
1455 }
1456 % \end{macrocode}
1457 % \end{macro}
1458 %
1459 % \begin{macro}{make.year.month}
1460 % \begin{macro}{make.year.nomonth}
1461 % Make a year string. We don't we use \evar{year.label} because that string is
1462 % sterilized to make it appropriate for use in running text in citations (and
1463 % for sorting I think); in the bibliography entry, we can be a little more
1464 % lax, accepting special characters, and text that is not simply four
1465 % numerals.
1466 % \begin{macrocode}
1467 FUNCTION {make.year.month}
1468 { year empty$ %$
1469 { ""
1470 }
1471 { year year.label.tag *
1472 month empty$ %$
1473 'skip$ %$
1474 { comma * space * month *
1475 }
1476 if$ %$
1477 }
1478 if$ %$
1479 }
1480 FUNCTION {make.year.nomonth}
1481 { year empty$ %$
1482 { ""
1483 }
1484 { year year.label.tag *
1485 }
1486 if$ %$
1487 }
1488 % \end{macrocode}
1489 % \end{macro}
1490 % \end{macro}
1491 %
1492 % \begin{macro}{make.year.or.oyear.month}
1493 % Push a string with year information. If \field{oyear} is empty, call
1494 % \function{make.year.month}. Warn in the almost-certainly-erroneous case of
1495 % an \field{oyear} without a \field{year}.
1496 % \begin{macrocode}
1497 FUNCTION {make.year.or.oyear.month}
1498 { oyear empty$ %$
1499 { make.year.month
1500 }
1501 { year empty$ %$
1502 { "oyear without year in " cite$ * warning$
1503 }
1504 'skip$ %$
1505 if$ %$
1506 oyear year.label.tag *
1507 month empty$ %$
1508 'skip$ %$
1509 { comma * space * month *
1510 }
1511 if$ %$
1512 }
1513 if$ %$
1514 }
1515 % \end{macrocode}
1516 % \end{macro}
1517 %
1518 % \begin{macro}{make.leaditem.with.tags}
1519 % Push \evar{leaditem} and if it's an editor, include a nice taggy.
1520 % \begin{macrocode}
1521 FUNCTION {make.leaditem.with.tags}
1522 { leaditem
1523 principal-type editor.ptype =
1524 { editor num.names$ #1 > %$
1525 { ",~eds." *
1526 }
1527 { ",~ed." *
1528 }
1529 if$ %$
1530 }
1531 'skip$ %$
1532 if$ %$
1533 }
1534 % \end{macrocode}
1535 % \end{macro}
1536 %
1537 % \begin{macro}{make.editors.secondary}
1538 % Give editors' names when not for the leaditem.
1539 % \begin{macrocode}
1540 FUNCTION {make.editors.secondary}
1541 { editor empty$ %$
1542 { ""
1543 }
1544 { output.state after.sentence =
1545 output.state after.block = or
1546 { "E"
1547 }
1548 { "e"
1549 }
1550 if$ %$
1551 "dited by " * editor format.names.firstfirst *
1552 }
1553 if$ %$
1554 }
1555 % \end{macrocode}
1556 % \end{macro}
1557 %
1558 % \begin{macro}{make.bookauthors.secondary}
1559 % This is for making authors' names that follow a title. When we use this, we
1560 % are only going to be interested in the \field{bookauthor}.
1561 % \begin{macrocode}
1562 FUNCTION {make.bookauthors.secondary}
1563 { bookauthor empty$ %$
1564 { ""
1565 }
1566 { output.state after.sentence =
1567 output.state after.block =
1568 or
1569 { "B"
1570 }
1571 { "b"
1572 }
1573 if$ %$
1574 "y " * bookauthor format.names.firstfirst *
1575 }
1576 if$ %$
1577 }
1578 % \end{macrocode}
1579 % \end{macro}
1580 %
1581 % \begin{macro}{make.translators}
1582 % \begin{macro}{make.illustrators}
1583 % Translators and illustrators are always secondary, until I write some extensions.
1584 % \begin{macrocode}
1585 FUNCTION {make.translators}
1586 { translator empty$ %$
1587 { ""
1588 }
1589 { output.state after.sentence =
1590 output.state after.block =
1591 or
1592 { "T"
1593 }
1594 { "t"
1595 }
1596 if$ %$
1597 "ranslated " *
1598 flanguage empty$ %$
1599 'skip$ %$
1600 { "from the " * flanguage * space *
1601 }
1602 if$ %$
1603 "by " * translator format.names.firstfirst *
1604 }
1605 if$ %$
1606 }
1607
1608 FUNCTION {make.illustrators}
1609 { illustrator empty$ %$
1610 { ""
1611 }
1612 { output.state after.sentence =
1613 output.state after.block =
1614 or
1615 { "I"
1616 }
1617 { "i"
1618 }
1619 if$ %$
1620 "llustrated by " * illustrator format.names.firstfirst *
1621 }
1622 if$ %$
1623 }
1624 % \end{macrocode}
1625 % \end{macro}
1626 % \end{macro}
1627 %
1628 % \begin{macro}{make.booktitle.ital}
1629 % \begin{macro}{make.title.ital}
1630 % \begin{macro}{make.as.ftitle.ital}
1631 % FIX: multilingual
1632 % \begin{macrocode}
1633 FUNCTION {make.title.ital}
1634 { title field.or.null italicize
1635 }
1636
1637 FUNCTION {make.booktitle.ital}
1638 { booktitle field.or.null italicize
1639 }
1640
1641 FUNCTION {make.as.ftitle.ital}
1642 { ftitle empty$ %$
1643 { ""
1644 }
1645 { "as " ftitle italicize *
1646 }
1647 if$ %$
1648 }
1649 % \end{macrocode}
1650 % \end{macro}
1651 % \end{macro}
1652 % \end{macro}
1653 %
1654 % \begin{macro}{make.title.inquotes}
1655 % Put the title in quotes on the stack. \cs\Wrapquotes is going to properly
1656 % handle punctuation that follows the closing quotation marks by sucking it
1657 % inside the quotes. FIX: make generic function format.wrapquotes? like
1658 % format.emphasize? FIX: make all those function that transform a string on
1659 % the stack into ``format'' functions.
1660 % \begin{macrocode}
1661 FUNCTION {make.title.inquotes}
1662 { title empty$ %$
1663 { ""
1664 }
1665 {
1666 "\Wrapquotes{" title * "}" *
1667 }
1668 if$ %$
1669 }
1670 % \end{macrocode}
1671 % \end{macro}
1672 %
1673 % \begin{macrocode}
1674 FUNCTION {make.pages}
1675 { pages empty$ %$
1676 { ""
1677 }
1678 { pages format.n.dashify
1679 }
1680 if$ %$
1681 }
1682 % \end{macrocode}
1683 %
1684 % \begin{macro}{make.vol.series.num.month.pages}
1685 %
1686 % For articles, the number of cases to handle these fields is very large: 32 to
1687 % do it properly! These cases could perhaps be collapsed, but it is going to
1688 % be much easier to read here and to maintain if we do it brutishly by
1689 % elaborating each case. The only exception I've made is when two adjacent
1690 % leaves are very similar. The way I've laid out this funciton here, adjacent
1691 % leaves are going to be the pairs of cases with and without a nonempty
1692 % \field{pages}.
1693 %
1694 % There are 5 relevant fields, each of which can be empty or not ($2^5 =
1695 % 32$). In the comments below, I mark each case with a series of 1 to 5 letters
1696 % represent the cases where that field is nonempty: |V| for \field{volume}, |S|
1697 % for \field{series}, |N| for \field{number}, |M| for \field{month}, and |P|
1698 % for \field{pages}. Thus, the case marked with the comment |SMP| is the one
1699 % where the \field{series}, \field{month}, and \field{pages} fields are
1700 % nonempty, and \field{volume} and \field{number} are empty.
1701 %
1702 % FIX: when I use \function{make.pages} in this function, it's slightly inefficient,
1703 % since \function{make.pages} does a check for empty pages which is unnecessary here.
1704 %
1705 % FIX: this does not yet handle entries with nonempty \field{series}.
1706 %
1707 % FIX: go through and combine adjacent leaves.
1708 %
1709 % We could really put the punctuation that should precede this unit right at
1710 % the beginning of the string we're making here, but let's conform better to
1711 % the conventions and put this in the scratch variable 'u instead. I don't
1712 % think this function will ever get called at any time other than mid-sentence,
1713 % after the journal title, but who knows. So a call to this function should
1714 % look like:
1715 % \begin{codeexample}
1716 % make.vol.series.num.month.pages u output
1717 % \end{codeexample}
1718 % Remember that when \function{output.internal} writes the punctuation, it adds a space
1719 % following, so it is unnecessary to begin the string this function returns
1720 % with a space. (Occasionally below, we want (and produce) a colon followed by
1721 % no space; we can do this because we are directly creating this string, not
1722 % using the \function{output} routine.)
1723 % \begin{macrocode}
1724 FUNCTION {make.vol.series.num.month.pages}
1725 { volume empty$ %$
1726 { series empty$ %$
1727 { number empty$ %$
1728 { month empty$ %$
1729 { pages empty$ %$
1730 % none of VSNMP
1731 { space 'u :=
1732 ""
1733 }
1734 % P
1735 { comma 'u :=
1736 multipage.p
1737 { "pp." pages format.n.dashify
1738 }
1739 { "p." pages
1740 }
1741 if$ %$
1742 tie.or.space.connect
1743 }
1744 if$ %$
1745 }
1746 { pages empty$ %$
1747 % M
1748 { comma 'u :=
1749 month
1750 }
1751 % MP
1752 { comma 'u :=
1753 month comma * space * make.pages *
1754 }
1755 if$ %$
1756 }
1757 if$ %$
1758 }
1759 { month empty$ %$
1760 { pages empty$ %$
1761 % N
1762 { comma 'u :=
1763 "no." number tie.or.space.connect
1764 }
1765 % NP
1766 { comma 'u :=
1767 "no." number colon * make.pages * tie.or.space.connect
1768 }
1769 if$ %$
1770 }
1771 { pages empty$ %$
1772 % NM
1773 { comma 'u :=
1774 "no." number tie.or.space.connect
1775 space * month parenthesize *
1776 }
1777 % NMP
1778 { comma 'u :=
1779 "no." number tie.or.space.connect
1780 space * month parenthesize *
1781 colon * space * make.pages *
1782 }
1783 if$ %$
1784 }
1785 if$ %$
1786 }
1787 if$ %$
1788 }
1789 { number empty$ %$
1790 { month empty$ %$
1791 { pages empty$ %$
1792 % S
1793 {
1794 }
1795 % SP
1796 {
1797 }
1798 if$ %$
1799 }
1800 { pages empty$ %$
1801 % SM
1802 {
1803 }
1804 % SMP
1805 {
1806 }
1807 if$ %$
1808 }
1809 if$ %$
1810 }
1811 { month empty$ %$
1812 { pages empty$ %$
1813 % SN
1814 {
1815 }
1816 % SNP
1817 {
1818 }
1819 if$ %$
1820 }
1821 { pages empty$ %$
1822 % SNP
1823 {
1824 }
1825 % SNMP
1826 {
1827 }
1828 if$ %$
1829 }
1830 if$ %$
1831 }
1832 if$ %$
1833 }
1834 if$ %$
1835 }
1836 { series empty$ %$
1837 { number empty$ %$
1838 { month empty$ %$
1839 { pages empty$ %$
1840 % V
1841 { comma 'u :=
1842 "vol." volume tie.or.space.connect
1843 }
1844 % VP
1845 { space 'u :=
1846 volume colon * make.pages *
1847 }
1848 if$ %$
1849 }
1850 { pages empty$ %$
1851 % VM
1852 { comma 'u :=
1853 "vol." volume tie.or.space.connect
1854 space * month parenthesize *
1855 }
1856 % VMP
1857 { space 'u :=
1858 volume space *
1859 month parenthesize * colon * space * make.pages *
1860 }
1861 if$ %$
1862 }
1863 if$ %$
1864 }
1865 { month empty$ %$
1866 { pages empty$ %$
1867 % VN
1868 { space 'u :=
1869 volume ", no." number tie.or.space.connect *
1870 }
1871 % VNP
1872 { space 'u :=
1873 volume space *
1874 number parenthesize * colon * space * make.pages *
1875 }
1876 if$ %$
1877 }
1878 { pages empty$ %$
1879 % VNM
1880 { space 'u :=
1881 volume ", no." number tie.or.space.connect *
1882 space * month parenthesize *
1883 }
1884 % VNMP
1885 { space 'u :=
1886 volume space * number parenthesize * colon * space *
1887 make.pages * space * month parenthesize *
1888 }
1889 if$ %$
1890 }
1891 if$ %$
1892 }
1893 if$ %$
1894 }
1895 { number empty$ %$
1896 { month empty$ %$
1897 { pages empty$ %$
1898 % VS
1899 {
1900 }
1901 % VSP
1902 {
1903 }
1904 if$ %$
1905 }
1906 { pages empty$ %$
1907 % VSM
1908 {
1909 }
1910 % VSMP
1911 {
1912 }
1913 if$ %$
1914 }
1915 if$ %$
1916 }
1917 { month empty$ %$
1918 { pages empty$ %$
1919 % VSN
1920 {
1921 }
1922 % VSNP
1923 {
1924 }
1925 if$ %$
1926 }
1927 { pages empty$ %$
1928 % VSNM
1929 {
1930 }
1931 % VSNMP
1932 {
1933 }
1934 if$ %$
1935 }
1936 if$ %$
1937 }
1938 if$ %$
1939 }
1940 if$ %$
1941 }
1942 if$ %$
1943 }
1944 % \end{macrocode}
1945 % \end{macro}
1946 %
1947 % \begin{macro}{make.crossref}
1948 % \begin{macrocode}
1949 FUNCTION {make.crossref}
1950 { "\citeNP{" crossref * "}" *
1951 }
1952 % \end{macrocode}
1953 % \end{macro}
1954 %
1955 % \begin{macro}{output.series.number}
1956 % Outputs the number with appropriate capitalization. Warns if we also have
1957 % nonempty \field{seriesedition}.
1958 % \begin{macrocode}
1959 FUNCTION {output.series.number}
1960 { series empty$ %$
1961 { number empty$ %$
1962 { ""
1963 }
1964 { "Can't use `number' without `series' in " cite$ * warning$
1965 ""
1966 }
1967 if$ %$
1968 }
1969 { number empty$ %$
1970 { series
1971 seriesedition empty$ %$
1972 'skip$ %$
1973 { comma output
1974 new.block
1975 seriesedition
1976 }
1977 if$ %$
1978 }
1979 { series space *
1980 "no." *
1981 number tie.or.space.connect
1982 "number and seriesedition" seriesedition either.or.check
1983 }
1984 if$ %$
1985 }
1986 if$ %$
1987 comma output
1988 }
1989 % \end{macrocode}
1990 % \end{macro}
1991 %
1992 % \begin{macro}{output.volume.series}
1993 % The \field{series} is not required. FIX: why do we output stuff here?
1994 % can't we use a make function like elsewhere?
1995 % \begin{macrocode}
1996 FUNCTION {output.volume.series}
1997 { volume empty$ %$
1998 { ""
1999 }
2000 { "Volume" volume tie.or.space.connect
2001 series empty$ %$
2002 'skip$ %$
2003 { " of " * series italicize *
2004 seriesedition empty$ %$
2005 'skip$ %$
2006 { comma output
2007 new.block
2008 seriesedition
2009 }
2010 if$ %$
2011 }
2012 if$ %$
2013 "volume and number" number either.or.check
2014 }
2015 if$ %$
2016 comma output
2017 }
2018 % \end{macrocode}
2019 % \end{macro}
2020 %
2021 % \begin{macro}{make.chapter.of}
2022 % To say for example ``Part 3'' instead of ``Chapter 3'', put ``Part'' into the
2023 % \field{type} field, and the number and the preposition into the \field{chapter} field,
2024 % e.g., ``3 of''. A tie is automatically put in between the \field{type} field
2025 % and the \field{chapter} field in this case. We can't make a decision based on the
2026 % length of the \field{chapter} field when it's going to contain the preposition.
2027 %
2028 % OK, putting the preposition in the chapter field doesn't work out when you do
2029 % crossreferences. So let's try ``of'' as a general preposition.
2030 % \begin{macrocode}
2031 FUNCTION {make.chapter.of}
2032 { chapter empty$ %$
2033 { ""
2034 }
2035 { type empty$ %$
2036 { "Chapter"
2037 }
2038 { type "t" change.case$ %$
2039 }
2040 if$ %$
2041 chapter tie.or.space.connect
2042 " of " *
2043 }
2044 if$ %$
2045 }
2046 % \end{macrocode}
2047 % \end{macro}
2048 %
2049 % \begin{macro}{make.chapter}
2050 % \begin{macrocode}
2051 FUNCTION {make.chapter}
2052 { chapter empty$ %$
2053 { ""
2054 }
2055 { type empty$ %$
2056 { "Chapter"
2057 }
2058 { type "t" change.case$ %$
2059 }
2060 if$ %$
2061 chapter tie.or.space.connect
2062 }
2063 if$ %$
2064 }
2065 % \end{macrocode}
2066 % \end{macro}
2067 %
2068 % \begin{macro}{make.number.tr}
2069 % \mbox{}
2070 % \begin{macrocode}
2071 FUNCTION {make.number.tr}
2072 { type empty$ %$
2073 { "Technical Report"
2074 }
2075 { type "t" change.case$ %$
2076 }
2077 if$ %$
2078 number empty$ %$
2079 'skip$ %$
2080 { number tie.or.space.connect
2081 }
2082 if$ %$
2083 }
2084 % \end{macrocode}
2085 % \end{macro}
2086 %
2087 % \subsection{Label and principal field functions}
2088 %
2089 % \begin{macro}{calc.labels}
2090 % \begin{macro}{set.principal-field.principal-type}
2091 % Set \evar{label} and \evar{year.label} from the original
2092 % database. Set \evar{leaditem}. For reference from above: \field{author}
2093 % ('\#0') \field{editor} (`\#1'), \field{organization} (`\#2'), and
2094 % \field{key} (`\#3').
2095 %
2096 % FIX: NOTE: the entry-type functions (and specifically its subroutines like
2097 % make.authors) are going to assume that bibentry contains the right field as
2098 % calculated by
2099 %
2100 % format the string on the stack based on the GLOBAL (not entry) variable
2101 % j (= bibentry.type)
2102 %%
2103 % confusion here over terminology. bibentry and leaditem are the same thing,
2104 % but it is also the basis for calculating the label.
2105 % let's call the most important field for each type the PRINCIPAL field. this
2106 % will be put into the lead position in the bibentry and also be massaged into
2107 % the label.
2108 %% FIX: new idea, start using it
2109 % leaves a string on the stack based on TYPE; the string is the first non-empty
2110 % relevant field for the type, or an emergency substitution as supplied by
2111 % \function{check.q}. FIX: end.the.q? would emergency be a 5th type that the
2112 % format.principal-field functions should recognize?
2113 %
2114 % Yes, \function{check.q} will put full cite-string on as emergency and set
2115 % \evar{principal-type} accordingly.
2116 %
2117 % FIX: ensure proper warnings if we are not getting something good in
2118 % principal-field.
2119 %
2120 % \begin{macrocode}
2121 FUNCTION {set.principal-field.principal-type}
2122 { type$ "book" = %$
2123 type$ "inbook" = %$
2124 or
2125 { start.a.q
2126 author.q
2127 editor.q
2128 blank.q
2129 key.q
2130 "author, editor, or key for entry type " type$ * check.q %$
2131 }
2132 { type$ "proceedings" = %$
2133 { start.a.q
2134 blank.q
2135 editor.q
2136 organization.q
2137 key.q
2138 "editor, organization, or key for entry type " type$ * check.q %$
2139 }
2140 { type$ "manual" = %$
2141 { start.a.q
2142 author.q
2143 blank.q
2144 organization.q
2145 key.q
2146 "author, organization, or key for entry type " type$ * check.q %$
2147 }
2148 % for all other entry types
2149 { start.a.q
2150 author.q
2151 blank.q
2152 blank.q
2153 key.q
2154 "author or key for entry type " type$ * check.q %$
2155 }
2156 if$ %$
2157 }
2158 if$ %$
2159 }
2160 if$ %$
2161 'principal-field :=
2162 j 'principal-type :=
2163 }
2164
2165 % TRUE if we've got \evar{principal-type} of \gvar{organization.ptype} and
2166 % nonempty \field{key} and entry type of \entry{manual} or \entry{proceedings}.
2167 FUNCTION {key.special.p}
2168 { type$ "manual" = %$
2169 type$ "proceedings" = %$
2170 or
2171 principal-type organization.ptype =
2172 and
2173 key empty$ not %$
2174 and
2175 }
2176
2177 FUNCTION {make.leaditem}
2178 { key.special.p
2179 % is \field{key} all-caps?
2180 { key duplicate$ "u" change.case$ =
2181 % if so, key is assumed to be an acronym FIX; should I warn what we're doing?
2182 { key " (" * organization * ")" *
2183 }
2184 % if not, key is assumed to be an initial prefix (abbreviation) of organization
2185 % for use only in the label
2186 { organization
2187 }
2188 if$ %$
2189 }
2190 { principal-field
2191 principal-type author.ptype =
2192 principal-type editor.ptype =
2193 or
2194 { format.names.lastfirst
2195 }
2196 % organization, key, or emergency ptype
2197 'skip$ %$
2198 if$ %$
2199 }
2200 if$ %$
2201 }
2202
2203 FUNCTION {make.label.from.principal-field}
2204 { principal-field
2205 principal-type author.ptype =
2206 principal-type editor.ptype =
2207 or
2208 { format.names.for.label
2209 }
2210 % organization, key, or emergency
2211 'skip$ %$
2212 if$ %$
2213 }
2214
2215 FUNCTION {make.label}
2216 { key.special.p
2217 { key
2218 }
2219 { make.label.from.principal-field
2220 }
2221 if$ %$
2222 }
2223 % \end{macrocode}
2224 %
2225 % \begin{macro}{format.names.for.sort}
2226 % \cs\stack{\meta{list of names}}{\meta{list of names suitable for sorting}}
2227 %
2228 % FIX: add dox here about how bibtex sorts, and the spaces strategy.
2229 %
2230 % \begin{tabular}{lp{1in}}
2231 % 1 & between tokens of a name part (word-by-word method; only after first-name's initials
2232 % in letter-by-letter) \\
2233 % 2 & between name-parts in a name (but consider `von' and `last' one name-part) \\
2234 % 3 & between names in a name list \\
2235 % 4 & between other sort levels, such as names and years \\
2236 % \end{tabular}
2237 % We don't bother to \function{format.sortify.clip}, just do that once before assignment to
2238 % the sort.key.
2239 %
2240 % \manual specifies all names should be given in the bibliography. FIX ref.
2241 % So the \manual doesn't tell us how to handle the conventional ``and others''
2242 % that might be in the database. We handle it by proceeding on the assumption
2243 % that ``and others'' always means the total names are more than 3, so we want
2244 % to alphabetize these entries after all those with 1, 2, or~3 names. We do
2245 % this by turning ``and others'' into a pseudo-name that will sort later than
2246 % any real name (i.e., we insert a lot of z's).
2247 %
2248 % The commented-out format is doing word-by-word alphabetization as defined
2249 % \manualref{17.97} with the exception of hyphens. \builtin{purify} turns
2250 % hyphens into spaces, so hyphens are word boundaries, unlike slashes and
2251 % apostrophes, which are suppressed. The \manual says hyphens should be
2252 % supressed like slashes and apostrophes, so we need to remove them with
2253 % \function{format.dehyphen} before we \builtin{purify}.
2254 %
2255 % The \manual prefers letter-by-letter alphabetization, which is what the
2256 % active code below does. We suppress spaces between tokens of a name part.
2257 % We need to remove hyphens as explained above.
2258 %
2259 % NOTE: We could therefore change our delimiters all down by one, since single space
2260 % delimters are no longer used, but I think there is no harm in starting with a
2261 % 2-space delimiter, and this lets us change back and forth easily.
2262 %
2263 % FIX: \manualref{17.100} names with initials in place of given names should
2264 % precede those names which are spelled out. ``J. Robert'' before ``James N.''
2265 % and ``K. T.'' before ``Keven S.''. This is not consistent with the
2266 % letter-by-letter method (it is with word-by-word). So, we want to insert a
2267 % space after first-name tokens of length 1. How do we do that!?
2268 %
2269 % FIX: do we need special handling for names with Saint, Mac, Mc, and M'
2270 % \manualref{17.107--109}?
2271 % \begin{macrocode}
2272
2273 % FIX: NOTE: \builtin{empty} returns TRUE if string contains no non-whitespace chars
2274 % FIX: other whitespace to check for?
2275
2276 % pop string, push its length not counting special chars as one char
2277 FUNCTION {length}
2278 { 'u :=
2279 % u "taking length of" debugval
2280 #0 'len :=
2281 % WHILE
2282 { u "" = not }
2283 { len #1 + 'len :=
2284 u #2 global.max$ substring$ 'u :=
2285 }
2286 while$ %$
2287 len
2288 % len int.to.str$ " length is" debugval %$
2289 }
2290
2291
2292 % FIX: a special+ char begins with a |{\| and continues through the next |}|.
2293 % \BibTeX{}'s ``special character'' is the same but only at brace level~0.
2294 % When we're stepping through a string, and we don't keep track of the brace
2295 % level, then those functions that recognize special chars are not going to
2296 % know the brace level, they will see every special+ char as a special char.
2297
2298 % pop string, push its first char counting special chars as one char
2299 % treat braces normally unless they are the start of a special char
2300 %
2301 % don't use \function{and} here for efficiency
2302 FUNCTION {head}
2303 { 'w :=
2304 w #1 #1 substring$ %$
2305 duplicate$ "{" = %$
2306 { w #2 #1 substring$ "\" = %$
2307 { pop$ %$
2308 w #1 text.prefix$ %$
2309 }
2310 'skip$ %$
2311 if$ %$
2312 }
2313 'skip$ %$
2314 if$ %$
2315 }
2316
2317 % FIX: using `and' and `or' requires calculation of both where nested branches
2318 % would not; see where this will help.
2319
2320 % pop string, push string without its first char, counting special chars as one char
2321 FUNCTION {behead}
2322 { 'u :=
2323 % u "beheading before" debugval
2324 u
2325 u head length #1 +
2326 global.max$ %$
2327 substring$ %$
2328 % duplicate$ "beheading after" debugval %$
2329 }
2330
2331 FUNCTION {behead.t}
2332 { t behead 't :=
2333 }
2334
2335 FUNCTION {format.dehyphen}
2336 { 't :=
2337 % t "dehyphen before" debugval
2338 ""
2339 % WHILE
2340 { t "" = not }
2341 { t head
2342 duplicate$ hyphen = %$
2343 { pop$ %$
2344 }
2345 { *
2346 }
2347 if$ %$
2348 behead.t
2349 }
2350 while$ %$
2351 % duplicate$ "dehyphen after" debugval %$
2352 }
2353
2354 % \builtin{text.length}: replace string on stack with its length, special chars count
2355 % as 1 char, don't count braces.
2356
2357 % \builtin{text.prefix}: like \builtin{substring} but count special chars as 1 char, don't
2358 % count braces, and supply a missing closing brace for a special-char. also,
2359 % have to always start at \#1.
2360
2361 % FIX: does \manual intend to skip over en-dash and em-dash? these could occur
2362 % in titles. For the moment I will remove them too, but not in special chars.
2363 % look at \function{format.n.dashify} to be able to distinguish hyphens from
2364 % the dashes.
2365
2366 FUNCTION {format.dehyphen.dewhitespace}
2367 { 't :=
2368 % t "dehyphen.dewhitespace before" debugval
2369 ""
2370 % WHILE
2371 { t "" = not }
2372 { t head
2373 duplicate$ %$
2374 duplicate$ hyphen = %$
2375 swap$ empty$
2376 or
2377 { pop$ %$
2378 }
2379 { *
2380 }
2381 if$ %$
2382 behead.t
2383 }
2384 while$ %$
2385 % duplicate$ "dehyphen.dewhitespace after" debugval %$
2386 }
2387
2388 FUNCTION {format.names.for.sort}
2389 { 's :=
2390 #1 'nameptr :=
2391 s num.names$ 'numnames := %$
2392 numnames 'namesleft :=
2393 % WHILE
2394 { namesleft #0 > }
2395 {
2396 % NOTE: order or name-parts ought to follow that used for leaditem
2397 % word-by-word alphabetization:
2398 % s nameptr "{vv{ } }{ll{ }}{ jj{ }}{ ff{ }}" format.name$ %$
2399 % letter-by-letter alphabetization, no attention to initials:
2400 % s nameptr "{vv{}}{ll{}}{ jj{}}{ ff{}}" format.name$ %$
2401
2402 % letter-by-letter alphabetization, with first initials exception:
2403
2404 s nameptr "{vv{}}{ll{}}{ jj{}}" format.name$ %$
2405
2406 % Each first-name token of the form of an initial ("L.") will be followed by a
2407 % space but other spaces will be removed.
2408
2409 % Algorithm: step through looking for space, which terminates name tokens,
2410 % adding non-spaces to an accumulator on the stack as we go.
2411 % When we find a space, look at the accumulator (a whole name token).
2412 % If it's length is 2 and 2d char is a period, we've got an initial, so
2413 % add the space to the accumulator. If not, throw away the space
2414 % and step on looking for another name.
2415
2416 % FIX: would it be simpler to replace periods with spaces?
2417 % would a period ever appear in a first-name when not an initial?
2418 % Rev.? Col.? These should be alphabetized as spelled out, prob.
2419 % but need to check \manual
2420
2421 % duplicate$ "beginning of initials funniness; last-part is" debugval %$
2422
2423 s nameptr "{ff{ } }" format.name$ 't := %$
2424 % t is "F1 F2 F3 ... FN " or empty
2425
2426 % t "initial t" debugval
2427
2428 t empty$ %$
2429 'skip$ %$
2430 { delimiter.name-part *
2431 "" % accumulator
2432 % WHILE
2433 { t "" = not }
2434 { t head
2435 % duplicate$ "stepping. t is [" t * "] and head is" * debugval %$
2436 duplicate$ empty$
2437 % last char will always be a space
2438 % accumulator contains whole name token
2439 { pop$ %$ throw space away for now; top of stack is now accumulator
2440 % duplicate$ "found a space; accumulator is" debugval %$
2441 duplicate$ %$
2442 duplicate$ text.length$ #2 = % 2 chars long
2443 swap$ behead head period = %$ 2d char is period
2444 and
2445 % name token in accumulator is an initial, so add a space to it
2446 { space *
2447 % duplicate$ "found an initial" debugval %$
2448 }
2449 % name token in accumulator is not an initial
2450 'skip$ %$
2451 if$ %$
2452 % in either case, concatenate the accumulator the name on the
2453 % stack and initialize it again
2454 % duplicate$ "adding to name" debugval %$
2455 * ""
2456 }
2457 % accumulator contains partial name token
2458 % add t's head (not a space) to accumulator
2459 { *
2460 }
2461 if$ %$
2462 behead.t
2463 }
2464 while$ %$
2465 % we always end up with an empty string on the stack
2466 pop$ %$
2467 % duplicate$ "formatted first-name is" debugval %$
2468 % s nameptr "{ff}{vv}{ll}{jj}" format.name$ "it came from" debugval %$
2469 }
2470 if$ %$
2471 % duplicate$ "end of initials funniness; stack has" debugval %$
2472
2473 format.dehyphen
2474 't :=
2475 % t now contains one name of a namelist
2476 nameptr #1 =
2477 { t
2478 }
2479 { delimiter.name *
2480 nameptr numnames =
2481 t "others" =
2482 and
2483 { "zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz" *
2484 }
2485 { t *
2486 }
2487 if$ %$
2488 }
2489 if$ %$
2490 nameptr #1 + 'nameptr :=
2491 namesleft #1 - 'namesleft :=
2492 }
2493 while$ %$
2494 }
2495 % \end{macrocode}
2496 % \end{macro}
2497 % \end{macro}
2498 % \end{macro}
2499 % \end{macro}
2500 % \end{macro}
2501 %
2502 % FIX: should be able to share code with \function{make.leaditem.with.tags}
2503 %
2504 % We don't bother to \function{format.sortify.clip}, just do that once before assignment to
2505 % the \field{sort.key\$}.
2506 % \begin{macrocode}
2507 FUNCTION {make.principal-field.for.sort} % FIX: note: leaditem must already be set
2508 { principal-type author.ptype =
2509 principal-type editor.ptype =
2510 or
2511 { principal-field format.names.for.sort
2512 }
2513 { principal-type emergency.ptype =
2514 { principal-field
2515 }
2516 % organization.ptype, key.ptype, including both key.special cases
2517 % leaditem is the same as principal-field except in the key.special
2518 % cases, when we do want the leaditem not the principal-field
2519 { leaditem
2520 % letter-by-letter alphabetization:
2521 format.dehyphen.dewhitespace
2522 }
2523 if$ %$
2524 }
2525 if$ %$
2526 }
2527 % \end{macrocode}
2528 %
2529 % \subsection{Begin and end entries}
2530 %
2531 % \begin{macro}{begin.entry}
2532 % Begin an entry.
2533 % \begin{macrocode}
2534 FUNCTION {begin.entry}
2535 { output.begin
2536 output.bibitem
2537 }
2538 % \end{macrocode}
2539 % \end{macro}
2540 %
2541 % \begin{macro}{finish.entry}
2542 % Conclude an entry.
2543 % \cs\stack{string}{null}
2544 % \begin{macrocode}
2545 FUNCTION {finish.entry}
2546 { add.period$ %$
2547 output.end
2548 newline$ %$
2549 make.annotation write$ %$
2550 }
2551 % \end{macrocode}
2552 % \end{macro}
2553 %
2554 % \subsection{Entry types}
2555 %
2556 % \subsubsection{Article}
2557 %
2558 % \begin{macro}{article}
2559 % An article from a journal or magazine. Required: \field{author},
2560 % \field{title}, \field{journal}, \field{year}. Optional: \field{volume},
2561 % \field{number}, \field{pages}, \field{month}, \field{note}. Title quoted.
2562 %
2563 % FIX: this is not true any more. hmm, which warnings to give? Warnings given
2564 % for no \field{pages}; no \field{volume} or \field{number}; and \field{number}
2565 % but no \field{volume}. It's a drag, but the latter warning should remain
2566 % there. The reason is that this bibstyle will produce a very misleading entry
2567 % if you mistakenly omit the volume and give a number for a journal.
2568 %
2569 % FIX: this is the old def of article, following output of title through end of
2570 % crossref conditional.
2571 % \begin{codeexample}
2572 % volume field.or.null
2573 % % \end{macrocode}
2574 % % One item (the volume) is on the stack now. Each of the four cases in the
2575 % % following conditionals should leave a second item on the stack.
2576 % % \begin{macrocode}
2577 % number empty$ %$
2578 % { volume empty$ %$
2579 % { "empty volume and number in " cite$ * warning$
2580 % ""
2581 % }
2582 % { colon
2583 % }
2584 % if$ %$
2585 % }
2586 % { volume empty$ %$
2587 % { "number but no volume in " cite$ * warning$
2588 % % \end{macrocode}
2589 % % FIX when a journal has no volume but a number, there should be a comma after
2590 % % the journal, a space and then ``no. n:ppp''. But we have already said
2591 % % ``space output'' after the journal name, no doubt. So we have to make this
2592 % % decision earlier.
2593 % % \begin{macrocode}
2594 % "\unskip, no." tie * number * colon *
2595 % }
2596 % { "(" number * ")" * tie.or.space.connect
2597 % % \end{macrocode}
2598 % % FIX: I don't think this is handling the case without pages right -- there
2599 % % will be a colon with nothing following. I could save either colon or
2600 % % colon+space in a variable, and slap it on before the pages if there are pages
2601 % % and leave it off if there are no pages. Hmm, no: see \manaul 15.215
2602 % % for how to handle missing pages. Not easy.
2603 % %
2604 % % Now there's just one item (the volume) on the stack, so leave the following
2605 % % as the second item.
2606 % % \begin{macrocode}
2607 % colon space *
2608 % }
2609 % if$
2610 % }
2611 % if$ *
2612 % make.pages "pages" check.empty *
2613 % space output
2614 % month parenthesize space output
2615 % \end{codeexample}
2616 %
2617 % A crossref from an article says ``See this, pages xxx.'' See \manual 16:107
2618 % for this peculiar bit about the spacing after the colon.
2619 % \begin{macrocode}
2620 FUNCTION {article}
2621 { begin.entry
2622 make.leaditem.with.tags space output
2623 new.block
2624 make.year.nomonth "year" check.empty space output
2625 new.block
2626 make.title.inquotes "title" check.empty space output
2627 new.block
2628 crossref empty$ %$
2629 { journal italicize "journal" check.empty space output
2630 series empty$ %$
2631 'skip$ %$
2632 % \end{macrocode}
2633 % FIX: take this out when we finish \function{make.vol.series}.
2634 % \begin{macrocode}
2635 { "Achicago can not yet handle nonempty series! in " cite$ * warning$
2636 }
2637 if$ %$
2638 volume empty$ number empty$ month empty$ pages empty$ and and and
2639 { "empty volume, number, month, and pages in " cite$ * warning$
2640 }
2641 'skip$ %$
2642 if$ %$
2643 % \end{macrocode}
2644 % See definition of \function{make.vol.series.num.month.pages} for why we set
2645 % \gvar{u} in that function.
2646 % \begin{macrocode}
2647 make.vol.series.num.month.pages u output
2648 }
2649 % \end{macrocode}
2650 % Unusual case where you are probably citing one journal issue and numerous
2651 % articles within it, so you have one entry for the issue itself, and others
2652 % referring to it. Perhaps there are other cases, but I think what's right
2653 % here is to give the crossref and only the pages.
2654 % \begin{macrocode}
2655 { "In " make.crossref * space output
2656 make.pages "pages" check.empty comma output
2657 }
2658 if$ %$
2659 new.block
2660 note space output
2661 finish.entry
2662 }
2663 % \end{macrocode}
2664 % \end{macro}
2665 %
2666 % \subsubsection{Book}
2667 %
2668 % \begin{macro}{book}
2669 % \mbox{}
2670 % \begin{macrocode}
2671 FUNCTION {book}
2672 { begin.entry
2673 make.leaditem.with.tags comma output
2674 new.block
2675 make.year.or.oyear.month "year" check.empty comma output
2676 new.block
2677 make.title.ital "title" check.empty comma output
2678 new.block
2679 make.edition comma output
2680 new.block
2681 crossref empty$ %$
2682 { volume empty$ %$
2683 { output.series.number
2684 }
2685 { output.volume.series
2686 }
2687 if$ %$
2688 editor empty$ author empty$ or
2689 'skip$ %$
2690 { new.block
2691 make.editors.secondary comma output
2692 }
2693 if$ %$
2694 new.block
2695 make.translators comma output
2696 new.block
2697 make.illustrators comma output
2698 new.block
2699 oyear empty$ %$
2700 { address comma output
2701 publisher "publisher" check.empty colon output
2702 }
2703 { oaddress comma output
2704 opublisher "opublisher" check.empty colon output
2705 new.block
2706 "Reprint" comma output
2707 address field.or.null comma output
2708 publisher "publisher" check.empty
2709 address empty$ %$
2710 { comma
2711 }
2712 { colon
2713 }
2714 if$ %$
2715 output
2716 year "year" check.empty comma output
2717 }
2718 if$ %$
2719 }
2720 { volume empty$ %$
2721 { "In "
2722 }
2723 { "Volume" volume tie.or.space.connect
2724 " of " *
2725 }
2726 if$ %$
2727 make.crossref * comma output
2728 }
2729 if$ %$
2730 new.block
2731 yearcomp empty$ %$
2732 'skip$ %$
2733 { "Composed in " yearcomp *
2734 comma output
2735 new.block
2736 }
2737 if$ %$
2738 % \end{macrocode}
2739 % The \field{fyear} must be nonempty to get any information about the first-published
2740 % edition,
2741 %
2742 % The \field{fpublisher}, \field{faddress}, and \field{flanguage} can be empty in any
2743 % combination. They are all ignored if \field{fyear} is empty, except for possibly
2744 % \field{flanguage}, which will be given with the translator if \field{translator} is
2745 % nonempty.
2746 % \begin{macrocode}
2747 fyear empty$
2748 'skip$
2749 { "First published "
2750 translator empty$ flanguage empty$ not and
2751 { "in " * flanguage * space *
2752 }
2753 'skip$
2754 if$
2755 % \end{macrocode}
2756 % If \field{ftitle} is empty, there will be a harmless? extra space.
2757 % FIX: surely i can fix that...
2758 % \begin{macrocode}
2759 make.as.ftitle.ital * space output
2760 faddress empty$ fpublisher empty$ not and
2761 { "by "
2762 }
2763 { "in "
2764 }
2765 if$ %$
2766 space output
2767 faddress space output
2768 fpublisher
2769 faddress empty$ %$
2770 { space
2771 }
2772 { colon
2773 }
2774 if$ %$
2775 output
2776 fyear
2777 faddress empty$ fpublisher empty$ and
2778 { space
2779 }
2780 { comma
2781 }
2782 if$ output %$
2783 new.block
2784 }
2785 if$ %$
2786 note comma output
2787 finish.entry
2788 }
2789 % \end{macrocode}
2790 % \end{macro}
2791 %
2792 % \subsubsection{Inbook}
2793 %
2794 % \begin{macro}{inbook}
2795 % \manual doesn't seem to recognize parts of a book without their own titles.
2796 % We make up our own version, moving the chapter and page information from the
2797 % end of the \field{booktitle} to the beginning.
2798 % \begin{macrocode}
2799 FUNCTION {inbook}
2800 { begin.entry
2801 make.leaditem.with.tags comma output
2802 new.block
2803 make.year.or.oyear.month "year" check.empty comma output
2804 new.block
2805 % \end{macrocode}
2806 % We store an extra copy of \function{make.chapter.of} in the variable\gvar{u} here, so
2807 % that we know whether to put pages or not after the \field{title} sentence
2808 % (with editors, and so on).
2809 % \begin{macrocode}
2810 crossref empty$ %$
2811 { make.chapter.of
2812 duplicate$ 'u := %$
2813 duplicate$ empty$
2814 { pop$ %$
2815 pages empty$ %$
2816 { "empty chapter, type, and pages in " cite$ * warning$
2817 "In "
2818 }
2819 { "Pages " make.pages * " in " *
2820 }
2821 if$ %$
2822 }
2823 'skip$ %$
2824 if$ %$
2825 comma output
2826 make.title.ital "title" check.empty space output
2827 make.bookauthors.secondary comma output
2828 make.editors.secondary comma output
2829 volume empty$ %$
2830 { output.series.number
2831 }
2832 { output.volume.series
2833 }
2834 if$ %$
2835 make.edition comma output
2836 % \end{macrocode}
2837 % Here we branch again on the contents of \function{make.chapter.of}. If it is not
2838 % empty, then we go ahead and \function{make.pages}. If it is empty we don't, because
2839 % this means that if \field{pages} were given, they have already been put earlier.
2840 % \begin{macrocode}
2841 u empty$ %$
2842 'skip$ %$
2843 { make.pages comma output
2844 }
2845 if$ %$
2846 new.block
2847 make.translators comma output
2848 new.block
2849 make.illustrators comma output
2850 new.block
2851 oyear empty$ %$
2852 { address comma output
2853 publisher "publisher" check.empty colon output
2854 }
2855 { oaddress comma output
2856 opublisher "opublisher" check.empty colon output
2857 new.block
2858 "Reprint" comma output
2859 address field.or.null comma output
2860 publisher "publisher" check.empty
2861 address empty$ %$
2862 { comma
2863 }
2864 { colon
2865 }
2866 if$ %$
2867 output
2868 year "year" check.empty comma output
2869 }
2870 if$ %$
2871 }
2872 % crossref not empty
2873 { "In " make.crossref * comma output
2874 make.chapter comma output
2875 make.pages comma output
2876 chapter empty$ pages empty$ and
2877 { "empty chapter and pages in " cite$ * warning$
2878 }
2879 'skip$ %$
2880 if$ %$
2881 }
2882 if$ %$
2883 new.block
2884 note comma output
2885 finish.entry
2886 }
2887 % \end{macrocode}
2888 % \end{macro}
2889 %
2890 % \subsubsection{Incollection}
2891 %
2892 % \begin{macro}{incollection}
2893 % \mbox{}
2894 % \begin{macrocode}
2895 FUNCTION {incollection}
2896 { begin.entry
2897 make.leaditem.with.tags comma output
2898 new.block
2899 make.year.or.oyear.month "year" check.empty space output
2900 new.block
2901 % FIX: use \field{type} to say what kind of title this is? e.g., play, poem,
2902 % chapter, story?
2903 make.title.inquotes "title" check.empty space output
2904 new.block
2905 crossref empty$ %$
2906 { make.chapter.of duplicate$ empty$
2907 { pop$ %$
2908 "In "
2909 }
2910 'skip$ %$
2911 if$ %$
2912 space output
2913 make.booktitle.ital "booktitle" check.empty space output
2914 make.bookauthors.secondary comma output
2915 make.editors.secondary comma output
2916 volume empty$ %$
2917 { output.series.number
2918 }
2919 { output.volume.series
2920 }
2921 if$ %$
2922 make.edition comma output
2923 % FIX: do I need this? I don't for copleston:cusa
2924 % make.year.or.oyear.month "year" check.empty comma output
2925 make.pages comma output
2926 chapter empty$ type empty$ and pages empty$ and %$
2927 { "empty chapter, type, and pages in " cite$ * warning$
2928 }
2929 'skip$ %$
2930 if$ %$
2931 new.block
2932 make.translators space output
2933 new.block
2934 make.illustrators space output
2935 new.block
2936 oyear empty$ %$
2937 { address space output
2938 publisher "publisher" check.empty colon output
2939 }
2940 { oaddress space output
2941 opublisher "opublisher" check.empty colon output
2942 new.block
2943 "Reprint" comma output
2944 address comma output
2945 publisher "publisher" check.empty
2946 address empty$ %$
2947 { comma
2948 }
2949 { colon
2950 }
2951 if$ %$
2952 output
2953 year comma output
2954 }
2955 if$ %$
2956 }
2957 % crossref not empty
2958 { new.block
2959 "In " make.crossref * space output
2960 make.chapter comma output
2961 make.pages comma output
2962 chapter empty$ pages empty$ and
2963 { "empty chapter and pages in " cite$ * warning$
2964 }
2965 'skip$ %$
2966 if$ %$
2967 }
2968 if$ %$
2969 new.block
2970 note space output
2971 finish.entry
2972 }
2973 % \end{macrocode}
2974 % \end{macro}
2975 %
2976 % \subsubsection{Majorthesis}
2977 %
2978 % \begin{macro}{format.thesis}
2979 % \begin{macro}{thesis}
2980 % \begin{macro}{phdthesis}
2981 % \begin{macro}{mastersthesis}
2982 % \begin{macro}{majorthesis}
2983 % \begin{macro}{minorthesis}
2984 % Theses are all set in the same way, with a different type name. An entry
2985 % with entry type \entry{thesis} ought to have a nonempty \field{type}. The other four
2986 % alias entry types simply supply an explicit value for \field{type}, which are
2987 % overridden by a nonempty \field{type}.
2988 %
2989 % FIX The \field{type} field should be hooked into a variable and done with the
2990 % \package{babel} package: \cs\majorthesisname and so on.
2991 % \begin{macrocode}
2992 FUNCTION {format.thesis}
2993 { 'v :=
2994 begin.entry
2995 make.leaditem.with.tags comma output
2996 new.block
2997 make.year.month "year" check.empty space output
2998 new.block
2999 make.title.inquotes "title" check.empty space output
3000 new.block
3001 v "type" check.empty space output
3002 school "school" check.empty comma output
3003 address comma output
3004 new.block
3005 note space output
3006 finish.entry
3007 }
3008 FUNCTION {thesis}
3009 { type field.or.null format.thesis
3010 }
3011 FUNCTION{mastersthesis}
3012 { type empty$ %$
3013 { "Master's thesis"
3014 }
3015 { type
3016 }
3017 if$ %$
3018 format.thesis
3019 }
3020 FUNCTION {minorthesis}
3021 { mastersthesis
3022 }
3023 FUNCTION {phdthesis}
3024 { type empty$ %$
3025 { "Ph.D.~diss."
3026 }
3027 { type
3028 }
3029 if$ %$
3030 format.thesis
3031 }
3032 FUNCTION {majorthesis}
3033 { phdthesis
3034 }
3035 % \end{macrocode}
3036 % \end{macro}
3037 % \end{macro}
3038 % \end{macro}
3039 % \end{macro}
3040 % \end{macro}
3041 % \end{macro}
3042 %
3043 % \subsubsection{Manual}
3044 %
3045 % \begin{macro}{manual}
3046 % Technical documentation. Required: \field{title} (italicized). Optional:
3047 % \field{author} or \field{organization} or \field{key}, \field{address},
3048 % \field{edition}, \field{month}, \field{year}, \field{note}. Logic:
3049 % \evar{leaditem} is first nonempty field of \field{author},
3050 % \field{organization}, and \field{key}. Subsequent nonempty fields in that
3051 % list are ignored. Special case: when \evar{principal-field} is
3052 % \field{organization} and \field{key} is nonempty, use \field{key} for the
3053 % label instead of \field{organization}.
3054 %
3055 % \begin{macrocode}
3056 FUNCTION {manual}
3057 { begin.entry
3058 make.leaditem.with.tags space output
3059 new.block
3060 make.year.month space output
3061 new.block
3062 make.title.ital "title" check.empty comma output
3063 new.block
3064 make.edition comma output
3065 new.block
3066 address space output
3067 organization colon output
3068 new.block
3069 note space output
3070 finish.entry
3071 }
3072 % \end{macrocode}
3073 % \end{macro}
3074 %
3075 % \subsubsection{Booklet}
3076 %
3077 % \begin{macro}{booklet}
3078 % A work that is printed and bound, but without a named publisher or sponsoring
3079 % institution. Required: \field{title}. Optional: \field{author}, \field{howpublished},
3080 % \field{address}, \field{month}, \field{year}, \field{note}. Title is quoted. \field{key} used if \field{author}
3081 % is empty.
3082 % \begin{macrocode}
3083 FUNCTION {booklet}
3084 { begin.entry
3085 make.leaditem.with.tags comma output
3086 new.block
3087 make.year.month space output
3088 new.block
3089 make.title.inquotes "title" check.empty comma output
3090 new.block
3091 howpublished space output
3092 address comma output
3093 new.block
3094 note space output
3095 finish.entry
3096 }
3097 % \end{macrocode}
3098 % \end{macro}
3099 %
3100 % \subsubsection{Inproceedings}
3101 %
3102 % \begin{macro}{inproceedings}
3103 % \begin{macro}{conference}
3104 % An article in a conference proceedings. Required: \field{author},
3105 % \field{title}, \field{booktitle}, \field{year}. Optional: \field{editor},
3106 % \field{volume} or \field{number}, \field{series}, \field{pages},
3107 % \field{address}, \field{month}, \field{organization}, \field{publisher},
3108 % \field{note}. \field{key} used where \field{author} empty. Title quoted.
3109 % \begin{macrocode}
3110 FUNCTION {inproceedings}
3111 { begin.entry
3112 make.leaditem.with.tags comma output
3113 new.block
3114 make.year.month "year" check.empty space output
3115 new.block
3116 make.title.inquotes "title" check.empty space output
3117 new.block
3118 crossref empty$ %$
3119 { make.editors.secondary space output
3120 make.booktitle.ital "booktitle" check.empty comma output
3121 volume empty$ %$
3122 { output.series.number
3123 }
3124 { output.volume.series
3125 }
3126 if$ %$
3127 make.edition comma output
3128 new.block
3129 organization space output
3130 address comma output
3131 publisher colon output
3132 make.pages comma output
3133 }
3134 { "In " make.crossref * space output
3135 make.chapter comma output
3136 make.pages comma output
3137 chapter empty$ pages empty$ and
3138 { "empty chapter and pages in " cite$ * warning$
3139 }
3140 'skip$ %$
3141 if$ %$
3142 }
3143 if$ %$
3144 new.block
3145 note space output
3146 finish.entry
3147 }
3148 FUNCTION {conference}
3149 { inproceedings
3150 }
3151 % \end{macrocode}
3152 % \end{macro}
3153 % \end{macro}
3154 %
3155 % \subsubsection{Proceedings}
3156 %
3157 % \begin{macro}{proceedings}
3158 % The proceedings of a conference. Required: \field{title}, \field{year}.
3159 % Optional: \field{editor}, \field{volume} or \field{number}, \field{series},
3160 % \field{address}, \field{month}, \field{organization}, \field{publisher},
3161 % \field{note}. If \field{editor} empty, use \field{organization} for
3162 % \evar{leaditem}. For label, like type manual, use nonempty \field{key} for
3163 % the label instead of \field{organization}. Title italicized.
3164 % \begin{macrocode}
3165 FUNCTION {proceedings}
3166 { begin.entry
3167 make.leaditem.with.tags space output
3168 new.block
3169 make.year.month "year" check.empty space output
3170 new.block
3171 make.title.ital "title" check.empty comma output
3172 new.block
3173 make.edition comma output
3174 new.block
3175 volume empty$ %$
3176 { output.series.number
3177 }
3178 { output.volume.series
3179 }
3180 if$ %$
3181 new.block
3182 organization space output
3183 address comma output
3184 publisher colon output
3185 new.block
3186 note comma output
3187 finish.entry
3188 }
3189 % \end{macrocode}
3190 % \end{macro}
3191 %
3192 % \subsubsection{Misc}
3193 % Required: \emph{none}. The rest are optional. \field{leaditem} is
3194 % \field{author} or \field{key} if empty. \field{year} with \field{month}.
3195 % Then \field{title}, quoted. Then \field{howpublished}. Then \field{note}.
3196 % \begin{macrocode}
3197 FUNCTION {misc}
3198 { begin.entry
3199 make.leaditem.with.tags comma output
3200 new.block
3201 make.year.month space output
3202 new.block
3203 title space output
3204 new.block
3205 howpublished comma output
3206 new.block
3207 note space output
3208 finish.entry
3209 }
3210 % \end{macrocode}
3211 %
3212 % \subsubsection{Techreport}
3213 %
3214 % \begin{macro}{techreport}
3215 % A report published by a school or other institution, usually numbered within
3216 % a series. Required: \field{author}, \field{title}, \field{institution},
3217 % \field{year}. Optional: \field{type}, \field{number}, \field{address},
3218 % \field{month}, \field{note}. \field{key} used when \field{author} empty.
3219 % \begin{macrocode}
3220 FUNCTION {techreport}
3221 { begin.entry
3222 make.leaditem.with.tags comma output
3223 new.block
3224 make.year.month "year" check.empty comma output
3225 new.block
3226 make.title.inquotes "title" check.empty comma output
3227 new.block
3228 make.number.tr comma output
3229 institution "institution" check.empty comma output
3230 address comma output
3231 new.block
3232 note comma output
3233 finish.entry
3234 }
3235 % \end{macrocode}
3236 % \end{macro}
3237 %
3238 % \subsubsection{Unpublished}
3239 %
3240 % \begin{macro}{unpublished}
3241 % A document having an author and title, but not formally published. Required:
3242 % \field{author}, \field{title}, \field{note}. Optional: \field{month},
3243 % \field{year}. Uses \field{key} for no \field{author}.
3244 % \begin{macrocode}
3245 FUNCTION {unpublished}
3246 { begin.entry
3247 make.leaditem.with.tags comma output
3248 new.block
3249 make.year.month space output
3250 new.block
3251 make.title.inquotes "title" check.empty space output
3252 new.block
3253 note "note" check.empty space output
3254 finish.entry
3255 }
3256 % \end{macrocode}
3257 % \end{macro}
3258 %
3259 % \subsubsection{Default}
3260 %
3261 % \begin{macro}{default.type}
3262 % I think \BibTeX{} is hardwired to look for this name.
3263 % \begin{macrocode}
3264 FUNCTION {default.type}
3265 { misc }
3266 % \end{macrocode}
3267 % \end{macro}
3268 %
3269 % \subsection{Sorting}
3270 %
3271 % \begin{macro}{chop.word}
3272 % \cs\stack{\meta{string} \meta{num} \meta{string}}{\meta{string}}
3273 % \begin{verbatim}
3274 % stack: S n T
3275 %
3276 % if S = substr(1,n,T)
3277 % then substr(n+1, max, T)
3278 % else S
3279 %
3280 % if T begins with S, then chop it off the beginning of T.
3281 % \end{verbatim}
3282 % I guess we don't bother calculating the length for efficiency's sake.
3283 % \begin{macrocode}
3284 FUNCTION {chop.word}
3285 { 't :=
3286 'len :=
3287 t #1 len substring$ = %$
3288 { t len #1 + global.max$ substring$
3289 }
3290 { t
3291 }
3292 if$ %$
3293 }
3294 % \end{macrocode}
3295 % \end{macro}
3296 %
3297 % \begin{macro}{make.title.for.sort}
3298 % We don't bother to \function{format.sortify.clip}, just do that once before assignment to
3299 % the sort.key.
3300 % \begin{macrocode}
3301 FUNCTION {make.title.for.sort}
3302 { title field.or.null
3303 't :=
3304 "A " #2
3305 "An " #3
3306 "The " #4 t chop.word
3307 chop.word
3308 chop.word
3309 % letter-by-letter alphabetization:
3310 format.dehyphen.dewhitespace
3311 }
3312 % \end{macrocode}
3313 % \end{macro}
3314 %
3315 % \begin{macro}{presort}
3316 %
3317 % Set \evar{label}, \evar{year.label}, \evar{leaditem}. Set \field{sort.key\$}
3318 % to \evar{leaditem} + \evar{year.label} + title suitably massaged.
3319 %
3320 % Note that \evar{year.label.tag} is not set yet; it will be set in stages in
3321 % \function{forward.pass.add.bcds} and \function{reverse.pass.add.as}.
3322 % \begin{macrocode}
3323 FUNCTION {presort}
3324 { set.principal-field.principal-type
3325
3326 % "principals set for " cite$ * debugmsg %$
3327 make.leaditem
3328 'leaditem :=
3329
3330 % "leaditem set for " cite$ * debugmsg %$
3331 make.label
3332 'label :=
3333
3334 % "label set for " cite$ * debugmsg %$
3335 oyear empty$ %$
3336 { year
3337 }
3338 { oyear
3339 }
3340 if$ %$
3341 % FIX: substring or text.prefix? if purify removes special chars then no diff.
3342 field.or.null purify$ #-1 #4 substring$
3343 'year.label :=
3344 }
3345
3346 FUNCTION {sortkey<-label+year+principal+title}
3347 { label
3348 delimiter.sub-sortkey *
3349 year.label *
3350 delimiter.sub-sortkey *
3351 make.principal-field.for.sort *
3352 delimiter.sub-sortkey *
3353 make.title.for.sort *
3354 format.sortify.clip
3355 'sort.key$ := %$
3356 }
3357
3358 FUNCTION {sortkey<-principal+year+year-tag}
3359 { make.principal-field.for.sort
3360 delimiter.sub-sortkey *
3361 year.label *
3362 % FIX if year.label is ever going to be a variable length, need some padding here?
3363 year.label.tag *
3364 format.sortify.clip
3365 'sort.key$ := %$
3366 }
3367
3368 FUNCTION {presort.&.sortkey<-label+year+principal+title}
3369 { presort
3370 % "presort done for " cite$ * debugmsg %$
3371 sortkey<-label+year+principal+title
3372 % "sortkey set to label+year+principal+title for " cite$ * debugmsg %$
3373 }
3374 % \end{macrocode}
3375 % \end{macro}
3376 %
3377 % \begin{macro}{initialize.sorting-gvars}
3378 % \mbox{}
3379 % \begin{macrocode}
3380 FUNCTION {initialize.sorting-gvars}
3381 { unidentified 'last.leaditem :=
3382 unidentified 'last.label.and.year :=
3383 "" 'following.year.label.tag :=
3384 #0 'last.year.tag.num :=
3385 }
3386 % \end{macrocode}
3387 % \end{macro}
3388 %
3389 % \section{Disambiguating citations and sorting the bibliography}
3390 %
3391 % The initial calculation of citations can result in
3392 % ambiguous labels for some entries. Two kinds of ambiguities can result:
3393 %
3394 % \begin{description}
3395 % \item[same principal]
3396 % These are disambiguated by adding a unique lowercase letter to the end of
3397 % the citations for each entry in the ambiguous set: (Smith 1980a) and
3398 % (Smith 1980b); (Smith et~al. 1970a), (Smith et~al. 1970b). The order of
3399 % the letters corresonds to the order of their appearance in the
3400 % bibliography (see below).
3401 % \item[different principal]
3402 %
3403 % Different principals can have be (initially) given the same label in two
3404 % cases: (1) the principals include 4 or more names and the initial names
3405 % share a surname, and (2) the principals include the same number $n<4$ of
3406 % names and both the initial names and each of the subsequent names when
3407 % present share a surname. In each case, the entries must also have the
3408 % same year+tag, that is, the same year \emph{including} any lowercase
3409 % letters that might have been added. In both cases, ambiguous labels are
3410 % disambiguated by adding first initials to those names which differ in the
3411 % first name: (P.~Smith 1980), (M.~Smith 1980); (Green, Z.~Black, and Meyer
3412 % 1980), (Green, B.~Black, and Meyer 1980); (Benson, Brown, Gray, White,
3413 % B.~Black, and Griscom 1900), (Benson, H.~Brown, Gray, White, Z.~Black,
3414 % and Griscom 1900). When even first initials aren't enough to
3415 % disambiguate, full names are used: (John~D.\ Smith 1990), (John~Q.\ Smith
3416 % 1990); etc.
3417 %
3418 % \end{description}
3419 %
3420 % FIX: current behavior disambiguates all ambiguous citations by means of the
3421 % lowercase letter. ``A, B, C, and D 1999'' together with ``A, B, C, and E
3422 % 1999'' are going to resolve to ``A et al 1999a'' and 1999b. This nicely
3423 % avoids disambiguation, but not what the Manual specifies.
3424 %
3425 % FIX: current behavior is going to disambiguate citations that are ambiguous
3426 % because authors share last but differ in first names by means of the
3427 % lowercase letter: ``Aa 1999'' and ``Ab 1999'' become ``Aa 1999a'' and ``Ab
3428 % 1999b'' (where `A' stands for last name, and the `a' right after it is the
3429 % unmentioned first name). The Manual, however, specifies (16.3)
3430 % disambiguating by using first initials in the label, such as ``M. Brown
3431 % 1999''.
3432 %
3433 % add.bcds: work on getting the right \evar{year.label.tag}. Compare current
3434 % entry's \evar{label} plus \evar{year.label} to the last entry's, which is
3435 % stored in the global string variable \gvar{last.label.and.year}. If they are
3436 % the same, increment global integer variable \gvar{last.year.tag.num} and set
3437 % \evar{year.label.tag} to the $n$th lowercase letter, where $n$ is
3438 % \gvar{last.year.tag.num}. If they are not the same, set
3439 % \gvar{last.label.and.year} to the current \evar{label} plus \evar{year.label}, set
3440 % \evar{year.label.tag} to empty string, and set \gvar{last.year.tag.num} to~0.
3441 %
3442 % After add.bcds pass, \evar{year.label.tag} will be blank for all first
3443 % entries of an ambiguous series, and ``b,'' ``c,'' etc.\ for second entries,
3444 % third entries, and so on. The ``a'''s will be added in the right places by
3445 % the reverse.pass.add.as function.
3446 %
3447 % Handle duplicate \evar{leaditem}s. Compare current entry's
3448 % \evar{leaditem} with the last entry's, which is stored in the global string
3449 % variable \gvar{last.leaditem}. When they are the same, wrap the current
3450 % entry's \evar{leaditem} in \cs\SCduplicate.
3451 % \begin{macrocode}
3452 FUNCTION {forward.pass.wrap.dupe.leaditems}
3453 { leaditem
3454 duplicate$ last.leaditem = %$
3455 % we add the brace pair at the end because this forces add.period$ to add a %$
3456 % period after it. FIX: if we ever want \SCdup to actually print its
3457 % argument, we must get it to print its argument minus any final period.
3458 { "\SCduplicate{" swap$ * "{}}" * 'leaditem := %$
3459 }
3460 { 'last.leaditem :=
3461 }
3462 if$ %$
3463 }
3464 FUNCTION {forward.pass.add.bcds}
3465 { label year.label * format.clip
3466 duplicate$ last.label.and.year = %$
3467 % same as previous entry
3468 { pop$ %$
3469 last.year.tag.num #1 + 'last.year.tag.num :=
3470 last.year.tag.num int.to.chr$ 'year.label.tag := %$
3471 }
3472 % different from previous entry
3473 { "a" chr.to.int$ 'last.year.tag.num := %$
3474 "" 'year.label.tag :=
3475 'last.label.and.year :=
3476 }
3477 if$ %$
3478 }
3479 % FIX: use a minimum of entry-variables to hold 'last' things.
3480 % FIX: change `last' to 'prev' where appropriate. what about vars that might
3481 % be used going forward and back? always use `prev'?
3482
3483 % \end{macrocode}
3484 %
3485 % \begin{macro}{reverse.pass.add.as}
3486 % Pass through the entries in reverse order. Set current
3487 % \evar{year.label.tag} to ``a'' on entries that precede ones with ``b''s.
3488 % Set \evar{following.year.label.tag} to the current \evar{year.label.tag}.
3489 % \begin{macrocode}
3490 FUNCTION {reverse.pass.add.as}
3491 { following.year.label.tag "b" =
3492 { "a" 'year.label.tag :=
3493 }
3494 'skip$ %$
3495 if$ %$
3496 year.label.tag 'following.year.label.tag :=
3497 }
3498 % \end{macrocode}
3499 % \end{macro}
3500 %
3501 % \begin{macro}{begin.bib}
3502 % \begin{macro}{end.bib}
3503 % These two functions are called to begin and end the entire bibliography.
3504 % \begin{macrocode}
3505 FUNCTION {begin.bib}
3506 { preamble$ empty$
3507 'skip$ %$
3508 { preamble$ write$ newline$ %$
3509 }
3510 if$ %$
3511 "\begin{thebibliography}{}" write$ newline$
3512 }
3513 FUNCTION {end.bib}
3514 { newline$ %$
3515 "\end{thebibliography}" write$ newline$
3516 }
3517 % \end{macrocode}
3518 % \end{macro}
3519 % \end{macro}
3520 %
3521 % \subsection{Actions}
3522 %
3523 % This is the main subroutine which calls all the others.
3524 % \begin{macrocode}
3525 READ
3526
3527 EXECUTE {init.scalars}
3528
3529 ITERATE {presort.&.sortkey<-label+year+principal+title}
3530 SORT
3531
3532 EXECUTE {initialize.sorting-gvars}
3533
3534 % add in "b"'s etc.
3535 ITERATE {forward.pass.add.bcds}
3536 % add in "a"'s
3537 REVERSE {reverse.pass.add.as}
3538
3539 ITERATE{sortkey<-principal+year+year-tag}
3540 SORT
3541
3542 EXECUTE {initialize.sorting-gvars}
3543 ITERATE {forward.pass.wrap.dupe.leaditems}
3544
3545
3546 EXECUTE {begin.bib}
3547 ITERATE {call.type$} %$
3548 EXECUTE {end.bib}
3549 % \end{macrocode}
3550 %
3551 % \Finale