Version 1.3
[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 % For formatting the issue number for a journal article.
356
357 FUNCTION {format.number}
358 { number empty$
359     { "" }
360     { " no.~" number * }
361   if$
362 }
363
364 FUNCTION {format.journal.vol.number.year}
365 { journal empty$
366     { "journal name" missing.warning ""}
367     { journal }
368   if$
369   volume empty$
370     'skip$
371     { " \textbf{" * volume * "}" * }
372   if$
373   format.number *
374   year empty$
375     { "year" missing.warning }
376     { " (" * year * ")" * }
377   if$
378 }
379
380 % For formatting miscellaneous dates
381
382 FUNCTION {format.date}
383 { year empty$
384     { month empty$
385         { "" }
386         { "there's a month but no year in " cite$ * warning$
387           month
388         }
389       if$
390     }
391     { month empty$
392         'year
393         { month " " * year * }
394       if$
395     }
396   if$
397 }
398
399 %%      The volume, series and number information is sort of tricky.
400 %%      This code handles it as follows:
401 %%      If the series is present, and the volume, but not the number,
402 %%        then we do "\emph{Book title}, Series Name, vol. 000"
403 %%      If the series is present, and the number, but not the volume,
404 %%        then we do "\emph{Book title}, Series Name, no. 000"
405 %%      If the series is present, and both number and volume,
406 %%        then we do "\emph{Book title}, vol. XX, Series Name, no. 000"
407 %%      Finally, if the series is absent,
408 %%        then we do "\emph{Book title}, vol. XX"
409 %%        or         "\emph{Book title}, no. 000"
410 %%        and if both volume and number are present, give a warning message.
411
412 FUNCTION {format.bookvolume.series.number}
413 { volume empty$
414     { "" % Push the empty string as a placeholder in case everything else
415          % is empty too.
416       series empty$
417         'skip$
418         { pop$ series } % if series is not empty put in stack
419       if$
420       number empty$
421         'skip$
422         { duplicate$ empty$ % if no preceding material,
423             'skip$          % do nothing, otherwise
424             { ", " * }      % add a comma and space to separate.
425           if$
426           "no." number tie.or.space.connect * % add the number information
427         }
428       if$
429     }
430 %% If the volume is NOT EMPTY:
431     { "vol." volume tie.or.space.connect % vol. XX
432       number empty$
433         { series empty$
434             'skip$
435             { series ", " * swap$ *}    % Series Name, vol. XX
436           if$
437         }
438         { series empty$
439             { "can't use both volume and number if series info is missing"
440               warning$
441               "in BibTeX entry type `" type$ * "'" * top$
442             }
443             { ", " * series * ", no." * number tie.or.space.connect }
444           if$
445         }
446       if$
447     }
448   if$
449
450 }  % end of format.bookvolume.series.number
451
452 %% format.inproc.title.where.editors is used by inproceedings entry types
453
454 %%      No case changing or emphasizing for the title.  We want initial
455 %%      caps, roman.
456 %%      We add parentheses around the address (place where conference
457 %%      was held).
458 %%      Likewise we add parentheses around the editors' names.
459
460 FUNCTION {format.inproc.title.address.editors}
461 { booktitle empty$
462     { "" }
463     { booktitle
464       address empty$
465         'skip$
466         { add.space.if.necessary "(" * address * ")" * }
467       if$
468       editor empty$
469         'skip$
470         { add.space.if.necessary "(" * format.nonauthor.editors * ")" * }
471       if$
472     }
473   if$
474 }
475
476 %% format.incoll.title.editors is similar to format.inproc... but
477 %% omits the address. For collections that are not proceedings volumes.
478
479 FUNCTION {format.incoll.title.editors}
480 { booktitle empty$
481     { "" }
482     { editor empty$
483         { booktitle }
484         { booktitle
485           add.space.if.necessary "(" * format.nonauthor.editors * ")" *
486         }
487       if$
488     }
489   if$
490 }
491
492 FUNCTION {format.edition}
493 { edition empty$
494     { "" }
495     { output.state mid.sentence =
496         { edition "l" change.case$ " ed." * }
497         { edition "t" change.case$ " ed." * }
498       if$
499     }
500   if$
501 }
502
503 INTEGERS { multiresult }
504
505 FUNCTION {multi.page.check}
506 { 't :=
507   #0 'multiresult :=
508     { multiresult not
509       t empty$ not
510       and
511     }
512     { t #1 #1 substring$
513       duplicate$ "-" =
514       swap$ duplicate$ "," =
515       swap$ "+" =
516       or or
517         { #1 'multiresult := }
518         { t #2 global.max$ substring$ 't := }
519       if$
520     }
521   while$
522   multiresult
523 }
524
525 FUNCTION {format.pages}
526 { pages empty$
527     { "" }
528     { pages n.dashify }
529   if$
530 }
531
532 FUNCTION {format.book.pages}
533 { pages empty$
534     { "" }
535     { pages multi.page.check
536         { "pp.~" pages n.dashify * }
537         { "p.~" pages * }
538       if$
539     }
540   if$
541 }
542
543 FUNCTION {format.chapter.pages}
544 { chapter empty$
545     'format.book.pages
546     { type empty$
547         { "ch.~" }
548         { type "l" change.case$ " " * }
549       if$
550       chapter *
551       pages empty$
552         'skip$
553         { ", " * format.book.pages * }
554       if$
555     }
556   if$
557 }
558
559 FUNCTION {empty.misc.check}
560 { author empty$ title empty$ howpublished empty$
561   month empty$ year empty$ note empty$
562   and and and and and
563   key empty$ not and
564     { "all relevant fields are empty in " cite$ * warning$ }
565     'skip$
566   if$
567 }
568
569 FUNCTION {format.thesis.type}
570 { type empty$
571     'skip$
572     { pop$
573       type "t" change.case$
574     }
575   if$
576 }
577
578 FUNCTION {format.tr.number}
579 { type empty$
580     { "Tech. Report" }
581     'type
582   if$
583   number empty$
584     { "t" change.case$ }
585     { number tie.or.space.connect }
586   if$
587 }
588
589 % The format.crossref functions haven't been paid much attention
590 % at the present time (June 1990) and could probably use some
591 % work.  MJD
592
593 FUNCTION {format.article.crossref}
594 { key empty$
595     { journal empty$
596         { "need key or journal for " cite$ * " to crossref " * crossref *
597           warning$
598           ""
599         }
600         { "in " journal * }
601       if$
602     }
603     { "in " key * }
604   if$
605   " \cite{" * crossref * "}" *
606 }
607
608 FUNCTION {format.crossref.editor}
609 { editor #1 "{vv~}{ll}" format.name$
610   editor num.names$ duplicate$
611   #2 >
612     { pop$ " et~al." * }
613     { #2 <
614         'skip$
615         { editor #2 "{ff }{vv }{ll}{ jj}" format.name$ "others" =
616             { " et~al." * }
617             { " and " * editor #2 "{vv~}{ll}" format.name$ * }
618           if$
619         }
620       if$
621     }
622   if$
623 }
624
625 FUNCTION {format.book.crossref}
626 { volume empty$
627     { "empty volume in " cite$ * "'s crossref of " * crossref * warning$
628       "in "
629     }
630     { "vol." volume tie.or.space.connect
631       " of " *
632     }
633   if$
634   editor empty$
635   editor field.or.null author field.or.null =
636   or
637     { key empty$
638         { series empty$
639             { "need editor, key, or series for " cite$ * " to crossref " *
640               crossref * warning$
641               "" *
642             }
643             { series * }
644           if$
645         }
646         { key * }
647       if$
648     }
649     { format.crossref.editor * }
650   if$
651   " \cite{" * crossref * "}" *
652 }
653
654 FUNCTION {format.incoll.inproc.crossref}
655 { editor empty$
656   editor field.or.null author field.or.null =
657   or
658     { key empty$
659         { booktitle empty$
660             { "need editor, key, or booktitle for " cite$ * " to crossref " *
661               crossref * warning$
662               ""
663             }
664             { "in \emph{" booktitle * "}" * }
665           if$
666         }
667         { "in " key * }
668       if$
669     }
670     { "in " format.crossref.editor * }
671   if$
672   " \cite{" * crossref * "}" *
673 }
674
675 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
676
677 % The main functions for each entry type.
678
679 % journal, vol and year are formatted together because they are
680 % not separated by commas.
681
682 FUNCTION {article}
683 { output.bibitem
684   format.authors "author" output.check
685   format.title "title" output.check
686   crossref missing$
687     { format.journal.vol.number.year 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         \~}