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