summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/source/latex/amslatex/amsxport.dtx
blob: 308a8c2698cd2c4620f3b5a3dee730e9c6090267 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
%%% ====================================================================
%%% @BibTeX-source-file{
%%%   filename  = "amsxport.dtx",
%%%   version   = "2.00",
%%%   date      = "2004/06/28",
%%%   time      = "14:50:12 EDT",
%%%   author    = "Michael J Downes",
%%%   address   = "American Mathematical Society,
%%%                Publications Technical Group,
%%%                PO Box 6248,
%%%                Providence, RI 02940,
%%%                USA",
%%%   email     = "tech-support at ams.org",
%%%   URL       = "http://www.ams.org/",
%%%   abstract  = "The BibTeX style file amsxport.bst produces .bbl
%%%                entries where most of the database structure is
%%%                retained. This is intended for processing by a smart
%%%                bibliography package such as the amsrefs package.",
%%%   checksum  = "40425 1822 6396 51551",
%%%   docstring = "The checksum field, produced by Robert Solovay's
%%%                checksum utility, gives CRC-16 checksum, lines,
%%%                words, and characters.",
%%%  }
%%% ====================================================================
% \iffalse
%<*driver>
\NeedsTeXFormat{LaTeX2e}
\documentclass[draft,oneside]{amsdtx}[1999/11/01]

