summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/source/latex/cleveref/cleveref.dtx
blob: 05370a49bb3614d23987c700e79d9e8217ae87d2 (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
12456
12457
12458
12459
12460
12461
12462
12463
12464
12465
12466
12467
12468
12469
12470
12471
12472
12473
12474
12475
12476
12477
12478
12479
12480
12481
12482
12483
12484
12485
12486
12487
12488
12489
12490
12491
12492
12493
12494
12495
12496
12497
12498
12499
12500
12501
12502
12503
12504
12505
12506
12507
12508
12509
12510
12511
12512
12513
12514
12515
12516
12517
12518
12519
12520
12521
12522
12523
12524
12525
12526
12527
12528
12529
12530
12531
12532
12533
12534
12535
12536
12537
12538
12539
12540
12541
12542
12543
12544
12545
12546
12547
12548
12549
12550
12551
12552
12553
12554
12555
12556
12557
12558
12559
12560
12561
12562
12563
12564
12565
12566
12567
12568
12569
12570
12571
12572
12573
12574
12575
12576
12577
12578
12579
12580
12581
12582
12583
12584
12585
12586
12587
12588
12589
12590
12591
12592
12593
12594
12595
12596
12597
12598
12599
12600
12601
12602
12603
12604
12605
12606
12607
12608
12609
12610
12611
12612
12613
12614
12615
12616
12617
12618
12619
12620
12621
12622
12623
12624
12625
12626
12627
12628
12629
12630
12631
12632
12633
12634
12635
12636
12637
12638
12639
12640
12641
12642
12643
12644
12645
12646
12647
12648
12649
12650
12651
12652
12653
12654
12655
12656
12657
12658
12659
12660
12661
12662
12663
12664
12665
12666
12667
12668
12669
12670
12671
12672
12673
12674
12675
12676
12677
12678
12679
12680
12681
12682
12683
12684
12685
12686
12687
12688
12689
12690
12691
12692
12693
12694
12695
12696
12697
12698
12699
12700
12701
12702
12703
12704
12705
12706
12707
12708
12709
12710
12711
12712
12713
12714
12715
12716
12717
12718
12719
12720
12721
12722
12723
12724
12725
12726
12727
12728
12729
12730
12731
12732
12733
12734
12735
12736
12737
12738
12739
12740
12741
12742
12743
12744
12745
12746
12747
12748
12749
12750
12751
12752
12753
12754
12755
12756
12757
12758
12759
12760
12761
12762
12763
12764
12765
12766
12767
12768
12769
12770
12771
12772
12773
12774
12775
12776
12777
12778
12779
12780
12781
12782
12783
12784
12785
12786
12787
12788
12789
12790
12791
12792
12793
12794
12795
12796
12797
12798
12799
12800
12801
12802
12803
12804
12805
12806
12807
12808
12809
12810
12811
12812
12813
12814
12815
12816
12817
12818
12819
12820
12821
12822
12823
12824
12825
12826
12827
12828
12829
12830
12831
12832
12833
12834
12835
12836
12837
12838
12839
12840
12841
12842
12843
12844
12845
12846
12847
12848
12849
12850
12851
12852
12853
12854
12855
12856
12857
12858
12859
12860
12861
12862
12863
12864
12865
12866
12867
12868
12869
12870
12871
12872
12873
12874
12875
12876
12877
12878
12879
12880
12881
12882
12883
12884
12885
12886
12887
12888
12889
12890
12891
12892
12893
12894
12895
12896
12897
12898
12899
12900
12901
12902
12903
12904
12905
12906
12907
12908
12909
12910
12911
12912
12913
12914
12915
12916
12917
12918
12919
12920
12921
12922
12923
12924
12925
12926
12927
12928
12929
12930
12931
12932
12933
12934
12935
12936
12937
12938
12939
12940
12941
12942
12943
12944
12945
12946
12947
12948
12949
12950
12951
12952
12953
12954
12955
12956
12957
12958
12959
12960
12961
12962
12963
12964
12965
12966
12967
12968
12969
12970
12971
12972
12973
12974
12975
12976
12977
12978
12979
12980
12981
12982
12983
12984
12985
12986
12987
12988
12989
12990
12991
12992
12993
12994
12995
12996
12997
12998
12999
13000
13001
13002
13003
13004
13005
13006
13007
13008
13009
13010
13011
13012
13013
13014
13015
13016
13017
13018
13019
13020
13021
13022
13023
13024
13025
13026
13027
13028
13029
13030
13031
13032
13033
13034
13035
13036
13037
13038
13039
13040
13041
13042
13043
13044
13045
13046
13047
13048
13049
13050
13051
13052
13053
13054
13055
13056
13057
13058
13059
13060
13061
13062
13063
13064
13065
13066
13067
13068
13069
13070
13071
13072
13073
13074
13075
13076
13077
13078
13079
13080
13081
13082
13083
13084
13085
13086
13087
13088
13089
13090
13091
13092
13093
13094
13095
13096
13097
13098
13099
13100
13101
13102
13103
13104
13105
13106
13107
13108
13109
13110
13111
13112
13113
13114
13115
13116
13117
13118
13119
13120
13121
13122
13123
13124
13125
13126
13127
13128
13129
13130
13131
13132
13133
13134
13135
13136
13137
13138
13139
13140
13141
13142
13143
13144
13145
13146
13147
13148
13149
13150
13151
13152
13153
13154
13155
13156
13157
13158
13159
13160
13161
13162
13163
13164
13165
13166
13167
13168
13169
13170
13171
13172
13173
13174
13175
13176
13177
13178
13179
13180
13181
13182
13183
13184
13185
13186
13187
13188
13189
13190
13191
13192
13193
13194
13195
13196
13197
13198
13199
13200
13201
13202
13203
13204
13205
13206
13207
13208
13209
13210
13211
13212
13213
13214
13215
13216
13217
13218
13219
13220
13221
13222
13223
13224
13225
13226
13227
13228
13229
13230
13231
13232
13233
13234
13235
13236
13237
13238
13239
13240
13241
13242
13243
13244
13245
13246
13247
13248
13249
13250
13251
13252
13253
13254
13255
13256
13257
13258
13259
13260
13261
13262
13263
13264
13265
13266
13267
13268
13269
13270
13271
13272
13273
13274
13275
13276
13277
13278
13279
13280
13281
13282
13283
13284
13285
13286
13287
13288
13289
13290
13291
13292
13293
13294
13295
13296
13297
13298
13299
13300
13301
13302
13303
13304
13305
13306
13307
13308
13309
13310
13311
13312
13313
13314
13315
13316
13317
13318
13319
13320
13321
13322
13323
13324
13325
13326
13327
13328
13329
13330
13331
13332
13333
13334
13335
13336
13337
13338
13339
13340
13341
13342
13343
13344
13345
13346
13347
13348
13349
13350
13351
13352
13353
13354
13355
13356
13357
13358
13359
13360
13361
13362
13363
13364
13365
13366
13367
13368
13369
13370
13371
13372
13373
13374
13375
13376
13377
13378
13379
13380
13381
13382
13383
13384
13385
13386
13387
13388
13389
13390
13391
13392
13393
13394
13395
13396
13397
13398
13399
13400
13401
13402
13403
13404
13405
13406
\def\packagedate{2018/03/27}
\def\packageversion{0.21.4}
% \iffalse meta-comment
%
% Package 'cleveref' to use with LaTeX2e
% Copyright 2006--2018 Toby Cubitt
%
% Written and maintained by Toby Cubitt
%
%% This file may be distributed and/or modified under the
%% conditions of the LaTeX Project Public License, either version 1.2
%% of this license or (at your option) any later version.
%% The latest version of this license is in:
%%
%%    http://www.latex-project.org/lppl.txt
%%
%% and version 1.2 or later is part of all distributions of LaTeX
%% version 1999/12/01 or later.
%
% Please send bug reports and suggestions to toby-cleveref@dr-qubit.org
% \fi
%
% \iffalse
%<package>\NeedsTeXFormat{LaTeX2e}[1999/12/01]
%<package>\ProvidesPackage{cleveref}
%<package> [\packagedate\space v\packageversion\space Intelligent cross-referencing]
%
%<*driver>
\documentclass{ltxdoc}
%\documentclass[draft]{ltxdoc}
\usepackage{url}
\usepackage{pifont} % FIXME: find nicer line-continuation symbol than \ding{229}
\usepackage[colorlinks=true,linktocpage=true]{hyperref}
\usepackage[capitalise]{cleveref}
\DisableCrossrefs
\CodelineIndex
\RecordChanges
\setcounter{IndexColumns}{2}
%%\newcommand\package[1]{\texttt{#1.sty}}
\newcommand\package{\texttt}
\newcommand\file{\texttt}
\newcommand\option{\texttt}
\begin{document}
  \DocInput{cleveref.dtx}
\end{document}
%</driver>
% \fi
%
% \CheckSum{19764}
%% \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{v0.01}{2006/06/29}{Initial version}
% \changes{v0.02}{2007/04/18}{Complete rewrite}
% \changes{v0.03}{2007/04/26}{Added reference ranges}
% \changes{v0.04}{2007/05/26}{Renamed "cleveref" -- first public release}
% \changes{v0.05}{2007/05/31}{Added \option{poorman} option}
% \changes{v0.06}{2007/06/11}{\option{poorman} no longer writes extra
%   .tmp file}
% \changes{v0.07}{2007/06/21}{Allow prevention of reference range
%   collapsing}
% \changes{v0.08}{2007/07/10}%
%   {Made referencing commands robust, improved default formats, made
%   starred versions of referencing commands for hyperref, allowed
%   multiple consecutive empty references in list to prevent range
%   collapsing, and fixed bugs. Phew.}
% \changes{v0.08.1}{2007/08/08}{Bug fixes.}
% \changes{v0.09}{2007/10/29}%
%   {Added an extra conjunction and format component, used when a list
%   only contains a single pair of references or reference
%   sub-lists. Formats are now constructed from customisable
%   components, unless overridden using the old format definition
%   commands.}
% \changes{v0.10}{2007/10/30}%
%   {Allow optional argument to \textbackslash{}label to override
%   reference type. Removed \option{hyperref} and \option{ntheorem}
%   options; support for these and \package{amsmath} is enabled
%   automatically if those packages are loaded.}
% \changes{v0.11}{2007/11/21}{Made referencing aware of appendices.}
% \changes{v0.11.1}{2007/11/29}{Bug fixes.}
% \changes{v0.12}{2009/02/11}{Restore working \textbackslash{}ref* when
%   hyperref is loaded -- first release mirrored on www.dr-qubit.org}
% \changes{v0.13}{2009/04/17}{Finally implemented \option{sort} and
%   \option{compress} package options. Support \package{amsmath}
%   \textbackslash{}tag command. Added \package{babel} support for
%   English, German and French. Added \package{varioref} support.}
% \changes{v0.13.1}{2009/07/01}{Bug fix to \textbackslash{}cref@get*
%   commands to allow fragile and non-expandable commands in label tags.}
% \changes{v0.13.2}{2009/07/26}{Added\newline
%   \textbackslash{}crefrangepreconjunction and
%   \textbackslash{}crefrangepostconjunction commands, needed by some
%   languages (such as Italian). Added \package{babel} support for
%   Spanish and Italian. Added notes about \package{memoir}
%   (in)compatibility.}
% \changes{v0.14}{2009/08/07}{Fixed bug that caused labels containing
%   components with values of 10 or higher to be sorted
%   incorrectly. Fixed \textbackslash{}Cref to no longer capitalise all
%   cross-reference names in a multi-reference, just the first one. Added
%   \option{capitalise} option to force capitalisation everywhere.}
% \changes{v0.14.1}{2009/08/18}{Added support for \package{amsmath}'s
%   subequations environment}
% \changes{v0.14.2}{2009/09/22}{Fixed subequations sorting bug. Fixed bug
%   in \option{poorman} when used without babel. \option{capitalise}
%   option no longer uses \textbackslash{}Cref variant everywhere; it now
%   redefines the \textbackslash{}cref variants instead.}
% \changes{v0.14.3}{2009/10/17}{Bug-fix in \textbackslash{}appendix
%   code.}
% \changes{v0.15}{2009/11/26}{Added \package{amsthm} support, contributed
%   by Michael Ummels. Added \textbackslash{}leavevmode before
%   \textbackslash{}begingroup in \textbackslash{}@cref to avoid subtle
%   bug that caused page count to be reset if the output routine was
%   triggered within \textbackslash{}@cref.}
% \changes{v0.15.1}{2009/12/02}{Fixed regression introduced in v0.13 in
%   non-\package{hyperref} \option{poorman} code. Fixed bug in
%   \package{varioref} support that caused \textbackslash{}vref to print
%   \textbackslash{}reftextcurrent string for references on the current
%   page, breaking \package{varioref} backwards-compatibility. Added
%   \package{babel} support for Dutch.}
% \changes{v0.15.2}{2009/12/07}{Fixed bug in \textbackslash{}appendix
%   that produced badly formed prefix data for labels that aren't reset
%   by other counters (e.g.\ tables and figures in most document
%   classes). Fixed bug in \package{hyperref} \option{poorman} code that
%   caused all label names to be lower-cased in the sed script. Fixed
%   spacing bugs in the \package{cleveref} versions of the
%   \package{varioref} commands.}
% \changes{v0.15.3}{2009/12/11}{Fixed bug in \package{varioref} support.
%   Changed \option{poorman} \textbackslash{}usepackage sed substitution
%   rule to use POSIX regexp syntax.}
% \changes{v0.16}{2010/04/19}{Major changes to the low-level
%   implementation! \package{cleveref} now stores the extra information
%   it requires in its own \textbackslash{}cref@currentlabel and its own
%   parallel series of labels in the aux file, staying out of the way of
%   the standard cross-reference mechanism and \textbackslash{}ref
%   command. Also added \textbackslash{}namecref and
%   \textbackslash{}nameCref commands, fixed a serious bug in the
%   \package{amsmath} support affecting spacing of multi-line equation
%   environments, added support for footnotes, and made
%   \textbackslash{}newtheorem automatically define the singular form of
%   the cross-reference name for new theorem-like environments.}
% \changes{v0.16.1}{2010/04/30}{Fixed bugs in \package{amsmath} spacing
%   fix and \package{amsthm} support.}
% \changes{v0.16.2}{2010/05/12}{Fixed bugs in \textbackslash{}appendix
%   version used with \package{hyperref}, and in \textbackslash{}footnote
%   support.}
% \changes{v0.16.3}{2010/05/25}{Added missing \textbackslash{}namecrefs
%   and \textbackslash{}nameCrefs commands. Fixed bug in
%   \textbackslash{}AtBeginDocument code used to define
%   \textbackslash{}cref<x>groupconjunction macros. Added missing
%   \textbackslash{}crefname definitions for subsection, subsubsection
%   etc. in terms of those for section, so that \textbackslash{}namecref
%   works for those (and also switching language in the middle of a
%   document). Added \package{babel} support for Russian and Ukrainian.
%   Fixed bug in \textbackslash{}refstepcounter@optarg.}
% \changes{v0.17}{2010/06/07}{Fixed bug in non-\package{hyperref}
%   version of \textbackslash{}refstepcounter. Added
%   \textbackslash{}crefalias command for aliasing a counter to a
%   different cross-reference type. Added support for \package{algorithm}
%   package. Improved support for \package{subfig} package. Added support
%   for \package{listings} package. Fixed bugs in \package{amsmath}
%   \textbackslash{}tag command when used with \option{sort} option, and
%   in the \package{amsmath} multline environment's support for the
%   optional argument to \textbackslash{}label.}
% \changes{v0.17.1}{2010/06/24}{Modified \textbackslash{}@crefname macro
%   so that it no longer makes global definitions, to fix support for
%   \package{babel}'s \textbackslash{}otherlanguage and
%   \textbackslash{}foreignlanguage commands. Fixed typos in
%   \option{poorman} \textbackslash{}foreignlanguage code. Fixed bug in
%   the \package{amsmath} multline environment's support for the optional
%   argument to \textbackslash{}label\dots{} again. Added
%   \textbackslash{}labelcref command.}
% \changes{v0.17.2}{2010/07/24}{Removed unneeded argument from
%   \textbackslash{}@footnotetext redefinition, to improve compatibility
%   with other packages that redefine footnotes.}
% \changes{v0.17.3}{2010/08/30}{Added missing default format definitions
%   for ``part''. Fixed bad active character interaction between
%   \package{cleveref} and some \package{babel} languages (in particular
%   Spanish). Fixed \package{hyperref} support code so
%   that it is only enabled if \package{hyperref} was loaded with the
%   \option{implicit} option set to \option{true} (the default).}
% \changes{v0.17.4}{2010/09/04}{Added automatic support for
%   \package{aliascnt} counters whose parent counter gets reset. Fixed
%   serious bug in the test for \package{hyperref}'s \option{implicit}
%   options.}
% \changes{v0.17.5}{2010/09/15}{Fixed bug that broke compilation of
%   documents that didn't use \package{hyperref}, because
%   \textbackslash{}if@cref@hyperrefloaded was not defined.}
% \changes{v0.17.6}{2011/01/05}{Added \package{babel} support for
%   Norwegian. Replaced ``appendice'' with ``annexe'' in French default
%   cross-reference names, to match \package{babel} names. Replaced
%   ``Linie'' with ``Zeile'' in the German default cross-reference names.
%   Added \textbackslash{}lcnamecref and \textbackslash{}lcnamecrefs
%   commands to force lowercase reference names, useful with the
%   \option{capitalise} option.}
% \changes{v0.17.7}{2011/01/10}{Fixed \textbackslash{}crefname to work
%   with empty reference names.}
% \changes{v0.17.8}{2011/01/19}{Fixed automatic
%   \textbackslash{}newtheorem name definitions to work with empty
%   names.}
% \changes{v0.17.9}{2011/03/22}{Added support for \package{algorithm2e}
%   package. Added missing \textbackslash{}crefname definitions for
%   `listing'. Changed case used in plural forms in Norwegian. Fixed bug
%   in redefinition of \package{amsmath} \textbackslash{}tag command.
%   Added \package{babel} support for Danish. Renamed internal
%   \textbackslash{}@result macro to \textbackslash{}cref@result to avoid
%   conflict with \package{tikz-qtree} package. Also renamed internal
%   \textbackslash{}@temp<x> macros to \textbackslash{}@temp<x>, which
%   seems to be more standard for temporary macros, to mitigate against
%   similar (though less likely) conflicts, and also save a minuscule
%   amount of \TeX{} memory.}
% \changes{v0.17.10}{2011/04/16}{Fixed bug in
%   \textbackslash{}@cref@stack@insert caused by a temporary macro name
%   clash.}
% \changes{v0.18}{2011/10/24}{Implemented clever page referencing via
%   \textbackslash{}cpageref et al.\ commands, which supports
%   multi-references, including sorting and page range collapsing.
%   Improved \package{varioref} support, combining \package{varioref} and
%   (new) \package{cleveref} page-referencing features. Removed
%   \option{legacyvarioref} option. Fixed bug in
%   \textbackslash{}newtheorem support. Documented \package{mathtools}
%   \option{showonlyrefs} incompatibility. Fixed some of the Spanish and
%   German translations. Implemented \option{nameinlink} option, to
%   include cross-reference names in hyperlinks when using
%   \package{hyperref}. Implemented \option{noabbrev} option to disable
%   all use of abbreviations in default cross-reference names. Added
%   support for a \file{cleveref.cfg} file, which is loaded after the
%   rest of \package{cleveref} has loaded. Made cross-references to
%   sections work correctly when using the \package{revtex4} or
%   \package{revtex4-1} docclasses. Fixed \package{subfig} and
%   \package{caption} compatibility with optional argument to
%   \textbackslash{}label.}
% \changes{v0.18.1}{2011/12/24}{Fixed compatibility with newer versions
%   of \package{caption} package.}
% \changes{v0.18.2}{2012/01/17}{Don't try to redefine
%   \textbackslash{}appendix if it's not defined in current document
%   class. Fixed bug in \textbackslash{}@setnamecref. Refactored common
%   code in format-definition macros into separate
%   \textbackslash{}cref@othervariant macro. Added
%   \package{IEEEtrantools} support.}
% \changes{v0.18.3}{2012/01/18}{Fixed bugs with multiple equations and
%   subequations in an \textbackslash{}IEEEeqnarray.}
% \changes{v0.18.4}{2012/01/23}{Set \textbackslash{}cref@currentlabel
%   locally instead of globally, to match how
%   \textbackslash{}@currentlabel is set. Fix \package{xr} compatibility
%   by adding a ``cref'' suffix  to \package{cleveref}'s internal label
%   names, instead of a prefix.}
% \changes{v0.18.5}{2012/03/05}{Fixed \package{listings} and
%   \package{algorithm} package support, broken by change to local rather
%   than global \textbackslash{}cref@currentlabel definitions. Fixed
%   compatibility with \package{memoir}'s internal \package{subfig}
%   re-implementation.}
% \changes{v0.18.6}{2012/09/25}{Sorted out \package{algorithm} and
%   \package{algorithmicx} package support. Note: \package{algorithmic}
%   package is \emph{not} supported. Fixed compatibility with
%   \package{bigfoot} package. Added support for \package{polyglossia}
%   package. Mentioned \package{autonum} as a possible replacement for
%   (incompatible) \option{showonlyrefs} option to \package{mathtools}
%   package.}
% \changes{v0.18.7}{2012/10/04}{Fixed regression in \package{varioref}
%   support that once again (see v0.15.1) caused \textbackslash{}vref to
%   print \textbackslash{}reftextcurrent string for references on the
%   current page. Fixed regression(?) causing spurious whitespace to be
%   produced for empty cross-reference names (see v0.17.7).}
% \changes{v0.18.8}{2013/03/22}{Fixed automatic
%   \textbackslash{}newtheorem definitions in \package{amsthm} support.
%   Add Swedish and Brazilian translations. Fix bug in
%   \package{algorithm2e} + \package{hyperref} support.}
% \changes{v0.18.9}{2013/03/22}{Fixed regression that broke
%   \option{nameinlink} option.}
% \changes{v0.19}{2013/12/28}{Added \package{breqn} package support.
%   Remove unwanted spaces in some macros. Added abbreviation for
%   ``Abbildung'' to German translations. Added \package{xr-hyper}
%   package support. Fixed bug in \package{amsmath} \textbackslash{}tag
%   support. Added \textbackslash{}crefstripprefix utility macro and
%   example usage. Added separate \texttt{subequation} cross-reference
%   type.}
% \changes{v0.19.1}{2014/08/14}{Fixed bug in \textbackslash{}labelcref
%   format customization. Fixed subtle \textbackslash{}varioref bug
%   caused by a stray \%. Fixed typo in Swedish translations. Fix
%   \textbackslash{}setcrefrange to use same test for matching reference
%   types \textbackslash{}cref@processgroup and
%   \textbackslash{}cref@processgroupall.}
% \changes{v0.19.2}{2015/11/18}{Fixed compatibility with REFTeX
%   \textbackslash{}appendix* command. Added catalan language support.
%   Fix \textbackslash{}@bsphack/\textbackslash{}@esphack spacing issues
%   in \textbackslash{}label refefinitions. Fix \textbackslash{}crefalias
%   mechanism in \package{hyperref} support. Fix bugs in \package{breqn}
%   and \package{varioref} support. Ensure any undefined
%   \textbackslash{}labelcref formats for sub-types (subsections,
%   subequations etc.) are copied from parent types. (This fixes missing
%   brackets around \textbackslash{}labelcref subequation references.)}
% \changes{v0.20}{2016/08/10}{Fix erroneous \%'s after
%   \textbackslash{}advance which broke \package{varioref} support.
%   Add \textbackslash{}cref@ifstreq utility macro for
%   catcode-independent string comparison.
%   Fix sorting of enum\meta{x} labels.}
% \changes{v0.21}{2017/07/10}{Add \texttt{cref@} prefix to
%   \textbackslash{}gobble@optarg to avoid conflicts with other packages.
%   Compress away duplicate references in \textbackslash{}cref etc.\ just
%   as we already did for \textbackslash{}cpageref. Fix
%   \textbackslash{}cpageref error on non-arabic page numbers. Fix bug
%   that disabled warning on more than one reference type within a
%   \textbackslash{}labelcref. Refactor \textbackslash{}cpageref to use
%   same machinery as \textbackslash{}cref, treating different page
%   numbering schemes within a document as different page number
%   ``types''. Refactor and simplify main \textbackslash{}@cref macro.
%   Fix compatibility with newer IEEEtrantools versions. Fix subtle
%   bug in \package{amsmath}$+$\package{hyperref} subequations support,
%   which made hyperlinks point to wrong location in \emph{all} equations
%   following the first use of subequations in a document.}
% \changes{v0.21.1}{2018/02/08}{Fix bug in \package{hyperref}
%   \textbackslash{}cpagerefrange support. Disable \package{hyperref}
%   support when \package{hyperref} is loaded with implicit=false option,
%   and generate a warning that this situation is unsupported. Fix bug
%   that broke \texttt{compress} option.}
% \changes{v0.21.2}{2018/02/09}{Fix bug in undefined reference warning
%   message printed by \textbackslash{}namecref etc., and note in the
%   documentation that these commands only accept a single reference.
%   Add support for \textbackslash{}crefalias'ing of appendix reference
%   types.}
% \changes{v0.21.3}{2018/03/03}{Fix bug in \package{hyperref}-support
%   version of \textbackslash{}cpageref. Fix spelling mistakes in Dutch
%   translations. Add additional advanced cross-reference formatting
%   example to manual. Modify \textbackslash{}@crefcopyformats so it
%   copys over format \emph{components}, rather than copying over the
%   low-level format definitions.}
% \changes{v0.21.4}{2018/03/27}{Make subsubsection/subsubappendix formats
%   inherit from subsection/subappendix rather than section/appendix.
%   Modify \textbackslash{}@crefcopyformats to copy over low-level
%   formats again \emph{if} no components have have been customised.
%   Improve explanation of sub-format inheritance in the manual.}
%
% \GetFileInfo{cleveref.sty}
%
%
% \title{The \package{cleveref} package\thanks{This document
%     corresponds to \textsf{cleveref}~\packageversion, dated
%     \packagedate.}}
% \author{Toby Cubitt \\
% \href{mailto:toby-cleveref@dr-qubit.org}{toby-cleveref@dr-qubit.org}}
% \date{\packagedate}
%
% \maketitle
%
% \begin{abstract}
%   The \package{cleveref} package enhances \LaTeX{}'s cross-referencing
%   features,\linebreak[4] allowing the format of cross-references to be
%   determined automatically according to the ``type'' of cross-reference
%   (equation, section, etc.) and the context in which the
%   cross-reference is used. The formatting for each cross-reference type
%   can be fully customised in the preamble of your document. In
%   addition, \package{cleveref} can typeset cross-references to lists
%   of multiple labels, automatically formatting them according to their
%   types, sorting them, and compressing sequences of numerically
%   consecutive labels. Again, the multiple-reference formatting is fully
%   customisable.
%
%   Normally, the latest version of the \package{cleveref} package is
%   available via CTAN.\ Occasionally, slightly newer ``pre-release''
%   versions are available at \url{www.dr-qubit.org/latex.php#cleveref} a
%   little before they make their way onto CTAN.
% \end{abstract}
%
% \clearpage
% \tableofcontents
% \clearpage
%
%
% \section{Introduction}
% When ``clever'' is used in the name of a computer program, it usually
% indicates that the programmer is overly smug about his own
% achievements. But at the heart of the \LaTeX{} philosophy also lies the
% idea that it is clever to delegate as much of the typesetting as
% possible to the computer, in order to achieve a beautiful --- and above
% all consistent --- visual appearance.
%
% All of this probably applies to the \package{cleveref} package. Its
% goals are two-fold: to exploit all the information that \LaTeX{} can
% collect about labels as intelligently as possible (clever processing),
% allowing you to produce an attractive, consistent formatting of
% cross-references throughout your document with the minimum of effort
% (you'd be clever to use it!).
%
% The \package{cleveref} package enhances \LaTeX{}'s cross-referencing
% features by automatically formatting cross-references depending on what
% they refer to (chapter, section, equation, theorem, etc.). It can
% automatically format cross-references to multiple labels, and can sort
% lists of multiple cross-references, compresses consecutive labels into
% a reference range, and all kinds of other clever wizardry. It also does
% similar things with page references.
%
% In standard \LaTeX{}, you have almost certainly found yourself writing
% things like |Eq.~(\ref{eq1})| and |Theorems~\ref{thm1} to~\ref{thm3}|
% over and over again. Tedium isn't the only downside to this. What
% happens if you later decide you want equation references to be typeset
% as |Equation~\ref{eq1}| instead (i.e.\ without the abbreviation and
% without the parentheses)? What happens if you decide to change the
% theorem labelled |thm1| into a lemma?\footnote{Note that to allow
% \package{cleveref} to automatically infer the type of theorem, you need
% to load either the \package{ntheorem} or the \package{amsthm} package.
% See \cref{sec:non-bugs} for more details.} What if you move |thm3| so
% that it appears (and is numbered) before |thm1|, meaning that
% references to the sequence of theorems 1 through 3 should now be
% ordered |Theorems~\ref{thm3} to~\ref{thm1}| (i.e.\ the other way
% around)? What if you decide you prefer references to multiple theorems
% to be written as |Theorems~\ref{thm1}--\ref{thm3}|? Any such change
% requires you to search through the entire \LaTeX{} source of your
% document, modifying all references to equations, updating all
% references to |thm1|, re-ordering all references to |thm1| and |thm3|,
% and changing all the formatting of references to multiple theorems.
%
% The \package{cleveref} package allows you to define the format for the
% different types of cross-references once-and-for-all in the preamble of
% your document. (Of course, sane default formats are provided, so you
% only have to redefine the format if you don't like the default for a
% particular cross-reference type.) If you later decide to change the
% format of equation references, you only have to change one preamble
% definition. If you change a theorem into a lemma, you don't need to
% change any cross-references at all, because \package{cleveref} will
% automatically use the appropriate name when typesetting any
% cross-references to it. This makes it far easier to typeset
% cross-references uniformly across your whole document, as well as
% avoiding repetitively typing similar text for each and every
% cross-reference.
%
%
%
% \section{Usage}
% The \package{cleveref} package is loaded in the usual way, by putting
% the line
% \begin{quote}
%   |\usepackage{cleveref}|
% \end{quote}
% in your document's preamble. However, care must be taken when using
% \package{cleveref} in conjunction with other packages that modify
% \LaTeX{}'s referencing system (see
% \cref{sec:other_packages}). Basically, \package{cleveref} must be
% loaded \emph{last}.
%
% If you just want to get going quickly with \package{cleveref}, and come
% back later to read up on all the features it provides in more detail,
% here's what you need to do. Wherever you would previously have used
% |\ref|, use |\cref| instead. (Except at the beginning of a sentence,
% where you should use |\Cref|.) You no longer need to put the name of
% the thing you're referencing in front of the |\cref| command, because
% \package{cleveref} will sort that out for you: i.e.\ use |\cref{eq1}|
% instead of |eq.~(\ref{eq1})|. If you want to refer to a range of
% labels, use the |\crefrange| command: |\crefrange{eq1}{eq5}| produces
% |eqs.~(1) to~(5)|. If you want to refer to multiple things at once, you
% can simply throw them all into one cross-reference and leave
% \package{cleveref} to sort it out: e.g.\
% |\cref{eq2,eq1,eq3,eq5,thm2,def1}| produces%
% |eqs.~(1) to~(3) and~(5),| |theorem~5, and definition~1|. Finally, if
% you want a page reference, use |\cpageref| (and don't write ``page'' in
% front), if you want a page range, use |\cpagerefrange|, and if you want
% to refer to multiple pages, simply throw them all into a single
% |\cpageref|. Just as with |\cref| (above), \package{cleveref} will sort
% it all out for you automaticaly.
%
% \package{Cleveref} supports a number of languages other than English,
% and also supports the \package{babel} and \package{polyglossia}
% packages for those languages. Either pass the desired language as an
% option to \package{cleveref}, or pass it as a global option to
% |\documentclass|. Note that if you're writing in a language in which
% nouns decline, the |\cref| and |\cpageref| commands may be less useful,
% as they always produce the cross-reference name in the nominative
% case.\footnote{Providing separate variants of the \package{cleveref}
% commands for each noun case quickly becomes more cumbersome than just
% typing the cross-reference name by hand. Trying to determine the
% appropriate case automatically would be tantamount to solving the full
% natural-language processing problem in \package{cleveref}. Check back
% in a century or so for this feature.} In such languages, you may
% instead prefer to use the |\labelcref| and |\labelcpageref| commands.
% Unlike |\cref| and |\cpageref|, these don't produce the name in front
% of the cross-reference, so you must supply it (in the appropriate case)
% yourself. But they do still cope with multi-references, so you still
% gain some benefit from using \package{cleveref}.
%
%
%
% \section{Comparison with Other Packages}
% Given how useful automated cross-reference typesetting is, there are
% naturally a number of other \LaTeX{} packages with similar goals to
% \package{cleveref}, most notably \package{varioref},
% \package{fancyref}, \package{hyperref}'s |\autoref| command, and (for
% theorem-like environments) \package{ntheorem} with the \option{thref}
% option. (There are many others, but these come closest to providing
% similar features to \package{cleveref}.) However, all have certain
% deficiencies which \package{cleveref} attempts to overcome.
%
% The \package{fancyref} package doesn't automatically determine the type
% of thing being referred to. Instead, it relies on you adhering to a
% naming convention for labels. This is usually a good idea in any case,
% but it can occasionally be inconvenient. For example, if you change a
% theorem into a lemma, you have to change the label name, and therefore
% also all cross-references to it. So with \package{fancyref}, you will
% at times be back to searching and replacing label names throughout your
% document. Not to mention missing out on all the other
% \package{cleveref} features, such as automatic sorting and compressing
% of consecutive references, \package{ntheorem} and \package{amsthm}
% support, precise control over hyperlinks, etc.
%
% The enhanced referencing feature provided by the \package{varioref}
% package's\linebreak[4] |\labelformat| command decides how to format
% cross-references when the label is \emph{defined}, rather than when it
% is \emph{referenced}. Often this isn't a problem. But it makes it
% impossible to format cross-references according to the context in which
% they are referenced, which can sometimes be very useful. For example,
% you may want cross-references at the beginning of a sentence formatted
% differently to cross-references in the middle of a sentence. E.g.\ you
% may want to use the abbreviation ``eq.'', but revert to ``Equation'' at
% the beginning of sentences (words at the start of sentences shouldn't
% be abbreviated in English). This is not possible with
% \package{varioref}. Perhaps even more significantly,
% \package{varioref}'s |\labelformat| implementation makes it impossible
% to typeset multiple references automatically; if you want to refer to
% equations |eq1| through |eq3|, with \package{varioref} you are back to
% typing |Eqs.~(\ref{eq1}) to~(\ref{eq3})| by hand. Not to mention
% missing out on all the other \package{cleveref} features. In fact,
% \package{cleveref} fully supports \package{varioref}, taking over
% responsibility for typesetting cross-references, whilst retaining (and
% even enhancing) all the \package{varioref} page-referencing magic.
%
% The \package{hyperref} package's |\autoref| command typesets a name
% before a cross-reference, determined by the cross-reference type. This
% is less flexible than \package{cleveref}'s fully customisable
% cross-reference formatting, but, when combined with \package{varioref},
% the two packages working together come pretty close. But surprisingly,
% even with \package{hyperref}, it is impossible to customise precisely
% which part of the cross-reference is made into a hyperlink in PDF
% documents; this is simple with \package{cleveref}. And it still remains
% impossible to typeset multiple references, have consecutive references
% sorted and compressed automatically, etc.
%
% The \package{ntheorem} package (with the \option{thref} option) does
% the right thing when it comes to how and when the format is
% defined\ldots except that it only works for theorem-like environments.
% It is possible to use it for other environments, but only in a
% bastardized form, by manually supplying an optional argument to every
% |\label| command to specify the label type. \package{Cleveref} works
% equally well with any type of cross-reference, as well as fully
% supporting \package{ntheorem}. And again, \package{cleveref} provides a
% number of additional features over \package{ntheorem}, such as
% multi-references, automatic sorting and compressing of consecutive
% cross-references, control over the placement of hyperlinks, etc.
%
%
%
% \section{Typesetting Cross-References}
% \label{sec:typesetting}
% \DescribeMacro\cref
% To automatically typeset a cross-reference according to the type of
% thing referred to, simply refer to it using |\cref|\marg{label}.
% \package{Cleveref} imposes just one extra restriction on the names of
% labels: they are no longer allowed to contain commas ``,''. These are
% instead used to typeset multiple cross-references (see below).
%
% \DescribeMacro\Cref
% As it is very difficult\footnote{Actually, very likely impossible!} for
% \LaTeX{} to determine whether a cross-reference appears at the
% beginning of a sentence or not, a beginning-of-sentence variant exists:
% |\Cref|\marg{label}. By default, this typesets the cross-reference with
% the first letter capitalised, and without using an abbreviation in
% those cases where the standard variant does use one. (However, the
% formatting of the |\cref| and |\Cref| forms can be fully and
% independently customised, see \cref{sec:customising}.)
%
% \DescribeMacro\crefrange
% \DescribeMacro\Crefrange
% To typeset a cross-reference range, e.g.\ |Eqs.~(1.1) to~(1.5)|,
% use\linebreak[4] |\crefrange| or |\Crefrange| (depending on the
% capitalisation you require), which take the beginning and end of the
% range as arguments:
% \begin{quote}
%   |\crefrange|\marg{label1}\marg{label2}
% \end{quote}
%
% \DescribeMacro\cref
% \DescribeMacro\Cref
% To typeset multiple cross-references, simply list the labels inside
% the |\cref| or |\Cref| command, separated by commas (recall that you
% are not allowed to use commas in label names when using
% \package{cleveref}):
% \begin{quote}
%   |\cref{|\meta{label1}|,|\meta{label2}|,|\meta{label3}|,|\dots|}|
% \end{quote}
%
% \DescribeMacro{\cref*}
% \DescribeMacro{\Cref*}
% \DescribeMacro{\crefrange*}
% \DescribeMacro{\Crefrange*}
% When \package{cleveref} is used along with the \package{hyperref}
% package (see \cref{sec:customising,sec:other_packages}), additional
% starred variants of all the referencing commands are available. The
% standard referencing commands will make cross-references into
% hyperlinks; the starred variants prevent this, producing the same
% typeset text but without creating hyperlinks.
%
% \DescribeMacro\cpageref
% \DescribeMacro\Cpageref
% To typeset a page reference, use |\cpageref|\marg{label}, which is
% typeset e.g.\ as ``page~3''. At the beginning of a sentence, use
% |\Cpageref| instead. Since page references are always references to,
% well\dots pages, this doesn't gain you so much over |\pageref|. Where
% |\cpageref| comes into its own is in referring to multiple pages:
% \begin{quote}
%   |\cpageref{|\meta{label1}|,|\meta{label2}|,|\meta{label3}|,|\dots|}|
% \end{quote}
% \DescribeMacro\cpagerefrange
% \DescribeMacro\Cpagerefrange
% Predictably enough, |\cpagerefrange| and |\Cpagerefrange| are used to
% typeset references to page ranges:
% \begin{quote}
%   |\cpagerefrange|\marg{label1}\marg{label2}
% \end{quote}
%
% \DescribeMacro\ref
% \DescribeMacro\pageref
% \package{Cleveref} does \emph{not} modify the standard |\ref| or
% |\pageref| commands, so you can still use them to typeset the
% formatted label counter or page number alone, without any additional
% text or formatting.
%
% \DescribeMacro{\namecref}
% \DescribeMacro{\nameCref}
% \DescribeMacro{\lcnamecref}
% \DescribeMacro{\namecrefs}
% \DescribeMacro{\nameCrefs}
% \DescribeMacro{\lcnamecrefs}
% Occasionally, it's useful to produce just the name of a reference,
% without the label itself. For example, if you want to refer to ``this
% section'', but you're not sure whether you might later change the
% section into a chapter, it might be useful to produce just the name
% ``section'' associated with the section's label. If you later change
% the section into a chapter, the text will then automatically change to
% ``this chapter''. The |\namecref| and |\nameCref| do exactly this:
% \begin{quote}
%   |\namecref{sec1}|
% \end{quote}
% is typeset as ``section'' (assuming |sec1| labels a section). The
% |\namecrefs| and |\nameCrefs| commands produce the plural forms. The
% |\lcnamecref| and |\lcnamecrefs| commands force the reference name to
% lowercase, for use when the \option{capitalise} option is enabled (see
% \cref{sec:capitalise}). (When that option is set, |\namecref| produces
% an uppercase reference name.)
%
% Note that all these commands can only be passed a \emph{single}
% reference name; they do \emph{not} accept multi-references like
% |\cref|. (Passing multiple references to these commands would make
% little sense if the references had different types, and is redundant if
% they have the same type.)
%
% There is a slight pitfall that you should be aware of when using the
% |\namecref| commands. They get the reference name from the names
% defined for the label's reference type using |\crefname| or |\Crefname|
% (see \cref{sec:individual_customisation}). The default reference
% formats provide these definitions. However, it is possible to customise
% reference formats using lower-level commands that do not create
% |\crefname| definitions (see \cref{sec:low-level_customisation}). If
% the |\crefname| definitions are missing for a particular reference
% type, |\namecref| and |\nameCref| will produce errors for labels of
% that type. You can fix the error by adding explicit |\crefname|
% definitions for these types.
%
% \DescribeMacro{\labelcref}
% Conversely, it is occasionally convenient to produce just the label
% part of a reference, without the cross-reference name. For example,
% this can be useful when writing in a language in which nouns decline.
% The |\labelcref| command does exactly this, and can also cope with
% multi-references, processing them just as |\cref| does. However, since
% it typesets a multi-reference without any name, \emph{all} labels in a
% |\labelcref| multi-reference \emph{must} be of the same type.
%
% The |\labelcref| command will typeset cross-reference labels using the
% default label format if no type-specific format is defined using
% |\creflabelformat| (see
% \cref{sec:global_customisation,sec:individual_customisation}). Note
% that, if you customise reference formats using the low-level commands,
% you may want to also explicitly define the |\labelcref| formats to
% match, using the |\labelcrefformat| etc.\ commands (see
% \cref{sec:low-level_customisation}).
%
% \DescribeMacro{\labelcpageref}
% Similarly, |\labelcpageref| typesets the page numbers alone, without
% inserting ``page'' in front. Like |\cpageref|, it also handles
% multi-references. Like |\labelcref|, by default |\labelcpageref|
% typesets the page numbers using the default label format, customised
% using |\crefdefaultlabelformat|. If you want to define a separate
% format for |\labelcpageref|, use |\creflabelformat| to customise the
% label format for the ``page'' cross-reference type. (see
% \cref{sec:low-level_customisation}).
%
%
%
% \section{Sorting and Compressing}
% \label{sec:sort&compress}
% When \package{cleveref} typesets lists of multiple cross-references or
% page-references, the default behaviour is to automatically sort the
% list and compress sequences of consecutive cross-references or page
% numbers into a reference range. You can change this behaviour by
% supplying one of the following package options:
% \begin{description}
% \item[\option{sort}] Sort lists of cross-references, but don't compress
%   consecutive references.
% \item[\option{compress}] Compress sequences of consecutive references
%   into a reference range, but don't sort the list of cross-references.
% \item[\option{nosort}] Neither sort lists of cross-references,
%   \emph{nor} compress consecutive references.
% \item[\option{sort\&compress}] Sort lists of cross-references, and
%   compress sequences of consecutive references into a reference
%   range (this is the default).
% \end{description}
%
% Occasionally, you may want to prevent a particular sequence of
% consecutive cross-references from being compressed to a reference
% range, without disabling this feature globally. To achieve this, you
% can separate the cross-references in the list by one or more empty
% references, at the point at which you want to prevent compression. For
% example,
% \begin{quote}
%   |\cref{eq1,eq2,eq3,,eq4}|
% \end{quote}
% will be typeset as
% \begin{quote}
%   eqs.~(1) to~(3) and (4)
% \end{quote}
% or
% \begin{quote}
%   |\cref{eq1,eq2,,eq3,eq4,eq5,,eq6,eq7,eq8}|
% \end{quote}
% will be typeset as
% \begin{quote}
%   eqs.~(1), (2), (3) to~(5) and (6) to~(8)
% \end{quote}
% You can safely put an empty reference between cross-references that
% would never be compressed anyway; it will simply be ignored.
%
% If lists of cross-references are also being sorted (the default), it
% can be a little confusing to work out where the empty reference should
% go in order to prevent compression of a particular consecutive
% sequence. It's best to think of the empty reference as being
% ``attached'' to the cross-reference preceding it. When the list is
% sorted, the empty reference will still appear after the same preceding
% reference, and will prevent it being compressed with any subsequent
% consecutive cross-references. In other words, an empty reference
% ensures that the preceding reference will appear explicitly in the
% final, typeset cross-reference:
% \begin{quote}
%   |\cref{eq3,,eq2,eq1,eq6,eq4,eq5}|
% \end{quote}
% will be typeset as
% \begin{quote}
%   eqs.~(1) to~(3) and (4) to~(6)
% \end{quote}
%
%
%
% \section{Overriding the Cross-Reference Type}
% \label{sec:label_type}
% \DescribeMacro\label
% A label's ``type'' is usually determined by the name of the counter it
% refers to, or in the case of \package{ntheorem} and \package{amsthm}
% theorem-like environments by the environment name. However, sometimes
% it is useful to override the type. \package{Cleveref} provides two
% different mechanisms for accomplishing this.
%
% You can alias a counter to a different cross-reference type using the
% |\crefalias| command:
% \begin{quote}
%   |\crefalias|\marg{counter}\marg{type}
% \end{quote}
% \meta{counter} will then use the cross-reference formatting of
% \meta{type}. This can be useful if you want multiple counters to use
% the same cross-reference format.
%
% Occasionally, you may want to override the cross-reference type for one
% particular label, one-off. You can do this by supplying the desired
% type as an optional argument to the |\label| command:
% \begin{quote}
%   |\label|\oarg{type}\marg{label}
% \end{quote}
%
% One circumstance in which is useful is when you want to define a
% special cross-reference format for certain labels of a given type. By
% supplying a type that doesn't already exist as the optional argument to
% |\label|, you can then define the cross-reference format for that new
% type in whatever way you like, without affecting other cross-references
% of the same type. For example, if a particular equation contains
% multiple expressions and you want it to always be referred to in the
% plural, you could use:
% \begin{quote}
%   |\crefname{pluralequation}{eqs.}{eqs.}|\\
%   \dots\\
%   |\label[pluralequation]{eq1}|
% \end{quote}
% You can of course reuse this format for other plural equations, too.
%
% If you need to do this frequently, it can become tedious specifying the
% label explicitly each time. An alternative is to use the
% \package{aliascnt} package. This lets you define one counter to be an
% alias for another, so that effectively the same counter has two names.
% Since \package{cleveref} determines the label type from the counter
% name, the two counter aliases can have different cross-reference
% formats whilst really being the same counter. You have to somehow
% arrange for the correct counter alias to be used depending on which
% cross-reference format you want (probably by defining two variants of
% the environment in question). But the effort involved might be worth
% the convenience of not having to remember to pass an explicit optional
% argument to a large number of labels.
%
% You can use this trick to get different cross-reference formats for
% different theorem-like environments,\footnote{This trick seems to
% belong to \LaTeX{} mythology, and certainly isn't my own idea! But I
% haven't been able to definitively track down who originally came up
% with it.} \emph{without} using the \package{amsthm} or
% \package{ntheorem} package (although using one of those packages is a
% better solution if available). For example,
% \begin{quote}
%   |\usepackage{aliascnt}|\\
%   |\usepackage{cleveref}|\\
%   |\newaliascnt{lemma}{theorem}|\\
%   |\newtheorem{lemma}[lemma]{Lemma}|\\
%   |\aliascntresetthe{lemma}|\\
%   |\crefname{lemma}{lemma}{lemmas}|
% \end{quote}
% Note that \package{aliascnt} must be loaded before \package{cleveref},
% and any \cmd{\newaliascnt} commands \emph{must} come \emph{after}
% \package{cleveref} has been loaded.
%
%
%
% \section{Options that Modify the Cross-Reference Format}
%
% \subsection{Capitalising All Cross-Reference Names}
% \label{sec:capitalise}
% \DescribeMacro{capitalise}
% Many authors prefer to always capitalise cross-reference names,
% regardless of where they appear in the sentence, writing Theorem~1 and
% Equation~3 (as opposed to theorem~1 and equation~3). If you count
% yourself among this group, you can pass the \option{capitalise} option
% to the \package{cleveref} package (\option{capitalize} also works).
%
% All the default cross-reference formats will then have the first letter
% capitalised, as will the automatically generated |\cref| variants (see
% \cref{sec:individual_customisation,sec:low-level_customisation}).
% (However, if you explicitly define a |\cref| variant to \emph{not} be
% capitalised, \package{cleveref} will still honour your definition. In
% other words, you're responsible for defining the capitalisation
% correctly in your own format definitions.)
%
% You should \emph{still} use the |\Cref| variants at the beginning of
% sentences, for one thing, because abbreviations should not be used at
% the beginning of a sentence,\footnote{At least in English; I'm not sure
% about other languages.} and for another, in case you later change your
% mind and remove the \option{capitalise} option.
%
%
% \subsection{Including Names in Hyperlink Targets}
% \label{sec:nameinlink}
% \DescribeMacro{nameinlink}
% When using the \package{hyperref} package, \package{cleveref}
% automatically makes all cross-references into hyperlinks to the
% corresponding reference. By default, only the label itself forms part
% of the hyperlink target (i.e.\ the text you can click on to navigate to
% the cross-reference). The cross-reference name is not part of the
% hyperlink. By contrast, \package{hyperref}'s |\autoref| command
% \emph{does} includes the name as part of the hyperlink. If you prefer
% to include the names in the hyperlinks when using \package{cleveref},
% you can pass the \option{nameinlink} option to the \package{cleveref}
% package. (For even more control over the placement of the hyperlink
% target, use the commands for customising the cross-reference format.
% See \cref{sec:customising}.)
%
% However, use of this option is discouraged on stylistic grounds.
% Firstly, when producing PDF output \package{hyperref} by default
% surrounds hyperlinks with red boxes, which looks particularly ugly when
% the entire cross-reference name is surrounded by a red box (though this
% unfortunate default can be changed using \package{hyperref} package
% options; see the \package{hyperref} documentation for details).
% Secondly, and more significantly, when using multi-references only the
% first reference in a group can include the cross-reference name as part
% of its hyperlink target, for obvious reasons. The hyperlink targets for
% the other references in the group will necessarily be just the labels.
% This makes for somewhat non-uniform typesetting of hyperlinks, with the
% first cross-reference in a multi-reference having a much larger
% hyperlink target than the others.
%
%
% \subsection{Abbreviations in Cross-Reference Names}
% \label{sec:noabbrev}
% \DescribeMacro{noabbrev}
% The default cross-reference names for some languages use common
% abbreviations for some of the names (e.g.\ in the default English
% format, |\cref{eq1}| will be typeset as |eq.~(1)|). Some authors may
% prefer to always use the full name, rather than an abbreviation
% (|equation~(1)| instead of |eq.~(1)|). To disable all use of
% abbreviations in the default cross-reference names, pass the
% \option{noabbrev} option to the \package{cleveref} package.
%
% Note that the default names \emph{never} use abbreviations for the
% start-of-sentence variants (|\Cref| etc.)
% This is because in good written English (and likely other languages
% too), abbreviations should never be used at the beginning of a
% sentence. Many of \TeX{}'s default settings (e.g.\ page margins) are
% specifically chosen to encourage good typesetting style.
% \package{Cleveref} tried to follow the same philosophy. If despite this
% you insist on using abbreviations at the start of sentences, you will
% need to customise the start-of-sentence formats yourself.
%
%
%
%
% \section{Customising the Cross-Reference Formats}
% \label{sec:customising}
% The \package{cleveref} package allows you to take full control of the
% typesetting of cross-references, by allowing the formatting to be
% customised. Defaults appropriate for English documents are provided for
% the standard label types,\footnote{For any pedantic classics scholars
% out there: ``lemmas'' is recognised as a valid plural form of ``lemma''
% in all current versions of the Oxford English Dictionary. ``Lemmata''
% was last heard in a mathematical debate that took place in a pub just
% around the corner from Hadrian's wall\dots a few years before the
% Romans pulled out of Britain. \package{Cleveref} might have ``clever''
% in its name, but even that doesn't make it pretentious enough to use
% ``lemmata'' for the plural of ``lemma''.} and support for a number of
% languages is provided via package options (see
% \cref{sec:language_babel}). But if you don't like the defaults, or are
% writing in a language that is not supported yet,\footnote{Any
% contributions of translations for missing languages are very welcome!
% See \cref{sec:new-features} for information on how to contribute
% translations.} or you need to refer to something for which no default
% format is defined, then you can take charge and define your own
% formats.
%
% If \package{cleveref} encounters a cross-reference to a type it does
% not know, it will produce a ``reference type undefined'' warning, and
% typeset the cross-reference as
% \begin{quote}
%   {\bf ??}~|\ref|\marg{label}
% \end{quote}
% i.e.\ the label counter preceded by a double question mark. The error
% message indicates the name of the unknown cross-reference type, which
% you will then probably want to define. (References to undefined labels
% still produce a ``reference undefined'' warning and appear as a double
% question mark, as usual.)
%
% The cross-reference formats are usually constructed out of components:
% the cross-reference name (different for each type of cross-reference),
% the format for the label itself, and the conjunctions used in reference
% ranges and lists of multiple cross-references. There are two levels of
% customisation: you can either customise the components, or you can take
% full control and override the component-derived format entirely.
%
% \package{Cleveref} treats page references, as produced e.g.\ by
% |\cpageref|, as cross-references with the type ``page''. Therefore, all
% of the mechanisms for customising cross-references apply equally well
% to page references, simply by using ``page'' as the cross-reference
% type.
%
%
% \subsection{Customising the Cross-Reference Components}
% \label{sec:component_customisation}
%
% \subsubsection{Global Customisation}
% \label{sec:global_customisation}
% The global customisation commands affect all cross-reference formats,
% unless they are overridden by lower-level customisation commands.
%
% \DescribeMacro\crefdefaultlabelformat
% The format for the label counter itself can be customised globally
% using
% \begin{quote}
%   |\crefdefaultlabelformat|\marg{format}
% \end{quote}
% The \meta{format} argument can be any valid \LaTeX{} code, though you
% will need to |\protect| fragile commands. It can (and almost certainly
% should!) contain three arguments, |#1|, |#2| and |#3|. The first
% argument is the formatted version of the label counter (e.g.\
% |\thesection|). The other two are used to mark the beginning and end
% of the part of the cross-reference that should form the hyperlink when
% the \package{hyperref} package is used (see
% \cref{sec:other_packages}). For example, if you wanted to surround all
% labels with square brackets, without the square brackets themselves
% being part of the hyperlink, you would need:
% \begin{quote}
%   |\crefdefaultlabelformat{[#2#1#3]}|
% \end{quote}
% The hyperlink arguments |#2| and |#3| \emph{must} appear in that
% order. (Leaving them out completely will not cause an error, but in
% that case no hyperlink will be created when \package{hyperref} is
% used, and there are better ways to achieve this. See
% \cref{sec:typesetting,sec:other_packages}.)
%
% Note that the default format for equation cross-references already
% overrides |\crefdefaultlabelformat| in order to surround the label with
% parentheses, so the redefining |\crefdefaultlabelformat| will have no
% effect on equations. The label format for equations must be customised
% separately if you want to change it (see
% \cref{sec:individual_customisation}).
%
% \DescribeMacro\crefrangeconjunction
% The conjunction used in a reference range can be customised by
% defining |\crefrangeconjunction|:
% \begin{quote}
%   |\newcommand{\crefrangeconjunction}|\marg{conjunction}
% \end{quote}
% It does not have to be an actual conjunction in the linguistic sense,
% e.g.\ it is perfectly reasonable to define it to be an endash
% ``|--|''. |\crefrangeconjunction| is used directly between the start
% and end references in a reference range, without any additional space
% surrounding it, e.g.\ |\crefrange{thm1}{thm2}| is typeset as
% \begin{quote}
%   |theorems~\ref{thm1}\crefrangeconjunction\ref{thm2}|
% \end{quote}
% so you may or may not want to include surrounding space, depending on
% the formatting you desire. For example,
% \begin{quote}
%   |\newcommand{\crefrangeconjunction}{ and~}|
% \end{quote}
% does require surrounding space, whereas
% \begin{quote}
%   |\newcommand{\crefrangeconjunction}{--}|
% \end{quote}
% does not.
%
% \DescribeMacro\crefrangepreconjunction
% \DescribeMacro\crefrangepostconjunction
% There are two other ``conjunction'' commands available for customizing
% the formatting for reference ranges. These are
% |\crefrangepreconjunction| and |\crefrangepostconjunction|, which
% insert text before the first label defining the range, and after the
% second label, respectively. For example, when these commands are
% defined, |\crefrange{thm1}{thm2}| is typeset as
% \begin{quote}
%   |theorems~\crefrangepreconjunction\ref{thm1}|\\
%   | |\ding{229} |\crefrangeconjunction\ref{thm2}\crefrangepostconjunction|
% \end{quote}
% These commands are not used in the default English format definitions,
% but they are needed in some languages to correctly express a range. For
% example, the Italian format defines |\crefrangepreconjunction| to be
% ``da'', so that |\crefrange{thm1}{thm2}| produces
% \begin{quote}
%   |teorema da~\ref{thm1} a~\ref{thm2}|
% \end{quote}
%
% \DescribeMacro\crefpairconjunction
% \DescribeMacro\crefmiddleconjunction
% \DescribeMacro\creflastconjunction
% The conjunctions used in lists of multiple cross-references can be
% customised by defining the commands |\crefpairconjunction|,
% |\crefmiddleconjunction| and |\creflastconjunction|:
% \begin{quote}
%   |\newcommand{\crefpairconjunction}|\marg{conjunction}\\
%   |\newcommand{\crefmiddleconjunction}|\marg{conjunction}\\
%   |\newcommand{\creflastconjunction}|\marg{conjunction}
% \end{quote}
% |\crefpairconjunction| is used when there are only two cross-references
% in the list, |\creflastconjunction| is used between the penultimate and
% final cross-reference in a list of more than two, and
% |\crefmiddleconjunction| is used between all the others. Again, they do
% not have to be conjunctions in the linguistic sense, and the same
% considerations about surrounding space apply as in the case of
% |\crefrangeconjunction|. For example, the default definition of
% |\crefmiddleconjunction| is:
% \begin{quote}
%   |\newcommand{\crefmiddleconjunction}{, }|
% \end{quote}
%
% \DescribeMacro\crefpairgroupconjunction
% \DescribeMacro\crefmiddlegroupconjunction
% \DescribeMacro\creflastgroupconjunction
% By default, the conjunctions used to separate sub-lists of different
% cross-reference types in a multi-reference are identical to those used
% to separate cross-references of the same type.\footnote{More
%   accurately, if you redefine $\backslash$crefpairconjunction etc.\ in
%   your preamble, $\backslash$crefpairgroupconjunction etc.\ are
%   automatically redefined so that they match. (In some languages, the
%   default definition of $\backslash$creflastgroupconjunction has an
%   additional comma lacking in $\backslash$creflastconjunction.)} You
% can override this by defining the conjunction commands
% |\crefpairgroupconjunction|, |\crefmiddlegroupconjunction| and
% |\creflastgroupconjunction|.
%
% For example,
% \begin{quote}
%   |\cref{eq1,eq2,eq3,thm1,thm2,fig1,thm3}|
% \end{quote}
% is typeset as
% \begin{quote}
%   eqs.~(1)|\crefrangeconjunction|(3)|\crefmiddlegroupconjunction|%\\
%   theorems~1|\crefpairconjunction|2|\crefmiddlegroupconjunction|%\\
%   fig.~1|\creflastgroupconjunction{}|theorem~3
% \end{quote}
%
%
% \subsubsection{Customising Individual Cross-Reference Types}
% \label{sec:individual_customisation}
% \DescribeMacro\crefname
% \DescribeMacro\Crefname
% The cross-reference name for a given cross-reference type is customised
% using the |\crefname| and |\Crefname| commands:
% \begin{quote}
%   |\crefname|\marg{type}\marg{singular}\marg{plural}\\
%   |\Crefname|\marg{type}\marg{singular}\marg{plural}
% \end{quote}
% used by the |\cref| and |\Cref| commands, respectively. You must supply
% both \meta{singular} and \meta{plural} forms of the name. If the
% corresponding |\Crefname| is undefined when |\crefname| is called, it
% will automatically define |\Crefname| to be a capitalised version of
% |\crefname|, using |\MakeUppercase|. Conversely, if the corresponding
% |\crefname| is undefined when |\Crefname| is called, it will
% automatically define |\crefname| to be a lower-case version of
% |\Crefname|, using |\MakeLowercase|. Obviously, this will only work
% properly if the names begin with a letter. If the first letter is a
% special character construct, such as an accented character, you will
% need to surround it by braces. If the first thing in the name is
% \emph{not} a letter at all (e.g.\ if it is a \LaTeX{} command), you
% \emph{must} define both capitalisation variants explicitly. Otherwise
% you will get strange and fatal errors when processing the document.
%
% The cross-reference \meta{type} is usually the name of the counter for
% the environment (equation, chapter, section, etc.). The exceptions are
% appendices, labels whose type has been overridden explicitly by
% supplying an optional argument (see \cref{sec:label_type}), and
% theorem-like environments when the \package{ntheorem} of
% \package{amsthm} packages are loaded, for which \meta{type} should
% instead be the environment name (lemma, corollary, definition, etc.)
% even when different environments are part of the same numbering
% sequence. (\package{ntheorem} and \package{amsthm} provide extra
% information about the environment when different theorem-like
% environments share a common counter, which \package{cleveref} makes use
% of to distinguish between them automatically.) In the case of
% appendices, the \meta{type} is ``appendix'' for the top-level
% sectioning command (|\chapter| or |\section|, depending on the document
% class), ``subappendix'' for the sectioning command one level below
% (|\section| or |\subsection|), ``subsubappendix'' for the next level of
% sectioning command, etc.
%
% For convenience, if they have not been otherwise customised by the end
% of the preamble, the cross-reference name (and label format) for
% |subsection| is by default inherited from that of |section|, and that
% of |subsubsection| is inherited from |subsection| (which might itself
% have been inherited from |section|). Similarly for |subappendix|,
% |subsubappendix| and |subsubsubappendix|. The |enumii|, |enumiii|,
% |enumiv| and |enumv| formats each inherit from the preceding one, with
% |enumii| inheriting from |enumi|. Finally, |subfigure|, |subtable| and
% |subequation| inherit from |figure|, |table| and |equation|,
% respectively.
%
% If some of the format components for one of these reference types have
% been customised using high-level customisation commands, any remaining
% components are inherited from the parent type, and the
% cross-reference formats are then defined in terms of those components.
% (In this case, if the format for the parent type has been customised
% using low-level commands, this low-level customisation will \emph{not}
% be inherited.) If \emph{none} of the format components have been
% customised, the whole format is always inherited from the parent type.
%
% \DescribeMacro\creflabelformat
% You may want the label format for a particular cross-reference type to
% differ from the global format set by |\crefdefaultlabelformat| (see
% \cref{sec:global_customisation}). You can do this using
% \begin{quote}
%   |\creflabelformat|\marg{type}\marg{format}
% \end{quote}
% The \meta{type} argument is the cross-reference type to customise, and
% the \meta{format} argument defines the label format for
% cross-references of that type. As in the case of\linebreak[4]
% |\crefdefaultlabelformat|, the latter should contain the three
% arguments |#1|, |#2| and |#3|, the first being the formatted version of
% the label counter, the others determining the beginning and end of the
% portion that becomes a hyperlink when the \package{hyperref} package
% is loaded (see \cref{sec:other_packages}). |#2| and |#3| \emph{must}
% appear in that order.
%
% \DescribeMacro\crefrangelabelformat
% Normally, the start and end references in a reference range are
% typeset using the usual label format (as defined by
% |\crefdefaultlabelformat| or |\creflabelformat|) separated by
% |\crefrangeconjunction| (\cref{sec:global_customisation}). You can
% override this for a given cross-reference type using
% \begin{quote}
%   |\crefrangelabelformat|\marg{type}\marg{format}
% \end{quote}
% The \meta{format} argument should contain six arguments: |#1|, |#2|,
% |#3|, |#4|, |#5|, |#6|. The first two (|#1| and |#2|) are the formatted
% versions of the two label counters defining the reference range. The
% next two (|#3| and |#4|) denote the beginning and end of the hyperlink
% for the first reference, the final two (|#5| and |#6|) the hyperlink
% for the second reference. The hyperlink arguments \emph{must} appear
% in order. For example,
% \begin{quote}
%   |\crefrangelabelformat{equation}{(#3#1#4) to~(#5#2#6)}|
% \end{quote}
%
%
% \subsubsection{Automatic \textbackslash\texttt{newtheorem} Definitions}
% \DescribeMacro\newtheorem
% The standard \LaTeX{} |\newtheorem| command for defining new
% theorem-like environments provides enough information to deduce a
% reasonable cross-reference name for the new environment. So
% \package{cleveref} automatically defines an appropriate cross-reference
% name for new theorem-like environments. This automatic definition is
% only used if no default definition is provided by \package{cleveref}
% itself, and if no |\crefname| or |\Crefname| definition is given
% explicitly (see \cref{sec:individual_customisation}).
%
% The caveat with this automatic definition is that, although
% |\newtheorem| essentially provides the singular form of the
% cross-reference name, it doesn't provide the plural form. And there is
% no reliable way of constructing the plural form from the
% singular.\footnote{If you're a native English-speaker, you might think
% that just adding an `s' would work, though a moment's thought will
% provide examples of words where this will fail. If you're a non-English
% speaker, it probably won't even occur to you to claim that plurals can
% reliably be constructed automatically!} Therefore, if the plural form
% is ever required, \package{cleveref} will produce a ``reference type
% undefined'' warning, and typeset the cross-reference where the plural
% form is required as:
% \begin{quote}
%   {\bf ??}~|\ref|\marg{label} \dots
% \end{quote}
% In this case, you will have to provide an explicit |\crefname| or
% |\Crefname| definition yourself, to define the plural form as well as
% the singular form.
%
% Note that this has \emph{nothing whatsoever} to do with automatically
% determining the type of theorem-like environment in a cross-reference!
% For that, you need to load either the \package{ntheorem} or the
% \package{amsthm} package. See \cref{sec:non-bugs} for more details.
%
%
%
% \subsection{Low-Level Customisation: Taking Full Control}
% \label{sec:low-level_customisation}
% If you need more precise control over the cross-reference format than
% is possible by customising the individual components, then you can take
% full control of the format for any given type, overriding the
% component-derived format entirely. The formats for single
% cross-references, reference ranges and multi-references are customised
% separately. If you only customise some of these, the other formats will
% be constructed from components, as usual.
%
% Note that when deciding which cross-references should be grouped
% together for sorting and/or compressing, \package{cleveref} does
% something slightly more complicated than simply checking whether the
% reference types match. In fact, it checks whether the reference
% \emph{formats} match.\footnote{To be precise, \package{cleveref} checks
% whether the $\backslash$|crefformat| definitions match.} This will
% always be the case for cross-references of the same type. But it could
% also be the case for cross-references that have different types, if the
% cross-reference formats happen to be identical.
%
% The reason for doing this is to allow cross-references to e.g.\
% sections and subsections to be grouped together if they have identical
% formats. The default formats for the sectioning commands, figures and
% subfigures, tables and subtables, and enumerated lists are set up in
% this way. If you change any of them using the low-level customisation
% commands, but still want them to be grouped together, then you must
% ensure that the formats are \emph{identical}. (It is \emph{not}
% sufficient for the formats to produce identical typeset text; the
% format definitions must contain identical \LaTeX{} code.)
%
% Note that if you use the low-level customisation commands, you might
% still want to provide |\crefname| and |\Crefname| definitions too, so
% that the |\namecref| commands will work (see \cref{sec:typesetting}).
%
%
% \subsubsection{Single Cross-References}
% \label{sec:ref_format}
% \DescribeMacro\crefformat
% \DescribeMacro\Crefformat
% Cross-reference formats for \emph{single} cross-references are defined
% or redefined using the |\crefformat| and |\Crefformat| commands, which
% are used by the |\cref| and |\Cref| commands respectively. These take
% two arguments: the cross-reference type, and the formatting code:
% \begin{quote}
%   |\crefformat|\marg{type}\marg{format}\\
%   |\Crefformat|\marg{type}\marg{format}
% \end{quote}
% The \meta{type} is usually the name of the counter, except for labels
% whose type has been overridden explicitly (see \cref{sec:label_type}),
% theorem-like environments \emph{when the \package{ntheorem} or
% \package{amsthm} package is loaded}, in which case it is the
% environment name, and appendices. For the latter, the \meta{type} is
% ``appendix'' for the top-level sectioning command (|\chapter| or
% |\section|, depending on the document class), ``subappendix'' for the
% sectioning command one level below (|\section| or |subsection|),
% ``subsubappendix'' for the next level of sectioning command, etc.
%
% As in the case of the |\crefname| and |\Crefname| commands, if the
% corresponding |\Crefformat| is undefined when |\crefformat| is called,
% it will define the |\Crefformat| to produce a capitalised version of
% |\crefformat|, using |\MakeUppercase|. Conversely, if the corresponding
% |\crefformat| is undefined when |\Crefformat| is called, it will define
% the |\crefformat| to produce a lower-case version of |\Crefformat|,
% using |\MakeLowercase|. Obviously, this will only work properly if the
% format starts with a letter, and letter constructs (such as accented
% letter constructs) must be surrounded by braces (see
% \cref{sec:global_customisation}).
%
% The \meta{format} argument can be any valid \LaTeX{} code, though you
% will need to |\protect| fragile commands. It should contain three
% arguments, |#1|, |#2| and |#3|. The first argument is the formatted
% version of the label counter (e.g.\ |\theequation|). The other two are
% used to mark the beginning and end of the part of the cross-reference
% that forms the hyperlink when the \package{hyperref} package is used,
% and \emph{must} appear in that order (see \cref{sec:other_packages}).
%
% As an example,
% \begin{quote}
%   |\crefformat{equation}{Eq.~(#2#1#3)}|
% \end{quote}
% will typeset equation references as
% \begin{quote}
%   Eq.~(\meta{counter})
% \end{quote}
% with the counter (excluding the parentheses) forming the hyperlink.
%
% Note that the hyperlink arguments are \emph{not} letters, so if |#2|
% appears at the beginning of \meta{format}, \package{cleveref} will not
% be able to automatically define the other capitalisation variant
% automatically using |\MakeUppercase| or |\MakeLowercase|. In this case,
% you will have to define both variants separately. For example, if you
% wanted the ``Eq.''\ to be part of the hyperlink, you would have to
% explicitly define:
% \begin{quote}
%   |\crefformat{equation}{#2eq.~(#1)#3}|\\
%   |\Crefformat{equation}{#2Eq.~(#1)#3}|
% \end{quote}
%
%
% \subsubsection{Reference Ranges}
% \label{sec:ref_range_format}
% \DescribeMacro\crefrangeformat
% \DescribeMacro\Crefrangeformat
% The format for reference ranges is defined by |\crefrangeformat|
% and\linebreak[4] |\Crefrangeformat|. Like |\creformat| and
% |\Crefformat|, the commands take two arguments: the cross-reference
% type, and the formatting code.
% \begin{quote}
%   |\crefrangeformat|\marg{type}\marg{format}\\
%   |\Crefrangeformat|\marg{type}\marg{format}
% \end{quote}
% The same comments apply as in the case of single cross-references: the
% \meta{type} is usually the name of the counter, except for appendices,
% labels with explicitly overridden types, and theorem-like environments
% when \package{ntheorem} or \package{amsthm} are loaded. Again, if the
% other-capitalisation variant is not already defined, it will be defined
% automatically.
%
% The \meta{format} argument can again be any valid \LaTeX{} code, with
% fragile commands |\protect|ed. However, this time it should contain
% \emph{six} arguments, |#1|--|#6|. The first two (|#1| and |#2|) are the
% formatted versions of the label counters, the next two (|#3| and |#4|)
% are used to mark the beginning and end of the hyperlink for the first
% cross-reference, and the final two (|#5| and |#6|) mark the beginning
% and end of the second cross-reference's hyperlink.
%
% As an example,
% \begin{quote}
%   |\crefrangeformat{equation}{eqs.~(#3#1#4) to~(#5#2#6)}|
% \end{quote}
% would typeset equation reference ranges as
% \begin{quote}
%   eqs.~(\meta{counter1}) to~(\meta{counter2})
% \end{quote}
% with the counters (excluding the parentheses) forming the hyperlinks.
%
%
% \subsubsection{Multiple Cross-References}
% \label{sec:multiple_ref_format}
% \DescribeMacro\crefmultiformat
% \DescribeMacro\Crefmultiformat
% \DescribeMacro\crefrangemultiformat
% \DescribeMacro\Crefrangemultiformat
% The format for multiple cross-references is defined by
% |\crefmultiformat| and\linebreak[4] |\Crefmultiformat|, and that of
% reference ranges within multiple cross-references by
% |\crefrangemultiformat| and |\Crefrangemultiformat|. Multi-references
% also require \emph{all} the other cross-reference formats to be defined
% (see \cref{sec:ref_format,sec:ref_range_format}), including the single
% reference range formats, even if you never use the |\crefrange| and
% |\Crefrange| commands.
%
% The commands all take five arguments: the cross-reference type, the
% format for the first cross-reference in a list, the format for the
% second cross-reference in a list of two, the format for the middle
% cross-references in a list of more than two, and the format for the
% last cross-reference in a list of more than two.
% \begin{quote}
%   |\crefmultiformat|\marg{type}\marg{first}\marg{second}\marg{middle}\marg{last}\\
%   |\Crefmultiformat|\marg{type}\marg{first}\marg{second}\marg{middle}\marg{last}\\
%   |\crefrangemultiformat|\marg{type}\marg{first}\marg{second}\marg{middle}\marg{last}\\
%   |\Crefrangemultiformat|\marg{type}\marg{first}\marg{second}\marg{middle}\marg{last}
% \end{quote}
%
% The \meta{type} is, as ever, the counter name (except for appendices,
% explicitly overridden label types, and theorem-like environments when
% the \package{ntheorem} or \package{amsthm} packages are loaded). The
% same considerations apply to the formatting arguments \meta{first},
% \meta{second}, \meta{middle} and \meta{last} as for the \meta{format}
% argument of |\crefformat| or |\crefrangeformat|, including the meaning
% of the arguments that should appear in the formatting code (|#1|, |#2|
% and |#3| for |\crefmultiformat| and |\Crefmultiformat|, |#1|--|#6| for
% |\crefrangemultiformat| and |\Crefrangemultiformat|). However, when the
% corresponding other-capitalisation variant is automatically defined,
% only the first letter of the \meta{first} argument is upper- or
% lower-cased; the other arguments are defined to be identical for both
% variants.
%
% Be careful to get the spaces at the beginning and end of the formatting
% code correct: the \meta{first} and \meta{second}, or \meta{first},
% \meta{middle} and \meta{last}, \LaTeX{} code snippets are typeset one
% after another in a multi-reference, with no space separating them. You
% may or may not want spaces at the beginning or end of the formatting
% code, depending on the formatting you desire. For example, in the
% default equation format:
% \begin{quote}
%   |\crefmultiformat{equation}{eqs.~(#2#1#3)}%|\\
%   |  { and~(#2#1#3)}{, (#2#1#3)}{ and~(#2#1#3)}|
% \end{quote}
% the \meta{middle} argument should \emph{not} have a space at the
% beginning, whereas the \meta{second} and \meta{last} arguments
% \emph{should} have a space.
%
%
% \subsubsection{Label Cross-References}
% If you define the format for a particular cross-reference type using
% the low-level customisation commands, and still want to use the
% |\labelcref| command to produce just the label part of the
% cross-reference, then you must also define the appropriate |\labelcref|
% formats for that type. This is done using the |\labelcrefformat|,
% |\labelcrefrangeformat|, |\labelcrefmultiformat| and
% |\labelcrefrangemultiformat| commands. Their syntax is identical to
% that of the corresponding |\crefformat|, |\crefrangmeformat|,
% |\crefmultiformat| or |\crefrangemultiformat| command. Typically, the
% |\labelcref| formats should be defined identically to the standard
% |\cref| formats, except for the \meta{first} part, which should leave
% off the cross-reference name. This is not enforced, however.
%
%
%
% \section{Advanced Cross-Reference Formating}
% When you define a custom cross-reference format using
% |\creflabelformat|, |\creformat| et al.\ (see \cref{sec:customising}),
% you're not merely defining a pattern with placeholders to be filled in.
% You're really defining the body of a LaTeX macro, with the formatted
% labels as arguments. This is a very powerful tool. It means that the
% only limit on how you can process the labels is your ability to code it
% in \TeX{}.\footnote{Since \TeX{} is Turing-complete, that means you
% can do anything you like short of solving the Halting Problem.} Which
% potentially allows for very sophisticated cross-reference formatting.
%
% One example of this is removing common prefixes from reference ranges.
% E.g.\ if you're numbering equations within sections, and |eq1|, |eq2|
% and |eq3| are all in the section 1.2, then you might want to typeset
% |\cref{eq1,eq2,eq3}| as ``eqs.~(1.2.1--3)'' instead of ``eqs.~(1.2.1)
% to~(1.2.3)''. Similarly, if |eq1a|, |eq1b| and |eq1c| are
% \package{amsmath} subequations, you might want to typeset
% |\cref{eq1a,eq1b,eq1c}| as ``eqs.~(1a--c)'' instead of ``eqs.~(1a)
% to~(1c)''.
%
% \package{Cleveref} provides a useful utility macro for this:
% |\crefstripprefix|, which takes two strings as arguments, and returns
% the second one with any common prefix stripped off. (However, the very
% last run of digits or letters in the string is retained in its
% entirety, even if it has a part in common.) With the help of this
% macro, you can produce the desired reference-range formatting with:
% \begin{quote}
%   |\crefrangelabelformat{equation}%|\\
%   |  {(#3#1#4--#5\crefstripprefix{#1}{#2}#6)}|\\
%   |\crefrangelabelformat{subequation}%|\\
%   | {(#3#1#4--#5\crefstripprefix{#1}{#2}#6)}|
% \end{quote}
%
% Similarly, stripping prefixes from multi-references so that e.g.\linebreak
% |\cref{fig1a,fig1b,fig1d}| is typeset as ``figs.~1a, b and d'' instead
% of ``figs.~1a, 1b and 1d'' can be achieved by passing the prefix from
% the first component to the others in an auxiliary macro (called
% |\crefstripprefixinfo| here):
% \begin{quote}
%   |\crefmultiformat{figure}%|\\
%   |  {\edef\crefstripprefixinfo{#1}figs.~#2#1#3}%|\\
%   |  { and~#2\crefstripprefix{\crefstripprefixinfo}{#1}#3}%|\\
%   |  {, #2\crefstripprefix{\crefstripprefixinfo}{#1}#3}%|\\
%   |  {, and~#2\crefstripprefix{\crefstripprefixinfo}{#1}#3}|
% \end{quote}
%
%
% \section{Language, \package{babel} and \package{polyglossia}
%             support}
% \label{sec:language_babel}
% \package{Cleveref} supports different languages via package options, in
% the usual way, though not all languages are supported
% yet.\footnote{Contributions of translations for missing languages are
% very welcome! See \cref{sec:new-features} for information on how to
% contribute translations.} Basic \package{cleveref} language support
% will work even if \package{babel} or \package{polyglossia} are not
% loaded. The only exception currently is Catalan (which requires the
% |\lgem| command provided by these packages).
%
% The \package{babel} package is fully supported if it is loaded,
% allowing you to change the language used in cross-references using the
% \package{babel} language switching commands, such as |\selectlanguage|
% and |\foreignlanguage|. Similar support is provided for the
% \package{polyglossia} babel replacement package.
%
% Note that when using \package{babel}, you still need to tell
% \package{cleveref} which language it should use for the default
% cross-reference formats. It is \emph{not} sufficient to pass the
% language option to \package{babel} alone. You \emph{must} also
% \emph{either} pass the language options to \package{cleveref} package
% directly when loading it:
% \begin{quote}
%   |\usepackage|\oarg{language}|{cleveref}|
% \end{quote}
% \emph{or} (better) specify the desired language globally as a document class
% option:
% \begin{quote}
%   |\documentclass|\oarg{language}\marg{class}\\
%   |\usepackage{babel}|\\
%   |\usepackage{cleveref}|\\
% \end{quote}
% The latter method is strongly recommended. \LaTeX{} automatically
% passes document class options to \emph{every} loaded package. So
% specifying the language as a global option causes the appropriate
% language support to be enabled automatically in every package that
% supports it.
%
% When writing multi-language documents, you may need to specify multiple
% language options in order to load \package{babel} support for all of
% them. In this case, \package{babel} sets the initial document language
% to the \emph{last} language option. (See the \package{babel}
% documentation for more details.) \package{Cleveref} does the same: the
% last language in the option list determines the language for the
% initial cross-reference format definitions; additional language options
% load \package{cleveref} support for switching between those languages.
%
% \package{Polyglossia} uses a different mechanism for selecting and
% loading languages, and ignores package language options entirely. The
% default language must be set using \cmd{\setdefaultlanguage}, and
% additional languages are loaded using \cmd{\setotherlanguage}.
% \package{Cleveref} recognises these commands, so you should \emph{not}
% pass language options to \package{cleveref} when using
% \package{polyglossia}. (Passing language options to \package{cleveref},
% either as package options or global options, will override the default
% language set by \package{polyglossia}'s \cmd{\setdefaultlanguage}.)
% Note that the |\setdefaultlanguage| option \emph{must} come before
% \package{cleveref} is loaded, so that \package{cleveref} knows what
% default language you want. (If you don't do this, \package{cleveref}
% will generate a warning message in the log.)
%
% The \package{babel} and \package{polyglossia} support works by
% redefining the cross-reference names and conjunctions for the default
% cross-reference types. Any customisations you make to the default
% cross-reference names and conjunctions \emph{in the preamble} apply to
% the main language (i.e.\ the last language listed in the options). A
% |\selectlanguage| \package{babel} command (or similar) in the document
% body will override these customisations, replacing them with the
% defaults for the newly selected language. If you later use
% |\selectlanguage| to switch back to the main language, any
% customisations from the preamble will be restored. If you want to
% customise cross-reference names or conjunctions for any language other
% than the main one, you either have to explicitly redefine them after
% every language switching command, or hook the redefinitions into
% \package{babel} or \package{polyglossia}'s language switching
% mechanism. (See section ``Language and \package{babel} Support'' in the
% full implementation documentation, and the \package{babel} or
% \package{polyglossia} package documentation.)
%
% If you have defined formats for new cross-reference types for which no
% defaults are provided, then you're on your own. \package{Cleveref} will
% not know how to redefine them for other languages, and again you will
% have to take care of it yourself, either by explicitly redefining them
% in your document after each language switch, or by hooking the
% redefinitions into \package{babel} or \package{polyglossia}'s language
% switching mechanisms.
%
% On the other hand, since the language switching commands only modify
% the cross-reference components, if you use the low-level customisation
% commands to take full control of the format for a particular
% cross-reference type, then (unless you're careful) you take it out of
% the control of \package{babel} or \package{polyglossia} entirely. If
% you want to use the low-level customisation commands, but \emph{do}
% still want the language switching commands to work, then you have to
% use the component macros in your customised formats. The
% cross-reference names are stored in macros called
% |\cref@|\meta{type}|@name|, |\Cref@|\meta{type}|@name|,
% |\cref@|\meta{type}|@name@plural|, and
% |\Cref@|\meta{type}|@name@plural|. (Note that since these
% macro names contain the ``@'' character, you must use |\makeatletter|
% and |\makeatother| to access them.)
%
% For example, if you wanted to redefine the equation format so that the
% cross-reference name (``equation'') was also part of the
% hyperlink,\footnote{This is merely as an example. Including names in
% hyperlinks is more easily accomplished by setting the
% \option{nameinlink} package option.} but you still want to be able to
% switch language using \package{babel} or \package{polyglossia}, you
% would need something like:
% \begin{quote}
%   |\makeatletter|\\
%   |\crefformat{equation}{#2\cref@equation@name~(#1)#3}|\\
%   \dots\\
%   |\makeatother|
% \end{quote}
% and similarly for |\crefrangeformat|, |\crefmultiformat|,
% |\Crefformat|, etc.
%
% Note that if you define an empty cross-reference name for some type
% using an empty |\crefname|, e.g.\ for equations
% \begin{quote}
%   |\crefname{equation}{}{}|
% \end{quote}
% then the empty cross-reference name will be retained when switching
% languages. This is probably what you want anyway.
%
%
%
% \section{The \file{cleveref.cfg} File}
% If \package{cleveref} finds a \file{cleveref.cfg} file somewhere in the
% \LaTeX{} search path, it automatically loads any definitions found in
% that file. (For details of which directories \LaTeX{} searches, consult
% the documentation for your site's \TeX{} installation.) The main use of
% \file{cleveref.cfg} is to store any cross-reference format
% customisations that you want to use in every document you write, so
% that you don't have to include them explicitly in every document's
% preamble.
%
%
%
% \section{Poor Man's \package{cleveref}}
% Sometimes you may need to send your \LaTeX{} source to someone who
% can't or won't install the \package{cleveref} package themselves. For
% example, many academic journals accept papers in \LaTeX{} format, but
% only support a small subset of the packages available on CTAN. The
% \option{poorman} option was designed specifically to help in this
% situation.
%
% When the \option{poorman} option is supplied, your document will be
% processed as normal. But in addition, a |sed| script will automatically
% be written, containing rules for replacing all the \package{cleveref}
% commands with the \LaTeX{} code that they would produce, and using the
% standard |\ref| command to produce the cross-references themselves.
% I.e.\ the script rewrites your document as you would have done if you
% had had to do it manually!
%
% The advantage, of course, is that you \emph{don't} have to do it
% manually. Instead, you can use all the features of \package{cleveref},
% and once you've created a version of your document that you want to
% send elsewhere, you can process it through the |sed| script to
% completely remove the \package{cleveref} dependency. The recipient
% won't even realise you used \package{cleveref}!
%
% The |sed| script is written to the same directory as the (main)
% \LaTeX{} source file, and given the same name as that source file but
% with the extension \file{.sed}. To process your document through the
% script, all you need to do is run the following from your shell:
% \begin{quote}
%   sed -f \meta{name}\file{.sed} \
%   \meta{name}\file{.tex} \textgreater \meta{newname}\file{.tex}
% \end{quote}
% where \meta{name} is the name of the file containing your \LaTeX{}
% source file minus the \file{.tex} extension, and \meta{newname} is
% whatever you want to call the new version. \emph{Do not} make
% \meta{newname} the same as \meta{name}: it won't work. (It's in any
% case wise to keep the original \LaTeX{} source file containing the
% \package{cleveref} commands, in case you need to produce an updated
% version of your document in the future. Think of the
% \meta{newname}\file{.tex} file in the same way as a \file{DVI} file:
% something you can always reproduce from the original source.)
%
% If your document is composed of a number of separate \LaTeX{} source
% files, combined with |\include| commands, only one |sed| script will be
% generated, but you will need to run \emph {each} source file through
% that \emph{same} script (and probably modify the |\include| commands to
% match the new file names). However, using \package{babel}'s language
% switching commands in a document split across multiple separate source
% files is beyond the capabilities of the \package{poorman} option. You
% will almost certainly need to manually tweak the |sed| script in that
% case.
%
% Note that the \option{poorman} script cannot fully reproduce the
% typesetting of the original \package{cleveref} cross-references in all
% cases.\footnote{At least, not without resorting to inserting low-level
% \LaTeX{} code in your document, which would somewhat defeat the purpose
% of the \option{poorman} option.} In particular, if you're using the
% \package{hyperref} package (see \cref{sec:other_packages}) to turn
% cross-references into hyperlinks, any customisation of hyperlinks will
% be lost. And if you're using the \package{varioref} package (see
% \cref{sec:other_packages}), you may need to manually tweak the spacing
% in front of some of the \package{varioref} commands in the document
% produced by the |sed| script.
%
%
%
% \section{Interaction with Other Packages}
% \label{sec:other_packages}
% The \package{cleveref} package \emph{must} be loaded \emph{after} all
% other packages that don't specifically support it,\footnote{At the time
% of writing, the only packages I'm aware of that should be loaded after
% \package{cleveref} are the \package{hypdvips} and \package{autonum}
% packages.} i.e.\ the
% \begin{quote}
%   |\usepackage{cleveref}|
% \end{quote}
% line should usually be the last |\usepackage| command in your
% document's preamble.
%
% \package{Cleveref} tries as far as possible to minimise its impact on
% the standard \LaTeX{} cross-referencing machinery, allowing it to work
% alongside many of the other packages that also enhance \LaTeX{}'s
% cross-referencing features, though it can occasionally interact badly
% with packages that redefine the same core \LaTeX{} commands. Beyond
% peacefully co-existing with many packages, \package{cleveref} includes
% specific support for a number other packages, allowing it to integrate
% its clever cross-referencing features with the features provided by
% these packages: \package{babel}, \package{polyglossia},
% \package{hyperref}, \package{varioref}, \package{ntheorem},
% \package{amsthm}, \package{aliascnt}, \package{subfig},
% \package{algorithmicx}\footnote{The \package{algorithmic} package is
% \emph{not} supported.}, \package{algorithm2e}, \package{listings}.
%
% \package{Cleveref} implements a significantly enhanced version of the
% features found in the \package{fancyref} package, \package{ntheorem}'s
% \option{thref} option, and \package{varioref}'s |\labelformat| command.
% Although these features may (or may not) work correctly alongside
% \package{cleveref}, there is no good reason to use them when using
% \package{cleveref}, and their use is unsupported. (Note that
% \package{varioref} \emph{is} fully supported by \package{cleveref},
% just that \package{cleveref}'s features supersede \package{varioref}'s
% |\labelformat| feature. Similarly, \package{ntheorem} is fully supported
% and even recommended, only the \option{thref} option is superseded by
% \package{cleveref}.)
%
% \DescribeMacro{\thref}
% \DescribeMacro{\vref}
% \DescribeMacro{\Vref}
% \DescribeMacro{\vrefrange}
% \DescribeMacro{\Vrefrange}
% \DescribeMacro{\fullref}
% \DescribeMacro{\Fullref}
% In fact, if \package{ntheorem} is loaded with the \option{thref}
% option, \package{cleveref} redefines \package{ntheorem}'s |\thref|
% command for you, to be an alias for |\cref|. Similarly, if
% \package{varioref} is loaded, \package{cleveref} redefines the |\vref|,
% |\vrefrange|, |\fullref| commands and variants to instead use the
% \package{cleveref} features for cross-reference formatting, whilst
% retaining all the \package{varioref} page-referencing magic. You can
% continue to use the other \package{varioref} and \package{ntheorem}
% commands (other than |\labelformat| and the \option{thref} option)
% whilst using \package{cleveref}, as long as \package{cleveref} is
% loaded \emph{last}.
%
% \DescribeMacro{\vref*}
% \DescribeMacro{\Vref*}
% \DescribeMacro{\vrefrange*}
% \DescribeMacro{\Vrefrange*}
% \DescribeMacro{\fullref*}
% \DescribeMacro{\Fullref*}
% Note that, whilst in the business of redefining the \package{varioref}
% commands, \package{cleveref} seizes the opportunity to get rid of the
% irritating spacing behaviour of the |\vref| and |\Vref| commands,
% instead making it consistent with the other \package{cleveref}
% cross-referencing commands. This also frees up the starred variants of
% the \package{varioref} commands to be used for suppressing hyperlinks
% when the \package{hyperref} package is loaded, as usual.
% (Unfortunately, due to lack of support for this in \package{varioref},
% the page references will still sometimes be hyperlinks, even when using
% the starred variants. Go bug the \package{varioref} maintainer about
% this if you don't like it.)
%
% \package{Cleveref} is currently incompatible with the
% \package{mathtools} package's\linebreak[4] \option{showonlyrefs}
% option, which automatically labels only those equations that are
% cross-referenced. The \package{autonum} package provides a possible
% alternative, which implements similar features in a
% \package{cleveref}-compatible manner.
%
%
%
% \section{Known Bugs, Non-Bugs, and Possible Improvements}
% \label{sec:known_bugs}
%
% \subsection{Non-Bugs}\label{sec:non-bugs}
% The following are \emph{not} bugs. They are either intentional
% behaviour, unavoidable behaviour, or are caused by \LaTeX{}
% misunderstandings:
% \begin{itemize}
% \item If you are using both \package{varioref} and \package{hyperref},
%   \emph{make sure you are loading them in the correct order}, otherwise
%   cross-references will reference completely the wrong thing
%   \emph{without any warning in the \LaTeX{} output or log!} The
%   packages \emph{must} be loaded in the following order:
%   \package{varioref}, \package{hyperref}, \package{cleveref}.
% \item \package{Cleveref} on its own won't automatically infer the type
%   of theorem-like environment you're referring to in a cross-reference.
%   Cross-references to all theorem-like environments will use the same
%   name, ``theorem''. To allow the theorem type to be determined
%   automatically, you need to load either the \package{ntheorem} or the
%   \package{amsthm} package. Also note that all |\newtheorem|
%   definitions must be placed \emph{after} the \package{cleveref}
%   package is loaded.
% \item Due to the way \TeX{} parses arguments, you have to be a little
%   careful when using |\label| inside an optional argument to another
%   command. |\label|\marg{label} will work, but trying to pass an
%   optional argument |\label|\oarg{type}\marg{label} will fail. If you
%   want to pass an optional argument to |\label| whilst already within
%   an optional argument to some other command, you must surround the
%   entire label command with braces:
%   |{\label|\oarg{type}\marg{label}|}|. This crops up e.g.\ when adding
%   labels to subfigure subcaptions in the \package{memoir} document
%   class. A simpler solution in this particular case is to define the
%   label in the subfigure body, instead of in the subcaption.
% \item \package{Cleveref} will not work properly with the standard
%   \LaTeX{} |eqnarray| environment. There is no intention to fix this.
%   The |eqnarray| environment is poorly implemented, making it difficult
%   to get it to work properly with \package{cleveref}, and it's broken
%   any way. You're \emph{far} better off using the \package{amsmath}
%   replacements, such as |gather|, |align|, |multline| and |split|,
%   which \emph{do} work properly with \package{cleveref}. (See
%   \url{http://www.tug.org/pracjourn/2006-4/madsen/}).
% \item If you are using \package{babel}, you \emph{must still} pass the
%   appropriate language option to \package{cleveref}, as well as to
%   \package{babel}. Passing it to \package{babel} alone is \emph{not}
%   sufficient (you will get the default English cross-reference
%   formats). The best way to set the document language is as a global
%   option in the |\documentclass| line. (This is standard \LaTeX{} and
%   \package{babel} practice -- read up on \LaTeX{}'s option handling for
%   more detail.)
% \item \package{Cleveref} can't cope with active characters being
%   present in cross-reference label names. For example, if French
%   \package{babel} support is loaded, the commonly used ``:'' in label
%   names will often fail, spewing the usual random selection of
%   mysterious \TeX{} errors that accompany such deep-seated errors. The
%   solution is to avoid using active characters in label names. (You may
%   need to consult the \package{babel} documentation to discover which
%   active characters are defined in your language.)
% \item The \option{poorman} |sed| script loses any custom
%   \package{cleveref} hyperlink formatting you might have defined, and
%   does not always reproduce the original spacing around the
%   \package{varioref} commands when \package{varioref} is used. This is
%   not a bug; it is a side-effect of the intended purpose of the
%   \option{poorman} option. The philosophy behind \option{poorman} is to
%   replace \package{cleveref}'s enhanced cross-referencing with standard
%   \LaTeX{} cross-reference commands that are guaranteed to work with
%   any standard \LaTeX{} installation. Although it would be simple to
%   fix these ``bugs'', it's almost certainly impossible without using
%   low-level \LaTeX{} code that is unlikely to be supported by e.g.\
%   academic journals, thereby defeating the whole purpose of the
%   \option{poorman} option.
% \end{itemize}
%
%
% \subsection{Known Bugs and Work-Arounds}
% In rough order of significance:
% \begin{itemize}
% \item When both the \package{amsmath} \emph{and} \package{hyperref}
%   packages are loaded at the same time, the \package{cleveref}
%   cross-referencing commands do not work when used within section
%   titles. If anyone can figure out why, let me know! As a work-around,
%   use |\ref| within section titles when your document uses both
%   \package{amsmath} and \package{hyperref}.
% \item When using \package{varioref} and \package{hyperref} with
%   \package{cleveref}, the \package{cleveref}\linebreak[4]
%   \option{nameinlink} option will not cause the word ``page'' in the
%   page-reference part of a |\vref| (or other \package{varioref})
%   command to be included in the hyperlink, nor will the ``on the
%   previous page'' (or similar) text produced by |\vref| be hyperlinked.
%   This is not strictly speaking a \package{cleveref} issue. It is the
%   normal behaviour of the \package{hyperref}-enhanced version of
%   \package{varioref}'s |\vpageref| command, which \package{cleveref}
%   uses to produce the page references in its enhanced |\vref| command.
%   (This \emph{might} be improved in a future version by partially
%   overriding \package{hyperref}.)
% \item \package{Cleveref} doesn't know about the \package{subfloat}
%   package, so you have to revert to using |\ref| for cross-references
%   to sub-figures. (Might be fixed in a future version.)
% \item The \package{beamer} document class redefines the |\label|
%   command in a particularly devious way that breaks
%   \package{cleveref}'s optional argument to that command. (Might be
%   fixed in a future version.)
% \item \package{Cleveref} is incompatible with the \option{showonlyrefs}
%   option of the \package{mathtools} package, though it should be
%   compatible with the rest of \package{mathtools}. (Might be fixed in a
%   future version.) The \package{autonum} package, which provides
%   similar functionality and \emph{is} designed to be
%   \package{cleveref}-compatible, is a possible alternative.
% \item \package{Cleveref} assumes that counters are only ever reset by
%   the standard sectioning commands (|\chapter|, |\section|, etc.). If
%   this is not the case, the automatic compression of consecutive
%   cross-references into a reference range may be incorrect. Making this
%   more flexible would be a simple task, but so far there doesn't seem
%   to be much need for it.
% \end{itemize}
%
%
% \subsection{Possible New Features and Improvements}
% \label{sec:new-features}
% In no particular order:
% \begin{itemize}
% \item The \option{poorman} option could be enhanced to allow a choice
%   of scripting language rather than just |sed| (e.g.\ |awk|, |perl|,
%   \dots?), but these are unlikely to be much better for those apt to
%   complain about the use of |sed|. The portable option would be to
%   output a \TeX{} ``script'', but this would be \emph{much} more
%   work\footnote{\LaTeX{} \emph{really} isn't suited to that kind of
%   pattern matching task -- just take a look at the code for escaping
%   regexp special characters in this package!} than I'm prepared to
%   invest.
% \item \package{Cleveref} doesn't include support for all languages yet.
%   Any contributions of translations for missing languages are most
%   welcome! If you can contribute definitions for a missing language,
%   ideally you should add them below the existing ones in the
%   implementation (using those as a model), generate a patch against the
%   original \package{cleveref.dtx} file, and send the patch by email to
%   the package author. However, if you don't know how to produce a
%   patch, you can instead just send the translations as a plain text
%   file.
% \end{itemize}
%
%
%
% \section{Thanks}
% A number of people have helped improve \package{cleveref} by
% contributing code and translations. Thanks to Michael Ummels for
% contributing the \package{amsthm} support code, and to Stefan Pinnow,
% Gonzalo Medina, Massimo Redaelli, Philip H\"olzenspies, Aleksander
% Gorohovski, Benjamin H{\o}yer, Johannes Mueller, Paulo Roberto Massa
% Cereda, Simon Sigurdhsson, Rafel Jaume Dey\`a and Eva Bosch Roura for
% contributing translations. Thanks also to Susanna Goldschmidt for
% additional help with the translations.
%
% Many people have suggested improvements or reported bugs -- indeed,
% many have put significant effort into helping investigate and fix them.
% So thanks (in alphabetical order) to: Adrian Knoth, Akim Demaille, Alan
% Munn, Aleksander Gorohovski, Amar Ghaisas, Anand Deopurkar, Andreas
% Haselbacher, Arne Meier, Bas Ploeger, Christian Tuma, Dan Luecking,
% David Gleich, Davide Liessi, Denis Bitouz\'e, Domenic Denicola, Donald
% Ars\-en\-eau, Eric Ahlberg, Frank Mittlebach, Hendrik Maryns, Iain
% Cunningham, Ingolf Becker, James Sharam, Jens Mueller, Joel C.\
% Salomon, Jonas Nyrup, Joris Pinkse, Kristian Debrabant, Leo Shidai Liu,
% Lev Bishop, Mak Trifkovic, Mark Cipolone, Matej Batic, Matt Gately,
% Matthew Skala, Michael Barber, Michael Gorven, Michal Kaut, Mico
% Loretan, Milania, Nicolas Dudebout, Olivier Roy, Patrick H\"acker, Paul
% Gomme, Ricardo de Aldama S\'anchez, Robert Fischer, Sebastian
% \O{}rsted, Simon Spiegel, Stefan Pinnow, Steve Dower, Ted Pavlic,
% Thomas Arildsen, Tobias Jores, Uwe L\"uck and Vadim Makarov for their
% help.
% (If I've inadvertently missed you out, please let me know!)
%
%
% \StopEventually{\clearpage\PrintChanges\clearpage\PrintIndex}
%
%
% \clearpage
% \section{Implementation}
% Essentially, the core of the implementation consists of writing an
% extra piece of information --- the label ``type'' --- to the \file{aux}
% file, and defining \cmd{\cref} commands which use this extra
% information to typeset the cross-reference.
%
% The least invasive previous implementation of this kind of thing seems
% to be that used by the \package{varioref} package. Namely, to redefine
% the \cmd{\refstepcounter} command so that the \cmd{\@currentlabel}
% macro, which usually just contains the typeset version of the counter,
% now contains the additional type information.
%
% However, even less invasive than \package{varioref}'s implementation is
% to leave \cmd{\@currentlabel} alone, and define a new
% \cmd{\cref@currentlabel} macro to hold the extra information. (In fact,
% we store three extra pieces of information: the type, the counter value
% itself, and the value of the counter that causes the label's counter to
% be reset, which we call the ``prefix'' from now on.) The standard
% \cmd{\@currentlabel} contents eventually get written to the \file{aux}
% file as an argument to \cmd{\newlabel} by the usual \LaTeX{} label
% mechanisms. In order to also get the information in
% \cmd{\cref@currentlabel} into the \file{aux} file, we have to redefine
% the \cmd{\label} macro so that it writes \emph{two} \cmd{\newlabel}
% lines to the \file{aux} file for \emph{each} label: the standard one,
% plus an additional one which contains the extra information in
% \cmd{\cref@currentlabel}. The additional \cmd{\newlabel} line has the
% suffix |@cref| added to the label name. Thus the extra information in
% \cmd{\cref@currentlabel} will end up in \cmd{\r@\meta{label}@cref} when
% the \file{aux} file is re-read on the next pass.
%
% Doing things this way involves less hacking to get everything else
% working again, since the standard cross-reference mechanism and
% \cmd{\ref} command are left entirely intact. \package{Cleveref} can
% then do what it likes with its own parallel set of labels, without
% getting in the way of other packages that play around with the
% cross-reference mechanism. The only downside is the additional memory
% resources this uses, but on modern \TeX{} implementations this is
% unlikely to be a problem.
%
%
% \subsection{Redefinitions of \LaTeX{} Kernel Macros}
% \begin{macro}{\refstepcounter}
% \begin{macro}{\cref@currentlabel}
% \begin{macro}{\cref@old@refstepcounter}
%   We store the original \cmd{\refstepcounter} in
%   \cmd{\cref@old@refstepcounter}, then redefine \cmd{\refstepcounter}
%   so that it first calls the old version to define the standard
%   \cmd{\@currentlabel} macro, before defining \package{cleveref}'s
%   \cmd{\cref@currentlabel}, which contains the extra information. The
%   cross-reference ``type'' stored in \cmd{\cref@currentlabel} is usually
%   inferred from the counter. This can be overridden by aliasing the
%   counter name to a different type using \cmd{\crefalias}. The new
%   \cmd{\refstepcounter} can also take an optional argument, which
%   always overrides the type.
%    \begin{macrocode}
\def\cref@currentlabel{}%
\let\cref@old@refstepcounter\refstepcounter%
\def\refstepcounter{%
  \@ifnextchar[{\refstepcounter@optarg}{\refstepcounter@noarg}%]
}%
\def\refstepcounter@noarg#1{%
  \cref@old@refstepcounter{#1}%
  \cref@constructprefix{#1}{\cref@result}%
  \@ifundefined{cref@#1@alias}%
    {\def\@tempa{#1}}%
    {\def\@tempa{\csname cref@#1@alias\endcsname}}%
  \protected@edef\cref@currentlabel{%
    [\@tempa][\arabic{#1}][\cref@result]%
    \csname p@#1\endcsname\csname the#1\endcsname}}%
\def\refstepcounter@optarg[#1]#2{%
  \cref@old@refstepcounter{#2}%
  \cref@constructprefix{#2}{\cref@result}%
  \@ifundefined{cref@#1@alias}%
    {\def\@tempa{#1}}%
    {\def\@tempa{\csname cref@#1@alias\endcsname}}%
  \protected@edef\cref@currentlabel{%
    [\@tempa][\arabic{#2}][\cref@result]%
    \csname p@#2\endcsname\csname the#2\endcsname}}%
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
%
%
% \begin{macro}{\label}
% \begin{macro}{\cref@label}
% \begin{macro}{\label@optarg}
% \begin{macro}{\label@noarg}
%   We redefine the \cmd{\label} command to make it define \emph{two}
%   labels each time it's called: the standard one, and an additional
%   \package{cleveref}-specific one with the suffix |@cref| added to the
%   label name, which contains the extra information from
%   \cmd{\cref@currentlabel}. We call the original \cmd{\label} command,
%   stored in \cmd{\cref@old@label}, to write the standard label to the
%   \file{aux} file. However, to avoid other packages messing around with
%   the content of the parallel set of \package{cleveref}-specific
%   labels, we write those directly to the \file{aux} file ourselves. We
%   also allow \cmd{\label} to take an optional argument which overrides
%   the default reference type in \cmd{\cref@currentlabel}.
%
%   The redefinition of \cmd{\label} has to be postponed until the
%   beginning of the document because some other packages postpone their
%   own \cmd{\label} redefinitions too, and we need to override their
%   redefinitions.
%    \begin{macrocode}
\AtBeginDocument{%
  \let\cref@old@label\label%
  \def\label{\@ifnextchar[\label@optarg\label@noarg}%]
  \let\cref@label\label%
  \def\label@noarg#1{%
    \cref@old@label{#1}%
    \@bsphack%
    \edef\@tempa{{page}{\the\c@page}}%
    \setcounter{page}{1}%
    \edef\@tempb{\thepage}%
    \expandafter\setcounter\@tempa%
    \cref@constructprefix{page}{\cref@result}%
    \protected@write\@auxout{}%
      {\string\newlabel{#1@cref}{{\cref@currentlabel}%
      {[\@tempb][\arabic{page}][\cref@result]\thepage}}}%
    \@esphack}%
  \def\label@optarg[#1]#2{%
    \cref@old@label{#2}%
    \@bsphack%
    \edef\@tempa{{page}{\the\c@page}}%
    \setcounter{page}{1}%
    \edef\@tempb{\thepage}%
    \expandafter\setcounter\@tempa%
    \cref@constructprefix{page}{\cref@result}%
    \protected@edef\cref@currentlabel{%
      \expandafter\cref@override@label@type%
        \cref@currentlabel\@nil{#1}}%
    \protected@write\@auxout{}%
      {\string\newlabel{#2@cref}{{\cref@currentlabel}%
      {[\@tempb][\arabic{page}][\cref@result]\thepage}}}%
    \@esphack}%
}% end of AtBeginDocument
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
%
%
% \begin{macro}{\@makefntext}
%   Footnotes don't use the \cmd{\refstepcounter} mechanism, but instead
%   set\linebreak[4] \cmd{\@currentlabel} directly inside the footnote
%   insertion item. Thus we need to explicitly set
%   \cmd{\cref@currentlabel} in footnotes. To avoid the definition
%   spilling out of the footnote, we need to set it inside
%   \cmd{\insert}'s implicit insertion item grouping level. To this end,
%   we add the explicit \cmd{\cref@currentlabel} redefinition to
%   \cmd{\@makefntext}, which gets called from within \cmd{\insert} by
%   both \cmd{\@footnotetext} and \cmd{\@mpfootnotentext}.
%    \begin{macrocode}
\let\cref@old@makefntext\@makefntext%
\long\def\@makefntext{%
  \cref@constructprefix{footnote}{\cref@result}%
  \protected@edef\cref@currentlabel{%
    [footnote][\arabic{footnote}][\cref@result]%
    \p@footnote\@thefnmark}%
  \cref@old@makefntext}%
%    \end{macrocode}
% \end{macro}
%
%
% \begin{macro}{\newtheorem}
%   A \cmd{\newtheorem} command provides sufficient information to
%   automatically define a reasonable cross-reference name for
%   theorem-like environments (\package{ntheorem}'s \option{thref} does
%   essentially this). So we modify \cmd{\newtheorem} (actually, the
%   lower-level \cmd{\@othm}, \cmd{\@xnthm} and \cmd{\@ynthm} macros) so
%   that it does so. We do this in such a way that default definitions or
%   explicit \cmd{\crefname} definitions for theorem-like environments
%   override those produced automatically by our modified
%   \cmd{\newtheorem}.
%
%   The catch is that, although the \cmd{\newtheorem} command provides
%   the singular form, there's no way of reliably deducing the correct
%   plural form. Rather than implement some half-baked attempt at this
%   which will be wrong more often than it's right (especially in
%   languages other than English) and generally cause more trouble than
%   it's worth, we simply define the singular form but leave the plural
%   form undefined. If the latter is ever needed, it will produce a
%   ``undefined cross-reference type'' warning, prompting the author to
%   provide an appropriate \cmd{\crefname} definition themselves.
%
% \begin{macro}{\@othm}
% \begin{macro}{\@xnthm}
% \begin{macro}{\@ynthm}
%   After sorting out its arguments, \cmd{\newtheorem} calls one of
%   \cmd{\@othm}, \cmd{\@xthm} or \cmd{\@ythm}. We add automatic
%   definitions of \cmd{\cref@\meta{type}@name} and\linebreak[4]
%   \cmd{\Cref@\meta{type}@name} to all three of these, and add the
%   theorem-like environment to the list of cross-reference types that
%   need to be defined from components at |\||begin{document}|. Since we
%   want explicit \cmd{\crefname}'s to override these automatic
%   definitions, we store the definitions in
%   \cmd{\cref@\meta{type}@name@preamble}, which are processed at
%   |\||begin{document}|) if they haven't been overridden. The default
%   definitions also get stored in \cmd{\cref@\meta{type}@name@preamble}
%   later on, so they too will override these automatic definitions,
%   which is what we want.
%
%   All this means that these automatic \cmd{\newtheorem} definitions
%   will only work when \cmd{\newtheorem} is used in the preamble.
%   However, this is also true of (new) cross-reference types defined
%   using \cmd{\crefname}, so it doesn't seem worth the significant
%   effort of getting the automatic definitions to work within the
%   document body.
%    \begin{macrocode}
\let\cref@old@othm\@othm%
\def\@othm#1[#2]#3{%
  \edef\@tempa{\expandafter\noexpand%
    \csname cref@#1@name@preamble\endcsname}%
  \edef\@tempb{\expandafter\noexpand%
    \csname Cref@#1@name@preamble\endcsname}%
  \def\@tempc{#3}%
  \ifx\@tempc\@empty\relax%
    \expandafter\gdef\@tempa{}%
    \expandafter\gdef\@tempb{}%
  \else%
    \if@cref@capitalise%
      \expandafter\expandafter\expandafter\gdef\expandafter%
        \@tempa\expandafter{\MakeUppercase #3}%
    \else%
      \expandafter\expandafter\expandafter\gdef\expandafter%
        \@tempa\expandafter{\MakeLowercase #3}%
    \fi%
    \expandafter\expandafter\expandafter\gdef\expandafter%
      \@tempb\expandafter{\MakeUppercase #3}%
  \fi%
  \cref@stack@add{#1}{\cref@label@types}%
  \cref@old@othm{#1}[#2]{#3}}%
\let\cref@old@xnthm\@xnthm%
\def\@xnthm#1#2[#3]{%
  \edef\@tempa{\expandafter\noexpand%
    \csname cref@#1@name@preamble\endcsname}%
  \edef\@tempb{\expandafter\noexpand%
      \csname Cref@#1@name@preamble\endcsname}%
  \def\@tempc{#2}%
  \ifx\@tempc\@empty\relax%
    \expandafter\gdef\@tempa{}%
    \expandafter\gdef\@tempb{}%
  \else%
    \if@cref@capitalise%
      \expandafter\expandafter\expandafter\gdef\expandafter%
        \@tempa\expandafter{\MakeUppercase #2}%
    \else%
      \expandafter\expandafter\expandafter\gdef\expandafter%
        \@tempa\expandafter{\MakeLowercase #2}%
    \fi%
    \expandafter\expandafter\expandafter\gdef\expandafter%
      \@tempb\expandafter{\MakeUppercase #2}%
  \fi%
  \cref@stack@add{#1}{\cref@label@types}%
  \cref@old@xnthm{#1}{#2}[#3]}%
\let\cref@old@ynthm\@ynthm%
\def\@ynthm#1#2{%
  \edef\@tempa{\expandafter\noexpand%
    \csname cref@#1@name@preamble\endcsname}%
  \edef\@tempb{\expandafter\noexpand%
      \csname Cref@#1@name@preamble\endcsname}%
  \def\@tempc{#2}%
  \ifx\@tempc\@empty\relax%
    \expandafter\gdef\@tempa{}%
    \expandafter\gdef\@tempb{}%
  \else%
    \if@cref@capitalise%
      \expandafter\expandafter\expandafter\gdef\expandafter%
        \@tempa\expandafter{\MakeUppercase #2}%
    \else%
      \expandafter\expandafter\expandafter\gdef\expandafter%
        \@tempa\expandafter{\MakeLowercase #2}%
    \fi%
    \expandafter\expandafter\expandafter\gdef\expandafter%
      \@tempb\expandafter{\MakeUppercase #2}%
  \fi%
  \cref@stack@add{#1}{\cref@label@types}%
  \cref@old@ynthm{#1}{#2}}%
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
%
%
% \begin{macro}{\appendix}
%   The \cmd{\appendix} command causes the top-level sectioning commands
%   (\cmd{\chapter} or \cmd{\section}, depending on the document class)
%   to produce appendices instead. Since we want to be able to format
%   references to appendices separately from references to normal
%   top-level sections, we add to the tasks that \cmd{\appendix} does: it
%   redefines \cmd{\refstepcounter@noarg} to exceptionally override the
%   label type for chapters or sections, as appropriate, setting it to
%   ``appendix'' instead. There are two alternative definitions: one if
%   ``section'' is the top-level sectioning command, and one if
%   ``chapter'' fulfils that role.
%    \begin{macrocode}
\@ifundefined{appendix}{}{%
  \let\cref@old@appendix\appendix%
  \def\appendix{%
    \@ifundefined{chapter}{%
      \gdef\refstepcounter@noarg##1{%
        \cref@old@refstepcounter{##1}%
        \cref@constructprefix{##1}{\cref@result}%
%    \end{macrocode}
%     We add a large value to the front of the counter data, to force
%     references to anything in appendices to be sorted after everything
%     else.
%    \begin{macrocode}
        \ifx\cref@result\@empty%
          \def\cref@result{2147483647}%
        \else%
          \edef\cref@result{2147483647,\cref@result}%
        \fi%
%    \end{macrocode}
%       Override the cross-reference type of sectioning commands.
%    \begin{macrocode}
        \def\@tempa{##1}%
        \def\@tempb{section}%
        \ifx\@tempa\@tempb%
          \@ifundefined{cref@appendix@alias}%
            {\def\@tempa{appendix}}%
            {\def\@tempa{\cref@appendix@alias}}%
          \protected@edef\cref@currentlabel{%
            [\@tempa][\arabic{##1}][\cref@result]%
            \csname p@##1\endcsname\csname the##1\endcsname}%
        \else%
          \def\@tempa{##1}%
          \def\@tempb{subsection}%
          \ifx\@tempa\@tempb%
            \@ifundefined{cref@subappendix@alias}%
              {\def\@tempa{subappendix}}%
              {\def\@tempa{\cref@subappendix@alias}}%
            \protected@edef\cref@currentlabel{%
              [\@tempa][\arabic{##1}][\cref@result]%
              \csname p@##1\endcsname\csname the##1\endcsname}%
          \else%
            \def\@tempa{##1}%
            \def\@tempb{subsubsection}%
            \ifx\@tempa\@tempb%
              \@ifundefined{cref@subsubappendix@alias}%
                {\def\@tempa{subsubappendix}}%
                {\def\@tempa{\cref@subsubappendix@alias}}%
              \protected@edef\cref@currentlabel{%
                [\@tempa][\arabic{##1}][\cref@result]%
                \csname p@##1\endcsname\csname the##1\endcsname}%
            \else%
              \@ifundefined{cref@##1@alias}%
                {\def\@tempa{##1}}%
                {\def\@tempa{\csname cref@##1@alias\endcsname}}%
              \protected@edef\cref@currentlabel{%
                [\@tempa][\arabic{##1}][\cref@result]%
                \csname p@##1\endcsname\csname the##1\endcsname}%
            \fi%
          \fi%
        \fi}%
      \cref@old@appendix%
    }{%
      \def\refstepcounter@noarg##1{%
        \cref@old@refstepcounter{##1}%
        \cref@constructprefix{##1}{\cref@result}%
%    \end{macrocode}
%     Again, the large value added to the front of the counter data forces
%     references to appendix items to be sorted last.
%    \begin{macrocode}
        \ifx\cref@result\@empty%
          \def\cref@result{2147483647}%
        \else%
          \edef\cref@result{2147483647,\cref@result}%
        \fi%
%    \end{macrocode}
%       Override the cross-reference type of sectioning commands.
%    \begin{macrocode}
        \def\@tempa{##1}%
        \def\@tempb{chapter}%
        \ifx\@tempa\@tempb%
          \@ifundefined{cref@appendix@alias}%
            {\def\@tempa{appendix}}%
            {\def\@tempa{\cref@appendix@alias}}%
          \protected@edef\cref@currentlabel{%
            [\@tempa][\arabic{##1}][\cref@result]%
            \csname p@##1\endcsname\csname the##1\endcsname}%
        \else%
          \def\@tempa{##1}%
          \def\@tempb{section}%
          \ifx\@tempa\@tempb%
            \@ifundefined{cref@subappendix@alias}%
              {\def\@tempa{subappendix}}%
              {\def\@tempa{\cref@subappendix@alias}}%
            \protected@edef\cref@currentlabel{%
              [\@tempa][\arabic{##1}][\cref@result]%
              \csname p@##1\endcsname\csname the##1\endcsname}%
          \else%
            \def\@tempa{##1}%
            \def\@tempb{subsection}%
            \ifx\@tempa\@tempb%
              \@ifundefined{cref@subsubappendix@alias}%
                {\def\@tempa{subsubappendix}}%
                {\def\@tempa{\cref@subsubappendix@alias}}%
              \protected@edef\cref@currentlabel{%
                [\@tempa][\arabic{##1}][\cref@result]%
                \csname p@##1\endcsname\csname the##1\endcsname}%
            \else%
              \def\@tempa{##1}%
              \def\@tempb{subsubsection}%
              \ifx\@tempa\@tempb%
                \@ifundefined{cref@subsubappendix@alias}%
                  {\def\@tempa{subsubsubappendix}}%
                  {\def\@tempa{\cref@subsubsubappendix@alias}}%
                \protected@edef\cref@currentlabel{%
                  [\@tempa][\arabic{##1}][\cref@result]%
                  \csname p@##1\endcsname\csname the##1\endcsname}%
              \else%
                \@ifundefined{cref@##1@alias}%
                  {\def\@tempa{##1}}%
                  {\def\@tempa{\csname cref@##1@alias\endcsname}}%
                \protected@edef\cref@currentlabel{%
                  [\@tempa][\arabic{##1}][\cref@result]%
                  \csname p@##1\endcsname\csname the##1\endcsname}%
              \fi%
            \fi%
          \fi%
        \fi}%
    \cref@old@appendix}%
  }%
}% end of \@ifundefined{appendix}
%    \end{macrocode}
% \end{macro}
%
%
%
% \subsection{Utility Macros}
%
% \subsubsection{miscellaneous}
% \begin{macro}{\cref@gobble@optarg}
%   A basic macro that gobbles one argument plus, if present, one
%   optional argument.
%    \begin{macrocode}
\def\cref@gobble@optarg{\@ifnextchar[\@cref@gobble@optarg\cref@gobble}%]
\def\cref@gobble#1{}%
\def\@cref@gobble@optarg[#1]#2{}%
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\cref@append@toks}
%   A basic utility macro for appending tokens to a token register.
%    \begin{macrocode}
\def\cref@append@toks#1#2{\toks0={#2}%
  \edef\act{\noexpand#1={\the#1\the\toks0}}%
  \act}%
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\cref@ifstreq}
%   A utility macro to test string equality in a catcode-independent
%   fashion. Assumes both arguments are fully expandable. Note: using the
%   |\pdfstrcmp| primitive from |pdftex| would be more robust, but we don't
%   want to depend on |pdftex|. This macro suffices for our purposes.
%    \begin{macrocode}
\def\cref@ifstreq#1#2#3#4{%
  \begingroup%
    \edef\@tempa{#1}%
    \edef\@tempb{#2}%
    \expandafter\def\expandafter\@tempa\expandafter{\csname\@tempa\endcsname}%
    \expandafter\def\expandafter\@tempb\expandafter{\csname\@tempb\endcsname}%
    \ifx\@tempa\@tempb%
      \let\@tempc\@firstoftwo%
    \else%
      \let\@tempc\@secondoftwo%
    \fi%
    \expandafter%
  \endgroup%
  \@tempc{#3}{#4}}%
%    \end{macrocode}
% \end{macro}
%
%
% \subsubsection{\file{aux} file information}
% \begin{macro}{\cref@getlabel}
% \begin{macro}{\cref@gettype}
% \begin{macro}{\cref@getcounter}
% \begin{macro}{\cref@getprefix}
%   Define some utility macros for extracting label, type, and counter
%   information from the contents of \cmd{\cref@currentlabel}, as written
%   to the \file{aux} file and stored in \cmd{\r@\meta{label}@cref} when
%   this is re-read on the next pass. Some other packages commandeer the
%   referencing system to write label information to the \file{aux} file
%   for other purposes, and probably use \cmd{\ref} to recover it later.
%   We still want them to work, so our utility macros must cope with the
%   type information being absent. However, since we need them to be
%   fully expandable in various places, and \cmd{\@ifnextchar} is
%   definitely \emph{not} fully expandable, we use the work-around of
%   having the macros store their result in another macro, whose name is
%   passed as the second argument. This other macro \emph{will} then be
%   fully expandable, and can be used e.g.\ inside an \cmd{\edef} or
%   \cmd{\csname}\ldots\cmd{\endcsname}.
%    \begin{macrocode}
\def\cref@getref#1#2{%
  \expandafter\let\expandafter#2\csname r@#1@cref\endcsname%
  \expandafter\expandafter\expandafter\def%
    \expandafter\expandafter\expandafter#2%
    \expandafter\expandafter\expandafter{%
      \expandafter\@firstoftwo#2}}%
\def\cref@getlabel#1#2{%
  \cref@getref{#1}{\@tempa}%
  \expandafter\@cref@getlabel\@tempa\@nil#2}%
\def\@cref@getlabel{\@ifnextchar[%]
  \@@cref@getlabel{\@@cref@getlabel[][][]}}%
\def\@@cref@getlabel[#1][#2][#3]#4\@nil#5{\def#5{#4}}%
\def\cref@gettype#1#2{%
  \cref@getref{#1}{\@tempa}%
  \expandafter\@cref@gettype\@tempa\@nil#2}%
\def\@cref@gettype{\@ifnextchar[%]
  \@@cref@gettype{\@@cref@gettype[][][]}}%
\def\@@cref@gettype[#1][#2][#3]#4\@nil#5{\def#5{#1}}%
\def\cref@getcounter#1#2{%
  \cref@getref{#1}{\@tempa}%
  \expandafter\@cref@getcounter\@tempa\@nil#2}%
\def\@cref@getcounter{\@ifnextchar[%]
  \@@cref@getcounter{\@@cref@getcounter[][][]}}%
\def\@@cref@getcounter[#1][#2][#3]#4\@nil#5{\def#5{#2}}%
\def\cref@getprefix#1#2{%
  \cref@getref{#1}{\@tempa}%
  \expandafter\@cref@getprefix\@tempa\@nil#2}%
\def\@cref@getprefix{\@ifnextchar[%]
  \@@cref@getprefix{\@@cref@getprefix[][][]}}%
\def\@@cref@getprefix[#1][#2][#3]#4\@nil#5{\def#5{#3}}%
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \begin{macro}{\cpageref@getlabel}
% \begin{macro}{\cpageref@gettype}
% \begin{macro}{\cpageref@getcounter}
%   Similarly for the page number information. Here, the information we
%   store in addition to the page label is the page label ``type'' (used
%   to distinguish different page numbering sequences, e.g.\ roman in the
%   front-matter and arabic in the main text), and the numerical value of
%   the page counter.
%    \begin{macrocode}
\def\cpageref@getref#1#2{%
  \expandafter\let\expandafter#2\csname r@#1@cref\endcsname%
  \expandafter\expandafter\expandafter\def%
    \expandafter\expandafter\expandafter#2%
    \expandafter\expandafter\expandafter{%
      \expandafter\@secondoftwo#2}}%
\def\cpageref@getlabel#1#2{%
  \cpageref@getref{#1}{\@tempa}%
  \expandafter\@cpageref@getlabel\@tempa\@nil#2}%
\def\@cpageref@getlabel{\@ifnextchar[%]
  \@@cpageref@getlabel{\@@cpageref@getlabel[][][]}}%
\def\@@cpageref@getlabel[#1][#2][#3]#4\@nil#5{\def#5{#4}}%
\def\cpageref@gettype#1#2{%
  \cpageref@getref{#1}{\@tempa}%
  \expandafter\@cpageref@gettype\@tempa\@nil#2}%
\def\@cpageref@gettype{\@ifnextchar[%]
  \@@cpageref@gettype{\@@cpageref@gettype[][][]}}%
\def\@@cpageref@gettype[#1][#2][#3]#4\@nil#5{\def#5{#1}}%
\def\cpageref@getcounter#1#2{%
  \cpageref@getref{#1}{\@tempa}%
  \expandafter\@cpageref@getcounter\@tempa\@nil#2}%
\def\@cpageref@getcounter{\@ifnextchar[%]
  \@@cpageref@getcounter{\@@cpageref@getcounter[][][]}}%
\def\@@cpageref@getcounter[#1][#2][#3]#4\@nil#5{\def#5{#2}}%
\def\cpageref@getprefix#1#2{%
  \cpageref@getref{#1}{\@tempa}%
  \expandafter\@cpageref@getprefix\@tempa\@nil#2}%
\def\@cpageref@getprefix{\@ifnextchar[%]
  \@@cpageref@getprefix{\@@cpageref@getprefix[][][]}}%
\def\@@cpageref@getprefix[#1][#2][#3]#4\@nil#5{\def#5{#3}}%
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
%
% \cmd{\cref@override@label@type} is a convenience macro for overriding
% the label type stored in \cmd{\cref@currentlabel}.
% \begin{macro}{\cref@override@label@type}
%    \begin{macrocode}
\def\cref@override@label@type[#1][#2][#3]#4\@nil#5{[#5][#2][#3]#4}%
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\cref@constructprefix}
%   The \cmd{\cref@constructprefix} macro constructs the prefix
%   information stored in \cmd{\cref@currentlabel} (retrieved using
%   \cmd{\cref@getprefix}). This information consists of the numerical
%   value of each counter that's involved in resetting the label's
%   counter, i.e.\ it contains the numerical values of the chapter,
%   section, subsection\dots{} numbers that (ought to) make up the
%   formatted label produced by \cmd{\the\meta{counter}}. E.g.\ if
%   \cmd{\theequation} produces ``B.1.3'', this utility macro will return
%   ``2,1'' (the ``3'' corresponds to the equation number itself, which
%   is stored separately in \cmd{\cref@currentlabel}). The first argument
%   is the counter in question; the return value is stored in the second
%   argument, which should be a macro name.
%
%   The real work is done by the recursive \cmd{\@cref@constructprefix}
%   macro, which works its way upwards through the counters' reset lists
%   until it reaches a counter that isn't reset by any other.
%    \begin{macrocode}
\def\cref@constructprefix#1#2{%
  \cref@stack@init{\@tempstack}%
%    \end{macrocode}
% We fully expand the first argument (the counter name) because sometimes
% we get passed a counter name containing a macro.
%    \begin{macrocode}
  \edef\@tempa{\noexpand{#1\noexpand}}%
  \expandafter\def\expandafter\@tempa\expandafter{\@tempa{#2}}%
  \expandafter\@cref@constructprefix\@tempa%
  \cref@stack@to@list{\@tempstack}{\@tempa}%
  \expandafter\def\expandafter#2\expandafter{\@tempa}}%
\def\@cref@constructprefix#1#2{%
  \cref@resetby{#1}{#2}%
  \ifx#2\relax%
  \else%
    \edef\@tempa{\the\csname c@#2\endcsname}%
    \expandafter\cref@stack@push\expandafter{\@tempa}{\@tempstack}%
    \edef\@tempa{{#2}}%
    \expandafter\expandafter\expandafter\@cref@constructprefix%
      \expandafter\@tempa\expandafter{\expandafter#2\expandafter}%
  \fi}%
%    \end{macrocode}
% \end{macro}
%
%
% \subsubsection{Stack data structures}
% \begin{macro}{\cref@stack@init}
% \begin{macro}{\cref@stack@top}
% \begin{macro}{\cref@stack@pop}
% \begin{macro}{\cref@stack@push}
% \begin{macro}{\cref@stack@topandbottom}
% \begin{macro}{\cref@stack@add}
% \begin{macro}{\cref@stack@to@list}
%   We treat multiple references, supplied as a comma-separated list to
%   \cmd{\cref} or \cmd{\Cref}, as a stack structure. So we define some
%   utility macros for manipulating stacks (\cmd{\@nil} is used as an
%   end-of-stack delimiter).
%    \begin{macrocode}
\def\cref@stack@init#1{\def#1{\@nil}}%
\def\cref@stack@top#1{\expandafter\@cref@stack@top#1}%
\def\@cref@stack@top#1,#2\@nil{#1}%
\def\cref@stack@pop#1{\expandafter\@cref@stack@pop#1#1}%
\def\@cref@stack@pop#1,#2\@nil#3{\def#3{#2\@nil}}%
\def\cref@stack@push#1#2{%
  \expandafter\@cref@stack@push\expandafter{#2}{#1}{#2}}%
\def\@cref@stack@push#1#2#3{\def#3{#2,#1}}%
\def\cref@stack@pull#1#2{\expandafter\@cref@stack@pull#2{#1}{#2}}%
\def\@cref@stack@pull#1\@nil#2#3{\def#3{#1#2,\@nil}}%
\def\cref@stack@to@list#1#2{%
  \cref@isstackfull{#1}%
  \if@cref@stackfull%
    \expandafter\expandafter\expandafter\def%
    \expandafter\expandafter\expandafter#2%
    \expandafter\expandafter\expandafter{%
      \expandafter\@cref@stack@to@list#1}%
  \else%
    \def#2{}%
  \fi}%
\def\@cref@stack@to@list#1,\@nil{#1}%
\def\cref@stack@topandbottom#1#2#3{%
  \def#2{}%
  \def#3{}%
  \cref@isstackfull{#1}%
  \if@cref@stackfull%
    \edef#2{\cref@stack@top{#1}}%
    \cref@stack@pop{#1}%
    \cref@isstackfull{#1}%
    \@whilesw\if@cref@stackfull\fi{%
      \edef#3{\cref@stack@top{#1}}%
      \cref@stack@pop{#1}%
      \cref@isstackfull{#1}}%
  \fi}%
\def\cref@stack@add#1#2{%
  \begingroup%
    \def\@arg1{#1}%
    \let\@tempstack#2%
    \newif\if@notthere%
    \@nottheretrue%
    \cref@isstackfull{\@tempstack}%
    \@whilesw\if@cref@stackfull\fi{%
      \edef\@tempb{\cref@stack@top{\@tempstack}}%
      \def\@tempa{#1}%
      \ifx\@tempa\@tempb%
        \@cref@stackfullfalse%
        \@nottherefalse%
      \else%
        \cref@stack@pop{\@tempstack}%
        \cref@isstackfull{\@tempstack}%
      \fi}%
  \expandafter\endgroup%
  \if@notthere\cref@stack@push{#1}{#2}\fi}%
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\if@cref@stackempty}
% \begin{macro}{\if@cref@stackfull}
% \begin{macro}{\cref@isstackempty}
% \begin{macro}{\cref@isstackfull}
%   The \cmd{\cref@isstackempty} and \cmd{\cref@isstackfull} macros test
%   whether a stack is empty or full, respectively, and set the
%   corresponding conditionals\linebreak[4] |\if@cref@stackempty| and
%   |\if@cref@stackfull|.
%    \begin{macrocode}
\newif\if@cref@stackempty%
\newif\if@cref@stackfull%
\def\cref@isstackempty#1{%
  \def\@tempa{\@nil}%
  \ifx#1\@tempa\@cref@stackemptytrue%
  \else\@cref@stackemptyfalse\fi}%
\def\cref@isstackfull#1{%
  \def\@tempa{\@nil}%
  \ifx#1\@tempa\@cref@stackfullfalse%
  \else\@cref@stackfulltrue\fi}%
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\cref@stack@dropempty}
%   Drop any empty references from head of a stack.
%    \begin{macrocode}
\def\cref@stack@dropempty#1{%
  \edef\@tempa{\cref@stack@top{#1}}%
  \@whilesw\ifx\@tempa\@empty\fi{%
    \cref@stack@pop{#1}%
    \cref@isstackempty{#1}%
    \if@cref@stackempty%
      \let\@tempa\relax%
    \else%
      \edef\@tempa{\cref@stack@top{#1}}%
    \fi}}%
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\cref@stack@sort}
%   The \cmd{\cref@stack@sort} macro sorts a stack passed in |#2|, using
%   the comparison macro passed in |#1|, which we use later to sort lists
%   of references. We use insertion sort despite its $O(n^2)$ scaling
%   because it's simpler to code, and because we're very unlikely to
%   encounter lists of more than ten or so references, so in practice a
%   more complicated $O(n\log n)$ sorting algorithm will very likely be
%   slower anyway.
%    \begin{macrocode}
\def\cref@stack@sort#1#2{%
  \begingroup%
  \cref@stack@init{\@sortstack}%
%    \end{macrocode}
% Push first element into sorted stack.
%    \begin{macrocode}
  \edef\@element{\cref@stack@top{#2}}%
  \expandafter\cref@stack@push\expandafter{\@element}{\@sortstack}%
  \cref@stack@pop{#2}%
%    \end{macrocode}
% If empty elements follow first one, need to add them after it in sorted
% stack.
%    \begin{macrocode}
  \cref@isstackfull{#2}%
  \if@cref@stackfull%
    \edef\@tempa{\cref@stack@top{#2}}%
    \@whilesw\ifx\@tempa\@empty\fi{%
      \cref@stack@pull{}{\@sortstack}%
      \cref@stack@pop{#2}%
      \cref@isstackempty{#2}%
      \if@cref@stackempty%
        \let\@tempa\relax%
      \else%
        \edef\@tempa{\cref@stack@top{#2}}%
      \fi}%
  \fi%
%    \end{macrocode}
% Process elements from stack.
%    \begin{macrocode}
  \cref@isstackfull{#2}%
  \@whilesw\if@cref@stackfull\fi{%
    \edef\@element{\cref@stack@top{#2}}%
    \cref@stack@pop{#2}%
%    \end{macrocode}
% If empty elements follow current one, need to add them to sorted stack,
% right after element we're currently dealing with.
%    \begin{macrocode}
    \def\@empties{}%
    \cref@isstackfull{#2}%
    \if@cref@stackfull%
      \edef\@tempa{\cref@stack@top{#2}}%
      \@whilesw\ifx\@tempa\@empty\fi{%
        \edef\@empties{\@empties,}%
        \cref@stack@pop{#2}%
        \cref@isstackempty{#2}%
        \if@cref@stackempty%
          \let\@tempa\relax%
        \else%
          \edef\@tempa{\cref@stack@top{#2}}%
        \fi}%
    \fi%
%    \end{macrocode}
% Insert current element into sorted stack, appending any following empty
% elements.
%    \begin{macrocode}
    \edef\@tempa{{\expandafter\noexpand\@element}%
      {\expandafter\noexpand\@empties}%
      {\noexpand\@sortstack}{\noexpand#1}}%
    \expandafter\cref@stack@insert\@tempa%
    \cref@isstackfull{#2}}%
  \expandafter\endgroup\expandafter%
  \def\expandafter#2\expandafter{\@sortstack}}%
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\cref@stack@insert}
%   \cmd{\cref@stack@insert}|{#1}{#2}{#3}{#4}| inserts |#1| into the
%   appropriate location in the sorted stack |#3| (appending |#2| onto
%   the end of |#1| when it's inserted), using the comparison macro |#4|.
%    \begin{macrocode}
\def\cref@stack@insert#1#2#3#4{%
  \let\@cmp#4%
  \@cref@stack@insert{}{#1}{#2}{#3}%
  \cref@stack@pop{#3}}%
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\@cref@stack@insert}
%   \cmd{\@cref@stack@insert}|{#1}{#2}{#3}{#4}| prepends |#1| to the
%   stack resulting from inserting |#2| (with |#3| appended to it) into
%   the sorted stack |#4|.
%    \begin{macrocode}
\def\@cref@stack@insert#1#2#3#4{%
  \let\cref@iterate\relax%
  \cref@isstackempty{#4}%
  \if@cref@stackempty%
    \cref@stack@push{#1,#2#3}{#4}%
  \else%
    \edef\cref@elem{\cref@stack@top{#4}}%
    \expandafter\@cmp\expandafter{\cref@elem}{#2}{\cref@result}%
    \ifnum\cref@result=2\relax%
      \cref@stack@push{#1,#2#3}{#4}%
    \else%
      \cref@stack@pop{#4}%
      \edef\cref@elem{{\noexpand#1,\cref@elem}{\noexpand#2}%
        {\noexpand#3}{\noexpand#4}}%
      \expandafter\def\expandafter\cref@iterate\expandafter%
        {\expandafter\@cref@stack@insert\cref@elem}%
    \fi%
  \fi%
  \cref@iterate}%
%    \end{macrocode}
% \end{macro}
%
%
% \subsubsection{Reference comparison and sorting}
% \begin{macro}{\cref@isrefsametype}
% \begin{macro}{\if@cref@sametype}
%   Test if two references have same type, and set |\if@cref@sametype|
%   conditional accordingly.
%    \begin{macrocode}
\newif\if@cref@sametype%
\def\cref@isrefsametype#1#2{%
  \begingroup%
%    \end{macrocode}
% Undefined references are treated as different from any other type, but
% the same type as each other.
%    \begin{macrocode}
  \expandafter\ifx\csname r@#1@cref\endcsname\relax%
    \expandafter\ifx\csname r@#2@cref\endcsname\relax%
      \def\@after{\@cref@sametypetrue}%
    \else%
      \def\@after{\@cref@sametypefalse}%
    \fi%
  \else%
    \expandafter\ifx\csname r@#2@cref\endcsname\relax%
      \def\@after{\@cref@sametypefalse}%
%    \end{macrocode}
% To test if two references have the same type, we actually compare the
% expansion of |\cref@|\meta{type}|@format| rather than the \meta{type}
% per se. This allows references with different counters but identical
% formatting (e.g.\ equations and subequations with the default
% formatting) to be typeset as part of the same reference group, which is
% almost always what we want.
%    \begin{macrocode}
    \else%
      \cref@gettype{#1}{\@type}%
      \expandafter\expandafter\expandafter\def%
        \expandafter\expandafter\expandafter\@formata%
        \expandafter\expandafter\expandafter{%
          \csname cref@\@type @format\endcsname%
          {\@dummya}{\@dummyb}{\@dummyc}}%
      \cref@gettype{#2}{\@type}%
      \expandafter\expandafter\expandafter\def%
        \expandafter\expandafter\expandafter\@formatb%
        \expandafter\expandafter\expandafter{%
          \csname cref@\@type @format\endcsname%
          {\@dummya}{\@dummyb}{\@dummyc}}%
      \ifx\@formata\@formatb%
        \def\@after{\@cref@sametypetrue}%
      \else%
        \def\@after{\@cref@sametypefalse}%
      \fi%
    \fi%
  \fi%
  \expandafter\endgroup\@after}%
%    \end{macrocode}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\cpageref@isrefsametype}
%   Test if two page references have same ``type'', and set
%   |\if@cref@sametype| conditional accordingly.
%    \begin{macrocode}
\def\cpageref@isrefsametype#1#2{%
  \begingroup%
%    \end{macrocode}
% Undefined references are treated as different from any other type, but
% the same type as each other.
%    \begin{macrocode}
  \expandafter\ifx\csname r@#1@cref\endcsname\relax%
    \expandafter\ifx\csname r@#2@cref\endcsname\relax%
      \def\@after{\@cref@sametypetrue}%
    \else%
      \def\@after{\@cref@sametypefalse}%
    \fi%
  \else%
    \expandafter\ifx\csname r@#2@cref\endcsname\relax%
      \def\@after{\@cref@sametypefalse}%
    \else%
      \cpageref@gettype{#1}{\@typea}%
      \cpageref@gettype{#2}{\@typeb}%
      \ifx\@typea\@typeb%
        \def\@after{\@cref@sametypetrue}%
      \else%
        \def\@after{\@cref@sametypefalse}%
      \fi%
    \fi%
  \fi%
  \expandafter\endgroup\@after}%
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\cref@countercmp}
%   The \cmd{\cref@countercmp} macro compares references |#1| and |#2|
%   according to their respective sets of counter data (stored in the
%   \file{aux} file). It \cmd{\chardef}'s |#3| to 0 if they're equal, 1
%   if the first comes earlier than the second, or 2 if the first
%   reference comes later than the second. This is used later for sorting
%   references. \cmd{\cref@countercmp} compares the references
%   themselves, \cmd{\cpageref@countercmp} compares their page numbers.
%    \begin{macrocode}
\def\cref@counter@first#1#2\@nil{#1}%
\def\cref@counter@rest#1#2\@nil{#2}%
\def\cref@countercmp{\@cref@countercmp{cref}}%
\def\cpageref@countercmp{\@cref@countercmp{cpageref}}%
\def\@cref@countercmp#1#2#3#4{%
  \begingroup%
  \def\@tempa{#2}%
%    \end{macrocode}
% In order to ensure empty references end up in the right place when
% sorting lists of multiple references, we make the comparison macro
% sort them before a non-empty reference.
%    \begin{macrocode}
  \ifx\@tempa\@empty%
    \def\cref@result{1}%
  \else%
    \def\@tempa{#3}%
    \ifx\@tempa\@empty%
      \def\cref@result{2}%
    \else%
%    \end{macrocode}
% Conversely, undefined references come after everything else.
%    \begin{macrocode}
      \expandafter\ifx\csname r@#2@cref\endcsname\relax%
        \def\cref@result{2}%
      \else%
        \expandafter\ifx\csname r@#3@cref\endcsname\relax%
          \def\cref@result{1}%
        \else%
%    \end{macrocode}
% The real work of comparing two references is done by
% \cmd{\@@cref@countercmp}.
%    \begin{macrocode}
          \csname #1@getcounter\endcsname{#2}{\@countera}%
          \csname #1@getprefix\endcsname{#2}{\@prefixa}%
          \csname #1@getcounter\endcsname{#3}{\@counterb}%
          \csname #1@getprefix\endcsname{#3}{\@prefixb}%
          \cref@stack@init{\@countstacka}%
          \expandafter\cref@stack@push\expandafter%
            {\@countera}{\@countstacka}%
          \ifx\@prefixa\@empty\else%
            \expandafter\cref@stack@push\expandafter%
              {\@prefixa}{\@countstacka}%
          \fi%
          \cref@stack@init{\@countstackb}%
          \expandafter\cref@stack@push\expandafter%
            {\@counterb}{\@countstackb}%
          \ifx\@prefixb\@empty\else%
            \expandafter\cref@stack@push\expandafter%
              {\@prefixb}{\@countstackb}%
          \fi%
          \@@cref@countercmp%
        \fi%
      \fi%
    \fi%
  \fi%
  \expandafter\endgroup\expandafter%
  \chardef\expandafter#4\expandafter=\cref@result\relax}%
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\@@cref@countercmp}
%   The \cmd{\@@cref@countercmp} macro recursively compares counter
%   components until it runs out of components for one of the references,
%   or finds two corresponding components that are unequal.
%    \begin{macrocode}
\def\@@cref@countercmp{%
  \let\@iterate\relax%
  \cref@isstackempty{\@countstacka}%
  \if@cref@stackempty%
    \cref@isstackempty{\@countstackb}%
    \if@cref@stackempty%
      \def\cref@result{0}%
    \else%
      \def\cref@result{1}%
    \fi%
  \else%
    \cref@isstackempty{\@countstackb}%
    \if@cref@stackempty%
      \def\cref@result{2}%
    \else%
      \edef\@tempa{\cref@stack@top{\@countstacka}}%
      \cref@stack@pop{\@countstacka}%
      \edef\@tempb{\cref@stack@top{\@countstackb}}%
      \cref@stack@pop{\@countstackb}%
      \ifnum\@tempa<\@tempb\relax%
        \def\cref@result{1}%
      \else%
        \ifnum\@tempa>\@tempb\relax%
          \def\cref@result{2}%
        \else%
          \def\@iterate{\@@cref@countercmp}%
        \fi%
      \fi%
    \fi%
  \fi%
  \@iterate}%
%    \end{macrocode}
% \end{macro}
%
%
% \begin{macro}{\if@cref@inresetlist}
% \begin{macro}{\cref@isinresetlist}
% \begin{macro}{\cref@resetby}
%   We need to be able to determine which counter is used to reset a
%   given counter. Usually, resets are done by sectioning counters, and
%   we assume that to be the case here. \cmd{\cref@isinresetlist}
%   searches through one counter's reset list, stored in
%   \cmd{\cl@\meta{counter}}, to determine whether another counter
%   appears there, and sets the new conditional
%   appropriately. \cmd{\cref@reset@by} searches through all the
%   sectioning counters' reset lists, from lowest-level (subsubsection)
%   to highest (part), checking whether the given counter is in the list,
%   and returns the first sectioning counter in whose list it appears.
%   (The value is returned by defining its second argument, which should
%   be a macro name.)
%    \begin{macrocode}
\newif\if@cref@inresetlist%
\def\cref@isinresetlist#1#2{%
  \begingroup%
    \def\@counter{#1}%
%    \end{macrocode}
%   We locally redefine \cmd{\@elt}, which appears at the head of the
%   expansion of |\cl@|\meta{counter}, so that entries in the reset list
%   end up separated by commas, thus can be treated as a stack.
%    \begin{macrocode}
    \def\@elt##1{##1,}%
    \expandafter\ifx\csname cl@#2\endcsname\relax%
      \def\cref@resetstack{,\@nil}%
    \else%
      \edef\cref@resetstack{\csname cl@#2\endcsname\noexpand\@nil}%
    \fi%
    \let\@nextcounter\relax%
    \cref@isstackfull{\cref@resetstack}%
    \@whilesw\if@cref@stackfull\fi{%
      \edef\@nextcounter{\cref@stack@top{\cref@resetstack}}%
      \ifx\@nextcounter\@counter%
        \@cref@stackfullfalse%
      \else%
        \let\@nextcounter\relax%
        \cref@stack@pop{\cref@resetstack}%
        \cref@isstackfull{\cref@resetstack}%
      \fi}%
    \ifx\@nextcounter\relax%
      \def\@next{\@cref@inresetlistfalse}%
    \else%
      \def\@next{\@cref@inresetlisttrue}%
    \fi%
  \expandafter%
  \endgroup%
  \@next}%
%    \end{macrocode}
%
% FIXME: We could easily remove the hard-coded search order in
% \cmd{\cref@resetby} and, say, replace it with a customisable list of
% counters to search in order. But, so far, I've yet to encounter a need
% for anything other than the hard-coded default.
%    \begin{macrocode}
\def\cref@resetby#1#2{%
  \let#2\relax%
%    \end{macrocode}
% If counter in question is |subfigure| or |subtable|, check if it's
% reset by |figure| or |table|, respectively.
%    \begin{macrocode}
  \cref@ifstreq{#1}{subfigure}{%
    \cref@isinresetlist{#1}{figure}%
    \if@cref@inresetlist%
      \def#2{figure}%
    \fi%
  }{}%
  \cref@ifstreq{#1}{subtable}{%
    \cref@isinresetlist{#1}{table}%
    \if@cref@inresetlist%
      \def#2{table}%
    \fi%
  }{}%
%    \end{macrocode}
% If counter in question is |equation|, and the counter |parentequation|
% is defined, check if it's reset by that. The |parentequation| counter
% is used by \package{amsmath}'s |subequations| environment. Although
% \package{amsmath} doesn't implement |subequations| using counter reset
% lists, \package{cleveref}'s \package{amsmath} support tweaks the reset
% lists inside |subequations| environments to hook into this mechanism.
% We should really only check this when \package{amsmath} is loaded, but
% checking it anyway might catch other packages that independently
% implement amsmath's |subequations| environment (are there any?).
%    \begin{macrocode}
  \@ifundefined{cl@parentequation}{}{%
    \cref@ifstreq{#1}{equation}{%
      \cref@isinresetlist{#1}{parentequation}%
      \if@cref@inresetlist%
        \expandafter\ifnum\c@parentequation=0\else%
          \def#2{parentequation}%
        \fi%
      \fi%
    }{}}%
%    \end{macrocode}
% \LaTeX{} hard-codes resetting of |enum|\meta{x} counters by
% higher-level |enum|\meta{x} counters, so we hard-code the results for
% these cases.
%    \begin{macrocode}
  \cref@ifstreq{#1}{enumii}{%
    \def#2{enumi}%
  }{%
    \cref@ifstreq{#1}{enumiii}{%
      \def#2{enumii}%
    }{%
      \cref@ifstreq{#1}{enumiv}{%
        \def#2{enumiii}%
      }{}%
    }%
  }%
%    \end{macrocode}
% If we haven't found anything so far, check if it's reset by a
% sectioning command.
%    \begin{macrocode}
  \ifx#2\relax%
    \cref@isinresetlist{#1}{table}%
    \if@cref@inresetlist%
      \def#2{table}%
    \else%
      \cref@isinresetlist{#1}{subsubsection}%
      \if@cref@inresetlist%
        \def#2{subsubsection}%
      \else%
        \cref@isinresetlist{#1}{subsection}%
        \if@cref@inresetlist%
          \def#2{subsection}%
        \else%
          \cref@isinresetlist{#1}{section}%
          \if@cref@inresetlist%
            \def#2{section}%
          \else%
            \cref@isinresetlist{#1}{chapter}%
            \if@cref@inresetlist%
              \def#2{chapter}%
            \else%
             \cref@isinresetlist{#1}{part}%
              \if@cref@inresetlist%
                \def#2{part}%
              \else%
                \let#2\relax%
              \fi%
            \fi%
          \fi%
        \fi%
      \fi%
    \fi%
  \fi}%
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\if@cref@refconsecutive}
% \begin{macro}{\cref@isrefconsecutive}
% \begin{macro}{\cpageref@isrefconsecutive}
%   Define a new conditional to test whether two references are
%   consecutive (needed when compressing references and typesetting
%   reference ranges). This uses the counter and prefix (i.e.\ chain of
%   counters that reset the reference's counter) information provided by
%   \cmd{\r@\meta{label}@cref} (via the \file{aux} file) to check if the
%   prefixes are identical (i.e.\ the references come from the same
%   chapter, section or whatever), and that the label counters differ
%   by~0 or~1. \cmd{\cref@isrefconsecutive} tests the references
%   themselves, \cmd{\cpageref@isrefconsecutve} tests their page numbers.
%    \begin{macrocode}
\newif\if@cref@refconsecutive%
\def\cref@isrefconsecutive{\@cref@isrefconsecutive{cref}}%
\def\cpageref@isrefconsecutive{\@cref@isrefconsecutive{cpageref}}%
\def\@cref@isrefconsecutive#1#2#3{%
  \begingroup%
  \def\@after{\@cref@refconsecutivefalse}%
  \expandafter\ifx\csname r@#2@cref\endcsname\relax\else%
    \expandafter\ifx\csname r@#3@cref\endcsname\relax\else%
      \countdef\refa@counter=0%
      \countdef\refb@counter=1%
      \csname #1@getcounter\endcsname{#2}{\cref@result}%
      \refa@counter=\cref@result%
      \csname #1@getcounter\endcsname{#3}{\cref@result}%
      \refb@counter=\cref@result%
      \csname #1@getprefix\endcsname{#2}{\refa@prefix}%
      \csname #1@getprefix\endcsname{#3}{\refb@prefix}%
      \ifx\refa@prefix\refb@prefix%
        \ifnum\refa@counter=\refb@counter\relax%
          \def\@after{\@cref@refconsecutivetrue}%
        \else%
          \advance\refa@counter 1\relax%
          \ifnum\refa@counter=\refb@counter\relax%
            \def\@after{\@cref@refconsecutivetrue}%
          \fi%
        \fi%
      \fi%
    \fi%
  \fi%
  \expandafter\endgroup\@after}%
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
%
%
% \subsubsection{Reference stack processing}
% \begin{macro}{\cref@processgroup}
%   \cmd{\cref@processgroup} processes the first group of references from
%   the stack passed in argument |#2|, by moving references to the stack
%   passed in argument |#3| until it encounters a reference that has a
%   different type to those that came before. Note that empty references
%   are treated as having the same type as the preceding one. If argument
%   |#1| is |cref| it processes references, it it's |cpageref| it
%   processes page references.
%    \begin{macrocode}
\def\cref@processgroup#1#2#3{%
  \cref@stack@dropempty{#2}%
  \edef\@firstref{\cref@stack@top{#2}}%
  \let\@nextref\@firstref%
  \@cref@sametypetrue%
  \@whilesw\if@cref@sametype\fi{%
    \expandafter\cref@stack@pull\expandafter{\@nextref}{#3}%
    \cref@stack@pop{#2}%
    \cref@isstackempty{#2}%
    \if@cref@stackempty%
      \@cref@sametypefalse%
    \else%
      \edef\@nextref{\cref@stack@top{#2}}%
      \ifx\@nextref\@empty%
        \@cref@sametypetrue%
      \else%
        \csname #1@isrefsametype\endcsname{\@firstref}{\@nextref}%
      \fi%
    \fi}}%
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\cref@processgroupall}
%   \cmd{\cref@processgroupall} processes the first group of references
%   from the stack passed in argument |#2|, by moving all references with
%   the same type as the first one into the stack passed in argument
%   |#3|. If argument |#1| is |cref| it processes references, if it's
%   |cpageref| it processes page references.
%    \begin{macrocode}
\def\cref@processgroupall#1#2#3{%
  \cref@stack@init{\@tempstack}%
  \cref@stack@dropempty{#2}%
  \edef\@firstref{\cref@stack@top{#2}}%
  \cref@isstackfull{#2}%
  \@whilesw\if@cref@stackfull\fi{%
    \edef\@nextref{\cref@stack@top{#2}}%
    \ifx\@nextref\@empty%
      \expandafter\cref@stack@pull\expandafter{\@nextref}{#3}%
    \else%
      \edef\@tempa{{\@firstref}{\@nextref}}%
      \csname #1@isrefsametype\expandafter\endcsname\@tempa%
      \if@cref@sametype%
        \expandafter\cref@stack@pull\expandafter{\@nextref}{#3}%
      \else%
        \expandafter\cref@stack@pull\expandafter{\@nextref}{\@tempstack}%
      \fi%
    \fi%
    \cref@stack@pop{#2}%
    \cref@isstackfull{#2}}%
  \let#2\@tempstack}%
%    \end{macrocode}
% \end{macro}
%
%
% \begin{macro}{\cref@processconsecutive}
%   \cmd{\cref@processconsecutive} processes the first sequence of
%   consecutive references from the stack passed in |#2|, sets the macro
%   passed as |#3| to the first reference in the sequence, sets |#4| to
%   the last reference, and sets the counter passed in |#5| to the number
%   of consecutive references in the sequence. If argument |#1| is |cref|
%   it processes references, if it's |cpageref| it processes page
%   references.
%    \begin{macrocode}
\def\cref@processconsecutive#1#2#3#4#5{%
%    \end{macrocode}
% Initialise return values to those appropriate for a single reference.
%    \begin{macrocode}
  \let#4\relax%
  #5=1\relax%
  \edef\@nextref{\cref@stack@top{#2}}%
  \edef#3{\@nextref}%
  \cref@stack@pop{#2}%
  \cref@isstackfull{#2}%
%    \end{macrocode}
% If stack contains multiple references, find end of consecutive references.
%    \begin{macrocode}
  \if@cref@stackfull%
    \edef\@nextref{\cref@stack@top{#2}}%
    \expandafter\ifx\csname r@#3@cref\endcsname\relax%
      \@cref@refconsecutivefalse%
    \else%
%    \end{macrocode}
%     If next reference in stack is empty, it indicates that no
%     further compression should take place. Having served its purpose,
%     the empty reference and any consecutive empty references are
%     removed from the stack.
%    \begin{macrocode}
      \ifx\@nextref\@empty%
        \@cref@refconsecutivefalse%
        \cref@stack@dropempty{#2}%
%    \end{macrocode}
%     Otherwise, test whether next reference is consecutive or not.
%    \begin{macrocode}
      \else%
        \edef\@tempa{{#3}{\@nextref}}%
        \csname #1@isrefconsecutive\expandafter\endcsname\@tempa%
      \fi%
    \fi%
%    \end{macrocode}
%   Remove references from the stack until we find end of consecutive
%   sequence.
%    \begin{macrocode}
    \@whilesw\if@cref@refconsecutive\fi{%
      \advance#5 1\relax%
      \let#4\@nextref%
      \cref@stack@pop{#2}%
      \cref@isstackempty{#2}%
      \if@cref@stackempty%
        \@cref@refconsecutivefalse%
      \else%
        \edef\@nextref{\cref@stack@top{#2}}%
%    \end{macrocode}
%       If next reference is empty, remove any consecutive empty
%       references and we're done.
%    \begin{macrocode}
        \ifx\@nextref\@empty%
          \@cref@refconsecutivefalse%
          \@whilesw\ifx\@nextref\@empty\fi{%
            \cref@stack@pop{#2}%
            \cref@isstackempty{#2}%
            \if@cref@stackempty%
              \let\@nextref\relax%
            \else%
              \edef\@nextref{\cref@stack@top{#2}}%
            \fi}%
%    \end{macrocode}
%         Otherwise, test whether next reference is consecutive or not.
%    \begin{macrocode}
        \else%
          \edef\@tempa{{#4}{\@nextref}}%
          \csname #1@isrefconsecutive\expandafter\endcsname\@tempa%
        \fi%
      \fi}%
  \fi}%
%    \end{macrocode}
% \end{macro}
%
%
% \subsubsection{Prefix-stripping}
% \begin{macro}{\crefstripprefix}
%   The \cmd{\crefstripprefix} utility command is intended for use in
%   cross-reference format definitions. It takes two strings of
%   characters as arguments, and strips any common prefix from the second
%   argument. The common prefix is only stripped up to the last sequence
%   of digits or letters in the second argument.
%    \begin{macrocode}
\newcommand\crefstripprefix[2]{%
  \begingroup%
    \edef\@toksa{#1}%
    \edef\@toksb{#2}%
    \let\cref@acc\@empty%
    \@crefstripprefix%
    \cref@result%
  \endgroup}%
%    \end{macrocode}
% \end{macro}
%
% The real work is done by the recursive \cmd{\@crefstripprefix} macro,
% which compares characters one-by-one (accumulating runs of the same
% type of character -- digit or letter as it goes). It removes matching
% characters from the strings, and outputs the remaining characters
% from the second string (plus any accumulated characters of the same
% type) when it encounters the first non-matching character;
%    \begin{macrocode}
\def\@crefstripprefix{%
  \let\@iterate\relax%
  \def\accum@flag{0}%
%    \end{macrocode}
% Pop next characters from |\@toksa| and |\@toksb| string into |\@tempa|
% and |\@tempb|, storing previous b-string character in |\@tempc|.
%    \begin{macrocode}
  \let\@tempc\@tempb%
  \cref@poptok{\@toksa}{\@tempa}%
  \cref@poptok{\@toksb}{\@tempb}%
%    \end{macrocode}
% If characters match, drop character and proceed to next.
%    \begin{macrocode}
  \ifx\@tempa\@tempb\relax%
    \def\@iterate{\@crefstripprefix}%
%    \end{macrocode}
%   Accumulate popped character if accumulated string is empty\dots
%    \begin{macrocode}
    \ifx\cref@acc\@empty\relax%
      \let\cref@acc\@tempb%
    \else%
%    \end{macrocode}
%     or if it has same catcode as previous character, and is either a
%     letter\dots
%    \begin{macrocode}
      \ifcat\@tempb\@tempc\relax%
        \ifcat\@tempb a\relax%
          \def\accum@flag{1}%
        \else%
%    \end{macrocode}
%    or a digit.
%    \begin{macrocode}
          \expandafter\chardef\expandafter\@tempa%
            \expandafter=\expandafter`\@tempb\relax%
          \ifnum\@tempa>`/\relax%
            \expandafter\ifnum\@tempb<`:\relax%
              \def\accum@flag{1}%
            \fi%
          \fi%
        \fi%
      \fi%
      \def\@tempa{1}%
      \ifx\accum@flag\@tempa%
        \edef\cref@acc{\cref@acc\@tempb}%
      \else%
        \let\cref@acc\@empty%
      \fi%
    \fi%
%    \end{macrocode}
% If characters don't match, return remaining characters from b-string,
% prepending any accumulated characters.
%    \begin{macrocode}
  \else%
    \ifcat\@tempb\@tempc\relax\else%
      \let\cref@acc\@empty%
    \fi%
    \edef\cref@result{\cref@acc\@tempb\@toksb}%
  \fi%
  \@iterate}%
%    \end{macrocode}
%
% \begin{macro}{\cref@poptok}
%   The \cmd{\cref@poptok} macro takes two arguments, both macros. It
%   defines |#2| to be the first token in |#1|'s expansion, and removes
%   that token from |#1|'s definition.
%    \begin{macrocode}
\def\cref@poptok#1#2{%
  \expandafter\expandafter\expandafter\def%
    \expandafter\expandafter\expandafter#2%
    \expandafter\expandafter\expandafter{%
      \expandafter\@cref@firsttok#1\@nil}%
  \expandafter\expandafter\expandafter\def%
    \expandafter\expandafter\expandafter#1%
    \expandafter\expandafter\expandafter{%
      \expandafter\@cref@poptok#1\@nil}}%
\def\@cref@firsttok#1#2\@nil{#1}%
\def\@cref@poptok#1#2\@nil{#2}%
%    \end{macrocode}
% \end{macro}
%
%
%
% \subsection{Cross-Referencing Commands}
% \begin{macro}{\cref}
% \begin{macro}{\Cref}
% \begin{macro}{\crefrange}
% \begin{macro}{\Crefrange}
%   Define the main referencing command \cmd{\cref} and the
%   start-of-sentence variant \cmd{\Cref}, along with the reference range
%   commands \cmd{\crefrange} and \cmd{\Crefrange}.
%    \begin{macrocode}
\DeclareRobustCommand{\cref}[1]{\@cref{cref}{#1}}%
\DeclareRobustCommand{\Cref}[1]{\@cref{Cref}{#1}}%
\DeclareRobustCommand{\crefrange}[2]{\@setcrefrange{#1}{#2}{}}%
\DeclareRobustCommand{\Crefrange}[2]{\@setCrefrange{#1}{#2}{}}%
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\if@crefstarred}
%   The |\if@crefstarred| flag is set within starred variants of
%   \package{cleveref} commands. Starred variants are only defined if
%   either the \package{hyperref} or \package{varioref} package is
%   loaded, so we only define it in those cases. We need to |\let|
%   |\if@crefstarred| to something even when not using it, otherwise
%   \TeX{} gets confused when parsing code that contains
%   |\if@crefstarred| inside a nested if.
%    \begin{macrocode}
\@ifpackageloaded{hyperref}{\newif\if@crefstarred}{%
  \@ifpackageloaded{varioref}{\newif\if@crefstarred}{}}%
\let\if@crefstarred\iffalse%
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\@cref}
%   To save duplicating code, the referencing macros pass an argument
%   determining the variant to an auxiliary macro \cmd{\@cref}, which
%   does the real work. The \cmd{\@cref} macro is the behemoth at the
%   heart of all the clever referencing features. It deals with grouping
%   references by type, typesetting the conjunctions between groups,
%   choosing the right formatting macro to use for each reference, and
%   compressing consecutive references into ranges.
%    \begin{macrocode}
\def\@cref#1#2{%
  \leavevmode%
  \begingroup%
  \def\cref@variant{#1}%
  \def\@tempa{\in@{page}}%
  \expandafter\@tempa\expandafter{\cref@variant}%
  \ifin@%
    \def\cref@variant@get{cpageref}%
  \else%
    \def\cref@variant@get{cref}%
  \fi%
%    \end{macrocode}
% Initialise some things, and put all the references into a stack called
% \cmd{\@refstack}. Note that we fully expand the second argument, in
% case it contains commands that \emph{expand to} label names, rather
% than label names per se.
%    \begin{macrocode}
  \countdef\count@consecutive=0%
  \countdef\count@group=1%
  \count@group=1%
  \countdef\count@subgroup=2%
  \cref@stack@init{\@refstack}%
  \edef\@tempa{#2}%
  \expandafter\cref@stack@push\expandafter{\@tempa}{\@refstack}%
  \cref@isstackfull{\@refstack}%
%    \end{macrocode}
%
% Loop until the reference stack is empty.
%    \begin{macrocode}
  \@whilesw\if@cref@stackfull\fi{%
%    \end{macrocode}
% Move next group of references with same type into \cmd{\@refsubstack}.
%    \begin{macrocode}
    \cref@stack@init{\@refsubstack}%
    \if@cref@sort%
      \expandafter\cref@processgroupall\expandafter%
        {\cref@variant@get}{\@refstack}{\@refsubstack}%
      \expandafter\cref@stack@sort\expandafter%
        {\csname\cref@variant@get @countercmp\endcsname}{\@refsubstack}%
    \else%
      \expandafter\cref@processgroup\expandafter%
        {\cref@variant@get}{\@refstack}{\@refsubstack}%
    \fi%
%    \end{macrocode}
%
% Typeset appropriate conjunction between groups of reference types.
%    \begin{macrocode}
    \ifnum\count@group=1\relax%
      \advance\count@group 1\relax%
    \else%
      \cref@isstackfull{\@refstack}%
      \if@cref@stackfull%
        \@setcref@middlegroupconjunction%
      \else%
        \ifnum\count@group=2\relax%
          \@setcref@pairgroupconjunction%
        \else%
          \@setcref@lastgroupconjunction%
        \fi%
      \fi%
      \advance\count@group 1\relax%
      \lowercase{\def\cref@variant{#1}}%
    \fi%
%    \end{macrocode}
%
% Process groups of consecutive references until substack is empty.
%    \begin{macrocode}
    \count@subgroup=1%
    \cref@isstackfull{\@refsubstack}%
    \@whilesw\if@cref@stackfull\fi{%
      \if@cref@compress%
        \expandafter\cref@processconsecutive\expandafter{\cref@variant@get}%
          {\@refsubstack}{\@beginref}{\@endref}{\count@consecutive}%
%    \end{macrocode}
% Empty references serve no purpose when we're not compressing, so we
% simply remove them and process the first non-empty reference..
%    \begin{macrocode}
      \else%
        \cref@stack@dropempty{\@refsubstack}%
        \edef\@beginref{\cref@stack@top{\@refsubstack}}%
        \cref@stack@pop{\@refsubstack}%
        \let\@endref\relax%
        \count@consecutive=1\relax%
      \fi%
%    \end{macrocode}
% If the start and end labels are identical, treat it as a single
% reference instead of a range
%    \begin{macrocode}
      \ifnum\count@consecutive>1\relax%
        \csname\cref@variant@get @getlabel\endcsname{\@beginref}{\@labela}%
        \csname\cref@variant@get @getlabel\endcsname{\@endref}{\@labelb}%
        \ifx\@labela\@labelb%
          \let\@endref\relax%
          \count@consecutive=1\relax%
        \fi%
      \fi%
%    \end{macrocode}
% If there were only two consecutive references, keep the first one and
% return the second one to the substack. (We add an empty reference after
% it just to make sure there's no further compression.)
%    \begin{macrocode}
      \ifnum\count@consecutive=2\relax%
        \expandafter\cref@stack@push\expandafter{\@endref,}{\@refsubstack}%
        \let\@endref\relax%
        \count@consecutive=1\relax%
      \fi%
%    \end{macrocode}
% Work out which type of reference we need to typeset.
%    \begin{macrocode}
      \cref@isstackfull{\@refsubstack}%
      \if@cref@stackfull%
        \ifnum\count@subgroup=1\relax%
          \def\@pos{@first}%
        \else%
          \def\@pos{@middle}%
        \fi%
      \else%
        \ifnum\count@subgroup=1\relax%
          \def\@pos{}%
        \else%
          \ifnum\count@subgroup=2\relax%
            \def\@pos{@second}%
          \else%
            \def\@pos{@last}%
          \fi%
        \fi%
      \fi%
%    \end{macrocode}
% If there were no consecutive references, just typeset the next
% reference;
%    \begin{macrocode}
      \ifnum\count@consecutive=1\relax%
        \edef\@tempa{{\@beginref}{\@pos}}%
        \csname @set\cref@variant\expandafter\endcsname\@tempa%
%    \end{macrocode}
% otherwise, typeset a reference range.
%    \begin{macrocode}
      \else%
        \edef\@tempa{{\@beginref}{\@endref}{\@pos}}%
        \csname @set\cref@variant range\expandafter\endcsname\@tempa%
      \fi%
      \advance\count@subgroup 1\relax%
      \cref@isstackfull{\@refsubstack}%
    }% end loop over reference substack
    \cref@isstackfull{\@refstack}%
%    \end{macrocode}
%
% If we're typesetting a \cmd{\labelcref} reference and references in
% stack have different types, throw a warning and stop processing.
%    \begin{macrocode}
    \if@cref@stackfull%
      \def\@tempa{labelcref}%
      \ifx\cref@variant\@tempa%
        \protect\G@refundefinedtrue%
        \nfss@text{\reset@font\bfseries\space ??}%
        \@latex@warning{References in label reference on page \thepage
          \space have different types}%
        \@cref@stackfullfalse%
      \fi%
    \fi%
  }% end loop over main reference stack
  \endgroup}%
%    \end{macrocode}
% \end{macro}
%
%
% \begin{macro}{\@setcref}
% \begin{macro}{\@setCref}
% \begin{macro}{\@setlavelcref}
% \begin{macro}{\@@setcref}
%   The \cmd{\@setcref}, \cmd{\@setCref} and \cmd{\@setlabelcref} macros
%   are called as appropriate by \cmd{\@cref} to typeset a reference.
%   These macros just turn the |cref|, |Cref| or |labelcref| variant into
%   a macro argument and pass it along to \cmd{\@@setcref}, which deals
%   with actually typesetting the reference by calling the appropriate
%   type-dependent formatting macro defined by \cmd{\crefformat} etc.
%   \cmd{\@@setcref} takes three arguments. |#1| is the variant passed
%   along by |\@set|\meta{x}|ref|. |#2| contains the reference itself.
%   |#3| is either empty or one of ``@second'', ``@middle'' or ``@last'',
%   determining the type of reference group to typeset.
%    \begin{macrocode}
\def\@setcref{\@@setcref{cref}}%
\def\@setCref{\@@setcref{Cref}}%
\def\@setlabelcref{\@@setcref{labelcref}}%
\def\@@setcref#1#2#3{%
  \expandafter\ifx\csname r@#2@cref\endcsname\relax%
    \protect\G@refundefinedtrue%
    \nfss@text{\reset@font\bfseries ??}%
    \@latex@warning{Reference `#2' on page \thepage \space undefined}%
  \else%
    \cref@gettype{#2}{\@temptype}%  puts label type in \@temptype
    \cref@getlabel{#2}{\@templabel}%  puts label in \@templabel
    \expandafter\ifx\csname #1@\@temptype @format#3\endcsname\relax%
%    \end{macrocode}
%     If reference format is undefined, but we're typesetting a
%     \cmd{\labelcref}, fall back to default \cmd{\labelcref} format.
%    \begin{macrocode}
      \edef\@tempa{#1}\def\@tempb{labelcref}%
      \ifx\@tempa\@tempb\relax%
        \expandafter\@@@setcref\expandafter%
          {\csname #1@default@format#3\endcsname}{#2}%
      \else%
        \protect\G@refundefinedtrue%
        \nfss@text{\reset@font\bfseries ??}~\@templabel%
        \@latex@warning{#1\space reference format for label type
          `\@temptype' undefined}%
      \fi%
    \else%
      \expandafter\@@@setcref\expandafter%
        {\csname #1@\@temptype @format#3\endcsname}{#2}%
    \fi%
  \fi}%
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\@@@setcref}
%   We separate out the very final typesetting step into a separate
%   macro, in order to make it easier to redefine things later to make
%   them work with the \package{hyperref} package.
%    \begin{macrocode}
\def\@@@setcref#1#2{\cref@getlabel{#2}{\@templabel}#1{\@templabel}{}{}}%
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\@setcrefrange}
% \begin{macro}{\@setCrefrange}
% \begin{macro}{\@setlabelcrefrange}
% \begin{macro}{\@@setcrefrange}
%   The \cmd{\@setcrefrange}, \cmd{\@setCrefrange} and
%   \cmd{\@setlabelrefrange} macros are called as appropriate by
%   \cmd{\@cref} to typeset a reference. The internal
%   \cmd{\@@setcrefrange} macro deals with actually typesetting reference
%   ranges, and takes four arguments. |#1| is the variant passed along by
%   |\@set|\meta{x}|ref|. |#2| and |#3| contains the references
%   themselves. |#4| is either empty or one of ``@second'', ``@middle''
%   or ``@last'', determining the type of reference group to typeset.
%
%   The actual typesetting is no more complicated than in the
%   \cmd{\@@setcref} case; it's the error checking that makes the code
%   longer. We now have to check whether \emph{two} references are
%   undefined, whether \emph{two} reference formats are undefined,
%   whether the reference types are consistent, and also combinations of
%   these various errors.
%    \begin{macrocode}
\def\@setcrefrange{\@@setcrefrange{cref}}%
\def\@setCrefrange{\@@setcrefrange{Cref}}%
\def\@setlabelcrefrange{\@@setcrefrange{labelcref}}%
\def\@@setcrefrange#1#2#3#4{%
  \begingroup%
%    \end{macrocode}
% Check if both references are defined.
%    \begin{macrocode}
    \expandafter\ifx\csname r@#2@cref\endcsname\relax%
      \protect\G@refundefinedtrue%
      \@latex@warning{Reference `#2' on page \thepage \space%
        undefined}%
      \expandafter\ifx\csname r@#3@cref\endcsname\relax%
        \nfss@text{\reset@font\bfseries ??}--%
        \nfss@text{\reset@font\bfseries ??}%
        \@latex@warning{Reference `#3' on page \thepage \space%
          undefined}%
      \else%
        \cref@getlabel{#3}{\@labelb}%
        \nfss@text{\reset@font\bfseries ??}--\@labelb%
      \fi%
    \else%
      \expandafter\ifx\csname r@#3@cref\endcsname\relax%
        \protect\G@refundefinedtrue%
        \cref@getlabel{#2}{\@labela}%
        \@labela--\nfss@text{\reset@font\bfseries ??}%
        \@latex@warning{Reference `#3' on page \thepage %
          \space undefined}%
%    \end{macrocode}
%   If both references are defined, check that the reference format is
%   defined.
%    \begin{macrocode}
      \else%
        \cref@gettype{#2}{\@typea}%
        \cref@gettype{#3}{\@typeb}%
        \cref@getlabel{#2}{\@labela}%
        \cref@getlabel{#3}{\@labelb}%
        \edef\@format{\expandafter\noexpand%
          \csname #1range@\@typea @format#4\endcsname}%
        \expandafter\ifx\@format\relax%
%    \end{macrocode}
%         If reference format is undefined, but we're typesetting a
%         \cmd{\labelcref}, fall back to default \cmd{\labelcref}
%         formats.
%    \begin{macrocode}
          \edef\@tempa{#1}\def\@tempb{labelcref}%
          \ifx\@tempa\@tempb\relax%
            \expandafter\@@@setcrefrange\expandafter%
              {\csname #1range@default@format#4\endcsname}{#2}{#3}%
          \else%
            \protect\G@refundefinedtrue%
            \nfss@text{\reset@font\bfseries ??}~\@labela--\@labelb%
            \@latex@warning{#1 reference range format for label
              type `\@typea' undefined}%
          \fi%
        \else%
%    \end{macrocode}
%     If reference types are identical, typeset reference range,
%     otherwise display warning.\\
%     (Note: there's no need to check if reference format for second type
%     is defined, since if it isn't it will be caught here as a
%     non-identical type.)
%    \begin{macrocode}
          \expandafter\expandafter\expandafter\def%
            \expandafter\expandafter\expandafter\@formata%
            \expandafter\expandafter\expandafter{%
              \csname #1range@\@typea @format#4\endcsname%
              {\@dummya}{\@dummyb}{\@dummyc}{\@dummyd}{\@dummye}{\@dummyf}}%
          \expandafter\expandafter\expandafter\def%
            \expandafter\expandafter\expandafter\@formatb%
            \expandafter\expandafter\expandafter{%
              \csname #1range@\@typeb @format#4\endcsname%
              {\@dummya}{\@dummyb}{\@dummyc}{\@dummyd}{\@dummye}{\@dummyf}}%
          \ifx\@formata\@formatb%
            \expandafter\@@@setcrefrange\expandafter{\@format}{#2}{#3}%
          \else%
            \protect\G@refundefinedtrue%
            \nfss@text{\reset@font\bfseries ??}~\@labela--\@labelb%
            \@latex@warning{References `#2' and `#3' in reference range
              on page \thepage \space have different types
              `\@typea' and `\@typeb'}%
          \fi%
        \fi%
      \fi%
    \fi%
  \endgroup}%
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\@@@setcrefrange}
%   We again separate out the very final typesetting step into a
%   separate macro, in order to make it easier to redefine things later
%   to make them work with the \package{hyperref} package.
%    \begin{macrocode}
\def\@@@setcrefrange#1#2#3{%
  \cref@getlabel{#2}{\@labela}%
  \cref@getlabel{#3}{\@labelb}%
  #1{\@labela}{\@labelb}{}{}{}{}}%
%    \end{macrocode}
% \end{macro}
%
%
% The typesetting of conjunctions is also separated out into separate
% macros, for the same reason.
%    \begin{macrocode}
\def\@setcref@pairgroupconjunction{\crefpairgroupconjunction}%
\def\@setcref@middlegroupconjunction{\crefmiddlegroupconjunction}%
\def\@setcref@lastgroupconjunction{\creflastgroupconjunction}%
%    \end{macrocode}
%
% \begin{macro}{\labelcref}
% \begin{macro}{\namecref}
% \begin{macro}{\nameCref}
% \begin{macro}{\lcnamecref}
% \begin{macro}{\namecrefs}
% \begin{macro}{\nameCrefs}
% \begin{macro}{\lcnamecrefs}
%   Finally, we define a \cmd{\labelcref} command that returns just the
%   typeset label part of a (multi-)reference, without the reference
%   name, and conversely \cmd{\namecref}, \cmd{\nameCref},
%   \cmd{\namecrefs} and \cmd{\nameCrefs} commands that return just the
%   typeset name of a reference, without the reference label. The latter
%   four retrieve the reference name from the corresponding
%   \cmd{\crefname} or \cmd{\Crefname} definition, so they only work when
%   this has been defined. We also define \cmd{\lcnamecref} and
%   \cmd{\lcnamecrefs} commands which force the reference name to
%   lowercase, for use when the \option{capitalise} option is enabled.
%    \begin{macrocode}
\DeclareRobustCommand{\labelcref}[1]{\@cref{labelcref}{#1}}%
\DeclareRobustCommand{\namecref}[1]{%
  \@setnamecref{cref}{#1}{}{}}%
\DeclareRobustCommand{\nameCref}[1]{%
  \@setnamecref{Cref}{#1}{}{}}%
\DeclareRobustCommand{\lcnamecref}[1]{%
  \@setnamecref{Cref}{#1}{}{\MakeLowercase}}%
\DeclareRobustCommand{\namecrefs}[1]{%
  \@setnamecref{cref}{#1}{@plural}{}}%
\DeclareRobustCommand{\nameCrefs}[1]{%
  \@setnamecref{Cref}{#1}{@plural}{}}%
\DeclareRobustCommand{\lcnamecrefs}[1]{%
  \@setnamecref{Cref}{#1}{@plural}{\MakeLowercase}}%
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\@setnamecref}
%   \cmd{\@setnamecref} is the real macro underlying all the
%   \cmd{\namecref} commands. |#1| is the capitalisation variant, |#2|
%   the reference, |#3| is either empty or |@plural| if the plural name
%   should be generated, and |#4| is either empty or contains
%   \cmd{\MakeLowercase} if a lower-cased name should be generated.
%    \begin{macrocode}
\def\@setnamecref#1#2#3#4{%
  \expandafter\ifx\csname r@#2@cref\endcsname\relax%
    \protect\G@refundefinedtrue%
    \nfss@text{\reset@font\bfseries ??}%
    \@latex@warning{Reference `#2' on page \thepage \space undefined}%
  \else%
    \cref@gettype{#2}{\@tempa}%
    \@ifundefined{#1@\@tempa @name#3}{%
      \protect\G@refundefinedtrue%
      \nfss@text{\reset@font\bfseries ??}%
      \@latex@warning{Reference name for label type `\@tempa' undefined}%
    }{%
      \edef\@tempa{%
        \expandafter\noexpand\csname #1@\@tempa @name#3\endcsname}%
      \expandafter\@@@setnamecref\expandafter{\@tempa}{#4}%
    }%
  \fi}%
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\@@@setnamecref}
%   We again separate out the final typesetting step of the
%   \cmd{\namecref} commands.
%    \begin{macrocode}
\def\@@@setnamecref#1#2{%
  \expandafter\def\expandafter\@tempa\expandafter{#1}%
  \expandafter#2\@tempa}%
%    \end{macrocode}
% \end{macro}
%
%
%
% \subsection{Page-Referencing Commands}
% \begin{macro}{\cpageref}
% \begin{macro}{\Cpageref}
% \begin{macro}{\cpagerefrange}
% \begin{macro}{\Cpagerefrange}
%   Define the main page referencing command \cmd{\cpageref} and the
%   start-of-sentence variant \cmd{\Cpageref}, along with the
%   \cmd{\cpagerefrange} and \cmd{\Cpagerefrange} page range referencing
%   commands, and \cmd{\labelcpageref} (the counterpart to
%   \cmd{\labelcref}).
%    \begin{macrocode}
\DeclareRobustCommand{\cpageref}[1]{\@cref{cpageref}{#1}}%
\DeclareRobustCommand{\Cpageref}[1]{\@cref{Cpageref}{#1}}%
\DeclareRobustCommand{\cpagerefrange}[2]{%
  \@@setcpagerefrange{#1}{#2}{cref}{}}%
\DeclareRobustCommand{\Cpagerefrange}[2]{%
  \@@setcpagerefrange{#1}{#2}{Cref}{}}%
\DeclareRobustCommand{\labelcpageref}[1]{%
  \@cref{labelcpageref}{#1}}%
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\@setcpageref}
% \begin{macro}{\@setCpageref}
% \begin{macro}{\@setlabelcpageref}
% \begin{macro}{\@@setcpageref}
%   The \cmd{\@setcpageref}, \cmd{\@setCpageref} and
%   \cmd{\@setlabelcpageref} macros are called as appropriate by
%   \cmd{\@cref} to typeset a page reference. These macros just turn the
%   |cref|, |Cref| or |labelcref| variant into a macro argument and pass
%   it along to \cmd{\@@setcpageref}, which deals with actually
%   typesetting the page reference by calling the appropriate page
%   reference formatting macro defined by \cmd{\crefformat}|{page}| etc.
%   \cmd{\@@setcpageref} takes four arguments. |#1| is the variant passed
%   along by |\@set|\meta{x}|pageref|. |#2| contains the reference
%   itself. |#3| is either empty or one of ``@second'', ``@middle'' or
%   ``@last'', determining the type of page reference group to typeset.
%    \begin{macrocode}
\def\@setcpageref{\@@setcpageref{cref}}
\def\@setCpageref{\@@setcpageref{Cref}}
\def\@setlabelcpageref{\@@setcpageref{labelcref}}
\def\@@setcpageref#1#2#3{%
  \expandafter\ifx\csname r@#2@cref\endcsname\relax%
    \protect\G@refundefinedtrue%
    \nfss@text{\reset@font\bfseries ??}%
    \@latex@warning{Reference `#2' on page \thepage \space undefined}%
  \else%
    \cpageref@getlabel{#2}{\@temppage}%
    \expandafter\ifx\csname #1@page@format#3\endcsname\relax%
%    \end{macrocode}
%     If reference format is undefined, but we're typesetting a
%     \cmd{\labelcpageref}, fall back to default \cmd{\labelcref} format.
%    \begin{macrocode}
      \edef\@tempa{#1}\def\@tempb{labelcref}%
      \ifx\@tempa\@tempb\relax%
        \expandafter\@@@setcpageref\expandafter%
          {\csname #1@default@format#3\endcsname}{#2}%
      \else%
        \protect\G@refundefinedtrue%
        \nfss@text{\reset@font\bfseries ??}~\@temppage%
        \@latex@warning{ #1 reference format for
          page references undefined}%
      \fi%
    \else%
      \expandafter\@@@setcpageref\expandafter%
        {\csname #1@page@format#3\endcsname}{#2}%
    \fi%
  \fi}%
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\@@@setcpageref}
%   We separate out the very final typesetting step into a separate
%   macro, in order to make it easier to redefine things later to make
%   them work with the \package{hyperref} package.
%    \begin{macrocode}
\def\@@@setcpageref#1#2{%
  \cpageref@getlabel{#2}{\@temppage}#1{\@temppage}{}{}}%
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\@@setcpagerefrange}
%   The \cmd{\@@setcpagerefrange} macro deals with typesetting page range
%   references, just as \cmd{\@@setcpageref} does for normal page
%   references.
%    \begin{macrocode}
\def\@@setcpagerefrange#1#2#3#4{%
  \begingroup%
%    \end{macrocode}
% Check if both references are defined.
%    \begin{macrocode}
    \expandafter\ifx\csname r@#1@cref\endcsname\relax%
      \protect\G@refundefinedtrue%
      \@latex@warning{Reference `#1' on page \thepage \space%
        undefined}%
      \expandafter\ifx\csname r@#2@cref\endcsname\relax%
        \nfss@text{\reset@font\bfseries ??}--%
        \nfss@text{\reset@font\bfseries ??}%
        \@latex@warning{Reference `#2' on page \thepage \space%
          undefined}%
      \else%
        \cpageref@getlabel{#2}{\@pageb}%
        \nfss@text{\reset@font\bfseries ??}--\@pageb%
      \fi%
    \else%
      \expandafter\ifx\csname r@#2@cref\endcsname\relax%
        \protect\G@refundefinedtrue%
        \cpageref@getlabel{#1}{\@pagea}%
        \@pagea--\nfss@text{\reset@font\bfseries ??}%
        \@latex@warning{Reference `#2' on page \thepage %
          \space undefined}%
%    \end{macrocode}
%   If both references are defined, check that the reference format is
%   defined.
%    \begin{macrocode}
      \else%
        \cpageref@getlabel{#1}{\@pagea}%
        \cpageref@getlabel{#2}{\@pageb}%
        \edef\@format{\expandafter\noexpand%
          \csname#3range@page@format#4\endcsname}%
        \expandafter\ifx\@format\relax%
%    \end{macrocode}
%         If page reference format is undefined, but we're typesetting a
%         \cmd{\labelcpageref}, fall back to default \cmd{\labelcref}
%         formats.
%    \begin{macrocode}
          \edef\@tempa{#3}\def\@tempb{labelcref}%
          \ifx\@tempa\@tempb\relax%
            \expandafter\@@@setcpagerefrange\expandafter%
              {\csname#3range@default@format#4\endcsname}{#1}{#2}%
          \else%
            \protect\G@refundefinedtrue%
            \nfss@text{\reset@font\bfseries ??}~\@pagea--\@pageb%
            \@latex@warning{#3 reference range format for page
              references undefined}%
          \fi%
        \else%
%    \end{macrocode}
%     typeset page reference range,
%    \begin{macrocode}
          \expandafter\@@@setcpagerefrange\expandafter{\@format}{#1}{#2}%
        \fi%
      \fi%
    \fi%
  \endgroup}%
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\@@@setcpagerefrange}
%   We again separate out the very final typesetting step into a
%   separate macro, in order to make it easier to redefine things later
%   to make them work with the \package{hyperref} package.
%    \begin{macrocode}
\def\@@@setcpagerefrange#1#2#3{%
  \cpageref@getlabel{#2}{\@pagea}%
  \cpageref@getlabel{#3}{\@pageb}%
  #1{\@pagea}{\@pageb}{}{}{}{}}%
%    \end{macrocode}
% \end{macro}
%
%
%
% \subsection{Reference Format Customisation Commands}
%
% \subsubsection{Format component commands}
% \begin{macro}{\cref@label@types}
%   The reference formats are usually constructed out of components
%   defined by the user-level \cmd{\crefname}, \cmd{\Crefname},
%   \cmd{\creflabel} and \cmd{\crefrangelabel} commands.
%   \cmd{\cref@label@types} keeps track of label types for which
%   components have been defined, and therefore need constructing at
%   \cmd{\begindocument} (see below).
%
%   FIXME: We don't check if the label type is already in the list, so
%   some formats may needlessly be redefined identically, multiple times.
%
%    \begin{macrocode}
\cref@stack@init{\cref@label@types}%
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\crefdefaultlabelformat}
% \begin{macro}{\crefname}
% \begin{macro}{\Crefname}
% \begin{macro}{\creflabelformat}
% \begin{macro}{\crefrangelabelformat}
%   The component customisation commands simply use the supplied
%   arguments to define appropriately named macros containing the
%   formatting components. If the corresponding \cmd{\Crefname} or
%   \cmd{\crefname} variant is not already defined, \cmd{\crefname} and
%   \cmd{\Crefname} define it to be a version with the first letter
%   capitalised or lower-cased, respectively.
%    \begin{macrocode}
\newcommand\crefdefaultlabelformat[1]{%
  \def\cref@default@label##1##2##3{#1}}%
\newcommand\crefname[3]{%
  \@crefname{cref}{#1}{#2}{#3}{}}%
\newcommand\Crefname[3]{%
  \@crefname{Cref}{#1}{#2}{#3}{}}%
\newcommand\creflabelformat[2]{%
  \expandafter\def\csname cref@#1@label\endcsname##1##2##3{#2}%
  \cref@stack@add{#1}{\cref@label@types}}%
\newcommand\crefrangelabelformat[2]{%
  \expandafter\def\csname cref@#1@rangelabel\endcsname%
    ##1##2##3##4##5##6{#2}%
  \cref@stack@add{#1}{\cref@label@types}}%
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\crefalias}
%   The \cmd{\crefalias} command aliases a counter name to another
%   cross-reference type, so can be used to make the same cross-reference
%   format apply to multiple different counters.
%\begin{macrocode}
\newcommand\crefalias[2]{%
  \expandafter\def\csname cref@#1@alias\endcsname{#2}}%
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\crefname@preamble}
% \begin{macro}{\Crefname@preamble}
%   The \cmd{\crefname@preamble} and \cmd{\Crefname@preamble} commands
%   are very like the \cmd{\crefname} and \cmd{\Crefname} commands, but
%   they tag ``|@preamble|'' onto the end of the generated macro names.
%   They are used when defining the default formats for different
%   languages (see \cref{sec:code:babel}).
%\begin{macrocode}
\newcommand\crefname@preamble[3]{%
  \@crefname{cref}{#1}{#2}{#3}{@preamble}}%
\newcommand\Crefname@preamble[3]{%
  \@crefname{Cref}{#1}{#2}{#3}{@preamble}}%
%    \end{macrocode}
% \end{macro}
% \end{macro}
%
%
% \begin{macro}{cref@othervariant}
%   The following utility macro sets up the appropriate definitions for
%   the other capitalisation variant. It defines the macro passed in |#2|
%   to be the other variant (``cref'' or ``Cref'') to the one specified
%   in |#1|, and defines |#3| to be the appropriate
%   capitalisation-changing command. It makes use of the fact that the
%   first character of \#1 is ``c'' for the lower-case variant and ``C''
%   for the upper-case one.
%    \begin{macrocode}
\def\cref@othervariant#1#2#3{\cref@@othervariant#1\@nil#2#3}%
\def\cref@@othervariant#1#2\@nil#3#4{%
  \if#1c%
    \def#3{C#2}%
    \def#4{\MakeUppercase}%
  \else%
    \def#3{c#2}%
    \if@cref@capitalise%
      \def#4{}%
    \else%
      \def#4{\MakeLowercase}%
    \fi%
  \fi}%
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\@crefname}
%   The \cmd{\@crefname} utility macro does the real work of defining
%   format names, by defining an appropriately named command to contain
%   the format component, and using the additional first argument
%   (``cref'' or ``Cref'') to determine how to define the corresponding
%   command with the other capitalisation. The extra fifth argument gets
%   tagged onto the end of the generated macro names. Note that
%   \cmd{\@crefname} \emph{must not} create global definitions, or else
%   it will break \package{babel}'s \cmd{\otherlanguage},
%   \cmd{\otherlanguage*} and \cmd{\foreignlanguage} commands.
%    \begin{macrocode}
\def\@crefname#1#2#3#4#5{%
  \expandafter\def\csname #1@#2@name#5\endcsname{#3}%
  \expandafter\def\csname #1@#2@name@plural#5\endcsname{#4}%
%    \end{macrocode}
% If the other capitalisation variant is not already defined\dots
%    \begin{macrocode}
  \cref@othervariant{#1}{\@tempc}{\@tempd}%
  \@ifundefined{\@tempc @#2@name#5}{%
%    \end{macrocode}
% Define \cmd{\@tempa} and \cmd{\@tempb} to be partial expansions (expanded
% just once) of the macros for the capitalisation variant we've just
% defined above.
%    \begin{macrocode}
    \expandafter\expandafter\expandafter\def%
    \expandafter\expandafter\expandafter\@tempa%
    \expandafter\expandafter\expandafter{%
      \csname#1@#2@name\endcsname}%
    \expandafter\expandafter\expandafter\def%
    \expandafter\expandafter\expandafter\@tempb%
    \expandafter\expandafter\expandafter{%
      \csname#1@#2@name@plural\endcsname}%
%    \end{macrocode}
% Add the case-change command stored in \cmd{\@tempd} to the front of the
% definitions of \cmd{\@tempa} and \cmd{\@tempb}.
%    \begin{macrocode}
    \expandafter\ifx\@tempa\@empty\else%
      \expandafter\expandafter\expandafter\def%
      \expandafter\expandafter\expandafter\@tempa%
      \expandafter\expandafter\expandafter{%
        \expandafter\@tempd\@tempa}%
      \expandafter\expandafter\expandafter\def%
      \expandafter\expandafter\expandafter\@tempb%
      \expandafter\expandafter\expandafter{%
        \expandafter\@tempd\@tempb}%
    \fi%
%    \end{macrocode}
% Define the other capitalisation variants to be the partial expansions
% (expanded just once) of \cmd{\@tempa} and \cmd{\@tempb}. The
% \cmd{\@toksa} token register just makes the code less verbose.
%    \begin{macrocode}
    \toksdef\@toksa=0%
    \@toksa={%
      \expandafter\def\csname\@tempc @#2@name#5\endcsname}%
    \expandafter\the\expandafter\@toksa\expandafter{\@tempa}%
    \@toksa={%
      \expandafter\def\csname\@tempc @#2@name@plural#5\endcsname}%
    \expandafter\the\expandafter\@toksa\expandafter{\@tempb}%
  }{}%
%    \end{macrocode}
% Add label type to list of types that need defining from components.
%    \begin{macrocode}
  \cref@stack@add{#2}{\cref@label@types}}%
%    \end{macrocode}
% \end{macro}
%
%
% \begin{macro}{\@crefconstructcomponents}
%   The \cmd{\@crefconstructcomponents} utility macro puts the reference
%   format components for the specified reference type into temporary
%   macros, for use by later macros. The ridiculous number of ``\#''
%   characters ensure that the correct number remain when they come to be
%   used later (recall that pairs ``\#\#'' are collapsed to a single
%   ``\#'' each time the code is expanded).
%    \begin{macrocode}
\def\@crefconstructcomponents#1{%
%    \end{macrocode}
% Single cross-reference label format.
%    \begin{macrocode}
  \@ifundefined{cref@#1@label}{%
    \let\@templabel\cref@default@label%
  }{%
    \expandafter\let\expandafter\@templabel%
    \csname cref@#1@label\endcsname%
  }%
%    \end{macrocode}
% Reference range label format.
%    \begin{macrocode}
  \@ifundefined{cref@#1@rangelabel}{%
    \expandafter\def\expandafter\@tempa\expandafter{%
      \@templabel{####1}{####3}{####4}}%
    \expandafter\def\expandafter\@tempb\expandafter{%
      \@templabel{####2}{####5}{####6}}%
    \toksdef\@toksa=0%
    \@toksa={\def\@temprangelabel##1##2##3##4##5##6}%
    \expandafter\expandafter\expandafter\the%
    \expandafter\expandafter\expandafter\@toksa%
    \expandafter\expandafter\expandafter{%
      \expandafter\expandafter\expandafter\crefrangepreconjunction%
      \expandafter\@tempa\expandafter\crefrangeconjunction\@tempb%
      \crefrangepostconjunction}%
  }{%
    \expandafter\let\expandafter\@temprangelabel%
    \csname cref@#1@rangelabel\endcsname%
  }%
%    \end{macrocode}
% If we're including names in hyperlinks, define variants of temporary
% label macros which lack the hyperlink start argument (it will instead
% be included in the temporary name macros).
%    \begin{macrocode}
  \if@cref@nameinlink%
    \expandafter\def\expandafter\@templabel@first\expandafter{%
      \@templabel{########1}{}{########3}}%
    \expandafter\def\expandafter\@temprangelabel@first\expandafter{%
      \@temprangelabel{########1}{########2}%
        {}{########4}{########5}{########6}}%
  \fi%
%    \end{macrocode}
% Get the correct number of ``\#'''s into the label format definitions.
%    \begin{macrocode}
  \expandafter\def\expandafter\@templabel\expandafter{%
    \@templabel{########1}{########2}{########3}}%
  \expandafter\def\expandafter\@temprangelabel\expandafter{%
    \@temprangelabel{########1}{########2}{########3}%
    {########4}{########5}{########6}}%
%    \end{macrocode}
% If we're not including names in hyperlinks, define all variants to be
% the same as standard temporary name macros.
%    \begin{macrocode}
  \if@cref@nameinlink\else%
    \let\@templabel@first\@templabel%
    \let\@temprangelabel@first\@temprangelabel%
  \fi%
%    \end{macrocode}
%
% If including names in hyperlinks, define temporary name macros to
% include hyperlink start argument.
%    \begin{macrocode}
  \if@cref@nameinlink%
    \def\@tempa##1##2{##2##1}%
%    \end{macrocode}
% Lower-case singular cross-reference name.
%    \begin{macrocode}
    \expandafter\expandafter\expandafter\def%
    \expandafter\expandafter\expandafter\@tempname%
    \expandafter\expandafter\expandafter{%
      \expandafter\@tempa\expandafter%
        {\csname cref@#1@name\endcsname}{########2}}%
%    \end{macrocode}
% Upper-case singular cross-reference name.
%    \begin{macrocode}
    \expandafter\expandafter\expandafter\def%
    \expandafter\expandafter\expandafter\@tempName%
    \expandafter\expandafter\expandafter{%
      \expandafter\@tempa\expandafter%
        {\csname Cref@#1@name\endcsname}{########2}}%
%    \end{macrocode}
% Lower-case plural cross-reference name.
%    \begin{macrocode}
    \expandafter\expandafter\expandafter\def%
    \expandafter\expandafter\expandafter\@tempnameplural%
    \expandafter\expandafter\expandafter{%
      \expandafter\@tempa\expandafter%
        {\csname cref@#1@name@plural\endcsname}{########2}}%
%    \end{macrocode}
% Upper-case plural cross-reference name.
%    \begin{macrocode}
    \expandafter\expandafter\expandafter\def%
    \expandafter\expandafter\expandafter\@tempNameplural%
    \expandafter\expandafter\expandafter{%
      \expandafter\@tempa\expandafter%
        {\csname Cref@#1@name@plural\endcsname}{########2}}%
%    \end{macrocode}
% For cross-reference ranges, the hyperlink start argument is \#3 instead
% of \#2, so we need a different variant of the temporary plural name
% macros.
%    \begin{macrocode}
    \expandafter\expandafter\expandafter\def%
    \expandafter\expandafter\expandafter\@tempnameplural@range%
    \expandafter\expandafter\expandafter{%
      \expandafter\@tempa\expandafter%
        {\csname cref@#1@name@plural\endcsname}{########3}}%
    \expandafter\expandafter\expandafter\def%
    \expandafter\expandafter\expandafter\@tempNameplural@range%
    \expandafter\expandafter\expandafter{%
      \expandafter\@tempa\expandafter%
        {\csname Cref@#1@name@plural\endcsname}{########3}}%
%    \end{macrocode}
%
% If we're not including names in hyperlinks, temporary name macros don't
% include the hyperlink start argument.
%    \begin{macrocode}
  \else%
%    \end{macrocode}
% Lower-case singular cross-reference name.
%    \begin{macrocode}
    \expandafter\def\expandafter\@tempname\expandafter{%
      \csname cref@#1@name\endcsname}%
%    \end{macrocode}
% Upper-case singular cross-reference name.
%    \begin{macrocode}
    \expandafter\def\expandafter\@tempName\expandafter{%
      \csname Cref@#1@name\endcsname}%
%    \end{macrocode}
% Lower-case plural cross-reference name.
%    \begin{macrocode}
    \expandafter\def\expandafter\@tempnameplural\expandafter{%
      \csname cref@#1@name@plural\endcsname}%
%    \end{macrocode}
% Upper-case plural cross-reference name.
%    \begin{macrocode}
    \expandafter\def\expandafter\@tempNameplural\expandafter{%
      \csname Cref@#1@name@plural\endcsname}%
%    \end{macrocode}
% Define reference range variants to be identical to normal variants.
%    \begin{macrocode}
    \let\@tempnameplural@range\@tempnameplural%
    \let\@tempNameplural@range\@tempNameplural%
  \fi%
}%
%    \end{macrocode}
% \end{macro}
%
%
% \begin{macro}{\@crefdefineformat}
%   The \cmd{\@crefdefineformat} et al.\ macros construct calls to
%   \cmd{\crefformat} et al.\ for the supplied reference type, which
%   define the corresponding formats in terms of the format components.
%   This is mostly just an arduous exercise in controlling macro
%   expansion order.
%    \begin{macrocode}
\def\@crefdefineformat#1{%
  \begingroup%
%    \end{macrocode}
% Put format components into tmp macros.
%    \begin{macrocode}
    \@crefconstructcomponents{#1}%
%    \end{macrocode}
% Assemble the arguments for \cmd{\crefformat}, \cmd{\Crefformat} and
% \cmd{\labelcrefformat} from the components.
%    \begin{macrocode}
    \expandafter\ifx\csname cref@#1@name\endcsname\@empty\relax%
      \expandafter\def\expandafter\@tempfirst\expandafter{\@templabel}%
    \else%
      \expandafter\expandafter\expandafter\def%
      \expandafter\expandafter\expandafter\@tempfirst%
      \expandafter\expandafter\expandafter{%
        \expandafter\@tempname\expandafter\nobreakspace\@templabel@first}%
    \fi%
    \expandafter\ifx\csname Cref@#1@name\endcsname\@empty\relax%
      \expandafter\def\expandafter\@tempFirst\expandafter{\@templabel}%
    \else%
      \expandafter\expandafter\expandafter\def%
      \expandafter\expandafter\expandafter\@tempFirst%
      \expandafter\expandafter\expandafter{%
        \expandafter\@tempName\expandafter\nobreakspace\@templabel@first}%
    \fi%
    \expandafter\def\expandafter\@templabel\expandafter{\@templabel}%
%    \end{macrocode}
% Define \cmd{\crefformat} and \cmd{\Crefformat}.
%    \begin{macrocode}
    \toksdef\@toksa=0%
    \@toksa={\crefformat{#1}}%
    \expandafter\the\expandafter\@toksa\expandafter{\@tempfirst}%
    \@toksa={\Crefformat{#1}}%
    \expandafter\the\expandafter\@toksa\expandafter{\@tempFirst}%
%    \end{macrocode}
% Define \cmd{\labelcrefformat} if type has custom label format.
%    \begin{macrocode}
    \@ifundefined{cref@#1@label}{}{%
      \@toksa={\labelcrefformat{#1}}%
      \expandafter\the\expandafter\@toksa\expandafter{\@templabel}}%
  \endgroup}%
%    \end{macrocode}
% \end{macro}
%
%
% \begin{macro}{\@crefrangedefineformat}
%   Construct call to \cmd{\crefrangeformat}.
%    \begin{macrocode}
\def\@crefrangedefineformat#1{%
  \begingroup%
%    \end{macrocode}
% Put format components into tmp macros.
%    \begin{macrocode}
    \@crefconstructcomponents{#1}%
%    \end{macrocode}
% Assemble the arguments for \cmd{\crefrangeformat},
% \cmd{\Crefrangeformat} and\linebreak[4] \cmd{\labelcrefrangeformat}
% from the components.
%    \begin{macrocode}
    \expandafter\ifx\csname cref@#1@name\endcsname\@empty\relax%
      \expandafter\def\expandafter\@tempfirst%
        \expandafter{\@temprangelabel}%
    \else%
      \expandafter\expandafter\expandafter\def%
      \expandafter\expandafter\expandafter\@tempfirst%
      \expandafter\expandafter\expandafter{%
        \expandafter\@tempnameplural@range%
        \expandafter\nobreakspace\@temprangelabel@first}%
    \fi%
    \expandafter\ifx\csname Cref@#1@name\endcsname\@empty\relax%
      \expandafter\def\expandafter\@tempFirst%
        \expandafter{\@temprangelabel}%
    \else%
      \expandafter\expandafter\expandafter\def%
      \expandafter\expandafter\expandafter\@tempFirst%
      \expandafter\expandafter\expandafter{%
        \expandafter\@tempNameplural@range%
        \expandafter\nobreakspace\@temprangelabel@first}%
    \fi%
    \expandafter\def\expandafter\@temprangelabel%
      \expandafter{\@temprangelabel}%
%    \end{macrocode}
% Define \cmd{\crefrangeformat} and \cmd{\Crefrangeformat}.
%    \begin{macrocode}
    \toksdef\@toksa=0%
    \@toksa={\crefrangeformat{#1}}%
    \expandafter\the\expandafter\@toksa\expandafter{\@tempfirst}%
    \@toksa={\Crefrangeformat{#1}}%
    \expandafter\the\expandafter\@toksa\expandafter{\@tempFirst}%
%    \end{macrocode}
% Define \cmd{\labelcrefrangeformat} if type has custom label format.
%    \begin{macrocode}
    \@ifundefined{cref@#1@rangelabel}{%
      \@ifundefined{cref@#1@label}{\let\@tempa\relax}{\def\@tempa{}}}%
      {\def\@tempa{}}%
    \ifx\@tempa\@empty\relax%
      \@toksa={\labelcrefrangeformat{#1}}%
      \expandafter\the\expandafter\@toksa\expandafter{%
        \@temprangelabel}%
    \fi%
  \endgroup}%
%    \end{macrocode}
% \end{macro}
%
%
% \begin{macro}{\@crefdefinemultiformat}
%   Construct call to \cmd{\crefmultiformat}.
%    \begin{macrocode}
\def\@crefdefinemultiformat#1{%
  \begingroup%
%    \end{macrocode}
% Put format components into tmp macros.
%    \begin{macrocode}
    \@crefconstructcomponents{#1}%
%    \end{macrocode}
% Assemble the arguments for \cmd{\crefmultiformat},
% \cmd{\Crefmultiformat} and\linebreak[4] \cmd{\labelcrefmultiformat}
% from the components.
%    \begin{macrocode}
    \expandafter\ifx\csname cref@#1@name@plural\endcsname\@empty\relax%
      \expandafter\def\expandafter\@tempfirst%
        \expandafter{\@templabel}%
    \else%
      \expandafter\expandafter\expandafter\def%
      \expandafter\expandafter\expandafter\@tempfirst%
      \expandafter\expandafter\expandafter{%
        \expandafter\@tempnameplural%
        \expandafter\nobreakspace\@templabel@first}%
    \fi%
    \expandafter\ifx\csname Cref@#1@name@plural\endcsname\@empty\relax%
      \expandafter\def\expandafter\@tempFirst%
        \expandafter{\@templabel}%
    \else%
      \expandafter\expandafter\expandafter\def%
      \expandafter\expandafter\expandafter\@tempFirst%
      \expandafter\expandafter\expandafter{%
        \expandafter\@tempNameplural%
        \expandafter\nobreakspace\@templabel@first}%
    \fi%
    \expandafter\def\expandafter\@tempsecond\expandafter{%
      \expandafter\crefpairconjunction\@templabel}%
    \expandafter\def\expandafter\@tempmiddle\expandafter{%
      \expandafter\crefmiddleconjunction\@templabel}%
    \expandafter\def\expandafter\@templast\expandafter{%
      \expandafter\creflastconjunction\@templabel}%
    \expandafter\def\expandafter\@templabel\expandafter{\@templabel}%
%    \end{macrocode}
% Bundle all four arguments for \cmd{\crefmultiformat} in token register
% \cmd{\@toksb}, then call it.
%    \begin{macrocode}
    \toksdef\@toksa=0%
    \toksdef\@toksb=1%
    \@toksb={}%
    \expandafter\cref@append@toks\expandafter\@toksb\expandafter{%
      \expandafter{\@tempfirst}}%
    \expandafter\cref@append@toks\expandafter\@toksb\expandafter{%
      \expandafter{\@tempsecond}}%
    \expandafter\cref@append@toks\expandafter\@toksb\expandafter{%
      \expandafter{\@tempmiddle}}%
    \expandafter\cref@append@toks\expandafter\@toksb\expandafter{%
      \expandafter{\@templast}}%
    \@toksa={\crefmultiformat{#1}}%
    \expandafter\the\expandafter\@toksa\the\@toksb%
%    \end{macrocode}
% Bundle all four arguments for \cmd{\Crefmultiformat} in token register
% \cmd{\@toksb}, then call it.
%    \begin{macrocode}
    \@toksb={}%
    \expandafter\cref@append@toks\expandafter\@toksb\expandafter{%
      \expandafter{\@tempFirst}}%
    \expandafter\cref@append@toks\expandafter\@toksb\expandafter{%
      \expandafter{\@tempsecond}}%
    \expandafter\cref@append@toks\expandafter\@toksb\expandafter{%
      \expandafter{\@tempmiddle}}%
    \expandafter\cref@append@toks\expandafter\@toksb\expandafter{%
      \expandafter{\@templast}}%
    \@toksa={\Crefmultiformat{#1}}%
    \expandafter\the\expandafter\@toksa\the\@toksb%
%    \end{macrocode}
% If type has custom label format, bundle all four arguments
% for\linebreak[4] \cmd{\labelcrefmultiformat} in token register
% \cmd{\@toksb}, then call it.
%    \begin{macrocode}
    \@ifundefined{cref@#1@label}{}{%
      \@toksb={}%
      \expandafter\cref@append@toks\expandafter\@toksb\expandafter{%
        \expandafter{\@templabel}}%
      \expandafter\cref@append@toks\expandafter\@toksb\expandafter{%
        \expandafter{\@tempsecond}}%
      \expandafter\cref@append@toks\expandafter\@toksb\expandafter{%
        \expandafter{\@tempmiddle}}%
      \expandafter\cref@append@toks\expandafter\@toksb\expandafter{%
        \expandafter{\@templast}}%
      \@toksa={\labelcrefmultiformat{#1}}%
      \expandafter\the\expandafter\@toksa\the\@toksb}%
  \endgroup}%
%    \end{macrocode}
% \end{macro}
%
%
% \begin{macro}{\@crefrangedefinemultiformat}
%   Construct call to \cmd{\crefrangemultiformat}.
%    \begin{macrocode}
\def\@crefrangedefinemultiformat#1{%
  \begingroup%
%    \end{macrocode}
% Put format components into tmp macros.
%    \begin{macrocode}
    \@crefconstructcomponents{#1}%
%    \end{macrocode}
% Assemble the arguments that need to be passed to
% \cmd{\crefrangemultiformat}, \cmd{\Crefrangemultiformat} and
% \cmd{\labelcrefrangemultiformat} from the reference components.
%    \begin{macrocode}
    \expandafter\ifx\csname cref@#1@name@plural\endcsname\@empty\relax%
      \expandafter\def\expandafter\@tempfirst%
        \expandafter{\@temprangelabel}%
    \else%
      \expandafter\expandafter\expandafter\def%
      \expandafter\expandafter\expandafter\@tempfirst%
      \expandafter\expandafter\expandafter{%
        \expandafter\@tempnameplural@range%
        \expandafter\nobreakspace\@temprangelabel@first}%
    \fi%
    \expandafter\ifx\csname Cref@#1@name@plural\endcsname\@empty\relax%
      \expandafter\def\expandafter\@tempFirst%
        \expandafter{\@temprangelabel}%
    \else%
      \expandafter\expandafter\expandafter\def%
      \expandafter\expandafter\expandafter\@tempFirst%
      \expandafter\expandafter\expandafter{%
        \expandafter\@tempNameplural@range%
        \expandafter\nobreakspace\@temprangelabel@first}%
    \fi%
    \expandafter\def\expandafter\@tempsecond\expandafter{%
      \expandafter\crefpairconjunction\@temprangelabel}%
    \expandafter\def\expandafter\@tempmiddle\expandafter{%
      \expandafter\crefmiddleconjunction\@temprangelabel}%
    \expandafter\def\expandafter\@templast\expandafter{%
      \expandafter\creflastconjunction\@temprangelabel}%
    \expandafter\def\expandafter\@temprangelabel%
      \expandafter{\@temprangelabel}%
%    \end{macrocode}
% Bundle all four arguments for \cmd{\crefrangemultiformat} in token
% register \cmd{\@toksb}, then call it.
%    \begin{macrocode}
    \toksdef\@toksa=0%
    \toksdef\@toksb=1%
    \@toksb={}%
    \expandafter\cref@append@toks\expandafter\@toksb\expandafter{%
      \expandafter{\@tempfirst}}%
    \expandafter\cref@append@toks\expandafter\@toksb\expandafter{%
      \expandafter{\@tempsecond}}%
    \expandafter\cref@append@toks\expandafter\@toksb\expandafter{%
      \expandafter{\@tempmiddle}}%
    \expandafter\cref@append@toks\expandafter\@toksb\expandafter{%
      \expandafter{\@templast}}%
    \@toksa={\crefrangemultiformat{#1}}%
    \expandafter\the\expandafter\@toksa\the\@toksb%
%    \end{macrocode}
% Bundle all four arguments for \cmd{\Crefrangemultiformat} in token
% register \cmd{\@toksb}, then call it.
%    \begin{macrocode}
    \@toksb={}%
    \expandafter\cref@append@toks\expandafter\@toksb\expandafter{%
      \expandafter{\@tempFirst}}%
    \expandafter\cref@append@toks\expandafter\@toksb\expandafter{%
      \expandafter{\@tempsecond}}%
    \expandafter\cref@append@toks\expandafter\@toksb\expandafter{%
      \expandafter{\@tempmiddle}}%
    \expandafter\cref@append@toks\expandafter\@toksb\expandafter{%
      \expandafter{\@templast}}%
    \@toksa={\Crefrangemultiformat{#1}}%
    \expandafter\the\expandafter\@toksa\the\@toksb%
%    \end{macrocode}
% If type has custom label format, bundle all four arguments
% for\linebreak[4] \cmd{\labelcrefrangemultiformat} in token register
% \cmd{\@toksb}, then call it.
%    \begin{macrocode}
    \@ifundefined{cref@#1@rangelabel}{%
      \@ifundefined{cref@#1@label}{\let\@tempa\relax}{\def\@tempa{}}}%
        {\def\@tempa{}}%
    \ifx\@tempa\@empty\relax%
      \@toksb={}%
      \expandafter\cref@append@toks\expandafter\@toksb\expandafter{%
        \expandafter{\@temprangelabel}}%
      \expandafter\cref@append@toks\expandafter\@toksb\expandafter{%
        \expandafter{\@tempsecond}}%
      \expandafter\cref@append@toks\expandafter\@toksb\expandafter{%
        \expandafter{\@tempmiddle}}%
      \expandafter\cref@append@toks\expandafter\@toksb\expandafter{%
        \expandafter{\@templast}}%
      \@toksa={\labelcrefrangemultiformat{#1}}%
      \expandafter\the\expandafter\@toksa\the\@toksb%
    \fi%
  \endgroup}%
%    \end{macrocode}
% \end{macro}
%
%
% \begin{macro}{\@labelcrefdefinedefaultformats}
%   \cmd{\@labelcrefdefinedefaultformats} defines the default formats for
%   the\linebreak[4] \cmd{\labelcref} command, which are used when no
%   type-specific formats are defined.
%    \begin{macrocode}
\def\@labelcrefdefinedefaultformats{%
  \begingroup%
    \toksdef\@toksa=0%
    \toksdef\@toksb=1%
%    \end{macrocode}
% Assemble the arguments that need to be passed to
% \cmd{\labelcrefformat},\linebreak[4] \cmd{\labelcrefrangeformat},
% \cmd{\labelcrefmultiformat} and\linebreak[4]
% \cmd{\labelcrefrangemultiformat}.
%    \begin{macrocode}
    \let\@templabel\cref@default@label%
    \expandafter\def\expandafter\@tempa\expandafter{%
      \@templabel{####1}{####3}{####4}}%
    \expandafter\def\expandafter\@tempb\expandafter{%
      \@templabel{####2}{####5}{####6}}%
    \@toksa={\def\@temprangelabel##1##2##3##4##5##6}%
    \expandafter\expandafter\expandafter\the%
    \expandafter\expandafter\expandafter\@toksa%
    \expandafter\expandafter\expandafter{%
      \expandafter\expandafter\expandafter\crefrangepreconjunction%
      \expandafter\@tempa\expandafter\crefrangeconjunction\@tempb%
      \crefrangepostconjunction}%
    \expandafter\def\expandafter\@templabel\expandafter{%
      \@templabel{########1}{########2}{########3}}%
    \expandafter\def\expandafter\@temprangelabel\expandafter{%
      \@temprangelabel{########1}{########2}{########3}%
      {########4}{########5}{########6}}%
    \expandafter\def\expandafter\@tempsecond\expandafter{%
      \expandafter\crefpairconjunction\@templabel}%
    \expandafter\def\expandafter\@tempmiddle\expandafter{%
      \expandafter\crefmiddleconjunction\@templabel}%
    \expandafter\def\expandafter\@templast\expandafter{%
      \expandafter\creflastconjunction\@templabel}%
    \expandafter\def\expandafter\@temprangesecond\expandafter{%
      \expandafter\crefpairconjunction\@temprangelabel}%
    \expandafter\def\expandafter\@temprangemiddle\expandafter{%
      \expandafter\crefmiddleconjunction\@temprangelabel}%
    \expandafter\def\expandafter\@temprangelast\expandafter{%
      \expandafter\creflastconjunction\@temprangelabel}%
    \expandafter\def\expandafter\@templabel\expandafter{\@templabel}%
    \expandafter\def\expandafter\@temprangelabel%
      \expandafter{\@temprangelabel}%
%    \end{macrocode}
% Define default \cmd{\labelcrefformat}.
%    \begin{macrocode}
    \@toksa={\labelcrefformat{default}}%
    \expandafter\the\expandafter\@toksa\expandafter{\@templabel}%
%    \end{macrocode}
% Define default \cmd{\labelcrefrangeformat}.
%    \begin{macrocode}
    \@toksa={\labelcrefrangeformat{default}}%
    \expandafter\the\expandafter\@toksa\expandafter{\@temprangelabel}%
%    \end{macrocode}
% Bundle all four arguments for \cmd{\labelcrefmultiformat} in token
% register \cmd{\@toksb}, then call it to define default formats.
%    \begin{macrocode}
    \@toksb={}%
    \expandafter\cref@append@toks\expandafter\@toksb\expandafter{%
      \expandafter{\@templabel}}%
    \expandafter\cref@append@toks\expandafter\@toksb\expandafter{%
      \expandafter{\@tempsecond}}%
    \expandafter\cref@append@toks\expandafter\@toksb\expandafter{%
      \expandafter{\@tempmiddle}}%
    \expandafter\cref@append@toks\expandafter\@toksb\expandafter{%
      \expandafter{\@templast}}%
    \@toksa={\labelcrefmultiformat{default}}%
    \expandafter\the\expandafter\@toksa\the\@toksb%
%    \end{macrocode}
% Bundle all four arguments for \cmd{\labelcrefrangemultiformat} in token
% register \cmd{\@toksb}, then call it to define default formats.
%    \begin{macrocode}
    \@toksb={}%
    \expandafter\cref@append@toks\expandafter\@toksb\expandafter{%
      \expandafter{\@temprangelabel}}%
    \expandafter\cref@append@toks\expandafter\@toksb\expandafter{%
      \expandafter{\@temprangesecond}}%
    \expandafter\cref@append@toks\expandafter\@toksb\expandafter{%
      \expandafter{\@temprangemiddle}}%
    \expandafter\cref@append@toks\expandafter\@toksb\expandafter{%
      \expandafter{\@temprangelast}}%
    \@toksa={\labelcrefrangemultiformat{default}}%
    \expandafter\the\expandafter\@toksa\the\@toksb%
  \endgroup}%
%    \end{macrocode}
% \end{macro}
%
%
% \begin{macro}{\@crefdefineallformats}
%   \cmd{\@crefdefineallformats} calls each of the above, to define all
%   formats for the given type from the corresponding components.
%    \begin{macrocode}
\def\@crefdefineallformats#1{%
  \@crefdefineformat{#1}%
  \@crefrangedefineformat{#1}%
  \@crefdefinemultiformat{#1}%
  \@crefrangedefinemultiformat{#1}}%
%    \end{macrocode}
% \end{macro}
%
%
% \begin{macro}{\@crefcopyformats}
%   \cmd{\@crefcopyformats} copies any undefined formats for type |#2|
%   from those for type |#1|.
%    \begin{macrocode}
\def\@crefcopyformats#1#2{%
  \let\@tempf\iffalse%
  \@ifundefined{cref@#2@name}{%
    \edef\@tempa{\expandafter\noexpand\csname cref@#2@name\endcsname}%
    \edef\@tempb{\expandafter\noexpand\csname cref@#1@name\endcsname}%
    \expandafter\expandafter\expandafter\let\expandafter\@tempa\@tempb%
    \edef\@tempa{\expandafter\noexpand\csname cref@#2@name@plural\endcsname}%
    \edef\@tempb{\expandafter\noexpand\csname cref@#1@name@plural\endcsname}%
    \expandafter\expandafter\expandafter\let\expandafter\@tempa\@tempb%
  }{%
    \let\@tempf\iftrue%
  }%
  \@ifundefined{Cref@#2@name}{%
    \edef\@tempa{\expandafter\noexpand\csname Cref@#2@name\endcsname}%
    \edef\@tempb{\expandafter\noexpand\csname Cref@#1@name\endcsname}%
    \expandafter\expandafter\expandafter\let\expandafter\@tempa\@tempb%
    \edef\@tempa{\expandafter\noexpand\csname Cref@#2@name@plural\endcsname}%
    \edef\@tempb{\expandafter\noexpand\csname Cref@#1@name@plural\endcsname}%
    \expandafter\expandafter\expandafter\let\expandafter\@tempa\@tempb%
  }{%
    \let\@tempf\iftrue%
  }%
  \@ifundefined{cref@#2@label}{%
    \@ifundefined{cref@#1@label}{}{%
      \edef\@tempa{\expandafter\noexpand\csname cref@#2@label\endcsname}%
      \edef\@tempb{\expandafter\noexpand\csname cref@#1@label\endcsname}%
      \expandafter\expandafter\expandafter\let\expandafter\@tempa\@tempb}%
  }{%
    \let\@tempf\iftrue%
  }%
  \@ifundefined{cref@#2@rangelabel}{%
    \@ifundefined{cref@#1@rangelabel}{}{%
      \edef\@tempa{\expandafter\noexpand\csname cref@#2@rangelabel\endcsname}%
      \edef\@tempb{\expandafter\noexpand\csname cref@#1@rangelabel\endcsname}%
      \expandafter\expandafter\expandafter\let\expandafter\@tempa\@tempb}%
  }{%
    \let\@tempf\iftrue%
  }%
%    \end{macrocode}
% If at least one format component has been customised specifically for
% reference type |#2|, generate its formats from components.
%    \begin{macrocode}
  \@tempf\relax%
    \@crefdefineallformats{#2}%
%    \end{macrocode}
% If no format components have been defined for reference type |#2|, copy
% over the low-level formats from type |#1|.
%    \begin{macrocode}
  \else%
    \@ifundefined{cref@#2@format}{%
      \edef\@tempa{\expandafter\noexpand\csname cref@#2@format\endcsname}%
      \edef\@tempb{\expandafter\noexpand\csname cref@#1@format\endcsname}%
      \expandafter\expandafter\expandafter\let\expandafter\@tempa\@tempb}{}%
    \@ifundefined{crefrange@#2@format}{%
      \edef\@tempa{\expandafter\noexpand\csname crefrange@#2@format\endcsname}%
      \edef\@tempb{\expandafter\noexpand\csname crefrange@#1@format\endcsname}%
      \expandafter\expandafter\expandafter\let\expandafter\@tempa\@tempb}{}%
    \@ifundefined{cref@#2@format@first}{%
      \edef\@tempa{\expandafter\noexpand\csname cref@#2@format@first\endcsname}%
      \edef\@tempb{\expandafter\noexpand\csname cref@#1@format@first\endcsname}%
      \expandafter\expandafter\expandafter\let\expandafter\@tempa\@tempb}{}%
    \@ifundefined{cref@#2@format@second}{%
      \edef\@tempa{\expandafter\noexpand\csname cref@#2@format@second\endcsname}%
      \edef\@tempb{\expandafter\noexpand\csname cref@#1@format@second\endcsname}%
      \expandafter\expandafter\expandafter\let\expandafter\@tempa\@tempb}{}%
    \@ifundefined{cref@#2@format@middle}{%
      \edef\@tempa{\expandafter\noexpand\csname cref@#2@format@middle\endcsname}%
      \edef\@tempb{\expandafter\noexpand\csname cref@#1@format@middle\endcsname}%
      \expandafter\expandafter\expandafter\let\expandafter\@tempa\@tempb}{}%
    \@ifundefined{cref@#2@format@last}{%
      \edef\@tempa{\expandafter\noexpand\csname cref@#2@format@last\endcsname}%
      \edef\@tempb{\expandafter\noexpand\csname cref@#1@format@last\endcsname}%
      \expandafter\expandafter\expandafter\let\expandafter\@tempa\@tempb}{}%
    \@ifundefined{crefrange@#2@format@first}{%
      \edef\@tempa{\expandafter\noexpand\csname crefrange@#2@format@first\endcsname}%
      \edef\@tempb{\expandafter\noexpand\csname crefrange@#1@format@first\endcsname}%
      \expandafter\expandafter\expandafter\let\expandafter\@tempa\@tempb}{}%
    \@ifundefined{crefrange@#2@format@second}{%
      \edef\@tempa{\expandafter\noexpand\csname crefrange@#2@format@second\endcsname}%
      \edef\@tempb{\expandafter\noexpand\csname crefrange@#1@format@second\endcsname}%
      \expandafter\expandafter\expandafter\let\expandafter\@tempa\@tempb}{}%
    \@ifundefined{crefrange@#2@format@middle}{%
      \edef\@tempa{\expandafter\noexpand\csname crefrange@#2@format@middle\endcsname}%
      \edef\@tempb{\expandafter\noexpand\csname crefrange@#1@format@middle\endcsname}%
      \expandafter\expandafter\expandafter\let\expandafter\@tempa\@tempb}{}%
    \@ifundefined{crefrange@#2@format@last}{%
      \edef\@tempa{\expandafter\noexpand\csname crefrange@#2@format@last\endcsname}%
      \edef\@tempb{\expandafter\noexpand\csname crefrange@#1@format@last\endcsname}%
      \expandafter\expandafter\expandafter\let\expandafter\@tempa\@tempb}{}%
%
    \@ifundefined{Cref@#2@format}{%
      \edef\@tempa{\expandafter\noexpand\csname Cref@#2@format\endcsname}%
      \edef\@tempb{\expandafter\noexpand\csname Cref@#1@format\endcsname}%
      \expandafter\expandafter\expandafter\let\expandafter\@tempa\@tempb}{}%
    \@ifundefined{Crefrange@#2@format}{%
      \edef\@tempa{\expandafter\noexpand\csname Crefrange@#2@format\endcsname}%
      \edef\@tempb{\expandafter\noexpand\csname Crefrange@#1@format\endcsname}%
      \expandafter\expandafter\expandafter\let\expandafter\@tempa\@tempb}{}%
    \@ifundefined{Cref@#2@format@first}{%
      \edef\@tempa{\expandafter\noexpand\csname Cref@#2@format@first\endcsname}%
      \edef\@tempb{\expandafter\noexpand\csname Cref@#1@format@first\endcsname}%
      \expandafter\expandafter\expandafter\let\expandafter\@tempa\@tempb}{}%
    \@ifundefined{Cref@#2@format@second}{%
      \edef\@tempa{\expandafter\noexpand\csname Cref@#2@format@second\endcsname}%
      \edef\@tempb{\expandafter\noexpand\csname Cref@#1@format@second\endcsname}%
      \expandafter\expandafter\expandafter\let\expandafter\@tempa\@tempb}{}%
    \@ifundefined{Cref@#2@format@middle}{%
      \edef\@tempa{\expandafter\noexpand\csname Cref@#2@format@middle\endcsname}%
      \edef\@tempb{\expandafter\noexpand\csname Cref@#1@format@middle\endcsname}%
      \expandafter\expandafter\expandafter\let\expandafter\@tempa\@tempb}{}%
    \@ifundefined{Cref@#2@format@last}{%
      \edef\@tempa{\expandafter\noexpand\csname Cref@#2@format@last\endcsname}%
      \edef\@tempb{\expandafter\noexpand\csname Cref@#1@format@last\endcsname}%
      \expandafter\expandafter\expandafter\let\expandafter\@tempa\@tempb}{}%
    \@ifundefined{Crefrange@#2@format@first}{%
      \edef\@tempa{\expandafter\noexpand\csname Crefrange@#2@format@first\endcsname}%
      \edef\@tempb{\expandafter\noexpand\csname Crefrange@#1@format@first\endcsname}%
      \expandafter\expandafter\expandafter\let\expandafter\@tempa\@tempb}{}%
    \@ifundefined{Crefrange@#2@format@second}{%
      \edef\@tempa{\expandafter\noexpand\csname Crefrange@#2@format@second\endcsname}%
      \edef\@tempb{\expandafter\noexpand\csname Crefrange@#1@format@second\endcsname}%
      \expandafter\expandafter\expandafter\let\expandafter\@tempa\@tempb}{}%
    \@ifundefined{Crefrange@#2@format@middle}{%
      \edef\@tempa{\expandafter\noexpand\csname Crefrange@#2@format@middle\endcsname}%
      \edef\@tempb{\expandafter\noexpand\csname Crefrange@#1@format@middle\endcsname}%
      \expandafter\expandafter\expandafter\let\expandafter\@tempa\@tempb}{}%
    \@ifundefined{Crefrange@#2@format@last}{%
      \edef\@tempa{\expandafter\noexpand\csname Crefrange@#2@format@last\endcsname}%
      \edef\@tempb{\expandafter\noexpand\csname Crefrange@#1@format@last\endcsname}%
      \expandafter\expandafter\expandafter\let\expandafter\@tempa\@tempb}{}%
%
    \@ifundefined{labelcref@#2@format}{%
      \edef\@tempa{\expandafter\noexpand\csname labelcref@#2@format\endcsname}%
      \edef\@tempb{\expandafter\noexpand\csname labelcref@#1@format\endcsname}%
      \expandafter\expandafter\expandafter\let\expandafter\@tempa\@tempb}{}%
    \@ifundefined{labelcrefrange@#2@format}{%
      \edef\@tempa{\expandafter\noexpand\csname labelcrefrange@#2@format\endcsname}%
      \edef\@tempb{\expandafter\noexpand\csname labelcrefrange@#1@format\endcsname}%
      \expandafter\expandafter\expandafter\let\expandafter\@tempa\@tempb}{}%
    \@ifundefined{labelcref@#2@format@first}{%
      \edef\@tempa{\expandafter\noexpand\csname labelcref@#2@format@first\endcsname}%
      \edef\@tempb{\expandafter\noexpand\csname labelcref@#1@format@first\endcsname}%
      \expandafter\expandafter\expandafter\let\expandafter\@tempa\@tempb}{}%
    \@ifundefined{labelcref@#2@format@second}{%
      \edef\@tempa{\expandafter\noexpand\csname labelcref@#2@format@second\endcsname}%
      \edef\@tempb{\expandafter\noexpand\csname labelcref@#1@format@second\endcsname}%
      \expandafter\expandafter\expandafter\let\expandafter\@tempa\@tempb}{}%
    \@ifundefined{labelcref@#2@format@middle}{%
      \edef\@tempa{\expandafter\noexpand\csname labelcref@#2@format@middle\endcsname}%
      \edef\@tempb{\expandafter\noexpand\csname labelcref@#1@format@middle\endcsname}%
      \expandafter\expandafter\expandafter\let\expandafter\@tempa\@tempb}{}%
    \@ifundefined{labelcref@#2@format@last}{%
      \edef\@tempa{\expandafter\noexpand\csname labelcref@#2@format@last\endcsname}%
      \edef\@tempb{\expandafter\noexpand\csname labelcref@#1@format@last\endcsname}%
      \expandafter\expandafter\expandafter\let\expandafter\@tempa\@tempb}{}%
    \@ifundefined{labelcrefrange@#2@format@first}{%
      \edef\@tempa{\expandafter\noexpand\csname labelcrefrange@#2@format@first\endcsname}%
      \edef\@tempb{\expandafter\noexpand\csname labelcrefrange@#1@format@first\endcsname}%
      \expandafter\expandafter\expandafter\let\expandafter\@tempa\@tempb}{}%
    \@ifundefined{labelcrefrange@#2@format@second}{%
      \edef\@tempa{\expandafter\noexpand\csname labelcrefrange@#2@format@second\endcsname}%
      \edef\@tempb{\expandafter\noexpand\csname labelcrefrange@#1@format@second\endcsname}%
      \expandafter\expandafter\expandafter\let\expandafter\@tempa\@tempb}{}%
    \@ifundefined{labelcrefrange@#2@format@middle}{%
      \edef\@tempa{\expandafter\noexpand\csname labelcrefrange@#2@format@middle\endcsname}%
      \edef\@tempb{\expandafter\noexpand\csname labelcrefrange@#1@format@middle\endcsname}%
      \expandafter\expandafter\expandafter\let\expandafter\@tempa\@tempb}{}%
    \@ifundefined{labelcrefrange@#2@format@last}{%
      \edef\@tempa{\expandafter\noexpand\csname labelcrefrange@#2@format@last\endcsname}%
      \edef\@tempb{\expandafter\noexpand\csname labelcrefrange@#1@format@last\endcsname}%
      \expandafter\expandafter\expandafter\let\expandafter\@tempa\@tempb}{}%
  \fi%
}
%    \end{macrocode}
% \end{macro}
%
%
%
% \subsubsection{Format definition commands}
% \label{sec:crefformat}
% \begin{macro}{\crefformat}
% \begin{macro}{\Crefformat}
% \begin{macro}{\crefrangeformat}
% \begin{macro}{\Crefrangeformat}
% \begin{macro}{\crefmultiformat}
% \begin{macro}{\Crefmultiformat}
% \begin{macro}{\crefrangemultiformat}
% \begin{macro}{\Crefrangemultiformat}
%   \cmd{\crefformat} et al.\ are lower-level commands that give complete
%   control over the format of different reference types. They override
%   the component-based formats, simply using the supplied arguments to
%   define appropriately named formatting macros, which are called by
%   \cmd{\@@setcref} etc. If the corresponding \cmd{\Crefformat} or
%   \cmd{\crefformat} variant is not already defined, they define it to
%   be a version with the first letter capitalised or lower-cased.
%    \begin{macrocode}
\newcommand\crefformat[2]{\@crefformat{cref}{#1}{#2}}%
\newcommand\Crefformat[2]{\@crefformat{Cref}{#1}{#2}}%
\newcommand\crefrangeformat[2]{\@crefrangeformat{crefrange}{#1}{#2}}%
\newcommand\Crefrangeformat[2]{\@crefrangeformat{Crefrange}{#1}{#2}}%
\newcommand\crefmultiformat[5]{%
  \@crefmultiformat{cref}{#1}{#2}{#3}{#4}{#5}}%
\newcommand\Crefmultiformat[5]{%
  \@crefmultiformat{Cref}{#1}{#2}{#3}{#4}{#5}}%
\newcommand\crefrangemultiformat[5]{%
  \@crefrangemultiformat{crefrange}{#1}{#2}{#3}{#4}{#5}}%
\newcommand\Crefrangemultiformat[5]{%
  \@crefrangemultiformat{Crefrange}{#1}{#2}{#3}{#4}{#5}}%
\newcommand\labelcrefformat[2]{%
  \expandafter\gdef\csname labelcref@#1@format\endcsname##1##2##3{#2}}%
\newcommand\labelcrefrangeformat[2]{%
  \expandafter\gdef\csname labelcrefrange@#1@format\endcsname%
  ##1##2##3##4##5##6{#2}}%
\newcommand\labelcrefmultiformat[5]{%
  \expandafter\gdef\csname labelcref@#1@format@first\endcsname%
    ##1##2##3{#2}%
  \expandafter\gdef\csname labelcref@#1@format@second\endcsname%
    ##1##2##3{#3}%
  \expandafter\gdef\csname labelcref@#1@format@middle\endcsname%
    ##1##2##3{#4}%
  \expandafter\gdef\csname labelcref@#1@format@last\endcsname%
    ##1##2##3{#5}}%
\newcommand\labelcrefrangemultiformat[5]{%
  \expandafter\gdef\csname labelcrefrange@#1@format@first\endcsname%
    ##1##2##3##4##5##6{#2}%
  \expandafter\gdef\csname labelcrefrange@#1@format@second\endcsname%
    ##1##2##3##4##5##6{#3}%
  \expandafter\gdef\csname labelcrefrange@#1@format@middle\endcsname%
    ##1##2##3##4##5##6{#4}%
  \expandafter\gdef\csname labelcrefrange@#1@format@last\endcsname%
    ##1##2##3##4##5##6{#5}}%
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
%
% The utility macros do the real work, by using the first argument
% (``cref'' or ``Cref'', and ``crefrange'' or ``Crefrange'') to determine
% how to define the corresponding command with the other capitalisation.
% \begin{macro}{\@crefformat}
%   \cmd{\@crefformat} defines the macros for single references.
%    \begin{macrocode}
\def\@crefformat#1#2#3{%
  \begingroup%
    \expandafter\gdef\csname #1@#2@format\endcsname##1##2##3{#3}%
%    \end{macrocode}
% If the other capitalisation variant is not already defined\dots
%    \begin{macrocode}
    \cref@othervariant{#1}{\@other}{\@changecase}%
    \@ifundefined{\@other @#2@format}{%
%    \end{macrocode}
% Define \cmd{\@tempa} to be a partial expansion (expanded just once) of
% the capitalisation variant we've just defined above. The \cmd{\@toska}
% token register just makes the code less verbose.
%    \begin{macrocode}
      \toksdef\@toksa=0%
      \@toksa={\def\@tempa##1##2##3}%
      \expandafter\expandafter\expandafter\the%
      \expandafter\expandafter\expandafter\@toksa%
      \expandafter\expandafter\expandafter{%
        \csname#1@#2@format\endcsname{##1}{##2}{##3}}%
%    \end{macrocode}
% Add the \cmd{\@changecase} command to the front of the definition of
% \cmd{\@tempa}.
%    \begin{macrocode}
      \expandafter\expandafter\expandafter\the%
      \expandafter\expandafter\expandafter\@toksa%
      \expandafter\expandafter\expandafter{%
        \expandafter\@changecase\@tempa{##1}{##2}{##3}}%
%    \end{macrocode}
% Define the other capitalisation variant to be the partial expansion
% (expanded just once) of \cmd{\@tempa}.
%    \begin{macrocode}
      \@toksa={%
        \expandafter\gdef\csname\@other @#2@format\endcsname##1##2##3}%
      \expandafter\the\expandafter\@toksa\expandafter{%
        \@tempa{##1}{##2}{##3}}%
    }{}%
  \endgroup}%
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\@crefrangeformat}
%   \cmd{\@crefrangeformat} defines the macros for single reference
%   ranges.
%    \begin{macrocode}
\def\@crefrangeformat#1#2#3{%
  \begingroup%
    \expandafter\gdef\csname #1@#2@format\endcsname%
      ##1##2##3##4##5##6{#3}%
%    \end{macrocode}
% If the other capitalisation variant is not already defined\dots
%    \begin{macrocode}
    \cref@othervariant{#1}{\@other}{\@changecase}%
    \@ifundefined{\@other @#2@format}{%
%    \end{macrocode}
% Define \cmd{\@tempa} to be a partial expansion (expanded just once) of
% the capitalisation variant we've just defined above. The \cmd{\@toska}
% token register just makes the code less verbose.
%    \begin{macrocode}
      \toksdef\@toksa=0%
      \@toksa={\def\@tempa##1##2##3##4##5##6}%
      \expandafter\expandafter\expandafter\the%
      \expandafter\expandafter\expandafter\@toksa%
      \expandafter\expandafter\expandafter{%
        \csname#1@#2@format\endcsname{##1}{##2}{##3}{##4}{##5}{##6}}%
%    \end{macrocode}
% Add the \cmd{\@changecase} command to the front of the definition of
% \cmd{\@tempa}.
%    \begin{macrocode}
      \expandafter\expandafter\expandafter\the%
      \expandafter\expandafter\expandafter\@toksa%
      \expandafter\expandafter\expandafter{%
        \expandafter\@changecase\@tempa{##1}{##2}{##3}{##4}{##5}{##6}}%
%    \end{macrocode}
% Define the other capitalisation variant to be the partial expansion
% (expanded just once) of \cmd{\@tempa}.
%    \begin{macrocode}
      \@toksa={\expandafter\gdef%
        \csname\@other @#2@format\endcsname##1##2##3##4##5##6}%
      \expandafter\the\expandafter\@toksa\expandafter{%
        \@tempa{##1}{##2}{##3}{##4}{##5}{##6}}%
    }{}%
  \endgroup}%
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\@crefmultiformat}
%   \cmd{\@crefmultiformat} defines the macros for multiple references.
%    \begin{macrocode}
\def\@crefmultiformat#1#2#3#4#5#6{%
  \begingroup%
    \expandafter\gdef\csname #1@#2@format@first\endcsname##1##2##3{#3}%
    \expandafter\gdef\csname #1@#2@format@second\endcsname##1##2##3{#4}%
    \expandafter\gdef\csname #1@#2@format@middle\endcsname##1##2##3{#5}%
    \expandafter\gdef\csname #1@#2@format@last\endcsname##1##2##3{#6}%
%    \end{macrocode}
% If the other capitalisation variant of the first part of the
% multi-format definition is not already defined\dots
%    \begin{macrocode}
    \cref@othervariant{#1}{\@other}{\@changecase}%
    \@ifundefined{\@other @#2@format@first}{%
%    \end{macrocode}
% Define \cmd{\@tempa} to be a partial expansion (expanded just once) of
% the capitalisation variant we've just defined above. The \cmd{\@toska}
% token register just makes the code less verbose.
%    \begin{macrocode}
      \toksdef\@toksa=0%
      \@toksa={\def\@tempa##1##2##3}%
      \expandafter\expandafter\expandafter\the%
      \expandafter\expandafter\expandafter\@toksa%
      \expandafter\expandafter\expandafter{%
        \csname#1@#2@format@first\endcsname{##1}{##2}{##3}}%
%    \end{macrocode}
% Add the \cmd{\@changecase} command to the front of the definition of
% \cmd{\@tempa}.
%    \begin{macrocode}
      \expandafter\expandafter\expandafter\the%
      \expandafter\expandafter\expandafter\@toksa%
      \expandafter\expandafter\expandafter{%
        \expandafter\@changecase\@tempa{##1}{##2}{##3}}%
%    \end{macrocode}
% Define the other capitalisation variant to be the partial expansion
% (expanded just once) of \cmd{\@tempa}.
%    \begin{macrocode}
      \@toksa={%
        \expandafter\gdef\csname\@other @#2@format@first\endcsname%
          ##1##2##3}%
      \expandafter\the\expandafter\@toksa\expandafter{%
        \@tempa{##1}{##2}{##3}}%
    }{}%
%    \end{macrocode}
% The other parts of the multi-format definition are defined to be
% identical for both capitalisation variants.
%    \begin{macrocode}
    \@ifundefined{\@other @#2@format@second}{%
      \@toksa={%
        \expandafter\global\expandafter\let%
        \csname\@other @#2@format@second\endcsname}%
      \expandafter\the\expandafter\@toksa%
        \csname #1@#2@format@second\endcsname%
    }{}%
    \@ifundefined{\@other @#2@format@middle}{%
      \@toksa={%
        \expandafter\global\expandafter\let%
        \csname\@other @#2@format@middle\endcsname}%
      \expandafter\the\expandafter\@toksa%
        \csname #1@#2@format@middle\endcsname%
    }{}%
    \@ifundefined{\@other @#2@format@last}{%
      \@toksa={%
        \expandafter\global\expandafter\let%
        \csname\@other @#2@format@last\endcsname}%
      \expandafter\the\expandafter\@toksa%
        \csname #1@#2@format@last\endcsname%
    }{}%
  \endgroup}%
%    \end{macrocode}
%\end{macro}
%
% \begin{macro}{\@crefrangemultiformat}
%   \cmd{\@crefmultiformat} defines the macros for reference ranges
%   within multiple references.
%    \begin{macrocode}
\def\@crefrangemultiformat#1#2#3#4#5#6{%
  \begingroup%
    \expandafter\gdef\csname #1@#2@format@first\endcsname%
      ##1##2##3##4##5##6{#3}%
    \expandafter\gdef\csname #1@#2@format@second\endcsname%
      ##1##2##3##4##5##6{#4}%
    \expandafter\gdef\csname #1@#2@format@middle\endcsname%
      ##1##2##3##4##5##6{#5}%
    \expandafter\gdef\csname #1@#2@format@last\endcsname%
      ##1##2##3##4##5##6{#6}%
%    \end{macrocode}
% If the other capitalisation variant of the first part of the
% multi-format definition is not already defined\dots
%    \begin{macrocode}
    \cref@othervariant{#1}{\@other}{\@changecase}%
    \@ifundefined{\@other @#2@format@first}{%
%    \end{macrocode}
% Define \cmd{\@tempa} to be a partial expansion (expanded just once) of
% the capitalisation variant we've just defined above. The \cmd{\@toska}
% token register just makes the code less verbose.
%    \begin{macrocode}
      \toksdef\@toksa=0%
      \@toksa={\def\@tempa##1##2##3##4##5##6}%
      \expandafter\expandafter\expandafter\the%
      \expandafter\expandafter\expandafter\@toksa%
      \expandafter\expandafter\expandafter{%
        \csname#1@#2@format@first\endcsname%
          {##1}{##2}{##3}{##4}{##5}{##6}}%
%    \end{macrocode}
% Add the \cmd{\@changecase} command to the front of the definition of
% \cmd{\@tempa}.
%    \begin{macrocode}
      \expandafter\expandafter\expandafter\the%
      \expandafter\expandafter\expandafter\@toksa%
      \expandafter\expandafter\expandafter{%
        \expandafter\@changecase\@tempa{##1}{##2}{##3}{##4}{##5}{##6}}%
%    \end{macrocode}
% Define the other capitalisation variant to be the partial expansion
% (expanded just once) of \cmd{\@tempa}.
%    \begin{macrocode}
      \@toksa={%
        \expandafter\gdef\csname\@other @#2@format@first\endcsname%
          ##1##2##3##4##5##6}%
      \expandafter\the\expandafter\@toksa\expandafter{%
        \@tempa{##1}{##2}{##3}{##4}{##5}{##6}}%
    }{}%
%    \end{macrocode}
% The other parts of the multi-format definition are defined to be
% identical for both capitalisation variants.
%    \begin{macrocode}
    \@ifundefined{\@other @#2@format@second}{%
      \@toksa={%
        \expandafter\global\expandafter\let%
        \csname\@other @#2@format@second\endcsname}%
      \expandafter\the\expandafter\@toksa%
        \csname #1@#2@format@second\endcsname%
    }{}%
    \@ifundefined{\@other @#2@format@middle}{%
      \@toksa={%
        \expandafter\global\expandafter\let%
        \csname\@other @#2@format@middle\endcsname}%
      \expandafter\the\expandafter\@toksa%
        \csname #1@#2@format@middle\endcsname%
    }{}%
    \@ifundefined{\@other @#2@format@last}{%
      \@toksa={%
        \expandafter\global\expandafter\let%
        \csname\@other @#2@format@last\endcsname}%
      \expandafter\the\expandafter\@toksa%
        \csname #1@#2@format@last\endcsname%
    }{}%
  \endgroup}%
%    \end{macrocode}
% \end{macro}
%
%
%
% \subsection{Support for Other Packages}
%
% \subsubsection{\package{hyperref} support}
% \begin{macro}{hyperref}
%   If the \package{hyperref} package is loaded, we add hyperlink
%   support to \package{cleveref}. Since \package{hyperref} messes around
%   with some of the same \LaTeX{} internals as we do, we also have to
%   override some of its redefinitions so that they work with
%   \package{cleveref}.
%    \begin{macrocode}
\let\if@cref@hyperrefloaded\iffalse%
\let\cref@addtoreset\@addtoreset%
\@ifpackageloaded{hyperref}{%
  \@ifpackagewith{hyperref}{implicit=false}{%
    \let\if@cref@hyperrefloaded\iftrue%
    \PackageWarning{cleveref}{hyperref package loaded with
      implicit=false option - disabling cleveref's hyperref support.
      This situation is not supported by cleveref, and there's no guarantee
      anything will work. You're on your own!}%
  }{%
    \let\if@cref@hyperrefloaded\iftrue%
    \PackageInfo{cleveref}{`hyperref' support loaded}%
%    \end{macrocode}
% \package{hyperref} redefines the \LaTeX{} kernel \cmd{\@addtoreset}
% macro (sigh), but we sometimes need the vanilla version without the
% \package{hyperref} shennanigans. \package{hyperref} saves the
% original in \cmd{\HyOrg@addtoreset}. So we create yet
% \emph{another} version called \cmd{\cref@addtotreset}, which is always
% let to the original \cmd{\@addtoreset}, whereever that's found.
%    \begin{macrocode}
    \let\cref@addtoreset\HyOrg@addtoreset%
%    \end{macrocode}
% \begin{macro}{\cref@hyperlinkname}
% \begin{macro}{\cref@hyperlinkurl}
%   We define a utility macro to extract the hyperlink supplied by
%   \package{hyperref} (via the \file{aux} file). Note that
%   \package{hyperref} adds the hyperlink info to the standard
%   \cmd{\newlabel} line in the \file{aux} file, so we have to retrieve
%   it from the standard \cmd{\r@\meta{label}}, \emph{not} the one
%   suffixed with |@cref| that we've created ourselves.
%    \begin{macrocode}
    \def\cref@hyperlinkname#1{\expandafter\expandafter\expandafter%
      \@fourthoffive\csname r@#1\endcsname}%
    \def\cref@hyperlinkurl#1{\expandafter\expandafter\expandafter%
      \@fifthoffive\csname r@#1\endcsname}%
%    \end{macrocode}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\cref@hyperlink}
%   Because of the way the cross-referencing formatting commands work, we
%   will need to use a delimited argument to specify the text to be
%   turned into a hyperlink. So we define a variant of
%   \package{hyperref}'s \cmd{\hyper@@link} command that takes the
%   hyperlink text as an argument delimited by |\@nil|, instead of a
%   standard argument. (We only ever need the |link| hyperlink type in
%   \package{cleveref}, so we don't bother providing \cmd{\hyper@@link}'s
%   optional argument.)
%    \begin{macrocode}
    \def\cref@hyperlink#1#2#3\@nil{\hyper@@link[link]{#1}{#2}{#3}}%
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\H@refstepcounter}
%   The \package{hyperref} package stores the original
%   \cmd{\refstepcounter} definition as\linebreak[4]
%   \cmd{\H@refstepcounter}. Unfortunately, it plasters
%   \cmd{\H@refstepcounter} all over the place, sometimes bypassing
%   \cmd{\refstepcounter} entirely. So we're forced to modify
%   \cmd{\H@refstepcounter} itself, in order to ensure that the extra
%   information we need is stored in \cmd{\cref@currentlabel}.
%    \begin{macrocode}
    \let\cref@old@H@refstepcounter\H@refstepcounter%
    \def\H@refstepcounter#1{%
      \cref@old@H@refstepcounter{#1}%
      \cref@constructprefix{#1}{\cref@result}%
      \@ifundefined{cref@#1@alias}%
        {\def\@tempa{#1}}%
        {\def\@tempa{\csname cref@#1@alias\endcsname}}%
      \protected@edef\cref@currentlabel{%
        [\@tempa][\arabic{#1}][\cref@result]%
        \csname p@#1\endcsname\csname the#1\endcsname}}%
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\refstepcounter@noarg}
% \begin{macro}{\refstepcounter@optarg}
%   \package{hyperref}'s \cmd{\refstepcounter}, which ends up stored in
%   our\linebreak[4] \cmd{\cref@old@refstepcounter}, already calls
%   \cmd{\H@refstepcounter}, and we just redefined the latter to store
%   the extra information. So we only need to change
%   \cmd{\cref@currentlabel} in \emph{our} \cmd{\refstepcounter} if an
%   optional argument was supplied. Note that, in this case, the
%   mechanism for setting \cmd{\cref@currentlabel} is slightly different
%   than it is without \package{hyperref}: \cmd{\cref@currentlabel} first
%   gets set by our modified \cmd{\H@refstepcounter}, which gets called
%   via \package{hyperref}'s original version, as stored in
%   \cmd{\cref@old@refstepcounter}. The version of
%   \cmd{\cref@refstepcounter@optarg} defined below then overrides the
%   label type.
%    \begin{macrocode}
    \let\refstepcounter@noarg\cref@old@refstepcounter%
    \def\refstepcounter@optarg[#1]#2{%
      \cref@old@refstepcounter{#2}%
      \@ifundefined{cref@#1@alias}%
        {\def\@tempa{#1}}%
        {\def\@tempa{\csname cref@#1@alias\endcsname}}%
      \protected@edef\cref@currentlabel{%
        \expandafter\cref@override@label@type%
          \cref@currentlabel\@nil{\@tempa}}}%
%    \end{macrocode}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\appendix}
%   We again make \cmd{\appendix} redefine things so that the label type
%   for chapters or sections is exceptionally overridden and set to
%   ``appendix'' instead. But this time, it is \cmd{\H@refstepcounter}
%   that needs to be redefined.
%    \begin{macrocode}
    \@ifundefined{appendix}{}{%
      \def\appendix{%
        \@ifundefined{chapter}{%
          \def\H@refstepcounter##1{%
            \cref@old@H@refstepcounter{##1}%
            \cref@constructprefix{##1}{\cref@result}%
%    \end{macrocode}
%         We add a large value to the front of the counter data, to force
%         references to anything in appendices to be sorted after
%         everything else.
%    \begin{macrocode}
            \ifx\cref@result\@empty%
              \def\cref@result{2147483647}%
            \else%
              \edef\cref@result{2147483647,\cref@result}%
            \fi%
%    \end{macrocode}
%         Override the cross-reference type of sectioning commands.
%    \begin{macrocode}
            \def\@tempa{##1}%
            \def\@tempb{section}%
            \ifx\@tempa\@tempb%
              \@ifundefined{cref@appendix@alias}%
                {\def\@tempa{appendix}}%
                {\def\@tempa{\cref@appendix@alias}}%
              \protected@edef\cref@currentlabel{%
                [\@tempa][\arabic{##1}][\cref@result]%
                \csname p@##1\endcsname\csname the##1\endcsname}%
            \else%
              \def\@tempa{##1}%
              \def\@tempb{subsection}%
              \ifx\@tempa\@tempb%
                \@ifundefined{cref@subappendix@alias}%
                  {\def\@tempa{subappendix}}%
                  {\def\@tempa{\cref@subappendix@alias}}%
                \protected@edef\cref@currentlabel{%
                  [\@tempa][\arabic{##1}][\cref@result]%
                  \csname p@##1\endcsname\csname the##1\endcsname}%
              \else%
                \def\@tempa{##1}%
                \def\@tempb{subsubsection}%
                \ifx\@tempa\@tempb%
                  \@ifundefined{cref@subsubappendix@alias}%
                    {\def\@tempa{subsubappendix}}%
                    {\def\@tempa{\cref@subsubappendix@alias}}%
                  \protected@edef\cref@currentlabel{%
                    [\@tempa][\arabic{##1}][\cref@result]%
                    \csname p@##1\endcsname\csname the##1\endcsname}%
                \else%
                  \@ifundefined{cref@##1@alias}%
                    {\def\@tempa{##1}}%
                    {\def\@tempa{\csname cref@##1@alias\endcsname}}%
                  \protected@edef\cref@currentlabel{%
                    [\@tempa][\arabic{##1}][\cref@result]%
                    \csname p@##1\endcsname\csname the##1\endcsname}%
                \fi%
              \fi%
            \fi}%
          \cref@old@appendix%
        }{%
          \def\H@refstepcounter##1{%
            \cref@old@H@refstepcounter{##1}%
            \cref@constructprefix{##1}{\cref@result}%
%    \end{macrocode}
%         Again, the large value added to the front of the counter data
%         forces references to appendix items to be sorted last.
%    \begin{macrocode}
            \ifx\cref@result\@empty%
              \def\cref@result{2147483647}%
            \else%
              \edef\cref@result{2147483647,\cref@result}%
            \fi%
%    \end{macrocode}
%         Override the cross-reference type of sectioning commands.
%    \begin{macrocode}
            \def\@tempa{##1}%
            \def\@tempb{chapter}%
            \ifx\@tempa\@tempb%
              \@ifundefined{cref@appendix@alias}%
                {\def\@tempa{appendix}}%
                {\def\@tempa{\cref@appendix@alias}}%
              \protected@edef\cref@currentlabel{%
                [\@tempa][\arabic{##1}][\cref@result]%
                \csname p@##1\endcsname\csname the##1\endcsname}%
            \else%
              \def\@tempa{##1}%
              \def\@tempb{section}%
              \ifx\@tempa\@tempb%
                \@ifundefined{cref@subappendix@alias}%
                  {\def\@tempa{subappendix}}%
                  {\def\@tempa{\cref@subappendix@alias}}%
                \protected@edef\cref@currentlabel{%
                  [\@tempa][\arabic{##1}][\cref@result]%
                  \csname p@##1\endcsname\csname the##1\endcsname}%
              \else%
                \def\@tempa{##1}%
                \def\@tempb{subsection}%
                \ifx\@tempa\@tempb%
                  \@ifundefined{cref@subsubappendix@alias}%
                    {\def\@tempa{subsubappendix}}%
                    {\def\@tempa{\cref@subsubappendix@alias}}%
                  \protected@edef\cref@currentlabel{%
                    [\@tempa][\arabic{##1}][\cref@result]%
                    \csname p@##1\endcsname\csname the##1\endcsname}%
                \else%
                  \def\@tempa{##1}%
                  \def\@tempb{subsubsection}%
                  \ifx\@tempa\@tempb%
                    \@ifundefined{cref@subsubappendix@alias}%
                      {\def\@tempa{subsubsubappendix}}%
                      {\def\@tempa{\cref@subsubsubappendix@alias}}%
                    \protected@edef\cref@currentlabel{%
                      [\@tempa][\arabic{##1}][\cref@result]%
                      \csname p@##1\endcsname\csname the##1\endcsname}%
                  \else%
                    \@ifundefined{cref@##1@alias}%
                      {\def\@tempa{##1}}%
                      {\def\@tempa{\csname cref@##1@alias\endcsname}}%
                    \protected@edef\cref@currentlabel{%
                      [\@tempa][\arabic{##1}][\cref@result]%
                      \csname p@##1\endcsname\csname the##1\endcsname}%
                  \fi%
                \fi%
              \fi%
            \fi}%
      \cref@old@appendix}%
      }%
    }% end of \@ifundefined{appendix}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\cref*}
% \begin{macro}{\Cref*}
% \begin{macro}{\@crefstar}
%   We redefine \cmd{\cref} and all the others to allow starred variants,
%   which don't create hyperlinks. The starred variants simply set a
%   flag, which is tested in the very final stage of reference
%   typesetting in \cmd{\@@@setcref}, \cmd{\@@@setcrefrange},
%   \cmd{\@@@setcpageref} and \cmd{\@@@setcpagerefrange} (below).
%    \begin{macrocode}
    \DeclareRobustCommand{\cref}{%
      \@ifstar{\@crefstar{cref}}{\@cref{cref}}}%
    \DeclareRobustCommand{\Cref}{%
      \@ifstar{\@crefstar{Cref}}{\@cref{Cref}}}%
    \def\@crefstar#1#2{%
      \@crefstarredtrue\@cref{#1}{#2}\@crefstarredfalse}%
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\crefrange*}
% \begin{macro}{\Crefrange*}
% \begin{macro}{\@crefrangestar}
% \begin{macro}{\@crefrangenostar}
%    \begin{macrocode}
    \DeclareRobustCommand{\crefrange}{%
      \@ifstar{\@crefrangestar{cref}}{\@crefrangenostar{cref}}}%
    \DeclareRobustCommand{\Crefrange}{%
      \@ifstar{\@crefrangestar{Cref}}{\@crefrangenostar{Cref}}}%
    \def\@crefrangenostar#1#2#3{\@@setcrefrange{#1}{#2}{#3}{}}
    \def\@crefrangestar#1#2#3{%
      \@crefstarredtrue\@@setcrefrange{#1}{#2}{#3}{}\@crefstarredfalse}%
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\cpageref*}
% \begin{macro}{\Cpageref*}
%    \begin{macrocode}
    \DeclareRobustCommand{\cpageref}{%
      \@ifstar\@crefstar\@cref{cpageref}}%
    \DeclareRobustCommand{\Cpageref}{%
      \@ifstar\@crefstar\@cref{Cpageref}}%
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \begin{macro}{\cpagerefrange*}
% \begin{macro}{\Cpagerefrange*}
% \begin{macro}{\@cpagerefrangestar}
%    \begin{macrocode}
    \DeclareRobustCommand{\cpagerefrange}{%
      \@ifstar{\@cpagerefrangestar{cref}}{\@cpagerefrangenostar{cref}}}%
    \DeclareRobustCommand{\Cpagerefrange}{%
      \@ifstar{\@cpagerefrangestar{Cref}}{\@cpagerefrangenostar{Cref}}}%
    \def\@cpagerefrangenostar#1#2#3{%
      \@@setcpagerefrange{#2}{#3}{#1}{}}
    \def\@cpagerefrangestar#1#2#3{%
      \@crefstarredtrue%
      \@@setcpagerefrange{#2}{#3}{#1}{}%
      \@crefstarredfalse}%
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\labelcref*}
% \begin{macro}{\labelcpageref*}
% \begin{macro}{\@labelcrefstar}
% \begin{macro}{\@labelcpagerefstar}
%    \begin{macrocode}
    \DeclareRobustCommand{\labelcref}{%
      \@ifstar{\@labelcrefstar}{\@cref{labelcref}}}%
    \def\@labelcrefstar#1{%
      \@crefstarredtrue%
      \@cref{labelcref}{#1}%
      \@crefstarredfalse}%
    \DeclareRobustCommand{\labelcpageref}{%
      \@ifstar{\@labelcpagerefstar}{\@cref{labelcpageref}}}%
    \def\@labelcpagerefstar#1{%
      \@crefstarredtrue%
      \@cref{labelcpageref}{#1}%
      \@crefstarredfalse}%
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\@@@setcref}
% \begin{macro}{\@@@setcrefrange}
% \begin{macro}{\@@@setcpageref}
% \begin{macro}{\@@@setcpagerefrange}
%   Redefine the final reference typesetting macros to create hyperlinks
%   (unless the starred flag is set), using the extra arguments supplied
%   in \cmd{\r@\meta{label}} (via the \file{aux} file) by
%   \package{hyperref}.
%    \begin{macrocode}
    \def\@@@setcref#1#2{%
      \cref@getlabel{#2}{\@templabel}%
      \if@crefstarred%
        #1{\@templabel}{}{}%
      \else%
        \edef\@tempname{\cref@hyperlinkname{#2}}%
        \edef\@tempurl{\cref@hyperlinkurl{#2}}%
        #1{\@templabel}{\cref@hyperlink{\@tempurl}{\@tempname}}{\@nil}%
      \fi}%
    \def\@@@setcrefrange#1#2#3{%
      \cref@getlabel{#2}{\@labela}%
      \cref@getlabel{#3}{\@labelb}%
      \if@crefstarred%
        #1{\@labela}{\@labelb}{}{}{}{}%
      \else%
        \edef\@tempnamea{\cref@hyperlinkname{#2}}%
        \edef\@tempurlb{\cref@hyperlinkurl{#3}}%
        \edef\@tempnameb{\cref@hyperlinkname{#3}}%
        \edef\@tempurla{\cref@hyperlinkurl{#2}}%
        #1{\@labela}{\@labelb}%
          {\cref@hyperlink{\@tempurla}{\@tempnamea}}{\@nil}%
          {\cref@hyperlink{\@tempurlb}{\@tempnameb}}{\@nil}%
      \fi}%
    \def\@@@setcpageref#1#2{%
      \cpageref@getlabel{#2}{\@temppage}%
      \if@crefstarred%
        #1{\@temppage}{}{}%
      \else%
        \edef\@tempname{\cref@hyperlinkname{#2}}%
        \edef\@tempurl{\cref@hyperlinkurl{#2}}%
        #1{\@temppage}{\cref@hyperlink{\@tempurl}{\@tempname}}{\@nil}%
      \fi}%
    \def\@@@setcpagerefrange#1#2#3{%
      \cpageref@getlabel{#2}{\@pagea}%
      \cpageref@getlabel{#3}{\@pageb}%
      \if@crefstarred%
        #1{\@pagea}{\@pageb}{}{}{}{}%
      \else%
        \edef\@tempnamea{\cref@hyperlinkname{#2}}%
        \edef\@tempurlb{\cref@hyperlinkurl{#3}}%
        \edef\@tempnameb{\cref@hyperlinkname{#3}}%
        \edef\@tempurla{\cref@hyperlinkurl{#2}}%
        #1{\@pagea}{\@pageb}%
          {\cref@hyperlink{\@tempurla}{\@tempnamea}}{\@nil}%
          {\cref@hyperlink{\@tempurlb}{\@tempnameb}}{\@nil}%
      \fi}%
  }%  end of false case of \@ifpackagewith{hyperref}{implicit=false}
%    \end{macrocode}
%
%
% \subsubsection{\package{revtex4} and \package{revtex4-1} support}
% The \package{revtex4} and \package{revtex4-1} document classes use
% |\H@refstepcounter| to increment section counters, even when
% \package{hyperref} isn't explicitly loaded. Therefore, for these
% docclasses we need to redefine |\H@refstepcounter| even when
% \package{hyperref} is not loaded.
%    \begin{macrocode}
}{% false case of \@ifpackageloaded{hyperref}
  \@ifclassloaded{revtex4}{\let\if@cref@hyperrefloaded\iftrue}{}%
  \@ifclassloaded{revtex4-1}{\let\if@cref@hyperrefloaded\iftrue}{}%
  \if@cref@hyperrefloaded\relax%
    \let\cref@old@H@refstepcounter\H@refstepcounter%
    \def\H@refstepcounter#1{%
      \cref@old@H@refstepcounter{#1}%
      \cref@constructprefix{#1}{\cref@result}%
      \@ifundefined{cref@#1@alias}%
        {\def\@tempa{#1}}%
        {\def\@tempa{\csname cref@#1@alias\endcsname}}%
      \protected@edef\cref@currentlabel{%
        [\@tempa][\arabic{#1}][\cref@result]%
        \csname p@#1\endcsname\csname the#1\endcsname}}%
%    \end{macrocode}
%   We also need to redefine |\appendix| to use
%    \begin{macrocode}
    \@ifundefined{appendix}{}{%
      \def\appendix{%
        \@ifundefined{chapter}{%
          \def\H@refstepcounter##1{%
            \cref@old@H@refstepcounter{##1}%
            \cref@constructprefix{##1}{\cref@result}%
%    \end{macrocode}
%         We add a large value to the front of the counter data, to force
%         references to anything in appendices to be sorted after
%         everything else.
%    \begin{macrocode}
            \ifx\cref@result\@empty%
              \def\cref@result{2147483647}%
            \else%
              \edef\cref@result{2147483647,\cref@result}%
            \fi%
%    \end{macrocode}
%         Override the cross-reference type of sectioning commands.
%    \begin{macrocode}
            \def\@tempa{##1}%
            \def\@tempb{section}%
            \ifx\@tempa\@tempb%
              \protected@edef\cref@currentlabel{%
                [appendix][\arabic{##1}][\cref@result]%
                \csname p@##1\endcsname\csname the##1\endcsname}%
            \else%
              \def\@tempa{##1}%
              \def\@tempb{subsection}%
              \ifx\@tempa\@tempb%
                \protected@edef\cref@currentlabel{%
                  [subappendix][\arabic{##1}][\cref@result]%
                  \csname p@##1\endcsname\csname the##1\endcsname}%
              \else%
                \def\@tempa{##1}%
                \def\@tempb{subsubsection}%
                \ifx\@tempa\@tempb%
                  \protected@edef\cref@currentlabel{%
                    [subsubappendix][\arabic{##1}][\cref@result]%
                    \csname p@##1\endcsname\csname the##1\endcsname}%
                \else%
                  \@ifundefined{cref@##1@alias}%
                    {\def\@tempa{##1}}%
                    {\def\@tempa{\csname cref@##1@alias\endcsname}}%
                  \protected@edef\cref@currentlabel{%
                    [\@tempa][\arabic{##1}][\cref@result]%
                    \csname p@##1\endcsname\csname the##1\endcsname}%
                \fi%
              \fi%
            \fi}%
          \cref@old@appendix%
        }{%
          \def\H@refstepcounter##1{%
            \cref@old@H@refstepcounter{##1}%
            \cref@constructprefix{##1}{\cref@result}%
%    \end{macrocode}
%         Again, the large value added to the front of the counter data
%         forces references to appendix items to be sorted last.
%    \begin{macrocode}
            \ifx\cref@result\@empty%
              \def\cref@result{2147483647}%
            \else%
              \edef\cref@result{2147483647,\cref@result}%
            \fi%
%    \end{macrocode}
%         Override the cross-reference type of sectioning commands.
%    \begin{macrocode}
            \def\@tempa{##1}%
            \def\@tempb{chapter}%
            \ifx\@tempa\@tempb%
              \protected@edef\cref@currentlabel{%
                [appendix][\arabic{##1}][\cref@result]%
                \csname p@##1\endcsname\csname the##1\endcsname}%
            \else%
              \def\@tempa{##1}%
              \def\@tempb{section}%
              \ifx\@tempa\@tempb%
                \protected@edef\cref@currentlabel{%
                  [subappendix][\arabic{##1}][\cref@result]%
                  \csname p@##1\endcsname\csname the##1\endcsname}%
              \else%
                \def\@tempa{##1}%
                \def\@tempb{subsection}%
                \ifx\@tempa\@tempb%
                  \protected@edef\cref@currentlabel{%
                    [subsubappendix][\arabic{##1}][\cref@result]%
                    \csname p@##1\endcsname\csname the##1\endcsname}%
                \else%
                  \def\@tempa{##1}%
                  \def\@tempb{subsubsection}%
                  \ifx\@tempa\@tempb%
                    \protected@edef\cref@currentlabel{%
                      [subsubsubappendix][\arabic{##1}][\cref@result]%
                      \csname p@##1\endcsname\csname the##1\endcsname}%
                  \else%
                    \@ifundefined{cref@##1@alias}%
                      {\def\@tempa{##1}}%
                      {\def\@tempa{\csname cref@##1@alias\endcsname}}%
                    \protected@edef\cref@currentlabel{%
                      [\@tempa][\arabic{##1}][\cref@result]%
                      \csname p@##1\endcsname\csname the##1\endcsname}%
                  \fi%
                \fi%
              \fi%
            \fi}%
      \cref@old@appendix}%
      }%
    }% end of \@ifundefined{appendix}
  \fi% end of \if@cref@hyperrefloaded
  \let\if@cref@hyperrefloaded\iffalse%
}% end of \@ifpackageloaded{hyperref}
%    \end{macrocode}
% Add check to AtBeginDocument to throw error if \package{hyperref} was
% loaded after cleveref.
%    \begin{macrocode}
\AtBeginDocument{%
  \if@cref@hyperrefloaded\else%
    \@ifpackageloaded{hyperref}{%
      \PackageError{cleveref}{cleveref must be loaded after hyperref!}%
        {Package load order is wrong: load cleveref *after* hyperref.}
    }{}%
  \fi}
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
%
% \end{macro}
%
%
%
% \subsubsection{\package{varioref} support}
% \begin{macro}{varioref}
%   If \package{varioref} is loaded, we redefine its commands to use
%   \cmd{\cref} instead of \cmd{\ref} to produce the reference. Since
%   \cmd{\cref} can cope with multiple references, we extend the page
%   referencing magic of \cmd{\vref} et al.\ to use \cmd{\cpageref}
%   instead, assisted by \cmd{\@@setvpageref} and \cmd{\@vpagerefrange}
%   (which typeset page references using \package{varioref} commands).
%   The former takes care of multi-references, the latter take care of
%   the \package{varioref} page referencing magic.
% \end{macro}
%
%    \begin{macrocode}
\let\if@cref@variorefloaded\iffalse%
\@ifpackageloaded{varioref}{%
  \let\if@cref@variorefloaded\iftrue%
  \PackageInfo{cleveref}{`varioref' support loaded}%
  \PackageInfo{cleveref}{`cleveref' supersedes `varioref's
    \string\labelformat command}%
%    \end{macrocode}
%
%
% \begin{macro}{\cref@old@@vpageref}
%   Unfortunately, \package{varioref}'s |\@@vpageref| macro calls a
%   |\vref@label| \emph{before} it typesets the page reference. The
%   |\protected@write| within |\vref@label| seems to prevent an |\unskip|
%   command coming after the |\vref@label| from removing any space that
%   was inserted before the |\vref@label|. This means that setting a
%   |\reftext|\meta{x} command to |\unskip| won't work; it won't properly
%   remove any preceding space in the event that an empty page reference
%   is typeset.
%
%   This didn't matter in the original \package{varioref} implementation,
%   because it \emph{always} removed any preceding space, then inserted
%   its own space \emph{after} the |\vref@label|, which the |\unskip|
%   could then gobble. But we want to get rid of this irritating
%   always-space-gobbling behaviour here. So we have to redefine
%   |\@@vpageref| (here renamed |\cref@old@@vpageref|) in order to move
%   the |\vref@label| to the end of the macro, after the page reference
%   has been typeset. We also remove the |\unskip| from the start of
%   |\@@vpageref|.
%    \begin{macrocode}
  \def\cref@old@@vpageref#1[#2]#3{%
    \leavevmode%\unskip  <<<
    \global\advance\c@vrcnt\@ne\relax%
    \vref@pagenum\@tempa{\the\c@vrcnt @vr}%
    \vref@pagenum\@tempb{\the\c@vrcnt @xvr}%
    %\vref@label{\the\c@vrcnt @xvr}%  <<<
    \ifx\@tempa\@tempb\else%
      \vref@err{\noexpand\vref or \noexpand\vpageref at page boundary
                \@tempb-\@tempa\space (may loop)%
                }%
    \fi%
    \vrefpagenum\thevpagerefnum{#3}%
    \vref@space%
    \ifx\@tempa\thevpagerefnum%
      \def\@tempc{#1}%
      \ifx\@tempc\@empty%
         \unskip%
      \else%
         #1%
      \fi%
    \else%
      #2%
      \is@pos@number\thevpagerefnum%
         {%
          \is@pos@number\@tempa%
           {\@tempcnta\@tempa%
            \advance\@tempcnta\@ne\relax%
           }%
           {\@tempcnta\maxdimen}%
          \ifnum \thevpagerefnum =\@tempcnta%
           \ifodd\@tempcnta%
             \if@twoside%
               \reftextfaceafter%
             \else%
               \reftextafter%
             \fi%
           \else%
             \reftextafter%
           \fi%
          \else%
            \advance\@tempcnta-2\relax%
            \ifnum \thevpagerefnum =\@tempcnta%
              \ifodd\@tempcnta%
                \reftextbefore%
              \else%
                \if@twoside%
                  \reftextfacebefore%
                \else%
                  \reftextbefore%
                \fi%
              \fi%
            \else%
              \reftextfaraway{#3}%
            \fi%
          \fi%
         }%
         {\reftextfaraway{#3}}%
    \fi%
    \vref@label{\the\c@vrcnt @xvr}%  <<<
    \vref@label{\the\c@vrcnt @vr}%
  }%
%    \end{macrocode}
% \end{macro}
%
%
% \begin{macro}{\cref@@vpageref}
%   We first enhance the core \package{varioref} |\vpageref| macro to
%   allow it to cope with lists of page references. This is done by
%   defining our version in terms of \package{cleveref}'s \cmd{\cpageref}
%   command, which handles multi-references, but telling \cmd{\cpageref}
%   to typeset the actual page references themselves using
%   \package{varioref}'s own page-referencing commands. (The alternative
%   version of \cmd{\vpagerefrange} is there to facilitate later
%   redefinitions.)
%
%   Most of the work is done by defining suitable |\@setvpageref| etc.\
%   commands (below), called as appropriate by our ever-faithful
%   \cmd{\@cref} work-horse. We only make use of one of the optional
%   arguments to the original \package{varioref} |\@@vpageref| macro,
%   which we store here in \cmd{\cref@@vpageref} for later.
%    \begin{macrocode}
  \def\cref@@vpageref#1[#2]#3{%
    \begingroup%
    \def\cref@@vpageref@arg{#1}%
    \@cref{vpageref}{#3}%
    \endgroup}%
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\cref@vref}
% \begin{macro}{\cref@vrefrange}
% \begin{macro}{\cref@fullref}
%   Now we define \package{cleveref}-enhanced versions of the other
%   \package{varioref} cross-\linebreak[4]referencing commands, which use
%   \cmd{\cref} et al.\ to type set the cross-references, and the
%   \package{cleveref}-enhanced \cmd{\vpageref} et al.\ to typeset page
%   references.
%
%   The original \cmd{\vref} command passes an empty first argument to
%   \cmd{\@@vpageref}, to omit the page reference if it refers to the
%   current page. In our case, we only want to omit it if it's the sole
%   page reference we're printing; otherwise we need to print it even if
%   it refers to the current page. This is taken care of by
%   \cmd{\cref@patchreftexts} (which gets called further down). For this
%   mechanism, it's more convenient to pass \cmd{\reftextcurrent} as the
%   first argument but temporarily redefine it to be empty, instead of
%   passing an empty first argument to \cmd{\cref@@vpageref}.
%    \begin{macrocode}
  \def\cref@vref#1#2{%
    \leavevmode%
    \begingroup%
      \def\reftextcurrent{}%
      \@cref{#1}{#2}\@setcref@space%
      \cref@@vpageref{\reftextcurrent}[]{#2}%
    \endgroup}%
  \def\cref@vrefrange#1#2#3{%
    \@@setcrefrange{#1}{#2}{#3}{}\@setcref@space\vpagerefrange{#2}{#3}}%
  \def\cref@fullref#1#2{%
    \@cref{#1}{#2}\@setcref@space\@cref{fullpageref}{#2}}%
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\cref@vpagerefconjunction}
%   When typesetting multi-references, we need to add appropriate
%   conjunctions to the page references produced by the
%   \package{varioref} macros. Since we need this in various different
%   commands, we separate it out into a self-contained macro.
%    \begin{macrocode}
  \def\cref@vpagerefconjunction#1{%
    \def\@tempa{#1}%
    \def\@tempb{@second}%
    \ifx\@tempa\@tempb\relax%
      \@setcref@pairconjunction%
    \else%
      \def\@tempb{@middle}%
      \ifx\@tempa\@tempb\relax%
        \@setcref@middleconjunction%
      \else%
        \def\@tempb{@last}%
        \ifx\@tempa\@tempb\relax%
          \@setcref@lastconjunction%
        \fi%
      \fi%
    \fi}%
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\@setcref@space}
%   We separate out the typesetting of the space between the
%   cross-reference and page-reference into a separate macro, to make it
%   easier to implement the \option{poorman} option.
%    \begin{macrocode}
  \def\@setcref@space{ }%
%    \end{macrocode}
% \end{macro}
%
%
% \begin{macro}{\@setvpageref}
%   The \cmd{\@setvpageref} macro is called by \cmd{\@cref} to typeset
%   page references using \package{varioref} commands, tweaked to work
%   with the enhanced \package{cleveref} page-referencing features.
%   |#1| is the reference itself. |#2| is either empty if we're
%   typesetting a single page reference, or one of |@first|, |@second|,
%   |@middle| or |@end|, identifying where the page reference comes in a
%   multi-reference. We only make use of one of the optional arguments to
%   the original \package{varioref} |\@@vpageref| macro, available here
%   as \cmd{\cref@@vpageref@arg} (stored there by \cmd{\cref@@vpageref},
%   above).
%    \begin{macrocode}
  \def\@setvpageref#1#2{%
%    \end{macrocode}
%   Add the appropriate conjunction before the page reference.
%    \begin{macrocode}
    \cref@vpagerefconjunction{#2}%
%    \end{macrocode}
%   Undefining |\vref@space| prevents the original \package{varioref}
%   |\@@vpageref| macro from |\unskip|ing any preceding space and
%   inserting its own. We definitely don't want it to do that here when
%   we're typesetting anything other than the first group of page
%   references, as any preceding space then is part of the preceding
%   conjunction, and should be strictly respected. But, since we're
%   modifying the \package{varioref} commands anyway, we take this
%   opportunity to get rid of the irritating \package{varioref} spacing
%   behaviour even for the first group of page references.
%    \begin{macrocode}
    \def\vref@space{}%
%    \end{macrocode}
%   Modify the \package{varioref} |\reftext|\meta{x} commands as
%   appropriate for the page reference we're currently typesetting, then
%   typeset the page reference.
%    \begin{macrocode}
    \begingroup%
      \cref@patchreftexts{#2}%
      \expandafter\@@@setvpageref\expandafter%
        {\cref@@vpageref@arg}[\vref@space]{#1}%
    \endgroup}%
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\@@@setvpageref}
%   We separate out the final type setting step, as always, to make it
%   easier to redefine things later.
%    \begin{macrocode}
  \let\@@@setvpageref\cref@old@@vpageref%
%    \end{macrocode}
% \end{macro}
%
%
% \begin{macro}{\@setvpagerefrange}
%   |\@setvpagerefrange| is similar to |\@setvpageref|, but typesets page
%   ranges. |#1| and |#2| are the labels themselves. |#3| is either empty
%   if we're typesetting a single page range, or one of |@first|,
%   |@second|, |@middle| or |@end|, identifying where the page reference
%   comes in a multi-reference. We only make use of one of the optional
%   arguments to the original \package{varioref} |\@@vpageref| macro,
%   available here as \cmd{\cref@@vpageref@arg} (stored there by
%   \cmd{\cref@@vpageref}, above).
%    \begin{macrocode}
  \def\@setvpagerefrange#1#2#3{%
%    \end{macrocode}
% Add the appropriate conjunction before the page range reference.
%    \begin{macrocode}
    \cref@vpagerefconjunction{#3}%
%    \end{macrocode}
%   Unlike |\vpageref|, \package{varioref}'s |\vpagerefrange| command
%   \emph{doesn't} go in for quite the same space-mangling behaviour. We
%   still undefine \cmd{\vref@space}, though.
%    \begin{macrocode}
    \let\vref@space\relax%
%    \end{macrocode}
% Modify the \package{varioref} |\reftext|\meta{x} commands as
% appropriate for the page range we're currently typesetting, then
% typeset the page range.
%    \begin{macrocode}
    \begingroup%
      \cref@patchreftexts{#3}%
      \expandafter\@@@setvpagerefrange\expandafter%
        [\cref@@vpageref@arg]{#1}{#2}%
    \endgroup}%
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\@@@setvpagerefrange}
% Again, we separate out the final typesetting step, to aid later
% redefinition.
%    \begin{macrocode}
  \let\@@@setvpagerefrange\vpagerefrange
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\@setfullpageref}
%   Ditto for \cmd{\@setfullpageref}, with |#1| the reference, |#2|
%   either empty, |@first|, |@second|, |@middle| or |@end|.
%    \begin{macrocode}
  \def\@setfullpageref#1#2{%
%    \end{macrocode}
% Add the appropriate conjunction before the page reference.
%    \begin{macrocode}
    \cref@vpagerefconjunction{#2}%
%    \end{macrocode}
% Modify the \package{varioref} |\reftext|\meta{x} commands as
% appropriate for the page reference we're currently typesetting, then
% typeset the page reference.
%    \begin{macrocode}
    \begingroup%
      \cref@patchreftexts{#2}%
      \@@@setfullpageref{#1}%
    \endgroup}%
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\@@@setfullpageref}
%   Separate out the final typesetting step, as usual.
%    \begin{macrocode}
  \let\@@@setfullpageref\reftextfaraway%
%    \end{macrocode}
% \end{macro}
%
%
% \begin{macro}{\@setfullpagerefrange}
%   Ditto for \cmd{\@setfullpagerefrange}, with |#1| and |#2| the
%   references, |#3| either empty, |@first|, |@second|, |@middle| or
%   |@end|.
%    \begin{macrocode}
  \def\@setfullpagerefrange#1#2#3{%
%    \end{macrocode}
% Add the appropriate conjunction before the page reference.
%    \begin{macrocode}
    \cref@vpagerefconjunction{#3}%
%    \end{macrocode}
% Modify the \package{varioref} |\reftext|\meta{x} commands as
% appropriate for the page reference we're currently typesetting, then
% typeset the page reference.
%    \begin{macrocode}
    \begingroup%
      \cref@patchreftexts{#3}%
      \@@@setfullpagerefrange{#1}{#2}%
    \endgroup}%
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\@@@setfullpagerefrange}
%   Separate out the final typesetting step, as usual.
%    \begin{macrocode}
  \let\@@@setfullpagerefrange\reftextpagerange%
%    \end{macrocode}
% \end{macro}
%
%
% We save the default \package{varioref} |\reftext|\meta{x} commands as
% |\creftext|\meta{x}, before the user's had any chance to redefine them.
% These are used if a |\reftext|\meta{x} is redefined to produce an empty
% reference, to force a non-empty reference within multi-references.
%    \begin{macrocode}
  \let\creftextcurrent\reftextcurrent%
  \let\creftextfaceafter\reftextfaceafter%
  \let\creftextfacebefore\reftextfacebefore%
  \let\creftextafter\reftextafter%
  \let\creftextbefore\reftextbefore%
  \let\creftextfaraway\reftextfaraway%
  \let\creftextpagerange\reftextpagerange%
%    \end{macrocode}
%
% \begin{macro}{\cref@patchreftexts}
% \begin{macro}{\cref@restorereftexts}
%   The |\cref@patchreftexts| command modifies \package{varioref}
%   |\reftext|\meta{x} commands, for use within |\@@setvpageref| and
%   |\@@setvpagerefrange|.
%    \begin{macrocode}
  \def\cref@patchreftexts#1{%
    \cref@patchreftext{reftextcurrent}{#1}%
    \cref@patchreftext{reftextfaceafter}{#1}%
    \cref@patchreftext{reftextfacebefore}{#1}%
    \cref@patchreftext{reftextafter}{#1}%
    \cref@patchreftext{reftextbefore}{#1}}%
%    \end{macrocode}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\cref@patchreftext}
%   |\cref@patchreftext| does the hard work of modifying the
%   |\reftext|\meta{x} command given in |#1| as appropriate for the
%   |\@setvpageref| or |\@setvpagerefrange| command that it's called
%   from. (It can only be called from within one of those commands.)
%   |#2| is empty if we're typesetting a single page reference, or one of
%   |@first|, |@second|, |@middle| or |@end| when typesetting a
%   multi-reference.
% \begin{macrocode}
  \def\cref@patchreftext#1#2{%
    \def\@tempa{#2}%
%    \end{macrocode}
%   If we're typesetting a single page reference\dots
%    \begin{macrocode}
    \ifx\@tempa\@empty%
%    \end{macrocode}
%     if the reftext command produces an empty reference, redefine it to
%     be |\unskip|.
%    \begin{macrocode}
      \def\@tempc{}%
      \expandafter\ifx\csname #1\endcsname\@tempc\relax%
        \expandafter\def\csname #1\endcsname{\unskip}%
          %{\advance\count@group -1\relax\reftextcurrent@orig}%
      \else%
        \long\def\@tempc{}%
        \expandafter\ifx\csname #1\endcsname\@tempc\relax%
          \expandafter\def\csname #1\endcsname{\unskip}%
            %{\advance\count@group -1\relax\reftextcurrent@orig}%
        \fi%
      \fi%
%    \end{macrocode}
%
%   If we're typesetting a multi-reference\dots
%    \begin{macrocode}
    \else%
%    \end{macrocode}
%     if the reftext command produces an empty page reference, patch it
%     to instead use |\creftext|\meta{x}, which always produces a
%     non-empty reference.
%    \begin{macrocode}
      \long\def\@tempc{\unskip}%
      \expandafter\ifx\csname #1\endcsname\@tempc\relax%
        \expandafter\expandafter\expandafter\def%
        \expandafter\expandafter\csname #1\endcsname\expandafter{%
          \csname c#1\endcsname}%
      \else%
        \long\def\@tempc{}%
        \expandafter\ifx\csname #1\endcsname\@tempc\relax%
          \expandafter\expandafter\expandafter\def%
          \expandafter\expandafter\csname #1\endcsname\expandafter{%
            \csname c#1\endcsname}%
        \else%
          \def\@tempc{\unskip}%
          \expandafter\ifx\csname #1\endcsname\@tempc\relax%
            \expandafter\expandafter\expandafter\def%
            \expandafter\expandafter\csname #1\endcsname\expandafter{%
              \csname c#1\endcsname}%
          \else%
            \def\@tempc{}%
            \expandafter\ifx\csname #1\endcsname\@tempc\relax%
              \expandafter\expandafter\expandafter\def%
              \expandafter\expandafter\csname #1\endcsname\expandafter{%
                \csname c#1\endcsname}%
            \fi%
          \fi%
        \fi%
      \fi%
    \fi}%
%    \end{macrocode}
% \end{macro}
%
%
% \begin{macro}{\@setcref@pairconjunction}
% \begin{macro}{\@setcref@middleconjunction}
% \begin{macro}{\@setcref@lastconjunction}
%   We also add an extra macro layer for typesetting the conjunctions,
%   for the same reason. (Note that we only needed to do this for the
%   group conjunctions previously, as the other conjunctions are never
%   used directly in the normal \package{cleveref} commands. But
%   |\@setvpageref| and |\@setvpagerefrange| \emph{do} use them directly,
%   so now we do need macros to separate out the final type setting of
%   the rest of the conjunctions.)
%    \begin{macrocode}
  \def\@setcref@pairconjunction{\crefpairconjunction}%
  \def\@setcref@middleconjunction{\crefmiddleconjunction}%
  \def\@setcref@lastconjunction{\creflastconjunction}%
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
%
%
% We now redefine the original \package{varioref} commands to use the
% \package{cleveref}-enhanced versions. The redefinition of
% \cmd{\@@vpageref} has to be postponed until the beginning of the
% document, to make sure it overrides \package{hyperref}'s redefinition
% (if loaded).
%    \begin{macrocode}
  \AtBeginDocument{%
    \let\@@vpageref\cref@@vpageref%
  }%
%    \end{macrocode}
%
% \begin{macro}{\vref}
% \begin{macro}{\vref*}
% \begin{macro}{\Vref}
% \begin{macro}{\Vref*}
% \begin{macro}{\vrefrange}
% \begin{macro}{\vrefrange*}
% \begin{macro}{\Vrefrange}
% \begin{macro}{\Vrefrange*}
% \begin{macro}{\fullref}
% \begin{macro}{\fullref*}
% \begin{macro}{\Fullref}
% \begin{macro}{\Fullref*}
%   Since we're defining the spacing behaviour of \cmd{\vref} et al.\ to
%   be consistent with the other \package{cleveref} referencing commands,
%   this frees up the starred variants to be used to suppress hyperlinks
%   when \package{hyperref} is loaded, as usual.
% \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{macrocode}
  \if@cref@hyperrefloaded\relax%  hyperref loaded%
    \DeclareRobustCommand{\vref}{%
      \@ifstar{\cref@vrefstar{cref}}{\cref@vref{cref}}}%
    \DeclareRobustCommand{\Vref}{%
      \@ifstar{\cref@vrefstar{Cref}}{\cref@vref{Cref}}}%
    \DeclareRobustCommand{\vrefrange}{%
      \@ifstar{\cref@vrefrangestar{cref}}{\cref@vrefrange{cref}}}%
    \DeclareRobustCommand{\Vrefrange}{%
      \@ifstar{\cref@vrefrangestar{Cref}}{\cref@vrefrange{Cref}}}%
    \DeclareRobustCommand{\fullref}{%
      \@ifstar{\cref@fullrefstar{cref}}{\cref@fullref{cref}}}%
    \DeclareRobustCommand{\Fullref}{%
      \@ifstar{\cref@fullrefstar{Cref}}{\cref@fullref{Cref}}}%
    \def\cref@vrefstar#1#2{%
      \@crefstarredtrue%
      \cref@vref{#1}{#2}%
      \@crefstarredfalse}%
    \def\cref@vrefrangestar#1#2#3{%
      \@crefstarredtrue%
      \cref@vrefrange{#1}{#2}{#3}%
      \@crefstarredfalse}%
    \def\cref@fullrefstar#1#2{%
      \@crefstarredtrue%
      \cref@fullref{#1}{#2}%
      \@crefstarredfalse}%
  \else%
    \DeclareRobustCommand{\vref}{\cref@vref{cref}}%
    \DeclareRobustCommand{\Vref}{\cref@vref{Cref}}%
    \DeclareRobustCommand{\vrefrange}{\cref@vrefrange{cref}}%
    \DeclareRobustCommand{\Vrefrange}{\cref@vrefrange{Cref}}%
    \DeclareRobustCommand{\fullref}{\cref@fullref{cref}}%
    \DeclareRobustCommand{\Fullref}{\cref@fullref{Cref}}%
  \fi%  end of test for hyperref
}{\let\if@cref@variorefloaded\iffalse}%  end of \@ifpackageloaded{varioref}
%    \end{macrocode}
% Add check to AtBeginDocument to throw error if \package{varioref} was
% loaded after cleveref.
%    \begin{macrocode}
\AtBeginDocument{%
  \if@cref@variorefloaded\relax\else%
    \@ifpackageloaded{varioref}{%
      \PackageError{cleveref}{cleveref must be loaded after varioref!}%
        {Package load order is wrong: load cleveref *after* varioref.}
    }{}%
  \fi}
%    \end{macrocode}
%
%
%
% \subsubsection{\package{amsmath} support}
% \begin{macro}{amsmath}
% \begin{macro}{\label}
% \begin{macro}{\label@in@display}
%   The \package{amsmath} package redefines the \cmd{\label} command
%   within equation environments, so if it is loaded we have to extend
%   the behaviour to support the optional argument. With
%   \package{amsmath}, the original \cmd{\label} command is stored in
%   \cmd{\ltx@label}, and \cmd{\label@in@display} replaces \cmd{\label}
%   inside equations. \cmd{\label@in@display} just saves the label for
%   later, and defining it is left until the end of the equation, when
%   \cmd{\ltx@label} is finally called.
%
%   To allow \cmd{\label} within equations to support an optional
%   argument, we first store the original \cmd{\label@in@display} and the
%   new \cmd{\label} macro we defined above (since \cmd{\label} will be
%   clobbered inside equations). Then we redefine \cmd{\label@in@display}
%   so that it wraps all its arguments, including any optional argument,
%   in an extra set of braces. These are stripped away again by
%   \cmd{\ltx@label} before calling the \package{cleveref} \cmd{\label}
%   command we defined previously (saved in \cmd{\cref@label}). As
%   before, we must postpone the redefinition of \cmd{\label} until the
%   beginning of the document, since other packages do so.
%    \begin{macrocode}
\let\if@cref@amsmathloaded\iffalse%
\@ifpackageloaded{amsmath}{%
  \let\if@cref@amsmathloaded\iftrue%
  \AtBeginDocument{%
    \let\cref@old@label@in@display\label@in@display%
    \def\label@in@display{%
      \@ifnextchar[\label@in@display@optarg\label@in@display@noarg}%]
    \def\label@in@display@noarg#1{\cref@old@label@in@display{{#1}}}%
    \def\label@in@display@optarg[#1]#2{%
      \cref@old@label@in@display{[#1]{#2}}}%
    \def\ltx@label#1{\cref@label#1}%
  }%  end of AtBeginDocument
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\measure@}
% \begin{macro}{\gmeasure@}
%   The \package{amsmath} multi-line equation environments scan their
%   bodies twice: once to measure, once to typeset. In the measure phase,
%   the \cmd{\label} command is disabled by letting it to \cmd{\@gobble}.
%   But this isn't sufficient to gobble all the arguments any more if an
%   optional argument is supplied to our new \cmd{\label}, so we have to
%   modify the \package{amsmath} measuring commands so that they let
%   \cmd{\label} to \cmd{\cref@gobble@optarg} instead.
%
%   Unfortunately, \package{amsmath} wasn't designed with redefinitions
%   of \cmd{\label} in mind, so there appears to be no safe way of doing
%   this other than copying the \package{amsmath} definitions and making
%   the modification directly in the macro's code. This is a recipe for
%   future chaos if these commands are ever modified in a new version of
%   \package{amsmath}, but it seems we have no choice. Luckily,
%   \package{amsmath} isn't updated too often!
%    \begin{macrocode}
  \def\measure@#1{%
    \begingroup%
        \measuring@true%
        \global\eqnshift@\z@%
        \global\alignsep@\z@%
        \global\let\tag@lengths\@empty%
        \global\let\field@lengths\@empty%
        \savecounters@%
        \global\setbox0\vbox{%
            \let\math@cr@@@\math@cr@@@align@measure%
            \everycr{\noalign{\global\tag@false%
              \global\let\raise@tag\@empty \global\column@\z@}}%
            \let\label\cref@gobble@optarg%  <<< cleveref modification
            \global\row@\z@%
            \tabskip\z@%
            \halign{\span\align@preamble\crcr%
                #1%
                \math@cr@@@%
                \global\column@\z@%
                \add@amps\maxfields@\cr%
            }%
        }%
        \restorecounters@%
        \ifodd\maxfields@%
            \global\advance\maxfields@\@ne\relax%
        \fi%
        \ifnum\xatlevel@=\tw@%
            \ifnum\maxfields@<\thr@@%
                \let\xatlevel@\z@%
            \fi%
        \fi%
        \setbox\z@\vbox{%
          \unvbox\z@ \unpenalty \global\setbox\@ne\lastbox%
        }%
        \global\totwidth@\wd\@ne%
        \if@fleqn \global\advance\totwidth@\@mathmargin\relax\fi%
        \global\let\maxcolumn@widths\@empty%
        \begingroup%
          \let\or\relax%
          \loop%
            \global\setbox\@ne\hbox{%
              \unhbox\@ne \unskip \global\setbox\thr@@\lastbox%
            }%
          \ifhbox\thr@@%
           \xdef\maxcolumn@widths{ \or \the\wd\thr@@ \maxcolumn@widths}%
          \repeat%
        \endgroup%
        \dimen@\displaywidth%
        \advance\dimen@-\totwidth@\relax%
        \ifcase\xatlevel@%
            \global\alignsep@\z@%
            \let\minalignsep\z@%
            \@tempcntb\z@%
            \if@fleqn%
                \@tempcnta\@ne%
                \global\eqnshift@\@mathmargin%
            \else%
                \@tempcnta\tw@%
                \global\eqnshift@\dimen@%
                \global\divide\eqnshift@\@tempcnta\relax%
            \fi%
        \or%
            \@tempcntb\maxfields@%
            \divide\@tempcntb\tw@\relax%
            \@tempcnta\@tempcntb%
            \advance\@tempcntb\m@ne\relax%
            \if@fleqn%
                \global\eqnshift@\@mathmargin%
                \global\alignsep@\dimen@%
                \global\divide\alignsep@\@tempcnta\relax%
            \else%
                \global\advance\@tempcnta\@ne\relax%
                \global\eqnshift@\dimen@%
                \global\divide\eqnshift@\@tempcnta\relax%
                \global\alignsep@\eqnshift@%
            \fi%
        \or%
            \@tempcntb\maxfields@%
            \divide\@tempcntb\tw@\relax%
            \global\advance\@tempcntb\m@ne\relax%
            \global\@tempcnta\@tempcntb\relax%
            \global\eqnshift@\z@%
            \global\alignsep@\dimen@%
            \if@fleqn%
                \global\advance\alignsep@\@mathmargin\relax%
            \fi%
            \global\divide\alignsep@\@tempcntb\relax%
        \fi%
        \ifdim\alignsep@<\minalignsep\relax%
            \global\alignsep@\minalignsep\relax%
            \ifdim\eqnshift@>\z@%
                \if@fleqn\else%
                    \global\eqnshift@\displaywidth%
                    \global\advance\eqnshift@-\totwidth@\relax%
                    \global\advance\eqnshift@-\@tempcntb\alignsep@\relax%
                    \global\divide\eqnshift@\tw@\relax%
                \fi%
            \fi%
        \fi%
        \ifdim\eqnshift@<\z@%
            \global\eqnshift@\z@%
        \fi%
        \calc@shift@align%
        \global\tagshift@\totwidth@%
        \global\advance\tagshift@\@tempcntb\alignsep@\relax%
        \if@fleqn%
            \ifnum\xatlevel@=\tw@%
                \global\advance\tagshift@-\@mathmargin\relax%
            \fi%
        \else%
            \global\advance\tagshift@\eqnshift@\relax%
        \fi%
        \iftagsleft@ \else%
            \global\advance\tagshift@-\displaywidth\relax%
        \fi%
        \dimen@\minalignsep\relax%
        \global\advance\totwidth@\@tempcntb\dimen@\relax%
        \ifdim\totwidth@>\displaywidth%
            \global\let\displaywidth@\totwidth@%
        \else%
            \global\let\displaywidth@\displaywidth%
        \fi%
    \endgroup%
  }%
  \def\gmeasure@#1{%
    \begingroup%
        \measuring@true%
        \totwidth@\z@%
        \global\let\tag@lengths\@empty%
        \savecounters@%
        \setbox\@ne\vbox{%
            \everycr{\noalign{\global\tag@false%
              \global\let\raise@tag\@empty \global\column@\z@}}%
            \let\label\@gobble%  <<< cleveref modification
            \halign{%
                \setboxz@h{$\m@th\displaystyle{##}$}%
                \ifdim\wdz@>\totwidth@%
                    \global\totwidth@\wdz@%
                \fi%
               &\setboxz@h{\strut@{##}}%
                \savetaglength@%
                \crcr%
                #1%
                \math@cr@@@%
            }%
        }%
        \restorecounters@%
        \if@fleqn%
            \global\advance\totwidth@\@mathmargin\relax%
        \fi%
        \iftagsleft@%
            \ifdim\totwidth@>\displaywidth%
                \global\let\gdisplaywidth@\totwidth@%
            \else%
                \global\let\gdisplaywidth@\displaywidth%
            \fi%
        \fi%
    \endgroup%
}%
%    \end{macrocode}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\multline@}
% \begin{macro}{\mmeasure@}
% \begin{macro}{\label@mmeasure@noarg}
% \begin{macro}{\label@mmeasure@optarg}
%   The |multline| environment works a bit differently to the other
%   \package{amsmath} environments, in that \cmd{\label} is
%   \emph{disabled} during the typesetting phase, and \emph{enabled}
%   during the measuring phase. To cope with \package{cleveref}'s
%   optional argument, we have to define separate versions of
%   \cmd{\label@in@display} specifically for \cmd{\mmeasure@}.
%    \begin{macrocode}
  \def\multline@#1{%
    \Let@%
    \@display@init{\global\advance\row@\@ne\relax\global\dspbrk@lvl\m@ne}%
    \chardef\dspbrk@context\z@%
    \restore@math@cr%
    \let\tag\tag@in@align%
    \global\tag@false \global\let\raise@tag\@empty%
    \mmeasure@{#1}%
    \let\tag\gobble@tag \let\label\cref@gobble@optarg%  <<< cleveref modification
    \tabskip \if@fleqn \@mathmargin \else \z@skip \fi%
    \totwidth@\displaywidth%
    \if@fleqn%
        \advance\totwidth@-\@mathmargin\relax%
    \fi%
    \halign\bgroup%
        \hbox to\totwidth@{%
            \if@fleqn%
                \hskip \@centering \relax%
            \else%
                \hfil%
            \fi%
            \strut@%
            $\m@th\displaystyle{}##\endmultline@math%
            \hfil%
        }% $
        \crcr%
        \if@fleqn%
            \hskip-\@mathmargin%
            \def\multline@indent{\hskip\@mathmargin}%
        \else%
            \hfilneg%
            \def\multline@indent{\hskip\multlinegap}%
        \fi%
        \iftagsleft@%
            \iftag@%
                \begingroup%
                    \ifshifttag@%
                        \rlap{\vbox{%
                                \normalbaselines%
                                \hbox{%
                                    \strut@%
                                    \make@display@tag%
                                }%
                                \vbox to\lineht@{}%
                                \raise@tag%
                        }}%
                        \multline@indent%
                    \else%
                        \setbox\z@\hbox{\make@display@tag}%
                        \dimen@\@mathmargin \advance\dimen@-\wd\z@\relax%
                        \ifdim\dimen@<\multlinetaggap%
                          \dimen@\multlinetaggap%
                        \fi%
                        \box\z@ \hskip\dimen@\relax%
                    \fi%
                \endgroup%
            \else%
                \multline@indent%
            \fi%
        \else%
            \multline@indent%
        \fi%
    #1%
  }%
  \def\mmeasure@#1{%
    \begingroup%
        \measuring@true%
        \def\label{%                  <<< cleveref modification
          \@ifnextchar[\label@in@mmeasure@optarg%]
            \label@in@mmeasure@noarg}%
        \def\math@cr@@@{\cr}%
        \let\shoveleft\@iden \let\shoveright\@iden%
        \savecounters@%
        \global\row@\z@%
        \setbox\@ne\vbox{%
            \global\let\df@tag\@empty%
            \halign{%
                \setboxz@h{\@lign$\m@th\displaystyle{}##$}%
                \iftagsleft@%
                    \ifnum\row@=\@ne%
                        \global\totwidth@\wdz@%
                        \global\lineht@\ht\z@%
                    \fi%
                \else%
                    \global\totwidth@\wdz@%
                    \global\lineht@\dp\z@%
                \fi%
                \crcr%
                #1%
                \crcr%
            }%
        }%
        \ifx\df@tag\@empty\else\global\tag@true\fi%
        \if@eqnsw\global\tag@true\fi%
        \iftag@%
            \setboxz@h{%
                \if@eqnsw%
                    \stepcounter{equation}%
                    \tagform@\theequation%
                \else%
                    \df@tag%
                \fi%
            }%
            \global\tagwidth@\wdz@%
            \dimen@\totwidth@%
            \advance\dimen@\tagwidth@\relax%
            \advance\dimen@\multlinetaggap\relax%
            \iftagsleft@\else%
                \if@fleqn%
                    \advance\dimen@\@mathmargin\relax%
                \fi%
            \fi%
            \ifdim\dimen@>\displaywidth%
                \global\shifttag@true%
            \else%
                \global\shifttag@false%
            \fi%
        \fi%
        \restorecounters@%
    \endgroup%
  }%
  \def\label@in@mmeasure@noarg#1{%
    \begingroup%
      \measuring@false%
      \cref@old@label@in@display{{#1}}%
    \endgroup}%
  \def\label@in@mmeasure@optarg[#1]#2{%
    \begingroup%
      \measuring@false%
      \cref@old@label@in@display{[#1]{#2}}%
    \endgroup}%
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
%
% \begin{macro}{subequations}
%   In order for |subequations| to be sorted properly, \package{cleveref}
%   needs to know that the |equation| counter is effectively reset by the
%   |parentequation| counter within the |subequations| environment. This
%   isn't how |amsmath| implements subequations (for obvious reasons!),
%   but we harmlessly add the |equation| counter to the |parentequation|
%   counter's reset list \emph{within} |subequations| environments, so
%   that \package{cleveref}'s sorting mechanism can figure things out. We
%   also harmlessly make sure |parentequation| is reset by the same
%   counter as |equation|.
%
%   We also want to treat subequations as a separate cross-reference type
%   from equations. However, \package{amsmath} still uses the |equation|
%   counter for subequations, not a separate ``subequation'' counter. We
%   therefore temporarily alias |equation| to |subequation| within
%   subequation environments.
%    \begin{macrocode}
  \let\cref@old@subequations\subequations%
  \let\cref@old@endsubequations\endsubequations%
  \cref@resetby{equation}{\cref@result}%
  \ifx\cref@result\relax\else%
    \cref@addtoreset{parentequation}{\cref@result}%
  \fi%
  \renewenvironment{subequations}{%
%    \end{macrocode}
%    Temporarily declare |equation| counter to be reset by |parentequation|.
%    \begin{macrocode}
    \cref@addtoreset{equation}{parentequation}%
%    \end{macrocode}
%    Temporarily alias |equation| to |subequation|, or to whatever
%    |subequation| has been aliased to.
%    \begin{macrocode}
    \let\cref@orig@equation@alias\cref@equation@alias%
    \@ifundefined{cref@subequation@alias}%
      {\crefalias{equation}{subequation}}%
      {\def\@tempa{{equation}}%
       \expandafter\expandafter\expandafter\crefalias%
       \expandafter\@tempa\expandafter{\cref@subequation@alias}}%
    \cref@old@subequations%
  }{%
%    \end{macrocode}
%    Remove |equation| from |parentequation| counter's reset list.
%    \begin{macrocode}
    \gdef\cl@parentequation{}%
    \cref@old@endsubequations%
    \setcounter{parentequation}{0}%
%    \end{macrocode}
%    Restore original |equation| alias (if any).
%    \begin{macrocode}
    \@ifundefined{cref@orig@cref@equation@alias}%
      {\let\cref@equation@alias\relax}%
      {\let\cref@equation@alias\cref@orig@equation@alias\relax}%
    \let\cref@orig@equation@alias\relax%
  }%
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\make@df@tag@@}
% \begin{macro}{\make@df@tag@@@}
%   We override the internals of the \package{amsmath} \cmd{\tag} command
%   to add the additional information to the label definition. Since
%   labels produced by \cmd{\tag} have no logical ordering when sorting a
%   list of references, we give them a large numerical value so that they
%   get pushed to the end of sorted cross-reference lists.
%    \begin{macrocode}
  \let\cref@old@make@df@tag@@\make@df@tag@@%
  \def\make@df@tag@@#1{%
    \cref@old@make@df@tag@@{#1}%
    \let\cref@old@df@tag\df@tag%
    \expandafter\gdef\expandafter\df@tag\expandafter{%
      \cref@old@df@tag%
      \def\cref@currentlabel{[equation][2147483647][]#1}}}%
  \let\cref@old@make@df@tag@@@\make@df@tag@@@%
  \def\make@df@tag@@@#1{%
    \cref@old@make@df@tag@@@{#1}%
    \let\cref@old@df@tag\df@tag%
    \expandafter\gdef\expandafter\df@tag\expandafter{%
      \cref@old@df@tag%
      \toks@\@xp{\p@equation{#1}}%
      \edef\cref@currentlabel{[equation][2147483647][]\the\toks@}}}%
}{}%  end of \@ifpackageloaded{amsmath}
%    \end{macrocode}
% \end{macro}
% \end{macro}
%
% Add check to AtBeginDocument to throw error if \package{amsmath} was
% loaded after cleveref.
%    \begin{macrocode}
\AtBeginDocument{%
  \if@cref@amsmathloaded\else%
    \@ifpackageloaded{amsmath}{%
      \PackageError{cleveref}{cleveref must be loaded after amsmath!}%
        {Package load order is wrong: load cleveref *after* amsmath.}
    }{}%
  \fi}
%
%
%
% \subsubsection{\package{amsthm} support}
% \begin{macro}{amsthm}
%   If \package{amsthm} is loaded, we need to modify its theorem
%   referencing features so that they work with \package{cleveref}.
%    \begin{macrocode}
\@ifpackageloaded{amsthm}{%
  \PackageInfo{cleveref}{`amsthm' support loaded}%
%    \end{macrocode}
%
% \begin{macro}{\@thm}
%   We modify \package{amsthm}'s version of the \cmd{\@thm} macro, to
%   have it call \cmd{\refstepcounter} with an optional argument
%   containing the theorem type.
%    \begin{macrocode}
  \let\cref@thmnoarg\@thm%
  \def\@thm{\@ifnextchar[{\cref@thmoptarg}{\cref@thmnoarg}}%]
  \def\cref@thmoptarg[#1]#2#3#4{%
    \ifhmode\unskip\unskip\par\fi%
    \normalfont%
    \trivlist%
    \let\thmheadnl\relax%
    \let\thm@swap\@gobble%
    \thm@notefont{\fontseries\mddefault\upshape}%
    \thm@headpunct{.}% add period after heading
    \thm@headsep 5\p@ plus\p@ minus\p@\relax%
    \thm@space@setup%
    #2% style overrides
    \@topsep \thm@preskip               % used by thm head
    \@topsepadd \thm@postskip           % used by \@endparenv
    \def\@tempa{#3}\ifx\@empty\@tempa%
      \def\@tempa{\@oparg{\@begintheorem{#4}{}}[]}%
    \else%
      \refstepcounter[#1]{#3}%  <<< cleveref modification
      \def\@tempa{\@oparg{\@begintheorem{#4}{\csname the#3\endcsname}}[]}%
    \fi%
    \@tempa}%
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\@ynthm}
%   We also have to modify \package{amsthm}'s \cmd{\@ynthm} command so
%   that it passes the optional argument to \cmd{\@thm}. Since
%   \package{amsmath}'s \cmd{\@ynthm} takes a different parameter list to
%   the standard \LaTeX{} \cmd{\@ynthm} macro, we deliberately override
%   our previous redefinition, and add the code for the automatic
%   \cmd{\crefname} definitions directly to this version.
%    \begin{macrocode}
  \def\@ynthm#1[#2]#3{%
%    \end{macrocode}
%   Here's the automatic \cmd{\crefname} definition.
%    \begin{macrocode}
    \edef\@tempa{\expandafter\noexpand%
      \csname cref@#1@name@preamble\endcsname}%
    \edef\@tempb{\expandafter\noexpand%
      \csname Cref@#1@name@preamble\endcsname}%
    \def\@tempc{#3}%
    \ifx\@tempc\@empty\relax%
      \expandafter\gdef\@tempa{}%
      \expandafter\gdef\@tempb{}%
    \else%
      \if@cref@capitalise%
        \expandafter\expandafter\expandafter\gdef\expandafter%
          \@tempa\expandafter{\MakeUppercase #3}%
      \else%
        \expandafter\expandafter\expandafter\gdef\expandafter%
          \@tempa\expandafter{\MakeLowercase #3}%
      \fi%
      \expandafter\expandafter\expandafter\gdef\expandafter%
        \@tempb\expandafter{\MakeUppercase #3}%
    \fi%
    \cref@stack@add{#1}{\cref@label@types}%
%    \end{macrocode}
%   Here's the original \package{amsthm} \cmd{\@ynthm} definition, with
%   the \package{cleveref} modification.
%    \begin{macrocode}
    \ifx\relax#2\relax%
      \def\@tempa{\@oparg{\@xthm{#1}{#3}}[]}%
    \else%
      \@ifundefined{c@#2}{%
        \def\@tempa{\@nocounterr{#2}}%
      }{%
        \@xp\xdef\csname the#1\endcsname{\@xp\@nx\csname the#2\endcsname}%
        \toks@{#3}%
        \@xp\xdef\csname#1\endcsname{%
          \@nx\@thm[#1]{%  <<< new optional argument for theorem name
            \let\@nx\thm@swap%
              \if S\thm@swap\@nx\@firstoftwo\else\@nx\@gobble\fi%
            \@xp\@nx\csname th@\the\thm@style\endcsname}%
              {#2}{\the\toks@}}%
        \let\@tempa\relax%
      }%
    \fi%
    \@tempa}%
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\@xnthm}
%   Finally, we have to restore the \package{amsthm} version of
%   \cmd{\@xnthm}, which we stored earlier in \cmd{\cref@old@xnthm} and
%   redefined. With \package{amsthm}, \cmd{\@xnthm} calls \cmd{\@ynthm},
%   so the automatic \cmd{\crefname} definition is already taken care of.
%    \begin{macrocode}
  \let\@xnthm\cref@old@xnthm%
}{}%  end of \@ifpackageloaded{amsthm}
%    \end{macrocode}
% \end{macro}
%
%
%
% \subsubsection{\package{ntheorem} support}
% \begin{macro}{ntheorem}
% \begin{macro}{thref}
%   If \package{ntheorem} is loaded, we need to modify its theorem
%   referencing features so that they work with \package{cleveref}.
%    \begin{macrocode}
\@ifpackageloaded{ntheorem}{%
  \PackageInfo{cleveref}{`ntheorem' support loaded}%
  \@ifpackagewith{ntheorem}{thref}{%
    \PackageWarning{cleveref}{`cleveref' supersedes `ntheorem's `thref'
      option}%
    \renewcommand{\thref}{\cref}}{}%
%    \end{macrocode}
%
% \begin{macro}{\theorem@prework}
%   Newer versions of \package{ntheorem} require a call to
%   \cmd{\theorem@prework} when typesetting theorems. If an older
%   version of \package{ntheorem} is being used, we just \cmd{\let} it to
%   \cmd{\relax} to make sure it's defined.
%    \begin{macrocode}
  \@ifundefined{theorem@prework}{\let\theorem@prework\relax}{}%
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\@thm}
%   We modify \package{ntheorem}'s version of the \cmd{\@thm} macro very
%   slightly, to have it call \cmd{\refstepcounter} with an optional
%   argument containing the theorem type.
%    \begin{macrocode}
  \gdef\@thm#1#2#3{%
    \if@thmmarks%
      \stepcounter{end\InTheoType ctr}%
    \fi%
    \renewcommand{\InTheoType}{#1}%
    \if@thmmarks%
      \stepcounter{curr#1ctr}%
      \setcounter{end#1ctr}{0}%
    \fi%
    \refstepcounter[#1]{#2}%  <<< cleveref modification
    \theorem@prework%
    \thm@topsepadd \theorempostskipamount%
    \ifvmode \advance\thm@topsepadd\partopsep\relax\fi%
    \trivlist%
    \@topsep \theorempreskipamount%
    \@topsepadd \thm@topsepadd%
    \advance\linewidth -\theorem@indent\relax%
    \advance\@totalleftmargin \theorem@indent\relax%
    \parshape \@ne \@totalleftmargin \linewidth%
    \@ifnextchar[{\@ythm{#1}{#2}{#3}}{\@xthm{#1}{#2}{#3}}%]
  }%
}{}%  end of \@ifpackageloaded{ntheorem}
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
%
%
%
% \subsubsection{\package{IEEEtrantools} support}
% \begin{macro}{IEEEtrantools}
%   The |IEEEeqnarray| environment and \cmd{\IEEEeqnarraccr} command calls
%   \cmd{\stepcounter} instead of \cmd{\refstepcounter} to increment the
%   equation counters, so they fail to set the cross-reference type for
%   \package{cleveref}. We patch in calls to \cmd{\refstepcounter} to fix
%   this.
%    \begin{macrocode}
\@ifpackageloaded{IEEEtrantools}{%
  \PackageInfo{cleveref}{`IEEEtrantools' support loaded}%
%    \end{macrocode}
%
% \begin{macro}{\@@IEEEeqnarray}
%   Rather than copying the whole of \cmd{\@@IEEEeqnarray} just to patch
%   the \cmd{\stepcounter} line (which would be fragile and liable to
%   breakage), we insert an extra step which calls \cmd{\refstepcounter}
%   to set the cross-reference type, then decrements the |equation|
%   counter by one, before calling the original \cmd{\@@IEEEeqnarray}.
%    \begin{macrocode}
  \let\cref@orig@@IEEEeqnarray\@@IEEEeqnarray%
  \def\@@IEEEeqnarray[#1]#2{%
    \refstepcounter{equation}%
    \addtocounter{equation}{-1}%
    \cref@orig@@IEEEeqnarray[#1]{#2}}%
%    \end{macrocode}
% \end{macro}
%
% We do the same thing with \cmd{\@IEEEeqnarrayXCR}, the last in the
% chain of macros that gets invoked by |\\| (let to
% \cmd{\IEEEeqnarraycr}) within |IEEEeqnarray| environments.
% \begin{macro}{\@IEEEeqnarrayXCR}
%    \begin{macrocode}
  \let\cref@orig@IEEEeqnarrayXCR\@IEEEeqnarrayXCR%
%    \end{macrocode}
% Newer versions of \package{IEEEtrantools} replace
% |\if@IEEEissubequation| conditional with a counter |\c@IEEEsubequation|
% that is $>0$ in subequations.
%    \begin{macrocode}
  \@ifundefined{c@IEEEsubequation}{%
    \def\@IEEEeqnarrayXCR[#1]{%
      \if@eqnsw%
        \if@IEEEissubequation%
          \refstepcounter{IEEEsubequation}%
          \addtocounter{IEEEsubequation}{-1}%
        \else%
          \refstepcounter{equation}%
          \addtocounter{equation}{-1}%
        \fi%
      \fi%
      \cref@orig@IEEEeqnarrayXCR[#1]}%
  }{
    \def\@IEEEeqnarrayXCR[#1]{%
      \if@eqnsw%
        \ifnum\c@IEEEsubequation>0\relax%
          \refstepcounter{IEEEsubequation}%
          \addtocounter{IEEEsubequation}{-1}%
        \else%
          \refstepcounter{equation}%
          \addtocounter{equation}{-1}%
        \fi%
      \fi%
      \cref@orig@IEEEeqnarrayXCR[#1]}%
  }% end of \@ifundefined{c@IEEEsubequation}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\IEEEyessubnumber}
%   And again for \cmd{\IEEEyessubnumber} (used to turn an equation into a
%   subequation).
%    \begin{macrocode}
  \let\cref@orig@IEEEyessubnumber\IEEEyessubnumber%
  \def\IEEEyessubnumber{%
    \if@IEEEeqnarrayISinner%
      \if@IEEElastlinewassubequation\else%
        \setcounter{IEEEsubequation}{0}%
        \refstepcounter{IEEEsubequation}%
      \fi%
    \fi%
    \cref@orig@IEEEyessubnumber}%
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{IEEEsubequation}
%   To get the subequation formatting right, we harmlessly add the
%   |IEEEsubequation| counter to the |equation| counter reset list so
%   that \package{cleveref} can figure out the subnumbering relationship,
%   and define |IEEEsubequation| to be an alias of the |subequation| format.
%    \begin{macrocode}
  \cref@addtoreset{IEEEsubequation}{subequation}%
  \crefalias{IEEEsubequation}{subequation}%
%    \end{macrocode}
% \end{macro}
%
%    \begin{macrocode}
}{}% end of \@ifpackageloaded{IEEEtrantools}
%    \end{macrocode}
% \end{macro}
%
%
%
% \subsubsection{\package{breqn} support}
% \begin{macro}{breqn}
%   The \package{breqn} package uses \cmd{\eq@setcounter} instead of
%   \cmd{\refstepcounter} to set equation numbers, which as usual breaks
%   \package{cleveref}. To fix this, we have to patch
%   \cmd{\eq@setcounter} with similar code to that already added to
%   \cmd{\refstepcounter}.
%    \begin{macrocode}
\@ifpackageloaded{breqn}{%
  \PackageInfo{cleveref}{`breqn' support loaded}%
  \let\cref@old@eq@setnumber\eq@setnumber%
  \def\eq@setnumber{%
    \cref@old@eq@setnumber%
    \cref@constructprefix{equation}{\cref@result}%
    \protected@xdef\cref@currentlabel{%
      [equation][\arabic{equation}][\cref@result]\p@equation\eq@number}}%
}{}% end of \@ifpackageloaded{breqn}
%    \end{macrocode}
% \end{macro}
%
%
%
% \subsubsection{\package{algorithmicx} support}
% \begin{macro}{algorithmicx}
%   If \package{algorithmicx} is loaded, we modify its line numbering
%   mechanism so that labels referring to line numbers in algorithms work
%   with \package{cleveref}.
% \end{macro}
%    \begin{macrocode}
  \@ifpackageloaded{algorithmicx}{%
  \PackageInfo{cleveref}{`algorithmicx' support loaded}%
%    \end{macrocode}
%
% \begin{macro}{\ALG@step}
%   We modify \package{algorithmicx}'s \cmd{\ALG@step} macro, which
%   increments the line number, so that it stores the necessary
%   information in \cmd{\cref@currentlabel}. \cmd{\ALG@step} already
%   increments the line number counter \cmd{\ALG@line} using
%   \cmd{\addtocounter}, but to get \package{cleveref} support working,
%   it's cleaner to hook into the \cmd{\refstepcounter} mechanism, so we
%   first decrement the counter and then re-increment it using
%   \cmd{\refstepcounter}.
%    \begin{macrocode}
  \g@addto@macro\ALG@step{%
    \addtocounter{ALG@line}{-1}%
    \refstepcounter{ALG@line}%
    \expandafter\@cref@getprefix\cref@currentlabel\@nil\cref@currentprefix%
    \xdef\cref@currentprefix{\cref@currentprefix}}%
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\ALG@beginalgorithmic}
%   However, this is not yet sufficient. The \cmd{\refstepcounter} above
%   is called within a group, so the resulting \cmd{\cref@currentlabel}
%   definition will not persist beyond the end of the group. To transfer
%   the information to the ``outside'', we follow \package{algorithmicx}'
%   own method for getting the label information into
%   \cmd{\@currentlabel}: we define \cmd{\cref@currentlabel} within
%   |algorithm| environments to refer specifically to macros that store
%   the line number information. The package conveniently supplies a
%   \cmd{\ALG@beginalgorithmic} hook, so we make use of it here.
%    \begin{macrocode}
  \g@addto@macro\ALG@beginalgorithmic{%
    \def\cref@currentlabel{%
      [line][\arabic{ALG@line}][\cref@currentprefix]\theALG@line}}%
  }{}%  end of \@ifpackageloaded{algorithmicx}
%    \end{macrocode}
% \end{macro}
%
%
%
% \subsubsection{\package{listings} support}
% \begin{macro}{listings}
%   To support cross-references to listings produced by the
%   \package{listings} package, all we need to do is alias the counter it
%   uses, \cmd{\lstnumber}, to the ``listing'' cross-reference type.
%    \begin{macrocode}
  \@ifpackageloaded{listings}{%
    \PackageInfo{cleveref}{`listings' support loaded}%
    \crefalias{lstlisting}{listing}%
    \crefalias{lstnumber}{line}%
%    \end{macrocode}
%
% However, supporting cross-references to the line numbers is
% unfortunately a little more complicated than simply aliasing the
% ``lstnumber'' counter to the ``line'' cross-reference type (above).
% \package{listings} calls \cmd{\refstepcounter} from its
% \cmd{\lsthk@EveryPar} hook. But the hook macro is expanded inside a
% group. So that \cmd{\refstepcounter} call is completely useless:
% neither the \cmd{\@currentlabel} nor the \cmd{\cref@currentlabel}
% definitions make it out of the group, so they have no effect on
% \cmd{\label} definitions!
%
% To make line labels work, \package{listings} sets \cmd{\@currentlabel}
% to \cmd{\thelstnumber} at the beginning of a listing, via the
% \cmd{\lsthk@Init} hook, and it is \emph{this} (and not
% \cmd{\refstepcounter}) which causes the current line number to be
% picked up by \cmd{\label}s. To get line numbers working with
% \package{cleveref} too, we need to replicate this for
% \cmd{\cref@currentlabel}, which is what the following hook code does.
%
% \begin{macro}{\lsthk@Init}
% \begin{macro}{\lsthk@EveryPar}
%    \begin{macrocode}
    \lst@AddToHook{Init}{%
      \def\cref@currentlabel{%
        [line][\arabic{lstnumber}][\cref@currentprefix]\thelstnumber}}%
    \lst@AddToHook{EveryPar}{%
      \expandafter\@cref@getprefix\cref@currentlabel\@nil\cref@currentprefix%
      \xdef\cref@currentprefix{\cref@currentprefix}}%
  }{}%  end of \@ifpackageloaded{listings}
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
%
%
%
% \subsubsection{\package{algorithm2e} support}
% \begin{macro}{algorithm2e}
%   When \package{hyperref} is not loaded, all we need to do to support
%   the \package{algorithm2e} package is to alias its counters,
%   \cmd{\algocf}, \cmd{AlgoLine} and \cmd{\algocfline}, to the
%   ``algorithm'' and ``line'' cross-reference types.
%    \begin{macrocode}
  \@ifpackageloaded{algorithm2e}{%
    \PackageInfo{cleveref}{`algorithm2e' support loaded}%
    \crefalias{algocf}{algorithm}%
    \crefalias{algocfline}{line}%
    \crefalias{AlgoLine}{line}%
%    \end{macrocode}
% When \package{hyperref} \emph{is} loaded, \package{algorithm2e} does
% some trickery when stepping the line number counter to avoid getting
% duplicate hyperlink anchor names, and updates \cmd{@currentlabel}
% manually. Unfortunately, this by-passes both \cmd{\refstepcounter} and
% \cmd{\H@refstepcounter}, so \cmd{\cref@currentlabel} never gets
% updated. To fix this, we have to hack its \cmd{algocf@nl@sethref} macro
% to update \cmd{cref@currentlabel} along with \cmd{@currentlabel}.
%    \begin{macrocode}
    \let\cref@old@algocf@nl@sethref\algocf@nl@sethref%
    \renewcommand{\algocf@nl@sethref}[1]{%
      \cref@old@algocf@nl@sethref{#1}%
      \cref@constructprefix{AlgoLine}{\cref@result}%
      \@ifundefined{cref@AlgoLine@alias}%
        {\def\@tempa{AlgoLine}}%
        {\def\@tempa{\csname cref@AlgoLine@alias\endcsname}}%
      \xdef\cref@currentlabel{%
        [\@tempa][\arabic{AlgoLine}][\cref@result]%
        \csname p@AlgoLine\endcsname\csname theAlgoLine\endcsname}}%
  }{}%  end of \@ifpackageloaded{algorithm2e}
%    \end{macrocode}
% \end{macro}
%
%
%
% \subsubsection{\package{subfig} support}
% \begin{macro}{subfig}
%   The \package{subfig} package modifies \cmd{\refstepcounter} within
%   floats. Most of the time, this isn't a problem for
%   \package{cleveref}, as \package{subfig}'s modified
%   \cmd{\refstepcounter} calls \package{cleveref}'s version after it's
%   done its stuff. However, this breaks support the
%   \cmd{\refstepcounter} optional argument, so we fix that here.
%
%   \package{Subfig} also redefines \cmd{\label} within subfloats,
%   breaking \package{cleveref}'s optional argument. We also fix that.
%    \begin{macrocode}
\@ifpackageloaded{subfig}{%
  \PackageInfo{cleveref}{`subfig' support loaded}%
%    \end{macrocode}
%
% \begin{macro}{\refsteponlycounter}
%   \package{subfig} replaces \cmd{\refstepcounter} with
%   \cmd{\refsteponlycounter} within floats, which calls the saved
%   \package{cleveref} \cmd{\refstepcounter} after doing some extra
%   \package{subfig}-related processing. We redefine
%   \cmd{\refsteponlycounter} so that passing it an optional argument
%   bypasses \package{subfig}'s code entirely and just calls the
%   \package{cleveref} code directly. Since only
%   \package{cleveref}-specific commands will ever pass an optional
%   argument to \cmd{\refstepcounter}, this won't affect
%   \package{subfig}'s use of \cmd{\refstepcounter}. We have to postpone
%   this redefinition until the beginning of the document because
%   \package{subfig} does.
%    \begin{macrocode}
  \AtBeginDocument{%
    \let\cref@old@refsteponlycounter\refsteponlycounter%
    \def\refsteponlycounter{%
      \@ifnextchar[\refstepcounter@optarg%
        \cref@old@refsteponlycounter%]
    }}%
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\sf@sub@label}
% \begin{macro}{\sf@old@label}
% \begin{macro}{\cref@old@label}
%   Inside a subfloat, \package{subfig} captures the current \cmd{\label}
%   definition in \cmd{\sf@oldlabel}, then replaces \cmd{\label} with
%   \cmd{\subfloat@label}, which does additional argument and
%   subfloat-related processing before calling \cmd{\sf@oldlabel}. This
%   breaks \package{cleveref}'s \cmd{\label} optional argument.
%
%   We need to insert an extra layer of processing into the chain of
%   redefined \cmd{\label} macro calls, to process \package{cleveref}'s
%   optional argument. We do this by redefining \package{subfig}'s
%   \cmd{\sf@sub@label} command to process \package{subfig}'s optional
%   argument (which uses parentheses rather than square brackets) as usual,
%   but then have it call \cmd{\cref@label} which stores
%   \package{cleveref}'s \cmd{\label} command (recall that we're inside a
%   subfloat here, where \package{subfig} has overridden the \cmd{\label}
%   macro itself), to process \package{cleveref}'s own \cmd{\label}
%   optional argument.
%
%   \cmd{\cref@label} would normally call the original \cmd{\label}
%   definition stored in \cmd{\cref@old@label}, whereas here we want it
%   to instead call \cmd{\sf@@sub@label}, the next layer of the
%   \package{subfig} \cmd{\label} macro stack, otherwise we bypass the
%   rest of the \package{subfig} processing and break it. So we
%   temporarily let \cmd{\cref@old@label} to \cmd{\sf@@sub@label}, so
%   that \cmd{\cref@label} hands back to \package{subfig}'s \cmd{\label}
%   processing when done. (We're inside a group, so \cmd{\cref@old@label}
%   gets restored at the end of the subfloat.)
%
%   The final issue is that \package{subfig} captures the original
%   \cmd{\label} definition in \cmd{\sf@oldlabel} at the beginning of the
%   subfloat. But this captures \package{cleveref}'s
%   definition,\footnote{Actually, because \package{subfig} always loads
%   the \package{caption} package, it captures \package{cleveref}'s
%   \package{caption}-related redefinition of \cmd{\label}.} instead of
%   the original \cmd{\label} definition that needs to be called after
%   \package{subfig} has finished its stuff. So, we let \cmd{\sf@oldlabel}
%   to \cmd{\cref@old@label} before redefining the latter, so that the
%   \package{subfig} \cmd{\label} stack calls the right thing once it's
%   done its own processing. Oof!
%    \begin{macrocode}
  \def\sf@sub@label(#1){%
    \ifhyperrefloaded%
      \protected@edef\@currentlabelname{%
        \expandafter\strip@period #1\relax.\relax\@@@}%
    \fi%
    \let\sf@oldlabel\cref@old@label%
    \let\cref@old@label\sf@@sub@label%
    \cref@label}%
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
%
%    \begin{macrocode}
  }{}%  end of \@ifpackageloaded{subfig}
%    \end{macrocode}
% \end{macro}
%
%
%
% \subsubsection{\package{memoir} subfig support}
% \begin{macro}{memoir}
%   We try to stay out of \package{memoir}'s way as much as possible, by
%   using a separate set of parallel label definitions for
%   \package{cleveref}, and leaving the standard labels alone for
%   \package{memoir} and other packages to use as normal. The one
%   remaining point of contention is the \cmd{\label} command itself.
%
% \begin{macro}{\sf@memsub@label}
% \begin{macro}{\@memoldlabel}
% \begin{macro}{\cref@old@label}
%   \package{memoir} contains its own internal re-implementation of
%   \package{subfig}, which redefines \cmd{\label} in a very similar way.
%   We therefore have to replicate the \package{subfig} support for
%   \package{memoir}'s internal re-implementation. (We have to postpone
%   the redefinitions until the beginning of the document because
%   \package{memoir} does, too.)
%    \begin{macrocode}
\@ifclassloaded{memoir}{%
  \AtBeginDocument{%
    \def\sf@memsub@label(#1){%
      \protected@edef\mem@currentlabelname{#1}%
      \let\@memoldlabel\cref@old@label%
      \let\cref@old@label\sf@@memsub@label%
      \cref@label}}%
}{}%
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
%
%
%
% \subsubsection{\package{caption} support}
% \begin{macro}{caption}
%   The \package{caption} package redefines \cmd{\label} within floats.
%   Since version 3.2c, it is careful to redefine \cmd{\label} in a way
%   that doesn't break any optional arguments introduced by other
%   packages (such as \package{cleveref}'s), so we no longer need to add
%   any compatibility hacks.
%
%   Earlier versions of \package{caption} do break \package{cleveref}'s
%   optional argument, however, so we have to fix things here for those
%   versions.
%    \begin{macrocode}
\@ifpackageloaded{caption}{%
  \@ifpackagelater{caption}{2011/08/19}{}{%
    \PackageInfo{cleveref}{`caption' support loaded}%
%    \end{macrocode}
%
% \begin{macro}{\cref@old@caption@xlabel}
% \begin{macro}{\cref@old@label}
% \begin{macro}{\cref@ORI@label}
% \begin{macro}{\caption@ORI@label}
%   We fix the \cmd{\label} argument parsing by redefining
%   \cmd{\caption@xlabel}, the macro which \cmd{\label} is let to inside
%   floats, to juggle around the various \package{cleveref} and
%   \package{caption} \cmd{\label}-processing macros so that everything
%   ultimately gets processed correctly.
%
%   \cmd{\cref@label} stores \package{cleveref}'s \cmd{\label}
%   redefinition (recall that we're inside a float here, where
%   \cmd{\label} itself has been redefined by \package{caption}).
%   \cmd{\cref@label} processes \package{cleveref}'s optional
%   \cmd{\label} argument, if any. It then calls \cmd{\cref@old@label}.
%   But we've let that to \cmd{\cref@old@caption@xlabel}, which stores
%   the original \cmd{\caption@xlabel}. So the net effect is to insert an
%   extra layer of optional argument processing between \cmd{\label} and
%   \cmd{\caption@xlabel}, which can then proceed as before.
%
%   The final issue is that \package{caption} captures the original
%   \cmd{\label} definition in \cmd{\caption@ORI@label}, but this picks
%   up the \package{cleveref} redefinition, which is not what we want. So
%   we let \cmd{\caption@ORI@label} to the original \cmd{\label}
%   definition as captured by \package{cleveref}. Usually, that's stored
%   in \cmd{\cref@old@label}, but we've temporarily redefined that. So we
%   need to save what was originally preserved in \cmd{\cref@old@label}
%   in \cmd{\cref@ORI@old@label}, and make \cmd{\caption@ORI@label} call
%   that. Oof!
%    \begin{macrocode}
    \let\cref@old@caption@xlabel\caption@xlabel%
    \def\caption@xlabel{%
      \let\cref@ORI@label\cref@old@label%
      \let\cref@old@label\cref@old@caption@xlabel%
      \let\caption@ORI@label\cref@ORI@label%
      \cref@label}%
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
%
%    \begin{macrocode}
    }% end of \@ifpackagelater
  }{}%  end of \@ifpackageloaded{caption}
%    \end{macrocode}
% \end{macro}
%
%
%
% \subsubsection{\package{aliascnt} support}
% \begin{macro}{aliascnt}
%   For the \package{aliascnt} trick described in \cref{sec:label_type}
%   of the documentation to work, we have to inform \package{cleveref}
%   about how aliased counters get reset. \package{aliascnt}'s
%   \cmd{\newaliascnt} command doesn't add the aliased counter to any
%   reset list, but if the counter it's aliased to gets reset, the
%   aliased counter will get reset too. In order for \package{cleveref}
%   to correctly sort cross-references to the aliased counter, we have to
%   add that counter to the appropriate reset list, even though that
%   isn't necessary to actually reset the counter itself. We add this to
%   the \cmd{\newaliascnt} command.
% \end{macro}
% \begin{macro}{\newaliascnt}
%    \begin{macrocode}
\@ifpackageloaded{aliascnt}{%
  \PackageInfo{cleveref}{`aliascnt' support loaded}%
  \let\cref@old@newaliascnt\newaliascnt%
  \renewcommand*{\newaliascnt}[2]{%
    \cref@old@newaliascnt{#1}{#2}%
    \cref@resetby{#2}{\cref@result}%
    \ifx\cref@result\relax\else%
      \cref@addtoreset{#1}{\cref@result}%
    \fi}%
  }{}%  end of \@ifpackageloaded{aliascnt}
%    \end{macrocode}
% \end{macro}
%
%
%
% \subsection{Poor Man's \package{cleveref}}
% \begin{macro}{poorman}
%   The \option{poorman} option causes a |sed| script to automatically be
%   written. When the original \LaTeX{} source file is processed through
%   this script, it strips out all the \package{cleveref} commands,
%   typesetting all the reference formatting explicitly, and using the
%   standard \cmd{\ref} and \cmd{\pageref} commands to produce the
%   references themselves.
% \end{macro}
%    \begin{macrocode}
\DeclareOption{poorman}{%
  \PackageInfo{cleveref}{option `poorman' loaded}%
%    \end{macrocode}
%
%
% \begin{macro}{\cref@poorman@text}
%   Define global macro \cmd{\cref@poorman@text} to store the text
%   produced by the \cmd{\cref} commands, and open an output stream for
%   writing the script before starting to process the document body.
%    \begin{macrocode}
  \gdef\cref@poorman@text{}%
  \AtBeginDocument{%
    \newwrite\@crefscript%
    \immediate\openout\@crefscript=\jobname.sed}%
%    \end{macrocode}
% \end{macro}
%
%
% \begin{macro}{select@language}
% \begin{macro}{foreign@language}
%   If \package{babel} is loaded, we add to the \cmd{\select@language}
%   and \cmd{\foreign@language} commands to make them write substitution
%   rules to the script that replace the cross-reference name and
%   conjunction component macros with the appropriate language-dependent
%   names. We use |sed| line-number addresses in the rules to ensure they
%   are only applied to the regions in which that particular language was
%   in use.
%
%   Note that we write substitution rules for the \emph{previous}
%   language block when the language is changed, because we need the
%   rules to appear in the script \emph{after} all the cross-reference
%   substitution rules for that language block. \cmd{\cref@inputlineno}
%   stores the input-file line-number of the start of the previous
%   language block.
%
%   We postpone the redefinitions until the beginning of the document not
%   only to ensure that they don't get clobbered by other package's
%   redefinitions, but also because we don't want the redefinitions to
%   take effect until after \package{babel} has called
%   \cmd{\selectlanguage} for the main language (remember, the
%   substitution rules for this first language block will get written at
%   the next language change).
%
%   Note that, since we're writing to the script file within
%   \cmd{\AtBeginDocument} and \cmd{\AtEndDocument}, this code has to
%   come \emph{after} the above \cmd{\AtBeginDocument} code which opens
%   the script file for writing, and \emph{before} the later
%   \cmd{\AtEndDocument} code (below) which closes it.
%
%   The |\if@cref@switched@language| flag is set when a \package{babel}
%   language switching command is called. It is checked by
%   \cmd{\cref@writelanguagerules} when writing substitution rules.
%    \begin{macrocode}
  \newif\if@cref@switched@language%
  \@ifpackageloaded{babel}{%
    \AtBeginDocument{%
      \let\cref@old@select@language\select@language%
      \def\select@language{%
        \@cref@switched@languagetrue%
        \cref@writelanguagerules%
        \cref@old@select@language}%
      \let\cref@old@foreign@language\foreign@language%
      \def\foreign@language{%
        \@cref@switched@languagetrue%
        \cref@writelanguagerules%
        \cref@old@foreign@language}%
      \edef\cref@inputlineno{\the\inputlineno}}%
    }{}%
%    \end{macrocode}
% \end{macro}
% \end{macro}
%
% The final set of substitution rules gets written at the end of the
% document. This is the only set of rules that gets written if
% \package{babel} is not loaded.
%    \begin{macrocode}
  \AtEndDocument{%
    \let\select@language\cref@old@select@language%
    \let\foreign@language\cref@old@foreign@language%
    \cref@writelanguagerules}%
%    \end{macrocode}
%
% \begin{macro}{\cref@writelanguagerules}
%   \cmd{\cref@writelanguagerules} does the grunt work of writing out the
%   necessary substitution rules.
%    \begin{macrocode}
  \def\cref@writelanguagerules{%
    \begingroup%
%    \end{macrocode}
% If |\if@cref@switched@language| hasn't been set, then we must be
% writing the final set of substitution rules at the end of a document
% in which no language switching command was ever used. In which case,
% the substitution rules don't specify a line-number address.
%    \begin{macrocode}
      \if@cref@switched@language%
        \edef\@address{\cref@inputlineno,\the\inputlineno}%
      \else%
        \def\@address{}%
      \fi%
      \expandafter\def\expandafter\cref@poorman@text\expandafter{%
        \crefrangeconjunction}%
      \expandafter\def\expandafter\@tempa\expandafter{%
        \expandafter{\@address}{\string\crefrangeconjunction}}%
      \expandafter\cref@writescript\@tempa%
      \expandafter\def\expandafter\cref@poorman@text\expandafter{%
        \crefrangepreconjunction}%
      \expandafter\def\expandafter\@tempa\expandafter{%
        \expandafter{\@address}{\string\crefrangepreconjunction}}%
      \expandafter\cref@writescript\@tempa%
      \expandafter\def\expandafter\cref@poorman@text\expandafter{%
        \crefrangepostconjunction}%
      \expandafter\def\expandafter\@tempa\expandafter{%
        \expandafter{\@address}{\string\crefrangepostconjunction}}%
      \expandafter\cref@writescript\@tempa%
      \expandafter\def\expandafter\cref@poorman@text\expandafter{%
        \crefpairconjunction}%
      \expandafter\def\expandafter\@tempa\expandafter{%
        \expandafter{\@address}{\string\crefpairconjunction}}%
      \expandafter\cref@writescript\@tempa%
      \expandafter\def\expandafter\cref@poorman@text\expandafter{%
        \crefmiddleconjunction}%
      \expandafter\def\expandafter\@tempa\expandafter{%
        \expandafter{\@address}{\string\crefmiddleconjunction}}%
      \expandafter\cref@writescript\@tempa%
      \expandafter\def\expandafter\cref@poorman@text\expandafter{%
        \creflastconjunction}%
      \expandafter\def\expandafter\@tempa\expandafter{%
        \expandafter{\@address}{\string\creflastconjunction}}%
      \expandafter\cref@writescript\@tempa%
      \expandafter\def\expandafter\cref@poorman@text\expandafter{%
        \crefpairgroupconjunction}%
      \expandafter\def\expandafter\@tempa\expandafter{%
        \expandafter{\@address}{\string\crefpairgroupconjunction}}%
      \expandafter\cref@writescript\@tempa%
      \expandafter\def\expandafter\cref@poorman@text\expandafter{%
        \crefmiddlegroupconjunction}%
      \expandafter\def\expandafter\@tempa\expandafter{%
        \expandafter{\@address}{\string\crefmiddlegroupconjunction}}%
      \expandafter\cref@writescript\@tempa%
      \expandafter\def\expandafter\cref@poorman@text\expandafter{%
        \creflastgroupconjunction}%
      \expandafter\def\expandafter\@tempa\expandafter{%
        \expandafter{\@address}{\string\creflastgroupconjunction}}%
      \expandafter\cref@writescript\@tempa%
%    \end{macrocode}
% We write substitution rules for all component-derived cross-reference
% formats, as listed in \cmd{\cref@label@types}.
%    \begin{macrocode}
      \let\@tempstack\cref@label@types%
      \cref@isstackfull{\@tempstack}%
      \@whilesw\if@cref@stackfull\fi{%
%    \end{macrocode}
% \cmd{\cref@\meta{type}@name} substitution rules.
%    \begin{macrocode}
        \edef\@tempa{\cref@stack@top{\@tempstack}}%
        \expandafter\expandafter\expandafter\def%
        \expandafter\expandafter\expandafter\cref@poorman@text%
        \expandafter\expandafter\expandafter{%
          \csname cref@\@tempa @name\endcsname}%
        \edef\@tempa{%
          \string\cref@\expandafter\noexpand\@tempa @name\space}%
        \expandafter\expandafter\expandafter\def%
        \expandafter\expandafter\expandafter\@tempa%
        \expandafter\expandafter\expandafter{%
          \expandafter\expandafter\expandafter{%
            \expandafter\@address\expandafter}%
          \expandafter{\@tempa}}%
        \expandafter\cref@writescript\@tempa%
%    \end{macrocode}
% \cmd{\cref@\meta{type}@name@plural} substitution rules.
%    \begin{macrocode}
        \edef\@tempa{\cref@stack@top{\@tempstack}}%
        \expandafter\expandafter\expandafter\def%
        \expandafter\expandafter\expandafter\cref@poorman@text%
        \expandafter\expandafter\expandafter{%
          \csname cref@\@tempa @name@plural\endcsname}%
        \edef\@tempa{%
          \string\cref@\expandafter\noexpand\@tempa%
          @name@plural\space}%
        \expandafter\expandafter\expandafter\def%
        \expandafter\expandafter\expandafter\@tempa%
        \expandafter\expandafter\expandafter{%
          \expandafter\expandafter\expandafter{%
            \expandafter\@address\expandafter}%
          \expandafter{\@tempa}}%
        \expandafter\cref@writescript\@tempa%
%    \end{macrocode}
% \cmd{\Cref@\meta{type}@name} substitution rules.
%    \begin{macrocode}
        \edef\@tempa{\cref@stack@top{\@tempstack}}%
        \expandafter\expandafter\expandafter\def%
        \expandafter\expandafter\expandafter\cref@poorman@text%
        \expandafter\expandafter\expandafter{%
          \csname Cref@\@tempa @name\endcsname}%
        \edef\@tempa{%
          \string\Cref@\expandafter\noexpand\@tempa @name\space}%
        \expandafter\expandafter\expandafter\def%
        \expandafter\expandafter\expandafter\@tempa%
        \expandafter\expandafter\expandafter{%
          \expandafter\expandafter\expandafter%
          {\expandafter\@address\expandafter}%
          \expandafter{\@tempa}}%
        \expandafter\cref@writescript\@tempa%
%    \end{macrocode}
% \cmd{\Cref@\meta{type}@name@plural} substitution rules.
%    \begin{macrocode}
        \edef\@tempa{\cref@stack@top{\@tempstack}}%
        \expandafter\expandafter\expandafter\def%
        \expandafter\expandafter\expandafter\cref@poorman@text%
        \expandafter\expandafter\expandafter{%
          \csname Cref@\@tempa @name@plural\endcsname}%
        \edef\@tempa{%
          \string\Cref@\expandafter\noexpand\@tempa%
          @name@plural\space}%
        \expandafter\expandafter\expandafter\def%
        \expandafter\expandafter\expandafter\@tempa%
        \expandafter\expandafter\expandafter{%
          \expandafter\expandafter\expandafter%
          {\expandafter\@address\expandafter}%
          \expandafter{\@tempa}}%
        \expandafter\cref@writescript\@tempa%
%    \end{macrocode}
% After the loop over cross-reference types, we set
% \cmd{\cref@inputlineno} to the current input-file line, in preparation
% for the next language block.
%    \begin{macrocode}
        \cref@stack@pop{\@tempstack}%
        \cref@isstackfull{\@tempstack}}%
    \endgroup%
    \edef\cref@inputlineno{\the\inputlineno}}%
%    \end{macrocode}
% \end{macro}
%
%
% After processing the document body, we re-read in the temporary script
% file, and write it out again to the final |sed| script file, escaping
% regexp special characters in the process. The escaping is carried out
% by turning the regexp special characters into active characters, and
% defining them to expand to their escaped form. This involves a lot of
% juggling of catcodes and lccodes!
%
% Both \cmd{\DeclareOption} and \cmd{\AtEndDocument} store their
% arguments in token lists, so all the following \TeX{} code is already
% tokenised long before it is expanded and evaluated. Thus there is no
% (easy) way to change the catcodes of the characters appearing here
% before they are tokenised. In one way this is convenient: the catcode
% changes we make don't ``take'' until evaluated, so we can continue to
% use the standard \TeX{} characters (\textbackslash, \{, \} etc.) even
% after the lines containing the catcode commands. But in another, more
% significant, way, it is very inconvenient: it makes it difficult to
% define the regexp special characters as active characters, since it's
% impossible to directly create tokens with the correct char- and
% catcodes.
%
% We get around this by creating the unusual charcode/catcode
% combinations using the \cmd{\lowercase} trick (\cmd{\lowercase} changes
% the charcodes of all characters in its argument to their lccodes, but
% \emph{leaves their catcodes alone}). That way, the argument of
% \cmd{\AtEndDocument} is tokenised correctly, and when it comes to be
% expanded and evaluated, the \cmd{\lowercase} commands create tokens
% with the correct char- and catcodes.
%    \begin{macrocode}
  \AtEndDocument{%
    \immediate\closeout\@crefscript%
    \newread\@crefscript%
    \immediate\openin\@crefscript=\jobname.sed%
    \begingroup%
      \newif\if@not@eof%
      \def\@eof{\par }%
%    \end{macrocode}
% Change catcodes of regexp special characters to make them active
% characters and define them to expand to their escaped forms. Change
% those of \TeX{} special characters to make them normal letters.
%    \begin{macrocode}
      \catcode`.=13 \catcode`*=13%
      \catcode`[=13 \catcode`]=13%
      \catcode`^=13 \catcode`$=13 %$
      \catcode`\=0 \catcode`<=1 \catcode`>=2%
      \catcode`\\=13 \catcode`\{=12 \catcode`\}=12 \catcode`_=12%
      \lccode`/=92%
      \lccode`~=92\lowercase{\def~{\string/\string/}}%
      \lccode`~=42\lowercase{\def~{\string/\string*}}%
      \lccode`~=46\lowercase{\def~{\string/\string.}}%
      \lccode`~=91\lowercase{\def~{\string/\string[}}%
      \lccode`~=93\lowercase{\def~{\string/\string]}}%
      \lccode`~=94\lowercase{\def~{\string/\string^}}%
      \lccode`~=36\lowercase{\def~{\string/\string$}}% $
      \lccode`~=0 \lccode`/=0 \catcode`~=12%
%    \end{macrocode}
% Read lines from the temporary script file, expand them to escape regexp
% special characters, and store them in \cmd{\cref@poorman@text}.
%    \begin{macrocode}
      \def\cref@poorman@text{}%
      \immediate\read\@crefscript to \@tempa%
      \ifx\@tempa\@eof%
        \@not@eoffalse%
      \else%
        \@not@eoftrue%
        \edef\@tempa{\@tempa}%
      \fi%
      \@whilesw\if@not@eof\fi{%
        \expandafter\g@addto@macro\expandafter%
          \cref@poorman@text\expandafter{\@tempa^^J}%
        \immediate\read\@crefscript to \@tempa%
        \ifx\@tempa\@eof%
          \@not@eoffalse%
        \else%
          \@not@eoftrue%
          \edef\@tempa{\@tempa}%
        \fi}%
    \endgroup%
    \immediate\closein\@crefscript%
%    \end{macrocode}
% Add some rules to remove other \package{cleveref} commands. We use the
% \cmd{\lowercase} trick again for writing the \textbackslash, \{ and \}
% characters. (This could be done in other ways, but since we're in
% \cmd{\lowercase} mood, why not stick with it.)
%    \begin{macrocode}
    \begingroup%
      \lccode`|=92 \lccode`<=123 \lccode`>=125 \lccode`C=67%
      \lowercase{\def\@tempa{%[|
          s/||label|[[^]]*|]/||label/g}}%
      \expandafter\g@addto@macro\expandafter%
        \cref@poorman@text\expandafter{\@tempa^^J}%
      \lowercase{\edef\@tempa{s/||usepackage|(|[.*|]|)|<0,1|><cleveref>//g}}%
      \expandafter\g@addto@macro\expandafter%
        \cref@poorman@text\expandafter{\@tempa^^J}%
      \lowercase{\edef\@tempa{s/||[cC]refformat<.*><.*>//g}}%
      \expandafter\g@addto@macro\expandafter%
        \cref@poorman@text\expandafter{\@tempa^^J}%
      \lowercase{\edef\@tempa{s/||[cC]refrangeformat<.*><.*>//g}}%
      \expandafter\g@addto@macro\expandafter%
        \cref@poorman@text\expandafter{\@tempa^^J}%
      \lowercase{\edef\@tempa{s/||[cC]refmultiformat<.*><.*><.*><.*>//g}}%
      \expandafter\g@addto@macro\expandafter%
        \cref@poorman@text\expandafter{\@tempa^^J}%
      \lowercase{\edef\@tempa{%
          s/||[cC]refrangemultiformat<.*><.*><.*><.*>//g}}%
      \expandafter\g@addto@macro\expandafter%
        \cref@poorman@text\expandafter{\@tempa^^J}%
      \lowercase{\edef\@tempa{s/||[cC]refname<.*><.*>//g}}%
      \expandafter\g@addto@macro\expandafter%
        \cref@poorman@text\expandafter{\@tempa^^J}%
      \lowercase{\edef\@tempa{s/||[cC]reflabelformat<.*><.*>//g}}%
      \expandafter\g@addto@macro\expandafter%
        \cref@poorman@text\expandafter{\@tempa^^J}%
      \lowercase{\edef\@tempa{s/||[cC]refrangelabelformat<.*><.*>//g}}%
      \expandafter\g@addto@macro\expandafter%
        \cref@poorman@text\expandafter{\@tempa^^J}%
      \lowercase{\edef\@tempa{s/||[cC]refdefaultlabelformat<.*>//g}}%
      \expandafter\g@addto@macro\expandafter%
        \cref@poorman@text\expandafter{\@tempa^^J}%
      \lowercase{\edef\@tempa{%
          s/||renewcommand<||crefpairconjunction><.*>//g}}%
      \expandafter\g@addto@macro\expandafter%
        \cref@poorman@text\expandafter{\@tempa^^J}%
      \lowercase{\edef\@tempa{%
          s/||renewcommand<||crefpairgroupconjunction><.*>//g}}%
      \expandafter\g@addto@macro\expandafter%
        \cref@poorman@text\expandafter{\@tempa^^J}%
      \lowercase{\edef\@tempa{%
          s/||renewcommand<||crefmiddleconjunction><.*>//g}}%
      \expandafter\g@addto@macro\expandafter%
        \cref@poorman@text\expandafter{\@tempa^^J}%
      \lowercase{\edef\@tempa{%
          s/||renewcommand<||crefmiddlegroupconjunction><.*>//g}}%
      \expandafter\g@addto@macro\expandafter%
        \cref@poorman@text\expandafter{\@tempa^^J}%
      \lowercase{\edef\@tempa{%
          s/||renewcommand<||creflastconjunction><.*>//g}}%
      \expandafter\g@addto@macro\expandafter%
        \cref@poorman@text\expandafter{\@tempa^^J}%
      \lowercase{\edef\@tempa{%
          s/||renewcommand<||creflastgroupconjunction><.*>//g}}%
      \expandafter\g@addto@macro\expandafter%
        \cref@poorman@text\expandafter{\@tempa^^J}%
      \lowercase{\edef\@tempa{s/||renewcommand<||[cC]ref><.*>//g}}%
      \expandafter\g@addto@macro\expandafter%
        \cref@poorman@text\expandafter{\@tempa^^J}%
      \lowercase{\edef\@tempa{s/||renewcommand<||[cC]refrange><.*>//g}}%
      \expandafter\g@addto@macro\expandafter%
        \cref@poorman@text\expandafter{\@tempa^^J}%
    \endgroup%
%    \end{macrocode}
% Overwrite the script file with the new, escaped regexp rules.
%    \begin{macrocode}
    \newwrite\@crefscript%
    \immediate\openout\@crefscript=\jobname.sed%
    \immediate\write\@crefscript{\cref@poorman@text}%
    \immediate\closeout\@crefscript%
  }%  end of \AtEndDocument
%    \end{macrocode}
%
%
% \begin{macro}{\cref@writescript}
%   The \cmd{\cref@writescript} utility macro does the actual writing of
%   the substitution rule to the script. The first argument is the
%   ``address'', the second argument is the regexp pattern to match,
%   whilst the substitution text is whatever is currently stored in
%   \cmd{\cref@poorman@text}.
%    \begin{macrocode}
  \def\cref@getmeaning#1{\expandafter\@cref@getmeaning\meaning#1\@nil}%
  \def\@cref@getmeaning#1->#2\@nil{#2}%
  \def\cref@writescript#1#2{%
    \edef\@tempa{\cref@getmeaning{\cref@poorman@text}}%
    \immediate\write\@crefscript{#1 s/#2/\@tempa/g}}%
%    \end{macrocode}
% \end{macro}
%
%
% \begin{macro}{\cref}
% \begin{macro}{\Cref}
% \begin{macro}{\crefrange}
% \begin{macro}{\Crefrange}
% \begin{macro}{\@crefstar}
% \begin{macro}{\@crefnostar}
% \begin{macro}{\@crefrangestar}
% \begin{macro}{\@crefrangenostar}
%   To make use of all the \option{poorman} infrastructure defined above,
%   we must redefine the \package{cleveref} referencing commands
%   themselves. There are two parts to this: at the very top layer of the
%   cross-referencing macro stack, we redefine the user-level commands to
%   first initialise |\cref@poorman@text| to the empty string, then
%   typeset the reference as usual, and finally write a substitution
%   rule to the |sed| script containing whatever has been accumulated in
%   |\cref@poorman@text|. At the very lowest layer of the macro stack, we
%   redefine the macros that actually typeset the various parts of the
%   references to additionally add a copy of whatever they typeset to
%   |\cref@poorman@text|.
%
%   We first redefine the user-level referencing commands so that they
%   write a substitution rule for the reference to the script, as well as
%   typesetting the reference itself. Most of the redefinitions differ
%   slightly depending on whether \package{hyperref} is loaded.
%    \begin{macrocode}
  \if@cref@hyperrefloaded\relax%  hyperref loaded
    \def\@crefnostar#1#2{%
      \gdef\cref@poorman@text{}%
      \@cref{#1}{#2}%
%    \end{macrocode}
% We use a temporary \cmd{\@tempa} macro here, which makes use of the
% fact that the first character of \#1 is ``c'' for lower-case and ``C''
% for upper-case in these commands, in order to write out the correct
% capitalisation in the substitution.
%
% FIXME: We only resort to this because |\string\#1| doesn't work. But
% there \emph{must} be a better way to get a backslash character into the
% token stream, obviating the need for the ugly \cmd{\@tempa} macro.
%    \begin{macrocode}
      \def\@tempa##1##2\@nil{%
        \if##1c%
          \cref@writescript{}{\string\cref\string{#2\string}}%
        \else%
          \cref@writescript{}{\string\Cref\string{#2\string}}%
        \fi}%
      \@tempa#1\@nil}%
    \def\@crefstar#1#2{%
      \gdef\cref@poorman@text{}%
      \@crefstarredtrue\@cref{#1}{#2}\@crefstarredfalse%
      \def\@tempa##1##2\@nil{%
        \if##1c%
          \cref@writescript{}{\string\cref*\string{#2\string}}%
        \else%
          \cref@writescript{}{\string\Cref*\string{#2\string}}%
        \fi}%
      \@tempa#1\@nil}%
    \def\@crefrangenostar#1#2#3{%
      \gdef\cref@poorman@text{}%
      \@@setcrefrange{#2}{#3}{#1}{}%
      \def\@tempa##1##2\@nil{%
        \if##1c%
          \cref@writescript{}{%
            \string\crefrange\string{#2\string}\string{#3\string}}%
        \else%
          \cref@writescript{}{%
            \strinsg\Crefrange\string{#2\string}\string{#3\string}}%
        \fi}%
      \@tempa#1\@nil}%
    \def\@crefrangestar#1#2#3{%
      \gdef\cref@poorman@text{}%
      \@crefstarredtrue\@@setcrefrange{#2}{#3}{#1}{}\@crefstarredfalse%
      \def\@tempa##1##2\@nil{%
        \if##1c%
          \cref@writescript{}{%
            \string\crefrange*\string{#2\string}\string{#3\string}}%
        \else%
          \cref@writescript{}{%
            \string\Crefrange*\string{#2\string}\string{#3\string}}%
        \fi}%
      \@tempa#1\@nil}%
    \def\@cpagerefrangenostar#1#2#3{%
      \gdef\cref@poorman@text{}%
      \@@setcpagerefrange{#2}{#3}{#1}{}%
      \def\@tempa##1##2\@nil{%
        \if##1c%
          \cref@writescript{}{%
            \string\cpagerefrange\string{#2\string}\string{#3\string}}%
        \else%
          \cref@writescript{}{%
            \string\Cpagerefrange\string{#2\string}\string{#3\string}}%
        \fi}%
      \@tempa#1\@nil}%
    \def\@cpagerefrangestar#1#2#3{%
      \gdef\cref@poorman@text{}%
      \@crefstarredtrue%
      \@@setcpagerefrange{#2}{#3}{#1}{}%
      \@crefstarredfalse%
      \def\@tempa##1##2\@nil{%
        \if##1c%
          \cref@writescript{}{%
            \string\cpagerefrange*\string{#2\string}\string{#3\string}}%
        \else%
          \cref@writescript{}{%
            \string\Cpagerefrange*\string{#2\string}\string{#3\string}}%
        \fi}%
      \@tempa#1\@nil}%
    \def\@labelcrefnostar#1{%
      \gdef\cref@poorman@text{}%
      \@cref{labelcref}{#1}%
      \cref@writescript{}{\string\labelcref\string{#1\string}}}%
    \def\@labelcrefstar#1{%
      \gdef\cref@poorman@text{}%
      \@crefstarredtrue%
      \@cref{labelcref}{#1}%
      \@crefstarredfalse%
      \cref@writescript{}{\string\labelcref*\string{#1\string}}}%
    \def\@labelcpagerefnostar#1{%
      \gdef\cref@poorman@text{}%
      \@cref{labelcpageref}{#1}%
      \cref@writescript{}{\string\labelcpageref\string{#1\string}}}%
    \def\@labelcpagerefstar#1{%
      \gdef\cref@poorman@text{}%
      \@crefstarredtrue%
      \@cref{labelcpageref}{#1}%
      \@crefstarredfalse%
      \cref@writescript{}{\string\labelcpageref*\string{#1\string}}}%
%
  \else%  hyperref not loaded
    \DeclareRobustCommand{\cref}[1]{%
      \gdef\cref@poorman@text{}%
      \@cref{cref}{#1}%
      \cref@writescript{}{\string\cref\string{#1\string}}}%
    \DeclareRobustCommand{\Cref}[1]{%
      \gdef\cref@poorman@text{}%
      \@cref{Cref}{#1}%
      \cref@writescript{}{\string\Cref\string{#1\string}}}%
    \DeclareRobustCommand{\crefrange}[2]{%
      \gdef\cref@poorman@text{}%
      \@@setcrefrange{#1}{#2}{cref}{}%
      \cref@writescript{}{%
        \string\crefrange\string{#1\string}\string{#2\string}}}%
    \DeclareRobustCommand{\Crefrange}[2]{%
      \gdef\cref@poorman@text{}%
      \@@setcrefrange{#1}{#2}{Cref}{}%
      \cref@writescript{}{%
        \string\Crefrange\string{#1\string}\string{#2\string}}}%
    \DeclareRobustCommand{\cpageref}[1]{%
      \gdef\cref@poorman@text{}%
      \@cref{cpageref}{#1}%
      \cref@writescript{}{\string\cpageref\string{#1\string}}}%
    \DeclareRobustCommand{\Cpageref}[1]{%
      \gdef\cref@poorman@text{}%
      \@cref{Cpageref}{#1}%
      \cref@writescript{}{\string\Cpageref\string{#1\string}}}%
    \DeclareRobustCommand{\cpagerefrange}[2]{%
      \gdef\cref@poorman@text{}%
      \@@setcpagerefrange{#1}{#2}{cref}{}%
      \cref@writescript{}{%
        \string\cpagerefrange\string{#1\string}\string{#2\string}}}%
    \DeclareRobustCommand{\Cpagerefrange}[2]{%
      \gdef\cref@poorman@text{}%
      \@@setcpagerefrange{#1}{#2}{Cref}{}%
      \cref@writescript{}{%
        \string\Cpagerefrange\string{#1\string}\string{#2\string}}}%
    \DeclareRobustCommand{\labelcref}[1]{%
      \gdef\cref@poorman@text{}%
      \@cref{labelcref}{#1}%
      \cref@writescript{}{\string\labelcref\string{#1\string}}}%
    \DeclareRobustCommand{\labelcpageref}[1]{%
      \gdef\cref@poorman@text{}%
      \@cref{labelcpageref}{#1}%
      \cref@writescript{}{\string\labelcpageref\string{#1\string}}}%
  \fi%  end of test for hyperref
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \begin{macro}{\namecref}
% \begin{macro}{\nameCref}
% \begin{macro}{\lcnamecref}
% \begin{macro}{\namecrefs}
% \begin{macro}{\nameCrefs}
% \begin{macro}{\lcnamecrefs}
%   The \cmd{\namecref} et al.\ commands don't do anything different when
%   \package{hyperref} is loaded, so we don't need to test for
%   \package{hyperref} when redefining them.
%    \begin{macrocode}
  \DeclareRobustCommand{\namecref}[1]{%
    \gdef\cref@poorman@text{}%
    \@setnamecref{cref}{#1}{}{}%
    \cref@writescript{}{\string\namecref\string{#1\string}}}%
  \DeclareRobustCommand{\nameCref}[1]{%
    \gdef\cref@poorman@text{}%
    \@setnamecref{Cref}{#1}{}{}%
    \cref@writescript{}{\string\nameCref\string{#1\string}}}%
  \DeclareRobustCommand{\lcnamecref}[1]{%
    \gdef\cref@poorman@text{}%
    \@setnamecref{Cref}{#1}{}{\MakeLowercase}%
    \cref@writescript{}{\string\lcnamecref\string{#1\string}}}%
  \DeclareRobustCommand{\namecrefs}[1]{%
    \gdef\cref@poorman@text{}%
    \@setnamecref{cref}{#1}{@plural}{}%
    \cref@writescript{}{\string\namecrefs\string{#1\string}}}%
  \DeclareRobustCommand{\nameCrefs}[1]{%
    \gdef\cref@poorman@text{}%
    \@setnamecref{Cref}{#1}{@plural}{}%
    \cref@writescript{}{\string\nameCrefs\string{#1\string}}}%
  \DeclareRobustCommand{\lcnamecrefs}[1]{%
    \gdef\cref@poorman@text{}%
    \@setnamecref{Cref}{#1}{@plural}{\MakeLowercase}%
    \cref@writescript{}{\string\lcnamecrefs\string{#1\string}}}%
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
%
%
% \begin{macro}{\@setcref@pairgroupconjunction}
% \begin{macro}{\@setcref@middlegroupconjunction}
% \begin{macro}{\@setcref@lastgroupconjunction}
%   Redefine \cmd{\@@@setcref}, \cmd{\@@@setcrefrange},
%   \cmd{\@@@setcpageref} and\linebreak[4] \cmd{\@@@setcpagerefrange}, as
%   well as the conjunction macros\linebreak[4]
%   \cmd{\@setcref@middlegroupconjunction},
%   \cmd{\@setcref@lastgroupconjunction} and
%   \cmd{\@setcref@pairgroupconjunction}, to append text they typeset
%   to\linebreak[4] the \cmd{\cref@poorman@text} macro, as well as
%   actually doing the typesetting.
%    \begin{macrocode}
  \def\@setcref@pairgroupconjunction{%
    \crefpairgroupconjunction%
    \expandafter\g@addto@macro\expandafter\cref@poorman@text%
      \expandafter{\crefpairgroupconjunction}}%
  \def\@setcref@middlegroupconjunction{%
    \crefmiddlegroupconjunction%
    \expandafter\g@addto@macro\expandafter\cref@poorman@text%
      \expandafter{\crefmiddlegroupconjunction}}%
  \def\@setcref@lastgroupconjunction{%
    \creflastgroupconjunction%
    \expandafter\g@addto@macro\expandafter\cref@poorman@text%
      \expandafter{\creflastgroupconjunction}}%
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
% \begin{macro}{\@@@setcref}
% \begin{macro}{\@@@setcrefrange}
% \begin{macro}{\@@@setcpageref}
% \begin{macro}{\@@@setcpagerefrange}
%   The necessary redefinitions of most of the cross-referencing commands
%   differ slightly depending on whether \package{hyperref} is loaded or
%   not.
%    \begin{macrocode}
  \let\old@@@setcref\@@@setcref%
  \let\old@@@setcrefrange\@@@setcrefrange%
  \let\old@@@setcpageref\@@@setcpageref%
  \let\old@@@setcpagerefrange\@@@setcpagerefrange%
  \if@cref@hyperrefloaded\relax%  hyperref loaded
    \def\@@@setcref#1#2{%
      \old@@@setcref{#1}{#2}%
      \if@crefstarred%
        \expandafter\g@addto@macro\expandafter\cref@poorman@text%
          \expandafter{#1{\ref*{#2}}{}{}}%
      \else%
        \expandafter\g@addto@macro\expandafter\cref@poorman@text%
          \expandafter{#1{\ref{#2}}{}{}}%
      \fi}%
    \def\@@@setcrefrange#1#2#3{%
      \old@@@setcrefrange{#1}{#2}{#3}%
      \if@crefstarred%
        \expandafter\g@addto@macro\expandafter\cref@poorman@text%
          \expandafter{#1{\ref*{#2}}{\ref*{#3}}{}{}{}{}}%
      \else%
        \expandafter\g@addto@macro\expandafter\cref@poorman@text%
          \expandafter{#1{\ref{#2}}{\ref{#3}}{}{}{}{}}%
      \fi}%
    \def\@@@setcpageref#1#2{%
      \old@@@setcpageref{#1}{#2}%
      \if@crefstarred%
        \expandafter\g@addto@macro\expandafter\cref@poorman@text%
          \expandafter{#1{\pageref*{#2}}{}{}}%
      \else%
        \expandafter\g@addto@macro\expandafter\cref@poorman@text%
          \expandafter{#1{\pageref{#2}}{}{}}%
      \fi}%
    \def\@@@setcpagerefrange#1#2#3{%
      \old@@@setcpagerefrange{#1}{#2}{#3}%
      \if@crefstarred%
        \expandafter\g@addto@macro\expandafter\cref@poorman@text%
          \expandafter{#1{\pageref*{#2}}{\pageref*{#3}}{}{}{}{}}%
      \else%
        \expandafter\g@addto@macro\expandafter\cref@poorman@text%
          \expandafter{#1{\pageref{#2}}{\pageref{#3}}{}{}{}{}}%
      \fi}%
%
  \else%  hyperref not loaded
    \def\@@@setcref#1#2{%
      \old@@@setcref{#1}{#2}%
      \expandafter\g@addto@macro\expandafter{%
        \expandafter\cref@poorman@text\expandafter}%
        \expandafter{#1{\ref{#2}}{}{}}}%
    \def\@@@setcrefrange#1#2#3{%
      \old@@@setcrefrange{#1}{#2}{#3}%
      \expandafter\g@addto@macro%
        \expandafter{\expandafter\cref@poorman@text\expandafter}%
        \expandafter{#1{\ref{#2}}{\ref{#3}}{}{}{}{}}}%
    \def\@@@setcpageref#1#2{%
      \old@@@setcpageref{#1}{#2}%
      \expandafter\g@addto@macro\expandafter{%
        \expandafter\cref@poorman@text\expandafter}%
        \expandafter{#1{\pageref{#2}}{}{}}}%
    \def\@@@setcpagerefrange#1#2#3{%
      \old@@@setcpagerefrange{#1}{#2}{#3}%
      \expandafter\g@addto@macro%
        \expandafter{\expandafter\cref@poorman@text\expandafter}%
        \expandafter{#1{\pageref{#2}}{\pageref{#3}}{}{}{}{}}}%
  \fi%  end of hyperref test
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \begin{macro}{\@@@setnamecref}
%   The \cmd{\namecref} et al.\ commands don't do anything different when
%   \package{hyperref} is loaded, so we don't need to test for
%   \package{hyperref} when redefining \cmd{\@@@setnamecref}.
%    \begin{macrocode}
  \let\old@@@setnamecref\@@@setnamecref%
  \def\@@@setnamecref#1#2{%
    \old@@@setnamecref{#1}{#2}%
    \expandafter\def\expandafter\@tempa\expandafter{#1}%
    \def\@tempb{#2}%
    \expandafter\expandafter\expandafter\g@addto@macro%
      \expandafter\expandafter\expandafter{%
      \expandafter\expandafter\expandafter\cref@poorman@text%
      \expandafter\expandafter\expandafter}%
      \expandafter\expandafter\expandafter{\expandafter\@tempb\@tempa}}%
%    \end{macrocode}
% \end{macro}
%
%
% \begin{macro}{varioref}
%   If \package{varioref} is loaded, do the same for the
%   \package{varioref} commands.
%    \begin{macrocode}
  \@ifpackageloaded{varioref}{%
    \AtBeginDocument{%
%    \end{macrocode}
%
% \begin{macro}{\@@vpageref}
% We redefine \cmd{\@@vpageref} to make it write a substitution rule to
% the script, as well as typesetting the page reference.
%    \begin{macrocode}
      \def\@@vpageref#1[#2]#3{%
        \gdef\cref@poorman@text{}%
        \cref@@vpageref{#1}[#2]{#3}%
        \cref@writescript{}{\string\vpageref\string{#3\string}}}%
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\cref@vref}
%   \cmd{\cref@vref} is similarly redefined to write a substitution rule.
%    \begin{macrocode}
      \let\old@cref@vref\cref@vref%
      \def\cref@vref#1#2{%
        \gdef\cref@poorman@text{}%
        \old@cref@vref{#1}{#2}%
        \def\@tempa##1##2\@nil{%
          \if##1c%
            \if@crefstarred%
              \cref@writescript{}{\string\vref*\string{#2\string}}%
            \else%
              \cref@writescript{}{\string\vref\string{#2\string}}%
            \fi%
          \else%
            \if@crefstarred%
              \cref@writescript{}{\string\Vref*\string{#2\string}}%
            \else%
              \cref@writescript{}{\string\Vref\string{#2\string}}%
            \fi%
          \fi}%
        \@tempa#1\@nil}%
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\cref@fullref}
% \begin{macro}{\cref@vrefrange}
%   \cmd{\cref@fullref} and \cmd{\cref@vrefrange} are also redefined so
%   that they write substitution rules. Strictly speaking, the starred
%   variants of \cmd{\fullref} and \cmd{\vrefrange} are not defined when
%   \package{hyperref} isn't loaded, so we could avoid checking for them
%   in that case. However, the redundant check does no harm, and avoids
%   some code duplication.
%    \begin{macrocode}
      \let\old@cref@fullref\cref@fullref%
      \def\cref@fullref#1#2{%
        \gdef\cref@poorman@text{}%
        \old@cref@fullref{#1}{#2}%
        \def\@tempa##1##2\@nil{%
          \if##1c%
            \if@crefstarred%
              \cref@writescript{}{\string\fullref*\string{#2\string}}%
            \else%
              \cref@writescript{}{\string\fullref\string{#2\string}}%
            \fi%
          \else%
            \if@crefstarred%
              \cref@writescript{}{\string\Fullref*\string{#2\string}}%
            \else%
              \cref@writescript{}{\string\Fullref\string{#2\string}}%
            \fi%
          \fi}%
        \@tempa#1\@nil}%
%
      \let\old@cref@vrefrange\cref@vrefrange%
      \def\cref@vrefrange#1#2#3{%
        \gdef\cref@poorman@text{}%
        \old@cref@vrefrange{#1}{#2}{#3}%
        \def\@tempa##1##2\@nil{%
          \if##1c%
            \if@crefstarred%
              \cref@writescript{}{%
                \string\vrefrange*\string{#2\string}\string{#3\string}}%
            \else%
              \cref@writescript{}{%
                \string\vrefrange\string{#2\string}\string{#3\string}}%
            \fi%
          \else%
            \if@crefstarred%
              \cref@writescript{}{%
                \string\Vrefrange*\string{#2\string}\string{#3\string}}%
            \else%
              \cref@writescript{}{%
                \string\Vrefrange\string{#2\string}\string{#3\string}}%
            \fi%
          \fi}%
        \@tempa#1\@nil}%
%    \end{macrocode}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\@@@setvpageref}
% \begin{macro}{\@@@setvpagerefrange}
%   In order to get the appropriate substitution for \package{varioref}
%   commands appended to \cmd{\cref@poorman@text}, we have to redefine
%   \cmd{\@@@setvpageref} and\linebreak[4] \cmd{\@@@setvpagerefrange},
%   which perform the final typesetting of \package{varioref} page
%   references, so that they append an appropriate substitution for the
%   page reference they're typesetting.
%    \begin{macrocode}
      \def\@@@setvpageref#1[#2]#3{%
        \cref@old@@vpageref{#1}[#2]{#3}%
        \g@addto@macro\cref@poorman@text{\vpageref{#3}}}%
      \def\@@@setvpagerefrange[#1]#2#3{%
        \vpagerefrange[#1]{#2}{#3}%
        \g@addto@macro\cref@poorman@text{\vpagerefrange{#2}{#3}}}%
      \def\@@@setfullpageref#1{%
        \reftextfaraway{#1}%
        \g@addto@macro\cref@poorman@text{\reftextfaraway{#1}}}%
      \def\@@@setfullpagerefrange#1#2{%
        \reftextpagerange{#1}{#2}%
        \g@addto@macro\cref@poorman@text{\reftextpagerange{#1}{#2}}}%
%    \end{macrocode}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\@setcref@space}
% \begin{macro}{\@setcref@pairconjunction}
% \begin{macro}{\@setcref@middleconjunction}
% \begin{macro}{\@setcref@lastconjunction}
%   Finally, we make sure the conjunctions also get appended to
%   the\linebreak[4] \cmd{\cref@poorman@text} substitution.
%    \begin{macrocode}
      \def\@setcref@space{ % space here is deliberate
        \g@addto@macro\cref@poorman@text{ }}%
      \def\@setcref@pairconjunction{%
        \crefpairconjunction%
        \expandafter\g@addto@macro\expandafter\cref@poorman@text%
          \expandafter{\crefpairconjunction}}%
      \def\@setcref@middleconjunction{%
        \crefmiddleconjunction%
        \expandafter\g@addto@macro\expandafter\cref@poorman@text%
          \expandafter{\crefmiddleconjunction}}%
      \def\@setcref@lastconjunction{%
        \creflastconjunction%
        \expandafter\g@addto@macro\expandafter\cref@poorman@text%
          \expandafter{\creflastconjunction}}%
    }% end of \AtBeginDocument
  }{}% end of \@ifpackageloaded{varioref}
}%  end of poorman option
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
%
%
%
% \subsection{Sort and Compress Options}
% \begin{macro}{sort}
% \begin{macro}{compress}
% \begin{macro}{nosort}
% \begin{macro}{\if@cref@sort}
% \begin{macro}{\if@cref@compress}
%   The \option{sort}, \option{compress} or \option{nosort} options
%   determine whether to sort and/or compress lists of multiple
%   references (default is to do both). They work simply by setting the
%   |\if@cref@sort| and |\if@cref@compress| flags appropriately.
%    \begin{macrocode}
\newif\if@cref@sort%
\newif\if@cref@compress%
%    \end{macrocode}
% Default is to both sort and compress references.
%    \begin{macrocode}
\@cref@sorttrue%
\@cref@compresstrue%
%    \end{macrocode}
% Options override default.
%    \begin{macrocode}
\DeclareOption{sort}{%
  \PackageInfo{cleveref}{sorting but not compressing references}%
  \@cref@sorttrue%
  \@cref@compressfalse}%
\DeclareOption{compress}{%
  \PackageInfo{cleveref}{compressing but not sorting references}%
  \@cref@sortfalse%
  \@cref@compresstrue}%
\DeclareOption{sort&compress}{%
  \PackageInfo{cleveref}{sorting and compressing references}%
  \@cref@sorttrue%
  \@cref@compresstrue}%
\DeclareOption{nosort}{%
  \PackageInfo{cleveref}{neither sorting nor compressing references}%
  \@cref@sortfalse%
  \@cref@compressfalse}%
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
%
%
%
% \subsection{Capitalise Option}
% \begin{macro}{capitalise}
% \begin{macro}{\if@cref@capitalise}
%   The \option{capitalise} option causes \package{cleveref} to always
%   use the |\Cref|* variants for typesetting cross-references, so that
%   cross-reference names are always capitalised.
%    \begin{macrocode}
\newif\if@cref@capitalise%
%    \end{macrocode}
% Disabled by default.
%    \begin{macrocode}
\@cref@capitalisefalse%
%    \end{macrocode}
% Option overrides default.
%    \begin{macrocode}
\DeclareOption{capitalise}{%
  \PackageInfo{cleveref}{always capitalise cross-reference names}%
  \@cref@capitalisetrue}%
\DeclareOption{capitalize}{%
  \PackageInfo{cleveref}{always capitalise cross-reference names}%
  \@cref@capitalisetrue}%
%    \end{macrocode}
% \end{macro}
% \end{macro}
%
%
%
% \subsection{Nameinlink Option}
% \begin{macro}{nameinlink}
% \begin{macro}{\if@cref@nameinlink}
%   The \option{nameinlink} option causes \package{cleveref} to include
%   the cross-reference name as part of the hyperlink target when the
%   \package{hyperref} package is used.
%    \begin{macrocode}
\newif\if@cref@nameinlink%
%    \end{macrocode}
% Disabled by default.
%    \begin{macrocode}
\@cref@nameinlinkfalse%
%    \end{macrocode}
% Option overrides default.
%    \begin{macrocode}
\DeclareOption{nameinlink}{%
  \PackageInfo{cleveref}{include cross-reference names in hyperlinks}%
  \@cref@nameinlinktrue}%
%    \end{macrocode}
% \end{macro}
% \end{macro}
%
%
%
% \subsection{Noabbrev Option}
% \begin{macro}{noabbrev}
% \begin{macro}{\if@cref@abbrev}
%   The \option{noabbrev} option causes \package{cleveref} to always use
%   the full cross-reference names, instead of abbreviating some of the
%   more common names in the middle of sentences.
%    \begin{macrocode}
\newif\if@cref@abbrev%
%    \end{macrocode}
% Enabled by default.
%    \begin{macrocode}
\@cref@abbrevtrue%
%    \end{macrocode}
% Option overrides default.
%    \begin{macrocode}
\DeclareOption{noabbrev}{%
  \PackageInfo{cleveref}{no abbreviation of names}%
  \@cref@abbrevfalse}%
%    \end{macrocode}
% \end{macro}
% \end{macro}
%
%
%
% \subsection{Language and \package{babel} Support}
% \label{sec:code:babel}
% Default reference formats for different languages are supported via
% package options, in the usual way.
%
% Any contributions of translations for missing languages are most
% welcome! If you can contribute definitions for a missing language,
% ideally you should add them below the existing ones (using those as a
% model), generate a patch against the original \package{cleveref.dtx}
% file, and send the patch by email to the package author. However, if
% you don't know how to produce a patch, you can instead just send the
% translations as a plain text file.
%
%
% \begin{macro}{\cref@addto}
%   Utility macro to use instead of \package{babel}'s flawed \cmd{\addto}
%   (copied and modified from \package{varioref}).
%    \begin{macrocode}
\def\cref@addto#1#2{%
  \@temptokena{#2}%
  \ifx#1\undefined%
    \edef#1{\the\@temptokena}%
  \else%
    \toks@\expandafter{#1}%
    \edef#1{\the\toks@\the\@temptokena}%
  \fi%
  \@temptokena{}\toks@\@temptokena}%
\@onlypreamble\cref@addto%
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\cref@addlanguagedefs}
%   Utility macro to add code to \cmd{\extras}\meta{language} or
%   \cmd{\captions}\meta{language}, depending on whether \package{babel}
%   or \package{polyglossia} are loaded.
%    \begin{macrocode}
\long\def\cref@addlanguagedefs#1#2{%
  \@ifpackageloaded{polyglossia}%
    {\AtBeginDocument{%
        \ifcsdef{#1@loaded}{%
          \expandafter\cref@addto\csname captions#1\endcsname{#2}}{}}}%
    {\@ifpackageloaded{babel}{%
      \edef\@curroptions{\@ptionlist{\@currname.\@currext}}%
      \@expandtwoargs\in@{,#1,}{,\@classoptionslist,\@curroptions,}%
      \ifin@%
        \AtBeginDocument{%
          \expandafter\cref@addto\csname extras#1\endcsname{#2}}%
      \fi}{}}}%
%    \end{macrocode}
% \end{macro}
%
%
% Passing a language option to \package{cleveref} defines the
% cross-reference names and conjunctions as appropriate for that
% language. We can't make the definitions straight away, since they would
% prevent the automatic definition of the other capitalisation variant
% from working if the user chooses to change a default definition in the
% preamble, so we postpone them until the beginning of the document.
% However, if each language option were to simply define any formats that
% aren't already defined by the end of the preamble, the \emph{first}
% language option would override all the others. Unfortunately, the
% convention in \LaTeX{} and \package{babel} is for the \emph{last}
% language option to take precedence. So we instead use the
% \cmd{\crefname@preamble} command to save the definitions in
% |\cref@|\meta{type}|@name@preamble| etc., and after all the language
% options have been processed, use the contents of these to set the
% default definitions for any undefined formats.
%
% For \package{babel} support, we add the appropriate redefinitions to
% the\linebreak[4] |\extras|\meta{language} macro, which is called by
% \package{babel}'s \cmd{\selectlanguage} et al.\ commands.  The main
% language (the last one listed in the options) is set up by an automatic
% call to \cmd{\selectlanguage} at the beginning of the document, which
% would clobber any redefinitions made by the user in the preamble. To
% avoid this, we postpone adding the redefinitions to
% |\extras|\meta{language} until the beginning of the document. Since
% \package{cleveref} must always be loaded \emph{after} \package{babel},
% the redefinitions won't be added to |\extras|\meta{language} until
% \emph{after} \package{babel} has already called \cmd{\selectlanguage}
% for the main language. Thus the redefinitions will only be in effect
% when \cmd{\selectlanguage} is called explicitly within the
% document. (The definitions for the main language are taken care of by
% the language options passed to \package{cleveref}, independently of
% \package{babel}.)
%
% Note that we define both capitalisation variants explicitly throughout,
% rather than relying on the automatic definition of the other variant,
% in order to make the code produced by the poor man's |sed| script
% slightly cleaner.
%
%
% \subsubsection{English}
% \begin{macro}{english}
%   English definitions (these are used by default).
% \end{macro}
%
% Set up the definitions used at the beginning of the document to define
% the formats created by the document preamble.
%    \begin{macrocode}
\DeclareOption{english}{%
  \AtBeginDocument{%
    \def\crefrangeconjunction@preamble{ to\nobreakspace}%
    \def\crefrangepreconjunction@preamble{}%
    \def\crefrangepostconjunction@preamble{}%
    \def\crefpairconjunction@preamble{ and\nobreakspace}%
    \def\crefmiddleconjunction@preamble{, }%
    \def\creflastconjunction@preamble{ and\nobreakspace}%
%    \end{macrocode}
% We have to define the group conjunctions explicitly here, rather than
% relying on fall-back definitions in terms of the above conjunctions
% (see \cref{sec:code:default_formats}), in case any other language
% option defines them explicitly and we need to override those.
%    \begin{macrocode}
    \def\crefpairgroupconjunction@preamble{ and\nobreakspace}%
    \def\crefmiddlegroupconjunction@preamble{, }%
    \def\creflastgroupconjunction@preamble{, and\nobreakspace}%
 %
    \Crefname@preamble{equation}{Equation}{Equations}%
    \Crefname@preamble{figure}{Figure}{Figures}%
    \Crefname@preamble{table}{Table}{Tables}%
    \Crefname@preamble{page}{Page}{Pages}%
    \Crefname@preamble{part}{Part}{Parts}%
    \Crefname@preamble{chapter}{Chapter}{Chapters}%
    \Crefname@preamble{section}{Section}{Sections}%
    \Crefname@preamble{appendix}{Appendix}{Appendices}%
    \Crefname@preamble{enumi}{Item}{Items}%
    \Crefname@preamble{footnote}{Footnote}{Footnotes}%
    \Crefname@preamble{theorem}{Theorem}{Theorems}%
    \Crefname@preamble{lemma}{Lemma}{Lemmas}%
    \Crefname@preamble{corollary}{Corollary}{Corollaries}%
    \Crefname@preamble{proposition}{Proposition}{Propositions}%
    \Crefname@preamble{definition}{Definition}{Definitions}%
    \Crefname@preamble{result}{Result}{Results}%
    \Crefname@preamble{example}{Example}{Examples}%
    \Crefname@preamble{remark}{Remark}{Remarks}%
    \Crefname@preamble{note}{Note}{Notes}%
    \Crefname@preamble{algorithm}{Algorithm}{Algorithms}%
    \Crefname@preamble{listing}{Listing}{Listings}%
    \Crefname@preamble{line}{Line}{Lines}%
 %
    \if@cref@capitalise%  capitalise set
      \if@cref@abbrev%
        \crefname@preamble{equation}{Eq.}{Eqs.}%
        \crefname@preamble{figure}{Fig.}{Figs.}%
      \else%
        \crefname@preamble{equation}{Equation}{Equations}%
        \crefname@preamble{figure}{Figure}{Figures}%
      \fi%
      \crefname@preamble{page}{Page}{Pages}%
      \crefname@preamble{table}{Table}{Tables}%
      \crefname@preamble{part}{Part}{Parts}%
      \crefname@preamble{chapter}{Chapter}{Chapters}%
      \crefname@preamble{section}{Section}{Sections}%
      \crefname@preamble{appendix}{Appendix}{Appendices}%
      \crefname@preamble{enumi}{Item}{Items}%
      \crefname@preamble{footnote}{Footnote}{Footnotes}%
      \crefname@preamble{theorem}{Theorem}{Theorems}%
      \crefname@preamble{lemma}{Lemma}{Lemmas}%
      \crefname@preamble{corollary}{Corollary}{Corollaries}%
      \crefname@preamble{proposition}{Proposition}{Propositions}%
      \crefname@preamble{definition}{Definition}{Definitions}%
      \crefname@preamble{result}{Result}{Results}%
      \crefname@preamble{example}{Example}{Examples}%
      \crefname@preamble{remark}{Remark}{Remarks}%
      \crefname@preamble{note}{Note}{Notes}%
      \crefname@preamble{algorithm}{Algorithm}{Algorithms}%
      \crefname@preamble{listing}{Listing}{Listings}%
      \crefname@preamble{line}{Line}{Lines}%
 %
    \else%  capitalise unset
      \if@cref@abbrev%
        \crefname@preamble{equation}{eq.}{eqs.}%
        \crefname@preamble{figure}{fig.}{figs.}%
      \else%
        \crefname@preamble{equation}{equation}{equations}%
        \crefname@preamble{figure}{figure}{figures}%
      \fi%
      \crefname@preamble{page}{page}{pages}%
      \crefname@preamble{table}{table}{tables}%
      \crefname@preamble{part}{part}{parts}%
      \crefname@preamble{chapter}{chapter}{chapters}%
      \crefname@preamble{section}{section}{sections}%
      \crefname@preamble{appendix}{appendix}{appendices}%
      \crefname@preamble{enumi}{item}{items}%
      \crefname@preamble{footnote}{footnote}{footnotes}%
      \crefname@preamble{theorem}{theorem}{theorems}%
      \crefname@preamble{lemma}{lemma}{lemmas}%
      \crefname@preamble{corollary}{corollary}{corollaries}%
      \crefname@preamble{proposition}{proposition}{propositions}%
      \crefname@preamble{definition}{definition}{definitions}%
      \crefname@preamble{result}{result}{results}%
      \crefname@preamble{example}{example}{examples}%
      \crefname@preamble{remark}{remark}{remarks}%
      \crefname@preamble{note}{note}{notes}%
      \crefname@preamble{algorithm}{algorithm}{algorithms}%
      \crefname@preamble{listing}{listing}{listings}%
      \crefname@preamble{line}{line}{lines}%
    \fi%
    \def\cref@language{english}%
  }}% end \AtBeginDocument and \DeclareOption
%    \end{macrocode}
%
% If using \package{babel} and the corresponding option is set, or if
% using \package{polyglossia} and the language has been loaded, add
% format definition commands to \cmd{\extras}\meta{language} or
% \cmd{\captions}\meta{language} so that language switching commands will
% change the cross-reference formats appropriately.
%    \begin{macrocode}
\cref@addlanguagedefs{english}{%
  \PackageInfo{cleveref}{loaded `english' language definitions}%
  \renewcommand{\crefrangeconjunction}{ to\nobreakspace}%
  \renewcommand\crefrangepreconjunction{}%
  \renewcommand\crefrangepostconjunction{}%
  \renewcommand{\crefpairconjunction}{ and\nobreakspace}%
  \renewcommand{\crefmiddleconjunction}{, }%
  \renewcommand{\creflastconjunction}{ and\nobreakspace}%
  \renewcommand{\crefpairgroupconjunction}{ and\nobreakspace}%
  \renewcommand{\crefmiddlegroupconjunction}{, }%
  \renewcommand{\creflastgroupconjunction}{, and\nobreakspace}%
 %
  \Crefname{equation}{Equation}{Equations}%
  \Crefname{figure}{Figure}{Figures}%
  \Crefname{subfigure}{Figure}{Figures}%
  \Crefname{table}{Table}{Tables}%
  \Crefname{subtable}{Table}{Tables}%
  \Crefname{page}{Page}{Pages}%
  \Crefname{part}{Part}{Parts}%
  \Crefname{chapter}{Chapter}{Chapters}%
  \Crefname{section}{Section}{Sections}%
  \Crefname{subsection}{Section}{Sections}%
  \Crefname{subsubsection}{Section}{Sections}%
  \Crefname{appendix}{Appendix}{Appendices}%
  \Crefname{subappendix}{Appendix}{Appendices}%
  \Crefname{subsubappendix}{Appendix}{Appendices}%
  \Crefname{subsubsubappendix}{Appendix}{Appendices}%
  \Crefname{enumi}{Item}{Items}%
  \Crefname{enumii}{Item}{Items}%
  \Crefname{enumiii}{Item}{Items}%
  \Crefname{enumiv}{Item}{Items}%
  \Crefname{enumv}{Item}{Items}%
  \Crefname{footnote}{Footnote}{Footnotes}%
  \Crefname{theorem}{Theorem}{Theorems}%
  \Crefname{lemma}{Lemma}{Lemmas}%
  \Crefname{corollary}{Corollary}{Corollaries}%
  \Crefname{proposition}{Proposition}{Propositions}%
  \Crefname{definition}{Definition}{Definitions}%
  \Crefname{result}{Result}{Results}%
  \Crefname{example}{Example}{Examples}%
  \Crefname{remark}{Remark}{Remarks}%
  \Crefname{note}{Note}{Notes}%
  \Crefname{algorithm}{Algorithm}{Algorithms}%
  \Crefname{listing}{Listing}{Listings}%
  \Crefname{line}{Line}{Lines}%
 %
  \if@cref@capitalise%  capitalise set
    \if@cref@abbrev%
      \crefname{equation}{Eq.}{Eqs.}%
      \crefname{figure}{Fig.}{Figs.}%
      \crefname{subfigure}{Fig.}{Figs.}%
    \else%
      \crefname{equation}{Equation}{Equations}%
      \crefname{figure}{Figure}{Figures}%
      \crefname{subfigure}{Figure}{Figures}%
    \fi%
    \crefname{page}{Page}{Pages}%
    \crefname{table}{Table}{Tables}%
    \crefname{subtable}{Table}{Tables}%
    \crefname{part}{Part}{Parts}%
    \crefname{chapter}{Chapter}{Chapters}%
    \crefname{section}{Section}{Sections}%
    \crefname{subsection}{Section}{Sections}%
    \crefname{subsubsection}{Section}{Sections}%
    \crefname{appendix}{Appendix}{Appendices}%
    \crefname{subappendix}{Appendix}{Appendices}%
    \crefname{subsubappendix}{Appendix}{Appendices}%
    \crefname{subsubsubappendix}{Appendix}{Appendices}%
    \crefname{enumi}{Item}{Items}%
    \crefname{enumii}{Item}{Items}%
    \crefname{enumiii}{Item}{Items}%
    \crefname{enumiv}{Item}{Items}%
    \crefname{enumv}{Item}{Items}%
    \crefname{footnote}{Footnote}{Footnotes}%
    \crefname{theorem}{Theorem}{Theorems}%
    \crefname{lemma}{Lemma}{Lemmas}%
    \crefname{corollary}{Corollary}{Corollaries}%
    \crefname{proposition}{Proposition}{Propositions}%
    \crefname{definition}{Definition}{Definitions}%
    \crefname{result}{Result}{Results}%
    \crefname{example}{Example}{Examples}%
    \crefname{remark}{Remark}{Remarks}%
    \crefname{note}{Note}{Notes}%
    \crefname{algorithm}{Algorithm}{Algorithms}%
    \crefname{listing}{Listing}{Listings}%
    \crefname{line}{Line}{Lines}%
 %
  \else%  capitalise unset
    \if@cref@abbrev%
      \crefname{equation}{eq.}{eqs.}%
      \crefname{figure}{fig.}{figs.}%
      \crefname{subfigure}{fig.}{figs.}%
    \else%
      \crefname{equation}{equation}{equations}%
      \crefname{figure}{figure}{figures}%
      \crefname{subfigure}{figure}{figures}%
    \fi%
    \crefname{table}{table}{tables}%
    \crefname{subtable}{table}{tables}%
    \crefname{page}{page}{pages}%
    \crefname{part}{part}{parts}%
    \crefname{chapter}{chapter}{chapters}%
    \crefname{section}{section}{sections}%
    \crefname{subsection}{section}{sections}%
    \crefname{subsubsection}{section}{sections}%
    \crefname{appendix}{appendix}{appendices}%
    \crefname{subappendix}{appendix}{appendices}%
    \crefname{subsubappendix}{appendix}{appendices}%
    \crefname{subsubsubappendix}{appendix}{appendices}%
    \crefname{enumi}{item}{items}%
    \crefname{enumii}{item}{items}%
    \crefname{enumiii}{item}{items}%
    \crefname{enumiv}{item}{items}%
    \crefname{enumv}{item}{items}%
    \crefname{footnote}{footnote}{footnotes}%
    \crefname{theorem}{theorem}{theorems}%
    \crefname{lemma}{lemma}{lemmas}%
    \crefname{corollary}{corollary}{corollaries}%
    \crefname{proposition}{proposition}{propositions}%
    \crefname{definition}{definition}{definitions}%
    \crefname{result}{result}{results}%
    \crefname{example}{example}{examples}%
    \crefname{remark}{remark}{remarks}%
    \crefname{note}{note}{notes}%
    \crefname{algorithm}{algorithm}{algorithms}%
    \crefname{listing}{listing}{listings}%
    \crefname{line}{line}{lines}%
  \fi}% end \cref@addlangagedefs
%    \end{macrocode}
%
%
%  \subsubsection{German}
% \begin{macro}{german}
%   German translations kindly provided by Stefan Pinnow, abbreviations
%   by Natanael Arndt, and a few additions by the package author (so you
%   know to blame the latter for any errors!).
% \end{macro}
%
% Set up the definitions used at the beginning of the document to define
% the formats created by the document preamble.
%    \begin{macrocode}
\DeclareOption{german}{%
  \AtBeginDocument{%
    \def\crefrangeconjunction@preamble{ bis\nobreakspace}%
    \def\crefrangepreconjunction@preamble{}%
    \def\crefrangepostconjunction@preamble{}%
    \def\crefpairconjunction@preamble{ und\nobreakspace}%
    \def\crefmiddleconjunction@preamble{, }%
    \def\creflastconjunction@preamble{ und\nobreakspace}%
%    \end{macrocode}
% We don't want the extra comma before ``und'' that would be added by the
% default fall-back definitions in terms of the above conjunctions, so we
% define \cmd{\crefpairgroupconjunction} explicitly. In fact, we have to
% define the other group conjunctions explicitly too here, in case any
% other language option defines them explicitly and we need to override
% them.
%    \begin{macrocode}
    \def\crefpairgroupconjunction@preamble{ und\nobreakspace}%
    \def\crefmiddlegroupconjunction@preamble{, }%
    \def\creflastgroupconjunction@preamble{ und\nobreakspace}%
 %
    \Crefname@preamble{equation}{Gleichung}{Gleichungen}%
    \Crefname@preamble{figure}{Abbildung}{Abbildungen}%
    \Crefname@preamble{table}{Tabelle}{Tabellen}%
    \Crefname@preamble{page}{Seite}{Seiten}%
    \Crefname@preamble{part}{Teil}{Teile}%
    \Crefname@preamble{chapter}{Kapitel}{Kapitel}%
    \Crefname@preamble{section}{Abschnitt}{Abschnitte}%
    \Crefname@preamble{appendix}{Anhang}{Anh\"ange}%
    \Crefname@preamble{enumi}{Punkt}{Punkte}%
    \Crefname@preamble{footnote}{Fu\ss note}{Fu\ss noten}%
    \Crefname@preamble{theorem}{Theorem}{Theoreme}%
    \Crefname@preamble{lemma}{Lemma}{Lemmata}%
    \Crefname@preamble{corollary}{Korollar}{Korollare}%
    \Crefname@preamble{proposition}{Satz}{S\"atze}%
    \Crefname@preamble{definition}{Definition}{Definitionen}%
    \Crefname@preamble{result}{Ergebnis}{Ergebnisse}%
    \Crefname@preamble{example}{Beispiel}{Beispiele}%
    \Crefname@preamble{remark}{Bemerkung}{Bemerkungen}%
    \Crefname@preamble{note}{Anmerkung}{Anmerkungen}%
    \Crefname@preamble{algorithm}{Algorithmus}{Algorithmen}%
    \Crefname@preamble{listing}{Listing}{Listings}%
    \Crefname@preamble{line}{Zeile}{Zeilen}%
 %
    \if@cref@abbrev%
      \crefname@preamble{figure}{Abb.}{Abb.}%
    \else%
      \crefname@preamble{figure}{Abbildung}{Abbildungen}%
    \fi%
    \crefname@preamble{equation}{Gleichung}{Gleichungen}%
    \crefname@preamble{table}{Tabelle}{Tabellen}%
    \crefname@preamble{page}{Seite}{Seiten}%
    \crefname@preamble{part}{Teil}{Teile}%
    \crefname@preamble{chapter}{Kapitel}{Kapitel}%
    \crefname@preamble{section}{Abschnitt}{Abschnitte}%
    \crefname@preamble{appendix}{Anhang}{Anh\"ange}%
    \crefname@preamble{enumi}{Punkt}{Punkte}%
    \crefname@preamble{footnote}{Fu\ss note}{Fu\ss noten}%
    \crefname@preamble{theorem}{Theorem}{Theoreme}%
    \crefname@preamble{lemma}{Lemma}{Lemmata}%
    \crefname@preamble{corollary}{Korollar}{Korollare}%
    \crefname@preamble{proposition}{Satz}{S\"atze}%
    \crefname@preamble{definition}{Definition}{Definitionen}%
    \crefname@preamble{result}{Ergebnis}{Ergebnisse}%
    \crefname@preamble{example}{Beispiel}{Beispiele}%
    \crefname@preamble{remark}{Bemerkung}{Bemerkungen}%
    \crefname@preamble{note}{Anmerkung}{Anmerkungen}%
    \crefname@preamble{algorithm}{Algorithmus}{Algorithmen}%
    \crefname@preamble{listing}{Listing}{Listings}%
    \crefname@preamble{line}{Zeile}{Zeilen}%
    \def\cref@language{german}%
  }}% end \AtBeginDocument and \DeclareOption
%    \end{macrocode}
%
% If using \package{babel} and the corresponding option is set, or if
% using \package{polyglossia} and the language has been loaded, add
% format definition commands to \cmd{\extras}\meta{language} or
% \cmd{\captions}\meta{language} so that language switching commands will
% change the cross-reference formats appropriately.
%    \begin{macrocode}
\cref@addlanguagedefs{german}{%
  \PackageInfo{cleveref}{loaded `german language definitions}%
  \renewcommand{\crefrangeconjunction}{ bis\nobreakspace}%
  \renewcommand\crefrangepreconjunction{}%
  \renewcommand\crefrangepostconjunction{}%
  \renewcommand{\crefpairconjunction}{ und\nobreakspace}%
  \renewcommand{\crefmiddleconjunction}{, }%
  \renewcommand{\creflastconjunction}{ und\nobreakspace}%
  \renewcommand{\crefpairgroupconjunction}{ und\nobreakspace}%
  \renewcommand{\crefmiddlegroupconjunction}{, }%
  \renewcommand{\creflastgroupconjunction}{ und\nobreakspace}%
 %
  \Crefname{equation}{Gleichung}{Gleichungen}%
  \Crefname{figure}{Abbildung}{Abbildungen}%
  \Crefname{subfigure}{Abbildung}{Abbildungen}%
  \Crefname{table}{Tabelle}{Tabellen}%
  \Crefname{subtable}{Tabelle}{Tabellen}%
  \Crefname{page}{Seite}{Seiten}%
  \Crefname{part}{Teil}{Teile}%
  \Crefname{chapter}{Kapitel}{Kapitel}%
  \Crefname{section}{Abschnitt}{Abschnitte}%
  \Crefname{subsection}{Abschnitt}{Abschnitte}%
  \Crefname{subsubsection}{Abschnitt}{Abschnitte}%
  \Crefname{appendix}{Anhang}{Anh\"ange}%
  \Crefname{subappendix}{Anhang}{Anh\"ange}%
  \Crefname{subsubappendix}{Anhang}{Anh\"ange}%
  \Crefname{subsubsubappendix}{Anhang}{Anh\"ange}%
  \Crefname{enumi}{Punkt}{Punkte}%
  \Crefname{enumii}{Punkt}{Punkte}%
  \Crefname{enumiii}{Punkt}{Punkte}%
  \Crefname{enumiv}{Punkt}{Punkte}%
  \Crefname{enumv}{Punkt}{Punkte}%
  \Crefname{footnote}{Fu\ss note}{Fu\ss noten}%
  \Crefname{theorem}{Theorem}{Theoreme}%
  \Crefname{lemma}{Lemma}{Lemmata}%
  \Crefname{corollary}{Korollar}{Korollare}%
  \Crefname{proposition}{Satz}{S\"atze}%
  \Crefname{definition}{Definition}{Definitionen}%
  \Crefname{result}{Ergebnis}{Ergebnisse}%
  \Crefname{example}{Beispiel}{Beispiele}%
  \Crefname{remark}{Bemerkung}{Bemerkungen}%
  \Crefname{note}{Anmerkung}{Anmerkungen}%
  \Crefname{algorithm}{Algorithmus}{Algorithmen}%
  \Crefname{listing}{Listing}{Listings}%
  \Crefname{line}{Zeile}{Zeilen}%
 %
  \if@cref@abbrev%
    \crefname{figure}{Abb.}{Abb.}%
    \crefname{subfigure}{Abb.}{Abb.}%
  \else%
    \crefname{figure}{Abbildung}{Abbildungen}%
    \crefname{subfigure}{Abbildung}{Abbildungen}%
  \fi%
  \crefname{equation}{Gleichung}{Gleichungen}%
  \crefname{table}{Tabelle}{Tabellen}%
  \crefname{subtable}{Tabelle}{Tabellen}%
  \crefname{page}{Seite}{Seiten}%
  \crefname{part}{Teil}{Teile}%
  \crefname{chapter}{Kapitel}{Kapitel}%
  \crefname{section}{Abschnitt}{Abschnitte}%
  \crefname{subsection}{Abschnitt}{Abschnitte}%
  \crefname{subsubsection}{Abschnitt}{Abschnitte}%
  \crefname{appendix}{Anhang}{Anh\"ange}%
  \crefname{subappendix}{Anhang}{Anh\"ange}%
  \crefname{subsubappendix}{Anhang}{Anh\"ange}%
  \crefname{subsubsubappendix}{Anhang}{Anh\"ange}%
  \crefname{enumi}{Punkt}{Punkte}%
  \crefname{enumii}{Punkt}{Punkte}%
  \crefname{enumiii}{Punkt}{Punkte}%
  \crefname{enumiv}{Punkt}{Punkte}%
  \crefname{enumv}{Punkt}{Punkte}%
  \crefname{footnote}{Fu\ss note}{Fu\ss noten}%
  \crefname{theorem}{Theorem}{Theoreme}%
  \crefname{lemma}{Lemma}{Lemmata}%
  \crefname{corollary}{Korollar}{Korollare}%
  \crefname{proposition}{Satz}{S\"atze}%
  \crefname{definition}{Definition}{Definitionen}%
  \crefname{result}{Ergebnis}{Ergebnisse}%
  \crefname{example}{Beispiel}{Beispiele}%
  \crefname{remark}{Bemerkung}{Bemerkungen}%
  \crefname{note}{Anmerkung}{Anmerkungen}%
  \crefname{algorithm}{Algorithmus}{Algorithmen}%
  \crefname{listing}{Listing}{Listings}%
  \crefname{line}{Zeile}{Zeilen}}% end \cref@addlangagedefs
%    \end{macrocode}
%
%
% \begin{macro}{ngerman}
%   It so happens that none of the cross-reference names differ in the
%   ``Neuerechtschreibung'', so we make \option{ngerman} execute
%   \option{german}.
% \end{macro}
%    \begin{macrocode}
\DeclareOption{ngerman}{%
  \ExecuteOptions{german}%
  \def\cref@language{ngerman}}%
%    \end{macrocode}
% However, we still need to add the definitions to \cmd{\extrasngerman}
% (note the ``n'') so that \cmd{\selectlanguage} etc.\ will work.
%    \begin{macrocode}
\cref@addlanguagedefs{ngerman}{%
  \PackageInfo{cleveref}{loaded `ngerman' language definitions}%
  \renewcommand{\crefrangeconjunction}{ bis\nobreakspace}%
  \renewcommand\crefrangepreconjunction{}%
  \renewcommand\crefrangepostconjunction{}%
  \renewcommand{\crefpairconjunction}{ und\nobreakspace}%
  \renewcommand{\crefmiddleconjunction}{, }%
  \renewcommand{\creflastconjunction}{ und\nobreakspace}%
  \renewcommand{\crefpairgroupconjunction}{ und\nobreakspace}%
  \renewcommand{\crefmiddlegroupconjunction}{, }%
  \renewcommand{\creflastgroupconjunction}{ und\nobreakspace}%
 %
  \Crefname{equation}{Gleichung}{Gleichungen}%
  \Crefname{figure}{Abbildung}{Abbildungen}%
  \Crefname{subfigure}{Abbildung}{Abbildungen}%
  \Crefname{table}{Tabelle}{Tabellen}%
  \Crefname{subtable}{Tabelle}{Tabellen}%
  \Crefname{page}{Seite}{Seiten}%
  \Crefname{part}{Teil}{Teile}%
  \Crefname{chapter}{Kapitel}{Kapitel}%
  \Crefname{section}{Abschnitt}{Abschnitte}%
  \Crefname{subsection}{Abschnitt}{Abschnitte}%
  \Crefname{subsubsection}{Abschnitt}{Abschnitte}%
  \Crefname{appendix}{Anhang}{Anh\"ange}%
  \Crefname{subappendix}{Anhang}{Anh\"ange}%
  \Crefname{subsubappendix}{Anhang}{Anh\"ange}%
  \Crefname{subsubsubappendix}{Anhang}{Anh\"ange}%
  \Crefname{enumi}{Punkt}{Punkte}%
  \Crefname{enumii}{Punkt}{Punkte}%
  \Crefname{enumiii}{Punkt}{Punkte}%
  \Crefname{enumiv}{Punkt}{Punkte}%
  \Crefname{enumv}{Punkt}{Punkte}%
  \Crefname{footnote}{Fu\ss note}{Fu\ss noten}%
  \Crefname{theorem}{Theorem}{Theoreme}%
  \Crefname{lemma}{Lemma}{Lemmata}%
  \Crefname{corollary}{Korollar}{Korollare}%
  \Crefname{proposition}{Satz}{S\"atze}%
  \Crefname{definition}{Definition}{Definitionen}%
  \Crefname{result}{Ergebnis}{Ergebnisse}%
  \Crefname{example}{Beispiel}{Beispiele}%
  \Crefname{remark}{Bemerkung}{Bemerkungen}%
  \Crefname{note}{Anmerkung}{Anmerkungen}%
  \Crefname{algorithm}{Algorithmus}{Algorithmen}%
  \Crefname{listing}{Listing}{Listings}%
  \Crefname{line}{Zeile}{Zeilen}%
 %
  \if@cref@abbrev%
    \crefname{figure}{Abb.}{Abb.}%
    \crefname{subfigure}{Abb.}{Abb.}%
  \else%
    \crefname{figure}{Abbildung}{Abbildungen}%
    \crefname{subfigure}{Abbildung}{Abbildungen}%
  \fi%
  \crefname{equation}{Gleichung}{Gleichungen}%
  \crefname{table}{Tabelle}{Tabellen}%
  \crefname{subtable}{Tabelle}{Tabellen}%
  \crefname{page}{Seite}{Seiten}%
  \crefname{part}{Teil}{Teile}%
  \crefname{chapter}{Kapitel}{Kapitel}%
  \crefname{section}{Abschnitt}{Abschnitte}%
  \crefname{subsection}{Abschnitt}{Abschnitte}%
  \crefname{subsubsection}{Abschnitt}{Abschnitte}%
  \crefname{appendix}{Anhang}{Anh\"ange}%
  \crefname{subappendix}{Anhang}{Anh\"ange}%
  \crefname{subsubappendix}{Anhang}{Anh\"ange}%
  \crefname{subsubsubappendix}{Anhang}{Anh\"ange}%
  \crefname{enumi}{Punkt}{Punkte}%
  \crefname{enumii}{Punkt}{Punkte}%
  \crefname{enumiii}{Punkt}{Punkte}%
  \crefname{enumiv}{Punkt}{Punkte}%
  \crefname{enumv}{Punkt}{Punkte}%
  \crefname{footnote}{Fu\ss note}{Fu\ss noten}%
  \crefname{theorem}{Theorem}{Theoreme}%
  \crefname{lemma}{Lemma}{Lemmata}%
  \crefname{corollary}{Korollar}{Korollare}%
  \crefname{proposition}{Satz}{S\"atze}%
  \crefname{definition}{Definition}{Definitionen}%
  \crefname{result}{Ergebnis}{Ergebnisse}%
  \crefname{example}{Beispiel}{Beispiele}%
  \crefname{remark}{Bemerkung}{Bemerkungen}%
  \crefname{note}{Anmerkung}{Anmerkungen}%
  \crefname{algorithm}{Algorithmus}{Algorithmen}%
  \crefname{listing}{Listing}{Listings}%
  \crefname{line}{Zeile}{Zeilen}}% end \cref@addlangagedefs
%    \end{macrocode}
%
%
%  \subsubsection{Dutch}
% \begin{macro}{dutch}
%   Dutch translations kindly contributed by Philip H\"olzenspies and Tom Marcoen.
% \end{macro}
%
% Set up the definitions used at the beginning of the document to define
% the formats created by the document preamble.
%    \begin{macrocode}
\DeclareOption{dutch}{%
  \AtBeginDocument{%
    \def\crefrangeconjunction@preamble{ tot\nobreakspace}%
    \def\crefrangepreconjunction@preamble{}%
    \def\crefrangepostconjunction@preamble{}%
    \def\crefpairconjunction@preamble{ en\nobreakspace}%
    \def\crefmiddleconjunction@preamble{, }%
    \def\creflastconjunction@preamble{ en\nobreakspace}%
%    \end{macrocode}
% As in German, we don't want the extra comma before ``en'' that would be
% added by the default fall-back definitions in terms of the above
% conjunctions, so we define \cmd{\crefpairgroupconjunction} explicitly.
% In fact, we have to define the other group conjunctions explicitly too
% here, in case any other language option defines them explicitly and we
% need to override them.
%    \begin{macrocode}
    \def\crefpairgroupconjunction@preamble{ en\nobreakspace}%
    \def\crefmiddlegroupconjunction@preamble{, }%
    \def\creflastgroupconjunction@preamble{ en\nobreakspace}%
 %
    \Crefname@preamble{equation}{Vergel\ij{}king}{Vergel\ij{}kingen}%
    \Crefname@preamble{figure}{Figuur}{Figuren}%
    \Crefname@preamble{table}{Tabel}{Tabellen}%
    \Crefname@preamble{page}{Pagina}{Pagina's}%
    \Crefname@preamble{part}{Deel}{Delen}%
    \Crefname@preamble{chapter}{Hoofdstuk}{Hoofdstukken}%
    \Crefname@preamble{section}{Paragraaf}{Paragrafen}%
    \Crefname@preamble{appendix}{Appendix}{Appendices}%
    \Crefname@preamble{enumi}{Punt}{Punten}%
    \Crefname@preamble{footnote}{Voetnoot}{Voetnoten}%
    \Crefname@preamble{lemma}{Lemma}{Lemma's}%
    \Crefname@preamble{corollary}{Corollarium}{Corollaria}%
    \Crefname@preamble{proposition}{Bewering}{Beweringen}%
    \Crefname@preamble{definition}{Definitie}{Definities}%
    \Crefname@preamble{result}{Resultaat}{Resultaten}%
    \Crefname@preamble{example}{Voorbeeld}{Voorbeelden}%
    \Crefname@preamble{remark}{Opmerking}{Opmerkingen}%
    \Crefname@preamble{note}{Aantekening}{Aantekeningen}%
    \Crefname@preamble{algorithm}{Algoritme}{Algoritmen}%
    \Crefname@preamble{listing}{Listing}{Listings}%
    \Crefname@preamble{line}{Lijn}{Lijnen}%
 %
    \if@cref@capitalise%  capitalise set
      \if@cref@abbrev%
        \crefname@preamble{equation}{Verg.}{Verg.'s}%
        \crefname@preamble{figure}{Fig.}{Fig.'s}%
      \else%
        \crefname@preamble{equation}{Vergel\ij{}king}{Vergel\ij{}kingen}%
        \crefname@preamble{figure}{Figuur}{Figuren}%
      \fi%
      \crefname@preamble{page}{Pagina}{Pagina's}%
      \crefname@preamble{table}{Tabel}{Tabellen}%
      \crefname@preamble{part}{Deel}{Delen}%
      \crefname@preamble{chapter}{Hoofdstuk}{Hoofdstukken}%
      \crefname@preamble{section}{Paragraaf}{Paragrafen}%
      \crefname@preamble{appendix}{Appendix}{Appendices}%
      \crefname@preamble{enumi}{Punt}{Punten}%
      \crefname@preamble{footnote}{Voetnoot}{Voetnoten}%
      \crefname@preamble{theorem}{Theorema}{Theorema's}%
      \crefname@preamble{lemma}{Lemma}{Lemma's}%
      \crefname@preamble{corollary}{Corollarium}{Corollaria}%
      \crefname@preamble{proposition}{Bewering}{Beweringen}%
      \crefname@preamble{definition}{Definitie}{Definities}%
      \crefname@preamble{result}{Resultaat}{Resultaten}%
      \crefname@preamble{example}{Voorbeeld}{Voorbeelden}%
      \crefname@preamble{remark}{Opmerking}{Opmerkingen}%
      \crefname@preamble{note}{Aantekening}{Aantekeningen}%
      \crefname@preamble{algorithm}{Algoritme}{Algoritmen}%
      \crefname@preamble{listing}{Listing}{Listings}%
      \crefname@preamble{line}{Lijn}{Lijnen}%
 %
    \else%  capitalise unset
      \if@cref@abbrev%
        \crefname@preamble{equation}{verg.}{verg.'s}%
        \crefname@preamble{figure}{fig.}{fig.'s}%
      \else%
        \crefname@preamble{equation}{vergel\ij{}king}{vergel\ij{}kingen}%
        \crefname@preamble{figure}{figuur}{figuren}%
      \fi%
      \crefname@preamble{page}{pagina}{pagina's}%
      \crefname@preamble{table}{tabel}{tabellen}%
      \crefname@preamble{part}{deel}{delen}%
      \crefname@preamble{chapter}{hoofdstuk}{hoofdstukken}%
      \crefname@preamble{section}{paragraaf}{paragrafen}%
      \crefname@preamble{appendix}{appendix}{appendices}%
      \crefname@preamble{enumi}{punt}{punten}%
      \crefname@preamble{footnote}{voetnoot}{voetnoten}%
      \crefname@preamble{theorem}{theorema}{theorema's}%
      \crefname@preamble{lemma}{lemma}{lemma's}%
      \crefname@preamble{corollary}{corollarium}{corollaria}%
      \crefname@preamble{proposition}{bewering}{beweringen}%
      \crefname@preamble{definition}{definitie}{definities}%
      \crefname@preamble{result}{resultaat}{resultaten}%
      \crefname@preamble{example}{voorbeeld}{voorbeelden}%
      \crefname@preamble{remark}{opmerking}{opmerkingen}%
      \crefname@preamble{note}{aantekening}{aantekeningen}%
      \crefname@preamble{algorithm}{algoritme}{algoritmen}%
      \crefname@preamble{listing}{listing}{listings}%
      \crefname@preamble{line}{lijn}{lijnen}%
    \fi%
    \def\cref@language{dutch}%
  }}% end \DeclareOption and \AtBeginDocument
%    \end{macrocode}
%
% If using \package{babel} and the corresponding option is set, or if
% using \package{polyglossia} and the language has been loaded, add
% format definition commands to \cmd{\extras}\meta{language} or
% \cmd{\captions}\meta{language} so that language switching commands will
% change the cross-reference formats appropriately.
%    \begin{macrocode}
\cref@addlanguagedefs{dutch}{%
  \PackageInfo{cleveref}{loaded `dutch' language definitions}%
  \renewcommand{\crefrangeconjunction}{ tot\nobreakspace}%
  \renewcommand\crefrangepreconjunction{}%
  \renewcommand\crefrangepostconjunction{}%
  \renewcommand{\crefpairconjunction}{ en\nobreakspace}%
  \renewcommand{\crefmiddleconjunction}{, }%
  \renewcommand{\creflastconjunction}{ en\nobreakspace}%
  \renewcommand{\crefpairgroupconjunction}{ en\nobreakspace}%
  \renewcommand{\crefmiddlegroupconjunction}{, }%
  \renewcommand{\creflastgroupconjunction}{ en\nobreakspace}%
 %
  \Crefname{equation}{Vergel\ij{}king}{Vergel\ij{}kingen}%
  \Crefname{figure}{Figuur}{Figuren}%
  \Crefname{subfigure}{Figuur}{Figuren}%
  \Crefname{table}{Tabel}{Tabellen}%
  \Crefname{subtable}{Tabel}{Tabellen}%
  \Crefname{page}{Pagina}{Pagina's}%
  \Crefname{part}{Deel}{Delen}%
  \Crefname{chapter}{Hoofdstuk}{Hoofdstuken}%
  \Crefname{section}{Paragraaf}{Paragrafen}%
  \Crefname{subsection}{Paragraaf}{Paragrafen}%
  \Crefname{subsubsection}{Paragraaf}{Paragrafen}%
  \Crefname{appendix}{Appendix}{Appendices}%
  \Crefname{subappendix}{Appendix}{Appendices}%
  \Crefname{subsubappendix}{Appendix}{Appendices}%
  \Crefname{subsubsubappendix}{Appendix}{Appendices}%
  \Crefname{enumi}{Punt}{Punten}%
  \Crefname{enumii}{Punt}{Punten}%
  \Crefname{enumiii}{Punt}{Punten}%
  \Crefname{enumiv}{Punt}{Punten}%
  \Crefname{enumv}{Punt}{Punten}%
  \Crefname{footnote}{Voetnote}{Voetnoten}%
  \Crefname{theorem}{Theorema}{Theorema's}%
  \Crefname{lemma}{Lemma}{Lemma's}%
  \Crefname{corollary}{Corollarium}{Corollaria}%
  \Crefname{proposition}{Bewering}{Beweringen}%
  \Crefname{definition}{Definitie}{Definities}%
  \Crefname{result}{Resultaat}{Resultaten}%
  \Crefname{example}{Voorbeeld}{Voorbeelden}%
  \Crefname{remark}{Opmerking}{Opmerkingen}%
  \Crefname{note}{Aantekening}{Aantekeningen}%
  \Crefname{algorithm}{Algoritme}{Algoritmen}%
  \Crefname{listing}{Listing}{Listings}%
  \Crefname{line}{Lijn}{Lijnen}%
 %
  \if@cref@capitalise%  capitalise set
    \if@cref@abbrev%
      \crefname{equation}{Verg.}{Verg's.}%
      \crefname{figure}{Fig.}{Fig's.}%
      \crefname{subfigure}{Fig.}{Fig's.}%
    \else%
      \crefname{equation}{Vergel\ij{}king}{Vergel\ij{}kingen}%
      \crefname{figure}{Figuur}{Figuren}%
      \crefname{subfigure}{Figuur}{Figuren}%
    \fi%
    \crefname{table}{Tabel}{Tabellen}%
    \crefname{subtable}{Tabel}{Tabellen}%
    \crefname{page}{Pagina}{Pagina's}%
    \crefname{part}{Deel}{Delen}%
    \crefname{chapter}{Hoofdstuk}{Hoofdstukken}%
    \crefname{section}{Paragraaf}{Paragrafen}%
    \crefname{appendix}{Appendix}{Appendices}%
    \crefname{enumi}{Punt}{Punten}%
    \crefname{footnote}{Voetnote}{Voetnoten}%
    \crefname{theorem}{Theorema}{Theorema's}%
    \crefname{lemma}{Lemma}{Lemma's}%
    \crefname{corollary}{Corollarium}{Corollaria}%
    \crefname{proposition}{Bewering}{Beweringen}%
    \crefname{definition}{Definitie}{Definities}%
    \crefname{result}{Resultaat}{Resultaten}%
    \crefname{example}{Voorbeeld}{Voorbeelden}%
    \crefname{remark}{Opmerking}{Opmerkingen}%
    \crefname{note}{Aantekening}{Aantekeningen}%
    \crefname{algorithm}{Algoritme}{Algoritmen}%
    \crefname{listing}{Listing}{Listings}%
    \crefname{line}{Lijn}{Lijnen}%
 %
  \else%  capitalise unset
    \if@cref@abbrev%
      \crefname{equation}{verg.}{verg's.}%
      \crefname{figure}{fig.}{fig's.}%
      \crefname{subfigure}{fig.}{fig's.}%
    \else%
      \crefname{equation}{vergel\ij{}king}{vergel\ij{}kingen}%
      \crefname{figure}{figuur}{figuren}%
      \crefname{subfigure}{figuur}{figuren}%
    \fi%
    \crefname{table}{tabel}{tabellen}%
    \crefname{subtable}{tabel}{tabellen}%
    \crefname{page}{pagina}{pagina's}%
    \crefname{part}{deel}{delen}%
    \crefname{chapter}{hoofdstuk}{hoofdstukken}%
    \crefname{section}{paragraaf}{paragrafen}%
    \crefname{appendix}{appendix}{appendices}%
    \crefname{enumi}{punt}{punten}%
    \crefname{footnote}{voetnote}{voetnoten}%
    \crefname{theorem}{theorema}{theorema's}%
    \crefname{lemma}{lemma}{lemma's}%
    \crefname{corollary}{corollarium}{corollaria}%
    \crefname{proposition}{bewering}{beweringen}%
    \crefname{definition}{definitie}{definities}%
    \crefname{result}{resultaat}{resultaten}%
    \crefname{example}{voorbeeld}{voorbeelden}%
    \crefname{remark}{opmerking}{opmerkingen}%
    \crefname{note}{aantekening}{aantekeningen}%
    \crefname{algorithm}{algoritme}{algoritmen}%
    \crefname{listing}{listing}{listings}%
    \crefname{line}{lijn}{lijnen}%
  \fi}% end \cref@addlanguagedefs
%    \end{macrocode}
%
%
%  \subsubsection{French}
% \begin{macro}{french}
%   French translations attempted by the package author (please report
%   any corrections that might be needed!).
% \end{macro}
%
% Set up the definitions used at the beginning of the document to define
% the formats created by the document preamble.
%    \begin{macrocode}
\DeclareOption{french}{%
  \AtBeginDocument{%
    \def\crefrangeconjunction@preamble{ \`a\nobreakspace}%
    \def\crefrangepreconjunction@preamble{}%
    \def\crefrangepostconjunction@preamble{}%
    \def\crefpairconjunction@preamble{ et\nobreakspace}%
    \def\crefmiddleconjunction@preamble{, }%
    \def\creflastconjunction@preamble{ et\nobreakspace}%
%    \end{macrocode}
% Erring on the side of caution, I've left off the extra comma before
% ``et'' between groups, pending more knowledgeable input on punctuation
% rules from a native French speaker.
%    \begin{macrocode}
    \def\crefpairgroupconjunction@preamble{ et\nobreakspace}%
    \def\crefmiddlegroupconjunction@preamble{, }%
    \def\creflastgroupconjunction@preamble{, et\nobreakspace}%
 %
    \Crefname@preamble{equation}{{\'E}quation}{{\'E}quations}%
    \Crefname@preamble{figure}{Figure}{Figures}%
    \Crefname@preamble{table}{Tableau}{Tableaux}%
    \Crefname@preamble{page}{Page}{Pages}%
    \Crefname@preamble{part}{Partie}{Parties}%
    \Crefname@preamble{chapter}{Chapitre}{Chapitres}%
    \Crefname@preamble{section}{Section}{Sections}%
    \Crefname@preamble{appendix}{Annexe}{Annexes}%
    \Crefname@preamble{enumi}{Point}{Points}%
    \Crefname@preamble{footnote}{Note}{Notes}%
    \Crefname@preamble{theorem}{Th\'eor\`eme}{Th\'eor\`emes}%
    \Crefname@preamble{lemma}{Lemme}{Lemmes}%
    \Crefname@preamble{corollary}{Corollaire}{Corollaires}%
    \Crefname@preamble{proposition}{Proposition}{Propositions}%
    \Crefname@preamble{definition}{D\'efinition}{D\'efinitions}%
    \Crefname@preamble{result}{R\'esultat}{R\'esultats}%
    \Crefname@preamble{example}{Exemple}{Exemples}%
    \Crefname@preamble{remark}{Remarque}{Remarques}%
    \Crefname@preamble{algorithm}{Algorithme}{Algorithmes}%
    \Crefname@preamble{listing}{Liste}{Listes}%
    \Crefname@preamble{line}{Ligne}{Lignes}%
 %
    \if@cref@capitalise%  capitalise set
      \crefname@preamble{equation}{{\'E}quation}{{\'E}quations}%
      \crefname@preamble{figure}{Figure}{Figures}%
      \crefname@preamble{table}{Tableau}{Tableaux}%
      \crefname@preamble{page}{Page}{Pages}%
      \crefname@preamble{part}{Partie}{Parties}%
      \crefname@preamble{chapter}{Chapitre}{Chapitres}%
      \crefname@preamble{section}{Section}{Sections}%
      \crefname@preamble{appendix}{Annexe}{Annexes}%
      \crefname@preamble{enumi}{Point}{Points}%
      \crefname@preamble{footnote}{Note}{Notes}%
      \crefname@preamble{theorem}{Th\'eor\`eme}{Th\'eor\`emes}%
      \crefname@preamble{lemma}{Lemme}{Lemmes}%
      \crefname@preamble{corollary}{Corollaire}{Corollaires}%
      \crefname@preamble{proposition}{Proposition}{Propositions}%
      \crefname@preamble{definition}{D\'efinition}{D\'efinitions}%
      \crefname@preamble{result}{R\'esultat}{R\'esultats}%
      \crefname@preamble{example}{Exemple}{Exemples}%
      \crefname@preamble{remark}{Remarque}{Remarques}%
      \crefname@preamble{note}{Commentaire}{Commentaires}%
      \crefname@preamble{algorithm}{Algorithme}{Algorithmes}%
      \crefname@preamble{listing}{Liste}{Listes}%
      \crefname@preamble{line}{Ligne}{Lignes}%
 %
    \else%  capitalise unset
      \crefname@preamble{equation}{{\'e}quation}{{\'e}quations}%
      \crefname@preamble{figure}{figure}{figures}%
      \crefname@preamble{table}{tableau}{tableaux}%
      \crefname@preamble{page}{page}{pages}%
      \crefname@preamble{part}{partie}{parties}%
      \crefname@preamble{chapter}{chapitre}{chapitres}%
      \crefname@preamble{section}{section}{sections}%
      \crefname@preamble{appendix}{annexe}{annexes}%
      \crefname@preamble{enumi}{point}{points}%
      \crefname@preamble{footnote}{note}{notes}%
      \crefname@preamble{theorem}{th\'eor\`eme}{th\'eor\`emes}%
      \crefname@preamble{lemma}{lemme}{lemmes}%
      \crefname@preamble{corollary}{corollaire}{corollaires}%
      \crefname@preamble{proposition}{proposition}{propositions}%
      \crefname@preamble{definition}{d\'efinition}{d\'efinitions}%
      \crefname@preamble{result}{r\'esultat}{r\'esultats}%
      \crefname@preamble{example}{exemple}{exemples}%
      \crefname@preamble{remark}{remarque}{remarques}%
      \crefname@preamble{note}{commentaire}{commentaires}%
      \crefname@preamble{algorithm}{algorithme}{algorithmes}%
      \crefname@preamble{listing}{liste}{listes}%
      \crefname@preamble{line}{ligne}{lignes}%
    \fi%
    \def\cref@language{french}%
  }}% end \DeclareOption and \AtBeginDocument
%    \end{macrocode}
%
% If using \package{babel} and the corresponding option is set, or if
% using \package{polyglossia} and the language has been loaded, add
% format definition commands to \cmd{\extras}\meta{language} or
% \cmd{\captions}\meta{language} so that language switching commands will
% change the cross-reference formats appropriately.
%    \begin{macrocode}
\cref@addlanguagedefs{french}{%
  \PackageInfo{cleveref}{loaded `french' language definitions}%
  \renewcommand{\crefrangeconjunction}{ \`a\nobreakspace}%
  \renewcommand\crefrangepreconjunction{}%
  \renewcommand\crefrangepostconjunction{}%
  \renewcommand{\crefpairconjunction}{ et\nobreakspace}%
  \renewcommand{\crefmiddleconjunction}{, }%
  \renewcommand{\creflastconjunction}{ et\nobreakspace}%
  \renewcommand{\crefpairgroupconjunction}{ et\nobreakspace}%
  \renewcommand{\crefmiddlegroupconjunction}{, }%
  \renewcommand{\creflastgroupconjunction}{ et\nobreakspace}%
 %
  \Crefname{equation}{{\'E}quation}{{\'E}quations}%
  \Crefname{figure}{Figure}{Figures}%
  \Crefname{subfigure}{Figure}{Figures}%
  \Crefname{table}{Tableau}{Tableaux}%
  \Crefname{subtable}{Tableau}{Tableaux}%
  \Crefname{page}{Page}{Pages}%
  \Crefname{part}{Partie}{Parties}%
  \Crefname{chapter}{Chapitre}{Chapitres}%
  \Crefname{section}{Section}{Sections}%
  \Crefname{subsection}{Section}{Sections}%
  \Crefname{subsubsection}{Section}{Sections}%
  \Crefname{appendix}{Annexe}{Annexes}%
  \Crefname{subappendix}{Annexe}{Annexes}%
  \Crefname{subsubappendix}{Annexe}{Annexes}%
  \Crefname{subsubsubappendix}{Annexe}{Annexes}%
  \Crefname{enumi}{Point}{Points}%
  \Crefname{enumii}{Point}{Points}%
  \Crefname{enumiii}{Point}{Points}%
  \Crefname{enumiv}{Point}{Points}%
  \Crefname{enumv}{Point}{Points}%
  \Crefname{footnote}{Note}{Notes}%
  \Crefname{theorem}{Th\'eor\`eme}{Th\'eor\`emes}%
  \Crefname{lemma}{Lemme}{Lemmes}%
  \Crefname{corollary}{Corollaire}{Corollaires}%
  \Crefname{proposition}{Proposition}{Propositions}%
  \Crefname{definition}{D\'efinition}{D\'efinitions}%
  \Crefname{result}{R\'esultat}{R\'esultats}%
  \Crefname{example}{Exemple}{Exemples}%
  \Crefname{remark}{Remarque}{Remarques}%
  \Crefname{note}{Commentaire}{Commentaires}%
  \Crefname{algorithm}{Algorithme}{Algorithmes}%
  \Crefname{listing}{Liste}{Listes}%
  \Crefname{line}{Ligne}{Lignes}%
 %
  \if@cref@capitalise%  capitalise set
    \crefname{equation}{{\'E}quation}{{\'E}quations}%
    \crefname{figure}{Figure}{Figures}%
    \crefname{subfigure}{Figure}{Figures}%
    \crefname{table}{Tableau}{Tableaux}%
    \crefname{subtable}{Tableau}{Tableaux}%
    \crefname{page}{Page}{Pages}%
    \crefname{part}{Partie}{Parties}%
    \crefname{chapter}{Chapitre}{Chapitres}%
    \crefname{section}{Section}{Sections}%
    \crefname{subsection}{Section}{Sections}%
    \crefname{subsubsection}{Section}{Sections}%
    \crefname{appendix}{Annexe}{Annexes}%
    \crefname{subappendix}{Annexe}{Annexes}%
    \crefname{subsubappendix}{Annexe}{Annexes}%
    \crefname{subsubsubappendix}{Annexe}{Annexes}%
    \crefname{enumi}{Point}{Points}%
    \crefname{enumii}{Point}{Points}%
    \crefname{enumiii}{Point}{Points}%
    \crefname{enumiv}{Point}{Points}%
    \crefname{enumv}{Point}{Points}%
    \crefname{footnote}{Note}{Notes}%
    \crefname{theorem}{Th\'eor\`eme}{Th\'eor\`emes}%
    \crefname{lemma}{Lemme}{Lemmes}%
    \crefname{corollary}{Corollaire}{Corollaires}%
    \crefname{proposition}{Proposition}{Propositions}%
    \crefname{definition}{D\'efinition}{D\'efinitions}%
    \crefname{result}{R\'esultat}{R\'esultats}%
    \crefname{example}{Exemple}{Exemples}%
    \crefname{remark}{Remarque}{Remarques}%
    \crefname{note}{Commentaire}{Commentaires}%
    \crefname{algorithm}{Algorithme}{Algorithmes}%
    \crefname{listing}{Liste}{Listes}%
    \crefname{line}{Ligne}{Lignes}%
 %
  \else%  capitalise unset
    \crefname{equation}{{\'e}quation}{{\'e}quations}%
    \crefname{figure}{figure}{figures}%
    \crefname{subfigure}{figure}{figures}%
    \crefname{table}{tableau}{tableaux}%
    \crefname{subtable}{tableau}{tableaux}%
    \crefname{page}{page}{pages}%
    \crefname{part}{partie}{parties}%
    \crefname{chapter}{chapitre}{chapitres}%
    \crefname{section}{section}{sections}%
    \crefname{subsection}{section}{sections}%
    \crefname{subsubsection}{section}{sections}%
    \crefname{appendix}{annexe}{annexes}%
    \crefname{subappendix}{annexe}{annexes}%
    \crefname{subsubappendix}{annexe}{annexes}%
    \crefname{subsubsubappendix}{annexe}{annexes}%
    \crefname{enumi}{point}{points}%
    \crefname{enumii}{point}{points}%
    \crefname{enumiii}{point}{points}%
    \crefname{enumiv}{point}{points}%
    \crefname{enumv}{point}{points}%
    \crefname{footnote}{note}{notes}%
    \crefname{theorem}{th\'eor\`eme}{th\'eor\`emes}%
    \crefname{lemma}{lemme}{lemmes}%
    \crefname{corollary}{corollaire}{corollaires}%
    \crefname{proposition}{proposition}{propositions}%
    \crefname{definition}{d\'efinition}{d\'efinitions}%
    \crefname{result}{r\'esultat}{r\'esultats}%
    \crefname{example}{exemple}{exemples}%
    \crefname{remark}{remarque}{remarques}%
    \crefname{note}{commentaire}{commentaires}%
    \crefname{algorithm}{algorithme}{algorithmes}%
    \crefname{listing}{liste}{listes}%
    \crefname{line}{ligne}{lignes}%
  \fi}% end \cref@loadlanguagedefs
%    \end{macrocode}
%
%
%  \subsubsection{Spanish}
% \begin{macro}{spanish}
%   Spanish translations generously contributed by Gonzalo Medina.
% \end{macro}
%
% Set up the definitions used at the beginning of the document to define
% the formats created by the document preamble.
%    \begin{macrocode}
\DeclareOption{spanish}{%
  \AtBeginDocument{%
    \def\crefrangeconjunction@preamble{ a\nobreakspace}%
    \def\crefrangepreconjunction@preamble{}%
    \def\crefrangepostconjunction@preamble{}%
    \def\crefpairconjunction@preamble{ y\nobreakspace}%
    \def\crefmiddleconjunction@preamble{, }%
    \def\creflastconjunction@preamble{ y\nobreakspace}%
    \def\crefpairgroupconjunction@preamble{ y\nobreakspace}%
    \def\crefmiddlegroupconjunction@preamble{, }%
    \def\creflastgroupconjunction@preamble{ y\nobreakspace}%
 %
    \Crefname@preamble{equation}{Ecuaci\'on}{Ecuaciones}%
    \Crefname@preamble{figure}{Figura}{Figuras}%
    \Crefname@preamble{table}{Cuadro}{Cuadros}%
    \Crefname@preamble{page}{P\'agina}{P\'aginas}%
    \Crefname@preamble{part}{Parte}{Partes}%
    \Crefname@preamble{chapter}{Cap\'itulo}{Cap\'itulos}%
    \Crefname@preamble{section}{Apartado}{Apartados}%
    \Crefname@preamble{appendix}{Ap\'endice}{Ap\'endices}%
    \Crefname@preamble{enumi}{Punto}{Puntos}%
    \Crefname@preamble{footnote}{Nota}{Notas}%
    \Crefname@preamble{theorem}{Teorema}{Teoremas}%
    \Crefname@preamble{lemma}{Lema}{Lemas}%
    \Crefname@preamble{corollary}{Corolario}{Corolarios}%
    \Crefname@preamble{proposition}{Proposici\'on}{Proposiciones}%
    \Crefname@preamble{definition}{Definici\'on}{Definiciones}%
    \Crefname@preamble{result}{Resultado}{Resultados}%
    \Crefname@preamble{example}{Ejemplo}{Ejemplos}%
    \Crefname@preamble{remark}{Observaci\'on}{Observaciones}%
    \Crefname@preamble{note}{Nota}{Notas}%
    \Crefname@preamble{algorithm}{Algoritmo}{Algoritmos}%
    \Crefname@preamble{listing}{Listado}{Listados}%
    \Crefname@preamble{line}{L\'inea}{L\'ineas}%
 %
    \if@cref@capitalise%  capitalise set
      \crefname@preamble{equation}{Ecuaci\'on}{Ecuaciones}%
      \crefname@preamble{figure}{Figura}{Figuras}%
      \crefname@preamble{table}{Cuadro}{Cuadros}%
      \crefname@preamble{page}{P\'agina}{P\'aginas}%
      \crefname@preamble{part}{Parte}{Partes}%
      \crefname@preamble{chapter}{Cap\'itulo}{Cap\'itulos}%
      \crefname@preamble{section}{Apartado}{Apartados}%
      \crefname@preamble{appendix}{Ap\'endice}{Ap\'endices}%
      \crefname@preamble{enumi}{Punto}{Puntos}%
      \crefname@preamble{footnote}{Nota}{Notas}%
      \crefname@preamble{theorem}{Teorema}{Teoremas}%
      \crefname@preamble{lemma}{Lema}{Lemas}%
      \crefname@preamble{corollary}{Corolario}{Corolarios}%
      \crefname@preamble{proposition}{Proposici\'on}{Proposiciones}%
      \crefname@preamble{definition}{Definici\'on}{Definiciones}%
      \crefname@preamble{result}{Resultado}{Resultados}%
      \crefname@preamble{example}{Ejemplo}{Ejemplos}%
      \crefname@preamble{remark}{Observaci\'on}{Observaciones}%
      \crefname@preamble{note}{Nota}{Notas}%
      \crefname@preamble{algorithm}{Algoritmo}{Algoritmos}%
      \crefname@preamble{listing}{Listado}{Listados}%
      \crefname@preamble{line}{L\'inea}{L\'ineas}%
 %
    \else%  capitalise unset
      \crefname@preamble{equation}{ecuaci\'on}{ecuaciones}%
      \crefname@preamble{figure}{figura}{figuras}%
      \crefname@preamble{table}{cuadro}{cuadros}%
      \crefname@preamble{page}{p\'agina}{p\'aginas}%
      \crefname@preamble{part}{parte}{partes}%
      \crefname@preamble{chapter}{cap\'itulo}{cap\'itulos}%
      \crefname@preamble{section}{apartado}{apartados}%
      \crefname@preamble{appendix}{ap\'endice}{ap\'endices}%
      \crefname@preamble{enumi}{punto}{puntos}%
      \crefname@preamble{footnote}{nota}{notas}%
      \crefname@preamble{theorem}{teorema}{teoremas}%
      \crefname@preamble{lemma}{lema}{lemas}%
      \crefname@preamble{corollary}{corolario}{corolarios}%
      \crefname@preamble{proposition}{proposici\'on}{proposiciones}%
      \crefname@preamble{definition}{definici\'on}{definiciones}%
      \crefname@preamble{result}{resultado}{resultados}%
      \crefname@preamble{example}{ejemplo}{ejemplos}%
      \crefname@preamble{remark}{observaci\'on}{observaciones}%
      \crefname@preamble{note}{nota}{notas}%
      \crefname@preamble{algorithm}{algoritmo}{algoritmos}%
      \crefname@preamble{listing}{listado}{listados}%
      \crefname@preamble{line}{l\'inea}{l\'ineas}%
    \fi%
    \def\cref@language{spanish}%
  }}% end \DeclareOption and \AtBeginDocument
%    \end{macrocode}
%
% If using \package{babel} and the corresponding option is set, or if
% using \package{polyglossia} and the language has been loaded, add
% format definition commands to \cmd{\extras}\meta{language} or
% \cmd{\captions}\meta{language} so that language switching commands will
% change the cross-reference formats appropriately.
%    \begin{macrocode}
\cref@addlanguagedefs{spanish}{%
  \PackageInfo{cleveref}{loaded `spanish' language definitions}%
  \renewcommand{\crefrangeconjunction}{ a\nobreakspace}%
  \renewcommand{\crefrangepreconjunction}{}%
  \renewcommand{\crefrangepostconjunction}{}%
  \renewcommand{\crefpairconjunction}{ y\nobreakspace}%
  \renewcommand{\crefmiddleconjunction}{, }%
  \renewcommand{\creflastconjunction}{ y\nobreakspace}%
  \renewcommand{\crefpairgroupconjunction}{ y\nobreakspace}%
  \renewcommand{\crefmiddlegroupconjunction}{, }%
  \renewcommand{\creflastgroupconjunction}{ y\nobreakspace}%
 %
  \Crefname{equation}{Ecuaci\'on}{Ecuaciones}%
  \Crefname{figure}{Figura}{Figuras}%
  \Crefname{subfigure}{Figura}{Figuras}%
  \Crefname{table}{Cuadro}{Cuadros}%
  \Crefname{subtable}{Cuadro}{Cuadros}%
  \Crefname{page}{P\'agina}{P\'aginas}%
  \Crefname{part}{Parte}{Partes}%
  \Crefname{chapter}{Cap\'itulo}{Cap\'itulos}%
  \Crefname{section}{Apartado}{Apartados}%
  \Crefname{subsection}{Apartado}{Apartados}%
  \Crefname{subsubsection}{Apartado}{Apartados}%
  \Crefname{appendix}{Ap\'endice}{Ap\'endices}%
  \Crefname{subappendix}{Ap\'endice}{Ap\'endices}%
  \Crefname{subsubappendix}{Ap\'endice}{Ap\'endices}%
  \Crefname{subsubsubappendix}{Ap\'endice}{Ap\'endices}%
  \Crefname{enumi}{Punto}{Puntos}%
  \Crefname{enumii}{Punto}{Puntos}%
  \Crefname{enumiii}{Punto}{Puntos}%
  \Crefname{enumiv}{Punto}{Puntos}%
  \Crefname{enumv}{Punto}{Puntos}%
  \Crefname{footnote}{Nota}{Notas}%
  \Crefname{theorem}{Teorema}{Teoremas}%
  \Crefname{lemma}{Lema}{Lemas}%
  \Crefname{corollary}{Corolario}{Corolarios}%
  \Crefname{proposition}{Proposici\'on}{Proposiciones}%
  \Crefname{definition}{Definici\'on}{Definiciones}%
  \Crefname{result}{Resultado}{Resultados}%
  \Crefname{example}{Ejemplo}{Ejemplos}%
  \Crefname{remark}{Observaci\'on}{Observaci\'on}%
  \Crefname{note}{Nota}{Notas}%
  \Crefname{algorithm}{Algoritmo}{Algoritmos}%
  \Crefname{listing}{Listado}{Listados}%
  \Crefname{line}{L\'inea}{L\'ineas}%
 %
  \if@cref@capitalise%  capitalise set
    \crefname{equation}{Ecuaci\'on}{Ecuaciones}%
    \crefname{figure}{Figura}{Figuras}%
    \crefname{subfigure}{Figura}{Figuras}%
    \crefname{table}{Cuadro}{Cuadros}%
    \crefname{subtable}{Cuadro}{Cuadros}%
    \crefname{page}{P\'agina}{P\'aginas}%
    \crefname{part}{Parte}{Partes}%
    \crefname{chapter}{Cap\'itulo}{Cap\'itulos}%
    \crefname{section}{Apartado}{Apartados}%
    \crefname{subsection}{Apartado}{Apartados}%
    \crefname{subsubsection}{Apartado}{Apartados}%
    \crefname{appendix}{Ap\'endice}{Ap\'endices}%
    \crefname{subappendix}{Ap\'endice}{Ap\'endices}%
    \crefname{subsubappendix}{Ap\'endice}{Ap\'endices}%
    \crefname{subsubsubappendix}{Ap\'endice}{Ap\'endices}%
    \crefname{enumi}{Punto}{Puntos}%
    \crefname{enumii}{Punto}{Puntos}%
    \crefname{enumiii}{Punto}{Puntos}%
    \crefname{enumiv}{Punto}{Puntos}%
    \crefname{enumv}{Punto}{Puntos}%
    \crefname{footnote}{Nota}{Notas}%
    \crefname{theorem}{Teorema}{Teoremas}%
    \crefname{lemma}{Lema}{Lemas}%
    \crefname{corollary}{Corolario}{Corolarios}%
    \crefname{proposition}{Proposici\'on}{Proposiciones}%
    \crefname{definition}{Definici\'on}{Definiciones}%
    \crefname{result}{Resultado}{Resultados}%
    \crefname{example}{Ejemplo}{Ejemplos}%
    \crefname{remark}{Observaci\'on}{Observaci\'ones}%
    \crefname{note}{Nota}{Notas}%
    \crefname{algorithm}{Algoritmo}{Algoritmos}%
    \crefname{listing}{Listado}{Listados}%
    \crefname{line}{L\'inea}{L\'ineas}%
 %
  \else%  capitalise unset
    \crefname{equation}{ecuaci\'on}{ecuaciones}%
    \crefname{figure}{figura}{figuras}%
    \crefname{subfigure}{figura}{figuras}%
    \crefname{table}{cuadro}{cuadros}%
    \crefname{subtable}{cuadro}{cuadros}%
    \crefname{page}{p\'agina}{p\'aginas}%
    \crefname{part}{parte}{partes}%
    \crefname{chapter}{cap\'itulo}{cap\'itulos}%
    \crefname{section}{apartado}{apartados}%
    \crefname{subsection}{apartado}{apartados}%
    \crefname{subsubsection}{apartado}{apartados}%
    \crefname{appendix}{ap\'endice}{ap\'endices}%
    \crefname{subappendix}{ap\'endice}{ap\'endices}%
    \crefname{subsubappendix}{ap\'endice}{ap\'endices}%
    \crefname{subsubsubappendix}{ap\'endice}{ap\'endices}%
    \crefname{enumi}{punto}{puntos}%
    \crefname{enumii}{punto}{puntos}%
    \crefname{enumiii}{punto}{puntos}%
    \crefname{enumiv}{punto}{puntos}%
    \crefname{enumv}{punto}{puntos}%
    \crefname{footnote}{nota}{notas}%
    \crefname{theorem}{teorema}{teoremas}%
    \crefname{lemma}{lema}{lemas}%
    \crefname{corollary}{corolario}{corolarios}%
    \crefname{proposition}{proposici\'on}{proposiciones}%
    \crefname{definition}{definici\'on}{definiciones}%
    \crefname{result}{resultado}{resultados}%
    \crefname{example}{ejemplo}{ejemplos}%
    \crefname{remark}{observaci\'on}{observaci\'ones}%
    \crefname{note}{nota}{notas}%
    \crefname{algorithm}{algoritmo}{algoritmos}%
    \crefname{listing}{listado}{listados}%
    \crefname{line}{l\'inea}{l\'ineas}%
  \fi}% end \cref@loadlanguagedefs
%    \end{macrocode}
%
%
%  \subsubsection{Italian}
% \begin{macro}{italian}
%   Italian translations kindly contributed by Massimo Redaelli.
% \end{macro}
%
% Set up the definitions used at the beginning of the document to define
% the formats created by the document preamble.
%    \begin{macrocode}
\DeclareOption{italian}{%
  \AtBeginDocument{%
    \def\crefrangeconjunction@preamble{ a\nobreakspace}%
    \def\crefrangepreconjunction@preamble{da\nobreakspace}%
    \def\crefrangepostconjunction@preamble{}%
    \def\crefpairconjunction@preamble{ e\nobreakspace}%
    \def\crefmiddleconjunction@preamble{, }%
    \def\creflastconjunction@preamble{ e\nobreakspace}%
%    \end{macrocode}
% We have to define the group conjunctions explicitly here, rather than
% relying on fall-back definitions in terms of the above conjunctions
% (see \cref{sec:code:default_formats}), in case any other language
% option defines them explicitly and we need to override those.
%    \begin{macrocode}
    \def\crefpairgroupconjunction@preamble{ e\nobreakspace}%
    \def\crefmiddlegroupconjunction@preamble{, }%
    \def\creflastgroupconjunction@preamble{ e\nobreakspace}%
 %
    \Crefname@preamble{equation}{Equazione}{Equazioni}%
    \Crefname@preamble{figure}{Figura}{Figure}%
    \Crefname@preamble{table}{Tabella}{Tabelle}%
    \Crefname@preamble{page}{Pagina}{Pagine}%
    \Crefname@preamble{part}{Parte}{Parti}%
    \Crefname@preamble{chapter}{Capitolo}{Capitoli}%
    \Crefname@preamble{section}{Sezione}{Sezioni}%
    \Crefname@preamble{appendix}{Appendice}{Appendici}%
    \Crefname@preamble{enumi}{Voce}{Voci}%
    \Crefname@preamble{footnote}{Nota}{Note}%
    \Crefname@preamble{theorem}{Teorema}{Teoremi}%
    \Crefname@preamble{lemma}{Lemma}{Lemmi}%
    \Crefname@preamble{corollary}{Corollario}{Corollari}%
    \Crefname@preamble{proposition}{Proposizione}{Proposizioni}%
    \Crefname@preamble{definition}{Definizioni}{Definizioni}%
    \Crefname@preamble{result}{Risultato}{Risultati}%
    \Crefname@preamble{example}{esempio}{esempi}%
    \Crefname@preamble{remark}{Osservazione}{Osservazioni}%
    \Crefname@preamble{note}{Nota}{Note}%
    \Crefname@preamble{algorithm}{Algoritmo}{Algoritmi}%
    \Crefname@preamble{listing}{Elenco}{Elenchi}%
    \Crefname@preamble{line}{Linea}{Linee}%
 %
    \if@cref@capitalise%  capitalise set
      \if@cref@abbrev%
        \crefname@preamble{equation}{Eq.}{Eq.}%
        \crefname@preamble{figure}{Fig.}{Fig.}%
      \else%
        \crefname@preamble{equation}{Equazione}{Equazioni}%
        \crefname@preamble{figure}{Figura}{Figure}%
      \fi%
      \crefname@preamble{table}{Tabella}{Tabelle}%
      \crefname@preamble{page}{Pagina}{Pagine}%
      \crefname@preamble{part}{Parte}{Parti}%
      \crefname@preamble{chapter}{Capitolo}{Capitoli}%
      \crefname@preamble{section}{Sezione}{Sezioni}%
      \crefname@preamble{appendix}{Appendice}{Appendici}%
      \crefname@preamble{enumi}{Voce}{Voci}%
      \crefname@preamble{footnote}{Nota}{Note}%
      \crefname@preamble{theorem}{Teorema}{Teoremi}%
      \crefname@preamble{lemma}{Lemma}{Lemmi}%
      \crefname@preamble{corollary}{Corollario}{Corollari}%
      \crefname@preamble{proposition}{Proposizione}{Proposizioni}%
      \crefname@preamble{definition}{Definizione}{Definizioni}%
      \crefname@preamble{result}{Risultato}{Risultati}%
      \crefname@preamble{example}{Esempio}{Esempi}%
      \crefname@preamble{remark}{Osservazione}{Osservazioni}%
      \crefname@preamble{note}{Nota}{Note}%
      \crefname@preamble{algorithm}{Algoritmo}{Algoritmi}%
      \crefname@preamble{listing}{Elenco}{Elenchi}%
      \crefname@preamble{line}{Linea}{Linee}%
 %
    \else%  capitalise unset
      \if@cref@abbrev%
        \crefname@preamble{equation}{eq.}{eq.}%
        \crefname@preamble{figure}{fig.}{fig.}%
      \else%
        \crefname@preamble{equation}{equazione}{equazioni}%
        \crefname@preamble{figure}{figura}{figure}%
      \fi%
      \crefname@preamble{table}{tabella}{tabelle}%
      \crefname@preamble{page}{pagina}{pagine}%
      \crefname@preamble{part}{parte}{parti}%
      \crefname@preamble{chapter}{capitolo}{capitoli}%
      \crefname@preamble{section}{sezione}{sezioni}%
      \crefname@preamble{appendix}{appendice}{appendici}%
      \crefname@preamble{enumi}{voce}{voci}%
      \crefname@preamble{footnote}{nota}{note}%
      \crefname@preamble{theorem}{teorema}{teoremi}%
      \crefname@preamble{lemma}{lemma}{lemmi}%
      \crefname@preamble{corollary}{corollario}{corollari}%
      \crefname@preamble{proposition}{proposizione}{proposizioni}%
      \crefname@preamble{definition}{definizione}{definizioni}%
      \crefname@preamble{result}{risultato}{risultati}%
      \crefname@preamble{example}{esempio}{esempi}%
      \crefname@preamble{remark}{osservazione}{osservazioni}%
      \crefname@preamble{note}{nota}{note}%
      \crefname@preamble{algorithm}{algoritmo}{algoritmi}%
      \crefname@preamble{listing}{elenco}{elenchi}%
      \crefname@preamble{line}{linea}{linee}%
    \fi%
    \def\cref@language{italian}%
  }}% end \DeclareOption and \AtBeginDocument
%    \end{macrocode}
%
% If using \package{babel} and the corresponding option is set, or if
% using \package{polyglossia} and the language has been loaded, add
% format definition commands to \cmd{\extras}\meta{language} or
% \cmd{\captions}\meta{language} so that language switching commands will
% change the cross-reference formats appropriately.
%    \begin{macrocode}
\cref@addlanguagedefs{italian}{%
  \PackageInfo{cleveref}{loaded `italian' language definitions}%
  \renewcommand{\crefrangeconjunction}{ a\nobreakspace}%
  \renewcommand\crefrangepreconjunction{da\nobreakspace}%
  \renewcommand\crefrangepostconjunction{}%
  \renewcommand{\crefpairconjunction}{ e\nobreakspace}%
  \renewcommand{\crefmiddleconjunction}{, }%
  \renewcommand{\creflastconjunction}{ e\nobreakspace}%
  \renewcommand{\crefpairgroupconjunction}{ e\nobreakspace}%
  \renewcommand{\crefmiddlegroupconjunction}{, }%
  \renewcommand{\creflastgroupconjunction}{ e\nobreakspace}%
 %
  \Crefname{equation}{Equazione}{Equazioni}%
  \Crefname{figure}{Figura}{Figure}%
  \Crefname{subfigure}{Figura}{Figure}%
  \Crefname{table}{Tabella}{Tabelle}%
  \Crefname{subtable}{Tabella}{Tabelle}%
  \Crefname{page}{Pagina}{Pagine}%
  \Crefname{part}{Parte}{Parti}%
  \Crefname{chapter}{Capitolo}{Capitoli}%
  \Crefname{section}{Sezione}{Sezioni}%
  \Crefname{subsection}{Sezione}{Sezioni}%
  \Crefname{subsubsection}{Sezione}{Sezioni}%
  \Crefname{appendix}{Appendice}{Appendici}%
  \Crefname{subappendix}{Appendice}{Appendici}%
  \Crefname{subsubappendix}{Appendice}{Appendici}%
  \Crefname{subsubsubappendix}{Appendice}{Appendici}%
  \Crefname{enumi}{Voce}{Voci}%
  \Crefname{enumii}{Voce}{Voci}%
  \Crefname{enumiii}{Voce}{Voci}%
  \Crefname{enumiv}{Voce}{Voci}%
  \Crefname{enumv}{Voce}{Voci}%
  \Crefname{footnote}{Nota}{Note}%
  \Crefname{theorem}{Teorema}{Teoremi}%
  \Crefname{lemma}{Lemma}{Lemmi}%
  \Crefname{corollary}{Corollario}{Corollari}%
  \Crefname{proposition}{Proposizione}{Proposizioni}%
  \Crefname{definition}{Definizione}{Definizione}%
  \Crefname{result}{Risultato}{Risultati}%
  \Crefname{example}{esempio}{esempi}%
  \Crefname{remark}{Osservazione}{Osservazioni}%
  \Crefname{note}{Nota}{Note}%
  \Crefname{algorithm}{Algoritmo}{Algoritmi}%
  \Crefname{listing}{Elenco}{Elenchi}%
  \Crefname{line}{Linea}{Linee}%
 %
  \if@cref@capitalise%  capitalise set
    \if@cref@abbrev%
      \crefname{equation}{Eq.}{Eq.}%
      \crefname{figure}{Fig.}{Fig.}%
      \crefname{subfigure}{Fig.}{Fig.}%
    \else%
      \crefname{equation}{Equazione}{Equazioni}%
      \crefname{figure}{Figura}{Figure}%
      \crefname{figure}{Figura}{Figure}%
    \fi%
    \crefname{table}{Tabella}{Tabelle}%
    \crefname{page}{Pagina}{Pagine}%
    \crefname{subtable}{Tabella}{Tabelle}%
    \crefname{part}{Parte}{Parti}%
    \crefname{chapter}{Capitolo}{Capitoli}%
    \crefname{section}{Sezione}{Sezioni}%
    \crefname{subsection}{Sezione}{Sezioni}%
    \crefname{subsubsection}{Sezione}{Sezioni}%
    \crefname{appendix}{Appendice}{Appendici}%
    \crefname{subappendix}{Appendice}{Appendici}%
    \crefname{subsubappendix}{Appendice}{Appendici}%
    \crefname{subsubsubappendix}{Appendice}{Appendici}%
    \crefname{enumi}{Voce}{Voci}%
    \crefname{enumii}{Voce}{Voci}%
    \crefname{enumiii}{Voce}{Voci}%
    \crefname{enumiv}{Voce}{Voci}%
    \crefname{enumv}{Voce}{Voci}%
    \crefname{footnote}{Nota}{Note}%
    \crefname{theorem}{Teorema}{Teoremi}%
    \crefname{lemma}{Lemma}{Lemmi}%
    \crefname{corollary}{Corollario}{Corollari}%
    \crefname{proposition}{Proposizione}{Proposizioni}%
    \crefname{definition}{Definizione}{Definizione}%
    \crefname{result}{Risultato}{Risultati}%
    \crefname{example}{Esempio}{Esempi}%
    \crefname{remark}{Osservazione}{Osservazioni}%
    \crefname{note}{Nota}{Note}%
    \crefname{algorithm}{Algoritmo}{Algoritmi}%
    \crefname{listing}{Elenco}{Elenchi}%
    \crefname{line}{Linea}{Linee}%
 %
  \else%  capitalise unset
    \if@cref@abbrev%
      \crefname{equation}{eq.}{eq.}%
      \crefname{figure}{fig.}{fig.}%
      \crefname{subfigure}{fig.}{fig.}%
    \else%
      \crefname{equation}{equazione}{equazioni}%
      \crefname{figure}{figura}{figure}%
      \crefname{figure}{figura}{figure}%
    \fi%
    \crefname{table}{tabella}{tabelle}%
    \crefname{page}{pagina}{pagine}%
    \crefname{subtable}{tabella}{tabelle}%
    \crefname{part}{parte}{parti}%
    \crefname{chapter}{capitolo}{capitoli}%
    \crefname{section}{sezione}{sezioni}%
    \crefname{subsection}{sezione}{sezioni}%
    \crefname{subsubsection}{sezione}{sezioni}%
    \crefname{appendix}{appendice}{appendici}%
    \crefname{subappendix}{appendice}{appendici}%
    \crefname{subsubappendix}{appendice}{appendici}%
    \crefname{subsubsubappendix}{appendice}{appendici}%
    \crefname{enumi}{voce}{voci}%
    \crefname{enumii}{voce}{voci}%
    \crefname{enumiii}{voce}{voci}%
    \crefname{enumiv}{voce}{voci}%
    \crefname{enumv}{voce}{voci}%
    \crefname{footnote}{nota}{note}%
    \crefname{theorem}{teorema}{teoremi}%
    \crefname{lemma}{lemma}{lemmi}%
    \crefname{corollary}{corollario}{corollari}%
    \crefname{proposition}{proposizione}{proposizioni}%
    \crefname{definition}{definizione}{definizione}%
    \crefname{result}{risultato}{risultati}%
    \crefname{example}{esempio}{esempi}%
    \crefname{remark}{osservazione}{osservazioni}%
    \crefname{note}{nota}{note}%
    \crefname{algorithm}{algoritmo}{algoritmi}%
    \crefname{listing}{elenco}{elenchi}%
    \crefname{line}{linea}{linee}%
  \fi}% end \cref@loadlanguagedefs
%    \end{macrocode}
%
%
%  \subsubsection{Russian}
% \begin{macro}{russian}
%   Russian translations generously contributed by Aleksander Gorohovski.
% \end{macro}
%
% Set up the definitions used at the beginning of the document to define
% the formats created by the document preamble.
%    \begin{macrocode}
\DeclareOption{russian}{%
  \AtBeginDocument{%
    \def\crefrangeconjunction@preamble{--}%
    \def\crefrangepreconjunction@preamble{}%
    \def\crefrangepostconjunction@preamble{}%
    \def\crefpairconjunction@preamble{ \cyri\nobreakspace}%
    \def\crefmiddleconjunction@preamble{, }%
    \def\creflastconjunction@preamble{ \cyri\nobreakspace}%
%    \end{macrocode}
% We have to define the group conjunctions explicitly here, rather than
% relying on fall-back definitions in terms of the above conjunctions
% (see \cref{sec:code:default_formats}), in case any other language
% option defines them explicitly and we need to override those.
%    \begin{macrocode}
    \def\crefpairgroupconjunction@preamble{ \cyri\nobreakspace}%
    \def\crefmiddlegroupconjunction@preamble{, }%
    \def\creflastgroupconjunction@preamble%
      {, \cyra\ \cyrt\cyra\cyrk\cyrzh\cyre\nobreakspace}%
 %
      \Crefname@preamble{equation}%
      {\CYRF\cyro\cyrr\cyrm\cyru\cyrl\cyra}%
      {\CYRF\cyro\cyrr\cyrm\cyru\cyrl\cyrery}%
    \Crefname@preamble{figure}%
      {\CYRR\cyri\cyrs\cyru\cyrn\cyro\cyrk}%
      {\CYRR\cyri\cyrs\cyru\cyrn\cyrk\cyri}%
    \Crefname@preamble{table}%
      {\CYRT\cyra\cyrb\cyrl\cyri\cyrc\cyra}%
      {\CYRT\cyra\cyrb\cyrl\cyri\cyrc\cyrery}%
    \Crefname@preamble{enumi}%
      {\CYRP\cyru\cyrn\cyrk\cyrt}%
      {\CYRP\cyru\cyrn\cyrk\cyrt\cyrery}%
    \Crefname@preamble{chapter}%
      {\CYRG\cyrl\cyra\cyrv\cyra}%
      {\CYRG\cyrl\cyra\cyrv\cyrery}%
    \Crefname@preamble{section}%
      {\CYRR\cyra\cyrz\cyrd\cyre\cyrl}%
      {\CYRR\cyra\cyrz\cyrd\cyre\cyrl\cyrery}%
    \Crefname@preamble{appendix}%
      {\CYRP\cyrr\cyri\cyrl\cyro\cyrzh\cyre\cyrn\cyri\cyre}%
      {\CYRP\cyrr\cyri\cyrl\cyro\cyrzh\cyre\cyrn\cyri\cyrya}%
    \Crefname@preamble{footnote}%
      {\CYRS\cyrn\cyro\cyrs\cyrk\cyra}%
      {\CYRS\cyrn\cyro\cyrs\cyrk\cyri}%
    \Crefname@preamble{theorem}%
      {\CYRT\cyre\cyro\cyrr\cyre\cyrm\cyra}%
      {\CYRT\cyre\cyro\cyrr\cyre\cyrm\cyrery}%
    \Crefname@preamble{lemma}%
      {\CYRL\cyre\cyrm\cyrm\cyra}%
      {\CYRL\cyre\cyrm\cyrm\cyrery}%
    \Crefname@preamble{corollary}%
      {\CYRV\cyrery\cyrv\cyro\cyrd}%
      {\CYRV\cyrery\cyrv\cyro\cyrd\cyrery}%
    \Crefname@preamble{proposition}%
      {\CYRU\cyrt\cyrv\cyre\cyrr\cyrzh\cyrd\cyre\cyrn\cyri\cyre}%
      {\CYRU\cyrt\cyrv\cyre\cyrr\cyrzh\cyrd\cyre\cyrn\cyri\cyrya}%
    \Crefname@preamble{definition}%
      {\CYRO\cyrp\cyrr\cyre\cyrd\cyre\cyrl\cyre\cyrn\cyri\cyre}%
      {\CYRO\cyrp\cyrr\cyre\cyrd\cyre\cyrl\cyre\cyrn\cyri\cyrya}%
    \Crefname@preamble{result}%
      {\CYRR\cyre\cyrz\cyru\cyrl\cyrsftsn\cyrt\cyra\cyrt}%
      {\CYRR\cyre\cyrz\cyru\cyrl\cyrsftsn\cyrt\cyra\cyrt\cyrery}%
    \Crefname@preamble{example}%
      {\CYRP\cyrr\cyri\cyrm\cyre\cyrr}%
      {\CYRP\cyrr\cyri\cyrm\cyre\cyrr\cyrery}%
    \Crefname@preamble{remark}%
      {\CYRP\cyrr\cyri\cyrm\cyre\cyrch\cyra\cyrn\cyri\cyre}%
      {\CYRP\cyrr\cyri\cyrm\cyre\cyrch\cyra\cyrn\cyri\cyrya}%
    \Crefname@preamble{note}%
      {\CYRZ\cyra\cyrm\cyre\cyrt\cyrk\cyra}%
      {\CYRZ\cyra\cyrm\cyre\cyrt\cyrk\cyri}%
    \Crefname@preamble{algorithm}%
      {\CYRA\cyrl\cyrg\cyro\cyrr\cyri\cyrt\cyrm}%
      {\CYRA\cyrl\cyrg\cyro\cyrr\cyri\cyrt\cyrm\cyrery}%
    \Crefname@preamble{listing}%
      {\CYRL\cyri\cyrs\cyrt\cyri\cyrn\cyrg}%
      {\CYRL\cyri\cyrs\cyrt\cyri\cyrn\cyrg\cyri}%
    \Crefname@preamble{line}%
      {\CYRS\cyrt\cyrr\cyro\cyrk\cyra}%
      {\CYRS\cyrt\cyrr\cyro\cyrk\cyri}%
    \Crefname@preamble{page}%
      {\CYRS\cyrt\cyrr\cyra\cyrn\cyri\cyrc\cyra}%
      {\CYRS\cyrt\cyrr\cyra\cyrn\cyri\cyrc\cyrery}%
    \Crefname@preamble{part}%
      {\CYRCH\cyra\cyrs\cyrt\cyrsftsn}%
      {\CYRCH\cyra\cyrs\cyrt\cyri}%
 %
    \if@cref@capitalise%  capitalise set
      \if@cref@abbrev%  abbrev set
        \crefname@preamble{equation}%
          {\CYRF-\cyrl.}%
          {\CYRF-\cyrl.}%
        \crefname@preamble{figure}%
          {\CYRR\cyri\cyrs.}%
          {\CYRR\cyri\cyrs.}%
        \crefname@preamble{table}%
          {\CYRT\cyra\cyrb\cyrl.}%
          {\CYRT\cyra\cyrb\cyrl.}%
        \crefname@preamble{enumi}%
          {\CYRP.}%
          {\CYRP.\cyrp.}%
      \else%
        \crefname@preamble{equation}%
          {\CYRF\cyro\cyrr\cyrm\cyru\cyrl\cyra}%
          {\CYRF\cyro\cyrr\cyrm\cyru\cyrl\cyrery}%
        \crefname@preamble{figure}%
          {\CYRR\cyri\cyrs\cyru\cyrn\cyro\cyrk}%
          {\CYRR\cyri\cyrs\cyru\cyrn\cyrk\cyri}%
        \crefname@preamble{table}%
          {\CYRT\cyra\cyrb\cyrl\cyri\cyrc\cyra}%
          {\CYRT\cyra\cyrb\cyrl\cyri\cyrc\cyrery}%
        \crefname@preamble{enumi}%
          {\CYRP\cyru\cyrn\cyrk\cyrt}%
          {\CYRP\cyru\cyrn\cyrk\cyrt\cyrery}%
      \fi%
      \crefname@preamble{chapter}%
        {\CYRG\cyrl\cyra\cyrv\cyra}%
        {\CYRG\cyrl\cyra\cyrv\cyrery}%
      \crefname@preamble{section}%
        {\CYRR\cyra\cyrz\cyrd\cyre\cyrl}%
        {\CYRR\cyra\cyrz\cyrd\cyre\cyrl\cyrery}%
      \crefname@preamble{appendix}%
        {\CYRP\cyrr\cyri\cyrl\cyro\cyrzh\cyre\cyrn\cyri\cyre}%
        {\CYRP\cyrr\cyri\cyrl\cyro\cyrzh\cyre\cyrn\cyri\cyrya}%
      \crefname@preamble{footnote}%
        {\CYRS\cyrn\cyro\cyrs\cyrk\cyra}%
        {\CYRS\cyrn\cyro\cyrs\cyrk\cyri}%
      \crefname@preamble{theorem}%
        {\CYRT\cyre\cyro\cyrr\cyre\cyrm\cyra}%
        {\CYRT\cyre\cyro\cyrr\cyre\cyrm\cyrery}%
      \crefname@preamble{lemma}%
        {\CYRL\cyre\cyrm\cyrm\cyra}%
        {\CYRL\cyre\cyrm\cyrm\cyrery}%
      \crefname@preamble{corollary}%
        {\CYRV\cyrery\cyrv\cyro\cyrd}%
        {\CYRV\cyrery\cyrv\cyro\cyrd\cyrery}%
      \crefname@preamble{proposition}%
        {\CYRU\cyrt\cyrv\cyre\cyrr\cyrzh\cyrd\cyre\cyrn\cyri\cyre}%
        {\CYRU\cyrt\cyrv\cyre\cyrr\cyrzh\cyrd\cyre\cyrn\cyri\cyrya}%
      \crefname@preamble{definition}%
        {\CYRO\cyrp\cyrr\cyre\cyrd\cyre\cyrl\cyre\cyrn\cyri\cyre}%
        {\CYRO\cyrp\cyrr\cyre\cyrd\cyre\cyrl\cyre\cyrn\cyri\cyrya}%
      \crefname@preamble{result}%
        {\CYRR\cyre\cyrz\cyru\cyrl\cyrsftsn\cyrt\cyra\cyrt}%
        {\CYRR\cyre\cyrz\cyru\cyrl\cyrsftsn\cyrt\cyra\cyrt\cyrery}%
      \crefname@preamble{example}%
        {\CYRP\cyrr\cyri\cyrm\cyre\cyrr}%
        {\CYRP\cyrr\cyri\cyrm\cyre\cyrr\cyrery}%
      \crefname@preamble{remark}%
        {\CYRP\cyrr\cyri\cyrm\cyre\cyrch\cyra\cyrn\cyri\cyre}%
        {\CYRP\cyrr\cyri\cyrm\cyre\cyrch\cyra\cyrn\cyri\cyrya}%
      \crefname@preamble{note}%
        {\CYRZ\cyra\cyrm\cyre\cyrt\cyrk\cyra}%
        {\CYRZ\cyra\cyrm\cyre\cyrt\cyrk\cyri}%
      \crefname@preamble{algorithm}%
        {\CYRA\cyrl\cyrg\cyro\cyrr\cyri\cyrt\cyrm}%
        {\CYRA\cyrl\cyrg\cyro\cyrr\cyri\cyrt\cyrm\cyrery}%
      \crefname@preamble{listing}%
        {\CYRL\cyri\cyrs\cyrt\cyri\cyrn\cyrg}%
        {\CYRL\cyri\cyrs\cyrt\cyri\cyrn\cyrg\cyri}%
      \crefname@preamble{line}%
        {\CYRS\cyrt\cyrr\cyro\cyrk\cyra}%
        {\CYRS\cyrt\cyrr\cyro\cyrk\cyri}%
      \crefname@preamble{page}%
        {\CYRS\cyrt\cyrr\cyra\cyrn\cyri\cyrc\cyra}%
        {\CYRS\cyrt\cyrr\cyra\cyrn\cyri\cyrc\cyrery}%
      \crefname@preamble{part}%
        {\CYRCH\cyra\cyrs\cyrt\cyrsftsn}%
        {\CYRCH\cyra\cyrs\cyrt\cyri}%
 %
    \else%  capitalise unset
      \if@cref@abbrev%  abbrev set
        \crefname@preamble{equation}%
          {\cyrf-\cyrl.}%
          {\cyrf-\cyrl.}%
        \crefname@preamble{figure}%
          {\cyrr\cyri\cyrs.}%
          {\cyrr\cyri\cyrs.}%
        \crefname@preamble{table}%
          {\cyrt\cyra\cyrb\cyrl.}%
          {\cyrt\cyra\cyrb\cyrl.}%
        \crefname@preamble{enumi}%
          {\cyrp.}%
          {\cyrp.\cyrp.}%
        \crefname@preamble{chapter}%
          {\cyrg\cyrl\cyra\cyrv.}%
          {\cyrg\cyrl\cyra\cyrv.}%
        \crefname@preamble{section}%
          {\cyrr\cyra\cyrz\cyrd.}%
          {\cyrr\cyra\cyrz\cyrd\cyre\cyrl.}%
        \crefname@preamble{appendix}%
          {\cyrp\cyrr\cyri\cyrl\cyro\cyrzh.}%
          {\cyrp\cyrr\cyri\cyrl\cyro\cyrzh.}%
        \crefname@preamble{footnote}%
          {\cyrs\cyrn\cyro\cyrs\cyrk.}%
          {\cyrs\cyrn\cyro\cyrs\cyrk.}%
        \crefname@preamble{theorem}%
          {\cyrt\cyre\cyro\cyrr\cyre\cyrm.}%
          {\cyrt\cyre\cyro\cyrr\cyre\cyrm.}%
        \crefname@preamble{lemma}%
          {\cyrl\cyre\cyrm\cyrm.}%
          {\cyrl\cyre\cyrm\cyrm.}%
        \crefname@preamble{corollary}%
          {\cyrv\cyrery\cyrv\cyro\cyrd}%
          {\cyrv\cyrery\cyrv\cyro\cyrd.}%
        \crefname@preamble{proposition}%
          {\cyru\cyrt\cyrv\cyre\cyrr\cyrzh\cyrd.}%
          {\cyru\cyrt\cyrv\cyre\cyrr\cyrzh\cyrd.}%
        \crefname@preamble{definition}%
          {\cyro\cyrp\cyrr\cyre\cyrd\cyre\cyrl\cyre\cyrn.}%
          {\cyro\cyrp\cyrr\cyre\cyrd\cyre\cyrl\cyre\cyrn.}%
        \crefname@preamble{result}%
          {\cyrr\cyre\cyrz\cyru\cyrl\cyrsftsn\cyrt.}%
          {\cyrr\cyre\cyrz\cyru\cyrl\cyrsftsn\cyrt.}%
        \crefname@preamble{example}%
          {\cyrp\cyrr\cyri\cyrm.}%
          {\cyrp\cyrr\cyri\cyrm\cyre\cyrr.}%
        \crefname@preamble{remark}%
          {\cyrp\cyrr\cyri\cyrm\cyre\cyrch.}%
          {\cyrp\cyrr\cyri\cyrm\cyre\cyrch.}%
        \crefname@preamble{note}%
          {\cyrz\cyra\cyrm\cyre\cyrt\cyrk.}%
          {\cyrz\cyra\cyrm\cyre\cyrt\cyrk.}%
        \crefname@preamble{algorithm}%
          {\cyra\cyrl\cyrg.}%
          {\cyra\cyrl\cyrg.}%
        \crefname@preamble{listing}%
          {\cyrl\cyri\cyrs\cyrt\cyri\cyrn.}%
          {\cyrl\cyri\cyrs\cyrt\cyri\cyrn\cyrg.}%
        \crefname@preamble{line}%
          {\cyrs\cyrt\cyrr\cyrk.}%
          {\cyrs\cyrt\cyrr\cyrk.}%
      \else%  abbrev unset
        \crefname@preamble{equation}%
          {\cyrf\cyro\cyrr\cyrm\cyru\cyrl\cyra}%
          {\cyrf\cyro\cyrr\cyrm\cyru\cyrl\cyrery}%
        \crefname@preamble{figure}%
          {\cyrr\cyri\cyrs\cyru\cyrn\cyro\cyrk}%
          {\cyrr\cyri\cyrs\cyru\cyrn\cyrk\cyri}%
        \crefname@preamble{table}%
          {\cyrt\cyra\cyrb\cyrl\cyri\cyrc\cyra}%
          {\cyrt\cyra\cyrb\cyrl\cyri\cyrc\cyrery}%
        \crefname@preamble{enumi}%
          {\cyrp\cyru\cyrn\cyrk\cyrt}%
          {\cyrp\cyru\cyrn\cyrk\cyrt\cyrery}%
        \crefname@preamble{chapter}%
          {\cyrg\cyrl\cyra\cyrv\cyra}%
          {\cyrg\cyrl\cyra\cyrv\cyrery}%
        \crefname@preamble{section}%
          {\cyrr\cyra\cyrz\cyrd\cyre\cyrl}%
          {\cyrr\cyra\cyrz\cyrd\cyre\cyrl\cyrery}%
        \crefname@preamble{appendix}%
          {\cyrp\cyrr\cyri\cyrl\cyro\cyrzh\cyre\cyrn\cyri\cyre}%
          {\cyrp\cyrr\cyri\cyrl\cyro\cyrzh\cyre\cyrn\cyri\cyrya}%
        \crefname@preamble{footnote}%
          {\cyrs\cyrn\cyro\cyrs\cyrk\cyra}%
          {\cyrs\cyrn\cyro\cyrs\cyrk\cyri}%
        \crefname@preamble{theorem}%
          {\cyrt\cyre\cyro\cyrr\cyre\cyrm\cyra}%
          {\cyrt\cyre\cyro\cyrr\cyre\cyrm\cyrery}%
        \crefname@preamble{lemma}%
          {\cyrl\cyre\cyrm\cyrm\cyra}%
          {\cyrl\cyre\cyrm\cyrm\cyrery}%
        \crefname@preamble{corollary}%
          {\cyrv\cyrery\cyrv\cyro\cyrd}%
          {\cyrv\cyrery\cyrv\cyro\cyrd\cyrery}%
        \crefname@preamble{proposition}%
          {\cyru\cyrt\cyrv\cyre\cyrr\cyrzh\cyrd\cyre\cyrn\cyri\cyre}%
          {\cyru\cyrt\cyrv\cyre\cyrr\cyrzh\cyrd\cyre\cyrn\cyri\cyrya}%
        \crefname@preamble{definition}%
          {\cyro\cyrp\cyrr\cyre\cyrd\cyre\cyrl\cyre\cyrn\cyri\cyre}%
          {\cyro\cyrp\cyrr\cyre\cyrd\cyre\cyrl\cyre\cyrn\cyri\cyrya}%
        \crefname@preamble{result}%
          {\cyrr\cyre\cyrz\cyru\cyrl\cyrsftsn\cyrt\cyra\cyrt}%
          {\cyrr\cyre\cyrz\cyru\cyrl\cyrsftsn\cyrt\cyra\cyrt\cyrery}%
        \crefname@preamble{example}%
          {\cyrp\cyrr\cyri\cyrm\cyre\cyrr}%
          {\cyrp\cyrr\cyri\cyrm\cyre\cyrr\cyrery}%
        \crefname@preamble{remark}%
          {\cyrp\cyrr\cyri\cyrm\cyre\cyrch\cyra\cyrn\cyri\cyre}%
          {\cyrp\cyrr\cyri\cyrm\cyre\cyrch\cyra\cyrn\cyri\cyrya}%
        \crefname@preamble{note}%
          {\cyrz\cyra\cyrm\cyre\cyrt\cyrk\cyra}%
          {\cyrz\cyra\cyrm\cyre\cyrt\cyrk\cyri}%
        \crefname@preamble{algorithm}%
          {\cyra\cyrl\cyrg\cyro\cyrr\cyri\cyrt\cyrm}%
          {\cyra\cyrl\cyrg\cyro\cyrr\cyri\cyrt\cyrm\cyrery}%
        \crefname@preamble{listing}%
          {\cyrl\cyri\cyrs\cyrt\cyri\cyrn\cyrg}%
          {\cyrl\cyri\cyrs\cyrt\cyri\cyrn\cyrg\cyri}%
        \crefname@preamble{line}%
          {\cyrs\cyrt\cyrr\cyro\cyrk\cyra}%
          {\cyrs\cyrt\cyrr\cyro\cyrk\cyri}%
      \fi%
      \crefname@preamble{page}%
        {\cyrs\cyrt\cyrr\cyra\cyrn\cyri\cyrc\cyre}%
        {\cyrs\cyrt\cyrr\cyra\cyrn\cyri\cyrc\cyra\cyrh}%
      \crefname@preamble{part}%
        {\cyrch\cyra\cyrs\cyrt\cyrsftsn}%
        {\cyrch\cyra\cyrs\cyrt\cyri}%
    \fi%
    \def\cref@language{russian}%
  }}% end \DeclareOption and \AtBeginDocument
%    \end{macrocode}
%
% If using \package{babel} and the corresponding option is set, or if
% using \package{polyglossia} and the language has been loaded, add
% format definition commands to \cmd{\extras}\meta{language} or
% \cmd{\captions}\meta{language} so that language switching commands will
% change the cross-reference formats appropriately.
%    \begin{macrocode}
\cref@addlanguagedefs{russian}{%
  \PackageInfo{cleveref}{loaded `russian' language definitions}%
  \renewcommand{\crefrangeconjunction}{--}%
  \renewcommand\crefrangepreconjunction{}%
  \renewcommand\crefrangepostconjunction{}%
  \renewcommand{\crefpairconjunction}{ \cyri\nobreakspace}%
  \renewcommand{\crefmiddleconjunction}{, }%
  \renewcommand{\creflastconjunction}{ \cyri\nobreakspace}%
  \renewcommand{\crefpairgroupconjunction}{ \cyri\nobreakspace}%
  \renewcommand{\crefmiddlegroupconjunction}{, }%
  \renewcommand{\creflastgroupconjunction}%
    {, \cyra\ \cyrt\cyra\cyrk\cyrzh\cyre\nobreakspace}%
 %
    \Crefname{page}%
    {\CYRS\cyrt\cyrr\cyra\cyrn\cyri\cyrc\cyra}%
    {\CYRS\cyrt\cyrr\cyra\cyrn\cyri\cyrc\cyrery}%
  \Crefname{equation}%
    {\CYRF\cyro\cyrr\cyrm\cyru\cyrl\cyra}%
    {\CYRF\cyro\cyrr\cyrm\cyru\cyrl\cyrery}%
  \Crefname{figure}%
    {\CYRR\cyri\cyrs\cyru\cyrn\cyro\cyrk}%
    {\CYRR\cyri\cyrs\cyru\cyrn\cyrk\cyri}%
  \Crefname{subfigure}%
    {\CYRR\cyri\cyrs\cyru\cyrn\cyro\cyrk}%
    {\CYRR\cyri\cyrs\cyru\cyrn\cyrk\cyri}%
  \Crefname{table}%
    {\CYRT\cyra\cyrb\cyrl\cyri\cyrc\cyra}%
    {\CYRT\cyra\cyrb\cyrl\cyri\cyrc\cyrery}%
  \Crefname{subtable}%
    {\CYRT\cyra\cyrb\cyrl\cyri\cyrc\cyra}%
    {\CYRT\cyra\cyrb\cyrl\cyri\cyrc\cyrery}%
  \Crefname{part}%
    {\CYRCH\cyra\cyrs\cyrt\cyrsftsn}%
    {\CYRCH\cyra\cyrs\cyrt\cyri}%
  \Crefname{chapter}%
    {\CYRG\cyrl\cyra\cyrv\cyra}%
    {\CYRG\cyrl\cyra\cyrv\cyrery}%
  \Crefname{section}%
    {\CYRR\cyra\cyrz\cyrd\cyre\cyrl}%
    {\CYRR\cyra\cyrz\cyrd\cyre\cyrl\cyrery}%
  \Crefname{subsection}%
    {\CYRR\cyra\cyrz\cyrd\cyre\cyrl}%
    {\CYRR\cyra\cyrz\cyrd\cyre\cyrl\cyrery}%
  \Crefname{subsubsection}%
    {\CYRR\cyra\cyrz\cyrd\cyre\cyrl}%
    {\CYRR\cyra\cyrz\cyrd\cyre\cyrl\cyrery}%
  \Crefname{appendix}%
    {\CYRP\cyrr\cyri\cyrl\cyro\cyrzh\cyre\cyrn\cyri\cyre}%
    {\CYRP\cyrr\cyri\cyrl\cyro\cyrzh\cyre\cyrn\cyri\cyrya}%
  \Crefname{subappendix}%
    {\CYRP\cyrr\cyri\cyrl\cyro\cyrzh\cyre\cyrn\cyri\cyre}%
    {\CYRP\cyrr\cyri\cyrl\cyro\cyrzh\cyre\cyrn\cyri\cyrya}%
  \Crefname{subsubappendix}%
    {\CYRP\cyrr\cyri\cyrl\cyro\cyrzh\cyre\cyrn\cyri\cyre}%
    {\CYRP\cyrr\cyri\cyrl\cyro\cyrzh\cyre\cyrn\cyri\cyrya}%
  \Crefname{subsubsubappendix}%
    {\CYRP\cyrr\cyri\cyrl\cyro\cyrzh\cyre\cyrn\cyri\cyre}%
    {\CYRP\cyrr\cyri\cyrl\cyro\cyrzh\cyre\cyrn\cyri\cyrya}%
  \Crefname{enumi}%
    {\CYRP\cyru\cyrn\cyrk\cyrt}%
    {\CYRP\cyru\cyrn\cyrk\cyrt\cyrery}%
  \Crefname{enumii}%
    {\CYRP\cyru\cyrn\cyrk\cyrt}%
    {\CYRP\cyru\cyrn\cyrk\cyrt\cyrery}%
  \Crefname{enumiii}%
    {\CYRP\cyru\cyrn\cyrk\cyrt}%
    {\CYRP\cyru\cyrn\cyrk\cyrt\cyrery}%
  \Crefname{enumiv}%
    {\CYRP\cyru\cyrn\cyrk\cyrt}%
    {\CYRP\cyru\cyrn\cyrk\cyrt\cyrery}%
  \Crefname{enumv}%
    {\CYRP\cyru\cyrn\cyrk\cyrt}%
    {\CYRP\cyru\cyrn\cyrk\cyrt\cyrery}%
  \Crefname{footnote}%
    {\CYRS\cyrn\cyro\cyrs\cyrk\cyra}%
    {\CYRS\cyrn\cyro\cyrs\cyrk\cyri}%
  \Crefname{theorem}%
    {\CYRT\cyre\cyro\cyrr\cyre\cyrm\cyra}%
    {\CYRT\cyre\cyro\cyrr\cyre\cyrm\cyrery}%
  \Crefname{lemma}%
    {\CYRL\cyre\cyrm\cyrm\cyra}%
    {\CYRL\cyre\cyrm\cyrm\cyrery}%
  \Crefname{corollary}%
    {\CYRV\cyrery\cyrv\cyro\cyrd}%
    {\CYRV\cyrery\cyrv\cyro\cyrd\cyrery}%
  \Crefname{proposition}%
    {\CYRU\cyrt\cyrv\cyre\cyrr\cyrzh\cyrd\cyre\cyrn\cyri\cyre}%
    {\CYRU\cyrt\cyrv\cyre\cyrr\cyrzh\cyrd\cyre\cyrn\cyri\cyrya}%
  \Crefname{definition}%
    {\CYRO\cyrp\cyrr\cyre\cyrd\cyre\cyrl\cyre\cyrn\cyri\cyre}%
    {\CYRO\cyrp\cyrr\cyre\cyrd\cyre\cyrl\cyre\cyrn\cyri\cyrya}%
  \Crefname{result}%
    {\CYRR\cyre\cyrz\cyru\cyrl\cyrsftsn\cyrt\cyra\cyrt}%
    {\CYRR\cyre\cyrz\cyru\cyrl\cyrsftsn\cyrt\cyra\cyrt\cyrery}%
  \Crefname{example}%
    {\CYRP\cyrr\cyri\cyrm\cyre\cyrr}%
    {\CYRP\cyrr\cyri\cyrm\cyre\cyrr\cyrery}%
  \Crefname{remark}%
    {\CYRP\cyrr\cyri\cyrm\cyre\cyrch\cyra\cyrn\cyri\cyre}%
    {\CYRP\cyrr\cyri\cyrm\cyre\cyrch\cyra\cyrn\cyri\cyrya}%
  \Crefname{note}%
    {\CYRZ\cyra\cyrm\cyre\cyrt\cyrk\cyra}%
    {\CYRZ\cyra\cyrm\cyre\cyrt\cyrk\cyri}%
  \Crefname{algorithm}%
    {\CYRA\cyrl\cyrg\cyro\cyrr\cyri\cyrt\cyrm}%
    {\CYRA\cyrl\cyrg\cyro\cyrr\cyri\cyrt\cyrm\cyrery}%
  \Crefname{listing}%
    {\CYRL\cyri\cyrs\cyrt\cyri\cyrn\cyrg}%
    {\CYRL\cyri\cyrs\cyrt\cyri\cyrn\cyrg\cyri}%
  \Crefname{line}%
    {\CYRS\cyrt\cyrr\cyro\cyrk\cyra}%
    {\CYRS\cyrt\cyrr\cyro\cyrk\cyri}%
 %
  \if@cref@capitalise%  capitalise set
    \if@cref@abbrev%  abbrev set
      \crefname{equation}%
        {\CYRF-\cyrl.}%
        {\CYRF-\cyrl.}%
      \crefname{figure}%
        {\CYRR\cyri\cyrs.}%
        {\CYRR\cyri\cyrs.}%
      \crefname{subfigure}%
        {\CYRR\cyri\cyrs.}%
        {\CYRR\cyri\cyrs.}%
      \crefname{table}%
        {\CYRT\cyra\cyrb\cyrl.}%
        {\CYRT\cyra\cyrb\cyrl.}%
      \crefname{subtable}%
        {\CYRT\cyra\cyrb\cyrl.}%
        {\CYRT\cyra\cyrb\cyrl.}%
      \crefname{enumi}%
        {\CYRP.}%
        {\CYRP.\cyrp.}%
      \crefname{enumii}%
        {\CYRP.}%
        {\CYRP.\cyrp.}%
      \crefname{enumiii}%
        {\CYRP.}%
        {\CYRP.\cyrp.}%
      \crefname{enumiv}%
        {\CYRP.}%
        {\CYRP.\cyrp.}%
      \crefname{enumv}%
        {\CYRP.}%
        {\CYRP.\cyrp.}%
    \else%  abbrev unset
      \crefname{equation}%
        {\CYRF\cyro\cyrr\cyrm\cyru\cyrl\cyra}%
        {\CYRF\cyro\cyrr\cyrm\cyru\cyrl\cyrery}%
      \crefname{figure}%
        {\CYRR\cyri\cyrs\cyru\cyrn\cyro\cyrk}%
        {\CYRR\cyri\cyrs\cyru\cyrn\cyrk\cyri}%
      \crefname{subfigure}%
        {\CYRR\cyri\cyrs\cyru\cyrn\cyro\cyrk}%
        {\CYRR\cyri\cyrs\cyru\cyrn\cyrk\cyri}%
      \crefname{table}%
        {\CYRT\cyra\cyrb\cyrl\cyri\cyrc\cyra}%
        {\CYRT\cyra\cyrb\cyrl\cyri\cyrc\cyrery}%
      \crefname{subtable}%
        {\CYRT\cyra\cyrb\cyrl\cyri\cyrc\cyra}%
        {\CYRT\cyra\cyrb\cyrl\cyri\cyrc\cyrery}%
      \crefname{enumi}%
        {\CYRP\cyru\cyrn\cyrk\cyrt}%
        {\CYRP\cyru\cyrn\cyrk\cyrt\cyrery}%
      \crefname{enumii}%
        {\CYRP\cyru\cyrn\cyrk\cyrt}%
        {\CYRP\cyru\cyrn\cyrk\cyrt\cyrery}%
      \crefname{enumiii}%
        {\CYRP\cyru\cyrn\cyrk\cyrt}%
        {\CYRP\cyru\cyrn\cyrk\cyrt\cyrery}%
      \crefname{enumiv}%
        {\CYRP\cyru\cyrn\cyrk\cyrt}%
        {\CYRP\cyru\cyrn\cyrk\cyrt\cyrery}%
      \crefname{enumv}%
        {\CYRP\cyru\cyrn\cyrk\cyrt}%
        {\CYRP\cyru\cyrn\cyrk\cyrt\cyrery}%
    \fi%
    \crefname{page}%
      {\CYRS\cyrt\cyrr\cyra\cyrn\cyri\cyrc\cyra}%
      {\CYRS\cyrt\cyrr\cyra\cyrn\cyri\cyrc\cyrery}%
    \crefname{part}%
      {\CYRCH\cyra\cyrs\cyrt\cyrsftsn}%
      {\CYRCH\cyra\cyrs\cyrt\cyri}%
    \crefname{chapter}%
      {\CYRG\cyrl\cyra\cyrv\cyra}%
      {\CYRG\cyrl\cyra\cyrv\cyrery}%
    \crefname{section}%
      {\CYRR\cyra\cyrz\cyrd\cyre\cyrl}%
      {\CYRR\cyra\cyrz\cyrd\cyre\cyrl\cyrery}%
    \crefname{subsection}%
      {\CYRR\cyra\cyrz\cyrd\cyre\cyrl}%
      {\CYRR\cyra\cyrz\cyrd\cyre\cyrl\cyrery}%
    \crefname{subsubsection}%
      {\CYRR\cyra\cyrz\cyrd\cyre\cyrl}%
      {\CYRR\cyra\cyrz\cyrd\cyre\cyrl\cyrery}%
    \crefname{appendix}%
      {\CYRP\cyrr\cyri\cyrl\cyro\cyrzh\cyre\cyrn\cyri\cyre}%
      {\CYRP\cyrr\cyri\cyrl\cyro\cyrzh\cyre\cyrn\cyri\cyrya}%
    \crefname{subappendix}%
      {\CYRP\cyrr\cyri\cyrl\cyro\cyrzh\cyre\cyrn\cyri\cyre}%
      {\CYRP\cyrr\cyri\cyrl\cyro\cyrzh\cyre\cyrn\cyri\cyrya}%
    \crefname{subsubappendix}%
      {\CYRP\cyrr\cyri\cyrl\cyro\cyrzh\cyre\cyrn\cyri\cyre}%
      {\CYRP\cyrr\cyri\cyrl\cyro\cyrzh\cyre\cyrn\cyri\cyrya}%
    \crefname{subsubsubappendix}%
      {\CYRP\cyrr\cyri\cyrl\cyro\cyrzh\cyre\cyrn\cyri\cyre}%
      {\CYRP\cyrr\cyri\cyrl\cyro\cyrzh\cyre\cyrn\cyri\cyrya}%
    \crefname{footnote}%
      {\CYRS\cyrn\cyro\cyrs\cyrk\cyra}%
      {\CYRS\cyrn\cyro\cyrs\cyrk\cyri}%
    \crefname{theorem}%
      {\CYRT\cyre\cyro\cyrr\cyre\cyrm\cyra}%
      {\CYRT\cyre\cyro\cyrr\cyre\cyrm\cyrery}%
    \crefname{lemma}%
      {\CYRL\cyre\cyrm\cyrm\cyra}%
      {\CYRL\cyre\cyrm\cyrm\cyrery}%
    \crefname{corollary}%
      {\CYRV\cyrery\cyrv\cyro\cyrd}%
      {\CYRV\cyrery\cyrv\cyro\cyrd\cyrery}%
    \crefname{proposition}%
      {\CYRU\cyrt\cyrv\cyre\cyrr\cyrzh\cyrd\cyre\cyrn\cyri\cyre}%
      {\CYRU\cyrt\cyrv\cyre\cyrr\cyrzh\cyrd\cyre\cyrn\cyri\cyrya}%
    \crefname{definition}%
      {\CYRO\cyrp\cyrr\cyre\cyrd\cyre\cyrl\cyre\cyrn\cyri\cyre}%
      {\CYRO\cyrp\cyrr\cyre\cyrd\cyre\cyrl\cyre\cyrn\cyri\cyrya}%
    \crefname{result}%
      {\CYRR\cyre\cyrz\cyru\cyrl\cyrsftsn\cyrt\cyra\cyrt}%
      {\CYRR\cyre\cyrz\cyru\cyrl\cyrsftsn\cyrt\cyra\cyrt\cyrery}%
    \crefname{example}%
      {\CYRP\cyrr\cyri\cyrm\cyre\cyrr}%
      {\CYRP\cyrr\cyri\cyrm\cyre\cyrr\cyrery}%
    \crefname{remark}%
      {\CYRP\cyrr\cyri\cyrm\cyre\cyrch\cyra\cyrn\cyri\cyre}%
      {\CYRP\cyrr\cyri\cyrm\cyre\cyrch\cyra\cyrn\cyri\cyrya}%
    \crefname{note}%
      {\CYRZ\cyra\cyrm\cyre\cyrt\cyrk\cyra}%
      {\CYRZ\cyra\cyrm\cyre\cyrt\cyrk\cyri}%
    \crefname{algorithm}%
      {\CYRA\cyrl\cyrg\cyro\cyrr\cyri\cyrt\cyrm}%
      {\CYRA\cyrl\cyrg\cyro\cyrr\cyri\cyrt\cyrm\cyrery}%
    \crefname{listing}%
      {\CYRL\cyri\cyrs\cyrt\cyri\cyrn\cyrg}%
      {\CYRL\cyri\cyrs\cyrt\cyri\cyrn\cyrg\cyri}%
    \crefname{line}%
      {\CYRS\cyrt\cyrr\cyro\cyrk\cyra}%
      {\CYRS\cyrt\cyrr\cyro\cyrk\cyri}%
 %
  \else%  capitalise unset
    \if@cref@abbrev%  abbrev set
      \crefname{equation}%
        {\cyrf-\cyrl.}%
        {\cyrf-\cyrl.}%
      \crefname{chapter}%
        {\cyrg\cyrl\cyra\cyrv.}%
        {\cyrg\cyrl\cyra\cyrv.}%
      \crefname{section}%
        {\cyrr\cyra\cyrz\cyrd.}%
        {\cyrr\cyra\cyrz\cyrd\cyre\cyrl.}%
      \crefname{subsection}%
        {\cyrr\cyra\cyrz\cyrd.}%
        {\cyrr\cyra\cyrz\cyrd\cyre\cyrl.}%
      \crefname{subsubsection}%
        {\cyrr\cyra\cyrz\cyrd.}%
        {\cyrr\cyra\cyrz\cyrd\cyre\cyrl.}%
      \crefname{appendix}%
        {\cyrp\cyrr\cyri\cyrl\cyro\cyrzh.}%
        {\cyrp\cyrr\cyri\cyrl\cyro\cyrzh.}%
      \crefname{subappendix}%
        {\cyrp\cyrr\cyri\cyrl\cyro\cyrzh.}%
        {\cyrp\cyrr\cyri\cyrl\cyro\cyrzh.}%
      \crefname{subsubappendix}%
        {\cyrp\cyrr\cyri\cyrl\cyro\cyrzh.}%
        {\cyrp\cyrr\cyri\cyrl\cyro\cyrzh.}%
      \crefname{subsubsubappendix}%
        {\cyrp\cyrr\cyri\cyrl\cyro\cyrzh.}%
        {\cyrp\cyrr\cyri\cyrl\cyro\cyrzh.}%
      \crefname{enumi}%
        {\cyrp.}%
        {\cyrp.\cyrp.}%
      \crefname{enumii}%
        {\cyrp.}%
        {\cyrp.\cyrp.}%
      \crefname{enumiii}%
        {\cyrp.}%
        {\cyrp.\cyrp.}%
      \crefname{enumiv}%
        {\cyrp.}%
        {\cyrp.\cyrp.}%
      \crefname{enumv}%
        {\cyrp.}%
        {\cyrp.\cyrp.}%
      \crefname{footnote}%
        {\cyrs\cyrn\cyro\cyrs\cyrk.}%
        {\cyrs\cyrn\cyro\cyrs\cyrk.}%
      \crefname{figure}%
        {\cyrr\cyri\cyrs.}%
        {\cyrr\cyri\cyrs.}%
      \crefname{subfigure}%
        {\cyrr\cyri\cyrs.}%
        {\cyrr\cyri\cyrs.}%
      \crefname{table}%
        {\cyrt\cyra\cyrb\cyrl.}%
        {\cyrt\cyra\cyrb\cyrl.}%
      \crefname{subtable}%
        {\cyrt\cyra\cyrb\cyrl.}%
        {\cyrt\cyra\cyrb\cyrl.}%
      \crefname{theorem}%
        {\cyrt\cyre\cyro\cyrr\cyre\cyrm.}%
        {\cyrt\cyre\cyro\cyrr\cyre\cyrm.}%
      \crefname{lemma}%
        {\cyrl\cyre\cyrm\cyrm.}%
        {\cyrl\cyre\cyrm\cyrm.}%
      \crefname{corollary}%
        {\cyrv\cyrery\cyrv\cyro\cyrd}%
        {\cyrv\cyrery\cyrv\cyro\cyrd.}%
      \crefname{proposition}%
        {\cyru\cyrt\cyrv\cyre\cyrr\cyrzh\cyrd.}%
        {\cyru\cyrt\cyrv\cyre\cyrr\cyrzh\cyrd.}%
      \crefname{definition}%
        {\cyro\cyrp\cyrr\cyre\cyrd\cyre\cyrl\cyre\cyrn.}%
        {\cyro\cyrp\cyrr\cyre\cyrd\cyre\cyrl\cyre\cyrn.}%
      \crefname{result}%
        {\cyrr\cyre\cyrz\cyru\cyrl\cyrsftsn\cyrt.}%
        {\cyrr\cyre\cyrz\cyru\cyrl\cyrsftsn\cyrt.}%
      \crefname{example}%
        {\cyrp\cyrr\cyri\cyrm.}%
        {\cyrp\cyrr\cyri\cyrm\cyre\cyrr.}%
      \crefname{remark}%
        {\cyrp\cyrr\cyri\cyrm\cyre\cyrch.}%
        {\cyrp\cyrr\cyri\cyrm\cyre\cyrch.}%
      \crefname{note}%
        {\cyrz\cyra\cyrm\cyre\cyrt\cyrk.}%
        {\cyrz\cyra\cyrm\cyre\cyrt\cyrk.}%
      \crefname{algorithm}%
        {\cyra\cyrl\cyrg.}%
        {\cyra\cyrl\cyrg.}%
      \crefname{listing}%
        {\cyrl\cyri\cyrs\cyrt\cyri\cyrn.}%
        {\cyrl\cyri\cyrs\cyrt\cyri\cyrn\cyrg.}%
      \crefname{line}%
        {\cyrs\cyrt\cyrr\cyrk.}%
        {\cyrs\cyrt\cyrr\cyrk.}%
    \else%  abbrev unset
      \crefname{equation}%
        {\cyrf\cyro\cyrr\cyrm\cyru\cyrl\cyra}%
        {\cyrf\cyro\cyrr\cyrm\cyru\cyrl\cyrery}%
      \crefname{figure}%
        {\cyrr\cyri\cyrs\cyru\cyrn\cyro\cyrk}%
        {\cyrr\cyri\cyrs\cyru\cyrn\cyrk\cyri}%
      \crefname{subfigure}%
        {\cyrr\cyri\cyrs\cyru\cyrn\cyro\cyrk}%
        {\cyrr\cyri\cyrs\cyru\cyrn\cyrk\cyri}%
      \crefname{table}%
        {\cyrt\cyra\cyrb\cyrl\cyri\cyrc\cyra}%
        {\cyrt\cyra\cyrb\cyrl\cyri\cyrc\cyrery}%
      \crefname{subtable}%
        {\cyrt\cyra\cyrb\cyrl\cyri\cyrc\cyra}%
        {\cyrt\cyra\cyrb\cyrl\cyri\cyrc\cyrery}%
      \crefname{enumi}%
        {\cyrp\cyru\cyrn\cyrk\cyrt}%
        {\cyrp\cyru\cyrn\cyrk\cyrt\cyrery}%
      \crefname{enumii}%
        {\cyrp\cyru\cyrn\cyrk\cyrt}%
        {\cyrp\cyru\cyrn\cyrk\cyrt\cyrery}%
      \crefname{enumiii}%
        {\cyrp\cyru\cyrn\cyrk\cyrt}%
        {\cyrp\cyru\cyrn\cyrk\cyrt\cyrery}%
      \crefname{enumiv}%
        {\cyrp\cyru\cyrn\cyrk\cyrt}%
        {\cyrp\cyru\cyrn\cyrk\cyrt\cyrery}%
      \crefname{enumv}%
        {\cyrp\cyru\cyrn\cyrk\cyrt}%
        {\cyrp\cyru\cyrn\cyrk\cyrt\cyrery}%
      \crefname{chapter}%
        {\cyrg\cyrl\cyra\cyrv\cyra}%
        {\cyrg\cyrl\cyra\cyrv\cyrery}%
      \crefname{section}%
        {\cyrr\cyra\cyrz\cyrd\cyre\cyrl}%
        {\cyrr\cyra\cyrz\cyrd\cyre\cyrl\cyrery}%
      \crefname{subsection}%
        {\cyrr\cyra\cyrz\cyrd\cyre\cyrl}%
        {\cyrr\cyra\cyrz\cyrd\cyre\cyrl\cyrery}%
      \crefname{subsubsection}%
        {\cyrr\cyra\cyrz\cyrd\cyre\cyrl}%
        {\cyrr\cyra\cyrz\cyrd\cyre\cyrl\cyrery}%
      \crefname{appendix}%
        {\cyrp\cyrr\cyri\cyrl\cyro\cyrzh\cyre\cyrn\cyri\cyre}%
        {\cyrp\cyrr\cyri\cyrl\cyro\cyrzh\cyre\cyrn\cyri\cyrya}%
      \crefname{subappendix}%
        {\cyrp\cyrr\cyri\cyrl\cyro\cyrzh\cyre\cyrn\cyri\cyre}%
        {\cyrp\cyrr\cyri\cyrl\cyro\cyrzh\cyre\cyrn\cyri\cyrya}%
      \crefname{subsubappendix}%
        {\cyrp\cyrr\cyri\cyrl\cyro\cyrzh\cyre\cyrn\cyri\cyre}%
        {\cyrp\cyrr\cyri\cyrl\cyro\cyrzh\cyre\cyrn\cyri\cyrya}%
      \crefname{subsubsubappendix}%
        {\cyrp\cyrr\cyri\cyrl\cyro\cyrzh\cyre\cyrn\cyri\cyre}%
        {\cyrp\cyrr\cyri\cyrl\cyro\cyrzh\cyre\cyrn\cyri\cyrya}%
      \crefname{footnote}%
        {\cyrs\cyrn\cyro\cyrs\cyrk\cyra}%
        {\cyrs\cyrn\cyro\cyrs\cyrk\cyri}%
      \crefname{theorem}%
        {\cyrt\cyre\cyro\cyrr\cyre\cyrm\cyra}%
        {\cyrt\cyre\cyro\cyrr\cyre\cyrm\cyrery}%
      \crefname{lemma}%
        {\cyrl\cyre\cyrm\cyrm\cyra}%
        {\cyrl\cyre\cyrm\cyrm\cyrery}%
      \crefname{corollary}%
        {\cyrv\cyrery\cyrv\cyro\cyrd}%
        {\cyrv\cyrery\cyrv\cyro\cyrd\cyrery}%
      \crefname{proposition}%
        {\cyru\cyrt\cyrv\cyre\cyrr\cyrzh\cyrd\cyre\cyrn\cyri\cyre}%
        {\cyru\cyrt\cyrv\cyre\cyrr\cyrzh\cyrd\cyre\cyrn\cyri\cyrya}%
      \crefname{definition}%
        {\cyro\cyrp\cyrr\cyre\cyrd\cyre\cyrl\cyre\cyrn\cyri\cyre}%
        {\cyro\cyrp\cyrr\cyre\cyrd\cyre\cyrl\cyre\cyrn\cyri\cyrya}%
      \crefname{result}%
        {\cyrr\cyre\cyrz\cyru\cyrl\cyrsftsn\cyrt\cyra\cyrt}%
        {\cyrr\cyre\cyrz\cyru\cyrl\cyrsftsn\cyrt\cyra\cyrt\cyrery}%
      \crefname{example}%
        {\cyrp\cyrr\cyri\cyrm\cyre\cyrr}%
        {\cyrp\cyrr\cyri\cyrm\cyre\cyrr\cyrery}%
      \crefname{remark}%
        {\cyrp\cyrr\cyri\cyrm\cyre\cyrch\cyra\cyrn\cyri\cyre}%
        {\cyrp\cyrr\cyri\cyrm\cyre\cyrch\cyra\cyrn\cyri\cyrya}%
      \crefname{note}%
        {\cyrz\cyra\cyrm\cyre\cyrt\cyrk\cyra}%
        {\cyrz\cyra\cyrm\cyre\cyrt\cyrk\cyri}%
      \crefname{algorithm}%
        {\cyra\cyrl\cyrg\cyro\cyrr\cyri\cyrt\cyrm}%
        {\cyra\cyrl\cyrg\cyro\cyrr\cyri\cyrt\cyrm\cyrery}%
      \crefname{listing}%
        {\cyrl\cyri\cyrs\cyrt\cyri\cyrn\cyrg}%
        {\cyrl\cyri\cyrs\cyrt\cyri\cyrn\cyrg\cyri}%
      \crefname{line}%
        {\cyrs\cyrt\cyrr\cyro\cyrk\cyra}%
        {\cyrs\cyrt\cyrr\cyro\cyrk\cyri}%
    \fi%
    \crefname{page}%
      {\cyrs\cyrt\cyrr\cyra\cyrn\cyri\cyrc\cyre}%
      {\cyrs\cyrt\cyrr\cyra\cyrn\cyri\cyrc\cyra\cyrh}%
    \crefname{part}%
      {\cyrch\cyra\cyrs\cyrt\cyrsftsn}%
      {\cyrch\cyra\cyrs\cyrt\cyri}%
  \fi}% end \cref@loadlanguagedefs
%    \end{macrocode}
%
%
%  \subsubsection{Ukrainian}
% \begin{macro}{ukrainian}
%   Ukrainian translations courtesy of Aleksander Gorohovski.
% \end{macro}
%
% Set up the definitions used at the beginning of the document to define
% the formats created by the document preamble.
%    \begin{macrocode}
\DeclareOption{ukrainian}{%
  \AtBeginDocument{%
    \def\crefrangeconjunction@preamble{--}%
    \def\crefrangepreconjunction@preamble{}%
    \def\crefrangepostconjunction@preamble{}%
    \def\crefpairconjunction@preamble{ \cyrii\nobreakspace}%
    \def\crefmiddleconjunction@preamble{, }%
    \def\creflastconjunction@preamble{ \cyrii\nobreakspace}%
%    \end{macrocode}
% We have to define the group conjunctions explicitly here, rather than
% relying on fall-back definitions in terms of the above conjunctions
% (see \cref{sec:code:default_formats}), in case any other language
% option defines them explicitly and we need to override those.
%    \begin{macrocode}
    \def\crefpairgroupconjunction@preamble{ \cyrt\cyra\nobreakspace}%
    \def\crefmiddlegroupconjunction@preamble{, }%
    \def\creflastgroupconjunction@preamble%
      {, \cyra\ \cyrt\cyra\cyrk\cyro\cyrzh\nobreakspace}%
 %
    \Crefname@preamble{equation}%
      {\CYRF\cyro\cyrr\cyrm\cyru\cyrl\cyra}%
      {\CYRF\cyro\cyrr\cyrm\cyru\cyrl\cyri}%
    \Crefname@preamble{figure}%
      {\CYRR\cyri\cyrs\cyru\cyrn\cyro\cyrk}%
      {\CYRR\cyri\cyrs\cyru\cyrn\cyrk\cyri}%
    \Crefname@preamble{table}%
      {\CYRT\cyra\cyrb\cyrl\cyri\cyrc\cyrya}%
      {\CYRT\cyra\cyrb\cyrl\cyri\cyrc\cyrii}%
    \Crefname@preamble{enumi}%
      {\CYRP\cyru\cyrn\cyrk\cyrt}%
      {\CYRP\cyru\cyrn\cyrk\cyrt\cyri}%
    \Crefname@preamble{chapter}%
      {\CYRG\cyrl\cyra\cyrv\cyra}%
      {\CYRG\cyrl\cyra\cyrv\cyri}%
    \Crefname@preamble{section}%
      {\CYRR\cyro\cyrz\cyrd\cyrii\cyrl}%
      {\CYRR\cyro\cyrz\cyrd\cyrii\cyrl\cyri}%
    \Crefname@preamble{appendix}%
      {\CYRD\cyro\cyrd\cyra\cyrt\cyro\cyrk}%
      {\CYRD\cyro\cyrd\cyra\cyrt\cyrk\cyri}%
    \Crefname@preamble{footnote}%
      {\CYRV\cyri\cyrn\cyro\cyrs\cyrk\cyra}%
      {\CYRV\cyri\cyrn\cyro\cyrs\cyrk\cyri}%
    \Crefname@preamble{theorem}%
      {\CYRT\cyre\cyro\cyrr\cyre\cyrm\cyra}%
      {\CYRT\cyre\cyro\cyrr\cyre\cyrm\cyri}%
    \Crefname@preamble{lemma}%
      {\CYRL\cyre\cyrm\cyrm\cyra}%
      {\CYRL\cyre\cyrm\cyrm\cyri}%
    \Crefname@preamble{corollary}%
      {\CYRV\cyri\cyrs\cyrn\cyro\cyrv\cyro\cyrk}%
      {\CYRV\cyri\cyrs\cyrn\cyro\cyrv\cyrk\cyri}%
    \Crefname@preamble{proposition}%
      {\CYRT\cyrv\cyre\cyrr\cyrd\cyrzh\cyre\cyrn\cyrn\cyrya}%
      {\CYRT\cyrv\cyre\cyrr\cyrd\cyrzh\cyre\cyrn\cyrn\cyrya}%
    \Crefname@preamble{definition}%
      {\CYRV\cyri\cyrz\cyrn\cyra\cyrch\cyre\cyrn\cyrn\cyrya}%
      {\CYRV\cyri\cyrz\cyrn\cyra\cyrch\cyre\cyrn\cyrn\cyrya}%
    \Crefname@preamble{result}%
      {\CYRR\cyre\cyrz\cyru\cyrl\cyrsftsn\cyrt\cyra\cyrt}%
      {\CYRR\cyre\cyrz\cyru\cyrl\cyrsftsn\cyrt\cyra\cyrt\cyri}%
    \Crefname@preamble{example}%
      {\CYRP\cyrr\cyri\cyrk\cyrl\cyra\cyrd}%
      {\CYRP\cyrr\cyri\cyrk\cyrl\cyra\cyrd\cyri}%
    \Crefname@preamble{remark}%
      {\CYRP\cyrr\cyri\cyrm\cyrii\cyrt\cyrk\cyra}%
      {\CYRP\cyrr\cyri\cyrm\cyrii\cyrt\cyrk\cyri}%
    \Crefname@preamble{note}%
      {\CYRZ\cyra\cyrm\cyrii\cyrt\cyrk\cyra}%
      {\CYRZ\cyra\cyrm\cyrii\cyrt\cyrk\cyri}%
    \Crefname@preamble{algorithm}%
      {\CYRA\cyrl\cyrg\cyro\cyrr\cyri\cyrt\cyrm}%
      {\CYRA\cyrl\cyrg\cyro\cyrr\cyri\cyrt\cyrm\cyri}%
    \Crefname@preamble{listing}%
      {\CYRL\cyrii\cyrs\cyrt\cyri\cyrn\cyrg}%
      {\CYRL\cyrii\cyrs\cyrt\cyri\cyrn\cyrg\cyri}%
    \Crefname@preamble{line}%
      {\CYRS\cyrt\cyrr\cyro\cyrk\cyra}%
      {\CYRS\cyrt\cyrr\cyro\cyrk\cyri}%
    \Crefname@preamble{page}%
      {\CYRS\cyrt\cyro\cyrr\cyri\cyrn\cyrk\cyra}%
      {\CYRS\cyrt\cyro\cyrr\cyrii\cyrn\cyrk\cyri}%
    \Crefname@preamble{part}%
      {\CYRCH\cyra\cyrs\cyrt\cyri\cyrn\cyra}%
      {\CYRCH\cyra\cyrs\cyrt\cyri\cyrn\cyri}%
 %
    \if@cref@capitalise%  capitalise set
      \if@cref@abbrev%  abbrev set
        \crefname@preamble{equation}%
          {\CYRF-\cyrl.}%
          {\CYRF-\cyrl.}%
        \crefname@preamble{figure}%
          {\CYRR\cyri\cyrs.}%
          {\CYRR\cyri\cyrs.}%
        \crefname@preamble{table}%
          {\CYRT\cyra\cyrb\cyrl.}%
          {\CYRT\cyra\cyrb\cyrl.}%
        \crefname@preamble{enumi}%
          {\CYRP.}%
          {\CYRP.\cyrp.}%
      \else%
        \crefname@preamble{equation}%
          {\CYRF\cyro\cyrr\cyrm\cyru\cyrl\cyra}%
          {\CYRF\cyro\cyrr\cyrm\cyru\cyrl\cyri}%
        \crefname@preamble{figure}%
          {\CYRR\cyri\cyrs\cyru\cyrn\cyro\cyrk}%
          {\CYRR\cyri\cyrs\cyru\cyrn\cyrk\cyri}%
        \crefname@preamble{table}%
          {\CYRT\cyra\cyrb\cyrl\cyri\cyrc\cyrya}%
          {\CYRT\cyra\cyrb\cyrl\cyri\cyrc\cyrii}%
        \crefname@preamble{enumi}%
          {\CYRP\cyru\cyrn\cyrk\cyrt}%
          {\CYRP\cyru\cyrn\cyrk\cyrt\cyri}%
      \fi%
      \crefname@preamble{chapter}%
        {\CYRG\cyrl\cyra\cyrv\cyra}%
        {\CYRG\cyrl\cyra\cyrv\cyri}%
      \crefname@preamble{section}%
        {\CYRR\cyro\cyrz\cyrd\cyrii\cyrl}%
        {\CYRR\cyro\cyrz\cyrd\cyrii\cyrl\cyri}%
      \crefname@preamble{appendix}%
        {\CYRD\cyro\cyrd\cyra\cyrt\cyro\cyrk}%
        {\CYRD\cyro\cyrd\cyra\cyrt\cyrk\cyri}%
      \crefname@preamble{footnote}%
        {\CYRV\cyri\cyrn\cyro\cyrs\cyrk\cyra}%
        {\CYRV\cyri\cyrn\cyro\cyrs\cyrk\cyri}%
      \crefname@preamble{theorem}%
        {\CYRT\cyre\cyro\cyrr\cyre\cyrm\cyra}%
        {\CYRT\cyre\cyro\cyrr\cyre\cyrm\cyri}%
      \crefname@preamble{lemma}%
        {\CYRL\cyre\cyrm\cyrm\cyra}%
        {\CYRL\cyre\cyrm\cyrm\cyri}%
      \crefname@preamble{corollary}%
        {\CYRV\cyri\cyrs\cyrn\cyro\cyrv\cyro\cyrk}%
        {\CYRV\cyri\cyrs\cyrn\cyro\cyrv\cyrk\cyri}%
      \crefname@preamble{proposition}%
        {\CYRT\cyrv\cyre\cyrr\cyrd\cyrzh\cyre\cyrn\cyrn\cyrya}%
        {\CYRT\cyrv\cyre\cyrr\cyrd\cyrzh\cyre\cyrn\cyrn\cyrya}%
      \crefname@preamble{definition}%
        {\CYRV\cyri\cyrz\cyrn\cyra\cyrch\cyre\cyrn\cyrn\cyrya}%
        {\CYRV\cyri\cyrz\cyrn\cyra\cyrch\cyre\cyrn\cyrn\cyrya}%
      \crefname@preamble{result}%
        {\CYRR\cyre\cyrz\cyru\cyrl\cyrsftsn\cyrt\cyra\cyrt}%
        {\CYRR\cyre\cyrz\cyru\cyrl\cyrsftsn\cyrt\cyra\cyrt\cyri}%
      \crefname@preamble{example}%
        {\CYRP\cyrr\cyri\cyrk\cyrl\cyra\cyrd}%
        {\CYRP\cyrr\cyri\cyrk\cyrl\cyra\cyrd\cyri}%
      \crefname@preamble{remark}%
        {\CYRP\cyrr\cyri\cyrm\cyrii\cyrt\cyrk\cyra}%
        {\CYRP\cyrr\cyri\cyrm\cyrii\cyrt\cyrk\cyri}%
      \crefname@preamble{note}%
        {\CYRZ\cyra\cyrm\cyrii\cyrt\cyrk\cyra}%
        {\CYRZ\cyra\cyrm\cyrii\cyrt\cyrk\cyri}%
      \crefname@preamble{algorithm}%
        {\CYRA\cyrl\cyrg\cyro\cyrr\cyri\cyrt\cyrm}%
        {\CYRA\cyrl\cyrg\cyro\cyrr\cyri\cyrt\cyrm\cyri}%
      \crefname@preamble{listing}%
        {\CYRL\cyrii\cyrs\cyrt\cyri\cyrn\cyrg}%
        {\CYRL\cyrii\cyrs\cyrt\cyri\cyrn\cyrg\cyri}%
      \crefname@preamble{line}%
        {\CYRS\cyrt\cyrr\cyro\cyrk\cyra}%
        {\CYRS\cyrt\cyrr\cyro\cyrk\cyri}%
      \crefname@preamble{page}%
        {\CYRS\cyrt\cyro\cyrr\cyri\cyrn\cyrk\cyra}%
        {\CYRS\cyrt\cyro\cyrr\cyrii\cyrn\cyrk\cyri}%
      \crefname@preamble{part}%
        {\CYRCH\cyra\cyrs\cyrt\cyri\cyrn\cyra}%
        {\CYRCH\cyra\cyrs\cyrt\cyri\cyrn\cyri}%
 %
    \else%  capitalise unset
      \if@cref@abbrev%  abbrev set
        \crefname@preamble{equation}%
          {\cyrf-\cyrl.}%
          {\cyrf-\cyrl.}%
        \crefname@preamble{figure}%
          {\cyrr\cyri\cyrs.}%
          {\cyrr\cyri\cyrs.}%
        \crefname@preamble{table}%
          {\cyrt\cyra\cyrb\cyrl.}%
          {\cyrt\cyra\cyrb\cyrl.}%
        \crefname@preamble{enumi}%
          {\cyrp.}%
          {\cyrp.\cyrp.}%
        \crefname@preamble{chapter}%
          {\cyrg\cyrl\cyra\cyrv.}%
          {\cyrg\cyrl\cyra\cyrv.}%
        \crefname@preamble{section}%
          {\cyrr\cyro\cyrz\cyrd.}%
          {\cyrr\cyro\cyrz\cyrd\cyrii\cyrl.}%
        \crefname@preamble{appendix}%
          {\cyrd\cyro\cyrd\cyra\cyrt.}%
          {\cyrd\cyro\cyrd\cyra\cyrt\cyrk.}%
        \crefname@preamble{footnote}%
          {\cyrv\cyri\cyrn\cyro\cyrs\cyrk.}%
          {\cyrv\cyri\cyrn\cyro\cyrs\cyrk.}%
        \crefname@preamble{theorem}%
          {\cyrt\cyre\cyro\cyrr\cyre\cyrm.}%
          {\cyrt\cyre\cyro\cyrr\cyre\cyrm.}%
        \crefname@preamble{lemma}%
          {\cyrl\cyre\cyrm\cyrm.}%
          {\cyrl\cyre\cyrm\cyrm.}%
        \crefname@preamble{corollary}%
          {\cyrv\cyri\cyrs\cyrn\cyro\cyrv.}%
          {\cyrv\cyri\cyrs\cyrn\cyro\cyrv\cyrk.}%
        \crefname@preamble{proposition}%
          {\cyrt\cyrv\cyre\cyrr\cyrd\cyrzh\cyre\cyrn\cyrn.}%
          {\cyrt\cyrv\cyre\cyrr\cyrd\cyrzh\cyre\cyrn\cyrn.}%
        \crefname@preamble{definition}%
          {\cyrv\cyri\cyrz\cyrn\cyra\cyrch\cyre\cyrn\cyrn.}%
          {\cyrv\cyri\cyrz\cyrn\cyra\cyrch\cyre\cyrn\cyrn.}%
        \crefname@preamble{result}%
          {\cyrr\cyre\cyrz\cyru\cyrl\cyrsftsn\cyrt.}%
          {\cyrr\cyre\cyrz\cyru\cyrl\cyrsftsn\cyrt\cyra\cyrt.}%
        \crefname@preamble{example}%
          {\cyrp\cyrr\cyri\cyrk\cyrl.}%
          {\cyrp\cyrr\cyri\cyrk\cyrl\cyra\cyrd.}%
        \crefname@preamble{remark}%
          {\cyrp\cyrr\cyri\cyrm\cyrii\cyrt.}%
          {\cyrp\cyrr\cyri\cyrm\cyrii\cyrt.}%
        \crefname@preamble{note}%
          {\cyrz\cyra\cyrm\cyrii\cyrt.}%
          {\cyrz\cyra\cyrm\cyrii\cyrt.}%
        \crefname@preamble{algorithm}%
          {\cyra\cyrl\cyrg.}%
          {\cyra\cyrl\cyrg.}%
        \crefname@preamble{listing}%
          {\cyrl\cyrii\cyrs\cyrt\cyri\cyrn.}%
          {\cyrl\cyrii\cyrs\cyrt\cyri\cyrn\cyrg.}%
        \crefname@preamble{line}%
          {\cyrs\cyrt\cyrr\cyrk.}%
          {\cyrs\cyrt\cyrr\cyrk.}%
      \else%  abbrev unset
        \crefname@preamble{equation}%
          {\cyrf\cyro\cyrr\cyrm\cyru\cyrl\cyra}%
          {\cyrf\cyro\cyrr\cyrm\cyru\cyrl\cyri}%
        \crefname@preamble{figure}%
          {\cyrr\cyri\cyrs\cyru\cyrn\cyro\cyrk}%
          {\cyrr\cyri\cyrs\cyru\cyrn\cyrk\cyri}%
        \crefname@preamble{table}%
          {\cyrt\cyra\cyrb\cyrl\cyri\cyrc\cyrya}%
          {\cyrt\cyra\cyrb\cyrl\cyri\cyrc\cyrii}%
        \crefname@preamble{enumi}%
          {\cyrp\cyru\cyrn\cyrk\cyrt}%
          {\cyrp\cyru\cyrn\cyrk\cyrt\cyri}%
        \crefname@preamble{chapter}%
          {\cyrg\cyrl\cyra\cyrv\cyra}%
          {\cyrg\cyrl\cyra\cyrv\cyri}%
        \crefname@preamble{section}%
          {\cyrr\cyro\cyrz\cyrd\cyrii\cyrl}%
          {\cyrr\cyro\cyrz\cyrd\cyrii\cyrl\cyri}%
        \crefname@preamble{appendix}%
          {\cyrd\cyro\cyrd\cyra\cyrt\cyro\cyrk}%
          {\cyrd\cyro\cyrd\cyra\cyrt\cyrk\cyri}%
        \crefname@preamble{footnote}%
          {\cyrv\cyri\cyrn\cyro\cyrs\cyrk\cyra}%
          {\cyrv\cyri\cyrn\cyro\cyrs\cyrk\cyri}%
        \crefname@preamble{theorem}%
          {\cyrt\cyre\cyro\cyrr\cyre\cyrm\cyra}%
          {\cyrt\cyre\cyro\cyrr\cyre\cyrm\cyri}%
        \crefname@preamble{lemma}%
          {\cyrl\cyre\cyrm\cyrm\cyra}%
          {\cyrl\cyre\cyrm\cyrm\cyri}%
        \crefname@preamble{corollary}%
          {\cyrv\cyri\cyrs\cyrn\cyro\cyrv\cyro\cyrk}%
          {\cyrv\cyri\cyrs\cyrn\cyro\cyrv\cyrk\cyri}%
        \crefname@preamble{proposition}%
          {\cyrt\cyrv\cyre\cyrr\cyrd\cyrzh\cyre\cyrn\cyrn\cyrya}%
          {\cyrt\cyrv\cyre\cyrr\cyrd\cyrzh\cyre\cyrn\cyrn\cyrya}%
        \crefname@preamble{definition}%
          {\cyrv\cyri\cyrz\cyrn\cyra\cyrch\cyre\cyrn\cyrn\cyrya}%
          {\cyrv\cyri\cyrz\cyrn\cyra\cyrch\cyre\cyrn\cyrn\cyrya}%
        \crefname@preamble{result}%
          {\cyrr\cyre\cyrz\cyru\cyrl\cyrsftsn\cyrt\cyra\cyrt}%
          {\cyrr\cyre\cyrz\cyru\cyrl\cyrsftsn\cyrt\cyra\cyrt\cyri}%
        \crefname@preamble{example}%
          {\cyrp\cyrr\cyri\cyrk\cyrl\cyra\cyrd}%
          {\cyrp\cyrr\cyri\cyrk\cyrl\cyra\cyrd\cyri}%
        \crefname@preamble{remark}%
          {\cyrp\cyrr\cyri\cyrm\cyrii\cyrt\cyrk\cyra}%
          {\cyrp\cyrr\cyri\cyrm\cyrii\cyrt\cyrk\cyri}%
        \crefname@preamble{note}%
          {\cyrz\cyra\cyrm\cyrii\cyrt\cyrk\cyra}%
          {\cyrz\cyra\cyrm\cyrii\cyrt\cyrk\cyri}%
        \crefname@preamble{algorithm}%
          {\cyra\cyrl\cyrg\cyro\cyrr\cyri\cyrt\cyrm}%
          {\cyra\cyrl\cyrg\cyro\cyrr\cyri\cyrt\cyrm\cyri}%
        \crefname@preamble{listing}%
          {\cyrl\cyrii\cyrs\cyrt\cyri\cyrn\cyrg}%
          {\cyrl\cyrii\cyrs\cyrt\cyri\cyrn\cyrg\cyri}%
        \crefname@preamble{line}%
          {\cyrs\cyrt\cyrr\cyro\cyrk\cyra}%
          {\cyrs\cyrt\cyrr\cyro\cyrk\cyri}%
      \fi%
      \crefname@preamble{page}%
        {\cyrs\cyrt\cyro\cyrr\cyri\cyrn\cyrc\cyrii}%
        {\cyrs\cyrt\cyro\cyrr\cyrii\cyrn\cyrk\cyra\cyrh}%
      \crefname@preamble{part}%
        {\cyrch\cyra\cyrs\cyrt\cyri\cyrn\cyra}%
        {\cyrch\cyra\cyrs\cyrt\cyri\cyrn\cyri}%
    \fi%
    \def\cref@language{ukrainian}%
  }}% end \DeclareOption and \AtBeginDocument
%    \end{macrocode}
%
% If using \package{babel} and the corresponding option is set, or if
% using \package{polyglossia} and the language has been loaded, add
% format definition commands to \cmd{\extras}\meta{language} or
% \cmd{\captions}\meta{language} so that language switching commands will
% change the cross-reference formats appropriately.
%    \begin{macrocode}
\cref@addlanguagedefs{ukrainian}{%
  \PackageInfo{cleveref}{loaded `ukrainian' language definitions}%
  \renewcommand{\crefrangeconjunction}{--}%
  \renewcommand\crefrangepreconjunction{}%
  \renewcommand\crefrangepostconjunction{}%
  \renewcommand{\crefpairconjunction}{ \cyrii\nobreakspace}%
  \renewcommand{\crefmiddleconjunction}{, }%
  \renewcommand{\creflastconjunction}{ \cyrii\nobreakspace}%
  \renewcommand{\crefpairgroupconjunction}%
    { \cyrt\cyra\nobreakspace}%
  \renewcommand{\crefmiddlegroupconjunction}{, }%
  \renewcommand{\creflastgroupconjunction}%
    {, \cyra\ \cyrt\cyra\cyrk\cyro\cyrzh\nobreakspace}%
 %
    \Crefname{equation}%
    {\CYRF\cyro\cyrr\cyrm\cyru\cyrl\cyra}%
    {\CYRF\cyro\cyrr\cyrm\cyru\cyrl\cyri}%
  \Crefname{figure}%
    {\CYRR\cyri\cyrs\cyru\cyrn\cyro\cyrk}%
    {\CYRR\cyri\cyrs\cyru\cyrn\cyrk\cyri}%
  \Crefname{subfigure}%
    {\CYRR\cyri\cyrs\cyru\cyrn\cyro\cyrk}%
    {\CYRR\cyri\cyrs\cyru\cyrn\cyrk\cyri}%
  \Crefname{table}%
    {\CYRT\cyra\cyrb\cyrl\cyri\cyrc\cyrya}%
    {\CYRT\cyra\cyrb\cyrl\cyri\cyrc\cyrii}%
  \Crefname{subtable}%
    {\CYRT\cyra\cyrb\cyrl\cyri\cyrc\cyrya}%
    {\CYRT\cyra\cyrb\cyrl\cyri\cyrc\cyrii}%
  \Crefname{enumi}%
    {\CYRP\cyru\cyrn\cyrk\cyrt}%
    {\CYRP\cyru\cyrn\cyrk\cyrt\cyri}%
  \Crefname{enumii}%
    {\CYRP\cyru\cyrn\cyrk\cyrt}%
    {\CYRP\cyru\cyrn\cyrk\cyrt\cyri}%
  \Crefname{enumiii}%
    {\CYRP\cyru\cyrn\cyrk\cyrt}%
    {\CYRP\cyru\cyrn\cyrk\cyrt\cyri}%
  \Crefname{enumiv}%
    {\CYRP\cyru\cyrn\cyrk\cyrt}%
    {\CYRP\cyru\cyrn\cyrk\cyrt\cyri}%
  \Crefname{enumv}%
    {\CYRP\cyru\cyrn\cyrk\cyrt}%
    {\CYRP\cyru\cyrn\cyrk\cyrt\cyri}%
  \Crefname{chapter}%
    {\CYRG\cyrl\cyra\cyrv\cyra}%
    {\CYRG\cyrl\cyra\cyrv\cyri}%
  \Crefname{section}%
    {\CYRR\cyro\cyrz\cyrd\cyrii\cyrl}%
    {\CYRR\cyro\cyrz\cyrd\cyrii\cyrl\cyri}%
  \Crefname{subsection}%
    {\CYRR\cyro\cyrz\cyrd\cyrii\cyrl}%
    {\CYRR\cyro\cyrz\cyrd\cyrii\cyrl\cyri}%
  \Crefname{subsubsection}%
    {\CYRR\cyro\cyrz\cyrd\cyrii\cyrl}%
    {\CYRR\cyro\cyrz\cyrd\cyrii\cyrl\cyri}%
  \Crefname{appendix}%
    {\CYRD\cyro\cyrd\cyra\cyrt\cyro\cyrk}%
    {\CYRD\cyro\cyrd\cyra\cyrt\cyrk\cyri}%
  \Crefname{subappendix}%
    {\CYRD\cyro\cyrd\cyra\cyrt\cyro\cyrk}%
    {\CYRD\cyro\cyrd\cyra\cyrt\cyrk\cyri}%
  \Crefname{subsubappendix}%
    {\CYRD\cyro\cyrd\cyra\cyrt\cyro\cyrk}%
    {\CYRD\cyro\cyrd\cyra\cyrt\cyrk\cyri}%
  \Crefname{subsubsubappendix}%
    {\CYRD\cyro\cyrd\cyra\cyrt\cyro\cyrk}%
    {\CYRD\cyro\cyrd\cyra\cyrt\cyrk\cyri}%
  \Crefname{footnote}%
    {\CYRV\cyri\cyrn\cyro\cyrs\cyrk\cyra}%
    {\CYRV\cyri\cyrn\cyro\cyrs\cyrk\cyri}%
  \Crefname{theorem}%
    {\CYRT\cyre\cyro\cyrr\cyre\cyrm\cyra}%
    {\CYRT\cyre\cyro\cyrr\cyre\cyrm\cyri}%
  \Crefname{lemma}%
    {\CYRL\cyre\cyrm\cyrm\cyra}%
    {\CYRL\cyre\cyrm\cyrm\cyri}%
  \Crefname{corollary}%
    {\CYRV\cyri\cyrs\cyrn\cyro\cyrv\cyro\cyrk}%
    {\CYRV\cyri\cyrs\cyrn\cyro\cyrv\cyrk\cyri}%
  \Crefname{proposition}%
    {\CYRT\cyrv\cyre\cyrr\cyrd\cyrzh\cyre\cyrn\cyrn\cyrya}%
    {\CYRT\cyrv\cyre\cyrr\cyrd\cyrzh\cyre\cyrn\cyrn\cyrya}%
  \Crefname{definition}%
    {\CYRV\cyri\cyrz\cyrn\cyra\cyrch\cyre\cyrn\cyrn\cyrya}%
    {\CYRV\cyri\cyrz\cyrn\cyra\cyrch\cyre\cyrn\cyrn\cyrya}%
  \Crefname{result}%
    {\CYRR\cyre\cyrz\cyru\cyrl\cyrsftsn\cyrt\cyra\cyrt}%
    {\CYRR\cyre\cyrz\cyru\cyrl\cyrsftsn\cyrt\cyra\cyrt\cyri}%
  \Crefname{example}%
    {\CYRP\cyrr\cyri\cyrk\cyrl\cyra\cyrd}%
    {\CYRP\cyrr\cyri\cyrk\cyrl\cyra\cyrd\cyri}%
  \Crefname{remark}%
    {\CYRP\cyrr\cyri\cyrm\cyrii\cyrt\cyrk\cyra}%
    {\CYRP\cyrr\cyri\cyrm\cyrii\cyrt\cyrk\cyri}%
  \Crefname{note}%
    {\CYRZ\cyra\cyrm\cyrii\cyrt\cyrk\cyra}%
    {\CYRZ\cyra\cyrm\cyrii\cyrt\cyrk\cyri}%
  \Crefname{algorithm}%
    {\CYRA\cyrl\cyrg\cyro\cyrr\cyri\cyrt\cyrm}%
    {\CYRA\cyrl\cyrg\cyro\cyrr\cyri\cyrt\cyrm\cyri}%
  \Crefname{listing}%
    {\CYRL\cyrii\cyrs\cyrt\cyri\cyrn\cyrg}%
    {\CYRL\cyrii\cyrs\cyrt\cyri\cyrn\cyrg\cyri}%
  \Crefname{line}%
    {\CYRS\cyrt\cyrr\cyro\cyrk\cyra}%
    {\CYRS\cyrt\cyrr\cyro\cyrk\cyri}%
  \Crefname{page}%
    {\CYRS\cyrt\cyro\cyrr\cyri\cyrn\cyrk\cyra}%
    {\CYRS\cyrt\cyro\cyrr\cyrii\cyrn\cyrk\cyri}%
  \Crefname{part}%
    {\CYRCH\cyra\cyrs\cyrt\cyri\cyrn\cyra}%
    {\CYRCH\cyra\cyrs\cyrt\cyri\cyrn\cyri}%
 %
  \if@cref@capitalise%  capitalise set
    \if@cref@abbrev%  abbrev set
      \crefname{equation}%
        {\CYRF-\cyrl.}%
        {\CYRF-\cyrl.}%
      \crefname{figure}%
        {\CYRR\cyri\cyrs.}%
        {\CYRR\cyri\cyrs.}%
      \crefname{subfigure}%
        {\CYRR\cyri\cyrs.}%
        {\CYRR\cyri\cyrs.}%
      \crefname{table}%
        {\CYRT\cyra\cyrb\cyrl.}%
        {\CYRT\cyra\cyrb\cyrl.}%
      \crefname{subtable}%
        {\CYRT\cyra\cyrb\cyrl.}%
        {\CYRT\cyra\cyrb\cyrl.}%
      \crefname{enumi}%
        {\CYRP.}%
        {\CYRP.\cyrp.}%
      \crefname{enumii}%
        {\CYRP.}%
        {\CYRP.\cyrp.}%
      \crefname{enumiii}%
        {\CYRP.}%
        {\CYRP.\cyrp.}%
      \crefname{enumiv}%
        {\CYRP.}%
        {\CYRP.\cyrp.}%
      \crefname{enumv}%
        {\CYRP.}%
        {\CYRP.\cyrp.}%
    \else%  abbrev unset
      \crefname{equation}%
        {\CYRF\cyro\cyrr\cyrm\cyru\cyrl\cyra}%
        {\CYRF\cyro\cyrr\cyrm\cyru\cyrl\cyri}%
      \crefname{figure}%
        {\CYRR\cyri\cyrs\cyru\cyrn\cyro\cyrk}%
        {\CYRR\cyri\cyrs\cyru\cyrn\cyrk\cyri}%
      \crefname{subfigure}%
        {\CYRR\cyri\cyrs\cyru\cyrn\cyro\cyrk}%
        {\CYRR\cyri\cyrs\cyru\cyrn\cyrk\cyri}%
      \crefname{table}%
        {\CYRT\cyra\cyrb\cyrl\cyri\cyrc\cyrya}%
        {\CYRT\cyra\cyrb\cyrl\cyri\cyrc\cyrii}%
      \crefname{subtable}%
        {\CYRT\cyra\cyrb\cyrl\cyri\cyrc\cyrya}%
        {\CYRT\cyra\cyrb\cyrl\cyri\cyrc\cyrii}%
      \crefname{enumi}%
        {\CYRP\cyru\cyrn\cyrk\cyrt}%
        {\CYRP\cyru\cyrn\cyrk\cyrt\cyri}%
      \crefname{enumii}%
        {\CYRP\cyru\cyrn\cyrk\cyrt}%
        {\CYRP\cyru\cyrn\cyrk\cyrt\cyri}%
      \crefname{enumiii}%
        {\CYRP\cyru\cyrn\cyrk\cyrt}%
        {\CYRP\cyru\cyrn\cyrk\cyrt\cyri}%
      \crefname{enumiv}%
        {\CYRP\cyru\cyrn\cyrk\cyrt}%
        {\CYRP\cyru\cyrn\cyrk\cyrt\cyri}%
      \crefname{enumv}%
        {\CYRP\cyru\cyrn\cyrk\cyrt}%
        {\CYRP\cyru\cyrn\cyrk\cyrt\cyri}%
    \fi%
    \crefname{chapter}%
      {\CYRG\cyrl\cyra\cyrv\cyra}%
      {\CYRG\cyrl\cyra\cyrv\cyri}%
    \crefname{section}%
      {\CYRR\cyro\cyrz\cyrd\cyrii\cyrl}%
      {\CYRR\cyro\cyrz\cyrd\cyrii\cyrl\cyri}%
    \crefname{subsection}%
      {\CYRR\cyro\cyrz\cyrd\cyrii\cyrl}%
      {\CYRR\cyro\cyrz\cyrd\cyrii\cyrl\cyri}%
    \crefname{subsubsection}%
      {\CYRR\cyro\cyrz\cyrd\cyrii\cyrl}%
      {\CYRR\cyro\cyrz\cyrd\cyrii\cyrl\cyri}%
    \crefname{appendix}%
      {\CYRD\cyro\cyrd\cyra\cyrt\cyro\cyrk}%
      {\CYRD\cyro\cyrd\cyra\cyrt\cyrk\cyri}%
    \crefname{subappendix}%
      {\CYRD\cyro\cyrd\cyra\cyrt\cyro\cyrk}%
      {\CYRD\cyro\cyrd\cyra\cyrt\cyrk\cyri}%
    \crefname{subsubappendix}%
      {\CYRD\cyro\cyrd\cyra\cyrt\cyro\cyrk}%
      {\CYRD\cyro\cyrd\cyra\cyrt\cyrk\cyri}%
    \crefname{subsubsubappendix}%
      {\CYRD\cyro\cyrd\cyra\cyrt\cyro\cyrk}%
      {\CYRD\cyro\cyrd\cyra\cyrt\cyrk\cyri}%
    \crefname{footnote}%
      {\CYRV\cyri\cyrn\cyro\cyrs\cyrk\cyra}%
      {\CYRV\cyri\cyrn\cyro\cyrs\cyrk\cyri}%
    \crefname{theorem}%
      {\CYRT\cyre\cyro\cyrr\cyre\cyrm\cyra}%
      {\CYRT\cyre\cyro\cyrr\cyre\cyrm\cyri}%
    \crefname{lemma}%
      {\CYRL\cyre\cyrm\cyrm\cyra}%
      {\CYRL\cyre\cyrm\cyrm\cyri}%
    \crefname{corollary}%
      {\CYRV\cyri\cyrs\cyrn\cyro\cyrv\cyro\cyrk}%
      {\CYRV\cyri\cyrs\cyrn\cyro\cyrv\cyrk\cyri}%
    \crefname{proposition}%
      {\CYRT\cyrv\cyre\cyrr\cyrd\cyrzh\cyre\cyrn\cyrn\cyrya}%
      {\CYRT\cyrv\cyre\cyrr\cyrd\cyrzh\cyre\cyrn\cyrn\cyrya}%
    \crefname{definition}%
      {\CYRV\cyri\cyrz\cyrn\cyra\cyrch\cyre\cyrn\cyrn\cyrya}%
      {\CYRV\cyri\cyrz\cyrn\cyra\cyrch\cyre\cyrn\cyrn\cyrya}%
    \crefname{result}%
      {\CYRR\cyre\cyrz\cyru\cyrl\cyrsftsn\cyrt\cyra\cyrt}%
      {\CYRR\cyre\cyrz\cyru\cyrl\cyrsftsn\cyrt\cyra\cyrt\cyri}%
    \crefname{example}%
      {\CYRP\cyrr\cyri\cyrk\cyrl\cyra\cyrd}%
      {\CYRP\cyrr\cyri\cyrk\cyrl\cyra\cyrd\cyri}%
    \crefname{remark}%
      {\CYRP\cyrr\cyri\cyrm\cyrii\cyrt\cyrk\cyra}%
      {\CYRP\cyrr\cyri\cyrm\cyrii\cyrt\cyrk\cyri}%
    \crefname{note}%
      {\CYRZ\cyra\cyrm\cyrii\cyrt\cyrk\cyra}%
      {\CYRZ\cyra\cyrm\cyrii\cyrt\cyrk\cyri}%
    \crefname{algorithm}%
      {\CYRA\cyrl\cyrg\cyro\cyrr\cyri\cyrt\cyrm}%
      {\CYRA\cyrl\cyrg\cyro\cyrr\cyri\cyrt\cyrm\cyri}%
    \crefname{listing}%
      {\CYRL\cyrii\cyrs\cyrt\cyri\cyrn\cyrg}%
      {\CYRL\cyrii\cyrs\cyrt\cyri\cyrn\cyrg\cyri}%
    \crefname{line}%
      {\CYRS\cyrt\cyrr\cyro\cyrk\cyra}%
      {\CYRS\cyrt\cyrr\cyro\cyrk\cyri}%
    \crefname{page}%
      {\CYRS\cyrt\cyro\cyrr\cyri\cyrn\cyrk\cyra}%
      {\CYRS\cyrt\cyro\cyrr\cyrii\cyrn\cyrk\cyri}%
    \crefname{part}%
      {\CYRCH\cyra\cyrs\cyrt\cyri\cyrn\cyra}%
      {\CYRCH\cyra\cyrs\cyrt\cyri\cyrn\cyri}%
 %
  \else%  capitalise unset
    \if@cref@abbrev%  abbrev set
      \crefname{equation}%
        {\cyrf-\cyrl.}%
        {\cyrf-\cyrl.}%
      \crefname{chapter}%
        {\cyrg\cyrl\cyra\cyrv.}%
        {\cyrg\cyrl\cyra\cyrv.}%
      \crefname{section}%
        {\cyrr\cyro\cyrz\cyrd.}%
        {\cyrr\cyro\cyrz\cyrd\cyrii\cyrl.}%
      \crefname{subsection}%
        {\cyrr\cyro\cyrz\cyrd.}%
        {\cyrr\cyro\cyrz\cyrd\cyrii\cyrl.}%
      \crefname{subsubsection}%
        {\cyrr\cyro\cyrz\cyrd.}%
        {\cyrr\cyro\cyrz\cyrd\cyrii\cyrl.}%
      \crefname{appendix}%
        {\cyrd\cyro\cyrd\cyra\cyrt.}%
        {\cyrd\cyro\cyrd\cyra\cyrt\cyrk.}%
      \crefname{subappendix}%
        {\cyrd\cyro\cyrd\cyra\cyrt.}%
        {\cyrd\cyro\cyrd\cyra\cyrt\cyrk.}%
      \crefname{subsubappendix}%
        {\cyrd\cyro\cyrd\cyra\cyrt.}%
        {\cyrd\cyro\cyrd\cyra\cyrt\cyrk.}%
      \crefname{subsubsubappendix}%
        {\cyrd\cyro\cyrd\cyra\cyrt.}%
        {\cyrd\cyro\cyrd\cyra\cyrt\cyrk.}%
      \crefname{enumi}%
        {\cyrp.}%
        {\cyrp.\cyrp.}%
      \crefname{enumii}%
        {\cyrp.}%
        {\cyrp.\cyrp.}%
      \crefname{enumiii}%
        {\cyrp.}%
        {\cyrp.\cyrp.}%
      \crefname{enumiv}%
        {\cyrp.}%
        {\cyrp.\cyrp.}%
      \crefname{enumv}%
        {\cyrp.}%
        {\cyrp.\cyrp.}%
      \crefname{footnote}%
        {\cyrv\cyri\cyrn\cyro\cyrs\cyrk.}%
        {\cyrv\cyri\cyrn\cyro\cyrs\cyrk.}%
      \crefname{figure}%
        {\cyrr\cyri\cyrs.}%
        {\cyrr\cyri\cyrs.}%
      \crefname{subfigure}%
        {\cyrr\cyri\cyrs.}%
        {\cyrr\cyri\cyrs.}%
      \crefname{table}%
        {\cyrt\cyra\cyrb\cyrl.}%
        {\cyrt\cyra\cyrb\cyrl.}%
      \crefname{subtable}%
        {\cyrt\cyra\cyrb\cyrl.}%
        {\cyrt\cyra\cyrb\cyrl.}%
      \crefname{theorem}%
        {\cyrt\cyre\cyro\cyrr\cyre\cyrm.}%
        {\cyrt\cyre\cyro\cyrr\cyre\cyrm.}%
      \crefname{lemma}%
        {\cyrl\cyre\cyrm\cyrm.}%
        {\cyrl\cyre\cyrm\cyrm.}%
      \crefname{corollary}%
        {\cyrv\cyri\cyrs\cyrn\cyro\cyrv.}%
        {\cyrv\cyri\cyrs\cyrn\cyro\cyrv\cyrk.}%
      \crefname{proposition}%
        {\cyrt\cyrv\cyre\cyrr\cyrd\cyrzh\cyre\cyrn\cyrn.}%
        {\cyrt\cyrv\cyre\cyrr\cyrd\cyrzh\cyre\cyrn\cyrn.}%
      \crefname{definition}%
        {\cyrv\cyri\cyrz\cyrn\cyra\cyrch\cyre\cyrn\cyrn.}%
        {\cyrv\cyri\cyrz\cyrn\cyra\cyrch\cyre\cyrn\cyrn.}%
      \crefname{result}%
        {\cyrr\cyre\cyrz\cyru\cyrl\cyrsftsn\cyrt.}%
        {\cyrr\cyre\cyrz\cyru\cyrl\cyrsftsn\cyrt\cyra\cyrt.}%
      \crefname{example}%
        {\cyrp\cyrr\cyri\cyrk\cyrl.}%
        {\cyrp\cyrr\cyri\cyrk\cyrl\cyra\cyrd.}%
      \crefname{remark}%
        {\cyrp\cyrr\cyri\cyrm\cyrii\cyrt.}%
        {\cyrp\cyrr\cyri\cyrm\cyrii\cyrt.}%
      \crefname{note}%
        {\cyrz\cyra\cyrm\cyrii\cyrt.}%
        {\cyrz\cyra\cyrm\cyrii\cyrt.}%
      \crefname{algorithm}%
        {\cyra\cyrl\cyrg.}%
        {\cyra\cyrl\cyrg.}%
      \crefname{listing}%
        {\cyrl\cyrii\cyrs\cyrt\cyri\cyrn.}%
        {\cyrl\cyrii\cyrs\cyrt\cyri\cyrn\cyrg.}%
      \crefname{line}%
        {\cyrs\cyrt\cyrr\cyrk.}%
        {\cyrs\cyrt\cyrr\cyrk.}%
    \else%  abbrev unset
      \crefname{equation}%
        {\cyrf\cyro\cyrr\cyrm\cyru\cyrl\cyra}%
        {\cyrf\cyro\cyrr\cyrm\cyru\cyrl\cyri}%
      \crefname{figure}%
        {\cyrr\cyri\cyrs\cyru\cyrn\cyro\cyrk}%
        {\cyrr\cyri\cyrs\cyru\cyrn\cyrk\cyri}%
      \crefname{subfigure}%
        {\cyrr\cyri\cyrs\cyru\cyrn\cyro\cyrk}%
        {\cyrr\cyri\cyrs\cyru\cyrn\cyrk\cyri}%
      \crefname{table}%
        {\cyrt\cyra\cyrb\cyrl\cyri\cyrc\cyrya}%
        {\cyrt\cyra\cyrb\cyrl\cyri\cyrc\cyrii}%
      \crefname{subtable}%
        {\cyrt\cyra\cyrb\cyrl\cyri\cyrc\cyrya}%
        {\cyrt\cyra\cyrb\cyrl\cyri\cyrc\cyrii}%
      \crefname{enumi}%
        {\cyrp\cyru\cyrn\cyrk\cyrt}%
        {\cyrp\cyru\cyrn\cyrk\cyrt\cyri}%
      \crefname{enumii}%
        {\cyrp\cyru\cyrn\cyrk\cyrt}%
        {\cyrp\cyru\cyrn\cyrk\cyrt\cyri}%
      \crefname{enumiii}%
        {\cyrp\cyru\cyrn\cyrk\cyrt}%
        {\cyrp\cyru\cyrn\cyrk\cyrt\cyri}%
      \crefname{enumiv}%
        {\cyrp\cyru\cyrn\cyrk\cyrt}%
        {\cyrp\cyru\cyrn\cyrk\cyrt\cyri}%
      \crefname{enumv}%
        {\cyrp\cyru\cyrn\cyrk\cyrt}%
        {\cyrp\cyru\cyrn\cyrk\cyrt\cyri}%
      \crefname{chapter}%
        {\cyrg\cyrl\cyra\cyrv\cyra}%
        {\cyrg\cyrl\cyra\cyrv\cyri}%
      \crefname{section}%
        {\cyrr\cyro\cyrz\cyrd\cyrii\cyrl}%
        {\cyrr\cyro\cyrz\cyrd\cyrii\cyrl\cyri}%
      \crefname{subsection}%
        {\cyrr\cyro\cyrz\cyrd\cyrii\cyrl}%
        {\cyrr\cyro\cyrz\cyrd\cyrii\cyrl\cyri}%
      \crefname{subsubsection}%
        {\cyrr\cyro\cyrz\cyrd\cyrii\cyrl}%
        {\cyrr\cyro\cyrz\cyrd\cyrii\cyrl\cyri}%
      \crefname{appendix}%
        {\cyrd\cyro\cyrd\cyra\cyrt\cyro\cyrk}%
        {\cyrd\cyro\cyrd\cyra\cyrt\cyrk\cyri}%
      \crefname{subappendix}%
        {\cyrd\cyro\cyrd\cyra\cyrt\cyro\cyrk}%
        {\cyrd\cyro\cyrd\cyra\cyrt\cyrk\cyri}%
      \crefname{subsubappendix}%
        {\cyrd\cyro\cyrd\cyra\cyrt\cyro\cyrk}%
        {\cyrd\cyro\cyrd\cyra\cyrt\cyrk\cyri}%
      \crefname{subsubsubappendix}%
        {\cyrd\cyro\cyrd\cyra\cyrt\cyro\cyrk}%
        {\cyrd\cyro\cyrd\cyra\cyrt\cyrk\cyri}%
      \crefname{footnote}%
        {\cyrv\cyri\cyrn\cyro\cyrs\cyrk\cyra}%
        {\cyrv\cyri\cyrn\cyro\cyrs\cyrk\cyri}%
      \crefname{theorem}%
        {\cyrt\cyre\cyro\cyrr\cyre\cyrm\cyra}%
        {\cyrt\cyre\cyro\cyrr\cyre\cyrm\cyri}%
      \crefname{lemma}%
        {\cyrl\cyre\cyrm\cyrm\cyra}%
        {\cyrl\cyre\cyrm\cyrm\cyri}%
      \crefname{corollary}%
        {\cyrv\cyri\cyrs\cyrn\cyro\cyrv\cyro\cyrk}%
        {\cyrv\cyri\cyrs\cyrn\cyro\cyrv\cyrk\cyri}%
      \crefname{proposition}%
        {\cyrt\cyrv\cyre\cyrr\cyrd\cyrzh\cyre\cyrn\cyrn\cyrya}%
        {\cyrt\cyrv\cyre\cyrr\cyrd\cyrzh\cyre\cyrn\cyrn\cyrya}%
      \crefname{definition}%
        {\cyrv\cyri\cyrz\cyrn\cyra\cyrch\cyre\cyrn\cyrn\cyrya}%
        {\cyrv\cyri\cyrz\cyrn\cyra\cyrch\cyre\cyrn\cyrn\cyrya}%
      \crefname{result}%
        {\cyrr\cyre\cyrz\cyru\cyrl\cyrsftsn\cyrt\cyra\cyrt}%
        {\cyrr\cyre\cyrz\cyru\cyrl\cyrsftsn\cyrt\cyra\cyrt\cyri}%
      \crefname{example}%
        {\cyrp\cyrr\cyri\cyrk\cyrl\cyra\cyrd}%
        {\cyrp\cyrr\cyri\cyrk\cyrl\cyra\cyrd\cyri}%
      \crefname{remark}%
        {\cyrp\cyrr\cyri\cyrm\cyrii\cyrt\cyrk\cyra}%
        {\cyrp\cyrr\cyri\cyrm\cyrii\cyrt\cyrk\cyri}%
      \crefname{note}%
        {\cyrz\cyra\cyrm\cyrii\cyrt\cyrk\cyra}%
        {\cyrz\cyra\cyrm\cyrii\cyrt\cyrk\cyri}%
      \crefname{algorithm}%
        {\cyra\cyrl\cyrg\cyro\cyrr\cyri\cyrt\cyrm}%
        {\cyra\cyrl\cyrg\cyro\cyrr\cyri\cyrt\cyrm\cyri}%
      \crefname{listing}%
        {\cyrl\cyrii\cyrs\cyrt\cyri\cyrn\cyrg}%
        {\cyrl\cyrii\cyrs\cyrt\cyri\cyrn\cyrg\cyri}%
      \crefname{line}%
        {\cyrs\cyrt\cyrr\cyro\cyrk\cyra}%
        {\cyrs\cyrt\cyrr\cyro\cyrk\cyri}%
    \fi%
    \crefname{page}%
      {\cyrs\cyrt\cyro\cyrr\cyri\cyrn\cyrc\cyrii}%
      {\cyrs\cyrt\cyro\cyrr\cyrii\cyrn\cyrk\cyra\cyrh}%
    \crefname{part}%
      {\cyrch\cyra\cyrs\cyrt\cyri\cyrn\cyra}%
      {\cyrch\cyra\cyrs\cyrt\cyri\cyrn\cyri}%
  \fi}% end \cref@loadlanguagedefs
%    \end{macrocode}
%
%
%  \subsubsection{Norwegian}
% \begin{macro}{norsk}
%   Norwegian translations kindly donated by Sveinung Heggen.
% \end{macro}
%
% Set up the definitions used at the beginning of the document to define
% the formats created by the document preamble.
%    \begin{macrocode}
\DeclareOption{norsk}{%
  \AtBeginDocument{%
    \def\crefrangeconjunction@preamble{ til\nobreakspace}%
    \def\crefrangepreconjunction@preamble{}%
    \def\crefrangepostconjunction@preamble{}%
    \def\crefpairconjunction@preamble{ og\nobreakspace}%
    \def\crefmiddleconjunction@preamble{, }%
    \def\creflastconjunction@preamble{ og\nobreakspace}%
%    \end{macrocode}
% We have to define the group conjunctions explicitly here, rather than
% relying on fall-back definitions in terms of the above conjunctions
% (see \cref{sec:code:default_formats}), in case any other language
% option defines them explicitly and we need to override those.
%    \begin{macrocode}
    \def\crefpairgroupconjunction@preamble{ og\nobreakspace}%
    \def\crefmiddlegroupconjunction@preamble{, }%
    \def\creflastgroupconjunction@preamble{ og\nobreakspace}%
 %
    \Crefname@preamble{equation}{Likning}{Likningene}%
    \Crefname@preamble{figure}{Figur}{Figurene}%
    \Crefname@preamble{table}{Tabell}{Tabellene}%
    \Crefname@preamble{page}{Side}{Siden}%
    \Crefname@preamble{part}{Del}{Delene}%
    \Crefname@preamble{chapter}{Kapittel}{Kapitlene}%
    \Crefname@preamble{section}{Avsnitt}{Avsnittene}%
    \Crefname@preamble{appendix}{Tillegg}{Tilleggene}%
    \Crefname@preamble{enumi}{Punkt}{Punktene}%
    \Crefname@preamble{footnote}{Fotnote}{Fotnotene}%
    \Crefname@preamble{theorem}{Teorem}{Teoremene}%
    \Crefname@preamble{lemma}{Lemma}{Lemma}%
    \Crefname@preamble{corollary}{Korollar}{Korollarene}%
    \Crefname@preamble{proposition}{P\aa stand}{P\aa standene}%
    \Crefname@preamble{definition}{Definisjon}{Definisjonene}%
    \Crefname@preamble{result}{Resultat}{Resultatene}%
    \Crefname@preamble{example}{Eksempel}{Eksemplene}%
    \Crefname@preamble{remark}{Bemerkning}{Bemerkningene}%
    \Crefname@preamble{note}{Note}{Notene}%
    \Crefname@preamble{algorithm}{Algoritme}{Algoritmene}%
    \Crefname@preamble{listing}{Opplisting}{Opplistingene}%
    \Crefname@preamble{line}{Linje}{Linjene}%
 %
    \if@cref@capitalise%
      \crefname@preamble{page}{Side}{Siden}%
      \crefname@preamble{equation}{Likning}{Likningene}%
      \crefname@preamble{figure}{Figur}{Figurene}%
      \crefname@preamble{table}{Tabell}{Tabellene}%
      \crefname@preamble{part}{Del}{Delene}%
      \crefname@preamble{chapter}{Kapittel}{Kapitlene}%
      \crefname@preamble{section}{Avsnitt}{Avsnittene}%
      \crefname@preamble{appendix}{Tillegg}{Tilleggene}%
      \crefname@preamble{enumi}{Punkt}{Punktene}%
      \crefname@preamble{footnote}{Fotnote}{Fotnotene}%
      \crefname@preamble{theorem}{Teorem}{Teoremene}%
      \crefname@preamble{lemma}{Lemma}{Lemma}%
      \crefname@preamble{corollary}{Korollar}{Korollarene}%
      \crefname@preamble{proposition}{P\aa stand}{P\aa standene}%
      \crefname@preamble{definition}{Definisjon}{Definisjonene}%
      \crefname@preamble{result}{Resultat}{Resultatene}%
      \crefname@preamble{example}{Eksempel}{Eksemplene}%
      \crefname@preamble{remark}{Bemerkning}{Bemerkningene}%
      \crefname@preamble{note}{Note}{Notene}%
      \crefname@preamble{algorithm}{Algoritme}{Algoritmene}%
      \crefname@preamble{listing}{Opplisting}{Opplistingene}%
      \crefname@preamble{line}{Linje}{Linjene}%
 %
    \else%
      \crefname@preamble{equation}{likning}{likningene}%
      \crefname@preamble{figure}{figur}{figurene}%
      \crefname@preamble{table}{tabell}{tabeller}%
      \crefname@preamble{page}{side}{siden}%
      \crefname@preamble{part}{del}{delene}%
      \crefname@preamble{chapter}{kapittel}{kapitlene}%
      \crefname@preamble{section}{avsnitt}{avsnittene}%
      \crefname@preamble{appendix}{tillegg}{tilleggene}%
      \crefname@preamble{enumi}{punkt}{punktene}%
      \crefname@preamble{footnote}{fotnote}{fotnotene}%
      \crefname@preamble{theorem}{teorem}{teoremene}%
      \crefname@preamble{lemma}{lemma}{lemma}%
      \crefname@preamble{corollary}{korollar}{korollarene}%
      \crefname@preamble{proposition}{p\aa stand}{p\aa standene}%
      \crefname@preamble{definition}{definisjon}{definisjonene}%
      \crefname@preamble{result}{resultat}{resultatene}%
      \crefname@preamble{example}{eksempel}{eksemplene}%
      \crefname@preamble{remark}{bemerkning}{bemerkningene}%
      \crefname@preamble{note}{note}{notene}%
      \crefname@preamble{algorithm}{algoritme}{algoritmene}%
      \crefname@preamble{listing}{opplisting}{opplistingene}%
      \crefname@preamble{line}{linje}{linjene}%
    \fi%
    \def\cref@language{norsk}%
  }}% end \DeclareOption and \AtBeginDocument
%    \end{macrocode}
%
% If using \package{babel} and the corresponding option is set, or if
% using \package{polyglossia} and the language has been loaded, add
% format definition commands to \cmd{\extras}\meta{language} or
% \cmd{\captions}\meta{language} so that language switching commands will
% change the cross-reference formats appropriately.
%    \begin{macrocode}
\cref@addlanguagedefs{norsk}{%
  \PackageInfo{cleveref}{loaded `norsk' language definitions}%
  \renewcommand{\crefrangeconjunction}{ til\nobreakspace}%
  \renewcommand\crefrangepreconjunction{}%
  \renewcommand\crefrangepostconjunction{}%
  \renewcommand{\crefpairconjunction}{ og\nobreakspace}%
  \renewcommand{\crefmiddleconjunction}{, }%
  \renewcommand{\creflastconjunction}{ og\nobreakspace}%
  \renewcommand{\crefpairgroupconjunction}{ og\nobreakspace}%
  \renewcommand{\crefmiddlegroupconjunction}{, }%
  \renewcommand{\creflastgroupconjunction}{ og\nobreakspace}%
 %
  \Crefname{equation}{Likning}{Likningene}%
  \Crefname{figure}{Figur}{Figurene}%
  \Crefname{subfigure}{Figur}{Figurene}%
  \Crefname{table}{Tabell}{Tabellene}%
  \Crefname{subtable}{Tabell}{Tabellene}%
  \Crefname{page}{Side}{Siden}%
  \Crefname{part}{Del}{Delene}%
  \Crefname{chapter}{Kapittel}{Kapitlene}%
  \Crefname{section}{Avsnitt}{Avsnittene}%
  \Crefname{subsection}{Avsnitt}{Avsnittene}%
  \Crefname{subsubsection}{Avsnitt}{Avsnittene}%
  \Crefname{appendix}{Tillegg}{Tilleggene}%
  \Crefname{subappendix}{Tillegg}{Tilleggene}%
  \Crefname{subsubappendix}{Tillegg}{Tilleggene}%
  \Crefname{subsubsubappendix}{Tillegg}{Tilleggene}%
  \Crefname{enumi}{Punkt}{Punktene}%
  \Crefname{enumii}{Punkt}{Punktene}%
  \Crefname{enumiii}{Punkt}{Punktene}%
  \Crefname{enumiv}{Punkt}{Punktene}%
  \Crefname{enumv}{Punkt}{Punktene}%
  \Crefname{footnote}{Fotnote}{Fotnotene}%
  \Crefname{theorem}{Teorem}{Teoremene}%
  \Crefname{lemma}{Lemma}{Lemma}%
  \Crefname{corollary}{Korollar}{Korollarene}%
  \Crefname{proposition}{P\aa stand}{P\aa standene}%
  \Crefname{definition}{Definisjon}{Definisjonene}%
  \Crefname{result}{Resultat}{Resultatene}%
  \Crefname{example}{Eksempel}{Eksemplene}%
  \Crefname{remark}{Bemerkning}{Bemerkningene}%
  \Crefname{note}{Note}{Notene}%
  \Crefname{algorithm}{Algoritme}{Algoritmene}%
  \Crefname{listing}{Opplisting}{Opplistingene}%
  \Crefname{line}{Linje}{Linjene}%
 %
  \if@cref@capitalise%
    \crefname{equation}{Likning}{Likningene}%
    \crefname{figure}{Figur}{Figurene}%
    \crefname{subfigure}{Figur}{Figurene}%
    \crefname{table}{Tabell}{Tabellene}%
    \crefname{subtable}{Tabell}{Tabellene}%
    \crefname{page}{Side}{Siden}%
    \crefname{part}{Del}{Delene}%
    \crefname{chapter}{Kapittel}{Kapitlene}%
    \crefname{section}{Avsnitt}{Avsnittene}%
    \crefname{subsection}{Avsnitt}{Avsnittene}%
    \crefname{subsubsection}{Avsnitt}{Avsnittene}%
    \crefname{appendix}{Tillegg}{Tilleggene}%
    \crefname{subappendix}{Tillegg}{Tilleggene}%
    \crefname{subsubappendix}{Tillegg}{Tilleggene}%
    \crefname{subsubsubappendix}{Tillegg}{Tilleggene}%
    \crefname{enumi}{Punkt}{Punktene}%
    \crefname{enumii}{Punkt}{Punktene}%
    \crefname{enumiii}{Punkt}{Punktene}%
    \crefname{enumiv}{Punkt}{Punktene}%
    \crefname{enumv}{Punkt}{Punktene}%
    \crefname{footnote}{Fotnote}{Fotnotene}%
    \crefname{theorem}{Teorem}{Teoremene}%
    \crefname{lemma}{Lemma}{Lemma}%
    \crefname{corollary}{Korollar}{Korollarene}%
    \crefname{proposition}{P\aa stand}{P\aa standene}%
    \crefname{definition}{Definisjon}{Definisjonene}%
    \crefname{result}{Resultat}{Resultatene}%
    \crefname{example}{Eksempel}{Eksemplene}%
    \crefname{remark}{Bemerkning}{Bemerkningene}%
    \crefname{note}{Note}{Notene}%
    \crefname{algorithm}{Algoritme}{Algoritmene}%
    \crefname{listing}{Opplisting}{Opplistingene}%
    \crefname{line}{Linje}{Linjene}%
 %
  \else%
    \crefname{equation}{likning}{likningene}%
    \crefname{figure}{figur}{figurene}%
    \crefname{subfigure}{figur}{figurene}%
    \crefname{table}{tabell}{tabellene}%
    \crefname{subtable}{tabell}{tabellene}%
    \crefname{page}{side}{siden}%
    \crefname{part}{del}{delene}%
    \crefname{chapter}{kapittel}{kapitlene}%
    \crefname{section}{avsnitt}{avsnittene}%
    \crefname{subsection}{avsnitt}{avsnittene}%
    \crefname{subsubsection}{avsnitt}{avsnittene}%
    \crefname{appendix}{tillegg}{tilleggene}%
    \crefname{subappendix}{tillegg}{tilleggene}%
    \crefname{subsubappendix}{tillegg}{tilleggene}%
    \crefname{subsubsubappendix}{tillegg}{tilleggene}%
    \crefname{enumi}{punkt}{punktene}%
    \crefname{enumii}{punkt}{punktene}%
    \crefname{enumiii}{punkt}{punktene}%
    \crefname{enumiv}{punkt}{punktene}%
    \crefname{enumv}{punkt}{punktene}%
    \crefname{footnote}{fotnote}{fotnotene}%
    \crefname{theorem}{teorem}{teoremene}%
    \crefname{lemma}{lemma}{lemma}%
    \crefname{corollary}{korollar}{korollarene}%
    \crefname{proposition}{p\aa stand}{p\aa standene}%
    \crefname{definition}{definisjon}{definisjonene}%
    \crefname{result}{resultat}{resultatene}%
    \crefname{example}{eksempel}{eksemplene}%
    \crefname{remark}{bemerkning}{bemerkningene}%
    \crefname{note}{note}{notene}%
    \crefname{algorithm}{algoritme}{algoritmene}%
    \crefname{listing}{opplisting}{opplistingene}%
    \crefname{line}{linje}{linjene}%
  \fi}% end \cref@loadlanguagedefs
%    \end{macrocode}
%
%
% \subsubsection{Danish}
% \begin{macro}{danish}
%   Danish translations courtesy of Benjamin H{\o}yer.
% \end{macro}
%
% Set up the definitions used at the beginning of the document to define
% the formats created by the document preamble.
%    \begin{macrocode}
\DeclareOption{danish}{%
  \AtBeginDocument{%
    \def\crefrangeconjunction@preamble{ til\nobreakspace}%
    \def\crefrangepreconjunction@preamble{}%
    \def\crefrangepostconjunction@preamble{}%
    \def\crefpairconjunction@preamble{ og\nobreakspace}%
    \def\crefmiddleconjunction@preamble{, }%
    \def\creflastconjunction@preamble{ og\nobreakspace}%
%    \end{macrocode}
% We have to define the group conjunctions explicitly here, rather than
% relying on fall-back definitions in terms of the above conjunctions
% (see \cref{sec:code:default_formats}), in case any other language
% option defines them explicitly and we need to override those.
%    \begin{macrocode}
    \def\crefpairgroupconjunction@preamble{ og\nobreakspace}%
    \def\crefmiddlegroupconjunction@preamble{, }%
    \def\creflastgroupconjunction@preamble{ og\nobreakspace}%
 %
    \Crefname@preamble{equation}{Ligning}{Ligninger}%
    \Crefname@preamble{figure}{Figur}{Figurer}%
    \Crefname@preamble{table}{Tabel}{Tabeller}%
    \Crefname@preamble{page}{Side}{Sider}%
    \Crefname@preamble{part}{Del}{Dele}%
    \Crefname@preamble{chapter}{Kapitel}{Kapitler}%
    \Crefname@preamble{section}{Afsnit}{Afsnit}%
    \Crefname@preamble{appendix}{Appendiks}{Appendiks}%
    \Crefname@preamble{enumi}{Punkt}{Punkter}%
    \Crefname@preamble{footnote}{Fodnote}{Fodnoter}%
    \Crefname@preamble{theorem}{Teorem}{Teoremer}%
    \Crefname@preamble{lemma}{Lemma}{Lemma}%
    \Crefname@preamble{corollary}{F\o lgeslutning}{F\o lgeslutninger}%
    \Crefname@preamble{proposition}{Udsagn}{Udsagn}%
    \Crefname@preamble{definition}{Definition}{Definitioner}%
    \Crefname@preamble{result}{Resultat}{Resultater}%
    \Crefname@preamble{example}{Eksempel}{Eksempler}%
    \Crefname@preamble{remark}{Bem\ae rkning}{Bem\ae rkninger}%
    \Crefname@preamble{note}{Note}{Noter}%
    \Crefname@preamble{algorithm}{Algoritme}{Algoritmer}%
    \Crefname@preamble{line}{Linje}{Linjer}%
 %
    \if@cref@capitalise%
      \crefname@preamble{equation}{Ligning}{Ligninger}%
      \crefname@preamble{figure}{Figur}{Figurer}%
      \crefname@preamble{table}{Tabel}{Tabeller}%
      \crefname@preamble{page}{Side}{Sider}%
      \crefname@preamble{part}{Del}{Dele}%
      \crefname@preamble{chapter}{Kapitel}{Kapitler}%
      \crefname@preamble{section}{Afsnit}{Afsnit}%
      \crefname@preamble{appendix}{Appendiks}{Appendiks}%
      \crefname@preamble{enumi}{Punkt}{Punkter}%
      \crefname@preamble{footnote}{Fodnote}{Fodnoter}%
      \crefname@preamble{theorem}{Teorem}{Teoremer}%
      \crefname@preamble{lemma}{Lemma}{Lemma}%
      \crefname@preamble{corollary}{F\o lgeslutning}{F\o lgeslutninger}%
      \crefname@preamble{proposition}{Udsagn}{Udsagn}%
      \crefname@preamble{definition}{Definition}{Definitioner}%
      \crefname@preamble{result}{Resultat}{Resultater}%
      \crefname@preamble{example}{Eksempel}{Eksempler}%
      \crefname@preamble{remark}{Bem\ae rkning}{Bem\ae rkninger}%
      \crefname@preamble{note}{Note}{Noter}%
      \crefname@preamble{algorithm}{Algoritme}{Algoritmer}%
      \crefname@preamble{line}{Linje}{Linjer}%
 %
    \else%
      \crefname@preamble{equation}{ligning}{ligninger}%
      \crefname@preamble{figure}{figur}{figurer}%
      \crefname@preamble{table}{tabel}{tabeller}%
      \crefname@preamble{page}{side}{sider}%
      \crefname@preamble{part}{del}{dele}%
      \crefname@preamble{chapter}{kapitel}{kapitler}%
      \crefname@preamble{section}{afsnit}{afsnit}%
      \crefname@preamble{appendix}{appendiks}{appendiks}%
      \crefname@preamble{enumi}{punkt}{punkter}%
      \crefname@preamble{footnote}{fodnote}{fodnoter}%
      \crefname@preamble{theorem}{teorem}{teoremer}%
      \crefname@preamble{lemma}{lemma}{lemma}%
      \crefname@preamble{corollary}{f\o lgeslutning}{f\o lgeslutninger}%
      \crefname@preamble{proposition}{udsagn}{udsagn}%
      \crefname@preamble{definition}{definition}{definitioner}%
      \crefname@preamble{result}{resultat}{resultater}%
      \crefname@preamble{example}{eksempel}{eksempler}%
      \crefname@preamble{remark}{bem\ae rkning}{bem\ae rkninger}%
      \crefname@preamble{note}{note}{noter}%
      \crefname@preamble{algorithm}{algoritme}{algoritmer}%
      \crefname@preamble{line}{linje}{linjer}%
    \fi%
    \def\cref@language{danish}%
  }}% end \DeclareOption and \AtBeginDocument
%    \end{macrocode}
%
% If using \package{babel} and the corresponding option is set, or if
% using \package{polyglossia} and the language has been loaded, add
% format definition commands to \cmd{\extras}\meta{language} or
% \cmd{\captions}\meta{language} so that language switching commands will
% change the cross-reference formats appropriately.
%    \begin{macrocode}
\cref@addlanguagedefs{danish}{%
  \PackageInfo{cleveref}{loaded `danish' language definitions}%
  \renewcommand{\crefrangeconjunction@preamble}{ til\nobreakspace}%
  \renewcommand\crefrangepreconjunction@preamble{}%
  \renewcommand\crefrangepostconjunction@preamble{}%
  \renewcommand{\crefpairconjunction@preamble}{ og\nobreakspace}%
  \renewcommand{\crefmiddleconjunction@preamble}{, }%
  \renewcommand{\creflastconjunction@preamble}{ og\nobreakspace}%
  \renewcommand{\crefpairgroupconjunction@preamble}{ og\nobreakspace}%
  \renewcommand{\crefmiddlegroupconjunction@preamble}{, }%
  \renewcommand{\creflastgroupconjunction@preamble}{ og\nobreakspace}%
 %
  \Crefname{equation}{Ligning}{Ligninger}%
  \Crefname{figure}{Figur}{Figurer}%
  \Crefname{subfigure}{Figur}{Figurer}%
  \Crefname{table}{Tabel}{Tabeller}%
  \Crefname{subtable}{Tabel}{Tabeller}%
  \Crefname{page}{Side}{Sider}%
  \Crefname{part}{Del}{Dele}%
  \Crefname{chapter}{Kapitel}{Kapitler}%
  \Crefname{section}{Afsnit}{Afsnit}%
  \Crefname{subsection}{Afsnit}{Afsnit}%
  \Crefname{subsubsection}{Afsnit}{Afsnit}%
  \Crefname{appendix}{Appendiks}{Appendiks}%
  \Crefname{subappendix}{Appendiks}{Appendiks}%
  \Crefname{subsubappendix}{Appendiks}{Appendiks}%
  \Crefname{subsubsubappendix}{Appendiks}{Appendiks}%
  \Crefname{enumi}{Punkt}{Punkter}%
  \Crefname{enumii}{Punkt}{Punkter}%
  \Crefname{enumiii}{Punkt}{Punkter}%
  \Crefname{enumiv}{Punkt}{Punkter}%
  \Crefname{enumv}{Punkt}{Punkter}%
  \Crefname{footnote}{Fodnote}{Fodnoter}%
  \Crefname{theorem}{Teorem}{Teoremer}%
  \Crefname{lemma}{Lemma}{Lemma}%
  \Crefname{corollary}{F\o lgeslutning}{F\o lgeslutninger}%
  \Crefname{proposition}{Udsagn}{Udsagn}%
  \Crefname{definition}{Definition}{Definitioner}%
  \Crefname{result}{Resultat}{Resultater}%
  \Crefname{example}{Eksempel}{Eksempler}%
  \Crefname{remark}{Bem\ae rkning}{Bem\ae rkninger}%
  \Crefname{note}{Note}{Noter}%
  \Crefname{algorithm}{Algoritme}{Algoritmer}%
  \Crefname{line}{Linje}{Linjer}%
 %
  \if@cref@capitalise%
    \crefname{equation}{Ligning}{Ligninger}%
    \crefname{figure}{Figur}{Figurer}%
    \crefname{subfigure}{Figur}{Figurer}%
    \crefname{table}{Tabel}{Tabeller}%
    \crefname{subtable}{Tabel}{Tabeller}%
    \crefname{page}{Side}{Sider}%
    \crefname{part}{Del}{Dele}%
    \crefname{chapter}{Kapitel}{Kapitler}%
    \crefname{section}{Afsnit}{Afsnit}%
    \crefname{subsection}{Afsnit}{Afsnit}%
    \crefname{subsubsection}{Afsnit}{Afsnit}%
    \crefname{appendix}{Appendiks}{Appendiks}%
    \crefname{subappendix}{Appendiks}{Appendiks}%
    \crefname{subsubappendix}{Appendiks}{Appendiks}%
    \crefname{subsubsubappendix}{Appendiks}{Appendiks}%
    \crefname{enumi}{Punkt}{Punkter}%
    \crefname{enumii}{Punkt}{Punkter}%
    \crefname{enumiii}{Punkt}{Punkter}%
    \crefname{enumiv}{Punkt}{Punkter}%
    \crefname{enumv}{Punkt}{Punkter}%
    \crefname{footnote}{Fodnote}{Fodnoter}%
    \crefname{theorem}{Teorem}{Teoremer}%
    \crefname{lemma}{Lemma}{Lemma}%
    \crefname{corollary}{F\o lgeslutning}{F\o lgeslutninger}%
    \crefname{proposition}{Udsagn}{Udsagn}%
    \crefname{definition}{Definition}{Definitioner}%
    \crefname{result}{Resultat}{Resultater}%
    \crefname{example}{Eksempel}{Eksempler}%
    \crefname{remark}{Bem\ae rkning}{Bem\ae rkninger}%
    \crefname{note}{Note}{Noter}%
    \crefname{algorithm}{Algoritme}{Algoritmer}%
    \crefname{line}{Linje}{Linjer}%
 %
  \else%
    \crefname{equation}{ligning}{ligninger}%
    \crefname{figure}{figur}{figurer}%
    \crefname{subfigure}{figur}{figurer}%
    \crefname{table}{tabel}{tabeller}%
    \crefname{subtable}{tabel}{tabeller}%
    \crefname{page}{side}{sider}%
    \crefname{part}{del}{dele}%
    \crefname{chapter}{kapitel}{kapitler}%
    \crefname{section}{afsnit}{afsnit}%
    \crefname{subsection}{afsnit}{afsnit}%
    \crefname{subsubsection}{afsnit}{afsnit}%
    \crefname{appendix}{appendiks}{appendiks}%
    \crefname{subappendix}{appendiks}{appendiks}%
    \crefname{subsubappendix}{appendiks}{appendiks}%
    \crefname{subsubsubappendix}{appendiks}{appendiks}%
    \crefname{enumi}{punkt}{punkter}%
    \crefname{enumii}{punkt}{punkter}%
    \crefname{enumiii}{punkt}{punkter}%
    \crefname{enumiv}{punkt}{punkter}%
    \crefname{enumv}{punkt}{punkter}%
    \crefname{footnote}{fodnote}{fodnoter}%
    \crefname{theorem}{teorem}{teoremer}%
    \crefname{lemma}{lemma}{lemma}%
    \crefname{corollary}{f\o lgeslutning}{f\o lgeslutninger}%
    \crefname{proposition}{udsagn}{udsagn}%
    \crefname{definition}{definition}{definitioner}%
    \crefname{result}{resultat}{resultater}%
    \crefname{example}{eksempel}{eksempler}%
    \crefname{remark}{bem\ae rkning}{bem\ae rkninger}%
    \crefname{note}{note}{noter}%
    \crefname{algorithm}{algoritme}{algoritmer}%
    \crefname{line}{linje}{linjer}%
  \fi}% end \cref@loadlanguagedefs
%    \end{macrocode}
%
%
% \subsubsection{Esperanto}
% \begin{macro}{esperanto}
%   Esperanto translations courtesy of Johannes Mueller.
% \end{macro}
%
% Set up the definitions used at the beginning of the document to define
% the formats created by the document preamble.
%    \begin{macrocode}
\DeclareOption{esperanto}{%
  \AtBeginDocument{%
    \def\crefrangeconjunction@preamble{ \^gis\nobreakspace}%
    \def\crefrangepreconjunction@preamble{}%
    \def\crefrangepostconjunction@preamble{}%
    \def\crefpairconjunction@preamble{ kaj\nobreakspace}%
    \def\crefmiddleconjunction@preamble{, }%
    \def\creflastconjunction@preamble{ kaj\nobreakspace}%
    \def\crefpairgroupconjunction@preamble{ kaj\nobreakspace}%
    \def\crefmiddlegroupconjunction@preamble{, }%
    \def\creflastgroupconjunction@preamble{ kaj\nobreakspace}%
%
    \Crefname@preamble{equation}{Ekvacio}{Ekvacioj}%
    \Crefname@preamble{part}{Parto}{Partoj}%
    \Crefname@preamble{chapter}{\^Capitro}{\^Capitroj}%
    \Crefname@preamble{section}{Sekcio}{Sekcioj}%
    \Crefname@preamble{appendix}{Aldono}{Aldonoj}%
    \Crefname@preamble{enumi}{Punkto}{Punktoj}%
    \Crefname@preamble{footnote}{Piednoto}{Piednotoj}%
    \Crefname@preamble{figure}{Figuro}{Figuroj}%
    \Crefname@preamble{table}{Tabelo}{Tabeloj}%
    \Crefname@preamble{theorem}{Teoremo}{Teoremoj}%
    \Crefname@preamble{lemma}{Lemo}{Lemoj}%
    \Crefname@preamble{corollary}{Korolario}{Korolarioj}%
    \Crefname@preamble{proposition}{Propozicio}{Propozicioj}%
    \Crefname@preamble{definition}{Defino}{Definoj}%
    \Crefname@preamble{result}{Rezulto}{Rezultoj}%
    \Crefname@preamble{example}{Ekzemplo}{Ekzemploj}%
    \Crefname@preamble{remark}{Rimarko}{Rimarkoj}%
    \Crefname@preamble{note}{Noto}{Notoj}%
    \Crefname@preamble{algorithm}{Algoritmo}{Algoritmoj}%
    \Crefname@preamble{listing}{Listado}{Listadoj}%
    \Crefname@preamble{line}{Linio}{Linioj}%
%
    \if@cref@capitalise%
      \crefname@preamble{equation}{Ekvacio}{Ekvacioj}%
      \crefname@preamble{part}{Parto}{Partoj}%
      \crefname@preamble{chapter}{\^Capitro}{\^Capitroj}%
      \crefname@preamble{section}{Sekcio}{Sekcioj}%
      \crefname@preamble{appendix}{Aldono}{Aldonoj}%
      \crefname@preamble{enumi}{Punkto}{Punktoj}%
      \crefname@preamble{footnote}{Piednoto}{Piednotoj}%
      \crefname@preamble{figure}{Figuro}{Figuroj}%
      \crefname@preamble{table}{Tabelo}{Tabeloj}%
      \crefname@preamble{theorem}{Teoremo}{Teoremoj}%
      \crefname@preamble{lemma}{Lemo}{Lemoj}%
      \crefname@preamble{corollary}{Korolario}{Korolarioj}%
      \crefname@preamble{proposition}{Propozicio}{Propozicioj}%
      \crefname@preamble{definition}{Defino}{Definoj}%
      \crefname@preamble{result}{Rezulto}{Rezultoj}%
      \crefname@preamble{example}{Ekzemplo}{Ekzemploj}%
      \crefname@preamble{remark}{Rimarko}{Rimarkoj}%
      \crefname@preamble{note}{Noto}{Notoj}%
      \crefname@preamble{algorithm}{Algoritmo}{Algoritmoj}%
      \crefname@preamble{listing}{Listado}{Listadoj}%
      \crefname@preamble{line}{Linio}{Linioj}%
%
    \else%
      \crefname@preamble{equation}{ekvacio}{ekvacioj}%
      \crefname@preamble{part}{parto}{partoj}%
      \crefname@preamble{chapter}{\^capitro}{\^capitroj}%
      \crefname@preamble{section}{sekcio}{sekcioj}%
      \crefname@preamble{appendix}{aldono}{aldonoj}%
      \crefname@preamble{enumi}{punkto}{punktoj}%
      \crefname@preamble{footnote}{piednoto}{piednotoj}%
      \crefname@preamble{figure}{figuro}{figuroj}%
      \crefname@preamble{table}{tabelo}{tabeloj}%
      \crefname@preamble{theorem}{teoremo}{teoremoj}%
      \crefname@preamble{lemma}{lemo}{lemoj}%
      \crefname@preamble{corollary}{korolario}{korolarioj}%
      \crefname@preamble{proposition}{propozicio}{propozicioj}%
      \crefname@preamble{definition}{defino}{definoj}%
      \crefname@preamble{result}{rezulto}{rezultoj}%
      \crefname@preamble{example}{ekzemplo}{ekzemploj}%
      \crefname@preamble{remark}{rimarko}{rimarkoj}%
      \crefname@preamble{note}{noto}{notoj}%
      \crefname@preamble{algorithm}{algoritmo}{algoritmoj}%
      \crefname@preamble{listing}{listado}{listadoj}%
      \crefname@preamble{line}{linio}{linioj}%
    \fi%
    \def\cref@language{esperanto}%
  }}% end \DeclareOption and \AtBeginDocument
% \end{macrocode}
%
% If using \package{babel} and the corresponding option is set, or if
% using \package{polyglossia} and the language has been loaded, add
% format definition commands to \cmd{\extras}\meta{language} or
% \cmd{\captions}\meta{language} so that language switching commands will
% change the cross-reference formats appropriately.
%    \begin{macrocode}
\cref@addlanguagedefs{esperanto}{%
  \PackageInfo{cleveref}{loaded `esperanto' language definitions}%
  \renewcommand{\crefrangeconjunction}{ \^gis\nobreakspace}%
  \renewcommand{\crefrangepreconjunction}{}%
  \renewcommand{\crefrangepostconjunction}{}%
  \renewcommand{\crefpairconjunction}{ kaj\nobreakspace}%
  \renewcommand{\crefmiddleconjunction}{, }%
  \renewcommand{\creflastconjunction}{ kaj\nobreakspace}%
  \renewcommand{\crefpairgroupconjunction}{ kaj\nobreakspace}%
  \renewcommand{\crefmiddlegroupconjunction}{, }%
  \renewcommand{\creflastgroupconjunction}{ kaj\nobreakspace}%
%
  \Crefname{equation}{Ekvacio}{Ekvacioj}%
  \Crefname{part}{Parto}{Partoj}%
  \Crefname{chapter}{\^Capitro}{\^Capitroj}%
  \Crefname{section}{Sekcio}{Sekcioj}%
  \Crefname{appendix}{Aldono}{Aldonoj}%
  \Crefname{enumi}{Punkto}{Punktoj}%
  \Crefname{footnote}{Piednoto}{Piednotoj}%
  \Crefname{figure}{Figuro}{Figuroj}%
  \Crefname{table}{Tabelo}{Tabeloj}%
  \Crefname{theorem}{Teoremo}{Teoremoj}%
  \Crefname{lemma}{Lemo}{Lemoj}%
  \Crefname{corollary}{Korolario}{Korolarioj}%
  \Crefname{proposition}{Propozicio}{Propozicioj}%
  \Crefname{definition}{Defino}{Definoj}%
  \Crefname{result}{Rezulto}{Rezultoj}%
  \Crefname{example}{Ekzemplo}{Ekzemploj}%
  \Crefname{remark}{Rimarko}{Rimarkoj}%
  \Crefname{note}{Noto}{Notoj}%
  \Crefname{algorithm}{Algoritmo}{Algoritmoj}%
  \Crefname{listing}{Listado}{Listadoj}%
  \Crefname{line}{Linio}{Linioj}%
%
  \if@cref@capitalise%
    \crefname{equation}{Ekvacio}{Ekvacioj}%
    \crefname{part}{Parto}{Partoj}%
    \crefname{chapter}{\^Capitro}{\^Capitroj}%
    \crefname{section}{Sekcio}{Sekcioj}%
    \crefname{appendix}{Aldono}{Aldonoj}%
    \crefname{enumi}{Punkto}{Punktoj}%
    \crefname{footnote}{Piednoto}{Piednotoj}%
    \crefname{figure}{Figuro}{Figuroj}%
    \crefname{table}{Tabelo}{Tabeloj}%
    \crefname{theorem}{Teoremo}{Teoremoj}%
    \crefname{lemma}{Lemo}{Lemoj}%
    \crefname{corollary}{Korolario}{Korolarioj}%
    \crefname{proposition}{Propozicio}{Propozicioj}%
    \crefname{definition}{Defino}{Definoj}%
    \crefname{result}{Rezulto}{Rezultoj}%
    \crefname{example}{Ekzemplo}{Ekzemploj}%
    \crefname{remark}{Rimarko}{Rimarkoj}%
    \crefname{note}{Noto}{Notoj}%
    \crefname{algorithm}{Algoritmo}{Algoritmoj}%
    \crefname{listing}{Listado}{Listadoj}%
    \crefname{line}{Linio}{Linioj}%
%
  \else%
    \crefname{equation}{ekvacio}{ekvacioj}%
    \crefname{part}{parto}{partoj}%
    \crefname{chapter}{\^capitro}{\^capitroj}%
    \crefname{section}{sekcio}{sekcioj}%
    \crefname{appendix}{aldono}{aldonoj}%
    \crefname{enumi}{punkto}{punktoj}%
    \crefname{footnote}{piednoto}{piednotoj}%
    \crefname{figure}{figuro}{figuroj}%
    \crefname{table}{tabelo}{tabeloj}%
    \crefname{theorem}{teoremo}{teoremoj}%
    \crefname{lemma}{lemo}{lemoj}%
    \crefname{corollary}{korolario}{korolarioj}%
    \crefname{proposition}{propozicio}{propozicioj}%
    \crefname{definition}{defino}{definoj}%
    \crefname{result}{rezulto}{rezultoj}%
    \crefname{example}{ekzemplo}{ekzemploj}%
    \crefname{remark}{rimarko}{rimarkoj}%
    \crefname{note}{noto}{notoj}%
    \crefname{algorithm}{algoritmo}{algoritmoj}%
    \crefname{listing}{listado}{listadoj}%
    \crefname{line}{linio}{linioj}%
  \fi}% end \cref@loadlanguagedefs
%    \end{macrocode}
%
%
% \subsubsection{Swedish}
% \begin{macro}{swedish}
%   Swedish definitions thanks to Simon Sigurdhsson.
% \end{macro}
%
% Set up the definitions used at the beginning of the document to define
% the formats created by the document preamble.
%    \begin{macrocode}
\DeclareOption{swedish}{%
  \AtBeginDocument{%
    \def\crefrangeconjunction@preamble{ till\nobreakspace}%
    \def\crefrangepreconjunction@preamble{}%
    \def\crefrangepostconjunction@preamble{}%
    \def\crefpairconjunction@preamble{ och\nobreakspace}%
    \def\crefmiddleconjunction@preamble{, }%
    \def\creflastconjunction@preamble{ och\nobreakspace}%
%    \end{macrocode}
% We have to define the group conjunctions explicitly here, rather than
% relying on fall-back definitions in terms of the above conjunctions
% (see \cref{sec:code:default_formats}), in case any other language
% option defines them explicitly and we need to override those.
%    \begin{macrocode}
    \def\crefpairgroupconjunction@preamble{ och\nobreakspace}%
    \def\crefmiddlegroupconjunction@preamble{, }%
    \def\creflastgroupconjunction@preamble{, och\nobreakspace}%
 %
    \Crefname@preamble{equation}{Ekvation}{Ekvation}%
    \Crefname@preamble{figure}{Figur}{Figur}%
    \Crefname@preamble{table}{Tabell}{Tabell}%
    \Crefname@preamble{page}{Sida}{Sida}%
    \Crefname@preamble{part}{Del}{Del}%
    \Crefname@preamble{chapter}{Kapitel}{Kapitel}%
    \Crefname@preamble{section}{Avsnitt}{Avsnitt}%
    \Crefname@preamble{appendix}{Appendix}{Appendix}%
    \Crefname@preamble{enumi}{Punkt}{Punkt}%
    \Crefname@preamble{footnote}{Fotnot}{Fotnot}%
    \Crefname@preamble{theorem}{Sats}{Sats}%
    \Crefname@preamble{lemma}{Lemma}{Lemmas}%
    \Crefname@preamble{corollary}{F\"oljdsats}{F\"oljdsats}%
    \Crefname@preamble{proposition}{Proposition}{Proposition}%
    \Crefname@preamble{definition}{Definition}{Definition}%
    \Crefname@preamble{result}{Resultat}{Resultat}%
    \Crefname@preamble{example}{Exempel}{Exempel}%
    \Crefname@preamble{remark}{Anm\"arkning}{Anm\"arkning}%
    \Crefname@preamble{note}{Notering}{Notering}%
    \Crefname@preamble{algorithm}{Algoritm}{Algoritm}%
    \Crefname@preamble{listing}{Kodlistning}{Kodlistning}%
    \Crefname@preamble{line}{Rad}{Rad}%
 %
    \if@cref@capitalise%  capitalise set
      \if@cref@abbrev%
        \crefname@preamble{equation}{Ekv.}{Ekv.}%
        \crefname@preamble{figure}{Fig.}{Fig.}%
      \else%
        \crefname@preamble{equation}{Ekvation}{Ekvation}%
        \crefname@preamble{figure}{Figur}{Figur}%
      \fi%
      \crefname@preamble{page}{Sida}{Sida}%
      \crefname@preamble{table}{Tabell}{Tabell}%
      \crefname@preamble{part}{Del}{Del}%
      \crefname@preamble{chapter}{Kapitel}{Kapitel}%
      \crefname@preamble{section}{Avsnitt}{Avsnitt}%
      \crefname@preamble{appendix}{Appendix}{Appendix}%
      \crefname@preamble{enumi}{Punkt}{Punkt}%
      \crefname@preamble{footnote}{Fotnot}{Fotnot}%
      \crefname@preamble{theorem}{Sats}{Sats}%
      \crefname@preamble{lemma}{Lemma}{Lemmas}%
      \crefname@preamble{corollary}{F\"oljdsats}{F\"oljdsats}%
      \crefname@preamble{proposition}{Proposition}{Proposition}%
      \crefname@preamble{definition}{Definition}{Definition}%
      \crefname@preamble{result}{Resultat}{Resultat}%
      \crefname@preamble{example}{Exempel}{Exempel}%
      \crefname@preamble{remark}{Anm\"arkning}{Anm\"arkning}%
      \crefname@preamble{note}{Notering}{Notering}%
      \crefname@preamble{algorithm}{Algoritm}{Algoritm}%
      \crefname@preamble{listing}{Kodlistning}{Kodlistning}%
      \crefname@preamble{line}{Rad}{Rad}%
 %
    \else%  capitalise unset
      \if@cref@abbrev%
        \crefname@preamble{equation}{ekv.}{ekv.}%
        \crefname@preamble{figure}{fig.}{fig.}%
        \crefname@preamble{page}{s.}{ss.}%
      \else%
        \crefname@preamble{equation}{ekvation}{ekvation}%
        \crefname@preamble{figure}{figur}{figur}%
        \crefname@preamble{page}{sida}{sida}%
      \fi%
      \crefname@preamble{table}{tabell}{tabell}%
      \crefname@preamble{part}{del}{del}%
      \crefname@preamble{chapter}{kapitel}{kapitel}%
      \crefname@preamble{section}{avsnitt}{avsnitt}%
      \crefname@preamble{appendix}{appendix}{appendix}%
      \crefname@preamble{enumi}{punkt}{punkt}%
      \crefname@preamble{footnote}{fotnot}{fotnot}%
      \crefname@preamble{theorem}{sats}{sats}%
      \crefname@preamble{lemma}{lemma}{lemmas}%
      \crefname@preamble{corollary}{f\"oljdsats}{f\"oljdsats}%
      \crefname@preamble{proposition}{proposition}{proposition}%
      \crefname@preamble{definition}{definition}{definition}%
      \crefname@preamble{result}{resultat}{resultat}%
      \crefname@preamble{example}{exempel}{exempel}%
      \crefname@preamble{remark}{anm\"arkning}{anm\"arkning}%
      \crefname@preamble{note}{notering}{notering}%
      \crefname@preamble{algorithm}{algoritm}{algoritm}%
      \crefname@preamble{listing}{kodlistning}{kodlistning}%
      \crefname@preamble{line}{rad}{rad}%
    \fi%
    \def\cref@language{swedish}%
  }}% end \AtBeginDocument and \DeclareOption
%    \end{macrocode}
%
% If using \package{babel} and the corresponding option is set, or if
% using \package{polyglossia} and the language has been loaded, add
% format definition commands to \cmd{\extras}\meta{language} or
% \cmd{\captions}\meta{language} so that language switching commands will
% change the cross-reference formats appropriately.
%    \begin{macrocode}
\cref@addlanguagedefs{swedish}{%
  \PackageInfo{cleveref}{loaded `swedish' language definitions}%
  \renewcommand{\crefrangeconjunction}{ till\nobreakspace}%
  \renewcommand\crefrangepreconjunction{}%
  \renewcommand\crefrangepostconjunction{}%
  \renewcommand{\crefpairconjunction}{ och\nobreakspace}%
  \renewcommand{\crefmiddleconjunction}{, }%
  \renewcommand{\creflastconjunction}{ och\nobreakspace}%
  \renewcommand{\crefpairgroupconjunction}{ and\nobreakspace}%
  \renewcommand{\crefmiddlegroupconjunction}{, }%
  \renewcommand{\creflastgroupconjunction}{, and\nobreakspace}%
 %
  \Crefname{equation}{Ekvation}{Ekvation}%
  \Crefname{figure}{Figur}{Figur}%
  \Crefname{subfigure}{Figur}{Figur}%
  \Crefname{table}{Tabell}{Tabell}%
  \Crefname{subtable}{Tabell}{Tabell}%
  \Crefname{page}{Sida}{Sida}%
  \Crefname{part}{Del}{Del}%
  \Crefname{chapter}{Kapitel}{Kapitel}%
  \Crefname{section}{Avsnitt}{Avsnitt}%
  \Crefname{subsection}{Avsnitt}{Avsnitt}%
  \Crefname{subsubsection}{Avsnitt}{Avsnitt}%
  \Crefname{appendix}{Appendix}{Appendix}%
  \Crefname{subappendix}{Appendix}{Appendix}%
  \Crefname{subsubappendix}{Appendix}{Appendix}%
  \Crefname{subsubsubappendix}{Appendix}{Appendix}%
  \Crefname{enumi}{Punkt}{Punkt}%
  \Crefname{enumii}{Punkt}{Punkt}%
  \Crefname{enumiii}{Punkt}{Punkt}%
  \Crefname{enumiv}{Punkt}{Punkt}%
  \Crefname{enumv}{Punkt}{Punkt}%
  \Crefname{footnote}{Fotnot}{Fotnot}%
  \Crefname{theorem}{Sats}{Sats}%
  \Crefname{lemma}{Lemma}{Lemmas}%
  \Crefname{corollary}{F\"oljdsats}{F\"oljdsats}%
  \Crefname{proposition}{Proposition}{Proposition}%
  \Crefname{definition}{Definition}{Definition}%
  \Crefname{result}{Resultat}{Resultat}%
  \Crefname{example}{Exempel}{Exempel}%
  \Crefname{remark}{Anm\"arkning}{Anm\"arkning}%
  \Crefname{note}{Notering}{Notering}%
  \Crefname{algorithm}{Algoritm}{Algoritm}%
  \Crefname{listing}{Kodlistning}{Kodlistning}%
  \Crefname{line}{Rad}{Rad}%
 %
  \if@cref@capitalise%  capitalise set
    \if@cref@abbrev%
      \crefname{equation}{Ekv.}{Ekv.}%
      \crefname{figure}{Fig.}{Fig.}%
      \crefname{subfigure}{Fig.}{Fig.}%
    \else%
      \crefname{equation}{Ekvation}{Ekvation}%
      \crefname{figure}{Figur}{Figur}%
      \crefname{subfigure}{Figur}{Figur}%
    \fi%
    \crefname{page}{Sida}{Sida}%
    \crefname{table}{Tabell}{Tabell}%
    \crefname{subtable}{Tabell}{Tabell}%
    \crefname{part}{Del}{Del}%
    \crefname{chapter}{Kapitel}{Kapitel}%
    \crefname{section}{Avsnitt}{Avsnitt}%
    \crefname{subsection}{Avsnitt}{Avsnitt}%
    \crefname{subsubsection}{Avsnitt}{Avsnitt}%
    \crefname{appendix}{Appendix}{Appendix}%
    \crefname{subappendix}{Appendix}{Appendix}%
    \crefname{subsubappendix}{Appendix}{Appendix}%
    \crefname{subsubsubappendix}{Appendix}{Appendix}%
    \crefname{enumi}{Punkt}{Punkt}%
    \crefname{enumii}{Punkt}{Punkt}%
    \crefname{enumiii}{Punkt}{Punkt}%
    \crefname{enumiv}{Punkt}{Punkt}%
    \crefname{enumv}{Punkt}{Punkt}%
    \crefname{footnote}{Fotnot}{Fotnot}%
    \crefname{theorem}{Sats}{Sats}%
    \crefname{lemma}{Lemma}{Lemmas}%
    \crefname{corollary}{F\"oljdsats}{F\"oljdsats}%
    \crefname{proposition}{Proposition}{Proposition}%
    \crefname{definition}{Definition}{Definition}%
    \crefname{result}{Resultat}{Resultat}%
    \crefname{example}{Exempel}{Exempel}%
    \crefname{remark}{Anm\"arkning}{Anm\"arkning}%
    \crefname{note}{Notering}{Notering}%
    \crefname{algorithm}{Algoritm}{Algoritm}%
    \crefname{listing}{Kodlistning}{Kodlistnings}%
    \crefname{line}{Rad}{Rad}%
 %
  \else%  capitalise unset
    \if@cref@abbrev%
      \crefname{equation}{ekv.}{ekv.}%
      \crefname{figure}{fig.}{fig.}%
      \crefname{subfigure}{fig.}{fig.}%
      \crefname{page}{s.}{ss.}%
    \else%
      \crefname{equation}{ekvation}{ekvation}%
      \crefname{figure}{figur}{figur}%
      \crefname{subfigure}{figur}{figur}%
      \crefname{page}{sida}{sida}%
    \fi%
    \crefname{table}{tabell}{tabell}%
    \crefname{subtable}{tabell}{tabell}%
    \crefname{part}{del}{del}%
    \crefname{chapter}{kapitel}{kapitel}%
    \crefname{section}{avsnitt}{avsnitt}%
    \crefname{subsection}{avsnitt}{avsnitt}%
    \crefname{subsubsection}{avsnitt}{avsnitt}%
    \crefname{appendix}{appendix}{appendix}%
    \crefname{subappendix}{appendix}{appendix}%
    \crefname{subsubappendix}{appendix}{appendix}%
    \crefname{subsubsubappendix}{appendix}{appendix}%
    \crefname{enumi}{punkt}{punkt}%
    \crefname{enumii}{punkt}{punkt}%
    \crefname{enumiii}{punkt}{punkt}%
    \crefname{enumiv}{punkt}{punkt}%
    \crefname{enumv}{punkt}{punkt}%
    \crefname{footnote}{fotnot}{fotnot}%
    \crefname{theorem}{sats}{sats}%
    \crefname{lemma}{lemma}{lemmas}%
    \crefname{corollary}{f\"oljdsats}{f\"oljdsats}%
    \crefname{proposition}{proposition}{proposition}%
    \crefname{definition}{definition}{definition}%
    \crefname{result}{resultat}{resultat}%
    \crefname{example}{exempel}{exempel}%
    \crefname{remark}{anm\"arkning}{anm\"arkning}%
    \crefname{note}{notering}{notering}%
    \crefname{algorithm}{algoritm}{algoritm}%
    \crefname{listing}{kodlistning}{kodlistnings}%
    \crefname{line}{rad}{rad}%
  \fi}% end \cref@addlangagedefs
%    \end{macrocode}
%
%
% \subsubsection{Brazilian}
% \begin{macro}{brazilian}
%   Brazilian translations courtesy of Paulo Roberto Massa Cereda.
% \end{macro}
%    \begin{macrocode}
\DeclareOption{brazilian}{%
  \AtBeginDocument{%
    \def\crefrangeconjunction@preamble{ a\nobreakspace}%
    \def\crefrangepreconjunction@preamble{}%
    \def\crefrangepostconjunction@preamble{}%
    \def\crefpairconjunction@preamble{ e\nobreakspace}%
    \def\crefmiddleconjunction@preamble{, }%
    \def\creflastconjunction@preamble{ e\nobreakspace}%
%    \end{macrocode}
% We have to define the group conjunctions explicitly here, rather than
% relying on fall-back definitions in terms of the above conjunctions
% (see \cref{sec:code:default_formats}), in case any other language
% option defines them explicitly and we need to override those.
%    \begin{macrocode}
    \def\crefpairgroupconjunction@preamble{ e\nobreakspace}%
    \def\crefmiddlegroupconjunction@preamble{, }%
    \def\creflastgroupconjunction@preamble{, e\nobreakspace}%
 %
    \Crefname@preamble{equation}{Equa\c c\~ao}{Equa\c c\~oes}%
    \Crefname@preamble{figure}{Figura}{Figuras}%
    \Crefname@preamble{table}{Tabela}{Tabelas}%
    \Crefname@preamble{page}{P\'agina}{P\'aginas}%
    \Crefname@preamble{part}{Parte}{Partes}%
    \Crefname@preamble{chapter}{Cap\'itulo}{Cap\'itulos}%
    \Crefname@preamble{section}{Se\c c\~ao}{Se\c c\~oes}%
    \Crefname@preamble{appendix}{Ap\^endice}{Ap\^endices}%
    \Crefname@preamble{enumi}{Item}{Itens}%
    \Crefname@preamble{footnote}{Nota de rodap\'e}{Notas de rodap\'e}%
    \Crefname@preamble{theorem}{Teorema}{Teoremas}%
    \Crefname@preamble{lemma}{Lema}{Lemas}%
    \Crefname@preamble{corollary}{Corol\'ario}{Corol\'arios}%
    \Crefname@preamble{proposition}{Proposi\c c\~ao}{Proposi\c c\~oes}%
    \Crefname@preamble{definition}{Defini\c c\~ao}{Defini\c c\~oes}%
    \Crefname@preamble{result}{Resultado}{Resultados}%
    \Crefname@preamble{example}{Exemplo}{Exemplos}%
    \Crefname@preamble{remark}{Observa\c c\~ao}{Observa\c c\~oes}%
    \Crefname@preamble{note}{Nota}{Notas}%
    \Crefname@preamble{algorithm}{Algoritmo}{Algoritmos}%
    \Crefname@preamble{listing}{Listagem}{Listagens}%
    \Crefname@preamble{line}{Linha}{Linhas}%
 %
    \if@cref@capitalise%  capitalise set
      \if@cref@abbrev%
        \crefname@preamble{equation}{Eq.}{Eqs.}%
        \crefname@preamble{figure}{Fig.}{Figs.}%
      \else%
        \crefname@preamble{equation}{Equa\c c\~ao}{Equa\c c\~oes}%
        \crefname@preamble{figure}{Figura}{Figuras}%
      \fi%
      \crefname@preamble{page}{P\'agina}{P\'aginas}%
      \crefname@preamble{table}{Tabela}{Tabelas}%
      \crefname@preamble{part}{Parte}{Partes}%
      \crefname@preamble{chapter}{Cap\'itulo}{Cap\'itulos}%
      \crefname@preamble{section}{Se\c c\~ao}{Se\c c\~oes}%
      \crefname@preamble{appendix}{Ap\^endice}{Ap\^endices}%
      \crefname@preamble{enumi}{Item}{Itens}%
      \crefname@preamble{footnote}{Nota de rodap\'e}{Notas de rodap\'e}%
      \crefname@preamble{theorem}{Teorema}{Teoremas}%
      \crefname@preamble{lemma}{Lema}{Lemas}%
      \crefname@preamble{corollary}{Corol\'ario}{Corol\'arios}%
      \crefname@preamble{proposition}{Proposi\c c\~ao}{Proposi\c c\~oes}%
      \crefname@preamble{definition}{Defini\c c\~ao}{Defini\c c\~oes}%
      \crefname@preamble{result}{Resultado}{Resultados}%
      \crefname@preamble{example}{Exemplo}{Exemplos}%
      \crefname@preamble{remark}{Observa\c c\~ao}{Observa\c c\~oes}%
      \crefname@preamble{note}{Nota}{Notas}%
      \crefname@preamble{algorithm}{Algoritmo}{Algoritmos}%
      \crefname@preamble{listing}{Listagem}{Listagens}%
      \crefname@preamble{line}{Linha}{Linhas}%
 %
    \else%  capitalise unset
      \if@cref@abbrev%
        \crefname@preamble{equation}{eq.}{eqs.}%
        \crefname@preamble{figure}{fig.}{figs.}%
      \else%
        \crefname@preamble{equation}{equa\c c\~ao}{equa\c c\~oes}%
        \crefname@preamble{figure}{figura}{figuras}%
      \fi%
      \crefname@preamble{page}{p\'agina}{p\'aginas}%
      \crefname@preamble{table}{tabela}{tabelas}%
      \crefname@preamble{part}{parte}{partes}%
      \crefname@preamble{chapter}{cap\'itulo}{cap\'itulos}%
      \crefname@preamble{section}{se\c c\~ao}{se\c c\~oes}%
      \crefname@preamble{appendix}{ap\^endice}{ap\^endices}%
      \crefname@preamble{enumi}{item}{itens}%
      \crefname@preamble{footnote}{nota de rodap\'e}{notas de rodap\'e}%
      \crefname@preamble{theorem}{teorema}{teoremas}%
      \crefname@preamble{lemma}{lema}{lemas}%
      \crefname@preamble{corollary}{corol\'ario}{corol\'arios}%
      \crefname@preamble{proposition}{proposi\c c\~ao}{proposi\c c\~oes}%
      \crefname@preamble{definition}{defini\c c\~ao}{defini\c c\~oes}%
      \crefname@preamble{result}{resultado}{resultados}%
      \crefname@preamble{example}{exemplo}{exemplos}%
      \crefname@preamble{remark}{observa\c c\~ao}{observa\c c\~oes}%
      \crefname@preamble{note}{nota}{notas}%
      \crefname@preamble{algorithm}{algoritmo}{algoritmos}%
      \crefname@preamble{listing}{listagem}{listagens}%
      \crefname@preamble{line}{linha}{linhas}%
    \fi%
    \def\cref@language{brazilian}%
  }}% end \AtBeginDocument and \DeclareOption
%    \end{macrocode}
%
% If using \package{babel} and the corresponding option is set, or if
% using \package{polyglossia} and the language has been loaded, add
% format definition commands to \cmd{\extras}\meta{language} or
% \cmd{\captions}\meta{language} so that language switching commands will
% change the cross-reference formats appropriately.
%    \begin{macrocode}
\cref@addlanguagedefs{brazilian}{%
  \PackageInfo{cleveref}{loaded `brazilian' language definitions}%
  \renewcommand{\crefrangeconjunction}{ a\nobreakspace}%
  \renewcommand\crefrangepreconjunction{}%
  \renewcommand\crefrangepostconjunction{}%
  \renewcommand{\crefpairconjunction}{ e\nobreakspace}%
  \renewcommand{\crefmiddleconjunction}{, }%
  \renewcommand{\creflastconjunction}{ e\nobreakspace}%
  \renewcommand{\crefpairgroupconjunction}{ e\nobreakspace}%
  \renewcommand{\crefmiddlegroupconjunction}{, }%
  \renewcommand{\creflastgroupconjunction}{ e\nobreakspace}%
 %
  \Crefname{equation}{Equa\c c\~ao}{Equa\c c\~oes}%
  \Crefname{figure}{Figura}{Figuras}%
  \Crefname{subfigure}{Figura}{Figuras}%
  \Crefname{table}{Tabela}{Tabelas}%
  \Crefname{subtable}{Tabela}{Tabelas}%
  \Crefname{page}{P\'agina}{P\'aginas}%
  \Crefname{part}{Parte}{Partes}%
  \Crefname{chapter}{Cap\'itulo}{Cap\'itulos}%
  \Crefname{section}{Se\c c\~ao}{Se\c c\~oes}%
  \Crefname{subsection}{Se\c c\~ao}{Se\c c\~oes}%
  \Crefname{subsubsection}{Se\c c\~ao}{Se\c c\~oes}%
  \Crefname{appendix}{Ap\^endice}{Ap\^endices}%
  \Crefname{subappendix}{Ap\^endice}{Ap\^endices}%
  \Crefname{subsubappendix}{Ap\^endice}{Ap\^endices}%
  \Crefname{subsubsubappendix}{Ap\^endice}{Ap\^endices}%
  \Crefname{enumi}{Item}{Itens}%
  \Crefname{enumii}{Item}{Itens}%
  \Crefname{enumiii}{Item}{Itens}%
  \Crefname{enumiv}{Item}{Itens}%
  \Crefname{enumv}{Item}{Itens}%
  \Crefname{footnote}{Nota de rodap\'e}{Notas de rodap\'e}%
  \Crefname{theorem}{Teorema}{Teoremas}%
  \Crefname{lemma}{Lema}{Lemas}%
  \Crefname{corollary}{Corol\'ario}{Corol\'arios}%
  \Crefname{proposition}{Proposi\c c\~ao}{Proposi\c c\~oes}%
  \Crefname{definition}{Defini\c c\~ao}{Defini\c c\~oes}%
  \Crefname{result}{Resultado}{Resultados}%
  \Crefname{example}{Exemplo}{Exemplos}%
  \Crefname{remark}{Observa\c c\~ao}{Observa\c c\~oes}%
  \Crefname{note}{Nota}{Notas}%
  \Crefname{algorithm}{Algoritmo}{Algoritmos}%
  \Crefname{listing}{Listagem}{Listagens}%
  \Crefname{line}{Linha}{Linhas}%
 %
  \if@cref@capitalise%  capitalise set
    \if@cref@abbrev%
      \crefname{equation}{Eq.}{Eqs.}%
      \crefname{figure}{Fig.}{Figs.}%
      \crefname{subfigure}{Fig.}{Figs.}%
    \else%
      \crefname{equation}{Equa\c c\~ao}{Equa\c c\~oes}%
      \crefname{figure}{Figura}{Figuras}%
      \crefname{subfigure}{Figura}{Figuras}%
    \fi%
    \crefname{page}{P\'agina}{P\'aginas}%
    \crefname{table}{Tabela}{Tabelas}%
    \crefname{subtable}{Tabela}{Tabelas}%
    \crefname{part}{Parte}{Partes}%
    \crefname{chapter}{Cap\'itulo}{Cap\'itulos}%
    \crefname{section}{Se\c c\~ao}{Se\c c\~oes}%
    \crefname{subsection}{Se\c c\~ao}{Se\c c\~oes}%
    \crefname{subsubsection}{Se\c c\~ao}{Se\c c\~oes}%
    \crefname{appendix}{Ap\^endice}{Ap\^endices}%
    \crefname{subappendix}{Ap\^endice}{Ap\^endices}%
    \crefname{subsubappendix}{Ap\^endice}{Ap\^endices}%
    \crefname{subsubsubappendix}{Ap\^endice}{Ap\^endices}%
    \crefname{enumi}{Item}{Itens}%
    \crefname{enumii}{Item}{Itens}%
    \crefname{enumiii}{Item}{Itens}%
    \crefname{enumiv}{Item}{Itens}%
    \crefname{enumv}{Item}{Itens}%
    \crefname{footnote}{Nota de rodap\'e}{Notas de rodap\'e}%
    \crefname{theorem}{Teorema}{Teoremas}%
    \crefname{lemma}{Lema}{Lemas}%
    \crefname{corollary}{Corol\'ario}{Corol\'arios}%
    \crefname{proposition}{Proposi\c c\~ao}{Proposi\c c\~oes}%
    \crefname{definition}{Defini\c c\~ao}{Defini\c c\~oes}%
    \crefname{result}{Resultado}{Resultados}%
    \crefname{example}{Exemplo}{Exemplos}%
    \crefname{remark}{Observa\c c\~ao}{Observa\c c\~oes}%
    \crefname{note}{Nota}{Notas}%
    \crefname{algorithm}{Algoritmo}{Algoritmos}%
    \crefname{listing}{Listagem}{Listagens}%
    \crefname{line}{Linha}{Linhas}%
 %
  \else%  capitalise unset
    \if@cref@abbrev%
      \crefname{equation}{eq.}{eqs.}%
      \crefname{figure}{fig.}{figs.}%
      \crefname{subfigure}{fig.}{figs.}%
    \else%
      \crefname{equation}{equa\c c\~ao}{equa\c c\~oes}%
      \crefname{figure}{figura}{figuras}%
      \crefname{subfigure}{figura}{figuras}%
    \fi%
    \crefname{table}{tabela}{tabelas}%
    \crefname{subtable}{tabela}{tabelas}%
    \crefname{page}{p\'agina}{p\'aginas}%
    \crefname{part}{parte}{partes}%
    \crefname{chapter}{cap\'itulo}{cap\'itulos}%
    \crefname{section}{se\c c\~ao}{se\c c\~oes}%
    \crefname{subsection}{se\c c\~ao}{se\c c\~oes}%
    \crefname{subsubsection}{se\c c\~ao}{se\c c\~oes}%
    \crefname{appendix}{ap\^endice}{ap\^endices}%
    \crefname{subappendix}{ap\^endice}{ap\^endices}%
    \crefname{subsubappendix}{ap\^endice}{ap\^endices}%
    \crefname{subsubsubappendix}{ap\^endice}{ap\^endices}%
    \crefname{enumi}{item}{itens}%
    \crefname{enumii}{item}{itens}%
    \crefname{enumiii}{item}{itens}%
    \crefname{enumiv}{item}{itens}%
    \crefname{enumv}{item}{itens}%
    \crefname{footnote}{nota de rodap\'e}{notas de rodap\'e}%
    \crefname{theorem}{teorema}{teoremas}%
    \crefname{lemma}{lema}{lemas}%
    \crefname{corollary}{corol\'ario}{corol\'arios}%
    \crefname{proposition}{proposi\c c\~ao}{proposi\c c\~oes}%
    \crefname{definition}{defini\c c\~ao}{defini\c c\~oes}%
    \crefname{result}{resultado}{resultados}%
    \crefname{example}{exemplo}{exemplos}%
    \crefname{remark}{observa\c c\~ao}{observa\c c\~oes}%
    \crefname{note}{nota}{notas}%
    \crefname{algorithm}{algoritmo}{algoritmos}%
    \crefname{listing}{listagem}{listagens}%
    \crefname{line}{linha}{linhas}%
  \fi}% end \cref@addlangagedefs
%    \end{macrocode}
%
%
% \subsubsection{Catalan}
% \begin{macro}{catalan}
%   Catalan definitions thanks to Rafel Jaume Deya and Eva Bosch Roura.
% \end{macro}
%
% Set up the definitions used at the beginning of the document to define
% the formats created by the document preamble.
%    \begin{macrocode}
\DeclareOption{catalan}{%
  \AtBeginDocument{%
    \def\crefrangeconjunction@preamble{ a\nobreakspace}%
    \def\crefrangepreconjunction@preamble{}%
    \def\crefrangepostconjunction@preamble{}%
    \def\crefpairconjunction@preamble{ i\nobreakspace}%
    \def\crefmiddleconjunction@preamble{, }%
    \def\creflastconjunction@preamble{ i\nobreakspace}%
%    \end{macrocode}
% We have to define the group conjunctions explicitly here, rather than
% relying on fall-back definitions in terms of the above conjunctions
% (see \cref{sec:code:default_formats}), in case any other language
% option defines them explicitly and we need to override those.
%    \begin{macrocode}
    \def\crefpairgroupconjunction@preamble{ i\nobreakspace}%
    \def\crefmiddlegroupconjunction@preamble{, }%
    \def\creflastgroupconjunction@preamble{ i\nobreakspace}%
 %
    \Crefname@preamble{equation}{Equaci\'o}{Equacions}%
    \Crefname@preamble{figure}{Gr\`afic}{Gr\`afics}%
    \Crefname@preamble{table}{Taula}{Taules}%
    \Crefname@preamble{page}{P\`agina}{P\`agines}%
    \Crefname@preamble{part}{Part}{Parts}%
    \Crefname@preamble{chapter}{Cap\'itol}{Cap\'itols}%
    \Crefname@preamble{section}{Secci\'o}{Seccions}%
    \Crefname@preamble{appendix}{Ap\`endix}{Ap\`endixs}%
    \Crefname@preamble{enumi}{Punt}{Punts}%
    \Crefname@preamble{footnote}{Nota}{Notes}%
    \Crefname@preamble{theorem}{Teorema}{Teoremes}%
    \Crefname@preamble{lemma}{Lema}{Lemes}%
    \Crefname@preamble{corollary}{Coro\lgem ari}{Coro\lgem aris}%
    \Crefname@preamble{proposition}{Proposici\'o}{Proposicions}%
    \Crefname@preamble{definition}{Definici\'o}{Definicions}%
    \Crefname@preamble{result}{Resultat}{Resultats}%
    \Crefname@preamble{example}{Exemple}{Exemples}%
    \Crefname@preamble{remark}{Observaci\'o}{Observacions}%
    \Crefname@preamble{note}{Nota}{Notes}%
    \Crefname@preamble{algorithm}{Algorisme}{Algorismes}%
    \Crefname@preamble{listing}{Llistat}{Llistats}%
    \Crefname@preamble{line}{L\'inia}{L\'inies}%
 %
    \if@cref@capitalise%  capitalise set
      \crefname@preamble{equation}{Equaci\'o}{Equacions}%
      \crefname@preamble{figure}{Gr\`afic}{Gr\`afics}%
      \crefname@preamble{table}{Taula}{Taules}%
      \crefname@preamble{page}{P\`agina}{P\`agines}%
      \crefname@preamble{part}{Part}{Parts}%
      \crefname@preamble{chapter}{Cap\'itol}{Cap\'itols}%
      \crefname@preamble{section}{Secci\'o}{Seccions}%
      \crefname@preamble{appendix}{Ap\`endix}{Ap\`endixs}%
      \crefname@preamble{enumi}{Punt}{Punts}%
      \crefname@preamble{footnote}{Nota}{Notes}%
      \crefname@preamble{theorem}{Teorema}{Teoremes}%
      \crefname@preamble{lemma}{Lema}{Lemes}%
      \crefname@preamble{corollary}{Coro\lgem ari}{Coro\lgem aris}%
      \crefname@preamble{proposition}{Proposici\'o}{Proposicions}%
      \crefname@preamble{definition}{Definici\'o}{Definicions}%
      \crefname@preamble{result}{Resultat}{Resultats}%
      \crefname@preamble{example}{Exemple}{Exemples}%
      \crefname@preamble{remark}{Observaci\'o}{Observacions}%
      \crefname@preamble{note}{Nota}{Notes}%
      \crefname@preamble{algorithm}{Algorisme}{Algorismes}%
      \crefname@preamble{listing}{Llistat}{Llistats}%
      \crefname@preamble{line}{L\'inia}{L\'inies}%
 %
    \else%  capitalise unset
      \crefname@preamble{equation}{equaci\'o}{equacions}%
      \crefname@preamble{figure}{gr\`afic}{gr\`afics}%
      \crefname@preamble{table}{taula}{taules}%
      \crefname@preamble{page}{p\`agina}{p\`agines}%
      \crefname@preamble{part}{part}{parts}%
      \crefname@preamble{chapter}{cap\'itol}{cap\'itols}%
      \crefname@preamble{section}{secci\'o}{seccions}%
      \crefname@preamble{appendix}{ap\`endix}{ap\`endixs}%
      \crefname@preamble{enumi}{punt}{punts}%
      \crefname@preamble{footnote}{nota}{notes}%
      \crefname@preamble{theorem}{teorema}{teoremes}%
      \crefname@preamble{lemma}{lema}{lemes}%
      \crefname@preamble{corollary}{coro\lgem ari}{coro\lgem aris}%
      \crefname@preamble{proposition}{proposici\'o}{proposicions}%
      \crefname@preamble{definition}{definici\'o}{definicions}%
      \crefname@preamble{result}{resultat}{resultats}%
      \crefname@preamble{example}{exemple}{exemples}%
      \crefname@preamble{remark}{observaci\'o}{observacions}%
      \crefname@preamble{note}{nota}{notes}%
      \crefname@preamble{algorithm}{algorisme}{algorismes}%
      \crefname@preamble{listing}{llistat}{llistats}%
      \crefname@preamble{line}{l\'inia}{l\'inies}%
    \fi%
    \def\cref@language{catalan}%
  }}% end \AtBeginDocument and \DeclareOption
%    \end{macrocode}
%
% If using \package{babel} and the corresponding option is set, or if
% using \package{polyglossia} and the language has been loaded, add
% format definition commands to \cmd{\extras}\meta{language} or
% \cmd{\captions}\meta{language} so that language switching commands will
% change the cross-reference formats appropriately.
%    \begin{macrocode}
\cref@addlanguagedefs{catalan}{%
  \PackageInfo{cleveref}{loaded `catalan language definitions}%
  \renewcommand{\crefrangeconjunction}{ a\nobreakspace}%
  \renewcommand{\crefrangepreconjunction}{}%
  \renewcommand{\crefrangepostconjunction}{}%
  \renewcommand{\crefpairconjunction}{ i\nobreakspace}%
  \renewcommand{\crefmiddleconjunction}{, }%
  \renewcommand{\creflastconjunction}{ i\nobreakspace}%
  \renewcommand{\crefpairgroupconjunction}{ i\nobreakspace}%
  \renewcommand{\crefmiddlegroupconjunction}{, }%
  \renewcommand{\creflastgroupconjunction}{ i\nobreakspace}%
 %
  \Crefname{equation}{Equaci\'o}{Equacions}%
  \Crefname{figure}{Gr\`afic}{Gr\`afics}%
  \Crefname{subfigure}{Gr\`afic}{Gr\`afics}%
  \Crefname{table}{Taula}{Taules}%
  \Crefname{subtable}{Taula}{Taules}%
  \Crefname{page}{P\`agina}{P\`aginas}%
  \Crefname{part}{Part}{Parts}%
  \Crefname{chapter}{Cap\'itol}{Cap\'itols}%
  \Crefname{section}{Secci\'o}{Seccions}%
  \Crefname{subsection}{Secci\'o}{Seccions}%
  \Crefname{subsubsection}{Secci\'o}{Seccions}%
  \Crefname{appendix}{Ap\`endix}{Ap\`endixs}%
  \Crefname{subappendix}{Ap\`endix}{Ap\`endixs}%
  \Crefname{subsubappendix}{Ap\`endix}{Ap\`endixs}%
  \Crefname{subsubsubappendix}{Ap\`endix}{Ap\`endixs}%
  \Crefname{enumi}{Punt}{Punts}%
  \Crefname{enumii}{Punt}{Punts}%
  \Crefname{enumiii}{Punt}{Punts}%
  \Crefname{enumiv}{Punt}{Punts}%
  \Crefname{enumv}{Punt}{Punts}%
  \Crefname{footnote}{Nota}{Notes}%
  \Crefname{theorem}{Teorema}{Teoremes}%
  \Crefname{lemma}{Lema}{Lemes}%
  \Crefname{corollary}{Coro\lgem ari}{Coro\lgem aris}%
  \Crefname{proposition}{Proposici\'o}{Proposicions}%
  \Crefname{definition}{Definici\'o}{Definicions}%
  \Crefname{result}{Resultat}{Resultats}%
  \Crefname{example}{Exemple}{Exemples}%
  \Crefname{remark}{Observaci\'o}{Observacions}%
  \Crefname{note}{Nota}{Notes}%
  \Crefname{algorithm}{Algorisme}{Algorismes}%
  \Crefname{listing}{Llistat}{Llistats}%
  \Crefname{line}{L\'inia}{L\'inies}%
 %
  \if@cref@capitalise%  capitalise set
    \crefname{equation}{Equaci\'o}{Equacions}%
    \crefname{figure}{Gr\`afic}{Gr\`afics}%
    \crefname{subfigure}{Gr\`afic}{Gr\`afics}%
    \crefname{table}{Taula}{Taules}%
    \crefname{subtable}{Taula}{Taules}%
    \crefname{page}{P\`agina}{P\`aginas}%
    \crefname{part}{Part}{Parts}%
    \crefname{chapter}{Cap\'itol}{Cap\'itols}%
    \crefname{section}{Secci\'o}{Seccions}%
    \crefname{subsection}{Secci\'o}{Seccions}%
    \crefname{subsubsection}{Secci\'o}{Seccions}%
    \crefname{appendix}{Ap\`endix}{Ap\`endixs}%
    \crefname{subappendix}{Ap\`endix}{Ap\`endixs}%
    \crefname{subsubappendix}{Ap\`endix}{Ap\`endixs}%
    \crefname{subsubsubappendix}{Ap\`endix}{Ap\`endixs}%
    \crefname{enumi}{Punt}{Punts}%
    \crefname{enumii}{Punt}{Punts}%
    \crefname{enumiii}{Punt}{Punts}%
    \crefname{enumiv}{Punt}{Punts}%
    \crefname{enumv}{Punt}{Punts}%
    \crefname{footnote}{Nota}{Notes}%
    \crefname{theorem}{Teorema}{Teoremes}%
    \crefname{lemma}{Lema}{Lemes}%
    \crefname{corollary}{Coro\lgem ari}{Coro\lgem aris}%
    \crefname{proposition}{Proposici\'o}{Proposicions}%
    \crefname{definition}{Definici\'o}{Definicions}%
    \crefname{result}{Resultat}{Resultats}%
    \crefname{example}{Exemple}{Exemples}%
    \crefname{remark}{Observaci\'o}{Observacions}%
    \crefname{note}{Nota}{Notes}%
    \crefname{algorithm}{Algorisme}{Algorismes}%
    \crefname{listing}{Llistat}{Llistats}%
    \crefname{line}{L\'inia}{L\'inies}%
 %
  \else%  capitalise unset
    \crefname{equation}{equaci\'o}{equacions}%
    \crefname{figure}{gr\`afic}{gr\`afics}%
    \crefname{subfigure}{gr\`afic}{gr\`afics}%
    \crefname{table}{taula}{taules}%
    \crefname{subtable}{taula}{taules}%
    \crefname{page}{p\`agina}{p\`aginas}%
    \crefname{part}{part}{parts}%
    \crefname{chapter}{cap\'itol}{cap\'itols}%
    \crefname{section}{secci\'o}{seccions}%
    \crefname{subsection}{secci\'o}{seccions}%
    \crefname{subsubsection}{secci\'o}{seccions}%
    \crefname{appendix}{ap\`endix}{ap\`endixs}%
    \crefname{subappendix}{ap\`endix}{ap\`endixs}%
    \crefname{subsubappendix}{ap\`endix}{ap\`endixs}%
    \crefname{subsubsubappendix}{ap\`endix}{ap\`endixs}%
    \crefname{enumi}{punt}{punts}%
    \crefname{enumii}{punt}{punts}%
    \crefname{enumiii}{punt}{punts}%
    \crefname{enumiv}{punt}{punts}%
    \crefname{enumv}{punt}{punts}%
    \crefname{footnote}{nota}{notes}%
    \crefname{theorem}{teorema}{teoremes}%
    \crefname{lemma}{lema}{lemes}%
    \crefname{corollary}{coro\lgem ari}{coro\lgem aris}%
    \crefname{proposition}{proposici\'o}{proposicions}%
    \crefname{definition}{definici\'o}{definicions}%
    \crefname{result}{resultat}{resultats}%
    \crefname{example}{exemple}{exemples}%
    \crefname{remark}{observaci\'o}{observacions}%
    \crefname{note}{nota}{notes}%
    \crefname{algorithm}{algorisme}{algorismes}%
    \crefname{listing}{llistat}{llistats}%
    \crefname{line}{l\'inia}{l\'inies}%
  \fi}% end \cref@loadlanguagedefs
%    \end{macrocode}
%
%
% \subsection{Default Cross-Reference Formats}
% \label{sec:code:default_formats}
% The \option{capitalise} and \option{nameinlink} options must be
% processed before we process any language options and define the default
% formats, so that they take effect in the default format definitions.
% Therefore, we have to manually check whether they're present, and force
% processing of those before the other options.
%    \begin{macrocode}
\edef\@curroptions{\@ptionlist{\@currname.\@currext}}%
\@expandtwoargs\in@{,capitalise,}{%
  ,\@classoptionslist,\@curroptions,}%
\ifin@%
  \ExecuteOptions{capitalise}%
\else%
  \@expandtwoargs\in@{,capitalize,}{%
    ,\@classoptionslist,\@curroptions,}%
  \ifin@%
    \ExecuteOptions{capitalise}%
  \fi%
\fi%
\@expandtwoargs\in@{,nameinlink,}{%
  ,\@classoptionslist,\@curroptions,}%
\ifin@%
  \ExecuteOptions{nameinlink}%
\fi%
%    \end{macrocode}
%
%
% \begin{macro}{\crefdefaultlabelformat}
% \begin{macro}{\creflabelformat}
%   Define the default label formats, which don't depend on language. We
%   override the default format for equations, to follow the near
%   universal convention of enclosing equation labels in parentheses.
%   However, if the \option{nameinlink} option is enabled, the end of the
%   hyperlink must come outside the group or it will cause \LaTeX{}
%   grouping errors, so we must define it differently in that case.
%    \begin{macrocode}
\crefdefaultlabelformat{#2#1#3}%
\if@cref@nameinlink%
  \creflabelformat{equation}{#2\textup{(#1)}#3}%
\else%
  \creflabelformat{equation}{\textup{(#2#1#3)}}%
\fi%
%    \end{macrocode}
% \end{macro}
% \end{macro}
%
%
% Set up the default English format definitions, then process options in
% the order they were supplied.
%    \begin{macrocode}
\@ifpackageloaded{polyglossia}%
  {\ifcsdef{languagename}%
    {\ExecuteOptions{\languagename}}%
    {\PackageWarning{cleveref}%
       {`polyglossia' loaded but default language not set
         - defaulting to english}%
     \ExecuteOptions{english}}}%
  {\ExecuteOptions{english}}%
\ProcessOptions*\relax%
%    \end{macrocode}
%
%
% Define the component-derived formats.
%    \begin{macrocode}
\AtBeginDocument{%
%    \end{macrocode}
% Use whatever's in the \dots|@preamble| definitions at the beginning of
% the document to set up the default cross-reference names, unless
% overridden by explicit definitions.
%    \begin{macrocode}
  \edef\@tempa{%
    \expandafter\noexpand\csname extras\cref@language\endcsname}%
  \@ifundefined{crefrangeconjunction}{%
    \let\crefrangeconjunction\crefrangeconjunction@preamble%
  }{%
    \expandafter\def\expandafter\@tempb\expandafter{%
      \expandafter\renewcommand\expandafter%
      {\expandafter\crefrangeconjunction\expandafter}%
      \expandafter{\crefrangeconjunction}}%
    \expandafter\expandafter\expandafter\cref@addto%
      \expandafter\@tempa\expandafter{\@tempb}%
  }%
  \@ifundefined{crefrangepreconjunction}{%
    \let\crefrangepreconjunction\crefrangepreconjunction@preamble%
  }{%
    \expandafter\def\expandafter\@tempb\expandafter{%
      \expandafter\renewcommand\expandafter%
      {\expandafter\crefrangepreconjunction\expandafter}%
      \expandafter{\crefrangepreconjunction}}%
    \expandafter\expandafter\expandafter\cref@addto%
      \expandafter\@tempa\expandafter{\@tempb}%
  }%
  \@ifundefined{crefrangepostconjunction}{%
    \let\crefrangepostconjunction\crefrangepostconjunction@preamble%
  }{%
    \expandafter\def\expandafter\@tempb\expandafter{%
      \expandafter\renewcommand\expandafter%
      {\expandafter\crefrangepostconjunction\expandafter}%
      \expandafter{\crefrangepostconjunction}}%
    \expandafter\expandafter\expandafter\cref@addto%
      \expandafter\@tempa\expandafter{\@tempb}%
  }%
%    \end{macrocode}
% If the group conjunctions haven't been defined, but explicit
% definitions \emph{have} been given for the reference list conjunctions,
% define the group conjunctions to be identical to the reference
% conjunctions.
%    \begin{macrocode}
  \@ifundefined{crefpairconjunction}{%
    \let\crefpairconjunction\crefpairconjunction@preamble%
  }{%
    \expandafter\def\expandafter\@tempb\expandafter{%
      \expandafter\renewcommand\expandafter%
      {\expandafter\crefpairconjunction\expandafter}%
      \expandafter{\crefpairconjunction}}%
    \expandafter\expandafter\expandafter\cref@addto%
      \expandafter\@tempa\expandafter{\@tempb}%
    \@ifundefined{crefpairgroupconjunction}{%
      \let\crefpairgroupconjunction\crefpairconjunction}{}%
  }%
  \@ifundefined{crefmiddleconjunction}{%
    \let\crefmiddleconjunction\crefmiddleconjunction@preamble%
  }{%
    \expandafter\def\expandafter\@tempb\expandafter{%
      \expandafter\renewcommand\expandafter%
      {\expandafter\crefmiddleconjunction\expandafter}%
      \expandafter{\crefmiddleconjunction}}%
    \expandafter\expandafter\expandafter\cref@addto%
      \expandafter\@tempa\expandafter{\@tempb}%
    \@ifundefined{crefmiddlegroupconjunction}{%
      \let\crefmiddlegroupconjunction\crefmiddleconjunction}{}%
  }%
  \@ifundefined{creflastconjunction}{%
    \let\creflastconjunction\creflastconjunction@preamble%
  }{%
    \expandafter\def\expandafter\@tempb\expandafter{%
      \expandafter\renewcommand\expandafter%
      {\expandafter\creflastconjunction\expandafter}%
      \expandafter{\creflastconjunction}}%
    \expandafter\expandafter\expandafter\cref@addto%
      \expandafter\@tempa\expandafter{\@tempb}%
%    \end{macrocode}
% Define the last group conjunction to include an extra comma.
%    \begin{macrocode}
    \@ifundefined{creflastgroupconjunction}{%
      \edef\creflastgroupconjunction{, \creflastconjunction}}{}%
  }%
  \@ifundefined{crefpairgroupconjunction}{%
    \let\crefpairgroupconjunction%
    \crefpairgroupconjunction@preamble%
  }{%
    \expandafter\def\expandafter\@tempb\expandafter{%
      \expandafter\renewcommand\expandafter%
      {\expandafter\crefpairgroupconjunction\expandafter}%
      \expandafter{\crefpairgroupconjunction}}%
    \expandafter\expandafter\expandafter\cref@addto%
      \expandafter\@tempa\expandafter{\@tempb}%
  }%
  \@ifundefined{crefmiddlegroupconjunction}{%
    \let\crefmiddlegroupconjunction%
      \crefmiddlegroupconjunction@preamble%
  }{%
    \expandafter\def\expandafter\@tempb\expandafter{%
      \expandafter\renewcommand\expandafter%
      {\expandafter\crefmiddlegroupconjunction\expandafter}%
      \expandafter{\crefmiddlegroupconjunction}}%
    \expandafter\expandafter\expandafter\cref@addto%
      \expandafter\@tempa\expandafter{\@tempb}%
  }%
  \@ifundefined{creflastgroupconjunction}{%
    \let\creflastgroupconjunction%
      \creflastgroupconjunction@preamble%
  }{%
    \expandafter\def\expandafter\@tempb\expandafter{%
      \expandafter\renewcommand\expandafter%
      {\expandafter\creflastgroupconjunction\expandafter}%
      \expandafter{\creflastgroupconjunction}}%
    \expandafter\expandafter\expandafter\cref@addto%
      \expandafter\@tempa\expandafter{\@tempb}%
  }%
%    \end{macrocode}
%
% Define any undefined formats listed in \cmd{\cref@label@types} using
% the components.
%    \begin{macrocode}
  \let\@tempstack\cref@label@types%
  \cref@isstackfull{\@tempstack}%
  \@whilesw\if@cref@stackfull\fi{%
    \edef\@tempa{\cref@stack@top{\@tempstack}}%
    \@ifundefined{cref@\@tempa @name}{%
      \expandafter\def\expandafter\@tempb\expandafter{%
        \csname cref@\@tempa @name\endcsname}%
      \expandafter\def\expandafter\@tempc\expandafter{%
        \csname cref@\@tempa @name@preamble\endcsname}%
      \expandafter\expandafter\expandafter%
        \let\expandafter\@tempb\@tempc%
      \expandafter\def\expandafter\@tempb\expandafter{%
        \csname cref@\@tempa @name@plural\endcsname}%
      \expandafter\def\expandafter\@tempc\expandafter{%
        \csname cref@\@tempa @name@plural@preamble\endcsname}%
      \expandafter\expandafter\expandafter%
        \let\expandafter\@tempb\@tempc%
    }{%
      \edef\@tempb{%
        \expandafter\noexpand\csname extras\cref@language\endcsname}%
      \expandafter\def\expandafter\@tempc\expandafter{%
        \expandafter\crefname\expandafter{\@tempa}}%
      \expandafter\expandafter\expandafter\cref@addto%
      \expandafter\expandafter\expandafter\@tempc%
      \expandafter\expandafter\expandafter{%
        \expandafter\expandafter\expandafter{%
          \csname cref@\@tempa @name\endcsname}}%
      \expandafter\expandafter\expandafter\cref@addto%
      \expandafter\expandafter\expandafter\@tempc%
      \expandafter\expandafter\expandafter{%
        \expandafter\expandafter\expandafter{%
          \csname cref@\@tempa @name@plural\endcsname}}%
      \expandafter\expandafter\expandafter\cref@addto%
        \expandafter\@tempb\expandafter{\@tempc}%
    }%
    \@ifundefined{Cref@\@tempa @name}{%
      \expandafter\def\expandafter\@tempb\expandafter{%
        \csname Cref@\@tempa @name\endcsname}%
      \expandafter\def\expandafter\@tempc\expandafter{%
        \csname Cref@\@tempa @name@preamble\endcsname}%
      \expandafter\expandafter\expandafter%
        \let\expandafter\@tempb\@tempc%
      \expandafter\def\expandafter\@tempb\expandafter{%
        \csname Cref@\@tempa @name@plural\endcsname}%
      \expandafter\def\expandafter\@tempc\expandafter{%
        \csname Cref@\@tempa @name@plural@preamble\endcsname}%
      \expandafter\expandafter\expandafter%
        \let\expandafter\@tempb\@tempc%
    }{%
      \edef\@tempb{%
        \expandafter\noexpand\csname extras\cref@language\endcsname}%
      \expandafter\def\expandafter\@tempc\expandafter{%
        \expandafter\Crefname\expandafter{\@tempa}}%
      \expandafter\expandafter\expandafter\cref@addto%
      \expandafter\expandafter\expandafter\@tempc%
      \expandafter\expandafter\expandafter{%
        \expandafter\expandafter\expandafter{%
          \csname Cref@\@tempa @name\endcsname}}%
      \expandafter\expandafter\expandafter\cref@addto%
      \expandafter\expandafter\expandafter\@tempc%
      \expandafter\expandafter\expandafter{%
        \expandafter\expandafter\expandafter{%
          \csname Cref@\@tempa @name@plural\endcsname}}%
      \expandafter\expandafter\expandafter\cref@addto%
        \expandafter\@tempb\expandafter{\@tempc}%
    }%
%    \end{macrocode}
% We only define the reference-range and multi-reference formats if the
% plural form of the name is defined in the corresponding
% \cmd{\cref\meta{type}@name@plural}. Though \cmd{\crefname} and
% \cmd{\Crefname} always define both the singular and plural forms
% together, cross-reference names can also be defined automatically by
% \cmd{\newtheorem}, which can only define the singular form. For
% symmetry, we apply the same logic to the normal cross-reference format
% definition (only defining it if the singular form of the name is
% defined in \cmd{\cref\meta{type}@name}), though this should always be
% the case.
%    \begin{macrocode}
    \@ifundefined{cref@\@tempa @format}{%
      \@ifundefined{cref@\@tempa @name}{}{%
        \expandafter\@crefdefineformat\expandafter{\@tempa}}}{}%
    \@ifundefined{crefrange@\@tempa @format}{%
      \@ifundefined{cref@\@tempa @name@plural}{}{%
        \expandafter\@crefrangedefineformat\expandafter{\@tempa}}}{}%
    \@ifundefined{cref@\@tempa @format@first}{%
      \@ifundefined{cref@\@tempa @name@plural}{}{%
        \expandafter\@crefdefinemultiformat\expandafter{\@tempa}}}{}%
    \@ifundefined{crefrange@\@tempa @format@first}{%
      \@ifundefined{cref@\@tempa @name@plural}{}{%
        \expandafter\@crefrangedefinemultiformat%
        \expandafter{\@tempa}}}{}%
    \cref@stack@pop{\@tempstack}%
    \cref@isstackfull{\@tempstack}}%
%    \end{macrocode}
%
% If formats for subsections are undefined, define them to be identical
% to the formats for sections. Similarly for subsections within
% appendices, subfigures, subtables, subequations and enums.
%    \begin{macrocode}
  \@crefcopyformats{section}{subsection}%
  \@crefcopyformats{subsection}{subsubsection}%
  \@crefcopyformats{appendix}{subappendix}%
  \@crefcopyformats{subappendix}{subsubappendix}%
  \@crefcopyformats{figure}{subfigure}%
  \@crefcopyformats{table}{subtable}%
  \@crefcopyformats{equation}{subequation}%
%
  \@crefcopyformats{enumi}{enumii}%
  \@crefcopyformats{enumii}{enumiii}%
  \@crefcopyformats{enumiii}{enumiv}%
  \@crefcopyformats{enumiv}{enumv}%
%    \end{macrocode}
% Definition of default |\labelcref| formats also needs to be postponed
% until beginning of document, in case |\crefdefaultlabelformat| has been
% modified.
%    \begin{macrocode}
  \@labelcrefdefinedefaultformats%
  %
  \let\cref@language\relax%
}%  end of \AtBeginDocument
%    \end{macrocode}
%
%
%
% \subsection{\file{cleveref.cfg} Config File}
% \begin{macro}{cleveref.cfg}
%   If \LaTeX{} can find a \file{cleveref.cfg} file in its search path,
%   then we read in whatever's in it. The intended use of
%   \file{cleveref.cfg} is to make it easy for authors to customise the
%   cross-reference formats for all their documents, without having to
%   manually include the definitions in every document preamble. In order
%   for these customisations to override the default formats, we input
%   \file{cleveref.cfg} right at the end, after the rest of
%   \package{cleveref} has loaded.
%    \begin{macrocode}
\InputIfFileExists{cleveref.cfg}%
  {\PackageInfo{cleveref}{reading definitions from cleveref.cfg}}{}%
%    \end{macrocode}
% \end{macro}
%
%
%
% \Finale
\endinput
%%
%% End of file `cleveref.dtx'.

%%% Local Variables:
%%% mode: doctex
%%% TeX-command-default: "Make"
%%% fill-column: 73
%%% TeX-master: t
%%% End: