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