bst: separate names with ' - ' instead of 'and'
[lematema] / lematema.bst
1 %%% ====================================================================
2 %%%  @BibTeX-style-file{
3 %%%     filename        = "lematema.bst",
4 %%%     version         = "0.1",
5 %%%     date            = "2007/11/19",
6 %%%     abstract        = "BibTeX bibliography style `lematema' for BibTeX
7 %%%                        versions 0.99a or later and LaTeX version 2e.
8 %%%                        Produces numeric-label bibliography items in
9 %%%                        a form typical for the Le Matematiche.
10 %%%                        Based on amsplain.bst"
11 %%%  }
12 %%% ====================================================================
13
14 % This defines the types of fields that can occur in a database entry
15 % for this particular bibliography style.  Except for `language',
16 % this is the standard list from plain.bst.
17
18 %% Types of entries currently allowed in a BibTeX file:
19 %%
20 %% ARTICLE -- An article from a journal or magazine.
21 %%
22 %% BOOK -- A book with an explicit publisher.
23 %%
24 %% BOOKLET -- A work that is printed and bound,
25 %% but without a named publisher or sponsoring institution.
26 %%
27 %% CONFERENCE -- The same as INPROCEEDINGS,
28 %% included for Scribe compatibility.
29 %%
30 %% INBOOK -- A part of a book,
31 %% which may be a chapter (or section or whatever) and/or a range of pages.
32 %%
33 %% INCOLLECTION -- A part of a book having its own title.
34 %%
35 %% INPROCEEDINGS -- An article in a conference proceedings.
36 %%
37 %% MANUAL -- Technical documentation.
38 %%
39 %% MASTERSTHESIS -- A Master's thesis.
40 %%
41 %% MISC -- Use this type when nothing else fits.
42 %%
43 %% PHDTHESIS -- A PhD thesis.
44 %%
45 %% PROCEEDINGS -- The proceedings of a conference.
46 %%
47 %% TECHREPORT -- A report published by a school or other institution,
48 %% usually numbered within a series.
49 %%
50 %% UNPUBLISHED -- A document having an author and title, but not formally
51 %% published.
52
53 ENTRY
54   { address
55     author
56     booktitle
57     chapter
58     edition
59     editor
60     howpublished
61     institution
62     journal
63     key
64     language
65     month
66     mrnumber
67     note
68     number
69     organization
70     pages
71     publisher
72     school
73     series
74     title
75     type
76     volume
77     year
78   }
79   {}
80   { label bysame }
81
82 % Removed after.sentence, after.block---not needed.
83
84 INTEGERS { output.state before.all mid.sentence }
85
86 FUNCTION {init.state.consts}
87 { #0 'before.all :=
88   #1 'mid.sentence :=
89 }
90
91 % Scratch variables:
92
93 STRINGS { s t }
94
95 % Utility functions
96
97 FUNCTION {shows}
98 { duplicate$ "::::  `" swap$ * "'" * top$
99 }
100
101 FUNCTION {showstack}
102 {"STACK====================================================================="
103 top$
104 stack$
105 "ENDSTACK=================================================================="
106 top$
107 }
108
109 FUNCTION {not}
110 {   { #0 }
111     { #1 }
112   if$
113 }
114
115 FUNCTION {and}
116 {   'skip$
117     { pop$ #0 }
118   if$
119 }
120
121 FUNCTION {or}
122 {   { pop$ #1 }
123     'skip$
124   if$
125 }
126
127 FUNCTION {field.or.null}
128 { duplicate$ empty$
129     { pop$ "" }
130     'skip$
131   if$
132 }
133
134 FUNCTION {emphasize}
135 { duplicate$ empty$
136     { pop$ "" }
137     { "\emph{" swap$ * "}" * }
138   if$
139 }
140
141 % n.dashify is used to make sure page ranges get the TeX code
142 % (two hyphens) for en-dashes.
143
144 FUNCTION {n.dashify}
145 { 't :=
146   ""
147     { t empty$ not }
148     { t #1 #1 substring$ "-" =
149         { t #1 #2 substring$ "--" = not
150             { "--" *
151               t #2 global.max$ substring$ 't :=
152             }
153             {   { t #1 #1 substring$ "-" = }
154                 { "-" *
155                   t #2 global.max$ substring$ 't :=
156                 }
157               while$
158             }
159           if$
160         }
161         { t #1 #1 substring$ *
162           t #2 global.max$ substring$ 't :=
163         }
164       if$
165     }
166   while$
167 }
168
169 % tie.or.space.connect connects two items with a ~ if the
170 % second item is less than 3 letters long, otherwise it just puts an
171 % ordinary space.
172
173 FUNCTION {tie.or.space.connect}
174 { duplicate$ text.length$ #3 <
175     { "~" }
176     { " " }
177   if$
178   swap$ * *
179 }
180
181 FUNCTION {add.space.if.necessary}
182 { duplicate$ "" =
183     'skip$
184     { " " * }
185   if$
186 }
187
188 % either.or.check gives a warning if two mutually exclusive fields
189 % were used in the database.
190
191 FUNCTION {either.or.check}
192 { empty$
193     'pop$
194     { "can't use both " swap$ * " fields in " * cite$ * warning$ }
195   if$
196 }
197
198 % output.nonnull is called by output.
199
200 FUNCTION {output.nonnull}
201 % remove the top item from the stack because it's in the way.
202 { 's :=
203   output.state mid.sentence =
204 % If we're in mid-sentence, add a comma to the new top item and write it
205     { ", " * write$ }
206 % Otherwise, if we're at the beginning of a bibitem,
207     { output.state before.all =
208 % just write out the top item from the stack;
209       'write$
210 % and the last alternative is that we're at the end of the current
211 % bibitem, so we add a period to the top stack item and write it out.
212         { add.period$ " " * write$ }
213       if$
214       mid.sentence 'output.state :=
215     }
216   if$
217 % Put the top item back on the stack that we removed earlier.
218   s
219 }
220
221 % Output checks to see if the stack top is empty; if not, it
222 % calls output.nonnull to write it out.
223
224 FUNCTION {output}
225 { duplicate$ empty$
226     'pop$
227     'output.nonnull
228   if$
229 }
230
231 % Standard warning message for a missing or empty field. For the user
232 % we call any such field `missing' without respect to the distinction
233 % made by BibTeX between missing and empty.
234
235 FUNCTION {missing.warning}
236 { "missing " swap$ * " in " * cite$ * warning$ }
237
238 % Output.check is like output except that it gives a warning on-screen
239 % if the given field in the database entry is empty.  t is the field
240 % name.
241
242 FUNCTION {output.check}
243 { 't :=
244   duplicate$ empty$
245     { pop$ t missing.warning }
246     'output.nonnull
247   if$
248 }
249
250 FUNCTION {output.bibitem}
251 { newline$
252   "\bibitem{" write$
253   cite$ write$
254   "}" write$
255   newline$
256 % This empty string is the first thing that will be written
257 % the next time write$ is called.  Done this way because each
258 % item is saved on the stack until we find out what punctuation
259 % should be added after it.  Therefore we need an empty first item.
260   ""
261   before.all 'output.state :=
262 }
263
264 FUNCTION {output.nonempty.mrnumber}
265 { duplicate$ missing$
266     { pop$ "" }
267     'skip$
268   if$
269   duplicate$ empty$
270     'pop$
271     { " \MR{" swap$ * "}" * write$ }
272   if$
273 }
274
275 FUNCTION {fin.entry}
276 { add.period$
277   write$
278   mrnumber output.nonempty.mrnumber
279   newline$
280 }
281
282 % Removed new.block, new.block.checka, new.block.checkb, new.sentence,
283 % new.sentence.checka, and new.sentence.checkb functions here, since they
284 % don't seem to be needed in the AMS style.  Also moved some real
285 % basic functions like `and' and 'or' earlier in the file.
286
287 INTEGERS { nameptr namesleft numnames }
288
289 % The extra section to write out a language field was added
290 % for AMSPLAIN.BST.  Not present in plain.bst.
291
292 FUNCTION {format.language}
293 { language empty$
294     { "" }
295     { " (" language * ")" * }
296   if$
297 }
298
299 % This version of format.names puts names in the format
300 %
301 % First von Last, Jr.
302 %
303 % (i.e., first name first, no abbreviating to initials).
304
305 FUNCTION {format.names}
306 { 's :=
307   #1 'nameptr :=
308   s num.names$ 'numnames :=
309   numnames 'namesleft :=
310     { namesleft #0 > }
311     { s nameptr "{ff~}{vv~}{ll}{, jj}" format.name$ 't :=
312       nameptr #1 >
313         { namesleft #1 >
314             { " - " * t * }
315             { }
316           if$
317         }
318         't
319       if$
320       nameptr #1 + 'nameptr :=
321       namesleft #1 - 'namesleft :=
322     }
323   while$
324 }
325
326 FUNCTION {format.authors}
327 { author empty$
328     { "" }
329     { bysame "\bysame" =
330          {"\bysame"}
331          { author format.names }
332      if$
333     }
334   if$
335 }
336
337 FUNCTION {format.editors}
338 { editor empty$
339     { "" }
340     { editor format.names
341       editor num.names$ #1 >
342         { " (eds.)" * }
343         { " (ed.)" * }
344       if$
345     }
346   if$
347 }
348
349 FUNCTION {format.nonauthor.editors}
350 { editor empty$
351     { "" }
352     { editor format.names
353       editor num.names$ #1 >
354         { ", eds." * }
355         { ", ed." * }
356       if$
357     }
358   if$
359 }
360
361 FUNCTION {format.title}
362 { title empty$
363     { "" }
364     { title "t" change.case$ emphasize }
365   if$
366 }
367
368 FUNCTION {format.journal.vol.year}
369 { journal empty$
370     { "journal name" missing.warning ""}
371     { journal }
372   if$
373   volume empty$
374     'skip$
375     { " \textbf{" * volume * "}" * }
376   if$
377   year empty$
378     { "year" missing.warning }
379     { " (" * year * ")" * }
380   if$
381 }
382
383 % For formatting the issue number for a journal article.
384
385 FUNCTION {format.number}
386 { number empty$
387     { "" }
388     { "no.~" number * }
389   if$
390 }
391
392 % For formatting miscellaneous dates
393
394 FUNCTION {format.date}
395 { year empty$
396     { month empty$
397         { "" }
398         { "there's a month but no year in " cite$ * warning$
399           month
400         }
401       if$
402     }
403     { month empty$
404         'year
405         { month " " * year * }
406       if$
407     }
408   if$
409 }
410
411 %%      The volume, series and number information is sort of tricky.
412 %%      This code handles it as follows:
413 %%      If the series is present, and the volume, but not the number,
414 %%        then we do "\emph{Book title}, Series Name, vol. 000"
415 %%      If the series is present, and the number, but not the volume,
416 %%        then we do "\emph{Book title}, Series Name, no. 000"
417 %%      If the series is present, and both number and volume,
418 %%        then we do "\emph{Book title}, vol. XX, Series Name, no. 000"
419 %%      Finally, if the series is absent,
420 %%        then we do "\emph{Book title}, vol. XX"
421 %%        or         "\emph{Book title}, no. 000"
422 %%        and if both volume and number are present, give a warning message.
423
424 FUNCTION {format.bookvolume.series.number}
425 { volume empty$
426     { "" % Push the empty string as a placeholder in case everything else
427          % is empty too.
428       series empty$
429         'skip$
430         { pop$ series } % if series is not empty put in stack
431       if$
432       number empty$
433         'skip$
434         { duplicate$ empty$ % if no preceding material,
435             'skip$          % do nothing, otherwise
436             { ", " * }      % add a comma and space to separate.
437           if$
438           "no." number tie.or.space.connect * % add the number information
439         }
440       if$
441     }
442 %% If the volume is NOT EMPTY:
443     { "vol." volume tie.or.space.connect % vol. XX
444       number empty$
445         { series empty$
446             'skip$
447             { series ", " * swap$ *}    % Series Name, vol. XX
448           if$
449         }
450         { series empty$
451             { "can't use both volume and number if series info is missing"
452               warning$
453               "in BibTeX entry type `" type$ * "'" * top$
454             }
455             { ", " * series * ", no." * number tie.or.space.connect }
456           if$
457         }
458       if$
459     }
460   if$
461
462 }  % end of format.bookvolume.series.number
463
464 %% format.inproc.title.where.editors is used by inproceedings entry types
465
466 %%      No case changing or emphasizing for the title.  We want initial
467 %%      caps, roman.
468 %%      We add parentheses around the address (place where conference
469 %%      was held).
470 %%      Likewise we add parentheses around the editors' names.
471
472 FUNCTION {format.inproc.title.address.editors}
473 { booktitle empty$
474     { "" }
475     { booktitle
476       address empty$
477         'skip$
478         { add.space.if.necessary "(" * address * ")" * }
479       if$
480       editor empty$
481         'skip$
482         { add.space.if.necessary "(" * format.nonauthor.editors * ")" * }
483       if$
484     }
485   if$
486 }
487
488 %% format.incoll.title.editors is similar to format.inproc... but
489 %% omits the address. For collections that are not proceedings volumes.
490
491 FUNCTION {format.incoll.title.editors}
492 { booktitle empty$
493     { "" }
494     { editor empty$
495         { booktitle }
496         { booktitle
497           add.space.if.necessary "(" * format.nonauthor.editors * ")" *
498         }
499       if$
500     }
501   if$
502 }
503
504 FUNCTION {format.edition}
505 { edition empty$
506     { "" }
507     { output.state mid.sentence =
508         { edition "l" change.case$ " ed." * }
509         { edition "t" change.case$ " ed." * }
510       if$
511     }
512   if$
513 }
514
515 INTEGERS { multiresult }
516
517 FUNCTION {multi.page.check}
518 { 't :=
519   #0 'multiresult :=
520     { multiresult not
521       t empty$ not
522       and
523     }
524     { t #1 #1 substring$
525       duplicate$ "-" =
526       swap$ duplicate$ "," =
527       swap$ "+" =
528       or or
529         { #1 'multiresult := }
530         { t #2 global.max$ substring$ 't := }
531       if$
532     }
533   while$
534   multiresult
535 }
536
537 FUNCTION {format.pages}
538 { pages empty$
539     { "" }
540     { pages n.dashify }
541   if$
542 }
543
544 FUNCTION {format.book.pages}
545 { pages empty$
546     { "" }
547     { pages multi.page.check
548         { "pp.~" pages n.dashify * }
549         { "p.~" pages * }
550       if$
551     }
552   if$
553 }
554
555 FUNCTION {format.chapter.pages}
556 { chapter empty$
557     'format.book.pages
558     { type empty$
559         { "ch.~" }
560         { type "l" change.case$ " " * }
561       if$
562       chapter *
563       pages empty$
564         'skip$
565         { ", " * format.book.pages * }
566       if$
567     }
568   if$
569 }
570
571 FUNCTION {empty.misc.check}
572 { author empty$ title empty$ howpublished empty$
573   month empty$ year empty$ note empty$
574   and and and and and
575   key empty$ not and
576     { "all relevant fields are empty in " cite$ * warning$ }
577     'skip$
578   if$
579 }
580
581 FUNCTION {format.thesis.type}
582 { type empty$
583     'skip$
584     { pop$
585       type "t" change.case$
586     }
587   if$
588 }
589
590 FUNCTION {format.tr.number}
591 { type empty$
592     { "Tech. Report" }
593     'type
594   if$
595   number empty$
596     { "t" change.case$ }
597     { number tie.or.space.connect }
598   if$
599 }
600
601 % The format.crossref functions haven't been paid much attention
602 % at the present time (June 1990) and could probably use some
603 % work.  MJD
604
605 FUNCTION {format.article.crossref}
606 { key empty$
607     { journal empty$
608         { "need key or journal for " cite$ * " to crossref " * crossref *
609           warning$
610           ""
611         }
612         { "in " journal * }
613       if$
614     }
615     { "in " key * }
616   if$
617   " \cite{" * crossref * "}" *
618 }
619
620 FUNCTION {format.crossref.editor}
621 { editor #1 "{vv~}{ll}" format.name$
622   editor num.names$ duplicate$
623   #2 >
624     { pop$ " et~al." * }
625     { #2 <
626         'skip$
627         { editor #2 "{ff }{vv }{ll}{ jj}" format.name$ "others" =
628             { " et~al." * }
629             { " and " * editor #2 "{vv~}{ll}" format.name$ * }
630           if$
631         }
632       if$
633     }
634   if$
635 }
636
637 FUNCTION {format.book.crossref}
638 { volume empty$
639     { "empty volume in " cite$ * "'s crossref of " * crossref * warning$
640       "in "
641     }
642     { "vol." volume tie.or.space.connect
643       " of " *
644     }
645   if$
646   editor empty$
647   editor field.or.null author field.or.null =
648   or
649     { key empty$
650         { series empty$
651             { "need editor, key, or series for " cite$ * " to crossref " *
652               crossref * warning$
653               "" *
654             }
655             { series * }
656           if$
657         }
658         { key * }
659       if$
660     }
661     { format.crossref.editor * }
662   if$
663   " \cite{" * crossref * "}" *
664 }
665
666 FUNCTION {format.incoll.inproc.crossref}
667 { editor empty$
668   editor field.or.null author field.or.null =
669   or
670     { key empty$
671         { booktitle empty$
672             { "need editor, key, or booktitle for " cite$ * " to crossref " *
673               crossref * warning$
674               ""
675             }
676             { "in \emph{" booktitle * "}" * }
677           if$
678         }
679         { "in " key * }
680       if$
681     }
682     { "in " format.crossref.editor * }
683   if$
684   " \cite{" * crossref * "}" *
685 }
686
687 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
688
689 % The main functions for each entry type.
690
691 % journal, vol and year are formatted together because they are
692 % not separated by commas.
693
694 FUNCTION {article}
695 { output.bibitem
696   format.authors "author" output.check
697   format.title "title" output.check
698   crossref missing$
699     { format.journal.vol.year output
700       format.number output
701       format.pages "pages" output.check
702     }
703     { format.article.crossref output.nonnull
704       format.pages "pages" output.check
705     }
706   if$
707   format.language *
708   note output
709   fin.entry
710 }
711
712 FUNCTION {book}
713 { output.bibitem
714   author empty$
715     { format.editors "author and editor" output.check }
716     { format.authors output.nonnull
717       crossref missing$
718         { "author and editor" editor either.or.check }
719         'skip$
720       if$
721     }
722   if$
723   format.title "title" output.check
724   format.edition output
725   crossref missing$
726     { format.bookvolume.series.number output
727       publisher "publisher" output.check
728       address output
729     }
730     { format.book.crossref output.nonnull
731     }
732   if$
733   format.date "year" output.check
734   format.language *
735   note output
736   fin.entry
737 }
738
739 FUNCTION {booklet}
740 { output.bibitem
741   format.authors output
742   format.title "title" output.check
743   howpublished output
744   address output
745   format.date output
746   note output
747   fin.entry
748 }
749
750 FUNCTION {inbook}
751 { output.bibitem
752   author empty$
753     { format.editors "author and editor" output.check }
754     { format.authors output.nonnull
755       crossref missing$
756         { "author and editor" editor either.or.check }
757         'skip$
758       if$
759     }
760   if$
761   format.title "title" output.check
762   format.edition output
763   crossref missing$
764     { format.bookvolume.series.number output
765       format.chapter.pages "chapter and pages" output.check
766       publisher "publisher" output.check
767       address output
768     }
769     { format.chapter.pages "chapter and pages" output.check
770       format.book.crossref output.nonnull
771     }
772   if$
773   format.date "year" output.check
774   format.language *
775   note output
776   fin.entry
777 }
778
779 FUNCTION {incollection}
780 { output.bibitem
781   format.authors "author" output.check
782   format.title "title" output.check
783   crossref missing$
784     { format.incoll.title.editors "booktitle" output.check
785       format.bookvolume.series.number output
786       publisher "publisher" output.check
787       address output
788       format.edition output
789       format.date "year" output.check
790     }
791     { format.incoll.inproc.crossref output.nonnull
792     }
793   if$
794   note output
795   format.book.pages output
796   format.language *
797   fin.entry
798 }
799
800 FUNCTION {inproceedings}
801 { output.bibitem
802   format.authors "author" output.check
803   format.title "title" output.check
804   crossref missing$
805     { format.inproc.title.address.editors "booktitle" output.check
806       format.bookvolume.series.number output
807       organization output
808       publisher output
809       format.date "year" output.check
810     }
811     { format.incoll.inproc.crossref output.nonnull
812     }
813   if$
814   note output
815   format.book.pages output
816   format.language *
817   fin.entry
818 }
819
820 FUNCTION {conference} { inproceedings }
821
822 FUNCTION {manual}
823 { output.bibitem
824   author empty$
825     { organization empty$
826         'skip$
827         { organization output.nonnull
828           address output
829         }
830       if$
831     }
832     { format.authors output.nonnull }
833   if$
834   format.title "title" output.check
835   author empty$
836     { organization empty$
837         { address output }
838         'skip$
839       if$
840     }
841     { organization output
842       address output
843     }
844   if$
845   format.edition output
846   format.date output
847   note output
848   fin.entry
849 }
850
851 FUNCTION {mastersthesis}
852 { output.bibitem
853   format.authors "author" output.check
854   format.title "title" output.check
855   "Master's thesis" format.thesis.type output.nonnull
856   school "school" output.check
857   address output
858   format.date "year" output.check
859   note output
860   format.book.pages output
861   fin.entry
862 }
863
864 FUNCTION {misc}
865 { output.bibitem
866   format.authors output
867   format.title output
868   howpublished output
869   format.date output
870   note output
871   format.book.pages output
872   fin.entry
873   empty.misc.check
874 }
875
876 FUNCTION {phdthesis}
877 { output.bibitem
878   format.authors "author" output.check
879   format.title "title" output.check
880   "Ph.D. thesis" format.thesis.type output.nonnull
881   school "school" output.check
882   address output
883   format.date "year" output.check
884   note output
885   format.book.pages output
886   fin.entry
887 }
888
889 FUNCTION {proceedings}
890 { output.bibitem
891   editor empty$
892     { organization output }
893     { format.editors output.nonnull }
894   if$
895   format.title "title" output.check
896   format.bookvolume.series.number output
897   address empty$
898     { editor empty$
899         'skip$
900         { organization output }
901       if$
902       publisher output
903       format.date "year" output.check
904     }
905     { address output.nonnull
906       editor empty$
907         'skip$
908         { organization output }
909       if$
910       publisher output
911       format.date "year" output.check
912     }
913   if$
914   note output
915   fin.entry
916 }
917
918 FUNCTION {techreport}
919 { output.bibitem
920   format.authors "author" output.check
921   format.title "title" output.check
922   format.tr.number output.nonnull
923   institution "institution" output.check
924   address output
925   format.date "year" output.check
926   note output
927   fin.entry
928 }
929
930 FUNCTION {unpublished}
931 { output.bibitem
932   format.authors "author" output.check
933   format.title "title" output.check
934   note "note" output.check
935   format.date output
936   fin.entry
937 }
938
939 FUNCTION {default.type} { misc }
940
941 MACRO {jan} {"January"}
942
943 MACRO {feb} {"February"}
944
945 MACRO {mar} {"March"}
946
947 MACRO {apr} {"April"}
948
949 MACRO {may} {"May"}
950
951 MACRO {jun} {"June"}
952
953 MACRO {jul} {"July"}
954
955 MACRO {aug} {"August"}
956
957 MACRO {sep} {"September"}
958
959 MACRO {oct} {"October"}
960
961 MACRO {nov} {"November"}
962
963 MACRO {dec} {"December"}
964
965 READ
966
967 FUNCTION {sortify}
968 { purify$
969   "l" change.case$
970 }
971
972 INTEGERS { len }
973
974 FUNCTION {chop.word}
975 { 's :=
976   'len :=
977   s #1 len substring$ =
978     { s len #1 + global.max$ substring$ }
979     's
980   if$
981 }
982
983 FUNCTION {sort.format.names}
984 { 's :=
985   #1 'nameptr :=
986   ""
987   s num.names$ 'numnames :=
988   numnames 'namesleft :=
989     { namesleft #0 > }
990     { nameptr #1 >
991         { "   " * }
992         'skip$
993       if$
994       s nameptr "{vv{ } }{ll{ }}{  ff{ }}{  jj{ }}" format.name$ 't :=
995       nameptr numnames = t "others" = and
996         { "et al" * }
997         { t sortify * }
998       if$
999       nameptr #1 + 'nameptr :=
1000       namesleft #1 - 'namesleft :=
1001     }
1002   while$
1003 }
1004
1005 FUNCTION {sort.format.title}
1006 { 't :=
1007   "A " #2
1008     "An " #3
1009       "The " #4 t chop.word
1010     chop.word
1011   chop.word
1012   sortify
1013   #1 global.max$ substring$
1014 }
1015
1016 FUNCTION {author.sort}
1017 { author empty$
1018     { key empty$
1019         { "to sort, need author or key in " cite$ * warning$
1020           ""
1021         }
1022         { key sortify }
1023       if$
1024     }
1025     { author sort.format.names }
1026   if$
1027 }
1028
1029 FUNCTION {author.editor.sort}
1030 { author empty$
1031     { editor empty$
1032         { key empty$
1033             { "to sort, need author, editor, or key in " cite$ * warning$
1034               ""
1035             }
1036             { key sortify }
1037           if$
1038         }
1039         { editor sort.format.names }
1040       if$
1041     }
1042     { author sort.format.names }
1043   if$
1044 }
1045
1046 FUNCTION {author.organization.sort}
1047 { author empty$
1048     { organization empty$
1049         { key empty$
1050             { "to sort, need author, organization, or key in " cite$ * warning$
1051               ""
1052             }
1053             { key sortify }
1054           if$
1055         }
1056         { "The " #4 organization chop.word sortify }
1057       if$
1058     }
1059     { author sort.format.names }
1060   if$
1061 }
1062
1063 FUNCTION {editor.organization.sort}
1064 { editor empty$
1065     { organization empty$
1066         { key empty$
1067             { "to sort, need editor, organization, or key in " cite$ * warning$
1068               ""
1069             }
1070             { key sortify }
1071           if$
1072         }
1073         { "The " #4 organization chop.word sortify }
1074       if$
1075     }
1076     { editor sort.format.names }
1077   if$
1078 }
1079
1080 FUNCTION {presort}
1081 { type$ "book" =
1082   type$ "inbook" =
1083   or
1084     'author.editor.sort
1085     { type$ "proceedings" =
1086         'editor.organization.sort
1087         { type$ "manual" =
1088             'author.organization.sort
1089             'author.sort
1090           if$
1091         }
1092       if$
1093     }
1094   if$
1095   "    "
1096   *
1097   year field.or.null sortify
1098   *
1099   "    "
1100   *
1101   title field.or.null
1102   sort.format.title
1103   *
1104   #1 entry.max$ substring$
1105   'sort.key$ :=
1106 }
1107
1108 ITERATE {presort}
1109
1110 SORT
1111
1112 STRINGS { longest.label prev.author this.author }
1113
1114 INTEGERS { number.label longest.label.width }
1115
1116 FUNCTION {initialize.longest.label}
1117 { "" 'longest.label :=
1118   #1 'number.label :=
1119   #0 'longest.label.width :=
1120   "abcxyz" 'prev.author :=
1121   "" 'this.author :=
1122 }
1123
1124 FUNCTION {longest.label.pass}
1125 { number.label int.to.str$ 'label :=
1126   number.label #1 + 'number.label :=
1127   label width$ longest.label.width >
1128     { label 'longest.label :=
1129       label width$ 'longest.label.width :=
1130     }
1131     'skip$
1132   if$
1133   author empty$
1134     { editor empty$
1135       { "" }
1136       'editor
1137       if$
1138     }
1139     'author
1140   if$
1141   'this.author :=
1142 }
1143
1144 EXECUTE {initialize.longest.label}
1145
1146 ITERATE {longest.label.pass}
1147
1148 FUNCTION {write.lines}
1149 { { duplicate$ "." = NOT }
1150     { write$ newline$ }
1151   while$
1152   pop$
1153 }
1154
1155 FUNCTION {begin.bib}
1156 { preamble$ empty$
1157     'skip$
1158     { preamble$ write$ newline$ }
1159   if$
1160   "\providecommand{\bysame}{\leavevmode\hbox to3em{\hrulefill}\thinspace}"
1161     write$ newline$
1162   "\providecommand{\MR}{\relax\ifhmode\unskip\space\fi MR }"
1163     write$ newline$
1164   "% \MRhref is called by the amsart/book/proc definition of \MR."
1165     write$ newline$
1166   "\providecommand{\MRhref}[2]{%"
1167     write$ newline$
1168   "  \href{http://www.ams.org/mathscinet-getitem?mr=#1}{#2}"
1169     write$ newline$
1170   "}"
1171     write$ newline$
1172   "\providecommand{\href}[2]{#2}"
1173     write$ newline$
1174   "\begin{thebibliography}{"  longest.label  * "}" *
1175     write$ newline$
1176 }
1177
1178 EXECUTE {begin.bib}
1179
1180 EXECUTE {init.state.consts}
1181
1182 ITERATE {call.type$}
1183
1184 FUNCTION {end.bib}
1185 { newline$
1186   "\end{thebibliography}" write$ newline$
1187 }
1188
1189 EXECUTE {end.bib}
1190 %% \CharacterTable
1191 %%  {Upper-case    \A\B\C\D\E\F\G\H\I\J\K\L\M\N\O\P\Q\R\S\T\U\V\W\X\Y\Z
1192 %%   Lower-case    \a\b\c\d\e\f\g\h\i\j\k\l\m\n\o\p\q\r\s\t\u\v\w\x\y\z
1193 %%   Digits        \0\1\2\3\4\5\6\7\8\9
1194 %%   Exclamation   \!     Double quote  \"     Hash (number) \#
1195 %%   Dollar        \$     Percent       \%     Ampersand     \&
1196 %%   Acute accent  \'     Left paren    \(     Right paren   \)
1197 %%   Asterisk      \*     Plus          \+     Comma         \,
1198 %%   Minus         \-     Point         \.     Solidus       \/
1199 %%   Colon         \:     Semicolon     \;     Less than     \<
1200 %%   Equals        \=     Greater than  \>     Question mark \?
1201 %%   Commercial at \@     Left bracket  \[     Backslash     \\
1202 %%   Right bracket \]     Circumflex    \^     Underscore    \_
1203 %%   Grave accent  \`     Left brace    \{     Vertical bar  \|
1204 %%   Right brace   \}     Tilde         \~}