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