\providecommand{\vn}[1]{\emph{#1}}% variable name

\renewcommand*\descriptionlabel[1]{\hspace\labelsep
                                \normalfont\bfseries #1:}

%% Use normal typesize instead of \small for code listings.

\def\MacroFont{%
    \fontencoding\encodingdefault
    \fontfamily\ttdefault
    \fontseries\mddefault
    \upshape
}

\makeatletter

%% Don't prepend \ to macro names.

\def\SpecialIndex@#1#2{%
   \@SpecialIndexHelper@#1\@nil
   \def\@tempb{ }%
   \ifcat \@tempb\@gtempa
      \special@index{\quotechar\space\actualchar
                     \string\verb\quotechar*\verbatimchar
                     \quotechar\space\verbatimchar#2}%
   \else
     \def\@tempb##1##2\relax{\ifx\relax##2\relax
          \def\@tempc{\special@index{\quotechar##1\actualchar
                      \string\verb\quotechar*\verbatimchar
                      \quotechar##1\verbatimchar#2}}%
        \else
          \def\@tempc{\special@index{##1##2\actualchar
                       \string\verb\quotechar*\verbatimchar
                       ##1##2\verbatimchar#2}}%
        \fi}%
     \expandafter\@tempb\@gtempa\relax
     \@tempc
   \fi}

\makeatother

\PageIndex

\begin{document}
\title{The AMS Export Bib\TeX{} style [\fn{amsxport}]}
\author{American Mathematical Society\\Michael Downes\\David M. Jones}
\date{Version \fileversion, \filedate}
\hDocInput{amsxport.dtx}
\PrintIndex
\end{document}
%</driver>
% \fi
%
% \MakeShortVerb{\|}
%
% \maketitle
%
% \tableofcontents
%
% \section{Introduction}
%
%    \bst{amsxport} is the collective name for a collection of
%    \bibtex/ styles that form a bridge between \BibTeX\ and
%    \pkg{amsrefs}. It produces output in which the structural
%    information of the original \bibtex/ database file is
%    retained. No ad hoc visual formatting is introduced that would
%    hamper the application of alternative design specifications when
%    rendering the information on paper or screen. This makes it
%    possible to have \bibtex/ handle only extraction and sorting and
%    leave the visual appearance to be controlled entirely by
%    \latex/. The process of applying typical bibliography specs to
%    exported data is illustrated in the \pkg{amsrefs} package. The
%    authoritative description of the export format is in the
%    \pkg{amsrefs} documentation, inasmuch as interpreting the format
%    is the chief task of the \pkg{amsrefs} package.
%
%    Each of the five \fn{.bst} files generated from this file
%    corresponds to a combination of \pkg{amsrefs} package options, as
%    follows:
%    \begin{description}
%
%    \item[amsrn]
%
%    This is the default style, used when none of the following is
%    appropriate.
%
%    \item[amsru]
%
%    This is used when the \opt{citation-order} option is specified.
%    It is identical to \bst{amsrn} except that the bibliography items
%    are not sorted.
%
%    \item[amsra]
%
%    This is when with the \opt{alphabetic} option is specified, byt
%    the \opt{y2k} option is \emph{not} also specified.
%
%    \item[amsry]
%
%    This is used when both the \opt{alphabetic} and \opt{y2k} options
%    are specified.
%
%    \item[amsrs]
%
%    This is used when the \opt{shortalphabetic} option is specified.
%
%    \end{description}
%
%    Readers may wish to refer also to the standard \bibtex/
%    documentation (\fn{btxdoc.tex}, \fn{btxhak.tex}, \fn{btxbst.doc})
%    for background information.
%
% \StopEventually{}
%
% \section{Implementation}
%
%    The list below gives the fields that are expected to occur. (Other
%    fields will be discarded without comment.)
%    suggested fields.
%    \begin{macrocode}
%<*bst>
ENTRY
  {
    address      institution  number       status
    archive      isbn         organization subtitle
    author       issn         pages        title
    booktitle    journal      part         translator
    chapter      key          pii          type
    date         language     preprint     url
    edition      meeting      publisher    volume
    editor       month        review       xid
    eprint       mrnumber     school       year
    howpublished note         series
  }
  { }
  { label }
%    \end{macrocode}
%
% Some comments about specific fields:
% \begin{description}
% \item[archive] The archive that holds the eprint listed in the
%    \fn{eprint} field.
% \item[author] \bibtex/ doesn't allow this field (or any field) to be
%    used more than once, but in the output its contents will be split
%    into a separate key-value pair for each name. Likewise for
%    \fn{editor} and \fn{translator}.
% \item[crossref] This is a built-in field type, so it doesn't occur in
%    the argument of ENTRY above.
% \item[date] This is a generalization of the \fn{year} and \fn{month}
%    fields. Its value should be written in ISO 8601 format, e.g.,
%    1987-06-05; but the day and month are omissible, so this can be
%    easily be used instead of the \fn{year} field.
% \item[edition] For books. The \bibtex/ documentation suggests that the
%    value of this field should be an ordinal word such as \qq{Second}.
%    This may be because the \bibtex/ language provides only the weakest
%    sort of support for an \emph{is-numeric} test.
% \item[eprint] Electronic preprint information such as for
%    \url{www.arXiv.org}.
% \item[institution] What's the difference between an \fn{institution}
%    and an \fn{organization}? The \bibtex/ documentation says that
%    \fn{institution} should be used for technical reports and
%    \fn{organization} for other entry types.
% \item[isbn] International Standard Book Number.
% \item[issn] International Standard Serial Number. See the discussion
%    of journal abbreviations.
% \item[language] Language of the work. This is especially desirable
%    when the value of the title field is a translation of the true
%    title (most often when the original language is one like Arabic or
%    Chinese that poses rendering problems for non-native software).
% \item[meeting] Since \bibtex/ doesn't allow a field name to be the
%    same as a function name, we have to use \fn{meeting} instead of
%    \fn{conference} if we want to give the title of a conference in a
%    dedicated field.
% \item[mrnumber] An alias for \fn{review} which we provide because
%    MathSciNet has been using it in the \bibtex/ output that it
%    provides for a couple of years already.
% \item[organization] See the comment for \fn{institution}.
% \item[pii] Publisher Item Identifier
% \item[part] This is for a long journal article that is published in
%    separate issues of the same journal. There should be a separate
%    \bibtex/ entry for each part (though all the ones after part 1
%    could crossref the first one).
%
% \item[preprint] It is not possible quite yet to assume that all
%    preprints should be classified as eprints. If you have a preprint
%    that is not an eprint, use this field to give the \qq{address}
%    where the preprint may be found (institution, preprint number,
%    etc.).
%
% \item[review] Review numbers or similar pointers, e.g., for
%    Mathematical Reviews or Zentralblatt.
%
% \item[school] The analog of \qq{organization}, for a thesis.
%
% \item[status] Typically used for notes such as ``to appear'' or ``in
%    preparation'' with journal articles.
%
% \item[subtitle] Typically used with a multipart journal article to
%    give a subtitle for each part.
%
% \item[translator] This needs no explanation, surely? Except perhaps to
%    note that the standard \bibtex/ styles don't provide it.
%
% \item[url] Universal Resource Locator.
%
% \item[xid] This is used by a cross-referenced item to pass its
%    identity to child entries that refer to it. It would not be
%    necessary if \bibtex/ left the \fn{crossref} field value
%    accessible, but for some reason that I have not found yet (skimming
%    in the source code) it is cleared internally before there is any
%    opportunity to save it.
%
%    Practically speaking: For every \fn{crossref} in your \fn{.bib}
%    files, the target should contain a matching \fn{xid} field.
%
% \end{description}
%
%    More on extra fields. In the Shelah bibliography, the \fn{author}
%    field is given without any accents in the author names, and the
%    normal \tex/ version of the author names is given in a separate
%    field called \fn{trueauthor}.
%
%    Also, for MR reviews:
%    \begin{verbatim}
%    review = {MR 48:3735},
%\end{verbatim}
%    And for each author a country is indicated with the \fn{fromwhere}
%    field, e.g.,
%    \begin{verbatim}
%    fromwhere = {UK, IL},
%\end{verbatim}
%    This means the first author is from the United Kingdom and the
%    second one from Israel.
%
% \section{Macros for month names}
%
%    \begin{macrocode}
MACRO {jan} {"-01"}
MACRO {feb} {"-02"}
MACRO {mar} {"-03"}
MACRO {apr} {"-04"}
MACRO {may} {"-05"}
MACRO {jun} {"-06"}
MACRO {jul} {"-07"}
MACRO {aug} {"-08"}
MACRO {sep} {"-09"}
MACRO {oct} {"-10"}
MACRO {nov} {"-11"}
MACRO {dec} {"-12"}
%    \end{macrocode}
%
%    Some scratch variables and global variables.
%    \begin{macrocode}
STRINGS { p s t l }
%    \end{macrocode}
%
%    \begin{macrocode}
INTEGERS { len ptr }
%<bst>
%    \end{macrocode}
%
%    \begin{footnotesize}\itshape
%    Note: \bibtex/ 0.99 requires a blank line in certain contexts, such
%    as after the \fn{READ} command, and will choke if it is missing.
%    When it is necessary to add a blank line at the boundary of a macro
%    code section we use a \verb'<bst>' marker.\par
%    \end{footnotesize}
%
%    Some utility functions.
%    \begin{macrocode}
FUNCTION {NOT} { { #0 } { #1 } if$ }

FUNCTION {AND} { 'skip$ { pop$ #0 } if$ }

FUNCTION {OR} { { pop$ #1 } 'skip$ if$ }

FUNCTION {TRUE} { #1 }

FUNCTION {FALSE} { #0 }
%<bst>
%    \end{macrocode}
%
%    \begin{macro}{incr.ptr}
%    \begin{macrocode}
FUNCTION {incr.ptr} { ptr #1 + 'ptr := }
%<bst>
%    \end{macrocode}
%    \end{macro}
%
%    \begin{macro}{current.char}
%    Returns: first character of STRING
%    \begin{macrocode}
FUNCTION {current.char} { ptr #1 substring$ }
%    \end{macrocode}
%    \end{macro}
%
%    \begin{macro}{copy.two.chars}
%    The function \fn{copy.two.chars} appends the next two characters
%    from s to STRING.
%
%    Arg: STRING (partial copy of pages string)
%
%    Returns: Modified version of STRING
%
%    Side effects: advances ptr
%    \begin{macrocode}
FUNCTION {copy.two.chars} { t * incr.ptr s current.char * incr.ptr }
%<bst>
%    \end{macrocode}
%    \end{macro}
%
%    \begin{macro}{is.digit}
%    \begin{macrocode}
FUNCTION {is.digit} {
    chr.to.int$
    duplicate$
    "0" chr.to.int$ #1 - >
    swap$
    "9" chr.to.int$ #1 + <
    AND
}
%<bst>
%    \end{macrocode}
%    \end{macro}
%
%    \begin{macro}{is.lowercase.letter}
%    In a previous implementation the \fn{is.letter} function first
%    lowercased the character using \verb'change.case$', then tested it
%    against the range a--z. But \verb'change.case$' issues a warning if
%    it is applied to a lone brace character.
%    \begin{macrocode}
FUNCTION {is.lowercase.letter} {
    chr.to.int$ duplicate$
    "a" chr.to.int$ #1 - >
    swap$
    "z" chr.to.int$ #1 + <
    AND
}
%    \end{macrocode}
%    \end{macro}
%
%    \begin{macro}{is.uppercase.letter}
%    \begin{macrocode}
FUNCTION {is.uppercase.letter} {
    chr.to.int$ duplicate$
    "A" chr.to.int$ #1 - >
    swap$
    "Z" chr.to.int$ #1 + <
    AND
}
%    \end{macrocode}
%    \end{macro}
%
%    \begin{macro}{is.letter}
%    \begin{macrocode}
FUNCTION {is.letter} {
    duplicate$
    is.lowercase.letter
        { pop$ TRUE }
        { is.uppercase.letter }
    if$
}
%    \end{macrocode}
%    \end{macro}
%
%    \begin{macro}{skip.accent}
%    This implementation of \fn{skip.accent} simply skips ahead one
%    character whenever a backslash is found. This handles things like
%    \verb'\v', \verb'\u', \verb'\k', \verb'\r'. Although this is overly
%    simplistic it is still an improvement over the previous method
%    which was to not even make the attempt. [mjd,2001-10-27]
%    \begin{macrocode}
FUNCTION {skip.accent} { pop$ incr.ptr }
%    \end{macrocode}
%    \end{macro}
%
%    \begin{macro}{strip.label}
%    \begin{macrocode}
FUNCTION {strip.label} {
    's :=
    #1 'ptr :=
    ""
    { s ptr #1 substring$ duplicate$ empty$ NOT }
        { duplicate$ is.letter
            { * }
            { duplicate$ "\" =
                { skip.accent }
                'pop$
              if$
            }
          if$
          incr.ptr
        }
    while$
%    \end{macrocode}
%    When the loop ends we have an extra empty-string on top of the
%    stack to get rid of.
%    \begin{macrocode}
    pop$
}
%    \end{macrocode}
%    \end{macro}
%
%    \begin{macro}{sortify}
%    \begin{macrocode}
FUNCTION {sortify} {
    purify$
    "l" change.case$
}
%    \end{macrocode}
%    \end{macro}
%
%    \begin{macro}{rpad}
%    Warning: The use of |text.length$| here and in \fn{lpad}
%    restricts their use to strings that we know do not contain any
%    special characters.  Since we only use \fn{lpad} for field names
%    and \fn{rpad} for |purify$|ed strings, this is ok.
%
%    \<string> \<int> \fn{rpad}
%    \begin{macrocode}
FUNCTION {rpad} {
    swap$
    'l :=
    l text.length$ - 'len :=
    { len #0 > }
        {
            l " " * 'l :=
            len #1 - 'len :=
        }
    while$
    l
}
%    \end{macrocode}
%    \end{macro}
%
%    \begin{macro}{lpad}
%    \<string> \<int> \fn{lpad}
%    \begin{macrocode}
FUNCTION {lpad} {
    swap$
    'l :=
    l text.length$ - 'len :=
    { len #0 > }
        {
            " " l * 'l :=
            len #1 - 'len :=
        }
    while$
    l
}
%    \end{macrocode}
%    \end{macro}
%
%    \begin{macro}{field.or.null}
%    \begin{macrocode}
FUNCTION {field.or.null} {
    duplicate$ empty$
        { pop$ "" }
        'skip$
    if$
}
%    \end{macrocode}
%    \end{macro}
%
%    \begin{macro}{missing.or.empty}
%    \begin{macrocode}
FUNCTION {missing.or.empty} { duplicate$ missing$ swap$ empty$ OR }
%<bst>
%    \end{macrocode}
%    \end{macro}
%
%    \begin{macro}{append.ndash.and.skip.hyphens}
%    The function \fn{append.ndash.and.skip.hyphens} adds \verb'\ndash'
%    to STRING when a hyphen is found and advances ptr to the next
%    non-hyphen character in \fn{s}.
%
%    Arg: STRING (partial copy of pages string)
%
%    Returns: modified version of STRING
%
%    Side effects: advances ptr
%    \begin{macrocode}
FUNCTION {append.ndash.and.skip.hyphens} {
    "\ndash " *
    incr.ptr
    { s current.char "-" = }
        { incr.ptr }
    while$
}
%    \end{macrocode}
%    \end{macro}
%
%    \begin{macro}{n.dashify}
%    In the \fn{n.dashify} function we store the given string in \fn{s},
%    push an empty string on the stack, and start examining the
%    characters of \fn{s}. For a non-hyphen character, we just append a
%    copy of it to the top string. For a hyphen, we append \cs{ndash} to
%    the top string and advance the pointer until we reach a non-hyphen
%    character. And there is one more exceptional case: for a backslash,
%    we copy two characters instead of one. This keeps us from
%    erroneously translating \verb'\-' to \verb'\\ndash'. One would
%    scarcely expect to see an instance of \verb'\-' in a page number
%    field but let's face it, in actual use nearly anything can and does
%    happen.
%
%    Arg: STRING (value of \fn{pages} field)
%
%    Returns: STRING (dashified version of input string)
%    \begin{macrocode}
FUNCTION {n.dashify} {
    's :=
    #1 'ptr :=
    ""
    { s current.char 't :=  t "" = NOT }
      { t "\" =
          { copy.two.chars }
          { t "-" =
              { append.ndash.and.skip.hyphens }
              { t * incr.ptr }
            if$
          }
        if$
      }
    while$
}
%    \end{macrocode}
%    \end{macro}
%
%    \begin{macro}{missing.warning}
%    Standard warning message for a missing or empty field. For the user
%    we call any such field `missing' without respect to the distinction
%    made by \bibtex/ between missing and empty.
%    \begin{macrocode}
FUNCTION {missing.warning} {
    "missing " swap$ * " in " * cite$ * warning$
}
%<bst>
%    \end{macrocode}
%    \end{macro}
%
%    \begin{macro}{string.length}
%    Because \bibtex/ doesn't provide a straightforward
%    \fn{string.length} function (\verb'text.length$' counts ``special
%    characters'' as a single character), it appears necessary to
%    implement one the hard way.
%    \begin{macrocode}
INTEGERS { string.ptr }

FUNCTION {string.length} {
    #1 'string.ptr :=
    { duplicate$ string.ptr #1 substring$ "" = 'FALSE 'TRUE if$ }
        { string.ptr #1 + 'string.ptr := }
    while$
    pop$
    string.ptr #1 -
}
%    \end{macrocode}
%    \end{macro}
%
%    \begin{macro}{format.title}
%    \begin{macrocode}
FUNCTION {format.title}{
    duplicate$
    missing.or.empty
        { pop$ "" }
        { "t" change.case$ }
    if$
}
%    \end{macrocode}
%    \end{macro}
%
%    \begin{macro}{start.field}
%    \begin{macrocode}
FUNCTION {start.field} {
    #12 lpad "={" * write$
}
%    \end{macrocode}
%    \end{macro}
%
%    \begin{macro}{fin.field}
%    \begin{macrocode}
FUNCTION {fin.field} { "}," write$ newline$ }
%<bst>
%    \end{macrocode}
%    \end{macro}
%
%    \begin{macro}{write.field}
%    \begin{macrocode}
FUNCTION {write.field} {
    duplicate$
    missing$
        { pop$ missing.warning }
        { duplicate$ empty$
            { pop$ missing.warning }
            { swap$ start.field write$ fin.field }
          if$
        }
    if$
}
%    \end{macrocode}
%    \end{macro}
%
%    \begin{macro}{optional.field}
%    \begin{macrocode}
FUNCTION {optional.field} {
    duplicate$
    missing.or.empty
        { pop$ pop$ }
        { swap$ start.field write$ fin.field }
    if$
}
%    \end{macrocode}
%    \end{macro}
%
%    \begin{macro}{optional.title.field}
%    \begin{macrocode}
FUNCTION {optional.title.field} {
    duplicate$
    missing.or.empty
        { pop$ pop$ }
        { format.title swap$ start.field write$ fin.field }
    if$
}
%    \end{macrocode}
%    \end{macro}
%
%    \begin{macro}{optional.pages.field}
%    \begin{macrocode}
FUNCTION {optional.pages.field} {
    duplicate$
    missing.or.empty
        { pop$ pop$ }
        { swap$ start.field
          n.dashify
          write$ fin.field
        }
    if$
}
%    \end{macrocode}
%    \end{macro}
%
%    \begin{macro}{optional.mr.field}
%    \begin{macrocode}
FUNCTION {optional.mr.field} {
    duplicate$
    missing.or.empty
        { pop$ pop$ }
        {
          swap$ start.field
          "\MR{" swap$ * "}" * write$ fin.field
        }
    if$
}
%    \end{macrocode}
%    \end{macro}
%
%    \begin{macro}{remove.ordinal.suffix}
%    \begin{macrocode}
FUNCTION {remove.ordinal.suffix} {
    's :=
    s string.length 'len :=
    #1 'ptr :=
    { ptr len < s ptr #1 substring$ is.digit AND }
        'incr.ptr
    while$
    s ptr global.max$ substring$ 'p :=
    p "st" =
        { TRUE }
        { p "nd" =
            { TRUE }
            { p "rd" =
                { TRUE }
                { p "th" =
                    { TRUE }
                    { FALSE }
                  if$
                }
              if$
            }
          if$
        }
    if$
    { s #1 ptr #1 - substring$ }
    { s }
  if$
}
%    \end{macrocode}
%    \end{macro}
%
%    \begin{macro}{optional.edition.field}
%    \begin{macrocode}
FUNCTION {optional.edition.field} {
    duplicate$ missing.or.empty
        { pop$ pop$ }
        { swap$ start.field
          remove.ordinal.suffix
          write$ fin.field
        }
    if$
}
%    \end{macrocode}
%    \end{macro}
%
% \section{Formatting author names and editor names}
%
%    Take a name list in \bibtex/ form (names separated by the word
%    \qq{and}) and output the desired form of each name.
%    \begin{macrocode}
INTEGERS { nameptr numnames namesleft }
STRINGS { namelist fieldname }
%    \end{macrocode}
%
%    \begin{macro}{format.name}
%    The \fn{format.name} function operates on a single name, producing
%    a string of the form
%    \begin{verbatim}
%    von Last, First, Jr.
%\end{verbatim}
%
%    Args: \vn{namelist}, \vn{index} (top; integer)
%
%    Returns: formatted version of the $n$th name in \vn{namelist} where
%    integer \vn{index} specifies $n$.
%    \begin{macrocode}
FUNCTION {format.name} { "{vv~}{ll}{, ff}{, jj}" format.name$ }
%<bst>
%    \end{macrocode}
%    \end{macro}
%
%    \begin{macro}{optional.name.field}
%    The function \fn{optional.name.field} handles the task of splitting
%    a multiple-name field value into multiple fields with single
%    values.
%
%    Args: \vn{fieldname}, \vn{namelist} (top)
%
%    Side effects: writes a key/value pair to the output file for each
%    name in \vn{namelist}.
%    \begin{macrocode}
FUNCTION {optional.name.field}{
    duplicate$ missing.or.empty
        { pop$ pop$ }
        { swap$ 'fieldname :=
          duplicate$ num.names$
          'namesleft :=
          #1 'ptr :=
          { namesleft #0 > }
            { fieldname start.field
%    \end{macrocode}
%    Copy the name string before running \fn{format.name} on it.
%    \begin{macrocode}
              duplicate$ ptr format.name write$
              fin.field
              ptr #1 + 'ptr :=
              namesleft #1 - 'namesleft :=
            }
          while$
%    \end{macrocode}
%    At this point we have an extra copy of the name string on the
%    stack.
%    \begin{macrocode}
        pop$
        }
    if$
}
%    \end{macrocode}
%    \end{macro}
%
% \section{Handling year, month, date}
%
%    \begin{macro}{assemble.date.field}
%    In the output we produce a \fn{date} field instead of the year and
%    month fields normally used in \bibtex/ files. In the date field we
%    use ISO date notation (e.g., 1987-06-05) to facilitate switching
%    between full and abbreviated month names. The month and day parts
%    are frequently absent, making the date field equivalent to a year
%    field.
%    \begin{macrocode}
FUNCTION {assemble.date.field}
{ date missing$
    { year missing.or.empty
        { status missing.or.empty
            { "No year or other date information for "
               cite$ * warning$ }
            'skip$
          if$
          "status"
        }
        { year month missing$ { "" } { month } if$ * }
      if$
    }
    { date }
  if$
%    \end{macrocode}
%    If the date string is now equal to \qq{status}, it means that we
%    have a status field or we already gave a warning about lack of date
%    info; in either case omit the date field.
%    \begin{macrocode}
  duplicate$ "status" =
    { pop$ pop$ }
    { swap$ start.field write$ fin.field }
  if$
}
%    \end{macrocode}
%    \end{macro}
%
% \section{Journal abbreviations}
%
%    Use of journal abbreviations is recommended to make supplying ISSN
%    numbers easier. To use this feature, you need a STRING definition
%    of the form
%    \begin{verbatim}
%    @STRING{cpam="cpam/0010-3640/"
%            #"Communications in Pure and Applied Mathematics"}
%\end{verbatim}
%    Then when you write
%    \begin{verbatim}
%    journal=cpam,
%\end{verbatim}
%    exporting with \fn{amsxport} will produce
%    \begin{verbatim}
%    journal={cpam},
%    ISSN={0010-3640},
%\end{verbatim}
%    The text before the ISSN number in the STRING definition is
%    preferably a repetition of the abbreviation name (leaving expansion
%    to be done on the \latex/ side); or it could be the full journal
%    name.
%
%    \textbf{Warning:} If you include braces and write
%    \verb'journal={cpam},' \bibtex/ will not expand the abbreviation
%    but leave it as the field value; and then you will not get
%    automatic lookup of the ISSN number.
%
%    \begin{macro}{optional.journal.field}
%    \begin{macrocode}
FUNCTION {optional.journal.field} {
    duplicate$ missing.or.empty
        { pop$ pop$ }
        {
            's :=
            start.field
            #1 'ptr :=
            s current.char is.lowercase.letter
                {
                    s "/" * 's :=
                    { s ptr #1 substring$ "/" = NOT }
                        { incr.ptr }
                    while$
%    \end{macrocode}
%    Journal name started with a lowercase letter, but we couldn't find
%    no slash? All right, just let it go through as it is.
%    \begin{macrocode}
                    s ptr #1 + #1 substring$ empty$
                        { s #1 ptr #1 - substring$ }
%    \end{macrocode}
%    But if we did find a slash, then we probably have found us an ISSN
%    number that we can write out.
%    \begin{macrocode}
                        {
                            s #1 ptr #1 - substring$
                            write$
                            fin.field
%    \end{macrocode}
%    ISSNs are always nine characters in length (four digits, hyphen,
%    four digits).
%    \begin{macrocode}
                            "ISSN" start.field
                            s ptr #1 + #9 substring$
                        }
                    if$
                }
                { s }
            if$
            write$
            fin.field
        }
    if$
}
%    \end{macrocode}
%    \end{macro}
%
% \section{Type info}
%
%    \begin{macro}{optional.type.field}
%    Putz around with the type info a little, for theses mainly. Two
%    types here: the type field, and the entry type.
%    \begin{macrocode}
FUNCTION {optional.type.field}
{ duplicate$ missing.or.empty
    { type$ "mastersthesis" = { "Master's Thesis" }
        { type$ "phdthesis" = { "Ph.D. Thesis" }
          { "" } if$ } if$
      swap$ pop$
    }
    'skip$
  if$
  duplicate$ empty$
    { pop$ pop$ }
    { swap$ start.field write$ fin.field }
  if$
}
%    \end{macrocode}
%    \end{macro}
%
% \section{Miscellaneous tail-end information}
%
%    \begin{macro}{url.note.status.review}
%    The following items are common to all entry types are output at
%    the tail end of the entry.
%    \begin{macrocode}
FUNCTION {url.note.status.review} {
    "url" url optional.field
    "note" note optional.field
    "status" status optional.field
%    \end{macrocode}
%    The \fn{review} field should perhaps be translated into multiple
%    fields like author names, if more than one review is given.
%    \begin{macrocode}
    "review" review optional.field
%    \end{macrocode}
%    Data from MathSciNet will have the Math Reviews number in an
%    mrnumber field. We assume that a given entry will have a review
%    field or an mrnumber field but not both.
%    \begin{macrocode}
    "review" mrnumber optional.mr.field
}
%    \end{macrocode}
%    \end{macro}
%
% \section{Wrapper for each entry}
%
%    \begin{macro}{start.entry}
%    \begin{macrocode}
FUNCTION {start.entry} {
    newline$
    "\bib{" cite$ * "}{" *
%    \end{macrocode}
%    Merge Master's thesis and Ph.D. thesis into a single type.
%    \begin{macrocode}
    type$ "mastersthesis" = type$ "phdthesis" =  OR
        { "thesis" }
        { type$ }
    if$
    * "}{" * write$
    newline$
%<*debug>
    "sort.label" label sortify optional.field
    "sort.key" sort.key$ optional.field
%</debug>
}
%    \end{macrocode}
%    \end{macro}
%
%    \begin{macro}{fin.entry}
%    \begin{macrocode}
FUNCTION {fin.entry} {
    "}" write$
    newline$
}
%    \end{macrocode}
%    \end{macro}
%
% \section{Entry types}
%
%    Here are the types of entries that are normally allowed in a
%    \bibtex/ file:
% \begin{description}
%
% \item[book] A book with an explicit publisher.
%
% \item[booklet] A work that is printed and bound, but without a named
%    publisher or sponsoring institution.
%
% \item[inbook] A part of a book, which may be a chapter (or section or
%    whatever) and/or a range of pages.
%
% \item[incollection] A part of a book having its own title.
%
% \item[manual] Technical documentation.
%
% \item[mastersthesis] A Master's thesis.
%
% \item[phdthesis] A PhD thesis.
%
% \item[proceedings] The proceedings of a conference.
%
% \item[techreport] A report published by a school or other institution,
%    usually numbered within a series.
%
% \item[article] An article from a journal or magazine.
%
% \item[inproceedings] An article in a conference proceedings.
%
% \item[conference] An alias for \fn{inproceedings}.
%
% \item[unpublished] A document having an author and title, but not
%    formally published.
%
% \item[misc] Use this type when nothing else fits.
%
% \end{description}
%
%    \begin{macro}{article}
%    A journal article differs from an inproceedings article by not
%    having booktitle, publisher, editor, and other such info.
%    \begin{macrocode}
FUNCTION {article} {
    start.entry
    "author" author optional.name.field
    "translator" translator optional.name.field
    "title" title format.title write.field
    "subtitle" subtitle optional.title.field
    "language" language optional.field
    "organization" organization optional.field
    "how" howpublished optional.field
%    \end{macrocode}
%    Construct a date value from date, year, month fields
%    \begin{macrocode}
    "date" assemble.date.field
    "ISSN" issn optional.field
    "journal" journal optional.journal.field
    "volume" volume optional.field
    "number" number optional.field
    "pages" pages optional.pages.field
    "PII" pii optional.field
    "archive" archive optional.field
    "eprint" eprint optional.field
    "preprint" preprint optional.field
    url.note.status.review
    fin.entry
}
%    \end{macrocode}
%    \end{macro}
%
%    \begin{macro}{inproceedings}
%    An inproceedings entry may have xid, booktitle, meeting, publisher
%    info; it is not expected to have journal, eprint, or preprint info.
%    \begin{macrocode}
FUNCTION {inproceedings} {
    start.entry
    "author" author optional.name.field
    "translator" translator optional.name.field
    "title" title format.title write.field
    "subtitle" subtitle optional.title.field
    "language" language optional.field
    "organization" organization optional.field
    "how" howpublished optional.field
%    \end{macrocode}
%    Construct a date value from date, year, month fields
%    \begin{macrocode}
    "date" assemble.date.field
    "xid" xid optional.field
%    \end{macrocode}
%    The following fields might be inherited from the parent of an
%    article in a proceedings volume or collection.
%    \begin{macrocode}
    "conference" meeting optional.field
    "booktitle" booktitle optional.title.field
%    \end{macrocode}
%    Include the edition in case this is an inbook entry.
%    \begin{macrocode}
    "edition" edition optional.edition.field
    "editor" editor optional.name.field
    "series" series optional.field
    "volume" volume optional.field
    "publisher" publisher optional.field
    "address" address optional.field
    "pages" pages optional.pages.field
    url.note.status.review
    fin.entry
}
%    \end{macrocode}
%    \end{macro}
%
%    \begin{macro}{inbook}
%    \begin{macrocode}
FUNCTION {inbook} { inproceedings }
%    \end{macrocode}
%    \end{macro}
%
%    \begin{macro}{incollection}
%    \begin{macrocode}
FUNCTION {incollection} { inproceedings }
%    \end{macrocode}
%    \end{macro}
%
%    \begin{macro}{inproceedings}
%    \begin{macrocode}
FUNCTION {conference} { inproceedings }
%    \end{macrocode}
%    \end{macro}
%
%    \begin{macro}{book}
%    The book type includes a meeting field because otherwise we'd have
%    to repeat the entire definition for the proceedings type with that
%    as the sole difference.
%    \begin{macrocode}
FUNCTION {book} {
    start.entry
    "author" author optional.name.field
    "editor" editor optional.name.field
    "translator" translator optional.name.field
    "title" title missing$ { booktitle } { title } if$
       format.title write.field
    "subtitle" subtitle optional.title.field
    "type" type optional.type.field
    "language" language optional.field
    "conference" meeting optional.field
    "edition" edition optional.edition.field
    "series" series optional.field
    "publisher" publisher optional.field
    organization missing.or.empty
        { "institution" institution optional.field }
        { "organization" organization optional.field }
    if$
    "address" address optional.field
    "how" howpublished optional.field
    "date" year write.field
    "volume" volume optional.field
%    \end{macrocode}
%    The number here is intended for a tech report.
%    \begin{macrocode}
    "number" number optional.field
    "ISBN" isbn optional.field
    url.note.status.review
    fin.entry
}
%    \end{macrocode}
%    \end{macro}
%
%    \begin{macro}{booklet}
%    \begin{macrocode}{booklet}
FUNCTION {booklet} { book }
%    \end{macrocode}
%    \end{macro}
%
%    \begin{macro}{manual}
%    \begin{macrocode}
FUNCTION {manual} { book }
%    \end{macrocode}
%    \end{macro}
%
%    \begin{macro}{mastersthesis}
%    \begin{macrocode}
FUNCTION {mastersthesis} { book }

FUNCTION {phdthesis} { book }

FUNCTION {proceedings} { book }

FUNCTION {collection} { book }

FUNCTION {techreport} { book }

FUNCTION {unpublished} { book }

FUNCTION {misc} { book }

FUNCTION {default.type} { misc }
%<bst>
%    \end{macrocode}
%    \end{macro}
%
%    \bibtex/ 0.99 keels over if READ does not have a blank line after
%    it.
%    \begin{macrocode}
%<bst>
READ
%<bst>
%    \end{macrocode}
%
% \section{Sorting the entries}
%
%    Since the final labels will be produced by the \pkg{amsrefs}
%    package, we don't need to worry about generating suffixes to
%    disambiguate between equal stems.  All we have to do is strive to
%    generate stems that are identical to the ones that \pkg{amsrefs}
%    will generate, so that \bst{amsxport} will sort its output in a
%    fashion that will be consistent with the labels.
%
%    Overall, this simplifies our job, since we don't have to keep
%    track of duplicate labels, so we can process each entry in
%    isolation.  However, we do have to be more careful about the
%    handling of text accents and text symbols in order to maintain
%    compatibility with \pkg{amsrefs}.
%
%    See (\emph{inter alia}) the sections ``Lexical structure of
%    names'' and ``Generating alphabetic lables'' in the
%    \pkg{amsrefs} implementation documentation for more information.
%
%    \begin{macrocode}
%<*sort>
%    \end{macrocode}
%
%    \begin{macro}{chop.word}
%    \begin{macrocode}
FUNCTION {chop.word} {
    's :=
    'len :=
    s #1 len substring$ =
        { s len #1 + global.max$ substring$ }
        's
    if$
}
%    \end{macrocode}
%    \end{macro}
%
%    \begin{macro}{sort.format.title}
%    \begin{macrocode}
FUNCTION {sort.format.title} {
    't :=
    "A " #2
      "An " #3
        "The " #4 t chop.word
      chop.word
    chop.word
    sortify
    #1 global.max$ substring$
}
%    \end{macrocode}
%    \end{macro}
%
%    \begin{macro}{format.lab.names}
%    \begin{macrocode}
%<*alpha|short>
FUNCTION {format.lab.names} {
   's :=
    s num.names$ 'numnames :=
    numnames #1 >
      { numnames #4 >
          { #3 'namesleft := }
          { numnames 'namesleft := }
        if$
        #1 'nameptr :=
        ""
          { namesleft #0 > }
          { nameptr numnames =
              { s nameptr "{ff }{vv }{ll}{ jj}" format.name$ "others" =
                  { "{\etalchar{+}}" * }
                  { s nameptr "{v{}}{l{}}" format.name$ * }
                if$
              }
              { s nameptr "{v{}}{l{}}" format.name$ * }
            if$
            nameptr #1 + 'nameptr :=
            namesleft #1 - 'namesleft :=
          }
        while$
        numnames #4 >
          { "{\etalchar{+}}" * }
          'skip$
        if$
      }
      { s #1 "{v{}}{l{}}" format.name$
        duplicate$ text.length$ #2 <
%<alpha>          { pop$ s #1 "{ll}" format.name$ #3 text.prefix$ }
%<short>          { pop$ s #1 "{ll}" format.name$ #1 text.prefix$ }
          'skip$
        if$
      }
    if$
}

FUNCTION {author.key.label}
{ author empty$
    { key empty$
	{ cite$ #1 #3 substring$ }
	{ key #3 text.prefix$ }
      if$
    }
    { author format.lab.names }
  if$
}

FUNCTION {author.editor.key.label}
{ author empty$
    { editor empty$
	{ key empty$
	    { cite$ #1 #3 substring$ }
	    { key #3 text.prefix$ }
	  if$
	}
	{ editor format.lab.names }
      if$
    }
    { author format.lab.names }
  if$
}

FUNCTION {author.key.organization.label}
{ author empty$
    { key empty$
	{ organization empty$
	    { cite$ #1 #3 substring$ }
	    { "The " #4 organization chop.word #3 text.prefix$ }
	  if$
	}
	{ key #3 text.prefix$ }
      if$
    }
    { author format.lab.names }
  if$
}

FUNCTION {editor.key.organization.label}
{ editor empty$
    { key empty$
	{ organization empty$
	    { cite$ #1 #3 substring$ }
	    { "The " #4 organization chop.word #3 text.prefix$ }
	  if$
	}
	{ key #3 text.prefix$ }
      if$
    }
    { editor format.lab.names }
  if$
}

FUNCTION {calc.label}{
    type$ "book" =  type$ "inbook" =  OR
    'author.editor.key.label
    { type$ "proceedings" =
	'editor.key.organization.label
	{ type$ "manual" =
	    'author.key.organization.label
	    'author.key.label
	  if$
	}
      if$
    }
    if$
    strip.label
    sortify
%<*alpha>
    year field.or.null
%<!y2k>    #3 #8 substring$
    purify$ *
%</alpha>
    'label :=
}
%</alpha|short>
%    \end{macrocode}
%    \end{macro}
%
%    \begin{macro}{sort.format.names}
%    \begin{macrocode}
FUNCTION {sort.format.names} {
    's :=
    #1 'ptr :=
    ""
    s num.names$ 'numnames :=
    numnames 'namesleft :=
      { namesleft #0 > }
      { ptr #1 >
          { " " * }
          'skip$
        if$
        s ptr "{ll}{ ff}{ jj}" format.name$ 't :=
        ptr numnames = t "others" = AND
          { "et al" }
          { t sortify }
        if$
        #20 rpad *
        ptr #1 + 'ptr :=
        namesleft #1 - 'namesleft :=
      }
    while$
}
%    \end{macrocode}
%    \end{macro}
%
%    \begin{macro}{sort.warning}
%    \begin{macrocode}
FUNCTION {sort.warning} {
    "to sort, need " swap$ * " or key in " * cite$ * warning$
}
%    \end{macrocode}
%    \end{macro}
%
%    \begin{macro}{author.sort}
%    \begin{macrocode}
FUNCTION {author.sort}
{ author empty$
    { key empty$
        { "author" sort.warning
          ""
        }
        { key sortify }
      if$
    }
    { author sort.format.names }
  if$
}
%    \end{macrocode}
%    \end{macro}
%
%    \begin{macro}{author.editor.sort}
%    \begin{macrocode}
FUNCTION {author.editor.sort}
{ author empty$
    { editor empty$
        { key empty$
            { "author, editor," sort.warning
              ""
            }
            { key sortify }
          if$
        }
        { editor sort.format.names }
      if$
    }
    { author sort.format.names }
  if$
}
%    \end{macrocode}
%    \end{macro}
%
%    \begin{macro}{author.organization.sort}
%    \begin{macrocode}
FUNCTION {author.organization.sort}
{ author empty$
    { organization empty$
        { key empty$
            { "author, organization," sort.warning
              ""
            }
            { key sortify }
          if$
        }
        { "The " #4 organization chop.word sortify }
      if$
    }
    { author sort.format.names }
  if$
}
%    \end{macrocode}
%    \end{macro}
%
%    \begin{macro}{editor.organization.sort}
%    \begin{macrocode}
FUNCTION {editor.organization.sort}
{ editor empty$
    { organization empty$
        { key empty$
            { "editor, organization," sort.warning
              ""
            }
            { key sortify }
          if$
        }
        { "The " #4 organization chop.word sortify }
      if$
    }
    { editor sort.format.names }
  if$
}
%    \end{macrocode}
%    \end{macro}
%
%    \begin{macro}{presort}
%    \begin{macrocode}
FUNCTION {presort} {
%<*alpha|short>
    calc.label
    label #20 rpad
%</alpha|short>
    type$ "book" = type$ "inbook" = OR type$ "collection" = OR
        'author.editor.sort
        { type$ "proceedings" =
            'editor.organization.sort
            { type$ "manual" =
                'author.organization.sort
                'author.sort
              if$
            }
          if$
        }
    if$
%<alpha|short>    * " " *
%<!alpha|short>    year field.or.null sortify #12 rpad * " " *
    title field.or.null sort.format.title *
    #1 entry.max$ substring$
    'sort.key$ :=
}
%    \end{macrocode}
%    \end{macro}
%
%    \begin{macrocode}
ITERATE {presort}

SORT
%    \end{macrocode}
%
%    \begin{macrocode}
%</sort>
%    \end{macrocode}
%
% \section{Final pass for output}
%
%    \begin{macro}{write.with.newlines}
%    The \fn{write.with.newlines} functions stores a string in \fn{s}
%    and runs through it looking for occurrences of \verb'^^M'; when one
%    is found, the substring before it is written out with a newline,
%    the remainder is left in \fn{s}, and the cycle begins again.
%    \begin{macrocode}
FUNCTION {write.with.newlines}
{ 's :=  #1 'ptr :=
  { s ptr #2 + #1 substring$ "" = NOT }
  { s ptr #3 substring$ "^^M" =
    { s #1 ptr #1 - substring$ write$ newline$
      ptr #3 + 'ptr :=
      s ptr global.max$ substring$ 's :=
      #1 'ptr :=
    }
    { incr.ptr }
    if$
  }
  while$
  s write$ newline$
}
%    \end{macrocode}
%    \end{macro}
%
%    \begin{macro}{begin.bin}
%    \begin{macrocode}
FUNCTION {begin.bib} {
    preamble$ empty$
        'skip$
        { preamble$ write.with.newlines }
    if$
    "% \bib, bibdiv, biblist are defined by the amsrefs package."
        write$ newline$
    "\begin{bibdiv}" write$ newline$
    "\begin{biblist}" write$ newline$
}
%    \end{macrocode}
%    \end{macro}
%
%    \begin{macro}{end.bin}
%    \begin{macrocode}
FUNCTION {end.bib} {
    newline$
    "\end{biblist}" write$ newline$
    "\end{bibdiv}" write$ newline$
}
%    \end{macrocode}
%    \end{macro}
%
%    \begin{macrocode}
EXECUTE {begin.bib}

ITERATE {call.type$}

EXECUTE {end.bib}
%</bst>
%    \end{macrocode}
%
% \section{Journal abbreviations}
%
%    By putting the ISSN into the \latex/ document, we make it easier to
%    construct www queries from the bibliography data. These string
%    definitions tie together journal abbreviations, ISSN numbers, and
%    journal names.
%
% These are the journals that are cited most frequently by American
% Mathematical Society authors at the present time (2000 CE).
%
% The format used here is designed to make it easy for BibTeX
% to retrieve an ISSN number when given a journal abbreviation.
%    \begin{macrocode}
%<*abbrevs>
@string{aa="aa/0065-1036/"
  #"Acta Arithmetica"}
@string{actamath="actamath/0001-5962/"
  #"Acta Mathematica"}
@string{asms="asms/0001-6969/"
  #"Acta Scientiarum Mathematicarum"}
@string{advmath="advmath/0001-8708/"
  #"Advances in Mathematics"}
@string{ajm="ajm/0002-9327/"
  #"American Journal of Mathematics"}
@string{amm="amm/0002-9890/"
  #"American Mathematical Monthly"}
@string{aifg="aifg/0373-0956/"
  #"Annales de l'Institut Fourier"}
@string{am2="am2/0003-486X/Annals of Mathematics"}
@string{ap="ap/0091-1798/"
  #"The Annals of Probability"}
@string{asens4="asens4/0012-9593/"
  #"Annales Scientifiques de l'\'{E}cole Normale Sup\'{e}rieure"}
@string{amb="amb/0003-889X/Archiv der Mathematik"}
@string{arma="arma/0003-9527/"
  #"Archive for Rational Mechanics and Analysis"}
@string{bamsn="bamsn/0273-0979/"
  #"Bulletin (New Series) of the American Mathematical Society"}
@string{bams="bams/0004-9727/"
  #"Bulletin of the Australian Mathematical Society"}
@string{blms="blms/0024-6093/"
  #"Bulletin of the London Mathematical Society"}
@string{bsmf="bsmf/0037-9484/"
  #"Bulletin de la Soci\'{e}t\'{e} Math\'{e}matique de France"}
@string{craspi="craspi/0764-4442/"
  #"Comptes Rendus de l'Acad\'{e}mie des Sciences (Paris)"
  #" S\'{e}rie I Math\'{e}matique"}
@string{cjm="cjm/0008-414X/Canadian Journal of Mathematics"}
@string{cmb="cmb/0008-4395/"
  #"Canadian Mathematical Bulletin"}
@string{colloqmath="colloqmath/0010-1354/"
  #"Colloquium Mathematicum"}
@string{commalgebra="commalgebra/0092-7872/"
  #"Communications in Algebra"}
@string{cmp="cmp/0010-3616/"
  #"Communications in Mathematical Physics"}
@string{cpam="cpam/0010-3640/"
  #"Communications on Pure and Applied Mathematics"}
@string{cmh="cmh/0010-2571/"
  #"Commentarii Mathematici Helvetici"}
@string{cvta="cvta/0278-1077/"
  #"Complex Variables"}
@string{compositiomath="compositiomath/0010-437X/"
  #"Compositio Mathematica"}
@string{c="c/0010-485X/Computing"}
@string{constrapprox="constrapprox/0176-4276/"
  #"Constructive Approximation"}
@string{dmj="dmj/0012-7094/"
  #"Duke Mathematical Journal"}
@string{eraams="eraams/1079-6762/"
  #"Electronic Research Announcements"
  #" of the American Mathematical Society"}
@string{etds="etds/0143-3857/"
  #"Ergodic Theory and Dynamical Systems"}
@string{fm="fm/0016-2736/"
  #"Fundamenta Mathematicae"}
@string{gd="gd/0046-5755/"
  #"Geometriae Dedicata"}
@string{illinoisjmath="illinoisjmath/0019-2082/"
  #"Illinois Journal of Mathematics"}
@string{iumj="iumj/0022-2518/"
  #"Indiana University Mathematics"}
@string{im="im/0020-9910/"
  #"Inventiones Mathematicae"}
@string{israeljmath="israeljmath/0021-2172/"
  #"Israel Journal of Mathematics"}
@string{iansm="iansm/??/"
  #"Izvestiya Akademii Nauk SSSR. Seriya Matematicheskaya"}
@string{ja="ja/0021-8693/"
  #"Journal of Algebra"}
@string{jams="jams/0894-0347/"
  #"Journal of the American Mathematical Society"}
@string{jam="jam/0021-7670/"
  #"Journal d'Analyse Math\'{e}matique"}
@string{jamm="jamm/0021-8928/"
  #"Journal of Applied Mathematics and Mechanics"}
@string{jat="jat/0021-9045/"
  #"Journal of Approximation Theory"}
@string{jamsa="jamsa/0263-6115/"
  #"Journal of the Australian Mathematical Society"}
@string{jcta="jcta/0097-3165/"
  #"Journal of Combinatorial Theory"}
@string{jde="jde/0022-0396/"
  #"Journal of Differential Equations"}
@string{jdg="jdg/0022-040X/Journal of Differential Geometry"}
@string{jfa="jfa/0022-1236/"
  #"Journal of Functional Analysis"}
@string{jlms2="jlms2/0024-6107/"
  #"Journal of the London Mathematical Society"}
@string{jmaa="jmaa/0022-247X/"
  #"Journal of Mathematical Analysis and Applications"}
@string{jmp="jmp/0022-2488/"
  #"Journal of Mathematical Physics"}
@string{jmsj="jmsj/0025-5645/"
  #"Journal of the Mathematical Society of Japan"}
@string{jnt="jnt/0022-314X/Journal of Number Theory"}
@string{jot="jot/0379-4024/"
  #"Journal of Operator Theory"}
@string{jpaa="jpaa/0022-4049/"
  #"Journal of Pure and Applied Algebra"}
% Braces instead of quotes, to hide the embedded \" control sequence
@string{jram={jram/0075-4102/}
  #{Journal f\"{u}r die Reine und Angewandte Mathematik}}
@string{jsl="jsl/0022-4812/"
  #"The Journal of Symbolic Logic"}
@string{laa="laa/0024-3795/"
  #"Linear Algebra and its Applications"}
@string{mm="mm/0025-2611/"
  #"Manuscripta Mathematica"}
@string{matzametki="matzametki/0025-567X/Matematicheskie Zametki"}
@string{ma="ma/0025-5831/"
  #"Mathematische Annalen"}
@string{mc="mc/0025-5718/"
  #"Mathematics of Computation"}
@string{mj="mj/0025-5513/"
  #"Mathematica Japonica"}
@string{mn="mn/0025-584X/Mathematische Nachrichten"}
@string{mpcps="mpcps/0305-0041/"
  #"Mathematical Proceedings of the"
  #" Cambridge Philosophical Society"}
@string{mrl="mrl/1073-2780/"
  #"Mathematical Research Letters"}
@string{ms="ms/0025-5521/"
  #"Mathematica Scandinavica"}
@string{mathz="mathz/0025-5874/"
  #"Mathematische Zeitschrift"}
@string{m="m/0025-5793/"
  #"Mathematika"}
@string{mmj="mmj/0026-2285/"
  #"The Michigan Mathematical Journal"}
@string{nmj="nmj/0027-7630/"
  #"Nagoya Mathematical Journal"}
@string{na="na/0362-546X/Nonlinear Analysis"}
@string{nm="nm/0029-599X/Numerische Mathematik"}
@string{ojm="ojm/0030-6126/"
  #"Osaka Journal of Mathematics"}
@string{pjm="pjm/0030-8730/"
  #"Pacific Journal of Mathematics"}
@string{pams="pams/0002-9939/"
  #"Proceedings of the American Mathematical Society"}
@string{pems2="pems2/0013-0915/"
  #"Proceedings of the Edinburgh Mathematical Society"}
@string{pjaa="pjaa/0386-2194/"
  #"Proceedings of the Japan Academy"}
@string{plms3="plms3/0024-6115/"
  #"Proceedings of the London Mathematical Society"}
@string{qjmo2="qjmo2/0033-5606/"
  #"The Quarterly Journal of Mathematics"}
@string{rmi="rmi/0213-2230/"
  #"Revista Matem\'{a}tica Iberoamericana"}
@string{rmjm="rmjm/0035-7596/"
  #"Rocky Mountain Journal of Mathematics"}
@string{sjam="sjam/0036-1399/"
  #"SIAM Journal on Applied Mathematics"}
@string{sjc="sjc/0097-5397/"
  #"SIAM Journal on Computing"}
@string{sjma="sjma/0036-1410/"
  #"SIAM Journal on Mathematical Analysis"}
@string{sjna="sjna/0036-1429/"
  #"SIAM Journal on Numerical Analysis"}
@string{sr="sr/0036-1445/"
  #"SIAM Review"}
@string{sm="sm/0039-3223/"
  #"Studia Mathematica"}
@string{tjm="tjm/0387-3870/"
  #"Tokyo Journal of Mathematics"}
@string{ta="ta/0166-8641/"
  #"Topology and its Applications"}
@string{t="t/0040-9383/"
  #"Topology"}
@string{tams="tams/0002-9947/"
  #"Transactions of the American Mathematical Society"}
%</abbrevs>
%    \end{macrocode}
%
% \section{To Do}
%
% ---When there is no author or editor info to create a label from: Use
%    the initial letters of all the words in the title. Plus the year.
%    Maybe year first.
%
% ---Add linelength and indent options to control the output?
%
% ---Discuss apacite "originalfoo" fields etc.
%
% ---Discuss Beebe's work.
%
% ---Add bibliography.
%
% ---Add AUDIO, VIDEO entry types.
%
% ---Add a field for MR subject classification numbers and the like?
%
% ---Write a converter to convert from typical .bib data to preferred
%    form. Have to go via perl or something to capture STRING defs and
%    PREAMBLE and interspersed comments? Or emacs lisp? Provide .bst
%    version as fallback.
%
% ---Alpha labels: add numbers after sorting? subscript option? L3Y2a
%    option.
%
% ---Test multi-author articles with ten-plus authors. What happens
%    with the alpha labels then?
%
% ---For url field especially, check length and prebreak by hand instead
%    of relying on \bibtex/'s slapdash stick-in-a-percent-at-column-72
%    regardless of where it happens to fall.
%
% ---How about a general `contributor' field.
%
% ---Test with a wimpy older version of \bibtex/.
%
% \CheckSum{24}
% \Finale