30b216959715dee3b2a194cef99a2ffe5d9a2375
[latex-mlastyle.git] / mlastyle.bst
1 % $Id: mlastyle.bst,v 1.18 2003-11-27 05:11:13 tpope Exp $
2 % BibTeX bibliography style `mlastyle'
3 % Based on BibTeX standard bibliography style `plain'
4         % version 0.99a for BibTeX versions 0.99a or later, LaTeX version 2.09.
5         % Copyright (C) 2003 Tim Pope, all rights reserved.
6         % Copying of this file is authorized only if either
7         % (1) you make absolutely no changes to your copy, including name, or
8         % (2) if you do make changes, you name it something other than
9         % btxbst.doc, plain.bst, unsrt.bst, alpha.bst, and abbrv.bst.
10         % This restriction helps ensure that all standard styles are identical.
11         % The file mlastyle.dvi has the documentation for this style.
12
13 ENTRY
14   { address
15     author
16     booktitle
17     chapter
18     edition
19     editor
20     howpublished
21     institution
22     journal
23     key
24     month
25     note
26     number
27     organization
28     pages
29     publisher
30     school
31     series
32     title
33     type
34     volume
35     year
36     % New fields
37     url
38     urldate
39     accessdate
40     urlpath
41     database
42     version
43     % eid isbn issn doi
44   }
45   { author.duplicate author.shared }
46   { label }
47
48 INTEGERS { output.state before.all mid.phrase mid.sentence after.sentence after.block author.different author.last author.flast citealp.used url.used }
49
50 STRINGS { s t u empty.title }
51
52 % Rearranged such that true values require capital letters
53 FUNCTION {init.consts}
54 { #-1 'mid.phrase :=
55   #0 'mid.sentence :=
56   #1 'before.all :=
57   #2 'after.sentence :=
58   #3 'after.block :=
59
60   #0 'author.different :=
61   #1 'author.last :=
62   #2 'author.flast :=
63   %#3 'author.firstlast :=
64
65   #0 'citealp.used :=
66   #0 'url.used :=
67   " \ \ \ \ \unskip\unskip\unskip\unskip\unskip " 'empty.title :=
68   "" 'empty.title :=
69 }
70
71 % I do this a lot
72 FUNCTION {duplicate}
73 {
74   duplicate$
75   "duplicate should be duplicate$" warning$
76 }
77
78 FUNCTION {not}
79 {   { #0 }
80     { #1 }
81   if$
82 }
83
84 FUNCTION {and}
85 {   'skip$
86     { pop$ #0 }
87   if$
88 }
89
90 FUNCTION {or}
91 {   { pop$ #1 }
92     'skip$
93   if$
94 }
95
96 INTEGERS {chars i j}
97
98 % text.length$ does not include braces
99 % This function is probably a bad idea
100 FUNCTION {num.chars}
101 {
102   #0 'chars :=
103     { duplicate$ duplicate$ #1 chars substring$ = not }
104     { duplicate$ duplicate$ text.length$ swap$ #1 chars
105     substring$ text.length$ - chars + #1 + 'chars := }
106   while$
107     { duplicate$ duplicate$ #1 chars #1 - substring$ = }
108     { chars #1 - 'chars := }
109   while$
110   pop$ chars
111 }
112
113 % Puts the period inside any quotes
114 FUNCTION {do.period}
115 {
116   duplicate$ #-1 #2 substring$ "''" =
117     { #2 'i :=
118         { duplicate$ #-1 i - #11 substring$ "'\thinspace" = }
119         { i #11 + 'i := }
120       while$
121       duplicate$ #-1 i - global.max$ substring$
122       add.period$ swap$ #-1 i substring$ *
123     }
124     {
125       duplicate$ #-1 #3 substring$ "''}" =
126         { #3 'i :=
127             { duplicate$ #-1 i - #11 substring$ "'\thinspace" = }
128             { i #11 + 'i := }
129           while$
130           duplicate$ #-1 i - global.max$ substring$
131           add.period$ swap$ #-1 i substring$ *
132         }
133         { add.period$ }
134       if$
135     }
136   if$
137 }
138
139 FUNCTION {do.space}
140 { duplicate$ duplicate$ do.period =
141     { "\ " * }
142     { " " * }
143   if$
144 }
145
146 % Switched to do.period and added mid.phrase
147 FUNCTION {output.nonnull}
148 { 's :=
149   output.state mid.sentence =
150     { ", " * write$ }
151     { output.state after.block =
152         { do.period write$
153           newline$
154           "\newblock " write$
155         }
156         { output.state before.all =
157             'write$
158             { output.state mid.phrase =
159                 { do.space write$ }
160                 { do.period " " * write$ }
161               if$
162             }
163           if$
164         }
165       if$
166       mid.sentence 'output.state :=
167     }
168   if$
169   s
170 }
171
172 FUNCTION {output}
173 { duplicate$ empty$
174     'pop$
175     'output.nonnull
176   if$
177 }
178
179 FUNCTION {output.check}
180 { 't :=
181   duplicate$ empty$
182     { pop$ "empty " t * " in " * cite$ * warning$ }
183     'output.nonnull
184   if$
185 }
186
187 % Switched to do.period
188 FUNCTION {fin.entry}
189 { do.period
190   write$
191   newline$
192 }
193
194 FUNCTION {new.block}
195 { output.state before.all =
196     'skip$
197     { after.block 'output.state := }
198   if$
199 }
200
201 FUNCTION {new.sentence}
202 { output.state after.block =
203     'skip$
204     { output.state before.all =
205         'skip$
206         { after.sentence 'output.state := }
207       if$
208     }
209   if$
210 }
211
212 FUNCTION {continue.sentence}
213 { output.state after.block =
214     'skip$
215     { output.state before.all =
216         'skip$
217         { mid.phrase 'output.state := }
218       if$
219     }
220   if$
221 }
222
223 FUNCTION {new.block.checka}
224 { empty$
225     'skip$
226     'new.block
227   if$
228 }
229
230 FUNCTION {new.block.checkb}
231 { empty$
232   swap$ empty$
233   and
234     'skip$
235     'new.block
236   if$
237 }
238
239 FUNCTION {new.sentence.checka}
240 { empty$
241     'skip$
242     'new.sentence
243   if$
244 }
245
246 FUNCTION {new.sentence.checkb}
247 { empty$
248   swap$ empty$
249   and
250     'skip$
251     'new.sentence
252   if$
253 }
254
255 FUNCTION {field.or.null}
256 { duplicate$ empty$
257     { pop$ "" }
258     'skip$
259   if$
260 }
261
262 FUNCTION {sortify}
263 { purify$
264   "l" change.case$
265 }
266
267 FUNCTION {emphasize}
268 { duplicate$ empty$
269     { pop$ "" }
270     { "\emph{" swap$ * "}" * }
271   if$
272 }
273
274 FUNCTION {enquote}
275 { duplicate$ empty$
276     { pop$ "" }
277     {
278       #1 'i :=
279       #0 'j :=
280         { duplicate$ i #1 substring$ "" = not }
281         { duplicate$ duplicate$ i #1 substring$ quote$ =
282           swap$ i #1 - #1 substring$ "\" = not and %"
283             { duplicate$ #1 i #1 - substring$ swap$
284               i #1 + global.max$ substring$
285               j
286                 { swap$ duplicate$ #-1 #1 substring$ "'" =
287                     { swap$ "\thinspace'" }
288                     { swap$ "'" }
289                   if$
290                    #0 'j :=
291                 }
292                 { duplicate$ #1 #1 substring$ "`" =
293                     { "`\thinspace" }
294                     { "`" }
295                   if$
296                 #1 'j :=
297                 }
298               if$
299               swap$ * *
300             }
301             'skip$
302           if$
303           i #1 + 'i :=
304         }
305       while$
306       j #1 =
307         { "odd number of quotation marks in " cite$ * warning$ }
308         'skip$
309       if$
310       duplicate$ #1 #1 substring$ "`" =
311         { "``\thinspace" swap$ * }
312         { "``" swap$ *}
313       if$
314       duplicate$ #-1 #1 substring$ "'" =
315         { "\thinspace''" * }
316         { "''" *}
317       if$
318     }
319   if$
320 }
321
322 FUNCTION {selective.emphasize}
323 { field.or.null duplicate$ sortify 's :=
324   s #1 #8 substring$ duplicate$ "rev. of " = swap$ "rev.~of " = or
325   s #1 #9 substring$ "rev.\ of " = or
326   s "home page" = or
327   s "america online" = or
328     'skip$
329     'emphasize
330   if$
331 }
332
333 FUNCTION {selective.enquote}
334 { field.or.null duplicate$ sortify 's :=
335   s #1 #8 substring$ duplicate$ "rev. of " = swap$ "rev.~of " = or
336   s #1 #9 substring$ "rev.\ of " = or
337   s "introduction" = or
338   s "preface" = or
339   s "forward" = or
340   s "afterward" = or
341   s "home page" = or
342     'skip$
343     'enquote
344   if$
345 }
346
347 INTEGERS { nameptr namesleft numnames }
348
349 FUNCTION {format.names.custom}
350 { 'u :=
351   's :=
352   #1 'nameptr :=
353   s num.names$ 'numnames :=
354   numnames 'namesleft :=
355     { namesleft #0 > }
356     { s nameptr u format.name$ 't :=
357       nameptr #1 >
358         { namesleft #1 >
359             { ", " * t * }
360             { numnames #2 >
361                 { "," * }
362                 'skip$
363               if$
364               t "others" =
365                 { " et~al." * }
366                 { " and " * t * }
367               if$
368             }
369           if$
370         }
371         't
372       if$
373       nameptr #1 + 'nameptr :=
374       namesleft #1 - 'namesleft :=
375     }
376   while$
377 }
378
379 FUNCTION {format.names}
380 { "{ff~}{vv~}{ll}{, jj}" format.names.custom }
381
382 % Changed first author to last name first
383 FUNCTION {format.names.beginning}
384 { 's :=
385   #1 'nameptr :=
386   s num.names$ 'numnames :=
387   numnames 'namesleft :=
388     { namesleft #0 > }
389     { nameptr #1 =
390         { s nameptr "{vv~}{ll}{, ff}{, jj}" format.name$
391           duplicate$ #1 #1 substring$ duplicate$ "{" =
392             'skip$
393             { "u" change.case$ }
394           if$
395           swap$ #2 global.max$ substring$ * 't :=
396         }
397         { s nameptr "{ff~}{vv~}{ll}{, jj}" format.name$ 't := }
398       if$
399       nameptr #1 >
400         { namesleft #1 >
401             { ", " * t * }
402             { numnames #2 >
403                 { "," * }
404                 'skip$
405               if$
406               t "others" =
407                 { " et~al." * }
408                 { " and " * t * }
409               if$
410             }
411           if$
412         }
413         't
414       if$
415       nameptr #1 + 'nameptr :=
416       namesleft #1 - 'namesleft :=
417     }
418   while$
419 }
420
421 % Added check for duplicate authors
422 FUNCTION {format.authors}
423 { author empty$
424     { "" }
425     { author.duplicate #1 =
426         { "-{}-{}-" }
427         { author format.names.beginning }
428       if$
429     }
430   if$
431 }
432
433 % Changed to MLA editor abbreviations
434 % author.duplicate also applies
435 FUNCTION {format.editors}
436 { editor empty$
437     { "" }
438     { author empty$ author.duplicate #1 = and
439         { "-{}-{}-" }
440         { editor format.names.beginning }
441       if$
442       editor num.names$ #1 >
443         { ", eds." * }
444         { ", ed." * }
445       if$
446     }
447   if$
448 }
449
450 FUNCTION {format.editors.mid}
451 { editor empty$
452     { "" }
453     {
454       editor num.names$ #1 >
455         { "Eds.\ " }
456         { "Ed.\ " }
457       if$
458       editor format.names *
459     }
460   if$
461 }
462
463 % Formats the address and publisher
464 FUNCTION {format.publisher}
465 { address empty$
466     { publisher }
467     { address ": " * publisher * }
468   if$
469 }
470
471 % Changed to preserve case and use quotes
472 FUNCTION {format.title}
473 { title selective.enquote
474 }
475
476 FUNCTION {n.dashify}
477 { 't :=
478   ""
479     { t empty$ not }
480     { t #1 #1 substring$ "-" =
481         { t #1 #2 substring$ "--" = not
482             { "--" *
483               t #2 global.max$ substring$ 't :=
484             }
485             {   { t #1 #1 substring$ "-" = }
486                 { "-" *
487                   t #2 global.max$ substring$ 't :=
488                 }
489               while$
490             }
491           if$
492         }
493         { t #1 #1 substring$ *
494           t #2 global.max$ substring$ 't :=
495         }
496       if$
497     }
498   while$
499 }
500
501 FUNCTION {format.year}
502 { year empty$
503     { "" }
504     { year n.dashify
505       duplicate$ duplicate$ num.chars #10 =
506       swap$ #5 #2 substring$ "--" = and
507         { duplicate$ duplicate$ #1 #2 substring$ swap$ #7 #2 substring$ =
508             { duplicate$ #1 #6 substring$ swap$ #9 #2 substring$ * }
509             {}
510           if$
511         }
512         {}
513       if$
514     }
515   if$
516 }
517
518 FUNCTION {format.date}
519 { year empty$
520     { month empty$
521         { "" }
522         { "there's a month but no year in " cite$ * warning$
523           month
524         }
525       if$
526     }
527     { month empty$
528         'format.year
529         { month do.space format.year * }
530       if$
531     }
532   if$
533 }
534
535 %INTEGERS {xx}
536 FUNCTION {format.btitle}
537 { title selective.emphasize
538 }
539
540 FUNCTION {tie.or.space.connect}
541 { duplicate$ text.length$ #3 <
542     { "~" }
543     { do.space }
544   if$
545   swap$ * *
546 }
547
548 FUNCTION {either.or.check}
549 { empty$
550     'pop$
551     { "can't use both " swap$ * " fields in " * cite$ * warning$ }
552   if$
553 }
554
555 FUNCTION {abbreviate}
556 { duplicate$ sortify 's := 't :=
557   ""
558   "10th" "tenth" "9th" "ninth" "8th" "eighth" "7th" "seventh" "6th" "sixth"
559   "5th" "fifth" "4th" "fourth" "3rd" "third" "2nd" "second" "1st" "first"
560   "Rev." "revised" "Abr." "abridged"
561   {duplicate$ empty$ { pop$ #0 }{ #1 } if$ }{ s = { 't := }{ pop$ } if$ }
562   while$
563   t
564 }
565
566 FUNCTION {format.bvolume.or.num.series}
567 { volume empty$
568     { number empty$
569         { series field.or.null }
570         { 
571           series empty$
572             { number "there's a number but no series in " cite$ * warning$ }
573             { series
574           %output.state mid.sentence =
575             %{ " Sers." * }
576             %{ "Sers." * }
577           %if$
578           number tie.or.space.connect
579           }
580           if$
581         }
582       if$
583     }
584     { "Vol." volume tie.or.space.connect
585       series empty$
586         'skip$
587         { " of " * series selective.emphasize * add.period$ }
588       if$
589       number empty$
590         'skip$
591         { number * " vols." * }
592       if$
593       %"volume and number" number either.or.check
594     }
595   if$
596 }
597
598 % Changed edition to MLA abbreviation
599 FUNCTION {format.edition}
600 { edition empty$
601     { version empty$
602         { "" }
603         { "Vers.~" version *}
604       if$
605     }
606     { edition abbreviate
607       duplicate$ sortify "revised" =
608         { pop$ "Rev." }
609         'skip$
610       if$
611       duplicate$ sortify "abridged" =
612         { pop$ "Abr." }
613         'skip$
614       if$
615       do.space "ed." *
616       "edition and version" version either.or.check
617     }
618   if$
619 }
620
621 INTEGERS { multiresult }
622
623 FUNCTION {multi.page.check}
624 { 't :=
625   #0 'multiresult :=
626     { multiresult not
627       t empty$ not
628       and
629     }
630     { t #1 #1 substring$
631       duplicate$ "-" =
632       swap$ duplicate$ "," =
633       swap$ "+" =
634       or or
635         { #1 'multiresult := }
636         { t #2 global.max$ substring$ 't := }
637       if$
638     }
639   while$
640   multiresult
641 }
642
643 FUNCTION {format.pages}
644 { pages empty$
645     { "" }
646     {
647 % j is positive if pages contains a comma
648 % (not fully implemented)
649       #0 'j :=
650       pages n.dashify duplicate$ 't :=
651         { duplicate$ empty$ not }
652         {
653           duplicate$ #1 #1 substring$ duplicate$
654           "{" =
655             { j #1 + 'j := }
656             'skip$
657           if$
658           "}" =
659             { j #1 - 'j := }
660             'skip$
661           if$
662           duplicate$ #1 #2 substring$ ", " =
663             { j j #0 = + 'j := }
664             'skip$
665           if$
666           #2 global.max$ substring$
667         }
668       while$
669         { t empty$ not }
670         { t #1 #2 substring$ "--" = j not and
671             { t #3 global.max$ substring$ 't :=
672               duplicate$ num.chars 'i :=
673               "--" *
674               i t num.chars =
675                 {   { i #2 > }
676                     { duplicate$ #1 i #2 - substring$
677                       t #1 i #2 - substring$ =
678                         { t i #1 - global.max$ substring$ * "" 't :=  #2 'i := }
679                         { i #1 - 'i := }
680                       if$
681                     }
682                   while$
683                 }
684                 'skip$
685               if$
686             }
687             { t #1 #1 substring$ duplicate$ "," = swap$ "-" = or j and
688                 { "+" * "" 't := }
689                 { t #1 #1 substring$ *
690                   t #2 global.max$ substring$ 't :=
691                 }
692               if$
693             }
694           if$
695         }
696       while$
697     }
698   if$
699 }
700
701 FUNCTION {format.vol.num.year.pages}
702 { volume empty$
703     { number empty$
704         'skip$
705         { number n.dashify
706           "there's a number but no volume in " cite$ * warning$ }
707       if$
708       format.date
709     }
710     { volume
711       number empty$
712         'skip$
713         { "." * number n.dashify * }
714       if$
715       " (" * format.date * ")" *
716     }
717   if$
718   edition empty$
719     'skip$
720     { ", " * format.edition * }
721   if$
722   type field.or.null sortify duplicate$ "sec." = swap$ "section" = or
723     { chapter empty$
724           { "section type requires chapter in " cite$ warning$ }
725           { ", sec." chapter n.dashify tie.or.space.connect }
726         if$
727       }
728     'skip$
729   if$
730   type field.or.null sortify "review" = chapter empty$ not and
731     { ", sec." chapter n.dashify tie.or.space.connect }
732     'skip$
733   if$
734   pages empty$
735     'skip$
736     { ": " * format.pages * }
737   if$
738 }
739
740 % chapter might be useful if type is set to "pars."
741 FUNCTION {format.chapter.pages}
742 { chapter empty$
743   type field.or.null sortify duplicate$ "def." = swap$ "definition" = or
744   or
745     'format.pages
746     { type empty$
747         { "chapter ignored in " cite$ * warning$ }
748         { type "t" change.case$
749           chapter n.dashify tie.or.space.connect
750           pages empty$
751             'skip$
752             { ", " * }
753           if$
754         }
755       if$
756       format.pages *
757     }
758   if$
759 }
760
761 FUNCTION {empty.misc.check}
762 { author empty$ title empty$ howpublished empty$
763   month empty$ year empty$ note empty$
764   and and and and and
765   key empty$ not and
766     { "all relevant fields are empty in " cite$ * warning$ }
767     'skip$
768   if$
769 }
770
771 FUNCTION {format.thesis.type}
772 { type empty$
773     'skip$
774     { pop$
775       type "t" change.case$
776     }
777   if$
778 }
779
780 FUNCTION {format.tr.number}
781 { type empty$
782     { "Technical Report" }
783     'type
784   if$
785   number empty$
786     { "t" change.case$ }
787     { number tie.or.space.connect }
788   if$
789 }
790
791 FUNCTION {format.urldate}
792 { database empty$
793     'skip$
794     { database selective.emphasize output.nonnull new.block }
795   if$
796   urldate missing$
797   { accessdate empty$
798       { cite$ " has no urldate field" * warning$
799         "\theurldate{}"
800       }
801       { "accessdate in " cite$ * " is depreciated; use urldate instead" *
802         warning$ accessdate
803       }
804     if$
805   }
806   { urldate }
807   if$
808 }
809 FUNCTION {output.url}
810 {
811   url empty$
812     { urlpath empty$ 
813         'skip$
814         { format.urldate output }
815       if$
816     }
817     { format.urldate
818       " $<$\url{" * url * "}$>$" *
819       output.nonnull
820     }
821   if$
822   urlpath empty$
823     'skip$
824     { "Path: " urlpath * output.nonnull }
825   if$
826 }
827
828 FUNCTION {format.crossref}
829 {
830   pages empty$ { "\citealp" } { "\citealp[" format.chapter.pages * "]" * } if$
831   "{" * crossref * "}" *
832 }
833
834
835 FUNCTION {cite.title}
836 { title empty$ journal empty$ not and
837     { key empty$ { journal }{ key } if$ selective.emphasize }
838     { title empty$ key empty$ and
839         { "empty title and key in " cite$ * warning$ "" }
840         { key empty$ {title}{key} if$
841           type$ "book" =
842           type$ "booklet" =
843           type$ "inbook" =
844           type$ "manual" =
845           type$ "phdthesis" =
846           type$ "proceedings" =
847           or or or or or
848             { selective.emphasize }
849             { type$ "article" =
850               %type$ "booklet" =
851               type$ "incollection" =
852               type$ "inproceedings" =
853               type$ "mastersthesis" =
854               type$ "misc" =
855               type$ "techreport" =
856               type$ "unpublished" =
857               or or or or or or
858                 { selective.enquote }
859                 {}
860               if$
861             }
862           if$
863         }
864       if$
865     }
866   if$
867 }
868
869 FUNCTION {cite.label}
870 {
871   %author empty$
872   %  { editor empty$ { organization field.or.null 'a := }{ editor 'a :=} if$}
873   %  { author 'a := }
874   %if$
875   %abbr empty$ {
876   author empty$
877     { editor empty$
878         { "" }
879         { editor }
880       if$
881     }
882     { author }
883   if$
884   duplicate$ empty$
885     { cite.title *
886     "(" * empty.title * ")" * }
887     { duplicate$
888       author.shared author.different =
889         { "{vv~}{ll}" format.names.custom 's := }
890         { author.shared author.last =
891             { "{f.~}{vv~}{ll}{, jj}" format.names.custom 's := }
892             { author.shared author.flast =
893                 { "{ff~}{vv~}{ll}{, jj}" format.names.custom 's := }
894                 { "{vv~}{ll}" format.names.custom ", " *
895                   cite.title * 's := "WTF" warning$ }
896               if$
897             }
898           if$
899         }
900       if$
901       s
902       "(" * empty.title *
903       author.duplicate { cite.title * }{} if$
904       "){" * swap$ "{ff~}{vv~}{ll}{, jj}" format.names.custom * "}" *
905     }
906   if$
907       %}
908       %if$
909     %}
910     %{}% abbr }
911  % if$
912 }
913
914 % TODO
915 FUNCTION {output.bibitem}
916 { newline$
917   "\bibitem[" write$
918   cite.label write$
919   "]{" write$
920   cite$ write$
921   "}" write$
922   newline$
923   ""
924   before.all 'output.state :=
925 }
926
927 FUNCTION {article}
928 { output.bibitem
929   format.authors "author" output.check
930   new.block
931   format.title "title" output.check
932   new.block
933   crossref missing$
934     { type empty$
935         'skip$
936         { type sortify "review" =
937             { "Rev.\ of " booktitle selective.emphasize * 
938             "booktitle" output.check new.block
939             }
940             { "Ignoring invalid type in " cite$ warning$ }
941           if$
942         }
943       if$
944       journal selective.emphasize "journal" output.check
945       continue.sentence
946       address empty$
947         'skip$
948         { "[" address * "]" * output
949           continue.sentence
950         }
951       if$
952       series empty$
953         'skip$
954         { series sortify
955           duplicate$ "new" =
956             { "ns" }
957             { duplicate$ "old" =
958                 { "os" }
959                 { series abbreviate do.space "ser." * "l" change.case$ }
960               if$
961             }
962           if$
963           output.nonnull
964           continue.sentence
965         }
966       if$
967       format.vol.num.year.pages output
968     }
969     { format.crossref output.nonnull
970       %format.pages output
971     }
972   if$
973   new.block
974   output.url
975   new.block
976   note output
977   fin.entry
978 }
979
980 FUNCTION {book}
981 { output.bibitem
982   author empty$
983     { format.editors "author and editor" output.check }
984     { format.authors output.nonnull }
985   if$
986   new.block
987   format.btitle "title" output.check
988   new.block
989   crossref missing$
990     { author empty$ 'skip$ { format.editors.mid output new.block } if$
991       format.edition output
992       new.sentence
993       format.bvolume.or.num.series output
994       new.block
995       format.publisher "publisher" output.check
996       format.date "year" output.check
997     }
998     {% format.date "year" output
999       new.block
1000       format.crossref output.nonnull
1001     }
1002   if$
1003   new.block
1004   output.url
1005   new.block
1006   note output
1007   fin.entry
1008 }
1009
1010 FUNCTION {booklet}
1011 { output.bibitem
1012   format.authors output
1013   new.block
1014   format.btitle "title" output.check
1015   howpublished address new.block.checkb
1016   howpublished output
1017   address output
1018   format.date output
1019   new.block
1020   note output
1021   fin.entry
1022 }
1023
1024 FUNCTION {inbook}
1025 { output.bibitem
1026   author empty$
1027     { format.editors "author and editor" output.check }
1028     { format.authors output.nonnull }
1029   if$
1030   new.block
1031   format.btitle "title" output.check
1032   new.block
1033   crossref missing$
1034     { author empty$ 'skip$ { format.editors.mid output new.block } if$
1035       format.edition output
1036       new.sentence
1037       format.bvolume.or.num.series output
1038       new.block
1039       format.publisher "publisher" output.check
1040       format.date "year" output.check
1041       new.sentence
1042       format.chapter.pages "chapter and pages" output.check
1043       %address output
1044     }
1045     {
1046       new.block
1047       format.crossref output.nonnull
1048     }
1049   if$
1050   new.block
1051   output.url
1052   note output
1053   fin.entry
1054 }
1055
1056 FUNCTION {incollection}
1057 { output.bibitem
1058   format.authors "author" output.check
1059   chapter empty$
1060     { new.block type output }
1061     'skip$
1062   if$
1063   new.block
1064   format.title "title" output.check
1065   type field.or.null sortify duplicate$ "definition" = swap$ "def." = or
1066     { new.block "Def.~" chapter field.or.null * "chapter" output.check } 
1067     'skip$
1068   if$
1069   new.block
1070   crossref missing$
1071     { 
1072       booktitle selective.emphasize "booktitle" output.check
1073       new.block
1074       format.editors.mid "editor" output.check
1075       new.block
1076       format.edition output
1077       new.sentence
1078       format.bvolume.or.num.series output
1079       new.block
1080       format.publisher "publisher" output.check
1081       %address output
1082       format.date "year" output.check
1083       new.block
1084       format.chapter.pages output
1085     }
1086     { format.crossref output.nonnull
1087       %format.chapter.pages output
1088     }
1089   if$
1090   new.block
1091   output.url
1092   new.block
1093   note output
1094   fin.entry
1095 }
1096
1097 FUNCTION {inproceedings}
1098 { output.bibitem
1099   format.authors "author" output.check
1100   new.block
1101   format.title "title" output.check
1102   new.block
1103   crossref missing$
1104     {
1105       booktitle "booktitle" output.check
1106       new.sentence
1107       format.editors.mid output
1108       new.block
1109       format.edition output
1110       new.sentence
1111       format.bvolume.or.num.series output
1112       new.block
1113       format.edition output
1114       new.sentence
1115       format.publisher output
1116       format.date "year" output.check
1117       %address empty$
1118         %{ organization publisher new.sentence.checkb
1119          % organization output
1120          % publisher output
1121          % format.date "year" output.check
1122         %}
1123         %{ address output.nonnull
1124          % format.date "year" output.check
1125          % new.sentence
1126          % organization output
1127          % publisher output
1128         %}
1129       %if$
1130       new.sentence
1131       format.pages output
1132     }
1133     { format.crossref output.nonnull
1134     }
1135   if$
1136   new.block
1137   output.url
1138   new.block
1139   note output
1140   fin.entry
1141 }
1142
1143 FUNCTION {conference} { inproceedings }
1144
1145 FUNCTION {manual}
1146 { output.bibitem
1147   author empty$
1148     { organization empty$
1149         'skip$
1150         { organization output.nonnull
1151           address output
1152         }
1153       if$
1154     }
1155     { format.authors output.nonnull }
1156   if$
1157   new.block
1158   format.btitle "title" output.check
1159   new.block
1160   format.edition output
1161   new.sentence
1162   author empty$
1163     { organization empty$
1164         { address new.block.checka
1165           address output
1166         }
1167         'skip$
1168       if$
1169     }
1170     { organization address new.block.checkb
1171       organization output
1172       address output
1173     }
1174   if$
1175   format.date output
1176   new.block
1177   output.url
1178   new.block
1179   note output
1180   fin.entry
1181 }
1182
1183 FUNCTION {mastersthesis}
1184 { output.bibitem
1185   format.authors "author" output.check
1186   new.block
1187   format.title "title" output.check
1188   new.block
1189   "Diss." format.thesis.type output.nonnull
1190   new.block
1191   school "school" output.check
1192   address output
1193   format.date "year" output.check
1194   new.block
1195   output.url
1196   new.block
1197   note output
1198   fin.entry
1199 }
1200
1201 FUNCTION {misc}
1202 { output.bibitem
1203   format.authors output
1204   title howpublished new.block.checkb
1205   format.title output
1206   new.block
1207   %howpublished new.block.checka
1208   howpublished output
1209   format.date output
1210   new.block
1211   output.url
1212   new.block
1213   note output
1214   fin.entry
1215   empty.misc.check
1216 }
1217
1218 FUNCTION {phdthesis}
1219 { output.bibitem
1220   format.authors "author" output.check
1221   new.block
1222   format.btitle "title" output.check
1223   new.block
1224   "Diss." format.thesis.type output.nonnull
1225   new.block
1226   school "school" output.check
1227   address output
1228   format.date "year" output.check
1229   new.block
1230   output.url
1231   new.block
1232   note output
1233   fin.entry
1234 }
1235
1236 FUNCTION {proceedings}
1237 { output.bibitem
1238   editor empty$
1239     { organization output }
1240     { format.editors output.nonnull }
1241   if$
1242   new.block
1243   format.btitle "title" output.check
1244   new.block
1245   format.bvolume.or.num.series output
1246   address empty$
1247     { editor empty$
1248         { publisher new.sentence.checka }
1249         { organization publisher new.sentence.checkb
1250           organization output
1251         }
1252       if$
1253       publisher output
1254       format.date "year" output.check
1255     }
1256     { address output.nonnull
1257       format.date "year" output.check
1258       new.sentence
1259       editor empty$
1260         'skip$
1261         { organization output }
1262       if$
1263       publisher output
1264     }
1265   if$
1266   new.block
1267   output.url
1268   new.block
1269   note output
1270   fin.entry
1271 }
1272
1273 FUNCTION {techreport}
1274 { output.bibitem
1275   format.authors "author" output.check
1276   new.block
1277   format.title "title" output.check
1278   new.block
1279   format.tr.number output.nonnull
1280   new.block
1281   institution "institution" output.check
1282   address output
1283   format.date "year" output.check
1284   new.block
1285   note output
1286   fin.entry
1287 }
1288
1289 FUNCTION {unpublished}
1290 { output.bibitem
1291   format.authors "author" output.check
1292   new.block
1293   format.title "title" output.check
1294   new.block
1295   output.url
1296   new.block
1297   note "note" output.check
1298   format.date output
1299   fin.entry
1300 }
1301
1302 FUNCTION {default.type} { misc }
1303
1304 MACRO {jan} {"Jan."}
1305
1306 MACRO {feb} {"Feb."}
1307
1308 MACRO {mar} {"Mar."}
1309
1310 MACRO {apr} {"Apr."}
1311
1312 MACRO {may} {"May"}
1313
1314 MACRO {jun} {"June"}
1315
1316 MACRO {jul} {"July"}
1317
1318 MACRO {aug} {"Aug."}
1319
1320 MACRO {sep} {"Sept."}
1321
1322 MACRO {oct} {"Oct."}
1323
1324 MACRO {nov} {"Nov."}
1325
1326 MACRO {dec} {"Dec."}
1327
1328 % Currently left in to help with compatibility
1329
1330 MACRO {acmcs} {"ACM Computing Surveys"}
1331
1332 MACRO {acta} {"Acta Informatica"}
1333
1334 MACRO {cacm} {"Communications of the ACM"}
1335
1336 MACRO {ibmjrd} {"IBM Journal of Research and Development"}
1337
1338 MACRO {ibmsj} {"IBM Systems Journal"}
1339
1340 MACRO {ieeese} {"IEEE Transactions on Software Engineering"}
1341
1342 MACRO {ieeetc} {"IEEE Transactions on Computers"}
1343
1344 MACRO {ieeetcad}
1345  {"IEEE Transactions on Computer-Aided Design of Integrated Circuits"}
1346
1347 MACRO {ipl} {"Information Processing Letters"}
1348
1349 MACRO {jacm} {"Journal of the ACM"}
1350
1351 MACRO {jcss} {"Journal of Computer and System Sciences"}
1352
1353 MACRO {scp} {"Science of Computer Programming"}
1354
1355 MACRO {sicomp} {"SIAM Journal on Computing"}
1356
1357 MACRO {tocs} {"ACM Transactions on Computer Systems"}
1358
1359 MACRO {tods} {"ACM Transactions on Database Systems"}
1360
1361 MACRO {tog} {"ACM Transactions on Graphics"}
1362
1363 MACRO {toms} {"ACM Transactions on Mathematical Software"}
1364
1365 MACRO {toois} {"ACM Transactions on Office Information Systems"}
1366
1367 MACRO {toplas} {"ACM Transactions on Programming Languages and Systems"}
1368
1369 MACRO {tcs} {"Theoretical Computer Science"}
1370
1371 READ
1372
1373 INTEGERS { len }
1374
1375 FUNCTION {chop.word}
1376 { 's :=
1377   'len :=
1378   s #1 len substring$ =
1379     { s len #1 + global.max$ substring$ }
1380     's
1381   if$
1382 }
1383
1384 FUNCTION {sort.format.names}
1385 { 's :=
1386   #1 'nameptr :=
1387   ""
1388   s num.names$ 'numnames :=
1389   numnames 'namesleft :=
1390     { namesleft #0 > }
1391     { nameptr #1 >
1392         { "   " * }
1393         'skip$
1394       if$
1395       s nameptr "{vv{ } }{ll{ }}{  ff{ }}{  jj{ }}" format.name$ 't :=
1396       nameptr numnames = t "others" = and
1397         { "et al" * }
1398         { t sortify * }
1399       if$
1400       nameptr #1 + 'nameptr :=
1401       namesleft #1 - 'namesleft :=
1402     }
1403   while$
1404 }
1405
1406 FUNCTION {sort.format.title}
1407 { 't :=
1408   "A " #2
1409     "An " #3
1410       "The " #4
1411         "Rev. of " #8
1412           "Rev.~of " #8
1413             "Rev.\ of " #9
1414             t chop.word
1415           chop.word
1416         chop.word
1417       chop.word
1418     chop.word
1419   chop.word
1420   sortify
1421   #1 global.max$ substring$
1422 }
1423
1424 FUNCTION {author.sort}
1425 { author empty$
1426     { key empty$
1427         { "to sort, need author or key in " cite$ * warning$
1428           ""
1429         }
1430         { key sortify }
1431       if$
1432     }
1433     { author sort.format.names }
1434   if$
1435 }
1436
1437 FUNCTION {author.editor.sort}
1438 { author empty$
1439     { editor empty$
1440         { key empty$
1441             { "to sort, need author, editor, or key in " cite$ * warning$
1442               ""
1443             }
1444             { key sortify }
1445           if$
1446         }
1447         { editor sort.format.names }
1448       if$
1449     }
1450     { author sort.format.names }
1451   if$
1452 }
1453
1454 FUNCTION {author.organization.sort}
1455 { author empty$
1456     { organization empty$
1457         { key empty$
1458             { "to sort, need author, organization, or key in " cite$ * warning$
1459               ""
1460             }
1461             { key sortify }
1462           if$
1463         }
1464         { "The " #4 organization chop.word sortify }
1465       if$
1466     }
1467     { author sort.format.names }
1468   if$
1469 }
1470
1471 FUNCTION {editor.organization.sort}
1472 { editor empty$
1473     { organization empty$
1474         { key empty$
1475             { "to sort, need editor, organization, or key in " cite$ * warning$
1476               ""
1477             }
1478             { key sortify }
1479           if$
1480         }
1481         { "The " #4 organization chop.word sortify }
1482       if$
1483     }
1484     { editor sort.format.names }
1485   if$
1486 }
1487
1488 FUNCTION {presort}
1489 { type$ "book" =
1490   type$ "inbook" =
1491   or
1492     'author.editor.sort
1493     { type$ "proceedings" =
1494         'editor.organization.sort
1495         { type$ "manual" =
1496             'author.organization.sort
1497             'author.sort
1498           if$
1499         }
1500       if$
1501     }
1502   if$
1503   duplicate$ empty$ 'skip$ { "    " * } if$
1504   key empty$
1505     { title field.or.null sort.format.title * "    " * booktitle field.or.null sort.format.title * }
1506     { key sortify * }
1507   if$
1508   "    "
1509   *
1510   year field.or.null sortify
1511   *
1512   #1 entry.max$ substring$
1513   'sort.key$ :=
1514 }
1515
1516 ITERATE {presort}
1517
1518 SORT
1519
1520 STRINGS {a b}
1521
1522 FUNCTION {init.vars}
1523 { #0 int.to.chr$ 'a :=
1524   #0 int.to.chr$ 'b :=
1525   #0 'i :=
1526   #0 'j :=
1527 }
1528
1529 % Function name is not strictly accurate
1530 FUNCTION {forward.author.dup.check}
1531 {
1532   url empty$ urlpath empty$ urldate empty$ and and
1533     'skip$
1534     { url.used #1 + 'url.used := }
1535   if$
1536   crossref empty$ 'skip$ { citealp.used #1 + 'citealp.used := } if$
1537   author empty$
1538     { editor empty$ { organization field.or.null 'a := }{ editor 'a :=} if$}
1539     { author 'a := }
1540   if$
1541   %'a :=
1542   a empty$
1543     'skip$
1544     { b "{ff~}{vv~}{ll}{, jj}" format.names.custom purify$
1545       a "{ff~}{vv~}{ll}{, jj}" format.names.custom purify$ =
1546         { #1 'author.duplicate := }
1547         { #0 'author.duplicate := }
1548       if$
1549       a 'b :=
1550     }
1551   if$
1552 }
1553
1554 FUNCTION {forward.author.share.check}
1555 %
1556 % Pass through all entries, comparing current author to last one.
1557 %
1558 { author.duplicate author empty$ or
1559   { author.duplicate { i 'author.shared := }{} if$}
1560   { b "{f.~}{vv~}{ll}{, jj}" format.names.custom purify$
1561     author field.or.null "{f.~}{vv~}{ll}{, jj}" format.names.custom purify$ =
1562     { author.flast 'author.shared := }
1563     { b "{vv~}{ll}" format.names.custom purify$
1564       author field.or.null "{vv~}{ll}" format.names.custom purify$ =
1565       { author.last 'author.shared := }
1566       { author.different 'author.shared := }
1567       if$
1568     }
1569     if$
1570     author.shared 'i :=
1571     author field.or.null 'b :=
1572   }
1573   if$
1574 }
1575
1576 FUNCTION {reverse.author}
1577
1578   author.duplicate
1579   { author.shared i <
1580       { i 'author.shared := }
1581       {}
1582     if$
1583   }
1584   { author.shared i <
1585       { author.shared i 'author.shared := 'i := }
1586       { author.shared 'i := }
1587     if$
1588   }
1589   if$
1590   j #1 = author.duplicate not and { #2 'author.duplicate := } {} if$
1591   author.duplicate 'j :=
1592 }
1593
1594 EXECUTE {init.consts}
1595
1596 EXECUTE {init.vars}
1597 ITERATE {forward.author.dup.check}
1598
1599 EXECUTE {init.vars}
1600 ITERATE {forward.author.share.check}
1601
1602 EXECUTE {init.vars}
1603 REVERSE {reverse.author}
1604
1605 %INTEGERS { number.label longest.label.width }
1606
1607 %FUNCTION {initialize.longest.label}
1608 %{ "" 'longest.label :=
1609 %  #1 'number.label :=
1610 %  #0 'longest.label.width :=
1611 %}
1612
1613 %FUNCTION {longest.label.pass}
1614 %{ number.label int.to.str$ 'label :=
1615 %  number.label #1 + 'number.label :=
1616 %  label width$ longest.label.width >
1617 %    { label 'longest.label :=
1618 %      label width$ 'longest.label.width :=
1619 %    }
1620 %    'skip$
1621 %  if$
1622 %}
1623
1624 %EXECUTE {initialize.longest.label}
1625
1626 %ITERATE {longest.label.pass}
1627
1628 FUNCTION {begin.bib}
1629 {
1630   citealp.used
1631     { "\expandafter\ifx\csname citealp\endcsname\relax\let\citealp\cite\fi"
1632       write$ newline$
1633     }
1634     'skip$
1635   if$
1636   url.used
1637     { "\providecommand\url[1]{\texttt{#1}}"
1638       write$ newline$
1639       "\providecommand\theurldate{\today}"
1640       write$ newline$
1641     }
1642     'skip$
1643   if$
1644   preamble$ empty$
1645     'skip$
1646     { preamble$ write$ newline$ }
1647   if$
1648   "\begin{thebibliography}{\rule{.5in}{0pt}}" write$ newline$
1649 }
1650
1651 EXECUTE {begin.bib}
1652
1653 ITERATE {call.type$}
1654
1655 FUNCTION {end.bib}
1656 { newline$
1657   "\end{thebibliography}" write$ newline$
1658 }
1659
1660 EXECUTE {end.bib}