Fixed urlstyle
[latex-mlastyle.git] / mlastyle.bst
1 % $Id: mlastyle.bst,v 1.15 2003-11-23 05:09:53 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   school "school" output.check
1186   address output
1187   format.date "year" output.check
1188   new.block
1189   output.url
1190   new.block
1191   note output
1192   fin.entry
1193 }
1194
1195 FUNCTION {misc}
1196 { output.bibitem
1197   format.authors output
1198   title howpublished new.block.checkb
1199   format.title output
1200   new.block
1201   %howpublished new.block.checka
1202   howpublished output
1203   format.date output
1204   new.block
1205   output.url
1206   new.block
1207   note output
1208   fin.entry
1209   empty.misc.check
1210 }
1211
1212 FUNCTION {phdthesis}
1213 { output.bibitem
1214   format.authors "author" output.check
1215   new.block
1216   format.btitle "title" output.check
1217   new.block
1218   "Diss." format.thesis.type output.nonnull
1219   school "school" output.check
1220   address output
1221   format.date "year" output.check
1222   new.block
1223   output.url
1224   new.block
1225   note output
1226   fin.entry
1227 }
1228
1229 FUNCTION {proceedings}
1230 { output.bibitem
1231   editor empty$
1232     { organization output }
1233     { format.editors output.nonnull }
1234   if$
1235   new.block
1236   format.btitle "title" output.check
1237   new.block
1238   format.bvolume.or.num.series output
1239   address empty$
1240     { editor empty$
1241         { publisher new.sentence.checka }
1242         { organization publisher new.sentence.checkb
1243           organization output
1244         }
1245       if$
1246       publisher output
1247       format.date "year" output.check
1248     }
1249     { address output.nonnull
1250       format.date "year" output.check
1251       new.sentence
1252       editor empty$
1253         'skip$
1254         { organization output }
1255       if$
1256       publisher output
1257     }
1258   if$
1259   new.block
1260   output.url
1261   new.block
1262   note output
1263   fin.entry
1264 }
1265
1266 FUNCTION {techreport}
1267 { output.bibitem
1268   format.authors "author" output.check
1269   new.block
1270   format.title "title" output.check
1271   new.block
1272   format.tr.number output.nonnull
1273   new.block
1274   institution "institution" output.check
1275   address output
1276   format.date "year" output.check
1277   new.block
1278   note output
1279   fin.entry
1280 }
1281
1282 FUNCTION {unpublished}
1283 { output.bibitem
1284   format.authors "author" output.check
1285   new.block
1286   format.title "title" output.check
1287   new.block
1288   output.url
1289   new.block
1290   note "note" output.check
1291   format.date output
1292   fin.entry
1293 }
1294
1295 FUNCTION {default.type} { misc }
1296
1297 MACRO {jan} {"Jan."}
1298
1299 MACRO {feb} {"Feb."}
1300
1301 MACRO {mar} {"Mar."}
1302
1303 MACRO {apr} {"Apr."}
1304
1305 MACRO {may} {"May"}
1306
1307 MACRO {jun} {"June"}
1308
1309 MACRO {jul} {"July"}
1310
1311 MACRO {aug} {"Aug."}
1312
1313 MACRO {sep} {"Sept."}
1314
1315 MACRO {oct} {"Oct."}
1316
1317 MACRO {nov} {"Nov."}
1318
1319 MACRO {dec} {"Dec."}
1320
1321 % Currently left in to help with compatibility
1322
1323 MACRO {acmcs} {"ACM Computing Surveys"}
1324
1325 MACRO {acta} {"Acta Informatica"}
1326
1327 MACRO {cacm} {"Communications of the ACM"}
1328
1329 MACRO {ibmjrd} {"IBM Journal of Research and Development"}
1330
1331 MACRO {ibmsj} {"IBM Systems Journal"}
1332
1333 MACRO {ieeese} {"IEEE Transactions on Software Engineering"}
1334
1335 MACRO {ieeetc} {"IEEE Transactions on Computers"}
1336
1337 MACRO {ieeetcad}
1338  {"IEEE Transactions on Computer-Aided Design of Integrated Circuits"}
1339
1340 MACRO {ipl} {"Information Processing Letters"}
1341
1342 MACRO {jacm} {"Journal of the ACM"}
1343
1344 MACRO {jcss} {"Journal of Computer and System Sciences"}
1345
1346 MACRO {scp} {"Science of Computer Programming"}
1347
1348 MACRO {sicomp} {"SIAM Journal on Computing"}
1349
1350 MACRO {tocs} {"ACM Transactions on Computer Systems"}
1351
1352 MACRO {tods} {"ACM Transactions on Database Systems"}
1353
1354 MACRO {tog} {"ACM Transactions on Graphics"}
1355
1356 MACRO {toms} {"ACM Transactions on Mathematical Software"}
1357
1358 MACRO {toois} {"ACM Transactions on Office Information Systems"}
1359
1360 MACRO {toplas} {"ACM Transactions on Programming Languages and Systems"}
1361
1362 MACRO {tcs} {"Theoretical Computer Science"}
1363
1364 READ
1365
1366 INTEGERS { len }
1367
1368 FUNCTION {chop.word}
1369 { 's :=
1370   'len :=
1371   s #1 len substring$ =
1372     { s len #1 + global.max$ substring$ }
1373     's
1374   if$
1375 }
1376
1377 FUNCTION {sort.format.names}
1378 { 's :=
1379   #1 'nameptr :=
1380   ""
1381   s num.names$ 'numnames :=
1382   numnames 'namesleft :=
1383     { namesleft #0 > }
1384     { nameptr #1 >
1385         { "   " * }
1386         'skip$
1387       if$
1388       s nameptr "{vv{ } }{ll{ }}{  ff{ }}{  jj{ }}" format.name$ 't :=
1389       nameptr numnames = t "others" = and
1390         { "et al" * }
1391         { t sortify * }
1392       if$
1393       nameptr #1 + 'nameptr :=
1394       namesleft #1 - 'namesleft :=
1395     }
1396   while$
1397 }
1398
1399 FUNCTION {sort.format.title}
1400 { 't :=
1401   "A " #2
1402     "An " #3
1403       "The " #4
1404         "Rev. of " #8
1405           "Rev.~of " #8
1406             "Rev.\ of " #9
1407             t chop.word
1408           chop.word
1409         chop.word
1410       chop.word
1411     chop.word
1412   chop.word
1413   sortify
1414   #1 global.max$ substring$
1415 }
1416
1417 FUNCTION {author.sort}
1418 { author empty$
1419     { key empty$
1420         { "to sort, need author or key in " cite$ * warning$
1421           ""
1422         }
1423         { key sortify }
1424       if$
1425     }
1426     { author sort.format.names }
1427   if$
1428 }
1429
1430 FUNCTION {author.editor.sort}
1431 { author empty$
1432     { editor empty$
1433         { key empty$
1434             { "to sort, need author, editor, or key in " cite$ * warning$
1435               ""
1436             }
1437             { key sortify }
1438           if$
1439         }
1440         { editor sort.format.names }
1441       if$
1442     }
1443     { author sort.format.names }
1444   if$
1445 }
1446
1447 FUNCTION {author.organization.sort}
1448 { author empty$
1449     { organization empty$
1450         { key empty$
1451             { "to sort, need author, organization, or key in " cite$ * warning$
1452               ""
1453             }
1454             { key sortify }
1455           if$
1456         }
1457         { "The " #4 organization chop.word sortify }
1458       if$
1459     }
1460     { author sort.format.names }
1461   if$
1462 }
1463
1464 FUNCTION {editor.organization.sort}
1465 { editor empty$
1466     { organization empty$
1467         { key empty$
1468             { "to sort, need editor, organization, or key in " cite$ * warning$
1469               ""
1470             }
1471             { key sortify }
1472           if$
1473         }
1474         { "The " #4 organization chop.word sortify }
1475       if$
1476     }
1477     { editor sort.format.names }
1478   if$
1479 }
1480
1481 FUNCTION {presort}
1482 { type$ "book" =
1483   type$ "inbook" =
1484   or
1485     'author.editor.sort
1486     { type$ "proceedings" =
1487         'editor.organization.sort
1488         { type$ "manual" =
1489             'author.organization.sort
1490             'author.sort
1491           if$
1492         }
1493       if$
1494     }
1495   if$
1496   duplicate$ empty$ 'skip$ { "    " * } if$
1497   key empty$
1498     { title field.or.null sort.format.title * "    " * booktitle field.or.null sort.format.title * }
1499     { key sortify * }
1500   if$
1501   "    "
1502   *
1503   year field.or.null sortify
1504   *
1505   #1 entry.max$ substring$
1506   'sort.key$ :=
1507 }
1508
1509 ITERATE {presort}
1510
1511 SORT
1512
1513 STRINGS {a b}
1514
1515 FUNCTION {init.vars}
1516 { #0 int.to.chr$ 'a :=
1517   #0 int.to.chr$ 'b :=
1518   #0 'i :=
1519   #0 'j :=
1520 }
1521
1522 % Function name is not strictly accurate
1523 FUNCTION {forward.author.dup.check}
1524 {
1525   url empty$ urlpath empty$ urldate empty$ and and
1526     'skip$
1527     { url.used #1 + 'url.used := }
1528   if$
1529   crossref empty$ 'skip$ { citealp.used #1 + 'citealp.used := } if$
1530   author empty$
1531     { editor empty$ { organization field.or.null 'a := }{ editor 'a :=} if$}
1532     { author 'a := }
1533   if$
1534   %'a :=
1535   a empty$
1536     'skip$
1537     { b "{ff~}{vv~}{ll}{, jj}" format.names.custom purify$
1538       a "{ff~}{vv~}{ll}{, jj}" format.names.custom purify$ =
1539         { #1 'author.duplicate := }
1540         { #0 'author.duplicate := }
1541       if$
1542       a 'b :=
1543     }
1544   if$
1545 }
1546
1547 FUNCTION {forward.author.share.check}
1548 %
1549 % Pass through all entries, comparing current author to last one.
1550 %
1551 { author.duplicate author empty$ or
1552   { author.duplicate { i 'author.shared := }{} if$}
1553   { b "{f.~}{vv~}{ll}{, jj}" format.names.custom purify$
1554     author field.or.null "{f.~}{vv~}{ll}{, jj}" format.names.custom purify$ =
1555     { author.flast 'author.shared := }
1556     { b "{vv~}{ll}" format.names.custom purify$
1557       author field.or.null "{vv~}{ll}" format.names.custom purify$ =
1558       { author.last 'author.shared := }
1559       { author.different 'author.shared := }
1560       if$
1561     }
1562     if$
1563     author.shared 'i :=
1564     author field.or.null 'b :=
1565   }
1566   if$
1567 }
1568
1569 FUNCTION {reverse.author}
1570
1571   author.duplicate
1572   { author.shared i <
1573       { i 'author.shared := }
1574       {}
1575     if$
1576   }
1577   { author.shared i <
1578       { author.shared i 'author.shared := 'i := }
1579       { author.shared 'i := }
1580     if$
1581   }
1582   if$
1583   j #1 = author.duplicate not and { #2 'author.duplicate := } {} if$
1584   author.duplicate 'j :=
1585 }
1586
1587 EXECUTE {init.consts}
1588
1589 EXECUTE {init.vars}
1590 ITERATE {forward.author.dup.check}
1591
1592 EXECUTE {init.vars}
1593 ITERATE {forward.author.share.check}
1594
1595 EXECUTE {init.vars}
1596 REVERSE {reverse.author}
1597
1598 %INTEGERS { number.label longest.label.width }
1599
1600 %FUNCTION {initialize.longest.label}
1601 %{ "" 'longest.label :=
1602 %  #1 'number.label :=
1603 %  #0 'longest.label.width :=
1604 %}
1605
1606 %FUNCTION {longest.label.pass}
1607 %{ number.label int.to.str$ 'label :=
1608 %  number.label #1 + 'number.label :=
1609 %  label width$ longest.label.width >
1610 %    { label 'longest.label :=
1611 %      label width$ 'longest.label.width :=
1612 %    }
1613 %    'skip$
1614 %  if$
1615 %}
1616
1617 %EXECUTE {initialize.longest.label}
1618
1619 %ITERATE {longest.label.pass}
1620
1621 FUNCTION {begin.bib}
1622 {
1623   citealp.used
1624     { "\expandafter\ifx\csname citealp\endcsname\relax\let\citealp\cite\fi"
1625       write$ newline$
1626     }
1627     'skip$
1628   if$
1629   url.used
1630     { "\providecommand\url[1]{\texttt{#1}}"
1631       write$ newline$
1632       "\providecommand\theurldate{\today}"
1633       write$ newline$
1634     }
1635     'skip$
1636   if$
1637   preamble$ empty$
1638     'skip$
1639     { preamble$ write$ newline$ }
1640   if$
1641   "\begin{thebibliography}{\rule{.5in}{0pt}}" write$ newline$
1642 }
1643
1644 EXECUTE {begin.bib}
1645
1646 ITERATE {call.type$}
1647
1648 FUNCTION {end.bib}
1649 { newline$
1650   "\end{thebibliography}" write$ newline$
1651 }
1652
1653 EXECUTE {end.bib}