summaryrefslogtreecommitdiff
path: root/macros/latex/contrib/songs/songs.dtx
blob: 3f6889fda2a51aa516b1f4c513a1732ec2f10096 (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
5260
5261
5262
5263
5264
5265
5266
5267
5268
5269
5270
5271
5272
5273
5274
5275
5276
5277
5278
5279
5280
5281
5282
5283
5284
5285
5286
5287
5288
5289
5290
5291
5292
5293
5294
5295
5296
5297
5298
5299
5300
5301
5302
5303
5304
5305
5306
5307
5308
5309
5310
5311
5312
5313
5314
5315
5316
5317
5318
5319
5320
5321
5322
5323
5324
5325
5326
5327
5328
5329
5330
5331
5332
5333
5334
5335
5336
5337
5338
5339
5340
5341
5342
5343
5344
5345
5346
5347
5348
5349
5350
5351
5352
5353
5354
5355
5356
5357
5358
5359
5360
5361
5362
5363
5364
5365
5366
5367
5368
5369
5370
5371
5372
5373
5374
5375
5376
5377
5378
5379
5380
5381
5382
5383
5384
5385
5386
5387
5388
5389
5390
5391
5392
5393
5394
5395
5396
5397
5398
5399
5400
5401
5402
5403
5404
5405
5406
5407
5408
5409
5410
5411
5412
5413
5414
5415
5416
5417
5418
5419
5420
5421
5422
5423
5424
5425
5426
5427
5428
5429
5430
5431
5432
5433
5434
5435
5436
5437
5438
5439
5440
5441
5442
5443
5444
5445
5446
5447
5448
5449
5450
5451
5452
5453
5454
5455
5456
5457
5458
5459
5460
5461
5462
5463
5464
5465
5466
5467
5468
5469
5470
5471
5472
5473
5474
5475
5476
5477
5478
5479
5480
5481
5482
5483
5484
5485
5486
5487
5488
5489
5490
5491
5492
5493
5494
5495
5496
5497
5498
5499
5500
5501
5502
5503
5504
5505
5506
5507
5508
5509
5510
5511
5512
5513
5514
5515
5516
5517
5518
5519
5520
5521
5522
5523
5524
5525
5526
5527
5528
5529
5530
5531
5532
5533
5534
5535
5536
5537
5538
5539
5540
5541
5542
5543
5544
5545
5546
5547
5548
5549
5550
5551
5552
5553
5554
5555
5556
5557
5558
5559
5560
5561
5562
5563
5564
5565
5566
5567
5568
5569
5570
5571
5572
5573
5574
5575
5576
5577
5578
5579
5580
5581
5582
5583
5584
5585
5586
5587
5588
5589
5590
5591
5592
5593
5594
5595
5596
5597
5598
5599
5600
5601
5602
5603
5604
5605
5606
5607
5608
5609
5610
5611
5612
5613
5614
5615
5616
5617
5618
5619
5620
5621
5622
5623
5624
5625
5626
5627
5628
5629
5630
5631
5632
5633
5634
5635
5636
5637
5638
5639
5640
5641
5642
5643
5644
5645
5646
5647
5648
5649
5650
5651
5652
5653
5654
5655
5656
5657
5658
5659
5660
5661
5662
5663
5664
5665
5666
5667
5668
5669
5670
5671
5672
5673
5674
5675
5676
5677
5678
5679
5680
5681
5682
5683
5684
5685
5686
5687
5688
5689
5690
5691
5692
5693
5694
5695
5696
5697
5698
5699
5700
5701
5702
5703
5704
5705
5706
5707
5708
5709
5710
5711
5712
5713
5714
5715
5716
5717
5718
5719
5720
5721
5722
5723
5724
5725
5726
5727
5728
5729
5730
5731
5732
5733
5734
5735
5736
5737
5738
5739
5740
5741
5742
5743
5744
5745
5746
5747
5748
5749
5750
5751
5752
5753
5754
5755
5756
5757
5758
5759
5760
5761
5762
5763
5764
5765
5766
5767
5768
5769
5770
5771
5772
5773
5774
5775
5776
5777
5778
5779
5780
5781
5782
5783
5784
5785
5786
5787
5788
5789
5790
5791
5792
5793
5794
5795
5796
5797
5798
5799
5800
5801
5802
5803
5804
5805
5806
5807
5808
5809
5810
5811
5812
5813
5814
5815
5816
5817
5818
5819
5820
5821
5822
5823
5824
5825
5826
5827
5828
5829
5830
5831
5832
5833
5834
5835
5836
5837
5838
5839
5840
5841
5842
5843
5844
5845
5846
5847
5848
5849
5850
5851
5852
5853
5854
5855
5856
5857
5858
5859
5860
5861
5862
5863
5864
5865
5866
5867
5868
5869
5870
5871
5872
5873
5874
5875
5876
5877
5878
5879
5880
5881
5882
5883
5884
5885
5886
5887
5888
5889
5890
5891
5892
5893
5894
5895
5896
5897
5898
5899
5900
5901
5902
5903
5904
5905
5906
5907
5908
5909
5910
5911
5912
5913
5914
5915
5916
5917
5918
5919
5920
5921
5922
5923
5924
5925
5926
5927
5928
5929
5930
5931
5932
5933
5934
5935
5936
5937
5938
5939
5940
5941
5942
5943
5944
5945
5946
5947
5948
5949
5950
5951
5952
5953
5954
5955
5956
5957
5958
5959
5960
5961
5962
5963
5964
5965
5966
5967
5968
5969
5970
5971
5972
5973
5974
5975
5976
5977
5978
5979
5980
5981
5982
5983
5984
5985
5986
5987
5988
5989
5990
5991
5992
5993
5994
5995
5996
5997
5998
5999
6000
6001
6002
6003
6004
6005
6006
6007
6008
6009
6010
6011
6012
6013
6014
6015
6016
6017
6018
6019
6020
6021
6022
6023
6024
6025
6026
6027
6028
6029
6030
6031
6032
6033
6034
6035
6036
6037
6038
6039
6040
6041
6042
6043
6044
6045
6046
6047
6048
6049
6050
6051
6052
6053
6054
6055
6056
6057
6058
6059
6060
6061
6062
6063
6064
6065
6066
6067
6068
6069
6070
6071
6072
6073
6074
6075
6076
6077
6078
6079
6080
6081
6082
6083
6084
6085
6086
6087
6088
6089
6090
6091
6092
6093
6094
6095
6096
6097
6098
6099
6100
6101
6102
6103
6104
6105
6106
6107
6108
6109
6110
6111
6112
6113
6114
6115
6116
6117
6118
6119
6120
6121
6122
6123
6124
6125
6126
6127
6128
6129
6130
6131
6132
6133
6134
6135
6136
6137
6138
6139
6140
6141
6142
6143
6144
6145
6146
6147
6148
6149
6150
6151
6152
6153
6154
6155
6156
6157
6158
6159
6160
6161
6162
6163
6164
6165
6166
6167
6168
6169
6170
6171
6172
6173
6174
6175
6176
6177
6178
6179
6180
6181
6182
6183
6184
6185
6186
6187
6188
6189
6190
6191
6192
6193
6194
6195
6196
6197
6198
6199
6200
6201
6202
6203
6204
6205
6206
6207
6208
6209
6210
6211
6212
6213
6214
6215
6216
6217
6218
6219
6220
6221
6222
6223
6224
6225
6226
6227
6228
6229
6230
6231
6232
6233
6234
6235
6236
6237
6238
6239
6240
6241
6242
6243
6244
6245
6246
6247
6248
6249
6250
6251
6252
6253
6254
6255
6256
6257
6258
6259
6260
6261
6262
6263
6264
6265
6266
6267
6268
6269
6270
6271
6272
6273
6274
6275
6276
6277
6278
6279
6280
6281
6282
6283
6284
6285
6286
6287
6288
6289
6290
6291
6292
6293
6294
6295
6296
6297
6298
6299
6300
6301
6302
6303
6304
6305
6306
6307
6308
6309
6310
6311
6312
6313
6314
6315
6316
6317
6318
6319
6320
6321
6322
6323
6324
6325
6326
6327
6328
6329
6330
6331
6332
6333
6334
6335
6336
6337
6338
6339
6340
6341
6342
6343
6344
6345
6346
6347
6348
6349
6350
6351
6352
6353
6354
6355
6356
6357
6358
6359
6360
6361
6362
6363
6364
6365
6366
6367
6368
6369
6370
6371
6372
6373
6374
6375
6376
6377
6378
6379
6380
6381
6382
6383
6384
6385
6386
6387
6388
6389
6390
6391
6392
6393
6394
6395
6396
6397
6398
6399
6400
6401
6402
6403
6404
6405
6406
6407
6408
6409
6410
6411
6412
6413
6414
6415
6416
6417
6418
6419
6420
6421
6422
6423
6424
6425
6426
6427
6428
6429
6430
6431
6432
6433
6434
6435
6436
6437
6438
6439
6440
6441
6442
6443
6444
6445
6446
6447
6448
6449
6450
6451
6452
6453
6454
6455
6456
6457
6458
6459
6460
6461
6462
6463
6464
6465
6466
6467
6468
6469
6470
6471
6472
6473
6474
6475
6476
6477
6478
6479
6480
6481
6482
6483
6484
6485
6486
6487
6488
6489
6490
6491
6492
6493
6494
6495
6496
6497
6498
6499
6500
6501
6502
6503
6504
6505
6506
6507
6508
6509
6510
6511
6512
6513
6514
6515
6516
6517
6518
6519
6520
6521
6522
6523
6524
6525
6526
6527
6528
6529
6530
6531
6532
6533
6534
6535
6536
6537
6538
6539
6540
6541
6542
6543
6544
6545
6546
6547
6548
6549
6550
6551
6552
6553
6554
6555
6556
6557
6558
6559
6560
6561
6562
6563
6564
6565
6566
6567
6568
6569
6570
6571
6572
6573
6574
6575
6576
6577
6578
6579
6580
6581
6582
6583
6584
6585
6586
6587
6588
6589
6590
6591
6592
6593
6594
6595
6596
6597
6598
6599
6600
6601
6602
6603
6604
6605
6606
6607
6608
6609
6610
6611
6612
6613
6614
6615
6616
6617
6618
6619
6620
6621
6622
6623
6624
6625
6626
6627
6628
6629
6630
6631
6632
6633
6634
6635
6636
6637
6638
6639
6640
6641
6642
6643
6644
6645
6646
6647
6648
6649
6650
6651
6652
6653
6654
6655
6656
6657
6658
6659
6660
6661
6662
6663
6664
6665
6666
6667
6668
6669
6670
6671
6672
6673
6674
6675
6676
6677
6678
6679
6680
6681
6682
6683
6684
6685
6686
6687
6688
6689
6690
6691
6692
6693
6694
6695
6696
6697
6698
6699
6700
6701
6702
6703
6704
6705
6706
6707
6708
6709
6710
6711
6712
6713
6714
6715
6716
6717
6718
6719
6720
6721
6722
6723
6724
6725
6726
6727
6728
6729
6730
6731
6732
6733
6734
6735
6736
6737
6738
6739
6740
6741
6742
6743
6744
6745
6746
6747
6748
6749
6750
6751
6752
6753
6754
6755
6756
6757
6758
6759
6760
6761
6762
6763
6764
6765
6766
6767
6768
6769
6770
6771
6772
6773
6774
6775
6776
6777
6778
6779
6780
6781
6782
6783
6784
6785
6786
6787
6788
6789
6790
6791
6792
6793
6794
6795
6796
6797
6798
6799
6800
6801
6802
6803
6804
6805
6806
6807
6808
6809
6810
6811
6812
6813
6814
6815
6816
6817
6818
6819
6820
6821
6822
6823
6824
6825
6826
6827
6828
6829
6830
6831
6832
6833
6834
6835
6836
6837
6838
6839
6840
6841
6842
6843
6844
6845
6846
6847
6848
6849
6850
6851
6852
6853
6854
6855
6856
6857
6858
6859
6860
6861
6862
6863
6864
6865
6866
6867
6868
6869
6870
6871
6872
6873
6874
6875
6876
6877
6878
6879
6880
6881
6882
6883
6884
6885
6886
6887
6888
6889
6890
6891
6892
6893
6894
6895
6896
6897
6898
6899
6900
6901
6902
6903
6904
6905
6906
6907
6908
6909
6910
6911
6912
6913
6914
6915
6916
6917
6918
6919
6920
6921
6922
6923
6924
6925
6926
6927
6928
6929
6930
6931
6932
6933
6934
6935
6936
6937
6938
6939
6940
6941
6942
6943
6944
6945
6946
6947
6948
6949
6950
6951
6952
6953
6954
6955
6956
6957
6958
6959
6960
6961
6962
6963
6964
6965
6966
6967
6968
6969
6970
6971
6972
6973
6974
6975
6976
6977
6978
6979
6980
6981
6982
6983
6984
6985
6986
6987
6988
6989
6990
6991
6992
6993
6994
6995
6996
6997
6998
6999
7000
7001
7002
7003
7004
7005
7006
7007
7008
7009
7010
7011
7012
7013
7014
7015
7016
7017
7018
7019
7020
7021
7022
7023
7024
7025
7026
7027
7028
7029
7030
7031
7032
7033
7034
7035
7036
7037
7038
7039
7040
7041
7042
7043
7044
7045
7046
7047
7048
7049
7050
7051
7052
7053
7054
7055
7056
7057
7058
7059
7060
7061
7062
7063
7064
7065
7066
7067
7068
7069
7070
7071
7072
7073
7074
7075
7076
7077
7078
7079
7080
7081
7082
7083
7084
7085
7086
7087
7088
7089
7090
7091
7092
7093
7094
7095
7096
7097
7098
7099
7100
7101
7102
7103
7104
7105
7106
7107
7108
7109
7110
7111
7112
7113
7114
7115
7116
7117
7118
7119
7120
7121
7122
7123
7124
7125
7126
7127
7128
7129
7130
7131
7132
7133
7134
7135
7136
7137
7138
7139
7140
7141
7142
7143
7144
7145
7146
7147
7148
7149
7150
7151
7152
7153
7154
7155
7156
7157
7158
7159
7160
7161
7162
7163
7164
7165
7166
7167
7168
7169
7170
7171
7172
7173
7174
7175
7176
7177
7178
7179
7180
7181
7182
7183
7184
7185
7186
7187
7188
7189
7190
7191
7192
7193
7194
7195
7196
7197
7198
7199
7200
7201
7202
7203
7204
7205
7206
7207
7208
7209
7210
7211
7212
7213
7214
7215
7216
7217
7218
7219
7220
7221
7222
7223
7224
7225
7226
7227
7228
7229
7230
7231
7232
7233
7234
7235
7236
7237
7238
7239
7240
7241
7242
7243
7244
7245
7246
7247
7248
7249
7250
7251
7252
7253
7254
7255
7256
7257
7258
7259
7260
7261
7262
7263
7264
7265
7266
7267
7268
7269
7270
7271
7272
7273
7274
7275
7276
7277
7278
7279
7280
7281
7282
7283
7284
7285
7286
7287
7288
7289
7290
7291
7292
7293
7294
7295
7296
7297
7298
7299
7300
7301
7302
7303
7304
7305
7306
7307
7308
7309
7310
7311
7312
7313
7314
7315
7316
7317
7318
7319
7320
7321
7322
7323
7324
7325
7326
7327
7328
7329
7330
7331
7332
7333
7334
7335
7336
7337
7338
7339
7340
7341
7342
7343
7344
7345
7346
7347
7348
7349
7350
7351
7352
7353
7354
7355
7356
7357
7358
7359
7360
7361
7362
7363
7364
7365
7366
7367
7368
7369
7370
7371
7372
7373
7374
7375
7376
7377
7378
7379
7380
7381
7382
7383
7384
7385
7386
7387
7388
7389
7390
7391
7392
7393
7394
7395
7396
7397
7398
7399
7400
7401
7402
7403
7404
7405
7406
7407
7408
7409
7410
7411
7412
7413
7414
7415
7416
7417
7418
7419
7420
7421
7422
7423
7424
7425
7426
7427
7428
7429
7430
7431
7432
7433
7434
7435
7436
7437
7438
7439
7440
7441
7442
7443
7444
7445
7446
7447
7448
7449
7450
7451
7452
7453
7454
7455
7456
7457
7458
7459
7460
7461
7462
7463
7464
7465
7466
7467
7468
7469
7470
7471
7472
7473
7474
7475
7476
7477
7478
7479
7480
7481
7482
7483
7484
7485
7486
7487
7488
7489
7490
7491
7492
7493
7494
7495
7496
7497
7498
7499
7500
7501
7502
7503
7504
7505
7506
7507
7508
7509
7510
7511
7512
7513
7514
7515
7516
7517
7518
7519
7520
7521
7522
7523
7524
7525
7526
7527
7528
7529
7530
7531
7532
7533
7534
7535
7536
7537
7538
7539
7540
7541
7542
7543
7544
7545
7546
7547
7548
7549
7550
7551
7552
7553
7554
7555
7556
7557
7558
7559
7560
7561
7562
7563
7564
7565
7566
7567
7568
7569
7570
7571
7572
7573
7574
7575
7576
7577
7578
7579
7580
7581
7582
7583
7584
7585
7586
7587
7588
7589
7590
7591
7592
7593
7594
7595
7596
7597
7598
7599
7600
7601
7602
7603
7604
7605
7606
7607
7608
7609
7610
7611
7612
7613
7614
7615
7616
7617
7618
7619
7620
7621
7622
7623
7624
7625
7626
7627
7628
7629
7630
7631
7632
7633
7634
7635
7636
7637
7638
7639
7640
7641
7642
7643
7644
7645
7646
7647
7648
7649
7650
7651
7652
7653
7654
7655
7656
7657
7658
7659
7660
7661
7662
7663
7664
7665
7666
7667
7668
7669
7670
7671
7672
7673
7674
7675
7676
7677
7678
7679
7680
7681
7682
7683
7684
7685
7686
7687
7688
7689
7690
7691
7692
7693
7694
7695
7696
7697
7698
7699
7700
7701
7702
7703
7704
7705
7706
7707
7708
7709
7710
7711
7712
7713
7714
7715
7716
7717
7718
7719
7720
7721
7722
7723
7724
7725
7726
7727
7728
7729
7730
7731
7732
7733
7734
7735
7736
7737
7738
7739
7740
7741
7742
7743
7744
7745
7746
7747
7748
7749
7750
7751
7752
7753
7754
7755
7756
7757
7758
7759
7760
7761
7762
7763
7764
7765
7766
7767
7768
7769
7770
7771
7772
7773
7774
7775
7776
7777
7778
7779
7780
7781
7782
7783
7784
7785
7786
7787
7788
7789
7790
7791
7792
7793
7794
7795
7796
7797
7798
7799
7800
7801
7802
7803
7804
7805
7806
7807
7808
7809
7810
7811
7812
7813
7814
7815
7816
7817
7818
7819
7820
7821
7822
7823
7824
7825
7826
7827
7828
7829
7830
7831
7832
7833
7834
7835
7836
7837
7838
7839
7840
7841
7842
7843
7844
7845
7846
7847
7848
7849
7850
7851
7852
7853
7854
7855
7856
7857
7858
7859
7860
7861
7862
7863
7864
7865
7866
7867
7868
7869
7870
7871
7872
7873
7874
7875
7876
7877
7878
7879
7880
7881
7882
7883
7884
7885
7886
7887
7888
7889
7890
7891
7892
7893
7894
7895
7896
7897
7898
7899
7900
7901
7902
7903
7904
7905
7906
7907
7908
7909
7910
7911
7912
7913
7914
7915
7916
7917
7918
7919
7920
7921
7922
7923
7924
7925
7926
7927
7928
7929
7930
7931
7932
7933
7934
7935
7936
7937
7938
7939
7940
7941
7942
7943
7944
7945
7946
7947
7948
7949
7950
7951
7952
7953
7954
7955
7956
7957
7958
7959
7960
7961
7962
7963
7964
7965
7966
7967
7968
7969
7970
7971
7972
7973
7974
7975
7976
7977
7978
7979
7980
7981
7982
7983
7984
7985
7986
7987
7988
7989
7990
7991
7992
7993
7994
7995
7996
7997
7998
7999
8000
8001
8002
8003
8004
8005
8006
8007
8008
8009
8010
8011
8012
8013
8014
8015
8016
8017
8018
8019
8020
8021
8022
8023
8024
8025
8026
8027
8028
8029
8030
8031
8032
8033
8034
8035
8036
8037
8038
8039
8040
8041
8042
8043
8044
8045
8046
8047
8048
8049
8050
8051
8052
8053
8054
8055
8056
8057
8058
8059
8060
8061
8062
8063
8064
8065
8066
8067
8068
8069
8070
8071
8072
8073
8074
8075
8076
8077
8078
8079
8080
8081
8082
8083
8084
8085
8086
8087
8088
8089
8090
8091
8092
8093
8094
8095
8096
8097
8098
8099
8100
8101
8102
8103
8104
8105
8106
8107
8108
8109
8110
8111
8112
8113
8114
8115
8116
8117
8118
8119
8120
8121
8122
8123
8124
8125
8126
8127
8128
8129
8130
8131
8132
8133
8134
8135
8136
8137
8138
8139
8140
8141
8142
8143
8144
8145
8146
8147
8148
8149
8150
8151
8152
8153
8154
8155
8156
8157
8158
8159
8160
8161
8162
8163
8164
8165
8166
8167
8168
8169
8170
8171
8172
8173
8174
8175
8176
8177
8178
8179
8180
8181
8182
8183
8184
8185
8186
8187
8188
8189
8190
8191
8192
8193
8194
8195
8196
8197
8198
8199
8200
8201
8202
8203
8204
8205
8206
8207
8208
8209
8210
8211
8212
8213
8214
8215
8216
8217
8218
8219
8220
8221
8222
8223
8224
8225
8226
8227
8228
8229
8230
8231
8232
8233
8234
8235
8236
8237
8238
8239
8240
8241
8242
8243
8244
8245
8246
8247
8248
8249
8250
8251
8252
8253
8254
8255
8256
8257
8258
8259
8260
8261
8262
8263
8264
8265
8266
8267
8268
8269
8270
8271
8272
8273
8274
8275
8276
8277
8278
8279
8280
8281
8282
8283
8284
8285
8286
8287
8288
8289
8290
8291
8292
8293
8294
8295
8296
8297
8298
8299
8300
8301
8302
8303
8304
8305
8306
8307
8308
8309
8310
8311
8312
8313
8314
8315
8316
8317
8318
8319
8320
8321
8322
8323
8324
8325
8326
8327
8328
8329
8330
8331
8332
8333
8334
8335
8336
8337
8338
8339
8340
8341
8342
8343
8344
8345
8346
8347
8348
8349
8350
8351
8352
8353
8354
8355
8356
8357
8358
8359
8360
8361
8362
8363
8364
8365
8366
8367
8368
8369
8370
8371
8372
8373
8374
8375
8376
8377
8378
8379
8380
8381
8382
8383
8384
8385
8386
8387
8388
8389
8390
8391
8392
8393
8394
8395
8396
8397
8398
8399
8400
8401
8402
8403
8404
8405
8406
8407
8408
8409
8410
8411
8412
8413
8414
8415
8416
8417
8418
8419
8420
8421
8422
8423
8424
8425
8426
8427
8428
8429
8430
8431
8432
8433
8434
8435
8436
8437
8438
8439
8440
8441
8442
8443
8444
8445
8446
8447
8448
8449
8450
8451
8452
8453
8454
8455
8456
8457
8458
8459
8460
8461
8462
8463
8464
8465
8466
8467
8468
8469
8470
8471
8472
8473
8474
8475
8476
8477
8478
8479
8480
8481
8482
8483
8484
8485
8486
8487
8488
8489
8490
8491
8492
8493
8494
8495
8496
8497
8498
8499
8500
8501
8502
8503
8504
8505
8506
8507
8508
8509
8510
8511
8512
8513
8514
8515
8516
8517
8518
8519
8520
8521
8522
8523
8524
8525
8526
8527
8528
8529
8530
8531
8532
8533
8534
8535
8536
8537
8538
8539
8540
8541
8542
8543
8544
8545
8546
8547
8548
8549
8550
8551
8552
8553
8554
8555
8556
8557
8558
8559
8560
8561
8562
8563
8564
8565
8566
8567
8568
8569
8570
8571
8572
8573
8574
8575
8576
8577
8578
8579
8580
8581
8582
8583
8584
8585
8586
8587
8588
8589
8590
8591
8592
8593
8594
8595
8596
8597
8598
8599
8600
8601
8602
8603
8604
8605
8606
8607
8608
8609
8610
8611
8612
8613
8614
8615
8616
8617
8618
8619
8620
8621
8622
8623
8624
8625
8626
8627
8628
8629
8630
8631
8632
8633
8634
8635
8636
8637
8638
8639
8640
8641
8642
8643
8644
8645
8646
8647
8648
8649
8650
8651
8652
8653
8654
8655
8656
8657
8658
8659
8660
8661
8662
8663
8664
8665
8666
8667
8668
8669
8670
8671
8672
8673
8674
8675
8676
8677
8678
8679
8680
8681
8682
8683
8684
8685
8686
8687
8688
8689
8690
8691
8692
8693
8694
8695
8696
8697
8698
8699
8700
8701
8702
8703
8704
8705
8706
8707
8708
8709
8710
8711
8712
8713
8714
8715
8716
8717
8718
8719
8720
8721
8722
8723
8724
8725
8726
8727
8728
8729
8730
8731
8732
8733
8734
8735
8736
8737
8738
8739
8740
8741
8742
8743
8744
8745
8746
8747
8748
8749
8750
8751
8752
8753
8754
8755
8756
8757
8758
8759
8760
8761
8762
8763
8764
8765
8766
8767
8768
8769
8770
8771
8772
8773
8774
8775
8776
8777
8778
8779
8780
8781
8782
8783
8784
8785
8786
8787
8788
8789
8790
8791
8792
8793
8794
8795
8796
8797
8798
8799
8800
8801
8802
8803
8804
8805
8806
8807
8808
8809
8810
8811
8812
8813
8814
8815
8816
8817
8818
8819
8820
8821
8822
8823
8824
8825
8826
8827
8828
8829
8830
8831
8832
8833
8834
8835
8836
8837
8838
8839
8840
8841
8842
8843
8844
8845
8846
8847
8848
8849
8850
8851
8852
8853
8854
8855
8856
8857
8858
8859
8860
8861
8862
8863
8864
8865
8866
8867
8868
8869
8870
8871
8872
8873
8874
8875
8876
8877
8878
8879
8880
8881
8882
8883
8884
8885
8886
8887
8888
8889
8890
8891
8892
8893
8894
8895
8896
8897
8898
8899
8900
8901
8902
8903
8904
8905
8906
8907
8908
8909
8910
8911
8912
8913
8914
8915
8916
8917
8918
8919
8920
8921
8922
8923
8924
8925
8926
8927
8928
8929
8930
8931
8932
8933
8934
8935
8936
8937
8938
8939
8940
8941
8942
8943
8944
8945
8946
8947
8948
8949
8950
8951
8952
8953
8954
8955
8956
8957
8958
8959
8960
8961
8962
8963
8964
8965
8966
8967
8968
8969
8970
8971
8972
8973
8974
8975
8976
8977
8978
8979
8980
8981
8982
8983
8984
8985
8986
8987
8988
8989
8990
8991
8992
8993
8994
8995
8996
8997
8998
8999
9000
9001
9002
9003
9004
9005
9006
9007
9008
9009
9010
9011
9012
9013
9014
9015
9016
9017
9018
9019
9020
9021
9022
9023
9024
9025
9026
9027
9028
9029
9030
9031
9032
9033
9034
9035
9036
9037
9038
9039
9040
9041
9042
9043
9044
9045
9046
9047
9048
9049
9050
9051
9052
9053
9054
9055
9056
9057
9058
9059
9060
9061
9062
9063
9064
9065
9066
9067
9068
9069
9070
9071
9072
9073
9074
9075
9076
9077
9078
9079
9080
9081
9082
9083
9084
9085
9086
9087
9088
9089
9090
9091
9092
9093
9094
9095
9096
9097
9098
9099
9100
9101
9102
9103
9104
9105
9106
9107
9108
9109
9110
9111
9112
9113
9114
9115
9116
9117
9118
9119
9120
9121
9122
9123
9124
9125
9126
9127
9128
9129
9130
9131
9132
9133
9134
9135
9136
9137
9138
9139
9140
9141
9142
9143
9144
9145
9146
9147
9148
9149
9150
9151
9152
9153
9154
9155
9156
9157
9158
9159
9160
9161
9162
9163
9164
9165
9166
9167
9168
9169
9170
9171
9172
9173
9174
9175
9176
9177
9178
9179
9180
9181
9182
9183
9184
9185
9186
9187
9188
9189
9190
9191
9192
9193
9194
9195
9196
9197
9198
9199
9200
9201
9202
9203
9204
9205
9206
9207
9208
9209
9210
9211
9212
9213
9214
9215
9216
9217
9218
9219
9220
9221
9222
9223
9224
9225
9226
9227
9228
9229
9230
9231
9232
9233
9234
9235
9236
9237
9238
9239
9240
9241
9242
9243
9244
9245
9246
9247
9248
9249
9250
9251
9252
9253
9254
9255
9256
9257
9258
9259
9260
9261
9262
9263
9264
9265
9266
9267
9268
9269
9270
9271
9272
9273
9274
9275
9276
9277
9278
9279
9280
9281
9282
9283
9284
9285
9286
9287
9288
9289
9290
9291
9292
9293
9294
9295
9296
9297
9298
9299
9300
9301
9302
9303
9304
9305
9306
9307
9308
9309
9310
9311
9312
9313
9314
9315
9316
9317
9318
9319
9320
9321
9322
9323
9324
9325
9326
9327
9328
9329
9330
9331
9332
9333
9334
9335
9336
9337
9338
9339
9340
9341
9342
9343
9344
9345
9346
9347
9348
9349
9350
9351
9352
9353
9354
9355
9356
9357
9358
9359
9360
9361
9362
9363
9364
9365
9366
9367
9368
9369
9370
9371
9372
9373
9374
9375
9376
9377
9378
9379
9380
9381
9382
9383
9384
9385
9386
9387
9388
9389
9390
9391
9392
9393
9394
9395
9396
9397
9398
9399
9400
9401
9402
9403
9404
9405
9406
9407
9408
9409
9410
9411
9412
9413
9414
9415
9416
9417
9418
9419
9420
9421
9422
9423
9424
9425
9426
9427
9428
9429
9430
9431
9432
9433
9434
9435
9436
9437
9438
9439
9440
9441
9442
9443
9444
9445
9446
9447
9448
9449
9450
9451
9452
9453
9454
9455
9456
9457
9458
9459
9460
9461
9462
9463
9464
9465
9466
9467
9468
9469
9470
9471
9472
9473
9474
9475
9476
9477
9478
9479
9480
9481
9482
9483
9484
9485
9486
9487
9488
9489
9490
9491
9492
9493
9494
9495
9496
9497
9498
9499
9500
9501
9502
9503
9504
9505
9506
9507
9508
9509
9510
9511
9512
9513
9514
9515
9516
9517
9518
9519
9520
9521
9522
9523
9524
9525
9526
9527
9528
9529
9530
9531
9532
9533
9534
9535
9536
9537
9538
9539
9540
9541
9542
9543
9544
9545
9546
9547
9548
9549
9550
9551
9552
9553
9554
9555
9556
9557
9558
9559
9560
9561
9562
9563
9564
9565
9566
9567
9568
9569
9570
9571
9572
9573
9574
9575
9576
9577
9578
9579
9580
9581
9582
9583
9584
9585
9586
9587
9588
9589
9590
9591
9592
9593
9594
9595
9596
9597
9598
9599
9600
9601
9602
9603
9604
9605
9606
9607
9608
9609
9610
9611
9612
9613
9614
9615
9616
9617
9618
9619
9620
9621
9622
9623
9624
9625
9626
9627
9628
9629
9630
9631
9632
9633
9634
9635
9636
9637
9638
9639
9640
9641
9642
9643
9644
9645
9646
9647
9648
9649
9650
9651
9652
9653
9654
9655
9656
9657
9658
9659
9660
9661
9662
9663
9664
9665
9666
9667
9668
9669
9670
9671
9672
9673
9674
9675
9676
9677
9678
9679
9680
9681
9682
9683
9684
9685
9686
9687
9688
9689
9690
9691
9692
9693
9694
9695
9696
9697
9698
9699
9700
9701
9702
9703
9704
9705
9706
9707
9708
9709
9710
9711
9712
9713
9714
9715
9716
9717
9718
9719
9720
9721
9722
9723
9724
9725
9726
9727
9728
9729
9730
9731
9732
9733
9734
9735
9736
9737
9738
9739
9740
9741
9742
9743
9744
9745
9746
9747
9748
9749
9750
9751
9752
9753
9754
9755
9756
9757
9758
9759
9760
9761
9762
9763
9764
9765
9766
9767
9768
9769
9770
9771
9772
9773
9774
9775
9776
9777
9778
9779
9780
9781
9782
9783
9784
9785
9786
9787
9788
9789
9790
9791
9792
9793
9794
9795
9796
9797
9798
9799
9800
9801
9802
9803
9804
9805
9806
9807
9808
9809
9810
9811
9812
9813
9814
9815
9816
9817
9818
9819
9820
9821
9822
9823
9824
9825
9826
9827
9828
9829
9830
9831
9832
9833
9834
9835
9836
9837
9838
9839
9840
9841
9842
9843
9844
9845
9846
9847
9848
9849
9850
9851
9852
9853
9854
9855
9856
9857
9858
9859
9860
9861
9862
9863
9864
9865
9866
9867
9868
9869
9870
9871
9872
9873
9874
9875
9876
9877
9878
9879
9880
9881
9882
9883
9884
9885
9886
9887
9888
9889
9890
9891
9892
9893
9894
9895
9896
9897
9898
9899
9900
9901
9902
9903
9904
9905
9906
9907
9908
9909
9910
9911
9912
9913
9914
9915
9916
9917
9918
9919
9920
9921
9922
9923
9924
9925
9926
9927
9928
9929
9930
9931
9932
9933
9934
9935
9936
9937
9938
9939
9940
9941
9942
9943
9944
9945
9946
9947
9948
9949
9950
9951
9952
9953
9954
9955
9956
9957
9958
9959
9960
9961
9962
9963
9964
9965
9966
9967
9968
9969
9970
9971
9972
9973
9974
9975
9976
9977
9978
9979
9980
9981
9982
9983
9984
9985
9986
9987
9988
9989
9990
9991
9992
9993
9994
9995
9996
9997
9998
9999
10000
10001
10002
10003
10004
10005
10006
10007
10008
10009
10010
10011
10012
10013
10014
10015
10016
10017
10018
10019
10020
10021
10022
10023
10024
10025
10026
10027
10028
10029
10030
10031
10032
10033
10034
10035
10036
10037
10038
10039
10040
10041
10042
10043
10044
10045
10046
10047
10048
10049
10050
10051
10052
10053
10054
10055
10056
10057
10058
10059
10060
10061
10062
10063
10064
10065
10066
10067
10068
10069
10070
10071
10072
10073
10074
10075
10076
10077
10078
10079
10080
10081
10082
10083
10084
10085
10086
10087
10088
10089
10090
10091
10092
10093
10094
10095
10096
10097
10098
10099
10100
10101
10102
10103
10104
10105
10106
10107
10108
10109
10110
10111
10112
10113
10114
10115
10116
10117
10118
10119
10120
10121
10122
10123
10124
10125
10126
10127
10128
10129
10130
10131
10132
10133
10134
10135
10136
10137
10138
10139
10140
10141
10142
10143
10144
10145
10146
10147
10148
10149
10150
10151
10152
10153
10154
10155
10156
10157
10158
10159
10160
10161
10162
10163
10164
10165
10166
10167
10168
10169
10170
10171
10172
10173
10174
10175
10176
10177
10178
10179
10180
10181
10182
10183
10184
10185
10186
10187
10188
10189
10190
10191
10192
10193
10194
10195
10196
10197
10198
10199
10200
10201
10202
10203
10204
10205
10206
10207
10208
10209
10210
10211
10212
10213
10214
10215
10216
10217
10218
10219
10220
10221
10222
10223
10224
10225
10226
10227
10228
10229
10230
10231
10232
10233
10234
10235
10236
10237
10238
10239
10240
10241
10242
10243
10244
10245
10246
10247
10248
10249
10250
10251
10252
10253
10254
10255
10256
10257
10258
10259
10260
10261
10262
10263
10264
10265
10266
10267
10268
10269
10270
10271
10272
10273
10274
10275
10276
10277
10278
10279
10280
10281
10282
10283
10284
10285
10286
10287
10288
10289
10290
10291
10292
10293
10294
10295
10296
10297
10298
10299
10300
10301
10302
10303
10304
10305
10306
10307
10308
10309
10310
10311
10312
10313
10314
10315
10316
10317
10318
10319
10320
10321
10322
10323
10324
10325
10326
10327
10328
10329
10330
10331
10332
10333
10334
10335
10336
10337
10338
10339
10340
10341
10342
10343
10344
10345
10346
10347
10348
10349
10350
10351
10352
10353
10354
10355
10356
10357
10358
10359
10360
10361
10362
10363
10364
10365
10366
10367
10368
10369
10370
10371
10372
10373
10374
10375
10376
10377
10378
10379
10380
10381
10382
10383
10384
10385
10386
10387
10388
10389
10390
10391
10392
10393
10394
10395
10396
10397
10398
10399
10400
10401
10402
10403
10404
10405
10406
10407
10408
10409
10410
10411
10412
10413
10414
10415
10416
10417
10418
10419
10420
10421
10422
10423
10424
10425
10426
10427
10428
10429
10430
10431
10432
10433
10434
10435
10436
10437
10438
10439
10440
10441
10442
10443
10444
10445
10446
10447
10448
10449
10450
10451
10452
10453
10454
10455
10456
10457
10458
10459
10460
10461
10462
10463
10464
10465
10466
10467
10468
10469
10470
10471
10472
10473
10474
10475
10476
10477
10478
10479
10480
10481
10482
10483
10484
10485
10486
10487
10488
10489
10490
10491
10492
10493
10494
10495
10496
10497
10498
10499
10500
10501
10502
10503
10504
10505
10506
10507
10508
10509
10510
10511
10512
10513
10514
10515
10516
10517
10518
10519
10520
10521
10522
10523
10524
10525
10526
10527
10528
10529
10530
10531
10532
10533
10534
10535
10536
10537
10538
10539
10540
10541
10542
10543
10544
10545
10546
10547
10548
10549
10550
10551
10552
10553
10554
10555
10556
10557
10558
10559
10560
10561
10562
10563
10564
10565
10566
10567
10568
10569
10570
10571
10572
10573
10574
10575
10576
10577
10578
10579
10580
10581
10582
10583
10584
10585
10586
10587
10588
10589
10590
10591
10592
10593
10594
10595
10596
10597
10598
10599
10600
10601
10602
10603
10604
10605
10606
10607
10608
10609
10610
10611
10612
10613
10614
10615
10616
10617
10618
10619
10620
10621
10622
10623
10624
10625
10626
10627
10628
10629
10630
10631
10632
10633
10634
10635
10636
10637
10638
10639
10640
10641
10642
10643
10644
10645
10646
10647
10648
10649
10650
10651
10652
10653
10654
10655
10656
10657
10658
10659
10660
10661
10662
10663
10664
10665
10666
10667
10668
10669
10670
10671
10672
10673
10674
10675
10676
10677
10678
10679
10680
10681
10682
10683
10684
10685
10686
10687
10688
10689
10690
10691
10692
10693
10694
10695
10696
10697
10698
10699
10700
10701
10702
10703
10704
10705
10706
10707
10708
10709
10710
10711
10712
10713
10714
10715
10716
10717
10718
10719
10720
10721
10722
10723
10724
10725
10726
10727
10728
10729
10730
10731
10732
10733
10734
10735
10736
10737
10738
10739
10740
10741
10742
10743
10744
10745
10746
10747
10748
10749
10750
10751
10752
10753
10754
10755
10756
10757
10758
10759
10760
10761
10762
10763
10764
10765
10766
10767
10768
10769
10770
10771
10772
10773
10774
10775
10776
10777
10778
10779
10780
10781
10782
10783
10784
10785
10786
10787
10788
10789
10790
10791
10792
10793
10794
10795
10796
10797
10798
10799
10800
10801
10802
10803
10804
10805
10806
10807
10808
10809
10810
10811
10812
10813
10814
10815
10816
10817
10818
10819
10820
10821
10822
10823
10824
10825
10826
10827
10828
10829
10830
10831
10832
10833
10834
10835
10836
10837
10838
10839
10840
10841
10842
10843
10844
10845
10846
10847
10848
10849
10850
10851
10852
10853
10854
10855
10856
10857
10858
10859
10860
10861
10862
10863
10864
10865
10866
10867
10868
10869
10870
10871
10872
10873
10874
10875
10876
10877
10878
10879
10880
10881
10882
10883
10884
10885
10886
10887
10888
10889
10890
10891
10892
10893
10894
10895
10896
10897
10898
10899
10900
10901
10902
10903
10904
10905
10906
10907
10908
10909
10910
10911
10912
10913
10914
10915
10916
10917
10918
10919
10920
10921
10922
10923
10924
10925
10926
10927
10928
10929
10930
10931
10932
10933
10934
10935
10936
10937
10938
10939
10940
10941
10942
10943
10944
10945
10946
10947
10948
10949
10950
10951
10952
10953
10954
10955
10956
10957
10958
10959
10960
10961
10962
10963
10964
10965
10966
10967
10968
10969
10970
10971
10972
10973
10974
10975
10976
10977
10978
10979
10980
10981
10982
10983
10984
10985
10986
10987
10988
10989
10990
10991
10992
10993
10994
10995
10996
10997
10998
10999
11000
11001
11002
11003
11004
11005
11006
11007
11008
11009
11010
11011
11012
11013
11014
11015
11016
11017
11018
11019
11020
11021
11022
11023
11024
11025
11026
11027
11028
11029
11030
11031
11032
11033
11034
11035
11036
11037
11038
11039
11040
11041
11042
11043
11044
11045
11046
11047
11048
11049
11050
11051
11052
11053
11054
11055
11056
11057
11058
11059
11060
11061
11062
11063
11064
11065
11066
11067
11068
11069
11070
11071
11072
11073
11074
11075
11076
11077
11078
11079
11080
11081
11082
11083
11084
11085
11086
11087
11088
11089
11090
11091
11092
11093
11094
11095
11096
11097
11098
11099
11100
11101
11102
11103
11104
11105
11106
11107
11108
11109
11110
11111
11112
11113
11114
11115
11116
11117
11118
11119
11120
11121
11122
11123
11124
11125
11126
11127
11128
11129
11130
11131
11132
11133
11134
11135
11136
11137
11138
11139
11140
11141
11142
11143
11144
11145
11146
11147
11148
11149
11150
11151
11152
11153
11154
11155
11156
11157
11158
11159
11160
11161
11162
11163
11164
11165
11166
11167
11168
11169
11170
11171
11172
11173
11174
11175
11176
11177
11178
11179
11180
11181
11182
11183
11184
11185
11186
11187
11188
11189
11190
11191
11192
11193
11194
11195
11196
11197
11198
11199
11200
11201
11202
11203
11204
11205
11206
11207
11208
11209
11210
11211
11212
11213
11214
11215
11216
11217
11218
11219
11220
11221
11222
11223
11224
11225
11226
11227
11228
11229
11230
11231
11232
11233
11234
11235
11236
11237
11238
11239
11240
11241
11242
11243
11244
11245
11246
11247
11248
11249
11250
11251
11252
11253
11254
11255
11256
11257
11258
11259
11260
11261
11262
11263
11264
11265
11266
11267
11268
11269
11270
11271
11272
11273
11274
11275
11276
11277
11278
11279
11280
11281
11282
11283
11284
11285
11286
11287
11288
11289
11290
11291
11292
11293
11294
11295
11296
11297
11298
11299
11300
11301
11302
11303
11304
11305
11306
11307
11308
11309
11310
11311
11312
11313
11314
11315
11316
11317
11318
11319
11320
11321
11322
11323
11324
11325
11326
11327
11328
11329
11330
11331
11332
11333
11334
11335
11336
11337
11338
11339
11340
11341
11342
11343
11344
11345
11346
11347
11348
11349
11350
11351
11352
11353
11354
11355
11356
11357
11358
11359
11360
11361
11362
11363
11364
11365
11366
11367
11368
11369
11370
11371
11372
11373
11374
11375
11376
11377
11378
11379
11380
11381
11382
11383
11384
11385
11386
11387
11388
11389
11390
11391
11392
11393
11394
11395
11396
11397
11398
11399
11400
11401
11402
11403
11404
11405
11406
11407
11408
11409
11410
11411
11412
11413
11414
11415
11416
11417
11418
11419
11420
11421
11422
11423
11424
11425
11426
11427
11428
11429
11430
11431
11432
11433
11434
11435
11436
11437
11438
11439
11440
11441
11442
11443
11444
11445
11446
11447
11448
11449
11450
11451
11452
11453
11454
11455
11456
11457
11458
11459
11460
11461
11462
11463
11464
11465
11466
11467
11468
11469
11470
11471
11472
11473
11474
11475
11476
11477
11478
11479
11480
11481
11482
11483
11484
11485
11486
11487
11488
11489
11490
11491
11492
11493
11494
11495
11496
11497
11498
11499
11500
11501
11502
11503
11504
11505
11506
11507
11508
11509
11510
11511
11512
11513
11514
11515
11516
11517
11518
11519
11520
11521
11522
11523
11524
11525
11526
11527
11528
11529
11530
11531
11532
11533
11534
11535
11536
11537
11538
11539
11540
11541
11542
11543
11544
11545
11546
11547
11548
11549
11550
11551
11552
11553
11554
11555
11556
11557
11558
11559
11560
11561
11562
11563
11564
11565
11566
11567
11568
11569
11570
11571
11572
11573
11574
11575
11576
11577
11578
11579
11580
11581
11582
11583
11584
11585
11586
11587
11588
11589
11590
11591
11592
11593
11594
11595
11596
11597
11598
11599
11600
11601
11602
11603
11604
11605
11606
11607
11608
11609
11610
11611
11612
11613
11614
11615
11616
11617
11618
11619
11620
11621
11622
11623
11624
11625
11626
11627
11628
11629
11630
11631
11632
11633
11634
11635
11636
11637
11638
11639
11640
11641
11642
11643
11644
11645
11646
11647
11648
11649
11650
11651
11652
11653
11654
11655
11656
11657
11658
11659
11660
11661
11662
11663
11664
11665
11666
11667
11668
11669
11670
11671
11672
11673
11674
11675
11676
11677
11678
11679
11680
11681
11682
11683
11684
11685
11686
11687
11688
11689
11690
11691
11692
11693
11694
11695
11696
11697
11698
11699
11700
11701
11702
11703
11704
11705
11706
11707
11708
11709
11710
11711
11712
11713
11714
11715
11716
11717
11718
11719
11720
11721
11722
11723
11724
11725
11726
11727
11728
11729
11730
11731
11732
11733
11734
11735
11736
11737
11738
11739
11740
11741
11742
11743
11744
11745
11746
11747
11748
11749
11750
11751
11752
11753
11754
11755
11756
11757
11758
11759
11760
11761
11762
11763
11764
11765
11766
11767
11768
11769
11770
11771
11772
11773
11774
11775
11776
11777
11778
11779
11780
11781
11782
11783
11784
11785
11786
11787
11788
11789
11790
11791
11792
11793
11794
11795
11796
11797
11798
11799
11800
11801
11802
11803
11804
11805
11806
11807
11808
11809
11810
11811
11812
11813
11814
11815
11816
11817
11818
11819
11820
11821
11822
11823
11824
11825
11826
11827
11828
11829
11830
11831
11832
11833
11834
11835
11836
11837
11838
11839
11840
11841
11842
11843
11844
11845
11846
11847
11848
11849
11850
11851
11852
11853
11854
11855
11856
11857
11858
11859
11860
11861
11862
11863
11864
11865
11866
11867
11868
11869
11870
11871
11872
11873
11874
11875
11876
11877
11878
11879
11880
11881
11882
11883
11884
11885
11886
11887
11888
11889
11890
11891
11892
11893
11894
11895
11896
11897
11898
11899
11900
11901
11902
11903
11904
11905
11906
11907
11908
11909
11910
11911
11912
11913
11914
11915
11916
11917
11918
11919
11920
11921
11922
11923
11924
11925
11926
11927
11928
11929
11930
11931
11932
11933
11934
11935
11936
11937
11938
11939
11940
11941
11942
11943
11944
11945
11946
11947
11948
11949
11950
11951
11952
11953
11954
11955
11956
11957
11958
11959
11960
11961
11962
11963
11964
11965
11966
11967
11968
11969
11970
11971
11972
11973
11974
11975
11976
11977
11978
11979
11980
11981
11982
11983
11984
11985
11986
11987
11988
11989
11990
11991
11992
11993
11994
11995
11996
11997
11998
11999
12000
12001
12002
12003
12004
12005
12006
12007
12008
12009
12010
12011
12012
12013
12014
12015
12016
12017
12018
12019
12020
12021
12022
12023
12024
12025
12026
12027
12028
12029
12030
12031
12032
12033
12034
12035
12036
12037
12038
12039
12040
12041
12042
12043
12044
12045
12046
12047
12048
12049
12050
12051
12052
12053
12054
12055
12056
12057
12058
12059
12060
12061
12062
12063
12064
12065
12066
12067
12068
12069
12070
12071
12072
12073
12074
12075
12076
12077
12078
12079
12080
12081
12082
12083
12084
12085
12086
12087
12088
12089
12090
12091
12092
12093
12094
12095
12096
12097
12098
12099
12100
12101
12102
12103
12104
12105
12106
12107
12108
12109
12110
12111
12112
12113
12114
12115
12116
12117
12118
12119
12120
12121
12122
12123
12124
12125
12126
12127
12128
12129
12130
12131
12132
12133
12134
12135
12136
12137
12138
12139
12140
12141
12142
12143
12144
12145
12146
12147
12148
12149
12150
12151
12152
12153
12154
12155
12156
12157
12158
12159
12160
12161
12162
12163
12164
12165
12166
12167
12168
12169
12170
12171
12172
12173
12174
12175
12176
12177
12178
12179
12180
12181
12182
12183
12184
12185
12186
12187
12188
12189
12190
12191
12192
12193
12194
12195
12196
12197
12198
12199
12200
12201
12202
12203
12204
12205
12206
12207
12208
12209
12210
12211
12212
12213
12214
12215
12216
12217
12218
12219
12220
12221
12222
12223
12224
12225
12226
12227
12228
12229
12230
12231
12232
12233
12234
12235
12236
12237
12238
12239
12240
12241
12242
12243
12244
12245
12246
12247
12248
12249
12250
12251
12252
12253
12254
12255
12256
12257
12258
12259
12260
12261
12262
12263
12264
12265
12266
12267
12268
12269
12270
12271
12272
12273
12274
12275
12276
12277
12278
12279
12280
12281
12282
12283
12284
12285
12286
12287
12288
12289
12290
12291
12292
12293
12294
12295
12296
12297
12298
12299
12300
12301
12302
12303
12304
12305
12306
12307
12308
12309
12310
12311
12312
12313
12314
12315
12316
12317
12318
12319
12320
12321
12322
12323
12324
12325
12326
12327
12328
12329
12330
12331
12332
12333
12334
12335
12336
12337
12338
12339
12340
12341
12342
12343
12344
12345
12346
12347
12348
12349
12350
12351
12352
12353
12354
12355
12356
12357
12358
12359
12360
12361
12362
12363
12364
12365
12366
12367
12368
12369
12370
12371
12372
12373
12374
12375
12376
12377
12378
12379
12380
12381
12382
12383
12384
12385
12386
12387
12388
12389
12390
12391
12392
12393
12394
12395
12396
12397
12398
12399
12400
12401
12402
12403
12404
12405
12406
12407
12408
12409
12410
12411
12412
12413
12414
12415
12416
12417
12418
12419
12420
12421
12422
12423
12424
12425
12426
12427
12428
12429
12430
12431
12432
12433
12434
12435
12436
12437
12438
12439
12440
12441
12442
12443
12444
12445
12446
12447
12448
12449
12450
12451
12452
12453
12454
12455
% \iffalse meta-comment
%
% Copyright (C) 2018 Kevin W. Hamlen
%
% This program is free software; you can redistribute it and/or
% modify it under the terms of the GNU General Public License
% as published by the Free Software Foundation; either version 2
% of the License, or (at your option) any later version.
%
% This program is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
% GNU General Public License for more details.
%
% You should have received a copy of the GNU General Public License
% along with this program; if not, write to the Free Software
% Foundation, Inc., 51 Franklin Street, 5th Floor, Boston,
% MA 02110-1301, USA.
%
% The latest version of this program can be obtained from
% http://songs.sourceforge.net.
%
% \fi
%
% \iffalse
%<*driver>
\ProvidesFile{songs.dtx}
%</driver>
%<package>\NeedsTeXFormat{LaTeX2e}
%<package>\ProvidesPackage{songs}
%<*package>
  [2018/09/12 v3.1 Songs package]
%</package>
%
%<*driver>
\documentclass{ltxdoc}

% This documentation compiles as part of the Songs self-installer, so it
% needs to work even on tiny LaTeX installations with few packages.  We
% therefore try to be especially robust to missing package failures.
\newcommand\trypackage[4][]{\IfFileExists{#2.sty}{\usepackage[#1]{#2}#3}{#4}}
\trypackage{microtype}{\linepenalty=20 \parfillskip=0pt plus\textwidth\relax}{}
\trypackage{lmodern}{\usepackage[T1]{fontenc}}{}
\trypackage{ifpdf}{}{\expandafter\newif\csname ifpdf\endcsname\pdffalse}
\trypackage{color}{}{}
\ifpdf
  \trypackage[bookmarks,linkbordercolor={.6 0 0}]{hyperref}{}{}
\fi
\usepackage[nopdfindex]{songs}

% Provide back-up hyperlinking and color macros that do nothing,
% in case the hyperref and/or color packages are absent.
\providecommand\href[2]{#2}
\providecommand\url[1]{#1}
\providecommand\pdfbookmark[3][]{}
\providecommand\hyperdef[3]{}
\providecommand\hyperlink[2]{#2}
\providecommand\texorpdfstring[2]{#1}
\providecommand\definecolor[3]{}
\providecommand\color[1]{}
\providecommand\textcolor[2]{#2}
\providecommand\microtypesetup[1]{}

% Configure the document:
\let\oldSE\StopEventually
\EnableCrossrefs
\CodelineIndex
\RecordChanges
%\OnlyDescription

% Create the \Songs logo, if the musix13 font is available:
\newcommand\Songs{\texorpdfstring{{\sffamily songs}}{songs}}
\newcount\imode
\imode=\interactionmode
\batchmode
\newfont\musicfont{musix13}
\interactionmode=\imode
\ifx\musicfont\nullfont\else
  \newdimen\msize
  \newcommand\wholenote{%
    \msize4ex
    \expandafter\ifx\csname musicfont\the\msize\endcsname\relax
      \expandafter\newfont\csname musicfont\the\msize\endcsname
        {musix13 at \the\msize}%
    \fi
    \kern.13ex
    \raise.5ex\hbox{{\csname musicfont\the\msize\endcsname\symbol9}}%
    \kern1.53ex
  }
  \renewcommand\Songs{\texorpdfstring{{\sffamily s\wholenote ngs}}{songs}}
\fi

% Create the logo for Christopher Rath's Songbook package:
\newcommand{\Rath}{{\sffamily Song$\flat$ook}}

% Colors
\definecolor{myred}{rgb}{0.6,0,0}
\definecolor{myblu}{rgb}{0,0,0.6}
\definecolor{mygra}{gray}{0.33}
\def\PrintDescribeMacro#1{\strut{\MacroFont\color{myred}\string#1}\ }
\let\PrintMacroName\PrintDescribeMacro
\def\PrintDescribeEnv#1{\strut{\MacroFont\color{myred}#1}\ }
\let\PrintEnvName\PrintDescribeEnv
{\makeatletter\gdef\verbatim@font{\normalfont\color{myblu}\ttfamily}}

% For some reason, doc.sty removes the \verbatim@font customization hook
% for \verb|...|.  (Why??)  That's not nice, so we put it back:
{\makeatletter
 \gdef\verb {\relax\ifmmode\hbox\else\leavevmode\null\fi
   \bgroup \let\do\do@noligs \verbatim@nolig@list
   \verbatim@font \verb@eol@error \let\do\@makeother \dospecials
   \@ifstar{\@sverb}{\@vobeyspaces \frenchspacing \@sverb}}
}

% Define some environments to simulate the interior of a verse,
% for showing samples in the documentation:
{\makeatletter
 \gdef\likeverse{%
   \SB@insongtrue\SB@inversetrue
   \SB@loadactives
   \global\SB@ctail\SB@cr@
 }
 \gdef\chordheight{\SB@setbaselineskip}
}

% Typeset a block of LaTeX code:
\newcommand\pfs{\parfillskip0pt plus1fil\relax}
\newenvironment{codeblock}{%
  \medskip
  \begingroup
    \ifdim\parindent=0pt \parindent=20pt\fi
    \indent\vbox\bgroup
      \hsize\linewidth
      \advance\hsize-\parindent
      \rightskip=0pt plus1fil\pfs
      \parindent=0pt
      \color{myblu}%
      \obeylines
}{%
  \egroup\endgroup
  \medskip
}

% Typeset a sample song or scripture quotation:
\songcolumns{0}
\newenvironment{sample}{%
  \medskip
  \noindent\hfil
  \vbox\bgroup
    \hsize.5\hsize
    \advance\hsize-.5\columnsep
    \versesep=5pt
    \pfs
}{%
  \egroup{\pfs\par}\medskip
}

% Typeset a sample lyric book fragment:
\newenvironment{lyrics}{%
  \medskip
  \noindent\hfil
  \vbox\bgroup\begingroup
    \hsize=.7\textwidth
    \leftskip=20pt\rightskip=0pt plus1fil\pfs
    \parindent=-20pt
    \likeverse\obeylines
}{%
  \par\endgroup\egroup
  \hfil{\pfs\par}
  \medskip
}

% Typeset a sample chord book fragment:
\newenvironment{chorded}{%
  \medskip
  \noindent\hfil
  \vbox\bgroup\begingroup
    \hsize=.7\textwidth
    \leftskip=20pt\rightskip=0pt plus1fil\pfs
    \parindent=-20pt
    \likeverse\obeylines
    \versesep=5pt\chordheight
}{%
  \par\endgroup\egroup
  \hfil{\pfs\par}
  \medskip
}

% Typeset a "<code> produces <text>" example:
\newlength\prodlen
\setlength{\prodlen}{2.7in}
\newbox\prodbox
\newcommand{\example}{%
  \medskip\setbox\prodbox\hbox\bgroup\begingroup\color{myblu}%
}
\newcommand{\produces}{%
  \endgroup\egroup
  \indent
  \vbox{\hbox to\prodlen{\unhbox\prodbox\hfil}}
  \ {\it produces}\quad
  \afterassignment\prodprefix
  \setbox\prodbox\hbox
}
\newcommand{\prodprefix}{%
  \likeverse\chordheight
  \aftergroup\prodsuffix
}
\newcommand{\prodsuffix}{\unhbox\prodbox{\pfs\par}\medskip}
\newbox\vcbox
\newdimen\vcadjust
\newcommand{\vcenterbox}[1]{%
  \setbox\vcbox\vbox{\hbox{#1}}%
  \vcadjust=.5\ht\vcbox
  \advance\vcadjust by-6pt
  \lower\vcadjust\box\vcbox
}

% Recode \DescribeMacro and \DescribeEnv to make nice pdfbookmark entries.
% Also create some \MainImpl macros that make pdfbookmarks to help the reader
% find the "real" implementations of important macros.
\newcount\seclevel
\newcommand\mybookmark[2]{%
  \ifnum\value{subsection}=0 \seclevel=2
  \else\ifnum\value{subsubsection}=0 \seclevel=3
  \else\seclevel=4 \fi\fi
  \setcounter{tocdepth}{4}%
  \pdfbookmark[\the\seclevel]{#1}{#2}%
  \setcounter{tocdepth}{3}%
}
{\makeatletter
 \xdef\bschar{\@backslashchar}
 \global\let\For\@for}
\newcommand\DescMacro[1]{%
  \ifhmode\unskip\fi
  \mybookmark{\bschar\bschar#1}{macdef-#1}%
  \expandafter\DescribeMacro\expandafter{\csname#1\endcsname}%
  \hyperdef{macro}{#1}{}\unpenalty
  \ignorespaces
}
\newcommand\DescMacroGroup[3]{%
  \ifhmode\unskip\fi
  \mybookmark{\bschar\bschar#2}{macdef-#1}%
  \expandafter\DescribeMacro\expandafter{\csname#2\endcsname}%
  \For\temp:=#3\do{\hyperdef{macro}{\temp}{}}\unpenalty
  \ignorespaces
}
\newcommand\MainImpl[1]{%
  \pdfbookmark[3]{\bschar\bschar#1}{mimpl-#1}%
}
\newcommand{\DescEnv}[1]{%
  \ifhmode\unskip\fi
  \mybookmark{#1}{envdef-#1}%
  \DescribeEnv{#1}%
  \hyperdef{env}{#1}{}\unpenalty
  \ignorespaces
}
\newcommand{\MainEnvImpl}[1]{%
  \mybookmark{#1}{eimpl-#1}%
}

% Create macros to hyperlink macro and environment names to their
% documentation points.
\newcommand{\mac}[1]{{\tt\hyperlink{macro.#1}{\textcolor{myblu}{\char92 #1}}}}
\newcommand{\env}[1]{{\tt\hyperlink{env.#1}{\textcolor{myblu}{#1}}}}

% Defining bookmarks for definitions of active characters is a little trickier
% because many of these characters have special meanings either to TeX or to
% PDF.  The only reliable way is to insert an "\ooo" escape sequence into the
% bookmark text, where ooo is the ascii number of the character expressed in
% octal.  To achieve this, we use `\string<symbol> to obtain the decimal
% ascii number d of the symbol, then do some math (implemented in \octal)
% to compute and tokenize each octal digit of d into the bookmark text.
\newcount\cnta
\newcount\cntb
\newcommand\ooo{}
\newcommand\octal{%
  \cntb\cnta
  \divide\cnta8
  \multiply\cnta-8
  \advance\cntb\cnta
  \edef\ooo{\the\cntb\ooo}%
  \divide\cnta-8
}
\newcommand{\DescChar}[2]{%
  \ifhmode\unskip\fi
  \expandafter\let\csname string#1\expandafter\endcsname
    \expandafter=\string#2%
  \cnta\expandafter`\string#2%
  \def\ooo{}\octal\octal\octal
  \mybookmark{\bschar\ooo}{#1def}%
  {\def\SpecialUsageIndex##1{}%
   \expandafter\DescribeMacro\string#2}%
  \hyperdef{env}{#1}{}\unpenalty
  \ignorespaces
}
\newcommand{\refchar}[1]{{\tt\hyperlink{env.#1}{\csname string#1\endcsname}}}

% At the end of the implementation section we'll have a code line index of
% macro definitions and usages. To make it look a bit less ragged than the
% default index style and to conserve some space, we'll customize a few of
% the parameters:

\IndexPrologue{%
  \subsection{Codeline Index}%
  Underlined numbers refer to the code line where the corresponding entry
  is defined; other numbers refer to the code lines where the entry
  is used.}

{\makeatletter

 \gdef\IndexParms{%
   \sfcode`,=1750
   \parindent0pt
   \columnsep15pt
   \parskip0pt plus1pt
   \rightskip0pt
   \mathsurround0pt
   \parfillskip0pt
   \small
   \microtypesetup{protrusion=false}%
   \def\@idxitem{\par\hangindent15pt}%
   \def\subitem{\@idxitem\hspace*{15pt}}%
   \def\subsubitem{\@idxitem\hspace*{25pt}}%
   \def\indexspace{\par\vspace{10pt plus 2pt minus 3pt}}}

 \gdef\SpecialMainOptIndex#1{%
   \@bsphack
   \special@index{%
     #1\actualchar{\string\ttfamily\space#1} (option)\encapchar main}%
   \special@index{%
     options:\levelchar
     #1\actualchar{\string\ttfamily\space#1}\encapchar main}%
   \@esphack}
}

% Create a conditional that typesets its first argument if we're including
% the implementation section, otherwise typesets its second argument.
\newcommand\ImplOrDesc[2]{%
  \ifx\StopEventually\oldSE#1\else#2\fi
}

% Hyphenating the word "choruses" looks weird. No "ruses" please!
\hyphenation{choruses white-space}

% An environment for describing the implementation of a package option:
\let\oldsmei\SpecialMainEnvIndex
\newenvironment{option}[1]{%
  \let\SpecialMainEnvIndex\SpecialMainOptIndex
  \begin{environment}{#1}%
    \let\SpecialMainEnvIndex\oldsmei
}{%
  \end{environment}%
  \let\SpecialMainEnvIndex\oldsmei
}

% Describe the default setting for an option:
\newcommand\optdef[1]{\noindent{\it(Default: #1)}\hspace{.5cm}}

% Typeset a chord name:
\newcommand{\chord}[1]{{\sffamily\slshape#1}}

% Here are a few macros to produce nice syntax parameters:
\newcommand\Meta[1]{{\color{mygra}\meta{#1}}}
\newcommand\argp[1]{\Meta{arg#1}}
\newcommand\Metarm[1]{\textrm{\Meta{#1}}}
\newcommand\OR{\,$\mid$\,}
\newcommand\SPC{\char`\ }

% Now let's quell those annoying "Marginpar has moved" warning messages.
{\makeatletter
 \global\let\oldamp=\@addmarginpar
 \global\let\oldlwnl=\@latex@warning@no@line
 \gdef\@addmarginpar{%
   \let\@latex@warning@no@line\@gobble
   \oldamp
   \let\@latex@warning@no@line\oldlwnl
 }
}

% The \eat macro just gobbles its argument. I use it to appease my syntax
% highlighter when it gets confused.
\newcommand{\eat}[1]{}

\begin{document}
  \DocInput{songs.dtx}
\end{document}
%</driver>
% \fi
%
% \CheckSum{8935}
%
% \CharacterTable
%  {Upper-case    \A\B\C\D\E\F\G\H\I\J\K\L\M\N\O\P\Q\R\S\T\U\V\W\X\Y\Z
%   Lower-case    \a\b\c\d\e\f\g\h\i\j\k\l\m\n\o\p\q\r\s\t\u\v\w\x\y\z
%   Digits        \0\1\2\3\4\5\6\7\8\9
%   Exclamation   \!     Double quote  \"     Hash (number) \#
%   Dollar        \$     Percent       \%     Ampersand     \&
%   Acute accent  \'     Left paren    \(     Right paren   \)
%   Asterisk      \*     Plus          \+     Comma         \,
%   Minus         \-     Point         \.     Solidus       \/
%   Colon         \:     Semicolon     \;     Less than     \<
%   Equals        \=     Greater than  \>     Question mark \?
%   Commercial at \@     Left bracket  \[     Backslash     \\
%   Right bracket \]     Circumflex    \^     Underscore    \_
%   Grave accent  \`     Left brace    \{     Vertical bar  \|
%   Right brace   \}     Tilde         \~}
%
% \changes{v1.0}{2001/12/01}{Initial version}
% \changes{v1.1}{2005/04/03}{Change log introduced and first release of this documentation}
% \changes{v1.17}{2005/09/24}{Transformed the source from a class to a package}
% \changes{v1.18}{2005/09/29}{Verse numbering added}
% \changes{v2.0}{2007/06/20}{Keyval syntax and chord-replay system added}
%
% \iffalse
% Here we list all the macros that should not be indexed because they are:
% (a) too common and therefore the index would be too large if we listed them,
% (b) not useful in an index because they are predefined TeX macros, or
% (c) not really macros but rather control sequence names given to \string.
% \fi
% \DoNotIndex{\@M,\@depth,\@empty,\@firstofone,\@firstoftwo,\@gobble,\@gobbletwo,\@height,\@m,\@minus,\@ne,\@plus,\@secondoftwo,\@width,\m@ne,\p@,\thr@@,\tw@,\voidb@x,\@xpt,\z@,\z@skip}
% \DoNotIndex{\advance,\char,\count,\divide,\font,\fontdimen,\maxdimen,\multiply,\setcounter,\setlength,\settoheight,\settowidth,\stepcounter}
% \DoNotIndex{\begin,\begingroup,\bgroup,\egroup,\end,\endgroup}
% \DoNotIndex{\box,\copy,\dp,\hbox,\ht,\leavevmode,\lower,\null,\prevdepth,\raise,\rlap,\setbox,\unhbox,\unhcopy,\unpenalty,\unskip,\unvbox,\unvcopy,\vbox,\vtop,\wd}
% \DoNotIndex{\csname,\def,\edef,\endcsname,\futurelet,\gdef,\global,\let,\long,\mathchardef,\newcommand,\renewcommand,\renewenvironment,\xdef}
% \DoNotIndex{\@ifundefined,\@for,\do,\else,\fi,\ifcase,\ifcat,\ifdim,\iffalse,\ifhmode,\ifmmode,\ifinner,\ifnum,\ifodd,\ifvbox,\ifvmode,\ifvoid,\ifx,\loop,\or,\repeat,\undefined}
% \DoNotIndex{\afterassignment,\aftergroup,\expandafter,\ignorespaces,\immediate,\noexpand,\protect,\relax,\space,\string,\the}
% \DoNotIndex{\hfil,\hfilneg,\hskip,\hss,\indent,\kern,\nobreak,\noindent,\nointerlineskip,\offinterlineskip,\par,\penalty,\strut,\thinspace,\vadjust,\vfil,\vfilneg,\vphantom,\vskip}
% \DoNotIndex{\@octets,\four,\three,\two,\UTFviii@,\UTFviii@zero@octets,\0,\1,\2,\3,\4,\5,\6,\7,\8,\9,\X,\O}
%
% \GetFileInfo{songs.dtx}
%
% \title{The \Songs{} package\thanks{This manual documents
%    \textsf{songs}~\fileversion, dated~\filedate,
%    \copyright~2018 Kevin W.~Hamlen, and
%    distributed under version~2 the GNU General Public License
%    as published by the Free Software Foundation.}}
% \author{Kevin W. Hamlen}
%
% \maketitle
%
% \begin{abstract}
% The \Songs{} package produces songbooks that contain lyrics and chords
% (but not full sheet music).
% It allows lyric books, chord books, overhead slides, and digital projector
% slides to all be maintained and generated from a single \LaTeX{} source
% document.
% Automatic transposition, guitar tablature diagrams, handouts, and
% a variety of specialized song indexes are supported.
% \end{abstract}
%
% \section{Introduction}
%
% The \Songs{} \LaTeX{} package produces books of songs that contain lyrics and
% (optionally) chords.
% A single source document yields a lyric book for singers, a chord book for
% musicians, and overhead or digital projector slides for corporate singing.
%
% The software is especially well suited for churches and religious
% fellowships desiring to create their own books of worship songs.
% Rather than purchasing a fixed hymnal of songs, the \Songs{} package allows
% worship coordinators to maintain a constantly evolving repertoire of music
% to which they can add and remove songs over time.
% As the book content changes, the indexes, spacing, and other formatting
% details automatically adjust to stay consistent.
% Songs can also be quickly selected and arranged for specific events or
% services through the use of scripture indexes, automatic transposition,
% and handout and slide set creation features.
%
% \section{Terms of Use}
%
% \noindent
% The \Songs{} package is free software; you can redistribute it and/or
% modify it under the terms of the GNU General Public License
% as published by the Free Software Foundation; either version~2
% of the License, or (at your option) any later version.
% A copy of the license can be found in \S\ref{sec:license}.
%
% \medskip
%
% \noindent
% This program is distributed in the hope that it will be useful,
% but {\sc without any warranty}; without even the implied warranty of
% {\sc merchantability} or {\sc fitness for a particular purpose}. See the
% GNU General Public License in \S\ref{sec:license} for details.
% A copy of the license can also be obtained by writing to the
% Free Software Foundation, Inc., 51 Franklin Street, 5th Floor,
% Boston, MA 02110-1301, USA.
%
% \medskip
%
% \noindent
% This software is copyright \copyright~2018 Kevin W.~Hamlen.
% For contact information or the latest version, see the project webpage at:
%
% \vskip1.5ex
% \begingroup\centering\noindent
% \href{http://songs.sourceforge.net}{{\tt http://songs.sourceforge.net}}\par
% \endgroup
%
% \section{Sample Document}
%
% For those who would like to start making song books quickly, the
% following is a sample document that yields a simple song book with
% one song.
% Starting from this template, you can begin to add songs and customizations
% to create a larger book.
% Instructions for compiling this sample song book follow the listing.
%
% \begingroup\color{myblu}
% \begin{verbatim}
% \documentclass{article}
% \usepackage[chorded]{songs}
%
% \noversenumbers
%
% \begin{document}
%
% \songsection{Worship Songs}
%
% \begin{songs}{}
% \beginsong{Doxology}[by={Louis Bourgeois and Thomas Ken},
%                      sr={Revelation 5:13},
%                      cr={Public domain.}]
% \beginverse
% \[G]Praise God, \[D]from \[Em]Whom \[Bm]all \[Em]bless\[D]ings \[G]flow;
% \[G]Praise Him, all \[D]crea\[Em]tures \[C]here \[G]be\[D]low;
% \[Em]Praise \[D]Him \[G]a\[D]bove, \[G]ye \[C]heav'n\[D]ly \[Em]host;
% \[G]Praise Fa\[Em]ther, \[D]Son, \[Am]and \[G/B G/C]Ho\[D]ly \[G]Ghost.
% \[C]A\[G]men.
% \endverse
% \endsong
% \end{songs}
%
% \end{document}
% \end{verbatim}
% \endgroup\nointerlineskip\vskip-6pt plus0pt minus0pt
%
% To compile this book, run \LaTeX{} (|pdflatex| is recommended):
%
% \begin{codeblock}
% |pdflatex mybook.tex|
% \end{codeblock}
%
% \noindent
% (where |mybook.tex| is the name of the source document above).
% The final document is named |mybook.pdf| if you use |pdflatex| or
% |mybook.dvi| if you use regular |latex|.
%
% Note that compiling a document that includes indexes requires extra steps.
% See \S\ref{sec:compiling} for details.
%
% \begin{figure}
% \noindent\vbox{\begingroup\hsize=352pt
%   \versesep=12pt\columnsep=7pt\parindent=20pt
%   \def\colbotglue{0pt}\def\lastcolglue{0pt}
%   \baselineadj=-1pt\relax
%   \noversenumbers
%   \setlength\textwidth{352pt}
%   \setlength\textheight{498pt}
%   \songcolumns{2}
%   \vskip-3.5ex plus-1ex minus-.2ex
%   \nointerlineskip\null\nointerlineskip
%   \songsection*{Worship Songs}
%   \begin{songs}{}
%   \beginsong{Doxology}[
%      by={Louis Bourgeois and Thomas Ken},
%      sr={Revelation 5:13},
%      cr={Public domain.}]
%   \beginverse
%   \[G]Praise God, \[D]from \[Em]Whom \[Bm]all \[Em]bless\[D]ings \[G]flow;
%   \[G]Praise Him, all \[D]crea\[Em]tures \[C]here \[G]be\[D]low;
%   \[Em]Praise \[D]Him \[G]a\[D]bove, \[G]ye \[C]heav'n\[D]ly \[Em]host;
%   \[G]Praise Fa\[Em]ther, \[D]Son, \[Am]and \[G/B G/C]Ho\[D]ly \[G]Ghost.
%   \[C]A\[G]men.
%   \endverse
%   \endsong\eat\]
%   \parindent=15pt
%   \beginscripture{Psalm 18:2-6}
%   \Acolon The LORD is my rock and my fortress and my deliverer,
%   \Bcolon my God, my rock, in whom I take refuge,
%   \Bcolon my shield, and the horn of my salvation, my stronghold.
%   \Acolon I call upon the LORD, who is worthy to be praised,
%   \Bcolon and I am saved from my enemies.
%   \strophe
%   \Acolon The cords of death encompassed me;
%   \Bcolon the torrents of destruction assailed me;
%   \Acolon the cords of Sheol entangled me;
%   \Bcolon the snares of death confronted me.
%   \strophe
%   \Acolon In my distress I called upon the LORD;
%   \Bcolon to my God I cried for help.
%   \Acolon From his temple he heard my voice,
%   \Bcolon and my cry to him reached his ears.
%   \endscripture
%   \parindent=20pt
%   \beginsong{A Mighty Fortress Is Our God}[
%     by={Martin Luther},
%     cr={Public Domain.}]
%   \beginverse
%   A \[A]mighty \[C#m]Fortress \[B7]is our \[E]God,
%   A \[D]bulwark \[A]never \[E7]fail\[A]ing.
%   Our helper \[C#m]He, a\[B7]mid the \[E]flood
%   Of \[D]mortal \[A]ills pre\[E7]vail\[A]ing.
%   For still our \[B7sus4]an\[B7]cient \[E]foe
%   Doth \[A]seek to \[E/G#]work us \[F#m]woe;
%   His craft and \[B7]pow'r are \[E]great,
%   And, \[Bm]armed with cruel \[C#]hate,
%   On \[D]earth is \[A]not his \[E7]e\[A]qual.
%   \endverse
%   \beginverse
%   Did ^we in ^our own ^strength con^fide,
%   Our ^striving ^would be ^los^ing.
%   Were not the ^right Man ^on our ^side,
%   The ^Man of ^God's own ^choos^ing.
%   Dost ask who ^that ^may ^be?
%   Christ ^Jesus, ^it is ^He;
%   Lord Saba^oth His ^Name,
%   From ^age to age the ^same;
%   And ^He must ^win the ^bat^tle.
%   \endverse
%   \endsong\eat\]
%   \end{songs}
% \endgroup}\par
% \caption{Sample page from a chord book}\label{fig:sample}
% \end{figure}
% A copy of the first page of a sample song section is shown in
% Figure~\ref{fig:sample}.
% The page shown in that figure is from a chorded version of the book.
% When generating a lyric version, the chords are omitted.
% See \S\ref{sec:options} for information on how to generate different
% versions of the same book.
%
% \section{Initialization and Options}\label{sec:options}
%
% Each \LaTeX{} document that uses the \Songs{} package should contain a
% line like the following near the top of the document:
%
% \begin{codeblock}
% |\usepackage[|\Meta{options}|]{songs}|
% \end{codeblock}
%
% \noindent
% Supported \Meta{options} include the following:
%
% \paragraph{Output Type.}
% \DescEnv{lyric}
% \DescEnv{chorded}
% \DescEnv{slides}
% \DescEnv{rawtext}
% The \Songs{} package can produce four kinds of books: lyric books, chord
% books, books of overhead slides, and raw text output.
% You can specify which kind of book is to be produced by specifying one of
% |lyric|, |chorded|, |slides|, or |rawtext| as an option.
% The |slides| and |chorded| options can be used together to create chorded
% slides.
% If no output options are specified, |chorded| is the default.
%
% Lyric books omit all chords, whereas chord books include chords and
% additional information for musicians (specified using \mac{musicnote}).
% Books of overhead slides typeset one song per page in a large font, centered.
%
% Raw text output yields an ascii text file named \Meta{jobname}|.txt|
% (where \Meta{jobname} is the root filename) containing lyrics without chords.
% This can be useful for importing song books into another program, such as a
% spell-checker.
%
% \DescMacro{chordson}
% \DescMacro{chordsoff}
% Chords can be turned on or off in the middle of the document
% by using the |\chordson| or |\chordsoff| macros.
%
% \DescMacro{slides}
% Slides mode can be activated in the middle of the document by using the
% |\slides| macro.
% For best results, this should typically only be done in the document
% preamble or at the beginning of a fresh page.
%
% \paragraph{Measure Bars.}
% \DescEnv{nomeasures}
% \DescEnv{showmeasures}
% \DescMacro{measureson}
% \DescMacro{measuresoff}
% The \Songs{} package includes a facility for placing measure bars in chord
% books (see \S\ref{sec:measures}).
% To omit these measure bars, use the |nomeasures| option;
% to display them, use the |showmeasures| option (the default).
% Measure bars can also be turned on or off in the middle of the document by
% using the |\measureson| or |\measuresoff| macros.
%
% \paragraph{Transposition.}
% \DescEnv{transposecapos}
% The |transposecapos| option changes the effect of the \mac{capo} macro.
% Normally, using |\capo{|\Meta{n}|}| within a song environment produces a
% textual note in chord books that suggests the use of a guitar capo on fret
% \Meta{n}.
% However, when the |transposecapos| option is active, these textual notes
% are omitted and instead the effect of |\capo{|\Meta{n}|}| is the
% same as for \mac{transpose}|{|\Meta{n}|}|.
% That is, chords between the \mac{capo} macro and the end of the song are
% automatically transposed up by \Meta{n} half-steps.
% This can be useful for adapting a chord book for guitarists to one that can
% be used by pianists, who don't have the luxury of capos.
% See \S\ref{sec:notes} and \S\ref{sec:transpose} for more information on the
% \mac{capo} and \mac{transpose} macros.
% 
% \paragraph{Indexes.}
% \DescEnv{noindexes}
% \DescMacro{indexeson}
% \DescMacro{indexesoff}
% The |noindexes| option suppresses the typesetting of any in-document indexes.
% Display of indexes can also be turned on or off using the |\indexeson| and
% |\indexesoff| macros.
%
% \DescEnv{nopdfindex}
% PDF bookmark entries and hyperlinks can be suppressed with the |nopdfindex|
% option.
% For finer control of PDF indexes, see \S\ref{sec:idxcust}.
%
% \paragraph{Scripture Quotations.}
% \DescEnv{noscripture}
% \DescMacro{scriptureon}
% \DescMacro{scriptureoff}
% The |noscripture| option omits scripture quotations (see
% \S\ref{sec:scripture}) from the output.
% You can also turn scripture quotations on or off in the middle of the
% document by using |\scriptureon| or |\scriptureoff|, respectively.
%
% \paragraph{Shaded Boxes.}
% \DescEnv{noshading}
% The |noshading| option causes all shaded boxes, such as those that surround
% song numbers and textual notes, to be omitted.
% You might want to use this option if printing such shaded boxes causes
% problems for your printer or uses too much ink.
%
% \paragraph{Partial Song Sets.}
% \DescMacro{includeonlysongs}
% Often it is useful to be able to extract a subset of songs from the master
% document---e.g.~to create a handout or set of overhead slides for a specific
% worship service.
% To do this, you can type |\includeonlysongs{|\Meta{songlist}|}| in the
% document preamble (i.e., before the |\begin{document}| line), where
% \Meta{songlist} is a comma-separated list of the song numbers to include.
% For example, 
%
% \begin{codeblock}
% |\includeonlysongs{37,50,2}|
% \end{codeblock}
%
% \noindent
% creates a document consisting only of songs 37, 50, and 2, in that order.
%
% Partial books generated with |\includeonlysongs| omit all scripture
% quotations (\S\ref{sec:scripture}), and ignore uses of
% \mac{nextcol}, \mac{brk}, \mac{sclearpage}, and \mac{scleardpage}
% between songs unless they are followed by a star (e.g., \mac{nextcol}|*|).
% To force a column- or page-break at a specific point in a partial book,
% add the word |nextcol|, |brk|, |sclearpage|, or |scleardpage| at the
% corresponding point in the \Meta{songlist}.
%
% The |\includeonlysongs| macro only reorders songs within each
% \env{songs} environment (see \S\ref{sec:songs}), not between different
% \env{songs} environments.
% It also cannot be used in conjunction with the \env{rawtext} option.
%
% \section{Songs}\label{sec:songs}
%
% \subsection{Beginning a Song}
%
% \paragraph{Song Sets.}
% \DescEnv{songs}
% Songs are contained within |songs| environments.
% Each |songs| environment begins and ends with:
%
% \begin{codeblock}
% |\begin{songs}{|\Meta{indexes}|}|
% $\vdots$
% |\end{songs}|
% \end{codeblock}
%
% \noindent
% \Meta{indexes} is a comma-separated list of index \Meta{id}'s
% (see \S\ref{sec:indexes})---one identifier for each index that is to
% include songs in this song set.
% Between the |\begin{songs}| and |\end{songs}| lines of
% a song section only songs (see below) or inter-song environments
% (see \S\ref{sec:between}) may appear.
% No text in a |songs| environment may appear outside of these environments.
%
% \paragraph{Songs.}
% \DescMacro{beginsong}
% \DescMacro{endsong}
% A song begins and ends with:
%
% \begin{codeblock}
% |\beginsong{|\Meta{titles}|}[|\Meta{otherinfo}|]|
% $\vdots$
% |\endsong|
% \end{codeblock}
%
% \noindent
% Songs should appear only within \env{songs} environments (see above)
% unless you are supplying your own page-builder (see \S\ref{sec:layout}).
%
% In the \mac{beginsong} line, \Meta{titles} is one or more song titles
% separated by |\\|.
% If multiple titles are provided, the first is typeset normally
% atop the song and the rest are each typeset in parentheses on
% separate lines.
%
% The |[|\Meta{otherinfo}|]| part is an optional comma-separated list of
% key-value pairs (keyvals) of the form \Meta{key}|=|\Meta{value}.
% The possible keys and their values are:
%
% \medskip
% \noindent\hfil\vbox{\halign{#\hfil&\kern2em{\it#}\hfil\cr
%   |by={|\Meta{authors}|}|&authors, composers, and other contributors\cr
%   |cr={|\Meta{copyright}|}|&copyright information\cr
%   |li={|\Meta{license}|}|&licensing information\cr
%   |sr={|\Meta{refs}|}|&related scripture references\cr
%   |index={|\Meta{lyrics}|}|&an extra index entry for a line of lyrics\cr
%   |ititle={|\Meta{title}|}|&an extra index entry for a hidden title\cr}}
% {\pfs\par}\medskip
%
% \noindent
% For example, a song that begins and ends with
%
% \begin{codeblock}
% |\beginsong{Title1 \\ Title2}[by={Joe Smith}, sr={Job 3},|
% |  cr={\copyright~|\unskip\expandafter|\the\year|| XYZ.}, li={Used with permission.}]|
% |\endsong|
% \end{codeblock}
%
% \noindent looks like
%
% \begin{sample}
%  \setcounter{songnum}{1}%
%  \vskip1pt%
%  \beginsong{Title1 \\ Title2}[by={Joe Smith}, sr={Job 3},
%     cr={\copyright~\the\year{} XYZ.}, li={Used with permission.}]
%  \endsong
% \end{sample}
%
% The four keyvals used in the above example are described in detail in the
% remainder of this section;
% the final two are documented in \S\ref{sec:ientry}.
% You can also create your own keyvals (see \S\ref{sec:newkey}).
%
% \paragraph{Song Authors.}
% \DescEnv{by=}
% The |by={|\Meta{authors}|}| keyval lists one or more authors,
% composers, translators, etc.
% An entry is added to each author index associated with the current
% \env{songs} environment for each contributor listed.
% Contributors are expected to be separated by commas, semicolons, or the
% word |and|.
% For example:
%
% \begin{codeblock}
% |by={Fred Smith, John Doe, and Billy Bob}|
% \end{codeblock}
%
% \noindent
% Words separated by a macro-space (\verb*@\ @\eat*) or tie (|~|)
% instead of a regular space are treated as single words by the indexer.
% For example, \verb*@The Vienna Boys' Choir@\eat* is indexed as
% ``Choir, The Vienna Boys'\thinspace'' but
% \verb*@The Vienna\ Boys'\ Choir@\eat* is indexed as
% ``Vienna Boys' Choir, The''.
%
% \paragraph{Copyright Info.}
% \DescEnv{cr=}
% The |cr={|\Meta{copyright}|}| keyval specifies the copyright-holder of the
% song, if any.
% For example:
%
% \begin{codeblock}
% |cr={\copyright~2000 ABC Songs, Inc.}|
% \end{codeblock}
%
% \noindent
% Copyright information is typeset in fine print at the bottom of the song.
%
% \paragraph{Licensing Info.}
% \DescEnv{li=}
% \DescMacro{setlicense}
% Licensing information is provided by |li={|\Meta{license}|}|, where
% \Meta{license} is any text.
% Licensing information is displayed in fine print under the song just
% after the copyright information (if any).
% Alternatively, writing |\setlicense{|\Meta{license}|}| anywhere between
% the \mac{beginsong} and \mac{endsong} lines is equivalent to using
% |li={|\Meta{license}|}| in the \mac{beginsong} line.
%
% When many songs in a book are covered by a common license, it is
% usually convenient to create a macro to abbreviate the licensing
% information.
% For example, if your organization has a music license from Christian
% Copyright Licensing International with license number 1234567, you might
% define a macro like
%
% \begin{codeblock}
% |\newcommand{\CCLI}{(CCLI \#1234567)}|
% \end{codeblock}
%
% \noindent
% Then you could write |li=\CCLI| in the \mac{beginsong} line of each song
% covered by CCLI.
%
% \paragraph{Scripture References.}
% \DescEnv{sr=}
% The \Songs{} package has extensive support for scripture citations and
% indexes of scripture citations.
% To cite scripture references for the song, use the keyval
% |sr={|\Meta{refs}|}|, where \Meta{refs} is a list of scripture
% references.
% Index entries are added to all scripture indexes associated
% with the current \env{songs} environment for each such reference.
% The |songidx| index generation script (see \S\ref{sec:compiling}) expects
% \Meta{refs} to be a list of references in which semicolons are used to
% separate references to different books, and commas are used to separate
% references to to different chapters and verses within the same book.
% For example, one valid scripture citation is
%
% \begin{codeblock}
% |sr={John 3:16,17, 4:1-5; Jude 3}|
% \end{codeblock}
%
% The full formal syntax of a valid \Meta{refs} argument is given in
% Figure~\ref{fig:srsyntax}.
% \begin{figure}
% \noindent\hfil\vbox{\advance\baselineskip2pt
% \halign{\hfil{\tt#}\,$\longrightarrow$\,&{\tt#}\hfil\cr
%   \Metarm{refs}&\Metarm{nothing}\OR\Metarm{ref};\SPC\Metarm{ref};$\ldots$;\SPC\Metarm{ref}\cr
%   \Metarm{ref}&\Metarm{many-chptr-book}\SPC\Metarm{chapters}\OR\Metarm{one-chptr-book}\SPC\Metarm{verses}\cr
%   \Metarm{many-chptr-book}&Genesis\OR Exodus\OR Leviticus\OR Numbers\OR $\ldots$\cr
%   \Metarm{one-chptr-book}&Obadiah\OR Philemon\OR 2 John\OR 3 John\OR Jude\cr
%   \Metarm{chapters}&\Metarm{chref},\SPC\Metarm{chref},$\ldots$,\SPC\Metarm{chref}\cr
%   \Metarm{chref}&\Metarm{chapter}\OR\Metarm{chapter}-\Metarm{chapter}\OR\Metarm{chapter}:\Metarm{verses}\OR\cr
%   \omit&\quad\Metarm{chapter}:\Metarm{verse}-\Metarm{chapter}:\Metarm{verse}\cr
%   \Metarm{verses}&\Metarm{vref},\Metarm{vref},$\ldots$,\Metarm{vref}\cr
%   \Metarm{vref}&\Metarm{verse}\OR\Metarm{verse}-\Metarm{verse}\cr}}
% \caption{Formal syntax rules for song scripture references}\label{fig:srsyntax}
% \end{figure}
% In those syntax rules, \Meta{chapter} and \Meta{verse} stand for arabic
% numbers denoting a valid chapter number for the given book, and a valid
% verse number for the given chapter, respectively.
% Note that when referencing a book that has only one chapter,
% one should list only its verses after the book name
% (rather than |1:|\Meta{verses}).
%
% \subsection{Verses and Choruses}
%
% \paragraph{Starting A Verse Or Chorus.}
% \DescMacro{beginverse}
% \DescMacro{endverse}
% \DescMacro{beginchorus}
% \DescMacro{endchorus}
% Between the \mac{beginsong} and \mac{endsong} lines of a song can
% appear any number of verses and choruses.
% A verse begins and ends with:
%
% \begin{codeblock}
% |\beginverse|
% $\vdots$
% |\endverse|
% \end{codeblock}
%
% \noindent and a chorus begins and ends with:
%
% \begin{codeblock}
% |\beginchorus|
% $\vdots$
% |\endchorus|
% \end{codeblock}
%
% \noindent
% Verses are numbered (unless \mac{noversenumbers} has been used to
% suppress verse numbering) whereas choruses have a vertical line placed to
% their left.
%
% To create an unnumbered verse, begin the verse with |\beginverse*| instead.
% This can be used for things that aren't really verses but should be
% typeset like a verse (e.g.~intros, endings, and the like).
% A verse that starts with |\beginverse*| should still end with |\endverse|
% (not |\endverse*|).
%
% Within a verse or chorus you should enter one line of text for
% each line of lyrics.
% Each line of the source document produces a separate line in the resulting
% document (like \LaTeX's |\obeylines| macro).
% Lines that are too long to fit are wrapped with hanging indentation
% of width |\parindent|.
%
% \subsection{Chords}\label{sec:chords}
%
% \DescMacro{[}
% \DescChar{hash}{#}
% \DescChar{amp}{&}
% Between the \mac{beginverse} and \mac{endverse} lines, or between
% the \mac{beginchorus} and \mac{endchorus} lines,
% chords can be produced using the macro |\[|\Meta{chordname}|]|\eat\].
% Chords only appear in chord books; they are omitted from lyric books.
% The \Meta{chordname} may consist of arbitrary text.
% To produce sharp and flat symbols, use |#| and |&| respectively.
%
% Any text that immediately follows the |\[]|\eat\] macro with no
% intervening whitespace is assumed to be the word or syllable
% that is to be sung as the chord is struck, and is therefore
% typeset directly under the chord.
% For example:
%
% \example|\[E&]peace and \[Am]joy|\produces{\[E&]peace and \[Am]joy}
% \eat\]
%
% \noindent
% If whitespace (a space or \Meta{return}) immediately follows,
% then the chord name be typeset without any lyric text
% below it, indicating that the chord is to be struck between
% any surrounding words.
% For example:
%
% \example|\[E&]peace and \[Am] joy|\produces{\[E&]peace and \[Am] joy}
% \eat\]
%
% If the lyric text that immediately follows the chord contains
% another chord, and if the width of the chord name exceeds the
% width of the lyric text, then hyphenation is added automatically.
% For example:
%
% \example|\[F#sus4]e\[A]ternal|\produces{\[F#sus4]e\[A]ternal}
% \eat\]
%
% Sequences of chords that sit above a single word can be written
% back-to-back with no intervening space, or as a single chord:
%
% \example|\[A]\[B]\[Em]joy|\produces{\[A]\[B]\[Em]joy}
% \example|\[A B Em]joy|\produces{\[A B Em]joy}
% \eat\]
%
% \noindent
% The only difference between the two examples above is that the chords
% in the first example can later be replayed separately (see
% \S\ref{sec:replay}) whereas the chords in the second example can only be
% replayed as a group.
%
% You can explicitly dictate how much of the text following a
% chord macro is to appear under the chord name by using braces.
% To exclude text that would normally be drawn under the chord,
% use a pair of braces that includes the chord macro.
% For example:
%
% \example|{\[G A]e}ternal|\produces{{\[G A]e}ternal}
% \eat\]
%
% \noindent
% (Without the braces, the syllables ``ternal'' would not be
% pushed out away from the chord.)
% This might be used to indicate that the chord transition occurs
% on the first syllable rather than as the second syllable is
% sung.
%
% Contrastingly, braces that do not include the chord itself can
% be used to include text under a chord that would otherwise be
% excluded.
% For example:
%
% \example|\[Gmaj7sus4]{th' eternal}|\produces{\[Gmaj7sus4]{th' eternal}}
% \eat\]
%
% \noindent
% Without the braces, the word ``eternal'' would be pushed out away
% from the chord so that the chord would appear only over
% the partial word ``th'\thinspace''.
%
% \paragraph{Chords Without Lyrics.}
% \DescMacro{nolyrics}
% Sometimes you may want to write a line of chords with no lyrics in it at all,
% such as for an instrumental intro or solo.
% To make the chords in such a line sit on the baseline instead of raised above
% it, use the |\nolyrics| macro.
% For example:
%
% \example|{\nolyrics Intro: \[G] \[A] \[D]}|\produces{\nolyrics Intro: \[G] \[A] \[D]}
% \eat\]
%
% \noindent
% Note the enclosing braces that determine how long the effect should last.
% Multiple lines can be included in the braces.
% Instrumental solos should typically not appear in lyric books, so such
% lines should usually also be surrounded by \mac{ifchorded} and |\fi|
% (see \S\ref{sec:conditionals}).
%
% \paragraph{Symbols Under Chords.}
% \DescMacro{DeclareLyricChar}
% If you are typesetting songs in a language whose alphabet contains symbols
% that \LaTeX{} treats as punctuation, you can use the |\DeclareLyricChar|
% macro to instruct the \Songs{} package to treat the symbol as
% non-chord-ending, so that it is included under chords by default just
% like an alphabetic character.
%
% \begin{codeblock}
% |\DeclareLyricChar{|\Meta{token}|}|
% \end{codeblock}
%
% \noindent
% Here, \Meta{token} must be a single \TeX{} macro control sequence,
% active character, letter (something \TeX{} assigns catcode 11), or
% punctuation symbol (something \TeX{} assigns catcode 12).
% For example, by default,
%
% \example|\[Fmaj7]s\dag range|\produces{\[Fmaj7]s\dag range}
% \eat\]
%
% \noindent
% because |\dag| is not recognized as an alphabetic symbol;
% but if you first type,
%
% \begin{codeblock}
% |\DeclareLyricChar{\dag}|
% \end{codeblock}
%
% \noindent
% then instead you will get:
%
% \DeclareLyricChar{\dag}
% \example|\[Fmaj7]s\dag range|\produces{\[Fmaj7]s\dag range}
% \eat\]
%
% \noindent
% \DescMacro{DeclareNonLyric}
% Likewise, you can type
%
% \begin{codeblock}
% |\DeclareNonLyric{|\Meta{token}|}|
% \end{codeblock}
%
% \noindent
% to reverse the above effect and force a token to be lyric-ending.
% Such tokens are pushed out away from long chord names so that they
% never fall under a chord, and hyphenation is added to the resulting gap.
%
% \DescMacro{DeclareNoHyphen}
% To declare a token to be lyric-ending but without the added hyphenation,
% use |\DeclareNoHyphen{|\Meta{token}|}| instead.
% Such tokens are pushed out away from long chord names so that they never
% fall under the chord, but hyphenation is not added to the resulting gap.
%
% \paragraph{Extending Chords Over Adjacent Words.}
% \DescMacro{MultiwordChords}
% The |\MultiwordChords| macro forces multiple words to be squeezed under one
% chord by default.
% Normally a long chord atop a short lyric pushes subsequent
% lyrics away to make room for the chord:
%
% \example|\[Gmaj7sus4]my life|\produces{\[Gmaj7sus4]my life}
% \eat\]
%
% \noindent
% But if you first type |\MultiwordChords|, then instead you get the more
% compact:
%
% \begingroup\MultiwordChords
% \example|\[Gmaj7sus4]my life|\produces{\[Gmaj7sus4]my life}
% \eat\]
% \endgroup
%
% \noindent
% Authors should exercise caution when using |\MultiwordChords| because
% including many words under a single chord can often produce output that
% is ambiguous or misleading to musicians.
% For example,
%
% \begingroup\MultiwordChords
% \example|\[F G Am]me free|\produces{\[F G Am]me free}\par
% \eat\]
% \endgroup
%
% \noindent
% This might be misleading to musicians if all three chords are intended
% to be played while singing the word ``me.''
% Liberal use of braces is therefore required to make |\MultiwordChords|
% produce good results, which is why it isn't the default.
%
% \paragraph{Accidentals Outside Chords.}
% \DescMacro{shrp}
% \DescMacro{flt}
% Sharp and flat symbols can be produced with |#| and |&| when they appear
% in chord macros, but if you wish to produce those symbols in
% other parts of the document, you must use the |\shrp| and |\flt| macros.
% For example, to define a macro that produces a \chord{C\shrp} chord, use:
%
% \begin{codeblock}
% |\newcommand{\Csharp}{C\shrp}|
% \end{codeblock}
%
% \subsection{Replaying Chords and Choruses}\label{sec:replay}
%
% \DescChar{hat}{^}
% Many songs consist of multiple verses that use the same chords.
% The \Songs{} package simplifies this common case by providing a means to
% replay the chord sequence of a previous verse without having to retype
% all the chords.
% To replay a chord from a previous verse, type a hat symbol (|^|) anywhere
% you would otherwise use a chord macro (|\[]|\eat\]).
% For example,
%
% \begin{codeblock}
% \mac{beginverse}
% |\[G]This is the \[C]first \[G]verse.|\eat\]
% \mac{endverse}
% \mac{beginverse}
% |The ^second verse ^ has the same ^chords.|
% \mac{endverse}
% \end{codeblock}
%
% \noindent produces
%
% \begin{chorded}\memorize
%   \[G]This is the \[C]first \[G]verse.\eat\]
% \end{chorded}
% \begin{chorded}
%   The ^second verse ^ has the same ^chords.
% \end{chorded}
%
% Normal chords can appear amidst replayed chords without disrupting the
% sequence of chords being replayed.
% Thus, a third verse could say,
%
% \begin{codeblock}
% \mac{beginverse}
% |The ^third verse ^has a \[Cm]new ^chord.|\eat\]
% \mac{endverse}
% \end{codeblock}
%
% \noindent to produce
%
% \begin{chorded}
%   The ^third verse ^has a \[Cm]new ^chord.\eat\]
% \end{chorded}
%
% Replaying can be used in combination with automatic transposition to produce
% modulated verses.
% See \S\ref{sec:transpose} for an example.
%
% \DescMacro{memorize}
% By default, chords are replayed from the current song's first verse, but
% you can replay the chords of a different verse or chorus by saying
% |\memorize| at the beginning of any verse or chorus whose chords you want
% to later replay.
% Subsequent verses or choruses that use \refchar{hat} replay chords
% from the most recently memorized verse or chorus.
%
% \paragraph{Selective Memorization.}
% It is also possible to inject unmemorized chords into a memorized verse
% so that they are not later replayed.
% To suppress memorization of a chord, begin the chord's name with a hat
% symbol.
% For example,
%
% \begin{codeblock}
% \mac{beginverse}\mac{memorize}
% |The \[G]third \[C]chord will \[^Cm]not be re\[G]played.|\eat\]
% \mac{endverse}
% \mac{beginverse}
% |When ^replaying, the ^unmemorized chord is ^skipped.|
% \mac{endverse}
% \end{codeblock}
%
% \noindent produces
%
% \begin{chorded}\memorize
%   The \[G]third \[C]chord will \[^Cm]not be re\[G]played.\eat\]
%   \vskip5pt%
%   When ^replaying, the ^unmemorized chord is ^skipped.
% \end{chorded}
%
% \noindent
% This is useful when the first verse of a song has something unique,
% like an intro that won't be repeated in subsequent verses, but has
% other chords that you wish to replay.
%
% \paragraph{Memorizing Multiple Chord Sequences.}
% By default, the \Songs{} package only memorizes one sequence of chords
% at a time and \refchar{hat} replays chords from that most recently
% memorized sequence.
% However, you can memorize and replay multiple independent sequences
% using the macros described in the following paragraphs.
%
% \DescMacro{newchords}
% Memorized or replayed chord sequences are stored in chord-replay registers.
% To declare a new chord-replay register, type
%
% \begin{codeblock}
% |\newchords{|\Meta{regname}|}|
% \end{codeblock}
%
% \noindent
% where \Meta{regname} is any unique alphabetic name.
%
% Once you've declared a register, you can memorize into that register
% by providing the \Meta{regname} as an optional argument to
% \mac{memorize}:
%
% \begin{codeblock}
% \mac{memorize}|[|\Meta{regname}|]|
% \end{codeblock}
%
% \noindent
% Memorizing into a non-empty register replaces the contents of that
% register with the new chord sequence.
%
% \DescMacro{replay}
% To replay chords from a particular register, type
%
% \begin{codeblock}
% |\replay[|\Meta{regname}|]|
% \end{codeblock}
%
% \noindent
% Subsequent uses of \refchar{hat} reproduce chords from the sequence
% stored in register \Meta{regname}.
%
% Register contents are global, so you can memorize a chord sequence from one
% song and replay it in others.
% You can also use |\replay| multiple times in the same verse or chorus to
% replay a sequence more than once.
%
% \paragraph{Replaying Choruses.}
% \DescMacro{repchoruses}
% When making overhead slides, it is often convenient to repeat the song's
% chorus after the first verse on each page, so that the projector-operator
% need not flip back to the first slide each time the chorus is to be sung.
% You can say |\repchoruses| to automate this process.
% This causes the first chorus in each subsequent song to be automatically
% repeated after the first verse on each subsequent page of the song (unless
% that verse is already immediately followed by a chorus).
% If the first chorus is part of a set of two or more consecutive choruses,
% then the whole set of choruses is repeated.
% (A set of choruses is assumed to consist of things like pre-choruses that
% should always be repeated along with the chorus.)
% Choruses are not automatically inserted immediately after unnumbered
% verses (i.e., verses that begin with \mac{beginverse}|*|).
% Unnumbered verses are assumed to be bridges or endings that aren't
% followed by a chorus.
%
% \DescMacro{norepchoruses}
% Writing |\norepchoruses| turns off chorus repetition for subsequent songs.
%
% If you need finer control over where replayed choruses appear, use the
% conditional macros covered in \S\ref{sec:conditionals} instead of
% |\repchoruses|.
% For example, to manually insert a chorus into only slide books at a
% particular point (without affecting other versions of your book),
% you could write:
%
% \begin{codeblock}
% \mac{ifslides}
% \mac{beginchorus}
% $\vdots$
% \mac{endchorus}
% |\fi|
% \end{codeblock}
%
% \noindent
% and copy and paste the desired chorus into the middle.
%
% \subsection{Line and Column Breaks}
%
% \paragraph{Line Breaking.}
% \DescMacro{brk}
% To cause a long line of lyrics to be broken in a particular place, put the
% |\brk| macro at that point in the line.
% This does not affect lines short enough to fit without breaking.
% For example,
%
% \begin{codeblock}
% |\beginverse|
% {\tt\frenchspacing This is a |\brk| short line.
%  But this is a particularly long line of lyrics |\brk| that will need to be wrapped.
% } |\endverse|
% \end{codeblock}
%
% \noindent produces
%
% \begin{lyrics}
%   This is a \brk short line.
%   But this is a particularly long line of lyrics \brk that will need to be wrapped.
% \end{lyrics}
%
% \paragraph{Column Breaks Within Songs.}
% To suggest a column break within a verse or chorus too long to fit in a
% single column, use |\brk| on a line by itself.
% If there are no |\brk| lines in a long verse, it is broken
% somewhere that a line does not wrap.
% (A wrapped line is never divided by a column break.)
% If there are no |\brk| lines in a long chorus, it overflows the column,
% yielding an overfull vbox warning.
%
% \paragraph{Column Breaks Between Songs.}
% \DescMacro{nextcol}
% \DescMacro{sclearpage}
% \DescMacro{scleardpage}
% To force a column break between songs, use |\nextcol|, |\brk|, |\sclearpage|,
% or |\scleardpage| between songs.
% The |\nextcol| macro ends the column by leaving blank space at the bottom.
% The |\brk| macro ends the current column in lyric books by stretching
% the preceeding text so that the column ends flush with the bottom
% of the page.
% (In non-lyric books |\brk| is identical to |\nextcol|.)
% The |\sclearpage| macro is like |\nextcol| except that it shifts to the next
% blank page if the current page is nonempty.
% The |\scleardpage| macro is like |\sclearpage| except that it shifts to the
% next blank even-numbered page in two-sided documents.
% Column breaks usually need to be in different places in different book types.
% To achieve this, use a conditional block from \S\ref{sec:conditionals}.
% For example,
%
% \begin{codeblock}
% \mac{ifchorded}|\else|\mac{ifslides}|\else\brk\fi\fi|
% \end{codeblock}
%
% \noindent
% forces a column break only in lyric books but does not affect chord books
% or books of overhead slides.
%
% When a partial list of songs is being extracted with \mac{includeonlysongs},
% |\brk|, |\nextcol|, |\clearpage|, and |\cleardpage| macros between songs
% must be followed by a star to have any effect.
% To force a column-break at a specific point in a partial book, add the
% word |nextcol|, |brk|, |clearpage|, or |cleardpage| at the corresponding
% point in the argument to \mac{includeonlysongs}.
%
% \subsection{Echoes and Repeats}
%
% \paragraph{Echo Parts.}
% \DescMacro{echo}
% To typeset an echo part, use |\echo{|\Meta{lyrics and chords}|}|.
% Echo parts are parenthesized and italicized.
% For example,
%
% \example|Alle\[G]luia! \echo{Alle\[A]luia!}|\produces{Alle\[G]luia! \echo{Alle\[A]luia!}}
% \eat\]
%
% \paragraph{Repeated Lines.}
% \DescMacro{rep}
% To indicate that a line should be sung multiple times by all singers, put
% |\rep{|\Meta{n}|}| at the end of the line.
% For example,
%
% \example|Alleluia! \rep{4}|\produces{Alleluia! \rep{4}}
%
% \DescMacro{lrep}
% \DescMacro{rrep}
% To indicate exactly where repeated parts begin and end, use |\lrep| and
% |\rrep| to create begin- and end-repeat signs.
% For example,
%
% \example|\lrep \[G]Alleluia!\rrep \rep{4}|\produces{\lrep \[G]Alleluia!\rrep \rep{4}}
% \eat\]
%
% \subsection{Measure Bars}\label{sec:measures}
%
% \DescMacro{measurebar}
% \DescChar{pipe}{|}
% Measure bars can be added to chord books in order to help musicians
% keep time when playing unfamiliar songs.
% To insert a measure bar, type either |\measurebar| or type the
% vertical pipe symbol (``\verb@|@'').
% For example,
%
% \example\verb@Alle|\[G]luia@\produces{Alle\meter{}{}\measurebar\[G]luia}
% \eat\]
%
% \noindent
% In order for measure bars to be displayed, the \env{showmeasures}
% option must be enabled.
% Measure bars are only displayed by default in chord books.
%
% \DescMacro{meter}
% The first measure bar in a song has meter numbers placed above
% it to indicate the time signature of the piece.
% By default, these numbers are 4/4, denoting four quarter notes
% per measure.
% To change the default, type |\meter{|\Meta{n}|}{|\Meta{d}|}|
% somewhere after the \mac{beginsong} line of the song but before the
% first measure bar, to declare a time signature of \Meta{n} \Meta{d}th
% notes per measure.
%
% \DescMacro{mbar}
% You can also change meters mid-song either by using |\meter| in the
% middle of the song or by typing |\mbar{|\Meta{n}|}{|\Meta{d}|}|
% to produce a measure bar with a time signature of \Meta{n}/\Meta{d}.
% For example,
%
% \begin{codeblock}
% |\meter{6}{8}|
% |\beginverse|
% \verb@|Sing to the |heavens, ye \mbar{4}{4}saints of |old!@
% |\endverse|
% \end{codeblock}
%
% \noindent produces
%
% \begin{chorded}
%   \meter{6}{8}%
%   \measurebar Sing to the \measurebar heavens,  ye \mbar{4}{4}saints of \measurebar old!
% \end{chorded}
%
% \subsection{Textual Notes}\label{sec:notes}
%
% \DescMacro{textnote}
% \DescMacro{musicnote}
% Aside from verses and choruses, songs can also contain textual notes
% that provide instructions to singers and musicians.
% To create a textual note that is displayed in both lyric books
% and chord books, use:
%
% \begin{codeblock}
% |\textnote{|\Meta{text}|}|
% \end{codeblock}
%
% \noindent
% To create a textual note that is displayed only in chord books, use:
%
% \begin{codeblock}
% |\musicnote{|\Meta{text}|}|
% \end{codeblock}
%
% \noindent
% Both of these create a shaded box containing \Meta{text}.
% For example,
%
% \begin{codeblock}
% |\textnote{Sing as a two-part round.}|
% \end{codeblock}
%
% \noindent produces
%
% \begin{lyrics}
%   \textnote{Sing as a two-part round.}
% \end{lyrics}
%
% \noindent
% Textual notes can be placed anywhere within a song, either within
% verses and choruses or between them.
%
% \paragraph{Guitar Capos.}
% \DescMacro{capo}
% One special kind of textual note suggests to guitarists a fret on which
% they should put their capos.
% Macro |\capo{|\Meta{n}|}| should be used for this purpose.
% It normally has the same effect as \mac{musicnote}|{capo |\Meta{n}|}|;
% however, if the \env{transposecapos} option is active then it
% instead has the effect of \mac{transpose}|{|\Meta{n}|}|.
% See \S\ref{sec:transpose} for more information on automatic chord
% transposition.
%
% \subsection{Chords in Ligatures}
%
% This subsection covers an advanced topic and can probably be
% skipped by those creating song books for non-professional use.
%
% The \mac{[\eat]} macro is the normal means by which chords should be inserted
% into a song; however, a special case occurs when a chord falls within a
% ligature.
% Ligatures are combinations of letters or symbols that \TeX{} normally
% typesets as a single font character so as to produce cleaner-looking
% output.
% The only ligatures in English are: ff, fi, fl, ffi, and ffl.
% Other languages have additional ligatures like \ae{} and \oe.
% Notice that in each of these cases, the letters are ``squished''
% together to form a single composite symbol.
%
% \DescMacro{ch}
% When a chord macro falls inside a ligature, \LaTeX{} fails to compact
% the ligature into a single font character even in non-chorded versions of
% the book.
% To avoid this minor typographical error, use the |\ch| macro to typeset
% the chord:
%
% \begin{codeblock}
% |\ch{|\Meta{chord}|}{|\Meta{pre}|}{|\Meta{post}|}{|\Meta{full}|}|
% \end{codeblock}
%
% \noindent
% where \Meta{chord} is the chord text, \Meta{pre} is the text to
% appear before the hyphen if the ligature is broken by auto-hyphenation,
% \Meta{post} is the text to appear after the hyphen if the ligature
% is broken by auto-hyphenation, and \Meta{full} is the full ligature
% if it is not broken by hyphenation.
% For example, to correctly typeset |\[Gsus4]dif\[G]ficult|\eat\],
% in which the \chord{G} chord falls in the middle of the ``ffi''
% ligature, one should use:
%
% \example|di\ch{G}{f}{fi}{ffi}cult|\produces{di\ch{G}{f}{fi}{ffi}cult}
%
% \noindent
% This causes the ``ffi'' ligature to appear intact yet still correctly
% places the \chord{G} chord over the second f.
% To use the |\ch| macro with a replayed chord name (see \S\ref{sec:replay}),
% use |^| as the \Meta{chord}.
%
% \DescMacro{mch}
% The |\mch| macro is exactly like the \mac{ch} macro except that it
% also places a measure bar into the ligature along with the chord.
% For example,
%
% \example|di\mch{G}{f}{fi}{ffi}cult|\produces{di\mch{G}{f}{fi}{ffi}cult}
%
% \noindent
% places both a measure bar and a \chord{G} chord after the first ``f''
% in ``difficult'', yet correctly produces an unbroken ``ffi'' ligature
% in copies of the book in which measure bars are not displayed.
%
% In the unusual case that a meter change is required within a
% ligature, this can be achieved with a construction like:
%
% \example|\meter{6}{8}di\mch{G}{f}{fi}{ffi}cult|\produces{\meter{6}{8}di\mch{G}{f}{fi}{ffi}cult}
%
% \noindent
% The \mac{meter} macro sets the new time signature, which appears
% above the next measure bar---in this case the measure bar
% produced by the |\mch| macro.
%
% Chords and measure bars produced with \refchar{hat} or
% \refchar{pipe} are safe to use in ligatures.
% Thus, |dif|\refchar{pipe}\refchar{hat}|ficult| requires
% no special treatment; it leaves the ``ffi'' ligature intact when measure
% bars are not being displayed.
%
% \section{Guitar Tablatures}\label{sec:tablatures}
%
% \DescMacro{gtab}
% Guitar tablature diagrams can be created by using the construct
%
% \begin{codeblock}
% |\gtab{|\Meta{chord}|}{|\Meta{fret}|:|\Meta{strings}|:|\Meta{fingering}|}|
% \end{codeblock}
%
% \noindent
% where the \Meta{fret} and \Meta{fingering} parts are both optional
% (and you may omit any colon that borders an omitted argument).
%
% \Meta{chord} is a chord name to be placed above the diagram.
%
% \Meta{fret} is an optional digit from 2 to 9 placed to the
% left of the diagram.
%
% \Meta{strings} should be a series of symbols, one for each string
% of the guitar from lowest pitch to highest.
% Each symbol should be one of:
% |X| if that string is not to be played,
% |0| (zero or the letter O) if that string is to be played open, or
% one of |1| through |9| if that string is to be played on the given
% numbered fret.
%
% \Meta{fingering} is an optional series of digits, one for each
% string of the guitar from lowest pitch to highest.
% Each digit should be one of:
% |0| if no fingering information is to be displayed for that string (e.g., if
% the string is not being played or is being played open), or
% one of |1| through |4| to indicate that the given numbered finger is to be
% used to hold down that string.
%
% Here are some examples to illustrate:
%
% \example|\gtab{A}{X02220:001230}|\produces{\vcenterbox{\gtab{A}{{\hphantom{4}}:X02220:001230}}}
% \example|\gtab{C#sus4}{4:XX3341}|\produces{\vcenterbox{\gtab{C\shrp sus4}{4:XX3341}}}
% \example|\gtab{B&}{X13331}|\produces{\vcenterbox{\gtab{B\flt}{{\hphantom{4}}:X13331:}}}
%
% To create a barre chord in which one finger is extended across multiple
% strings, use parentheses |()| or brackets |[]| in the \Meta{strings}
% argument to group the barred strings.
% Each such group will draw a barre on the lowest numbered fret it contains.
% For example:
%
% \example|\gtab{C7}{X(3535X):013140}|\produces{\vcenterbox{\gtab{C7}{{\hphantom{4}}:X(3535X):013140}}}
%
% \DescMacro{minfrets}
% By default, tablature diagrams always consist of at least 4 fret rows
% (more if the \Meta{strings} argument contains a number larger than 4).
% To change the minimum number of fret rows, change the value of |\minfrets|.
% For example, typing
%
% \begin{codeblock}
% |\minfrets=1|
% \end{codeblock}
%
% \noindent
% causes tablature diagrams to have only as many rows are required to
% accommodate the largest digit appearing in the \Meta{strings} argument.
%
% \paragraph{Tablatures Within Macros}
% Macros that produce tablatures must not bury the colons that separate the
% \Meta{fret}, \Meta{strings}, and \Meta{fingering} arguments within other
% macros, and it's safest to always include both colons to avoid ambiguities
% related to optional argument parsing.
% For example,
%
% \begin{codeblock}
% |\newcommand{\mystrings}{X4412X}|
% |\newcommand{\myfingers}{X3412X}|
% |\newcommand{\mychord}{|\mac{gtab}|{C|\mac{shrp}|}{:\mystrings:\myfingers}}|
% \end{codeblock}
%
% \noindent
% works as expected.
% But omitting the colon before |\mystrings| in the definition of |\mychord|
% confuses \mac{gtab} into thinking |\mystrings| is the \Meta{fret}
% argument, and writing code like |\gtab{C\shrp}{\allargs}| with |\allargs|
% defined to something with colons results in an error, because it confuses
% \mac{gtab} into thinking that |\allargs| is only the \Meta{strings} argument.
%
% \section{Automatic Transposition}\label{sec:transpose}
%
% \DescMacro{transpose}
% You can automatically transpose some or all of the chords in a song up by
% \Meta{n} half-steps by adding the line
%
% \begin{codeblock}
% |\transpose{|\Meta{n}|}|
% \end{codeblock}
%
% \noindent
% somewhere between the song's \mac{beginsong} line and the first chord to
% be transposed.
% For example, if a song's first chord is |\[D]|\eat\], and the line
% |\transpose{2}| appears before it, then the chord appears as an
% \chord{E} in the resulting document.
% Specifying a negative number for \Meta{n} transposes subsequent chords
% down instead of up.
%
% The |\transpose| macro affects all chords appearing after it until the
% \mac{endsong} line.
% If two |\transpose| macros appear in the same song, their effects are
% cumulative.
%
% When the \env{transposecapos} option is active, the \mac{capo}
% macro acts like |\transpose|.
% See \S\ref{sec:notes} for more information.
%
% \paragraph{Enharmonics.}
% \DescMacro{preferflats}
% \DescMacro{prefersharps}
% When using \mac{transpose} to automatically transpose the chords of a song,
% the \Songs{} package code chooses between enharmonically equivalent
% names for ``black key'' notes based on the first chord of the song.
% For example, if |\transpose{1}| is used, and if the first chord of the
% song is an \chord{E}, then all \chord{A} chords that appear in
% the song are transcribed as \chord{B\flt} chords rather than
% \chord{A\shrp} chords, since the key of \chord{F}-major (\chord{E}
% transposed up by one half-step) has a flatted key signature.
% Usually this guess produces correct results, but if not, you can use
% either |\preferflats| or |\prefersharps| after the \mac{transpose} line
% to force all transcription to use flatted names or sharped names
% respectively, when resolving enharmonic equivalents.
%
% \paragraph{Modulated Verses.}
% Automatic transposition can be used in conjunction with chord-replaying
% (see \S\ref{sec:chords}) to produce modulated verses.
% For example,
%
% \begin{codeblock}
% \mac{beginverse}\mac{memorize}
% |\[F#]This is a \[B/F#]memorized \[F#]verse. \[E&7]|\eat\]
% \mac{endverse}
% \mac{transpose}|{2}|
% \mac{beginverse}
% |^This verse is ^modulated up two ^half-steps.|
% \mac{endverse}
% \end{codeblock}
%
% \noindent produces
%
% \begin{chorded}\memorize
%   \[F#]This is a \[B/F#]memorized \[F#]verse. \[E&7]\eat\]
%   \vskip5pt\replay\transpose{2}%
%   ^This verse is ^modulated up two ^half-steps.
%   \transpose{-2}%
% \end{chorded}
%
% \paragraph{Both Keys.}
% \DescMacro{trchordformat}
% By default, when chords are automatically transposed using \mac{transpose},
% only the transposed chords are printed.
% However, in some cases you may wish to print the old chords and the
% transposed chords together so that musicians playing transposing and
% non-transposing instruments can play from the same piece of music.
% This can be achieved by redefining the |\trchordformat| macro, which
% receives two arguments---the original chord name and the transposed chord
% name, respectively.
% For example, to print the old chord above the new chord above each lyric,
% define
%
% \begin{codeblock}
% |\renewcommand{\trchordformat}[2]{\vbox{\hbox{#1}\hbox{#2}}}|
% \end{codeblock}
%
% \paragraph{Changing Note Names.}
% \DescMacro{solfedge}
% \DescMacro{alphascale}
% In many countries it is common to use the solfedge names for the notes of
% the scale (\chord{LA, SI, DO, RE, MI, FA, SOL\/}) instead of the
% alphabetic names (\chord{A, B, C, D, E, F, G\/}).
% By default, the transposition logic only understands alphabetic names, but
% you can tell it to look for solfedge names by typing |\solfedge|.
% To return to alphabetic names, type |\alphascale|.
%
% \DescMacro{notenames}
% You can use other note names as well.
% To define your own note names, type
%
% \begin{codeblock}
% |\notenames{|\Meta{nameA}|}{|\Meta{nameB}|}|$\ldots$|{|\Meta{nameG}|}|
% \end{codeblock}
%
% \noindent
% where each of \Meta{nameA} through \Meta{nameG} must consist entirely of
% a sequence of one or more \emph{uppercase} letters.
% For example, some solfedge musicians use \chord{TI} instead of \chord{SI}
% for the second note of the scale.
% To automatically transpose such music, use:
%
% \begin{codeblock}
% |\notenames{LA}{TI}{DO}{RE}{MI}{FA}{SOL}|
% \end{codeblock}
%
% \DescMacro{notenamesin}
% \DescMacro{notenamesout}
% The \Songs{} package can also automatically convert one set of note names
% to another.
% For example, suppose you have a large song book in which chords have been
% typed using alphabetic note names, but you wish to produce a book that
% uses the equivalent solfedge names.
% You could achieve this by using the |\notenamesin| macro to tell the
% \Songs{} package which note names you typed in the input file, and then
% using |\notenamesout| to tell the \Songs{} package how you want it to
% typeset each note name in the output file.
% The final code looks like this:
%
% \begin{codeblock}
% |\notenamesin{A}{B}{C}{D}{E}{F}{G}|
% |\notenamesout{LA}{SI}{DO}{RE}{MI}{FA}{SOL}|
% \end{codeblock}
%
% \noindent
% The syntaxes of |\notenamesin| and |\notenamesout| are identical to that
% of \mac{notenames} (see above), except that the arguments of |\notenamesout|
% can consist of any \LaTeX{} code that is legal in horizontal mode, not just
% uppercase letters.
%
% To stop converting between note names, use \mac{alphascale}, \mac{solfedge},
% or \mac{notenames} to reset all note names back to identical input and
% output scales.
%
% \paragraph{Transposing Chords In Macros.}
% \DescMacro{transposehere}
% The automatic transposition logic does not find chord names that are hidden
% inside macro bodies.
% For example, if you abbreviate a chord by typing,
%
% \begin{codeblock}
% |\newcommand{\mychord}{F|\mac{shrp}| sus4/C|\mac{shrp}|}|
% \mac{transpose}|{4}|
% |\[\mychord]|\eat\]
% \end{codeblock}
%
% \noindent
% then the \mac{transpose} macro fails to transpose it; the
% resulting chord is still an \chord{F\shrp sus4/C\shrp} chord.
% To fix the problem, you can use |\transposehere| in your macros to
% explicitly invoke the transposition logic on chord names embedded in
% macro bodies.
% The above example could be corrected by instead defining:
%
% \begin{codeblock}
% |\newcommand{\mychord}{\transposehere{F|\mac{shrp}| sus4/C|\mac{shrp}|}}|
% \end{codeblock}
%
% \DescMacro{notrans}
% Transposition can be suppressed within material that would otherwise be
% transposed by using the |\notrans| macro.
% For example, writing
%
% \begin{codeblock}
% \mac{transposehere}|{G = \notrans{G}}|
% \end{codeblock}
%
% \noindent
% would typeset a transposed \chord{G} followed by a non-transposed
% \chord{G} chord.
% This does not suppress note name conversion (see \mac{notenames}).
% To suppress both transposition and note name conversion, just use
% braces (e.g., |{G}| instead of |\notrans{G}|).
%
% \paragraph{Transposing Guitar Tablatures.}
% \DescMacro{gtabtrans}
% The songs package cannot automatically transpose tablature diagrams
% (see \S\ref{sec:tablatures}).
% Therefore, when automatic transposition is taking place, only the chord
% names of \mac{gtab} macros are displayed (and transposed); the diagrams
% are omitted.
% To change this default, redefine the |\gtabtrans| macro, whose two
% arguments are the two arguments to \mac{gtab}.
% For example, to display original tablatures without transposing them even
% when transposition has been turned on, write
%
% \begin{codeblock}
% |\renewcommand{\gtabtrans}[2]{|\mac{gtab}|{|\mac{notrans}|{#1}}{#2}}|
% \end{codeblock}
%
% \noindent
% To transpose the chord name but not the diagram under it, replace
% \mac{notrans}|{#1}| with simply |#1| in the above.
% To restore the default behavior, write
%
% \begin{codeblock}
% |\renewcommand{\gtabtrans}[2]{|\mac{transposehere}|{#1}}|
% \end{codeblock}
%
% \section{Between Songs}\label{sec:between}
%
% Never put any material directly into the top level of a \env{songs}
% environment.
% Doing so will disrupt the page-builder, usually producing strange page
% breaks and blank pages.
% To safely put material between songs, use one of the environments
% described in this section.
%
% \subsection{Intersong Displays}\label{sec:intersong}
%
% \DescEnv{intersong}
% To put column-width material between the songs in a \env{songs} environment,
% use an |intersong| environment:
%
% \begin{codeblock}
% |\begin{intersong}|
% $\vdots$
% |\end{intersong}|
% \end{codeblock}
%
% \noindent
% Material contributed in an |intersong| environment is subject to the same
% column-breaking rules as songs (see \S\ref{sec:layout}), but all other
% formatting is up to you.
% By default, \LaTeX{} inserts interline glue below the last line of an
% |intersong| environment.
% To suppress this, end the |intersong| content with |\par\nointerlineskip|.
%
% \DescEnv{intersong*}
% To instead put page-width material above a song, use an |intersong*|
% environment:
%
% \begin{codeblock}
% |\begin{intersong*}|
% $\vdots$
% |\end{intersong*}|
% \end{codeblock}
%
% \noindent
% This starts a new page if the current page already has column-width
% material in it.
%
% \DescEnv{songgroup}
% By default, all intersong displays are omitted when generating a partial
% book with \mac{includeonlysongs}.
% You can force them to be included whenever a particular song is included
% by using a |songgroup| environment:
%
% \begin{codeblock}
% |\begin{songgroup}|
% $\vdots$
% |\end{songgroup}|
% \end{codeblock}
%
% \noindent
% Each |songgroup| environment may include any number of \env{intersong},
% \env{intersong*}, or scripture quotations (see \S\ref{sec:scripture}),
% but must include exactly one song.
% When using \mac{includeonlysongs}, the entire group is included in the
% book if the enclosed song is included; otherwise the entire group is
% omitted.
%
% \subsection{Scripture Quotations}\label{sec:scripture}
%
% \paragraph{Starting a Scripture Quotation.}
% \DescMacro{beginscripture}
% \DescMacro{endscripture}
% A special form of intersong block typesets a scripture quotation.
% Scripture quotations begin and end with
%
% \begin{codeblock}
% |\beginscripture{|\Meta{ref}|}|
% $\vdots$
% |\endscripture|
% \end{codeblock}
%
% \noindent
% where \Meta{ref} is a scripture reference that is
% typeset at the end of the quotation.
% The \Meta{ref} argument should conform to the same syntax
% rules as for the \Meta{ref} arguments passed to \mac{beginsong}
% macros (see \S\ref{sec:songs}).
%
% The text of the scripture quotation between the |\beginscripture| and
% |\endscripture| lines are parsed in normal paragraph mode.
% For example:
%
% \begin{codeblock}
% |\beginscripture{James 5:13}|
% {\tt\frenchspacing%
%   Is any one of you in trouble? He should pray. Is anyone happy? Let him sing songs of praise.
% } |\endscripture|
% \end{codeblock}
%
% \noindent produces
%
% \begin{sample}
%   \beginscripture{James 5:13}
%   Is any one of you in trouble? He should pray. Is anyone happy? Let him sing songs of praise.
%   \endscripture
% \end{sample}
%
% \paragraph{Tuplets.}
% \DescMacro{Acolon}
% \DescMacro{Bcolon}
% To typeset biblical poetry the way it appears in most bibles, begin each
% line with either |\Acolon| or |\Bcolon|.
% A-colons are typeset flush with the left margin, while B-colons are
% indented.
% Any lines too long to fit are wrapped with double-width hanging indentation.
% For example,
%
% \begin{codeblock}
% |\beginscripture{Psalm 1:1}|
% {\tt\frenchspacing%
%   |\Acolon| Blessed is the man
%   |\Bcolon| who does not walk in the counsel of the wicked
%   |\Acolon| or stand in the way of sinners
%   |\Bcolon| or sit in the seat of mockers.
% } |\endscripture|
% \end{codeblock}
%
% \noindent produces
%
% \begin{sample}
%   \beginscripture{Psalm 1:1}
%   \Acolon Blessed is the man
%   \Bcolon who does not walk in the counsel of the wicked
%   \Acolon or stand in the way of sinners
%   \Bcolon or sit in the seat of mockers.
%   \endscripture
% \end{sample}
%
% \paragraph{Stanzas.}
% \DescMacro{strophe}
% Biblical poetry is often grouped into stanzas or ``strophes'',
% each of which is separated from the next by a small vertical
% space.
% You can create that vertical space by typing |\strophe|.
% For example,
%
% \begin{codeblock}
% |\beginscripture{Psalm 88:2-3}|
% {\tt\frenchspacing%
%   |\Acolon| May my prayer come before you;
%   |\Bcolon| turn your ear to my cry.
%   |\strophe|
%   |\Acolon| For my soul is full of trouble
%   |\Bcolon| and my life draws near the grave.
% } |\endscripture|
% \end{codeblock}
%
% \noindent produces
%
% \begin{sample}
%   \beginscripture{Psalm 88:2-3}
%   \Acolon May my prayer come before you;\par
%   \Bcolon turn your ear to my cry.\par
%   \strophe
%   \Acolon For my soul is full of trouble\par
%   \Bcolon and my life draws near the grave.
%   \endscripture
% \end{sample}
%
% \paragraph{Indented Blocks.}
% \DescMacro{scripindent}
% \DescMacro{scripoutdent}
% Some bible passages, such as those that mix prose and poetry, contain
% indented blocks of text.
% You can increase the indentation level within a scripture quotation
% by using |\scripindent| and decrease it by using |\scripoutdent|.
% For example,
%
% \begin{codeblock}
% |\beginscripture{Hebrews 10:17-18}|
% {\tt\frenchspacing%
%   Then he adds:
%   |\scripindent|
%   |\Acolon ``|Their sins and lawless acts
%   |\Bcolon| I will remember no more.|''|
%   |\scripoutdent|
%   And where these have been forgiven, there is no longer any sacrifice for sin.
% } |\endscripture|
% \end{codeblock}
%
% \noindent produces
%
% \begin{sample}
%   \beginscripture{Hebrews 10:17-18}
%   Then he adds:\par
%   \scripindent
%   \Acolon ``Their sins and lawless acts\par
%   \Bcolon I will remember no more.''\par
%   \scripoutdent
%   And where these have been forgiven, there is no longer any sacrifice for sin.
%   \endscripture
% \end{sample}
%
% \section{Chapters and Sections}\label{sec:sectioning}
%
% \DescMacro{songsection}
% \DescMacro{songchapter}
% Song books can be divided into chapters and sections using all the usual
% macros provided by \LaTeX{} (e.g., |\chapter|, |\section|, etc.) and by
% other macro packages.
% In addition, the \Songs{} package provides two helpful built-in sectioning
% macros:
%
% \begin{codeblock}
% |\songchapter{|\Meta{title}|}|
% |\songsection{|\Meta{title}|}|
% \end{codeblock}
%
% \noindent
% which act like \LaTeX's |\chapter| and |\section| commands except that they
% center the \Meta{title} text in sans serif font and omit the chapter/section
% number.
% The |\songchapter| macro only works in document classes that support
% |\chapter| (e.g., the |book| class).
%
% \section{Indexes}
%
% \subsection{Index Creation}\label{sec:indexes}
%
% \DescMacro{newindex}
% \DescMacro{newauthorindex}
% \DescMacro{newscripindex}
% The \Songs{} package supports three kinds of indexes: indexes by title and/or
% notable lyrics, indexes by author, and indexes by scripture reference.
% To generate an index, first declare the index in the document preamble
% (i.e., before the |\begin{document}| line) with one of the following:
%
% \begin{codeblock}
% |\newindex{|\Meta{id}|}{|\Meta{filename}|}|
% |\newauthorindex{|\Meta{id}|}{|\Meta{filename}|}|
% |\newscripindex{|\Meta{id}|}{|\Meta{filename}|}|
% \end{codeblock}
%
% \noindent
% The \Meta{id} should be an alphabetic identifier that will be used to
% identify the index in other macros that reference it.
% The \Meta{filename} should be a string that, when appended with an
% extension, constitutes a valid filename on the system.
% Auxiliary files named \Meta{filename}|.sxd| and \Meta{filename}|.sbx|
% are generated during the automatic index generation process.
% For example:
%
% \begin{codeblock}
% |\newindex{mainindex}{idxfile}|
% \end{codeblock}
%
% \noindent
% creates a title index named ``|mainindex|'' whose data is
% stored in files named |idxfile.sxd| and |idxfile.sbx|.
%
% \DescMacro{showindex}
% To display the index in the document, use:
%
% \begin{codeblock}
% |\showindex[|\Meta{columns}|]{|\Meta{title}|}{|\Meta{id}|}|
% \end{codeblock}
%
% \noindent
% where \Meta{id} is the same identifier used in the \mac{newindex},
% \mac{newauthorindex}, or \mac{newscripindex} command, and where
% the \Meta{title} is the title of the index, which should consist only of
% simple text (no font or formatting macros, since those cannot be used in
% pdf bookmark indexes).
% The |[|\Meta{columns}|]| part is optional; if specified it dictates the
% number of columns if the index can't fit in a single column.
% For example, for a 2-column title index, write:
%
% \begin{codeblock}
% |\showindex[2]{Index of Song Titles}{mainindex}|
% \end{codeblock}
%
% \subsection{Index Entries}\label{sec:ientry}
%
% Every song automatically gets entries in the current \env{songs}
% environment's list of title index(es) (see \S\ref{sec:songs}).
% However, you can also add extra index entries for a song to any index.
%
% \paragraph{Indexing Lyrics.}
% \DescEnv{index=}
% For example, title indexes often have entries for memorable lines
% of lyrics in a song in addition to the song's title.
% You can add an index entry for the current song to the section's
% title index(es) by adding |index={|\Meta{lyrics}|}| to the song's
% \mac{beginsong} line.
% For example,
%
% \begin{codeblock}
% \mac{beginsong}|{Doxology}|
% |          [index={Praise God from Whom all blessings flow}]|
% \end{codeblock}
%
% \noindent
% causes the song to be indexed both as ``\textit{Doxology}'' and as
% ``Praise God from Whom all blessings flow'' in the section's title index(es).
% You can use |index=| multiple times in a \mac{beginsong} line to produce
% multiple additional index entries.
% Index entries produced with |index={|\Meta{lyrics}|}| are
% typeset in an upright font instead of in italics to distinguish
% them from song titles.
%
% \paragraph{Indexing Extra Song Titles.}
% \DescEnv{ititle=}
% To add a regular index entry typeset in italics to the title
% index(es), use:
%
% \begin{codeblock}
% |ititle={|\Meta{title}|}|
% \end{codeblock}
%
% \noindent
% in the \mac{beginsong} line instead.
% Like \env{index=} keyvals, |ititle=| can be used multiple times to produce
% multiple additional index entries.
%
% \DescMacro{indexentry}
% \DescMacro{indextitleentry}
% You can also create index entries by saying
% |\indexentry[|\Meta{indexes}|]{|\Meta{lyrics}|}| (which creates an
% entry like \env{index=}) or
% |\indextitleentry[|\Meta{indexes}|]{|\Meta{title}|}| (which
% creates an entry like \env{ititle=}).
% These two macros can be used anywhere between the song's \mac{beginsong}
% and \mac{endsong} lines, and can be used multiple times to produce
% multiple entries.
% If specified, \Meta{indexes} is a comma-separated list of the identifiers
% of indexes to which the entry should be added.
% Otherwise the new entry is added to all of the title indexes for the current
% \env{songs} environment.
%
% \subsection{Compiling}\label{sec:compiling}
%
% As with a typical \LaTeX{} document, compiling a song book document with
% indexes requires three steps.
% First, use \LaTeX{} (|pdflatex| is recommended) to generate auxiliary files
% from the |.tex| file:
%
% \begin{codeblock}
% |pdflatex mybook.tex|
% \end{codeblock}
%
% Second, use the |songidx.lua| script to generate an index for each index that
% you declared with \mac{newindex}, \mac{newauthorindex}, or
% \mac{newscripindex}.
% The script can be launched using Lua\TeX, using the following syntax:
%
% \begin{codeblock}
% |texlua songidx.lua |\textcolor{black}{[}|-b| \Meta{canon}|.can|\textcolor{black}{]} \Meta{filename}|.sxd| \Meta{filename}|.sbx|
% \end{codeblock}
%
% \noindent
% where \Meta{filename} is the same \Meta{filename} that was used in the
% \mac{newindex}, \mac{newauthorindex}, or \mac{newscripindex} macro.
% If the index was declared with \mac{newscripindex}, then the |-b| option
% is used to specify which version of the bible you wish to use as a basis
% for sorting your scripture index.
% The \Meta{canon} part can be any of the |.can| files provided with
% the |songidx| distribution.
% If you are using a Protestant, Catholic, or Greek Orthodox Christian bible
% with book names in English, then the |bible.can| canon file should work
% well.
% For other bibles, you should create your own |.can| file by copying and
% modifying one of the existing |.can| files.
%
% For example, if your song book |.tex| file contains the lines
%
% \begin{codeblock}
% \mac{newindex}|{titleidx}{titlfile}|
% \mac{newauthorindex}|{authidx}{authfile}|
% \mac{newscripindex}|{scripidx}{scrpfile}|
% \end{codeblock}
%
% \noindent
% then to generate indexes sorted according to a Christian English bible,
% execute:
%
% \begin{codeblock}
% |texlua songidx.lua titlfile.sxd titlfile.sbx|
% |texlua songidx.lua authfile.sxd authfile.sbx|
% |texlua songidx.lua -b bible.can scrpfile.sxd scrpfile.sbx|
% \end{codeblock}
%
% Once the indexes are generated, generate the final book by invoking
% \LaTeX{} one more time:
%
% \begin{codeblock}
% |pdflatex mybook.tex|
% \end{codeblock}
%
% \section{Customizing the Book}
%
% \subsection{Song and Verse Numbering}\label{sec:numbering}
%
% \paragraph{Song Numbering.}
% \DescEnv{songnum}
% The |songnum| counter defines the next song's number.
% It is set to 1 at the beginning of a \env{songs} environment and is
% increased by 1 after each \mac{endsong}.
% It can be redefined anywhere except within a song.
% For example,
%
% \begin{codeblock}
% |\setcounter{songnum}{3}|
% \end{codeblock}
%
% \noindent sets the next song's number to be 3.
%
% \DescMacro{thesongnum}
% You can change the song numbering style for a song section by redefining
% |\thesongnum|.
% For example, to cause songs to be numbered A1, A2, etc., in the current
% song section, type
%
% \begin{codeblock}
% |\renewcommand{\thesongnum}{A\arabic{songnum}}|
% \end{codeblock}
%
% \noindent
% The expansion of |\thesongnum| must always produce plain text with no
% font formatting or unexpandable macro tokens, since its text is
% exported to auxiliary index generation files where it is sorted.
%
% \DescMacro{printsongnum}
% To change the formatting of song numbers as they appear at the beginning
% of each song, redefine the |\printsongnum| macro,
% which expects the text yielded by \mac{thesongnum} as its only argument.
% For example, to typeset song numbers in italics atop each song, define
%
% \begin{codeblock}
% |\renewcommand{\printsongnum}[1]{\it\LARGE#1}|
% \end{codeblock}
%
% \DescMacro{songnumwidth}
% The |\songnumwidth| length defines the width of the shaded boxes that contain
% song numbers at the beginning of each song.
% For example, to make each such box 2 centimeters wide, you could define
%
% \begin{codeblock}
% |\setlength{\songnumwidth}{2cm}|
% \end{codeblock}
%
% \noindent
% If |\songnumwidth| is set to zero, song numbers are not shown at all.
%
% \DescMacro{nosongnumbers}
% To turn off song numbering entirely, type |\nosongnumbers|.
% This inhibits the display of the song number atop each song
% (but song numbers are still be displayed elsewhere, such as in indexes).
% The same effect can be achieved by setting \mac{songnumwidth} to zero.
%
% \paragraph{Verse Numbering.}
% \DescEnv{versenum}
% The |versenum| counter defines the next verse's number.
% It is set to 1 after each \mac{beginsong} line and is increased by 1 after
% each \mac{endverse} (except if the verse begins with \mac{beginverse}|*|).
% The |versenum| counter can be redefined anywhere within a song.
% For example,
%
% \begin{codeblock}
% |\setcounter{versenum}{3}|
% \end{codeblock}
%
% \noindent sets the next verse's number to be 3.
%
% \DescMacro{theversenum}
% You can change the verse numbering style by redefining |\theversenum|.
% For example, to cause verses to be numbered in uppercase roman numerals,
% define
%
% \begin{codeblock}
% |\renewcommand{\theversenum}{\Roman{versenum}}|
% \end{codeblock}
%
% \DescMacro{printversenum}
% To change the formatting of verse numbers as they appear at the beginning
% of each verse, redefine the |\printversenum| macro,
% which expects the text yielded by \mac{theversenum} as its only argument.
% For example, to typeset verse numbers in italics, define
%
% \begin{codeblock}
% |\renewcommand{\printversenum}[1]{\it\LARGE#1.\ }|
% \end{codeblock}
%
% \DescMacro{versenumwidth}
% The |\versenumwidth| length defines the horizontal space reserved for verse
% numbers to the left of each verse text.
% Verse text is shifted right by this amount.
% For example, to reserve half a centimeter of space for verse numbers, define
%
% \begin{codeblock}
% |\setlength{\versenumwidth}{0.5cm}|
% \end{codeblock}
%
% Verse numbers whose widths exceed |\versenumwidth| indent the first
% line of the verse an additional amount to make room, but subsequent lines
% of the verse are only indented by |\versenumwidth|.
%
% \DescMacro{noversenumbers}
% To turn off verse numbering entirely, use |\noversenumbers|.
% This is equivalent to saying
%
% \begin{codeblock}
% |\renewcommand{|\mac{printversenum}|}[1]{}|
% |\setlength{\versenumwidth}{0pt}|
% \end{codeblock}
%
% \DescMacro{placeversenum}
% The horizontal placement of verse numbers within the first line of each
% verse is controlled by the |\placeversenum| macro.
% By default, each verse number is placed flush-left.
% \ImplOrDesc
%   {Authors interested in changing the placement of verse numbers should
%    consult \S\ref{sec:impparams} of the implementation section for more
%    information on this macro.}
%   {For more information on this macro, recompile this documentation with
%    the implementation section included.}
%
% \subsection{Song Appearance}
%
% \paragraph{Font Selection.}
% \DescMacro{lyricfont}
% By default, lyrics are typeset using the document-default font
% (|\normalfont|) and with the document-default point size (|\normalsize|).
% You can change these defaults by redefining |\lyricfont|.
% For example, to cause lyrics to be typeset in small sans serif font,
% you could define
%
% \begin{codeblock}
% |\renewcommand{\lyricfont}{\sffamily\small}|
% \end{codeblock}
%
% \DescMacro{stitlefont}
% Song titles are typeset in a sans-serif, slanted font by default
% (sans-serif, upright if producing slides), with minimal line spacing.
% You can change this default by redefining |\stitlefont|.
% For example, to cause titles to be typeset in a roman font with lines
% spaced 20 points apart, you could define
%
% \begin{codeblock}
% |\renewcommand{\stitlefont}{|
% |  \rmfont\Large\baselineskip=20pt\lineskiplimit=0pt|
% |}|
% \end{codeblock}
%
% \DescMacro{versefont}
% \DescMacro{chorusfont}
% \DescMacro{meterfont}
% \DescMacro{echofont}
% \DescMacro{notefont}
% You can apply additional font changes to verses, choruses, meter numbers,
% echo parts produced with \mac{echo}, and textual notes produced with
% \mac{textnote} and \mac{musicnote}, by redefining |\versefont|,
% |\chorusfont|, |\meterfont|, |\echofont|, and |\notefont|, respectively.
% For example, to typeset choruses in italics, you could define
%
% \begin{codeblock}
% |\renewcommand{\chorusfont}{\it}|
% \end{codeblock}
%
% \DescMacro{notebgcolor}
% \DescMacro{snumbgcolor}
% The colors of shaded boxes containing textual notes and song numbers
% can be changed by redefining the |\notebgcolor| and |\snumbgcolor|
% macros.
% For example:
%
% \begin{codeblock}
% |\renewcommand{\notebgcolor}{red}|
% \end{codeblock}
%
% \DescMacro{printchord}
% By default, chords are typeset in sans serif oblique (slanted) font.
% You can customize chord appearance by redefining |\printchord|, which
% accepts the chord text as its argument.
% For example, to cause chords to be printed in roman boldface font,
% you could define
%
% \begin{codeblock}
% |\renewcommand{\printchord}[1]{\rmfamily\bf#1}|
% \end{codeblock}
%
% \paragraph{Accidental Symbols.}
% \DescMacro{sharpsymbol}
% \DescMacro{flatsymbol}
% By default, sharp and flat symbols are typeset using \LaTeX's
% |\#| ($\#$) and |\flat| ($\flat$) macros.
% Users can change this by redefining |\sharpsymbol| and |\flatsymbol|.
% For example, to use |\sharp| ($\sharp$) instead of $\#$, one could
% redefine |\sharpsymbol| as follows.
%
% \begin{codeblock}
% |\renewcommand{\sharpsymbol}{\ensuremath{^\sharp}}|
% \end{codeblock}
%
% \paragraph{Verse and Chorus Titles.}
% \DescMacro{everyverse}
% \DescMacro{everychorus}
% The |\everyverse| macro is executed at the beginning of each verse, and
% |\everychorus| is executed at the beginning of each chorus.
% Thus, to begin each chorus with the word ``Chorus:'' one could type,
%
% \begin{codeblock}
% |\renewcommand{\everychorus}{|\mac{textnote}|{Chorus:}}|
% \end{codeblock}
%
% \paragraph{Spacing Options.}
% \DescMacro{versesep}
% The vertical distance between song verses and song choruses is defined by
% the skip register |\versesep|.
% For example, to put 12 points of space between each pair of verses and
% choruses, with a flexibility of plus or minus 2 points, you could define
%
% \begin{codeblock}
% |\versesep=12pt plus 2pt minus 2pt|
% \end{codeblock}
%
% \DescMacro{afterpreludeskip}
% \DescMacro{beforepostludeskip}
% The vertical distance between the song's body and its prelude and postlude
% material is controlled by skips |\afterpreludeskip| and
% |\beforepostludeskip|.
% This glue can be made stretchable for centering effects.
% For example, to cause each song body to be centered on the page with one
% song per page, you could write:
%
% \begin{codeblock}
% \mac{songcolumns}|{1}|
% \mac{spenalty}|=-10000|
% |\afterpreludeskip=2pt plus 1fil|
% |\beforepostludeskip=2pt plus 1fil|
% \end{codeblock}
%
% \DescMacro{baselineadj}
% The vertical distance between the baselines of consecutive lines of
% lyrics is computed by the \Songs{} package based on several factors
% including the lyric font size, the chord font size (if in \env{chorded}
% mode), and whether \env{slides} mode is currently active.
% You can adjust the results of this computation by redefining skip
% register |\baselineadj|.
% For example, to reduce the natural distance between baselines by 1 point
% but allow an additional 1 point of stretching when attempting to balance
% columns, you could define
%
% \begin{codeblock}
% |\baselineadj=-1pt plus 1pt minus 0pt|
% \end{codeblock}
%
% \DescMacro{clineparams}
% To change the vertical distance between chords and the lyrics below them,
% redefine the |\clineparams| macro with a definition that adjusts the
% \LaTeX{} parameters |\baselineskip|, |\lineskiplimit|, and |\lineskip|.
% For example, to cause the baselines of chords and their lyrics to be
% 12 points apart with at least 1 point of space between the bottom of the
% chord and the top of the lyric, you could write:
%
% \begin{codeblock}
% |\renewcommand{\clineparams}{|
% |  \baselineskip=12pt|
% |  \lineskiplimit=1pt|
% |  \lineskip=1pt|
% |}|
% \end{codeblock}
%
% \DescMacro{cbarwidth}
% The width of the vertical line that appears to the left of choruses is
% controlled by the |\cbarwidth| length.
% To eliminate the line entirely (and the spacing around it), you can set
% |\cbarwidth| to |0pt|:
%
% \begin{codeblock}
% |\setlength{\cbarwidth}{0pt}|
% \end{codeblock}
%
% \DescMacro{sbarheight}
% The height of the horizontal line that appears between each pair of songs
% is controlled by the |\sbarheight| length.
% To eliminate the line entirely (and the spacing around it), you can set
% |\sbarheight| to |0pt|:
%
% \begin{codeblock}
% |\setlength{\sbarheight}{0pt}|
% \end{codeblock}
%
% \paragraph{Song Top and Bottom Material.}
% You can adjust the header and footer material that precedes and concludes
% each song by redefining |\extendprelude| and |\extendpostlude|.
%
% \DescMacro{extendprelude}
% \DescMacro{showauthors}
% \DescMacro{showrefs}
% By default, |\extendprelude| displays the song's authors and scripture
% references using the macros |\showauthors| and |\showrefs|.
% The following definition changes it to also print copyright info:
%
% \begin{codeblock}
% |\renewcommand{\extendprelude}{|
% |  |\mac{showrefs}\mac{showauthors}
% |  {\bfseries|\mac{songcopyright}|\par}|
% |}|
% \end{codeblock}
%
% \DescMacro{extendpostlude}
% By default, |\extendpostlude| prints the song's copyright and licensing
% information as a single paragraph using \mac{songcopyright} and
% \mac{songlicense}.
% The following definition changes it to also print the words
% ``Used with permission'' at the end of every song's footer information:
%
% \begin{codeblock}
% |\renewcommand{\extendpostlude}{|
% |  |\mac{songcopyright}|\ |\mac{songlicense}|\unskip|
% |  \ Used with permission.|
% |}|
% \end{codeblock}
%
% In general, any macro documented in \S\ref{sec:songinfo} can be used
% in |\extendprelude| and |\extendpostlude| to print song information, such
% as \mac{songauthors}, \mac{songrefs}, \mac{songcopyright}, and
% \mac{songlicense}.
% For convenience, the \mac{showauthors} and \mac{showrefs} macros display
% author and scripture reference information as a pre-formatted paragraph
% the way it appears in the default song header blocks.
%
% See \S\ref{sec:newkey} for how to define new \mac{beginsong} keyvals and
% use them in |\extendprelude|.
%
% \DescMacro{makeprelude}
% \DescMacro{makepostlude}
% For complete control over the appearance of the header and footer material
% that precedes and concludes each song, you can redefine the macros
% |\makeprelude| and |\makepostlude|.
% When typesetting a song, the \Songs{} package code invokes both of these
% macros once (after processing all the material between the \mac{beginsong}
% and \mac{endsong} lines), placing the results within vboxes.
% The resulting vboxes are placed atop and below the song content.
% By default, |\makeprelude| displays the song's titles, authors, and scripture
% references to the right of a shaded box containing the song's number; and
% |\makepostlude| displays the song's copyright and licensing information in
% fine print.
%
% As a simple example, the following causes each song to start with its
% number and title(s), centered, in a large, boldface font, and then centers
% the rest of the prelude material (e.g., references and authors) below that
% (using \mac{extendprelude}).
%
% \begin{codeblock}
% |\renewcommand\makeprelude{%|
% |  |\mac{resettitles}
% |  \centering|
% |  {\Large\bfseries|\mac{thesongnum}|. |\mac{songtitle}|\par|
% |   |\mac{nexttitle}\mac{foreachtitle}|{(|\mac{songtitle}|)\par}}%|
% |  |\mac{extendprelude}
% |}|
% \end{codeblock}
%
% \paragraph{Page- and Column-breaking.}
% \DescMacro{vvpenalty}
% \DescMacro{ccpenalty}
% \DescMacro{vcpenalty}
% \DescMacro{cvpenalty}
% \DescMacro{brkpenalty}
% Page-breaking and column-breaking within songs that are too large to fit
% in a single column/page is influenced by the values of several penalties.
% Penalties of value |\interlinepenalty| are inserted between consecutive
% lines of each verse and chorus;
% penalties of value |\vvpenalty|, |\ccpenalty|, |\vcpenalty|, and |\cvpenalty|
% are inserted into each song between consecutive verses, between consecutive
% choruses, after a verse followed by a chorus, and after a chorus followed by
% a verse, respectively;
% and penalties of value |\brkpenalty| are inserted wherever \mac{brk} is
% used on a line by itself.
% The higher the penalty, the less likely \TeX{} is to place a
% page- or column-break at that site.
% If any are set to $-10000$ or lower, breaks are forced there.
% By default, |\interlinepenalty| is set to 1000 and the rest are set to 200
% so that breaks between verses and choruses are preferred over breaks within
% choruses and verses, but are not forced.
%
% \DescMacro{sepverses}
% Saying |\sepverses| sets all of the above penalties to $-10000$ except for
% |\ccpenalty| which is set to 100.
% This is useful in \env{slides} mode because it forces each verse and
% chorus to be typeset on a separate slide, except for consecutive choruses,
% which remain together when possible.
% (This default reflects an expectation that consecutive choruses typically
% consist of a pre-chorus and chorus that are always sung together.)
%
% These defaults can be changed by changing the relevant penalty register
% directly.
% For example, to force a page- or column-break between consecutive choruses,
% type
%
% \begin{codeblock}
% |\ccpenalty=-10000|
% \end{codeblock}
%
% \paragraph{Text Justification.}
% \DescMacro{versejustify}
% \DescMacro{chorusjustify}
% \DescMacro{justifyleft}
% \DescMacro{justifycenter}
% To left-justify or center the lines of verses or choruses, redefine
% |\versejustify| or |\chorusjustify| to |\justifyleft| or |\justifycenter|,
% respectively.
% For example, to cause choruses to be centered, one could type:
%
% \begin{codeblock}
% |\renewcommand{|\mac{chorusjustify}|}{\justifycenter}|
% \end{codeblock}
%
% \DescMacro{notejustify}
% Justification of textual notes too long to fit on a single line
% is controlled by the |\notejustify| macro.
% By default, it sets up an environment that fully justifies the note
% (i.e., all but the last line of each paragraph extends all the way from
% the left to the right margin).
% \ImplOrDesc
%   {Authors interested in changing this behavior should consult
%    \S\ref{sec:impparams} of the implementation section for more
%    information about this macro.}
%   {For more information, recompile this documentation with the
%    implementation section included.}
%
% \DescMacro{placenote}
% A textual note that is shorter than a single line is placed flush-left by
% default, or is centered when in slides mode.
% This placement of textual notes is controlled by |\placenote|.
% \ImplOrDesc
%   {Authors interested in changing this behavior should consult
%    \S\ref{sec:impparams} of the implementation section for more
%    information about this macro.}
%   {For more information, recompile this documentation with the
%    implementation section included.}
%
% \subsection{Scripture Appearance}
%
% \DescMacro{scripturefont}
% By default, scripture quotations are typeset in Zaph Chancery font
% with the document-default point size (|\normalsize|).
% You can change these defaults by redefining |\scripturefont|.
% For example, to cause scripture quotations to be typeset in sans serif
% italics, define:
%
% \begin{codeblock}
% |\renewcommand{\scripturefont}{\sffamily\it}|
% \end{codeblock}
%
% \DescMacro{printscrcite}
% By default, the citation at the end of a scripture quotation is
% typeset in sans serif font at the document-default point size
% (|\normalsize|).
% You can customize the appearance of the citation by redefining
% |\printscrcite|, which accepts the citation text as its argument.
% For example, to cause citations to be printed in roman italics font, define:
%
% \begin{codeblock}
% |\renewcommand{\printscrcite}[1]{\rmfamily\it#1}|
% \end{codeblock}
%
% \subsection{Conditional Blocks}\label{sec:conditionals}
%
% Conditional macros allow certain material to be included in some books but
% not others.
% For example, a musician's chord book might include extra verses with
% alternate chordings.
%
% \DescMacroGroup{if}{if...}{ifchorded,iflyric,ifslides,ifpartiallist,ifsongindexes,ifmeasures,ifrawtext,iftranscapos,ifnolyrics,ifpagepreludes,ifvnumbered}
% A conditional block begins with a macro named |\if|\Meta{type}, where
% \Meta{type} is one of the types listed in the first column of
% Table~\ref{tab:conditionals}.
% \begin{table}
% \newcommand\tablerule{\noalign{\hrule}}
% \newlength\oldbaselineskip \oldbaselineskip\baselineskip
% \newlength\oldlineskip \oldlineskip\lineskip
% \newdimen\oldlineskiplimit \oldlineskiplimit\lineskiplimit
% \newcommand\oninterlineskip{%
%   \baselineskip\oldbaselineskip
%   \lineskip\oldlineskip
%   \lineskiplimit\oldlineskiplimit}
% \vbox{\offinterlineskip\hrule
% \halign{&\vrule#&\strut\quad#\hfil\quad&\vrule#&\quad\vtop{\oninterlineskip\hsize3.5in\leftskip0.25in\parindent-0.25in\indent\vrule height\ht\strutbox width0pt depth0pt#\vrule height0pt width0pt depth\dp\strutbox\par}\quad\cr
% height2pt&\omit&&\omit&\cr
% &\hfil{\large\strut Type}&&\hfil{\large\strut Processed only if\kern1pt$\ldots$}&\cr\tablerule
% height2pt&\omit&&\omit&\cr
% &|chorded|&&the \env{chorded} option is active&\cr\tablerule
% &|lyric|&&the \env{chorded} option is not active&\cr\tablerule
% &|slides|&&the \env{slides} option is active&\cr\tablerule
% &|partiallist|&&the \mac{includeonlysongs} macro is being used to extract
%   a partial list of songs&\cr\tablerule
% &|songindexes|&&the \env{noindexes} option is not active&\cr\tablerule
% &|measures|&&the \env{nomeasures} option is not active&\cr\tablerule
% &|rawtext|&&the \env{rawtext} option is active&\cr\tablerule
% &|transcapos|&&the \env{transposecapos} option is active&\cr\tablerule
% &|nolyrics|&&the \mac{nolyrics} macro is in effect&\cr\tablerule
% &|pagepreludes|&&the \mac{pagepreludes} macro is in effect&\cr\tablerule
% &|vnumbered|&&the current verse is numbered (i.e., it was started
%   with \mac{beginverse} instead of \mac{beginverse}|*|)&\cr}
% \hrule}
% \caption{Conditional macros}\label{tab:conditionals}
% \end{table}
% The conditional block concludes with the macro |\fi|.
% Between the |\if|\Meta{type} and the |\fi| may also appear an |\else|.
% For example, in the construction
%
% \begin{codeblock}
% |\ifchorded|
% \quad\Meta{A}
% |\else|
% \quad\Meta{B}
% |\fi|
% \end{codeblock}
%
% \noindent
% material \Meta{A} is only included if the \env{chorded} option is active,
% and material \Meta{B} is only included if the \env{chorded} option is not
% active.
%
% \subsection{Page Layout}\label{sec:layout}
%
% \DescMacro{songcolumns}
% The number of columns per page can be set with |\songcolumns|.
% For example, to create 3 columns per page, write
%
% \begin{codeblock}
% |\songcolumns{3}|
% \end{codeblock}
%
% \noindent
% The number of columns should only be changed outside of \env{songs}
% environments.
%
% Setting the number of columns to zero disables the page-building algorithm
% entirely.
% This can be useful if you want to use an external package, such as
% |multicol| or \LaTeX's built-in |\twocolumn| macro, to build pages.
% For example, the following sets up an environment that is suitable for
% a lyric book that uses |\twocolumn|:
%
% \begin{codeblock}
% |\songcolumns{0}|
% |\flushbottom|
% |\twocolumn[\LARGE\centering My Songs]|
% |\begin{|\env{songs}|}{}|
% $\vdots$
% |\end{|\env{songs}|}|
% \end{codeblock}
%
% \noindent
% When disabling the page-builder, please note the following potential
% issues:
%
% \begin{itemize}
% \item The \mac{repchoruses} feature does not work when the page-builder
% is disabled because the page-builder is responsible for inserting
% repeated choruses as new columns are formed.
% \item External page-building packages tend to allow column- and
% page-breaks within songs because they have no mechanism for moving an
% entire song to the next column or page to avoid such a break
% (see \mac{songpos} below).
% \item Indexes produced with \mac{showindex} are typeset to the width of
% the enclosing environment.
% Thus, you should be sure to reset \LaTeX{} back to one column (via
% |\onecolumn|) before executing \mac{showindex}.
% \end{itemize}
%
% \DescMacro{pagepreludes}
% Song preludes (i.e., the material atop each song, including the title) are
% typeset by default at column width.
% Writing |\pagepreludes| typesets subsequent preludes at page width atop
% fresh pages, with the rest of the song in multiple columns beneath its title.
% (To prohibit separation of songs from their preludes, it also sets
% \mac{songpos} to 0.)
%
% \DescMacro{columnsep}
% The horizontal distance between consecutive columns is controlled by
% the |\columnsep| dimension.
% For example, to separate columns by 1 centimeter of space, write
%
% \begin{codeblock}
% |\columnsep=1cm|
% \end{codeblock}
%
% \DescMacro{colbotglue}
% When \LaTeX{} ends each column it inserts glue equal to |\colbotglue|.
% In lyric books this macro is set to |0pt| so that each column ends flush with
% the bottom of the page.
% In other books that have ragged bottoms, it is set to stretchable
% glue so that columns end at whatever vertical position is convenient.
% The recommended setting for typsetting columns with ragged bottoms is:
%
% \begin{codeblock}
% |\renewcommand{\colbotglue}{0pt plus .5\textheight minus 0pt}|
% \end{codeblock}
%
% \DescMacro{lastcolglue}
% The last column in a \env{songs} environment gets |\lastcolglue| appended
% to it instead.
% By default it is infinitely stretchable so that the last column ends
% at its natural height.
% By setting it to |0pt|, you can force the last column to be flush with
% the bottom of the page:
%
% \begin{codeblock}
% |\renewcommand{\lastcolglue}{0pt}|
% \end{codeblock}
%
% \DescMacro{songpos}
% The \Songs{} package uses a song-positioning algorithm that
% moves songs to the next column or page in order to avoid column- or
% page-breaks within songs.
% The algorithm has four levels of aggressiveness, numbered from 0 to 3.
% You can change the aggressiveness level by typing
%
% \begin{codeblock}
% |\songpos{|\Meta{level}|}|
% \end{codeblock}
%
% \noindent
% The default level is 3, which avoids column-breaks, page-breaks,
% and page-turns within songs whenever possible.
% (Page-turns are page-breaks after odd-numbered pages in two-sided documents,
% or after all pages in one-sided documents.)
% Level 2 avoids page-breaks and page-turns but allows column-breaks within
% songs.
% Level 1 avoids only page-turns within songs.
% Level 0 turns off the song-positioning algorithm entirely.
% This causes songs to be positioned wherever \TeX{} thinks is best
% based on penalty settings (see \mac{vvpenalty} and \mac{spenalty}).
%
% \DescMacro{spenalty}
% The value of |\spenalty| controls the undesirability of column breaks
% at song boundaries.
% Usually it should be set to a value between 0 and \mac{vvpenalty} so that
% breaks between songs are preferable to breaks between verses within a song.
% By default it is set to 100.
% When it is $-10000$ or less, breaks between songs are required, so that
% each song always begins a fresh column.
%
% \subsection{Indexes}\label{sec:idxcust}
%
% \subsubsection{Index Appearance}
%
% \paragraph{Index Titles.}
% To customize the appearance of index titles, redefine the \mac{songsection}
% and/or \mac{songchapter} macros from \S\ref{sec:sectioning}.
% For example, to use \LaTeX's built-in |\section| and |\chapter| macros
% instead, you could write:
%
% \begin{codeblock}
% |\renewcommand{|\mac{songchapter}|}{\chapter}|
% |\renewcommand{|\mac{songsection}|}{\section}|
% \end{codeblock}
%
% \paragraph{Layout and page divisions.}
% \DescMacro{sepindexestrue}
% \DescMacro{sepindexesfalse}
% Indexes are by default typeset on separate pages, and when an index is
% sufficiently small, it is centered on the page in one column.
% To disable these defaults, write |\sepindexesfalse|.
% This causes indexes to avoid using unnecessary vertical space or
% starting unnecessary new pages.
% To re-enable the defaults, use |\sepindexestrue|.
%
% \DescMacro{idxheadwidth}
% The |\idxheadwidth| length defines the width of the shaded boxes that
% begin each alphabetic block of a large title index.
% Setting it to 0pt suppresses the boxes entirely.
% For example, to set the width of those boxes to 1 centimeter, you could
% define
%
% \begin{codeblock}
% |\setlength{\idxheadwidth}{1cm}|
% \end{codeblock}
%
% \paragraph{Fonts and colors.}
% \DescMacro{idxrefsfont}
% To control the formatting of the list of references on the right-hand side
% of index entries, redefine |\idxrefsfont|.
% For example, to typeset each list in boldface, write
%
% \begin{codeblock}
% |\renewcommand{\idxrefsfont}{\bfseries}|
% \end{codeblock}
%
% \DescMacro{idxtitlefont}
% \DescMacro{idxlyricfont}
% Title indexes contain entries for song titles and also entries for notable
% lines of lyrics.
% The fonts for these entries are controlled by |\idxtitlefont| and
% |\idxlyricfont|, respectively.
% For example, to show title entries in boldface sans-serif and lyric entries
% in regular roman font, one could define:
%
% \begin{codeblock}
% |\renewcommand{\idxtitlefont}{\sffamily\bfseries}|
% |\renewcommand{\idxlyricfont}{\rmfamily\mdseries}|
% \end{codeblock}
%
% \DescMacro{idxheadfont}
% To change the font used to typeset the capital letters that start each
% alphabetic section of a large title index, redefine |\idxheadfont|.
% For example, to typeset those letters in italics instead of boldface, type
%
% \begin{codeblock}
% |\renewcommand{\idxheadfont}{\sffamily\it\LARGE}|
% \end{codeblock}
%
% \DescMacro{idxbgcolor}
% To change the background color of the shaded boxes that contain the
% capital letters that start each alphabetic sectino of a large title
% index, redefine |\idxbgcolor|.
% For example:
%
% \begin{codeblock}
% |\renewcommand{\idxbgcolor}{red}|
% \end{codeblock}
%
% \DescMacro{idxauthfont}
% The font used to typeset entries of an author index is controlled by
% |\idxauthfont|.
% For example, to typeset such entries in italics instead of boldface, type
%
% \begin{codeblock}
% |\renewcommand{\idxauthfont}{\small\it}|
% \end{codeblock}
%
% \DescMacro{idxscripfont}
% The font used to typeset entries of a scripture index is controlled by
% |\idxscripfont|.
% For example, to typeset such entries in boldface instead of italics, type
%
% \begin{codeblock}
% |\renewcommand{\idxscripfont}{\sffamily\small\bfseries}|
% \end{codeblock}
%
% \DescMacro{idxbook}
% To control the formatting of the lines that start each new book of the
% bible in a scripture index, redefine |\idxbook|, which accepts the book
% name as its single argument.
% For example, to typeset each book name in a box, one could define
%
% \begin{codeblock}
% |\renewcommand{\idxbook}[1]{\framebox{\small\bfseries#1}}|
% \end{codeblock}
%
% \DescMacro{idxcont}
% In a scripture index, when a column break separates a block of entries
% devoted to a book of the bible, the new column is titled
% ``\Meta{bookname} (continued)'' by default.
% You can change this default by redefining the |\idxcont| macro, which
% receives the \Meta{bookname} as its single argument.
% For example, to typeset an index in German, one might define
%
% \begin{codeblock}
% |\renewcommand{\idxcont}[1]{\small\textbf{#1} (fortgefahren)}|
% \end{codeblock}
%
% \subsubsection{Entry References}
%
% \DescMacro{indexsongsas}
% By default, the right-hand side of each index entry contains a list of
% one or more song numbers.
% To instead list page numbers, use the |\indexsongsas| macro:
%
% \begin{codeblock}
% |\indexsongsas{|\Meta{id}|}{\thepage}|
% \end{codeblock}
%
% \noindent
% where \Meta{id} is the same identifier used in the \mac{newindex},
% \mac{newauthorindex}, or \mac{newscripindex} macro that created the index.
% The second argument must always be something that expands into raw text
% without any formatting, since this text gets output to auxiliary files that
% are lexographically sorted by the index-generation program.
% To go back to indexing songs by song number, use \mac{thesongnum} in place
% of |\thepage| in the above.
%
% \subsubsection{PDF Bookmarks and Links}
%
% \DescMacro{songtarget}
% \DescMacro{songlink}
% Each \mac{beginsong} environment adds a PDF bookmark (if generating a PDF)
% and hyperlink target (if using the |hyperref| package) for the
% song by invoking |\songtarget| with two arguments:
% (1) a suggested PDF bookmark level, and (2) a link target name.
% Links in indexes to these targets are created by |\songlink|, which
% also gets two arguments:
% (1) the link target name (same as the second argument to \mac{songtarget}),
% and (2) the text to be linked.
%
% Redefine these macros to customize or suppress these bookmarks, targets,
% and links.
% For example, to enable both bookmarks and links (the default behavior) use:
%
% \begin{codeblock}
% |\renewcommand{\songtarget}[2]|
% |  {\pdfbookmark[#1]{|\mac{thesongnum}|. |\mac{songtitle}|}{#2}}|
% |\renewcommand{\songlink}[2]{\hyperlink{#1}{#2}}|
% \end{codeblock}
%
% \noindent
% To enable links but not bookmarks, use:
%
% \begin{codeblock}
% |\renewcommand{\songtarget}[2]{\hypertarget{#2}{\relax}}|
% |\renewcommand{\songlink}[2]{\hyperlink{#1}{#2}}|
% \end{codeblock}
%
% \noindent
% To disable both bookmarks and links, use:
%
% \begin{codeblock}
% |\renewcommand{\songtarget}[2]{}|
% |\renewcommand{\songlink}[2]{#2}|
% \end{codeblock}
%
% \subsubsection{Sort Order}
%
% The alphabetic ordering of entries in title and author indexes is dictated
% by the computer system on which the \Songs{} software is installed.
% Different languages and regions have different sorting conventions, so the
% |songidx| Lua script delegates decisions about order to your operating system.
% If the default ordering proves inadequate, you can modify it by changing your
% operating system's \emph{locale} (see your system's local help files).
% Alternatively, you can explicitly tell the |songidx| program which locale to
% use in one of three ways:
%
% \begin{itemize}
% \item \emph{Windows:}
% Edit the |generate.bat| file in the |Sample| folder (or your working folder)
% with any plain text editor (e.g., Vim or Notepad).
% Near the top, find the line that says |SET locale=|.
% After the |=|, type any valid locale name.
% For a list of valid locale names on Windows, please see the ``Language name
% abbreviation'' column of Microsoft's online National Language Support (NLS)
% API Reference:
%
% {\centering\url{http://msdn.microsoft.com/en-us/goglobal/bb896001.aspx}\par}
%
% \item \emph{Unix:}
% Create an environment variable named |SONGIDX_LOCALE| and set it equal to
% the desired locale name.
% The command |locale -a| lists all valid locale names on most Unix systems.
%
% \item \emph{Command-line:}
% If you are executing the |songidx| script manually, use the |-l| option to
% specify the locale:
%
% \begin{codeblock}
% |texlua songidx -l sv_SE myindex.sxd myindex.sbx|
% \end{codeblock}
%
% \end{itemize}
%
% \subsubsection{Special Words In Song Info}
%
% The following macros control how certain keywords are treated when parsing
% and sorting index entries.
% They only affect indexes that have already been declared, so put them
% strictly after all your index creation commands (see \S\ref{sec:indexes}).
%
% \DescMacro{titleprefixword}
% In English, when a title begins with ``The'' or ``A'', it is traditional to
% move these words to the end of the title and sort the entry by the following
% word.
% So for example, ``The Song Title'' is typically indexed as
% ``Song Title, The''.
% To change this default behavior, you can use |\titleprefixword| in the
% document preamble to identify each word to be moved to the end whenever
% it appears as the first word of a title index entry.
% For example, to cause the word ``I'' to be moved to the end of title index
% entries, one could say,
%
% \begin{codeblock}
% |\titleprefixword{I}|
% \end{codeblock}
%
% \noindent
% The first use of |\titleprefixword| overrides the defaults, so if you also
% want to continue to move ``The'' and ``A'' to the end of entries, you must
% also say |\titleprefixword{The}| and |\titleprefixword{A}| explicitly.
% This macro may only be used in the document preamble but may be used
% multiple times to declare multiple prefix words.
%
% \DescMacro{authsepword}
% When parsing author index entries, the word ``and'' is recognized by the
% |songidx| script as a conjunctive that separates author names.
% To override this default and specify a different conjunctive, use the
% |\authsepword| macro one or more times in the document preamble.
% For example, to instead treat ``und'' as a conjunctive, you could say,
%
% \begin{codeblock}
% |\authsepword{und}|
% \end{codeblock}
%
% \noindent
% The first use of |\authsepword| and each of the following macros overrides
% the default, so if you also want to continue to treat ``and'' as a
% conjunctive, you must also say |\authsepword{and}| explicitly.
%
% \DescMacro{authbyword}
% When parsing author index entries, the word ``by'' is recognized as a
% keyword signaling that the index entry should only include material
% in the current list item that follows the word ``by''.
% So for example, ``Music by J.S. Bach'' is indexed as ``Bach, J.S.''
% rather than ``Bach, Music by J.S.''
% To recognize a different word instead of ``by'', you can use |\authbyword|
% in the document preamble.
% For example, to recognize ``durch'' instead, you could say
%
% \begin{codeblock}
% |\authbyword{durch}|
% \end{codeblock}
%
% \DescMacro{authignoreword}
% When parsing author index entries, if a list item contains the word
% ``unknown'', that item is ignored and is not indexed.
% This prevents items like ``Composer unknown'' from being indexed as names.
% To cause the indexer to recognize and ignore a different word, you can
% use the |\authignoreword| macro in the document preamble.
% For example, to ignore author index entries containing the word
% ``unbekannt'', you could say,
%
% \begin{codeblock}
% |\authignoreword{unbekannt}|
% \end{codeblock}
%
% \subsection{Page Headers and Footers}
%
% In \LaTeX, page headers and footers are defined using a system of
% invisible \emph{marks} that get inserted into the document at the
% beginning of each logical unit of the document (e.g., each section, song,
% verse, and chorus).
% The headers and footers are then defined so as to refer to the first
% and/or last invisible mark that ends up on each page once the document
% is divided into pages.
% This section describes the marks made available by the \Songs{} package.
% For more detailed information about the marks already provided by
% \LaTeX{} and how to use them, consult any \LaTeX{} user manual.
%
% \DescMacro{songmark}
% \DescMacro{versemark}
% \DescMacro{chorusmark}
% To add song information to page headings and footers, redefine |\songmark|,
% |\versemark|, or |\chorusmark| to add the necessary \TeX{} marks to the
% current page whenever a new song, verse, or chorus begins.
% These macros expect no arguments; to access the current song's
% information including titles, use the macros documented in
% \S\ref{sec:songinfo}.
% To access the current song's number or the current verse's number, use
% \mac{thesongnum} or \mac{theversenum} (see \S\ref{sec:numbering}).
% For example, to include the song number in the page headings produced by
% \LaTeX's |\pagestyle{myheadings}| feature, you could redefine |\songmark|
% as follows:
%
% \begin{codeblock}
% |\renewcommand{\songmark}{\markboth{|\mac{thesongnum}|}{|\mac{thesongnum}|}}|
% \end{codeblock}
%
% \subsection{Defining New Beginsong Keyvals}\label{sec:newkey}
%
% \DescMacro{newsongkey}
% The \mac{beginsong} macro supports several optional keyval parameters for
% declaring song information, including \env{by=}, \env{sr=}, and \env{cr=}.
% Users can define their own additional keyvals as well.
% To do so, use the |\newsongkey| macro, which has the syntax
%
% \begin{codeblock}
% |\newsongkey{|\Meta{keyname}|}{|\Meta{initcode}|}[|\Meta{default}|]{|\Meta{setcode}|}|
% \end{codeblock}
%
% \noindent
% Here, \Meta{keyname} is the name of the new key for the keyval,
% \Meta{initcode} is \LaTeX{} code that is executed at the start of each
% \mac{beginsong} line before the \mac{beginsong} arguments are processed,
% \Meta{default} (if specified) is the default value used for the keyval when
% \Meta{keyname} appears in \mac{beginsong} without a value,
% and \Meta{setcode} is macro code that is executed whenever
% \Meta{key} is parsed as part of the \mac{beginsong} keyval arguments.
% In \Meta{setcode}, |#1| expands to the value given by the user for the
% keyval (or to \Meta{default} if no value was given).
%
% For example, to define a new song key called |arr| which stores its
% value in a macro called |\arranger|, one could write:
%
% \begin{codeblock}
% |\newcommand{\arranger}{}|
% |\newsongkey{arr}{\def\arranger{}}|
% |                {\def\arranger{Arranged by #1\par}}|
% \end{codeblock}
%
% \noindent
% Then one could redefine \mac{extendprelude} to print the arranger below the
% other song header information:
%
% \begin{codeblock}
% |\renewcommand{\extendprelude}{|
% |  |\mac{showrefs}\mac{showauthors}
% |  {\bfseries\arranger}|
% |}|
% \end{codeblock}
%
% \noindent
% A \mac{beginsong} line could then specify the song's arranger as follows:
%
% \begin{codeblock}
% \mac{beginsong}|{The Title}[arr={R. Ranger}]|
% $\vdots$
% \mac{endsong}
% \end{codeblock}
%
% \noindent This produces
%
% \begin{sample}
%  \setcounter{songnum}{1}%
%  \vskip1pt%
%  \newcommand\arranger{}%
%  \newsongkey{arr}{\def\arranger{}}%
%                  {\def\arranger{Arranged by #1\par}}%
%  \renewcommand{\extendprelude}{
%    \showrefs\showauthors
%    {\bfseries\arranger}
%  }%
%  \beginsong{The Title}[arr={R. Ranger}]
%  \endsong
%  \renewcommand{\extendprelude}{}%
% \end{sample}
%
% For more detailed information about keyvals and how they work, consult the
% documentation for David Carlisle's |keyval| package, which comes standard
% with most \LaTeXe{} installations.
%
% \subsection{Font Kerning Corrections}
%
% \paragraph{Chord Overstriking.}
% In order to conserve space and keep songs readable, the \Songs{} package
% pushes chords down very close to the lyrics with which they are paired.
% Unfortunately, this can sometimes cause low-hanging characters in chord
% names to overstrike the lyrics they sit above.
% For example,
%
% \example|\[(Gsus4/D)]Overstrike|\produces{\[(Gsus4/D)]Overstrike}
% \eat\]
%
% \noindent
% Note that the parentheses and slash symbols in the chord name have
% invaded the lyric that sits beneath them.
%
% \DescMacro{chordlocals}
% The best solution to this problem is to use a font for chord names that
% minimizes low-hanging symbols; but if you lack such a font, then the
% following trick works pretty well.
% Somewhere in the preamble of your document, you can write the following
% \LaTeX{} code:
%
% \begin{codeblock}
% |\renewcommand{\chordlocals}{\catcode`(\active|
% |                            \catcode`)\active|
% |                            \catcode`/\active}|
% |\newcommand{\smraise}[1]{\raise2pt\hbox{\small#1}}|
% |\newcommand{\myslash}{\smraise/}|
% |\newcommand{\myopenparen}{\smraise(|\eat)|}|
% |\newcommand{\mycloseparen}{\smraise)}|
% |{\chordlocals|
% | \global\let(\myopenparen|
% | \global\let)\mycloseparen|
% | \global\let/\myslash}|
% \end{codeblock}
%
% \noindent
% This sets the |/|, |(|, and |)| symbols as active characters whenever they
% appear within chord names.
% \ImplOrDesc
%   {(See \S\ref{sec:chordlocals} for documentation of the
%    \texttt{\string\chordlocals} hook.)}
%   {(Recompile this documentation to include the implementation section
%    for more information about the \texttt{\string\chordlocals} macro.)}
% Each active character is defined so that it produces a smaller, raised
% version of the original symbol.
% The result is as follows:
%
% \renewcommand{\chordlocals}{\catcode`(\active
%                             \catcode`)\active
%                             \catcode`/\active}
% \newcommand{\smraise}[1]{\raise2pt\hbox{\small#1}}
% \newcommand{\myslash}{\smraise/}
% \newcommand{\myopenparen}{\smraise(}
% \newcommand{\mycloseparen}{\smraise)}
% {\chordlocals
%  \global\let(\myopenparen
%  \global\let)\mycloseparen
%  \global\let/\myslash}
% 
% \example|\[(Gsus4/D)]Overstrike (fixed)|\produces{\[(Gsus4/D)]Overstrike (fixed)}
% \eat\]
%
% \renewcommand\chordlocals{}
%
% \noindent
% As you can see, the low-hanging symbols have been elevated so that they
% sit above the baseline, correcting the overstrike problem.
%
% \paragraph{Scripture Font Quotation Marks.}
% \DescMacro{shiftdblquotes}
% The \Songs{} package compensates for a kerning problem in the Zaph Chancery
% font (used to typeset scripture quotations) by redefining the |``| and |''|
% token sequences to be active characters that yield double-quotes shifted
% 1.1 points and 2 points left, respectively, of their normal positions.
% If you use a different font size for scripture quotations, then you can use
% the |\shiftdblquotes| macro when redefining \mac{scripturefont} to change
% this kerning correction.
% For example,
%
% \begin{codeblock}
% |\renewcommand{|\mac{scripturefont}|}{|
% |  \usefont{OT1}{pzc}{mb}{it}|
% |  \shiftdblquotes{-1pt}{-2pt}{-3pt}{-4pt}|
% |}|
% \end{codeblock}
%
% \noindent
% removes 1 point of space to the left and 2 points of space to the
% right of left-double-quote characters, and 3 points to the left and 4 points
% to the right of right-double-quotes, within scripture quotations.
%
% \section{Informational Macros}\label{sec:songinfo}
%
% The macros described in this section can be used to retrieve information
% about the current song.
% This can be used when redefining \mac{extendprelude}, \mac{extendpostlude},
% \mac{makeprelude}, \mac{makepostlude}, \mac{songmark}, \mac{versemark}, or
% \mac{chorusmark}, or any other macros that might typeset this information.
%
% \DescMacro{songauthors}
% To get the current song's list of authors (if any) use |\songauthors|.
% This yields the value of the \env{by=} key used in the \mac{beginsong}
% line.
%
% \DescMacro{songrefs}
% To get the current song's list of scripture references (if any) use
% |\songrefs|.
% This yields the value of the \env{sr=} key used in the \mac{beginsong}
% line, but modified with hyphens changed to en-dashes and spaces falling
% within a list of verse numbers changed to thin spaces for better
% typesetting.
% In addition, various penalties have been added to inhibit line breaks
% in strange places and encourage line breaks in others.
%
% \DescMacro{songcopyright}
% To get the current song's copyright info (if any), use |\songcopyright|.
% This yields the value of the \env{cr=} key used in the \mac{beginsong} line.
%
% \DescMacro{songlicense}
% To get the current song's licensing information (if any), use
% |\songlicense|.
% This yields the value of the \env{li=} key used in the \mac{beginsong}
% line, or whatever text was declared with \mac{setlicense}.
%
% \DescMacro{songtitle}
% The |\songtitle| macro yields the current song's title.
% By default this is the first title provided in the \mac{beginsong} line.
% The \mac{nexttitle} and \mac{foreachtitle} macros (see below) cause it
% to be set to the current song's other titles, if any.
%
% \DescMacro{resettitles}
% To get the current song's primary title (i.e., the first title specified
% in the song's \mac{beginsong} line), execute |\resettitles|.
% This sets the |\songtitle| macro to be the song's primary title.
%
% \DescMacro{nexttitle}
% To get the song's next title, execute |\nexttitle|, which
% sets |\songtitle| to be the next title in the song's list of titles
% (or sets |\songtitle| to |\relax| if there are no more titles).
%
% \DescMacro{foreachtitle}
% The |\foreachtitle| macro accepts \LaTeX{} code as its single
% argument and executes it once for each (remaining) song title.
% Within the provided code, use |\songtitle| to get the current title.
% For example, the following code generates a comma-separated list of all
% of the current song's titles:
%
% \begin{codeblock}
% \mac{resettitles}
% \mac{songtitle}
% \mac{nexttitle}
% |\foreachtitle{, |\mac{songtitle}|}|
% \end{codeblock}
%
% \DescMacro{songlist}
% When \mac{includeonlysongs} is used to extract a partial list of songs, the
% |\songlist| macro expands to the comma-separated list of songs that is being
% extracted.
% Redefining |\songlist| within the document preamble alters the list of
% songs to be extracted.
% Redefining it after the preamble may have unpredictable results.
%
% \section{Other Resources}
%
% There are a number of other \LaTeX{} packages available for typesetting
% songs, tablature diagrams, or song books.
% Probably the best of these is the \Rath{} package by Christopher Rath
% (\href{http://rath.ca/Misc/Songbook/}{{\tt http://rath.ca/Misc/Songbook/}}).
% Most of the differences between other packages and this one are intentional;
% the following is a summary of where I've adopted various differing design
% decisions and why.
%
% \bigskip
%
% \paragraph{Ease of Song Entry.}
% Much of the \Songs{} package programming is devoted to easing the burden of
% typing chords.
% With most \LaTeX{} song book packages the user types chords using a standard
% \LaTeX{} macro syntax like |\chord{|\Meta{chord}|}{|\Meta{lyric}|}|.
% The \Songs{} package uses a less conventional
% |\[|\Meta{chord}|]|\Meta{lyric}\eat\] syntax for several
% reasons detailed below.
%
% First, macros in the standard \LaTeX{} syntax require more key-presses
% than macros in the \Songs{} package's syntax.
% This can become become very taxing when typing up a large book.
% Chords often appear as frequently as one per syllable, especially in hymns,
% so keeping the syntax as brief as possible is desirable.
%
% Second, the standard \LaTeX{} macro syntax requires the user to estimate how
% much of the \Meta{lyric} will lie below the chord (because the \Meta{lyric}
% part must be enclosed in braces) whereas the \Songs{} package's syntax does
% not.
% Estimating this accurately can be quite difficult, since in many cases the
% \Meta{lyric} part must include punctuation or multiple words to get proper
% results.
% The \Songs{} package automates this for the user, significantly easing the
% task of chord-entry.
%
% Third, unlike the standard \LaTeX{} chord syntax, the \Songs{} package's
% syntax handles all hyphenation of chorded lyrics fully automatically.
% Extra hyphenation must be introduced in chord books wherever a chord
% is wider than the syllable it sits above.
% With the standard \LaTeX{} chord syntax such hyphenation must be
% introduced manually by the user (usually via a special hyphenation macro),
% but the \Songs{} package does this automatically.
%
% Fourth and finally, some other packages allow the user to use ``|b|''
% in a \Meta{chord} to produce a flat symbol, whereas the \Songs{} package
% requires an ``|&|'' instead.
% Using ``|b|'' is more intuitive but prevents the
% use of ``|b|'' for any other purpose within a \Meta{chord}, such as to
% produce a literal ``b'' or to type another macro name like |\hbox| that
% contains a ``b''.
% Consequently, the \Songs{} package uses the less obvious ``|&|'' symbol to
% produce flat symbols.
%
% \paragraph{Song Structure.}
% The \Songs{} package provides a relatively small number of macros for
% typesetting high-level song structure, including verses, choruses,
% textual comments, and conditional macros that indicate that certain sections
% should go in chord books but not lyric books.
% These can be combined to typeset more sophisticated structures such as
% intros, bridges, brackets, endings, and the like.
% This is done in lieu of providing a specific macro for each of these
% structures since it results in greater flexibility and fewer macros for
% users to learn.
%
% \paragraph{Multiple columns.}
% The \Songs{} package was designed from the ground up to produce song books
% with many songs per page, arranged in multiple columns.
% As a result, it includes elaborate support for many features not found in
% most other packages, such as automatic column balancing, completely
% customizable song header and song footer blocks, and facilities for adding
% beautiful scripture quotations to fill in gaps between songs.
%
% \paragraph{Indexes.}
% Another major feature of the \Songs{} package is its support for a variety
% of different index types, most notably indexes arranged by scripture
% reference.
% Scripture indexes can be invaluable for planning services around particular
% sermons or topics.
% The \Songs{} package allows book authors to specify the names and preferred
% ordering of books of the bible, and automatically handles complex issues
% like overlapping verse ranges to produce an easy-to-read, compact, and
% well-ordered index.
% Other supported indexes include those sorted by author, by title, and by
% notable lines of lyrics.
%
% \paragraph{Automatic Transposition.}
% The \Songs{} package has a facility for automatically transposing songs, and
% even generating chord books that print the chords in multiple keys (e.g., so
% that a pianist and guitarist using a capo can play together from the same
% book).
%
% \bigskip
%
% The \Songs{} package was developed entirely independently of all other
% \LaTeX{} song book packages.
% I originally developed the set of \LaTeX{} macros that eventually became
% the \Songs{} package in order to typeset a song book for the Graduate
% Christian Fellowship (GCF) at Cornell University, and the Cornell
% International Christian Fellowship (CICF).
% Once I had fine-tuned my package to be sufficiently versatile, I decided
% to release it for public use.
% At that time I noticed the \Rath{} package and others, and wrote this
% summary of the most prominent differences.
%
% For information on more song-typesetting resources for \LaTeX, I recommend
% consulting the documentation provided with the \Rath{} package.
% It includes an excellent list of other resources that might be of interest
% to creators of song books.
%
% \section{GNU General Public License}\label{sec:license}
%
% \begingroup\small
%
% \begin{center}
% {\large\sc Terms and Conditions For \\ Copying, Distribution and Modification}
% \end{center}
%
% \begin{enumerate}\addtocounter{enumi}{-1}
%
% \item 
%
% This License applies to any program or other work which contains a notice
% placed by the copyright holder saying it may be distributed under the
% terms of this General Public License.  The ``Program'', below, refers to
% any such program or work, and a ``work based on the Program'' means either
% the Program or any derivative work under copyright law: that is to say, a
% work containing the Program or a portion of it, either verbatim or with
% modifications and/or translated into another language.  (Hereinafter,
% translation is included without limitation in the term ``modification''.)
% Each licensee is addressed as ``you''.
%
% Activities other than copying, distribution and modification are not
% covered by this License; they are outside its scope.  The act of
% running the Program is not restricted, and the output from the Program
% is covered only if its contents constitute a work based on the
% Program (independent of having been made by running the Program).
% Whether that is true depends on what the Program does.
%
% \item You may copy and distribute verbatim copies of the Program's source
%   code as you receive it, in any medium, provided that you conspicuously
%   and appropriately publish on each copy an appropriate copyright notice
%   and disclaimer of warranty; keep intact all the notices that refer to
%   this License and to the absence of any warranty; and give any other
%   recipients of the Program a copy of this License along with the Program.
%
% You may charge a fee for the physical act of transferring a copy, and you
% may at your option offer warranty protection in exchange for a fee.
%
% \item
%
% You may modify your copy or copies of the Program or any portion
% of it, thus forming a work based on the Program, and copy and
% distribute such modifications or work under the terms of Section~1
% above, provided that you also meet all of these conditions:
%
% \begin{enumerate}
%
% \item 
%
% You must cause the modified files to carry prominent notices stating that
% you changed the files and the date of any change.
%
% \item
%
% You must cause any work that you distribute or publish, that in
% whole or in part contains or is derived from the Program or any
% part thereof, to be licensed as a whole at no charge to all third
% parties under the terms of this License.
%
% \item
% If the modified program normally reads commands interactively
% when run, you must cause it, when started running for such
% interactive use in the most ordinary way, to print or display an
% announcement including an appropriate copyright notice and a
% notice that there is no warranty (or else, saying that you provide
% a warranty) and that users may redistribute the program under
% these conditions, and telling the user how to view a copy of this
% License.  (Exception: if the Program itself is interactive but
% does not normally print such an announcement, your work based on
% the Program is not required to print an announcement.)
%
% \end{enumerate}
%
% These requirements apply to the modified work as a whole.  If
% identifiable sections of that work are not derived from the Program,
% and can be reasonably considered independent and separate works in
% themselves, then this License, and its terms, do not apply to those
% sections when you distribute them as separate works.  But when you
% distribute the same sections as part of a whole which is a work based
% on the Program, the distribution of the whole must be on the terms of
% this License, whose permissions for other licensees extend to the
% entire whole, and thus to each and every part regardless of who wrote it.
%
% Thus, it is not the intent of this section to claim rights or contest
% your rights to work written entirely by you; rather, the intent is to
% exercise the right to control the distribution of derivative or
% collective works based on the Program.
%
% In addition, mere aggregation of another work not based on the Program
% with the Program (or with a work based on the Program) on a volume of
% a storage or distribution medium does not bring the other work under
% the scope of this License.
%
% \item
% You may copy and distribute the Program (or a work based on it,
% under Section~2) in object code or executable form under the terms of
% Sections~1 and~2 above provided that you also do one of the following:
%
% \begin{enumerate}
%
% \item
%
% Accompany it with the complete corresponding machine-readable
% source code, which must be distributed under the terms of Sections~1
% and~2 above on a medium customarily used for software interchange; or,
%
% \item
%
% Accompany it with a written offer, valid for at least three
% years, to give any third party, for a charge no more than your
% cost of physically performing source distribution, a complete
% machine-readable copy of the corresponding source code, to be
% distributed under the terms of Sections~1 and~2 above on a medium
% customarily used for software interchange; or,
%
% \item
%
% Accompany it with the information you received as to the offer
% to distribute corresponding source code.  (This alternative is
% allowed only for noncommercial distribution and only if you
% received the program in object code or executable form with such
% an offer, in accord with Subsection~b above.)
%
% \end{enumerate}
%
% The source code for a work means the preferred form of the work for
% making modifications to it.  For an executable work, complete source
% code means all the source code for all modules it contains, plus any
% associated interface definition files, plus the scripts used to
% control compilation and installation of the executable.  However, as a
% special exception, the source code distributed need not include
% anything that is normally distributed (in either source or binary
% form) with the major components (compiler, kernel, and so on) of the
% operating system on which the executable runs, unless that component
% itself accompanies the executable.
%
% If distribution of executable or object code is made by offering
% access to copy from a designated place, then offering equivalent
% access to copy the source code from the same place counts as
% distribution of the source code, even though third parties are not
% compelled to copy the source along with the object code.
%
% \item
% You may not copy, modify, sublicense, or distribute the Program
% except as expressly provided under this License.  Any attempt
% otherwise to copy, modify, sublicense or distribute the Program is
% void, and will automatically terminate your rights under this License.
% However, parties who have received copies, or rights, from you under
% this License will not have their licenses terminated so long as such
% parties remain in full compliance.
%
% \item
% You are not required to accept this License, since you have not
% signed it.  However, nothing else grants you permission to modify or
% distribute the Program or its derivative works.  These actions are
% prohibited by law if you do not accept this License.  Therefore, by
% modifying or distributing the Program (or any work based on the
% Program), you indicate your acceptance of this License to do so, and
% all its terms and conditions for copying, distributing or modifying
% the Program or works based on it.
%
% \item
% Each time you redistribute the Program (or any work based on the
% Program), the recipient automatically receives a license from the
% original licensor to copy, distribute or modify the Program subject to
% these terms and conditions.  You may not impose any further
% restrictions on the recipients' exercise of the rights granted herein.
% You are not responsible for enforcing compliance by third parties to
% this License.
%
% \item
% If, as a consequence of a court judgment or allegation of patent
% infringement or for any other reason (not limited to patent issues),
% conditions are imposed on you (whether by court order, agreement or
% otherwise) that contradict the conditions of this License, they do not
% excuse you from the conditions of this License.  If you cannot
% distribute so as to satisfy simultaneously your obligations under this
% License and any other pertinent obligations, then as a consequence you
% may not distribute the Program at all.  For example, if a patent
% license would not permit royalty-free redistribution of the Program by
% all those who receive copies directly or indirectly through you, then
% the only way you could satisfy both it and this License would be to
% refrain entirely from distribution of the Program.
%
% If any portion of this section is held invalid or unenforceable under
% any particular circumstance, the balance of the section is intended to
% apply and the section as a whole is intended to apply in other
% circumstances.
%
% It is not the purpose of this section to induce you to infringe any
% patents or other property right claims or to contest validity of any
% such claims; this section has the sole purpose of protecting the
% integrity of the free software distribution system, which is
% implemented by public license practices.  Many people have made
% generous contributions to the wide range of software distributed
% through that system in reliance on consistent application of that
% system; it is up to the author/donor to decide if he or she is willing
% to distribute software through any other system and a licensee cannot
% impose that choice.
%
% This section is intended to make thoroughly clear what is believed to
% be a consequence of the rest of this License.
%
% \item
% If the distribution and/or use of the Program is restricted in
% certain countries either by patents or by copyrighted interfaces, the
% original copyright holder who places the Program under this License
% may add an explicit geographical distribution limitation excluding
% those countries, so that distribution is permitted only in or among
% countries not thus excluded.  In such case, this License incorporates
% the limitation as if written in the body of this License.
%
% \item
% The Free Software Foundation may publish revised and/or new versions
% of the General Public License from time to time.  Such new versions will
% be similar in spirit to the present version, but may differ in detail to
% address new problems or concerns.
%
% Each version is given a distinguishing version number.  If the Program
% specifies a version number of this License which applies to it and ``any
% later version'', you have the option of following the terms and conditions
% either of that version or of any later version published by the Free
% Software Foundation.  If the Program does not specify a version number of
% this License, you may choose any version ever published by the Free Software
% Foundation.
%
% \item
% If you wish to incorporate parts of the Program into other free
% programs whose distribution conditions are different, write to the author
% to ask for permission.  For software which is copyrighted by the Free
% Software Foundation, write to the Free Software Foundation; we sometimes
% make exceptions for this.  Our decision will be guided by the two goals
% of preserving the free status of all derivatives of our free software and
% of promoting the sharing and reuse of software generally.
%
% \begin{center}
% {\large\sc No Warranty}
% \end{center}
%
% \item
% {\sc Because the program is licensed free of charge, there is no warranty
% for the program, to the extent permitted by applicable law.  Except when
% otherwise stated in writing the copyright holders and/or other parties
% provide the program ``as is'' without warranty of any kind, either expressed
% or implied, including, but not limited to, the implied warranties of
% merchantability and fitness for a particular purpose.  The entire risk as
% to the quality and performance of the program is with you.  Should the
% program prove defective, you assume the cost of all necessary servicing,
% repair or correction.}
%
% \item
% {\sc In no event unless required by applicable law or agreed to in writing
% will any copyright holder, or any other party who may modify and/or
% redistribute the program as permitted above, be liable to you for damages,
% including any general, special, incidental or consequential damages arising
% out of the use or inability to use the program (including but not limited
% to loss of data or data being rendered inaccurate or losses sustained by
% you or third parties or a failure of the program to operate with any other
% programs), even if such holder or other party has been advised of the
% possibility of such damages.}
%
% \end{enumerate}
%
% \endgroup
%
% \StopEventually{\PrintIndex}
%
% \clearpage
% \section{Implementation}
%
% The following provides the verbatim implementation of the \Songs{} \LaTeX{} 
% package, along with commentary on how it works.
% In general, macro names that contain a |@| symbol are not intended to be
% directly accessible by the outside world; they are for purely internal use.
% All other macros are intended to be used or redefined by document authors.
%
% Most of the macros likely to be of real interest to song book authors can
% be found in \S\ref{sec:impparams}.
% To find the implementation of any particular macro, the index at the end
% of this document should prove helpful.
%
% The unwary \TeX er may wonder at the rather large size of the
% implementation.
% The volume and complexity of the code stems mainly from the following
% challenging features:
% \begin{itemize}
% \item Putting chords above lyrics fully automatically requires building an
% entire lyric-parser in \LaTeX{} (see \S\ref{sec:lyricscan}).
% \item Avoiding page-turns within songs without prohibiting column-breaks
% requires building a completely new page-breaking algorithm
% (see \S\ref{sec:pagebuilder}).
% \item The package must be able to generate a daunting number of document
% variants from a common source: lyric-only books, chorded books, digital
% slides, transparency slides, selected song subsets, transposed songs, and
% combinations of the above.
% This is like putting six or more packages into one.
% \item Song book indexes are far more complex than those for a prose book.
% See \S\ref{sec:indexgen} for some of the difficulties involved.
% \end{itemize}
%
% \subsection{Initialization}
%
% The code in this section detects any \TeX{} versioning or configuration
% settings that are relevant to the rest of the song book code.
%
% \begin{macro}{\ifSB@etex}
% Numerous enhancements are possible when using an $\varepsilon$-\TeX{}
% compatible version of \LaTeX.
% We start by checking to see whether $\varepsilon$-\TeX{} primitives are
% available.
%    \begin{macrocode}
\newif\ifSB@etex
\ifx\eTeXversion\undefined\else
  \ifx\eTeXversion\relax\else
    \SB@etextrue
    \ifx\e@alloc\@undefined
      \IfFileExists{etex.sty}{\RequirePackage{etex}}{}
    \fi
  \fi
\fi
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\ifSB@pdf}
% Detect whether we're generating a pdf file, since this affects the
% treatment of hyperlinks and bookmark indexes.
%    \begin{macrocode}
\newif\ifSB@pdf\SB@pdffalse
\IfFileExists{ifpdf.sty}{\RequirePackage{ifpdf}\ifpdf\SB@pdftrue\fi}{
  \ifx\pdfoutput\undefined\else
    \ifx\pdfoutput\relax\else
      \ifnum\pdfoutput<\@ne\else
        \SB@pdftrue
      \fi
    \fi
  \fi
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\ifSB@preamble}
% Some macros have different effects depending on when they're used in the
% preamble or in the document body, so we need a conditional that remembers
% whether we're still in the preamble.
% It gets initialized to true and later changed to false once the body begins.
%    \begin{macrocode}
\newif\ifSB@preamble
\SB@preambletrue
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\ifSB@test}
% \begin{macro}{\ifSB@testii}
% \begin{macro}{\SB@temp}
% \begin{macro}{\SB@tempii}
% \begin{macro}{\SB@tempiii}
% \begin{macro}{\SB@tempiv}
% \begin{macro}{\SB@tempv}
% Reserve some control sequence names for scratch use.
%    \begin{macrocode}
\newif\ifSB@test
\newif\ifSB@testii
\newcommand\SB@temp{}
\newcommand\SB@tempii{}
\newcommand\SB@tempiii{}
\newcommand\SB@tempiv{}
\newcommand\SB@tempv{}
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\SB@newcount}
% \begin{macro}{\SB@newdimen}
% \begin{macro}{\SB@newbox}
% \begin{macro}{\SB@newtoks}
% \begin{macro}{\SB@newwrite}
% Create macros for safely allocating count, dimen, box, token, and write
% registers with detection for name-clashes.
% For some reason, the default allocation macros provided by the \LaTeX{}
% kernel do not detect name-clashes(!), which means that packages that use them
% might accidentally overwrite our registers, causing all sorts of problems.
% But at least we can do our best to avoid overwriting their registers.
%    \begin{macrocode}
\newcommand\SB@newcount[1]{\@ifdefinable#1{\newcount#1}}
\newcommand\SB@newdimen[1]{\@ifdefinable#1{\newdimen#1}}
\newcommand\SB@newbox[1]{\@ifdefinable#1{\newbox#1}}
\newcommand\SB@newtoks[1]{\@ifdefinable#1{\newtoks#1}}
\newcommand\SB@newwrite[1]{\@ifdefinable#1{\newwrite#1}}
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\SB@dimen}
% \begin{macro}{\SB@dimenii}
% \begin{macro}{\SB@dimeniii}
% \begin{macro}{\SB@dimeniv}
% \begin{macro}{\SB@box}
% \begin{macro}{\SB@boxii}
% \begin{macro}{\SB@boxiii}
% \begin{macro}{\SB@toks}
% \begin{macro}{\SB@cnt}
% \begin{macro}{\SB@cntii}
% \begin{macro}{\SB@skip}
% Reserve some temp registers for various purposes.
%    \begin{macrocode}
\SB@newdimen\SB@dimen
\SB@newdimen\SB@dimenii
\SB@newdimen\SB@dimeniii
\SB@newdimen\SB@dimeniv
\SB@newbox\SB@box
\SB@newbox\SB@boxii
\SB@newbox\SB@boxiii
\SB@newtoks\SB@toks
\SB@newcount\SB@cnt
\SB@newcount\SB@cntii
\newlength\SB@skip
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\SB@envbox}
% Also reserve a slightly less volatile box register for per-environment use.
% In scripture environments it holds the scripture citation.
% In indexes it holds the index title text.
%    \begin{macrocode}
\SB@newbox\SB@envbox
%    \end{macrocode}
% \end{macro}
%
% Load David Carlisle's |keyval| package for processing
% \Meta{key}=\Meta{value} style macro arguments.
%    \begin{macrocode}
\RequirePackage{keyval}
%    \end{macrocode}
%
% \begin{macro}{\SB@app}
% Utility macro: Append some text to the definition of another macro.
%    \begin{macrocode}
\newcommand\SB@app[3]{%
  \expandafter#1\expandafter#2\expandafter{#2#3}%
}
%    \end{macrocode}
% \end{macro}
%
% \subsection{Default Parameters}\label{sec:impparams}
%
% This section defines macros and lengths that will typically be executed or
% redefined by the user in the document preamble to initialize the document.
% (Not all of these are restricted to preamble usage, however. Many can be used
% throughout the document to switch styles for different sections or different
% songs.)
%
% \begin{macro}{\lyricfont}\MainImpl{lyricfont}
% Define the font style to use for formatting song lyrics.
%    \begin{macrocode}
\newcommand\lyricfont{\normalfont\normalsize}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\stitlefont}\MainImpl{stitlefont}
% Define the font style to use for formatting song titles.
%    \begin{macrocode}
\newcommand\stitlefont{%
  \sffamily\ifslides\Huge\else\slshape\Large\fi%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\versefont}\MainImpl{versefont}
% \begin{macro}{\chorusfont}\MainImpl{chorusfont}
% \begin{macro}{\notefont}\MainImpl{notefont}
% \begin{macro}{\meterfont}\MainImpl{meterfont}
% \changes{v2.1}{2007/08/02}{Added}
% By default, verses, choruses, and textual notes just allow the |\lyricfont|
% style to continue.
% Meter numbers are in tiny, sans-serif, upright font.
% Echo parts toggle slanted and upright fonts.
%    \begin{macrocode}
\newcommand\versefont{}
\newcommand\chorusfont{}
\newcommand\notefont{}
\newcommand\meterfont{\tiny\sffamily\upshape}
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\echofont}\MainImpl{echofont}
% \changes{v2.18}{2014/06/28}{Added}
% Echo parts toggle between oblique and upright shapes like |\emph|, but we
% use |\slshape| instead of |\itshape| because it tends to look nicer with the
% larger fonts used in slides mode.
%    \begin{macrocode}
\newcommand\echofont{%
  \ifdim\fontdimen\@ne\font>\z@\upshape\else\slshape\fi%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\scripturefont}\MainImpl{scripturefont}
% \changes{v1.13}{2005/05/12}{Added kerning correction for double-quote ligatures}
% Define the font style to use for formatting scripture quotations
% (defaults to Zapf Chancery).
%    \begin{macrocode}
\newcommand\scripturefont{%
  \usefont{OT1}{pzc}{mb}{it}%
  \shiftdblquotes{-1.1\p@}\z@{-2\p@}\z@%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\printscrcite}\MainImpl{printscrcite}
% Define the printing style for the citation at the end of a scripture
% quotation.
%    \begin{macrocode}
\newcommand\printscrcite[1]{\sffamily\small#1}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\snumbgcolor}\MainImpl{snumbgcolor}
% \begin{macro}{\notebgcolor}\MainImpl{notebgcolor}
% \begin{macro}{\idxbgcolor}\MainImpl{idxbgcolor}
% Define the background color used for shaded boxes containing
% song numbers, textual notes, and index section headers, respectively.
% To turn off all shading for a box type, use |\def|\Meta{macroname}|{}|.
%    \begin{macrocode}
\newcommand\snumbgcolor{SongbookShade}
\newcommand\notebgcolor{SongbookShade}
\newcommand\idxbgcolor{SongbookShade}
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\versejustify}\MainImpl{versejustify}
% \begin{macro}{\chorusjustify}\MainImpl{chorusjustify}
% \changes{v2.1}{2007/08/02}{Added}
% Verses and choruses are both left-justified with hanging indentation equal
% to |\parindent|.
%    \begin{macrocode}
\newcommand\versejustify{\justifyleft}
\newcommand\chorusjustify{\justifyleft}
%    \end{macrocode}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\notejustify}\MainImpl{notejustify}
% \changes{v2.1}{2007/08/02}{Added}
% Textual notes are fully justified when they are too long to fit in
% a single line.
%    \begin{macrocode}
\newcommand\notejustify{%
  \advance\baselineskip\p@\relax%
  \leftskip\z@skip\rightskip\z@skip%
  \parfillskip\@flushglue\parindent\z@%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\placenote}\MainImpl{placenote}
% \changes{v2.1}{2007/08/02}{Added}
% Textual notes are placed flush-left.
% The single argument to this macro is horizontal material that comprises the
% note.
% Usually it will consist of various hboxes and specials that were produced
% by |\colorbox|.
%    \begin{macrocode}
\newcommand\placenote[1]{%
  \leftskip\z@skip\rightskip\@flushglue\SB@cbarshift%
  \noindent#1\par%
}
%    \end{macrocode}
% \end{macro}
%
% These counters define the current song number and verse number.
% They can be redefined by the user at any time.
%    \begin{macrocode}
\newcounter{songnum}
\newcounter{versenum}
%    \end{macrocode}
%
% \begin{macro}{\thesongnum}\MainImpl{thesongnum}
% \begin{macro}{\songnumstyle}
% By default, the song numbering style will simply be an arabic number.
% Redefine |\thesongnum| to change it.
% (The |\songnumstyle| macro is obsolete and exists only for backward
% compatibility.)
%    \begin{macrocode}
\renewcommand\thesongnum{\songnumstyle{songnum}}
\newcommand\songnumstyle{}
\let\songnumstyle\arabic
%    \end{macrocode}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\theversenum}\MainImpl{theversenum}
% \begin{macro}{\versenumstyle}
% By default, the verse numbering style will simply be an arabic number.
% Redefine |\theversenum| to change it.
% (The |\versenumstyle| macro is obsolete and exists only for backward
% compatibility.)
%    \begin{macrocode}
\renewcommand\theversenum{\versenumstyle{versenum}}
\newcommand\versenumstyle{}
\let\versenumstyle\arabic
%    \end{macrocode}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\printsongnum}\MainImpl{printsongnum}
% Define the printing style for the large, boxed song numbers starting each
% song.
%    \begin{macrocode}
\newcommand\printsongnum[1]{\sffamily\bfseries\LARGE#1}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\printversenum}\MainImpl{printversenum}
% Define the printing style for the verse numbers to the left of each verse.
%    \begin{macrocode}
\newcommand\printversenum[1]{\lyricfont#1.\ }
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\placeversenum}\MainImpl{placeversenum}
% \changes{v2.1}{2007/08/02}{Added}
% Verse numbers are placed flush-left.
% This is achieved by inserting horizontal glue that reverses both the
% |\leftskip| and the |\parindent|.
% The single argument to this macro is an hbox containing the verse number.
%    \begin{macrocode}
\newcommand\placeversenum[1]{%
  \hskip-\leftskip\hskip-\parindent\relax%
  \box#1%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\everyverse}\MainImpl{everyverse}
% \begin{macro}{\everychorus}\MainImpl{everychorus}
% \changes{v2.1}{2007/08/02}{Added}
% The following hooks allow users to insert material at the head of each
% verse or chorus.
%    \begin{macrocode}
\newcommand\everyverse{}
\newcommand\everychorus{}
%    \end{macrocode}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\printchord}\MainImpl{printchord}
% Define the printing style for chords.
%    \begin{macrocode}
\newcommand\printchord[1]{\sffamily\slshape\large#1}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\chordlocals}\MainImpl{chordlocals}
% \label{sec:chordlocals}
% This hook is expanded at the start of the scoping group that surrounds
% every chord name.
% Thus, it can be used to set any catcodes or definitions that should be
% local to chord names.
%    \begin{macrocode}
\newcommand\chordlocals{}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\versesep}\MainImpl{versesep}
% Specify the vertical distance between song verses.
% This gets set to a sentinel value by default; if the user doesn't redefine
% it by the end of the document preamble, it gets redefined to something
% sensible based on other settings.
%    \begin{macrocode}
\newlength\versesep
\versesep123456789sp\relax
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\afterpreludeskip}\MainImpl{afterpreludeskip}
% \begin{macro}{\beforepostludeskip}\MainImpl{beforepostludeskip}
% Users can specify the amount of vertical space that separates song prelude
% and postlude material from the body of the song by adjusting the following
% two macros.
%    \begin{macrocode}
\newlength\afterpreludeskip
\afterpreludeskip=2\p@\@plus4\p@
\newlength\beforepostludeskip
\beforepostludeskip=2\p@\@plus4\p@
%    \end{macrocode}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\baselineadj}\MainImpl{baselineadj}
% Define an adjustment factor for the vertical distance between consecutive
% lyric baselines.
% Setting this to zero accepts the default baseline distance computed by the
% songs package.
%    \begin{macrocode}
\newlength\baselineadj
\baselineadj\z@skip
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\clineparams}\MainImpl{clineparams}
% The spacing between chords and the lyrics below them can be adjusted
% by changing the values of |\baselineskip|, |\lineskiplimit|, and
% |\lineskip| within the following macro.
% By default, |\baselineskip| is set to 2 points smaller than the height
% of the current (lyric) font, and |\lineskiplimit| and |\lineskip| are
% set so that chords intrude at most 2 points into the lyric below them.
% This helps to keep chords tight with lyrics.
%    \begin{macrocode}
\newcommand\clineparams{%
  \baselineskip\f@size\p@%
  \advance\baselineskip-2\p@%
  \lineskiplimit-2\p@%
  \lineskip-2\p@%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\parindent}
% The |\parindent| length controls how far broken lyric lines are
% indented from the left margin.
%    \begin{macrocode}
\parindent.25in
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\idxheadwidth}\MainImpl{idxheadwidth}
% Specify the width of the head-boxes in a large index.
%    \begin{macrocode}
\newlength\idxheadwidth
\setlength\idxheadwidth{1.5cm}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\songnumwidth}\MainImpl{songnumwidth}
% Set the width of the song number boxes that begin each song.
% We guess a suitable width by typesetting the text ``999.''
%    \begin{macrocode}
\newlength\songnumwidth
\settowidth\songnumwidth{\printsongnum{999.}}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\versenumwidth}\MainImpl{versenumwidth}
% Set the width that is reserved for normal-sized verse numbers.
% (Verse numbers wider than this will indent the first line of lyrics.)
%    \begin{macrocode}
\newlength\versenumwidth
\settowidth\versenumwidth{\printversenum{9\kern1em}}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\cbarwidth}
% This dictates the width of the vertical line placed to the left of
% choruses.
% Setting it to |0pt| eliminates the line entirely.
%    \begin{macrocode}
\newlength\cbarwidth
\setlength\cbarwidth\p@
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\sbarheight}
% This dictates the height of the horizontal line placed between each pair
% of songs.
% Setting it to |0pt| eliminates the line entirely.
%    \begin{macrocode}
\newlength\sbarheight
\setlength\sbarheight\p@
%    \end{macrocode}
% \end{macro}
%
% Column- and page-breaks should typically not occur within a verse or chorus
% unless they are unavoidable.
% Thus, we set the |\interlinepenalty| to a high number (1000).
%    \begin{macrocode}
\interlinepenalty\@m
%    \end{macrocode}
%
% \begin{macro}{\vvpenalty}\MainImpl{vvpenalty}
% \begin{macro}{\ccpenalty}\MainImpl{ccpenalty}
% \begin{macro}{\vcpenalty}\MainImpl{vcpenalty}
% \begin{macro}{\cvpenalty}\MainImpl{cvpenalty}
% \begin{macro}{\brkpenalty}\MainImpl{brkpenalty}
% \changes{v2.1}{2007/08/02}{Added.}
% The following count registers define the line-breaking penalties inserted
% between verses, between choruses, after a verse followed by a chorus, after
% a chorus followed by a verse, and at |\brk| macros, respectively.
%
% The default value of 200 was chosen based on the following logic:
% Chord books should not yield underfull vbox warnings no matter how short
% their columns are.
% However, we still want to put as much material in each column as possible
% while avoiding intra-song column-breaks when they can be avoided.
% Chorded mode therefore sets |\colbotglue| with glue whose stretchability
% is half of the |\textheight|.
% Such glue will stretch at most twice its stretchability, yielding a
% badness of 800 in the worst case.
% The default |\vbadness| setting starts issuing warnings at badness 1000,
% so we set the penalties below to $1000-800=200$.
%    \begin{macrocode}
\SB@newcount\vvpenalty\vvpenalty200
\SB@newcount\ccpenalty\ccpenalty200
\SB@newcount\vcpenalty\vcpenalty200
\SB@newcount\cvpenalty\cvpenalty200
\SB@newcount\brkpenalty\brkpenalty200
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\spenalty}\MainImpl{spenalty}
% \changes{v2.1}{2007/08/02}{Added.}
% The following penalty gets inserted between songs.
% Setting it to a proper value is a somewhat delicate balancing act.
% It should typically be something between 0 and the default penalties above,
% so for now it defaults to 100.
% To start each song on a fresh column/page, set it to $-10000$ or below.
%    \begin{macrocode}
\SB@newcount\spenalty\spenalty100
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\songmark}\MainImpl{songmark}
% \changes{v1.17}{2005/09/24}{Added.}
% \begin{macro}{\versemark}\MainImpl{versemark}
% \begin{macro}{\chorusmark}\MainImpl{chorusmark}
% \changes{v2.1}{2007/08/02}{Added.}
% The user can redefine the following macros to add \TeX{} marks for each
% song, each verse, or each chorus.
% Such marks are used by \LaTeX{} to define page headers and footers.
%    \begin{macrocode}
\newcommand\songmark{}
\newcommand\versemark{}
\newcommand\chorusmark{}
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\extendprelude}\MainImpl{extendprelude}
% \begin{macro}{\extendpostlude}\MainImpl{extendpostlude}
% \changes{v2.0}{2007/06/18}{Added.}
% To just add some fields to the existing |\makeprelude| or |\makepostlude|
% without having to redefine them entirely, users can redefine
% |\extendprelude| or |\extendpostlude|.
% By default, the prelude has the scripture references followed by the
% authors, and the postlude has the copyright info followed by the licensing
% info.
%    \begin{macrocode}
\newcommand\extendprelude{\showrefs\showauthors}
\newcommand\extendpostlude{\songcopyright\ \songlicense\unskip}
%    \end{macrocode}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\idxheadfont}\MainImpl{idxheadfont}
% \changes{v2.8}{2009/02/22}{Added.}
% Users can redefine |\idxheadfont| to affect the font in which each capital
% letter that heads a section of a title index is rendered.
%    \begin{macrocode}
\newcommand\idxheadfont{\sffamily\bfseries\LARGE}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\idxtitlefont}\MainImpl{idxtitlefont}
% \changes{v2.8}{2009/02/22}{Added.}
% Users can redefine |\idxtitlefont| to affect the font in which song title
% index entries are rendered.
%    \begin{macrocode}
\newcommand\idxtitlefont{\sffamily\slshape}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\idxlyricfont}\MainImpl{idxlyricfont}
% \changes{v2.8}{2009/02/22}{Added.}
% Users can redefine |\idxlyricfont| to affect the font in which notable lines
% of lyrics are rendered in a title index.
%    \begin{macrocode}
\newcommand\idxlyricfont{\rmfamily}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\idxscripfont}\MainImpl{idxscripfont}
% \changes{v2.8}{2009/02/22}{Added.}
% Users can redefine |\idxscripfont| to affect the font in which scripture
% references are rendered in a scripture index.
%    \begin{macrocode}
\newcommand\idxscripfont{\sffamily\small\slshape}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\idxauthfont}\MainImpl{idxauthfont}
% \changes{v2.8}{2009/02/22}{Added.}
% Users can redefine |\idxauthfont| to affect the font in which contributor
% names are rendered in an author index.
%    \begin{macrocode}
\newcommand\idxauthfont{\small\bfseries}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\idxrefsfont}\MainImpl{idxrefsfont}
% \changes{v2.8}{2009/02/22}{Added.}
% Users can redefine |\idxrefsfont| to affect the font in which the list of
% song references on the right-hand-side of an index entry is typeset.
%    \begin{macrocode}
\newcommand\idxrefsfont{\normalfont\normalsize}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\idxbook}\MainImpl{idxbook}
% \changes{v2.8}{2009/02/22}{Added.}
% Users can redefine |\idxbook| to dictate the book name header in a
% scripture index that begins each book of the bible.
%    \begin{macrocode}
\newcommand\idxbook[1]{\small\bfseries#1}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\idxcont}\MainImpl{idxcont}
% \changes{v2.0}{2007/06/18}{Added.}
% Users can redefine |\idxcont| to dictate the column header in a scripture
% index after a column break falls within a book of the bible.
%    \begin{macrocode}
\newcommand\idxcont[1]{\small\textbf{#1} (continued)}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\colbotglue}
% Glue of size |\colbotglue| is inserted at the bottom of each column.
% We use a macro instead of a glue register so that this can be redefined
% in terms of variable quantities such as |\textheight|.
%    \begin{macrocode}
\newcommand\colbotglue{}
\let\colbotglue\z@skip
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\lastcolglue}
% Glue of size |\lastcolglue| is inserted at the bottom of the last column.
%    \begin{macrocode}
\newcommand\lastcolglue{}
\let\lastcolglue\@flushglue
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\minfrets}
% Define the minimum number of fret rows that should appear in tablature
% diagrams.
%    \begin{macrocode}
\SB@newcount\minfrets\minfrets4
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\SB@colwidth}
% Define a length to store the computed width of each column in a
% multi-column song page.
% The user shouldn't set this one directly, but some users might want to
% refer to it in calculations.
%    \begin{macrocode}
\SB@newdimen\SB@colwidth
%    \end{macrocode}
% \end{macro}
%
% \subsection{Package Options}
%
% This section defines code associated with the various option
% settings that can be specified on the |\usepackage| line.
% Many of these options can also be turned on or off subsequent to the
% |\usepackage| line, so macros for doing that are also located here.
% The options are not actually processed until \S\ref{sec:optproc} because
% some of the macros defined here refer to macros that have not yet been
% defined.
%
% \begin{option}{slides}\MainEnvImpl{slides}
% \begin{macro}{\slides}\MainImpl{slides}
% \optdef{off}
% Turning this option on generates a book of overhead slides---one for each
% song.
% It really just amounts to changing various parameter settings.
% Elsewhere in the code we also consult |\ifslides| to determine a few default
% parameter settings and to use a different song preamble structure.
% All the parameter changes below are local to the current scope; so to
% undo slides mode, just put |\slides| within a group and end the group
% wherever you want the slides settings to end.
%    \begin{macrocode}
\DeclareOption{slides}{\slides}
\newcommand\slides{%
  \slidestrue%
  \def\lyricfont{\normalfont\huge}%
  \def\chorusfont{\slshape}%
  \def\versejustify{\justifycenter}%
  \let\chorusjustify\versejustify
  \def\placenote##1{\justifycenter\noindent##1\par}%
  \scriptureoff%
  \onesongcolumn%
  \ifSB@preamble\ifSB@chordedspec\else\SB@chordsoff\fi\fi%
  \spenalty-\@M%
  \let\colbotglue\@flushglue%
  \setlength\cbarwidth\z@%
  \setlength\sbarheight\z@%
}
%    \end{macrocode}
% \end{macro}
% \end{option}
%
% \begin{macro}{\justifyleft}
% \changes{v2.1}{2007/08/02}{Added}
% The |\justifyleft| macro sets up an environment in which lyrics are
% left-justified with hanging indentation equal to |\parindent|.
% It reserves spaces for verse numbers if used in a verse, and reserves
% space for the vertical bar left of choruses if used in a chorus.
%    \begin{macrocode}
\newcommand\justifyleft{%
  \leftskip\parindent%
  \ifSB@inverse\advance\leftskip\versenumwidth\fi%
  \SB@cbarshift%
  \parindent-\parindent%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\justifycenter}
% \changes{v2.1}{2007/08/02}{Added}
% The |\justifycenter| macro sets up an environment in which lyrics are
% centered on each line.
% Verse numbers continue to be placed flush-left, but |\placeversenum|
% is temporarily redefined to keep the rest of the line containing a
% verse number centered.
%    \begin{macrocode}
\newcommand\justifycenter{%
  \centering\SB@cbarshift\rightskip\leftskip%
  \def\placeversenum##1{%
    \hskip-\leftskip\hskip-\parindent\relax%
    \hangindent-\wd##1\hangafter\m@ne%
    \box##1\hfil%
  }%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{option}{unouter}\MainEnvImpl{unouter}
% \begin{macro}{\SB@outer}
% \optdef{off}
% Several macros provided by the \Songs{} package are, by default, declared
% |\outer| to aid in debugging.
% However, unusual documents may need to use these macros within larger
% constructs.
% To do so, use the |unouter| option to prevent any of the macros supplied
% by this package from being declared |\outer|.
%    \begin{macrocode}
\newcommand\SB@outer{\outer}
\DeclareOption{unouter}{\let\SB@outer\relax}
%    \end{macrocode}
% \end{macro}
% \end{option}
%
% \begin{option}{rawtext}\MainEnvImpl{rawtext}
% \optdef{off}
% Instead of generating a document, this dumps a text version of the song book
% to a file. This option can only be set in the |\usepackage| line because
% it dictates many top-level macro definitions. Turning rawtext on turns off
% the indexes by default, but this can be overridden by explicitly setting
% index options. (Note: Using rawtext with indexes turned on doesn't actually
% work yet, but might be added in a future revision.)
%    \begin{macrocode}
\DeclareOption{rawtext}{\rawtexttrue\indexesoff}
%    \end{macrocode}
% \end{option}
%
% \begin{option}{noshading}\MainEnvImpl{noshading}
% \optdef{off}
% Inhibit all shaded boxes (e.g., if the color package is unavailable).
% This option can only be set in the |\usepackage| line because the color
% package must be loaded in the preamble if at all. (Note: In a future release
% this might be extended to be modifiable throughout the preamble.)
%    \begin{macrocode}
\DeclareOption{noshading}{\SB@colorboxesfalse}
%    \end{macrocode}
% \end{option}
%
% \begin{option}{noindexes}\MainEnvImpl{noindexes}
% \begin{macro}{\indexeson}\MainImpl{indexeson}
% \begin{macro}{\indexesoff}\MainImpl{indexesoff}
% \optdef{off}
% Suppress generation of index files and displaying of in-document indexes.
% The |\indexeson| and |\indexesoff| macros can be used elsewhere to toggle
% display of indexes.
% Index-regeneration will occur if indexes are turned on by the end of the
% document.
%    \begin{macrocode}
\DeclareOption{noindexes}{\indexesoff}
\newcommand\indexeson{\songindexestrue}
\newcommand\indexesoff{\songindexesfalse}
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{option}
%
% \begin{option}{nopdfindex}\MainEnvImpl{nopdfindex}
% \optdef{off}
% Suppress creation of PDF bookmark entries and hyperlinks.
%    \begin{macrocode}
\DeclareOption{nopdfindex}{%
  \let\songtarget\@gobbletwo%
  \let\songlink\@secondoftwo%
}
%    \end{macrocode}
% \end{option}
%
% \begin{macro}{\ifSB@measurespec}
% \begin{macro}{\ifSB@chordedspec}
% The |showmeasures| and |chorded| options interact in the sense that by
% default, switching one of them on or off switches the other on or off as
% well.
% However, if the user explicitly says that one should be on or off, then
% switching the other shouldn't affect it.
% To produce this behavior, we need two extra conditionals to remember whether
% each of these options has been explicitly specified by the user or whether
% it is still in a default state.
%    \begin{macrocode}
\newif\ifSB@measurespec
\newif\ifSB@chordedspec
%    \end{macrocode}
% \end{macro}
% \end{macro}
%
% \begin{option}{chorded}\MainEnvImpl{chorded}
% \begin{option}{lyric}\MainEnvImpl{lyric}
% \begin{macro}{\chordson}\MainImpl{chordson}
% \begin{macro}{\chordsoff}\MainImpl{chordsoff}
% \begin{macro}{\SB@chordson}
% \begin{macro}{\SB@chordsoff}
% \changes{v1.22}{2007/05/15}{Update \cs{baselineskip} when in songs.}
% \optdef{chorded}
% Determines whether chords should be shown.
% This option can be set in the |\usepackage| line or toggled elsewhere
% with the |\chordson| and |\chordsoff| macros.
% Chords cannot be turned on in conjunction with the |rawtext| option.
% If chords are turned on by the end of the preamble, no attempt will be made
% to balance columns on each page.
%    \begin{macrocode}
\DeclareOption{chorded}{\chordson}
\DeclareOption{lyric}{\chordsoff}
\newcommand\chordson{\SB@chordedspectrue\SB@chordson}
\newcommand\chordsoff{\SB@chordedspectrue\SB@chordsoff}
\newcommand\SB@chordson{%
  \ifrawtext%
    \SB@errrtopt%
  \else%
    \chordedtrue\lyricfalse%
    \let\SB@bracket\SB@chord%
    \let\SB@rechord\SB@@rechord%
    \let\SB@ch\SB@ch@on%
    \ifSB@measurespec%
      \ifmeasures\SB@measureson\else\SB@measuresoff\fi%
    \else%
      \SB@measureson%
    \fi%
    \ifSB@preamble\def\colbotglue{\z@\@plus.5\textheight}\fi%
    \SB@setbaselineskip%
  \fi%
}
\newcommand\SB@chordsoff{%
  \chordedfalse\lyrictrue%
  \def\SB@bracket##1]{\ignorespaces}%
  \let\SB@rechord\relax%
  \let\SB@ch\SB@ch@off%
  \ifSB@measurespec%
    \ifmeasures\SB@measureson\else\SB@measuresoff\fi%
  \else%
    \SB@measuresoff%
  \fi%
  \ifSB@preamble\let\colbotglue\z@skip\fi%
  \SB@setbaselineskip%
}
%    \end{macrocode}
% \eat\]
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{option}
% \end{option}
%
% \begin{option}{showmeasures}\MainEnvImpl{showmeasures}
% \begin{option}{nomeasures}\MainEnvImpl{nomeasures}
% \begin{macro}{\measureson}\MainImpl{measureson}
% \begin{macro}{\measuresoff}\MainImpl{measuresoff}
% \begin{macro}{\SB@measureson}
% \begin{macro}{\SB@measuresoff}
% \optdef{showmeasures if chorded, nomeasures otherwise}
% Determines whether measure bars and meter notes should be shown.
% Option can be set in the |\usepackage| line or toggled elsewhere with the
% |\measureson| and |\measuresoff| macros.
%    \begin{macrocode}
\DeclareOption{showmeasures}{\measureson}
\DeclareOption{nomeasures}{\measuresoff}
\newcommand\measureson{\SB@measurespectrue\SB@measureson}
\newcommand\measuresoff{\SB@measurespectrue\SB@measuresoff}
\newcommand\SB@measureson{%
  \measurestrue%
  \let\SB@mbar\SB@makembar%
  \ifchorded%
    \let\SB@mch\SB@mch@on%
  \else%
    \let\SB@mch\SB@mch@m%
  \fi%
  \ifSB@inverse\SB@loadactives\fi%
  \ifSB@inchorus\SB@loadactives\fi%
}
\newcommand\SB@measuresoff{%
  \measuresfalse%
  \let\SB@mbar\@gobbletwo%
  \ifchorded%
    \let\SB@mch\SB@ch@on%
  \else%
    \let\SB@mch\SB@ch@off%
  \fi%
  \ifSB@inverse\SB@loadactives\fi%
  \ifSB@inchorus\SB@loadactives\fi%
}
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{option}
% \end{option}
%
% \begin{option}{transposecapos}\MainEnvImpl{transposecapos}
% \optdef{off}
% If set, the |\capo| macro transposes the song instead of printing a note
% to use a capo. Use this option to generate a chord book for pianists who
% have trouble transposing or guitarists who don't have capos.
%    \begin{macrocode}
\DeclareOption{transposecapos}{\transcapostrue}
%    \end{macrocode}
% \end{option}
%
% \begin{option}{noscripture}\MainEnvImpl{noscripture}
% \begin{macro}{\scriptureon}\MainImpl{scriptureon}
% \begin{macro}{\scriptureoff}\MainImpl{scriptureoff}
% \optdef{off}
% Inhibits the display of scripture quotes.
% This option can also be toggled on and off anywhere with the |\sciptureon|
% and |\scriptureoff| macros.
%    \begin{macrocode}
\DeclareOption{noscripture}{\SB@omitscriptrue}
\newcommand\scriptureon{\SB@omitscripfalse}
\newcommand\scriptureoff{\SB@omitscriptrue}
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{option}
%
% \begin{option}{onesongcolumn}\MainEnvImpl{onesongcolumn}
% \begin{option}{twosongcolumns}\MainEnvImpl{twosongcolumns}
% \begin{macro}{\onesongcolumn}\MainImpl{onesongcolumn}
% \begin{macro}{\twosongcolumns}\MainImpl{twosongcolumns}
% \begin{macro}{\songcolumns}\MainImpl{songcolumns}
% \optdef{onesongcolumn is the default if generating slides or rawtext, twosongcolumns otherwise}
% The number of columns per page is specified using the following package
% options and macros.
% In \env{rawtext} mode it must remain set to one column per page.
% The entire page-making system can be turned off by setting the number of
% columns to zero.
% This will cause each song to be contributed to the current vertical list
% without any attempt to form columns; the enclosing environment must handle
% the page layout.
% Probably this means that |\repchoruses| will not work, since an external
% package won't know to insert repeated choruses when building pages.
%    \begin{macrocode}
\DeclareOption{twosongcolumns}{\SB@numcols\tw@}
\DeclareOption{onesongcolumn}{\SB@numcols\@ne}
\newcommand\songcolumns[1]{%
  \SB@cnt#1\relax%
  \ifnum\SB@cnt=\SB@numcols\else%
    \ifSB@preamble\else{\SB@clearpage}\fi%
  \fi%
  \SB@numcols\SB@cnt%
  \ifnum\SB@numcols>\z@%
    \SB@colwidth-\columnsep%
    \multiply\SB@colwidth\SB@numcols%
    \advance\SB@colwidth\columnsep%
    \advance\SB@colwidth\textwidth%
    \divide\SB@colwidth\SB@numcols%
  \else%
    \ifrepchorus\SB@warnrc\fi%
  \fi%
}
\newcommand\onesongcolumn{\songcolumns\@ne}
\newcommand\twosongcolumns{\songcolumns\tw@}
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{option}
% \end{option}
%
% \begin{macro}{\includeonlysongs}\MainImpl{includeonlysongs}
% \begin{macro}{\songlist}
% Display only a select list of songs and ignore the rest.
%    \begin{macrocode}
\newcommand\songlist{}
\newcommand\includeonlysongs[1]{%
  \ifSB@songsenv\SB@errpl\else%
    \partiallisttrue%
    \renewcommand\songlist{#1}%
  \fi%
}
%    \end{macrocode}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\nosongnumbers}\MainImpl{nosongnumbers}
% \changes{v2.9}{2009/04/01}{Added.}
% The user can turn off song numbering with the following macro.
%    \begin{macrocode}
\newcommand\nosongnumbers{\setlength\songnumwidth\z@}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\noversenumbers}\MainImpl{noversenumbers}
% \changes{v1.20}{2006/03/12}{Added.}
% The user can turn off verse numbering with the following macro.
%    \begin{macrocode}
\newcommand\noversenumbers{%
  \renewcommand\printversenum[1]{}%
  \setlength\versenumwidth\z@%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\repchoruses}\MainImpl{repchoruses}
% \begin{macro}{\norepchoruses}\MainImpl{norepchoruses}
% \changes{v2.1}{2007/08/02}{Added.}
% Using |\repchoruses| causes choruses to be automatically repeated on
% subsequent pages of the song.
% The feature requires $\varepsilon$-\TeX{} because the supporting code needs
% an extended mark register class.
%    \begin{macrocode}
\ifSB@etex
  \newcommand\repchoruses{%
    \ifnum\SB@numcols<\@ne\SB@warnrc\fi%
    \repchorustrue%
  }
\else
  \newcommand\repchoruses{\SB@erretex}
\fi
\newcommand\norepchoruses{\repchorusfalse}
%    \end{macrocode}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\sepverses}
% The following penalty settings cause verses and choruses to be separated
% onto different slides when in slides mode, except that consecutive choruses
% remain together when they fit.
%    \begin{macrocode}
\newcommand\sepverses{%
  \vvpenalty-\@M%
  \ccpenalty100 %
  \vcpenalty\vvpenalty%
  \cvpenalty\vvpenalty%
  \let\colbotglue\@flushglue%
}
%    \end{macrocode}
% \end{macro}
%
% Some option settings, margins, and other lengths are finalized at the end of
% the preamble.
% That code is below.
%
%    \begin{macrocode}
\AtBeginDocument{
%    \end{macrocode}
%
% If the user hasn't set the |\versesep|, set it to the default.
%    \begin{macrocode}
  \SB@setversesep
%    \end{macrocode}
%
% Initialize page layout algorithm.
%    \begin{macrocode}
  \songcolumns\SB@numcols
%    \end{macrocode}
%
% Macros used after this point occur outside the preamble.
%    \begin{macrocode}
  \SB@preamblefalse
}
%    \end{macrocode}
%
% \subsection{Page-builder}
% \label{sec:pagebuilder}
%
% The following macros handle the building of pages that contain songs.
% They compute where best to place each song (e.g., whether to place it in the
% current column or move to the next column or page).
% The output routines for generating a partial list of songs in a specified
% order also can be found here.
%
% \begin{macro}{\SB@songbox}
% The most recently processed song (or scripture quotation) is stored in this
% box.
%    \begin{macrocode}
\SB@newbox\SB@songbox
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\SB@numcols}
% \begin{macro}{\SB@colnum}
% Reserve two count registers to hold the total number of columns and the
% current column number, respectively.
%    \begin{macrocode}
\SB@newcount\SB@numcols\SB@numcols\tw@
\SB@newcount\SB@colnum
%    \end{macrocode}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\SB@colbox}
% Reserve a box register to hold the current column in progress.
%    \begin{macrocode}
\SB@newbox\SB@colbox
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\SB@pgbox}
% Reserve a box register to hold the current page in progress.
%    \begin{macrocode}
\SB@newbox\SB@pgbox
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\SB@mrkbox}
% Reserve a box register to hold marks that migrate out of songs as they
% get split into columns and pages.
%    \begin{macrocode}
\SB@newbox\SB@mrkbox
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\SB@maxmin}
% The following helper macro takes the max or min of two dimensions.
% If \argp{2}=``|<|'', it sets \argp{1} to the maximum of \argp{1} and
% \argp{3}.
% If \argp{2}=``|>|'', it sets \argp{1} to the minimum of \argp{1} and
% \argp{3}.
%    \begin{macrocode}
\newcommand\SB@maxmin[3]{\ifdim#1#2#3#1#3\fi}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\SB@mkpage}
% The following macro is the heart of the page-building engine.
% It splits the contents of a box into a page of columns.
% If |\repchoruses| is active, the contents of |\SB@chorusbox|
% are additionally inserted into fresh columns created during the spitting
% process.
% The macro arguments are:
% \begin{enumerate}
% \item an integer (positive or zero) indicating whether box $b$ should be
% fully emptied and committed as columns (if positive), or whether its
% final less-than-column-height remainder should be reserved as an in-progress
% column (if zero);
% \item the box $b$ to split;
% \item a count register $i$ equaling the column index (zero or greater)
% where the content of $b$ is to begin; and
% \item the desired column height.
% \end{enumerate}
% Box $b$ is split and $i$ is incremented until $i$ reaches
% |\SB@numcols| or $b$ is emptied.
% If $b$ is emptied and the first argument is 0, the final column is \emph{not}
% contributed; instead it is left in $b$ and $i$ is left equal to the index
% of the column that would have been added if $b$ had been emptied.
% This allows the next call to reconsider whether to end the
% current column here or add some or all of the next contribution to it.
% Otherwise, if $b$ is emptied and the first argument is positive, the final
% column is contributed and $i$ is set to one greater than the index of that
% column.
% (If $i$ reaches |\SB@numcols| before $b$ is emptied, the first argument is
% ignored.)
%
% Box $b$ and count register $i$ are globally modified.
% If |\SB@updatepage| is not redefined, boxes |\SB@pgbox| and |\SB@mrkbox|
% are also globally modified based on the results of the split.
%
% The implementation takes two special steps to avoid pre-committing
% in-progress columns (when the first macro argument is zero):
% First, the final split that empties box $b$ is ``undone'' by reverting to a
% backup copy made before each split.
% Second, any underfull box warnings for this final split are suppressed by
% temporarily adding infinite-stretch |\vfil| glue to the bottom of the box.
% This strategy preserves underfull and overfull box warnings for the columns
% that are actually committed, but suppresses faux warnings for the last split
% that is undone.
%    \begin{macrocode}
\newcommand\SB@mkpage[4]{%
  \ifvoid#2\else\begingroup%
    \edef\SB@temp{\ifnum#2=\SB@box\SB@boxii\else\SB@box\fi}%
    \edef\SB@tempii{\ifnum#2=\SB@boxiii\SB@boxii\else\SB@boxiii\fi}%
    \splitmaxdepth\maxdepth\splittopskip\z@skip%
    \ifnum#1=\z@\global\setbox#2\vbox{\unvbox#2\vfil}\fi%
    \loop\ifnum#3<\SB@numcols%
      \ifnum#1=\z@\setbox\SB@tempii\copy#2\fi%
      \setbox\SB@temp\vsplit#2to#4\relax%
      \ifvoid#2%
        \ifnum#1=\z@%
          \global\setbox#2\box\SB@tempii%
        \else%
          \SB@updatepage%
          \global\advance#3\@ne%
        \fi%
        #3\SB@numcols%
      \else%
        \SB@updatepage%
        \global\advance#3\@ne%
        \ifrepchorus\ifvoid\SB@chorusbox\else%
          \SB@insertchorus#2%
        \fi\fi%
      \fi%
    \repeat%
    \ifnum#1=\z@\global\setbox#2\vbox{\unvbox#2\unskip}\fi%
  \endgroup\fi%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\SB@migrate}
% Migrate a mark out of a recently split vertical list, but do not insert
% superfluous empty marks that may override previous marks.
%    \begin{macrocode}
\newcommand\SB@migrate[1]{%
  \SB@toks\expandafter{#1}%
  \edef\SB@temp{\the\SB@toks}%
  \ifx\SB@temp\@empty\else\mark{\the\SB@toks}\fi%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\SB@updatepage}
% Update boxes |\SB@pgbox| and |\SB@mrkbox| immediately after splitting
% the contents of |\SB@colbox|.
%    \begin{macrocode}
\newcommand\SB@updatepage{%
  \global\setbox\SB@mrkbox\vbox{%
    \unvbox\SB@mrkbox%
    \SB@migrate\splitfirstmark%
    \SB@migrate\splitbotmark%
  }%
  \global\setbox\SB@pgbox\hbox{%
    \SB@dimen\SB@colwidth%
    \advance\SB@dimen\columnsep%
    \multiply\SB@dimen\SB@colnum%
    \advance\SB@dimen-\wd\SB@pgbox%
    \unhbox\SB@pgbox%
    \ifdim\SB@dimen=\z@\else\hskip\SB@dimen\relax\fi%
    \box\SB@temp%
  }%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\SB@droppage}
% This alternate definition of |\SB@updatepage| drops the just-created
% page instead of contributing it.
% This allows |\SB@mkpage| to be called by the song-positioning algorithm
% as a trial run without outputting anything.
%    \begin{macrocode}
\newcommand\SB@droppage{\setbox\SB@temp\box\voidb@x}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\SB@output}
% This is the main output routine for the page-builder.
% It repeatedly calls |\SB@mkpage|, emitting pages as they are completed,
% until the remaining content of box |\SB@colbox| is not enough to fill a
% column.
% If the macro argument is 0, this final, in-progress column is left
% unfinished, pending future contributions.
% If the argument is positive, the final material is committed as a column.
% If the argument is two or greater, the entire in-progress page is also
% committed and the column number reset.
%    \begin{macrocode}
\newcommand\SB@output[1]{%
  \ifnum\SB@numcols>\z@\begingroup%
    \loop%
      \SB@dimen\textheight%
      \ifinner\else\advance\SB@dimen-\pagetotal\fi%
      \SB@mkpage#1\SB@colbox\SB@colnum\SB@dimen%
      \SB@testfalse\SB@testiitrue%
      \ifnum#1>\@ne\ifvoid\SB@colbox\ifnum\SB@colnum>\z@%
        \SB@testtrue\SB@testiifalse%
      \fi\fi\fi%
      \ifnum\SB@colnum<\SB@numcols\SB@testiifalse\else\SB@testtrue\fi%
      \ifSB@test%
        \unvbox\SB@mrkbox%
        \ifinner\else\kern\z@\fi%
        \box\SB@pgbox%
        \ifinner\else\vfil\break\vskip\vsize\relax\fi%
        \global\SB@colnum\z@%
      \fi%
    \ifSB@testii\repeat%
  \endgroup\else%
    \unvbox\SB@colbox\unskip%
  \fi%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\SB@putboxes}
% Create a vertical list consisting of the already committed contents of the
% current column plus the most recently submitted song box.
% The \LaTeX{} primitive that should be used to contribute each box is
% specified in the first argument.
%    \begin{macrocode}
\newcommand\SB@putboxes[1]{%
  \SB@dimen\ifnum\SB@numcols>\z@\ht\SB@colbox\else\p@\fi%
  #1\SB@colbox%
  \ifdim\SB@dimen>\z@%
    \SB@breakpoint\spenalty%
    \ifdim\sbarheight>\z@%
      \vskip-\sbarheight\relax%
    \fi%
  \fi%
  #1\SB@songbox%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\SB@nextcol}
% Force $n$ column breaks, where $n$ is given by the first argument.
% The first created column is finished with the glue specified in the
% second argument.
% When the second argument is |\@flushglue|, this forces a break that leaves
% whitespace at the bottom of the column.
% When it's |\colbotglue|, it acts like a natural column break chosen by
% the page-breaker.
% However, if the current column is empty, |\@flushglue| is always used so
% that an empty column will result.
%    \begin{macrocode}
\newcommand\SB@nextcol[2]{%
  \ifnum#1>\z@%
    \ifnum\SB@numcols>\z@%
      \global\setbox\SB@colbox\vbox{%
        \SB@cnt#1\relax%
        \SB@dimen\ht\SB@colbox%
        \unvbox\SB@colbox%
        \unskip%
        \ifdim\SB@dimen>\z@%
          \vskip#2\relax%
          \break%
          \advance\SB@cnt\m@ne%
        \fi%
        \loop\ifnum\SB@cnt>\z@%
          \nointerlineskip%
          \null%
          \vfil%
          \break%
          \advance\SB@cnt\m@ne%
        \repeat%
      }%
      \SB@output1%
    \else%
      \ifnum\lastpenalty=-\@M\null\fi%
      \break%
    \fi%
  \fi%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\SB@selectcol}
% This is the entrypoint to the song-positioning algorithm.
% It gets defined by |\songpos| to either |\SB@@selectcol| (below) or
% |\relax| (when song-positioning is turned off).
%    \begin{macrocode}
\newcommand\SB@selectcol{}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\SB@@selectcol}
% \changes{v2.1}{2007/08/02}{Rewritten to better handle glue}
% \changes{v2.9}{2009/07/30}{Rewritten to handle repeated choruses}
% Songs should be squeezed in wherever they fit, but breaking a column or page
% within a song should be avoided.
% The following macro outputs zero or more column breaks to select a good
% place for |\SB@songbox| to be contributed to the current (or the next) page.
% The number of column breaks is determined by temporarily setting
% |\SB@updatepage| to |\SB@droppage| and then calling the |\SB@mkpage|
% algorithm under various conditions to see how many columns it would
% contribute if we start the current song at various positions.
%    \begin{macrocode}
\newcommand\SB@@selectcol{%
  \begingroup%
    \SB@cnt\z@%
    \vbadness\@M\vfuzz\maxdimen%
    \let\SB@updatepage\SB@droppage%
    \SB@dimen\textheight%
    \ifinner\else\advance\SB@dimen-\pagetotal\fi%
    \setbox\SB@boxii\vbox{\SB@putboxes\unvcopy}%
    \SB@cntii\SB@colnum%
    \SB@mkpage0\SB@boxii\SB@cntii\SB@dimen%
    \SB@spos%
    \global\SB@cnt\SB@cnt%
  \endgroup%
  \SB@nextcol\SB@cnt\colbotglue%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\SB@spbegnew}
% Begin a trial typesetting of the current song on a fresh page to see if
% it fits within a page.
%    \begin{macrocode}
\newcommand\SB@spbegnew{%
  \setbox\SB@boxiii\copy\SB@songbox%
  \SB@cntii\z@%
  \SB@mkpage0\SB@boxiii\SB@cntii\textheight%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\SB@spextold}
% Tentatively extend the song previously typeset on the current even page to
% the next odd page to see whether it fits on a double-page.
% If the current page is odd-numbered, do nothing since extending the song
% to the next page would introduce a page-turn.
%    \begin{macrocode}
\newcommand\SB@spextold{%
  \ifodd\c@page\else%
    \SB@cntii\z@%
    \SB@mkpage0\SB@boxii\SB@cntii\textheight%
  \fi%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\SB@spextnew}
% Extend the trial typesetting started with |\SB@spbegnew| to a second
% page to see whether the song fits on a fresh double-page.
%    \begin{macrocode}
\newcommand\SB@spextnew{%
  \SB@cntii\z@%
  \SB@mkpage0\SB@boxiii\SB@cntii\textheight%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\SB@spdblpg}
% Compute the number of column breaks required to shift the current song
% to the next double-page if the result of the last test run fits within
% its page (as indicated by counter |\SB@cntii|).
% Otherwise leave the requested number of column breaks set to zero.
%    \begin{macrocode}
\newcommand\SB@spdblpg{%
  \ifnum\SB@cntii<\SB@numcols%
    \SB@cnt\SB@numcols%
    \advance\SB@cnt-\SB@colnum%
    \if@twoside\ifodd\c@page\else%
      \advance\SB@cnt\SB@numcols%
    \fi\fi%
  \fi%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\SB@sposi}
% This is the level-1 song positioning algorithm.
% It moves songs to the next double-page only if doing so would avoid a
% page-turn that would otherwise appear within the song.
%    \begin{macrocode}
\newcommand\SB@sposi{%
  \ifnum\SB@cntii<\SB@numcols\else\if@twoside%
    \SB@spextold%
  \fi\fi%
  \ifnum\SB@cntii<\SB@numcols\else%
    \SB@spbegnew%
    \ifnum\SB@cntii<\SB@numcols\else\if@twoside%
      \SB@spextnew%
    \fi\fi%
    \SB@spdblpg%
  \fi%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\SB@sposii}
% This is the level-2 song-positioning algorithm.
% It moves songs to the next page or double-page if doing so avoids a
% page-break or page-turn that would otherwise appear within the song.
%    \begin{macrocode}
\newcommand\SB@sposii{%
  \ifnum\SB@cntii<\SB@numcols\else%
    \SB@spbegnew%
    \ifnum\SB@cntii<\SB@numcols%
      \SB@cnt\SB@numcols%
      \advance\SB@cnt-\SB@colnum%
    \else%
      \if@twoside%
        \SB@spextold%
        \ifnum\SB@cntii<\SB@numcols\else%
          \SB@spextnew%
          \SB@spdblpg%
        \fi%
      \fi%
    \fi%
  \fi%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\SB@sposiii}
% This is the level-3 song-positioning algorithm.
% It moves songs to the next column, the next page, or the next double-page
% if doing so avoids a column-break, page-break, or page-turn that would
% otherwise appear within the song.
%    \begin{macrocode}
\newcommand\SB@sposiii{%
  \ifnum\SB@cntii>\SB@colnum%
    \SB@cnt\SB@colnum%
    \advance\SB@cnt\@ne%
    \ifnum\SB@cnt<\SB@numcols%
      \setbox\SB@boxiii\copy\SB@songbox%
      \SB@mkpage0\SB@boxiii\SB@cnt\SB@dimen%
      \advance\SB@cnt\m@ne%
    \fi%
    \ifnum\SB@cnt>\SB@colnum%
      \SB@cnt\z@%
      \SB@sposii%
    \else%
      \SB@cnt\@ne%
    \fi%
  \fi%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\songpos}
% This is the macro by which the user adjusts the aggressiveness level of the
% song-positioning algorithm.
% See the macros above for what each level does.
%    \begin{macrocode}
\newcommand\songpos[1]{%
  \ifcase#1%
    \let\SB@selectcol\relax%
    \let\SB@spos\relax%
  \or%
    \let\SB@selectcol\SB@@selectcol%
    \let\SB@spos\SB@sposi%
  \or%
    \let\SB@selectcol\SB@@selectcol%
    \let\SB@spos\SB@sposii%
  \or%
    \let\SB@selectcol\SB@@selectcol%
    \let\SB@spos\SB@sposiii%
  \else%
    \SB@errspos%
  \fi%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\SB@spos}
% The |\SB@spos| macro gets redefined by |\songpos| above depending on the
% current song-positioning aggressiveness level.
% By default it is set to level 3.
%    \begin{macrocode}
\newcommand\SB@spos{}
\songpos\thr@@
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\SB@clearpage}
% Output all contributed material as a new page unless there is no contributed
% material. In that case do nothing (i.e., don't produce a blank page).
% The |\SB@colbox| is tested for zero height and depth rather than voidness,
% since sometimes it contains zero-length |\splittopskip| glue.
%    \begin{macrocode}
\newcommand\SB@clearpage{%
  \SB@testtrue%
  \ifvoid\SB@pgbox%
    \ifdim\ht\SB@colbox=\z@\ifdim\dp\SB@colbox=\z@%
      \SB@testfalse%
    \fi\fi%
  \fi%
  \ifSB@test%
    \SB@cnt\SB@numcols%
    \advance\SB@cnt-\SB@colnum%
    \SB@nextcol\SB@cnt\lastcolglue%
    \SB@output2%
  \fi%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\SB@cleardpage}
% Like |\SB@clearpage| but shift to a fresh \emph{even-numbered} page in
% two-sided documents.
% Note that this differs from \LaTeX's |\cleardoublepage|, which shifts to
% odd-numbered pages.
% Song books prefer starting things on even-numbered pages because this
% maximizes the distance until the next page-turn.
%    \begin{macrocode}
\newcommand\SB@cleardpage{%
  \SB@clearpage%
  \if@twoside\ifodd\c@page%
    \SB@nextcol\SB@numcols\@flushglue%
    \SB@output2%
  \fi\fi%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\SB@stype}
% There are two song content submission types: column- and page-submissions.
% Page-submissions are page-width and go atop fresh pages unless the current
% page has only page-width material so far.
% Column-submissions are column-width and start a new page only when the
% current page is full.
% This macro gets set to the desired type for the current submission.
% Mostly it stays set to the default column-submission type.
%    \begin{macrocode}
\newcommand\SB@stype{\SB@stypcol}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\SB@stypcol}
% \changes{v2.1}{2007/08/02}{Rewritten to better handle glue}
% Column-submissions contribute the contents of |\SB@songbox| to either the
% current column or the next column or page, depending on where it best fits.
%    \begin{macrocode}
\newcommand\SB@stypcol{%
  \ifnum\SB@numcols>\z@%
    \SB@selectcol%
    \global\setbox\SB@colbox\vbox{\SB@putboxes\unvbox}%
    \SB@output0%
  \else%
    \unvbox\voidb@x%
    \SB@breakpoint\spenalty%
    \ifdim\sbarheight>\z@%
      \vskip-\sbarheight\relax%
    \fi%
    \unvbox\SB@songbox%
  \fi%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\SB@styppage}
% Page-submissions go directly to the top of the nearest fresh page unless
% the current page has all page-width material so far.
%
% Implementation notes:
% The |\null| is needed because the page builder consults |\pagetotal|,
% which isn't updated by \TeX{} until a box is contributed (|\unvbox| doesn't
% count).
% Both |\nointerlineskip|s are needed because |\unvbox| fails to update
% |\prevdepth|, and it doesn't make sense to inherit its value from whatever
% preceeded this contribution.
% Authors who want interline glue must therefore insert it explicitly at the
% bottom of their contributed text.
%    \begin{macrocode}
\newcommand\SB@styppage{%
  \ifnum\SB@numcols>\z@%
    \SB@clearpage%
    \unvbox\SB@songbox%
    \nointerlineskip\null%
  \else%
    \unvbox\SB@songbox%
  \fi%
  \nointerlineskip%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\SB@sgroup}
% This macro controls whether songs submitted to the
% page-builder are actually contributed to the final document when
% using |\includeonlysongs| to generate a partial list.
% If |\SB@sgroup| is empty, then the song is silently dropped.
% Otherwise it is contributed only if |\SB@sgroup| is a member of
% |\songlist|.
%    \begin{macrocode}
\newcommand\SB@sgroup{}
\let\SB@sgroup\@empty
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\SB@groupcnt}
% This counter assigns a unique integer to each item of a group.
% Environments that come before the group's song are numbered decreasingly
% from $-1$.
% The song itself has number 0.
% Environments that come after the song are numbered increasingly from 1.
%    \begin{macrocode}
\SB@newcount\SB@groupcnt
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\SB@clearpboxes}
% This dynamically constructed macro clears the content of all boxes created
% by the workings of |\includeonlysongs|.
%    \begin{macrocode}
\newcommand\SB@clearpboxes{}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\SB@partbox}
% Save a box of full-song or chorus material for later output when producing
% a partial list using |\includeonlysongs|.
%    \begin{macrocode}
\newcommand\SB@partbox[1]{%
  \SB@newbox#1%
  \SB@app\gdef\SB@clearpboxes{\setbox#1\box\voidb@x}%
  \global\setbox#1\box%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\SB@submitpart}
% When a song completes and we're generating a partial list, save the song
% in a box so that it can be submitted at the end of the section in the
% order specified by |\includeonlysongs|.
%    \begin{macrocode}
\newcommand\SB@submitpart{%
  \ifx\SB@sgroup\@empty\else%
    \SB@testfalse
    \@for\SB@temp:=\songlist\do{\ifx\SB@temp\SB@sgroup\SB@testtrue\fi}%
    \ifSB@test%
      \edef\SB@tempii{\SB@sgroup @\the\SB@groupcnt}%
      \expandafter\SB@partbox
        \csname songbox@\SB@tempii\endcsname\SB@songbox%
      \global\expandafter\let%
        \csname stype@\SB@tempii\endcsname\SB@stype%
      \ifrepchorus\ifvoid\SB@chorusbox\else%
        \expandafter\SB@partbox
	  \csname chbox@\SB@tempii\endcsname\SB@chorusbox%
      \fi\fi%
    \fi%
    \global\advance\SB@groupcnt%
      \ifnum\SB@groupcnt<\z@\m@ne\else\@ne\fi%
  \fi%
  \setbox\SB@songbox\box\voidb@x%
  \setbox\SB@chorusbox\box\voidb@x%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\SB@submitsong}
% Submit the most recently finished song (or block of other vertical material)
% for output.
% If we're generating a partial list of songs, save it in a box instead of
% submitting it here.
% (The saved boxes will be submitted in the requested order at the end of
% the songs section.)
%    \begin{macrocode}
\newcommand\SB@submitsong{%
  \ifpartiallist\SB@submitpart\else\SB@stype\fi%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\SB@submitenv}
% Submit the |\SB@envbox| box as a page-width contribution.
%    \begin{macrocode}
\newcommand\SB@submitenv{%
  \begingroup%
    \let\SB@songbox\SB@envbox%
    \SB@styppage%
  \endgroup%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\SB@songlistbrk}
% \begin{macro}{\SB@songlistnc}
% \begin{macro}{\SB@songlistcp}
% \begin{macro}{\SB@songlistcdp}
% These macros define the words that, when placed in a |\songlist|,
% force a column break at that point.
% Using |brk| produces a soft break (like |\brk|) that won't leave
% whitespace at the bottom of the broken column in lyric books.
% Using |nextcol| produces a hard break (like |\nextcol|) that may
% insert whitespace to finish the column.
% Using |sclearpage| moves to the next page if the current page is
% nonempty.
% Using |scleardpage| moves to the next double-page if the current
% double-page is nonempty.
%    \begin{macrocode}
\newcommand*\SB@songlistbrk{brk}
\newcommand*\SB@songlistnc{nextcol}
\newcommand*\SB@songlistcp{sclearpage}
\newcommand*\SB@songlistcdp{scleardpage}
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\commitsongs}\MainImpl{commitsongs}
% If we're generating only a partial list, then wait until the end of the
% section and then output all the songs we saved in boxes in the order
% specified.
%    \begin{macrocode}
\newcommand\commitsongs{%
  \ifpartiallist%
    \ifnum\SB@numcols>\z@%
      \@for\SB@temp:=\songlist\do{%
        \ifx\SB@temp\SB@songlistnc\SB@nextcol\@ne\@flushglue\else%
        \ifx\SB@temp\SB@songlistbrk\SB@nextcol\@ne\colbotglue\else%
        \ifx\SB@temp\SB@songlistcp\SB@clearpage\else%
        \ifx\SB@temp\SB@songlistcdp\SB@cleardpage\else%
          \SB@groupcnt\m@ne\SB@finloop%
          \SB@groupcnt\z@\SB@finloop%
        \fi\fi\fi\fi%
      }%
    \else%
      \@for\SB@temp:=\songlist\do{%
        \ifx\SB@temp\SB@songlistnc\vfil\break\else%
        \ifx\SB@temp\SB@songlistbrk\break\else%
        \ifx\SB@temp\SB@songlistcp\clearpage\else%
        \ifx\SB@temp\SB@songlistcdp%
          \clearpage%
          \ifodd\c@page\null\newpage\fi%
        \else%
          \SB@groupcnt\m@ne\SB@finloop%
          \SB@groupcnt\z@\SB@finloop%
        \fi\fi\fi\fi%
      }%
    \fi%
    \SB@clearpboxes%
  \fi%
  \SB@clearpage%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\SB@finloop}
% While contributing saved material included by |\includeonlysongs|,
% this macro contributes each series of boxes grouped together as part of a
% |songgroup| environment.
%    \begin{macrocode}
\newcommand\SB@finloop{%
  \loop\edef\SB@tempii{\SB@temp @\the\SB@groupcnt}%
       \expandafter\ifx%
         \csname songbox@\SB@tempii\endcsname\relax\else%
    \setbox\SB@songbox\expandafter\copy%
        \csname songbox@\SB@tempii\endcsname%
    \expandafter\ifx\csname chbox@\SB@tempii\endcsname\relax%
      \repchorusfalse%
    \else%
      \repchorustrue%
      \setbox\SB@chorusbox\expandafter\copy%
        \csname chbox@\SB@tempii\endcsname%
    \fi%
    \csname stype@\SB@tempii\endcsname%
    \advance\SB@groupcnt\ifnum\SB@groupcnt<\z@\m@ne\else\@ne\fi%
  \repeat%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\SB@insertchorus}
% Insert a chorus into the first marked spot in the box given
% in the first argument.
% This is usually achieved by splitting the box at the first valid
% breakpoint after the first |\SB@cmark| in the box.
% The box is globally modified.
%    \begin{macrocode}
\newcommand\SB@insertchorus[1]{{%
  \vbadness\@M\vfuzz\maxdimen%
  \setbox\SB@box\copy#1%
  \setbox\SB@box\vsplit\SB@box to\maxdimen%
  \edef\SB@temp{\splitfirstmarks\SB@nocmarkclass}%
  \ifx\SB@temp\SB@nocmark\else%
    \edef\SB@temp{\splitfirstmarks\SB@cmarkclass}%
    \ifx\SB@temp\SB@cmark%
      \SB@dimen4096\p@%
      \SB@dimenii\maxdimen%
      \SB@dimeniii\SB@dimen%
      \loop%
        \SB@dimeniii.5\SB@dimeniii%
        \setbox\SB@box\copy#1%
        \setbox\SB@box\vsplit\SB@box to\SB@dimen%
        \edef\SB@temp{\splitfirstmarks\SB@cmarkclass}%
        \ifx\SB@temp\SB@cmark%
          \SB@dimenii\SB@dimen%
          \advance\SB@dimen-\SB@dimeniii%
        \else%
          \advance\SB@dimen\SB@dimeniii%
        \fi%
      \ifdim\SB@dimeniii>2\p@\repeat%
      \setbox\SB@box\vsplit#1to\SB@dimenii%
      \global\setbox#1\vbox{%
        \unvbox\SB@box\unskip%
        \SB@inversefalse\SB@prevversetrue\SB@stanzabreak%
        \SB@putbox\unvcopy\SB@chorusbox%
        \SB@inversetrue\SB@prevversefalse\SB@stanzabreak%
        \unvbox#1%
      }%
%    \end{macrocode}
% However, if the first mark is a |\SB@lastcmark|, it means that this chorus
% should go after the last verse in the song.
% There is no valid breakpoint there, so to get a chorus into that spot, we
% have to do a rather ugly hack:
% We pull the bottom material off the box with |\unskip|, |\unpenalty|, and
% |\lastbox|, then insert the chorus, then put the bottom material back on.
% This works because the high-level structure of the bottom material should
% be static.
% Even if the user redefines |\makepostlude|, the new definition gets put
% in a single box that can be manipulated with |\lastbox|.
% However, if we ever change the high-level structure, we need to remember to
% change this code accordingly.
%    \begin{macrocode}
    \else\ifx\SB@temp\SB@lastcmark%
      \global\setbox#1\vbox{%
        \unvbox#1%
        \unskip%
        \ifdim\sbarheight>\z@%
          \setbox\SB@box\lastbox%
          \unskip\unpenalty%
        \fi%
        \setbox\SB@box\lastbox%
        \unskip\unskip%
        \SB@inversefalse\SB@prevversetrue\SB@stanzabreak%
        \marks\SB@nocmarkclass{\SB@nocmark}%
        \unvcopy\SB@chorusbox%
        \vskip\versesep\vskip\beforepostludeskip\relax%
        \nointerlineskip\box\SB@box%
        \ifdim\sbarheight>\z@%
          \nobreak\vskip2\p@\@plus\p@%
          \hrule\@height\sbarheight\@width\SB@colwidth%
        \fi%
      }%
    \fi\fi%
  \fi%
}}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\nextcol}\MainImpl{nextcol}
% End the current column (inserting vertical space as needed).
% This differs from column breaks produced with |\brk|, which does not
% introduce any empty vertical space.
%    \begin{macrocode}
\newcommand\nextcol{%
  \@ifstar{\SB@nextcol\@ne\@flushglue}%
          {\ifpartiallist\else\SB@nextcol\@ne\@flushglue\fi}%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\sclearpage}\MainImpl{sclearpage}
% Move to the next page if the current page is nonempty.
%    \begin{macrocode}
\newcommand\sclearpage{%
  \@ifstar\SB@clearpage{\ifpartiallist\else\SB@clearpage\fi}%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\scleardpage}\MainImpl{scleardpage}
% Move to the next even-numbered page if the current page is odd or nonempty.
%    \begin{macrocode}
\newcommand\scleardpage{%
  \@ifstar\SB@cleardpage{\ifpartiallist\else\SB@cleardpage\fi}%
}
%    \end{macrocode}
% \end{macro}
%
% \subsection{Songs}
%
% The following macros handle the parsing and formatting of the material that
% begins and ends each song.
%
% \begin{macro}{\SB@lop}
% \begin{macro}{\SB@@lop}
% \begin{macro}{\SB@emptylist}
% \begin{macro}{\SB@ifempty}
% The following macros were adapted from Donald Knuth's \emph{The \TeX book},
% for manipulating lists of the form
% {\it |\\|item1|\\|item2|\\|...|\\|itemN|\\|}.
%    \begin{macrocode}
\newcommand\SB@lop[1]{\expandafter\SB@@lop\the#1\SB@@lop#1}
\newcommand\SB@@lop{}
\def\SB@@lop\\#1\\#2\SB@@lop#3#4{\global#3{\\#2}\global#4{#1}}
\newcommand*\SB@emptylist{\\}
\newcommand\SB@ifempty[3]{%
  \edef\SB@temp{\the#1}%
  \ifx\SB@temp\SB@emptylist#2\else#3\fi%
}
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\SB@titlelist}
% \begin{macro}{\SB@titletail}
% These registers hold the full list of titles for the current song and
% the tail list of titles that has not yet been iterated over.
%    \begin{macrocode}
\SB@newtoks\SB@titlelist
\SB@newtoks\SB@titletail
%    \end{macrocode}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\songtitle}
% \changes{v1.15}{2005/05/26}{Added song title iterators}
% The |\songtitle| macro will initially hold the primary title of the
% current song.
% The user can iterate over titles using |\nexttitle| or |\foreachtitle|.
%    \begin{macrocode}
\newcommand\songtitle{}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\resettitles}\MainImpl{resettitles}
% \changes{v1.15}{2005/05/26}{Added.}
% Initialize the title list iterator.
%    \begin{macrocode}
\newcommand\resettitles{%
  \global\SB@titletail\SB@titlelist%
  \nexttitle%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\nexttitle}\MainImpl{nexttitle}
% \changes{v1.15}{2005/05/26}{Added.}
% Advance the title list iterator to the next title.
%    \begin{macrocode}
\newcommand\nexttitle{%
  \SB@ifempty\SB@titletail{%
    \global\let\songtitle\relax%
  }{%
    \SB@lop\SB@titletail\SB@toks%
    \edef\songtitle{\the\SB@toks}%
  }%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\foreachtitle}\MainImpl{foreachtitle}
% \changes{v1.15}{2005/05/26}{Added.}
% Execute a block of code for each remaining title in the title list.
%    \begin{macrocode}
\newcommand\foreachtitle[1]{%
  \ifx\songtitle\relax\else%
    \loop#1\nexttitle\ifx\songtitle\relax\else\repeat%
  \fi%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\ifSB@insong}
% \begin{macro}{\ifSB@intersong}
% \begin{macro}{\ifSB@inverse}
% \begin{macro}{\ifSB@inchorus}
% To help the user locate errors, keep track of which environments we're inside
% and immediately signal an error if someone tries to use a song command inside
% a scripture quotation, etc.
%    \begin{macrocode}
\newif\ifSB@songsenv\SB@songsenvfalse
\newif\ifSB@insong\SB@insongfalse
\newif\ifSB@intersong\SB@intersongfalse
\newif\ifSB@inverse\SB@inversefalse
\newif\ifSB@inchorus\SB@inchorusfalse
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\SB@closeall}
% If an error is detected using one of the above, the following macro will
% contain a macro sequence sufficient to end the unclosed environment,
% hopefully allowing processing to continue.
%    \begin{macrocode}
\newcommand\SB@closeall{}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\SB@rawrefs}
% \begin{macro}{\songauthors}\MainImpl{songauthors}
% \begin{macro}{\songcopyright}\MainImpl{songcopyright}
% \begin{macro}{\songlicense}\MainImpl{songlicense}
% The current song's scripture references, authors, copyright info, and
% copyright license information are stored in these macros.
%    \begin{macrocode}
\newcommand\SB@rawrefs{}
\newcommand\songauthors{}
\newcommand\songcopyright{}
\newcommand\songlicense{}
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\songrefs}\MainImpl{songrefs}
% When the user asks for the song's scripture references, rather than give
% them the raw token list that the author entered, we return a prettier
% version in which spaces, dashes, and penalties have been adjusted.
% The prettier version is stored in the following control sequence.
%    \begin{macrocode}
\newcommand\songrefs{}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\setlicense}\MainImpl{setlicense}
% The user sets the licensing info for the current song with this command.
%    \begin{macrocode}
\newcommand\setlicense{\gdef\songlicense}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\newsongkey}\MainImpl{newsongkey}
% \begin{macro}{\SB@clearbskeys}
% \changes{v2.0}{2007/06/18}{Added.}
% Defining a new key for |\beginsong| is just like the |keyval| package's
% |\define@key| macro except that we must also define some initializer code
% for each key.
% This provides an opportunity to clear registers before each song.
% (Otherwise when a key wasn't specified, we'd inherit the old values from
% the previous song.)
%    \begin{macrocode}
\newcommand\SB@clearbskeys{}
\newcommand\newsongkey[2]{%
  \SB@app\gdef\SB@clearbskeys{#2}%
  \define@key{beginsong}{#1}%
}
%    \end{macrocode}
% \end{macro}
% \end{macro}
%
% Define keys |sr|, |by|, |cr|, |li|, |index|, and |ititle| for scripture
% references, authors, copyright info, licensing info, lyric index entries,
% and alternate title index entries, respectively.
%    \begin{macrocode}
\newsongkey{sr}{\def\SB@rawrefs{}\gdef\songrefs{}}
               {\def\SB@rawrefs{#1}\SB@parsesrefs{#1}}
\newsongkey{by}{\def\songauthors{}}{\def\songauthors{#1}}
\newsongkey{cr}{\def\songcopyright{}}{\def\songcopyright{#1}}
\newsongkey{li}{\setlicense{}}{\setlicense{#1}}
\newsongkey{index}{}{\indexentry{#1}}
\newsongkey{ititle}{}{\indextitleentry{#1}}
%    \end{macrocode}
%
% \begin{environment}{song}\MainEnvImpl{song}
% \begin{macro}{\beginsong}
% \begin{macro}{\SB@@beginsong}
% \begin{macro}{\SB@bsoldfmt}
% \begin{macro}{\SB@@bskvfmt}
% Parse the arguments of a |\beginsong| macro.
% The |\beginsong| macro supports two syntaxes.
% The preferred syntax takes the song title(s) as its first argument and
% an optional keyval list in brackets as its second argument.
% A legacy syntax supports four arguments, all enclosed in braces,
% which are: the title(s), scripture references, authors, and copyright info.
%    \begin{macrocode}
\newenvironment{song}{\beginsong}{\SB@endsong}
\newcommand\beginsong[1]{%
  \ifSB@insong\SB@errboo\SB@closeall\fi%
  \ifSB@intersong\SB@errbor\SB@closeall\fi%
  \SB@insongtrue%
  \def\SB@closeall{\endsong}%
  \SB@parsetitles{#1}%
  \global\setbox\SB@songwrites\box\voidb@x%
  \SB@clearbskeys%
  \@ifnextchar[\SB@bskvfmt\SB@@beginsong%
}
\newcommand\SB@@beginsong{%
  \@ifnextchar\bgroup\SB@bsoldfmt\SB@@@beginsong%
}
\newcommand\SB@bsoldfmt[3]{%
  \SB@bskvfmt[sr={#1},by={#2},cr={#3}]%
}
\newcommand\SB@bskvfmt{}
\def\SB@bskvfmt[#1]{%
  \setkeys{beginsong}{#1}%
  \SB@@@beginsong%
}
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\SB@@@beginsong}
% \changes{v1.12}{2005/05/10}{Redid spacing and page-breaking}
% \changes{v1.14}{2005/05/15}{Improved scripture reference line-breaking}
% \changes{v2.0}{2007/06/18}{Added keyval syntax.}
% Begin typesetting a song.
% Beginning a song involves typesetting the title and other info, adding
% entries to the indexes, and setting up the environment in which verses and
% choruses reside.
%    \begin{macrocode}
\newcommand\SB@@@beginsong{%
  \global\SB@stanzafalse%
  \setbox\SB@chorusbox\box\voidb@x%
  \SB@gotchorusfalse%
  \setbox\SB@songbox\vbox\bgroup\begingroup%
    \ifnum\SB@numcols>\z@\hsize\SB@colwidth\fi%
    \leftskip\z@skip\rightskip\z@skip%
    \parfillskip\@flushglue\parskip\z@skip%
    \SB@raggedright%
    \global\SB@transposefactor\z@%
    \global\SB@cr@{\\}%
    \protected@edef\@currentlabel{\p@songnum\thesongnum}%
    \setcounter{versenum}{1}%
    \SB@prevversetrue%
    \meter44%
    \resettitles%
    \SB@addtoindexes\songtitle\SB@rawrefs\songauthors%
    \nexttitle%
    \foreachtitle{\expandafter\SB@addtotitles\expandafter{\songtitle}}%
    \resettitles%
    \lyricfont\relax%
    \SB@setbaselineskip%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\SB@endsong}
% \changes{v1.12}{2005/05/10}{Redid spacing and page-breaking}
% \changes{v2.0}{2007/06/18}{Removed hyperref dependency}
% Ending a song involves creating the song header (with |\makeprelude|),
% creating the song footer (with |\makepostlude|), and then assembling
% everything together into the |\SB@songbox|.
% The box is then submitted to the page-builder via |\SB@submitsong|.
% We do things this way instead of just contributing material directly
% to the main vertical list because submitting material song by song allows
% for a more sophisticated page-breaking algorithm than is possible with
% \TeX's built-in algorithm.
%    \begin{macrocode}
\newcommand\SB@endsong{%
  \ifSB@insong%
      \ifSB@inverse\SB@erreov\endverse\fi%
      \ifSB@inchorus\SB@erreoc\endchorus\fi%
      \global\SB@skip\versesep%
      \unskip%
      \ifrepchorus\ifvoid\SB@chorusbox\else%
        \ifSB@prevverse\ifvnumbered%
          \marks\SB@cmarkclass{\SB@lastcmark}%
        \fi\fi%
      \fi\fi%
    \endgroup\egroup%
    \begingroup%
      \ifnum\SB@numcols>\z@%
        \hsize\ifpagepreludes\textwidth\else\SB@colwidth\fi%
      \fi%
      \leftskip\z@skip\rightskip\z@skip%
      \parfillskip\@flushglue\parskip\z@skip\parindent\z@%
      \global\setbox\SB@envbox\vbox{%
        \songmark%
        \unvbox\SB@songwrites%
        \ifpagepreludes\else\ifdim\sbarheight>\z@%
          \hrule\@height\sbarheight\@width\hsize%
          \nobreak\vskip5\p@\relax%
        \fi\fi%
        \resettitles%
        \begingroup%
          \songtarget{\ifnum\c@section=\z@1\else2\fi}%
                     {song\theSB@songsnum-\thesongnum}%
        \endgroup%
        \vbox{\makeprelude}%
        \nobreak\vskip\SB@skip%
        \vskip\afterpreludeskip\relax%
      }%
      \ifnum\SB@numcols>\z@\hsize\SB@colwidth\fi%
      \global\setbox\SB@songbox\vbox{%
        \ifpagepreludes\else\unvbox\SB@envbox\fi%
        \unvbox\SB@songbox%
        \nobreak\vskip\SB@skip%
        \vskip\beforepostludeskip\relax%
        \nointerlineskip%
        \vbox{\makepostlude}%
        \ifdim\sbarheight>\z@%
          \nobreak\vskip2\p@\@plus\p@%
          \nointerlineskip%
          \hbox{\vrule\@height\sbarheight\@width\hsize}%
        \fi%
      }%
    \endgroup%
    \SB@insongfalse%
    \edef\SB@sgroup{\thesongnum}%
    \global\SB@groupcnt\z@%
    \ifpagepreludes\SB@submitenv\fi%
    \SB@submitsong%
    \ifnum\SB@grouplvl=\z@\let\SB@sgroup\@empty\fi%
    \stepcounter{songnum}%
  \else%
    \ifSB@intersong\SB@erreor\SB@closeall%
    \else\SB@erreot\fi%
  \fi%
}
%    \end{macrocode}
% \end{macro}
% \end{environment}
%
% \begin{macro}{\SB@setbaselineskip}
% \changes{v1.22}{2007/05/15}{Added.}
% \changes{v2.1}{2007/08/02}{Fixed to scale better with large font sizes.}
% Set the |\baselineskip| to an appropriate line height.
%    \begin{macrocode}
\newcommand\SB@setbaselineskip{%
  \SB@dimen\f@size\p@%
  \baselineskip\SB@dimen\relax%
  \ifchorded%
    \setbox\SB@box\hbox{{\printchord{ABCDEFG\shrp\flt/j7}}}%
    \advance\baselineskip\ht\SB@box%
    \advance\baselineskip2\p@%
  \fi%
  \ifslides%
    \advance\baselineskip.2\SB@dimen\@plus.5\SB@dimen%
      \@minus.2\SB@dimen%
  \else%
    \advance\baselineskip\z@\@plus.1\SB@dimen\relax%
  \fi%
  \advance\baselineskip\baselineadj%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\SB@setversesep}
% Set the |\versesep| to an appropriate amount if has not already been
% explicitly set by the user.
%    \begin{macrocode}
\newcommand\SB@setversesep{%
  \SB@dimen123456789sp%
  \edef\SB@temp{\the\SB@dimen}%
  \edef\SB@tempii{\the\versesep}%
  \ifx\SB@temp\SB@tempii%
    \begingroup%
      \lyricfont\relax%
      \SB@dimen\f@size\p@%
      \ifchorded%
        \setbox\SB@box\hbox{{\printchord{ABCDEFG\shrp\flt/j7}}}%
        \advance\SB@dimen\ht\SB@box%
      \fi%
      \ifslides%
        \global\versesep1.2\SB@dimen\@plus.3\SB@dimen%
        \@minus.3\SB@dimen%
      \else%
        \global\versesep.75\SB@dimen\@plus.25\SB@dimen%
        \@minus.13\SB@dimen%
      \fi%
    \endgroup%
  \fi%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\makeprelude}\MainImpl{makeprelude}
% \changes{v1.15}{2005/05/26}{Added to make song header format customizable.}
% \changes{v2.0}{2007/06/18}{Arguments removed to support keyval syntax.}
% Generate the material that begins each song.
% This macro is invoked at |\endsong| so that its code can access song info
% defined throughout the song.
%
% Note that if you are redefining |\makeprelude|, you can probably replace
% everything below with something much simpler.
% The code below is lengthy because it accommodates all of the many different
% options that various authors may adjust to customize their books.
% If you redefine it, you can replace all of this with smaller, more
% specialized programming that just outputs the prelude format you desire. 
%    \begin{macrocode}
\newcommand\makeprelude{%
  \resettitles%
%    \end{macrocode}
% In slides mode, the title, references, and authors are simply centered on
% the page with no song number.
% Only the first of the song titles is included.
% The references and authors only span the middle 50\% of the page, since
% letting them span the whole page width stretches them out too much and makes
% their fine print too hard to read.
%    \begin{macrocode}
  \ifslides%
    \hbox to\hsize{{\hfil\stitlefont\relax\songtitle\hfil}}%
    \vskip5\p@%
    \hbox to\hsize{%
      \hfil%
      \vbox{%
        \divide\hsize\tw@\parskip\p@\relax%
        \centering\small\extendprelude%
      }%
      \hfil%
    }%
  \else%
%    \end{macrocode}
% In non-slides mode, we write the song number in a shaded box to the left
% (if |\songnumwidth| is positive) and everything else in left-justified
% paragraphs to the right of it (or centered if |\pagepreludes| is on).
% The height of the shaded box that contains the song number depends on
% which is higher: the natural height of the song number, or everything else
% that goes to the right of it.
% To find out which is higher, we start by putting the song number in its
% own box (|\SB@boxii|).
%    \begin{macrocode}
    \ifdim\songnumwidth>\z@%
      \setbox\SB@boxii\hbox{{\SB@colorbox\snumbgcolor{%
        \hbox to\songnumwidth{%
          \printsongnum{\thesongnum}\hfil%
        }%
      }}}%
    \fi%
%    \end{macrocode}
% Now we know the width $w$ of the song number box, so we typeset everything
% else in a box (|\SB@box|) of width $c-w$, where $c$ is the column width.
% (If |\pagepreludes| is on, we instead use width $c-2w$ so that the material
% stays centered on the page.)
%    \begin{macrocode}
    \setbox\SB@box\vbox{%
      \ifdim\songnumwidth>\z@%
        \SB@dimen\wd\SB@boxii%
        \advance\SB@dimen3\p@%
        \ifpagepreludes\multiply\SB@dimen\tw@\fi%
        \advance\hsize-\SB@dimen%
      \fi%
      \ifpagepreludes\centering\else\SB@raggedright\fi%
      \offinterlineskip\lineskip\p@%
      {\stitlefont\relax%
       \songtitle\par%
       \nexttitle%
       \foreachtitle{(\songtitle)\par}}%
      \ifdim\prevdepth=\z@\kern\p@\fi%
      \parskip\p@\relax\tiny%
      \extendprelude%
      \kern\z@%
    }%
%    \end{macrocode}
% If the song number is being printed (i.e., |\songnumwidth| is positive),
% and its height is greater than the height of the other material, then we
% just put |\SB@boxii| and |\SB@box| side-by-side.
% If the song number is being printed but its height is less, then we
% re-typeset it at height equal to the other material, and place the boxes
% side-by-side.
% Finally, if the song number is not being printed at all, we just unbox
% |\SB@box| onto the vertical list.
%    \begin{macrocode}
    \ifdim\songnumwidth>\z@%
      \hbox{%
        \ifdim\ht\SB@boxii>\ht\SB@box%
          \box\SB@boxii%
          \kern3\p@%
          \vtop{\box\SB@box}%
        \else%
          \SB@colorbox\snumbgcolor{\vbox to\ht\SB@box{{%
            \hbox to\songnumwidth{%
              \printsongnum{\thesongnum}\hfil%
            }\vfil%
          }}}%
          \kern3\p@%
          \box\SB@box%
        \fi%
      }%
    \else%
      \unvbox\SB@box%
    \fi%
  \fi%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\makepostlude}\MainImpl{makepostlude}
% \changes{v1.15}{2005/05/26}{Added to make song trailer format customizable.}
% \changes{v2.0}{2007/06/18}{Arguments removed to support keyval syntax.}
% Generate the material that ends each song.
% The default implementation just prints the copyright and licensing
% information (if any) as a single, left-justified, non-indentended paragraph
% in fine print.
%    \begin{macrocode}
\newcommand\makepostlude{%
  \SB@raggedright\baselineskip\z@skip\parskip\z@skip\parindent\z@%
  \tiny\extendpostlude%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\showauthors}\MainImpl{showauthors}
% Display the author information in the prelude.
% This macro is only called by |\extendprelude|, which is only called by
% |\makeprelude|; so if you redefine either of those, you don't need this.
% The default implementation prints the authors in boldface and shortens the
% spacing after periods so that they don't look like ends of sentences.
%    \begin{macrocode}
\newcommand\showauthors{%
  \setbox\SB@box\hbox{\bfseries\sfcode`.\@m\songauthors}%
  \ifdim\wd\SB@box>\z@\unhbox\SB@box\par\fi%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\showrefs}\MainImpl{showrefs}
% Display the scripture references in the prelude.
% This macro is only called by |\extendprelude|, which is only called by
% |\makeprelude|; so if you redefine either of those, you don't need this.
% The default implementation prints the scripture references in slanted
% (oblique) font.
%    \begin{macrocode}
\newcommand\showrefs{%
  \setbox\SB@box\hbox{\slshape\songrefs\vphantom,}%
  \ifdim\wd\SB@box>\z@\unhbox\SB@box\par\fi%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\SB@next}
% \begin{macro}{\SB@donext}
% \begin{macro}{\SB@dothis}
% Several macros use |\futurelet| to look ahead in the input stream, and then
% take various actions depending on what is seen.
% In these macros, |\SB@next| is assigned the token seen, |\SB@dothis| is
% assigned the action to be taken on this loop iteration, and |\SB@donext| is
% assigned the action to be taken to continue (or terminate) the loop.
%    \begin{macrocode}
\newcommand\SB@next{}
\newcommand\SB@donext{}
\newcommand\SB@dothis{}
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\SB@nextname}
% Sometimes when scanning ahead we |\string|ify the name of the next token.
% When that happens, the name is stored in this macro for safekeeping.
%    \begin{macrocode}
\newcommand\SB@nextname{}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\SB@appendsp}
% Append an explicit space token (catcode 10) to a token register.
% This is a useful macro to have around because inlining this code directly
% into a larger macro is harder than it seems:
% If you write the following code but with an explicit control sequence
% instead of |#1|, then the space immediately following the name will get
% stripped by the \TeX{} parser.
% But invoking the following macro with a control sequence as an argument
% works fine, because in that case the explicit space has already been
% tokenized when this macro was first defined and won't be stripped as it
% is expanded.
%    \begin{macrocode*}
\newcommand\SB@appendsp[1]{#1\expandafter{\the#1 }}
%    \end{macrocode*}
% \end{macro}
%
% \begin{macro}{\SB@parsetitles}
% \changes{v2.1}{2007/08/02}{Added}
% Parse a list of song titles.
% This just involves removing leading and trailing spaces from around each
% title in the |\\|-separated list.
%    \begin{macrocode}
\newcommand\SB@parsetitles[1]{%
  \begingroup%
    \global\SB@titlelist{\\}%
    \SB@toks{}%
    \let\\\SB@titlesep%
    \SB@pthead#1\SB@endparse%
  \endgroup%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\SB@pthead}
% \begin{macro}{\SB@@pthead}
% \begin{macro}{\SB@@@pthead}
% While processing tokens at the head of a title, we skip over all spaces
% until we reach a non-space token.
%    \begin{macrocode}
\newcommand\SB@pthead{\futurelet\SB@next\SB@@pthead}
\newcommand\SB@@pthead{%
  \ifcat\noexpand\SB@next\@sptoken%
    \expandafter\SB@@@pthead%
  \else%
    \expandafter\SB@ptmain%
  \fi%
}
\newcommand\SB@@@pthead{%
  \afterassignment\SB@pthead%
  \let\SB@next= }
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\SB@ptloop}
% The iterator of the title parser loop just scans the next token.
%    \begin{macrocode}
\newcommand\SB@ptloop{\futurelet\SB@next\SB@ptmain}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\SB@ptmain}
% Once we've reached a non-space token in the title, we consume the remainder
% of the title as-is, except that space tokens should be trimmed from the end
% of each title.
%    \begin{macrocode}
\newcommand\SB@ptmain{%
  \ifcat\noexpand\SB@next\@sptoken%
    \let\SB@donext\SB@ptsp%
  \else\ifcat\noexpand\SB@next\bgroup%
    \let\SB@donext\SB@ptbg%
  \else\ifx\SB@next\SB@endparse%
    \global\SB@titlelist\expandafter{\the\SB@titlelist\\}%
    \let\SB@donext\@gobble%
  \else\ifx\SB@next\\%
    \SB@toks{}%
    \def\SB@donext{\SB@ptstep\SB@pthead}%
  \else%
    \def\SB@donext{\SB@ptstep\SB@ptloop}%
  \fi\fi\fi\fi%
  \SB@donext}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\SB@ptstep}
% Consume a non-space, non-left-brace token and add it to the current song
% title.
% If any spaces preceded it, add those too.
%    \begin{macrocode}
\newcommand\SB@ptstep[2]{%
  \global\SB@titlelist\expandafter\expandafter\expandafter{%
    \expandafter\the\expandafter\SB@titlelist\the\SB@toks#2}%
  \SB@toks{}%
  #1}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\SB@ptbg}
% The next title token is a left-brace.
% It should be balanced, so consume the entire group and add it (along with
% its surrounding braces) as-is to the current title.
%    \begin{macrocode}
\newcommand\SB@ptbg[1]{\SB@ptstep\SB@ptloop{{#1}}}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\SB@ptsp}
% The next title token is a space.
% We won't know whether to include it in the title until we see what
% follows it.
% Strings of spaces followed by the |\\| title-delimiter token, or that
% conclude a title argument, should be stripped.
% So rather than add the space token to the title, we remember it in a
% token register for possible later inclusion.
%    \begin{macrocode}
\newcommand\SB@ptsp{
  \SB@appendsp\SB@toks%
  \afterassignment\SB@ptloop%
  \let\SB@next= }
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\SB@titlesep}
% While parsing song titles, we temporarily assign |\\| a non-trivial
% top-level expansion (|\SB@titlesep|) in order to distinguish it from
% other macros.
%    \begin{macrocode}
\newcommand\SB@titlesep{SB@titlesep}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\SB@endparse}
% The |\SB@endparse| token marks the end of a token sequence being parsed.
% If parsing works as intended, the macro should never be expanded, so
% produce an error if it is.
%    \begin{macrocode}
\newcommand\SB@endparse{%
  \SB@Error{Title parsing failed}{This error should not occur.}%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\SB@parsesrefs}
% \changes{v1.14}{2005/05/15}{Added}
% Assign the |\songrefs| macro a processed version of a scripture reference in
% which the following adjustments have been made:
% (1)~Spaces not preceded by a comma or semicolon are made non-breaking.
% For example, |2 John 1:1| and |Song of Solomon 1:1| become |2~John~1:1| and
% |Song~of~Solomon~1:1|, respectively.
% (2)~Spaces between a semicolon and a book name are lengthened to en-spaces.
% (3)~Single hyphens are lengthened to en-dashes (|--|).
% (4)~Non-breaking, thin spaces are appended to commas not followed by a
% space. For example |John 3:16,17| becomes |John~3:16,\nobreak\thinspace17|.
% (5)~Everything within an explicit group is left unchanged, allowing the
% user to suppress all of the above as desired.
%
% To achieve this, we must change all commas, hyphens, and spaces
% in the scripture reference into active characters.
% Unfortunately, the catcodes of everything in the text were set back when
% the full keyval list was digested as an argument to |\beginsong|, so we
% must unset and reset the catcodes.
% One obvious solution is to use |\scantokens| from $\varepsilon$-\TeX{} to
% do this, but that doesn't allow us to suppress the re-catcoding process
% within groups, and we'd like to avoid intoducing features that require
% $\varepsilon$-\TeX{} anyway for compatibility reasons.
% Therefore, we build the following small scanner instead.
%
% The scanner walks through the text token by token, replacing each important
% token by its active equivalent.
% No character codes are modified during this process and no tokens are
% inserted because some of these tokens might end up being arguments to
% multi-byte unicode character macros rather than being expanded directly.
% The |inputenc| package only cares about the character codes, not the
% category codes, so modifying only the category codes should be safe.
%    \begin{macrocode}
\newcommand\SB@parsesrefs[1]{%
  \begingroup%
    \SB@toks{\begingroup\SB@sractives}%
    \SB@prloop#1\SB@endparse%
    \xdef\songrefs{\the\SB@toks\endgroup}%
  \endgroup%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\SB@prloop}
% \begin{macro}{\SB@prstep}
% \begin{macro}{\SB@@prstep}
% The main loop of the scripture reference scanner identifies each space,
% hyphen, and comma for special treatment.
%    \begin{macrocode}
\newcommand\SB@prloop{\futurelet\SB@next\SB@prstep}
\newcommand\SB@prstep{%
  \ifcat\noexpand\SB@next A%
    \expandafter\SB@prcpy%
  \else%
    \expandafter\SB@@prstep%
  \fi%
}
\newcommand\SB@@prstep{%
  \ifcat\noexpand\SB@next\@sptoken%
    \let\SB@donext\SB@prspace%
  \else\ifx\SB@next-%
    \let\SB@donext\SB@prhyphen%
  \else\ifx\SB@next,%
    \let\SB@donext\SB@prcomma%
  \else\ifx\SB@next\SB@endparse%
    \let\SB@donext\@gobble%
  \else\ifcat\noexpand\SB@next\bgroup%
    \let\SB@donext\SB@prgr%
  \else%
    \let\SB@donext\SB@prcpy%
  \fi\fi\fi\fi\fi%
  \SB@donext%
}
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\SB@prcpy}
% \begin{macro}{\SB@prgr}
% Anything that isn't one of the special tokens above, and anything in a
% group, is copied without modification.
%    \begin{macrocode}
\newcommand\SB@prcpy[1]{\SB@toks\expandafter{\the\SB@toks#1}\SB@prloop}
\newcommand\SB@prgr[1]{\SB@toks\expandafter{\the\SB@toks{#1}}\SB@prloop}
%    \end{macrocode}
% \end{macro}
% \end{macro}

% \begin{macro}{\SB@prcomma}
% \begin{macro}{\SB@prhyphen}
% Commas and hyphens are replaced with active equivalents.
%    \begin{macrocode} 
\newcommand\SB@prcomma[1]{}
{\catcode`,\active
 \gdef\SB@prcomma#1{\SB@toks\expandafter{\the\SB@toks,}\SB@prloop}}
\newcommand\SB@prhyphen[1]{}
{\catcode`-\active
 \gdef\SB@prhyphen#1{\SB@toks\expandafter{\the\SB@toks-}\SB@prloop}}
%    \end{macrocode}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\SB@prspace}
% \begin{macro}{\SB@@prspace}
% Spaces are made active as well, but doing so requires some
% specialized code since they cannot be consumed as implicit macro arguments.
%    \begin{macrocode*}
\newcommand\SB@prspace[1]{}
{\obeyspaces
\gdef\SB@prspace{\SB@toks\expandafter{\the\SB@toks }\SB@@prspace}}
%    \end{macrocode*}
%    \begin{macrocode}
\newcommand\SB@@prspace{\afterassignment\SB@prloop\let\SB@temp= }
%    \end{macrocode}
% \end{macro}
% \end{macro}

% \begin{macro}{\SB@sractives}
% Assign macro definitions to active commas, hyphens, spaces, and returns
% when the token list generated by |\SB@parsesrefs| is used to typeset a
% scripture reference list.
%    \begin{macrocode*}
\newcommand\SB@sractives{}
{\catcode`,\active\catcode`-\active\obeyspaces%
\gdef\SB@sractives{%
\let,\SB@srcomma\let-\SB@srhyphen\let \SB@srspace%
\SB@srspacing}%
}
%    \end{macrocode*}
% \end{macro}
%
% \begin{macro}{\SB@srspacing}
% The space factors of semicolons and commas are what the active spaces
% within a scripture reference text use to decide what came before.
% The following sets them to their default values in case they have been
% changed, but sets all other space factors to 1000.
%    \begin{macrocode}
\newcommand\SB@srspacing{%
  \nonfrenchspacing\sfcode`\;=1500\sfcode`\,=1250\relax%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\SB@srcomma}
% \begin{macro}{\SB@@srcomma}
% Commas not already followed by whitespace are appended with a thin,
% non-breaking space.
%    \begin{macrocode}
\newcommand\SB@srcomma{,\futurelet\SB@next\SB@@srcomma}
\newcommand\SB@@srcomma{%
  \ifx\SB@next\SB@srspace\else%
    \nobreak\thinspace%
  \fi%
}
%    \end{macrocode}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\SB@srhyphen}
% \begin{macro}{\SB@@srhyphen}
% \begin{macro}{\SB@srdash}
% \begin{macro}{\SB@@srdash}
% Hyphens that are not already part of a ligature (an en- or em-dash)
% become en-dashes.
%    \begin{macrocode}
\newcommand\SB@srhyphen{\futurelet\SB@next\SB@@srhyphen}
\newcommand\SB@@srhyphen{%
  \ifx\SB@next\SB@srhyphen\expandafter\SB@srdash\else--\fi%
}
\newcommand\SB@srdash[1]{\futurelet\SB@next\SB@@srdash}
\newcommand\SB@@srdash{%
  \ifx\SB@next\SB@srhyphen---\expandafter\@gobble\else--\fi%
}
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\SB@srspace}
% \begin{macro}{\SB@@srspace}
% To compress consecutive whitespace, we ignore spaces
% immediately followed by more whitespace.
% Spaces not preceded by a semicolon or comma become non-breaking.
% Most spaces following a semicolon become en-spaces with favorable
% breakpoints, but a special case arises for spaces between a semicolon
% and a digit (see |\SB@srcso| below).
%    \begin{macrocode}
\newcommand\SB@srspace{\futurelet\SB@next\SB@@srspace}
\newcommand\SB@@srspace{%
  \let\SB@donext\relax%
  \ifx\SB@next\SB@srspace\else%
    \ifnum\spacefactor>\@m%
      \ifnum\spacefactor>1499 %
        \ifcat\noexpand\SB@next0%
          \let\SB@donext\SB@srcso%
        \else%
          \penalty-5\enskip%
        \fi%
      \else%
        \space%
      \fi%
    \else%
      \nobreak\space%
    \fi%
  \fi%
  \SB@donext%
}
%    \end{macrocode}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\SB@srcso}
% \begin{macro}{\SB@@srcso}
% A space between a semicolon and a digit could be within a list of
% verse references for a common book (e.g., |Job 1:1; 2:2|);
% or it could separate the previous book from a new book whose name
% starts with a number (e.g., |Job 1:1; 1 John 1:1|).
% In the former case, we should just use a regular space;
% but in the latter case we should be using an en-space with a
% favorable breakpoint.
% To distinguish between the two, we peek ahead at the next two tokens.
% If the second one is a space, assume the latter; otherwise assume the
% former.
%    \begin{macrocode}
\newcommand\SB@srcso[1]{\futurelet\SB@temp\SB@@srcso}
\newcommand\SB@@srcso{%
  \ifx\SB@temp\SB@srspace%
    \penalty-5\enskip%
  \else%
    \space%
  \fi%
  \SB@next%
}
%    \end{macrocode}
% \end{macro}
% \end{macro}
%
% \subsection{Verses and Choruses}
%
% The following programming typesets song contents, including verses, choruses,
% and textual notes.
%
% \begin{macro}{\ifSB@stanza}
% The following conditional remembers if we've seen any stanzas yet in the
% current song.
%    \begin{macrocode}
\newif\ifSB@stanza
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\SB@stanzabreak}
% \changes{v1.12}{2005/05/10}{Fixed stanza counting code and improved spacing}
% End this song stanza and start a new one.
%    \begin{macrocode}
\newcommand\SB@stanzabreak{%
  \ifhmode\par\fi%
  \ifSB@stanza%
    \SB@breakpoint{%
      \ifSB@inverse%
        \ifSB@prevverse\vvpenalty\else\cvpenalty\fi%
      \else%
        \ifSB@prevverse\vcpenalty\else\ccpenalty\fi%
      \fi%
    }%
    \vskip\versesep%
  \fi%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\SB@breakpoint}
% Insert a valid breakpoint into the vertical list comprising a song.
%    \begin{macrocode}
\newcommand\SB@breakpoint[1]{%
  \begingroup%
    \ifnum#1<\@M%
      \SB@skip\colbotglue\relax%
      \SB@skip-\SB@skip%
    \else%
      \SB@skip\z@skip%
    \fi%
    \advance\SB@skip\lastskip%
    \unskip%
    \nobreak%
    \ifnum#1<\@M%
      \vskip\colbotglue\relax%
      \penalty#1%
    \fi%
    \vskip\SB@skip%
  \endgroup%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\SB@putbox}
% Unbox a vbox and follow it by vertical glue if its depth is unusually
% shallow.
% This ensures that verses and choruses will look equally spaced even if
% one of them has a final line with no descenders.
%    \begin{macrocode}
\newcommand\SB@putbox[2]{%
  \begingroup%
    \SB@dimen\dp#2%
    #1#2%
    \setbox\SB@box\hbox{{\lyricfont\relax p}}%
    \ifdim\SB@dimen<\dp\SB@box%
      \advance\SB@dimen-\dp\SB@box%
      \vskip-\SB@dimen%
    \fi%
    \setbox\SB@box\box\voidb@x%
  \endgroup%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\SB@obeylines}
% Within verses and choruses we would like to use |\obeylines| so that each
% \Meta{return} in the source file ends a paragraph without having to say
% |\par| explicitly.
% The \LaTeX{} base code establishes the convention that short-term changes to
% |\par| will restore |\par| by setting it equal to |\@par|.
% Long-term (i.e., environment-long) changes to |\par| should therefore
% redefine |\@par| to restore the desired long-term definition.
% The following code starts a long-term redefinition of |\par| adhering to
% these conventions, and extends that definition to \Meta{return} as well.
%    \begin{macrocode}
\newcommand\SB@obeylines{%
  \let\par\SB@par%
  \obeylines%
  \let\@par\SB@@par%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\SB@par}
% The following replacement definition of |\par| constructs paragraphs in
% which page-breaks are disallowed, since no wrapped line in a song should
% span a page- or column-break.
% It then inserts an interlinepenalty after the paragraph so that such
% penalties will appear between consecutive lines in each verse.
% (Note: The |\endgraf| macro must not be uttered within a local group
% since this prevents parameters like |\hangindent| from being
% reset at the conclusion of each paragraph.)
%    \begin{macrocode}
\newcommand\SB@par{%
  \ifhmode%
    \SB@cnt\interlinepenalty%
    \interlinepenalty\@M%
    \endgraf%
    \interlinepenalty\SB@cnt%
    \ifSB@inchorus%
      \ifdim\cbarwidth>\z@\nobreak\else\SB@ilpenalty\fi%
    \else%
      \SB@ilpenalty%
    \fi%
  \fi%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\SB@ilpenalty}
% By default, breaking a vertical list between paragraphs incurs a penalty
% of zero.
% Thus, we only insert an explicit penalty between lines if
% |\interlinepenalty| is non-zero.
% This avoids cluttering the vertical list with superfluous zero penalties.
%    \begin{macrocode}
\newcommand\SB@ilpenalty{%
  \ifnum\interlinepenalty=\z@\else%
    \penalty\interlinepenalty%
  \fi%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\SB@@par}
% This replacement definition of |\@par| restores the |\SB@par| definition of
% |\par| and then ends the paragraph.
%    \begin{macrocode}
\newcommand\SB@@par{\let\par\SB@par\par}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\SB@parindent}
% \changes{v1.12}{2005/05/10}{Added}
% Reserve a length to remember the current |\parindent|.
%    \begin{macrocode}
\SB@newdimen\SB@parindent
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\SB@everypar}
% Reserve a control sequence to hold short-term changes to |\everypar|.
%    \begin{macrocode}
\newcommand\SB@everypar{}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\SB@raggedright}
% \changes{v1.12}{2005/05/10}{Added}
% Perform |\raggedright| except don't nuke the |\parindent|.
%    \begin{macrocode}
\newcommand\SB@raggedright{%
  \SB@parindent\parindent%
  \raggedright%
  \parindent\SB@parindent%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\vnumbered}
% \changes{v2.1}{2007/08/02}{Renamed.}
% The following conditional remembers whether this verse is being numbered
% or not (i.e., it distinguishes between |\beginverse| and |\beginverse*|).
%    \begin{macrocode}
\newif\ifvnumbered
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\ifSB@prevverse}
% Reserve a conditional to remember if the previous block in this song was
% a verse.
%    \begin{macrocode}
\newif\ifSB@prevverse
%    \end{macrocode}
% \end{macro}
%
% Before replacing the little-used |verse| environment with a new one,
% issue a warning if the current definition of |\verse| is not the
% \LaTeX-default one.
% This may indicate a package clash.
%    \begin{macrocode}
\CheckCommand\verse{%
  \let\\\@centercr%
  \list{}{%
    \itemsep\z@%
    \itemindent-1.5em%
    \listparindent\itemindent%
    \rightmargin\leftmargin%
    \advance\leftmargin1.5em%
  }%
  \item\relax%
}
%    \end{macrocode}
%
% \begin{environment}{verse}\MainEnvImpl{verse}
% \begin{environment}{verse*}
% \begin{macro}{\beginverse}
% Begin a new verse.
% This can be done by beginning a |verse| environment or by using the
% |\beginverse| macro.
% The latter must check for a trailing star to determine whether this
% verse should be numbered.
% We use |\@ifstar| to scan ahead for the star, but this needs to be done
% carefully because while scanning we might encounter tokens that
% should be assigned different catcodes once the verse really begins.
% Thus, we temporarily invoke |\SB@loadactives| for the duration of
% |\@ifstar| so that everything gets the right catcode.
%    \begin{macrocode}
\renewenvironment{verse}
  {\vnumberedtrue\SB@beginverse}
  {\SB@endverse}
\newenvironment{verse*}
  {\vnumberedfalse\SB@beginverse}
  {\SB@endverse}
\newcommand\beginverse{%
  \begingroup%
    \SB@loadactives%
    \@ifstar{\endgroup\vnumberedfalse\SB@beginverse}%
            {\endgroup\vnumberedtrue\SB@beginverse}%
}
%    \end{macrocode}
% \end{macro}
% \end{environment}
% \end{environment}
%
% \begin{macro}{\SB@beginverse}
% \changes{v1.12}{2005/05/10}{Shifted to using \cs{parindent} instead of \cs{everypar} to do indentation}
% Start the body of a verse.
% We begin by inserting a mark if |\repchoruses| is active and this verse
% was preceded by a numbered verse (making this an eligible place to insert
% a chorus later).
%
% Verse numbering is implemented using |\everypar| so that if there is any
% vertical material between the |\beginverse| and the first line of the
% verse, that material will come before the verse number.
% Intervening horizontal material (e.g., |\textnote|) can temporarily
% clear |\everypar| to defer the verse number until later.
%    \begin{macrocode}
\newcommand\SB@beginverse{%
  \ifSB@insong%
    \ifSB@inverse\SB@errbvv\endverse\fi%
    \ifSB@inchorus\SB@errbvc\endchorus\fi%
  \else%
    \SB@errbvt\beginsong{Unknown Song}%
  \fi%
  \ifrepchorus\ifvoid\SB@chorusbox\else%
    \SB@gotchorustrue%
    \ifSB@prevverse\ifvnumbered%
      \marks\SB@cmarkclass{\SB@cmark}%
    \fi\fi%
  \fi\fi%
  \SB@inversetrue%
  \def\SB@closeall{\endverse\endsong}%
  \SB@stanzabreak%
  \versemark\nobreak%
  \global\SB@stanzatrue%
  \SB@ifempty\SB@cr@\memorize{\replay[]}%
  \setbox\SB@box\vbox\bgroup\begingroup%
    \ifvnumbered%
      \protected@edef\@currentlabel{\p@versenum\theversenum}%
      \def\SB@everypar{%
        \setbox\SB@box\hbox{{\printversenum{\theversenum}}}%
        \ifdim\wd\SB@box<\versenumwidth%
          \setbox\SB@box%
          \hbox to\versenumwidth{\unhbox\SB@box\hfil}%
        \fi%
        \ifchorded\vrule\@height\baselineskip\@width\z@\@depth\z@\fi%
        \placeversenum\SB@box%
        \gdef\SB@everypar{}%
      }%
    \else%
      \def\SB@everypar{%
        \ifchorded\vrule\@height\baselineskip\@width\z@\@depth\z@\fi%
        \gdef\SB@everypar{}%
      }%
    \fi%
    \everypar{\SB@everypar\everypar{}}%
    \versefont\relax\SB@setbaselineskip\versejustify%
    \SB@loadactives%
    \SB@obeylines%
    \penalty12345 %
    \everyverse\relax%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\SB@endverse}
% End a verse.
% This involves unboxing the verse material with |\SB@putbox|, which
% corrects for last lines that are unusually shallow.
%    \begin{macrocode}
\newcommand\SB@endverse{%
  \ifSB@insong%
    \ifSB@inverse%
        \unpenalty%
      \endgroup\egroup%
      \SB@putbox\unvbox\SB@box%
      \SB@inversefalse%
      \def\SB@closeall{\endsong}%
      \ifvnumbered\stepcounter{versenum}\fi%
      \SB@prevversetrue%
    \else\ifSB@inchorus\SB@errevc\endchorus%
    \else\SB@errevo\fi\fi%
  \else%
    \SB@errevt%
  \fi%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\ifSB@chorustop}
% When a chorus is broken in to several pieces by column-breaks (via |\brk|),
% the following conditional remembers whether the current piece is the
% topmost one for this chorus.
%    \begin{macrocode}
\newif\ifSB@chorustop
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\SB@chorusbox}
% When |\repchoruses| is used, the first sequence of consecutive choruses
% is remembered in the following box register.
%    \begin{macrocode}
\SB@newbox\SB@chorusbox
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\ifSB@gotchorus}
% The following conditional remembers whether we've completed storing the
% first block of consecutive choruses.
%    \begin{macrocode}
\newif\ifSB@gotchorus
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\SB@cmarkclass}
% \begin{macro}{\SB@nocmarkclass}
% \changes{v2.6}{2008/02/14}{Added safe allocation of extended mark registers}
% The |\repeatchoruses| feature requires the use of two extended mark
% classes provided by $\varepsilon$-\TeX.
% We use the |\newmarks| macro to allocate these classes, if it's
% available.
% If |\newmarks| doesn't exist, then that means the user has an
% $\varepsilon$-\TeX{} compatible version of \LaTeX, but no |etex| style
% file to go with it;
% we just have to pick two mark classes and hope that nobody else is
% using them.
%    \begin{macrocode}
\ifSB@etex
  \@ifundefined{newmarks}{
    \@ifundefined{newmark}{
      \mathchardef\SB@cmarkclass83
      \mathchardef\SB@nocmarkclass84
    }{
      \newmark\SB@cmarkclass
      \newmark\SB@nocmarkclass
    }
  }{
    \newmarks\SB@cmarkclass
    \newmarks\SB@nocmarkclass
  }
\fi
%    \end{macrocode}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\SB@cmark}
% \begin{macro}{\SB@lastcmark}
% \begin{macro}{\SB@nocmark}
% To determine where choruses should be inserted when |\repchoruses| is
% active, three kinds of marks are inserted into song boxes:
% |\SB@cmark| is used to mark places where a chorus might be inserted between
% verses, and |\SB@lastcmark| marks a place where a chorus might be inserted
% after the last verse of the song.
% Both marks are $\varepsilon$-\TeX{} marks of class |\SB@cmarkclass|,
% to avoid disrupting the use of standard \TeX{} marks.
% Each time a chorus is automatically inserted, |\SB@nocmark| is inserted
% with mark class |\SB@nocmarkclass| just above it (and at the top of each
% additional page it spans).
% This inhibits future chorus inserts until the already-inserted chorus has
% been fully committed to the output file.
% Otherwise some choruses could get auto-inserted multiple times at the same
% spot, possibly even leading to an infinite loop!
%    \begin{macrocode}
\newcommand*\SB@cmark{SB@cmark}
\newcommand*\SB@lastcmark{SB@lastcmark}
\newcommand*\SB@nocmark{SB@nocmark}
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
%
% \begin{environment}{chorus}\MainEnvImpl{chorus}
% \begin{macro}{\beginchorus}
% \changes{v1.12}{2005/05/10}{Shifted to using \cs{parindent} instead of \cs{everypar} to do indentation}
% \changes{v1.14}{2005/05/15}{Choruses now stretch like the verses}
% Start a new chorus.
% If |\repchoruses| is active and this is part of the first set of consecutive
% choruses in the song, then include it and its preceding vertical material
% in the |\SB@chorusbox| for possible later duplication elsewhere.
%    \begin{macrocode}
\newenvironment{chorus}{\beginchorus}{\SB@endchorus}
\newcommand\beginchorus{%
  \ifSB@insong
    \ifSB@inverse\SB@errbcv\endverse\fi%
    \ifSB@inchorus\SB@errbcc\endchorus\fi%
  \else%
    \SB@errbct\beginsong{Unknown Song}%
  \fi%
  \SB@inchorustrue%
  \def\SB@closeall{\endchorus\endsong}%
  \SB@chorustoptrue%
  \vnumberedfalse%
  \SB@stanzabreak%
  \chorusmark%
  \ifrepchorus%
    \ifSB@gotchorus\else\ifSB@prevverse\else%
      \global\setbox\SB@chorusbox\vbox{%
        \unvbox\SB@chorusbox%
        \SB@stanzabreak%
        \chorusmark%
      }%
    \fi\fi%
  \fi%
  \global\SB@stanzatrue%
  \replay[]%
  \SB@@beginchorus%
  \everychorus\relax%
}
%    \end{macrocode}
% \end{macro}
% \end{environment}
%
% \begin{macro}{\SB@@beginchorus}
% Begin the body of a chorus, or continue the body of a chorus after |\brk|
% has paused it to insert a valid breakpoint.
% We insert an empty class-|\SB@cmarkclass| mark here so that this chorus
% will not be duplicated elsewhere on the same page(s) where it initially
% appears.
%    \begin{macrocode}
\newcommand\SB@@beginchorus{%
  \ifrepchorus\marks\SB@cmarkclass{}\fi%
  \setbox\SB@box\vbox\bgroup\begingroup%
    \ifchorded%
      \def\SB@everypar{%
        \vrule\@height\baselineskip\@width\z@\@depth\z@%
        \gdef\SB@everypar{}%
      }%
      \everypar{\SB@everypar\everypar{}}%
    \fi%
    \chorusfont\relax\SB@setbaselineskip\chorusjustify%
    \SB@loadactives%
    \SB@obeylines%
    \penalty12345 %
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\SB@endchorus}
% End a chorus.
% This involves creating the vertical line to the left of the chorus and then
% unboxing the chorus material that was previously accumulated.
%    \begin{macrocode}
\newcommand\SB@endchorus{%
  \ifSB@insong%
    \ifSB@inchorus%
        \unpenalty%
      \endgroup\egroup%
      \SB@inchorusfalse%
      \def\SB@closeall{\endsong}%
      \setbox\SB@box\vbox{%
        \SB@chorusbar\SB@box%
        \SB@putbox\unvbox\SB@box%
      }
      \ifrepchorus\ifSB@gotchorus\else%
        \global\setbox\SB@chorusbox\vbox{%
          \unvbox\SB@chorusbox%
          \unvcopy\SB@box%
        }%
      \fi\fi%
      \unvbox\SB@box%
      \SB@prevversefalse%
    \else\ifSB@inverse\SB@errecv\endverse%
    \else\SB@erreco\fi\fi%
  \else%
    \SB@errect%
  \fi%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\SB@cbarshift}
% Increase |\leftskip| to accommodate the chorus bar, if any.
%    \begin{macrocode}
\newcommand\SB@cbarshift{%
  \ifSB@inchorus\ifdim\cbarwidth>\z@%
    \advance\leftskip\cbarwidth%
    \advance\leftskip5\p@\relax%
  \fi\fi%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\SB@chorusbar}
% Create the vertical bar that goes to the left of a chorus.
% Rather than boxing up the chorus in order to put the bar to the left,
% the bar is introduced as leaders directly into the vertical list of the
% main song box.
% This allows it to stretch and shrink when a column is typeset by the
% page-builder.
%    \begin{macrocode}
\newcommand\SB@chorusbar[1]{%
  \ifdim\cbarwidth>\z@%
    \SB@dimen\ht#1%
    \SB@dimenii\dp#1%
    \advance\SB@dimen%
      \ifSB@chorustop\ifchorded\else2\fi\fi\SB@dimenii%
    \SB@skip\SB@dimen\relax%
    \SB@computess\SB@skip1\@plus#1%
    \SB@computess\SB@skip{-1}\@minus#1%
    \nointerlineskip\null\nobreak%
    \leaders\vrule\@width\cbarwidth\vskip\SB@skip%
    \ifSB@chorustop\ifchorded\else%
      \advance\SB@skip-\SB@dimenii%
    \fi\fi%
    \nobreak\vskip-\SB@skip%
  \fi%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\SB@computess}
% \changes{v1.14}{2005/05/15}{Added}
% This computes the stretchability or shrinkability of a vbox and stores
% the result in the skip register given by \argp{1}.
% If $\argp{2}=1$ and \argp{3} is ``\texttt{plus}'', then the stretchability
% of box \argp{4} is added to the plus component of \argp{1}.
% If $\argp{2}=-1$ and \argp{3} is ``\texttt{minus}'', then the shrinkability
% of the box is added to the minus component of \argp{1}.
% If the stretchability or shrinkability is infinite, then we guess 1fil
% for that component.
%    \begin{macrocode}
\newcommand\SB@computess[4]{%
  \begingroup%
    \vbadness\@M\vfuzz\maxdimen%
    \SB@dimen4096\p@%
    \setbox\SB@box\vbox spread#2\SB@dimen{\unvcopy#4}%
    \ifnum\badness=\z@%
      \global\advance#1\z@#31fil\relax%
    \else%
      \SB@dimenii\SB@dimen%
      \loop%
        \SB@dimenii.5\SB@dimenii%
        \ifnum\badness<100 %
          \advance\SB@dimen\SB@dimenii%
        \else
          \advance\SB@dimen-\SB@dimenii%
        \fi%
        \setbox\SB@box\vbox spread#2\SB@dimen{\unvcopy#4}%
        \ifnum\badness=100 \SB@dimenii\z@\fi%
      \ifdim\SB@dimenii>.1\p@\repeat%
      \ifdim\SB@dimen<.1\p@\SB@dimen\z@\fi%
      \global\advance#1\z@#3\SB@dimen\relax%
    \fi%
  \endgroup%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\brk}\MainImpl{brk}
% Placing |\brk| within a line in a verse or chorus tells \TeX{} to break the
% line at that point (if it needs to be broken at all).
%
% Placing |\brk| on a line by itself within a chorus stops the chorus (and its
% vertical bar), inserts a valid breakpoint, and then restarts the chorus
% with no intervening space so that if the breakpoint isn't used, there will
% be no visible effect.
% Placing it on a line by itself within a verse just inserts a breakpoint.
%
% Placing |\brk| between songs forces a column- or page-break, but only if
% generating a non-partial list of songs.
% When generating a partial list, |\brk| between songs is ignored.
%    \begin{macrocode}
\newcommand\brk{%
  \ifSB@insong%
    \ifhmode\penalty-5 \else%
      \unpenalty%
      \ifSB@inchorus%
        \ifdim\cbarwidth=\z@%
          \ifrepchorus\marks\SB@cmarkclass{}\fi%
          \SB@breakpoint\brkpenalty%
        \else%
          \endgroup\egroup%
          \ifrepchorus\ifSB@gotchorus\else%
            \global\setbox\SB@chorusbox\vbox{%
              \unvbox\SB@chorusbox%
              \SB@chorusbar\SB@box%
              \unvcopy\SB@box%
              \SB@breakpoint\brkpenalty%
            }%
          \fi\fi%
          \SB@chorusbar\SB@box%
          \unvbox\SB@box%
          \SB@breakpoint\brkpenalty%
          \SB@chorustopfalse%
          \SB@@beginchorus%
        \fi%
      \else%
        \SB@breakpoint\brkpenalty%
      \fi%
    \fi%
  \else%
    \ifpartiallist\else\SB@nextcol\@ne\colbotglue\fi%
  \fi%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\SB@boxup}
% Typeset a shaded box containing a textual note to singers or musicians.
% We first try typesetting the note on a single line.
% If it's too big, then we try again in paragraph mode with full
% justification.
%    \begin{macrocode}
\newcommand\SB@boxup[1]{%
  \setbox\SB@box\hbox{{\notefont\relax#1}}%
  \SB@dimen\wd\SB@box%
  \advance\SB@dimen6\p@%
  \advance\SB@dimen\leftskip%
  \advance\SB@dimen\rightskip%
  \ifdim\SB@dimen>\hsize%
    \vbox{{%
      \advance\hsize-6\p@%
      \advance\hsize-\leftskip%
      \advance\hsize-\rightskip%
      \notejustify%
      \unhbox\SB@box\par%
      \kern\z@%
    }}%
  \else%
    \vbox{\box\SB@box\kern\z@}%
  \fi%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\textnote}\MainImpl{textnote}
% \changes{v1.12}{2005/05/10}{Defined unset paragraph parameters}
% Create a textual note for singers and musicians.
% If the note begins a verse or chorus, it should not be preceded by any
% spacing.
% Verses and choruses begin with the sentinel penalty 12345, so we check
% |\lastpenalty| to identify this case.
% When typesetting the note, we must be sure to temporarily clear |\everypar|
% to inhibit any verse numbering that might be pending.
% We also readjust the |\baselineskip| as if we weren't doing chords, since
% no chords go above a textual note.
%    \begin{macrocode}
\newcommand\textnote[1]{%
  \ifhmode\par\fi%
  \ifnum\lastpenalty=12345\else%
    \ifSB@inverse%
      \vskip2\p@\relax%
    \else\ifSB@inchorus%
      \vskip2\p@\relax%
    \else\ifSB@stanza%
      \nobreak\vskip\versesep%
    \fi\fi\fi%
  \fi%
  \begingroup%
    \everypar{}%
    \ifchorded\chordedfalse\SB@setbaselineskip\chordedtrue\fi%
    \placenote{\SB@colorbox\notebgcolor{\SB@boxup{#1}}}%
  \endgroup%
  \nobreak%
  \ifSB@inverse%
    \vskip2\p@\relax%
  \else\ifSB@inchorus%
    \vskip2\p@\relax%
  \else\ifSB@stanza\else%
    \nobreak\vskip\versesep%
  \fi\fi\fi%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\musicnote}\MainImpl{musicnote}
% \changes{v1.12}{2005/05/10}{Now just (conditionally) calls \cs{textnote} for consistency}
% Create a textual note for musicians.
%    \begin{macrocode}
\newcommand\musicnote[1]{\ifchorded\textnote{#1}\fi}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\echo}\MainImpl{echo}
% \begin{macro}{\SB@echo}
% \begin{macro}{\SB@@echo}
% \changes{v1.21}{2006/09/17}{Customized fonts now preserved.}
% \changes{v2.1}{2007/08/02}{Toggles instead of forces slanted font.}
% Typeset an echo part in the lyrics.
% Echo parts are in a user-customizable font and parenthesized.
%
% The |\echo| macro must be able to accept chords in its argument.
% This complicates the implementation because chord macros should change
% catcodes, but if we grab |\echo|'s argument in the usual way then all the
% catcodes will be set before the chord macros have a chance to change them.
% This would disallow chord name abbreviations like |#| and |&| within
% |\echo| parts.
%
% If we're using $\varepsilon$-\TeX{} then the solution is easy: we use
% |\scantokens| to re-scan the argument and thereby re-assign the catcodes.
% (One subtlety: Whenever \LaTeX{} consumes an argument to a macro, it changes
% |#| to |##| so that when the argument text is substituted into the body of
% the macro, the replacement text will not contain unsubstituted parameters
% (such as |#1|).
% If |\scantokens| is used on the replacement text and the scanned tokens
% assign a new catcode to |#|, that causes |#|'s to be doubled in the
% \emph{output}, which was not the intent.
% To avoid this problem, we use |\@sanitize| before consuming the argument to
% |\echo|, which sets the catcodes of most special tokens (including |#|) to
% 12, so that \LaTeX{} will not recognize any of them as parameters and will
% therefore not double any of them.)
%    \begin{macrocode}
\ifSB@etex
  \newcommand\echo{\begingroup\@sanitize\SB@echo}
  \newcommand\SB@echo[1]{%
    \endgroup%
    \begingroup%
      \echofont\relax%
      \endlinechar\m@ne%
      \scantokens{(#1)}%
    \endgroup%
  }
\else
%    \end{macrocode}
% If we're not using $\varepsilon$-\TeX, we must do something more complicated.
% We set up the appropriate font within a local group and finish with
% |\hbox| so that the argument to |\echo| is treated as the body of the box.
% Control is reacquired after the box using |\aftergroup|, whereupon we
% unbox the box and insert the closing parenthesis.
% This almost works except that if the last thing in an echo part is a long
% chord name atop a short lyric, the closing parenthesis will float out away
% from the lyric instead of being sucked under the chord.
% I can find no solution to this problem, so to avoid it users must find a
% version of \LaTeX{} that is $\varepsilon$-\TeX{} compatible.
%    \begin{macrocode}
  \newcommand\echo{%
    \begingroup%
      \echofont\relax%
      \afterassignment\SB@echo%
      \setbox\SB@box\hbox%
  }
  \newcommand\SB@echo{\aftergroup\SB@@echo(}
  \newcommand\SB@@echo{\unhbox\SB@box)\endgroup}
\fi
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\rep}\MainImpl{rep}
% \changes{v1.21}{2006/09/17}{Changed to avoid math mode.}
% Place |\rep{|\Meta{n}|}| at the end of a line to indicate that it should be
% sung \Meta{n} times.
%    \begin{macrocode}
\newcommand\rep[1]{%
  (\raise.25ex\hbox{%
    \fontencoding{OMS}\fontfamily{cmsy}\selectfont\char\tw@%
   }#1)%
}
%    \end{macrocode}
% \end{macro}
%
% \subsection{Scripture Quotations}
%
% The macros in this section typeset scripture quotations and other
% between-songs environments.
%
% \begin{environment}{songgroup}\MainEnvImpl{songgroup}
% A |songgroup| environment associates all enclosed environments
% with the enclosed song.
% When generating a partial list, all the enclosed environments are
% contributed if and only if the enclosed song is contributed.
%    \begin{macrocode}
\newenvironment{songgroup}{%
  \ifnum\SB@grouplvl=\z@%
    \edef\SB@sgroup{\thesongnum}%
    \global\SB@groupcnt\m@ne%
  \fi%
  \advance\SB@grouplvl\@ne%
}{%
  \advance\SB@grouplvl\m@ne%
  \ifnum\SB@grouplvl=\z@\let\SB@sgroup\@empty\fi%
}
%    \end{macrocode}
% \end{environment}
%
% \begin{macro}{\SB@grouplvl}
% Count the |songgroup| environment nesting depth.
%    \begin{macrocode}
\SB@newcount\SB@grouplvl
%    \end{macrocode}
% \end{macro}
%
% \begin{environment}{intersong}\MainEnvImpl{intersong}
% An intersong block contributes vertical material to a column between the
% songs of a songs section.
% It is subject to the same column-breaking algorithm as real songs, but
% receives none of the other formatting applied to songs.
%    \begin{macrocode}
\newenvironment{intersong}{%
  \ifSB@insong\SB@errbro\SB@closeall\fi%
  \ifSB@intersong\SB@errbrr\SB@closeall\fi%
  \setbox\SB@chorusbox\box\voidb@x%
  \SB@intersongtrue%
  \def\SB@closeall{\end{intersong}}%
  \setbox\SB@songbox\vbox\bgroup\begingroup%
    \ifnum\SB@numcols>\z@\hsize\SB@colwidth\fi%
    \ifdim\sbarheight>\z@%
      \hrule\@height\sbarheight\@width\hsize%
      \nobreak%
    \fi%
}{%
  \ifSB@intersong
      \ifdim\sbarheight>\z@%
        \ifhmode\par\fi%
        \SB@skip\lastskip%
        \unskip\nobreak\vskip\SB@skip%
        \hbox{\vrule\@height\sbarheight\@width\hsize}%
      \fi%
    \endgroup\egroup%
    \ifSB@omitscrip%
      \setbox\SB@songbox\box\voidb@x%
    \else%
      \SB@submitsong%
    \fi%
    \SB@intersongfalse%
  \else%
    \ifSB@insong\SB@errero\SB@closeall\else\SB@errert\fi%
  \fi%
}
%    \end{macrocode}
% The starred form contributes page-spanning vertical material directly to
% the top of the nearest fresh page.
%    \begin{macrocode}
\newenvironment{intersong*}{%
  \ifSB@insong\SB@errbro\SB@closeall\fi%
  \ifSB@intersong\SB@errbrr\SB@closeall\fi%
  \setbox\SB@chorusbox\box\voidb@x%
  \SB@intersongtrue%
  \def\SB@closeall{\end{intersong*}}%
  \setbox\SB@songbox\vbox\bgroup\begingroup%
}{%
  \ifSB@intersong%
    \endgroup\egroup%
    \ifSB@omitscrip%
      \setbox\SB@songbox\box\voidb@x%
    \else%
      \def\SB@stype{\SB@styppage}%
      \SB@submitsong%
      \def\SB@stype{\SB@stypcol}%
    \fi%
    \SB@intersongfalse%
  \else%
    \ifSB@insong\SB@errero\SB@closeall\else\SB@errert\fi%
  \fi%
}
%    \end{macrocode}
% \end{environment}
%
% \begin{environment}{scripture}\MainEnvImpl{scripture}
% \begin{macro}{\beginscripture}
% Begin a scripture quotation.
% We first store the reference in a box for later use, and then set up
% a suitable environment for the quotation.
% Quotations cannot typically be reworded if line-breaking fails,
% so we set |\emergencystretch| to a relatively high value at the outset.
%    \begin{macrocode}
\newenvironment{scripture}{\beginscripture}{\SB@endscripture}
\newcommand\beginscripture[1]{%
  \begin{intersong}%
    \SB@parsesrefs{#1}%
    \setbox\SB@envbox\hbox{{\printscrcite\songrefs}}%
    \def\SB@closeall{\endscripture}%
    \nobreak\vskip5\p@%
    \SB@parindent\parindent\parindent\z@%
    \parskip\z@skip\parfillskip\@flushglue%
    \leftskip\SB@parindent\rightskip\SB@parindent\relax%
    \scripturefont\relax%
    \baselineskip\f@size\p@\@plus\p@\relax%
    \advance\baselineskip\p@\relax%
    \emergencystretch.3em%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\SB@endscripture}
% End a scripture quotation.
%    \begin{macrocode}
\newcommand\SB@endscripture{%
  \ifSB@intersong
      \scitehere%
      \ifhmode\par\fi%
      \vskip-3\p@%
    \end{intersong}%
  \fi%
}
%    \end{macrocode}
% \end{macro}
% \end{environment}
%
% \begin{macro}{\scitehere}\MainImpl{scitehere}
% \changes{v2.1}{2007/08/02}{Added}
% Usually the scripture citation should just come at the |\endscripture|
% line, but at times the user might want to invoke this macro explicitly
% at a more suitable point.
% A good example is when something near the end of the scripture quotation
% drops \TeX{} into vertical mode.
% In such cases, it is often better to issue the citation before leaving
% horizontal mode.
%
% In any case, this macro should work decently whether in horizontal or
% vertical mode.
% In horizontal mode life is easy: we just append the reference to the
% current horizontal list using the classic code from p.~106 of The \TeX book.
% However, if we're now in vertical mode, the problem is a little harder.
% We do the best we can by using |\lastbox| to remove the last line, then
% adding the reference and re-typesetting it.
% This isn't as good as the horizontal mode solution because \TeX{} only
% gets to reevaluate the last line instead of the whole paragraph, but
% usually the results are passable.
%    \begin{macrocode}
\newcommand\scitehere{%
  \ifSB@intersong%
    \ifvoid\SB@envbox\else%
      \ifvmode%
        \setbox\SB@box\lastbox%
        \nointerlineskip\noindent\hskip-\leftskip%
        \unhbox\SB@box\unskip%
      \fi%
      \unskip\nobreak\hfil\penalty50\hskip.8em\null\nobreak\hfil%
      \box\SB@envbox\kern-\SB@parindent%
      {\parfillskip\z@\finalhyphendemerits2000\par}%
    \fi%
  \else%
    \SB@errscrip\scitehere%
  \fi%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\Acolon}\MainImpl{Acolon}
% \begin{macro}{\Bcolon}\MainImpl{Bcolon}
% \changes{v1.13}{2005/05/12}{Added}
% Typeset a line of poetry in a scripture quotation.
%    \begin{macrocode}
\newcommand\Acolon{\SB@colon2\Acolon}
\newcommand\Bcolon{\SB@colon1\Bcolon}
%    \end{macrocode}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\SB@colon}
% Begin a group of temporary definitions that will end at the next
% \Meta{return}.
% The \Meta{return} will end the paragraph and close the local scope.
%    \begin{macrocode}
\newcommand\SB@colon[2]{%
  \ifSB@intersong\else%
    \SB@errscrip#2%
    \beginscripture{Unknown}%
  \fi%
  \ifhmode\par\fi%
  \begingroup%
    \rightskip\SB@parindent\@plus4em%
    \advance\leftskip2\SB@parindent%
    \advance\parindent-#1\SB@parindent%
    \def\par{\endgraf\endgroup}%
    \obeylines%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\strophe}\MainImpl{strophe}
% \changes{v1.13}{2005/05/12}{Added}
% Insert blank space indicative of a strophe division in a scripture quotation.
%    \begin{macrocode}
\newcommand\strophe{%
  \ifSB@intersong\else%
    \SB@errscrip\strophe\beginscripture{Unknown}%
  \fi%
  \vskip.9ex\@plus.45ex\@minus.68ex\relax%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\scripindent}\MainImpl{scripindent}
% \begin{macro}{\scripoutdent}\MainImpl{scripoutdent}
% \begin{macro}{\SB@scripdent}
% \changes{v1.13}{2005/05/12}{Added}
% Create an indented sub-block within a scripture quotation.
%    \begin{macrocode}
\newcommand\SB@scripdent[2]{%
  \ifSB@intersong\else%
    \SB@errscrip#2\beginscripture{Unknown}%
  \fi%
  \ifhmode\par\fi%
  \advance\leftskip#1\SB@parindent\relax%
}
\newcommand\scripindent{\SB@scripdent1\scripindent}
\newcommand\scripoutdent{\SB@scripdent-\scripoutdent}
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\shiftdblquotes}\MainImpl{shiftdblquotes}
% \changes{v1.13}{2005/05/12}{Added}
% \begin{macro}{\SB@ldqleft}
% \begin{macro}{\SB@ldqright}
% \begin{macro}{\SB@rdqleft}
% \begin{macro}{\SB@rdqright}
% \begin{macro}{\SB@scanlq}
% \begin{macro}{\SB@scanrq}
% \begin{macro}{\SB@dolq}
% \begin{macro}{\SB@dorq}
% The Zaph Chancery font used by default to typeset scripture quotations
% seems to have some kerning problems with double-quote ligatures. The
% |\shiftdblquotes| macro allows one to modify the spacing around all
% double-quotes until the current group ends.
%    \begin{macrocode}
\newcommand\SB@quotesactive{%
  \catcode`'\active%
  \catcode``\active%
}
\newcommand\shiftdblquotes[4]{}
\newcommand\SB@ldqleft{}
\newcommand\SB@ldqright{}
\newcommand\SB@rdqleft{}
\newcommand\SB@rdqright{}
\newcommand\SB@scanlq{}
\newcommand\SB@scanrq{}
\newcommand\SB@dolq{}
\newcommand\SB@dorq{}
{
  \SB@quotesactive
  \gdef\shiftdblquotes#1#2#3#4{%
    \def\SB@ldqleft{\kern#1}%
    \def\SB@ldqright{\kern#2}%
    \def\SB@rdqleft{\kern#3}%
    \def\SB@rdqright{\kern#4}%
    \SB@quotesactive%
    \def`{\futurelet\SB@next\SB@scanlq}%
    \def'{\futurelet\SB@next\SB@scanrq}%
  }
  \gdef\SB@scanlq{%
    \ifx\SB@next`%
      \expandafter\SB@dolq%
    \else%
      \expandafter\lq%
    \fi%
  }
  \gdef\SB@scanrq{%
    \ifx\SB@next'%
      \expandafter\SB@dorq%
    \else%
      \expandafter\rq%
    \fi%
  }
  \gdef\SB@dolq`{%
    \ifvmode\leavevmode\else\/\fi%
    \vadjust{}%
    \SB@ldqleft\lq\lq\SB@ldqright%
    \vadjust{}%
  }
  \gdef\SB@dorq'{%
    \ifvmode\leavevmode\else\/\fi%
    \vadjust{}%
    \SB@rdqleft\rq\rq\SB@rdqright%
    \vadjust{}%
  }
}
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
%
% \subsection{Transposition}
%
% The macros that transpose chords are contained in this section.
%
% \begin{macro}{\SB@transposefactor}
% This counter identifies the requested number of halfsteps by which chords are
% to be transposed (from $-11$ to $+11$).
%    \begin{macrocode}
\SB@newcount\SB@transposefactor
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\ifSB@convertnotes}
% Even when transposition is not requested, the transposition logic can be
% used to automatically convert note names to another form.
% The following conditional turns that feature on or off.
%    \begin{macrocode}
\newif\ifSB@convertnotes
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\notenameA}
% \begin{macro}{\notenameB}
% \begin{macro}{\notenameC}
% \begin{macro}{\notenameD}
% \begin{macro}{\notenameE}
% \begin{macro}{\notenameF}
% \begin{macro}{\notenameG}
% Reserve a control sequence for each note of the diatonic scale.
% These will be used to identify which token sequences the input file uses
% to denote the seven scale degrees.
% Their eventual definitions \emph{must} consist entirely of uppercase
% letters, and they must be assigned using |\def|, but that comes later.
%    \begin{macrocode}
\newcommand\notenameA{}
\newcommand\notenameB{}
\newcommand\notenameC{}
\newcommand\notenameD{}
\newcommand\notenameE{}
\newcommand\notenameF{}
\newcommand\notenameG{}
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\printnoteA}
% \begin{macro}{\printnoteB}
% \begin{macro}{\printnoteC}
% \begin{macro}{\printnoteD}
% \begin{macro}{\printnoteE}
% \begin{macro}{\printnoteF}
% \begin{macro}{\printnoteG}
% These control sequences are what the transposition logic actually
% outputs to denote each scale degree.
% They can include any \LaTeX{} code that is legal in horizontal mode.
%    \begin{macrocode}
\newcommand\printnoteA{}
\newcommand\printnoteB{}
\newcommand\printnoteC{}
\newcommand\printnoteD{}
\newcommand\printnoteE{}
\newcommand\printnoteF{}
\newcommand\printnoteG{}
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\notenamesin}\MainImpl{notenamesin}
% Set the note names used by the input file.
%    \begin{macrocode}
\newcommand\notenamesin[7]{%
  \def\notenameA{#1}%
  \def\notenameB{#2}%
  \def\notenameC{#3}%
  \def\notenameD{#4}%
  \def\notenameE{#5}%
  \def\notenameF{#6}%
  \def\notenameG{#7}%
  \SB@convertnotestrue%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\notenamesout}\MainImpl{notenamesout}
% Set the note names that are output by the transposition logic.
%    \begin{macrocode}
\newcommand\notenamesout[7]{%
  \def\printnoteA{#1}%
  \def\printnoteB{#2}%
  \def\printnoteC{#3}%
  \def\printnoteD{#4}%
  \def\printnoteE{#5}%
  \def\printnoteF{#6}%
  \def\printnoteG{#7}%
  \SB@convertnotestrue%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\notenames}\MainImpl{notenames}
% Set an identical input name and output name for each scale degree.
%    \begin{macrocode}
\newcommand\notenames[7]{%
  \notenamesin{#1}{#2}{#3}{#4}{#5}{#6}{#7}%
  \notenamesout{#1}{#2}{#3}{#4}{#5}{#6}{#7}%
  \SB@convertnotesfalse%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\alphascale}\MainImpl{alphascale}
% \begin{macro}{\solfedge}\MainImpl{solfedge}
% Predefine scales for alphabetic names and solfedge names, and
% set alphabetic scales to be the default.
%    \begin{macrocode}
\newcommand\alphascale{\notenames ABCDEFG}
\newcommand\solfedge{\notenames{LA}{SI}{DO}{RE}{MI}{FA}{SOL}}
\alphascale
%    \end{macrocode}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\ifSB@prefshrps}
% When a transposed chord falls on a black key, the code must choose which
% enharmonically equivalent name to give the new chord.
% (For example, should C transposed by +1 be named C$\#$ or D$\flat$?)
% A heuristic is used to guess which name is most appropriate.
% The following conditional records whether the current key signature is
% sharped or flatted according to this heuristic guess.
%    \begin{macrocode}
\newif\ifSB@prefshrps
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\ifSB@needkey}
% The first chord seen is usually the best indicator of the key of the song.
% (Even when the first chord isn't the tonic, it will often be the dominant
% or subdominant, which usually has the same kind of accidental in its key
% signatures as the actual key.) This conditional remembers whether the current
% chord is the first one seen in the song, and should therefore be used to
% guess the key of the song.
%    \begin{macrocode}
\newif\ifSB@needkey
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\transpose}\MainImpl{transpose}
% The |\transpose| macro sets the transposition adjustment factor and
% informs the transposition logic that the next chord seen will be the first
% one in the new key.
%    \begin{macrocode}
\newcommand\transpose[1]{%
  \advance\SB@transposefactor by#1\relax%
  \SB@cnt\SB@transposefactor%
  \divide\SB@cnt12 %
  \multiply\SB@cnt12 %
  \advance\SB@transposefactor-\SB@cnt%
  \SB@needkeytrue%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\capo}\MainImpl{capo}
% Specifying a |\capo| normally just causes a textual note to musicians to be
% typeset, but if the |transposecapos| option is active, it activates
% transposition of the chords.
%    \begin{macrocode}
\newcommand\capo[1]{%
  \iftranscapos\transpose{#1}\else\musicnote{capo #1}\fi%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\prefersharps}\MainImpl{prefersharps}
% \begin{macro}{\preferflats}\MainImpl{preferflats}
% One of these macros is called after the first chord has been seen to
% register that we're transposing to a key with a sharped or flatted key
% signature.
%    \begin{macrocode}
\newcommand\prefersharps{\SB@prefshrpstrue\SB@needkeyfalse}
\newcommand\preferflats{\SB@prefshrpsfalse\SB@needkeyfalse}
%    \end{macrocode}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\transposehere}\MainImpl{transposehere}
% If automatic transposition has been requested, yield the given chord
% transposed by the requested amount.
% Otherwise return the given chord verbatim.
%    \begin{macrocode}
\newcommand\transposehere[1]{%
  \ifnum\SB@transposefactor=\z@%
    \ifSB@convertnotes%
      \SB@dotranspose{#1}%
      \the\SB@toks%
    \else%
      #1%
    \fi%
  \else%
    \ifSB@convertnotes%
      {\SB@transposefactor\z@%
       \SB@dotranspose{#1}%
       \xdef\SB@tempv{\the\SB@toks}}%
    \else%
      \def\SB@tempv{#1}%
    \fi%
    \SB@dotranspose{#1}%
    \expandafter\trchordformat\expandafter{\SB@tempv}{\the\SB@toks}%
  \fi%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\notrans}\MainImpl{notrans}
% Suppress chord transposition without suppressing note name conversion.
% When a |\notrans{|\Meta{text}|}| macro appears within text undergoing
% transposition, the |\notrans| macro and the group will be preserved
% verbatim by the transposition parser.
% When it is then expanded after parsing, we must therefore re-invoke
% the transposition logic on the argument, but in an environment where
% the transposition factor has been temporarily set to zero.
% This causes note name conversion to occur without actually transposing.
%    \begin{macrocode}
\newcommand\notrans[1]{%
  \begingroup%
    \SB@transposefactor\z@%
    \transposehere{#1}%
  \endgroup%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\SB@dotranspose}
% Parse the argument to a chord macro, yielding the transposed equivalent in
% the |\SB@toks| token register.
%    \begin{macrocode}
\newcommand\SB@dotranspose[1]{%
  \SB@toks{}%
  \let\SB@dothis\SB@trmain%
  \SB@trscan#1\SB@trend%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\trchordformat}\MainImpl{trchordformat}
% By default, transposing means replacing old chords with new chords in the
% new key. However, sometimes the user may want to typeset something more
% sophisticated, like old chords followed by new chords in parentheses so
% that musicians who use capos and those who don't can play from the same
% piece of music. Such typesetting is possible by redefining the following
% macro to something like |#1 (#2)| instead of |#2|.
%    \begin{macrocode}
\newcommand\trchordformat[2]{#2}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\SB@trscan}
% This is the entrypoint to the code that scans over the list of tokens
% comprising a chord and transposes note names as it goes.
% Start by peeking ahead at the next symbol without consuming it.
%    \begin{macrocode}
\newcommand\SB@trscan{\futurelet\SB@next\SB@dothis}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\SB@trmain}
% Test to see whether the token was a begin-brace, end-brace, or space.
% These tokens require special treatment because they cannot be
% accepted as implicit arguments to macros.
%    \begin{macrocode}
\newcommand\SB@trmain{%
  \ifx\SB@next\bgroup%
    \let\SB@donext\SB@trgroup%
  \else\ifx\SB@next\egroup%
    \SB@toks\expandafter{\the\SB@toks\egroup}%
    \let\SB@donext\SB@trskip%
  \else\ifcat\noexpand\SB@next\@sptoken%
    \SB@appendsp\SB@toks%
    \let\SB@donext\SB@trskip%
  \else%
    \let\SB@donext\SB@trstep%
  \fi\fi\fi%
  \SB@donext%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\SB@trgroup}
% A begin-group brace lies next in the input stream.
% Consume the entire group as an argument to this macro, and append it,
% including the begin- and end-group tokens, to the list of tokens processed
% so far.
% No transposition takes place within a group; they are copied verbatim
% because they probably contain macro code.
%    \begin{macrocode}
\newcommand\SB@trgroup[1]{%
  \SB@toks\expandafter{\the\SB@toks{#1}}%
  \SB@trscan%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\SB@trskip}
% A space or end-brace lies next in the input stream.
% It has already been added to the token list, so skip over it.
%    \begin{macrocode}
\newcommand\SB@trskip{%
  \afterassignment\SB@trscan%
  \let\SB@next= }
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\SB@trstep}
% A non-grouping token lies next in the input stream.
% Consume it as an argument to this macro, and then test it to see whether
% it's a note letter or some other recognized item.
% If so, process it; otherwise just append it to the token list and continue
% scanning.
%    \begin{macrocode}
\newcommand\SB@trstep[1]{%
  \let\SB@donext\SB@trscan%
  \ifcat\noexpand\SB@next A%
    \ifnum\uccode`#1=`#1%
      \def\SB@temp{#1}%
      \let\SB@dothis\SB@trnote%
    \else%
      \SB@toks\expandafter{\the\SB@toks#1}%
    \fi%
  \else\ifx\SB@next\SB@trend
    \let\SB@donext\relax%
  \else%
    \SB@toks\expandafter{\the\SB@toks#1}%
  \fi\fi%
  \SB@donext%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\SB@trnote}
% We're in the midst of processing a sequence of uppercase letters that
% might comprise a note name.
% Check to see whether the next token is an accidental (sharp or flat),
% or yet another letter.
%    \begin{macrocode}
\newcommand\SB@trnote{%
  \ifcat\noexpand\SB@next A%
    \let\SB@donext\SB@trnotestep%
  \else\ifnum\SB@transposefactor=\z@%
    \SB@cnt\z@%
    \let\SB@donext\SB@trtrans%
  \else\ifx\SB@next\flt%
    \SB@cnt\m@ne%
    \let\SB@donext\SB@tracc%
  \else\ifx\SB@next\shrp%
    \SB@cnt\@ne%
    \let\SB@donext\SB@tracc%
  \else%
    \SB@cnt\z@%
    \let\SB@donext\SB@trtrans%
  \fi\fi\fi\fi%
  \SB@donext%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\SB@trnotestep}
% The next token is a letter.
% Consume it and test to see whether it is an uppercase letter.
% If so, add it to the note name being assembled; otherwise reinsert it into
% the input stream and jump directly to the transposition logic.
%    \begin{macrocode}
\newcommand\SB@trnotestep[1]{%
  \ifnum\uccode`#1=`#1%
    \SB@app\def\SB@temp{#1}%
    \expandafter\SB@trscan%
  \else%
    \SB@cnt\z@%
    \expandafter\SB@trtrans\expandafter#1%
  \fi%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\SB@tracc}
% We've encountered an accidental (sharp or flat) immediately following a
% note name.
% Peek ahead at the next token without consuming it, and then jump to the
% transposition logic.
% This is done because the transposition logic might need to infer the key
% signature of the song, and if the next token is an m (for minor), then
% that information can help.
%    \begin{macrocode}
\newcommand\SB@tracc[1]{\futurelet\SB@next\SB@trtrans}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\SB@trtrans}
% We've assembled a sequence of capital letters (in |\SB@temp|) that might
% comprise a note name to be transposed.
% If the letters were followed by a |\shrp| then |\SB@cnt| is 1; if they were
% followed by a |\flt| then it is $-1$; otherwise it is 0.
% If the assembled letters turn out to not match any valid note name, then
% do nothing and return to scanning.
% Otherwise compute a new transposed name.
%    \begin{macrocode}
\newcommand\SB@trtrans{%
  \advance\SB@cnt%
    \ifx\SB@temp\notenameA\z@%
    \else\ifx\SB@temp\notenameB\tw@%
    \else\ifx\SB@temp\notenameC\thr@@%
    \else\ifx\SB@temp\notenameD5 %
    \else\ifx\SB@temp\notenameE7 %
    \else\ifx\SB@temp\notenameF8 %
    \else\ifx\SB@temp\notenameG10 %
    \else-99 \fi\fi\fi\fi\fi\fi\fi%
  \ifnum\SB@cnt<\m@ne%
    \SB@toks\expandafter\expandafter\expandafter{%
      \expandafter\the\expandafter\SB@toks\SB@temp}%
  \else%
    \advance\SB@cnt\SB@transposefactor%
    \ifnum\SB@cnt<\z@\advance\SB@cnt12 \fi%
    \ifnum\SB@cnt>11 \advance\SB@cnt-12 \fi%
    \ifSB@needkey\ifnum\SB@transposefactor=\z@\else\SB@setkeysig\fi\fi%
    \edef\SB@temp{%
      \the\SB@toks%
      \ifSB@prefshrps%
        \ifcase\SB@cnt\printnoteA\or\printnoteA\noexpand\shrp\or%
          \printnoteB\or\printnoteC\or\printnoteC\noexpand\shrp\or%
          \printnoteD\or\printnoteD\noexpand\shrp\or\printnoteE\or%
          \printnoteF\or\printnoteF\noexpand\shrp\or\printnoteG\or%
          \printnoteG\noexpand\shrp\fi%
      \else%
        \ifcase\SB@cnt\printnoteA\or\printnoteB\noexpand\flt\or%
          \printnoteB\or\printnoteC\or\printnoteD\noexpand\flt\or%
          \printnoteD\or\printnoteE\noexpand\flt\or\printnoteE\or%
          \printnoteF\or\printnoteG\noexpand\flt\or\printnoteG\or%
          \printnoteA\noexpand\flt\fi%
      \fi}%
    \SB@toks\expandafter{\SB@temp}%
  \fi%
  \let\SB@dothis\SB@trmain%
  \SB@trscan%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\SB@setkeysig}
% If this is the first chord of the song, assume that this is the tonic of the
% key, and select whether to use a sharped or flatted key signature for the
% rest of the song based on that.
% Even if this isn't the tonic, it's probably the dominant or sub-dominant,
% which almost always has a number of sharps or flats similar to the tonic.
% If the bottom note of the chord turns out to be a black key, we choose the
% enharmonic equivalent that is closest to C on the circle of fifths
% (i.e., the one that has fewest sharps or flats).
%    \begin{macrocode}
\newcommand\SB@setkeysig{%
  \global\SB@needkeyfalse%
  \ifcase\SB@cnt%
    \global\SB@prefshrpstrue\or% A
    \global\SB@prefshrpsfalse\or% Bb
    \global\SB@prefshrpstrue\or% B
    \ifx\SB@next m% C
      \global\SB@prefshrpsfalse%
    \else%
      \global\SB@prefshrpstrue%
    \fi\or%
    \global\SB@prefshrpstrue\or% C#
    \ifx\SB@next m% D
      \global\SB@prefshrpsfalse%
    \else%
      \global\SB@prefshrpstrue%
    \fi\or%
    \global\SB@prefshrpsfalse\or% Eb
    \global\SB@prefshrpstrue\or% E
    \global\SB@prefshrpsfalse\or% F
    \global\SB@prefshrpstrue\or% F#
    \ifx\SB@next m% G
      \global\SB@prefshrpsfalse%
    \else%
      \global\SB@prefshrpstrue%
    \fi\or%
    \global\SB@prefshrpsfalse\else% Ab
    \global\SB@needkeytrue% non-chord
  \fi%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\SB@trend}
% The following macro marks the end of chord text to be processed.
% It should always be consumed and discarded by the chord-scanning
% logic above, so generate an error if it is ever expanded.
%    \begin{macrocode}
\newcommand\SB@trend{%
  \SB@Error{Internal Error: Transposition failed}%
           {This error should not occur.}%
}
%    \end{macrocode}
% \end{macro}
%
% \subsection{Measure Bars}
%
% The following code handles the typesetting of measure bars.
%
% \begin{macro}{\SB@metertop}
% \begin{macro}{\SB@meterbot}
% These macros remember the current numerator and denominator of the meter.
%    \begin{macrocode}
\newcommand\SB@metertop{}
\newcommand\SB@meterbot{}
%    \end{macrocode}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\meter}\MainImpl{meter}
% Set the current meter without producing an actual measure bar yet.
%    \begin{macrocode}
\newcommand\meter[2]{\gdef\SB@metertop{#1}\gdef\SB@meterbot{#2}}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\SB@measuremark}
% Normally measure bar boxes should be as thin as possible so that they can be
% slipped into lyrics without making them hard to read. But when two measure
% bars appear consecutively, they need to be spaced apart more so that they
% look like two separate lines instead of one thick line. To achieve this,
% there needs to be a way to pull a vbox off the current list and determine
% whether or not it is a box that contains a measure bar. The solution is to
% insert a mark (|\SB@measuremark|) at the top of each measure bar vbox.
% We can then see whether this measure bar immediately follows another measure
% bar by using |\vsplit| on |\lastbox|.
%    \begin{macrocode}
\newcommand\SB@measuremark{SB@IsMeasure}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\SB@makembar}\MainImpl{mbar}
% Typeset a measure bar. If provided, \argp{1} is the numerator and \argp{2} is
% the denominator of the meter to be rendered above the bar. If those arguments
% are left blank, render a measure bar without a meter marking.
%    \begin{macrocode}
\newcommand\SB@makembar[2]{%
  \ifSB@inverse\else%
    \ifSB@inchorus\else\SB@errmbar\fi%
  \fi%
  \ifhmode%
    \SB@skip\lastskip\unskip%
    \setbox\SB@box\lastbox%
    \copy\SB@box%
    \ifvbox\SB@box%
      \begingroup%
        \setbox\SB@boxii\copy\SB@box%
        \vbadness\@M\vfuzz\maxdimen%
        \setbox\SB@boxii%
          \vsplit\SB@boxii to\maxdimen%
      \endgroup%
      \long\edef\SB@temp{\splitfirstmark}%
      \ifx\SB@temp\SB@measuremark%
        \penalty100\hskip1em%
      \else%
        \penalty100\hskip\SB@skip%
      \fi%
    \else%
      \penalty100\hskip\SB@skip%
    \fi%
  \fi%
  \ifvmode\leavevmode\fi%
  \setbox\SB@box\hbox{{\meterfont\relax#1}}%
  \setbox\SB@boxii\hbox{{\meterfont\relax#2}}%
  \SB@dimen\wd\ifdim\wd\SB@box>\wd\SB@boxii\SB@box\else\SB@boxii\fi%
  \SB@dimenii\baselineskip%
  \advance\SB@dimenii-2\p@%
  \advance\SB@dimenii-\ht\SB@box%
  \advance\SB@dimenii-\dp\SB@box%
  \advance\SB@dimenii-\ht\SB@boxii%
  \advance\SB@dimenii-\dp\SB@boxii%
  \let\SB@temp\relax%
  \ifdim\SB@dimen>\z@%
    \advance\SB@dimenii-.75\p@%
    \def\SB@temp{\kern.75\p@}%
  \fi%
  \SB@maxmin\SB@dimen<{.5\p@}%
  \SB@maxmin\SB@dimenii<\z@%
  \vbox{%
    \mark{\SB@measuremark}%
    \hbox to\SB@dimen{%
      \hfil%
      \box\SB@box%
      \hfil%
    }%
    \nointerlineskip%
    \hbox to\SB@dimen{%
      \hfil%
      \box\SB@boxii%
      \hfil%
    }%
    \SB@temp%
    \nointerlineskip%
    \hbox to\SB@dimen{%
      \hfil%
      \vrule\@width.5\p@\@height\SB@dimenii%
      \hfil%
    }%
  }%
  \meter{}{}%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\mbar}
% The |\mbar| macro invokes |\SB@mbar|, which gets redefined by macros and
% options that turn measure bars on and off.
%    \begin{macrocode}
\newcommand\mbar{\SB@mbar}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\measurebar}\MainImpl{measurebar}
% Make a measure bar using the most recently defined meter.
% Then set the meter to nothing so that the next measure bar will not
% display any meter unless the meter changes.
%    \begin{macrocode}
\newcommand\measurebar{%
  \mbar\SB@metertop\SB@meterbot%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\SB@repcolon}
% Create the colon that preceeds or follows a repeat sign.
%    \begin{macrocode}
\newcommand\SB@repcolon{{%
  \usefont{OT1}{cmss}{m}{n}\selectfont%
  \ifchorded%
    \baselineskip.5\SB@dimen%
    \vbox{\hbox{:}\hbox{:}\kern.5\p@}%
  \else%
    \raise.5\p@\hbox{:}%
  \fi%
}}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\lrep}\MainImpl{lrep}
% Create a begin-repeat sign.
%    \begin{macrocode}
\newcommand\lrep{%
  \SB@dimen\baselineskip%
  \advance\SB@dimen-2\p@%
  \vrule\@width1.5\p@\@height\SB@dimen\@depth\p@%
  \kern1.5\p@%
  \vrule\@width.5\p@\@height\SB@dimen\@depth\p@%
  \SB@repcolon%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\rrep}\MainImpl{rrep}
% Create an end-repeat sign.
%    \begin{macrocode}
\newcommand\rrep{%
  \SB@dimen\baselineskip%
  \advance\SB@dimen-2\p@%
  \SB@repcolon%
  \vrule\@width.5\p@\@height\SB@dimen\@depth\p@%
  \kern1.5\p@%
  \vrule\@width1.5\p@\@height\SB@dimen\@depth\p@%
}
%    \end{macrocode}
% \end{macro}
%
% \subsection{Lyric Scanning}\label{sec:lyricscan}
%
% The obvious way to create a chord macro is as a normal macro with
% two arguments, one for the chord name and one for the lyrics to go
% under the chord---e.g.~|\chord{|\Meta{chordname}|}{|\Meta{lyric}|}|.
% However, in practice such a macro is extremely cumbersome and
% difficult to use.
% The problem is that in order to use such a macro properly, the user
% must remember a bunch of complex style rules that govern what
% part of the lyric text needs to go in the \Meta{lyric} parameter and
% what part should be typed after the closing brace.
% To avoid separating a word from its trailing punctuation, the
% \Meta{lyric} parameter must often include punctuation but not certain
% special punctuation like hyphens, should include the rest of the
% word but not if there's another chord in the word, should omit
% measure bars but only if measure bars are being shown, etc.
% This is way too difficult for the average user.
%
% To avoid this problem, we define chords using a one-argument macro
% (the argument is the chord name), but with no explicit argument for
% the lyric part.
% Instead, the macro scans ahead in the input stream, automatically
% determining what portion of the lyric text that follows should be
% sucked in as an implicit second argument.
% The following code does this look-ahead scanning.
%
% \begin{macro}{\ifSB@wordends}
% \begin{macro}{\ifSB@brokenword}
% Chord macros must look ahead in the input stream to see whether this chord
% is immediately followed by whitespace or the remainder of a word.
% If the latter, hyphenation might need to be introduced.
% These macros keep track of the need for hyphenation, if any.
%    \begin{macrocode}
\newif\ifSB@wordends
\newif\ifSB@brokenword
%    \end{macrocode}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\SB@lyric}
% Lyrics appearing after a chord are scanned into the following token list
% register.
%    \begin{macrocode}
\SB@newtoks\SB@lyric
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\SB@numhyps}
% Hyphens appearing in lyrics require special treatment.
% The following counter counts the number of explicit hyphens ending
% the lyric syllable that follows the current chord.
%    \begin{macrocode}
\SB@newcount\SB@numhyps
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\SB@lyricnohyp}
% When a lyric syllable under a chord ends in exactly one hyphen, the
% following token register is set to be the syllable without the hyphen.
%    \begin{macrocode}
\SB@newtoks\SB@lyricnohyp
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\SB@lyricbox}
% \begin{macro}{\SB@chordbox}
% The following two boxes hold the part of the lyric text that is to be
% typeset under the chord, and the chord text that is to be typeset above.
%    \begin{macrocode}
\SB@newbox\SB@lyricbox
\SB@newbox\SB@chordbox
%    \end{macrocode}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\SB@chbstok}
% \changes{v1.22}{2007/05/15}{Added.}
% When |\MultiwordChords| is active, the following reserved control
% sequence remembers the first (space) token not yet included into the
% |\SB@lyricbox| box.
%    \begin{macrocode}
\newcommand\SB@chbstok{}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\SB@setchord}
% \changes{v2.3}{2007/09/23}{Support replayed chords over ligatures}
% \changes{v2.7}{2009/01/08}{Extend rather than replace chordbox}
% \changes{v3.0}{2017/04/19}{Fix transposition of replayed chord over ligature}
% The following macro typesets its argument as a chord and stores the
% result in box |\SB@chordbox| for later placement into the document.
% The hat token (|^|) is redefined so that outside of math mode it
% suppresses chord memorization, but inside of math mode it retains
% its usual superscript meaning.
% If memorization is active, the chord's token sequence is stored in
% the current replay register.
% If |\SB@chordbox| is non-empty, the new chord is appended to it
% rather than replacing it.
% This allows consecutive chords not separated by whitespace to be
% typeset as a single chord sequence atop a common lyric.
%    \begin{macrocode}
\newcommand\SB@setchord{}
{
  \catcode`^\active
  \gdef\SB@setchord#1{%
    \SB@gettabindtrue\SB@nohattrue%
    \setbox\SB@chordbox\hbox{%
      \unhbox\SB@chordbox%
      \begingroup%
        \ifSB@trackch%
          \let\SB@activehat\SB@hat@tr%
        \else%
          \let\SB@activehat\SB@hat@notr%
        \fi%
        \let^\SB@activehat%
        \printchord{%
          \ifSB@firstchord\else\kern.15em\fi%
          \vphantom/%
          \transposehere{#1}%
          \kern.2em%
        }%
      \endgroup%
    }%
    \SB@gettabindfalse%
    \ifSB@trackch\ifSB@nohat%
      \global\SB@creg\expandafter{\the\SB@creg#1\\}%
    \fi\fi%
    \let\SB@noreplay\@firstofone%
  }
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\SB@outertest}
% \begin{macro}{\SB@otesta}
% \begin{macro}{\SB@otestb}
% The lyric-scanning code must preemptively determine whether the next token
% is a macro declared |\outer| before it tries to accept that token as an
% argument.
% Otherwise \TeX{} will abort with a parsing error.
% Macros declared |\outer| are not allowed in arguments, so determining
% whether a token is |\outer| is a delicate process.
% The following does so by consulting |\meaning|.
% A macro can be identified as |\outer| if its meaning has the
% word ``|\outer|'' before the first colon.
%    \begin{macrocode}
\newcommand\SB@outertest{%
  \expandafter\SB@otesta\meaning\SB@next:\SB@otesta%
}
\newcommand\SB@otesta{}
\edef\SB@otesta#1:#2\SB@otesta{%
  \noexpand\SB@otestb%
  #1\string\outer%
  \noexpand\SB@otestb%
}
\newcommand\SB@otestb{}
\expandafter\def\expandafter\SB@otestb%
\expandafter#\expandafter1\string\outer#2\SB@otestb{%
  \def\SB@temp{#2}%
  \ifx\SB@temp\@empty\SB@testfalse\else\SB@testtrue\fi%
}
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\SB@UTFtest}
% \begin{macro}{\SB@U@two}
% \begin{macro}{\SB@U@three}
% \begin{macro}{\SB@U@four}
% \begin{macro}{\SB@@UTFtest}
% \changes{v1.22}{2007/05/15}{Added.}
% To support UTF-8 encoded \LaTeX{} source files, we need to be able to
% identify multibyte characters during the lyric scanning process.
% Alas, the |utf8.def| file provides no clean way of identifying the
% macros it defines for this purpose.
% The best solution seems to be to look for any token named
% |\UTFviii@|$\ldots$|@octets| in the top-level expansion of the macro.
%    \begin{macrocode}
\newcommand\SB@UTFtest{}
\edef\SB@UTFtest#1{%
  \noexpand\expandafter%
  \noexpand\SB@@UTFtest%
  \noexpand\meaning#1%
  \string\UTFviii@zero@octets%
  \noexpand\SB@@UTFtest%
}
\newcommand\SB@U@two{\global\SB@cnt\tw@}
\newcommand\SB@U@three{\global\SB@cnt\thr@@}
\newcommand\SB@U@four{\global\SB@cnt4\relax}
\newcommand\SB@@UTFtest{}
{\escapechar\m@ne
 \xdef\SB@temp{\string\@octets}}
\edef\SB@temp{##1\string\UTFviii@##2\SB@temp}
\expandafter\def\expandafter\SB@@UTFtest\SB@temp#3\SB@@UTFtest{%
  \SB@cnt\z@%
  {\csname SB@U@#2\endcsname}%
}
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\DeclareLyricChar}\MainImpl{DeclareLyricChar}
% \begin{macro}{\DeclareNonLyric}\MainImpl{DeclareNonLyric}
% \begin{macro}{\DeclareNoHyphen}\MainImpl{DeclareNoHyphen}
% \begin{macro}{\SB@declare}
% \changes{v1.22}{2007/05/15}{Added \cs{DeclareLyricChar}.}
% \changes{v2.1}{2007/08/02}{Added \cs{DeclareNonLyric} and \cs{DeclareNoHyphen}.}
% \changes{v2.6}{2008/03/27}{Macro tests made name-based instead of def-based}
% When scanning the lyric text that follows a chord, it is necessary to
% distinguish accents and other intra-word macros (which should be included
% in the under-chord lyric text) from other macros (which should be pushed
% out away from the text).
% The following macros allow users to declare a token to be lyric-continuing
% or lyric-ending.
%    \begin{macrocode}
\newcommand\SB@declare[3]{%
  \afterassignment\iffalse\let\SB@next= #3\relax\fi%
  \SB@UTFtest\SB@next%
  \ifcase\SB@cnt%
    \ifcat\noexpand#3\relax%
      \SB@addNtest\SB@macrotests#1#2#3%
    \else\ifcat\noexpand#3.%
      \SB@addDtest\SB@othertests#1#2%
    \else\ifcat\noexpand#3A%
      \SB@addDtest\SB@lettertests#1#2%
    \else%
      \SB@addDtest\relax0#2%
    \fi\fi\fi%
  \or%
    \SB@addNtest\SB@macrotests#1#2#3%
  \else%
    \SB@addMtest\SB@multitests#1#2#3\relax\relax\relax%
  \fi%
}
\newcommand\DeclareLyricChar{\SB@declare\SB@testtrue0}
\newcommand\DeclareNonLyric{\SB@declare\SB@testfalse\SB@testfalse}
\newcommand\DeclareNoHyphen{\SB@declare\SB@testfalse\SB@testtrue}
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\SB@lettertests}
% \begin{macro}{\SB@macrotests}
% \begin{macro}{\SB@multitests}
% \begin{macro}{\SB@othertests}
% For speed, token tests introduced by |\DeclareLyricChar| and friends
% are broken out into separate macros based on category codes.
%    \begin{macrocode}
\newcommand\SB@lettertests{}
\newcommand\SB@macrotests{}
\newcommand\SB@multitests{}
\newcommand\SB@othertests{}
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
%
% The following macros add tests to the test macros defined above.
% In each, \argp{1} is the test macro to which the test should be added,
% \argp{2} and \argp{3} is the code to be executed at scanning-time and
% at hyphenation-time if the test succeeds (or ``0'' if no action is to
% be performed), and \argp{4} is the token to which the currently scanned
% token should be compared to determine whether it matches.
%
% \begin{macro}{\SB@addDtest}
% A definition-test: The test succeeds if the next lyric token has the same
% meaning (at test-time) of the non-macro, non-active character token that
% was given to the |\Declare| macro.
%    \begin{macrocode}
\newcommand\SB@addDtest[3]{%
  \ifx0#2\else%
    \def#1{{\csname SB@!\meaning\SB@next\endcsname}}%
    \expandafter\def\csname SB@!\meaning\SB@next\endcsname{\global#2}%
  \fi%
  \ifx0#3\else%
    \expandafter\def\csname SB@HT@\meaning\SB@next\endcsname{\global#3}%
  \fi%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\SB@addNtest}
% A name-test:  The test succeeds if the next token is a non-|\outer|
% macro or active character and its |\string|ified name matches the
% |\string|ified name of the control sequence that was given to the
% |\Declare| macro.
%    \begin{macrocode}
\newcommand\SB@addNtest[4]{%
  \ifx0#2\else%
    \def#1{{\csname SB@!\SB@nextname\endcsname}}%
    \expandafter\def\csname SB@!\string#4\endcsname{\global#2}%
  \fi%
  \ifx0#3\else%
    \expandafter\def\csname SB@HT@\string#4\endcsname{\global#3}%
  \fi%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\SB@addMtest}
% A multibyte-test:  The test succeeds if the next lyric token is the
% beginning of a UTF-8 encoded multibyte character sequence that matches
% the multibyte sequence given to the |\Declare| macro.
%    \begin{macrocode}
\newcommand\SB@addMtest[7]{%
  \edef\SB@temp{%
    \string#4%
    \ifx\relax#5\else\string#5\fi%
    \ifx\relax#6\else\string#6\fi%
    \ifx\relax#7\else\string#7\fi%
  }%
  \ifx0#2\else%
    \def#1{{\csname SB@!\SB@nextname\endcsname}}%
    \expandafter\def\csname SB@!\SB@temp\endcsname{\global#2}%
  \fi%
  \ifx0#3\else%
    \expandafter\def\csname SB@HT@\SB@temp\endcsname{\global#3}%
  \fi%
}
%    \end{macrocode}
% \end{macro}
%
% The following code declares the common intra-word macros provided by
% \TeX{} (as listed on p.~52 of The \TeX book) to be lyric-continuing.
%    \begin{macrocode}
\DeclareLyricChar\`
\DeclareLyricChar\'
\DeclareLyricChar\^
\DeclareLyricChar\"
\DeclareLyricChar\~
\DeclareLyricChar\=
\DeclareLyricChar\.
\DeclareLyricChar\u
\DeclareLyricChar\v
\DeclareLyricChar\H
\DeclareLyricChar\t
\DeclareLyricChar\c
\DeclareLyricChar\d
\DeclareLyricChar\b
\DeclareLyricChar\oe
\DeclareLyricChar\OE
\DeclareLyricChar\ae
\DeclareLyricChar\AE
\DeclareLyricChar\aa
\DeclareLyricChar\AA
\DeclareLyricChar\o
\DeclareLyricChar\O
\DeclareLyricChar\l
\DeclareLyricChar\L
\DeclareLyricChar\ss
\DeclareLyricChar\i
\DeclareLyricChar\j
\DeclareLyricChar\/
\DeclareLyricChar\-
\DeclareLyricChar\discretionary
%    \end{macrocode}
%
% We declare |\par| to be lyric-ending without introducing hyphenation.
% The |\par| macro doesn't actually appear in most verses because we use
% |\obeylines|, but we include a check for it in case the user says |\par|
% explicitly somewhere.
%    \begin{macrocode}
\DeclareNoHyphen\par
%    \end{macrocode}
%
% \begin{macro}{\SB@bracket}
% This macro gets invoked by the |\[|\eat\] macro whenever a chord begins.
% It gets redefined by code that turns chords on and off, so its initial
% definition doesn't matter.
%    \begin{macrocode}
\newcommand\SB@bracket{}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\SB@chord}
% Begin parsing a chord macro.
% While parsing the chord name argument, we set some special catcodes so
% that chord names can use |#| and |&| for sharps and flats.
%    \begin{macrocode}
\newcommand\SB@chord{\SB@begincname\SB@@chord}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\SB@begincname}
% \begin{macro}{\SB@endcname}
% While parsing a chord name, certain characters such as |#| and |&| are
% temporarily set active so that they can be used as abbreviations for
% sharps and flats.
% To accomplish this, |\SB@begincname| must always be invoked before any
% macro whose argument is a chord name, and |\SB@endcname| must be invoked
% at the start of the body of any macro whose argument is a chord name.
% To aid in debugging, we also temporarily set \Meta{return} characters and
% chord macros |\outer|.
% This will cause \TeX{} to halt with a runaway argument error on the correct
% source line if the user forgets to type a closing end-brace (a common typo).
% Colon characters are also set non-active to avoid a conflict between the
% \textsf{Babel} French package and the |\gtab| macro.
%    \begin{macrocode}
\newcommand\SB@begincname{}
{\catcode`\^^M\active
 \gdef\SB@begincname{%
   \begingroup%
     \catcode`##\active\catcode`&\active%
     \catcode`:12\relax%
     \catcode`\^^M\active\SB@outer\def^^M{}%
     \SB@outer\def\[{}%
     \chordlocals\relax%
  }
}
\newcommand\SB@endcname{}
\let\SB@endcname\endgroup
%    \end{macrocode}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\SB@nbsp}
% Non-breaking spaces (|~|) should be treated as spaces by the lyric-scanner
% code that follows.
% Although |~| is usually an active character that creates a non-breaking
% space, some packages (e.g., the \textsf{Babel} package) redefine it to
% produce accents, which are typically not lyric-ending.
% To distinguish the real |~| from redefined |~|, we need to create a macro
% whose definition is the non-breaking space definition normally assigned to
% |~|.
%    \begin{macrocode}
\newcommand*\SB@nbsp{\nobreakspace{}}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\SB@firstchord}
% The following conditional is true when the current chord is the first
% chord in a sequence of one or more chord macros.
%    \begin{macrocode}
\newif\ifSB@firstchord\SB@firstchordtrue
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\SB@@chord}
% Finish processing the chord name and then begin scanning the implicit
% lyric argument that follows it.
% This is the main entrypoint to the lyric-scanner code.
%    \begin{macrocode}
\newcommand*\SB@@chord{}
\def\SB@@chord#1]{%
  \SB@endcname%
  \ifSB@firstchord%
    \setbox\SB@lyricbox\hbox{\kern\SB@tabindent}%
    \global\SB@tabindent\z@%
    \SB@lyric{}%
    \SB@numhyps\z@%
    \SB@spcinit%
    \setbox\SB@chordbox\box\voidb@x%
  \fi%
  \SB@setchord{#1}%
  \SB@firstchordfalse%
  \let\SB@dothis\SB@chstart%
  \SB@chscan%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\MultiwordChords}\MainImpl{MultiwordChords}
% \begin{macro}{\SB@spcinit}
% \changes{v1.22}{2007/05/15}{Added.}
% The |\SB@spcinit| macro is invoked at the beginning of the lyric
% scanning process.
% By default it does nothing, but if |\MultiwordChords| is invoked,
% it initializes the lyric-scanner state to process spaces as part of
% lyrics.
%    \begin{macrocode}
\newcommand\SB@spcinit{}
\newcommand\MultiwordChords{%
  \def\SB@spcinit{%
    \let\SB@chdone\SB@chlyrdone%
    \let\SB@chimpspace\SB@chnxtdone%
    \let\SB@chexpspace\SB@chnxtdone%
    \let\SB@chespace\SB@chendspace%
  }%
}
%    \end{macrocode}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\SB@chscan}
% \begin{macro}{\SB@chmain}
% This is the main loop of the lyric-scanner.
% Peek ahead at the next token without consuming it, then execute
% a loop body based on the current state (|\SB@dothis|), and finally
% go to the next iteration (|\SB@donext|).
%    \begin{macrocode}
\newcommand\SB@chscan{%
  \let\SB@nextname\relax%
  \futurelet\SB@next\SB@chmain%
}
\newcommand\SB@chmain{\SB@dothis\SB@donext}
%    \end{macrocode}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\SB@chnxtrelax}
% \begin{macro}{\SB@chnxtstep}
% \begin{macro}{\SB@chnxtdone}
% To shorten the lyric parser macros that follow and thereby improve their
% speed, we here define some abbreviations for common logic in untaken
% branches.
%    \begin{macrocode}
\newcommand\SB@chnxtrelax{\let\SB@donext\relax}
\newcommand\SB@chnxtstep{\let\SB@donext\SB@chstep}
\newcommand\SB@chnxtdone{\let\SB@donext\SB@chdone}
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
% 
% Warning: In the lyric-scanner macros that follow, |\SB@next|
% might be a macro declared |\outer|.
% This means that it must \emph{never} be passed as an argument to
% a macro and it must never explicitly appear in any untaken branch
% of a conditional.
% If it does, the \TeX{} parser will complain of a runaway argument
% when it tries to skip over an |\outer| macro while consuming tokens
% at high speed.
%
% \begin{macro}{\SB@chstart}
% We begin lyric-scanning with two special cases:
% (1) If the chord macro is immediately followed by another chord macro with
% no intervening whitespace, drop out of the lyric scanner and reenter it when
% the second macro is parsed.
% The chord texts will get concatenated together above the lyric that follows.
% (2) If the chord macro is immediately followed by one or more quote
% tokens, then consume them all and output them \emph{before} the chord.
% This causes the chord to sit above the actual word instead of the
% left-quote or left-double-quote symbol, which looks better.
%    \begin{macrocode}
\newcommand\SB@chstart{%
  \ifx\SB@next\[\SB@chnxtrelax%
  \else\ifx\SB@next\SB@activehat\SB@chnxtrelax%
  \else\ifx\SB@next\ch\SB@chnxtrelax%
  \else\ifx\SB@next\mch\SB@chnxtrelax%
  \else\ifx\SB@next`\SB@chnxtstep%
  \else\ifx\SB@next'\SB@chnxtstep%
  \else\ifx\SB@next"\SB@chnxtstep%
  \else%
    \the\SB@lyric%
    \SB@lyric{}%
    \SB@firstchordtrue%
    \let\SB@dothis\SB@chnorm%
    \SB@chnorm%
  \fi\fi\fi\fi\fi\fi\fi%
}
%    \end{macrocode}
% \end{macro}
% \eat\]
%
% \begin{macro}{\SB@chnorm}
% \changes{v2.0}{2007/06/18}{Rewritten for speed}
% First, check to see whether the lyric token is a letter.
% Since that's the most common case, we do this check first for speed.
%    \begin{macrocode}
\newcommand\SB@chnorm{%
  \ifcat\noexpand\SB@next A%
    \SB@testtrue\SB@lettertests%
    \ifSB@test%
      \SB@chespace\SB@chnxtstep%
    \else%
      \SB@chnxtdone%
    \fi%
  \else%
    \SB@chtrymacro%
  \fi%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\SB@chtrymacro}
% Next, check to see whether it's a macro or active character.
% We do these checks next because these are the only cases when the
% token might be |\outer|.
% Once we eliminate that ugly possibility, we can write the rest of
% the code without having to worry about putting |\SB@next| in
% places where |\outer| tokens are illegal.
%    \begin{macrocode}
\newcommand\SB@chtrymacro{%
  \ifcat\noexpand\SB@next\relax%
    \SB@chmacro%
  \else%
    \SB@chother%
  \fi%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\SB@chother}
% The token is not a letter, macro, or active character.
% The only other cases of interest are spaces, braces, and hyphens.
% If it's one of those, take the appropriate action; otherwise end the
% lyric here.
% Since we've eliminated the possibility of macros and active characters,
% we can be sure that the token isn't |\outer| at this point.
%    \begin{macrocode}
\newcommand\SB@chother{%
  \ifcat\noexpand\SB@next\@sptoken%
    \SB@chexpspace%
  \else\ifcat\noexpand\SB@next\bgroup%
    \SB@chespace\let\SB@donext\SB@chbgroup%
  \else\ifcat\noexpand\SB@next\egroup%
    \SB@chespace\let\SB@donext\SB@chegroup%
  \else\ifx\SB@next-%
    \SB@numhyps\@ne\relax%
    \SB@lyricnohyp\expandafter{\the\SB@lyric}%
    \let\SB@dothis\SB@chhyph%
    \SB@chespace\SB@chnxtstep%
  \else\ifcat\noexpand\SB@next.%
    \SB@testtrue\SB@othertests%
    \ifSB@test%
      \SB@chespace\SB@chnxtstep%
    \else%
      \SB@chnxtdone%
    \fi%
  \else%
    \SB@chespace\SB@chnxtstep%
  \fi\fi\fi\fi\fi%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\SB@chmacro}
% \changes{v1.22}{2007/05/15}{Added support for UTF-8.}
% The lyric-scanner has encountered a macro or active character.
% If it's |\outer|, it should never be used in an argument, so stop here.
%    \begin{macrocode}
\newcommand\SB@chmacro{%
  \SB@outertest%
  \ifSB@test%
    \SB@chnxtdone%
  \else%
    \let\SB@donext\SB@chgetname%
  \fi%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\SB@chgetname}
% We've encountered a non-|\outer| macro or active character.
% Use |\string| to get its name, but insert the token back into the
% input stream since we haven't decided whether to consume it yet.
%    \begin{macrocode}
\newcommand\SB@chgetname[1]{%
  \edef\SB@nextname{\string#1}%
  \SB@@chmacro\SB@donext#1%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\SB@@chmacro}
% The lyric-scanner has encountered a non-|\outer| macro or active character.
% Its |\string|ified name has been stored in |\SB@nextname|.
% Test to see whether it's a known macro or the beginning of a
% multibyte-encoded international character.
% If the former, dispatch some macro-specific code to handle it.
% If the latter, grab the full multibyte sequence and include it in the lyric.
%    \begin{macrocode}
\newcommand\SB@@chmacro{%
  \ifx\SB@next\SB@activehat%
    \SB@chnxtdone%
  \else\ifx\SB@next\SB@par%
    \SB@chnxtdone%
  \else\ifx\SB@next\measurebar%
    \SB@chmbar%
  \else\ifx\SB@next\mbar%
    \SB@chmbar%
  \else\ifx\SB@next\ch%
    \SB@chespace\let\SB@donext\SB@chlig%
  \else\ifx\SB@next\mch%
    \SB@chespace\let\SB@donext\SB@mchlig%
  \else\ifx\SB@next\ %
    \SB@chimpspace%
  \else\ifx\SB@next\SB@nbsp%
    \SB@chimpspace%
  \else%
    \SB@UTFtest\SB@next%
    \ifcase\SB@cnt\SB@chothermac%
    \or\or\SB@chespace\let\SB@donext\SB@chsteptwo%
    \or\SB@chespace\let\SB@donext\SB@chstepthree%
    \or\SB@chespace\let\SB@donext\SB@chstepfour\fi%
  \fi\fi\fi\fi\fi\fi\fi\fi%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\SB@chothermac}
% \changes{v2.6}{2008/03/26}{All active chars now included in lyrics by default.}
% The lyric-scanner has encountered a macro or active character that is
% not |\outer|, not a known macro that requires special treatment,
% and not a multibyte international character.
% First, check the macro's name (stored in |\SB@nextname|) to see whether it
% begins with a non-escape character.
% If so, it's probably an accenting or punctuation character made active
% by the |inputenc| or |babel| packages.
% Most such characters should be included in the lyric, so include it by
% default; otherwise exclude it by default.
% The user can override the defaults using |\DeclareLyricChar| and friends.
%    \begin{macrocode}
\newcommand\SB@chothermac{%
  \SB@testfalse%
  \afterassignment\iffalse%
  \SB@cnt\expandafter`\SB@nextname x\fi%
  \ifnum\the\catcode\SB@cnt=\z@\else\SB@testtrue\fi%
  \SB@macrotests%
  \ifSB@test%
    \SB@chespace\SB@chnxtstep%
  \else%
    \SB@chnxtdone%
  \fi%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\SB@chstep}
% \begin{macro}{\SB@chsteptwo}
% \begin{macro}{\SB@chstepthree}
% \begin{macro}{\SB@chstepfour}
% \begin{macro}{\SB@chmulti}
% \begin{macro}{\SB@chmstop}
% We've encountered one or more tokens that should be included in the
% lyric text.
% (More than one means we've encountered a multibyte encoding of an
% international character.)
% Consume them (as arguments to this macro) and add them to the list
% of tokens we've already consumed.
%    \begin{macrocode}
\newcommand\SB@chstep[1]{%
  \SB@lyric\expandafter{\the\SB@lyric#1}%
  \SB@chscan%
}
\newcommand\SB@chsteptwo[2]{\SB@chmulti{#1#2}{\string#1\string#2}}
\newcommand\SB@chstepthree[3]{%
  \SB@chmulti{#1#2#3}{\string#1\string#2\string#3}%
}
\newcommand\SB@chstepfour[4]{%
  \SB@chmulti{#1#2#3#4}{\string#1\string#2\string#3\string#4}%
}
\newcommand\SB@chmulti[2]{%
  \def\SB@next{#1}%
  \edef\SB@nextname{#2}%
  \SB@testtrue\SB@multitests%
  \ifSB@test%
    \SB@lyric\expandafter{\the\SB@lyric#1}%
    \expandafter\SB@chscan%
  \else%
    \expandafter\SB@chmstop%
  \fi%
}
\newcommand\SB@chmstop{\expandafter\SB@chdone\SB@next}
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\SB@chhyph}
% We've encountered a hyphen.
% Continue to digest hyphens, but terminate as soon as we see anything
% else.
%    \begin{macrocode}
\newcommand\SB@chhyph{%
  \ifx\SB@next-%
    \advance\SB@numhyps\@ne\relax%
    \SB@chnxtstep%
  \else%
    \SB@chnxtdone%
  \fi%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\SB@chimpspace}
% \begin{macro}{\SB@chexpspace}
% We've encountered an implicit or explicit space.
% Normally this just ends the lyric, but if |\MultiwordChords| is
% active, these macros both get redefined to process the space.
%    \begin{macrocode}
\newcommand\SB@chimpspace{}
\let\SB@chimpspace\SB@chnxtdone
\newcommand\SB@chexpspace{}
\let\SB@chexpspace\SB@chnxtdone
%    \end{macrocode}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\SB@chespace}
% \begin{macro}{\SB@chendspace}
% \changes{v1.22}{2007/05/15}{Added.}
% The |\SB@chespace| macro gets invoked by the lyric-scanner just before a
% non-space token is about to be accepted as part of an under-chord lyric.
% Normally it does nothing; however, if |\MultiwordChords| is active, it
% gets redefined to do one of three things:
% (1) Initially it is set equal to |\SB@chendspace| so that if the very
% first token following the chord macro is not a space, the lyric-scanner
% macros are redefined to process any future spaces encountered.
% Otherwise the very first token is a space, and the lyric ends immediately.
% (2) While scanning non-space lyric tokens, it is set to nothing, since no
% special action needs to be taken until we encounter a sequence of one or
% more spaces.
% (3) When a space token is encountered (but not the very first token after
% the chord macro), it is set equal to |\SB@chendspace| again so that
% |\SB@chendspace| is invoked once the sequence of one or more space tokens
% is finished.
%    \begin{macrocode}
\newcommand\SB@chespace{}
\newcommand\SB@chendspace{%
  \let\SB@chdone\SB@chlyrdone%
  \def\SB@chexpspace{\SB@chbspace\SB@chexpspace}%
  \def\SB@chimpspace{\SB@chbspace\SB@chimpspace}%
  \def\SB@chespace{}%
}
%    \end{macrocode}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\SB@chbspace}
% \begin{macro}{\SB@chgetspace}
% \changes{v1.22}{2007/05/15}{Added.}
% The |\SB@chbspace| macro gets invoked when |\MultiwordChords| is active
% and the lyric-scanner has encountered a space token that was immediately
% preceded by a non-space token.
% Before processing the space, we add all lyrics seen so far to the
% |\SB@lyricbox| and check its width.
% If we've seen enough lyrics to match or exceed the width of the chord,
% a space stops the lyric-scanning process.
% (This is important because it minimizes the size of the chord box,
% providing as many line breakpoints as possible to the paragraph-formatter.)
%
% Otherwise we begin scanning space tokens without adding them to the
% lyric until we see what the next non-space token is.
% If the next non-space token would have ended the lyric anyway, roll back
% and end the lyric here, reinserting the space tokens back into the token
% stream.
% If the next non-space token would have been included in the lyric,
% the lyric-scanner proceeds as normal.
%    \begin{macrocode}
\newcommand\SB@chbspace{%
  \setbox\SB@lyricbox\hbox{%
    \unhbox\SB@lyricbox%
    \the\SB@lyric%
  }%
  \SB@lyric{}%
  \ifdim\wd\SB@lyricbox<\wd\SB@chordbox%
    \let\SB@chbstok= \SB@next%
    \def\SB@chexpspace{\let\SB@donext\SB@chgetspace}%
    \let\SB@chimpspace\SB@chnxtstep%
    \let\SB@chespace\SB@chendspace%
    \let\SB@chdone\SB@chspcdone%
  \else%
    \let\SB@chimpspace\SB@chnxtdone%
    \let\SB@chexpspace\SB@chnxtdone%
  \fi%
}
\newcommand\SB@chgetspace{%
  \SB@appendsp\SB@lyric%
  \let\SB@nextname\relax%
  \afterassignment\SB@chscan%
  \let\SB@next= }
%    \end{macrocode}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\SB@chmbar}
% We've encountered a measure bar.
% Either ignore it or end the lyric text, depending on whether
% measure bars are being displayed.
%    \begin{macrocode}
\newcommand\SB@chmbar{%
  \ifmeasures%
    \SB@chnxtdone%
  \else%
    \SB@chespace\SB@chnxtstep%
  \fi%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\SB@chbgroup}
% We've encountered a begin-group brace.
% Consume the entire group that it begins, and add it to the list
% of tokens including the begin and end group tokens.
%    \begin{macrocode}
\newcommand\SB@chbgroup[1]{%
  \SB@lyric\expandafter{\the\SB@lyric{#1}}%
  \SB@chscan%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\SB@chegroup}
% \begin{macro}{\SB@chegrpscan}
% \begin{macro}{\SB@chegrpmacro}
% \begin{macro}{\SB@chegrpouter}
% \begin{macro}{\SB@chegrpname}
% \begin{macro}{\SB@chegrpdone}
% We've encountered an end-group brace whose matching begin-group brace
% must have come before the chord macro itself.
% This forcibly ends the lyric text.
% Before stopping, we must set |\SB@next| to the token following the brace
% and |\SB@nextname| to its |\string|ified name so that |\SB@emitchord| will
% know whether to add hyphenation.
% Therefore, we temporarily consume the end-group brace, then scan the
% next token without consuming it, and finally reinsert the end-group brace
% and stop.
%    \begin{macrocode}
\newcommand\SB@chegroup{%
  \let\SB@nextname\relax%
  \afterassignment\SB@chegrpscan%
  \let\SB@next= }
\newcommand\SB@chegrpscan{%
  \futurelet\SB@next\SB@chegrpmacro%
}
\newcommand\SB@chegrpmacro{%
  \ifcat\noexpand\SB@next\relax%
    \expandafter\SB@chegrpouter%
  \else%
    \expandafter\SB@chegrpdone%
  \fi%
}
\newcommand\SB@chegrpouter{%
  \SB@outertest%
  \ifSB@test%
    \expandafter\SB@chegrpdone%
  \else%
    \expandafter\SB@chegrpname%
  \fi%
}
\newcommand\SB@chegrpname[1]{%
  \edef\SB@nextname{\string#1}%
  \SB@chegrpdone#1%
}
\newcommand\SB@chegrpdone{\SB@chdone\egroup}
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\SB@chlig}
% \begin{macro}{\SB@mchlig}
% We've encountered a |\ch| chord-over-ligature macro, or an
% |\mch| measurebar-and-chord-over-ligature macro.
% Consume it and all of its arguments, and load them into some
% registers for future processing.
% (Part of the ligature might fall into this lyric text or might
% not, depending on whether we decide to add hyphenation.)
% Then end the lyric text here.
%    \begin{macrocode}
\newcommand\SB@chlig[5]{%
  \gdef\SB@ligpre{{#3}}%
  \gdef\SB@ligpost{\[#2]{#4}}%
  \gdef\SB@ligfull{%
    \[\SB@noreplay{\hphantom{{\lyricfont\relax#3}}}#2]{#5}%
  }%
  \SB@chdone%
}
\newcommand\SB@mchlig[5]{%
  \SB@lyric\expandafter{\the\SB@lyric#3}%
  \let\SB@next\measurebar%
  \edef\SB@nextname{\string\measurebar}%
  \gdef\SB@ligpost{\measurebar\[#2]{#4}}%
  \gdef\SB@ligfull{\measurebar\[#2]{#4}}%
  \SB@chdone%
}
%    \end{macrocode}
% \eat\]
% \end{macro}
% \end{macro}
%
% \begin{macro}{\SB@chdone}
% \begin{macro}{\SB@chlyrdone}
% \begin{macro}{\SB@chspcdone}
% The |\SB@chdone| macro is invoked when we've decided to end the lyric
% text (usually because we've encountered a non-lyric token).
% Normally this expands to |\SB@chlyrdone|, which adds any uncontributed
% lyric material to the |\SB@lyricbox| and jumps to the main chord
% formatting macro.
% However, if |\MultiwordChords| is active and if the lyric ended with
% a sequence of one or more space tokens, then we instead reinsert the
% space tokens into the token stream without contributing them to the
% |\SB@lyricbox|.
%    \begin{macrocode}
\newcommand\SB@chlyrdone{%
  \setbox\SB@lyricbox\hbox{%
    \unhbox\SB@lyricbox%
    \ifnum\SB@numhyps=\@ne%
      \the\SB@lyricnohyp%
    \else%
      \the\SB@lyric%
    \fi%
  }%
  \SB@emitchord%
}
\newcommand\SB@chspcdone{%
  \let\SB@nextname\relax%
  \let\SB@next= \SB@chbstok%
  \expandafter\SB@emitchord\the\SB@lyric%
}
\newcommand\SB@chdone{}
\let\SB@chdone\SB@chlyrdone
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\SB@ligpre}
% \begin{macro}{\SB@ligpost}
% \begin{macro}{\SB@ligfull}
% The following three macros record arguments passed to a |\ch| macro that
% concludes the lyric text of the |\[]|\eat\] macro currently being processed.
%    \begin{macrocode}
\newcommand\SB@ligpre{}
\newcommand\SB@ligpost{}
\newcommand\SB@ligfull{}
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\SB@clearlig}
% Clear all ligature-chord registers.
%    \begin{macrocode}
\newcommand\SB@clearlig{%
  \gdef\SB@ligpre{}%
  \gdef\SB@ligpost{}%
  \gdef\SB@ligfull{}%
}
%    \end{macrocode}
% \end{macro}
%
% \subsection{Chords}
%
% \begin{macro}{\SB@emitchord}\MainImpl{[}
% \changes{v1.12}{2005/05/10}{Inhibited hyphenation of trailing punctuation}
% \changes{v1.13}{2005/05/12}{Added code to preserve the spacefactor}
% \changes{v1.16}{2005/07/23}{Chord macros massively reorganized to take lyrics as implicit rather than explicit arguments}
% The |\SB@emitchord| macro does the actual work of typesetting chord text
% over lyric text, introducing appropriate hyphenation when necessary.
% We begin by consulting |\SB@next|, which should have been set by the
% lyric-scanning code in \S\ref{sec:lyricscan} to the token that immediately
% follows the lyric under this chord, to determine whether the lyric text
% ends on a word boundary.
%    \begin{macrocode}
\newcommand\SB@emitchord{%
  \ifSB@inverse\else\ifSB@inchorus\else\SB@errchord\fi\fi%
  \SB@testfalse%
  \ifcat\noexpand\SB@next\@sptoken\SB@testtrue\fi%
  \ifcat\noexpand\SB@next.\SB@testtrue\fi%
  \ifx\SB@next\SB@par\SB@testtrue\fi%
  \ifx\SB@next\egroup\SB@testtrue\fi%
  \ifx\SB@next\endgroup\SB@testtrue\fi%
  {\csname%
     SB@HT@\ifx\SB@nextname\relax\meaning\SB@next\else\SB@nextname\fi%
   \endcsname}%
  \ifSB@test\SB@wordendstrue\else\SB@wordendsfalse\fi%
%    \end{macrocode}
% Next, compare the width of the lyric to the width of the chord to
% determine whether hyphenation might be necessary.
% The original lyric text might have ended in a string of one or more
% explicit hyphens, enumerated by |\SB@numhyps|.
% If it ended in exactly one, the lyric-scanning code suppresses that hyphen
% so that we can here add a new hyphen that floats out away from the word
% when the chord above it is long.
% If it ended in more than one (e.g., the encoding of an en- or em-dash) then
% the lyric-scanner leaves it alone; we must not add any hyphenation or float
% the dash away from the word.
%
% There is also code here to insert a penalty that discourages linebreaking
% immediately before lyricless chords.
% Beginning a wrapped line with a lyricless chord is undesirable because it
% makes it look as though the wrapped line is extra-indented (due to the
% empty lyric space below the chord).
% It should therefore happen only as a last resort.
%    \begin{macrocode}
  \SB@dimen\wd\SB@chordbox%
  \ifvmode\leavevmode\fi%
  \SB@brokenwordfalse%
  \ifdim\wd\SB@lyricbox>\z@%
    \ifdim\SB@dimen>\wd\SB@lyricbox%
      \ifSB@wordends\else\SB@brokenwordtrue\fi%
    \fi%
  \else%
    \SB@skip\lastskip%
    \unskip\penalty200\hskip\SB@skip%
  \fi%
  \ifnum\SB@numhyps>\z@%
    \ifnum\SB@numhyps>\@ne%
      \SB@brokenwordfalse%
    \else%
      \SB@brokenwordtrue%
    \fi%
  \fi%
%    \end{macrocode}
% If lyrics are suppressed on this line (e.g., by using |\nolyrics|), then just
% typeset the chord text on the natural baseline.
%    \begin{macrocode}
  \SB@testfalse%
  \ifnolyrics\ifdim\wd\SB@lyricbox=\z@\SB@testtrue\fi\fi%
  \ifSB@test%
    \unhbox\SB@chordbox%
    \gdef\SB@temp{\expandafter\SB@clearlig\SB@ligfull}%
  \else%
%    \end{macrocode}
% Otherwise, typeset the chord above the lyric on a double-height line.
%    \begin{macrocode}
    \vbox{\clineparams\relax%
      \ifSB@brokenword%
        \global\setbox\SB@lyricbox\hbox{%
          \unhbox\SB@lyricbox%
          \SB@ligpre%
        }%
        \SB@maxmin\SB@dimen<{\wd\SB@lyricbox}%
        \advance\SB@dimen.5em%
        \hbox to\SB@dimen{\unhbox\SB@chordbox\hfil}%
        \hbox to\SB@dimen{%
          \unhcopy\SB@lyricbox\hfil
          \ifnum\hyphenchar\font>\m@ne\char\hyphenchar\font\hfil\fi%
        }%
        \global\SB@cnt\@m%
        \gdef\SB@temp{\expandafter\SB@clearlig\SB@ligpost}%
      \else%
        \box\SB@chordbox%
        \hbox{%
          \unhcopy\SB@lyricbox%
          \global\SB@cnt\spacefactor%
          \hfil%
        }%
        \gdef\SB@temp{\expandafter\SB@clearlig\SB@ligfull}%
      \fi%
    }%
%    \end{macrocode}
% If the chord is lyricless, inhibit a linebreak immediately following it.
% This prevents sequences of lyricless chords (which often end lines) from
% being wrapped in the middle, which looks very unsightly and makes them
% difficult to read.
% If the chord has a lyric but it doesn't end on a word boundary, insert
% an appropriate penalty to prevent linebreaking without hyphenation.
% Also preserve the spacefactor in this case, which allows \LaTeX{} to
% fine-tune the spacing between consecutive characters in the word that
% contains the chord.
%    \begin{macrocode}
    \ifSB@wordends%
      \ifdim\wd\SB@lyricbox>\z@\else\nobreak\fi%
    \else%
      \penalty%
        \ifnum\SB@numhyps>\z@\exhyphenpenalty%
        \else\ifSB@brokenword\hyphenpenalty%
        \else\@M\fi\fi%
      \spacefactor\SB@cnt%
    \fi%
  \fi%
%    \end{macrocode}
% Finally, end the macro with some code that handles the special case that
% this chord is immediately followed by a chord-over-ligature macro.
% The code above sets |\SB@temp| to the portion of the ligature that should
% come after this chord but before the chord that tops the ligature.
% This text must be inserted here.
%    \begin{macrocode}
  \SB@temp%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\SB@accidental}
% Typeset an accidental symbol as a superscript within a chord.
% Since chord names are often in italics but math symbols like sharp and
% flat are not, we need to do some kerning adjustments before and after the
% accidental to position it as if it were italicized.
% The pre-adjustment is just a simple italic correction using |\/|.
% The post-adjustment is based on the current font's slant-per-point metric.
%    \begin{macrocode}
\newcommand\SB@accidental[1]{{%
  \/%
  \m@th#1%
  \SB@dimen-\fontdimen\@ne\font%
  \advance\SB@dimen.088142\p@%
  \ifdim\SB@dimen<\z@%
    \kern\f@size\SB@dimen%
  \fi%
}}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\sharpsymbol}\MainImpl{sharpsymbol}
% \begin{macro}{\flatsymbol}\MainImpl{flatsymbol}
% When changing the sharp or flat symbol, change these macros rather than
% changing |\shrp| or |\flt|.
% This will ensure that other shortcuts like |#| and |&| will reflect your
% change.
%    \begin{macrocode}
\newcommand\sharpsymbol{\ensuremath{^\#}}
\newcommand\flatsymbol{\raise.5ex\hbox{{\SB@flatsize$\flat$}}}
%    \end{macrocode}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\shrp}\MainImpl{shrp}
% \begin{macro}{\flt}\MainImpl{flt}
% \changes{v2.10}{2009/08/18}{Font size made relative}
% These macros typeset sharp and flat symbols.
%    \begin{macrocode}
\newcommand\shrp{\SB@accidental\sharpsymbol}
\newcommand\flt{\SB@accidental\flatsymbol}
%    \end{macrocode}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\DeclareFlatSize}
% The |\flat| math symbol is too small for properly typesetting
% chord names.
% (Its size was designed for staff notation not textual chord names.)
% The correct size for the symbol should be approximately 30\% larger
% than the current superscript size, or 90\% of the base font size $b$.
% However, simply computing $0.9b$ does not work well because most fonts
% do not render well in arbitrary sizes.
% To solve the problem, we must therefore choose an appropriate size
% individually for each possible base font size $b$.
% This is the solution adopted by the rest of \LaTeX{} for such things.
% For example, \LaTeX's |\DeclareMathSizes| macro defines an appropriate
% superscript size for each possible base font size.
% The macro below creates a similar macro that that defines an appropriate
% flat-symbol size for each possible base font size.
%    \begin{macrocode}
\newcommand\DeclareFlatSize[2]{%
  \expandafter\xdef\csname SB@flatsize@#1\endcsname{#2}%
}
\DeclareFlatSize\@vpt\@vpt
\DeclareFlatSize\@vipt\@vipt
\DeclareFlatSize\@viipt\@vipt
\DeclareFlatSize\@viiipt\@viipt
\DeclareFlatSize\@ixpt\@viiipt
\DeclareFlatSize\@xpt\@ixpt
\DeclareFlatSize\@xipt\@xpt
\DeclareFlatSize\@xiipt\@xipt
\DeclareFlatSize\@xivpt\@xiipt
\DeclareFlatSize\@xviipt\@xivpt
\DeclareFlatSize\@xxpt\@xviipt
\DeclareFlatSize\@xxvpt\@xxpt
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\SB@flatsize}
% Select the correct flat symbol size based on the current font size.
%    \begin{macrocode}
\newcommand\SB@flatsize{%
  \@ifundefined{SB@flatsize@\f@size}{}{%
    \expandafter\fontsize%
      \csname SB@flatsize@\f@size\endcsname\f@baselineskip%
    \selectfont%
  }%
}    
%    \end{macrocode}
% \end{macro}
%
% In the following code, the |\ch|, |\mch|, |\[|\eat\], and |^| macros are
% each defined to be a single macro that then expands to the real definition.
% This is necessary because the top-level definitions of each must stay the
% same in order to allow the lyric-scanning code to uniquely identify them,
% yet their internal definitions must be redefined by code that turns
% chords and/or measure bars on and off.
% Such code redefines |\SB@ch|, |\SB@mch|, |\SB@bracket|, and |\SB@rechord|
% to effect a change of mode without touching the top-level definitions.
%
% \begin{macro}{\ch}\MainImpl{ch}
% \begin{macro}{\SB@ch}
% \begin{macro}{\SB@ch@on}
% \begin{macro}{\SB@@ch}
% \begin{macro}{\SB@@@ch}
% \begin{macro}{\SB@ch@off}
% The |\ch| macro puts a chord atop a ligature without breaking the ligature.
% Normally this just means placing the chord midway over the unbroken
% ligature (ignoring the third argument completely).
% However, when a previous chord macro encounters it while scanning ahead in
% the input stream to parse its lyric, the |\ch| macro itself is not actually
% expanded at all.
% Instead, the chord macro scans ahead, spots the |\ch| macro, gobbles it,
% and then steals its arguments, breaking the ligature with hyphenation.
% Thus, the |\ch| macro is only actually expanded when the ligature
% shouldn't be broken.
%    \begin{macrocode}
\newcommand\ch{\SB@ch}
\newcommand\SB@ch{}
\newcommand\SB@ch@on{\SB@begincname\SB@@ch}
\newcommand*\SB@@ch[1]{\SB@endcname\SB@@@ch{#1}}
\newcommand*\SB@@@ch[4]{\[\SB@noreplay{\hphantom{#2}}#1]#4}
\newcommand*\SB@ch@off[4]{#4}
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \eat\]
%
% \begin{macro}{\mch}\MainImpl{mch}
% \begin{macro}{\SB@mch}
% \begin{macro}{\SB@mch@m}
% \begin{macro}{\SB@mch@on}
% \begin{macro}{\SB@@mch}
% \begin{macro}{\SB@@@mch}
% The |\mch| macro is like |\ch| except that it also introduces a measure
% bar.
%    \begin{macrocode}
\newcommand\mch{\SB@mch}
\newcommand\SB@mch{}
\newcommand*\SB@mch@m[4]{#2\measurebar#3}
\newcommand\SB@mch@on{\SB@begincname\SB@@mch}
\newcommand*\SB@@mch[1]{\SB@endcname\SB@@@mch{#1}}
\newcommand*\SB@@@mch[4]{#2\measurebar\[#1]#3}
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \eat\]
%
% \begin{macro}{\SB@activehat}
% This macro must always contain the current definition of the |^|
% chord-replay active character, in order for the lyric scanner to properly
% identify it and insert proper hyphenation when necessary.
%    \begin{macrocode}
\newcommand\SB@activehat{%
  \ifmmode^\else\expandafter\SB@rechord\fi%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\SB@hat@tr}
% In verses/choruses where chords are being memorized, |\SB@activehat|
% gets set to this definition, which marks the current chord as immune to
% memorization.
%    \begin{macrocode}
\newcommand\SB@hat@tr{%
  \ifmmode^\else\global\SB@nohatfalse\fi%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\SB@hat@notr}
% In verses/choruses where chords are being replayed, |\SB@activehat|
% get set to the following, which replays the next memorized chord and
% subjects it to any required transposition and/or note conversion.
%    \begin{macrocode}
\newcommand\SB@hat@notr{%
  \ifmmode^\else%
    \SB@lop\SB@ctail\SB@toks%
    \expandafter\transposehere\expandafter{\the\SB@toks}%
  \fi%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\SB@loadactives}
% It's cumbersome to have to type |\shrp|, |\flt|, and |\mbar| every time you
% want a sharp, flat, or measure bar, so within verses and choruses we allow
% the hash, ampersand, and pipe symbols to perform the those functions too.
% It's also cumbersome to have to type something like |\chord{Am}{lyric}| to
% produce each chord.
% As an easier alternative, we here define |\[Am]|\eat\]
% to typeset chords.
%    \begin{macrocode}
\newcommand\SB@loadactives{}
{
  \catcode`&\active
  \catcode`#\active
  \catcode`|\active
  \catcode`^\active
  \global\let&\flt
  \global\let#\shrp
  \global\let|\measurebar
  \global\let^\SB@activehat
  \gdef\SB@loadactives{%
    \catcode`^\ifchorded\active\else9 \fi%
    \catcode`|\ifmeasures\active\else9 \fi%
    \def\[{\SB@bracket}%
  }
}
%    \end{macrocode}
% \end{macro}
%
% \subsection{Chord Replaying}
%
% \begin{macro}{\SB@trackch}
% While inside a verse where the chord history is being remembered for future
% verses, |\SB@trackch| is true.
%    \begin{macrocode}
\newif\ifSB@trackch
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\SB@cr@}
% Reserve token registers to record a history of the chords seen in a verse.
%    \begin{macrocode}
\SB@newtoks\SB@cr@
\SB@newtoks\SB@ctail
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\SB@creg}
% The following control sequence equals the token register being memorized
% into or replayed from.
%    \begin{macrocode}
\newcommand\SB@creg{}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\newchords}\MainImpl{newchords}
% \changes{v2.6}{2008/02/23}{Added}
% Allocate a new chord-replay register to hold memorized chords.
%    \begin{macrocode}
\newcommand\newchords[1]{%
  \@ifundefined{SB@cr@#1}{%
    \expandafter\SB@newtoks\csname SB@cr@#1\endcsname%
    \global\csname SB@cr@#1\endcsname{\\}%
  }{\SB@errdup{#1}}%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\memorize}\MainImpl{memorize}
% \begin{macro}{\SB@memorize}
% \changes{v2.6}{2008/02/23}{Optional argument added}
% Saying |\memorize| throws out any previously memorized list of chords and
% starts memorizing chords until the end of the current verse or chorus.
%    \begin{macrocode}
\newcommand\memorize{%
  \@ifnextchar[\SB@memorize{\SB@memorize[]}%
}
\newcommand\SB@memorize{}
\def\SB@memorize[#1]{%
  \@ifundefined{SB@cr@#1}{\SB@errreg{#1}}{%
    \SB@trackchtrue%
    \global\expandafter\let\expandafter\SB@creg%
      \csname SB@cr@#1\endcsname%
    \global\SB@creg{\\}%
  }%
}
%    \end{macrocode}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\replay}\MainImpl{replay}
% \begin{macro}{\SB@replay}
% \begin{macro}{\SB@@replay}
% \changes{v2.6}{2008/02/23}{Added}
% Saying |\replay| stops any memorization and begins replaying memorized
% chords.
%    \begin{macrocode}
\newcommand\replay{\@ifnextchar[\SB@replay\SB@@replay}
\newcommand\SB@replay{}
\def\SB@replay[#1]{%
  \@ifundefined{SB@cr@#1}{\SB@errreg{#1}}{%
    \SB@trackchfalse%
    \global\expandafter\let\expandafter\SB@creg%
      \csname SB@cr@#1\endcsname%
    \global\SB@ctail\SB@creg%
  }%
}
\newcommand\SB@@replay{%
  \SB@trackchfalse%
  \global\SB@ctail\SB@creg%
}
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\SB@rechord}
% \begin{macro}{\SB@@rechord}
% Replay the same chord that was in a previous verse.
%    \begin{macrocode}
\newcommand\SB@rechord{}
\newcommand\SB@@rechord{%
  \SB@ifempty\SB@ctail{%
    \SB@errreplay%
    \SB@toks{}%
    \let\SB@donext\@gobble%
  }{%
    \SB@lop\SB@ctail\SB@toks%
    \let\SB@donext\SB@chord%
    \let\SB@noreplay\@gobble%
  }%
  \expandafter\SB@donext\the\SB@toks]%
}
%    \end{macrocode}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\ifSB@nohat}
% The |\ifSB@nohat| conditional is set to false when a chord macro contains
% a |^| in its argument.
% This suppresses the recording mechanism momentarily so that replays will
% skip this chord.
%    \begin{macrocode}
\newif\ifSB@nohat
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\SB@noreplay}
% Sometimes material must be added to a chord but omitted when the chord is
% replayed.
% We accomplish this by enclosing such material in |\SB@noreplay| macros,
% which are set to |\@gobble| just before a replay and reset to
% |\@firstofone| at other times.
%    \begin{macrocode}
\newcommand\SB@noreplay{}
\let\SB@noreplay\@firstofone
%    \end{macrocode}
% \end{macro}
%
% \subsection{Guitar Tablatures}
%
% The song book software not only supports chord names alone, but can also
% typeset guitar tablature diagrams. The macros for producing these diagrams
% are found here.
%
% \begin{macro}{\SB@fretwidth}
% Set the width of each vertical string in the tablature diagram.
%    \begin{macrocode}
\newlength\SB@fretwidth
\setlength\SB@fretwidth{6\p@}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\SB@fretnum}
% Typeset a fret number to appear to the left of the diagram.
%    \begin{macrocode}
\newcommand\SB@fretnum[1]{{%
  \sffamily\fontsize\@xpt\@xpt\selectfont#1%
}}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\SB@onfret}
% Typeset one string of one fret with \argp{1} typeset overtop of it (usually
% a dot or nothing at all).
%    \begin{macrocode}
\newcommand\SB@onfret[1]{%
  \kern.5\SB@fretwidth\kern-.2\p@%
  \vrule\@height6\p@%
  \kern-.2\p@\kern-.5\SB@fretwidth%
  \hbox to\SB@fretwidth{\hfil#1\hfil}%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\SB@atopfret}
% Typeset material (given by \argp{1}) to be placed above a string in the
% tablature diagram.
%    \begin{macrocode}
\newcommand\SB@atopfret[1]{%
  \hbox to\SB@fretwidth{\hfil#1\hfil}%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\SB@fretbar}
% Typeset a horizontal fret bar of width |\SB@dimen|.
%    \begin{macrocode}
\newcommand\SB@fretbar{%
  \nointerlineskip%
  \hbox to\SB@dimen{%
    \advance\SB@dimen-\SB@fretwidth%
    \advance\SB@dimen.4\p@%
    \hfil%
    \vrule\@width\SB@dimen\@height.4\p@\@depth\z@%
    \hfil%
  }%
  \nointerlineskip%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\SB@topempty}
% \begin{macro}{\SB@topX}
% \begin{macro}{\SB@topO}
% Above a string in a tablature diagram there can be nothing,
% an $\times$, or an $\circ$.
%    \begin{macrocode}
\newcommand\SB@topempty{\SB@atopfret\relax}
\newcommand\SB@topX{\SB@atopfret{%
  \hbox{%
    \kern-.2\p@%
    \fontencoding{OMS}\fontfamily{cmsy}%
    \fontseries{m}\fontshape{n}%
    \fontsize\@viipt\@viipt\selectfont\char\tw@%
    \kern-.2\p@%
  }%
}}
\newcommand\SB@topO{\SB@atopfret{%
  \vrule\@width\z@\@height4.3333\p@\@depth.8333\p@%
  \lower.74\p@\hbox{%
    \fontencoding{OMS}\fontfamily{cmsy}%
    \fontseries{m}\fontshape{n}%
    \fontsize\@xpt\@xpt\selectfont\char14%
  }%
}}
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\SB@doify}
% \begin{macro}{\SB@@doify}
% \begin{macro}{\SB@do}
% Define the macro given in the first argument to equal the fully expanded
% content of the second argument, but with |\SB@do| inserted before each token
% or group.
%    \begin{macrocode}
\newcommand\SB@do[1]{}
\newcommand\SB@doify[2]{%
  \SB@toks{}%
  \edef#1{#2}%
  \expandafter\SB@@doify#1\SB@@doify%
  \edef#1{\the\SB@toks}%
}
\newcommand\SB@@doify[1]{%
  \ifx#1\SB@@doify\else%
    \SB@toks\expandafter{\the\SB@toks\SB@do{#1}}%
    \expandafter\SB@@doify%
  \fi%
}
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\SB@allbarres}
% \begin{macro}{\SB@dobarre}
% Reserve a control sequence to remember all the stacks, start control
% sequences, and end control sequences associated with barre delimiter pairs;
% and a control sequence to perform an arbitrary action on them.
%    \begin{macrocode}
\newcommand\SB@allbarres{}
\newcommand\SB@dobarre{}
%    \end{macrocode}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\SB@barreI}
% \begin{macro}{\SB@barreN}
% \begin{macro}{\SB@barreY}
% As we process strings in order, barres in progress can be in one of three
% states: initial (|\SB@barreI|), deactivated (|\SB@barreN|), or
% tentatively activated (|\SB@barreY|).
%    \begin{macrocode}
\newcommand\SB@barreI{\noexpand\SB@barreI}
\newcommand\SB@barreN{\noexpand\SB@barreN}
\newcommand\SB@barreY{\noexpand\SB@barreY}
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\SB@lowfret}
% \begin{macro}{\SB@@lowfret}
% If we see a lower numbered fret than the current fret within a barre,
% deactivate the barre.
% (It has already been shown on an earlier fret.)
%    \begin{macrocode}
\newcommand\SB@lowfret{%
  \let\SB@dobarre\SB@@lowfret\SB@allbarres%
  \SB@fretempty%
}
\newcommand\SB@@lowfret[3]{{%
  \let\SB@barreI\SB@barreN%
  \let\SB@barreY\SB@barreN%
  \xdef#1{#1}%
}}
%    \end{macrocode}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\SB@bactivate}
% If we see the current fret within a barre, tentatively activate the barre
% (unless it is already deactivated).
%    \begin{macrocode}
\newcommand\SB@bactivate[3]{{%
  \let\SB@barreI\SB@barreY%
  \xdef#1{#1}%
}}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\SB@bbarre}
% Starting a barre group pushes it onto its stack in the initial state.
%    \begin{macrocode}
\newcommand\SB@bbarre[1]{%
  \xdef#1{\SB@barreI{\the\SB@cntii}#1}%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\SB@ebarre}
% \begin{macro}{\SB@@ebarre}
% \begin{macro}{\SB@@@ebarre}
% Ending a barre group pops it and draws it if it's active.
%    \begin{macrocode}
\newcommand\SB@ebarre[3]{%
  \ifx#1\@empty%
    \ifnum\SB@cnt=\@ne\SB@errebar#2#3\fi%
  \else%
    \expandafter\SB@@ebarre#1\SB@@ebarre#1%
  \fi%
}
\newcommand\SB@@ebarre{}
\def\SB@@ebarre#1#2#3\SB@@ebarre#4{{%
  \gdef#4{#3}%
  \let\SB@barreI\@gobble%
  \let\SB@barreN\@gobble%
  \let\SB@barreY\SB@barre%
  #1{#2}%
}}
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\SB@barreson}
% \begin{macro}{\SB@barresoff}
% Turn barre delimiters on or off, depending on whether we're typesetting
% the interior or upper part of the tablature diagram.
%    \begin{macrocode}
\newcommand\SB@barreson[3]{%
  \def#2{\SB@bbarre#1}%
  \def#3{\SB@ebarre#1#2#3}%
}
\newcommand\SB@barresoff[3]{\let#2\relax\let#3\relax}
%    \end{macrocode}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\SB@fretempty}
% \begin{macro}{\SB@fretdot}
% \begin{macro}{\SB@@fretdot}
% On a string in a fret diagram there can be nothing or a filled circle.
%    \begin{macrocode}
\newcommand\SB@fretempty{%
  \advance\SB@cntii\@ne%
  \SB@onfret\relax%
}
\newcommand\SB@fretdot{%
  \advance\SB@cntii\@ne%
  \let\SB@dobarre\SB@bactivate\SB@allbarres%
  \SB@@fretdot%
}
\newcommand\SB@@fretdot{%
  \SB@onfret{%
    \fontencoding{OMS}\fontfamily{cmsy}%
    \fontseries{m}\fontshape{n}%
    \fontsize\@xiipt\@xiipt\selectfont\char15%
  }%
}
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\SB@barre}
% Draw a barre.
%    \begin{macrocode}
\newcommand\SB@barre[1]{{%
  \SB@dimen\SB@fretwidth%
  \multiply\SB@dimen\SB@cntii%
  \advance\SB@dimen-#1\SB@fretwidth%
  \kern-\SB@dimen%
  \SB@@fretdot%
  \kern-.5\SB@fretwidth%
  \advance\SB@dimen-\SB@fretwidth%
  \raise.7pt\hbox{\vrule\@height4.6\p@\@width\SB@dimen}%
  \kern-.5\SB@fretwidth%
  \SB@@fretdot%
}}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\SB@fretend}
% At the end of a barred row in a tablature diagram, we auto-finish any
% activated barres that weren't explicitly closed by the user.
%    \begin{macrocode}
\newcommand\SB@fretend{{%
  \let\SB@barreI\@gobble%
  \let\SB@barreN\@gobble%
  \let\SB@barreY\SB@barre%
  \def\SB@dobarre##1##2##3{##1\gdef##1{}}\SB@allbarres%
}}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\SB@finger}
% \begin{macro}{\SB@X}
% \begin{macro}{\SB@Z}
% \begin{macro}{\SB@O}
% If we're including fingering info in the tablature diagram, then below
% each string there might be a number.
%    \begin{macrocode}
\newcommand*\SB@X{X}
\newcommand*\SB@Z{0}
\newcommand*\SB@O{O}
\newcommand\SB@finger[1]{%
  \def\SB@temp{#1}%
  \ifx\SB@temp\SB@X\SB@topempty\else%
  \ifx\SB@temp\SB@Z\SB@topempty\else%
  \ifx\SB@temp\SB@O\SB@topempty\else%
    \SB@atopfret{\sffamily\fontsize\@vipt\@vipt\selectfont#1}%
  \fi\fi\fi%
}
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\ifSB@gettabind}
% \begin{macro}{\SB@tabindent}
% Lyrics under tablature diagrams look odd if they aren't aligned with the
% leftmost string of the diagram.
% To accomplish this, the following two macros record the amount by which
% a lyric under this tablature diagram must be indented to position it
% properly.
%    \begin{macrocode}
\newif\ifSB@gettabind\SB@gettabindfalse
\SB@newdimen\SB@tabindent
%    \end{macrocode}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\SB@targfret}
% \begin{macro}{\SB@targstr}
% \begin{macro}{\SB@targfing}
% Reserve some macro names in which to store the three pieces of the
% second argument to the |\gtab| macro.
% The first is for the fret number, the second is for the \Meta{strings}
% info, and the last is for the \Meta{fingering} info.
%    \begin{macrocode}
\newcommand\SB@targfret{}
\newcommand\SB@targstr{}
\newcommand\SB@targfing{}
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
%
% In general |\gtab| macros often appear inside chord macros, which means
% that their arguments have already been scanned by the time the
% |\gtab| macro itself is expanded.
% This means that catcodes cannot be reassigned (without resorting to
% $\varepsilon$-\TeX).
%
% We therefore adopt the alternative strategy of converting each token
% in the \Meta{strings} and \Meta{fingering} arguments of a |\gtab| macro
% into a control sequence (using |\csname|).
% We can then temporarily assign meanings to those control sequences and
% replay the arguments to achieve various effects.
%
% \begin{macro}{\SB@gtinit}
% \begin{macro}{\SB@gtinc}
% Different meanings are assigned to digits, |X|'s, and |O|'s
% as we typeset each row of the interior of the diagram.
% These meanings are set by |\SB@gtinit| and |\SB@gtinc|.
%    \begin{macrocode}
\newcommand\SB@gtinit{%
  \def\SB@do##1{\csname##1\endcsname}%
  \let\O\0%
  \let\3\2\let\4\2\let\5\2\let\6\2%
  \let\7\2\let\8\2\let\9\2%
}
\newcommand\SB@gtinc{%
  \advance\SB@cnt\@ne%
  \let\9\8\let\8\7\let\7\6\let\6\5\let\5\4%
  \let\4\3\let\3\2\let\2\1\let\1\SB@lowfret%
}
%    \end{macrocode}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\BarreDelims}
% \begin{macro}{\SB@bdelims}
% Each pair of barre delimiters reserves a stack and augments the
% initialization state to recognize those delimiters.
%    \begin{macrocode}
\newcommand\BarreDelims[2]{%
  \expandafter\SB@bdelims\csname SB@bs@#1#2\expandafter\endcsname%
    \csname#1\expandafter\endcsname\csname#2\endcsname%
}
\newcommand\SB@bdelims[3]{%
  \newcommand*#1{}%
  \SB@app\def\SB@allbarres{\SB@dobarre#1#2#3}%
}
\BarreDelims()
\BarreDelims[]
%    \end{macrocode}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\gtab}
% \begin{macro}{\SB@gtab}
% \changes{v2.9}{2009/03/27}{Fixed compatibility issue with Babel French}
% A |\gtab| macro begins by setting catcodes suitable for parsing a chord
% name as its first argument.
% This allows tokens like |#| and |&| to be used for sharp and flat even
% when |\gtab| is used outside a chord macro.
% Colon is reset to a non-active character while processing the second
% argument to avoid a potential conflict with \textsf{Babel} French.
%    \begin{macrocode}
\newcommand\gtab{\SB@begincname\SB@gtab}
\newcommand*\SB@gtab[1]{%
  \SB@endcname%
  \begingroup%
    \catcode`:12\relax%
    \SB@@gtab{#1}%
}
%    \end{macrocode}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\SB@@gtab}
% If transposition is currently taking place, allow the user to customize
% the behavior by redefining |\gtabtrans|.
% Using |\gtab| within |\gtabtrans| should go directly to |\SB@@@gtab|
% (otherwise an infinite loop would result!).
%    \begin{macrocode}
\newcommand*\SB@@gtab[2]{%
  \endgroup%
  \ifnum\SB@transposefactor=\z@%
    \SB@@@gtab{#1}{#2}%
  \else%
    \begingroup%
      \let\gtab\SB@@@gtab%
      \gtabtrans{#1}{#2}%
    \endgroup%
  \fi%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\gtabtrans}\MainImpl{gtabtrans}
% By default, transposed guitar tablatures just display the transposed
% chord name and omit the diagram.
% Transposing a tablature diagram requires manual judgment calls for most
% stringed instruments, so we can't do it automatically.
%    \begin{macrocode}
\newcommand\gtabtrans[2]{\transposehere{#1}}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\SB@@@gtab}\MainImpl{gtab}
% \changes{v2.13}{2011/04/16}{Added transposition for chord names}
% Typeset a full tablature diagram.
% Text \argp{1} is a chord name placed above the diagram.
% Text \argp{2} consists of a colon-separated list of:
% (1) an optional fret number placed to the left of the diagram;
% (2) a sequence of tokens, each of which can be
% |X| (to place an $\times$ above the string),
% |0| or |O| (to place an $\circ$ above the string), or
% one of |1| through |9| (to place a filled circle on that string at the
% fret of the given number); and
% (3) an optional sequence of tokens, each of which is either |0|
% (no fingering information for that string),
% or one of |1| through |4| (to place the given number under that string).
%    \begin{macrocode}
\newcommand\SB@@@gtab[2]{%
  \let\SB@targfret\@empty%
  \let\SB@targstr\@empty%
  \let\SB@targfing\@empty%
  \SB@tabargs#2:::\SB@tabargs%
  \ifx\SB@targstr\@empty%
    \def\SB@targstr{\0\0\0\0\0\0}%
  \fi%
  \ifvmode\leavevmode\fi%
  \vbox{%
    \normalfont\normalsize%
    \setbox\SB@box\hbox{%
      \thinspace{\printchord{\transposehere{#1}\strut}}\thinspace%
    }%
    \setbox\SB@boxii\hbox{\SB@fretnum{\SB@targfret}}%
    \setbox\SB@boxiii\hbox{{%
      \let\X\SB@topX\let\0\SB@topO%
      \let\1\SB@topempty\let\2\1%
      \SB@gtinit%
      \let\SB@dobarre\SB@barresoff\SB@allbarres%
      \SB@targstr%
    }}%
    \hsize\wd\SB@box%
    \ifSB@gettabind%
      \global\SB@tabindent\wd\SB@boxii%
      \global\advance\SB@tabindent.5\SB@fretwidth%
      \global\advance\SB@tabindent-.5\p@%
    \fi%
    \SB@dimen\wd\SB@boxii%
    \advance\SB@dimen\wd\SB@boxiii%
    \ifdim\hsize<\SB@dimen%
      \hsize\SB@dimen%
    \else\ifSB@gettabind%
      \SB@dimenii\hsize%
      \advance\SB@dimenii-\SB@dimen%
      \divide\SB@dimenii\tw@%
      \global\advance\SB@tabindent\SB@dimenii%
    \fi\fi%
    \hbox to\hsize{\hfil\unhbox\SB@box\hfil}%
    \kern-\p@\nointerlineskip%
    \hbox to\hsize{%
      \hfil%
      \vtop{\kern\p@\kern2\p@\box\SB@boxii}%
      \vtop{%
        \SB@dimen\wd\SB@boxiii%
        \box\SB@boxiii%
        \let\X\SB@fretempty\let\0\X%
        \let\1\SB@fretdot\def\2{\SB@fretempty\global\SB@testtrue}%
        \SB@gtinit%
        \let\SB@dobarre\SB@barreson\SB@allbarres%
        \SB@cnt\@ne%
        \loop%
          \SB@testfalse%
          \SB@fretbar\hbox{\SB@cntii\z@\SB@targstr\SB@fretend}%
          \ifnum\SB@cnt<\minfrets\SB@testtrue\fi%
        \ifSB@test\SB@gtinc\repeat%
        \SB@fretbar%
        \ifx\SB@targsfing\@empty\else%
          \kern1.5\p@%
          \hbox{\let\SB@do\SB@finger\SB@targfing}%
        \fi%
      }%
      \hfil%
    }%
    \kern3\p@%
  }%
  \SB@gettabindfalse%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\SB@tabargs}
% \begin{macro}{\SB@@tabargs}
% \begin{macro}{\SB@ctoken}
% \changes{v3.1}{2017/06/23}{Allow macros within 2nd gtab arg}
% Break the second argument to a |\gtab| macro into three sub-arguments.
% The possible forms are:
% (a) \Meta{strings},
% (b) \Meta{fret}|:|\Meta{strings},
% (c) \Meta{strings}|:|\Meta{fingering}, or
% (d) \Meta{fret}|:|\Meta{strings}|:|\Meta{fingering}.
% To distinguish forms (b) and (c), we count the number of tokens before
% the first colon.
% If there is only one token or group, we assume it must be form (b),
% since frets larger than 9 and 1-stringed instruments are both rare.
% Otherwise we assume form (c).
%    \begin{macrocode}
\newcommand\SB@ctoken{} \def\SB@ctoken{:}
\newcommand\SB@tabargs{}
\def\SB@tabargs#1:#2:#3:#4\SB@tabargs{%
  \def\SB@temp{#4}%
  \ifx\SB@temp\@empty%
    \SB@doify\SB@targstr{#1}%
  \else\ifx\SB@temp\SB@ctoken%
    \SB@@tabargs#1\SB@@tabargs%
    \ifx\SB@temp\@empty%
      \def\SB@targfret{#1}%
      \SB@doify\SB@targstr{#2}%
    \else%
      \SB@doify\SB@targfing{#2}%
      \SB@doify\SB@targstr{#1}%
    \fi%
  \else%
    \def\SB@targfret{#1}%
    \SB@doify\SB@targfing{#3}%
    \SB@doify\SB@targstr{#2}%
  \fi\fi%
}
\newcommand\SB@@tabargs{}
\def\SB@@tabargs#1#2\SB@@tabargs{\def\SB@temp{#2}}
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
%
% \subsection{Book Sectioning}
%
% The following macros divide the song book into distinct sections, each with
% different headers, different song numbering styles, different indexes, etc.
%
% \begin{macro}{\songchapter}\MainImpl{songchapter}
% \changes{v1.19}{2005/10/24}{Added}
% Format the chapter header for a chapter in a song book.
% By default, chapter headers on a song book omit the chapter number, but do
% include an entry in the pdf index or table of contents.
% Thus, the chapter has a number; it's just not displayed at the start of
% the chapter.
%    \begin{macrocode}
\newcommand\songchapter{%
  \let\SB@temp\@seccntformat%
  \def\@seccntformat##1{}%
  \@startsection{chapter}{0}{\z@}%
    {3.5ex\@plus1ex\@minus.2ex}%
    {.4ex\let\@seccntformat\SB@temp}%
    {\sffamily\bfseries\LARGE\centering}%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\songsection}\MainImpl{songsection}
% \changes{v1.19}{2005/10/24}{Section headers changed to omit numbers}
% Format the section header for a section in a song book.
% This is the same as for chapter headers except at the section level.
%    \begin{macrocode}
\newcommand\songsection{%
  \let\SB@temp\@seccntformat%
  \def\@seccntformat##1{}%
  \@startsection{section}{1}{\z@}%
    {3.5ex\@plus1ex\@minus.2ex}%
    {.4ex\let\@seccntformat\SB@temp}%
    {\sffamily\bfseries\LARGE\centering}%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{environment}{songs}\MainEnvImpl{songs}
% \changes{v1.19}{2005/10/24}{Song numbers now starts at one instead of zero}
% Begin and end a book section.
% The argument is a list of indexes with which to associate songs in this
% section. 
%    \begin{macrocode}
\newenvironment{songs}[1]{%
  \ifSB@songsenv\SB@errnse\fi%
  \gdef\SB@indexlist{#1}%
  \SB@chkidxlst%
  \stepcounter{SB@songsnum}%
  \setcounter{songnum}{1}%
  \let\SB@sgroup\@empty%
  \ifinner\else\ifdim\pagetotal>\z@%
    \null\nointerlineskip%
  \fi\fi%
  \songcolumns\SB@numcols%
  \SB@songsenvtrue%
}{%
  \commitsongs%
  \global\let\SB@indexlist\@empty%
  \ifinner\else\clearpage\fi%
  \SB@songsenvfalse%
}
%    \end{macrocode}
% \end{environment}
%
% Each |songs| section needs a unique number to aid in hyperlinking.
%    \begin{macrocode}
\newcounter{SB@songsnum}
%    \end{macrocode}
%
% \subsection{Index Generation}
% \label{sec:indexgen}
%
% The following macros generate the various types of indexes. At present there
% are four types:
% \begin{enumerate}
% \item A ``large'' index has a separate section for each capital letter and
% is printed in two columns.
% \item A ``small'' index has only a single column, centered, and has no
% sections.
% \item A ``scripture'' index has three columns and each entry has a
% comma-separated list of references.
% \item An ``author'' index is like a large index except in bold and without
% the sectioning.
% \end{enumerate}
% ``Large'' and ``small'' indexes will be chosen automatically based on the
% number of index entries when building a song index. The other two types are
% designated by the user.
%
% As is typical of \LaTeX{} indexes, generation of song book indexes requires
% two passes of document compilation. During the first pass, data files are
% generated with song titles, authors, and scripture references. An external
% program is then used to produce \LaTeX{} source files from those data files.
% During the second pass of document compilation, those source files are
% imported to typeset all the indexes and display them in the document.
%
% Internally, this package code uses a \emph{four} step process to move
% the index data from the source |.tex| file to the |.sxd| data files.
% \begin{enumerate}
% \item While the current song box is in the midst of construction,
% the data is stored in a box of non-immediate write whatsit nodes.
% \item The whatsits are migrated out to the top of the song box when
% it is finalized at |\endsong|.
% \item When the song box is shipped out to the output file, \TeX{} expands
% the whatsits, causing the data to be written to the |.sxc| auxiliary file.
% \item At the |\end{document}| line, the |.sxc| is processed multiple
% times---once for each index---to split the data into the respective
% |.sxd| files.
% \end{enumerate}
% The first and second steps allow index references to point to the
% beginning of the song no matter where the indexing commands appear
% within the song.
% The third step allows \TeX{} to drop index entries that refer to
% songs that do not actually appear in the output (e.g., because of
% |\includeonlysongs|).
% It also allows index entries to refer to information that is only decided
% at shipout time, such as page numbers.
% The fourth step allows all indexing to be accomplished with at most one
% write register.
% \LaTeX{} provides extremely few write registers, so using as
% few as possible is essential for supporting books with many indexes.
%
% \begin{macro}{\songtarget}\MainImpl{songtarget}
% This macro is invoked by each \mac{beginsong} environment with two arguments:
% (1) a suggested pdf bookmark index level, and
% (2) a target name to which hyperlinks for this song in the index will refer.
% The macro is expected to produce a suitable pdf bookmark entry and/or
% link target.
% The default definition tries to use |\pdfbookmark| if generating a PDF,
% and resorts to |\hypertarget| (if it exists) otherwise.
% The user can redefine the macro to customize how and whether bookmarks
% and/or links are created.
%    \begin{macrocode}
\newcommand\songtarget[2]{%
  \ifnum\@ne=0\ifSB@pdf\ifx\pdfbookmark\undefined\else%
                       \ifx\pdfbookmark\relax\else1\fi\fi\fi\relax%
    \pdfbookmark[#1]{\thesongnum. \songtitle}{#2}%
  \else\ifx\hypertarget\undefined%
  \else\ifx\hypertarget\relax\else%
    \hypertarget{#2}{\relax}%
  \fi\fi\fi%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\songlink}\MainImpl{songlink}
% This macro is invoked by the index code to produce a link to a song target
% created by \mac{songtarget}.
% Its two arguments are:
% (1) the target name (same as the second argument to \mac{songtarget}, and
% (2) the text that is to be linked.
% The default implementation uses |\hyperlink| if it exists; otherwise it
% just leaves the text unlinked.
%    \begin{macrocode}
\newcommand\songlink{%
  \ifnum\@ne=0\ifx\hyperlink\undefined\else%
              \ifx\hyperlink\relax\else1\fi\fi\relax%
    \expandafter\hyperlink%
  \else%
    \expandafter\@gobble%
  \fi%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\SB@indexlist}
% This macro records the comma-separated list of the identifiers of indexes
% associated with the current book section.
%    \begin{macrocode}
\newcommand\SB@indexlist{}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\SB@allindexes}
% This macro records a comma-separated list of all the index identifiers
% for the entire document.
%    \begin{macrocode}
\newcommand\SB@allindexes{}
\let\SB@allindexes\@empty
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\SB@out}
% The |\SB@out| control sequence is reserved for the write register allocated
% by the package code, if one is needed.
% (It is allocated at the first index declaration.)
%    \begin{macrocode}
\newcommand\SB@out{}
\let\SB@out\relax
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\SB@newindex}
% Initialize a new title, author, or scripture index.
%    \begin{macrocode}
\newcommand\SB@newindex[4]{%
  \expandafter\newcommand\csname SB@idxfilename@#3\endcsname{#4}%
  \expandafter\newcommand\csname SB@idxsel@#3\endcsname[3]{###1}%
  \expandafter\newcommand\csname SB@idxref@#3\endcsname{\thesongnum}%
  \xdef\SB@allindexes{%
    \ifx\SB@allindexes\@empty\else\SB@allindexes,\fi#3%
  }%
  \if@filesw%
    \ifx\SB@out\relax%
      \SB@newwrite\SB@out%
      \immediate\openout\SB@out=\jobname.sxc\relax%
    \fi%
    \immediate\write\SB@out{\noexpand\SB@iwrite{#3}{#2}}%
  \fi%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\newindex}\MainImpl{newindex}
% Define a new title index.
% The first argument is an identifier for the index (used in constructing
% index-specific control sequence names).
% The second argument is a filename root; auxiliary file \argp{2}|.sxd| is
% where the index data is stored at the end of processing.
%    \begin{macrocode}
\newcommand\newindex{\SB@newindex1{TITLE INDEX DATA FILE}}
\@onlypreamble\newindex
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\newscripindex}\MainImpl{newscripindex}
% Define a new scripture index. This is exactly like |\newindex| except that
% scripture references are added to the auxiliary file instead of titles.
%    \begin{macrocode}
\newcommand\newscripindex{\SB@newindex2{SCRIPTURE INDEX DATA FILE}}
\@onlypreamble\newscripindex
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\newauthorindex}\MainImpl{newauthorindex}
% Define a new author index. This is exactly like |\newindex| except that
% author info is added to the auxiliary file instead of titles.
%    \begin{macrocode}
\newcommand\newauthorindex{\SB@newindex3{AUTHOR INDEX DATA FILE}}
\@onlypreamble\newauthorindex
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\SB@cwrite}
% Write index data to a Song indeX Combined (|.sxc|) auxiliary file.
% The first argument is the identifier for the index to which the data
% ultimately belongs.
% The second argument is the data itself.
% The write is non-immediate so that it is only output if its enclosing
% song is ultimately shipped to the output file.
%    \begin{macrocode}
\newcommand\SB@cwrite[2]{%
  \ifx\SB@out\relax\else%
    \protected@write\SB@out\SB@keepactive{\protect\SB@iwrite{#1}{#2}}%
  \fi%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\SB@keepactive}
% By default, the |inputenc| package expands Unicode characters into macro
% names when writing them to files.
% This behavior must be inhibited when writing to the |.sxc| file, since
% |songidx| needs the original Unicode characters for sorting.
% To achieve this, we temporarily redefine most active characters so that
% they expand to an unexpandable string version of themselves.
%    \begin{macrocode}
\newcommand\SB@keepactive{}
{\catcode`\~\active
 \catcode`\.12
 \def\\#1#2{%
   \endgroup
   \SB@app\gdef\SB@keepactive{\def#1{#2}}%
 }
 \def\SB@temp#1#2{%
   \SB@cnt#1\relax
   \loop
     \begingroup
       \uccode`\~\SB@cnt
       \uccode`\.\SB@cnt
     \uppercase{\\~.}
   \ifnum\SB@cnt<#2\relax
     \advance\SB@cnt\@ne
   \repeat
 }
 \SB@temp{1}{8}
 \SB@temp{11}{11}
 \SB@temp{14}{91}
 \SB@temp{93}{255}
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\SB@iwrite}
% The line contributed by |\SB@cwrite| to the |.sxc| file is an |\SB@iwrite|
% macro that re-outputs the data to an appropriate |.sxd| file.
%    \begin{macrocode}
\newcommand\SB@iwrite[2]{%
  \def\SB@tempii{#1}%
  \ifx\SB@temp\SB@tempii%
    \SB@toks{#2}%
    \immediate\write\SB@out{\the\SB@toks}%
  \fi%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\SB@uncombine}
% At the end of the document, the |.sxc| file can be processed multiple
% times to produce all the |.sxd| files without resorting to multiple write
% registers.
% Each pass activates the subset of the |\SB@iwrite| commands that apply to
% one index.
%    \begin{macrocode}
\newcommand\SB@uncombine{%
  \ifx\SB@out\relax\else%
    \immediate\closeout\SB@out%
    \ifsongindexes%
      \@for\SB@temp:=\SB@allindexes\do{%
        \immediate\openout\SB@out=%
          \csname SB@idxfilename@\SB@temp\endcsname.sxd\relax%
        \begingroup\makeatletter\catcode`\%12\relax%
                   \input{\jobname.sxc}\endgroup%
        \immediate\closeout\SB@out%
      }%
    \fi%
  \fi%
}
\AtEndDocument{\SB@uncombine}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\SB@songwrites}
% The following box register stores index data until it can be migrated to
% the top of the song box currently under construction.
%    \begin{macrocode}
\SB@newbox\SB@songwrites
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\SB@addtoindex}
% \changes{v2.8}{2009/02/03}{Writes made non-immediate}
% Queue data \argp{2} associated with the current song for eventual writing
% to the index whose identifier is given by \argp{1}.
%    \begin{macrocode}
\newcommand\SB@addtoindex[2]{%
  \protected@edef\SB@tempii{#2}%
  \ifx\SB@tempii\@empty\else%
    \global\setbox\SB@songwrites\vbox{%
      \unvbox\SB@songwrites%
      \SB@cwrite{#1}{#2}%
      \SB@cwrite{#1}{\csname SB@idxref@#1\endcsname}%
      \SB@cwrite{#1}{song\theSB@songsnum-\thesongnum.%
                     \ifnum\c@section=\z@1\else2\fi}%
    }%
  \fi%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\SB@addtoindexes}
% Add \argp{1} to all title indexes, \argp{2} to all scripture indexes, and
% \argp{3} to all author indexes.
%    \begin{macrocode}
\newcommand\SB@addtoindexes[3]{%
  \@for\SB@temp:=\SB@indexlist\do{%
    \SB@addtoindex\SB@temp%
      {\csname SB@idxsel@\SB@temp\endcsname{#1}{#2}{#3}}%
  }%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\SB@addtotitles}
% Add \argp{1} to all title indexes, but leave other indexes unaffected.
%    \begin{macrocode}
\newcommand\SB@addtotitles[1]{%
  \@for\SB@temp:=\SB@indexlist\do{%
    \csname SB@idxsel@\SB@temp\endcsname%
      {\SB@addtoindex\SB@temp{#1}}{}{}%
  }%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\SB@chkidxlst}
% \changes{v2.3}{2007/09/23}{Added.}
% Check the current list of indexes and flag an error if any are undefined.
%    \begin{macrocode}
\newcommand\SB@chkidxlst{%
  \let\SB@temp\SB@indexlist%
  \let\SB@indexlist\@empty%
  \@for\SB@tempii:=\SB@temp\do{%
    \@ifundefined{SB@idxsel@\SB@tempii}{\SB@errnoidx\SB@tempii}{%
      \ifx\SB@indexlist\@empty%
        \SB@toks\expandafter{\SB@tempii}%
      \else%
        \SB@toks\expandafter\expandafter\expandafter{%
          \expandafter\SB@indexlist\expandafter,\SB@tempii}%
      \fi%
      \edef\SB@indexlist{\the\SB@toks}%
    }%
  }%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\indexentry}\MainImpl{indexentry}
% \changes{v2.3}{2007/09/23}{Optional argument added}
% \begin{macro}{\SB@idxentry}
% \begin{macro}{\SB@@idxentry}
% |\SB@addtoindexes| will be called automatically for each song in a section.
% However, |\indexentry| may be called by the user in order to add an
% alternative index entry for the given song.
% Usually this is done to index the song by its first line or some other
% memorable line in a chorus or verse somewhere.
%    \begin{macrocode}
\newcommand\indexentry{\@ifnextchar[{\SB@idxentry*}{\SB@@idxentry*}}
\newcommand\SB@idxentry{}
\def\SB@idxentry#1[#2]#3{{%
  \def\SB@indexlist{#2}%
  \SB@chkidxlst%
  \SB@addtoindexes{#1#3}{#3}{#3}%
}}
\newcommand\SB@@idxentry[2]{\SB@addtotitles{#1#2}}
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\indextitleentry}\MainImpl{indextitleentry}
% \changes{v2.3}{2007/09/23}{Optional argument added}
% |\indextitleentry| may be used to add an alternate title for the song to
% the index.
% (The only difference between the effects of |\indexentry| and
% |\indextitleentry| is that the latter are italicized in the rendered index
% and the former are not.)
%    \begin{macrocode}
\newcommand\indextitleentry{%
  \@ifnextchar[{\SB@idxentry{}}{\SB@@idxentry{}}%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\indexsongsas}\MainImpl{indexsongsas}
% \changes{v2.8}{2009/02/03}{Added.}
% The following macro allows the user to change how songs are indexed on the
% right side of index entries.
% By default, the song's number is listed.
%    \begin{macrocode}
\newcommand\indexsongsas[1]{%
  \@ifundefined{SB@idxref@#1}%
    {\SB@errnoidx{#1}\@gobble}%
    {\expandafter\renewcommand\csname SB@idxref@#1\endcsname}%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\SB@idxcmd}
% \begin{macro}{\SB@@idxcmd}
% \begin{macro}{\authsepword}\MainImpl{authsepword}
% \begin{macro}{\authbyword}\MainImpl{authbyword}
% \begin{macro}{\authignoreword}\MainImpl{authignoreword}
% \begin{macro}{\titleprefixword}\MainImpl{titleprefixword}
% \changes{v2.0}{2007/06/18}{Added.}
% The |songidx| index-generation script understands several different
% directives that each dictate various aspects of how index entries are
% parsed, sorted, and displayed.
% Such directives should typically appear at the start of the |.sxd|
% file just after the header line that identifies the type of index.
%    \begin{macrocode}
\newcommand\SB@idxcmd[3]{%
  \ifx\SB@allindexes\@empty%
    \SB@warnnoidx%
  \else\ifx\SB@out\relax\else%
    \@for\SB@temp:=\SB@allindexes\do{%
      \csname SB@idxsel@\SB@temp\endcsname%
        {\SB@@idxcmd{#1}}{\SB@@idxcmd{#2}}{\SB@@idxcmd{#3}}%
    }%
  \fi\fi%
}
\newcommand\SB@@idxcmd[1]{%
  \def\SB@tempii{#1}%
  \ifx\SB@tempii\@empty\else%
    \immediate\write\SB@out{%
      \noexpand\SB@iwrite{\SB@temp}{#1}%
    }%
  \fi%
}
\newcommand\authsepword[1]{}
\newcommand\authbyword[1]{}
\newcommand\authignoreword[1]{}
\newcommand\titleprefixword[1]{}
{\catcode`\%=12
 \gdef\authsepword#1{\SB@idxcmd{}{}{%sep #1}}
 \gdef\authbyword#1{\SB@idxcmd{}{}{%after #1}}
 \gdef\authignoreword#1{\SB@idxcmd{}{}{%ignore #1}}
 \gdef\titleprefixword#1{\SB@idxcmd{%prefix #1}{}{}}}
\@onlypreamble\authsepword
\@onlypreamble\authbyword
\@onlypreamble\authignoreword
\@onlypreamble\titleprefixword
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\SB@idxlineskip}
% Set the spacing between lines in an index.
%    \begin{macrocode}
\newcommand\SB@idxlineskip[1]{%
  \vskip#1\p@\@plus#1\p@\@minus#1\p@%
}
%    \end{macrocode}
% \end{macro}
%
% When rendering an index entry $X\ldots Y$ that is too long to fit on one
% physical line, we must break text $X$ and/or $Y$ up into multiple lines.
% Text $X$ should be typeset as a left-justified paragraph with a right
% margin of about 2em; however, its final line must not be so long that it
% cannot fit even the first item of list $Y$.
% Text $Y$ should be typeset as a right-justified paragraph whose first line
% begins on the last line of $X$.
% However, breaking $Y$ up the way paragraphs are normally broken up doesn't
% work well because that causes most of $Y$ to be crammed into the first few
% lines, leaving the last line very short.
% This looks strange and is hard to read.
% It looks much better to instead break $Y$ up in such a way that the portion
% of $Y$ that is placed on each line is of approximately equal width (subject
% to the constraint that we don't want to introduce any more lines than are
% necessary).
% This makes it visually clear that all of these lines are associated with $X$.
% The following code performs the width computations that do this
% horizontal-balancing of text.
%
% \begin{macro}{\SB@ellipspread}
% Typeset an index entry of the form $X\ldots Y$.
% In the common case, the entire entry fits on one line so we just typeset
% it in the usual way.
% If it doesn't fit on one line, we call |\SB@balancerows| for a more
% sophisticated treatment.
%    \begin{macrocode}
\newcommand\SB@ellipspread[2]{%
  \begingroup%
    \SB@dimen\z@%
    \def\SB@temp{#1}%
    \SB@toks{#2}%
    \setbox\SB@box\hbox{{%
      \SB@temp%
      \leaders\hbox to.5em{\hss.\hss}\hskip2em\@plus1fil%
      {\the\SB@toks}%
    }}%
    \ifdim\wd\SB@box>\hsize%
      \SB@balancerows%
    \else%
      \hbox to\hsize{\unhbox\SB@box}\par%
    \fi%
  \endgroup%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\SB@balancerows}
% Typeset an index entry of the form $X\ldots Y$ that doesn't fit on one line,
% where $X$ is the content of macro |\SB@temp| and
% $Y$ is the content of token register |\SB@toks|.
%
% First, we must pre-compute the width $w_1$ of the final line of $X$ when
% $X$ is typeset as a left-justified paragraph, storing it in |\SB@dimenii|.
% This is necessary because in order to force \TeX{} to typeset the first
% line of $Y$ at some chosen width $w_2$, we must insert leaders of width
% $c-w_1-w_2$ into the paragraph between $X$ and $Y$, where $c$ is the column
% width.
%
% Computing this width $w_1$ is a bit tricky.
% We must tell \TeX{} that the last line of $X$ must not be so long that it
% does not even have room for the first item of $Y$.
% Thus, we must strip off the first item of $Y$ and add it (or a non-breaking
% space of equivalent width) to the end of $X$ to typeset the paragraph.
% Then we use |\lastbox| to pull off the final line and check its width.
%    \begin{macrocode}
\newcommand\SB@balancerows{%
  \edef\SB@tempii{\the\SB@toks}%
  \setbox\SB@box\vbox{%
    \SB@toks\expandafter{\expandafter\\\the\SB@toks\\}%
    \SB@lop\SB@toks\SB@toks%
    \settowidth\SB@dimen{\the\SB@toks}%
    \advance\SB@dimen-.5em%
    \leftskip.5cm%
    {\hbadness\@M\hfuzz\maxdimen%
     \hskip-.5cm\relax\SB@temp\unskip\nobreak%
     \hskip\SB@dimen\nobreak%
     \rightskip2em\@plus1fil\par}%
    \setbox\SB@box\lastbox%
    \setbox\SB@box\hbox{%
      \unhbox\SB@box%
      \unskip\unskip\unpenalty%
      \unpenalty\unskip\unpenalty%
    }%
    \expandafter%
  }%
  \expandafter\SB@dimenii\the\wd\SB@box\relax%
%    \end{macrocode}
% Next, compute the smallest width $w_2$ such that the index entry text
% produced by |\SB@multiline| with |\SB@dimen|=$w_2$ has no more lines than
% with |\SB@dimen| set to the maximum available width for the right-hand side.
% This effectively horizontal-balances the right-hand side of the index entry
% text, making all lines of $Y$ roughly equal in width without introducing
% any extra lines.
%    \begin{macrocode}
  \SB@dimen\hsize%
  \advance\SB@dimen-.5cm%
  \setbox\SB@box\vbox{%
    \SB@multiline{\hbadness\@M\hfuzz\maxdimen}%
  }%
  \SB@dimeniii.5\SB@dimen%
  \SB@dimeniv\SB@dimeniii%
  \loop%
    \SB@dimeniv.5\SB@dimeniv%
    \setbox\SB@boxii\vbox{%
      \SB@dimen\SB@dimeniii%
      \SB@multiline{\hbadness\@M\hfuzz\maxdimen}%
    }%
    \ifnum\SB@cnt<\@M%
      \ifdim\ht\SB@boxii>\ht\SB@box%
        \advance\SB@dimeniii\SB@dimeniv%
      \else%
        \SB@dimen\SB@dimeniii%
        \advance\SB@dimeniii-\SB@dimeniv%
      \fi%
    \else%
      \advance\SB@dimeniii\SB@dimeniv%
    \fi%
  \ifdim\SB@dimeniv>2\p@\repeat%
  \setbox\SB@box\box\voidb@x%
  \setbox\SB@boxii\box\voidb@x%
%    \end{macrocode}
% Finally, typeset the results based on the quantities computed above.
%    \begin{macrocode}
  \SB@multiline\relax%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\SB@multiline}
% Create a paragraph containing text $X\ldots Y$
% where $X$ is the content of |\SB@temp|, $Y$ is the content of |\SB@tempii|,
% and $Y$ is restricted to width |\SB@dimen| (but may span multiple
% lines of that width).
% Dimen register |\SB@dimenii| must be set with the expected width of the
% final line of $X$.
% The first argument contains any parameter definitions that should be in
% effect when $X$ is processed.
%
% Note that the expansion of |\SB@tempii|, which may contain |\SB@idxitemsep|,
% depends on |\SB@dimen|.
% Therefore, the redefinition of |\SB@dimen| at the start of this macro must
% not be removed!
%    \begin{macrocode}
\newcommand\SB@multiline[1]{%
  \begingroup%
    \SB@dimen-\SB@dimen%
    \advance\SB@dimen\hsize%
    \SB@dimenii-\SB@dimenii%
    \advance\SB@dimenii\SB@dimen%
    {#1\hskip-.5cm\relax\SB@temp\unskip\nobreak%
     \SB@maxmin\SB@dimenii<{1.5em}%
     \leftskip.5cm\rightskip2em\@plus1fil%
     \interlinepenalty\@M%
     \leaders\hbox to.5em{\hss.\hss}\hskip\SB@dimenii\@plus1fill%
     \nobreak{\SB@tempii\kern-2em}%
     \par\global\SB@cnt\badness}%
  \endgroup%
}%
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\SB@idxitemsep}
% \changes{v1.11}{2005/04/21}{Changed macro name to avoid a name clash}
% If text $Y$ in index entry $X\ldots Y$ has multiple items in a list, those
% items should be separated by |\\| macros instead of by commas.
% The |\\| macro will be assigned the definition of |\SB@idxitemsep| during
% index generation, which produces the comma along with the complex spacing
% required if $Y$ ends up being broken into multiple lines.
% In particular, it forces each wrapped line of $Y$ to be right-justified
% with left margin at least |\SB@dimen|.
%    \begin{macrocode}
\newcommand\SB@idxitemsep{%
  ,\kern-2em\penalty-8\hskip2.33em\@minus.11em%
  \hskip-\SB@dimen\@plus-1fill%
  \vadjust{}\nobreak%
  \hskip\SB@dimen\@plus1fill\relax%
}
%    \end{macrocode}
% \end{macro}
%
% The following set of macros and environments are intended for use in the
% |.sbx| files that are automatically generated by an index-generating
% program; they shouldn't normally appear in the user's |.tex| or |.sbd|
% files directly.
% However, they are named as exported macros (no |@| symbols) since they are
% used outside the package code and are therefore not stricly internal.
%
% \begin{environment}{idxblock}
% Some indexes are divided into blocks (e.g., one for each letter of the
% alphabet or one for each book of the bible).
% Each such block should be enclosed between |\begin{idxblock}{X}| and
% |\end{idxblock}| lines, where X is the title of the block. The actual
% definition of the |idxblock| environment is set within the initialization
% code for each type of index (below).
%    \begin{macrocode}
\newenvironment{idxblock}[1]{}{}
%    \end{macrocode}
% \end{environment}
%
% \begin{macro}{\idxentry}
% \begin{macro}{\idxaltentry}
% Within each |idxblock| environment there should be a series of |\idxentry|
% and/or |\idxaltentry| macros, one for each line of the index. Again, the
% exact definitions of these macros will vary between index types.
%    \begin{macrocode}
\newcommand\idxentry[2]{}
\newcommand\idxaltentry[2]{}
%    \end{macrocode}
% \end{macro}
% \end{macro}
%
% \begin{environment}{SB@lgidx}
% \begin{environment}{SB@smidx}
% Some indexes actually have two definitions for each |idxblock|
% environment---one for use when there are few enough entries to permit a
% small style index, and another for use in a large style index. These macros
% will be redefined appropriately within the initialization code for each
% type of index.
%    \begin{macrocode}
\newenvironment{SB@lgidx}[1]{}{}
\newenvironment{SB@smidx}[1]{}{}
%    \end{macrocode}
% \end{environment}
% \end{environment}
%
% \begin{macro}{\SB@idxsetup}
% Set various parameters for a column of an index environment.
%    \begin{macrocode}
\newcommand\SB@idxsetup{%
  \hsize\SB@colwidth%
  \parskip\z@skip\parfillskip\z@skip\parindent\z@%
  \baselineskip\f@size\p@\@plus\p@\@minus\p@%
  \lineskiplimit\z@\lineskip\p@\@plus\p@\@minus\p@%
  \hyphenpenalty\@M\exhyphenpenalty\@M%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\SB@makeidxcolumn}
% Break off enough material from |\SB@box| to create one column of the
% index.
%    \begin{macrocode}
\newcommand\SB@makeidxcolumn{%
  \ifdim\ht\SB@box=\z@%
    \hskip\hsize\relax%
  \else%
    \splittopskip\z@skip\splitmaxdepth\maxdepth%
    \vsplit\SB@box to\SB@dimen%
    \global\setbox\SB@box\vbox{%
      \SB@idxsetup%
      \splitbotmark%
      \unvbox\SB@box%
    }%
  \fi%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\SB@oneidxpage}
% Construct one full page of the index.
% The definition of |\SB@oneidxpage| is generated dynamically based on the
% type of index and number of columns.
%    \begin{macrocode}
\newcommand\SB@oneidxpage{}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\SB@displayindex}
% \changes{v1.11}{2005/04/21}{Item separator macro now localized in scope to the index file}
% \changes{v2.0}{2007/06/18}{Removed hyperref dependency}
% \changes{v2.6}{2008/02/16}{Balance columns on final page}
% \changes{v2.8}{2009/03/06}{Changed argument order}
% Create an index with title \argp{2} and with \argp{1} columns (must be a
% literal constant). Input the index contents from external file \argp{3},
% which is expected to be a \TeX{} file.
%    \begin{macrocode}
\newcommand\SB@displayindex[3]{%
  \ifsongindexes\begingroup%
    \SB@colwidth\hsize%
    \advance\SB@colwidth-#1\columnsep%
    \advance\SB@colwidth\columnsep%
    \divide\SB@colwidth#1%
    \setbox\SB@envbox\vbox{%
      \let\SB@temp\songsection%
      \ifx\chapter\undefined\else%
        \ifx\chapter\relax\else%
          \let\SB@temp\songchapter%
        \fi%
      \fi%
      \SB@temp{#2}%
    }%
%    \end{macrocode}
% The |.sbx| index file might not exist (e.g., if this is the first pass
% through the \TeX{} compiler).
% If it exists, first try typesetting its content as a small index
% (one column, centered, with no divisions).
%    \begin{macrocode}
    \IfFileExists{\csname SB@idxfilename@#3\endcsname.sbx}{%
      \ifsepindexes%
        \global\setbox\SB@box\vbox{%
          \null%
          \vfil%
          \unvcopy\SB@envbox%
          \vskip.5in\@minus.3in\relax%
          \hbox to\hsize{%
            \hfil%
            \vbox{%
              \SB@idxsetup%
              \renewenvironment{idxblock}[1]%
                {\begin{SB@smidx}{####1}}{\end{SB@smidx}}%
              \let\\\SB@idxitemsep%
              \input{\csname SB@idxfilename@#3\endcsname.sbx}%
            }%
            \hfil%
          }%
          \vskip\z@\@plus2fil\relax%
        }%
%    \end{macrocode}
% Test whether the resulting small index fits within one page.
% If not, re-typeset it as a large index.
%    \begin{macrocode}
        {\vbadness\@M\vfuzz\maxdimen%
         \splitmaxdepth\maxdepth\splittopskip\z@skip%
         \global\setbox\SB@boxii\vsplit\SB@box to\textheight}%
        \ifvoid\SB@box%
          \box\SB@boxii%
        \else%
          \SB@lgindex{#1}{#3}%
        \fi%
      \else%
        \SB@lgindex{#1}{#3}%
      \fi%
    }%
%    \end{macrocode}
% If the |.sbx| file doesn't exist, then instead typeset a page with a
% message on it indicating that the document must be compiled a second
% time in order to generate the index.
%    \begin{macrocode}
    {%
      \ifsepindexes%
        \vbox to\textheight{%
          \vfil%
          \unvbox\SB@envbox%
          \vskip1em\relax%
          \hbox to\hsize{\hfil[Index not yet generated.]\hfil}%
          \vskip\z@\@plus2fil\relax%
        }%
      \else%
        \unvbox\SB@envbox%
        \hbox to\hsize{\hfil[Index not yet generated.]\hfil}%
      \fi%
    }%
    \ifsepindexes\clearpage\fi%
  \endgroup\fi%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\SB@lgindex}
% Typeset a large-style index.
% We begin by typesetting the entire index into a box.
%    \begin{macrocode}
\newcommand\SB@lgindex[2]{%
  \global\setbox\SB@box\vbox{%
    \renewenvironment{idxblock}[1]%
      {\begin{SB@lgidx}{##1}}{\end{SB@lgidx}}%
    \let\\\SB@idxitemsep%
    \SB@idxsetup%
    \input{\csname SB@idxfilename@#2\endcsname.sbx}%
    \unskip%
  }%
%    \end{macrocode}
% Next, we split the box into columns and pages until the last page is reached.
%    \begin{macrocode}
  \SB@toks{\SB@makeidxcolumn}%
  \SB@cnt#1\relax%
  \loop\ifnum\SB@cnt>\@ne%
    \SB@toks\expandafter{\the\SB@toks%
      \kern\columnsep\SB@makeidxcolumn}%
    \advance\SB@cnt\m@ne%
  \repeat%
  \edef\SB@oneidxpage{\the\SB@toks}%
  \unvbox\SB@envbox%
  \vskip.2in\relax%
  \nointerlineskip%
  \null%
  \nointerlineskip%
  \SB@cnt\vbadness\vbadness\@M%
  \SB@dimenii\vfuzz\vfuzz\maxdimen%
  \loop%
    \SB@dimen\textheight%
    \ifinner\else\kern\z@\advance\SB@dimen-\pagetotal\fi%
    \global\setbox\SB@boxii\copy\SB@box%
    \global\setbox\SB@boxiii\hbox{\SB@oneidxpage}%
    \ifdim\ht\SB@box>\z@%
      \box\SB@boxiii%
      \vfil\break%
  \repeat%
%    \end{macrocode}
% The final page of the index should have all equal-height columns instead
% of a few full columns followed by some short or empty columns at the end.
% To achieve this, we re-typeset the final page, trying different column
% heights until we find one that causes the material to span an equal
% percentage of all the columns on the page.
%    \begin{macrocode}
  \SB@dimenii\ht\SB@boxii%
  \divide\SB@dimenii#1\relax%
  \SB@maxmin\SB@dimen>\SB@dimenii%
  \loop%
    \global\setbox\SB@box\copy\SB@boxii%
    \global\setbox\SB@boxiii\hbox{\SB@oneidxpage}%
    \ifdim\ht\SB@box>\z@%
      \advance\SB@dimen\p@%
  \repeat%
  \box\SB@boxiii%
  \global\setbox\SB@boxii\box\voidb@x%
  \vbadness\SB@cnt\vfuzz\SB@dimenii%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\showindex}\MainImpl{showindex}
% \changes{v2.8}{2009/03/06}{Added optional argument}
% Create an index with title \argp{2} based on the data associated with index
% identifier \argp{3} (which was passed to |\newindex|).
% Optional argument \argp{1} specifies the number of columns.
% This macro calls the appropriate index-creation macro depending on the type
% of index that \argp{3} was declared to be.
%    \begin{macrocode}
\newcommand\showindex[3][0]{%
  \@ifundefined{SB@idxsel@#3}{\SB@errnoidx{#3}}{%
    \expandafter\let\expandafter\SB@temp\csname SB@idxsel@#3\endcsname%
    \SB@cnt#1\relax%
    \ifnum\SB@cnt<\@ne\SB@cnt\SB@temp232\relax\fi%
    \expandafter\SB@temp%
    \expandafter\SB@maketitleindex%
    \expandafter\SB@makescripindex%
    \expandafter\SB@makeauthorindex%
    \expandafter{\the\SB@cnt}%
    {#2}{#3}%
  }%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\SB@maketitleindex}
% \changes{v2.8}{2009/03/06}{Added columns argument}
% Create a song title index.
% \argp{1} is a column count,
% \argp{2} is the title, and
% \argp{3} is the index identifier (which was passed to |\newindex|).
%    \begin{macrocode}
\newcommand\SB@maketitleindex{%
  \ifnum\idxheadwidth>\z@%
    \renewenvironment{SB@lgidx}[1]{
      \hbox{\SB@colorbox\idxbgcolor{\vbox{%
        \hbox to\idxheadwidth{{\idxheadfont\relax##1}\hfil}%
      }}}%
      \nobreak\vskip3\p@\@plus2\p@\@minus2\p@\nointerlineskip%
    }{\penalty-50\vskip5\p@\@plus5\p@\@minus4\p@}%
  \else%
    \renewenvironment{SB@lgidx}[1]{}{}%
  \fi%
  \renewenvironment{SB@smidx}[1]{}{}%
  \renewcommand\idxentry[2]{%
    \SB@ellipspread{\idxtitlefont\relax\ignorespaces##1\unskip}%
                   {{\idxrefsfont\relax##2}}%
  }%
  \renewcommand\idxaltentry[2]{%
    \SB@ellipspread{\idxlyricfont\relax\ignorespaces##1\unskip}%
                   {{\idxrefsfont\relax##2}}%
  }%
  \SB@displayindex%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\SB@idxcolhead}
% In a scripture index, this macro remembers the current book of the bible
% we're in so that new columns can be headed with ``Bookname (continued)''.
%    \begin{macrocode}
\newcommand\SB@idxcolhead{}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\SB@idxheadsep}
% Add vertical space following the header line that begins (or continues) a
% section of a scripture index.
%    \begin{macrocode}
\newcommand\SB@idxheadsep{{%
  \SB@dimen4\p@%
  \advance\SB@dimen-\prevdepth%
  \SB@maxmin\SB@dimen<\z@%
  \SB@dimenii\SB@dimen%
  \SB@maxmin\SB@dimenii>\p@%
  \vskip\SB@dimen\@plus\p@\@minus\SB@dimenii%
}}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\SB@idxcont}
% Typeset the ``Bookname (continued)'' line that continues a scripture
% index section when it spans a column break.
%    \begin{macrocode}
\newcommand\SB@idxcont[1]{%
  \hbox to\hsize{{\idxcont{#1}}\hfil}%
  \nobreak%
  \SB@idxheadsep\nointerlineskip%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\SB@makescripindex}
% \changes{v2.4}{2007/10/08}{Scripture index spacing made more uniform}
% \changes{v2.8}{2009/03/06}{Added columns argument}
% Create a scripture index.
% \argp{1} is a column count,
% \argp{1} is the title, and
% \argp{2} is the index identifier (which was passed to |\newscripindex|).
%    \begin{macrocode}
\newcommand\SB@makescripindex{%
  \renewenvironment{SB@lgidx}[1]{%
    \gdef\SB@idxcolhead{##1}%
    \hbox to\hsize{{\idxbook{##1}}\hfil}%
    \nobreak%
    \SB@idxheadsep\nointerlineskip%
  }{%
    \mark{\noexpand\relax}%
    \penalty-20\vskip3\p@\@plus3\p@\relax%
  }%
  \renewenvironment{SB@smidx}[1]
    {\begin{SB@lgidx}{##1}}{\end{SB@lgidx}}%
  \renewcommand\idxentry[2]{%
    \SB@ellipspread{\hskip.25cm\idxscripfont\relax##1}%
                   {{\idxrefsfont\relax##2}}%
    \SB@toks\expandafter{\SB@idxcolhead}%
    \mark{\noexpand\SB@idxcont{\the\SB@toks}}%
  }%
  \renewcommand\idxaltentry[2]{\SB@erridx{a scripture}}%
  \SB@displayindex%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\SB@makeauthorindex}
% \changes{v2.8}{2009/03/06}{Added columns argument}
% Create an author index.
% \argp{1} is a column count,
% \argp{2} is the title, and
% \argp{2} is the index identifier (which was passed to |\newauthindex|).
%    \begin{macrocode}
\newcommand\SB@makeauthorindex{%
  \renewenvironment{SB@lgidx}[1]{}{}%
  \renewenvironment{SB@smidx}[1]{}{}%
  \renewcommand\idxentry[2]{%
    \SB@ellipspread{{\idxauthfont\relax\sfcode`.\@m##1}}%
                   {{\idxrefsfont##2}}%
  }%
  \renewcommand\idxaltentry[2]{\SB@erridx{an author}}%
  \SB@displayindex%
}
%    \end{macrocode}
% \end{macro}
%
% \subsection{Error Messages}
%
% We break error messages out into separate macros here in order to reduce the
% length (in tokens) of the more frequently used macros that do actual work.
% This can result in a small speed improvement on slower machines.
%
% \begin{macro}{\SB@Error}
% \begin{macro}{\SB@Warn}
% All errors and warnings will be reported as coming from package ``songs''.
%    \begin{macrocode}
\newcommand\SB@Error{\PackageError{songs}}
\newcommand\SB@Warn{\PackageWarning{songs}}
%    \end{macrocode}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\SB@errspos}
%    \begin{macrocode}
\newcommand\SB@errspos{%
  \SB@Error{Illegal \protect\songpos\space argument}{The argume%
  nt to \protect\songpos\space must be a number from 0 to 3.}%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\SB@errnse}
%    \begin{macrocode}
\newcommand\SB@errnse{%
  \SB@Error{Nested songs environments are not supported}{End th%
  e previous songs environment before beginning the next one.}%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\SB@errpl}
%    \begin{macrocode}
\newcommand\SB@errpl{%
  \SB@Error{\protect\includeonlysongs\space not permitted with%
  in a songs environment}{\protect\includeonlysongs\space can o%
  nly be used in the document preamble or between songs environ%
  ments in the document body.}%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\SB@errrtopt}
%    \begin{macrocode}
\newcommand\SB@errrtopt{%
  \SB@Error{Cannot display chords in a rawtext dump}{You have u%
  sed the rawtext option in the \protect\usepackage\space lin%
  e and have either used the chorded option as well or have use%
  d the \protect\chordson\space macro subsequently.}%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\SB@warnrc}
%    \begin{macrocode}
\newcommand\SB@warnrc{%
  \SB@Warn{The \protect\repchoruses\space feature will not wor%
  k when the number of columns is set to zero}%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\SB@warnnoidx}
%    \begin{macrocode}
\newcommand\SB@warnnoidx{%
  \SB@Warn{Index command has no effect since no indexes are ye%
  t declared}%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\SB@errboo}
%    \begin{macrocode}
\newcommand\SB@errboo{%
  \SB@Error{Encountered \protect\beginsong\space without seein%
  g an \protect\endsong\space for the previous song}%
  {Song \thesongnum\space might be missing a%
  n \protect\endsong\space line.}%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\SB@errbor}
%    \begin{macrocode}
\newcommand\SB@errbor{%
  \SB@Error{Encountered \protect\beginsong\space without seein%
  g an \protect\endscripture\space for the preceding scriptur%
  e quotation}{A scripture quotation appearing after son%
  g \thesongnum\space might be missing a%
  n \protect\endscripture\space line.}%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\SB@erreov}
%    \begin{macrocode}
\newcommand\SB@erreov{%
  \SB@Error{Encountered \protect\endsong\space without seein%
  g an \protect\endverse\space for the preceding verse}{Son%
  g \thesongnum\space has a \protect\beginverse\space%
  line with no matching \protect\endverse\space line.}%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\SB@erreoc}
%    \begin{macrocode}
\newcommand\SB@erreoc{%
  \SB@Error{Encountered \protect\endsong\space without seein%
  g an \protect\endchorus\space for the preceding chorus}{Son%
  g \thesongnum\space has a \protect\beginchorus\space%
  line with no matching \protect\endchorus\space line.}%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\SB@erreor}
%    \begin{macrocode}
\newcommand\SB@erreor{%
  \SB@Error{Encountered \protect\endsong\space without seein%
  g an \protect\endscripture for the preceding scripture quot%
  e}{A scripture quote appearing before song \thesongnum\space%
  ended with \protect\endsong\space instead of wit%
  h \protect\endscripture.}%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\SB@erreot}
%    \begin{macrocode}
\newcommand\SB@erreot{%
  \SB@Error{Encountered \protect\endsong\space with no matchin%
  g \protect\beginsong}{Before song \thesongnum\space there wa%
  s an \protect\endsong\space with no matchin%
  g \protect\beginsong.}%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\SB@errbvv}
%    \begin{macrocode}
\newcommand\SB@errbvv{%
  \SB@Error{Encountered \protect\beginverse\space without seein%
  g an \protect\endverse\space for the preceding verse}{Son%
  g \thesongnum\space might have a verse that has n%
  o \protect\endendverse\space line.}%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\SB@errbvc}
%    \begin{macrocode}
\newcommand\SB@errbvc{%
  \SB@Error{Encountered \protect\beginverse\space without seein%
  g an \protect\endchorus\space for the preceding chorus}{Son%
  g \thesongnum\space might have a chorus that has n%
  o \protect\endchorus\space line.}%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\SB@errbvt}
%    \begin{macrocode}
\newcommand\SB@errbvt{%
  \SB@Error{Encountered \protect\beginverse\space without firs%
  t seeing a \protect\beginsong\space line}{Before son%
  g \thesongnum, there is a \protect\beginverse\space line no%
  t contained in any song.}%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\SB@errevc}
%    \begin{macrocode}
\newcommand\SB@errevc{%
  \SB@Error{Encountered \protect\endverse\space while process%
  ing a chorus}{Song \thesongnum\space might hav%
  e a \protect\beginchorus\space concluded by a%
  n \protect\endverse\space instead of an \protect\endchorus.}%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\SB@errevo}
%    \begin{macrocode}
\newcommand\SB@errevo{%
  \SB@Error{Encountered \protect\endverse\space without firs%
  t seeing a \protect\beginverse}{Song \thesongnum\space m%
  ight have an \protect\endverse\space with no matchin%
  g \protect\beginverse.}%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\SB@errevt}
%    \begin{macrocode}
\newcommand\SB@errevt{%
  \SB@Error{Encountered an \protect\endverse\space outside o%
  f any song}{Before song \thesongnum, there is a%
  n \protect\endverse\space line not preceded b%
  y a \protect\beginsong\space line.}%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\SB@erretex}
%    \begin{macrocode}
\newcommand\SB@erretex{%
  \SB@Error{The \protect\repchoruses\space feature requires e-%
  TeX compatibility}{Your version of LaTeX2e does not appear t%
  o be e-TeX compatible. Find a distribution that includes e-T%
  eX support in order to use this feature.}%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\SB@errbcv}
%    \begin{macrocode}
\newcommand\SB@errbcv{%
  \SB@Error{Encountered \protect\beginchorus\space without see%
  ing an \protect\endverse\space for the preceding verse}{Son%
  g \thesongnum\space might hav%
  e a \protect\beginverse\space with no match%
  ing \protect\endverse.}%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\SB@errbcc}
%    \begin{macrocode}
\newcommand\SB@errbcc{%
  \SB@Error{Encountered \protect\beginchorus\space without see%
  ing an \protect\endchorus\space for the preceding chorus}%
  {Song \thesongnum\space might have a \protect\beginchorus%
  \space with no matching \protect\endchorus.}%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\SB@errbct}
%    \begin{macrocode}
\newcommand\SB@errbct{%
  \SB@Error{Encountered \protect\beginchorus\space without see%
  ing a \protect\beginsong\space line first}{After son%
  g \thesongnum\space there is a \protect\beginchorus\space%
  line outside of any song.}%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\SB@errecv}
%    \begin{macrocode}
\newcommand\SB@errecv{%
  \SB@Error{Encountered an \protect\endchorus\space while proc%
  essing a verse}{Song \thesongnum\space might hav%
  e a \protect\beginverse\space concluded by \protect\endchorus%
  \space instead of \protect\endverse.}%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\SB@erreco}
%    \begin{macrocode}
\newcommand\SB@erreco{%
  \SB@Error{Encountered \protect\endchorus\space without firs%
  t seeing a \protect\beginchorus}{Song \thesongnum\space m%
  ight have an \protect\endchorus\space with no match%
  ing \protect\beginchorus.}%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\SB@errect}
%    \begin{macrocode}
\newcommand\SB@errect{%
  \SB@Error{Encountered an \protect\endchorus\space outside o%
  f any song}{Before song \thesongnum, there is a%
  n \protect\endchorus\space line not preceded b%
  y a \protect\beginsong\space line.}%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\SB@errbro}
%    \begin{macrocode}
\newcommand\SB@errbro{%
  \SB@Error{Missing \protect\endsong}%
  {Nested song and intersong environments are not supported%
  . Song \thesongnum\space might be missing a%
  n \protect\endsong\space line.}%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\SB@errbrr}
%    \begin{macrocode}
\newcommand\SB@errbrr{%
  \SB@Error{Nested intersong environments are not supported}%
  {A scripture quote or other intersong environment before s%
  ong \thesongnum\space is missing its ending line.}%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\SB@errero}
%    \begin{macrocode}
\newcommand\SB@errero{%
  \SB@Error{Encountered an \protect\endscripture\space whil%
  e processing a song}{Song \thesongnum\space ends wit%
  h \protect\endscripture\space when it should end wit%
  h \protect\endsong.}%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\SB@errert}
%    \begin{macrocode}
\newcommand\SB@errert{%
  \SB@Error{Encountered an \protect\endscripture\space with%
  out first seeing a \protect\beginscripture}{Before son%
  g \thesongnum, there is an \protect\endscripture\space w%
  ith no matching \protect\beginscripture.}%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\SB@errscrip}
%    \begin{macrocode}
\newcommand\SB@errscrip[1]{%
  \SB@Error{Encountered a \protect#1\space outside a scriptu%
  re quote}{\protect#1\space can only appear betwee%
  n \protect\beginscripture\space an%
  d \protect\endscripture\space lines.}%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\SB@errchord}
%    \begin{macrocode}
\newcommand\SB@errchord{%
  \SB@Error{Song \thesongnum\space seems to have chord%
  s that appear outside of any verse or chorus}{All chords a%
  nd lyrics should appear between \protect\beginverse\space%
  and \protect\endverse, or between \protect\beginchorus\space%
  and \protect\endchorus.}%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\SB@errreplay}
%    \begin{macrocode}
\newcommand\SB@errreplay{%
  \SB@Error{Replayed chord has no matching chord}{Son%
  g \thesongnum\space uses \protect^ more times than the%
  re are chords in the previously memorized verse.}%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\SB@errreg}
%    \begin{macrocode}
\newcommand\SB@errreg[1]{%
  \SB@Error{Unknown chord-replay register name: #1}{Chord-re%
  play registers must be declared with \protect\newchords.}%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\SB@errdup}
%    \begin{macrocode}
\newcommand\SB@errdup[1]{%
  \SB@Error{Duplicate definition of chord-replay register%
  : #1}{\protect\newchords\space was used to declare the sa%
  me chord-replay register twice.}%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\SB@errmbar}
%    \begin{macrocode}
\newcommand\SB@errmbar{%
  \SB@Error{Song \thesongnum\space seems to have measur%
  e bars that appear outside of any verse or chorus}{All mea%
  sure bars (produced with \protect\mbar\space or |) must ap%
  pear between \protect\beginverse\space an%
  d \protect\endverse, or between \protect\beginchorus\space%
  and \protect\endchorus.}%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\SB@errebar}
%    \begin{macrocode}
\newcommand\SB@errebar[2]{%
  \SB@Error{Ignoring unbalanced \expandafter\@gobble\string#2 i%
  n \protect\gtab}{Found no \expandafter\@gobble\string#1 to ma%
  tch the \expandafter\@gobble\string#2.}%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\SB@errnoidx}
%    \begin{macrocode}
\newcommand\SB@errnoidx[1]{%
  \SB@Error{Unknown index identifier: #1}{This index identifie%
  r was never declared using \protect\newindex.}%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\SB@erridx}
%    \begin{macrocode}
\newcommand\SB@erridx[1]{%
  \SB@Error{\protect\idxaltentry\space not allowed in #1 index}%
  {This error should not occur. The index generation routines ha%
  ve malfunctioned. Try deleting all temporary files and then re%
  compiling.}%
}
%    \end{macrocode}
% \end{macro}
%
% \subsection{Option Processing}\label{sec:optproc}
%
% \begin{macro}{\ifchorded}
% \begin{macro}{\iflyric}
% \begin{macro}{\ifslides}
% \begin{macro}{\ifmeasures}
% \begin{macro}{\ifpartiallist}
% \begin{macro}{\ifrepchorus}
% \begin{macro}{\iftranscapos}
% \begin{macro}{\ifnolyrics}
% \begin{macro}{\ifrawtext}
% \begin{macro}{\ifsongindexes}
% \begin{macro}{\ifsepindexes}
% \begin{macro}{\ifpagepreludes}
% \begin{macro}{\ifSB@colorboxes}
% \begin{macro}{\ifSB@omitscrip}
% Reserve conditionals for all of the various option settings.
% We wait to define these since if any are used earlier than this, it is
% an error in the package code, and we'd rather get an error than continue.
%    \begin{macrocode}
\newif\ifchorded
\newif\iflyric\lyrictrue
\newif\ifslides
\newif\ifmeasures
\newif\ifpartiallist
\newif\ifrepchorus
\newif\iftranscapos
\newif\ifnolyrics
\newif\ifrawtext
\newif\ifsongindexes\songindexestrue
\newif\ifsepindexes\sepindexestrue
\newif\ifpagepreludes
\newif\ifSB@colorboxes
\IfFileExists{color.sty}\SB@colorboxestrue\SB@colorboxesfalse
\newif\ifSB@omitscrip
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\nolyrics}
% \begin{macro}{\pagepreludes}
% The |\nolyrics| and |\pagepreludes| macros are just shorthand for
% |\nolyricstrue| and |\pagepreludestrue|, respectively.
%    \begin{macrocode}
\newcommand\nolyrics{}
\let\nolyrics\nolyricstrue
\newcommand\pagepreludes{\pagepreludestrue\songpos0}
%    \end{macrocode}
% \end{macro}
% \end{macro}
%
% Finally we're ready to process all of the package options.
% This is delayed until near the end because the option processing code
% needs to execute various macros found in the previous sections.
%    \begin{macrocode}
\SB@chordson
\ProcessOptions\relax
%    \end{macrocode}
%
% \begin{macro}{\SB@colorbox}
% Include the colors package and define colors, if requested.
%    \begin{macrocode}
\ifSB@colorboxes
  \RequirePackage{color}
  \definecolor{SongbookShade}{gray}{.80}
  \newcommand\SB@colorbox[2]{%
    \ifx\@empty#1%
      \vbox{%
        \kern3\p@%
        \hbox{\kern3\p@{#2}\kern3\p@}%
        \kern3\p@%
      }%
    \else%
      \colorbox{#1}{#2}%
    \fi%
  }
\else
  \newcommand\SB@colorbox[2]{\vbox{%
    \kern3\p@%
    \hbox{\kern3\p@{#2}\kern3\p@}%
    \kern3\p@%
  }}
\fi
%    \end{macrocode}
% \end{macro}
%
% \subsection{Rawtext Mode}
%
% If generating raw text, most of what has been defined previously is ignored
% in favor of some very specialized macros that write all the song lyrics to
% a text file.
%    \begin{macrocode}
\ifrawtext
  \SB@newwrite\SB@txtout
  \immediate\openout\SB@txtout=\jobname.txt
  \newif\ifSB@doEOL
  {\catcode`\^^M12 %
   \catcode`\^^J12 %
   \gdef\SB@printEOL{\ifSB@doEOL^^M^^J\fi}}
  {\catcode`#12\gdef\SB@hash{#}}
  {\catcode`&12\gdef\SB@amp{&}}
  \renewcommand\SB@@@beginsong{%
    \begingroup%
      \def\'{}\def\`{}\def\v{}\def\u{}\def\={}\def\^{}%
      \def\.{}\def\H{}\def\~{}\def\"{}\def\t{}%
      \def\copyright{(c)}%
      \let~\space%
      \let\par\SB@printEOL%
      \let\#\SB@hash%
      \let\&\SB@amp%
      \catcode`|9 %
      \catcode`*9 %
      \catcode`^9 %
      \def\[##1]{}%
      \resettitles%
      \immediate\write\SB@txtout{\thesongnum. \songtitle}%
      \nexttitle%
      \foreachtitle{\immediate\write\SB@txtout{(\songtitle)}}%
      \ifx\songauthors\@empty\else%
         \immediate\write\SB@txtout{\songauthors}%
      \fi%
      \ifx\SB@rawrefs\@empty\else%
         \immediate\write\SB@txtout{\SB@rawrefs}%
      \fi%
      \immediate\write\SB@txtout{}%
      \SB@doEOLfalse%
      \obeylines%
  }
  \renewcommand\SB@endsong{%
      \SB@doEOLtrue%
      \immediate\write\SB@txtout{\songcopyright\space%
        \songlicense\SB@printEOL}%
    \endgroup%
    \SB@insongfalse%
    \stepcounter{songnum}%
  }
  \def\SB@parsesrefs#1{\def\songrefs{#1}}
  \long\def\beginverse#1#2\endverse{%
    \SB@doEOLtrue\begingroup%
      \def\textnote##1{##1}%
      \def\SB@temp{#1}%
      \def\SB@star{*}%
      \ifx\SB@temp\SB@star%
        \immediate\write\SB@txtout{\@gobble#2}%
      \else%
        \immediate\write\SB@txtout{#2}%
      \fi%
    \endgroup\SB@doEOLfalse}
  \long\def\beginchorus#1\endchorus{%
    \SB@doEOLtrue\begingroup%
      \def\textnote##1{##1}%
      \immediate\write\SB@txtout{Chorus:#1}%
    \endgroup\SB@doEOLfalse}
  \long\def\beginscripture#1\endscripture{}
  \def\musicnote#1{}
  \def\textnote#1{%
    \SB@doEOLtrue%
    \immediate\write\SB@txtout{#1\SB@printEOL}%
    \SB@doEOLfalse}
  \def\brk{}
  \def\rep#1{(x#1)}
  \def\echo#1{(#1)}
  \def\mbar#1#2{}
  \def\lrep{}
  \def\rrep{}
  \def\nolyrics{}
  \renewcommand\memorize[1][]{}
  \renewcommand\replay[1][]{}
\fi
%    \end{macrocode}
%
% \Finale
\endinput