summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/bibtex/bst/apacite/apacannx.bst
blob: 5b8406c10c1b9b429759d2638700bc1843cc7ee5 (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
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065
4066
4067
4068
4069
4070
4071
4072
4073
4074
4075
4076
4077
4078
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
4123
4124
4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147
4148
4149
4150
4151
4152
4153
4154
4155
4156
4157
4158
4159
4160
4161
4162
4163
4164
4165
4166
4167
4168
4169
4170
4171
4172
4173
4174
4175
4176
4177
4178
4179
4180
4181
4182
4183
4184
4185
4186
4187
4188
4189
4190
4191
4192
4193
4194
4195
4196
4197
4198
4199
4200
4201
4202
4203
4204
4205
4206
4207
4208
4209
4210
4211
4212
4213
4214
4215
4216
4217
4218
4219
4220
4221
4222
4223
4224
4225
4226
4227
4228
4229
4230
4231
4232
4233
4234
4235
4236
4237
4238
4239
4240
4241
4242
4243
4244
4245
4246
4247
4248
4249
4250
4251
4252
4253
4254
4255
4256
4257
4258
4259
4260
4261
4262
4263
4264
4265
4266
4267
4268
4269
4270
4271
4272
4273
4274
4275
4276
4277
4278
4279
4280
4281
4282
4283
4284
4285
4286
4287
4288
4289
4290
4291
4292
4293
4294
4295
4296
4297
4298
4299
4300
4301
4302
4303
4304
4305
4306
4307
4308
4309
4310
4311
4312
4313
4314
4315
4316
4317
4318
4319
4320
4321
4322
4323
4324
4325
4326
4327
4328
4329
4330
4331
4332
4333
4334
4335
4336
4337
4338
4339
4340
4341
4342
4343
4344
4345
4346
4347
4348
4349
4350
4351
4352
4353
4354
4355
4356
4357
4358
4359
4360
4361
4362
4363
4364
4365
4366
4367
4368
4369
4370
4371
4372
4373
4374
4375
4376
4377
4378
4379
4380
4381
4382
4383
4384
4385
4386
4387
4388
4389
4390
4391
4392
4393
4394
4395
4396
4397
4398
4399
4400
4401
4402
4403
4404
4405
4406
4407
4408
4409
4410
4411
4412
4413
4414
4415
4416
4417
4418
4419
4420
4421
4422
4423
4424
4425
4426
4427
4428
4429
4430
4431
4432
4433
4434
4435
4436
4437
4438
4439
4440
4441
4442
4443
4444
4445
4446
4447
4448
4449
4450
4451
4452
4453
4454
4455
4456
4457
4458
4459
4460
4461
4462
4463
4464
4465
4466
4467
4468
4469
4470
4471
4472
4473
4474
4475
4476
4477
4478
4479
4480
4481
4482
4483
4484
4485
4486
4487
4488
4489
4490
4491
4492
4493
4494
4495
4496
4497
4498
4499
4500
4501
4502
4503
4504
4505
4506
4507
4508
4509
4510
4511
4512
4513
4514
4515
4516
4517
4518
4519
4520
4521
4522
4523
4524
4525
4526
4527
4528
4529
4530
4531
4532
4533
4534
4535
4536
4537
4538
4539
4540
4541
4542
4543
4544
4545
4546
4547
4548
4549
4550
4551
4552
4553
4554
4555
4556
4557
4558
4559
4560
4561
4562
4563
4564
4565
4566
4567
4568
4569
4570
4571
4572
4573
4574
4575
4576
4577
4578
4579
4580
4581
4582
4583
4584
4585
4586
4587
4588
4589
4590
4591
4592
4593
4594
4595
4596
4597
4598
4599
4600
4601
4602
4603
4604
4605
4606
4607
4608
4609
4610
4611
4612
4613
4614
4615
4616
4617
4618
4619
4620
4621
4622
4623
4624
4625
4626
4627
4628
4629
4630
4631
4632
4633
4634
4635
4636
4637
4638
4639
4640
4641
4642
4643
4644
4645
4646
4647
4648
4649
4650
4651
4652
4653
4654
4655
4656
4657
4658
4659
4660
4661
4662
4663
4664
4665
4666
4667
4668
4669
4670
4671
4672
4673
4674
4675
4676
4677
4678
4679
4680
4681
4682
4683
4684
4685
4686
4687
4688
4689
4690
4691
4692
4693
4694
4695
4696
4697
4698
4699
4700
4701
4702
4703
4704
4705
4706
4707
4708
4709
4710
4711
4712
4713
4714
4715
4716
4717
4718
4719
4720
4721
4722
4723
4724
4725
4726
4727
4728
4729
4730
4731
4732
4733
4734
4735
4736
4737
4738
4739
4740
4741
4742
4743
4744
4745
4746
4747
4748
4749
4750
4751
4752
4753
4754
4755
4756
4757
4758
4759
4760
4761
4762
4763
4764
4765
4766
4767
4768
4769
4770
4771
4772
4773
4774
4775
4776
4777
4778
4779
4780
4781
4782
4783
4784
4785
4786
4787
4788
4789
4790
4791
4792
4793
4794
4795
4796
4797
4798
4799
4800
4801
4802
4803
4804
4805
4806
4807
4808
4809
4810
4811
4812
4813
4814
4815
4816
4817
4818
4819
4820
4821
4822
4823
4824
4825
4826
4827
4828
4829
4830
4831
4832
4833
4834
4835
4836
4837
4838
4839
4840
4841
4842
4843
4844
4845
4846
4847
4848
4849
4850
4851
4852
4853
4854
4855
4856
4857
4858
4859
4860
4861
4862
4863
4864
4865
4866
4867
4868
4869
4870
4871
4872
4873
4874
4875
4876
4877
4878
4879
4880
4881
4882
4883
4884
4885
4886
4887
4888
4889
4890
4891
4892
4893
4894
4895
4896
4897
4898
4899
4900
4901
4902
4903
4904
4905
4906
4907
4908
4909
4910
4911
4912
4913
4914
4915
4916
4917
4918
4919
4920
4921
4922
4923
4924
4925
4926
4927
4928
4929
4930
4931
4932
4933
4934
4935
4936
4937
4938
4939
4940
4941
4942
4943
4944
4945
4946
4947
4948
4949
4950
4951
4952
4953
4954
4955
4956
4957
4958
4959
4960
4961
4962
4963
4964
4965
4966
4967
4968
4969
4970
4971
4972
4973
4974
4975
4976
4977
4978
4979
4980
4981
4982
4983
4984
4985
4986
4987
4988
4989
4990
4991
4992
4993
4994
4995
4996
4997
4998
4999
5000
5001
5002
5003
5004
5005
5006
5007
5008
5009
5010
5011
5012
5013
5014
5015
5016
5017
5018
5019
5020
5021
5022
5023
5024
5025
5026
5027
5028
5029
5030
5031
5032
5033
5034
5035
5036
5037
5038
5039
5040
5041
5042
5043
5044
5045
5046
5047
5048
5049
5050
5051
5052
5053
5054
5055
5056
5057
5058
5059
5060
5061
5062
5063
5064
5065
5066
5067
5068
5069
5070
5071
5072
5073
5074
5075
5076
5077
5078
5079
5080
5081
5082
5083
5084
5085
5086
5087
5088
5089
5090
5091
5092
5093
5094
5095
5096
5097
5098
5099
5100
5101
5102
5103
5104
5105
5106
5107
5108
5109
5110
5111
5112
5113
5114
5115
5116
5117
5118
5119
5120
5121
5122
5123
5124
5125
5126
5127
5128
5129
5130
5131
5132
5133
5134
5135
5136
5137
5138
5139
5140
5141
5142
5143
5144
5145
5146
5147
5148
5149
5150
5151
5152
5153
5154
5155
5156
5157
5158
5159
5160
5161
5162
5163
5164
5165
5166
5167
5168
5169
5170
5171
5172
5173
5174
5175
5176
5177
5178
5179
5180
5181
5182
5183
5184
5185
5186
5187
5188
5189
5190
5191
5192
5193
5194
5195
5196
5197
5198
5199
5200
5201
5202
5203
5204
5205
5206
5207
5208
5209
5210
5211
5212
5213
5214
5215
5216
5217
5218
5219
5220
5221
5222
5223
5224
5225
5226
5227
5228
5229
5230
5231
5232
5233
5234
5235
5236
5237
5238
5239
5240
5241
5242
5243
5244
5245
5246
5247
5248
5249
5250
5251
5252
5253
5254
5255
5256
5257
5258
5259
%%
%% This is file `apacannx.bst',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% apacite.dtx  (with options: `xbibstyle,annotated')
%% 
%% This is a generated file.
%% 
%% Copyright (C) 1994-2009 Erik Meijer and any individual authors listed
%% elsewhere in this file.
%% 
%% This file is part of the `apacite' package.
%% -------------------------------------------
%% 
%% It may be distributed and/or modified under the
%% conditions of the LaTeX Project Public License, either
%% version 1.3 of this license or (at your option) any later
%% version.  The latest version of this license is in:
%% 
%%    http://www.latex-project.org/lppl.txt
%% 
%% and version 1.3 or later is part of all distributions of
%% LaTeX version 2005/12/01 or later.
%% 
%% The `apacite' package consists of the files apacite.dtx and
%% apacite.ins, and the following generated files:
%% apacite.sty, apacite.bst, apacitex.bst, apa5ex.bib,
%% apacite.drv, apacdoc.sty, apacann.bst,  apacannx.bst,
%% english.apc, dutch.apc,   finnish.apc,  french.apc,  german.apc,
%% ngerman.apc, greek.apc,   norsk.apc,   spanish.apc,  swedish.apc.
%% 
%% This work has the LPPL maintenance status `maintained'
%% 
%% The Current Maintainer of this work is Erik Meijer
%% 
%% This file may only be distributed together with a copy of the
%% source files of the apacite package, i.e., apacite.dtx and
%% apacite.ins. You may however distribute the apacite package without
%% the generated files.
%% 
%% apacannx.bst
%%   [2009/03/01 v4.05 APA annotated bibl. style with author index info]
%% apacannx.bst : reference list according to APA manual
%%                with annotations and author indexing information
%% Written by Erik Meijer

FUNCTION {identify.apacite.version}
{ % Put identifying string in the .blg file
  "apacannx.bst"
" [2009/03/01 v4.05 APA annotated bibl. style with author index info]"
  * top$
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

ENTRY
  { address
    annote       % only used for annotated version
    annotate     % only used for annotated version
    author
    booktitle    % for articles in books
    chair        % for lectures
    chapter      % for incollection, esp. internet documents
    day
    edition
    editor
    englishtitle % english translation of title in other language
    firstkey     % key for first citation
    howpublished
    institution  % for technical reports
    journal
    key          % key for second and later citations, or all
                 % citations if firstkey is missing
    lastchecked  % for URL's
    month
    note
    number       % number of journal or report
    organization % for unpublished
        %
        % for reprints, translations, etc.
        %
    originaladdress
    originalbooktitle
    originaledition
    originaleditor
    originaljournal
    originalnumber
    originalpages
    originalpublisher
    originalvolume
    originalyear
        %
        % back to normal
        %
    pages
    publisher
    school       % for theses
    series       % not used
    symposium    % for lectures
    text         % for literals
    title
    translator   % translator of book (or article)
    type         % type of phdthesis (e.g., Doctoral dissertation)
                 % or type of article (e.g., Letter to the editor)
                 % etc.
    url
    volume
    year
  }
  { title.number           % for sorting titles
    cite.initials          % dummy (0-1) indicating whether or not
                           % initials of the 1st author must
                           % be used for citing
    cite.num.names.full    % number of names to be cited for full and
    cite.num.names.short   % short cite
    add.to.year            % For a, b, c, etc. after year
                           % in multiple citations with same author-year
  }
  { year.label             % For sorting entries by year
    author.year.sort.label % For sorting entries and checking whether
                           % initials should be added, how many authors
                           % should be cited and whether a, b, etc.
                           % after year is necessary
    title.sort.label       % for sorting titles
    type.2                 % Replacement for type with misc entries and
                           % entries that revert to misc.
  }

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

INTEGERS { len  pos  name.max  old.number  numnames  numnames.old
           nameptr  lastname  format.num.names  cite.initials.old
           cite.num.names.old add.to.year.old  forward
           multiresult  dot brace.level
         }

STRINGS  { s  t  u old.label  field
           aut1f  aut1s  aut1f.old  aut1s.old
           aut2          aut2.old
           aut3          aut3.old
           aut4          aut4.old
           aut5          aut5.old
           aut6          aut6.old
           year.label.old
         }

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

FUNCTION {test} { #0 }

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

FUNCTION {make.index} { #1 }

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


MACRO {jan}    {"{\APACmonth{01}}"}

MACRO {feb}    {"{\APACmonth{02}}"}

MACRO {mar}    {"{\APACmonth{03}}"}

MACRO {apr}    {"{\APACmonth{04}}"}

MACRO {may}    {"{\APACmonth{05}}"}

MACRO {jun}    {"{\APACmonth{06}}"}

MACRO {jul}    {"{\APACmonth{07}}"}

MACRO {aug}    {"{\APACmonth{08}}"}

MACRO {sep}    {"{\APACmonth{09}}"}

MACRO {oct}    {"{\APACmonth{10}}"}

MACRO {nov}    {"{\APACmonth{11}}"}

MACRO {dec}    {"{\APACmonth{12}}"}

MACRO {winter} {"{\APACmonth{13}}"}

MACRO {spring} {"{\APACmonth{14}}"}

MACRO {summer} {"{\APACmonth{15}}"}

MACRO {fall}   {"{\APACmonth{16}}"}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

FUNCTION {not}
{   { #0 }
    { #1 }
  if$
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

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

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

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

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    % issues warning if field is empty
    % call with
    %    "field"  field  warning.if.empty
    % Note that the first field must be between quotes
    % because it is the fieldname for use in the warning message.
    %
FUNCTION {warning.if.empty}
{ empty$
    { "No "  swap$ * " in " * cite$ * warning$ }
    { pop$ }
  if$
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    %
    % issues warning if title, type, and howpublished are empty
    %
FUNCTION {check.relevant.fields}
{ title        empty$
  type         empty$ and
  howpublished empty$ and
    { "No title, type, and howpublished in " cite$ * warning$ }
    'skip$
  if$
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    %
    % delivers 1 if (both editor and translator
    %                not empty and not equal to each other)
    %          0 if (editor or translator empty) or
    %               (editor = translator)
    %
FUNCTION {editor.ne.trans}
{ translator empty$
    { #0 }
    { editor empty$
        { #0 }
        { translator editor =
            { #0 }
            { #1 }
          if$
        }
      if$
    }
  if$
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

FUNCTION {conv.int.to.str}
{ duplicate$ #10 <
    { "0000" swap$ int.to.str$ * }
    { duplicate$ #100 <
        { "000" swap$ int.to.str$ * }
        { duplicate$ #1000 <
            { "00" swap$ int.to.str$ * }
            { duplicate$ #10000 <
                { "0" swap$ int.to.str$ * }
                { int.to.str$ }
              if$
            }
          if$
        }
      if$
    }
  if$
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

FUNCTION {ref.type}
{ type$ "article"      =
    type$ "magazine"     =
      type$ "newspaper"    =
        type$ "book"         =
          type$ "techreport"   =
            type$ "unpublished"  =
              type$ "misc"         =
                type$ "booklet"      =
                  type$ "manual"       =
                    type$ "proceedings"  =
                    or
                  or
                or
              or
            or
          or
        or
      or
    or
    { #1 }
    { type$ "incollection"   =
        type$ "phdthesis"      =
          type$ "mastersthesis"  =
            type$ "lecture"        =
              type$ "inbook"         =
                type$ "inproceedings"  =
                  type$ "conference"  =
                    type$ "intechreport"   =
                    or
                  or
                or
              or
            or
          or
        or
        { #2 }
        { type$ "literal" =
            { #3 }
            { #0 }
          if$
        }
      if$
    }
  if$
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

FUNCTION {is.atype}
{ type$ "article"        =
    type$ "magazine"       =
      type$ "newspaper"      =
        type$ "incollection"   =
          type$ "inbook"         =
            type$ "inproceedings"  =
              type$ "conference"  =
                type$ "intechreport"   =
                  type$ "manual"         =
                  or
                or
              or
            or
          or
        or
      or
    or
    { #1 }
    { journal empty$ not
        %
      type$ "phdthesis"      =
        type$ "mastersthesis"  =
        or
        %
      and
        { #1 }
        { type$ "misc" =
          type empty$ not and
            { type "\bibmessage" =
                type "\bibcomputerprogram" =
                  type "\bibcomputerprogrammanual" =
                    type "\bibcomputerprogramandmanual" =
                      type "\bibcomputersoftware" =
                        type "\bibcomputersoftwaremanual" =
                          type "\bibcomputersoftwareandmanual" =
                            type "\bibprogramminglanguage" =
                            or
                          or
                        or
                      or
                    or
                  or
                or
                { #1 }
                { #0 }
              if$
            }
            { #0 }
          if$
        }
      if$
    }
  if$
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    %
    % connects two strings with connect string
    % if one of them empty, then connect string
    % is left out
    %
    % call with S1 S2 connectstring connect.check
    %
FUNCTION {connect.check}
{ 'u :=
    %
    % if S2 = ""
    %
  duplicate$ empty$
      %
      % then remove S2
      %
    { pop$
        %
        % S1 is on top of stack.
        % if it is empty, it is replaced by the empty string ""
        %
      duplicate$ empty$
        { pop$ "" }
        'skip$
      if$
    }
      %
      % else swap S1 and S2 so that S1 can be checked
      %
    { swap$
        %
        % if S1 is empty, remove S1 so that S2 is left on the
        % stack and is the result is given
        %
      duplicate$ empty$
        { pop$ }
            %
            % now the real work starts:
            % push the connect string "C"
            % so that top of stack is "C" "S1" "S2"
            % concatenate, so that top of stack is
            % "S1+C" "S2"
            %
        { u *
            %
            % swap and concatenate
            %
          swap$ *
        }
      if$
    }
  if$
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    %
    % connects two strings with space ("\ ")
    % if length of second is 4 or larger,
    % connects them with non-breaking space ("tie", "~")
    % if length of second smaller than 4
    %
    % call with S1 S2 tie.or.space.connect
    % result: "S1\ S2" or "S1~S2"
    %
FUNCTION {tie.or.space.connect}
{ duplicate$ text.length$ #4 <
    { "~" }
    { "\ " }
  if$
  swap$ * *
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    %
    % connects two strings with comma (", ")
    % if one of them is empty, the comma is left out
    %
    % call with S1 S2 connect.with.comma.check
    % result: "S1, S2"
    %
FUNCTION {connect.with.comma.check}
{ ", " connect.check }

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    %
    % connects two strings with semicolon ("; ")
    % if one of them is empty, semicolon is left out
    %
    % call with S1 S2 connect.with.semicolon.check
    % result: "S1; S2"
    %
FUNCTION {connect.with.semicolon.check}
{ "; " connect.check }

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    %
    % connects two strings with colon (": ")
    % if one of them is empty, colon is left out
    %
    % call with S1 S2 connect.with.colon.check
    % result: "S1: S2"
    %
FUNCTION {connect.with.colon.check}
{ ": " connect.check }

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    %
    % connects two strings with space ("\ ")
    %
    % call with S1 S2 connect.with.space.check
    % result: "S1\ S2"
    %
FUNCTION {connect.with.space.check}
{ "\ " connect.check }

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    %
    % encloses string in pre- and postfix string
    % call with
    %    prefix postfix  S  enclose.check
    % delivers empty string if S empty
    %
FUNCTION {enclose.check}
{ duplicate$ empty$
    { pop$ pop$ pop$
      ""
    }
    { swap$ * * }
  if$
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    %
    % emphasizes top of stack
    % call with
    %     "string" emphasize.check
    %
FUNCTION {emphasize.check}
{ "\Bem{" swap$
  "}"     swap$
  enclose.check
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    %
    % brackets top of stack
    % call with
    %     "string" bracket
    %
FUNCTION {bracket.check}
{ "[" swap$
  "]" swap$
  enclose.check
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    %
    % parenthesizes top of stack
    % call with
    %     "string" parenthesize
    %
FUNCTION {parenthesize.check}
{ "(" swap$
  ")" swap$
  enclose.check
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    %
    % checks whether argument is "multiresult":
    % whether it contains '-', '+', or ',' characters
    % used with pages to check whether pp. or p. must be used
    %
FUNCTION {multi.result.check}
{ 't :=
  #0 'multiresult :=
  %
  % while (not multiresult) and (length(t) > 1) do
  %
    { multiresult not
      t text.length$ #1 >
      and
    }
        %
        % if t(1-2) = "--" or t(1) = "+" or ","
        % then  multiresult = 1
        % else  t = t(2-last)
        %
    { t #1 #2 substring$ 's :=
      "--" s =
        { #1 'multiresult := }
        { t #1 #1 substring$ 's :=
          "+" s =
            "," s =
            or
            { #1 'multiresult := }
            { t #2 global.max$ substring$ 't := }
          if$
        }
      if$
    }
  while$
  multiresult
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    %
    % Checks whether an author is a corporate author, i.e.,
    % whether the field starts with "{\bibcorporate".
    % Call with
    %   field is.bibcorporate
    %
FUNCTION {is.bibcorporate}
{ #1 #14 substring$ "{\bibcorporate" = }

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

FUNCTION {sortify}
{ purify$
  "l" change.case$
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

FUNCTION {remove.spaces}
{   % Remove spaces from string.
    % Works best if string only contains alphanumeric characters and spaces.
  's :=                    % The original string
  s text.length$ 'len :=   % Its length (no. of characters)
  "" 't :=                 % Initialize the transformed string
  #0 'pos :=
    %
    % while (pos < len) do
    %
  { pos len < }
    { pos #1 +  'pos :=
      s pos #1 substring$  'u :=
        %
        % u is the pos-th character in s
        % If it is a space, move to next character,
        % else copy character to output.
        %
      u " " =
        'skip$
        { t u *  't := }
      if$
    }
  while$
    %
    % Now push the result back on the stack
  t
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    %
    % starting new block by writing what's left on the stack,
    % starting a new line and adding some extra space or
    % whatever is more defined in \newblock
    %
FUNCTION {output.end.block}
{ write$
  newline$
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    %
    % starting new block by writing what's left on the stack,
    % starting a new line and adding some extra space or
    % whatever is more defined in \newblock
    %
FUNCTION {output.new.block}
{ output.end.block
  "\newblock" write$
  newline$
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    %
    % starting new block by writing what's left on the stack,
    % starting a new line and adding some extra space or
    % whatever is more defined in \newblock
    %
FUNCTION {output.dot.new.block}
{ add.period$
  output.new.block
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

FUNCTION {start.new.block}
{ newline$
  "\unskip\ " write$ newline$
  "\newblock " write$ newline$
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    %
    % finish current entry
    % by writing what's left on the stack and starting a new line
    %
FUNCTION {fin.entry}
{ output.end.block
  "\PrintBackRefs{\CurrentBib}" write$ newline$
  test
    { "\vspace{\baselineskip}" write$ newline$ }
    'skip$
  if$
    %
    % According to TLC2, pp. 810-811, both annote and annotate fields are
    % known, so support them both, but do not print them both, in case
    % someone wants to make a file that is compatible with both the annotate
    % and annotation styles and thus duplicates the information. Instead, we
    % give annote priority.
    %
  annote empty$
    {% Try annotate
      annotate empty$
        'skip$
        { % add annotation
          "\begin{APACrefannotation}" write$ newline$
          annotate write$ newline$
          "\end{APACrefannotation}" write$ newline$
        }
      if$
    }
    { % add annotation
      "\begin{APACrefannotation}" write$ newline$
      annote write$ newline$
      "\end{APACrefannotation}" write$ newline$
    }
  if$
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

FUNCTION {sort.name.format} { "{ll{}}{  f{}}{  vv{}}{  jj{}}" }

FUNCTION {cite.name.format} { "{ll}" }

FUNCTION {cite.initials.name.format} { "{f{\BPBI }.~~}{vv }{ll}{ jj}" }

FUNCTION {author.name.format} { "{ll}{, f{\BPBI }.}{ vv}{, jj}" }

FUNCTION {editor.name.format} { "{f{\BPBI }.~~}{vv }{ll}{ jj}" }

FUNCTION {index.name.format} { "{ll}{, f{\BPBI }.}{ vv}{, jj}" }

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

FUNCTION {init.initials}
{ "yyyyy"  'aut1f.old :=
  "yyyyy"  'aut1s.old :=
  #0       'cite.initials.old :=
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

FUNCTION {update.no.initials}
{ 'field :=
  field  'aut1f.old :=
  field  'aut1s.old :=
  #0     'cite.initials.old :=
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

FUNCTION {check.add.initials.aut}
{   %
    % If last name is equal to previous last name
    % but initials are different, then initials should
    % be cited. If initials are also the same, initials
    % should be cited if that is the case for the previous
    % author .
    %
  aut1s aut1s.old =
    { aut1f aut1f.old =
        { cite.initials.old  'cite.initials := }
        { #1             'cite.initials :=
          aut1f          'aut1f.old :=
          aut1s          'aut1s.old :=
          cite.initials  'cite.initials.old :=
        }
      if$
    }
    {  %
       % Different last name.
      aut1f          'aut1f.old :=
      aut1s          'aut1s.old :=
      cite.initials  'cite.initials.old :=
    }
  if$
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

FUNCTION {check.add.initials.field}
{ 'field :=
  field #1 cite.initials.name.format format.name$  'aut1f :=
  field #1 cite.name.format          format.name$  'aut1s :=
    %
    % Now do the actual work
    %
  check.add.initials.aut
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

FUNCTION {check.add.initials}
{   %
    % Check whether author or editor or other field acts as author.
    % Initials are only relevant with author or editor.
    %
  firstkey empty$ not
    { key empty$ not
        {   %
            % Both key and firstkey are nonempty.
            % Then, key is treated as last name of first author,
            % and firstkey is treated as last name + initials of
            % first author .
            %
          firstkey  sortify  remove.spaces  'aut1f :=
          key       sortify  remove.spaces  'aut1s :=
          check.add.initials.aut
        }
        { firstkey  sortify  remove.spaces  update.no.initials }
      if$
    }
    { key empty$ not
        { key  sortify  remove.spaces  update.no.initials }
        {   %
            % No key or firstkey, so find out which field
            % to use as author.
            %
            % Check reference type:
            %   if result is 1 then possibly editor acts as author
            %                2 then editor does not act as author
            %                3 then key should have been used
            %                0 then unknown reference type
          ref.type  #2 =
            {   %
                % Format first author with and without initials
              author empty$
                { title.sort.label  update.no.initials }
                { author  check.add.initials.field }
              if$
            }
            {   %
                % Format first author with and without initials
              author empty$
                { editor empty$
                    { title.sort.label  update.no.initials }
                    { editor check.add.initials.field }
                  if$
                }
                { author check.add.initials.field }
              if$
            }
          if$
        }
      if$
    }
  if$
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

FUNCTION {tentative.cite.num.names.field}
{ 'field :=
  field num.names$  'numnames :=
  numnames #3 <
    {   %
        % 1 or 2 names: always cite all of them.
      numnames  'cite.num.names.full  :=
      numnames  'cite.num.names.short :=
    }
    { numnames #6 <
        {   %
            % 3-5 names: cite all of them the first time,
            % only the first name later times
          numnames  'cite.num.names.full  :=
          #1        'cite.num.names.short :=
        }
        {   %
            % 6 or more names: cite only the first name
          #1  'cite.num.names.full  :=
          #1  'cite.num.names.short :=
        }
      if$
    }
  if$
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

FUNCTION {tentative.cite.num.names}
{   %
    % Check whether author or editor or other field acts as author.
    % Number of names is only relevant with author or editor.
    %
  firstkey empty$ not
    {
      #1 'cite.num.names.full  :=
      #1 'cite.num.names.short :=
    }
    { key empty$ not
        {
          #1 'cite.num.names.full  :=
          #1 'cite.num.names.short :=
        }
        {   %
            % No key or firstkey, so find out which field
            % to use as author.
            %
            % Check reference type:
            %   if result is 1 then possibly editor acts as author
            %                2 then editor does not act as author
            %                3 then key should have been used
            %                0 then unknown reference type
          ref.type  #2 =
            {   %
                % Format first author with and without initials
              author empty$
                {
                  #1 'cite.num.names.full  :=
                  #1 'cite.num.names.short :=
                }
                { author tentative.cite.num.names.field }
              if$
            }
            {   %
                % Format first author with and without initials
              author empty$
                { editor empty$
                    {
                      #1 'cite.num.names.full  :=
                      #1 'cite.num.names.short :=
                    }
                    { editor tentative.cite.num.names.field }
                  if$
                }
                { author tentative.cite.num.names.field }
              if$
            }
          if$
        }
      if$
    }
  if$
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

FUNCTION {init.cite.num.names}
{ #0      'cite.num.names.old  :=
  #0      'numnames.old        :=
  "yyyy"  'year.label.old      :=
  #0      'add.to.year.old     :=
  ""      'aut1f.old           :=
  ""      'aut2.old            :=
  ""      'aut3.old            :=
  ""      'aut4.old            :=
  ""      'aut5.old            :=
  ""      'aut6.old            :=
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

FUNCTION {update.cite.num.names}
{ cite.num.names.short  'cite.num.names.old  :=
  numnames              'numnames.old        :=
  year.label            'year.label.old      :=
  add.to.year           'add.to.year.old     :=
  aut1f                 'aut1f.old           :=
  aut2                  'aut2.old            :=
  aut3                  'aut3.old            :=
  aut4                  'aut4.old            :=
  aut5                  'aut5.old            :=
  aut6                  'aut6.old            :=
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

FUNCTION {format.6.authors}
{   %
    % First author: with initials.
    %
  field #1 cite.initials.name.format format.name$  'aut1f :=
    %
    % Second and later authors: without initials.
    %
  numnames #1 >
    name.max #1 >
      and
    {   %
        % 2nd author
      field #2 cite.name.format format.name$  'aut2 :=
        %
      numnames #2 >
        name.max #2 >
          and
        {   %
            % 3nd author
          field #3 cite.name.format format.name$  'aut3 :=
            %
          numnames #3 >
            name.max #3 >
              and
            {   %
                % 4th author
              field #4 cite.name.format format.name$  'aut4 :=
                %
              numnames #4 >
                name.max #4 >
                  and
                {   %
                    % 5th author
                  field #5 cite.name.format format.name$  'aut5 :=
                    %
                  numnames #5 >
                    name.max #5 >
                      and
                    {   %
                        % 6th author
                      field #6 cite.name.format format.name$  'aut6 :=
                    }
                    {   %
                        % 5 authors: 6 is empty
                        %
                      "" 'aut6 :=
                    }
                  if$
                }
                {   %
                    % 4 authors: 5-6 are empty
                    %
                  "" 'aut5 :=
                  "" 'aut6 :=
                }
              if$
            }
            {   %
                % 3 authors: 4-6 are empty
                %
              "" 'aut4 :=
              "" 'aut5 :=
              "" 'aut6 :=
            }
          if$
        }
        {   %
            % 2 authors: 3-6 are empty
            %
          "" 'aut3 :=
          "" 'aut4 :=
          "" 'aut5 :=
          "" 'aut6 :=
        }
      if$
    }
    {   %
        % Only 1 author: 2-6 are empty
        %
      "" 'aut2 :=
      "" 'aut3 :=
      "" 'aut4 :=
      "" 'aut5 :=
      "" 'aut6 :=
    }
  if$
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

FUNCTION {change.add.to.year}
{
  forward  #1  =
    {   %
        % Moving forward: this add.to.year number must be 1 higher than
        % previous.
        %
      add.to.year.old  #0  >
        { add.to.year.old  #1 +    'add.to.year  := }
        { #2  'add.to.year  := }
      if$
    }
    {   %
        % Moving backward: this add.to.year number must be 1 lower than
        % previous.
        %
      add.to.year.old  #1 -    'add.to.year  :=
    }
  if$
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

FUNCTION {definitive.cite.num.names.1.or.2}
{   %
  numnames  numnames.old  =
    {   %
        % Same number of names: ambiguity could arise. Check whether current
        % and previous have the same author(s).
        %
      aut1f aut1f.old =
        {   %
            % Same first author: if the second author is also the same or if
            % there is only one author, a's and b's should be added.
            %
          aut2  aut2.old  =
            numnames  #2  =
              and
                %
          numnames  #1  =
            or
            {   %
                % Same author(s): add to year.
                %
              change.add.to.year
            }
            {   %
                % Different second author: no ambiguity possible.
                %
              skip$
            }
          if$
        }
        {   %
            % Different first author: no ambiguity possible.
            %
          skip$
        }
      if$
    }
    {   %
        % Different number of names: no ambiguity possible.
        %
      skip$
    }
  if$
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

FUNCTION {definitive.cite.num.names.3.or.more}
{   %
    % Check whether current and previous have the same first author.
    %
  aut1f aut1f.old =
    {   %
        % Same first author: check second author
        %
      aut2 aut2.old =
        {   %
            % Same 1st & 2nd author: check 3rd.
            %
          aut3 aut3.old =
            {   %
                % Same 1st-3rd authors: check 4th.
                %
              numnames.old #3 =
                { numnames #3 =
                    {   %
                        % Both current and previous have 3 authors, which are
                        % the same, so both have identical author-year
                        % combinations, so ambiguity should be resolved by
                        % a's and b's. Check whether more authors were
                        % necessary for previous one.
                        %
                      change.add.to.year
                      cite.num.names.short  cite.num.names.old  <
                        { cite.num.names.old
                            'cite.num.names.short :=
                        }
                        'skip$
                      if$
                    }
                    {   %
                        % Previous has 3 authors, current has more, with same
                        % first 3, so at least 4 must be used for current to
                        % make a difference.
                        %
                      cite.num.names.short  #4  <
                        { #4  'cite.num.names.short := }
                        'skip$
                      if$
                    }
                  if$
                }
                { numnames #3 =
                    {   %
                        % Current has 3 authors, previous has more, with same
                        % first 3, so all 3 of current must be used.
                        %
                      numnames  'cite.num.names.short :=
                    }
                    {   %
                        % Same 1st-3rd author and both current and previous
                        % have at least 4 authors: check 4th.
                        %
                      aut4 aut4.old =
                        {   %
                            % Same 1st-4th authors: check 5th.
                            %
                          numnames.old #4 =
                            { numnames #4 =
                                {   %
                                    % Both current and previous have 4 authors,
                                    % which are the same, so both have
                                    % identical author-year combinations, so
                                    % ambiguity should be resolved by a's and
                                    % b's. Check whether more authors were
                                    % necessary for previous one.
                                    %
                                  change.add.to.year
                                  cite.num.names.short cite.num.names.old  <
                                    { cite.num.names.old
                                        'cite.num.names.short :=
                                    }
                                    'skip$
                                  if$
                                }
                                {   %
                                    % Previous has 4 authors, current has more,
                                    % with same first 4, so at least 5 must be
                                    % used for current to make a difference.
                                    %
                                  cite.num.names.short  #5  <
                                    { #5  'cite.num.names.short := }
                                    'skip$
                                  if$
                                }
                              if$
                            }
                            { numnames #4 =
                                {   %
                                    % Current has 4 authors, previous has more,
                                    % with same first 4, so all 4 of current
                                    % must be used.
                                    %
                                  numnames  'cite.num.names.short :=
                                }
                                {   %
                                    % Same 1st-4th author and both current and
                                    % previous have at least 5 authors: check
                                    % 5th.
                                    %
                                  aut5 aut5.old =
                                    {   %
                                        % Same 1st-5th authors: check 6th.
                                        %
                                      numnames.old #5 =
                                        { numnames #5 =
                                            {   %
                                                % Both current and previous
                                                % have 5 authors, which are the
                                                % same, so both have identical
                                                % author-year combinations, so
                                                % ambiguity should be resolved
                                                % by a's and b's. Check whether
                                                % more authors were necessary
                                                % for previous one.
                                                %
                                              change.add.to.year
                                              cite.num.names.short
                                                cite.num.names.old  <
                                                { cite.num.names.old
                                                    'cite.num.names.short  :=
                                                }
                                                'skip$
                                              if$
                                            }
                                            {   %
                                                % Previous has 5 authors,
                                                % current has more, with same
                                                % first 5, so at least 6 must
                                                % be used for current to make
                                                % a difference.
                                                %
                                              cite.num.names.short #6 <
                                                { #6 'cite.num.names.short := }
                                                'skip$
                                              if$
                                            }
                                          if$
                                        }
                                        { numnames #5 =
                                            {   %
                                                % Current has 5 authors,
                                                % previous has more, with same
                                                % first 5, so all 5 of current
                                                % must be used.
                                                %
                                              numnames 'cite.num.names.short :=
                                            }
                                            {   %
                                                % Same 1st-5th author and both
                                                % current and previous have at
                                                % least 6 authors. If one has
                                                % 6 authors and the other has
                                                % more or the 6th is different,
                                                % 6 should be used (which is
                                                % the maximum).
                                                %
                                              numnames #6 >
                                                numnames.old #6 =
                                                  and
                                                %
                                              numnames #6 =
                                                numnames.old #6 >
                                                  and
                                                %
                                              or
                                                %
                                              aut6 aut6.old =
                                                not
                                                %
                                              or
                                                { #6 cite.num.names.short <
                                                    { #6
                                                        'cite.num.names.short
                                                          :=
                                                    }
                                                    'skip$
                                                  if$
                                                }
                                                {   %
                                                    % The first 6 authors are
                                                    % the same and either both
                                                    % have 6 or both have more.
                                                    % So for all practical
                                                    % purposes they have
                                                    % identical author-year
                                                    % combination, so ambiguity
                                                    % should be resolved by a's
                                                    % and b's. Check whether
                                                    % more authors were
                                                    % necessary for previous
                                                    % one.
                                                    %
                                                  change.add.to.year
                                                  cite.num.names.short
                                                    cite.num.names.old
                                                      <
                                                    { cite.num.names.old
                                                        'cite.num.names.short
                                                          :=
                                                    }
                                                    'skip$
                                                  if$
                                                }
                                              if$
                                            }
                                          if$
                                        }
                                      if$
                                    }
                                    {   %
                                        % Different 5th author: citing 5 authors is
                                        % sufficient for this comparison.
                                        %
                                      cite.num.names.short #5 <
                                        { #5 'cite.num.names.short := }
                                        'skip$
                                      if$
                                    }
                                  if$
                                }
                              if$
                            }
                          if$
                        }
                        {   %
                            % Different 4th author: citing 4 authors is
                            % sufficient for this comparison.
                            %
                          cite.num.names.short #4 <
                            { #4 'cite.num.names.short := }
                            'skip$
                          if$
                        }
                      if$
                    }
                  if$
                }
              if$
            }
            {   %
                % Different 3rd author: citing 3 authors is sufficient for this
                % comparison.
                %
              cite.num.names.short #3 <
                { #3 'cite.num.names.short := }
                'skip$
              if$
            }
          if$
        }
        {   %
            % Different 2nd author: citing 2 authors is sufficient for this
            % comparison.
            %
          cite.num.names.short #2 <
            { #2 'cite.num.names.short := }
            'skip$
          if$
        }
      if$
    }
    {   %
        % Different first author: no ambiguity, move to next entry.
        %
      skip$
    }
  if$
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

FUNCTION {definitive.cite.num.names.field}
{ 'field :=
  field num.names$  'numnames :=
    %
    % Format authors
    %
  format.6.authors
    %
    % Now compare authors with authors of previous entry.
    %
  cite.num.names.short   numnames.old    >
    {   %
        % The previous entry has less authors than already defined
        % necessary to be cited. No ambiguity is possible and we're ready.
        %
      skip$
    }
    {   %
        % Both previous and current entry have at least one author .
        %
      year.label   year.label.old  =
        {   %
            % Same year label: possibly ambiguous citation.
            %
            % First check: current and/or previous have 1 or
            % 2 authors.
            %
          numnames  #3  <
            numnames.old  #3  <
              or
               %
            { definitive.cite.num.names.1.or.2 }
            { definitive.cite.num.names.3.or.more }
          if$
        }
        {   %
            % Different year label: everything's fine,
            % move to next entry.
            %
          skip$
        }
      if$
    }
  if$
    %
    % If during the previous process the name maximum is exceeded
    % (which was not checked), correct this. NOTE: If the name
    % maximum is smaller than 6, this could lead to ambiguous
    % citations if, e.g., the year and the first 5 authors are
    % the same, but the 6th author is different.
    %
  cite.num.names.short   name.max   >
    { name.max  'cite.num.names.short  := }
    'skip$
  if$
    %
    % For a "full" cite, the number of names should always be at least
    % as large as for a "short" cite.
    %
  cite.num.names.full   cite.num.names.short   <
    { cite.num.names.short 'cite.num.names.full := }
    'skip$
  if$
    %
    % Update "old" variables for next entry.
    %
  update.cite.num.names
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

FUNCTION {definitive.cite.no.names}
{   %
    % The formatted field that acts as author is on top
    % of the stack.
      'aut1f :=
  ""  'aut2 :=
  ""  'aut3 :=
  ""  'aut4 :=
  ""  'aut5 :=
  ""  'aut6 :=
  #1  'numnames  :=
    %
  year.label   year.label.old  =
    {   %
        % Same year label: possibly ambiguous citation.
        %
      definitive.cite.num.names.1.or.2
    }
    {   %
        % Different year label: everything's fine,
        % move to next entry.
        %
      skip$
    }
  if$
    %
    % Update "old" variables for next entry.
    %
  update.cite.num.names
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

FUNCTION {definitive.cite.num.names}
{   %
    % Check whether author or editor or other field acts as author.
    % Number of names is only relevant with author or editor.
    %
  firstkey empty$ not
    { firstkey  sortify  remove.spaces  definitive.cite.no.names }
    { key empty$ not
        { key  sortify  remove.spaces  definitive.cite.no.names }
        {   %
            % No key or firstkey, so find out which field
            % to use as author.
            %
            % Check reference type:
            %   if result is 1 then possibly editor acts as author
            %                2 then editor does not act as author
            %                3 then key should have been used
            %                0 then unknown reference type
          ref.type  #2 =
            {   %
                % Format first author with and without initials
              author empty$
                { title.sort.label  definitive.cite.no.names }
                { author  definitive.cite.num.names.field }
              if$
            }
            {   %
                % Format first author with and without initials
              author empty$
                { editor empty$
                    { title.sort.label  definitive.cite.no.names }
                    { editor definitive.cite.num.names.field }
                  if$
                }
                { author definitive.cite.num.names.field }
              if$
            }
          if$
        }
      if$
    }
  if$
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

FUNCTION {make.tentative.year.sort.label}
{   %
    % Implicit or explicit ``no date'' is put at the front
    % (the year zero; years B.C. will imply complications)
    % because these are possibly old works.
    % ``In press'' is put at the end.
    %
  year empty$
    { "0000" 'year.label := }
    { year "\bibnodate" =
        year "n.d." =
        or
        { "0000" 'year.label := }
        { year "\BIP" =
            { "9999" 'year.label := }
            {   % It is not checked whether the year field
                % makes sense.
              year  sortify  remove.spaces  'year.label :=
            }
          if$
        }
      if$
    }
  if$
    %
    % Push year sort label on the stack
  year.label
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

FUNCTION {month.number.day}
{ month empty$
    { "" }
    { month sortify remove.spaces
        %
        % Add the day when available.
      day empty$
        'skip$
        { "/" *
          day  sortify  remove.spaces  *
        }
      if$
    }
  if$
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

FUNCTION {make.name.sort.label}
{   %
    % Author or editor-acting-as-author available.
    % => Make tentative "short cite with initials" author
    %    label (L1) of one of the forms
    %     "Last1  F1"
    %     "Last1  F1   Last2"
    %     "Last1  F1   zzzz"  ("zzzz" representing et al.)
    % => If more than 2 'authors': make label (L2) for 2nd-6th authors
    %    of one of the forms
    %     "Last2   Last3"
    %     "Last2   Last3   Last4"
    %     "Last2   Last3   Last4   Last5"
    %     "Last2   Last3   Last4   Last5   Last6"
    %     "Last2   Last3   Last4   Last5   Last6   zzzz"
    %
    % Then format year label (L3) of one of the forms:
    %     "0000"  (missing year or explicit 'no date')
    %     "9999"  ('in press')
    %     year    (otherwise; don't use originalyear here yet)
    %
    % From earlier sorting of titles, we have title number. Convert
    % to string, which gives title label (L4) .
    %
    % Then tentative sorting label (author.year.sort.label) is a
    % concatenation of
    %     L1
    %     "    "
    %     L3
    %     "    "
    %     L2
    %     "    "
    %     L4
    %
    % The name field is on top of the stack.
  'field :=
    %
    % numnames is the total number of names contained in field
  field num.names$ 'numnames :=
    %
    % Format first author
  field  #1  sort.name.format  format.name$
    %
    % Format the second author if there are two, or else "zzzz" = et al.
  numnames #1 =
    'skip$
    { numnames #2 =
        {   %
            % Two authors: format second author
          field  #2  "{ll{}}"  format.name$  's :=
          s "others" =
            { "   zzzz" * }    % Add "et al."-substitute
            { "   " * s * }    % Add second author
          if$
        }
        { "   zzzz" * } % 3 or more authors: add "et al."-substitute
      if$
    }
  if$
  "    "  *                          % Add spaces
  make.tentative.year.sort.label *   % Add year (L3).
  "    "  *                          % Add spaces
    %
    % Now build up L2 if applicable
  numnames #3 <
    'skip$
    {   %
        % Treat last author slightly differently
      numnames name.max >
        { name.max  'lastname  :=
          "   zzzz"                 % Push "et al."-substitute on stack
        }
        { numnames  'lastname  :=
          ""                        % Push empty string on stack
        }
      if$
        %
        % Names 2 to "last" - 1
      ""                            % Push empty string on stack
      #2 'nameptr :=
      { nameptr lastname < }
        {   % Add name no. nameptr
          field  nameptr  "{ll{}}"  format.name$ *
          "   " *
          nameptr #1 +  'nameptr :=
        }
      while$
        %
        % "Last" author
      field  lastname  "{ll{}}"  format.name$  's :=
      s "others" =
        { "zzzz" * }    % Add "et al."-substitute
        { s * }         % Add last author
      if$
        %
      swap$ *  % Add the previously formatted empty string or
               % "et al."-substitute if there are many authors.
      *        % Add L2 to the earlier labels.
    }
  if$
    %
  "    "  *                          % Add spaces
  title.number  conv.int.to.str  *   % Add sorted title number (L4).
  sortify                            % Clean up and convert to lowercase
  "    "  *                          % Add spaces
  month.number.day  *                % Add month and day when available
  'author.year.sort.label :=         % Assign result to sort label.
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

FUNCTION {make.field.year.sort.label}
{   %
    % 'field' acts as first author (L1), subsequent authors
    % are empty (L2).
    %
    % Then format year label (L3) of one of the forms:
    %     "0000"  (missing year or explicit 'no date')
    %     "9999"  ('in press')
    %     year    (otherwise; don't use originalyear here yet)
    %
    % From earlier sorting of titles, we have title number. Convert
    % to string, which gives title label (L4) .
    %
    % Then tentative sorting label (author.year.sort.label) is a
    % concatenation of
    %     L1
    %     "    "
    %     L3
    %     "    "
    %     L2
    %     "    "
    %     L4
    %
    % 'field' is on top of the stack. It is already supposed to be cleaned
    % (i.e., sortified and space-removed), so this is already L1.
  "    "  *                          % Add spaces to L1
  make.tentative.year.sort.label *   % Add year (L3).
  "    "  *                          % Add spaces
  "    "  *                          % L2 is empty, add spaces
  title.number  conv.int.to.str  *   % Add sorted title number (L4).
  sortify                            % Clean up and convert to lowercase
  "    "  *                          % Add spaces
  month.number.day  *                % Add month and day when available
  'author.year.sort.label :=         % Assign result to sort label.
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

FUNCTION {make.author.editor.sort.label}
{ author empty$
    { editor empty$
        {   %
            % Use what has previously been stored in title.sort.label
            % as author substitute .
          title.sort.label   make.field.year.sort.label
        }
        { editor make.name.sort.label }
      if$
    }
    { author make.name.sort.label }
  if$
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

FUNCTION {make.author.sort.label}
{ author empty$
    {   %
        % Use what has previously been stored in title.sort.label
        % as author substitute .
      title.sort.label   make.field.year.sort.label
    }
    { author make.name.sort.label }
  if$
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

FUNCTION {make.tentative.sort.label}
{   %
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    % General strategy:
    %
    % Ordinary situation: author or editor-acting-as-author
    % available.
    % => Make tentative "short cite with initials" author
    %    label (L1) of one of the forms
    %     "Last1  F1"
    %     "Last1  F1   Last2"
    %     "Last1  F1   zzzz"  ("zzzz" representing et al.)
    % => If more than 2 'authors': make label (L2) for 2nd-6th authors
    %    of one of the forms
    %     "Last2   Last3"
    %     "Last2   Last3   Last4"
    %     "Last2   Last3   Last4   Last5"
    %     "Last2   Last3   Last4   Last5   Last6"
    %     "Last2   Last3   Last4   Last5   Last6   zzzz"
    % When key is available (overrules author and editor fields):
    % => L1 = key, L2 = ""
    % No author, editor, and key: define title or substitute as key
    % and format as key.
    %
    % Then format year label (L3) of one of the forms:
    %     "0000"  (missing year or explicit 'no date')
    %     "9999"  ('in press')
    %     year    (otherwise; don't use originalyear here yet)
    %
    % From earlier sorting of titles, we have title number. Convert
    % to string, which gives title label (L4) .
    %
    % Then tentative sorting label (author.year.sort.label) is a
    % concatenation of
    %     L1
    %     "    "
    %     L3
    %     "    "
    %     L2
    %     "    "
    %     L4
    %
    % This can then be sorted, from which it can be derived
    % whether initials are necessary, how many names must
    % be used for short and full citations, and whether "a"'s and
    % "b"'s etc. are necessary behind the year labels.
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    %
    % key and firstkey overrule author information
    %
  firstkey empty$ not
    { key empty$ not
        {   %
            % Both key and firstkey available:
            % for sorting and checking initials, treat key as last
            % name and firstkey as initials.
            %
          key       sortify  remove.spaces
          "  " *
          firstkey  sortify  remove.spaces *
          make.field.year.sort.label
        }
        { firstkey  sortify  remove.spaces make.field.year.sort.label }
      if$
    }
    { key empty$ not
        { key   sortify  remove.spaces make.field.year.sort.label }
        {   %
            % No key or firstkey, so find out which field
            % to use as author.
            %
            % Check reference type:
            %   if result is 1 then possibly editor acts as author
            %                2 then editor does not act as author
            %                3 then key should have been used
            %                0 then unknown reference type
          ref.type
          duplicate$ #1 =
            { pop$
              make.author.editor.sort.label
            }
            { duplicate$ #2 =
                { pop$
                  make.author.sort.label
                }
                { #3 =
                    { "no key in " cite$ * warning$
                      make.author.editor.sort.label
                    }
                    { make.author.editor.sort.label }
                  if$
                }
              if$
            }
          if$
        }
      if$
    }
  if$
    %
  author.year.sort.label  'sort.key$ :=
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

FUNCTION {make.definitive.name.sort.label}
{   %
    % Author or editor-acting-as-author available.
    % => Make author-with-initials label (L1) of one of the forms
    %     "Last1  F1   Last2  F2   ...   LastN  FN"
    %     "Last1  F1   Last2  F2   ...   Last6  F6   zzzz"
    %     (where N <= 6 is the total number of authors, and
    %      "zzzz" represents et al. if there are more than 6 authors)
    % No author, editor, and key: define title or substitute as sort key.
    %
    % The name field is on top of the stack.
  'field :=
    %
    % numnames is the total number of names contained in field
  field num.names$ 'numnames :=
    %
    % If there are more than 6 authors, only 6 are mentioned.
  numnames  name.max  >
    { name.max  'format.num.names  := }
    { numnames  'format.num.names  := }
  if$
    % Initialize stack with empty string
  ""
    %
    % Cycle over authors.
  #1  'nameptr  :=
    { nameptr  format.num.names  < }
    { % Format author and add spaces
       field  nameptr  sort.name.format  format.name$  *
       "   " *
       nameptr #1 + 'nameptr :=
    }
  while$
    % Format last author that must be formatted
  field  nameptr  sort.name.format  format.name$  *
    % Add et al. if necessary
  nameptr numnames  <
    { "   zzzz" * }
    'skip$
  if$
  sortify                            % Clean up and change case
  "    "  *                          % Add spaces
  year.label *                       % Add year
  "    "  *                          % Add spaces
  title.number  conv.int.to.str  *   % Add sorted title number
  "    "  *                          % Add spaces
  month.number.day  *                % Add month and day when available
  'author.year.sort.label :=         % Assign result to sort label.
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

FUNCTION {make.definitive.field.year.sort.label}
{   %
    % 'field' acts as author (L1).
    %
    % Then format year label (L2) of one of the forms:
    %     "0000"  (missing year or explicit `no date')
    %     "9999"  (`in press')
    %     year    (otherwise; don't use originalyear here yet)
    %
    % From earlier sorting of titles, we have title number. Convert
    % to string, which gives title label (L3) .
    %
    % Then tentative sorting label (author.year.sort.label) is a
    % concatenation of
    %     L1
    %     "    "
    %     L2
    %     "    "
    %     L3
    %
    % 'field' is on top of the stack. It is already supposed to be cleaned
    % (i.e., sortified and space-removed), so this is already L1.
  "    "  *                          % Add spaces
  year.label *                       % Add year
  "    "  *                          % Add spaces
  title.number  conv.int.to.str  *   % Add sorted title number
  "    "  *                          % Add spaces
  month.number.day  *                % Add month and day when available
  'author.year.sort.label :=         % Assign result to sort label.
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

FUNCTION {make.definitive.author.editor.sort.label}
{ author empty$
    { editor empty$
        {   %
            % Use what has previously been stored in title.sort.label
            % as author substitute .
          title.sort.label   make.definitive.field.year.sort.label
        }
        { editor  make.definitive.name.sort.label }
      if$
    }
    { author  make.definitive.name.sort.label }
  if$
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

FUNCTION {make.definitive.author.sort.label}
{ author empty$
    {   %
        % Use what has previously been stored in title.sort.label
        % as author substitute .
      title.sort.label   make.definitive.field.year.sort.label
    }
    { author  make.definitive.name.sort.label }
  if$
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

FUNCTION {make.final.sort.key}
{   %
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    % General strategy:
    %
    % Ordinary situation: author or editor-acting-as-author
    % available.
    % => Make author-with-initials label (L1) of one of the forms
    %     "Last1  F1   Last2  F2   ...   LastN  FN"
    %     "Last1  F1   Last2  F2   ...   Last6  F6   zzzz"
    %     (where N <= 6 is the total number of authors, and
    %      "zzzz" represents et al. if there are more than 6 authors)
    % No author, editor, and key: define title or substitute as sort key.
    %
    % Then format year label (L2) of one of the forms:
    %     "0000"  (missing year or explicit `no date')
    %     "9999"  (`in press')
    %     year    (otherwise; don't use originalyear here yet)
    %       Add "/"month"/"day to the latter when available.
    %
    % From earlier sorting of titles, we have title number. Convert
    % to string, which gives title label (L3) .
    %
    % Then final sorting label (author.year.sort.label) is a
    % concatenation of
    %     L1
    %     "    "
    %     L2
    %     "    "
    %     L3
    %
    % This can then be sorted.
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    %
    %
    % Find out which field
    % to use as author.
    %
    % Check reference type:
    %   if result is 1 then possibly editor acts as author
    %                2 then editor does not act as author
    %                3 then key should have been used
    %                0 then unknown reference type
  ref.type  #2 =
    { make.definitive.author.sort.label }
    { make.definitive.author.editor.sort.label }
  if$
    %
  author.year.sort.label  'sort.key$ :=
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

FUNCTION {chop.word}
{ 's :=
  'len :=
  s #1 len substring$ =
    { s len #1 + global.max$ substring$ }
    { s }
  if$
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

FUNCTION {chop.articles}
{ 's :=
  "a " #2
    "an " #3
      "the " #4
        s
      chop.word
    chop.word
  chop.word
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

FUNCTION {format.sort.title}
{   %
    % Remove non-alphanumeric characters and change to lower case .
  sortify
    %
    % Remove "a ", "an ", and "the " from the front .
  chop.articles #1 entry.max$ substring$
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

FUNCTION {make.sort.title}
{ title empty$
    { text empty$
        { type empty$
            { howpublished empty$
                { note empty$
                    { url empty$
                        { " " }
                        { url  format.sort.title }
                      if$
                    }
                    { note  format.sort.title }
                  if$
                }
                { howpublished  format.sort.title }
              if$
            }
            { type  format.sort.title }
          if$
        }
        { text format.sort.title }
      if$
    }
    { title  format.sort.title }
  if$
  remove.spaces
  'title.sort.label :=
  title.sort.label 'sort.key$ :=
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

FUNCTION {make.title.number}
{ title.sort.label  old.label  =
    {   %
        % A tie: old and new label are the same .
      old.number  'title.number :=
    }
    {   %
        % The usual situation: titles are different.
      old.number  #1  +  'title.number :=
      title.number       'old.number   :=
      title.sort.label   'old.label    :=
    }
  if$
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


FUNCTION {last.part.name.format} { "{ll}" }

FUNCTION {initials.with.space.name.format} { "{f.}" }

FUNCTION {von.last.junior.name.format} { "{vv }{ll}{ jj}" }

FUNCTION {von.junior.name.format} { "{ vv}{, jj}" }

FUNCTION {one.complete.name.format} { "{vv }{ll}{, jj}{, ff}" }

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

FUNCTION {string.length}
{ #0 'pos :=
  % If the next character exists, i.e., is not empty,
  % add 1 to the string length.
  % We cannot use empty$ because " " empty$ is true.
  { duplicate$ pos #1 + #1 substring$ "" = not }
    { pos #1 + 'pos := }
  while$
  pop$ pos
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

FUNCTION {transform.spaces.and.hyphens}
{ 's :=                    % The original string
  s string.length 'len :=  % Its length (no. of characters)
  "" 't :=                 % Initialize the transformed string
  #1 'pos :=
  #0 'brace.level :=
    %
    % while (pos < len) do
    %
  { pos len < }
    { % First, check whether we are at brace level 0
      brace.level #0 =
        {
          % At least two characters left: check for ". ", ".~", and ".-".
          % If so, replace and shift two positions.
          s pos #2 substring$  ". " =
          s pos #2 substring$  ".~" = or
            { t "\BPBI " *  't :=
              pos #2 +  'pos :=
            }
            { s pos #2 substring$  ".-" =
                { t "\BHBI " *  't :=
                  pos #2 +  'pos :=
                }
                { % neither is true, copy one character and shift one position
                  t   s pos #1 substring$   *   't :=
                  % Check whether we need to increase brace level.
                  % Note that this is not sophisticated: it does not capture
                  % \{, \verb+}+, etc.
                  % Note also that unbalanced braces cause problems.
                  s pos #1 substring$ "{" =
                    { brace.level #1 + 'brace.level := }
                    'skip$
                  if$
                  pos #1 +  'pos :=
                }
              if$
            }
          if$
        }
        { % Not at brace level 0: copy result literally
          t   s pos #1 substring$   *   't :=
          % Check whether we need to increase or decrease brace level.
          % Note that this is not sophisticated: it does not capture
          % \{, \verb+}+, etc.
          s pos #1 substring$ "{" =
            { brace.level #1 + 'brace.level := }
            { s pos #1 substring$ "}" =
                { brace.level #1 - 'brace.level := }
                'skip$
              if$
            }
          if$
          pos #1 +  'pos :=
        }
      if$
    }
  while$
    %
  pos len =
    { % Last character, copy
      t   s pos #1 substring$   *   't :=
    }
    { % pos = len + 1, so s ends with ". " or ".-"
      % This should not have happened, but make the best out of it.
      % Push last two characters of s on the stack, i.e., ". " or ".-".
      s len #1 - #2 substring$
      % Remove "\BPBI " or "\BHBI " from t
      t text.length$ 'len :=   % Length of t (no. of characters)
      t #1 len #6 - substring$
      % Concatenate and assign to t
      swap$ * 't :=
    }
  if$
    %
    % Now push the result back on the stack
  t
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

FUNCTION {format.initials.with.hyphen}
{ % Format initials.
  % Call with
  %   field authornumber format.initials.with.hyphen
  % e.g.
  %   author #1 format.initials.with.hyphen
  % Instead of field, a string may also be used.
  %
  % First, format initials in the default way, retaining spaces
  % and hyphens.
  initials.with.space.name.format format.name$
  transform.spaces.and.hyphens
}

FUNCTION {format.last.part.name}
{ % Format a name with last.part.name.format,
  % as part of more complicated things.
  % Call with
  %   field authornumber format.last.part.name
  % e.g.
  %   author #1 format.last.part.name
  % Instead of field, a string may also be used.
  last.part.name.format  format.name$
}

FUNCTION {format.von.last.junior.name}
{ % Format a name with von.last.junior.name.format,
  % for citing or as part of more complicated things.
  % Call with
  %   field authornumber format.von.last.junior.name
  % e.g.
  %   author #1 format.von.last.junior.name
  % Instead of field, a string may also be used.
  von.last.junior.name.format  format.name$
}

FUNCTION {format.von.junior.name}
{ % Format a name with von.last.junior.name.format,
  % for citing or as part of more complicated things.
  % Call with
  %   field authornumber format.von.junior.name
  % e.g.
  %   author #1 format.von.junior.name
  % Instead of field, a string may also be used.
  von.junior.name.format  format.name$
}

FUNCTION {format.cite.initials.name}
{ % Format a name for citing with initials.
  % Call with
  %   field authornumber format.cite.initials.name
  % e.g.
  %   author #1 format.cite.initials.name
  % Instead of field, a string may also be used.
  %
  % First, extract the complete name, format it in the canonical form,
  % and push on the stack.
  one.complete.name.format format.name$
  %
  % Format the initials and push on the stack.
  duplicate$ #1 format.initials.with.hyphen
  %
  % Format the von-last-junior part and push on the stack.
  swap$ #1 format.von.last.junior.name
  %
  % Connect with "~" hyphen (if they're both non-empty).
  "~" connect.check
}

FUNCTION {format.author.name}
{ % Format an author name for the reference list.
  % Call with
  %   field authornumber format.author.name
  % e.g.
  %   author #1 format.author.name
  % Instead of field, a string may also be used.
  %
  % First, extract the complete name, format it in the canonical form,
  % and push on the stack.
  one.complete.name.format format.name$
  %
  % Make two copies of the name, format the last name and push on the stack.
  duplicate$ duplicate$ #1 format.last.part.name
  %
  % Format the initials and push on the stack.
  swap$ #1 format.initials.with.hyphen
  %
  % Connect with last name.
  connect.with.comma.check
  %
  % Format the von-junior part and connect with initials.
  swap$ #1 format.von.junior.name "" connect.check
}

FUNCTION {format.editor.name}
{ % Format a name for the reference list as an editor.
  % Call with
  %   field authornumber format.editor.name
  % e.g.
  %   author #1 format.editor.name
  % Instead of field, a string may also be used.
  %
  format.cite.initials.name
}

FUNCTION {format.index.name}
{ % Format an author name for the index.
  % Call with
  %   field authornumber format.index.name
  % e.g.
  %   author #1 format.index.name
  % Instead of field, a string may also be used.
  %
  format.author.name
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

FUNCTION {comma.between.two} { "\BCBT{}" }

FUNCTION {comma.between.names} { ", " }

FUNCTION {comma.before.last} { "\BCBL{}" }

FUNCTION {and.before.last} { "\ \BBA{} " }

FUNCTION {et.al.string.cite} { "\ \protect\BOthers{.}" }

FUNCTION {et.al.string} { "\ \BOthers{.}" }

FUNCTION {et.al.string.period} { "\ \BOthersPeriod{.}" }

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

FUNCTION {add.name.index}
{   %
    %
  make.index
    { "%" * write$ newline$
        % Check for corporate author
      field is.bibcorporate
        { "\corporateAX{" }
        { "\AX{" }
      if$
      write$
      field nameptr sort.name.format  format.name$  sortify  write$ newline$
      "@"  write$
      field nameptr format.index.name
      "}%"  *   write$ newline$
    }
    { "%" * write$ newline$ }
  if$
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

FUNCTION {make.name.cite.label}
{ 'field  :=
  'format.num.names  :=
    %
  field  num.names$  'numnames :=   % numnames is the total number of names
                                    %   contained in field
    %
    % It is implicit in the APA manual that if "et al." would refer
    % to exactly one author, then this author should be named
    % instead of "et al."
    %
  format.num.names  numnames  #1  -  =
    { numnames  'format.num.names  := }
    'skip$
  if$
    %
    % Format first author: with or without initials
    %
  #1 'nameptr :=
  cite.initials  #1  =
    { field  nameptr  format.cite.initials.name     }
    { field  nameptr  cite.name.format format.name$ }
  if$
  add.name.index  % Add index entry when desired.
    %
  numnames  #1  =
    'skip$
    { format.num.names  #1  =
        {   %
            % First author et al.
            %
          et.al.string.cite write$
        }
        { numnames  #2  =
            {   %
                % Given that  format.num.names > 1, it is 2.
                % Format second author.
                %
              #2  'nameptr :=
              field  nameptr  cite.name.format  format.name$  's :=
                %
                % Check if 2nd author is explicit "others".
                % If so, insert "et al." string.
                %
              s "others" =
                { et.al.string.cite write$ }  % First et al.
                {   %
                    % First \& Second
                    %
                  and.before.last write$
                  s
                  add.name.index  % Add index entry when desired.
                }
              if$
            }
            {   %
                % 3 or more names, 2 or more must be cited
                %
                % for nameptr := 2  to  format.num.names - 1  do
                %
              #2  'nameptr  :=
                { nameptr  format.num.names  < }
                {   %
                    % Put comma between consecutive authors
                    %
                  comma.between.names  write$
                    %
                    % Format and add next author
                    %
                  field  nameptr  cite.name.format  format.name$
                  add.name.index  % Add index entry when desired.
                    %
                    % Move to next author
                    %
                  nameptr  #1  +  'nameptr :=
                }
              while$
                %
                % nameptr  =  format.num.names
                % Format this author.
                %
              field  nameptr  cite.name.format  format.name$  's :=
                %
              format.num.names  numnames  =
                {   %
                    % This is also the last author. Add (optional) comma.
                    %
                  comma.before.last  write$
                    %
                    % Check if this author is explicit "others".
                    % If so, insert "et al." string.
                    %
                  s "others" =
                    { et.al.string.cite  write$ }
                    { and.before.last    write$
                      s
                      add.name.index  % Add index entry when desired.
                    }
                  if$
                }
                {   %
                    % This is not the last author.
                    % Add comma, author name, and "et al."
                    %
                  comma.between.names  write$
                  s
                  add.name.index  % Add index entry when desired.
                    %
                  comma.before.last  et.al.string.cite  *  write$
                }
              if$
            }
          if$
        }
      if$
    }
  if$
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

FUNCTION {make.title.cite.label}
{   %
    % Formatting: check if formatted as article title or
    % as book title, and insert this formatting.
    %
  is.atype
    { "\APACciteatitle{" }
    { "\APACcitebtitle{" }
  if$
    %
  title empty$
    { text empty$
        { type empty$
            { howpublished empty$
                { note empty$
                    { url empty$
                        { cite$ }
                        { url   }
                      if$
                    }
                    { note  }
                  if$
                }
                { howpublished }
              if$
            }
            { type }
          if$
        }
        { text }
      if$
    }
    { title }
  if$
    %
    % Connect with formatting.
    %
  * "}" *
    %
    % Write to output
    %
  write$
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

FUNCTION {make.author.editor.cite.label}
{ author empty$
    { editor empty$
        {   %
            % No author or editor:
            % Use title or other description as citation label.
            %
          make.title.cite.label
          "}{%"  write$ newline$
          make.title.cite.label
        }
        { cite.num.names.full   editor  make.name.cite.label
          "}{%"  write$ newline$
          cite.num.names.short  editor  make.name.cite.label
        }
      if$
    }
    { cite.num.names.full   author  make.name.cite.label
      "}{%"  write$ newline$
      cite.num.names.short  author  make.name.cite.label
    }
  if$
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

FUNCTION {make.author.cite.label}
{ author empty$
    {   %
        % No author:
        % Use title or other description as citation label.
        %
      make.title.cite.label
      "}{%"  write$ newline$
      make.title.cite.label
    }
    { cite.num.names.full   author  make.name.cite.label
      "}{%"  write$ newline$
      cite.num.names.short  author  make.name.cite.label
    }
  if$
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

FUNCTION {make.definitive.year.supplement}
{   %
    % Add "a", "b", etc. when necessary.
    %
  add.to.year  #0  =
    { "" }
    { "{\protect"
      year empty$
        { "\BCntND" * }
        { year "\bibnodate" =
            { "\BCntND" * }
            { year "\BIP" =
                { "\BCntIP" * }
                { "\BCnt" * }
              if$
            }
          if$
        }
      if$
      "{" * add.to.year int.to.str$ * "}}" *
    }
  if$
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

FUNCTION {protect.year}
{ year empty$
    { "{\protect\bibnodate{}}" }
    { year "\bibnodate" =
        { "{\protect\bibnodate{}}" }
        { year "\BIP" =
            { "{\protect\BIP{}}" }
            { year }
          if$
        }
      if$
    }
  if$
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

FUNCTION {make.definitive.year.label}
{ "{\protect\APACyear{"
  originalyear empty$
    { protect.year }
    { originalyear "\bibnodate" =    % date of original publication unknown
        { translator empty$
            { protect.year }
            { year empty$
                { "{\protect\BTRANSL{}~\protect\bibnodate{}}" }  % trans. n.d.
                { "{\protect\BTRANSL{}}~"   protect.year *    }  % trans. 1931
              if$
            }
          if$
        }
        { year empty$
            { originalyear "/{\protect\bibnodate{}}"   * }  % 1923/n.d.
            { originalyear year =
                { protect.year }
                { originalyear  "/"  *  protect.year * }    % 1923/1961
              if$
            }
          if$
        }
      if$
    }
  if$
  * "}}%" * write$ newline$
    %
    % Add "a", "b", etc. when necessary.
    %
  "{\protect\APACexlab{" "}}"
  make.definitive.year.supplement enclose.check
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

FUNCTION {make.cite.labels}
{ newline$
    %
    % Write a few lines for testing purposes.
    %
  test
    { "\bibitem[]{} \fullciteA{" cite$ * "}" *  write$ newline$
      "\bibitem[]{} \citeA{"     cite$ * "}" *  write$ newline$
    }
    'skip$
  if$
    %
  "\bibitem[\protect\citeauthoryear{%" write$ newline$
    %
    % When key or firstkey is available, this takes precedence.
    %
  firstkey  empty$  not
    {   %
        % Full cite: firstkey.
        %
      firstkey  write$
      "}{%"     write$ newline$
        %
        % Short cite: if key is not empty and cite.initials is 0,
        % then key, else firstkey.
        %
      cite.initials  #0  =
        key empty$ not
          and
        { key      }
        { firstkey }
      if$
      write$
    }
    { key empty$ not
        {   %
            % No firstkey, but key available:
            % Both full and short labels are key.
            %
          key    write$
          "}{%"  write$ newline$
          key    write$
        }
        {   % No key or firstkey, so find out which field
            % to use as author.
            %
            % Check reference type:
            %   if result is 1 then possibly editor acts as author
            %                2 then editor does not act as author
            %                3 then key should have been used
            %                0 then unknown reference type
          ref.type  #2  =
            { make.author.cite.label }
            { make.author.editor.cite.label }
          if$
        }
      if$
    }
  if$
  "}{%"  write$ newline$
    %
    % Make year label that's used for citations
    %
  make.definitive.year.label  write$
  "}]{%"                      write$ newline$
  cite$                       write$
  "}%"                        write$ newline$
  % author.year.sort.label      write$ newline$ % for testing purposes
  % year.label                  write$ newline$ % for testing purposes
    %
    % If the item is used in a meta-analysis, indicate this with
    % a star.
    %
  "\APACinsertmetastar{%"     write$ newline$
  cite$                       write$
  "}%"                        write$ newline$
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

FUNCTION {editor.postfix}
{ editor num.names$ #1 >
    { "(\BEDS)" }
    { "(\BED)"  }
  if$
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

FUNCTION {editor.trans.postfix}
{ editor num.names$ #1 >
    { "(\BEDS{} \BAnd{} \BTRANSS)" }
    { "(\BED{} \BAnd{} \BTRANS)"   }
  if$
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    %
    % "(Trans.)" postfix
    % translator must not be empty
    %
FUNCTION {trans.postfix}
{ translator num.names$ #1 >
    { "(\BTRANSS)" }
    { "(\BTRANS)" }
  if$
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

FUNCTION {format.author.names}
{ 'field  :=
  'dot    :=
    %
  field  num.names$  'numnames :=   % numnames is the total number of names
                                    %   contained in field
  numnames  'format.num.names  :=   % Format all authors
  format.num.names   name.max  >    % Unless this exceeds the maximum of 6.
    { dot
        { name.max             'format.num.names := } % Format 6 authors
        { cite.num.names.full  'format.num.names := } % Format 1 editor
      if$
    }
    'skip$
  if$
    %
    % It is kind of explicit in the APA manual that if "et al." would
    % refer to exactly one author (the 7th), then this author should
    % still be replaced by "et al.", unlike with citations.
    % So format.num.names is not adapted.
    %
    % Format first author
    %
  #1  'nameptr :=
  field  nameptr  format.author.name
    %
    % Add period if required and if this is the only author.
    %
  numnames  #1  =
    dot
    and
    { add.period$ }
    'skip$
  if$
  add.name.index  % Add index entry when desired.
    %
  numnames  #1  =
    'skip$
    { format.num.names  #1  =
        {   %
            % First author et al.
            %
          comma.between.two
            %
            % Add period if required.
            %
          dot
            { et.al.string.period * }
            { et.al.string * }
          if$
          write$
        }
        { numnames  #2  =
            {   %
                % Given that  format.num.names > 1, it is 2.
                %
              comma.between.two  write$
                %
                % Format second author.
                %
              #2  'nameptr :=
              field  nameptr  format.author.name  's :=
                %
                % Check if 2nd author is explicit "others".
                % If so, insert "et al." string.
                %
              s "others" =
                {   %
                    % First et al.
                    % Add period if required.
                    %
                  dot
                    { et.al.string.period }
                    { et.al.string }
                  if$
                  write$
                }
                {   %
                    % First \& Second
                    %
                  and.before.last write$
                    %
                    % Add period if required.
                    %
                  dot
                    { s add.period$ }
                    { s }
                  if$
                  add.name.index  % Add index entry when desired.
                }
              if$
            }
            {   %
                % 3 or more names, 2 or more must be cited
                %
                % for nameptr := 2  to  format.num.names - 1  do
                %
              #2  'nameptr  :=
                { nameptr  format.num.names  < }
                {   %
                    % Put comma between consecutive authors
                    %
                  comma.between.names  write$
                    %
                    % Format and add next author
                    %
                  field  nameptr  format.author.name
                  add.name.index  % Add index entry when desired.
                    %
                    % Move to next author
                    %
                  nameptr  #1  +  'nameptr :=
                }
              while$
                %
                % nameptr  =  format.num.names
                % Format this author.
                %
              field  nameptr  format.author.name  's :=
                %
              format.num.names  numnames  =
                {   %
                    % This is also the last author. Add (optional) comma.
                    %
                  comma.before.last  write$
                    %
                    % Check if this author is explicit "others".
                    % If so, insert "et al." string.
                    %
                  s "others" =
                    {   %
                        % Add period if required.
                        %
                      dot
                        { et.al.string.period }
                        { et.al.string }
                      if$
                      write$
                    }
                    { and.before.last  write$
                        %
                        % Add period if required.
                        %
                      dot
                        { s add.period$ }
                        { s }
                      if$
                      add.name.index  % Add index entry when desired.
                    }
                  if$
                }
                {   %
                    % This is not the last author.
                    % Add comma, author name, and "et al."
                    %
                  comma.between.names  write$
                  s
                  add.name.index  % Add index entry when desired.
                    %
                  comma.before.last
                    %
                    % Add period if required.
                    %
                  dot
                    { et.al.string.period * }
                    { et.al.string * }
                  if$
                  write$
                }
              if$
            }
          if$
        }
      if$
    }
  if$
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

FUNCTION {format.authors}
{ #1 author format.author.names
  "%" write$
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

FUNCTION {format.editors.as.authors}
{ #0  editor  format.author.names
  "\ " editor.postfix * add.period$ write$
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

FUNCTION {format.ed.trans.as.authors}
{ #0  editor  format.author.names
  "\ " editor.trans.postfix * add.period$ write$
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

FUNCTION {format.editor.names}
{ 'field  :=
    %
  field  num.names$  'numnames :=   % numnames is the total number of names
                                    %   contained in field
  numnames  'format.num.names  :=   % Format all authors
  format.num.names   name.max  >    % Unless this exceeds the maximum of 6.
    { #1 'format.num.names := }     % Then it becomes 1 (First et al.)
    'skip$
  if$
    %
    % Format first editor
    %
  field  #1  format.editor.name
    %
  numnames  #1  =
    'skip$
    { format.num.names  #1  =
        { et.al.string * } % First editor et al., no comma.
        { numnames  #2  =
            {   %
                % Given that  format.num.names > 1, it is 2.
                % No comma. Format second editor.
                %
              field  #2  format.editor.name  's :=
                %
                % Check if 2nd editor is explicit "others".
                % If so, insert "et al." string.
                %
              s "others" =
                { et.al.string  * }          % First et al.
                { and.before.last  *  s * }  % First \& Second
              if$
            }
            {   %
                % 3 or more names, 2 or more must be cited
                %
                % for nameptr := 2  to  format.num.names - 1  do
                %
              #2  'nameptr  :=
                { nameptr  format.num.names  < }
                {   %
                    % Put comma between consecutive editors
                    %
                  comma.between.names  *
                    %
                    % Format and add next editor
                    %
                  field  nameptr  format.editor.name  *
                    %
                    % Move to next editor
                    %
                  nameptr  #1  +  'nameptr :=
                }
              while$
                %
                % nameptr  =  format.num.names
                % Format this editor.
                %
              field  nameptr  format.editor.name  's :=
                %
              format.num.names  numnames  =
                {   %
                    % This is also the last editor. Add (optional) comma.
                    %
                  comma.before.last  *
                    %
                    % Check if this editor is explicit "others".
                    % If so, insert "et al." string.
                    %
                  s "others" =
                    { et.al.string     *     }
                    { and.before.last  * s * }
                  if$
                }
                {   %
                    % This is not the last editor.
                    % Add comma, editor name, and "et al."
                    %
                  comma.between.names  * s *
                  comma.before.last    * et.al.string  *
                }
              if$
            }
          if$
        }
      if$
    }
  if$
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    %
    % format editors in case editors do not act as authors
    % (such as reference to chapter in edited book)
    %
    % L. W. Poon (Ed.)                         (1 editor)
    %    or
    % A. S. Gurman \& D. P. Kniskern (Eds.)    (2 editors)
    %    or
    % L. Poon, A. Jones, \& D. P. Smith (Eds.) (>2 editors)
    %
    % editor must not be empty
    %
FUNCTION {format.editors.in.line}
{ editor           format.editor.names
  editor.postfix   connect.with.space.check
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    %
    % format editors in case editors are also translators
    % and do not act as authors
    % (such as reference to chapter in edited book
    %  of translated articles)
    %
    % L. W. Poon (Ed. and Trans.)                         (1 editor)
    %    or
    % A. S. Gurman \& D. P. Kniskern (Eds. and Trans.)    (2 editors)
    %    or
    % L. Poon, A. Jones, \& D. P. Smith (Eds. and Trans.) (>2 editors)
    %
    % editor must not be empty
    %
FUNCTION {format.editors.trans.in.line}
{ editor                 format.editor.names
  editor.trans.postfix   connect.with.space.check
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    %
    % format translators in case translators act as editors
    % (such as reference to chapter in translated book)
    %
    % L. W. Poon (Trans.)                         (1 translator)
    %    or
    % A. S. Gurman \& D. P. Kniskern (Trans.)    (2 translators)
    %    or
    % L. Poon, A. Jones, \& D. P. Smith (Trans.) (>2 translators)
    %
    % translator must not be empty
    %
FUNCTION {format.translators.in.line}
{ translator      format.editor.names
  trans.postfix   connect.with.space.check
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    %
    % format translators in case translator does not act as editor
    % (such as reference to translated book)
    %
    % L. Solotaroff, Trans.
    %
FUNCTION {format.translators.in.paren.check}
{ translator empty$
    { "" }
    { translator format.editor.names
      translator num.names$ #1 >
        { ", \BTRANSS{}" * }
        { ", \BTRANS{}" * }
      if$
    }
  if$
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    %
    % format editors and translators in case neither act as editor
    % (such as reference to edited or translated book with a
    % a single author)
    %
    % L. Solotaroff, Ed.
    % L. Solotaroff, Ed. \& Trans.
    % L. Solotaroff, Trans.
    % L. Solotaroff, Ed. \& S. Prokofieff, Trans.
    %
FUNCTION {format.editors.translators.in.paren.check}
{ editor empty$
    { translator empty$
        { "" }
        { translator format.editor.names
          translator num.names$ #1 >
            { ", \BTRANSS{}" * }
            { ", \BTRANS{}" * }
          if$
        }
      if$
    }
    { editor format.editor.names
      editor num.names$ #1 >
        { ", \BEDS{}" * }
        { ", \BED{}" * }
      if$
      translator empty$
        'skip$
        { editor translator =
            { editor num.names$ #1 >
                { " \BAnd{} \BTRANSS" * }
                { " \BAnd{} \BTRANS" * }
              if$
            }
            { " \BAnd{} " *
              translator format.editor.names *
              translator num.names$ #1 >
                { ", \BTRANSS{}" * }
                { ", \BTRANS{}" * }
              if$
            }
          if$
        }
      if$
    }
  if$
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    %
    % translator of article
    %
FUNCTION {format.atrans.check}
{ format.translators.in.paren.check   parenthesize.check }

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    %
    % format "In editor (Ed.), "
    %
FUNCTION {format.in.editors}
{ "\BIn{} "
  editor empty$
    'skip$
    { format.editors.in.line * ", " * }
  if$
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    %
    % format "In translator (Trans.),"
    %
FUNCTION {format.in.trans}
{ "\BIn{} "
  translator empty$
    'skip$
    { format.translators.in.line * ", " * }
  if$
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    %
    % format "In editor (Ed. and Trans.)"
    %  or "In editor (Ed.)" if editor not equal to translator
    %
FUNCTION {format.in.editors.trans}
{ "\BIn{} "
  editor empty$
    { translator empty$
        'skip$
        { format.translators.in.line * ", " * }
      if$
    }
    { translator empty$
        { format.editors.in.line * }
        { editor translator =
            { format.editors.trans.in.line * }
            { format.editors.in.line * }
          if$
        }
      if$
      ", " *
    }
  if$
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

FUNCTION {format.year.check}
{ "\APACrefYear{"
  year empty$
    { "\bibnodate{}" * }
    { year * }
  if$
    %
    % Add "a", "b", etc. when necessary.
    %
  make.definitive.year.supplement *
  "}" *
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

FUNCTION {format.year.month.day.check}
{ "\APACrefYearMonthDay{"
  year empty$
    { "\bibnodate{}" * }
    { year * }
  if$
    %
    % Add "a", "b", etc. when necessary.
    %
  make.definitive.year.supplement *
  "}{" *
    %
    % Add month and day when present.
    %
  month empty$
    'skip$
    { month * }
  if$
  "}{" *
  day empty$
    'skip$
    { day * }
  if$
  "}" *
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    %
    % title of article in journal or book
    % no finishing period
    % field must be on top of stack
    %  (so englishtitle can be handled also)
    %
FUNCTION {format.atitle.no.dot}
{ "\BBOQ{}" swap$
  "\BBCQ{}" swap$
  duplicate$ empty$
    'skip$
    { duplicate$
      % Two arguments: Title twice: (1) don't change case; (2) change case
      "\APACrefatitle{" swap$ * "}{" * swap$
      "t" change.case$
      * "}" *
    }
  if$
  enclose.check
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    %
    % title of article in journal or book
    % with finishing period
    % field must be on top of stack
    %  (so englishtitle can be handled also)
    %
FUNCTION {format.atitle.dot}
{ "\BBOQ{}" swap$
  "\BBCQ{}" swap$
  duplicate$ empty$
    'skip$
    { duplicate$
      % Two arguments: Title twice: (1) don't change case; (2) change case
      "\APACrefatitle{" swap$ * "}{" * swap$
      "t" change.case$
      * "}" * add.period$
    }
  if$
  enclose.check
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    %
    % title of article in journal or book
    % field must be on top of stack
    % second element on stack must be connected:
    %   if that is empty, then atitle.dot
    %   else atitle.no.dot, connect, and add period
    %
FUNCTION {format.atitle.connect}
{ swap$
  duplicate$ empty$
    { pop$
      format.atitle.dot
    }
    { swap$
      format.atitle.no.dot
      swap$ connect.with.space.check
      add.period$
    }
  if$
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    %
    % title of book or so, without period
    % call with
    %     field format.btitle.no.dot
    %
FUNCTION {format.btitle.no.dot}
{ duplicate$ empty$
    'skip$
    { duplicate$
      % Two arguments: Title twice: (1) don't change case; (2) change case
      "\APACrefbtitle{" swap$ * "}{" * swap$
      "t" change.case$
      * "}" *
    }
  if$
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    %
    % title of book or so, with period
    % call with
    %     field format.btitle.dot
    %
FUNCTION {format.btitle.dot}
{ duplicate$ empty$
    'skip$
    { add.period$ format.btitle.no.dot }
  if$
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    %
    % title of book and similar
    % field must be on top of stack
    % second element on stack must be connected:
    %   if that is empty, then btitle.dot
    %   else btitle.no.dot, connect, and add period
    %
FUNCTION {format.btitle.connect}
{ swap$
  duplicate$ empty$
    { pop$
      format.btitle.dot
    }
    { swap$
      format.btitle.no.dot
      swap$   connect.with.space.check
      add.period$
    }
  if$
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    %
    % title of book and similar
    % field must be on top of stack
    % second element on stack must be connected
    %
FUNCTION {format.btitle.connect.no.dot}
{ swap$
  duplicate$ empty$
    { pop$
      format.btitle.no.dot
    }
    { swap$
      format.btitle.no.dot
      swap$   connect.with.space.check
    }
  if$
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    %
    % format englishtitle (of nonenglish article, etc.)
    %
FUNCTION {format.aetitle.check}
{ englishtitle empty$
    { "" }
    { % Two arguments: Title twice: (1) don't change case; (2) change case
      "\APACrefaetitle{" englishtitle * "}{" *
                         englishtitle "t" change.case$ * "}" *
    }
  if$
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    %
    % format englishtitle (of nonenglish book, etc.)
    %
FUNCTION {format.betitle.check}
{ englishtitle empty$
    { "" }
    { % Two arguments: Title twice: (1) don't change case; (2) change case
      "\APACrefbetitle{" englishtitle * "}{" *
                         englishtitle "t" change.case$ * "}" *
    }
  if$
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    %
    % format type (of article, etc.)
    %
FUNCTION {format.atype.check}
{ type bracket.check }

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    %
    % format title and englishtitle (of article, etc.)
    %
FUNCTION {format.atitle.check}
{ format.aetitle.check
  title format.atitle.connect
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    %
    % format title, englishtitle, and type
    % (of article, etc.)
    %
FUNCTION {format.atitle.type.check}
{ format.aetitle.check
  format.atype.check   connect.with.space.check
  title format.atitle.connect
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    %
    % format title, englishtitle,
    % and translator (of article, etc.)
    %
FUNCTION {format.atitle.trans.check}
{ format.aetitle.check
  format.atrans.check  connect.with.space.check
  title format.atitle.connect
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    %
    % format title, englishtitle, type,
    % and translator (of article, etc.)
    %
FUNCTION {format.atitle.type.trans.check}
{ format.aetitle.check
  format.atype.check   connect.with.space.check
  format.atrans.check  connect.with.space.check
  title format.atitle.connect
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    %
    % format journal, volume, number and pages
    % call with
    %   formatted.pages format.journal.vol.num.pages.check
    %
FUNCTION { format.journal.vol.num.pages.check }
{ "journal" journal warning.if.empty
  duplicate$ empty$
  journal    empty$ and
  volume     empty$ and
  number     empty$ and
    { pop$ "" }
    { "\APACjournalVolNumPages{" journal "" connect.check
      "}{" *                     volume  "" connect.check
      "}{" *                     number  "" connect.check
      "}{" *                     swap$   "" connect.check
      "}"  *
    }
  if$
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    %
    % volume of book, checks whether
    % "Volume" or "Volumes"
    %
    % call with
    %   field format.bvolume.check
    %
FUNCTION {format.bvolume.check}
{ duplicate$ empty$
    'skip$
    { duplicate$ multi.result.check
        { "\BVOLS" swap$ tie.or.space.connect }
        { "\BVOL"  swap$ tie.or.space.connect }
      if$
    }
  if$
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    %
    % edition of book, must not be empty
    % call with
    %   field format.edition.check
    %
FUNCTION {format.edition.check}
{ duplicate$ empty$
    'skip$
    { "\PrintOrdinal{" swap$ * "}" *
      "\BEd" connect.with.space.check
    }
  if$
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    %
    % volume and edition of book
    %
FUNCTION {format.bvol.edition.check}
{ edition format.edition.check
  volume  format.bvolume.check
  connect.with.comma.check
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    %
    % volume and edition of book
    %
FUNCTION {format.bvol.edition}
{ format.bvol.edition.check
  parenthesize.check
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    %
    % volume and edition and translator of translated book
    %
FUNCTION {format.bvol.edition.trans}
{ format.bvol.edition.check
  format.translators.in.paren.check connect.with.semicolon.check
  parenthesize.check
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    %
    % volume, edition, editor, and translator of (translated) book
    %
FUNCTION {format.bvol.edition.editor.trans}
{ format.bvol.edition.check
  format.editors.translators.in.paren.check connect.with.semicolon.check
  parenthesize.check
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    %
    % formats pages by first checking if 1 or more pages
    % and prefixing pages with "p." or "pp." (these strings
    % are given in the commands \BPG and \BPGS, respectively),
    % whichever is applicable, and do a tie or space connect
    %
    % call with
    %   field format.bpages.check
    %
FUNCTION {format.bpages.check}
{ duplicate$ empty$
    'skip$
    { duplicate$ multi.result.check
        { "\BPGS" swap$ tie.or.space.connect }
        { "\BPG~" swap$ * }
      if$
    }
  if$
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    %
    % formats chapters by first checking if 1 or more chapters
    % and prefixing pages with "chap." (this string
    % is given in the commands \BCHAP and \BCHAPS, respectively),
    % whichever is applicable, and do a tie or space connect
    %
    % call with
    %   field format.bchapter.check
    %
FUNCTION {format.bchapter.check}
{ duplicate$ empty$
    'skip$
    { duplicate$ multi.result.check
        { "\BCHAPS" swap$ tie.or.space.connect }
        { "\BCHAP"  swap$ tie.or.space.connect }
      if$
    }
  if$
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    %
    % volume, edition, and pages or chapter of article in book etc.
    %
FUNCTION {format.bvol.edition.pages}
{ format.bvol.edition.check
  pages empty$
    { chapter format.bchapter.check  connect.with.comma.check }
    { pages   format.bpages.check    connect.with.comma.check }
  if$
  parenthesize.check
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    %
    % title, volume, edition of book
    %
FUNCTION {format.btitle.vol.edition}
{ format.betitle.check
  format.bvol.edition  connect.with.space.check
  title  format.btitle.connect.no.dot
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    %
    % title, volume, edition, and translator of book
    %
FUNCTION {format.btitle.vol.edition.trans}
{ format.betitle.check
  format.bvol.edition.trans  connect.with.space.check
  title  format.btitle.connect.no.dot
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    %
    % title, volume, edition, editor, and translator of book
    %
FUNCTION {format.btitle.vol.edition.editor.trans}
{ format.betitle.check
  format.bvol.edition.editor.trans  connect.with.space.check
  title  format.btitle.connect.no.dot
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    %
    % format address and publisher of book etc.
    %
    % New York: Wiley
    %      or
    % Wiley      (if address empty)
    %      or
    % New York   (if publisher empty)
    %
FUNCTION {format.address.publisher}
{   %
    % If publisher = author or publisher = "author" or publisher = "Author"
    % then hand over the final choice how to format this to \LaTeX.
    % (I could imagine similar code for editors, but the APA manual does
    % not mention it and then we'd have to check whether the editor is in
    % the author position, so let's keep it simple until someone complains.)
    %
  author empty$
  publisher empty$ or
    { publisher "\APACaddressPublisher{" }
    { author   publisher =
      "author" publisher =  or
      "Author" publisher =  or
        { author    "\APACaddressPublisherEqAuth{" }
        { publisher "\APACaddressPublisher{"       }
      if$
    }
  if$
  address "" connect.check  "}{" *
    % Recover publisher that was pushed onto the stack previously.
  swap$   "" connect.check  "}"  *
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    %
    % format address and publisher of book etc.
    %
    % New York: Wiley
    %      or
    % Wiley      (if address empty)
    %      or
    % New York   (if publisher empty)
    %
    % warning if no publisher or no address
    %
FUNCTION {format.address.publisher.check}
{ "publisher" publisher warning.if.empty
  "address"   address   warning.if.empty
  publisher empty$
  address   empty$
  and
    'skip$
    { % Clear the stack
      duplicate$ empty$
        'skip$
        { output.new.block }
      if$
      format.address.publisher
    }
  if$
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    %
    % format number as in reports: No. 2017
    % call with
    %   field format.rnumber.check
    %
FUNCTION {format.rnumber.check}
{ duplicate$ empty$
    'skip$
    { duplicate$ multi.result.check
        { "\BNUMS" swap$ tie.or.space.connect }
        { "\BNUM"  swap$ tie.or.space.connect }
      if$
    }
  if$
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    %
    % format type and number of a standalone item
    % call with
    %   format.type.number
    %
FUNCTION { format.type.number }
{ type empty$
    { type.2 }
    { type   }
  if$
  number empty$
    { bracket.check }
    { number format.rnumber.check connect.with.space.check
      parenthesize.check
    }
  if$
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    %
    % format howpublished if not empty,
    % for various entry types
    % call with
    %   format.howpublished
    %
FUNCTION {format.howpublished}
{ howpublished empty$
    'skip$
    { % clear the stack
      duplicate$ empty$
        'pop$
        { output.dot.new.block }
      if$
      "\APAChowpublished{" howpublished * "}" *
    }
  if$
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    %
    % format howpublished if not empty,
    % for misc
    % call with
    %   output.howpublished
    %
FUNCTION {output.howpublished}
{ howpublished empty$
    'skip$
    { "\APAChowpublished{" howpublished * "}" *
      output.dot.new.block
    }
  if$
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    %
    % begin and end of url environment
    %
FUNCTION {begin.end.url.env}
{ " \begin{APACrefURL} "
    % For "Retrieved <date>, from"
  lastchecked empty$
    'skip$
    { "[{" * lastchecked * "}]" * }
  if$
  " \end{APACrefURL} "
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    %
    % begin and end of message environment
    %
FUNCTION {begin.end.msg.env}
{ " \begin{APACrefURLmsg} "
  " \end{APACrefURLmsg} "
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    %
    % format url given that it is not empty,
    % for various entry types
    % call with
    %   format.url
    %
FUNCTION {format.url}
{ % First format begin and end of the enclosing environment.
  % With posted messages, a different environment is used.
  type.2 empty$
    { begin.end.url.env }
    { type.2 "\bibmessage" =
        { begin.end.msg.env }
        { begin.end.url.env }
      if$
    }
  if$
    % The url string.
  "\url{" url * "}" *
    % Enclose in begin and end environment
  enclose.check
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    %
    % format optional note
    %
FUNCTION {format.note}
{ "\APACrefnote{"  "}"  note  enclose.check }

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    %
    % format original year of publication and note
    % (reprint or translation)
    %
FUNCTION {format.orig.year.note}
{ originalyear empty$
    { format.note }
    { "\APACorigyearnote{"
      originalyear    "" connect.check "}{" *
      note            "" connect.check "}"  *
    }
  if$
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    %
    % format original journal of publication and note
    % (reprint or translation)
    %
FUNCTION {format.orig.journal.note}
{ "\APACorigjournalnote{"
  originalyear    "" connect.check "}{" *
  originaljournal "" connect.check "}{" *
  originalvolume  "" connect.check "}{" *
  originalnumber  "" connect.check "}{" *
  originalpages   "" connect.check "}{" *
  note            "" connect.check "}"  *
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    %
    % format original book of publication and note
    % (reprint or translation)
    %
FUNCTION {format.orig.book.note}
{ "\APACorigbooknote{" originalyear  ""  connect.check "}{" *
    %
  originaleditor empty$
    'skip$
    { originaleditor num.names$ #1 >
        { "\APACorigEDS{" * originaleditor format.editor.names * "}" * }
        { "\APACorigED{"  * originaleditor format.editor.names * "}" * }
      if$
    }
  if$
    %
  "}{" *
  originalbooktitle format.btitle.no.dot "" connect.check "}{" *
  originaledition   format.edition.check "" connect.check "}{" *
  originalvolume    format.bvolume.check "" connect.check "}{" *
  originalpages     format.bpages.check  "" connect.check "}{" *
  originaladdress   "" connect.check "}{" *
  originalpublisher "" connect.check "}{" *
  note              "" connect.check "}"  *
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    %
    % format information about original publication of reprint
    % and format optional note
    %
FUNCTION {format.orig.note}
{ originaljournal empty$
    { originalbooktitle empty$
        { note empty$
            { originalyear empty$
                'skip$
                { originalyear "\bibnodate" =
                    'skip$
                    { output.new.block
                      format.orig.year.note
                    }
                  if$
                }
              if$
            }
            { output.new.block
              format.orig.year.note
            }
          if$
        }
        { output.new.block
          format.orig.book.note
        }
      if$
    }
    { output.new.block
      format.orig.journal.note
    }
  if$
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    %
    % article in periodical: journal, magazine, newspaper, ...
    %
    % call with
    %   formatted.pages  formatted.date   periodical
    %
FUNCTION {periodical}
{   %
    % author or editor, year, title, englishtitle, type
    %
  author empty$
        %
        % no author: possibly special issue with editors as authors
        % (APA manual, ex. 11, p. 121)
        %
    { editor empty$
            %
            % no author or editor: title serves as author.
            % title formatted as article title (APA manual not consistent in this,
            % compare statement on p. 119: ``treat as book title'' and
            % example 8, p. 121: no underlining => article title)
            %
        { format.atitle.type.trans.check output.new.block
            %
            % now formatted date on top of stack
            %
          output.dot.new.block
        }
            %
            % format editor and year, and check if year is present
            % format article title and check if title or type present
            %
        { format.editors.as.authors   start.new.block
            %
            % now formatted date on top of stack
            %
          output.dot.new.block
          format.atitle.type.trans.check output.new.block
        }
      if$
    }
        %
        % format author and year, and check if year is present
        % format article title and check if title or type present
        %
    { format.authors   start.new.block
            %
            % now formatted date on top of stack
            %
      output.dot.new.block
      format.atitle.type.trans.check output.new.block
    }
  if$
    %
    % format journal name, volume and issue number, and pages
    %   and check if journal not empty
    %
  format.journal.vol.num.pages.check
    %
    % if not empty, insert howpublished.
    % (used if article is retrieved from the internet)
    %
  format.howpublished  add.period$
      %
      % format url
      %
  url empty$
    'skip$
    { % Clear the stack
      duplicate$ empty$
        'skip$
        { output.new.block }
      if$
      format.url
    }
  if$
    %
    % possible reprint and optional note
    %
  format.orig.note
  fin.entry
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    %
    % journal article
    %
FUNCTION {article}
{ pages  format.year.month.day.check  periodical }

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    %
    % magazine article
    %
FUNCTION {magazine}
{ pages  format.year.month.day.check  periodical }

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    %
    % newspaper article
    %
FUNCTION {newspaper}
{ pages  format.bpages.check  format.year.month.day.check  periodical }

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    %
    % (translation of) entire book
    %
FUNCTION {book}
{     %
      % author or editor,
      % year, title, englishtitle, translator
      %
  author empty$
        %
        % no author: possibly edited book with editors as authors
        %
    { editor empty$
            %
            % no author or editor: title serves as author.
            % title formatted as book title
            %
        { format.btitle.vol.edition.trans
          format.type.number               connect.with.space.check
          output.dot.new.block
          format.year.check                add.period$
        }
            %
            % format editor and year, and check if year is present
            % format booktitle, volume, and edition and check if title present
            %
        { translator empty$
            { format.editors.as.authors  start.new.block
              format.year.check          output.dot.new.block
              format.btitle.vol.edition
            }
                %
                % format translator correctly
                %
            { translator editor =
              not
                { format.editors.as.authors        start.new.block
                  format.year.check                output.dot.new.block
                  format.btitle.vol.edition.trans
                }
                { format.ed.trans.as.authors  start.new.block
                  format.year.check           output.dot.new.block
                  format.btitle.vol.edition
                }
              if$
            }
          if$
          format.type.number     connect.with.space.check
          add.period$
        }
      if$
    }
        %
        % format author and year, and check if year is present
        % format booktitle, volume, and edition and check if title present
        %
    { format.authors                          start.new.block
      format.year.check                       output.dot.new.block
      format.btitle.vol.edition.editor.trans
      format.type.number                      connect.with.space.check
      add.period$
    }
  if$
      %
      % format address and publisher, check if address and publisher present
      %
  format.address.publisher.check
      %
      % if not empty, insert howpublished.
      % (used if book is retrieved from the internet)
      %
  format.howpublished  add.period$
      %
      % format url
      %
  url empty$
    'skip$
    { % Clear the stack
      duplicate$ empty$
        'skip$
        { output.new.block }
      if$
      format.url
    }
  if$
      %
      % format original publication (of reprint/translation)
      % and optional note
      %
  format.orig.note
  fin.entry
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    %
    % (translated) article or chapter in edited book
    %
FUNCTION {incollection}
{ author empty$
        %
        % no author: title serves as author.
        % title formatted as article title (APA manual not consistent in this,
        % compare statement on p. 119: ``treat as book title'' and
        % example 8, p. 121: no underlining => article title)
        %
    { editor.ne.trans
        { format.atitle.type.trans.check }
        { format.atitle.type.check }
      if$
      output.new.block
        %
        % format month and day as well when available
        % esp. for ``collections'' that are not books,
        % such as parts of internet documents
        %
      format.year.month.day.check   add.period$
    }
        %
        % format author and year, and check if year is present
        % format article title and check if title or type present
        %
    { format.authors                start.new.block
      format.year.month.day.check   output.dot.new.block
      editor.ne.trans
        { format.atitle.type.trans.check }
        { format.atitle.type.check }
      if$
    }
  if$
      %
      % format "In " editor " (Ed. \& Trans.), "
      % booktitle, volume, edition, pages
      %
  output.new.block
  format.in.editors.trans
  format.bvol.edition.pages
  booktitle  format.btitle.connect * add.period$
      %
      % format address and publisher, check if publisher present
      %
  format.address.publisher.check
      %
      % if not empty, insert howpublished.
      % (used if article is retrieved from the internet)
      %
  format.howpublished  add.period$
      %
      % format url
      %
  url empty$
    'skip$
    { % Clear the stack
      duplicate$ empty$
        'skip$
        { output.new.block }
      if$
      format.url
    }
  if$
      %
      % format original publication (of reprint/translation)
      % and optional note
      %
  format.orig.note
  fin.entry
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    %
    % technical report number
    %
FUNCTION {format.tr.number}
{ type empty$
    { "\BTR{}" }
    { type "\bibnotype" =
        { ""   }
        { type }
      if$
    }
  if$
  number format.rnumber.check   connect.with.space.check
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    %
    % title, volume, edition, report number
    %
FUNCTION {format.tr.title.number}
{ format.betitle.check
    % Single out the situation in which there is no number
    % and type = {\bibnotype}, i.e., no type as well.
    % (Why not use book then?)
  type empty$
    { % Now, we're in the regular situation with at least a
      % number, a type, a volume, or an edition.
      "\APACbVolEdTR{" format.bvol.edition.check * "}{" *
      format.tr.number *  "}" *
    }
    { type "\bibnotype" =
        number empty$
          volume empty$
            edition empty$
            and
          and
        and
        { "" }
        { % Now, we're in the regular situation with at least a
          % number, a type, a volume, or an edition.
          "\APACbVolEdTR{" format.bvol.edition.check * "}{" *
          format.tr.number *  "}" *
        }
      if$
    }
  if$
  connect.with.space.check
  title  format.btitle.connect
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    %
    % format address and institution of reports etc.
    %
    % Washington, DC: National Institute of Education
    %      or
    % National Institute of Education (if address empty)
    %
    % warning if no institution
    %
FUNCTION {format.address.institution.check}
{ "institution" institution warning.if.empty
  "address"     address     warning.if.empty
  institution empty$
  address     empty$
  and
    'skip$
    { % Clear the stack
      duplicate$ empty$
        'skip$
        { output.new.block }
      if$
        %
        % If institution = author or institution = "author"
        % or institution = "Author" then hand over the final choice how to
        % format this to \LaTeX. See also format.address.publisher
        %
      author empty$
      institution empty$ or
        { institution "\APACaddressInstitution{" }
        { author   institution =
          "author" institution =  or
          "Author" institution =  or
            { author      "\APACaddressInstitutionEqAuth{" }
            { institution "\APACaddressInstitution{"       }
          if$
        }
      if$
      address "" connect.check  "}{" *
        % Recover institution that was pushed onto the stack previously.
      swap$   "" connect.check  "}"  *
    }
  if$
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    %
    % reports
    %
FUNCTION {techreport}
{ author empty$
        %
        % no author: possibly edited report with editors as authors
        %
    { editor empty$
            %
            % no author or editor: title serves as author.
            % title formatted as book title
            %
        { format.tr.title.number      output.dot.new.block
          format.year.month.day.check add.period$
        }
            %
            % format editor and year, and check if year is present
            % format report title and check if title present
            % format volume, edition, type, and number
            %
        { format.editors.as.authors   start.new.block
          format.year.month.day.check output.dot.new.block
          format.tr.title.number      add.period$
        }
      if$
    }
        %
        % format author and year, and check if year is present
        % format report title and check if title present
        % format volume, edition, type, and number
        %
    { format.authors              start.new.block
      format.year.month.day.check output.dot.new.block
      format.tr.title.number      add.period$
    }
  if$
    %
    % format address and institution, check if institution present
    %
  format.address.institution.check
    %
    % if not empty, insert howpublished.
    % (used if report is retrieved from the internet)
    %
  format.howpublished add.period$
      %
      % format url
      %
  url empty$
    'skip$
    { % Clear the stack
      duplicate$ empty$
        'skip$
        { output.new.block }
      if$
      format.url
    }
  if$
    %
    % format optional note
    %
  note empty$
    'skip$
    { % Clear the stack
      duplicate$ empty$
        'skip$
        { output.new.block }
      if$
      format.note
    }
  if$
  fin.entry
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    %
    % (translated) article or chapter in report
    %
FUNCTION {intechreport}
{ author empty$
        %
        % no author: title serves as author.
        % title formatted as article title (APA manual not consistent in this,
        % compare statement on p. 119: ``treat as book title'' and
        % example 8, p. 121: no underlining => article title)
        %
    { editor.ne.trans
        { format.atitle.trans.check }
        { format.atitle.check }
      if$
      output.new.block
      format.year.month.day.check output.dot.new.block
    }
        %
        % format author and year, and check if year is present
        % format article title and check if title or type present
        %
    { format.authors                start.new.block
      format.year.month.day.check   output.dot.new.block
      editor.ne.trans
        { format.atitle.trans.check }
        { format.atitle.check }
      if$
      output.new.block
    }
  if$
      %
      % format "In " editor " (Ed. \& Trans.), "
      % booktitle, volume, edition, pages
      %
  format.in.editors.trans
      %
      % volume, edition, report type and number, pages
      %
  "\APACbVolEdTRpgs{" format.bvol.edition.check * "}{" *
  format.tr.number *
  "}{" * pages format.bpages.check *
  "}" *
      %
  booktitle format.btitle.connect *
  add.period$
      %
      % format address and publisher, check if publisher present
      %
  format.address.institution.check
    %
    % if not empty, insert howpublished.
    % (used if report is retrieved from the internet)
    %
  format.howpublished add.period$
      %
      % format url
      %
  url empty$
    'skip$
    { % Clear the stack
      duplicate$ empty$
        'skip$
        { output.new.block }
      if$
      format.url
    }
  if$
      %
      % format original publication (of reprint/translation)
      % and optional note
      %
  format.orig.note
  fin.entry
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    %
    % papers presented at conferences etc.
    %
FUNCTION {lecture}
{ author empty$
    { "author" author warning.if.empty }
    { format.authors  start.new.block  }
  if$
      %
      % format year, month, and day, and check if year present
      % format title and check if title present
      % format howpublished and check if howpublished present
      %
  format.year.month.day.check output.dot.new.block
  symposium empty$
    { format.betitle.check
      title  format.btitle.connect  output.new.block
      howpublished empty$
        { "symposium and howpublished missing in " cite$ * warning$
          ""
        }
        { "\APAChowpublished{" howpublished * "}" * }
      if$
      address connect.with.comma.check
    }
    { format.atitle.type.check output.new.block
      "\BIn{} "
      chair empty$
        'skip$
        { chair  format.editor.names
          chair num.names$ #1 >
            { "(\BCHAIRS)" }
            { "(\BCHAIR)" }
          if$
          connect.with.space.check * ", " *
        }
      if$
      symposium format.btitle.no.dot *
      format.howpublished
      address connect.with.comma.check
    }
  if$
  add.period$
      %
      % format url
      %
  url empty$
    'skip$
    { % Clear the stack
      duplicate$ empty$
        'skip$
        { output.new.block }
      if$
      format.url
    }
  if$
      %
      % format optional note
      %
  note empty$
    'skip$
    { % Clear the stack
      duplicate$ empty$
        'skip$
        { output.new.block }
      if$
      format.note
    }
  if$
  fin.entry
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    %
    % default thesis type is on top of stack
    % now, if type field is empty, this default is used
    % else default is removed and replaced by value of
    % type field
    %
FUNCTION {format.type.school}
{ type empty$
    'skip$
    { pop$
      type "t" change.case$
    }
  if$
  school connect.with.comma.check
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    %
    % phd theses, etc.
    % call with
    %   "default.published.thesis" "default.unpublished.thesis" thesis
    %
FUNCTION {thesis}
{ author empty$
    { "author" author warning.if.empty }
    { format.authors  start.new.block  }
  if$
      %
      % format year and check if year present
      %
  format.year.check output.dot.new.block
      %
      % format title and check if title present
      % journal empty => unpublished PhD thesis
      % journal not empty => published (e.g., Dissertation Abstracts Int.)
      %
  journal empty$
    { format.btitle.vol.edition output.dot.new.block
        %
        % pop default unpublished thesis, top is default published thesis
        %
      swap$ pop$
      format.type.school
      address   connect.with.comma.check
    }
        %
        % pop default published thesis, top is default unpublished thesis
        %
    { pop$
      type empty$
        school empty$
          originalyear empty$
          and
        and
        { pop$
          ""
        }
        { format.type.school
          originalyear   connect.with.comma.check
          parenthesize.check
        }
      if$
      format.aetitle.check
      swap$    connect.with.space.check
      "title"  title warning.if.empty
      title    format.atitle.connect   output.new.block
      pages    format.journal.vol.num.pages.check
    }
  if$
    %
    % if not empty, insert howpublished.
    % (used if thesis is retrieved from the internet)
    %
  format.howpublished add.period$
      %
      % format url
      %
  url empty$
    'skip$
    { % Clear the stack
      duplicate$ empty$
        'skip$
        { output.new.block }
      if$
      format.url
    }
  if$
      %
      % format optional note
      %
  note empty$
    'skip$
    { % Clear the stack
      duplicate$ empty$
        'skip$
        { output.new.block }
      if$
      format.note
    }
  if$
  fin.entry
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    %
    % phd theses, etc.
    %
FUNCTION {phdthesis}
{ "\BPhD"  "\BUPhD"  thesis }

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    %
    % master's theses, etc.
    %
FUNCTION {mastersthesis}
{ "\BMTh"  "\BUMTh"  thesis }

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    %
    % title of something (used in unpublished and misc)
    % english translation of title
    % type and number of something
    %
FUNCTION {format.btitle.type.num}
{ format.betitle.check
  format.bvol.edition  connect.with.space.check
  format.type.number
  connect.with.space.check
  title empty$
    { add.period$ }
    { title format.btitle.connect }
  if$
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    %
    % title of message or software-related thing (used in misc)
    % english translation of title
    % type and number of something
    %
FUNCTION {format.mtitle.type.num}
{ format.aetitle.check
  format.bvol.edition  connect.with.space.check
  type.2 "\bibmessage" =
    { number empty$
        'skip$
        { type.2 number tie.or.space.connect
          bracket.check
          connect.with.space.check
        }
      if$
    }
    { format.type.number
      connect.with.space.check
    }
  if$
  title empty$
    { add.period$ }
    { title format.atitle.connect }
  if$
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    %
    % title, english translation of title,
    % type and number of something (used in misc)
    %
FUNCTION {output.misctitle.type.num}
{ type.2 empty$
    { format.btitle.type.num }
    { type.2 "\bibmessage"                    =
      type.2 "\bibcomputerprogram"            =  or
      type.2 "\bibcomputerprogrammanual"      =  or
      type.2 "\bibcomputerprogramandmanual"   =  or
      type.2 "\bibcomputersoftware"           =  or
      type.2 "\bibcomputersoftwaremanual"     =  or
      type.2 "\bibcomputersoftwareandmanual"  =  or
      type.2 "\bibprogramminglanguage"        =  or
        { format.mtitle.type.num }
        { format.btitle.type.num }
      if$
    }
  if$
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    %
    % unpublished manuscripts, etc.
    %
FUNCTION {unpublished}
{ check.relevant.fields
  author empty$
        %
        % no author: possibly edited book with editors as authors
        %
    { editor empty$
            %
            % no author or editor: title serves as author.
            % title formatted as book title
            %
        { format.btitle.type.num       output.new.block
          format.year.month.day.check  add.period$
        }
            %
            % format editor and year, and check if year is present
            % format book title, volume, and edition and check if title present
            %
        { format.editors.as.authors    start.new.block
          format.year.month.day.check  output.dot.new.block
          format.btitle.type.num
        }
      if$
    }
        %
        % format author and year, and check if year is present
        % format book title, volume, and edition
        % and check if title or type present
        %
    { format.authors               start.new.block
      format.year.month.day.check  output.dot.new.block
      format.btitle.type.num
    }
  if$
  howpublished empty$
  organization empty$ and
  address      empty$ and
    'skip$
    { output.new.block
      "\APAChowpublished{" "}" howpublished enclose.check
      organization    connect.with.comma.check
      address         connect.with.comma.check
      add.period$
    }
  if$
      %
      % format url
      %
  url empty$
    'skip$
    { % Clear the stack
      duplicate$ empty$
        'skip$
        { output.new.block }
      if$
      format.url
    }
  if$
      %
      % format optional note
      %
  note empty$
    'skip$
    { % Clear the stack
      duplicate$ empty$
        'skip$
        { output.new.block }
      if$
      format.note
    }
  if$
  fin.entry
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    %
    % nonprint media and other things that don't fit
    %
FUNCTION {misc}
{   %
    % To handle @manual: use type.2 instead of type.
  type.2 empty$
  type   empty$ not and
    { type 'type.2 := }
    'skip$
  if$
    %
  author empty$
        %
        % no author: possibly edited item with editors as authors
        %
    { editor empty$
            %
            % no author or editor: title/type serves as author.
            % title formatted as book title
            %
            % if no title and no type, howpublished is title
            %
        { title  empty$
          type.2 empty$ and
            { howpublished empty$
                { "No author, editor, title, type, and howpublished in "
                  cite$ * warning$
                  ""
                }
                { "\APAChowpublished{" howpublished * "}" * add.period$ }
              if$
              format.year.month.day.check  add.period$
            }
            { output.misctitle.type.num    output.new.block
              format.year.month.day.check  add.period$
              format.howpublished          add.period$
            }
          if$
        }
            %
            % format editor and year, and check if year is present
            % format book title, volume, and edition and check if title present
            %
        { format.editors.as.authors        start.new.block
          format.year.month.day.check      output.dot.new.block
          output.misctitle.type.num
          format.howpublished              add.period$
        }
      if$
    }
        %
        % format author and year, and check if year is present
        % format book title, volume, and edition
        % and check if title or type present
        %
    { format.authors                   start.new.block
      format.year.month.day.check      output.dot.new.block
      output.misctitle.type.num
      format.howpublished              add.period$
    }
  if$
      %
  address   empty$
  publisher empty$ and
      'skip$
      { % Clear the stack
        duplicate$ empty$
          'skip$
          { output.new.block }
        if$
        format.address.publisher add.period$
      }
  if$
      %
      % format url
      %
  url empty$
    'skip$
    { % Clear the stack
      duplicate$ empty$
        'skip$
        { output.new.block }
      if$
      format.url
    }
  if$
      %
      % format optional note
      %
  note empty$
    'skip$
    { % Clear the stack
      duplicate$ empty$
        'skip$
        { output.new.block }
      if$
      format.note
    }
  if$
  fin.entry
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    %
    % for legal cases and other cases that need to be
    % done by hand
    %
FUNCTION {literal}
{ "key"  key  warning.if.empty
  "text" text warning.if.empty
  text empty$
    { "" }
    { text }
  if$
  fin.entry
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    %
    % technical documentation
    %
FUNCTION {manual}
{ %
  % If type is empty, assume that it is a computer software manual.
  %
  type empty$
    { "\bibcomputersoftwaremanual"  'type.2 := }
    'skip$
  if$
  misc
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    %
    % following functions not used for APA Manual examples
    %

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    %
    % booklet
    %
FUNCTION {booklet}
{ misc }

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    %
    % part of a book
    %
FUNCTION {inbook}
{ incollection }

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    %
    % article in proceedings
    %
FUNCTION {inproceedings}
{ incollection }

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    %
    % article in proceedings (Kopka & Daly, 2004, p. 230)
    %
FUNCTION {conference}
{ inproceedings }

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    %
    % proceedings
    %
FUNCTION {proceedings}
{ misc }

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    %
    % unknown types
    %
FUNCTION {default.type}
{ misc }

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

FUNCTION {initialize}
{   %
    % Maximum number of names to be formatted .
  #6  'name.max :=
}

FUNCTION {init.old.number}
{   %
    % For numbering the entries according to current sorting order.
  #0  'old.number :=
}

FUNCTION {init.old.label}
{   %
    % For comparing labels across entries .
  "zzzzzz"   'old.label  :=
}

FUNCTION {init.cite.initials.add.to.year}
{   %
    % Initialize "cite initials" indicator for all entries.
  #0  'cite.initials :=
    %
    % Initialize "add to year", i.e., whether a, b, etc. must
    % be added to the year in citation, to "no".
  #0  'add.to.year :=
    %
}

FUNCTION {move.forward}
{   %
    % Indicates that we're moving forward (ITERATE) through the entry list .
  #1 'forward :=
}

FUNCTION {move.backward}
{   %
    % Indicates that we're moving backward (REVERSE) through the entry list .
  #0 'forward :=
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

FUNCTION {begin.bib}
{ preamble$ empty$
    'skip$
    { preamble$ write$ newline$ }
  if$
  "\begin{thebibliography}{}"  write$ newline$
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

FUNCTION {end.bib}
{ newline$
  "\end{thebibliography}"  write$ newline$
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

FUNCTION {write.bbl.entry}
{   %
    % Output \bibitem and \citeauthoryear command.
    %
  make.cite.labels
    %
    % Format and output reference list entry.
    %
  call.type$
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


READ


EXECUTE { identify.apacite.version }


EXECUTE { initialize }


ITERATE { make.sort.title }

SORT

EXECUTE { init.old.number }

EXECUTE { init.old.label }

ITERATE { make.title.number }


ITERATE { make.tentative.sort.label }

SORT


ITERATE { init.cite.initials.add.to.year }

EXECUTE { init.initials }

ITERATE { check.add.initials }

EXECUTE { init.initials }

REVERSE { check.add.initials }

ITERATE { tentative.cite.num.names }

EXECUTE { init.cite.num.names }

EXECUTE { move.forward }

ITERATE { definitive.cite.num.names }

EXECUTE { init.cite.num.names }

EXECUTE { move.backward }

REVERSE { definitive.cite.num.names }


ITERATE { make.final.sort.key }

SORT


EXECUTE { begin.bib }


ITERATE { write.bbl.entry }


EXECUTE { end.bib }

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%
%%
%% End of file `apacannx.bst'.