home *** CD-ROM | disk | FTP | other *** search
/ The Datafile PD-CD 3 / PDCD_3.iso / tex / texbase2 / Documents / btxdoc / doc < prev    next >
Text File  |  1990-01-05  |  73KB  |  2,525 lines

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