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