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