Debian Codegraph @

texmf-dist/doc/bibtex/base/btxbst.doc

raw
1 % BibTeX `plain' family
2 % Version 0.99b (8-Dec-10 release) for BibTeX versions 0.99a or later.
3 % Copyright (C) 1984, 1985, 1988, 2010 Howard Trickey and Oren Patashnik.
4 % Unlimited copying and redistribution of this file are permitted as long as
5 % it is unmodified. Modifications (and redistribution of modified versions)
6 % are also permitted, but only if the resulting file is renamed to something
7 % besides btxbst.doc, plain.bst, unsrt.bst, alpha.bst, and abbrv.bst.
8 % This restriction helps ensure that all standard styles are identical.
9 % The file btxbst.doc has the documentation for this style.
10 % Please notify [email protected] of any bugs in
11 % these standard styles or in this documentation file.
12 %
13 % This is file btxbst.doc; it helps document bibliography styles,
14 % and is also a template file that you can use to make
15 % several different style files, if you have access to a C preprocessor.
16 % For example, the standard styles were made by doing something like
17 % cpp -P -DPLAIN btxbst.doc plain.txt
18 % cpp -P -DUNSRT btxbst.doc unsrt.txt
19 % cpp -P -DALPHA btxbst.doc alpha.txt
20 % cpp -P -DABBRV btxbst.doc abbrv.txt
21 % and then renaming after removing unwanted comments and blank lines.
22 % If you don't have access,
23 % you can edit this file by hand to imitate the preprocessor,
24 % with the following explanation of the C preprocessor constructs used here.
25 %
26 % The output of the preprocessor is the same as the input, except that certain
27 % lines will be excluded (and some blank lines will be added). The sequence
28 % #if VAR
29 % lines to be included when VAR is not zero
30 % #else
31 % lines to be included when VAR is zero
32 % #endif
33 % (with the #-signs appearing in column 1) means that one set or the other of
34 % the lines are to be included depending on the value of VAR.
35 % The #else part is optional. Comments can be added after #else and #endif.
36 % Variables can be set by
37 % #define VAR value
38 % and one can also use #ifdef VAR to see if VAR has any value, and #ifndef
39 % to see if it has none.
40 % Another #if form used in this file is #if !VAR, which includes the lines
41 % after the #if only if VAR is zero.
42 %
43 % Convention: Use all uppercase identifiers for these preprocessor variables
44 % so you can spot them easily
45 %
46 % The command line to the preprocessor should define one of PLAIN, UNSRT, ALPHA
47 % or ABBRV (though PLAIN will be used by default if none is given),
48 % and the following lines will set various boolean variables to control the
49 % various lines that are chosen from the rest of the file.
50 % Each boolean variable should be set true (1) or false (0) in each style.
51 % Here are the current variables, and their meanings:
52 % LAB_ALPH: an alphabetic label is used (if false then a numeric
53 % label is used)
54 % SORTED: the entries should be sorted by label (if nonnumeric)
55 % and other info, like authors (if false, then
56 % entries remain in order of occurrence)
57 % NAME_FULL: the authors, editors, etc., get the full names as
58 % given in the bibliography file (if false, the first
59 % names become initials)
60 % ATIT_LOWER: titles of non-"books" (e.g., articles) should be
61 % converted to lower-case, except the first letter or
62 % first letter after a colon
63 % (if false then they appear as in the database)
64 % MONTH_FULL: months are spelled out in full (if false, then
65 % they're abbreviated)
66 % JOUR_FULL: macro journal names are spelled out in full
67 % (if false then they are abbreviated, currently
68 % as they appear in ACM publications)
69 #ifndef UNSRT
70 # ifndef ALPHA
71 # ifndef ABBRV
72 # define PLAIN 1
73 # endif
74 # endif
75 #endif
76 #ifdef PLAIN
77 % plain style (sorted numbers)
78 # define LAB_ALPH 0
79 # define SORTED 1
80 # define NAME_FULL 1
81 # define ATIT_LOWER 1
82 # define MONTH_FULL 1
83 # define JOUR_FULL 1
84 #endif
85 #ifdef UNSRT
86 % unsrt style (unsorted numbers)
87 # define LAB_ALPH 0
88 # define SORTED 0
89 # define NAME_FULL 1
90 # define ATIT_LOWER 1
91 # define MONTH_FULL 1
92 # define JOUR_FULL 1
93 #endif
94 #ifdef ALPHA
95 % alpha style (sorted short alphabetics)
96 # define LAB_ALPH 1
97 # define SORTED 1
98 # define NAME_FULL 1
99 # define ATIT_LOWER 1
100 # define MONTH_FULL 1
101 # define JOUR_FULL 1
102 #endif
103 #ifdef ABBRV
104 % abbrv style (sorted numbers, with abbreviations)
105 # define LAB_ALPH 0
106 # define SORTED 1
107 # define NAME_FULL 0
108 # define ATIT_LOWER 1
109 # define MONTH_FULL 0
110 # define JOUR_FULL 0
111 #endif
112 %
113 % Entry formatting: Similar to that recommended by Mary-Claire van Leunen
114 % in "A Handbook for Scholars". Book-like titles are italicized
115 % (emphasized) and non-book titles are converted to sentence
116 % capitilization (and not enclosed in quotes).
117 % This file outputs a \newblock between major blocks of an entry
118 % (the name \newblock is analogous to the names \newline and \newpage)
119 % so that the user can obtain an "open" format, which has a line break
120 % before each block and lines after the first are indented within blocks,
121 % by giving the optional \documentstyle argument `openbib';
122 % The default is the "closed" format---blocks runs together.
123 %
124 % Citation alphabetic label format:
125 % [Knu73] for single author (or editor or key)
126 % [AHU83] (first letters of last names) for multiple authors
127 %
128 % Citation label numberic format:
129 % [number]
130 %
131 % Reference list ordering for sorted, alphabetic lables:
132 % alphabetical by citation label, then by author(s) or whatever
133 % passes for author in the absence of one, then by year,
134 % then title
135 %
136 % Reference list ordering for sorted, numeric lables:
137 % alphabetical by author(s) or whatever passes
138 % for author in the absence of one, then by year, then title
139 %
140 % Reference list ordering for unsorted:
141 % by the order cited in the text
142 %
143 % History
144 % 12/16/84 (HWT) Original `plain' version, by Howard Trickey.
145 % 12/23/84 (LL) Some comments made by Leslie Lamport.
146 % 2/16/85 (OP) Changes based on LL's comments, Oren Patashnik.
147 % 2/17/85 (HWT) Template file and other standard styles made.
148 % 3/28/85 (OP) First release, version 0.98b for BibTeX 0.98f.
149 % 5/ 9/85 (OP) Version 0.98c for BibTeX 0.98i:
150 % fixed Theoretical Computer Science macro name;
151 % fixed the format.vol.num.pages function.
152 % 1/24/88 (OP) Version 0.99a for BibTeX 0.99a, main changes:
153 % assignment operator (:=) arguments reversed;
154 % the preamble$ function outputs the database PREAMBLE;
155 % entry.max$ and global.max$ (built-in) variables replace
156 % entry.string.max and global.string.max functions;
157 % alphabetizing by year then title, not just title;
158 % many unnecessary ties removed; \it ==> \em;
159 % the `alpha' style uses a superscripted `+' instead of a
160 % `*' for unnamed names in constructing the label;
161 % the `abbrv' style now uses "Mar." and "Sept.";
162 % the functions calc.label and presort now look at just
163 % the fields they're supposed to;
164 % BOOKLET, MASTERSTHESIS, TECHREPORT use nonbook titles;
165 % INBOOK and INCOLLECTION take an optional type (e.g.
166 % type = "Section"), overriding the default "chapter";
167 % BOOK, INBOOK, INCOLLECTION, and PROCEEDINGS now allow
168 % either volume or number, not just volume;
169 % INCOLLECTION now allows an edition and series field;
170 % PROCEEDINGS and INPROCEEDINGS now use the address field
171 % to tell where a conference was held;
172 % INPROCEEDINGS and PROCEEDINGS now allow either volume
173 % or number, and also a series field;
174 % MASTERSTHESIS and PHDTHESIS accept types other than
175 % "Master's thesis" and "PhD thesis";
176 % UNPUBLISHED now outputs, in one block, note then date;
177 % MANUAL now prints out the organization in
178 % the first block if the author field is empty;
179 % MISC can't be empty---it requires some optional field.
180 % 3/23/88 (OP) Version 0.99b for BibTeX 0.99c---changed the three
181 % erroneous occurrences of `cite ' to `cite$ '; this
182 % change didn't affect the four standard styles, so the
183 % 0.99a versions of those styles are still current.
184 % 12/ 8/10 (OP) Still version 0.99b, as the code itself was unchanged;
185 % this release clarified the license.
186 %
187 % The ENTRY declaration
188 % Like Scribe's (according to pages 231-2 of the April '84 edition),
189 % but no fullauthor or editors fields because BibTeX does name handling.
190 % The annote field is commented out here because this family doesn't
191 % include an annotated bibliography style. And in addition to the fields
192 % listed here, BibTeX has a built-in crossref field, explained later.
193
194 ENTRY
195 % Fields:
196 { address
197 % Usually the address of a publisher or other type of organization.
198 % Put information in this field only if it helps the reader find the
199 % thing---for example you should omit the address of a major
200 % publisher entirely. For a PROCEEDINGS or an INPROCEEDINGS,
201 % however, it's the address of the conference; for those two entry
202 % types, include the publisher's or organization's address, if
203 % necessary, in the publisher or organization field.
204 % annote
205 % Long annotation---for annotated bibliographies (begins sentence).
206 author
207 % Name(s) of author(s), in BibTeX name format.
208 booktitle
209 % Book title when the thing being referenced isn't the whole book.
210 % For book entries, the title field should be used instead.
211 chapter
212 % Chapter (or section or whatever) number.
213 edition
214 % Edition of a book---should be an ordinal (e.g., "Second").
215 editor
216 % Name(s) of editor(s), in BibTeX name format.
217 % If there is also an author field, then the editor field should be
218 % for the book or collection that the work appears in.
219 howpublished
220 % How something strange has been published (begins sentence).
221 institution
222 % Sponsoring institution of a technical report.
223 journal
224 % Journal name (macros are provided for many).
225 key
226 % Alphabetizing, labeling, and cross-referencing key
227 % (needed when an entry has no author or editor).
228 month
229 % Month (macros are provided).
230 note
231 % To help the reader find a reference (begins sentence).
232 number
233 % Number of a journal or technical report, or of a work in a series.
234 organization
235 % Organization sponsoring a conference (or publishing a manual); if
236 % the editor (or author) is empty, and if the organization produces
237 % an awkward label or cross reference, you should put appropriately
238 % condensed organization information in the key field as well.
239 pages
240 % Page number or numbers (use `--' to separate a range, use `+'
241 % to indicate pages following that don't form a simple range).
242 publisher
243 % Publisher name.
244 school
245 % School name (for theses).
246 series
247 % The name of a series or set of books.
248 % An individual book will will also have it's own title.
249 title
250 % The title of the thing you're referred to.
251 type
252 % Type of a Techreport (e.g., "Research Note") to be used instead of
253 % the default "Technical Report"; or, similarly, the type of a
254 % thesis; or of a part of a book.
255 volume
256 % The volume number of a journal or multivolume work.
257 year
258 % The year should contain only numerals (technically, it should end
259 % with four numerals, after purification; doesn't a begin sentence).
260 }
261 % There are no integer entry variables
262 {}
263 % These string entry variables are used to form the citation label.
264 % In a storage pinch, sort.label can be easily computed on the fly.
265 #if LAB_ALPH
266 #if SORTED
267 { label extra.label sort.label }
268 #else !SORTED
269 % It doesn't seem like a good idea to use an order-of-citation
270 % reference list when using alphabetic labels, but when this happens
271 % we do things a little differently
272 { label }
273 #endif SORTED
274 #else !LAB_ALPH
275 { label }
276 #endif LAB_ALPH
277
278 % Each entry function starts by calling output.bibitem, to write the
279 % \bibitem and its arguments to the .BBL file. Then the various fields
280 % are formatted and printed by output or output.check. Those functions
281 % handle the writing of separators (commas, periods, \newblock's),
282 % taking care not to do so when they are passed a null string.
283 % Finally, fin.entry is called to add the final period and finish the
284 % entry.
285 %
286 % A bibliographic reference is formatted into a number of `blocks':
287 % in the open format, a block begins on a new line and subsequent
288 % lines of the block are indented. A block may contain more than
289 % one sentence (well, not a grammatical sentence, but something to
290 % be ended with a sentence ending period). The entry functions should
291 % call new.block whenever a block other than the first is about to be
292 % started. They should call new.sentence whenever a new sentence is
293 % to be started. The output functions will ensure that if two
294 % new.sentence's occur without any non-null string being output between
295 % them then there won't be two periods output. Similarly for two
296 % successive new.block's.
297 %
298 % The output routines don't write their argument immediately.
299 % Instead, by convention, that argument is saved on the stack to be
300 % output next time (when we'll know what separator needs to come
301 % after it). Meanwhile, the output routine has to pop the pending
302 % output off the stack, append any needed separator, and write it.
303 %
304 % To tell which separator is needed, we maintain an output.state.
305 % It will be one of these values:
306 % before.all just after the \bibitem
307 % mid.sentence in the middle of a sentence: comma needed
308 % if more sentence is output
309 % after.sentence just after a sentence: period needed
310 % after.block just after a block (and sentence):
311 % period and \newblock needed.
312 % Note: These styles don't use after.sentence
313 %
314 % VAR: output.state : INTEGER -- state variable for output
315 %
316 % The output.nonnull function saves its argument (assumed to be nonnull)
317 % on the stack, and writes the old saved value followed by any needed
318 % separator. The ordering of the tests is decreasing frequency of
319 % occurrence.
320 %
321 % output.nonnull(s) ==
322 % BEGIN
323 % s := argument on stack
324 % if output.state = mid.sentence then
325 % write$(pop() * ", ")
326 % -- "pop" isn't a function: just use stack top
327 % else
328 % if output.state = after.block then
329 % write$(add.period$(pop()))
330 % newline$
331 % write$("\newblock ")
332 % else
333 % if output.state = before.all then
334 % write$(pop())
335 % else -- output.state should be after.sentence
336 % write$(add.period$(pop()) * " ")
337 % fi
338 % fi
339 % output.state := mid.sentence
340 % fi
341 % push s on stack
342 % END
343 %
344 % The output function calls output.nonnull if its argument is non-empty;
345 % its argument may be a missing field (thus, not necessarily a string)
346 %
347 % output(s) ==
348 % BEGIN
349 % if not empty$(s) then output.nonnull(s)
350 % fi
351 % END
352 %
353 % The output.check function is the same as the output function except that, if
354 % necessary, output.check warns the user that the t field shouldn't be empty
355 % (this is because it probably won't be a good reference without the field;
356 % the entry functions try to make the formatting look reasonable even when
357 % such fields are empty).
358 %
359 % output.check(s,t) ==
360 % BEGIN
361 % if empty$(s) then
362 % warning$("empty " * t * " in " * cite$)
363 % else output.nonnull(s)
364 % fi
365 % END
366 %
367 % The output.bibitem function writes the \bibitem for the current entry
368 % (the label should already have been set up), and sets up the separator
369 % state for the output functions. And, it leaves a string on the stack
370 % as per the output convention.
371 %
372 % output.bibitem ==
373 % BEGIN
374 % newline$
375 % write$("\bibitem[") % for alphabetic labels,
376 % write$(label) % these three lines
377 % write$("]{") % are used
378 % write$("\bibitem{") % this line for numeric labels
379 % write$(cite$)
380 % write$("}")
381 % push "" on stack
382 % output.state := before.all
383 % END
384 %
385 % The fin.entry function finishes off an entry by adding a period to the
386 % string remaining on the stack. If the state is still before.all
387 % then nothing was produced for this entry, so the result will look bad,
388 % but the user deserves it. (We don't omit the whole entry because the
389 % entry was cited, and a bibitem is needed to define the citation label.)
390 %
391 % fin.entry ==
392 % BEGIN
393 % write$(add.period$(pop()))
394 % newline$
395 % END
396 %
397 % The new.block function prepares for a new block to be output, and
398 % new.sentence prepares for a new sentence.
399 %
400 % new.block ==
401 % BEGIN
402 % if output.state <> before.all then
403 % output.state := after.block
404 % fi
405 % END
406 %
407 % new.sentence ==
408 % BEGIN
409 % if output.state <> after.block then
410 % if output.state <> before.all then
411 % output.state := after.sentence
412 % fi
413 % fi
414 % END
415 %
416
417 INTEGERS { output.state before.all mid.sentence after.sentence after.block }
418
419 FUNCTION {init.state.consts}
420 { #0 'before.all :=
421 #1 'mid.sentence :=
422 #2 'after.sentence :=
423 #3 'after.block :=
424 }
425
426 % the variables s and t are temporary string holders
427
428 STRINGS { s t }
429
430 FUNCTION {output.nonnull}
431 { 's :=
432 output.state mid.sentence =
433 { ", " * write$ }
434 { output.state after.block =
435 { add.period$ write$
436 newline$
437 "\newblock " write$
438 }
439 { output.state before.all =
440 'write$
441 { add.period$ " " * write$ }
442 if$
443 }
444 if$
445 mid.sentence 'output.state :=
446 }
447 if$
448 s
449 }
450
451 FUNCTION {output}
452 { duplicate$ empty$
453 'pop$
454 'output.nonnull
455 if$
456 }
457
458 FUNCTION {output.check}
459 { 't :=
460 duplicate$ empty$
461 { pop$ "empty " t * " in " * cite$ * warning$ }
462 'output.nonnull
463 if$
464 }
465
466 FUNCTION {output.bibitem}
467 { newline$
468 #if LAB_ALPH
469 "\bibitem[" write$
470 label write$
471 "]{" write$
472 #else
473 "\bibitem{" write$
474 #endif LAB_ALPH
475 cite$ write$
476 "}" write$
477 newline$
478 ""
479 before.all 'output.state :=
480 }
481
482 % This function finishes all entries.
483
484 FUNCTION {fin.entry}
485 { add.period$
486 write$
487 newline$
488 }
489
490 FUNCTION {new.block}
491 { output.state before.all =
492 'skip$
493 { after.block 'output.state := }
494 if$
495 }
496
497 FUNCTION {new.sentence}
498 { output.state after.block =
499 'skip$
500 { output.state before.all =
501 'skip$
502 { after.sentence 'output.state := }
503 if$
504 }
505 if$
506 }
507
508 % These three functions pop one or two (integer) arguments from the stack
509 % and push a single one, either 0 or 1.
510 % The 'skip$ in the `and' and `or' functions are used because
511 % the corresponding if$ would be idempotent
512
513 FUNCTION {not}
514 { { #0 }
515 { #1 }
516 if$
517 }
518
519 FUNCTION {and}
520 { 'skip$
521 { pop$ #0 }
522 if$
523 }
524
525 FUNCTION {or}
526 { { pop$ #1 }
527 'skip$
528 if$
529 }
530
531 % Sometimes we begin a new block only if the block will be big enough. The
532 % new.block.checka function issues a new.block if its argument is nonempty;
533 % new.block.checkb does the same if either of its TWO arguments is nonempty.
534
535 FUNCTION {new.block.checka}
536 { empty$
537 'skip$
538 'new.block
539 if$
540 }
541
542 FUNCTION {new.block.checkb}
543 { empty$
544 swap$ empty$
545 and
546 'skip$
547 'new.block
548 if$
549 }
550
551 % The new.sentence.check functions are analogous.
552
553 FUNCTION {new.sentence.checka}
554 { empty$
555 'skip$
556 'new.sentence
557 if$
558 }
559
560 FUNCTION {new.sentence.checkb}
561 { empty$
562 swap$ empty$
563 and
564 'skip$
565 'new.sentence
566 if$
567 }
568
569 % Here are some functions for formatting chunks of an entry.
570 % By convention they either produce a string that can be followed by
571 % a comma or period (using add.period$, so it is OK to end in a period),
572 % or they produce the null string.
573 %
574 % A useful utility is the field.or.null function, which checks if the
575 % argument is the result of pushing a `missing' field (one for which no
576 % assignment was made when the current entry was read in from the database)
577 % or the result of pushing a string having no non-white-space characters.
578 % It returns the null string if so, otherwise it returns the field string.
579 % Its main (but not only) purpose is to guarantee that what's left on the
580 % stack is a string rather than a missing field.
581 %
582 % field.or.null(s) ==
583 % BEGIN
584 % if empty$(s) then return ""
585 % else return s
586 % END
587 %
588 % Another helper function is emphasize, which returns the argument emphazised,
589 % if that is non-empty, otherwise it returns the null string. Italic
590 % corrections aren't used, so this function should be used when punctation
591 % will follow the result.
592 %
593 % emphasize(s) ==
594 % BEGIN
595 % if empty$(s) then return ""
596 % else return "{\em " * s * "}"
597 %
598 % The format.names function formats the argument (which should be in
599 % BibTeX name format) into "First Von Last, Junior", separated by commas
600 % and with an "and" before the last (but ending with "et~al." if the last
601 % of multiple authors is "others"). This function's argument should always
602 % contain at least one name.
603 %
604 % VAR: nameptr, namesleft, numnames: INTEGER
605 % pseudoVAR: nameresult: STRING (it's what's accumulated on the stack)
606 %
607 % format.names(s) ==
608 % BEGIN
609 % nameptr := 1
610 % numnames := num.names$(s)
611 % namesleft := numnames
612 % while namesleft > 0
613 % do
614 % % for full names:
615 % t := format.name$(s, nameptr, "{ff~}{vv~}{ll}{, jj}")
616 % % for abbreviated first names:
617 % t := format.name$(s, nameptr, "{f.~}{vv~}{ll}{, jj}")
618 % if nameptr > 1 then
619 % if namesleft > 1 then nameresult := nameresult * ", " * t
620 % else if numnames > 2
621 % then nameresult := nameresult * ","
622 % fi
623 % if t = "others"
624 % then nameresult := nameresult * " et~al."
625 % else nameresult := nameresult * " and " * t
626 % fi
627 % fi
628 % else nameresult := t
629 % fi
630 % nameptr := nameptr + 1
631 % namesleft := namesleft - 1
632 % od
633 % return nameresult
634 % END
635 %
636 % The format.authors function returns the result of format.names(author)
637 % if the author is present, or else it returns the null string
638 %
639 % format.authors ==
640 % BEGIN
641 % if empty$(author) then return ""
642 % else return format.names(author)
643 % fi
644 % END
645 %
646 % Format.editors is like format.authors, but it uses the editor field,
647 % and appends ", editor" or ", editors"
648 %
649 % format.editors ==
650 % BEGIN
651 % if empty$(editor) then return ""
652 % else
653 % if num.names$(editor) > 1 then
654 % return format.names(editor) * ", editors"
655 % else
656 % return format.names(editor) * ", editor"
657 % fi
658 % fi
659 % END
660 %
661 % Other formatting functions are similar, so no "comment version" will be
662 % given for them.
663 %
664 % The `pop$' in this function gets rid of the duplicate `empty' value and
665 % the `skip$' returns the duplicate field value
666
667 FUNCTION {field.or.null}
668 { duplicate$ empty$
669 { pop$ "" }
670 'skip$
671 if$
672 }
673
674 FUNCTION {emphasize}
675 { duplicate$ empty$
676 { pop$ "" }
677 { "{\em " swap$ * "}" * }
678 if$
679 }
680
681 INTEGERS { nameptr namesleft numnames }
682
683 FUNCTION {format.names}
684 { 's :=
685 #1 'nameptr :=
686 s num.names$ 'numnames :=
687 numnames 'namesleft :=
688 { namesleft #0 > }
689 #if NAME_FULL
690 { s nameptr "{ff~}{vv~}{ll}{, jj}" format.name$ 't :=
691 #else
692 { s nameptr "{f.~}{vv~}{ll}{, jj}" format.name$ 't :=
693 #endif NAME_FULL
694 nameptr #1 >
695 { namesleft #1 >
696 { ", " * t * }
697 { numnames #2 >
698 { "," * }
699 'skip$
700 if$
701 t "others" =
702 { " et~al." * }
703 { " and " * t * }
704 if$
705 }
706 if$
707 }
708 't
709 if$
710 nameptr #1 + 'nameptr :=
711 namesleft #1 - 'namesleft :=
712 }
713 while$
714 }
715
716 FUNCTION {format.authors}
717 { author empty$
718 { "" }
719 { author format.names }
720 if$
721 }
722
723 FUNCTION {format.editors}
724 { editor empty$
725 { "" }
726 { editor format.names
727 editor num.names$ #1 >
728 { ", editors" * }
729 { ", editor" * }
730 if$
731 }
732 if$
733 }
734
735 % The format.title function is used for non-book-like titles.
736 % For most styles we convert to lowercase (except for the very first letter,
737 % and except for the first one after a colon (followed by whitespace)),
738 % and hope the user has brace-surrounded words that need to stay capitilized;
739 % for some styles, however, we leave it as it is in the database.
740
741 FUNCTION {format.title}
742 { title empty$
743 { "" }
744 #if ATIT_LOWER
745 { title "t" change.case$ }
746 #else
747 'title
748 #endif ATIT_LOWER
749 if$
750 }
751
752 % By default, BibTeX sets the global integer variable global.max$ to the BibTeX
753 % constant glob_str_size, the maximum length of a global string variable.
754 % Analogously, BibTeX sets the global integer variable entry.max$ to
755 % ent_str_size, the maximum length of an entry string variable.
756 % The style designer may change these if necessary (but this is unlikely)
757
758 % The n.dashify function makes each single `-' in a string a double `--'
759 % if it's not already
760 %
761 % pseudoVAR: pageresult: STRING (it's what's accumulated on the stack)
762 %
763 % n.dashify(s) ==
764 % BEGIN
765 % t := s
766 % pageresult := ""
767 % while (not empty$(t))
768 % do
769 % if (first character of t = "-")
770 % then
771 % if (next character isn't)
772 % then
773 % pageresult := pageresult * "--"
774 % t := t with the "-" removed
775 % else
776 % while (first character of t = "-")
777 % do
778 % pageresult := pageresult * "-"
779 % t := t with the "-" removed
780 % od
781 % fi
782 % else
783 % pageresult := pageresult * the first character
784 % t := t with the first character removed
785 % fi
786 % od
787 % return pageresult
788 % END
789
790 FUNCTION {n.dashify}
791 { 't :=
792 ""
793 { t empty$ not }
794 { t #1 #1 substring$ "-" =
795 { t #1 #2 substring$ "--" = not
796 { "--" *
797 t #2 global.max$ substring$ 't :=
798 }
799 { { t #1 #1 substring$ "-" = }
800 { "-" *
801 t #2 global.max$ substring$ 't :=
802 }
803 while$
804 }
805 if$
806 }
807 { t #1 #1 substring$ *
808 t #2 global.max$ substring$ 't :=
809 }
810 if$
811 }
812 while$
813 }
814
815 % The format.date function is for the month and year, but we give a warning if
816 % there's an empty year but the month is there, and we return the empty string
817 % if they're both empty.
818
819 FUNCTION {format.date}
820 { year empty$
821 { month empty$
822 { "" }
823 { "there's a month but no year in " cite$ * warning$
824 month
825 }
826 if$
827 }
828 { month empty$
829 'year
830 { month " " * year * }
831 if$
832 }
833 if$
834 }
835
836 % The format.btitle is for formatting the title field when it is a book-like
837 % entry---the style used here keeps it in uppers-and-lowers and emphasizes it.
838
839 FUNCTION {format.btitle}
840 { title emphasize
841 }
842
843 % For several functions we'll need to connect two strings with a
844 % tie (~) if the second one isn't very long (fewer than 3 characters).
845 % The tie.or.space.connect function does that. It concatenates the two
846 % strings on top of the stack, along with either a tie or space between
847 % them, and puts this concatenation back onto the stack:
848 %
849 % tie.or.space.connect(str1,str2) ==
850 % BEGIN
851 % if text.length$(str2) < 3
852 % then return the concatenation of str1, "~", and str2
853 % else return the concatenation of str1, " ", and str2
854 % END
855
856 FUNCTION {tie.or.space.connect}
857 { duplicate$ text.length$ #3 <
858 { "~" }
859 { " " }
860 if$
861 swap$ * *
862 }
863
864 % The either.or.check function complains if both fields or an either-or pair
865 % are nonempty.
866 %
867 % either.or.check(t,s) ==
868 % BEGIN
869 % if empty$(s) then
870 % warning$(can't use both " * t * " fields in " * cite$)
871 % fi
872 % END
873
874 FUNCTION {either.or.check}
875 { empty$
876 'pop$
877 { "can't use both " swap$ * " fields in " * cite$ * warning$ }
878 if$
879 }
880
881 % The format.bvolume function is for formatting the volume and perhaps
882 % series name of a multivolume work. If both a volume and a series field
883 % are there, we assume the series field is the title of the whole multivolume
884 % work (the title field should be the title of the thing being referred to),
885 % and we add an "of <series>". This function is called in mid-sentence.
886
887 FUNCTION {format.bvolume}
888 { volume empty$
889 { "" }
890 { "volume" volume tie.or.space.connect
891 series empty$
892 'skip$
893 { " of " * series emphasize * }
894 if$
895 "volume and number" number either.or.check
896 }
897 if$
898 }
899
900 % The format.number.series function is for formatting the series name
901 % and perhaps number of a work in a series. This function is similar to
902 % format.bvolume, although for this one the series must exist (and the
903 % volume must not exist). If the number field is empty we output either
904 % the series field unchanged if it exists or else the null string.
905 % If both the number and series fields are there we assume the series field
906 % gives the name of the whole series (the title field should be the title
907 % of the work being one referred to), and we add an "in <series>".
908 % We capitilize Number when this function is used at the beginning of a block.
909
910 FUNCTION {format.number.series}
911 { volume empty$
912 { number empty$
913 { series field.or.null }
914 { output.state mid.sentence =
915 { "number" }
916 { "Number" }
917 if$
918 number tie.or.space.connect
919 series empty$
920 { "there's a number but no series in " cite$ * warning$ }
921 { " in " * series * }
922 if$
923 }
924 if$
925 }
926 { "" }
927 if$
928 }
929
930 % The format.edition function appends " edition" to the edition, if present.
931 % We lowercase the edition (it should be something like "Third"), because
932 % this doesn't start a sentence.
933
934 FUNCTION {format.edition}
935 { edition empty$
936 { "" }
937 { output.state mid.sentence =
938 { edition "l" change.case$ " edition" * }
939 { edition "t" change.case$ " edition" * }
940 if$
941 }
942 if$
943 }
944
945 % The format.pages function is used for formatting a page range in a book
946 % (and in rare circumstances, an article).
947 %
948 % The multi.page.check function examines the page field for a "-" or "," or "+"
949 % so that format.pages can use "page" instead of "pages" if none exists.
950 % Note: global.max$ here means "take the rest of the string"
951 %
952 % VAR: multiresult: INTEGER (actually, a boolean)
953 %
954 % multi.page.check(s) ==
955 % BEGIN
956 % t := s
957 % multiresult := false
958 % while ((not multiresult) and (not empty$(t)))
959 % do
960 % if (first character of t = "-" or "," or "+")
961 % then multiresult := true
962 % else t := t with the first character removed
963 % fi
964 % od
965 % return multiresult
966 % END
967
968 INTEGERS { multiresult }
969
970 FUNCTION {multi.page.check}
971 { 't :=
972 #0 'multiresult :=
973 { multiresult not
974 t empty$ not
975 and
976 }
977 { t #1 #1 substring$
978 duplicate$ "-" =
979 swap$ duplicate$ "," =
980 swap$ "+" =
981 or or
982 { #1 'multiresult := }
983 { t #2 global.max$ substring$ 't := }
984 if$
985 }
986 while$
987 multiresult
988 }
989
990 % This function doesn't begin a sentence so "pages" isn't capitalized.
991 % Other functions that use this should keep that in mind.
992
993 FUNCTION {format.pages}
994 { pages empty$
995 { "" }
996 { pages multi.page.check
997 { "pages" pages n.dashify tie.or.space.connect }
998 { "page" pages tie.or.space.connect }
999 if$
1000 }
1001 if$
1002 }
1003
1004 % The format.vol.num.pages function is for the volume, number, and page range
1005 % of a journal article. We use the format: vol(number):pages, with some
1006 % variations for empty fields. This doesn't begin a sentence.
1007
1008 FUNCTION {format.vol.num.pages}
1009 { volume field.or.null
1010 number empty$
1011 'skip$
1012 { "(" number * ")" * *
1013 volume empty$
1014 { "there's a number but no volume in " cite$ * warning$ }
1015 'skip$
1016 if$
1017 }
1018 if$
1019 pages empty$
1020 'skip$
1021 { duplicate$ empty$
1022 { pop$ format.pages }
1023 { ":" * pages n.dashify * }
1024 if$
1025 }
1026 if$
1027 }
1028
1029
1030 % The format.chapter.pages, if the chapter is present, puts whatever is in the
1031 % type field (or else "chapter" if type is empty) in front of a chapter number.
1032 % It then appends the pages, if present. This doesn't begin a sentence.
1033
1034 FUNCTION {format.chapter.pages}
1035 { chapter empty$
1036 'format.pages
1037 { type empty$
1038 { "chapter" }
1039 { type "l" change.case$ }
1040 if$
1041 chapter tie.or.space.connect
1042 pages empty$
1043 'skip$
1044 { ", " * format.pages * }
1045 if$
1046 }
1047 if$
1048 }
1049
1050 % The format.in.ed.booktitle function is used for starting out a sentence
1051 % that begins "In <booktitle>", putting an editor before the title if one
1052 % exists.
1053
1054 FUNCTION {format.in.ed.booktitle}
1055 { booktitle empty$
1056 { "" }
1057 { editor empty$
1058 { "In " booktitle emphasize * }
1059 { "In " format.editors * ", " * booktitle emphasize * }
1060 if$
1061 }
1062 if$
1063 }
1064
1065 % The function empty.misc.check complains if all six fields are empty, and
1066 % if there's been no sorting or alphabetic-label complaint.
1067
1068 FUNCTION {empty.misc.check}
1069 { author empty$ title empty$ howpublished empty$
1070 month empty$ year empty$ note empty$
1071 and and and and and
1072 #if SORTED
1073 key empty$ not and
1074 #else !SORTED
1075 #if LAB_ALPH
1076 key empty$ not and
1077 #endif LAB_ALPH
1078 #endif SORTED
1079 { "all relevant fields are empty in " cite$ * warning$ }
1080 'skip$
1081 if$
1082 }
1083
1084 % The function format.thesis.type returns either the (case-changed) type field,
1085 % if it is defined, or else the default string already on the stack
1086 % (like "Master's thesis" or "PhD thesis").
1087
1088 FUNCTION {format.thesis.type}
1089 { type empty$
1090 'skip$
1091 { pop$
1092 type "t" change.case$
1093 }
1094 if$
1095 }
1096
1097 % The function format.tr.number makes a string starting with "Technical Report"
1098 % (or type, if that field is defined), followed by the number if there is one;
1099 % it returns the starting part (with a case change) even if there is no number.
1100 % This is used at the beginning of a sentence.
1101
1102 FUNCTION {format.tr.number}
1103 { type empty$
1104 { "Technical Report" }
1105 'type
1106 if$
1107 number empty$
1108 { "t" change.case$ }
1109 { number tie.or.space.connect }
1110 if$
1111 }
1112
1113 % Now come the cross-referencing functions (these are invoked because
1114 % one entry in the database file(s) cross-references another, by giving
1115 % the other entry's database key in a `crossref' field). This feature
1116 % allows one or more titled things that are part of a larger titled
1117 % thing to cross-reference the larger thing. These styles allow for
1118 % five posibilities: (1) an ARTICLE may cross-reference an ARTICLE;
1119 % (2) a BOOK, (3) INBOOK, or (4) INCOLLECTION may cross-reference a BOOK;
1120 % or (5) an INPROCEEDINGS may cross-reference a PROCEEDINGS.
1121 % Each of these is explained in more detail later.
1122 %
1123 % An ARTICLE entry type may cross reference another ARTICLE (this is
1124 % intended for when an entire journal is devoted to a single topic---
1125 % but since there is no JOURNAL entry type, the journal, too, should be
1126 % classified as an ARTICLE but without the author and title fields).
1127 % This will result in two warning messages for the journal's entry
1128 % if it's included in the reference list, but such is life.
1129 %
1130 % format.article.crossref ==
1131 % BEGIN
1132 % if empty$(key) then
1133 % if empty$(journal) then
1134 % warning$("need key or journal for " * cite$ *
1135 % " to crossref " * crossref)
1136 % return(" \cite{" * crossref * "}")
1137 % else
1138 % return("In " * emphazise.correct (journal) *
1139 % " \cite{" * crossref * "}")
1140 % fi
1141 % else
1142 % return("In " * key * " \cite{" * crossref * "}")
1143 % fi
1144 % END
1145 %
1146 % The other cross-referencing functions are similar, so no "comment version"
1147 % will be given for them.
1148
1149 FUNCTION {format.article.crossref}
1150 { key empty$
1151 { journal empty$
1152 { "need key or journal for " cite$ * " to crossref " * crossref *
1153 warning$
1154 ""
1155 }
1156 { "In {\em " journal * "\/}" * }
1157 if$
1158 }
1159 { "In " key * }
1160 if$
1161 " \cite{" * crossref * "}" *
1162 }
1163
1164 % We use just the last names of editors for a cross reference: either
1165 % "editor", or "editor1 and editor2", or "editor1 et~al." depending on
1166 % whether there are one, or two, or more than two editors.
1167
1168 FUNCTION {format.crossref.editor}
1169 { editor #1 "{vv~}{ll}" format.name$
1170 editor num.names$ duplicate$
1171 #2 >
1172 { pop$ " et~al." * }
1173 { #2 <
1174 'skip$
1175 { editor #2 "{ff }{vv }{ll}{ jj}" format.name$ "others" =
1176 { " et~al." * }
1177 { " and " * editor #2 "{vv~}{ll}" format.name$ * }
1178 if$
1179 }
1180 if$
1181 }
1182 if$
1183 }
1184
1185 % A BOOK (or INBOOK) entry type (assumed to be for a single volume in a
1186 % multivolume work) may cross reference another BOOK (the entire multivolume).
1187 % Usually there will be an editor, in which case we use that to construct the
1188 % cross reference; otherwise we use a nonempty key field or else the series
1189 % field (since the series gives the title of the multivolume work).
1190
1191 FUNCTION {format.book.crossref}
1192 { volume empty$
1193 { "empty volume in " cite$ * "'s crossref of " * crossref * warning$
1194 "In "
1195 }
1196 { "Volume" volume tie.or.space.connect
1197 " of " *
1198 }
1199 if$
1200 editor empty$
1201 editor field.or.null author field.or.null =
1202 or
1203 { key empty$
1204 { series empty$
1205 { "need editor, key, or series for " cite$ * " to crossref " *
1206 crossref * warning$
1207 "" *
1208 }
1209 { "{\em " * series * "\/}" * }
1210 if$
1211 }
1212 { key * }
1213 if$
1214 }
1215 { format.crossref.editor * }
1216 if$
1217 " \cite{" * crossref * "}" *
1218 }
1219
1220 % An INCOLLECTION entry type may cross reference a BOOK (assumed to be the
1221 % collection), or an INPROCEEDINGS may cross reference a PROCEEDINGS.
1222 % Often there will be an editor, in which case we use that to construct
1223 % the cross reference; otherwise we use a nonempty key field or else
1224 % the booktitle field (which gives the cross-referenced work's title).
1225
1226 FUNCTION {format.incoll.inproc.crossref}
1227 { editor empty$
1228 editor field.or.null author field.or.null =
1229 or
1230 { key empty$
1231 { booktitle empty$
1232 { "need editor, key, or booktitle for " cite$ * " to crossref " *
1233 crossref * warning$
1234 ""
1235 }
1236 { "In {\em " booktitle * "\/}" * }
1237 if$
1238 }
1239 { "In " key * }
1240 if$
1241 }
1242 { "In " format.crossref.editor * }
1243 if$
1244 " \cite{" * crossref * "}" *
1245 }
1246
1247 % Now we define the type functions for all entry types that may appear
1248 % in the .BIB file---e.g., functions like `article' and `book'. These
1249 % are the routines that actually generate the .BBL-file output for
1250 % the entry. These must all precede the READ command. In addition, the
1251 % style designer should have a function `default.type' for unknown types.
1252 % Note: The fields (within each list) are listed in order of appearance,
1253 % except as described for an `inbook' or a `proceedings'.
1254 %
1255 % The article function is for an article in a journal. An article may
1256 % CROSSREF another article.
1257 % Required fields: author, title, journal, year
1258 % Optional fields: volume, number, pages, month, note
1259 %
1260 % article ==
1261 % BEGIN
1262 % output.bibitem
1263 % output.check(format.authors,"author")
1264 % new.block
1265 % output.check(format.title,"title")
1266 % new.block
1267 % if missing$(crossref) then
1268 % output.check(emphasize(journal),"journal")
1269 % output(format.vol.num.pages)
1270 % output.check(format.date,"year")
1271 % else
1272 % output.nonnull(format.article.crossref)
1273 % output(format.pages)
1274 % fi
1275 % new.block
1276 % output(note)
1277 % fin.entry
1278 % END
1279 %
1280 % The book function is for a whole book. A book may CROSSREF another book.
1281 % Required fields: author or editor, title, publisher, year
1282 % Optional fields: volume or number, series, address, edition, month,
1283 % note
1284 %
1285 % book ==
1286 % BEGIN
1287 % if empty$(author) then output.check(format.editors,"author and editor")
1288 % else output.check(format.authors,"author")
1289 % if missing$(crossref) then
1290 % either.or.check("author and editor",editor)
1291 % fi
1292 % fi
1293 % new.block
1294 % output.check(format.btitle,"title")
1295 % if missing$(crossref) then
1296 % output(format.bvolume)
1297 % new.block
1298 % output(format.number.series)
1299 % new.sentence
1300 % output.check(publisher,"publisher")
1301 % output(address)
1302 % else
1303 % new.block
1304 % output.nonnull(format.book.crossref)
1305 % fi
1306 % output(format.edition)
1307 % output.check(format.date,"year")
1308 % new.block
1309 % output(note)
1310 % fin.entry
1311 % END
1312 %
1313 % The other entry functions are all quite similar, so no "comment version"
1314 % will be given for them.
1315
1316 FUNCTION {article}
1317 { output.bibitem
1318 format.authors "author" output.check
1319 new.block
1320 format.title "title" output.check
1321 new.block
1322 crossref missing$
1323 { journal emphasize "journal" output.check
1324 format.vol.num.pages output
1325 format.date "year" output.check
1326 }
1327 { format.article.crossref output.nonnull
1328 format.pages output
1329 }
1330 if$
1331 new.block
1332 note output
1333 fin.entry
1334 }
1335
1336 FUNCTION {book}
1337 { output.bibitem
1338 author empty$
1339 { format.editors "author and editor" output.check }
1340 { format.authors output.nonnull
1341 crossref missing$
1342 { "author and editor" editor either.or.check }
1343 'skip$
1344 if$
1345 }
1346 if$
1347 new.block
1348 format.btitle "title" output.check
1349 crossref missing$
1350 { format.bvolume output
1351 new.block
1352 format.number.series output
1353 new.sentence
1354 publisher "publisher" output.check
1355 address output
1356 }
1357 { new.block
1358 format.book.crossref output.nonnull
1359 }
1360 if$
1361 format.edition output
1362 format.date "year" output.check
1363 new.block
1364 note output
1365 fin.entry
1366 }
1367
1368 % A booklet is a bound thing without a publisher or sponsoring institution.
1369 % Required: title
1370 % Optional: author, howpublished, address, month, year, note
1371
1372 FUNCTION {booklet}
1373 { output.bibitem
1374 format.authors output
1375 new.block
1376 format.title "title" output.check
1377 howpublished address new.block.checkb
1378 howpublished output
1379 address output
1380 format.date output
1381 new.block
1382 note output
1383 fin.entry
1384 }
1385
1386 % For the conference entry type, see inproceedings.
1387
1388 % An inbook is a piece of a book: either a chapter and/or a page range.
1389 % It may CROSSREF a book. If there's no volume field, the type field
1390 % will come before number and series.
1391 % Required: author or editor, title, chapter and/or pages, publisher,year
1392 % Optional: volume or number, series, type, address, edition, month, note
1393
1394 FUNCTION {inbook}
1395 { output.bibitem
1396 author empty$
1397 { format.editors "author and editor" output.check }
1398 { format.authors output.nonnull
1399 crossref missing$
1400 { "author and editor" editor either.or.check }
1401 'skip$
1402 if$
1403 }
1404 if$
1405 new.block
1406 format.btitle "title" output.check
1407 crossref missing$
1408 { format.bvolume output
1409 format.chapter.pages "chapter and pages" output.check
1410 new.block
1411 format.number.series output
1412 new.sentence
1413 publisher "publisher" output.check
1414 address output
1415 }
1416 { format.chapter.pages "chapter and pages" output.check
1417 new.block
1418 format.book.crossref output.nonnull
1419 }
1420 if$
1421 format.edition output
1422 format.date "year" output.check
1423 new.block
1424 note output
1425 fin.entry
1426 }
1427
1428 % An incollection is like inbook, but where there is a separate title
1429 % for the referenced thing (and perhaps an editor for the whole).
1430 % An incollection may CROSSREF a book.
1431 % Required: author, title, booktitle, publisher, year
1432 % Optional: editor, volume or number, series, type, chapter, pages,
1433 % address, edition, month, note
1434
1435 FUNCTION {incollection}
1436 { output.bibitem
1437 format.authors "author" output.check
1438 new.block
1439 format.title "title" output.check
1440 new.block
1441 crossref missing$
1442 { format.in.ed.booktitle "booktitle" output.check
1443 format.bvolume output
1444 format.number.series output
1445 format.chapter.pages output
1446 new.sentence
1447 publisher "publisher" output.check
1448 address output
1449 format.edition output
1450 format.date "year" output.check
1451 }
1452 { format.incoll.inproc.crossref output.nonnull
1453 format.chapter.pages output
1454 }
1455 if$
1456 new.block
1457 note output
1458 fin.entry
1459 }
1460
1461 % An inproceedings is an article in a conference proceedings, and it may
1462 % CROSSREF a proceedings. If there's no address field, the month (& year)
1463 % will appear just before note.
1464 % Required: author, title, booktitle, year
1465 % Optional: editor, volume or number, series, pages, address, month,
1466 % organization, publisher, note
1467
1468 FUNCTION {inproceedings}
1469 { output.bibitem
1470 format.authors "author" output.check
1471 new.block
1472 format.title "title" output.check
1473 new.block
1474 crossref missing$
1475 { format.in.ed.booktitle "booktitle" output.check
1476 format.bvolume output
1477 format.number.series output
1478 format.pages output
1479 address empty$
1480 { organization publisher new.sentence.checkb
1481 organization output
1482 publisher output
1483 format.date "year" output.check
1484 }
1485 { address output.nonnull
1486 format.date "year" output.check
1487 new.sentence
1488 organization output
1489 publisher output
1490 }
1491 if$
1492 }
1493 { format.incoll.inproc.crossref output.nonnull
1494 format.pages output
1495 }
1496 if$
1497 new.block
1498 note output
1499 fin.entry
1500 }
1501
1502 % The conference function is included for Scribe compatibility.
1503
1504 FUNCTION {conference} { inproceedings }
1505
1506 % A manual is technical documentation.
1507 % Required: title
1508 % Optional: author, organization, address, edition, month, year, note
1509
1510 FUNCTION {manual}
1511 { output.bibitem
1512 author empty$
1513 { organization empty$
1514 'skip$
1515 { organization output.nonnull
1516 address output
1517 }
1518 if$
1519 }
1520 { format.authors output.nonnull }
1521 if$
1522 new.block
1523 format.btitle "title" output.check
1524 author empty$
1525 { organization empty$
1526 { address new.block.checka
1527 address output
1528 }
1529 'skip$
1530 if$
1531 }
1532 { organization address new.block.checkb
1533 organization output
1534 address output
1535 }
1536 if$
1537 format.edition output
1538 format.date output
1539 new.block
1540 note output
1541 fin.entry
1542 }
1543
1544 % A mastersthesis is a Master's thesis.
1545 % Required: author, title, school, year
1546 % Optional: type, address, month, note
1547
1548 FUNCTION {mastersthesis}
1549 { output.bibitem
1550 format.authors "author" output.check
1551 new.block
1552 format.title "title" output.check
1553 new.block
1554 "Master's thesis" format.thesis.type output.nonnull
1555 school "school" output.check
1556 address output
1557 format.date "year" output.check
1558 new.block
1559 note output
1560 fin.entry
1561 }
1562
1563 % A misc is something that doesn't fit elsewhere.
1564 % Required: at least one of the `optional' fields
1565 % Optional: author, title, howpublished, month, year, note
1566
1567 FUNCTION {misc}
1568 { output.bibitem
1569 format.authors output
1570 title howpublished new.block.checkb
1571 format.title output
1572 howpublished new.block.checka
1573 howpublished output
1574 format.date output
1575 new.block
1576 note output
1577 fin.entry
1578 empty.misc.check
1579 }
1580
1581 % A phdthesis is like a mastersthesis.
1582 % Required: author, title, school, year
1583 % Optional: type, address, month, note
1584
1585 FUNCTION {phdthesis}
1586 { output.bibitem
1587 format.authors "author" output.check
1588 new.block
1589 format.btitle "title" output.check
1590 new.block
1591 "PhD thesis" format.thesis.type output.nonnull
1592 school "school" output.check
1593 address output
1594 format.date "year" output.check
1595 new.block
1596 note output
1597 fin.entry
1598 }
1599
1600 % A proceedings is a conference proceedings.
1601 % If there is an organization but no editor field, the organization will
1602 % appear as the first optional field (we try to make the first block nonempty);
1603 % if there's no address field, the month (& year) will appear just before note.
1604 % Required: title, year
1605 % Optional: editor, volume or number, series, address, month,
1606 % organization, publisher, note
1607
1608 FUNCTION {proceedings}
1609 { output.bibitem
1610 editor empty$
1611 { organization output }
1612 { format.editors output.nonnull }
1613 if$
1614 new.block
1615 format.btitle "title" output.check
1616 format.bvolume output
1617 format.number.series output
1618 address empty$
1619 { editor empty$
1620 { publisher new.sentence.checka }
1621 { organization publisher new.sentence.checkb
1622 organization output
1623 }
1624 if$
1625 publisher output
1626 format.date "year" output.check
1627 }
1628 { address output.nonnull
1629 format.date "year" output.check
1630 new.sentence
1631 editor empty$
1632 'skip$
1633 { organization output }
1634 if$
1635 publisher output
1636 }
1637 if$
1638 new.block
1639 note output
1640 fin.entry
1641 }
1642
1643 % A techreport is a technical report.
1644 % Required: author, title, institution, year
1645 % Optional: type, number, address, month, note
1646
1647 FUNCTION {techreport}
1648 { output.bibitem
1649 format.authors "author" output.check
1650 new.block
1651 format.title "title" output.check
1652 new.block
1653 format.tr.number output.nonnull
1654 institution "institution" output.check
1655 address output
1656 format.date "year" output.check
1657 new.block
1658 note output
1659 fin.entry
1660 }
1661
1662 % An unpublished is something that hasn't been published.
1663 % Required: author, title, note
1664 % Optional: month, year
1665
1666 FUNCTION {unpublished}
1667 { output.bibitem
1668 format.authors "author" output.check
1669 new.block
1670 format.title "title" output.check
1671 new.block
1672 note "note" output.check
1673 format.date output
1674 fin.entry
1675 }
1676
1677 % We use entry type `misc' for an unknown type; BibTeX gives a warning.
1678
1679 FUNCTION {default.type} { misc }
1680
1681 % Here are macros for common things that may vary from style to style.
1682 % Users are encouraged to use these macros.
1683 %
1684 % Months are either written out in full or abbreviated
1685
1686 #if MONTH_FULL
1687
1688 MACRO {jan} {"January"}
1689
1690 MACRO {feb} {"February"}
1691
1692 MACRO {mar} {"March"}
1693
1694 MACRO {apr} {"April"}
1695
1696 MACRO {may} {"May"}
1697
1698 MACRO {jun} {"June"}
1699
1700 MACRO {jul} {"July"}
1701
1702 MACRO {aug} {"August"}
1703
1704 MACRO {sep} {"September"}
1705
1706 MACRO {oct} {"October"}
1707
1708 MACRO {nov} {"November"}
1709
1710 MACRO {dec} {"December"}
1711
1712 #else !MONTH_FULL
1713
1714 MACRO {jan} {"Jan."}
1715
1716 MACRO {feb} {"Feb."}
1717
1718 MACRO {mar} {"Mar."}
1719
1720 MACRO {apr} {"Apr."}
1721
1722 MACRO {may} {"May"}
1723
1724 MACRO {jun} {"June"}
1725
1726 MACRO {jul} {"July"}
1727
1728 MACRO {aug} {"Aug."}
1729
1730 MACRO {sep} {"Sept."}
1731
1732 MACRO {oct} {"Oct."}
1733
1734 MACRO {nov} {"Nov."}
1735
1736 MACRO {dec} {"Dec."}
1737
1738 #endif MONTH_FULL
1739
1740 % Journals are either written out in full or abbreviated;
1741 % the abbreviations are like those found in ACM publications.
1742 %
1743 % To get a completely different set of abbreviations, it may be best to make
1744 % a separate .bib file with nothing but those abbreviations; users could then
1745 % include that file name as the first argument to the \bibliography command
1746
1747 #if JOUR_FULL
1748
1749 MACRO {acmcs} {"ACM Computing Surveys"}
1750
1751 MACRO {acta} {"Acta Informatica"}
1752
1753 MACRO {cacm} {"Communications of the ACM"}
1754
1755 MACRO {ibmjrd} {"IBM Journal of Research and Development"}
1756
1757 MACRO {ibmsj} {"IBM Systems Journal"}
1758
1759 MACRO {ieeese} {"IEEE Transactions on Software Engineering"}
1760
1761 MACRO {ieeetc} {"IEEE Transactions on Computers"}
1762
1763 MACRO {ieeetcad}
1764 {"IEEE Transactions on Computer-Aided Design of Integrated Circuits"}
1765
1766 MACRO {ipl} {"Information Processing Letters"}
1767
1768 MACRO {jacm} {"Journal of the ACM"}
1769
1770 MACRO {jcss} {"Journal of Computer and System Sciences"}
1771
1772 MACRO {scp} {"Science of Computer Programming"}
1773
1774 MACRO {sicomp} {"SIAM Journal on Computing"}
1775
1776 MACRO {tocs} {"ACM Transactions on Computer Systems"}
1777
1778 MACRO {tods} {"ACM Transactions on Database Systems"}
1779
1780 MACRO {tog} {"ACM Transactions on Graphics"}
1781
1782 MACRO {toms} {"ACM Transactions on Mathematical Software"}
1783
1784 MACRO {toois} {"ACM Transactions on Office Information Systems"}
1785
1786 MACRO {toplas} {"ACM Transactions on Programming Languages and Systems"}
1787
1788 MACRO {tcs} {"Theoretical Computer Science"}
1789
1790 #else !JOUR_FULL
1791
1792 MACRO {acmcs} {"ACM Comput. Surv."}
1793
1794 MACRO {acta} {"Acta Inf."}
1795
1796 MACRO {cacm} {"Commun. ACM"}
1797
1798 MACRO {ibmjrd} {"IBM J. Res. Dev."}
1799
1800 MACRO {ibmsj} {"IBM Syst.~J."}
1801
1802 MACRO {ieeese} {"IEEE Trans. Softw. Eng."}
1803
1804 MACRO {ieeetc} {"IEEE Trans. Comput."}
1805
1806 MACRO {ieeetcad}
1807 {"IEEE Trans. Comput.-Aided Design Integrated Circuits"}
1808
1809 MACRO {ipl} {"Inf. Process. Lett."}
1810
1811 MACRO {jacm} {"J.~ACM"}
1812
1813 MACRO {jcss} {"J.~Comput. Syst. Sci."}
1814
1815 MACRO {scp} {"Sci. Comput. Programming"}
1816
1817 MACRO {sicomp} {"SIAM J. Comput."}
1818
1819 MACRO {tocs} {"ACM Trans. Comput. Syst."}
1820
1821 MACRO {tods} {"ACM Trans. Database Syst."}
1822
1823 MACRO {tog} {"ACM Trans. Gr."}
1824
1825 MACRO {toms} {"ACM Trans. Math. Softw."}
1826
1827 MACRO {toois} {"ACM Trans. Office Inf. Syst."}
1828
1829 MACRO {toplas} {"ACM Trans. Prog. Lang. Syst."}
1830
1831 MACRO {tcs} {"Theoretical Comput. Sci."}
1832
1833 #endif JOUR_FULL
1834
1835 % Now we read in the .BIB entries.
1836
1837 READ
1838
1839 % The sortify function converts to lower case after purify$ing; it's
1840 % used in sorting and in computing alphabetic labels after sorting
1841 %
1842 % The chop.word(w,len,s) function returns either s or, if the first len
1843 % letters of s equals w (this comparison is done in the third line of the
1844 % function's definition), it returns that part of s after w.
1845
1846 #if SORTED
1847
1848 FUNCTION {sortify}
1849 { purify$
1850 "l" change.case$
1851 }
1852
1853 INTEGERS { len }
1854
1855 FUNCTION {chop.word}
1856 { 's :=
1857 'len :=
1858 s #1 len substring$ =
1859 { s len #1 + global.max$ substring$ }
1860 's
1861 if$
1862 }
1863
1864 #else !SORTED
1865 #if LAB_ALPH
1866
1867 % We need the chop.word stuff for the dubious unsorted-list-with-labels case.
1868
1869 INTEGERS { len }
1870
1871 FUNCTION {chop.word}
1872 { 's :=
1873 'len :=
1874 s #1 len substring$ =
1875 { s len #1 + global.max$ substring$ }
1876 's
1877 if$
1878 }
1879
1880 #endif LAB_ALPH
1881 #endif SORTED
1882
1883 % This long comment applies only to alphabetic labels
1884 %
1885 % The format.lab.names function makes a short label by using the initials of
1886 % the von and Last parts of the names (but if there are more than four names,
1887 % (i.e., people) it truncates after three and adds a superscripted "+";
1888 % it also adds such a "+" if the last of multiple authors is "others").
1889 % If there is only one name, and its von and Last parts combined have just
1890 % a single name-token ("Knuth" has a single token, "Brinch Hansen" has two),
1891 % we take the first three letters of the last name. The boolean
1892 % et.al.char.used tells whether we've used a superscripted "+", so that we
1893 % know whether to include a LaTeX macro for it.
1894 %
1895 % format.lab.names(s) ==
1896 % BEGIN
1897 % numnames := num.names$(s)
1898 % if numnames > 1 then
1899 % if numnames > 4 then
1900 % namesleft := 3
1901 % else
1902 % namesleft := numnames
1903 % nameptr := 1
1904 % nameresult := ""
1905 % while namesleft > 0
1906 % do
1907 % if (name_ptr = numnames) and
1908 % format.name$(s, nameptr, "{ff }{vv }{ll}{ jj}") = "others"
1909 % then nameresult := nameresult * "{\etalchar{+}}"
1910 % et.al.char.used := true
1911 % else nameresult := nameresult *
1912 % format.name$(s, nameptr, "{v{}}{l{}}")
1913 % nameptr := nameptr + 1
1914 % namesleft := namesleft - 1
1915 % od
1916 % if numnames > 4 then
1917 % nameresult := nameresult * "{\etalchar{+}}"
1918 % et.al.char.used := true
1919 % else
1920 % t := format.name$(s, 1, "{v{}}{l{}}")
1921 % if text.length$(t) < 2 then % there's just one name-token
1922 % nameresult := text.prefix$(format.name$(s,1,"{ll}"),3)
1923 % else
1924 % nameresult := t
1925 % fi
1926 % fi
1927 % return nameresult
1928 % END
1929 %
1930 % Exactly what fields we look at in constructing the primary part of the label
1931 % depends on the entry type; this selectivity (as opposed to, say, always
1932 % looking at author, then editor, then key) helps ensure that "ignored" fields,
1933 % as described in the LaTeX book, really are ignored. Note that MISC is part
1934 % of the deepest `else' clause in the nested part of calc.label; thus, any
1935 % unrecognized entry type in the database is handled correctly.
1936 %
1937 % There is one auxiliary function for each of the four different sequences of
1938 % fields we use. The first of these functions looks at the author field, and
1939 % then, if necessary, the key field. The other three functions, which might
1940 % look at two fields and the key field, are similar, except that the key field
1941 % takes precedence over the organization field (for labels---not for sorting).
1942 %
1943 % The calc.label function calculates the preliminary label of an entry, which
1944 % is formed by taking three letters of information from the author or editor or
1945 % key or organization field (depending on the entry type and on what's empty,
1946 % but ignoring a leading "The " in the organization), and appending the last
1947 % two characters (digits) of the year. It is an error if the appropriate fields
1948 % among author, editor, organization, and key are missing, and we use
1949 % the first three letters of the cite$ in desperation when this happens.
1950 % The resulting label has the year part, but not the name part, purify$ed
1951 % (purify$ing the year allows some sorting shenanigans by the user).
1952 %
1953 % This function also calculates the version of the label to be used in sorting.
1954 %
1955 % The final label may need a trailing 'a', 'b', etc., to distinguish it from
1956 % otherwise identical labels, but we can't calculated those "extra.label"s
1957 % until after sorting.
1958 %
1959 % calc.label ==
1960 % BEGIN
1961 % if type$ = "book" or "inbook" then
1962 % author.editor.key.label
1963 % else if type$ = "proceedings" then
1964 % editor.key.organization.label
1965 % else if type$ = "manual" then
1966 % author.key.organization.label
1967 % else
1968 % author.key.label
1969 % fi fi fi
1970 % label := label * substring$(purify$(field.or.null(year)), -1, 2)
1971 % % assuming we will also sort, we calculate a sort.label
1972 % sort.label := sortify(label), but use the last four, not two, digits
1973 % END
1974
1975 #if LAB_ALPH
1976
1977 INTEGERS { et.al.char.used }
1978
1979 FUNCTION {initialize.et.al.char.used}
1980 { #0 'et.al.char.used :=
1981 }
1982
1983 EXECUTE {initialize.et.al.char.used}
1984
1985 FUNCTION {format.lab.names}
1986 { 's :=
1987 s num.names$ 'numnames :=
1988 numnames #1 >
1989 { numnames #4 >
1990 { #3 'namesleft := }
1991 { numnames 'namesleft := }
1992 if$
1993 #1 'nameptr :=
1994 ""
1995 { namesleft #0 > }
1996 { nameptr numnames =
1997 { s nameptr "{ff }{vv }{ll}{ jj}" format.name$ "others" =
1998 { "{\etalchar{+}}" *
1999 #1 'et.al.char.used :=
2000 }
2001 { s nameptr "{v{}}{l{}}" format.name$ * }
2002 if$
2003 }
2004 { s nameptr "{v{}}{l{}}" format.name$ * }
2005 if$
2006 nameptr #1 + 'nameptr :=
2007 namesleft #1 - 'namesleft :=
2008 }
2009 while$
2010 numnames #4 >
2011 { "{\etalchar{+}}" *
2012 #1 'et.al.char.used :=
2013 }
2014 'skip$
2015 if$
2016 }
2017 { s #1 "{v{}}{l{}}" format.name$
2018 duplicate$ text.length$ #2 <
2019 { pop$ s #1 "{ll}" format.name$ #3 text.prefix$ }
2020 'skip$
2021 if$
2022 }
2023 if$
2024 }
2025
2026 FUNCTION {author.key.label}
2027 { author empty$
2028 { key empty$
2029 #if SORTED
2030 { cite$ #1 #3 substring$ }
2031 #else !SORTED % need warning here because we won't give it later
2032 { "for label, need author or key in " cite$ * warning$
2033 cite$ #1 #3 substring$
2034 }
2035 #endif SORTED
2036 { key #3 text.prefix$ }
2037 if$
2038 }
2039 { author format.lab.names }
2040 if$
2041 }
2042
2043 FUNCTION {author.editor.key.label}
2044 { author empty$
2045 { editor empty$
2046 { key empty$
2047 #if SORTED
2048 { cite$ #1 #3 substring$ }
2049 #else !SORTED % need warning here because we won't give it later
2050 { "for label, need author, editor, or key in " cite$ * warning$
2051 cite$ #1 #3 substring$
2052 }
2053 #endif SORTED
2054 { key #3 text.prefix$ }
2055 if$
2056 }
2057 { editor format.lab.names }
2058 if$
2059 }
2060 { author format.lab.names }
2061 if$
2062 }
2063
2064 FUNCTION {author.key.organization.label}
2065 { author empty$
2066 { key empty$
2067 { organization empty$
2068 #if SORTED
2069 { cite$ #1 #3 substring$ }
2070 #else !SORTED % need warning here because we won't give it later
2071 { "for label, need author, key, or organization in " cite$ *
2072 warning$
2073 cite$ #1 #3 substring$
2074 }
2075 #endif SORTED
2076 { "The " #4 organization chop.word #3 text.prefix$ }
2077 if$
2078 }
2079 { key #3 text.prefix$ }
2080 if$
2081 }
2082 { author format.lab.names }
2083 if$
2084 }
2085
2086 FUNCTION {editor.key.organization.label}
2087 { editor empty$
2088 { key empty$
2089 { organization empty$
2090 #if SORTED
2091 { cite$ #1 #3 substring$ }
2092 #else !SORTED % need warning here because we won't give it later
2093 { "for label, need editor, key, or organization in " cite$ *
2094 warning$
2095 cite$ #1 #3 substring$
2096 }
2097 #endif SORTED
2098 { "The " #4 organization chop.word #3 text.prefix$ }
2099 if$
2100 }
2101 { key #3 text.prefix$ }
2102 if$
2103 }
2104 { editor format.lab.names }
2105 if$
2106 }
2107
2108 FUNCTION {calc.label}
2109 { type$ "book" =
2110 type$ "inbook" =
2111 or
2112 'author.editor.key.label
2113 { type$ "proceedings" =
2114 'editor.key.organization.label
2115 { type$ "manual" =
2116 'author.key.organization.label
2117 'author.key.label
2118 if$
2119 }
2120 if$
2121 }
2122 if$
2123 duplicate$
2124 year field.or.null purify$ #-1 #2 substring$
2125 *
2126 'label :=
2127 year field.or.null purify$ #-1 #4 substring$
2128 *
2129 sortify 'sort.label :=
2130 }
2131
2132 % It doesn't seem like a particularly good idea to use an order-of-citation
2133 % reference list when using alphabetic labels, but we need to have a
2134 % special pass to calculate labels when this happens.
2135
2136 #if !SORTED
2137
2138 ITERATE {calc.label}
2139
2140 #endif !SORTED
2141
2142 #endif LAB_ALPH
2143
2144 % When sorting, we compute the sortkey by executing "presort" on each entry.
2145 % The presort key contains a number of "sortify"ed strings, concatenated
2146 % with multiple blanks between them. This makes things like "brinch per"
2147 % come before "brinch hansen per".
2148 %
2149 % The fields used here are: the sort.label for alphabetic labels (as set by
2150 % calc.label), followed by the author names (or editor names or organization
2151 % (with a leading "The " removed) or key field, depending on entry type and on
2152 % what's empty), followed by year, followed by the first bit of the title
2153 % (chopping off a leading "The ", "A ", or "An ").
2154 % Names are formatted: Von Last First Junior.
2155 % The names within a part will be separated by a single blank
2156 % (such as "brinch hansen"), two will separate the name parts themselves
2157 % (except the von and last), three will separate the names,
2158 % four will separate the names from year (and from label, if alphabetic),
2159 % and four will separate year from title.
2160 %
2161 % The sort.format.names function takes an argument that should be in
2162 % BibTeX name format, and returns a string containing " "-separated
2163 % names in the format described above. The function is almost the same
2164 % as format.names.
2165
2166 #if SORTED
2167
2168 FUNCTION {sort.format.names}
2169 { 's :=
2170 #1 'nameptr :=
2171 ""
2172 s num.names$ 'numnames :=
2173 numnames 'namesleft :=
2174 { namesleft #0 > }
2175 { nameptr #1 >
2176 { " " * }
2177 'skip$
2178 if$
2179 #if NAME_FULL
2180 s nameptr "{vv{ } }{ll{ }}{ ff{ }}{ jj{ }}" format.name$ 't :=
2181 #else
2182 s nameptr "{vv{ } }{ll{ }}{ f{ }}{ jj{ }}" format.name$ 't :=
2183 #endif NAME_FULL
2184 nameptr numnames = t "others" = and
2185 { "et al" * }
2186 { t sortify * }
2187 if$
2188 nameptr #1 + 'nameptr :=
2189 namesleft #1 - 'namesleft :=
2190 }
2191 while$
2192 }
2193
2194 % The sort.format.title function returns the argument,
2195 % but first any leading "A "'s, "An "'s, or "The "'s are removed.
2196 % The chop.word function uses s, so we need another string variable, t
2197
2198 FUNCTION {sort.format.title}
2199 { 't :=
2200 "A " #2
2201 "An " #3
2202 "The " #4 t chop.word
2203 chop.word
2204 chop.word
2205 sortify
2206 #1 global.max$ substring$
2207 }
2208
2209 % The auxiliary functions here, for the presort function, are analogous to
2210 % the ones for calc.label; the same comments apply, except that the
2211 % organization field takes precedence here over the key field. For sorting
2212 % purposes, we still remove a leading "The " from the organization field.
2213
2214 FUNCTION {author.sort}
2215 { author empty$
2216 { key empty$
2217 { "to sort, need author or key in " cite$ * warning$
2218 ""
2219 }
2220 { key sortify }
2221 if$
2222 }
2223 { author sort.format.names }
2224 if$
2225 }
2226
2227 FUNCTION {author.editor.sort}
2228 { author empty$
2229 { editor empty$
2230 { key empty$
2231 { "to sort, need author, editor, or key in " cite$ * warning$
2232 ""
2233 }
2234 { key sortify }
2235 if$
2236 }
2237 { editor sort.format.names }
2238 if$
2239 }
2240 { author sort.format.names }
2241 if$
2242 }
2243
2244 FUNCTION {author.organization.sort}
2245 { author empty$
2246 { organization empty$
2247 { key empty$
2248 { "to sort, need author, organization, or key in " cite$ * warning$
2249 ""
2250 }
2251 { key sortify }
2252 if$
2253 }
2254 { "The " #4 organization chop.word sortify }
2255 if$
2256 }
2257 { author sort.format.names }
2258 if$
2259 }
2260
2261 FUNCTION {editor.organization.sort}
2262 { editor empty$
2263 { organization empty$
2264 { key empty$
2265 { "to sort, need editor, organization, or key in " cite$ * warning$
2266 ""
2267 }
2268 { key sortify }
2269 if$
2270 }
2271 { "The " #4 organization chop.word sortify }
2272 if$
2273 }
2274 { editor sort.format.names }
2275 if$
2276 }
2277
2278 % There is a limit, entry.max$, on the length of an entry string variable
2279 % (which is what its sort.key$ is), so we take at most that many characters
2280 % of the constructed key, and hope there aren't many references that match
2281 % to that many characters!
2282
2283 FUNCTION {presort}
2284 #if LAB_ALPH
2285 { calc.label
2286 sort.label
2287 " "
2288 *
2289 type$ "book" =
2290 #else !LAB_ALPH
2291 { type$ "book" =
2292 #endif LAB_ALPH
2293 type$ "inbook" =
2294 or
2295 'author.editor.sort
2296 { type$ "proceedings" =
2297 'editor.organization.sort
2298 { type$ "manual" =
2299 'author.organization.sort
2300 'author.sort
2301 if$
2302 }
2303 if$
2304 }
2305 if$
2306 #if LAB_ALPH
2307 *
2308 #endif LAB_ALPH
2309 " "
2310 *
2311 year field.or.null sortify
2312 *
2313 " "
2314 *
2315 title field.or.null
2316 sort.format.title
2317 *
2318 #1 entry.max$ substring$
2319 'sort.key$ :=
2320 }
2321
2322 ITERATE {presort}
2323
2324 % And now we can sort
2325
2326 SORT
2327
2328 #endif SORTED
2329
2330 % This long comment applies only to alphabetic labels, when sorted
2331 %
2332 % Now comes the final computation for alphabetic labels, putting in the 'a's
2333 % and 'b's and so forth if required. This involves two passes: a forward
2334 % pass to put in the 'b's, 'c's and so on, and a backwards pass
2335 % to put in the 'a's (we don't want to put in 'a's unless we know there
2336 % are 'b's).
2337 % We have to keep track of the longest (in width$ terms) label, for use
2338 % by the "thebibliography" environment.
2339 %
2340 % VAR: longest.label, last.sort.label, next.extra: string
2341 % longest.label.width, last.extra.num: integer
2342 %
2343 % initialize.longest.label ==
2344 % BEGIN
2345 % longest.label := ""
2346 % last.sort.label := int.to.chr$(0)
2347 % next.extra := ""
2348 % longest.label.width := 0
2349 % last.extra.num := 0
2350 % END
2351 %
2352 % forward.pass ==
2353 % BEGIN
2354 % if last.sort.label = sort.label then
2355 % last.extra.num := last.extra.num + 1
2356 % extra.label := int.to.chr$(last.extra.num)
2357 % else
2358 % last.extra.num := chr.to.int$("a")
2359 % extra.label := ""
2360 % last.sort.label := sort.label
2361 % fi
2362 % END
2363 %
2364 % reverse.pass ==
2365 % BEGIN
2366 % if next.extra = "b" then
2367 % extra.label := "a"
2368 % fi
2369 % label := label * extra.label
2370 % if width$(label) > longest.label.width then
2371 % longest.label := label
2372 % longest.label.width := width$(label)
2373 % fi
2374 % next.extra := extra.label
2375 % END
2376
2377 #if LAB_ALPH
2378
2379 #if SORTED
2380
2381 STRINGS { longest.label last.sort.label next.extra }
2382
2383 INTEGERS { longest.label.width last.extra.num }
2384
2385 FUNCTION {initialize.longest.label}
2386 { "" 'longest.label :=
2387 #0 int.to.chr$ 'last.sort.label :=
2388 "" 'next.extra :=
2389 #0 'longest.label.width :=
2390 #0 'last.extra.num :=
2391 }
2392
2393 FUNCTION {forward.pass}
2394 { last.sort.label sort.label =
2395 { last.extra.num #1 + 'last.extra.num :=
2396 last.extra.num int.to.chr$ 'extra.label :=
2397 }
2398 { "a" chr.to.int$ 'last.extra.num :=
2399 "" 'extra.label :=
2400 sort.label 'last.sort.label :=
2401 }
2402 if$
2403 }
2404
2405 FUNCTION {reverse.pass}
2406 { next.extra "b" =
2407 { "a" 'extra.label := }
2408 'skip$
2409 if$
2410 label extra.label * 'label :=
2411 label width$ longest.label.width >
2412 { label 'longest.label :=
2413 label width$ 'longest.label.width :=
2414 }
2415 'skip$
2416 if$
2417 extra.label 'next.extra :=
2418 }
2419
2420 EXECUTE {initialize.longest.label}
2421
2422 ITERATE {forward.pass}
2423
2424 REVERSE {reverse.pass}
2425
2426 #else !SORTED
2427
2428 % It still doesn't seem like a good idea to use an order-of-citation
2429 % reference list when using alphabetic labels, but when this happens we
2430 % must compute the longest label
2431
2432 STRINGS { longest.label }
2433
2434 INTEGERS { longest.label.width }
2435
2436 FUNCTION {initialize.longest.label}
2437 { "" 'longest.label :=
2438 #0 'longest.label.width :=
2439 }
2440
2441 FUNCTION {longest.label.pass}
2442 { label width$ longest.label.width >
2443 { label 'longest.label :=
2444 label width$ 'longest.label.width :=
2445 }
2446 'skip$
2447 if$
2448 }
2449
2450 EXECUTE {initialize.longest.label}
2451
2452 ITERATE {longest.label.pass}
2453
2454 #endif SORTED
2455
2456 #else !LAB_ALPH
2457
2458 % Now comes the computation for numeric labels.
2459 % We use either the sorted order or original order.
2460 % We still have to keep track of the longest (in width$ terms) label, for use
2461 % by the "thebibliography" environment.
2462
2463 STRINGS { longest.label }
2464
2465 INTEGERS { number.label longest.label.width }
2466
2467 FUNCTION {initialize.longest.label}
2468 { "" 'longest.label :=
2469 #1 'number.label :=
2470 #0 'longest.label.width :=
2471 }
2472
2473 FUNCTION {longest.label.pass}
2474 { number.label int.to.str$ 'label :=
2475 number.label #1 + 'number.label :=
2476 label width$ longest.label.width >
2477 { label 'longest.label :=
2478 label width$ 'longest.label.width :=
2479 }
2480 'skip$
2481 if$
2482 }
2483
2484 EXECUTE {initialize.longest.label}
2485
2486 ITERATE {longest.label.pass}
2487
2488 #endif LAB_ALPH
2489
2490 % Now we're ready to start writing the .BBL file.
2491 % We begin, if necessary, with a LaTeX macro for unnamed names in an alphabetic
2492 % label; next comes stuff from the `preamble' command in the database files.
2493 % Then we give an incantation containing the command
2494 % \begin{thebibliography}{...}
2495 % where the `...' is the longest label.
2496 %
2497 % We also call init.state.consts, for use by the output routines.
2498
2499 FUNCTION {begin.bib}
2500 #if LAB_ALPH
2501 { et.al.char.used
2502 { "\newcommand{\etalchar}[1]{$^{#1}$}" write$ newline$ }
2503 'skip$
2504 if$
2505 preamble$ empty$
2506 #else !LAB_ALPH
2507 { preamble$ empty$
2508 #endif LAB_ALPH
2509 'skip$
2510 { preamble$ write$ newline$ }
2511 if$
2512 "\begin{thebibliography}{" longest.label * "}" * write$ newline$
2513 }
2514
2515 EXECUTE {begin.bib}
2516
2517 EXECUTE {init.state.consts}
2518
2519 % Now we produce the output for all the entries
2520
2521 ITERATE {call.type$}
2522
2523 % Finally, we finish up by writing the `\end{thebibliography}' command.
2524
2525 FUNCTION {end.bib}
2526 { newline$
2527 "\end{thebibliography}" write$ newline$
2528 }
2529
2530 EXECUTE {end.bib}