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
|
% \iffalse meta-comment
%
% Copyright (C) 2006-2010 by
% Heiko Oberdiek <heiko.oberdiek at googlemail.com>
%
% This work may be distributed and/or modified under the
% conditions of the LaTeX Project Public License, either
% version 1.3c of this license or (at your option) any later
% version. This version of this license is in
% http://www.latex-project.org/lppl/lppl-1-3c.txt
% and the latest version of this license is in
% http://www.latex-project.org/lppl.txt
% and version 1.3 or later is part of all distributions of
% LaTeX version 2005/12/01 or later.
%
% This work has the LPPL maintenance status "maintained".
%
% This Current Maintainer of this work is Heiko Oberdiek.
%
% This work consists of the main source file zref.dtx
% and the derived files
% zref.sty, zref.pdf, zref.ins, zref.drv, zref-base.sty,
% zref-abspage.sty, zref-counter.sty, zref-dotfill.sty,
% zref-hyperref.sty, zref-lastpage.sty, zref-nextpage.sty,
% zref-perpage.sty, zref-runs.sty, zref-savepos.sty,
% zref-thepage.sty, zref-titleref.sty, zref-totpages.sty,
% zref-user.sty, zref-xr.sty, zref-example.tex,
% zref-example-lastpage.tex, zref-example-nextpage.tex,
% zref-test1.tex, zref-test-runs.tex.
%
% Distribution:
% CTAN:macros/latex/contrib/oberdiek/zref.dtx
% CTAN:macros/latex/contrib/oberdiek/zref.pdf
%
% Unpacking:
% (a) If zref.ins is present:
% tex zref.ins
% (b) Without zref.ins:
% tex zref.dtx
% (c) If you insist on using LaTeX
% latex \let\install=y\input{zref.dtx}
% (quote the arguments according to the demands of your shell)
%
% Documentation:
% (a) If zref.drv is present:
% latex zref.drv
% (b) Without zref.drv:
% latex zref.dtx; ...
% The class ltxdoc loads the configuration file ltxdoc.cfg
% if available. Here you can specify further options, e.g.
% use A4 as paper format:
% \PassOptionsToClass{a4paper}{article}
%
% Programm calls to get the documentation (example):
% pdflatex zref.dtx
% makeindex -s gind.ist zref.idx
% pdflatex zref.dtx
% makeindex -s gind.ist zref.idx
% pdflatex zref.dtx
%
% Installation:
% TDS:tex/latex/oberdiek/zref.sty
% TDS:tex/latex/oberdiek/zref-base.sty
% TDS:tex/latex/oberdiek/zref-abspage.sty
% TDS:tex/latex/oberdiek/zref-counter.sty
% TDS:tex/latex/oberdiek/zref-dotfill.sty
% TDS:tex/latex/oberdiek/zref-hyperref.sty
% TDS:tex/latex/oberdiek/zref-lastpage.sty
% TDS:tex/latex/oberdiek/zref-nextpage.sty
% TDS:tex/latex/oberdiek/zref-perpage.sty
% TDS:tex/latex/oberdiek/zref-runs.sty
% TDS:tex/latex/oberdiek/zref-savepos.sty
% TDS:tex/latex/oberdiek/zref-thepage.sty
% TDS:tex/latex/oberdiek/zref-titleref.sty
% TDS:tex/latex/oberdiek/zref-totpages.sty
% TDS:tex/latex/oberdiek/zref-user.sty
% TDS:tex/latex/oberdiek/zref-xr.sty
% TDS:doc/latex/oberdiek/zref.pdf
% TDS:doc/latex/oberdiek/zref-example.tex
% TDS:doc/latex/oberdiek/zref-example-lastpage.tex
% TDS:doc/latex/oberdiek/zref-example-nextpage.tex
% TDS:doc/latex/oberdiek/test/zref-test1.tex
% TDS:doc/latex/oberdiek/test/zref-test-runs.tex
% TDS:source/latex/oberdiek/zref.dtx
%
%<*ignore>
\begingroup
\catcode123=1 %
\catcode125=2 %
\def\x{LaTeX2e}%
\expandafter\endgroup
\ifcase 0\ifx\install y1\fi\expandafter
\ifx\csname processbatchFile\endcsname\relax\else1\fi
\ifx\fmtname\x\else 1\fi\relax
\else\csname fi\endcsname
%</ignore>
%<*install>
\input docstrip.tex
\Msg{************************************************************************}
\Msg{* Installation}
\Msg{* Package: zref 2010/03/26 v2.8 New reference scheme for LaTeX2e (HO)}
\Msg{************************************************************************}
\keepsilent
\askforoverwritefalse
\let\MetaPrefix\relax
\preamble
This is a generated file.
Copyright (C) 2006-2010 by
Heiko Oberdiek <heiko.oberdiek at googlemail.com>
This work may be distributed and/or modified under the
conditions of the LaTeX Project Public License, either
version 1.3c of this license or (at your option) any later
version. This version of this license is in
http://www.latex-project.org/lppl/lppl-1-3c.txt
and the latest version of this license is in
http://www.latex-project.org/lppl.txt
and version 1.3 or later is part of all distributions of
LaTeX version 2005/12/01 or later.
This work has the LPPL maintenance status "maintained".
This Current Maintainer of this work is Heiko Oberdiek.
This work consists of the main source file zref.dtx
and the derived files
zref.sty, zref.pdf, zref.ins, zref.drv, zref-base.sty,
zref-abspage.sty, zref-counter.sty, zref-dotfill.sty,
zref-hyperref.sty, zref-lastpage.sty, zref-nextpage.sty,
zref-perpage.sty, zref-runs.sty, zref-savepos.sty,
zref-thepage.sty, zref-titleref.sty, zref-totpages.sty,
zref-user.sty, zref-xr.sty, zref-example.tex,
zref-example-lastpage.tex, zref-example-nextpage.tex,
zref-test1.tex, zref-test-runs.tex.
\endpreamble
\let\MetaPrefix\DoubleperCent
\generate{%
\file{zref.ins}{\from{zref.dtx}{install}}%
\file{zref.drv}{\from{zref.dtx}{driver}}%
\usedir{tex/latex/oberdiek}%
\file{zref.sty}{\from{zref.dtx}{package}}%
\file{zref-base.sty}{\from{zref.dtx}{base}}%
\file{zref-abspage.sty}{\from{zref.dtx}{abspage}}%
\file{zref-counter.sty}{\from{zref.dtx}{counter}}%
\file{zref-dotfill.sty}{\from{zref.dtx}{dotfill}}%
\file{zref-hyperref.sty}{\from{zref.dtx}{hyperref}}%
\file{zref-lastpage.sty}{\from{zref.dtx}{lastpage}}%
\file{zref-nextpage.sty}{\from{zref.dtx}{nextpage}}%
\file{zref-perpage.sty}{\from{zref.dtx}{perpage}}%
\file{zref-runs.sty}{\from{zref.dtx}{runs}}%
\file{zref-savepos.sty}{\from{zref.dtx}{savepos}}%
\file{zref-thepage.sty}{\from{zref.dtx}{thepage}}%
\file{zref-titleref.sty}{\from{zref.dtx}{titleref}}%
\file{zref-totpages.sty}{\from{zref.dtx}{totpages}}%
\file{zref-user.sty}{\from{zref.dtx}{user}}%
\file{zref-xr.sty}{\from{zref.dtx}{xr}}%
\usedir{doc/latex/oberdiek}%
\file{zref-example.tex}{\from{zref.dtx}{example}}%
\file{zref-example-lastpage.tex}{\from{zref.dtx}{example-lastpage}}%
\file{zref-example-nextpage.tex}{\from{zref.dtx}{example-nextpage}}%
\usedir{doc/latex/oberdiek/test}%
\file{zref-test1.tex}{\from{zref.dtx}{test1}}%
\file{zref-test-runs.tex}{\from{zref.dtx}{test-runs}}%
}
\catcode32=13\relax% active space
\let =\space%
\Msg{************************************************************************}
\Msg{*}
\Msg{* To finish the installation you have to move the following}
\Msg{* files into a directory searched by TeX:}
\Msg{*}
\Msg{* zref.sty, zref-base.sty, zref-abspage.sty, zref-counter.sty,}
\Msg{* zref-dotfill.sty, zref-hyperref.sty, zref-lastpage.sty,}
\Msg{* zref-nextpage.sty, zref-perpage.sty, zref-runs.sty,}
\Msg{* zref-savepos.sty, zref-thepage.sty, zref-titleref.sty,}
\Msg{* zref-totpages.sty, zref-user.sty, zref-xr.sty}
\Msg{*}
\Msg{* And install the following script file:}
\Msg{*}
\Msg{* }
\Msg{*}
\Msg{* To produce the documentation run the file `zref.drv'}
\Msg{* through LaTeX.}
\Msg{*}
\Msg{* Happy TeXing!}
\Msg{*}
\Msg{************************************************************************}
\endbatchfile
%</install>
%<*ignore>
\fi
%</ignore>
%<*driver>
\NeedsTeXFormat{LaTeX2e}
\ProvidesFile{zref.drv}%
[2010/03/26 v2.8 New reference scheme for LaTeX2e (HO)]%
\documentclass{ltxdoc}
\usepackage{holtxdoc}[2008/08/11]
\begin{document}
\DocInput{zref.dtx}%
\end{document}
%</driver>
% \fi
%
% \CheckSum{1838}
%
% \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 \~}
%
% \GetFileInfo{zref.drv}
%
% \title{The \xpackage{zref} package}
% \date{2010/03/26 v2.8}
% \author{Heiko Oberdiek\\\xemail{heiko.oberdiek at googlemail.com}}
%
% \maketitle
%
% \begin{abstract}
% Package \xpackage{zref} tries to get rid of the restriction
% in \LaTeX's reference system that only two properties are
% supported. The package implements an extensible referencing
% system, where properties are handled in a more flexible way.
% It offers an interface for macro programmers for the access
% to the system and some applications that uses the new
% reference scheme.
% \end{abstract}
%
% \tableofcontents
%
% \newcommand*{\metacs}[1]{\texttt{\itshape #1}}
%
% \newcommand{\markexp}{^^A
% \textsuperscript{exp}^^A
% \space
% }
% \newcommand{\markrobust}{^^A
% \textsuperscript{robust}^^A
% \space
% }
% \newcommand{\marknowarn}{^^A
% \textsuperscript{nowarn}^^A
% \space
% }
% \newcommand{\markbabel}{^^A
% \textsuperscript{babel}^^A
% \space
% }
%
% \section{Introduction}
%
% Standard \LaTeX's reference system with \cs{label}, \cs{ref},
% and \cs{pageref} supports two properties, the apperance of
% the counter that is last incremented by \cs{refstepcounter} and
% the page with the \cs{label} command.
%
% Unhappily \LaTeX\ does not provide an interface for adding
% another properties. Packages such as \xpackage{hyperref},
% \xpackage{nameref}, or \xpackage{titleref} are forced to
% use ugly hacks to extend the reference system.
% These ugly hacks are one of the causes for \xpackage{hyperref}'s
% difficulty regarding compatibility with other packages.
%
% \subsection{Standard \LaTeX\ behaviour}
%
% References are created by the \cs{label} command:
% \begin{quote}
% |\chapter{Second chapter}|\\
% |\section{First section on page 7} % section 2.1|\\
% |\label{myref}|
% \end{quote}
% Now \LaTeX\ records the section number |2.1| and the page |7|
% in the reference. Internally the reference is a list with
% two entries:
% \begin{quote}
% |\r@myref| $\rightarrow$ |{2.1}{7}|
% \end{quote}
% The length of the list if fixed in the \LaTeX\ kernel,
% An interface for adding new properties is missing.
%
% There are several tries to add new properties:
% \begin{description}
% \item[\xpackage{hyperref}] uses a list of five
% properties instead of the standard list with two entries.
% This causes many compatibility problems with \LaTeX\ and
% other packages.
% \item[\xpackage{titleref}] stores its title data into the
% first entry in the list. \LaTeX\ is happy because it
% does only see its list with two entries. The situation
% becomes more difficult, if more properties are added
% this way. Then the macros form a nested structure
% inside the first reference argument for the label.
% Expandable extractions will then become painful.
% \end{description}
%
% \subsection{Basic idea}
%
% Some time ago Morten H\o gholm sent me an experimental
% cross referencing mechanism as ``expl3'' code. His
% idea is:
% \begin{quote}
% |\g_xref_mylabel_plist| $\rightarrow$\\
% \mbox{}\qquad|\xref_dance_key{salsa}\xref_name_key{Morten}|\dots
% \end{quote}
% The entries have the following format:
% \begin{quote}
% |\xref_|\meta{your key}|_key{|\meta{some text}|}|
% \end{quote}
% This approach is much more flexible:
% \begin{itemize}
% \item New properties can easily be added, just use a new key.
% \item The length of the list is not fixed. A reference
% can use a subset of the keys.
% \item The order of the entries does not matter.
% \end{itemize}
% Unhappily I am not familiar with the experimental code
% for \LaTeX3 that will need some time before its first release.
% Thus I have implemented it as \LaTeXe\ package without disturbing
% the existing \LaTeX\ reference system.
%
% \subsection{Interfaces}
%
% The package provides a generic \emph{interface for programmers}.
% Commands of this interface are prefixed by \cs{zref@}.
%
% Option \xoption{user} enabels the \emph{user interface}.
% Here the commands are prefixed by \cs{z} to avoid name
% clashes with existing macros.
%
% Then the packages provides some \emph{modules}. They
% are applications for the reference system and can also be
% considered as examples how to use the reference system.
%
% The modules can be loaded as packages. The package
% name is prefixed with |zref-|, for example:
%\begin{quote}
%\begin{verbatim}
%\RequirePackage{zref-abspage}
%\end{verbatim}
%\end{quote}
% This is the preferred way if the package is loaded from
% within other packages to avoid option clashes.
%
% As alternative package |zref| can be used and the modules
% are given as options:
%\begin{quote}
%\begin{verbatim}
%\usepackage[perpage,user]{zref}
%\end{verbatim}
%\end{quote}
%
% \section{Interface for programmers}
%
% The user interface is described in the next section \ref{sec:user}.
%
% \subsection{Entities}
%
% \paragraph{Reference.}
% Internally a reference is a list of key value pairs:
% \begin{quote}
% |\Z@R@myref| $\rightarrow$
% |\default{2.1}\page{7}|
% \end{quote}
% The generic format of a entry is:
% \begin{quote}
% |\Z@R@|\meta{refname} $\rightarrow$
% |\|\meta{propname}|{|\meta{value}|}|
% \end{quote}
% \meta{refname} is the name that denoted references
% (the name used in \cs{label} and \cs{ref}). \meta{propname}
% is the name of the property or key. The property key macro
% is never executed, it is used in parameter text matching only.
%
% \paragraph{Property.}
% Because the name of a property is used in a macro name
% that must survive the \xfile{.aux} file, the name is
% restricted to letters and `@'.
%
% \paragraph{Property list.}
% Often references are used for special purposes. Thus it
% saves memory if just the properties are used in this
% reference that are necessary for its purpose.
%
% Therefore this package uses the concept of \emph{property lists}.
% A property list is a set of properties. The set of properties
% that is used by the default \cs{label} command is the
% \emph{main property list}.
%
% \subsection{Property list}
%
% \markexp means that the implementation of the
% marked macro is expandable.
%
% \begin{declcs}{zref@newlist}
% \M{listname}
% \end{declcs}
% Declares a new empty property list.
%
% \begin{declcs}{zref@addprop}
% \M{listname} \M{propname}
% \end{declcs}
% Adds the property \meta{propname} to the property list \meta{listname}.
% The property and list must exist.
%
% \begin{declcs}{zref@localaddprop}
% \M{listname} \M{propname}
% \end{declcs}
% Local variant of \cs{zref@addprop}.
%
% \begin{declcs}{zref@listexists}
% \M{listname} \M{then}
% \end{declcs}
% Executes \meta{then} if the property list \meta{listname} exists
% or raise an error otherwise.
%
% \begin{declcs}{zref@iflistundefined}\markexp \M{listname}
% \M{then} \M{else}
% \end{declcs}
% Executes \meta{then} if the list exists or \meta{else}
% otherwise.
%
% \begin{declcs}{zref@iflistcontainsprop}
% \M{listname} \M{propname} \M{then} \M{else}
% \end{declcs}
% Executes \meta{then} if the property \meta{propname} is part
% of property list \meta{listname} or otherwise it
% runs the \meta{else} part.
%
% \subsection{Property}
%
% \begin{declcs}{zref@newprop}
% \* \M{propname} |[|\meta{default}|]| \M{value}
% \end{declcs}
% This command declares and configures a new property with
% name \meta{propname}.
%
% In case of unknown references
% or the property does not exist in the reference, the
% \meta{default} is used as value. If it is not specified
% here, a global default is used, see \cs{zref@setdefault}.
%
% The correct values of some properties are not known
% immediately but at page shipout time. Prominent example
% is the page number. These properties are declared with
% the star form of the command.
%
% \begin{declcs}{zref@setcurrent}
% \M{propname} \M{value}
% \end{declcs}
% This sets the current value of the property \meta{propname}.
% It is a generalization of setting \LaTeX's \cs{currentlabel}.
%
% \begin{declcs}{zref@getcurrent}
% \M{propname} \M{value}
% \end{declcs}
% This returns the current value of the property \meta{propname}.
% The value may not be correct, especially if the property
% is bound to a page (start form of \cs{zref@newprop}) and the
% right value is only known at shipout time (e.g. property `page').
%
% \begin{declcs}{zref@propexists}
% \M{propname} \M{then}
% \end{declcs}
% Calls \meta{then} if the property \meta{propname} is available
% or generates an error message otherwise.
%
% \begin{declcs}{zref@ifpropundefined}\markexp
% \M{propname} \M{then} \M{else}
% \end{declcs}
% Calls \meta{then} or \meta{else} depending on the existence
% of property \meta{propname}.
%
% \subsection{Reference generation}
%
% \begin{declcs}{zref@label}
% \M{refname}
% \end{declcs}
% This works similar to \cs{label}. The reference \meta{refname} is
% created and put into the \xfile{.aux} file with the
% properties of the main property list.
%
% \begin{declcs}{zref@labelbylist}
% \M{refname} \M{listname}
% \end{declcs}
% Same as \cs{zref@label} except that the properties are
% taken from the specified property list \meta{listname}.
%
% \begin{declcs}{zref@labelbyprops}
% \M{refname} |{|\meta{propnameA}|,|\meta{propnameB}|,|\dots|}|
% \end{declcs}
% Same as \cs{zref@label} except that these properties
% are used that are given as comma separated list in the
% second argument.
%
% \begin{declcs}{zref@newlabel}
% \M{refname} |{|\dots|}|
% \end{declcs}
% This is the macro that is used in the \xfile{.aux} file.
% It is basically the same as \cs{newlabel} apart from
% the format of the data in the second argument.
%
% \subsection{Data extraction}
%
% \begin{declcs}{zref@extractdefault}\markexp
% \M{refname} \M{propname} \M{default}
% \end{declcs}
% This is the basic command that refernces the value of a
% property \meta{propname} for the reference \meta{refname}.
% In case of errors such as undefined reference the \meta{default}
% is used instead.
%
% \begin{declcs}{zref@extract}\markexp
% \M{refname} \M{propname}
% \end{declcs}
% The command is an abbreviation for \cs{zref@extractdefault}.
% As default the default of the property is taken, otherwise
% the global default.
%
% Example for page references:
% \begin{quote}
% \begin{tabular}{@{}ll}
% \LaTeX:& |\pageref{foobar}|\\
% \xpackage{zref}:& |\zref@extract{foobar}{page}|
% \end{tabular}
% \end{quote}
% Both \cs{zref@extract} and \cs{zref@extractdefault} are
% expandable. That means, these macros can directly
% be used in expandable calculations, see the example file.
% On the other side, babel's shorthands are not supported,
% there are no warnings in case of undefined references.
%
% If an user interface doesn't need expandable macros
% then it can use \cs{zref@refused} and \cs{zref@wrapper@babel}
% for its user macros.
%
% \begin{declcs}{zref@refused}
% \M{refname}
% \end{declcs}
% This command is not expandable. It causes the warnings if
% the reference \meta{refname} is not defined. Use the
% \cs{zref@extract} commands inside expandable contexts and
% mark their use outside by \cs{zref@refused}, see the example
% file.
%
% \begin{declcs}{zref@ifrefundefined}\markexp
% \M{refname} \M{then} \M{else}
% \end{declcs}
% A possibility to check whether a reference exists.
%
% \begin{declcs}{zifrefundefined}
% \M{refname} \M{then} \M{else}
% \end{declcs}
% Macro \cs{zifrefundefined} calls \cs{ref@refused} before
% executing \cs{zref@ifrefundefined}. Babel shorthands are
% supported in \meta{refname}.
%
% \begin{declcs}{zref@ifrefcontainsprop}\markexp
% \M{refname} \M{propname} \M{then} \M{else}
% \end{declcs}
% Test whether a reference provides a property.
%
% \subsection{Setup}
%
% \begin{declcs}{zref@default}
% \end{declcs}
% Holds the global default for unknown values.
%
% \begin{declcs}{zref@setdefault}
% |{|\meta{value}|}|
% \end{declcs}
% Sets the global default for unknown values.
% The global default is used, if a property does not specify
% an own default and the value for a property
% cannot be extracted. This can happen if the reference is
% unknown or the reference does not have the property.
%
% \begin{declcs}{zref@setmainlist}
% |{|\meta{value}|}|
% \end{declcs}
% Sets the name of the main property list. The package
% sets and uses |main|.
%
% \subsection{Declared properties}
%
% \begin{quote}
% \renewcommand*{\arraystretch}{1.05}
% \setlength{\tabcolsep}{2\tabcolsep}
% \def\VV{\vphantom{\large \"Ag}}
% \def\EMPTY{{\itshape\textless empty\textgreater}}
% \begin{tabular}{@{}>{\sffamily}l|>{\ttfamily}l|>{\ttfamily}l|>{\ttfamily}l@{}}
% \rmfamily Module&
% \rmfamily Property&
% \rmfamily Property list&
% \rmfamily Default\\
% \hline
% & default & main & \EMPTY\\
% & page & main & \EMPTY\\
% \hline
% abspage\textrm{, }totpages & abspage & main & 0\\
% \hline
% perpage & pagevalue & perpage & 0\\
% & page & perpage & \EMPTY\\
% & abspage & perpage & 0\\
% \hline
% counter & counter & main & \EMPTY\\
% \hline
% titleref & title & main & \EMPTY\\
% \hline
% savepos & posx & savepos & 0\\
% & posy & savepos & 0\\
% \hline
% hyperref & anchor & main & \EMPTY\\
% & url & & \EMPTY\\
% \hline
% xr & url & & \EMPTY\\
% \end{tabular}
% \end{quote}
%
% \subsection{Wrapper for advanced situations}
%
% \begin{declcs}{zref@wrapper@babel}
% |{|\dots|}| \M{name}
% \end{declcs}
% This macro helps to add shorthand support. The second
% argument is protected, then the code of the first argument
% is called with the protected name appended. Examples
% are in the sources.
%
% \begin{declcs}{zref@wrapper@immediate}
% |{|\dots|}|
% \end{declcs}
% There are situations where a label must be written instantly
% to the \xfile{.aux} file, for example after the last page.
% If the \cs{zlabel} or \cs{label} command is put inside this wrapper,
% immediate writing is enabled. See the implementation for
% module \xmodule{lastpage} for an example of its use.
%
% \begin{declcs}{zref@wrapper@unexpanded}
% |{|\dots|}|
% \end{declcs}
% Assuming someone wants to extract a value for property |bar|
% and store the result in a macro |\foo| without traces of
% the expanding macros and without expanding the value.
% This (theoretical?) problem can be solved by this wrapper:
% \begin{quote}
%\begin{verbatim}
%\edef\foo{%
% \zref@wrapper@unexpanded{%
% \zref@extract{someref}{bar}%
% }%
%}
%\end{verbatim}
% \end{quote}
% The \cs{edef} forces the expansion of \cs{zref@extract},
% but the extraction of the value is prevented by
% the wrapper that uses \eTeX'\ \cs{unexpanded} for this
% purpose.
%
% \subsection{Counter for unique names}
%
% Some modules (\xmodule{titleref} and \xmodule{dotfillmin})
% need unique names for automatically generated label names.
%
% \begin{declcs}{zref@require@unique}
% \end{declcs}
% This command creates the unique counter |zref@unique| if the
% counter does not already exist.
%
% \begin{declcs}{thezref@unique}
% \end{declcs}
% This command is used to generate unique label names.
%
% \section{User interface}\label{sec:user}
%
% \subsection{Module \xmodule{user}}
%
% The user interface for this package and its modules
% is enabled by \xpackage{zref}'s package option \xmodule{user}
% or package \xpackage{zref-user}.
% The names of user commands are prefixed by |z| in order
% to avoid name clashes with existing macros of the same
% functionality. Thus the package does not disturb the
% traditional reference scheme, both can be used together.
%
% The syntax descriptions contain the following markers
% that are intended as hints for programmers:
% \begin{quote}
% \begin{tabular}{@{}ll@{}}
% \markbabel\unskip & Babel shorthands are allowed.\\
% \markrobust\unskip & Robust macro.\\
% \markexp\unskip & Expandable version:\\
% & \textbullet\ robust,
% unless the extracted values are fragile,\\
% & \textbullet\ no babel shorthand suport.
% \end{tabular}
% \end{quote}
%
% The basic user interface of the package without modules
% are commands that mimic the standard \LaTeX\ behaviour
% of \cs{label}, \cs{ref}, and \cs{pageref}:
%
% \begin{declcs}{zlabel}
% \M{refname}\markbabel
% \end{declcs}
% Similar to \cs{label}. It generates a label with name
% \meta{refname} in the new reference scheme.
%
% \begin{declcs}{zref}
% |[|\meta{propname}|]| \M{refname}\markbabel
% \end{declcs}
% Without optional argument similar to \cs{ref}, it returns
% the default reference property. This property is named
% |default|:
% \[
% |\zref{|x|}| \equiv |\zref[default]{|x|}|
% \]
%
% \begin{declcs}{zpageref}
% \M{refname}\markbabel
% \end{declcs}
% Convenience macro, similar to \cs{pageref}.
% \[
% |\zpageref{|x|}| \equiv |\zref[page]{|x|}|
% \]
%
% \begin{declcs}{zrefused}
% \M{refname}\markbabel
% \end{declcs}
% Some of the user commands in the modules are expandable.
% The use of such commands do not cause any undefined
% reference warnings, because inside of expandable
% contexts this is not possible. However, if there is
% a place outside of expandable contexts, \cs{refused}
% is strongly recommended. The reference \meta{refname}
% is marked as used, undefined ones will generate
% warnings.
%
% \subsection{Module \xmodule{abspage}}
%
% With the help of package \xpackage{atbegshi}
% a new counter |abspage| with absolute page numbers is provided.
% Also a new property |abspage| is defined and added to the
% main property list. Thus you can reference the absolute
% page number:
% \begin{quote}
% |Section \zref{foo} is on page \zpageref{foo}.|\\
% |This is page \zref[abspage]{foo} of \zref[abspage]{LastPage}.|
% \end{quote}
% The example also makes use of module \xmodule{lastpage}.
%
% \subsection{Module \xmodule{lastpage}}
%
% Provides the functionality of package \xpackage{lastpage}
% \cite{lastpage} in the new reference scheme.
% The label |LastPage| is put at the end of the document.
% You can refer the last page number with:
% \begin{quote}
% |\zref@extract{LastPage}{page}| (+ |\zref@refused{LastPage}|)\\
% \end{quote}
% or
% \begin{quote}
% |\zpageref{LastPage}| (module \xmodule{user})
% \end{quote}
%
% Since version 2008/10/01 v2.3 the module defines the list |LastPage|.
% In addition to the properties of the main list label |LastPage| also
% stores the properties of this list |LastPage|. The default of this
% list is empty. The list can be used by the user to add additional
% properties for label |LastPage|.
%
% \subsubsection{Tests for last page}
%
% Since version 2010/03/26 v2.8 the macros \cs{zref@iflastpage}
% and \cs{ziflastpage} were added. They test the reference,
% whether it is a reference of the last page.
%
% \begin{declcs}{zref@iflastpage}\markexp \M{refname} \M{then} \M{else}
% \end{declcs}
% Macro \cs{zref@iflastpage} compares the references \meta{refname}
% with \meta{LastPage}. Basis of the comparison is the value of
% property |abspage|, because the values are different for different
% pages. This is not ensured by property |page|. Therefore module
% \xmodule{abspage} is loaded by module \xmodule{lastpage}.
% If both values of property |abspage| are present and match,
% then \meta{then} is executed, otherwise code \meta{else} is called.
% If one or both references are undefined or lack the property |abspage|,
% then \meta{else} is executed.
%
% Macro \cs{zref@iflastpage} is expandable, therefore \cs{zref@refused}
% should be called on \meta{refname} and \meta{LastPage}.
%
% \begin{declcs}{ziflastpage} \M{refname} \M{then} \M{else}
% \end{declcs}
% Macro \cs{ziflastpage} has the same function as \cs{zref@iflastpage},
% but adds support for babel shorthands in \meta{refname} and
% calls \cs{zref@refused}. However macro \cs{ziflastpage} is not
% expandable.
%
% \subsubsection{Example}
%
% \begin{macrocode}
%<*example-lastpage>
%<<END_EXAMPLE
\NeedsTeXFormat{LaTeX2e}
\documentclass{report}
\newcounter{foo}
\renewcommand*{\thefoo}{\Alph{foo}}
\usepackage{zref-lastpage,zref-user}[2008/10/01]
\makeatletter
\zref@newprop{thefoo}{\thefoo}
\zref@newprop{valuefoo}{\the\value{foo}}
\zref@newprop{chapter}{\thechapter}
\zref@addprop{LastPage}{thefoo}
\zref@addprop{LastPage}{valuefoo}
\zref@addprop{LastPage}{chapter}
\makeatother
\newcommand*{\foo}{%
\stepcounter{foo}%
[Current foo: \thefoo]%
}
\begin{document}
\chapter{First chapter}
Last page is \zref{LastPage}.\\
Last chapter is \zref[chapter]{LastPage}.\\
Last foo is \zref[thefoo]{LastPage}.\\
Last value of foo is \zref[valuefoo]{LastPage}.\\
\foo
\chapter{Second chapter}
\foo\foo\foo
\chapter{Last chapter}
\foo
\end{document}
%END_EXAMPLE
%</example-lastpage>
% \end{macrocode}
%
% \subsection{Module \xmodule{thepage}}
%
% This module \xmodule{thepage} loads module \xmodule{abspage},
% constructs a reference name using the absolute page number
% and remembers property |page|. Other properties can be added
% by adding them to the property list |thepage|.
%
% \begin{declcs}{zthepage} \M{absolute page number}\\
% \end{declcs}
% Macro \cs{zthepage} is basically a \cs{zpageref}. The reference
% name is yield by the \meta{absolute page number}. If the reference
% is not defined, then the default for property |page| is used.
%
% \begin{declcs}{zref@thepage@name}\markexp \M{absolute page number}
% \end{declcs}
% Macro \cs{zref@thepage@name} returns the internal reference
% name that is constructed using the \meta{absolute page number}.
% The internal reference name should not be used directly, because
% it might change in future versions.
%
% \begin{declcs}{zref@thepage}\markexp \M{absolute page number}\\
% \cs{zref@thepage@refused} \M{absolute page number}
% \end{declcs}
% Macro \cs{zref@thepage} returns the page number (\cs{thepage})
% of \meta{absolute page number}. Because this macro is expandable,
% \cs{zref@thepage@refused} is used outside an expandable context
% to mark the reference as used.
%
%
% \subsection{Module \xmodule{nextpage}}
%
% \begin{declcs}{znextpage}
% \end{declcs}
% Macro \cs{znextpage} prints \cs{thepage} of the following page.
% It gets the current absolute page number by using a label.
% There are three cases for the next page:
% \begin{enumerate}
% \item The next page is not known yet because of undefined references.
% Then \cs{zunknownnextpagename} is used instead. The default for
% this macro is the default of property |page|.
% \item This page is the last page. Then \cs{znonextpagename}
% is used. Its default is empty.
% \item The next page is known, then \cs{thepage} of the next
% page is used (the value of property |page| of the next page).
% \end{enumerate}
%
% \subsubsection{Configuration}
%
% The behaviour can be configured by the following macros.
%
% \begin{declcs}{zunknownnextpagename}\\
% \cs{znonextpagename}
% \end{declcs}
% If the next page is not known or available, then
% \cs{znextpage} uses these name macros as default.
% \cs{zunknownnextpagename} is used in case of undefined
% references. Default is the value of property |page| of the
% next page (\cs{thepage}). Module \xmodule{thepage} is used.
%
% Macro \cs{znonextpagename} is used, if the next page does
% not exists. That means that the current page is last page.
% The default is empty.
%
% \begin{declcs}{znextpagesetup} \M{unknown} \M{no next}
% \M{next}
% \end{declcs}
% Acording to the case (see \cs{znextpage}) macro \cs{znextpage}
% calls an internal macro with an argument. The argument is
% either \cs{thepage} of the next page or one of \cs{zunknownnextpagename}
% or \cs{znonextpagename}. These internal macro can be changed by
% \cs{znextpagesetup}. It expects the definition texts for these
% three cases of a macro with one argument.
% The default is
% \begin{quote}
% |\znextpagesetup{#1}{#1}{#1}|
% \end{quote}
%
% \subsubsection{Example}
%
% \begin{macrocode}
%<*example-nextpage>
%<<END_EXAMPLE
\documentclass{book}
\usepackage{zref-nextpage}[2010/03/26]
\znextpagesetup
{\thepage}% next page is unknown
{\thepage\ (#1)}% this page is last page
{\thepage\ $\rightarrow$ #1}% next page is known
\renewcommand*{\znonextpagename}{last page}
\usepackage{fancyhdr}
\pagestyle{fancy}
\fancyhf{}
\fancyhead[LE,RO]{\znextpage}
\fancypagestyle{plain}{%
\fancyhf{}%
\fancyhead[LE,RO]{\znextpage}%
}
\begin{document}
\frontmatter
\tableofcontents
\mainmatter
\chapter{Hello World}
\clearpage
\section{Last section}
\end{document}
%END_EXAMPLE
%</example-nextpage>
% \end{macrocode}
%
%
% \subsection{Module \xmodule{totpages}}
%
% For the total number of pages of a document you need to
% know the absolute page number of the last page.
% Both modules \xmodule{abspage} and \xmodule{lastpage}
% are necessary and automatically enabled.
%
% \begin{declcs}{ztotpages}\markexp
% \end{declcs}
% Prints the total number of pages or |0| if this
% number is not yet known. It expands to an explicit number
% and can also used even in expandable calculations (\cs{numexpr})
% or counter assignments.
%
% \subsection{Module \xmodule{runs}}
%
% Module \xmodule{runs} counts the \LaTeX\ runs since last
% \xext{aux} file creation and prints the number in the
% \xext{log} file.
%
% \begin{declcs}{zruns}\markexp
% \end{declcs}
% Prints the the total number of \LaTeX\ runs including
% the current one. It expands to an explicit number.
% Before |begin{document}| the value is zero meaning
% the \xext{aux} file is not read yet. If a previous
% \xext{aux} file exists, the value found there increased
% by one is the new number. Otherwise \cs{zruns} is set to one.
% \LaTeX~runs where the \xext{aux} files are not rewritten
% are not counted (see \cs{nofiles}).
%
% \subsection{Module \xmodule{perpage}}
%
% With \cs{@addtoreset} or \cs{numberwithin} a counter can be
% reset if another counter is incremented. This do not work
% well if the other counter is the page counter. The page counter is
% incremented in the output routine that is often called asynchronous
% somewhere on the next page. A reference mechanism costs at least
% two \LaTeX\ runs, but ensures correct page counter values.
%
% \begin{declcs}{zmakeperpage}
% |[|\meta{reset}|]| \M{counter}
% \end{declcs}
% At the of a new page counter \meta{counter} starts
% counting with value \meta{reset} (default is \texttt{1}).
% The macro has the same
% syntax and semantics as \cs{MakePerPage} of package
% \xpackage{perpage} \cite{perpage}.
% Also \xoption{perpage} of package \xpackage{footmisc} \cite{footmisc}
% can easily be simulated by
% \begin{quote}
% |\zmakeperpage{footnote}| \itshape |% \usepackage[perpage]{footmisc}|
%\end{quote}
% If footnote symbols are used, some people dislike the
% first symbol \ensuremath{\dagger}. It can easily be skipped:
% \begin{quote}
% |\zmakeperpage[2]{footnote}|
% \end{quote}
%
% \begin{declcs}{thezpage}\\
% counter |zpage|
% \end{declcs}
% If the formatted counter value of the counter that is reset at
% a new page contains the page value, then you can use \cs{thezpage},
% the page number of the current page. Or counter |zpage| can be
% used, if the page number should be formatted differently from
% the current page number. Example:
%\begin{quote}
%\begin{verbatim}
%\newcounter{foobar}
%\zmakeperpage{foobar}
%\renewcommand*{\thefoobar}{\thezpage-\arabic{foobar}}
% % or
%\renewcommand*{\thefoobar}{\roman{zpage}-\arabic{foobar}}
%\end{verbatim}
%\end{quote}
%
% \begin{declcs}{zunmakeperpage}
% \M{counter}
% \end{declcs}
% The reset mechanism for this counter is deactivated.
%
%
% \subsection{Module \xmodule{counter}}
%
% This option just add the property |counter| to the main
% property list. The property stores the counter name,
% that was responsible for the reference. This is the
% property \xpackage{hyperref}'s \cs{autoref} feature
% uses. Thus this property |counter| may be useful
% for a reimplementation of the autoref feature,
% see the section \ref{sec:todo} with the todo list.
%
% \subsection{Module \xmodule{titleref}}
%
% This option makes section and caption titles available
% to the reference system similar to packages \xpackage{titleref}
% or \xpackage{nameref}.
%
% \begin{declcs}{ztitleref}
% \M{refname}\markbabel
% \end{declcs}
% Print the section or caption title of reference \meta{refname},
% similar to \cs{nameref} or \cs{titleref}.
%
% \begin{declcs}{ztitlerefsetup}
% |{|\textit{key$_1$=value$_1$, key$_2$=value$_2$, \dots}|}|
% \end{declcs}
% This command allows to configure the behaviour of module
% \xmodule{titleref}. The following keys are available:
% \begin{description}
% \let\bfseries\relax
% \item[\texttt{title=}\meta{value}]\mbox{}\\*
% Sets the current title.
% \item[\texttt{stripperiod=true\string|false}]\mbox{}\\*
% Follow package \xpackage{nameref} that
% removes a last period. Default: |true|.
% \item[\texttt{expand=true\string|false}]\mbox{}\\*
% Package \cs{titleref} expands the title first. This way
% garbage and dangerous commands can be removed, e.g.
% \cs{label}, \cs{index}\dots. See implementation section
% for more details. Default is |false|.
% \item[\texttt{cleanup=\{}\textrm{\dots}\texttt{\}}]\mbox{}\\*
% Hook to add own cleanup code, if method |expand| is used.
% See implementation section for more details.
% \end{description}
%
% \subsection{Module \xmodule{savepos}}
%
% This option supports a feature that \pdfTeX\ provides
% (and Xe\TeX).
% \pdfTeX\ is able to tell the current position on the
% page. The page position is not instantly known. First the
% page must be constructed by \TeX's asynchronous output
% routine. Thus the time where the position is known is
% the page shipout time. Thus a reference system where the
% information is recorded in the first run and made available
% for use in the second run comes in handy.
%
% \begin{declcs}{zsavepos}
% \M{refname}
% \end{declcs}
% It generates a reference with name \meta{refname} to
% the location where the command is executed.
%
% \begin{declcs}{zposx}\markexp
% \M{refname}\\
% \SpecialUsageIndex{\zposy}\cs{zposy}\markexp \M{refname}
% \end{declcs}
% Get the position as number. Unit is sp. Horizontal
% positions by \cs{zposx} increase from left to right.
% Vertical positions by \cs{zposy} from bottom to top.
%
% Do not rely on absolute page numbers. Because of problems
% with the origin the numbers may differ in DVI or PDF mode
% of \pdfTeX. Therefore work with relative values by comparisons.
%
% Both \cs{zposx} and \cs{zposy} are expandable and can be
% used inside calculations (\cs{setcounter}, \cs{addtocounter},
% package \xpackage{calc}, \cs{numexpr}). However this property
% prevents from notifying \LaTeX\ that the reference is actually
% used (the notifying is not expandable). Therefore you should
% mark the reference as used by \cs{zrefused}.
%
% This module uses \pdfTeX's \cs{pdfsavepos}, \cs{pdflastxpos},
% and \cs{pdflastypos}. They are available in PDF mode and
% since version 1.40.0 also in DVI mode.
%
% \subsection{Module \xmodule{dotfill}}
%
% \begin{declcs}{zdotfill}
% \end{declcs}
% This package provides the command \cs{zdotfill} that works
% similar to \cs{dotfill}, but can be configured. Especially
% it suppresses the dots if a minimum number of dots cannot be set.
%
% \begin{declcs}{zdotfillsetup}
% |{|\textit{key$_1$=value$_1$, key$_2$=value$_2$, \dots}|}|
% \end{declcs}
% This command allows to configure the behaviour of \cs{zdotfill}.
% The following keys are available:
% \begin{description}
% \let\bfseries\relax
% \item[\texttt{min=}\meta{count value}]\mbox{}\\*
% If the actual number of dots are smaller than \meta{count value},
% then the dots are suppressed. Default: |2|.
% \item[\texttt{unit=}\meta{dimen value}]\mbox{}\\*
% The width of a dot unit is given by \meta{dimen value}.
% Default: |0.44em| (same as the unit in \cs{dotfill}).
% \item[\texttt{dot=}\meta{value}]\mbox{}\\*
% The dot itself is given by \meta{value}. Default: |.| (dot, same as
% the dot in \cs{dotfill}).
% \end{description}
%
% \subsection{Module \xmodule{xr}}
%
% This package provides the functionality of package \xpackage{xr},
% see \cite{xr}. It also supports the syntax of \xpackage{xr-hyper}.
%
% \begin{declcs}{zexternaldocument}
% \* |[|\meta{prefix}|]|\markbabel \M{external document}
% |[|\meta{url}|]|
% \end{declcs}
% See \cs{externaldocument} for a description of this option.
% The standard reference scheme and the scheme of this
% package use different name spaces for reference names.
% If the external document uses both systems. Then one
% import statement would put the names in one namespace
% and probably causing problems with multiple references
% of the same name. Thus the star form only looks for
% \cs{newlabel} in the \xfile{.aux} files, whereas without
% star only \cs{zref@newlabel}s are used.
%
% In the star form it tries to detect labels from
% \xpackage{hyperref}, \xpackage{titleref}, and \xpackage{ntheorem}.
% If such an extended property from the packages before cannot
% be found or are empty, they are not included in the
% imported reference.
%
% Warnings are given if a reference name is already in use
% and the item is ignored. Unknown properties will automatically
% be declared.
%
% If the external references contain |anchor| properties,
% then we need also a url to be able to address the external
% file. As default the filename is taken with a default
% extension.
%
% \begin{declcs}{zxrsetup}
% |{|\textit{key$_1$=value$_1$, key$_2$=value$_2$, \dots}|}|
% \end{declcs}
% Currently the key |ext| is defined, this sets the
% url default extension.
%
% \begin{declcs}{zref@xr@ext}
% \end{declcs}
% If the \meta{url} is not specified in \cs{zref@externaldocument},
% then the url will be constructed with the file name and
% this macro as extension. \cs{XR@ext} is used if
% \xpackage{hyperref} is loaded, otherwise |pdf|.
%
% \section{ToDo}\label{sec:todo}
%
% Among other things the following issues are left for future work:
% \begin{itemize}
% \item
% The user land macros are not checked for robustness yet.
% They can be fragile. If this happens, use \cs{protect}
% until a later version of this package. The \cs{protect}
% will not disturb, if the protected macro become robust
% in the future.
% \item Other applications: autoref, hyperref, \dots
% \end{itemize}
%
% \section{Example}
%
% \begin{macrocode}
%<*example>
% \end{macrocode}
%
% \begin{macrocode}
\documentclass{book}
\usepackage[ngerman]{babel}%
\usepackage[savepos,totpages,titleref,dotfill,counter,user]{zref}
% \end{macrocode}
%
% Chapters are wrapped inside \cs{ChapterStart} and
% \cs{ChapterStop}. The first argument \verb|#1| of \cs{ChapterStart}
% is used to form a label id \verb|chap:#1|. At the end of
% the chapter another label is set by \cs{zref@wrapper@immediate}, because
% otherwise at the end of document a deferred write would not
% be written, because there is no page for shipout.
%
% Also this example shows how chapter titles can be recorded.
% A new property \verb|chaptitle| is declared and added to the
% main property list. In \cs{ChapterStart} the current value
% of the property is updated.
% \begin{macrocode}
\makeatletter
\zref@newprop{chaptitle}{}
\zref@addprop{main}{chaptitle}
\newcommand*{\ChapterStart}[2]{%
\cleardoublepage
\def\current@chapid{#1}%
\zref@setcurrent{chaptitle}{#2}%
\chapter{#2}%
\zlabel{chap:#1}%
}
\newcommand*{\ChapterStop}{%
\cleardoublepage
\zref@wrapper@immediate{%
\zref@labelbyprops{chapend:\current@chapid}{abspage}%
}%
}
% \end{macrocode}
% \cs{ChapterPages} calculates and returns the number of pages of the
% referenced chapter.
% \begin{macrocode}
\newcommand*{\ChapterPages}[1]{%
\zrefused{chap:#1}%
\zrefused{chapend:#1}%
\number\numexpr
\zref@extract{chapend:#1}{abspage}%
-\zref@extract{chap:#1}{abspage}%
+1\relax
}
\makeatother
% \end{macrocode}
% \begin{macrocode}
\begin{document}
% \end{macrocode}
% As exception we use \cs{makeatletter} here, because
% this is just an example file that also should show some of
% programmer's interface.
% \begin{macrocode}
\makeatletter
\frontmatter
\zlabel{documentstart}
\begin{itemize}
\item
The frontmatter part has
\number\numexpr\zref@extract{chap:first}{abspage}-1\relax~pages.
\item
Chapter \zref{chap:first} has \ChapterPages{first} page(s).
\item
Section \zref{hello} is on the
\ifcase\numexpr
\zref@extractdefault{hello}{page}{0}%
-\zref@extractdefault{chap:first}{page}{0}%
+1\relax
??\or first\or second\or third\or forth\fi
~page inside its chapter.
\item
The document has
\zref[abspage]{LastPage} pages.
This number is \ifodd\ztotpages odd\else even\fi.
\item
The last page is labeled with \zpageref{LastPage}.
\item
The title of chapter \zref{chap:next} is ``\zref[chaptitle]{chap:next}''.
\end{itemize}
\tableofcontents
\mainmatter
\ChapterStart{first}{First chapter}
% \end{macrocode}
% The user level commands should protect babel shorthands
% where possible. On the other side, expandable extracting
% macros are useful in calculations, see above the
% examples with \cs{numexpr}.
% \begin{macrocode}
\section{Test}
\zlabel{a"o}
Section \zref{a"o} on page
\zref@wrapper@babel\zref@extract{a"o}{page}.
Text.
\newpage
\section{Hello World}
\zlabel{hello}
\ChapterStop
\ChapterStart{next}{Next chapter with \emph{umlauts}: "a"o"u"s}
% \end{macrocode}
%
% Here an example follows that makes use of \pdfTeX's ``savepos''
% feature. The position on the page is not known before the
% page is constructed and shipped out. Therefore the position
% ist stored in references and are available for calculations
% in the next \LaTeX\ compile run.
% \begin{macrocode}
The width of the first column is
\the\dimexpr \zposx{secondcol}sp - \zposx{firstcol}sp\relax,\\
the height difference of the two baselines is
\the\dimexpr \zposy{firstcol}sp - \zposy{secondline}sp\relax:\\
\begin{tabular}{ll}
\zsavepos{firstcol}Hello&\zsavepos{secondcol}World\\
\zsavepos{secondline}Second line&foobar\\
\end{tabular}
% \end{macrocode}
% With \cs{zrefused} \LaTeX\ is notified, if the references
% are not yet available and \LaTeX\ can generate the rerun
% hint.
% \begin{macrocode}
\zrefused{firstcol}
\zrefused{secondcol}
\zrefused{secondline}
\ChapterStop
% \end{macrocode}
% Test for module \cs{dotfill}.
% \begin{macrocode}
\ChapterStart{dotfill}{Test for dotfill feature}
\newcommand*{\dftest}[1]{%
#1&
[\makebox[{#1}]{\dotfill}]&
[\makebox[{#1}]{\zdotfill}]\\
}
\begin{tabular}{rll}
& [\verb|\dotfill|] & [\verb|\zdotfill|]\\
\dftest{0.43em}
\dftest{0.44em}
\dftest{0.45em}
\dftest{0.87em}
\dftest{0.88em}
\dftest{0.89em}
\dftest{1.31em}
\dftest{1.32em}
\dftest{1.33em}
\end{tabular}
\ChapterStop
\end{document}
% \end{macrocode}
%
% \begin{macrocode}
%</example>
% \end{macrocode}
%
% \StopEventually{
% }
%
% \section{Implementation}
%
% \subsection{Package \xpackage{zref}}
%
% \subsubsection{Identification}
%
% \begin{macrocode}
%<*package>
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{zref}
[2010/03/26 v2.8 New reference scheme for LaTeX2e (HO)]%
% \end{macrocode}
%
% \subsubsection{Load basic module}
%
% \begin{macrocode}
\RequirePackage{zref-base}[2010/03/26]
% \end{macrocode}
% Abort package loading if \xpackage{zref-base} could not be
% loaded successfully.
% \begin{macrocode}
\@ifundefined{ZREF@baseok}{\endinput}{}
% \end{macrocode}
%
% \subsubsection{Process options}
%
% Known modules are loaded and the release date is checked.
% \begin{macrocode}
\def\ZREF@temp#1{%
\DeclareOption{#1}{%
\AtEndOfPackage{%
\RequirePackage{zref-#1}[2010/03/26]%
}%
}%
}
\ZREF@temp{abspage}
\ZREF@temp{counter}
\ZREF@temp{dotfill}
\ZREF@temp{hyperref}
\ZREF@temp{lastpage}
\ZREF@temp{perpage}
\ZREF@temp{savepos}
\ZREF@temp{titleref}
\ZREF@temp{totpages}
\ZREF@temp{user}
\ZREF@temp{xr}
% \end{macrocode}
% \begin{macrocode}
\ProcessOptions\relax
%</package>
% \end{macrocode}
%
%
% \subsection{Module \xmodule{base}}
%
% \subsubsection{Prefixes}
%
% This package uses the following prefixes for macro names:
% \begin{description}
% \item[\cs{zref@}:] Macros of the programmer's interface.
% \item[\cs{ZREF@}:] Internal macros.
% \item[\cs{Z@L@}\metacs{listname}:]
% The properties of the list \meta{listname}.
% \item[\cs{Z@D@}\metacs{propname}:]
% The default value for property \meta{propname}.
% \item[\cs{Z@E@}\metacs{propname}:]
% Extract function for property \meta{propname}.
% \item[\cs{Z@X@}\metacs{propname}:]
% Information whether a property value for property
% \meta{propname} is expanded
% immediately or at shipout time.
% \item[\cs{Z@C@}\metacs{propname}:]
% Current value of the property \meta{propname}.
% \item[\cs{Z@R@}\metacs{labelname}:]
% Data for reference \meta{labelname}.
% \item[\cs{ZREF@org@}:] Original versions of patched commands.
% \item[\cs{z}:] For macros in user land, defined if
% module \xmodule{user} is set.
% \end{description}
% The following family names are used for keys defined
% according to the \xpackage{keyval} package:
% \begin{description}
% \item[\texttt{ZREF@TR}:] Setup for module \xmodule{titleref}.
% \end{description}
%
% \subsubsection{Identification}
%
% \begin{macrocode}
%<*base>
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{zref-base}%
[2010/03/26 v2.8 Module base for zref (HO)]%
% \end{macrocode}
%
% \subsubsection{Utilities}
%
% \begin{macrocode}
\RequirePackage{ltxcmds}[2009/12/12]
% \end{macrocode}
%
% \begin{macro}{\ZREF@name}
% Several times the package name is used, thus we store it
% in \cmd{\ZREF@name}.
% \begin{macrocode}
\def\ZREF@name{zref}
% \end{macrocode}
% \end{macro}
%
% \begin{macro}{\ZREF@ErrorNoLine}
% An error message for this package without line information is
% generated by \cs{ZREF@ErrorNoLine}
% \begin{macrocode}
\def\ZREF@ErrorNoLine#1#2{%
\begingroup
\let\on@line\@empty
\PackageError\ZREF@name{#1}{#2}%
\endgroup
}
% \end{macrocode}
% \end{macro}
%
% \begin{macro}{\ZREF@UpdatePdfTeX}
% \cs{ZREF@UpdatePdfTeX} is used as help message text in
% error messages.
% \begin{macrocode}
\def\ZREF@UpdatePdfTeX{Update pdfTeX.}
% \end{macrocode}
% \end{macro}
%
% \begin{macro}{\ifZREF@found}
% The following switch is usded in list processing.
% \begin{macrocode}
\newif\ifZREF@found
% \end{macrocode}
% \end{macro}
%
% \begin{macro}{\ZREF@patch}
% Macro \cs{ZREF@patch} first checks the existence of
% the command and safes it.
% \begin{macrocode}
\def\ZREF@patch#1{%
\begingroup\expandafter\expandafter\expandafter\endgroup
\expandafter\ifx\csname #1\endcsname\relax
\expandafter\ltx@gobble
\else
\expandafter\let\csname ZREF@org@#1\expandafter\endcsname
\csname #1\endcsname
\expandafter\ltx@firstofone
\fi
}
% \end{macrocode}
% \end{macro}
%
% \subsubsection{Check for \eTeX}
%
% The use of \eTeX\ should be standard nowadays for \LaTeX.
% We test for \eTeX\ in order to use its features later.
% \begin{macrocode}
\ltx@IfUndefined{eTeXversion}{%
\ZREF@ErrorNoLine{%
Missing support for eTeX; package is abandoned%
}{%
Use a TeX compiler that support eTeX and enable eTeX %
in the format.%
}%
\endinput
}{}%
% \end{macrocode}
%
% \begin{macrocode}
\RequirePackage{etexcmds}[2007/09/09]
\ifetex@unexpanded
\else
\ZREF@ErrorNoLine{%
Missing e-TeX's \string\unexpanded.\MessageBreak
Add \string\RequirePackage\string{etexcmds\string} before %
\string\documentclass%
}{%
Probably you are using some package (e.g. ConTeXt) that %
redefines \string\unexpanded%
}%
\expandafter\endinput
\fi
% \end{macrocode}
%
% \subsubsection{Auxiliary file stuff}
%
% We are using some commands in the \xfile{.aux} files.
% However sometimes these auxiliary files are interpreted
% by \LaTeX\ processes that haven't loaded this package
% (e.g. package \xpackage{xr}).
% Therefore we provide dummy definitions.
% \begin{macrocode}
\RequirePackage{auxhook}
\AddLineBeginAux{%
\string\providecommand\string\zref@newlabel[2]{}%
}
% \end{macrocode}
% \begin{macro}{\zref@newlabel}
% For the implementation of \cs{zref@newlabel} we call
% the same internal macro \cs{@newl@bel} that is used
% in \cs{newlabel}. Thus we have for free:
% \begin{itemize}
% \item \cs{Z@R@}\metacs{labelname} is defined.
% \item \LaTeX's check for multiple references.
% \item \LaTeX's check for changed references.
% \end{itemize}
% \begin{macrocode}
\def\zref@newlabel{%
\@newl@bel{Z@R}%
}
% \end{macrocode}
% \end{macro}
%
% \subsubsection{Property lists}
%
% \begin{macro}{\zref@newlist}
% Property lists are stored as list of property names
% enclosed in curly braces. \cs{zref@newlist}
% creates a new list as empty list. Assignments to
% property lists are global.
% \begin{macrocode}
\def\zref@newlist#1{%
\zref@iflistundefined{#1}{%
\@ifdefinable{Z@L@#1}{%
\global\expandafter\let\csname Z@L@#1\endcsname\@empty
\PackageInfo{zref}{New property list: #1}%
}%
}{%
\PackageError\ZREF@name{%
Property list `#1' already exists%
}\@ehc
}%
}
% \end{macrocode}
% \end{macro}
%
% \begin{macro}{\zref@iflistundefined}
% \cs{zref@iflistundefined} checks the existence of the
% property list \verb|#1|. If the property list is present,
% then \verb|#2| is executed and \verb|#3| otherwise.
% \begin{macrocode}
\def\zref@iflistundefined#1{%
\expandafter\ifx\csname Z@L@#1\endcsname\relax
\expandafter\ltx@firstoftwo
\else
\expandafter\ltx@secondoftwo
\fi
}
% \end{macrocode}
% \end{macro}
% \begin{macro}{\zref@listexists}
% \cs{zref@listexists} only executes \verb|#2| if the
% property list \verb|#1| exists and raises an error
% message otherwise.
% \begin{macrocode}
\def\zref@listexists#1{%
\zref@iflistundefined{#1}{%
\PackageError\ZREF@name{%
Property list `#1' does not exist%
}\@ehc
}%
}
% \end{macrocode}
% \end{macro}
%
% \begin{macro}{\zref@iflistcontainsprop}
% \cs{zref@iflistcontainsprop} checks, whether a property \verb|#2| is
% already present in a property list \verb|#1|.
% \begin{macrocode}
\def\zref@iflistcontainsprop#1{%
\expandafter\ZREF@iflistcontainsprop\csname Z@L@#1\endcsname
}
\def\ZREF@iflistcontainsprop#1#2{%
\begingroup
\ZREF@foundfalse
\edef\y{#2}%
\expandafter\@tfor\expandafter\x
\expandafter:\expandafter=#1\do{%
\edef\x{\x}%
\ifx\x\y
\ZREF@foundtrue
\fi
}%
\expandafter\endgroup
\ifZREF@found
\expandafter\ltx@firstoftwo
\else
\expandafter\ltx@secondoftwo
\fi
}
% \end{macrocode}
% \end{macro}
%
% \begin{macro}{\zref@listforloop}
% \begin{macrocode}
\def\zref@listforloop#1#2{%
\expandafter\expandafter\expandafter\@tfor
\expandafter\expandafter\expandafter\zref@prop
\expandafter\expandafter\expandafter:%
\expandafter\expandafter\expandafter=%
\csname Z@L@#1\endcsname
\do{%
#2\zref@prop
}%
}
% \end{macrocode}
% \end{macro}
%
% \begin{macro}{\zref@addprop}
% \cs{zref@addprop} adds the property \verb|#2| to the property
% list \verb|#1|, if the property is not already in the list.
% Otherwise a warning is given.
% \begin{macrocode}
\def\zref@addprop#1#2{%
\zref@listexists{#1}{%
\zref@propexists{#2}{%
\zref@iflistcontainsprop{#1}{#2}{%
\PackageWarning\ZREF@name{%
Property `#2' is already in list `#1'%
}%
}{%
\expandafter\g@addto@macro\csname Z@L@#1\endcsname{{#2}}%
}%
}%
}%
}
% \end{macrocode}
% \end{macro}
%
% \begin{macro}{\zref@localaddprop}
% \begin{macrocode}
\def\zref@localaddprop#1#2{%
\zref@listexists{#1}{%
\zref@propexists{#2}{%
\zref@iflistcontainsprop{#1}{#2}{%
\PackageWarning\ZREF@name{%
Property `#2' is already in list `#1'%
}%
}{%
\expandafter\ZREF@l@addto@macro\csname Z@L@#1\endcsname{{#2}}%
}%
}%
}%
}
% \end{macrocode}
% \end{macro}
% \begin{macro}{\ZREF@l@addto@macro}
% \begin{macrocode}
\ifetex@unexpanded
\def\ZREF@l@addto@macro#1#2{%
\global\let\ZREF@gtemp#1%
\g@addto@macro\ZREF@gtemp{#2}%
\let#1\ZREF@gtemp
}%
\else
\def\ZREF@l@addto@macro#1#2{%
\edef#1{%
\etex@unexpanded\expandafter{#1#2}%
}%
}%
\fi
% \end{macrocode}
% \end{macro}
%
% \subsubsection{Properties}
%
% \begin{macro}{\zref@ifpropundefined}
% \cs{zref@ifpropundefined} checks the existence of the
% property \verb|#1|. If the property is present,
% then \verb|#2| is executed and \verb|#3| otherwise.
% \begin{macrocode}
\def\zref@ifpropundefined#1{%
\expandafter\ifx\csname Z@E@#1\endcsname\relax
\expandafter\ltx@firstoftwo
\else
\expandafter\ltx@secondoftwo
\fi
}
% \end{macrocode}
% \end{macro}
% \begin{macro}{\zref@propexists}
% Some macros rely on the existence of a property.
% \cs{zref@propexists} only executes \verb|#2| if the
% property \verb|#1| exists and raises an error
% message otherwise.
% \begin{macrocode}
\def\zref@propexists#1{%
\zref@ifpropundefined{#1}{%
\PackageError\ZREF@name{%
Property `#1' does not exist%
}\@ehc
}%
}
% \end{macrocode}
% \end{macro}
%
% \begin{macro}{\zref@newprop}
% A new property is declared by \cs{zref@newprop}, the
% property name \meta{propname} is given in \verb|#1|. The
% property is created and configured. If the star form
% is given, then the expansion of the property value
% is delayed to page shipout time, when the reference
% is written to the \xfile{.aux} file.
% \begin{description}
% \item[\cs{Z@D@}\metacs{propname}:]
% Stores the default value for this property.
% \item[\cs{Z@E@}\metacs{propname}:]
% Extract function.
% \item[\cs{Z@X@}\metacs{propname}:]
% Information whether the expansion of the property value
% is delayed to shipout time.
% \item[\cs{Z@C@}\metacs{propname}:]
% Current value of the property.
% \end{description}
% \begin{macrocode}
\def\zref@newprop{%
\@ifstar{%
\let\ZREF@X\noexpand
\ZREF@newprop
}{%
\let\ZREF@X\@empty
\ZREF@newprop
}%
}
\def\ZREF@newprop#1{%
\PackageInfo{zref}{New property: #1}%
\def\ZREF@P{#1}%
\@ifnextchar[\ZREF@@newprop{\ZREF@@newprop[\zref@default]}%
}
\def\ZREF@@newprop[#1]{%
\global\@namedef{Z@D@\ZREF@P}{#1}%
\global\expandafter\let\csname Z@X@\ZREF@P\endcsname\ZREF@X
\expandafter\ZREF@@@newprop\csname\ZREF@P\endcsname
\zref@setcurrent\ZREF@P
}
\def\ZREF@@@newprop#1{%
\expandafter\gdef\csname Z@E@\ZREF@P\endcsname##1#1##2##3\ZREF@nil{##2}%
}
% \end{macrocode}
% \end{macro}
%
% \begin{macro}{\zref@setcurrent}
% \cs{zref@setcurrent} sets the current value for a property.
% \begin{macrocode}
\def\zref@setcurrent#1{%
\expandafter\def\csname Z@C@#1\endcsname
}
% \end{macrocode}
% \end{macro}
%
% \begin{macro}{\zref@getcurrent}
% \cs{zref@getcurrent} gets the current value for a property.
% \begin{macrocode}
\def\zref@getcurrent#1{%
\csname Z@C@#1\endcsname
}
% \end{macrocode}
% \end{macro}
%
% \subsubsection{Reference generation}
%
% \begin{macro}{\zref@label}
% Label macro that uses the main property list.
% \begin{macrocode}
\def\zref@label#1{%
\zref@labelbylist{#1}\ZREF@mainlist
}
% \end{macrocode}
% \end{macro}
% \begin{macro}{\zref@labelbylist}
% Label macro that stores the properties, specified in the
% property list \verb|#2|.
% \begin{macrocode}
\def\zref@labelbylist#1#2{%
\@bsphack
\zref@listexists{#2}{%
\expandafter\expandafter\expandafter\ZREF@label
\expandafter\expandafter\expandafter{%
\csname Z@L@#2\endcsname
}{#1}%
}%
\@esphack
}
% \end{macrocode}
% \end{macro}
% \begin{macro}{\zref@labelbyprops}
% The properties are directly specified in a comma separated list.
% \begin{macrocode}
\def\zref@labelbyprops#1#2{%
\@bsphack
\begingroup
\edef\l{#2}%
\toks@{}%
\@for\x:=#2\do{%
\zref@ifpropundefined{\x}{%
\PackageWarning\ZREF@name{%
Property `\x' is not known%
}%
}{%
\toks@\expandafter\expandafter\expandafter{%
\expandafter\the\expandafter\toks@\expandafter{\x}%
}%
}%
}%
\expandafter\endgroup
\expandafter\ZREF@label\expandafter{\the\toks@}{#1}%
\@esphack
}
% \end{macrocode}
% \end{macro}
%
% \begin{macro}{\ifZREF@immediate}
% The switch \cs{ifZREF@immediate} tells us, whether the
% label should be written immediately or at page shipout time.
% \cs{ZREF@label} need to be notified about this, because
% it must disable the deferred execution of property values,
% if the label is written immediately.
% \begin{macrocode}
\newif\ifZREF@immediate
% \end{macrocode}
% \end{macro}
% \begin{macro}{\zref@wrapper@immediate}
% The argument of \cs{zref@wrapper@immediate} is executed inside
% a group where \cs{write} is redefined by adding
% \cs{immediate} before its execution. Also \cs{ZREF@label}
% is notified via the switch \cs{ifZREF@immediate}.
% \begin{macrocode}
\long\def\zref@wrapper@immediate#1{%
\begingroup
\ZREF@immediatetrue
\let\ZREF@org@write\write
\def\write{\immediate\ZREF@org@write}%
#1%
\endgroup
}
% \end{macrocode}
% \end{macro}
%
% \begin{macro}{\ZREF@label}
% \cs{ZREF@label} writes the data in the \xfile{.aux} file.
% \verb|#1| contains the list of valid properties,
% \verb|#2| the name of the reference. In case of immediate
% writing, the deferred execution of property values is
% disabled. Also \thepage is made expandable in this case.
% \begin{macrocode}
\def\ZREF@label#1#2{%
\if@filesw
\begingroup
\ifZREF@immediate
\let\ZREF@org@thepage\thepage
\fi
\protected@write\@auxout{%
\ifZREF@immediate
\let\thepage\ZREF@org@thepage
\fi
\let\ZREF@temp\@empty
\@tfor\ZREF@P:=#1\do{%
\expandafter\ifx
\csname\ifZREF@immediate relax\else Z@X@\ZREF@P\fi\endcsname
\noexpand
\expandafter\let\csname Z@C@\ZREF@P\endcsname\relax
\fi
\toks@\expandafter{\ZREF@temp}%
\edef\ZREF@temp{%
\the\toks@
\expandafter\string\csname\ZREF@P\endcsname{%
\expandafter\noexpand\csname Z@C@\ZREF@P\endcsname
}%
}%
}%
}{%
\string\zref@newlabel{#2}{\ZREF@temp}%
}%
\endgroup
\fi
}
\def\ZREF@addtoks#1{%
\toks@\expandafter\expandafter\expandafter{%
\expandafter\the\expandafter\toks@#1%
}%
}
% \end{macrocode}
% \end{macro}
%
% \subsubsection{Reference querying and extracting}
%
% Design goal for the extracting macros is that the extraction
% process is full expandable. Thus these macros can be used
% in expandable contexts. But there are problems that cannot
% be solved by full expandable macros:
% \begin{itemize}
% \item In standard \LaTeX\ undefined references sets a flag
% and generate a warning. Both actions are not expandable.
% \item Babel's support for its shorthand uses commands that
% use non-expandable assignments. However currently there
% is hope, that primitives are added to \pdfTeX\ that
% allows the detection of contexts. Then the shorthand
% can detect, if they are executed inside \cs{csname}
% and protect themselves automatically.
% \end{itemize}
% \begin{macro}{\zref@ifrefundefined}
% If a reference \verb|#1| is undefined, then macro
% \cs{zref@ifrefundefined} calls \verb|#2| and \verb|#3| otherwise.
% \begin{macrocode}
\def\zref@ifrefundefined#1{%
\expandafter\ifx\csname Z@R@#1\endcsname\relax
\expandafter\ltx@firstoftwo
\else
\expandafter\ltx@secondoftwo
\fi
}
% \end{macrocode}
% \end{macro}
%
% \begin{macro}{\zifrefundefined}
% If a reference \verb|#1| is undefined, then macro
% \cs{zref@ifrefundefined} calls \verb|#2| and \verb|#3| otherwise.
% Also the reference is marked used.
% \begin{macrocode}
\newcommand*{\zifrefundefined}[1]{%
\zref@wrapper@babel\ZREF@ifrefundefined{#1}%
}
% \end{macrocode}
% \end{macro}
% \begin{macro}{\ZREF@ifrefundefined}
% \begin{macrocode}
\def\ZREF@ifrefundefined#1{%
\zref@refused{#1}%
\zref@ifrefundefined{#1}%
}
% \end{macrocode}
% \end{macro}
%
% \begin{macro}{\zref@refused}
% The problem with undefined references is addressed by
% the macro \cs{zref@refused}. This can be used outside
% the expandable context. In case of an undefined reference
% the flag is set to notify \LaTeX\ and a warning is given.
% \begin{macrocode}
\def\zref@refused#1{%
\zref@wrapper@babel\ZREF@refused{#1}%
}
% \end{macrocode}
% \end{macro}
% \begin{macro}{\ZREF@refused}
% \begin{macrocode}
\def\ZREF@refused#1{%
\zref@ifrefundefined{#1}{%
\protect\G@refundefinedtrue
\@latex@warning{%
Reference `#1' on page \thepage \space undefined%
}%
}{}%
}
% \end{macrocode}
% \end{macro}
%
% \begin{macro}{\zref@extract}
% \cs{zref@extract} is an abbreviation for the case
% that the default of the property is used as default
% value.
% \begin{macrocode}
\def\zref@extract#1#2{%
\expandafter\expandafter\expandafter\ZREF@extract
\expandafter\expandafter\expandafter{%
\csname Z@D@#2\endcsname
}{#1}{#2}%
}
\def\ZREF@extract#1#2#3{%
\zref@extractdefault{#2}{#3}{#1}%
}
% \end{macrocode}
% \end{macro}
%
% \begin{macro}{\zref@ifrefcontainsprop}
% \cs{zref@ifrefcontainsprop} looks, if the reference \verb|#1|
% has the property \verb|#2| and calls then \verb|#3| and
% \verb|#4| otherwise.
% \begin{macrocode}
\def\zref@ifrefcontainsprop#1#2{%
\zref@ifrefundefined{#1}{%
\ltx@secondoftwo
}{%
\expandafter\ZREF@ifrefcontainsprop
\csname Z@E@#2\expandafter\endcsname
\csname#2\expandafter\expandafter\expandafter\endcsname
\expandafter\expandafter\expandafter{%
\csname Z@R@#1\endcsname
}%
}%
}
\def\ZREF@ifrefcontainsprop#1#2#3{%
\expandafter\ifx\expandafter\ZREF@novalue
#1#3#2\ZREF@novalue\ZREF@nil\@empty
\expandafter\ltx@secondoftwo
\else
\expandafter\ltx@firstoftwo
\fi
}
\def\ZREF@novalue{\ZREF@NOVALUE}
% \end{macrocode}
% \end{macro}
%
% \begin{macro}{\zref@extractdefault}
% The basic extracting macro is \cs{zref@extractdefault} with
% the reference name in \verb|#1|, the property in \verb|#2| and
% the default value in \verb|#3| in case for problems.
% \begin{macrocode}
\def\zref@extractdefault#1#2#3{%
\zref@ifrefundefined{#1}{%
\ZREF@unexpanded{#3}%
}{%
\expandafter\expandafter\expandafter\ZREF@unexpanded
\expandafter\expandafter\expandafter{%
\csname Z@E@#2\expandafter\expandafter\expandafter\endcsname
\csname Z@R@#1\expandafter\endcsname
\csname#2\endcsname{#3}\ZREF@nil
}%
}%
}
% \end{macrocode}
% \end{macro}
%
% \begin{macro}{\zref@wrapper@unexpanded}
% \begin{macrocode}
\long\def\zref@wrapper@unexpanded#1{%
\let\ZREF@unexpanded\etex@unexpanded
#1%
\let\ZREF@unexpanded\ltx@firstofone
}
\let\ZREF@unexpanded\ltx@firstofone
% \end{macrocode}
% \end{macro}
%
% \subsubsection{Compatibility with \xpackage{babel}}
%
% \begin{macro}{\zref@wrapper@babel}
% \begin{macrocode}
\long\def\zref@wrapper@babel#1#2{%
\ifcsname if@safe@actives\endcsname
\expandafter\ltx@firstofone
\else
\expandafter\ltx@secondoftwo
\fi
{%
\if@safe@actives
\expandafter\ltx@secondoftwo
\else
\expandafter\ltx@firstoftwo
\fi
{%
\begingroup
\csname @safe@activestrue\endcsname
\edef\x{#2}%
\expandafter\endgroup
\expandafter\ZREF@wrapper@babel\expandafter{\x}{#1}%
}%
}{%
#1{#2}%
}%
}
\long\def\ZREF@wrapper@babel#1#2{%
#2{#1}%
}
% \end{macrocode}
% \end{macro}
%
% \subsubsection{Unique counter support}
%
% \begin{macro}{\zref@require@unique}
% Generate the counter |zref@unique| if the counter does not
% already exist.
% \begin{macrocode}
\def\zref@require@unique{%
\@ifundefined{c@zref@unique}{%
\begingroup
\let\@addtoreset\ltx@gobbletwo
\newcounter{zref@unique}%
\endgroup
% \end{macrocode}
% \end{macro}
%
% \begin{macro}{\thezref@unique}
% \cs{thezref@unique} is used for automatically generated unique
% labelnames.
% \begin{macrocode}
\renewcommand*{\thezref@unique}{%
zref@\number\c@zref@unique
}%
}{}%
}
% \end{macrocode}
% \end{macro}
%
% \subsubsection{Setup}
%
% \begin{macro}{\zref@setdefault}
% Standard \LaTeX\ prints ``??'' in bold face if a reference
% is not known. \cs{zref@default} holds the text that is
% printed in case of unknown references and is used, if
% the default was not specified during the definition
% of the new property by \cs{ref@newprop}.
% The global default value can be set by \cs{zref@setdefault}.
% \begin{macrocode}
\def\zref@setdefault#1{%
\def\zref@default{#1}%
}
% \end{macrocode}
% \end{macro}
% \begin{macro}{\zref@default}
% Now we initialize \cs{zref@default} with the same value
% that \LaTeX\ uses for its undefined references.
% \begin{macrocode}
\zref@setdefault{%
\nfss@text{\reset@font\bfseries ??}%
}
% \end{macrocode}
% \end{macro}
%
% \paragraph{Main property list.}
%
% \begin{macro}{\zref@setmainlist}
% The name of the default property list is stored in
% \cs{ZREF@mainlist} and can be set by \cs{zref@setmainlist}.
% \begin{macrocode}
\def\zref@setmainlist#1{%
\def\ZREF@mainlist{#1}%
}
\zref@setmainlist{main}
% \end{macrocode}
% \end{macro}
% Now we create the list.
% \begin{macrocode}
\zref@newlist\ZREF@mainlist
% \end{macrocode}
%
% \paragraph{Main properties.}
%
% The two properties \texttt{default} and \texttt{page}
% are created and added to the main property list.
% They store the data that
% standard \LaTeX\ uses in its references created by
% \cs{label}.
% \begin{description}
% \item[\texttt{default}] the apperance of the latest
% counter that is incremented by \cs{refstepcounter}
% \item[\texttt{page}] the apperance of the page counter
% \end{description}
% \begin{macrocode}
\zref@newprop{default}{\@currentlabel}
\zref@newprop*{page}{\thepage}
\zref@addprop\ZREF@mainlist{default}
\zref@addprop\ZREF@mainlist{page}
% \end{macrocode}
%
% \paragraph{Mark successful loading}
%
% \begin{macrocode}
\let\ZREF@baseok\@empty
%</base>
% \end{macrocode}
%
%
% \subsection{Module \xmodule{user}}
%
% \begin{macrocode}
%<*user>
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{zref-user}%
[2010/03/26 v2.8 Module user for zref (HO)]%
\RequirePackage{zref-base}[2010/03/26]
\@ifundefined{ZREF@baseok}{\endinput}{}
% \end{macrocode}
%
% Module \xmodule{user} enables a small user interface.
% All macros are prefixed by \cs{z}.
%
% First we define the pendants to the standard \LaTeX\ referencing
% commands \cs{label}, \cs{ref}, and \cs{pageref}.
%
% \begin{macro}{\zlabel}
% Similar to \cs{label} the macro \cs{zlabel} writes a reference
% entry in the \xfile{.aux} file. The main property list is used.
% Also we add the babel patch. The \cs{label} command can also be
% used inside section titles, but it must not go into the
% table of contents. Therefore we have to check this situation.
% \begin{macrocode}
\newcommand*\zlabel{%
\ifx\label\ltx@gobble
\expandafter\ltx@gobble
\else
\expandafter\zref@wrapper@babel\expandafter\zref@label
\fi
}%
% \end{macrocode}
% \end{macro}
%
% \begin{macro}{\zref}
% Macro \cs{zref} is the corresponding macro for \cs{ref}.
% Also it provides an optional argument in order to
% select another property.
% \begin{macrocode}
\newcommand*{\zref}[2][default]{%
\zref@propexists{#1}{%
\zref@wrapper@babel\ZREF@zref{#2}{#1}%
}%
}%
\def\ZREF@zref#1{%
\zref@refused{#1}%
\zref@extract{#1}%
}%
% \end{macrocode}
% \end{macro}
%
% \begin{macro}{\zpageref}
% For macro \cs{zpageref} we just call \cs{zref}
% with property \verb|page|.
% \begin{macrocode}
\newcommand*\zpageref{%
\zref[page]%
}%
% \end{macrocode}
% \end{macro}
%
% \begin{macro}{\zrefused}
% For the following expandible user macros \cs{zrefused}
% should be used to notify \LaTeX\ in case of undefined
% references.
% \begin{macrocode}
\newcommand*{\zrefused}{\zref@refused}%
% \end{macrocode}
% \end{macro}
%
% \begin{macrocode}
%</user>
% \end{macrocode}
%
%
% \subsection{Module \xmodule{abspage}}
%
% \begin{macrocode}
%<*abspage>
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{zref-abspage}%
[2010/03/26 v2.8 Module abspage for zref (HO)]%
\RequirePackage{zref-base}[2010/03/26]
\@ifundefined{ZREF@baseok}{\endinput}{}
% \end{macrocode}
%
% Module \xmodule{abspage} adds a new property \verb|abspage|
% to the \verb|main| property list for absolute page numbers.
% These are recorded by the help of package \xpackage{atbegshi}.
% \begin{macrocode}
\RequirePackage{atbegshi}%
% \end{macrocode}
% The counter \verb|abspage| must not go in the clear list
% of \verb|@ckpt| that is used to set counters in
% \xfile{.aux} files of included \TeX\ files.
% \begin{macrocode}
\begingroup
\let\@addtoreset\ltx@gobbletwo
\newcounter{abspage}%
\endgroup
\setcounter{abspage}{0}%
\AtBeginShipout{%
\stepcounter{abspage}%
}%
\zref@newprop*{abspage}[0]{\the\c@abspage}%
\zref@addprop\ZREF@mainlist{abspage}%
% \end{macrocode}
% Note that counter \verb|abspage| shows the
% previous page during page processing. Before
% shipout the counter is incremented.
% Thus the property is correctly written with
% deferred writing. If the counter is written
% using \cs{zref@wrapper@immediate}, then the number
% is too small by one.
%
% \begin{macrocode}
%</abspage>
% \end{macrocode}
%
%
% \subsection{Module \xmodule{counter}}
%
% \begin{macrocode}
%<*counter>
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{zref-counter}%
[2010/03/26 v2.8 Module counter for zref (HO)]%
\RequirePackage{zref-base}[2010/03/26]
\@ifundefined{ZREF@baseok}{\endinput}{}
% \end{macrocode}
%
% For features such as \xpackage{hyperref}'s \cs{autoref}
% we need the name of the counter. The property
% \verb|counter| is defined and added to the main property
% list.
% \begin{macrocode}
\zref@newprop{counter}{}
\zref@addprop\ZREF@mainlist{counter}
% \end{macrocode}
%
% \cs{refstepcounter} is the central macro where we know
% which counter is responsible for the reference.
% \begin{macrocode}
\AtBeginDocument{%
\ZREF@patch{refstepcounter}{%
\def\refstepcounter#1{%
\zref@setcurrent{counter}{#1}%
\ZREF@org@refstepcounter{#1}%
}%
}%
}
% \end{macrocode}
% \begin{macrocode}
%</counter>
% \end{macrocode}
%
%
% \subsection{Module \xmodule{lastpage}}
%
% \begin{macrocode}
%<*lastpage>
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{zref-lastpage}%
[2010/03/26 v2.8 Module lastpage for zref (HO)]%
\RequirePackage{zref-base}[2010/03/26]
\RequirePackage{zref-abspage}[2010/03/26]
\RequirePackage{atveryend}[2009/12/07]
\@ifundefined{ZREF@baseok}{\endinput}{}
% \end{macrocode}
%
% The module \xmodule{lastpage} implements the service
% of package \xpackage{lastpage} by setting a reference
% \verb|LastPage| at the end of the document.
% If module \xmodule{abspage} is given, also the absolute
% page number is available, because the properties of
% the main property list are used.
% \begin{macrocode}
\zref@newlist{LastPage}
\AfterLastShipout{%
\if@filesw
\begingroup
\advance\c@page\m@ne
\toks@\expandafter\expandafter\expandafter{%
\expandafter\Z@L@main
\Z@L@LastPage
}%
\expandafter\zref@wrapper@immediate\expandafter{%
\expandafter\ZREF@label\expandafter{\the\toks@}{LastPage}%
}%
\endgroup
\fi
}
% \end{macrocode}
% \begin{macro}{\zref@iflastpage}
% \begin{macrocode}
\def\zref@iflastpage#1{%
\ifnum\zref@extractdefault{#1}{abspage}{-1}=%
\zref@extractdefault{LastPage}{abspage}{-2} %
\expandafter\ltx@firstoftwo
\else
\expandafter\ltx@secondoftwo
\fi
}
% \end{macrocode}
% \end{macro}
% \begin{macro}{\ziflastpage}
% \begin{macrocode}
\newcommand*{\ziflastpage}{%
\zref@wrapper@babel\ZREF@iflastpage
}
% \end{macrocode}
% \end{macro}
% \begin{macro}{ZREF@iflastpage}
% \begin{macrocode}
\def\ZREF@iflastpage#1{%
\zref@refused{LastPage}%
\zref@refused{#1}%
\zref@iflastpage{#1}%
}
% \end{macrocode}
% \end{macro}
% \begin{macrocode}
%</lastpage>
% \end{macrocode}
%
%
% \subsection{Module \xmodule{thepage}}
%
% \begin{macrocode}
%<*thepage>
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{zref-thepage}%
[2010/03/26 v2.8 Module thepage for zref (HO)]%
\RequirePackage{zref-base}[2010/03/26]
\@ifundefined{ZREF@baseok}{\endinput}{}
% \end{macrocode}
%
% \begin{macrocode}
\RequirePackage{atbegshi}
\RequirePackage{zref-abspage}[2010/03/26]
% \end{macrocode}
% \begin{macrocode}
\zref@newlist{thepage}
\zref@addprop{thepage}{page}
\AtBeginShipout{%
\zref@wrapper@immediate{%
\zref@labelbylist{thepage\the\value{abspage}}{thepage}%
}%
}
% \end{macrocode}
% \begin{macro}{\zref@thepage@name}
% \begin{macrocode}
\ltx@IfUndefined{numexpr}{%
\def\zref@thepage@name#1{thepage\number#1}%
}{%
\def\zref@thepage@name#1{thepage\the\numexpr#1}%
}
% \end{macrocode}
% \end{macro}
% \begin{macro}{\zref@thepage}
% \begin{macrocode}
\def\zref@thepage#1{%
\zref@extract{\zref@thepage@name{#1}}{page}%
}%
% \end{macrocode}
% \end{macro}
% \begin{macro}{\zref@thepage@refused}
% \begin{macrocode}
\def\zref@thepage@refused#1{%
\zref@refused{\zref@thepage@name{#1}}%
}%
% \end{macrocode}
% \end{macro}
% \begin{macro}{\zthepage}
% \begin{macrocode}
\newcommand*{\zthepage}[1]{%
\zref@thepage@refused{#1}%
\zref@thepage{#1}%
}
% \end{macrocode}
% \end{macro}
% \begin{macrocode}
%</thepage>
% \end{macrocode}
%
%
% \subsection{Module \xmodule{nextpage}}
%
% \begin{macrocode}
%<*nextpage>
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{zref-nextpage}%
[2010/03/26 v2.8 Module nextpage for zref (HO)]%
\RequirePackage{zref-base}[2010/03/26]
\@ifundefined{ZREF@baseok}{\endinput}{}
% \end{macrocode}
%
% \begin{macrocode}
\RequirePackage{zref-abspage}[2010/03/26]
\RequirePackage{zref-thepage}[2010/03/26]
\RequirePackage{zref-lastpage}[2010/03/26]
\RequirePackage{uniquecounter}[2009/12/18]
% \end{macrocode}
% \begin{macrocode}
\UniqueCounterNew{znextpage}
\newcommand*{\znextpagesetup}{%
\afterassignment\ZREF@np@setup@i
\def\ZREF@np@call@unknown##1%
}
\def\ZREF@np@setup@i{%
\afterassignment\ZREF@np@setup@ii
\def\ZREF@np@call@nonext##1%
}
\def\ZREF@np@setup@ii{%
\def\ZREF@np@call@next##1%
}
\def\ZREF@np@call@unknown#1{#1}
\def\ZREF@np@call@nonext#1{#1}
\def\ZREF@np@call@next#1{#1}
\newcommand*{\znextpage}{%
\UniqueCounterCall{znextpage}{\ZREF@nextpage}%
}
\newcommand*{\znonextpagename}{}
\newcommand*{\zunknownnextpagename}{\Z@D@page}
\def\ZREF@nextpage#1{%
\begingroup
\def\ZREF@refname@this{zref@np#1}%
\zref@labelbyprops\ZREF@refname@this{abspage}%
\chardef\ZREF@call=0 % unknown
\ZREF@ifrefundefined\ZREF@refname@this{%
}{%
\edef\ZREF@pagenum@this{%
\zref@extractdefault\ZREF@refname@this{abspage}{0}%
}%
\edef\ZREF@refname@next{%
\zref@thepage@name{%
\the\numexpr\ZREF@pagenum@this+1%
}%
}%
\ifnum\ZREF@pagenum@this>0 %
\ZREF@ifrefundefined{LastPage}{%
\zref@ifrefundefined\ZREF@refname@next{%
}{%
\chardef\ZREF@call=2 % next page
}%
}{%
\edef\ZREF@pagenum@last{%
\zref@extractdefault{LastPage}{abspage}{0}%
}%
\ifnum\ZREF@pagenum@this<\ZREF@pagenum@last\ltx@space
\ZREF@ifrefundefined\ZREF@refname@next{%
}{%
\chardef\ZREF@call=2 % next page
}%
\else
\ifnum\ZREF@pagenum@this=\ZREF@pagenum@this\ltx@space
\chardef\ZREF@call=1 % no next page
\fi
\fi
}%
\fi
}%
\edef\x{%
\endgroup
\ifcase\ZREF@call
\noexpand\ZREF@np@call@unknown{%
\noexpand\zunknownnextpagename
}%
\or
\noexpand\ZREF@np@call@nonext{%
\noexpand\znonextpagename
}%
\else
\noexpand\ZREF@np@call@next{%
\noexpand\zref@extract{\ZREF@refname@next}{page}%
}%
\fi
}%
\x
}
% \end{macrocode}
% \begin{macrocode}
%</nextpage>
% \end{macrocode}
%
%
% \subsection{Module \xmodule{totpages}}
%
% \begin{macrocode}
%<*totpages>
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{zref-totpages}%
[2010/03/26 v2.8 Module totpages for zref (HO)]%
\RequirePackage{zref-base}[2010/03/26]
\@ifundefined{ZREF@baseok}{\endinput}{}
% \end{macrocode}
%
% The absolute page number of the last page is the total
% page number.
% \begin{macrocode}
\RequirePackage{zref-abspage}[2010/03/26]
\RequirePackage{zref-lastpage}[2010/03/26]
% \end{macrocode}
%
% \begin{macro}{\ztotpages}
% Macro \cs{ztotpages} contains the number of pages. It can be
% used inside expandable calculations. It expands to zero if
% the reference is not yet available.
% \begin{macrocode}
\newcommand*{\ztotpages}{%
\zref@extractdefault{LastPage}{abspage}{0}%
}
% \end{macrocode}
% \end{macro}
% Also we mark the reference |LastPage| as used:
% \begin{macrocode}
\AtBeginDocument{%
\zref@refused{LastPage}%
}
% \end{macrocode}
% \begin{macrocode}
%</totpages>
% \end{macrocode}
%
%
% \subsection{Module \xmodule{runs}}
%
% This module does not use the label-reference-system.
% The reference changes with each \LaTeX~run and would
% force a rerun warning always.
% \begin{macrocode}
%<*runs>
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{zref-runs}%
[2010/03/26 v2.8 Module runs for zref (HO)]%
% \end{macrocode}
%
% \begin{macro}{\zruns}
% \begin{macrocode}
\providecommand*{\zruns}{0}%
\AtBeginDocument{%
\edef\zruns{\number\numexpr\zruns+1}%
\begingroup
\def\on@line{}%
\PackageInfo{zref-runs}{LaTeX runs: \zruns}%
\if@filesw
\immediate\write\@mainaux{%
\string\gdef\string\zruns{\zruns}%
}%
\fi
\endgroup
}
% \end{macrocode}
% \end{macro}
%
% \begin{macrocode}
%</runs>
% \end{macrocode}
%
%
% \subsection{Module \xmodule{perpage}}
%
% \begin{macrocode}
%<*perpage>
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{zref-perpage}%
[2010/03/26 v2.8 Module perpage for zref (HO)]%
\RequirePackage{zref-base}[2010/03/26]
\@ifundefined{ZREF@baseok}{\endinput}{}
% \end{macrocode}
%
% This module resets a counter at page boundaries.
% Because of the asynchronous output routine
% page counter properties cannot be asked directly,
% references are necessary.
%
% For detecting changed pages module \xmodule{abspage}
% is loaded.
% \begin{macrocode}
\RequirePackage{zref-abspage}[2010/03/26]
% \end{macrocode}
%
% We group the properties for the needed references
% in the property list |perpage|. The property |pagevalue|
% records the correct value of the page counter.
% \begin{macrocode}
\zref@newprop*{pagevalue}[0]{\number\c@page}
\zref@newlist{perpage}
\zref@addprop{perpage}{abspage}
\zref@addprop{perpage}{page}
\zref@addprop{perpage}{pagevalue}
% \end{macrocode}
% The page value, known by the reference mechanism, will be
% stored in counter |zpage|.
% \begin{macrocode}
\newcounter{zpage}
% \end{macrocode}
% Counter |zref@unique| helps in generating unique reference
% names.
% \begin{macrocode}
\zref@require@unique
% \end{macrocode}
% In order to be able to reset the counter, we hook here
% into \cs{stepcounter}. In fact two nested hooks are used
% to allow other packages to use the first hook at the beginning
% of \cs{stepcounter}.
% \begin{macrocode}
\let\ZREF@org@stepcounter\stepcounter
\def\stepcounter#1{%
\ifcsname @stepcounterhook@#1\endcsname
\csname @stepcounterhook@#1\endcsname
\fi
\ZREF@org@stepcounter{#1}%
}
% \end{macrocode}
%
% \begin{macro}{\zmakeperpage}
% Makro \cs{zmakeperpage} resets a counter at each page
% break. It uses the same syntax and semantics as
% \cs{MakePerPage} from package \xpackage{perpage} \cite{perpage}.
% The initial start value can be given by the optional
% argument. Default is one that means after the first
% \cs{stepcounter} on a new page the counter starts with
% one.
% \begin{macrocode}
\newcommand*{\zmakeperpage}{%
\@ifnextchar[\ZREF@makeperpage@opt{\ZREF@@makeperpage[\z@]}%
}
% \end{macrocode}
% \end{macro}
% We hook before the counter is incremented in \cs{stepcounter},
% package \xpackage{perpage} afterwards. Thus a little
% calculation is necessary.
% \begin{macrocode}
\def\ZREF@makeperpage@opt[#1]{%
\begingroup
\edef\x{\endgroup
\noexpand\ZREF@@makeperpage[\number\numexpr#1-1\relax]%
}%
\x
}
% \end{macrocode}
% \begin{macrocode}
\def\ZREF@@makeperpage[#1]#2{%
\@ifundefined{@stepcounterhook@#2}{%
\expandafter\gdef\csname @stepcounterhook@#2\endcsname{}%
}{}%
\expandafter\gdef\csname ZREF@perpage@#2\endcsname{%
\ZREF@@perpage@step{#2}{#1}%
}%
\expandafter\g@addto@macro\csname @stepcounterhook@#2\endcsname{%
\ifcsname ZREF@perpage@#2\endcsname
\csname ZREF@perpage@#2\endcsname
\fi
}%
}
% \end{macrocode}
% \begin{macro}{\ZREF@@perpage@step}
% The heart of this module follows.
% \begin{macrocode}
\def\ZREF@@perpage@step#1#2{%
% \end{macrocode}
% First the reference is generated.
% \begin{macrocode}
\global\advance\c@zref@unique\@ne
\begingroup
\expandafter\zref@labelbylist\expandafter{\thezref@unique}{perpage}%
% \end{macrocode}
% The \cs{expandafter} commands are necessary, because \cs{ZREF@temp}
% is also used inside of \cs{zref@labelbylist}.
%
% The evaluation of the reference follows. If the reference
% is not yet kwown, we use the page counter as approximation.
% \begin{macrocode}
\zref@ifrefundefined\thezref@unique{%
\global\c@zpage=\c@page
\global\let\thezpage\thepage
\expandafter\xdef\csname ZREF@abspage@#1\endcsname{\number\c@abspage}%
}{%
% \end{macrocode}
% The reference is used to set \cs{thezpage} and counter |zpage|.
% \begin{macrocode}
\global\c@zpage=\zref@extract\thezref@unique{pagevalue}\relax
\xdef\thezpage{\noexpand\zref@extract{\thezref@unique}{page}}%
\expandafter\xdef\csname ZREF@abspage@#1\endcsname{%
\zref@extractdefault\thezref@unique{abspage}{\number\c@abspage}%
}%
}%
% \end{macrocode}
% Page changes are detected by a changed absolute page number.
% \begin{macrocode}
\expandafter\ifx\csname ZREF@abspage@#1\expandafter\endcsname
\csname ZREF@currentabspage@#1\endcsname
\else
\global\csname c@#1\endcsname=#2\relax
\global\expandafter\let
\csname ZREF@currentabspage@#1\expandafter\endcsname
\csname ZREF@abspage@#1\endcsname
\fi
\endgroup
}
% \end{macrocode}
% \end{macro}
% \begin{macro}{\zunmakeperpage}
% Macro \cs{zunmakeperpage} cancels the effect of \cs{zmakeperpage}.
% \begin{macrocode}
\newcommand*{\zunmakeperpage}[1]{%
\global\expandafter\let\csname ZREF@perpage@#1\endcsname\@undefined
}
% \end{macrocode}
% \end{macro}
%
% \begin{macrocode}
%</perpage>
% \end{macrocode}
%
%
% \subsection{Module \xmodule{titleref}}
%
% \begin{macrocode}
%<*titleref>
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{zref-titleref}%
[2010/03/26 v2.8 Module titleref for zref (HO)]%
\RequirePackage{zref-base}[2010/03/26]
\@ifundefined{ZREF@baseok}{\endinput}{}
\RequirePackage{gettitlestring}[2009/12/08]
% \end{macrocode}
%
% \subsubsection{Implementation}
% \begin{macrocode}
\RequirePackage{keyval}
% \end{macrocode}
%
% This module makes section and caption titles available
% for the reference system. It uses some of the ideas
% of package \xpackage{nameref} and \xpackage{titleref}.
%
% \begin{macro}{\zref@titleref@current}
% Later we will redefine the section and caption macros
% to catch the current title and remember the value in
% \cs{zref@titleref@current}.
% \begin{macrocode}
\let\zref@titleref@current\@empty
% \end{macrocode}
% \end{macro}
% Now we can add the property \verb|title| is added to
% the main property list.
% \begin{macrocode}
\zref@newprop{title}{\zref@titleref@current}%
\zref@addprop\ZREF@mainlist{title}%
% \end{macrocode}
%
% The title strings go into the \xfile{.aux} file, thus
% they need some kind of protection.
% Package \xpackage{titleref} uses a protected expansion
% method. The advantage is that this can be used to
% cleanup the string and to remove \cs{label}, \cs{index}
% and other macros unwanted for referencing.
% But there is the risk that fragile stuff can break.
%
% Therefore package \xpackage{nameref} does not expand
% the string. Thus the entries can safely be written to
% the \xfile{.aux} file. But potentially dangerous
% macros such as \cs{label} remain in the string and
% can cause problems when using the string in references.
%
% \begin{macro}{\ifzref@titleref@expand}
% The switch \cs{ifzref@titleref@expand} distinguishes
% between the both methods. Package \xpackage{nameref}'s
% behaviour is achieved by setting the switch to false,
% otherwise \xpackage{titleref}'s expansion is used.
% Default is false.
% \begin{macrocode}
\newif\ifzref@titleref@expand
% \end{macrocode}
% \end{macro}
%
% \begin{macro}{\ZREF@titleref@hook}
% The hook \cs{ZREF@titleref@hook} allows to extend
% the cleanup for the expansion method. Thus
% unnecessary macros can be removed or dangerous commands
% removed. The hook is executed before the expansion of
% \cs{zref@titleref@current}.
% \begin{macrocode}
\let\ZREF@titleref@hook\@empty
% \end{macrocode}
% \end{macro}
% \begin{macro}{\zref@titleref@cleanup}
% The hook should not be used directly, instead we provide the
% macro \cs{zref@titleref@cleanup} to add stuff to the hook
% and prevents that a previous non-empty content is not discarded
% accidently.
% \begin{macrocode}
\def\zref@titleref@cleanup#1{%
\begingroup
\toks@\expandafter{%
\ZREF@titleref@hook
#1%
}%
\expandafter\endgroup
\expandafter\def\expandafter\ZREF@titleref@hook\expandafter{%
\the\toks@
}%
}%
% \end{macrocode}
% \end{macro}
%
% \begin{macro}{\ifzref@titleref@stripperiod}
% Sometimes a title contains a period at the end.
% Package \xpackage{nameref} removes this. This behaviour
% is controlled by the switch \cs{ifzref@titleref@stripperiod}
% and works regardless of the setting of option \xoption{expand}.
% Period stripping is the default.
% \begin{macrocode}
\newif\ifzref@titleref@stripperiod
\zref@titleref@stripperiodtrue
% \end{macrocode}
% \end{macro}
%
% \begin{macro}{\zref@titleref@setcurrent}
% Macro \cs{zref@titleref@setcurrent} sets a new current title
% stored in \cs{zref@titleref@current}. Some cleanup and
% expansion is performed that can be controlled by the
% previous switches.
% \begin{macrocode}
\def\zref@titleref@setcurrent#1{%
\ifzref@titleref@expand
\GetTitleStringExpand{#1}%
\else
\GetTitleStringNonExpand{#1}%
\fi
\edef\zref@titleref@current{%
\detokenize\expandafter{\GetTitleStringResult}%
}%
\ifzref@titleref@stripperiod
\edef\zref@titleref@current{%
\expandafter\ZREF@stripperiod\zref@titleref@current
\@empty.\@empty\@nil
}%
\fi
}%
\GetTitleStringDisableCommands{%
\ZREF@titleref@hook
}
% \end{macrocode}
% \end{macro}
% \begin{macro}{\ZREF@stripperiod}
% If \cs{ZREF@stripperiod} is called, the argument consists of
% space tokens and tokens with catcode 12 (other), because
% of \eTeX's \cs{detokenize}.
% \begin{macrocode}
\def\ZREF@stripperiod#1.\@empty#2\@nil{#1}%
% \end{macrocode}
% \end{macro}
%
% \subsubsection{User interface}
%
% \begin{macro}{\ztitlerefsetup}
% The behaviour of module \xmodule{titleref} is controlled
% by switches and a hook. They can be set by \cs{ztitlerefsetup}
% with a key value interface, provided by package \xpackage{keyval}.
% Also the current title can be given explicitly by the key
% \verb|title|.
% \begin{macrocode}
\define@key{ZREF@TR}{expand}[true]{%
\csname zref@titleref@expand#1\endcsname
}%
\define@key{ZREF@TR}{stripperiod}[true]{%
\csname zref@titleref@stripperiod#1\endcsname
}%
\define@key{ZREF@TR}{cleanup}{%
\zref@titleref@cleanup{#1}%
}%
\define@key{ZREF@TR}{title}{%
\def\zref@titleref@current{#1}%
}%
\newcommand*{\ztitlerefsetup}{%
\setkeys{ZREF@TR}%
}%
% \end{macrocode}
% \end{macro}
%
% \begin{macro}{\ztitleref}
% The user command \cs{ztitleref} references the title.
% For safety \cs{label} is disabled to prevent multiply
% defined references.
% \begin{macrocode}
\newcommand*{\ztitleref}{%
\zref@wrapper@babel\ZREF@titleref
}%
\def\ZREF@titleref#1{%
\begingroup
\zref@refused{#1}%
\let\label\ltx@gobble
\zref@extract{#1}{title}%
\endgroup
}%
% \end{macrocode}
% \end{macro}
%
% \subsubsection{Patches for section and caption commands}
%
% The section and caption macros are patched to extract the
% title data.
%
% Captions of figures and tables.
% \begin{macrocode}
\AtBeginDocument{%
\ZREF@patch{@caption}{%
\long\def\@caption#1[#2]{%
\zref@titleref@setcurrent{#2}%
\ZREF@org@@caption{#1}[{#2}]%
}%
}%
% \end{macrocode}
%
% Section commands without star. The title version for the
% table of contents is used because it is usually shorter and
% more robust.
% \begin{macrocode}
\ZREF@patch{@part}{%
\def\@part[#1]{%
\zref@titleref@setcurrent{#1}%
\ZREF@org@@part[{#1}]%
}%
}%
\ZREF@patch{@chapter}{%
\def\@chapter[#1]{%
\zref@titleref@setcurrent{#1}%
\ZREF@org@@chapter[{#1}]%
}%
}%
\ZREF@patch{@sect}{%
\def\@sect#1#2#3#4#5#6[#7]{%
\zref@titleref@setcurrent{#7}%
\ZREF@org@@sect{#1}{#2}{#3}{#4}{#5}{#6}[{#7}]%
}%
}%
% \end{macrocode}
% The star versions of the section commands.
% \begin{macrocode}
\ZREF@patch{@spart}{%
\def\@spart#1{%
\zref@titleref@setcurrent{#1}%
\ZREF@org@@spart{#1}%
}%
}%
\ZREF@patch{@schapter}{%
\def\@schapter#1{%
\zref@titleref@setcurrent{#1}%
\ZREF@org@@schapter{#1}%
}%
}%
\ZREF@patch{@ssect}{%
\def\@ssect#1#2#3#4#5{%
\zref@titleref@setcurrent{#5}%
\ZREF@org@@ssect{#1}{#2}{#3}{#4}{#5}%
}%
}%
% \end{macrocode}
%
% Class \xpackage{beamer}.
% \begin{macrocode}
\@ifclassloaded{beamer}{%
\ZREF@patch{beamer@section}{%
\long\def\beamer@section[#1]{%
\zref@titleref@setcurrent{#1}%
\ZREF@org@beamer@section[{#1}]%
}%
}%
\ZREF@patch{beamer@subsection}{%
\long\def\beamer@subsection[#1]{%
\zref@titleref@setcurrent{#1}%
\ZREF@org@beamer@subsection[{#1}]%
}%
}%
\ZREF@patch{beamer@subsubsection}{%
\long\def\beamer@subsubsection[#1]{%
\zref@titleref@setcurrent{#1}%
\ZREF@org@beamer@subsubsection[{#1}]%
}%
}%
}{}%
% \end{macrocode}
%
% Package \xpackage{titlesec}.
% \begin{macrocode}
\@ifpackageloaded{titlesec}{%
\ZREF@patch{ttl@sect@i}{%
\def\ttl@sect@i#1#2[#3]#4{%
\zref@titleref@setcurrent{#4}%
\ZREF@org@ttl@sect@i{#1}{#2}[{#3}]{#4}%
}%
}%
}{}%
% \end{macrocode}
%
% Package \xpackage{longtable}: some support for its \cs{caption}.
% However \cs{label} inside the caption is not supported.
% \begin{macrocode}
\@ifpackageloaded{longtable}{%
\ZREF@patch{LT@c@ption}{%
\def\LT@c@ption#1[#2]#3{%
\ZREF@org@LT@c@ption{#1}[{#2}]{#3}%
\zref@titleref@setcurrent{#2}%
}%
}%
}{}%
% \end{macrocode}
%
% Package \xpackage{listings}: support for its caption.
% \begin{macrocode}
\@ifpackageloaded{listings}{%
\ZREF@patch{lst@MakeCaption}{%
\def\lst@MakeCaption{%
\ifx\lst@label\@empty
\else
\expandafter\zref@titleref@setcurrent\expandafter{%
\lst@@caption
}%
\fi
\ZREF@org@lst@MakeCaption
}%
}%
}{}%
}
% \end{macrocode}
%
%
% \begin{macrocode}
%</titleref>
% \end{macrocode}
%
%
% \subsection{Module \xmodule{xr}}
%
% \begin{macrocode}
%<*xr>
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{zref-xr}%
[2010/03/26 v2.8 Module xr for zref (HO)]%
\RequirePackage{zref-base}[2010/03/26]
\@ifundefined{ZREF@baseok}{\endinput}{}
% \end{macrocode}
% \begin{macrocode}
\RequirePackage{keyval}
% \end{macrocode}
%
% We declare property |url|, because this is added,
% if a reference is imported and has not already set this field.
% Or if |hyperref| is used, then this property can be asked.
% \begin{macrocode}
\zref@newprop{url}{}%
% \end{macrocode}
%
%
% Most code, especially the handling of the \xfile{.aux}
% files are taken from David Carlisle's \xpackage{xr} package.
% Therefore I drop the documentation for these macros here.
%
% \begin{macro}{\zref@xr@ext}
% If the URL is not specied, then assume
% processed file with a guessed extension.
% Use the setting of \xpackage{hyperref} if available.
% \begin{macrocode}
\providecommand*{\zref@xr@ext}{%
\ltx@ifundefined{XR@ext}{pdf}{\XR@ext}%
}%
% \end{macrocode}
% \end{macro}
% \begin{macro}{\ifZREF@xr@zreflabel}
% The use of the star form of \cs{zexternaldocument}
% is remembered in the switch \cs{ifZREF@xr@zreflabel}.
% \begin{macrocode}
\newif\ifZREF@xr@zreflabel
% \end{macrocode}
% \end{macro}
% \begin{macro}{\zexternaldocument}
% In its star form it looks for \cs{newlabel},
% otherwise for \cs{zref@newlabel}.
% Later we
% will read \xfile{.aux} files that expects
% |@| to have catcode 11 (letter).
% \begin{macrocode}
\newcommand*{\zexternaldocument}{%
\begingroup
\csname @safe@actives@true\endcsname
\makeatletter
\@ifstar{%
\ZREF@xr@zreflabelfalse
\@testopt\ZREF@xr@externaldocument{}%
}{%
\ZREF@xr@zreflabeltrue
\@testopt\ZREF@xr@externaldocument{}%
}%
}%
% \end{macrocode}
% \end{macro}
%
% If the \cs{include} featuer was used, there can be
% several \xfile{.aux} files. These files are read
% one after another, especially they are not recursively
% read in order to save read registers. Thus it can
% happen that the read order of the newlabel commands
% differs from \LaTeX's order using \cs{input}.
%
% \begin{macro}{\ZREF@xr@externaldocument}
% It reads the remaining arguments. \cs{newcommand}
% comes in handy for the optional argument.
% \begin{macrocode}
\def\ZREF@xr@externaldocument[#1]#2{%
\def\ZREF@xr@prefix{#1}%
\let\ZREF@xr@filelist\@empty
\edef\ZREF@xr@file{#2.aux}%
\filename@parse{#2}%
\@testopt\ZREF@xr@graburl{#2.\zref@xr@ext}%
}%
\def\ZREF@xr@graburl[#1]{%
\edef\ZREF@xr@url{#1}%
\ZREF@xr@checkfile
\endgroup
}%
% \end{macrocode}
% \end{macro}
% \begin{macro}{\ZREF@xr@processfile}
% We follow \xpackage{xr} here, \cs{IfFileExists} offers
% a nicer test, but we have to open the file anyway.
% \begin{macrocode}
\def\ZREF@xr@checkfile{%
\openin\@inputcheck\ZREF@xr@file\relax
\ifeof\@inputcheck
\PackageWarning{zref-xr}{%
File `\ZREF@xr@file' not found or empty,\MessageBreak
labels not imported%
}%
\else
\PackageInfo{zref-xr}{%
Label \ifZREF@xr@zreflabel (zref) \fi import from `\ZREF@xr@file'%
}%
\def\ZREF@xr@found{0}%
\def\ZREF@xr@ignored{0}%
\ZREF@xr@processfile
\closein\@inputcheck
\begingroup
\let\on@line\@empty
\PackageInfo{zref-xr}{%
Statistics for `\ZREF@xr@file': %
\ZREF@xr@found\space found, %
\ZREF@xr@ignored\space ignored%
}%
\endgroup
\fi
\ifx\ZREF@xr@filelist\@empty
\else
\edef\ZREF@xr@file{\expandafter\@car\ZREF@xr@filelist\@nil}%
\edef\ZREF@xr@filelist{\expandafter\@cdr\ZREF@xr@filelist\@nil}%
\expandafter\ZREF@xr@checkfile
\fi
}%
% \end{macrocode}
% \end{macro}
%
% \begin{macro}{\ZREF@xr@processfile}
% \begin{macrocode}
\def\ZREF@xr@processfile{%
\read\@inputcheck to\ZREF@xr@line
\expandafter\ZREF@xr@processline\ZREF@xr@line..\ZREF@nil
\ifeof\@inputcheck
\else
\expandafter\ZREF@xr@procesfile
\fi
}%
% \end{macrocode}
% \end{macro}
% \begin{macro}{\ZREF@xr@processline}
% The most work must be done for analyzing the
% arguments of \cs{newlabel}.
% \begin{macrocode}
\long\def\ZREF@xr@processline#1#2#3\ZREF@nil{%
\def\x{#1}%
\toks@{#2}%
\ifZREF@xr@zreflabel
\ifx\x\ZREF@xr@zref@newlabel
\expandafter\ZREF@xr@process@zreflabel\ZREF@xr@line...\ZREF@nil
\fi
\else
\ifx\x\ZREF@xr@newlabel
\expandafter\ZREF@xr@process@label\ZREF@xr@line...[]\ZREF@nil
\fi
\fi
\ifx\x\ZREF@xr@@input
\edef\ZREF@xr@filelist{%
\etex@unexpanded\expandafter{\ZREF@xr@filelist}%
{\filename@area\the\toks@}%
}%
\fi
\ifeof\@inputcheck
\else
\expandafter\ZREF@xr@processfile
\fi
}%
\def\ZREF@xr@process@zreflabel\zref@newlabel#1#2#3\ZREF@nil{%
\def\ZREF@xr@refname{Z@R@\ZREF@xr@prefix#1}%
\edef\ZREF@xr@found{\the\numexpr\ZREF@xr@found+1\relax}%
\def\x{#2}%
\@ifundefined{\ZREF@xr@refname}{%
\let\ZREF@xr@list\x
\ifx\ZREF@xr@list\@empty
\PackageWarningNoLine{zref-xr}{%
Label `#1' without properties ignored\MessageBreak
in file `\ZREF@xr@file'%
}%
\edef\ZREF@xr@ignored{\the\numexpr\ZREF@xr@ignored+1\relax}%
\else
\expandafter\ZREF@xr@checklist\x\ZREF@nil
\expandafter\global\expandafter\let
\csname \ZREF@xr@refname\endcsname\x
\fi
\ZREF@xr@urlcheck{\ZREF@xr@prefix#1}%
}{%
\ZREF@xr@ignorewarning{\ZREF@xr@prefix#1}%
}%
}%
\def\ZREF@xr@process@label\newlabel#1#2#3[#4]#5\ZREF@nil{%
\def\ZREF@xr@refname{Z@R@\ZREF@xr@prefix#1}%
\edef\ZREF@xr@found{\the\numexpr\ZREF@xr@found+1\relax}%
\def\x{#2}%
\@ifundefined{\ZREF@xr@refname}{%
\expandafter\ZREF@xr@scanparams
\csname\ZREF@xr@refname\expandafter\endcsname
\x{}{}{}{}{}\ZREF@nil
\ifx\\#4\\%
\else
% ntheorem knows an optional argument at the end of \newlabel
\zref@ifpropundefined{theotype}{%
\zref@newprop{theotype}{}%
}{}%
\expandafter\g@addto@macro
\csname\ZREF@xr@refname\endcsname{\theotype{#4}}%
\fi
\ZREF@xr@urlcheck{\ZREF@xr@prefix#1}%
}{%
\ZREF@xr@ignorewarning{\ZREF@xr@prefix#1}%
}%
}
\def\ZREF@xr@zref@newlabel{\zref@newlabel}%
\def\ZREF@xr@newlabel{\newlabel}%
\def\ZREF@xr@@input{\@input}%
% \end{macrocode}
% \end{macro}
%
% \begin{macro}{\ZREF@xr@ignorewarning}
% \begin{macrocode}
\def\ZREF@xr@ignorewarning#1{%
\PackageWarningNoLine{zref-xr}{%
Label `#1' is already in use\MessageBreak
in file `\ZREF@xr@file'%
}%
\edef\ZREF@xr@ignored{\the\numexpr\ZREF@xr@ignored+1\relax}%
}%
% \end{macrocode}
% \end{macro}
%
% \begin{macro}{\ZREF@xr@checklist}
% \begin{macrocode}
\def\ZREF@xr@checklist#1#2#3\ZREF@nil{%
\ifx\@undefined#1\relax
\expandafter\ZREF@xr@checkkey\string#1\@nil
\fi
\ifx\\#3\\%
\else
\@ReturnAfterFi{%
\ZREF@xr@checklist#3\ZREF@nil
}%
\fi
}%
\long\def\@ReturnAfterFi#1\fi{\fi#1}%
\def\ZREF@xr@checkkey#1#2\@nil{%
\zref@ifpropundefined{#2}{%
\zref@newprop{#2}{}%
}{}%
}%
% \end{macrocode}
% \end{macro}
%
% \begin{macro}{\ZREF@xr@scanparams}
% \begin{macrocode}
\def\ZREF@xr@scanparams#1#2#3#4#5#6#7\ZREF@nil{%
\global\let#1\@empty
\ZREF@foundfalse
\ZREF@xr@scantitleref#1#2\TR@TitleReference{}{}\ZREF@nil
\ifZREF@found
\else
\g@addto@macro#1{\default{#2}}%
\fi
% page
\g@addto@macro#1{\page{#3}}%
% nameref title
\ifZREF@found
\else
\ifx\\#4\\%
\else
\zref@ifpropundefined{title}{%
\zref@newprop{title}{}%
}{}%
\g@addto@macro#1{\title{#4}}%
\fi
\fi
% anchor
\ifx\\#5\\%
\else
\zref@ifpropundefined{anchor}{%
\zref@newprop{anchor}{}%
}{}%
\g@addto@macro#1{\anchor{#5}}%
\fi
\ifx\\#6\\%
\else
\zref@ifpropundefined{url}{%
\zref@newprop{url}{}%
}{}%
\g@addto@macro#1{\url{#6}}%
\fi
}%
% \end{macrocode}
% \end{macro}
%
% \begin{macro}{\ZREF@xr@scantitleref}
% \begin{macrocode}
\def\ZREF@xr@scantitleref#1#2\TR@TitleReference#3#4#5\ZREF@nil{%
\ifx\\#5\\%
\else
\g@addto@macro#1{%
\default{#3}%
\title{#4}%
}%
\ZREF@foundtrue
\fi
}%
% \end{macrocode}
% \end{macro}
%
% \begin{macro}{\ZREF@xr@urlcheck}%
% \begin{macrocode}
\def\ZREF@xr@urlcheck#1{%
\zref@ifrefcontainsprop{#1}{anchor}{%
\zref@ifrefcontainsprop{#1}{url}{%
}{%
\expandafter\g@addto@macro\csname Z@R@#1\expandafter\endcsname
\expandafter{%
\expandafter\url\expandafter{\ZREF@xr@url}%
}%
}%
}{%
}%
}%
% \end{macrocode}
% \end{macro}
%
% \begin{macro}{\zxrsetup}
% Just one key for setting the default extension is currently used.
% \begin{macrocode}
\define@key{ZREF@XR}{ext}{%
\def\zref@xr@ext{#1}%
}%
\newcommand*{\zxrsetup}{%
\setkeys{ZREF@XR}%
}%
% \end{macrocode}
% \end{macro}
%
% \begin{macrocode}
%</xr>
% \end{macrocode}
%
%
% \subsection{Module \xmodule{hyperref}}
%
% UNFINISHED :-(
%
% \begin{macrocode}
%<*hyperref>
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{zref-hyperref}%
[2010/03/26 v2.8 Module hyperref for zref (HO)]%
\RequirePackage{zref-base}[2010/03/26]
\@ifundefined{ZREF@baseok}{\endinput}{}
% \end{macrocode}
%
% \begin{macrocode}
\zref@newprop{anchor}[]{%
\ltx@ifundefined{@currentHref}{}{\@currentHref}%
}%
\zref@addprop\ZREF@mainlist{anchor}%
% \end{macrocode}
%
% \begin{macrocode}
%</hyperref>
% \end{macrocode}
%
%
% \subsection{Module \xmodule{savepos}}
%
% Module \xmodule{savepos} provides an interface for
% \pdfTeX's \cmd{\pdfsavepos}, see the manual for
% \pdfTeX.
%
% \subsubsection{Identification}
%
% \begin{macrocode}
%<*savepos>
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{zref-savepos}%
[2010/03/26 v2.8 Module savepos for zref (HO)]%
\RequirePackage{zref-base}[2010/03/26]
\@ifundefined{ZREF@baseok}{\endinput}{}
% \end{macrocode}
%
% \subsubsection{Availability}
%
% First we check, whether the feature is available.
% \begin{macrocode}
\ltx@IfUndefined{pdfsavepos}{%
\ZREF@ErrorNoLine{%
\string\pdfsavepos\space is not supported.\MessageBreak
It is provided by pdfTeX (1.40) or XeTeX%
}\ZREF@UpdatePdfTeX
\endinput
}{}%
% \end{macrocode}
% In PDF mode we are done. However support for DVI mode
% was added later in version 1.40.0. In earlier versions
% \cs{pdfsavepos} is defined, but its execution raises
% an error. Note that Xe\TeX\ also provides \cs{pdfsavepos}.
% \begin{macrocode}
\RequirePackage{ifpdf}
\ifpdf
\else
\begingroup\expandafter\expandafter\expandafter\endgroup
\expandafter\ifx\csname pdftexversion\endcsname\relax
\else
\ifnum\pdftexversion<140 %
\ZREF@ErrorNoLine{%
\string\pdfsavepos\space is not supported in DVI mode\MessageBreak
of this pdfTeX version%
}\ZREF@UpdatePdfTeX
\expandafter\expandafter\expandafter\endinput
\fi
\fi
\fi
% \end{macrocode}
%
% \subsubsection{Setup}
%
% \begin{macrocode}
\zref@newlist{savepos}
\zref@newprop*{posx}[0]{\the\pdflastxpos}
\zref@newprop*{posy}[0]{\the\pdflastypos}
\zref@addprop{savepos}{posx}
\zref@addprop{savepos}{posy}
% \end{macrocode}
%
% \subsubsection{User macros}
%
% \begin{macro}{\zsavepos}
% The current location is stored in a reference with the
% given name.
% \begin{macrocode}
\def\zsavepos#1{%
\@bsphack
\if@filesw
\pdfsavepos
\zref@labelbylist{#1}{savepos}%
\fi
\@esphack
}
% \end{macrocode}
% \end{macro}
%
% \begin{macro}{\zposx}
% \begin{macro}{\zposy}
% The horizontal and vertical position are available by
% \cs{zposx} and \cs{zposy}. Do not rely on absolute
% positions. They differ in DVI and PDF mode of \pdfTeX.
% Use differences instead. The unit of the position numbers
% is sp.
% \begin{macrocode}
\newcommand*{\zposx}[1]{%
\zref@extract{#1}{posx}%
}%
\newcommand*{\zposy}[1]{%
\zref@extract{#1}{posy}%
}%
% \end{macrocode}
% \end{macro}
% \end{macro}
%
% Typically horizontal and vertical positions are used
% inside calculations. Therefore the extracting macros
% should be expandable and babel's patch is not applyable.
%
% Also it is in the responsibility of the user to marked
% used positions by \cs{zrefused}
% in order to notify \LaTeX\ about undefined references.
%
% \begin{macrocode}
%</savepos>
% \end{macrocode}
%
%
% \subsection{Module \xmodule{dotfill}}
%
% \begin{macrocode}
%<*dotfill>
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{zref-dotfill}%
[2010/03/26 v2.8 Module dotfill for zref (HO)]%
\RequirePackage{zref-base}[2010/03/26]
\@ifundefined{ZREF@baseok}{\endinput}{}
% \end{macrocode}
%
% For measuring the width of \cs{zdotfill} we use the features
% provided by module \xmodule{savepos}.
% \begin{macrocode}
\RequirePackage{zref-savepos}[2010/03/26]
% \end{macrocode}
% For automatically generated label names we use the unique
% counter of module \xmodule{base}.
% \begin{macrocode}
\zref@require@unique
% \end{macrocode}
% Configuration is done by the key value interface of package
% \xpackage{keyval}.
% \begin{macrocode}
\RequirePackage{keyval}
% \end{macrocode}
% The definitions of the keys follow.
% \begin{macrocode}
\define@key{ZREF@DF}{unit}{%
\def\ZREF@df@unit{#1}%
}
\define@key{ZREF@DF}{min}{%
\def\ZREF@df@min{#1}%
}
\define@key{ZREF@DF}{dot}{%
\def\ZREF@df@dot{#1}%
}
% \end{macrocode}
% Defaults are set, see user interface.
% \begin{macrocode}
\providecommand\ZREF@df@min{2}
\providecommand\ZREF@df@unit{.44em}
\providecommand\ZREF@df@dot{.}
% \end{macrocode}
% \begin{macro}{\zdotfillsetup}
% Configuration of \cs{zdotfill} is done by \cs{zdotfillsetup}.
% \begin{macrocode}
\newcommand*{\zdotfillsetup}{\setkeys{ZREF@DF}}
% \end{macrocode}
% \end{macro}
%
% \begin{macro}{\zdotfill}
% \cs{zdotfill} sets labels at the left and the right to get
% the horizontal position. \cs{zsavepos} is not used, because
% we do not need the vertical position.
% \begin{macrocode}
\newcommand*{\zdotfill}{%
\leavevmode
\global\advance\c@zref@unique\@ne
\begingroup
\def\ZREF@temp{zref@\number\c@zref@unique}%
\pdfsavepos
\zref@labelbyprops{\thezref@unique L}{posx}%
\setlength{\dimen@}{\ZREF@df@unit}%
\zref@ifrefundefined{\thezref@unique R}{%
\ZREF@dotfill
}{%
\ifnum\numexpr\zposx{\thezref@unique R}-\zposx{\thezref@unique L}\relax
<\dimexpr\ZREF@df@min\dimen@\relax
\hfill
\else
\ZREF@dotfill
\fi
}%
\pdfsavepos
\zref@labelbyprops{\thezref@unique R}{posx}%
\endgroup
\kern\z@
}
% \end{macrocode}
% \end{macro}
% \begin{macro}{\ZREF@dotfill}
% Help macro that actually sets the dots.
% \begin{macrocode}
\def\ZREF@dotfill{%
\cleaders\hb@xt@\dimen@{\hss\ZREF@df@dot\hss}\hfill
}
% \end{macrocode}
% \end{macro}
%
% \begin{macrocode}
%</dotfill>
% \end{macrocode}
%
% \section{Test}
%
% \subsection{\cs{zref@localaddprop}}
%
% \begin{macrocode}
%<*test1>
\NeedsTeXFormat{LaTeX2e}
\nofiles
\documentclass{article}
\usepackage{zref-base}[2010/03/26]
\usepackage{qstest}
\IncludeTests{*}
\LogTests{log}{*}{*}
\makeatletter
\begin{qstest}{localaddprop}{localaddprop}
\Expect*{\Z@L@main}*{{default}{page}}%
\zref@newprop{foobar}{FOO}%
\zref@newlist{alist}%
\Expect*{\Z@L@alist}{}%
\begingroup
\zref@localaddprop{main}{foobar}%
\Expect*{\Z@L@main}{{default}{page}{foobar}}%
\zref@localaddprop{alist}{page}%
\Expect*{\Z@L@alist}{{page}}%
\endgroup
\Expect*{\Z@L@main}*{{default}{page}}%
\Expect*{\Z@L@alist}{}%
\end{qstest}
\@@end
%</test1>
% \end{macrocode}
%
% \subsection{Module \xmodule{runs}}
%
% \begin{macrocode}
%<*test-runs>
\NeedsTeXFormat{LaTeX2e}
\documentclass{article}
\usepackage{zref-runs}[2010/03/26]
\usepackage{qstest}
\IncludeTests{*}
\LogTests{log}{*}{*}
\begin{qstest}{zruns-preamble}{zruns-preamble}
\Expect{0}*{\zruns}%
\end{qstest}
\AtBeginDocument{%
\begin{qstest}{zruns-atbegindocument}{zruns-atbegindocument}%
\Expect*{\number\ExpectRuns}*{\zruns}%
\end{qstest}%
}
\begin{document}
\begin{qstest}{zruns-document}{zruns-document}
\Expect*{\number\ExpectRuns}*{\zruns}%
\end{qstest}
\end{document}
%</test-runs>
% \end{macrocode}
%
% \section{Installation}
%
% \subsection{Download}
%
% \paragraph{Package.} This package is available on
% CTAN\footnote{\url{ftp://ftp.ctan.org/tex-archive/}}:
% \begin{description}
% \item[\CTAN{macros/latex/contrib/oberdiek/zref.dtx}] The source file.
% \item[\CTAN{macros/latex/contrib/oberdiek/zref.pdf}] Documentation.
% \end{description}
%
%
% \paragraph{Bundle.} All the packages of the bundle `oberdiek'
% are also available in a TDS compliant ZIP archive. There
% the packages are already unpacked and the documentation files
% are generated. The files and directories obey the TDS standard.
% \begin{description}
% \item[\CTAN{install/macros/latex/contrib/oberdiek.tds.zip}]
% \end{description}
% \emph{TDS} refers to the standard ``A Directory Structure
% for \TeX\ Files'' (\CTAN{tds/tds.pdf}). Directories
% with \xfile{texmf} in their name are usually organized this way.
%
% \subsection{Bundle installation}
%
% \paragraph{Unpacking.} Unpack the \xfile{oberdiek.tds.zip} in the
% TDS tree (also known as \xfile{texmf} tree) of your choice.
% Example (linux):
% \begin{quote}
% |unzip oberdiek.tds.zip -d ~/texmf|
% \end{quote}
%
% \paragraph{Script installation.}
% Check the directory \xfile{TDS:scripts/oberdiek/} for
% scripts that need further installation steps.
% Package \xpackage{attachfile2} comes with the Perl script
% \xfile{pdfatfi.pl} that should be installed in such a way
% that it can be called as \texttt{pdfatfi}.
% Example (linux):
% \begin{quote}
% |chmod +x scripts/oberdiek/pdfatfi.pl|\\
% |cp scripts/oberdiek/pdfatfi.pl /usr/local/bin/|
% \end{quote}
%
% \subsection{Package installation}
%
% \paragraph{Unpacking.} The \xfile{.dtx} file is a self-extracting
% \docstrip\ archive. The files are extracted by running the
% \xfile{.dtx} through \plainTeX:
% \begin{quote}
% \verb|tex zref.dtx|
% \end{quote}
%
% \paragraph{TDS.} Now the different files must be moved into
% the different directories in your installation TDS tree
% (also known as \xfile{texmf} tree):
% \begin{quote}
% \def\t{^^A
% \begin{tabular}{@{}>{\ttfamily}l@{ $\rightarrow$ }>{\ttfamily}l@{}}
% zref.sty & tex/latex/oberdiek/zref.sty\\
% zref-base.sty & tex/latex/oberdiek/zref-base.sty\\
% zref-abspage.sty & tex/latex/oberdiek/zref-abspage.sty\\
% zref-counter.sty & tex/latex/oberdiek/zref-counter.sty\\
% zref-dotfill.sty & tex/latex/oberdiek/zref-dotfill.sty\\
% zref-hyperref.sty & tex/latex/oberdiek/zref-hyperref.sty\\
% zref-lastpage.sty & tex/latex/oberdiek/zref-lastpage.sty\\
% zref-nextpage.sty & tex/latex/oberdiek/zref-nextpage.sty\\
% zref-perpage.sty & tex/latex/oberdiek/zref-perpage.sty\\
% zref-runs.sty & tex/latex/oberdiek/zref-runs.sty\\
% zref-savepos.sty & tex/latex/oberdiek/zref-savepos.sty\\
% zref-thepage.sty & tex/latex/oberdiek/zref-thepage.sty\\
% zref-titleref.sty & tex/latex/oberdiek/zref-titleref.sty\\
% zref-totpages.sty & tex/latex/oberdiek/zref-totpages.sty\\
% zref-user.sty & tex/latex/oberdiek/zref-user.sty\\
% zref-xr.sty & tex/latex/oberdiek/zref-xr.sty\\
% zref.pdf & doc/latex/oberdiek/zref.pdf\\
% zref-example.tex & doc/latex/oberdiek/zref-example.tex\\
% zref-example-lastpage.tex & doc/latex/oberdiek/zref-example-lastpage.tex\\
% zref-example-nextpage.tex & doc/latex/oberdiek/zref-example-nextpage.tex\\
% test/zref-test1.tex & doc/latex/oberdiek/test/zref-test1.tex\\
% test/zref-test-runs.tex & doc/latex/oberdiek/test/zref-test-runs.tex\\
% zref.dtx & source/latex/oberdiek/zref.dtx\\
% \end{tabular}^^A
% }^^A
% \sbox0{\t}^^A
% \ifdim\wd0>\linewidth
% \begingroup
% \advance\linewidth by\leftmargin
% \advance\linewidth by\rightmargin
% \edef\x{\endgroup
% \def\noexpand\lw{\the\linewidth}^^A
% }\x
% \def\lwbox{^^A
% \leavevmode
% \hbox to \linewidth{^^A
% \kern-\leftmargin\relax
% \hss
% \usebox0
% \hss
% \kern-\rightmargin\relax
% }^^A
% }^^A
% \ifdim\wd0>\lw
% \sbox0{\small\t}^^A
% \ifdim\wd0>\linewidth
% \ifdim\wd0>\lw
% \sbox0{\footnotesize\t}^^A
% \ifdim\wd0>\linewidth
% \ifdim\wd0>\lw
% \sbox0{\scriptsize\t}^^A
% \ifdim\wd0>\linewidth
% \ifdim\wd0>\lw
% \sbox0{\tiny\t}^^A
% \ifdim\wd0>\linewidth
% \lwbox
% \else
% \usebox0
% \fi
% \else
% \lwbox
% \fi
% \else
% \usebox0
% \fi
% \else
% \lwbox
% \fi
% \else
% \usebox0
% \fi
% \else
% \lwbox
% \fi
% \else
% \usebox0
% \fi
% \else
% \lwbox
% \fi
% \else
% \usebox0
% \fi
% \end{quote}
% If you have a \xfile{docstrip.cfg} that configures and enables \docstrip's
% TDS installing feature, then some files can already be in the right
% place, see the documentation of \docstrip.
%
% \subsection{Refresh file name databases}
%
% If your \TeX~distribution
% (\teTeX, \mikTeX, \dots) relies on file name databases, you must refresh
% these. For example, \teTeX\ users run \verb|texhash| or
% \verb|mktexlsr|.
%
% \subsection{Some details for the interested}
%
% \paragraph{Attached source.}
%
% The PDF documentation on CTAN also includes the
% \xfile{.dtx} source file. It can be extracted by
% AcrobatReader 6 or higher. Another option is \textsf{pdftk},
% e.g. unpack the file into the current directory:
% \begin{quote}
% \verb|pdftk zref.pdf unpack_files output .|
% \end{quote}
%
% \paragraph{Unpacking with \LaTeX.}
% The \xfile{.dtx} chooses its action depending on the format:
% \begin{description}
% \item[\plainTeX:] Run \docstrip\ and extract the files.
% \item[\LaTeX:] Generate the documentation.
% \end{description}
% If you insist on using \LaTeX\ for \docstrip\ (really,
% \docstrip\ does not need \LaTeX), then inform the autodetect routine
% about your intention:
% \begin{quote}
% \verb|latex \let\install=y\input{zref.dtx}|
% \end{quote}
% Do not forget to quote the argument according to the demands
% of your shell.
%
% \paragraph{Generating the documentation.}
% You can use both the \xfile{.dtx} or the \xfile{.drv} to generate
% the documentation. The process can be configured by the
% configuration file \xfile{ltxdoc.cfg}. For instance, put this
% line into this file, if you want to have A4 as paper format:
% \begin{quote}
% \verb|\PassOptionsToClass{a4paper}{article}|
% \end{quote}
% An example follows how to generate the
% documentation with pdf\LaTeX:
% \begin{quote}
%\begin{verbatim}
%pdflatex zref.dtx
%makeindex -s gind.ist zref.idx
%pdflatex zref.dtx
%makeindex -s gind.ist zref.idx
%pdflatex zref.dtx
%\end{verbatim}
% \end{quote}
%
% \newcommand*{\bibpackage}[4]{^^A
% \bibitem{#1}
% Package \xpackage{#1}, #2, #3.^^A
% \ifx\\#4\\\else#4\fi\par
% }
%
% \begin{thebibliography}{99}
% \bibpackage{footmisc}{Robin Fairbairns}{2004/01/23 v5.3a}
% {\CTAN{macros/latex/contrib/footmisc/footmisc.dtx}}
% \bibpackage{hyperref}{Sebastian Rahtz, Heiko Oberdiek}{2006/08/16 v6.75c}
% {\CTAN{macros/latex/contrib/hyperref/}}
% \bibpackage{lastpage}{Jeff Goldberg}{1994/06/25 v0.1b}
% {\CTAN{macros/latex/contrib/lastpage/}}
% \bibpackage{nameref}{Sebastian Rahtz, Heiko Oberdiek}{2006/02/12 v2.24}
% {\CTAN{macros/latex/contrib/hyperref/nameref.dtx}}
% \bibpackage{perpage}{David Kastrup}{2002/12/20 v1.0}
% {\CTAN{macros/latex/contrib/bigfoot/perpage.dtx}}
% \bibpackage{titleref}{Donald Arsenau}{2001/04/05 v3.1}
% {\CTAN{macros/latex/contrib/misc/titleref.sty}}
% \bibpackage{totpages}{Wilhelm M\"uller}{1999/07/14 v1.00}
% {\CTAN{macros/latex/contrib/totpages/}}
% \bibpackage{xr}{David Carlisle}{1994/05/28 v5.02}
% {\CTAN{macros/latex/required/tools/xr.pdf}}
% \bibpackage{xr-hyper}{David Carlisle}{2000/03/22 v6.00beta4}
% {\CTAN{macros/latex/contrib/hyperref/xr-hyper.sty}}
% \end{thebibliography}
%
% \begin{History}
% \begin{Version}{2006/02/20 v1.0}
% \item
% First version.
% \end{Version}
% \begin{Version}{2006/05/03 v1.1}
% \item
% Module \xmodule{perpage} added.
% \item
% Module redesign as packages.
% \end{Version}
% \begin{Version}{2006/05/25 v1.2}
% \item
% Module \xmodule{dotfillmin} added.
% \item
% Module \xmodule{base}: macros \cs{zref@require@uniqe}
% and \cs{thezref@unique} added
% (used by modules \xmodule{titleref} and \xmodule{dotfillmin}).
% \end{Version}
% \begin{Version}{2006/09/08 v1.3}
% \item
% Typo fixes and English cleanup by Per Starback.
% \end{Version}
% \begin{Version}{2007/01/23 v1.4}
% \item
% Typo in macro name fixed in documentation.
% \end{Version}
% \begin{Version}{2007/02/18 v1.5}
% \item
% \cs{zref@getcurrent} added (suggestion of Igor Akkerman).
% \item
% Module \xmodule{savepos} also supports Xe\TeX.
% \end{Version}
% \begin{Version}{2007/04/06 v1.6}
% \item
% Fix in modules \xmodule{abspage} and \xmodule{base}:
% Now counter |abspage| and |zref@unique|
% are not remembered by \cs{include}.
% \item
% Beamer support for module \xmodule{titleref}.
% \end{Version}
% \begin{Version}{2007/04/17 v1.7}
% \item
% Package \xpackage{atbegshi} replaces \xpackage{everyshi}.
% \end{Version}
% \begin{Version}{2007/04/22 v1.8}
% \item
% \cs{zref@wrapper@babel} and \cs{zref@refused} are now expandable
% if babel is not used or \cs{if@safe@actives} is already set to true.
% (Feature request of Josselin Noirel)
% \end{Version}
% \begin{Version}{2007/05/02 v1.9}
% \item
% Module \xmodule{titleref}: Some support for \cs{caption} of package
% \xpackage{longtable}, but only if \cs{label} is given after
% \cs{caption}.
% \end{Version}
% \begin{Version}{2007/05/06 v2.0}
% \item
% Uses package \xpackage{etexcmds} for accessing \eTeX's \cs{unexpanded}.
% \end{Version}
% \begin{Version}{2007/05/28 v2.1}
% \item
% Module \xmodule{titleref} supports caption of package \xpackage{listings}.
% \item
% Fixes in module \xmodule{titleref} for support
% of packages \xpackage{titlesec} and \xpackage{longtable}.
% \end{Version}
% \begin{Version}{2008/09/21 v2.2}
% \item
% Module \xmodule{base}: \cs{zref@iflistcontainsprop} is documented, but
% a broken \cs{zref@listcontainsprop} implemented. Name and
% implementation fixed (thanks Ohad Kammar).
% \end{Version}
% \begin{Version}{2008/10/01 v2.3}
% \item
% \cs{zref@localaddprop} added (feature request of Ohad Kammar).
% \item
% Module \xmodule{lastpage}: list `LastPage' added. Label `LastPage' will use
% the properties of this list (default is empty) along with the
% properties of the main list.
% \end{Version}
% \begin{Version}{2009/08/07 v2.4}
% \item
% Module \xmodule{runs} added.
% \end{Version}
% \begin{Version}{2009/12/06 v2.5}
% \item
% Module \xmodule{lastpage}: Uses package \xpackage{atveryend}.
% \item
% Module \xmodule{titleref}: Further commands are disabled
% during string expansion, imported from package \xpackage{nameref}.
% \end{Version}
% \begin{Version}{2009/12/07 v2.6}
% \item
% Version date added for package \xpackage{atveryend}.
% \end{Version}
% \begin{Version}{2009/12/08 v2.7}
% \item
% Module \xmodule{titleref}: Use of package \xpackage{gettitlestring}.
% \end{Version}
% \begin{Version}{2010/03/26 v2.8}
% \item
% \cs{zifrefundefined} added.
% \item
% Module \xmodule{lastpage}: Macros \cs{zref@iflastpage}
% and \cs{ziflastpage} added.
% \item
% Module \xmodule{thepage} added.
% \item
% Module \xmodule{nextpage} added.
% \end{Version}
% \end{History}
%
% \PrintIndex
%
% \Finale
\endinput
|