83f4b76b6161947f6c09657cb2d6e230279bb0ae
[latex-mlastyle.git] / mlastyle.bst
1 % $Id: mlastyle.bst,v 1.13 2003-11-22 19:15:11 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     {
593 % j is positive if pages contains a comma
594 % (not fully implemented)
595       #0 'j :=
596       pages n.dashify 't :=
597       ""
598         { t empty$ not }
599         { t #1 #2 substring$ "--" =
600             { t #3 global.max$ substring$ 't :=
601               duplicate$ num.chars 'i :=
602               "--" *
603               i t num.chars =
604                 {   { i #2 > }
605                     { duplicate$ #1 i #2 - substring$
606                       t #1 i #2 - substring$ =
607                         { t i #1 - global.max$ substring$ * "" 't :=  #2 'i := }
608                         { i #1 - 'i := }
609                       if$
610                     }
611                   while$
612                 }
613                 'skip$
614               if$
615             }
616             { t #1 #1 substring$ *
617               t #2 global.max$ substring$ 't :=
618             }
619           if$
620         }
621       while$
622     }
623   if$
624 }
625
626 FUNCTION {format.year}
627 { year empty$
628     { "" }
629     { year n.dashify
630       duplicate$ duplicate$ num.chars #10 =
631       swap$ #5 #2 substring$ "--" = and
632         { duplicate$ duplicate$ #1 #2 substring$ swap$ #7 #2 substring$ =
633             { duplicate$ #1 #6 substring$ swap$ #8 #2 substring$ * }
634             {}
635           if$
636         }
637         {}
638       if$
639     }
640   if$
641 }
642
643 FUNCTION {format.vol.num.year.pages}
644 { volume empty$
645     { number empty$
646         'skip$
647         { "there's a number but no volume in " cite$ * warning$ }
648       if$
649       format.date
650     }
651     { volume
652       number empty$
653         'skip$
654         { "." * number * }
655       if$
656       " (" * format.date * ")" *
657     }
658   if$
659   edition empty$
660     'skip$
661     { ", " * format.edition * }
662   if$
663   pages empty$
664     'skip$
665     { ": " * pages n.dashify * }
666   if$
667 }
668
669
670 FUNCTION {format.vol.num.pages}
671 { volume field.or.null
672   number empty$
673     'skip$
674     { "(" number * ")" * *
675       volume empty$
676         { "there's a number but no volume in " cite$ * warning$ }
677         'skip$
678       if$
679     }
680   if$
681   pages empty$
682     'skip$
683     { duplicate$ empty$
684         { pop$ format.pages }
685         { ":" * pages n.dashify * }
686       if$
687     }
688   if$
689 }
690
691 % chapter might be useful if type is set to "pars."
692 FUNCTION {format.chapter.pages}
693 { chapter empty$
694   type field.or.null sortify duplicate$ "def." = swap$ "definition" = or
695   or
696     'format.pages
697     { type empty$
698         { "Chapter" }
699         { type "t" change.case$ }
700       if$
701       chapter n.dashify tie.or.space.connect
702       pages empty$
703         'skip$
704         { ", " * format.pages * }
705       if$
706     }
707   if$
708 }
709
710 FUNCTION {empty.misc.check}
711 { author empty$ title empty$ howpublished empty$
712   month empty$ year empty$ note empty$
713   and and and and and
714   key empty$ not and
715     { "all relevant fields are empty in " cite$ * warning$ }
716     'skip$
717   if$
718 }
719
720 FUNCTION {format.thesis.type}
721 { type empty$
722     'skip$
723     { pop$
724       type "t" change.case$
725     }
726   if$
727 }
728
729 FUNCTION {format.tr.number}
730 { type empty$
731     { "Technical Report" }
732     'type
733   if$
734   number empty$
735     { "t" change.case$ }
736     { number tie.or.space.connect }
737   if$
738 }
739
740 FUNCTION {format.url}
741 { url empty$
742     { "" }
743     { urldate empty$
744         { accessdate empty$
745             { "there's a url but no urldate in " cite$ * warning$ "\today" }
746             { "accessdate in " cite$ * " depreciated; use urldate instead" *
747               warning$ accessdate }
748             if$
749         }
750         { urldate }
751       if$
752       " $<$\url{" * url * "}$>$" *
753       urlpath empty$
754         'skip$
755         { do.period " Path: " * urlpath * }
756       if$
757     }
758   if$
759 }
760
761 FUNCTION {format.crossref}
762 {
763   pages empty$ { "\citealp" } { "\citealp[" format.chapter.pages * "]" * } if$
764   "{" * crossref * "}" *
765 }
766
767
768 FUNCTION {cite.title}
769 { title empty$ journal empty$ not and
770     { key empty$ { journal }{ key } if$ emphasize }
771     { title empty$ key empty$ and
772         { "empty title and key in " cite$ * warning$ "" }
773         { key empty$ {title}{key} if$
774           type$ "book" =
775           type$ "booklet" =
776           type$ "inbook" =
777           type$ "manual" =
778           type$ "phdthesis" =
779           type$ "proceedings" =
780           or or or or or
781             { emphasize }
782             { type$ "article" =
783               %type$ "booklet" =
784               type$ "incollection" =
785               type$ "inproceedings" =
786               type$ "mastersthesis" =
787               type$ "misc" =
788               type$ "techreport" =
789               type$ "unpublished" =
790               or or or or or or
791                 { selective.enquote }
792                 {}
793               if$
794             }
795           if$
796         }
797       if$
798     }
799   if$
800 }
801
802 FUNCTION {cite.label}
803 {
804   %author empty$
805   %  { editor empty$ { organization field.or.null 'a := }{ editor 'a :=} if$}
806   %  { author 'a := }
807   %if$
808   %abbr empty$ {
809   author empty$
810     { editor empty$
811         { "" }
812         { editor }
813       if$
814     }
815     { author }
816   if$
817   duplicate$ empty$
818     { cite.title *
819     "(" * empty.title * ")" * }
820     { duplicate$
821       author.shared author.different =
822         { "{vv~}{ll}" format.names.custom 's := }
823         { author.shared author.last =
824             { "{f.~}{vv~}{ll}{, jj}" format.names.custom 's := }
825             { author.shared author.flast =
826                 { "{ff~}{vv~}{ll}{, jj}" format.names.custom 's := }
827                 { "{vv~}{ll}" format.names.custom ", " * cite.title * 's := "WTF" warning$ }
828               if$
829             }
830           if$
831         }
832       if$
833       s
834       "(" * empty.title *
835       author.duplicate { cite.title * }{} if$
836       ")" * swap$ "{ff~}{vv~}{ll}{, jj}" format.names.custom purify$ *
837     }
838   if$
839       %}
840       %if$
841     %}
842     %{}% abbr }
843  % if$
844 }
845
846 % TODO
847 FUNCTION {output.bibitem}
848 { newline$
849   "\bibitem[" write$
850   cite.label write$
851   "]{" write$
852   cite$ write$
853   "}" write$
854   newline$
855   ""
856   before.all 'output.state :=
857 }
858
859 FUNCTION {article}
860 { output.bibitem
861   format.authors "author" output.check
862   new.block
863   format.title "title" output.check
864   new.block
865   crossref missing$
866     { type empty$
867         'skip$
868         { type sortify "review" =
869             { "Rev.\ of " booktitle emphasize * 
870             "booktitle" output.check new.block
871             }
872             { "Ignoring invalid type in " cite$ warning$ }
873           if$
874         }
875       if$
876       journal emphasize "journal" output.check after.title 'output.state :=
877       address empty$
878         'skip$
879         { "[" address * "]" * output
880           after.title 'output.state :=
881         }
882       if$
883       %format.date "year" output.check
884       %edition output
885       format.vol.num.year.pages output
886     }
887     { format.crossref output.nonnull
888       %format.pages output
889     }
890   if$
891   new.block
892   format.url output
893   new.block
894   note output
895   fin.entry
896 }
897
898 FUNCTION {book}
899 { output.bibitem
900   author empty$
901     { format.editors "author and editor" output.check }
902     { format.authors output.nonnull }
903   if$
904   new.block
905   format.btitle "title" output.check
906   new.block
907   crossref missing$
908     { author empty$ 'skip$ { format.editors.mid output new.block } if$
909       format.edition output
910       new.sentence
911       format.bvolume.or.num.series output
912       new.block
913       format.publisher "publisher" output.check
914       format.date "year" output.check
915     }
916     {% format.date "year" output
917       new.block
918       format.crossref output.nonnull
919     }
920   if$
921   new.block
922   format.url output
923   new.block
924   note output
925   fin.entry
926 }
927
928 FUNCTION {booklet}
929 { output.bibitem
930   format.authors output
931   new.block
932   format.btitle "title" output.check
933   howpublished address new.block.checkb
934   howpublished output
935   address output
936   format.date output
937   new.block
938   note output
939   fin.entry
940 }
941
942 FUNCTION {inbook}
943 { output.bibitem
944   author empty$
945     { format.editors "author and editor" output.check }
946     { format.authors output.nonnull }
947   if$
948   new.block
949   format.btitle "title" output.check
950   new.block
951   crossref missing$
952     { author empty$ 'skip$ { format.editors.mid output new.block } if$
953       format.edition output
954       new.sentence
955       format.bvolume.or.num.series output
956       new.block
957       format.publisher "publisher" output.check
958       format.date "year" output.check
959       new.sentence
960       format.chapter.pages "chapter and pages" output.check
961       %address output
962     }
963     {
964       new.block
965       format.crossref output.nonnull
966     }
967   if$
968   new.block
969   format.url output
970   note output
971   fin.entry
972 }
973
974 FUNCTION {incollection}
975 { output.bibitem
976   format.authors "author" output.check
977   chapter empty$
978     { new.block type output }
979     'skip$
980   if$
981   new.block
982   format.title "title" output.check
983   type field.or.null sortify duplicate$ "definition" = swap$ "def." = or
984     { new.block "Def.~" chapter field.or.null * "chapter" output.check } 
985     'skip$
986   if$
987   new.block
988   crossref missing$
989     { 
990       booktitle emphasize "booktitle" output.check
991       new.block
992       format.editors.mid "editor" output.check
993       new.block
994       format.edition output
995       new.sentence
996       format.bvolume.or.num.series output
997       new.block
998       format.publisher "publisher" output.check
999       %address output
1000       format.date "year" output.check
1001       new.sentence
1002       format.chapter.pages output
1003     }
1004     { format.crossref output.nonnull
1005       %format.chapter.pages output
1006     }
1007   if$
1008   new.block
1009   format.url output
1010   new.block
1011   note output
1012   fin.entry
1013 }
1014
1015 FUNCTION {inproceedings}
1016 { output.bibitem
1017   format.authors "author" output.check
1018   new.block
1019   format.title "title" output.check
1020   new.block
1021   crossref missing$
1022     {
1023       booktitle "booktitle" output.check
1024       new.sentence
1025       format.editors.mid output
1026       new.block
1027       format.edition output
1028       new.sentence
1029       format.bvolume.or.num.series output
1030       new.block
1031       format.edition output
1032       new.sentence
1033       format.publisher output
1034       format.date "year" output.check
1035       %address empty$
1036         %{ organization publisher new.sentence.checkb
1037          % organization output
1038          % publisher output
1039          % format.date "year" output.check
1040         %}
1041         %{ address output.nonnull
1042          % format.date "year" output.check
1043          % new.sentence
1044          % organization output
1045          % publisher output
1046         %}
1047       %if$
1048       new.sentence
1049       format.pages output
1050     }
1051     { format.crossref output.nonnull
1052     }
1053   if$
1054   new.block
1055   format.url output
1056   new.block
1057   note output
1058   fin.entry
1059 }
1060
1061 FUNCTION {conference} { inproceedings }
1062
1063 FUNCTION {manual}
1064 { output.bibitem
1065   author empty$
1066     { organization empty$
1067         'skip$
1068         { organization output.nonnull
1069           address output
1070         }
1071       if$
1072     }
1073     { format.authors output.nonnull }
1074   if$
1075   new.block
1076   format.btitle "title" output.check
1077   new.block
1078   format.edition output
1079   new.sentence
1080   author empty$
1081     { organization empty$
1082         { address new.block.checka
1083           address output
1084         }
1085         'skip$
1086       if$
1087     }
1088     { organization address new.block.checkb
1089       organization output
1090       address output
1091     }
1092   if$
1093   format.date output
1094   new.block
1095   format.url output
1096   new.block
1097   note output
1098   fin.entry
1099 }
1100
1101 FUNCTION {mastersthesis}
1102 { output.bibitem
1103   format.authors "author" output.check
1104   new.block
1105   format.title "title" output.check
1106   new.block
1107   "Diss." format.thesis.type do.period output.nonnull
1108   after.title 'output.state :=
1109   school "school" output.check
1110   address output
1111   format.date "year" output.check
1112   new.block
1113   format.url output
1114   new.block
1115   note output
1116   fin.entry
1117 }
1118
1119 FUNCTION {misc}
1120 { output.bibitem
1121   format.authors output
1122   title howpublished new.block.checkb
1123   format.title output
1124   new.block
1125   %howpublished new.block.checka
1126   howpublished output
1127   format.date output
1128   new.block
1129   format.url output
1130   new.block
1131   note output
1132   fin.entry
1133   empty.misc.check
1134 }
1135
1136 FUNCTION {phdthesis}
1137 { output.bibitem
1138   format.authors "author" output.check
1139   new.block
1140   format.btitle "title" output.check
1141   new.block
1142   "Diss." format.thesis.type do.period output.nonnull
1143   after.title 'output.state :=
1144   school "school" output.check
1145   address output
1146   format.date "year" output.check
1147   new.block
1148   format.url output
1149   new.block
1150   note output
1151   fin.entry
1152 }
1153
1154 FUNCTION {proceedings}
1155 { output.bibitem
1156   editor empty$
1157     { organization output }
1158     { format.editors output.nonnull }
1159   if$
1160   new.block
1161   format.btitle "title" output.check
1162   new.block
1163   format.bvolume.or.num.series output
1164   address empty$
1165     { editor empty$
1166         { publisher new.sentence.checka }
1167         { organization publisher new.sentence.checkb
1168           organization output
1169         }
1170       if$
1171       publisher output
1172       format.date "year" output.check
1173     }
1174     { address output.nonnull
1175       format.date "year" output.check
1176       new.sentence
1177       editor empty$
1178         'skip$
1179         { organization output }
1180       if$
1181       publisher output
1182     }
1183   if$
1184   new.block
1185   format.url output
1186   new.block
1187   note output
1188   fin.entry
1189 }
1190
1191 FUNCTION {techreport}
1192 { output.bibitem
1193   format.authors "author" output.check
1194   new.block
1195   format.title "title" output.check
1196   new.block
1197   format.tr.number output.nonnull
1198   new.block
1199   institution "institution" output.check
1200   address output
1201   format.date "year" output.check
1202   new.block
1203   note output
1204   fin.entry
1205 }
1206
1207 FUNCTION {unpublished}
1208 { output.bibitem
1209   format.authors "author" output.check
1210   new.block
1211   format.title "title" output.check
1212   new.block
1213   format.url output
1214   new.block
1215   note "note" output.check
1216   format.date output
1217   fin.entry
1218 }
1219
1220 FUNCTION {default.type} { misc }
1221
1222 MACRO {jan} {"Jan."}
1223
1224 MACRO {feb} {"Feb."}
1225
1226 MACRO {mar} {"Mar."}
1227
1228 MACRO {apr} {"Apr."}
1229
1230 MACRO {may} {"May"}
1231
1232 MACRO {jun} {"June"}
1233
1234 MACRO {jul} {"July"}
1235
1236 MACRO {aug} {"Aug."}
1237
1238 MACRO {sep} {"Sept."}
1239
1240 MACRO {oct} {"Oct."}
1241
1242 MACRO {nov} {"Nov."}
1243
1244 MACRO {dec} {"Dec."}
1245
1246 % Currently left in to help with compatibility
1247
1248 MACRO {acmcs} {"ACM Computing Surveys"}
1249
1250 MACRO {acta} {"Acta Informatica"}
1251
1252 MACRO {cacm} {"Communications of the ACM"}
1253
1254 MACRO {ibmjrd} {"IBM Journal of Research and Development"}
1255
1256 MACRO {ibmsj} {"IBM Systems Journal"}
1257
1258 MACRO {ieeese} {"IEEE Transactions on Software Engineering"}
1259
1260 MACRO {ieeetc} {"IEEE Transactions on Computers"}
1261
1262 MACRO {ieeetcad}
1263  {"IEEE Transactions on Computer-Aided Design of Integrated Circuits"}
1264
1265 MACRO {ipl} {"Information Processing Letters"}
1266
1267 MACRO {jacm} {"Journal of the ACM"}
1268
1269 MACRO {jcss} {"Journal of Computer and System Sciences"}
1270
1271 MACRO {scp} {"Science of Computer Programming"}
1272
1273 MACRO {sicomp} {"SIAM Journal on Computing"}
1274
1275 MACRO {tocs} {"ACM Transactions on Computer Systems"}
1276
1277 MACRO {tods} {"ACM Transactions on Database Systems"}
1278
1279 MACRO {tog} {"ACM Transactions on Graphics"}
1280
1281 MACRO {toms} {"ACM Transactions on Mathematical Software"}
1282
1283 MACRO {toois} {"ACM Transactions on Office Information Systems"}
1284
1285 MACRO {toplas} {"ACM Transactions on Programming Languages and Systems"}
1286
1287 MACRO {tcs} {"Theoretical Computer Science"}
1288
1289 READ
1290
1291 INTEGERS { len }
1292
1293 FUNCTION {chop.word}
1294 { 's :=
1295   'len :=
1296   s #1 len substring$ =
1297     { s len #1 + global.max$ substring$ }
1298     's
1299   if$
1300 }
1301
1302 FUNCTION {sort.format.names}
1303 { 's :=
1304   #1 'nameptr :=
1305   ""
1306   s num.names$ 'numnames :=
1307   numnames 'namesleft :=
1308     { namesleft #0 > }
1309     { nameptr #1 >
1310         { "   " * }
1311         'skip$
1312       if$
1313       s nameptr "{vv{ } }{ll{ }}{  ff{ }}{  jj{ }}" format.name$ 't :=
1314       nameptr numnames = t "others" = and
1315         { "et al" * }
1316         { t sortify * }
1317       if$
1318       nameptr #1 + 'nameptr :=
1319       namesleft #1 - 'namesleft :=
1320     }
1321   while$
1322 }
1323
1324 FUNCTION {sort.format.title}
1325 { 't :=
1326   "A " #2
1327     "An " #3
1328       "The " #4
1329         "Rev. of " #8
1330           "Rev.~of " #8
1331             "Rev.\ of " #9
1332             t chop.word
1333           chop.word
1334         chop.word
1335       chop.word
1336     chop.word
1337   chop.word
1338   sortify
1339   #1 global.max$ substring$
1340 }
1341
1342 FUNCTION {author.sort}
1343 { author empty$
1344     { key empty$
1345         { "to sort, need author or key in " cite$ * warning$
1346           ""
1347         }
1348         { key sortify }
1349       if$
1350     }
1351     { author sort.format.names }
1352   if$
1353 }
1354
1355 FUNCTION {author.editor.sort}
1356 { author empty$
1357     { editor empty$
1358         { key empty$
1359             { "to sort, need author, editor, or key in " cite$ * warning$
1360               ""
1361             }
1362             { key sortify }
1363           if$
1364         }
1365         { editor sort.format.names }
1366       if$
1367     }
1368     { author sort.format.names }
1369   if$
1370 }
1371
1372 FUNCTION {author.organization.sort}
1373 { author empty$
1374     { organization empty$
1375         { key empty$
1376             { "to sort, need author, organization, or key in " cite$ * warning$
1377               ""
1378             }
1379             { key sortify }
1380           if$
1381         }
1382         { "The " #4 organization chop.word sortify }
1383       if$
1384     }
1385     { author sort.format.names }
1386   if$
1387 }
1388
1389 FUNCTION {editor.organization.sort}
1390 { editor empty$
1391     { organization empty$
1392         { key empty$
1393             { "to sort, need editor, organization, or key in " cite$ * warning$
1394               ""
1395             }
1396             { key sortify }
1397           if$
1398         }
1399         { "The " #4 organization chop.word sortify }
1400       if$
1401     }
1402     { editor sort.format.names }
1403   if$
1404 }
1405
1406 FUNCTION {presort}
1407 { type$ "book" =
1408   type$ "inbook" =
1409   or
1410     'author.editor.sort
1411     { type$ "proceedings" =
1412         'editor.organization.sort
1413         { type$ "manual" =
1414             'author.organization.sort
1415             'author.sort
1416           if$
1417         }
1418       if$
1419     }
1420   if$
1421   duplicate$ empty$ 'skip$ { "    " * } if$
1422   key empty$
1423     { title field.or.null sort.format.title * "    " * booktitle field.or.null sort.format.title * }
1424     { key sortify * }
1425   if$
1426   "    "
1427   *
1428   year field.or.null sortify
1429   *
1430   #1 entry.max$ substring$
1431   'sort.key$ :=
1432 }
1433
1434 ITERATE {presort}
1435
1436 SORT
1437
1438 STRINGS {a b}
1439
1440 FUNCTION {init.vars}
1441 { #0 int.to.chr$ 'a :=
1442   #0 int.to.chr$ 'b :=
1443   #0 'i :=
1444   #0 'j :=
1445 }
1446
1447 FUNCTION {forward.author.dup.check}
1448 {
1449   url empty$ 'skip$ { url.used #1 + 'url.used := } if$
1450   crossref empty$ 'skip$ { citealp.used #1 + 'citealp.used := } if$
1451   author empty$
1452     { editor empty$ { organization field.or.null 'a := }{ editor 'a :=} if$}
1453     { author 'a := }
1454   if$
1455   %'a :=
1456   a empty$
1457     'skip$
1458     { b "{ff~}{vv~}{ll}{, jj}" format.names.custom purify$
1459       a "{ff~}{vv~}{ll}{, jj}" format.names.custom purify$ =
1460         { #1 'author.duplicate := }
1461         { #0 'author.duplicate := }
1462       if$
1463       a 'b :=
1464     }
1465   if$
1466 }
1467
1468 FUNCTION {forward.author.share.check}
1469 %
1470 % Pass through all entries, comparing current author to last one.
1471 %
1472 { author.duplicate author empty$ or
1473   { author.duplicate { i 'author.shared := }{} if$}
1474   { b "{f.~}{vv~}{ll}{, jj}" format.names.custom purify$
1475     author field.or.null "{f.~}{vv~}{ll}{, jj}" format.names.custom purify$ =
1476     { author.flast 'author.shared := }
1477     { b "{vv~}{ll}" format.names.custom purify$
1478       author field.or.null "{vv~}{ll}" format.names.custom purify$ =
1479       { author.last 'author.shared := }
1480       { author.different 'author.shared := }
1481       if$
1482     }
1483     if$
1484     author.shared 'i :=
1485     author field.or.null 'b :=
1486   }
1487   if$
1488 }
1489
1490 FUNCTION {reverse.author}
1491
1492   author.duplicate
1493   { author.shared i <
1494       { i 'author.shared := }
1495       {}
1496     if$
1497   }
1498   { author.shared i <
1499       { author.shared i 'author.shared := 'i := }
1500       { author.shared 'i := }
1501     if$
1502   }
1503   if$
1504   j #1 = author.duplicate not and { #2 'author.duplicate := } {} if$
1505   author.duplicate 'j :=
1506 }
1507
1508 EXECUTE {init.consts}
1509
1510 EXECUTE {init.vars}
1511 ITERATE {forward.author.dup.check}
1512
1513 EXECUTE {init.vars}
1514 ITERATE {forward.author.share.check}
1515
1516 EXECUTE {init.vars}
1517 REVERSE {reverse.author}
1518
1519 %INTEGERS { number.label longest.label.width }
1520
1521 %FUNCTION {initialize.longest.label}
1522 %{ "" 'longest.label :=
1523 %  #1 'number.label :=
1524 %  #0 'longest.label.width :=
1525 %}
1526
1527 %FUNCTION {longest.label.pass}
1528 %{ number.label int.to.str$ 'label :=
1529 %  number.label #1 + 'number.label :=
1530 %  label width$ longest.label.width >
1531 %    { label 'longest.label :=
1532 %      label width$ 'longest.label.width :=
1533 %    }
1534 %    'skip$
1535 %  if$
1536 %}
1537
1538 %EXECUTE {initialize.longest.label}
1539
1540 %ITERATE {longest.label.pass}
1541
1542 FUNCTION {begin.bib}
1543 {
1544   citealp.used
1545     { "\expandafter\ifx\csname citealp\endcsname\relax\let\citealp\cite\fi"
1546       write$ newline$ }
1547     'skip$
1548   if$
1549   url.used
1550     { "\expandafter\ifx\csname citealp\endcsname\relax\url\let\url\relax\fi"
1551       write$ newline$ }
1552     'skip$
1553   if$
1554   preamble$ empty$
1555     'skip$
1556     { preamble$ write$ newline$ }
1557   if$
1558   "\begin{thebibliography}{\rule{.5in}{0pt}}" write$ newline$
1559 }
1560
1561 EXECUTE {begin.bib}
1562
1563 ITERATE {call.type$}
1564
1565 FUNCTION {end.bib}
1566 { newline$
1567   "\end{thebibliography}" write$ newline$
1568 }
1569
1570 EXECUTE {end.bib}