summaryrefslogtreecommitdiff
path: root/macros/latex/contrib/etoc/etoc.dtx
blob: 1745aef81832ae9bea4c00dde79098c62610c4fc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065
4066
4067
4068
4069
4070
4071
4072
4073
4074
4075
4076
4077
4078
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
4123
4124
4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147
4148
4149
4150
4151
4152
4153
4154
4155
4156
4157
4158
4159
4160
4161
4162
4163
4164
4165
4166
4167
4168
4169
4170
4171
4172
4173
4174
4175
4176
4177
4178
4179
4180
4181
4182
4183
4184
4185
4186
4187
4188
4189
4190
4191
4192
4193
4194
4195
4196
4197
4198
4199
4200
4201
4202
4203
4204
4205
4206
4207
4208
4209
4210
4211
4212
4213
4214
4215
4216
4217
4218
4219
4220
4221
4222
4223
4224
4225
4226
4227
4228
4229
4230
4231
4232
4233
4234
4235
4236
4237
4238
4239
4240
4241
4242
4243
4244
4245
4246
4247
4248
4249
4250
4251
4252
4253
4254
4255
4256
4257
4258
4259
4260
4261
4262
4263
4264
4265
4266
4267
4268
4269
4270
4271
4272
4273
4274
4275
4276
4277
4278
4279
4280
4281
4282
4283
4284
4285
4286
4287
4288
4289
4290
4291
4292
4293
4294
4295
4296
4297
4298
4299
4300
4301
4302
4303
4304
4305
4306
4307
4308
4309
4310
4311
4312
4313
4314
4315
4316
4317
4318
4319
4320
4321
4322
4323
4324
4325
4326
4327
4328
4329
4330
4331
4332
4333
4334
4335
4336
4337
4338
4339
4340
4341
4342
4343
4344
4345
4346
4347
4348
4349
4350
4351
4352
4353
4354
4355
4356
4357
4358
4359
4360
4361
4362
4363
4364
4365
4366
4367
4368
4369
4370
4371
4372
4373
4374
4375
4376
4377
4378
4379
4380
4381
4382
4383
4384
4385
4386
4387
4388
4389
4390
4391
4392
4393
4394
4395
4396
4397
4398
4399
4400
4401
4402
4403
4404
4405
4406
4407
4408
4409
4410
4411
4412
4413
4414
4415
4416
4417
4418
4419
4420
4421
4422
4423
4424
4425
4426
4427
4428
4429
4430
4431
4432
4433
4434
4435
4436
4437
4438
4439
4440
4441
4442
4443
4444
4445
4446
4447
4448
4449
4450
4451
4452
4453
4454
4455
4456
4457
4458
4459
4460
4461
4462
4463
4464
4465
4466
4467
4468
4469
4470
4471
4472
4473
4474
4475
4476
4477
4478
4479
4480
4481
4482
4483
4484
4485
4486
4487
4488
4489
4490
4491
4492
4493
4494
4495
4496
4497
4498
4499
4500
4501
4502
4503
4504
4505
4506
4507
4508
4509
4510
4511
4512
4513
4514
4515
4516
4517
4518
4519
4520
4521
4522
4523
4524
4525
4526
4527
4528
4529
4530
4531
4532
4533
4534
4535
4536
4537
4538
4539
4540
4541
4542
4543
4544
4545
4546
4547
4548
4549
4550
4551
4552
4553
4554
4555
4556
4557
4558
4559
4560
4561
4562
4563
4564
4565
4566
4567
4568
4569
4570
4571
4572
4573
4574
4575
4576
4577
4578
4579
4580
4581
4582
4583
4584
4585
4586
4587
4588
4589
4590
4591
4592
4593
4594
4595
4596
4597
4598
4599
4600
4601
4602
4603
4604
4605
4606
4607
4608
4609
4610
4611
4612
4613
4614
4615
4616
4617
4618
4619
4620
4621
4622
4623
4624
4625
4626
4627
4628
4629
4630
4631
4632
4633
4634
4635
4636
4637
4638
4639
4640
4641
4642
4643
4644
4645
4646
4647
4648
4649
4650
4651
4652
4653
4654
4655
4656
4657
4658
4659
4660
4661
4662
4663
4664
4665
4666
4667
4668
4669
4670
4671
4672
4673
4674
4675
4676
4677
4678
4679
4680
4681
4682
4683
4684
4685
4686
4687
4688
4689
4690
4691
4692
4693
4694
4695
4696
4697
4698
4699
4700
4701
4702
4703
4704
4705
4706
4707
4708
4709
4710
4711
4712
4713
4714
4715
4716
4717
4718
4719
4720
4721
4722
4723
4724
4725
4726
4727
4728
4729
4730
4731
4732
4733
4734
4735
4736
4737
4738
4739
4740
4741
4742
4743
4744
4745
4746
4747
4748
4749
4750
4751
4752
4753
4754
4755
4756
4757
4758
4759
4760
4761
4762
4763
4764
4765
4766
4767
4768
4769
4770
4771
4772
4773
4774
4775
4776
4777
4778
4779
4780
4781
4782
4783
4784
4785
4786
4787
4788
4789
4790
4791
4792
4793
4794
4795
4796
4797
4798
4799
4800
4801
4802
4803
4804
4805
4806
4807
4808
4809
4810
4811
4812
4813
4814
4815
4816
4817
4818
4819
4820
4821
4822
4823
4824
4825
4826
4827
4828
4829
4830
4831
4832
4833
4834
4835
4836
4837
4838
4839
4840
4841
4842
4843
4844
4845
4846
4847
4848
4849
4850
4851
4852
4853
4854
4855
4856
4857
4858
4859
4860
4861
4862
4863
4864
4865
4866
4867
4868
4869
4870
4871
4872
4873
4874
4875
4876
4877
4878
4879
4880
4881
4882
4883
4884
4885
4886
4887
4888
4889
4890
4891
4892
4893
4894
4895
4896
4897
4898
4899
4900
4901
4902
4903
4904
4905
4906
4907
4908
4909
4910
4911
4912
4913
4914
4915
4916
4917
4918
4919
4920
4921
4922
4923
4924
4925
4926
4927
4928
4929
4930
4931
4932
4933
4934
4935
4936
4937
4938
4939
4940
4941
4942
4943
4944
4945
4946
4947
4948
4949
4950
4951
4952
4953
4954
4955
4956
4957
4958
4959
4960
4961
4962
4963
4964
4965
4966
4967
4968
4969
4970
4971
4972
4973
4974
4975
4976
4977
4978
4979
4980
4981
4982
4983
4984
4985
4986
4987
4988
4989
4990
4991
4992
4993
4994
4995
4996
4997
4998
4999
5000
5001
5002
5003
5004
5005
5006
5007
5008
5009
5010
5011
5012
5013
5014
5015
5016
5017
5018
5019
5020
5021
5022
5023
5024
5025
5026
5027
5028
5029
5030
5031
5032
5033
5034
5035
5036
5037
5038
5039
5040
5041
5042
5043
5044
5045
5046
5047
5048
5049
5050
5051
5052
5053
5054
5055
5056
5057
5058
5059
5060
5061
5062
5063
5064
5065
5066
5067
5068
5069
5070
5071
5072
5073
5074
5075
5076
5077
5078
5079
5080
5081
5082
5083
5084
5085
5086
5087
5088
5089
5090
5091
5092
5093
5094
5095
5096
5097
5098
5099
5100
5101
5102
5103
5104
5105
5106
5107
5108
5109
5110
5111
5112
5113
5114
5115
5116
5117
5118
5119
5120
5121
5122
5123
5124
5125
5126
5127
5128
5129
5130
5131
5132
5133
5134
5135
5136
5137
5138
5139
5140
5141
5142
5143
5144
5145
5146
5147
5148
5149
5150
5151
5152
5153
5154
5155
5156
5157
5158
5159
5160
5161
5162
5163
5164
5165
5166
5167
5168
5169
5170
5171
5172
5173
5174
5175
5176
5177
5178
5179
5180
5181
5182
5183
5184
5185
5186
5187
5188
5189
5190
5191
5192
5193
5194
5195
5196
5197
5198
5199
5200
5201
5202
5203
5204
5205
5206
5207
5208
5209
5210
5211
5212
5213
5214
5215
5216
5217
5218
5219
5220
5221
5222
5223
5224
5225
5226
5227
5228
5229
5230
5231
5232
5233
5234
5235
5236
5237
5238
5239
5240
5241
5242
5243
5244
5245
5246
5247
5248
5249
5250
5251
5252
5253
5254
5255
5256
5257
5258
5259
5260
5261
5262
5263
5264
5265
5266
5267
5268
5269
5270
5271
5272
5273
5274
5275
5276
5277
5278
5279
5280
5281
5282
5283
5284
5285
5286
5287
5288
5289
5290
5291
5292
5293
5294
5295
5296
5297
5298
5299
5300
5301
5302
5303
5304
5305
5306
5307
5308
5309
5310
5311
5312
5313
5314
5315
5316
5317
5318
5319
5320
5321
5322
5323
5324
5325
5326
5327
5328
5329
5330
5331
5332
5333
5334
5335
5336
5337
5338
5339
5340
5341
5342
5343
5344
5345
5346
5347
5348
5349
5350
5351
5352
5353
5354
5355
5356
5357
5358
5359
5360
5361
5362
5363
5364
5365
5366
5367
5368
5369
5370
5371
5372
5373
5374
5375
5376
5377
5378
5379
5380
5381
5382
5383
5384
5385
5386
5387
5388
5389
5390
5391
5392
5393
5394
5395
5396
5397
5398
5399
5400
5401
5402
5403
5404
5405
5406
5407
5408
5409
5410
5411
5412
5413
5414
5415
5416
5417
5418
5419
5420
5421
5422
5423
5424
5425
5426
5427
5428
5429
5430
5431
5432
5433
5434
5435
5436
5437
5438
5439
5440
5441
5442
5443
5444
5445
5446
5447
5448
5449
5450
5451
5452
5453
5454
5455
5456
5457
5458
5459
5460
5461
5462
5463
5464
5465
5466
5467
5468
5469
5470
5471
5472
5473
5474
5475
5476
5477
5478
5479
5480
5481
5482
5483
5484
5485
5486
5487
5488
5489
5490
5491
5492
5493
5494
5495
5496
5497
5498
5499
5500
5501
5502
5503
5504
5505
5506
5507
5508
5509
5510
5511
5512
5513
5514
5515
5516
5517
5518
5519
5520
5521
5522
5523
5524
5525
5526
5527
5528
5529
5530
5531
5532
5533
5534
5535
5536
5537
5538
5539
5540
5541
5542
5543
5544
5545
5546
5547
5548
5549
5550
5551
5552
5553
5554
5555
5556
5557
5558
5559
5560
5561
5562
5563
5564
5565
5566
5567
5568
5569
5570
5571
5572
5573
5574
5575
5576
5577
5578
5579
5580
5581
5582
5583
5584
5585
5586
5587
5588
5589
5590
5591
5592
5593
5594
5595
5596
5597
5598
5599
5600
5601
5602
5603
5604
5605
5606
5607
5608
5609
5610
5611
5612
5613
5614
5615
5616
5617
5618
5619
5620
5621
5622
5623
5624
5625
5626
5627
5628
5629
5630
5631
5632
5633
5634
5635
5636
5637
5638
5639
5640
5641
5642
5643
5644
5645
5646
5647
5648
5649
5650
5651
5652
5653
5654
5655
5656
5657
5658
5659
5660
5661
5662
5663
5664
5665
5666
5667
5668
5669
5670
5671
5672
5673
5674
5675
5676
5677
5678
5679
5680
5681
5682
5683
5684
5685
5686
5687
5688
5689
5690
5691
5692
5693
5694
5695
5696
5697
5698
5699
5700
5701
5702
5703
5704
5705
5706
5707
5708
5709
5710
5711
5712
5713
5714
5715
5716
5717
5718
5719
5720
5721
5722
5723
5724
5725
5726
5727
5728
5729
5730
5731
5732
5733
5734
5735
5736
5737
5738
5739
5740
5741
5742
5743
5744
5745
5746
5747
5748
5749
5750
5751
5752
5753
5754
5755
5756
5757
5758
5759
5760
5761
5762
5763
5764
5765
5766
5767
5768
5769
5770
5771
5772
5773
5774
5775
5776
5777
5778
5779
5780
5781
5782
5783
5784
5785
5786
5787
5788
5789
5790
5791
5792
5793
5794
5795
5796
5797
5798
5799
5800
5801
5802
5803
5804
5805
5806
5807
5808
5809
5810
5811
5812
5813
5814
5815
5816
5817
5818
5819
5820
5821
5822
5823
5824
5825
5826
5827
5828
5829
5830
5831
5832
5833
5834
5835
5836
5837
5838
5839
5840
5841
5842
5843
5844
5845
5846
5847
5848
5849
5850
5851
5852
5853
5854
5855
5856
5857
5858
5859
5860
5861
5862
5863
5864
5865
5866
5867
5868
5869
5870
5871
5872
5873
5874
5875
5876
5877
5878
5879
5880
5881
5882
5883
5884
5885
5886
5887
5888
5889
5890
5891
5892
5893
5894
5895
5896
5897
5898
5899
5900
5901
5902
5903
5904
5905
5906
5907
5908
5909
5910
5911
5912
5913
5914
5915
5916
5917
5918
5919
5920
5921
5922
5923
5924
5925
5926
5927
5928
5929
5930
5931
5932
5933
5934
5935
5936
5937
5938
5939
5940
5941
5942
5943
5944
5945
5946
5947
5948
5949
5950
5951
5952
5953
5954
5955
5956
5957
5958
5959
5960
5961
5962
5963
5964
5965
5966
5967
5968
5969
5970
5971
5972
5973
5974
5975
5976
5977
5978
5979
5980
5981
5982
5983
5984
5985
5986
5987
5988
5989
5990
5991
5992
5993
5994
5995
5996
5997
5998
5999
6000
6001
6002
6003
6004
6005
6006
6007
6008
6009
6010
6011
6012
6013
6014
6015
6016
6017
6018
6019
6020
6021
6022
6023
6024
6025
6026
6027
6028
6029
6030
6031
6032
6033
6034
6035
6036
6037
6038
6039
6040
6041
6042
6043
6044
6045
6046
6047
6048
6049
6050
6051
6052
6053
6054
6055
6056
6057
6058
6059
6060
6061
6062
6063
6064
6065
6066
6067
6068
6069
6070
6071
6072
6073
6074
6075
6076
6077
6078
6079
6080
6081
6082
6083
6084
6085
6086
6087
6088
6089
6090
6091
6092
6093
6094
6095
6096
6097
6098
6099
6100
6101
6102
6103
6104
6105
6106
6107
6108
6109
6110
6111
6112
6113
6114
6115
6116
6117
6118
6119
6120
6121
6122
6123
6124
6125
6126
6127
6128
6129
6130
6131
6132
6133
6134
6135
6136
6137
6138
6139
6140
6141
6142
6143
6144
6145
6146
6147
6148
6149
6150
6151
6152
6153
6154
6155
6156
6157
6158
6159
6160
6161
6162
6163
6164
6165
6166
6167
6168
6169
6170
6171
6172
6173
6174
6175
6176
6177
6178
6179
6180
6181
6182
6183
6184
6185
6186
6187
6188
6189
6190
6191
6192
6193
6194
6195
6196
6197
6198
6199
6200
6201
6202
6203
6204
6205
6206
6207
6208
6209
6210
6211
6212
6213
6214
6215
6216
6217
6218
6219
6220
6221
6222
6223
6224
6225
6226
6227
6228
6229
6230
6231
6232
6233
6234
6235
6236
6237
6238
6239
6240
6241
6242
6243
6244
6245
6246
6247
6248
6249
6250
6251
6252
6253
6254
6255
6256
6257
6258
6259
6260
6261
6262
6263
6264
6265
6266
6267
6268
6269
6270
6271
6272
6273
6274
6275
6276
6277
6278
6279
6280
6281
6282
6283
6284
6285
6286
6287
6288
6289
6290
6291
6292
6293
6294
6295
6296
6297
6298
6299
6300
6301
6302
6303
6304
6305
6306
6307
6308
6309
6310
6311
6312
6313
6314
6315
6316
6317
6318
6319
6320
6321
6322
6323
6324
6325
6326
6327
6328
6329
6330
6331
6332
6333
6334
6335
6336
6337
6338
6339
6340
6341
6342
6343
6344
6345
6346
6347
6348
6349
6350
6351
6352
6353
6354
6355
6356
6357
6358
6359
6360
6361
6362
6363
6364
6365
6366
6367
6368
6369
6370
6371
6372
6373
6374
6375
6376
6377
6378
6379
6380
6381
6382
6383
6384
6385
6386
6387
6388
6389
6390
6391
6392
6393
6394
6395
6396
6397
6398
6399
6400
6401
6402
6403
6404
6405
6406
6407
6408
6409
6410
6411
6412
6413
6414
6415
6416
6417
6418
6419
6420
6421
6422
6423
6424
6425
6426
6427
6428
6429
6430
6431
6432
6433
6434
6435
6436
6437
6438
6439
6440
6441
6442
6443
6444
6445
6446
6447
6448
6449
6450
6451
6452
6453
6454
6455
6456
6457
6458
6459
6460
6461
6462
6463
6464
6465
6466
6467
6468
6469
6470
6471
6472
6473
6474
6475
6476
6477
6478
6479
6480
6481
6482
6483
6484
6485
6486
6487
6488
6489
6490
6491
6492
6493
6494
6495
6496
6497
6498
6499
6500
6501
6502
6503
6504
6505
6506
6507
6508
6509
6510
6511
6512
6513
6514
6515
6516
6517
6518
6519
6520
6521
6522
6523
6524
6525
6526
6527
6528
6529
6530
6531
6532
6533
6534
6535
6536
6537
6538
6539
6540
6541
6542
6543
6544
6545
6546
6547
6548
6549
6550
6551
6552
6553
6554
6555
6556
6557
6558
6559
6560
6561
6562
6563
6564
6565
6566
6567
6568
6569
6570
6571
6572
6573
6574
6575
6576
6577
6578
6579
6580
6581
6582
6583
6584
6585
6586
6587
6588
6589
6590
6591
6592
6593
6594
6595
6596
6597
6598
6599
6600
6601
6602
6603
6604
6605
6606
6607
6608
6609
6610
6611
6612
6613
6614
6615
6616
6617
6618
6619
6620
6621
6622
6623
6624
6625
6626
6627
6628
6629
6630
6631
6632
6633
6634
6635
6636
6637
6638
6639
6640
6641
6642
6643
6644
6645
6646
6647
6648
6649
6650
6651
6652
6653
6654
6655
6656
6657
6658
6659
6660
6661
6662
6663
6664
6665
6666
6667
6668
6669
6670
6671
6672
6673
6674
6675
6676
6677
6678
6679
6680
6681
6682
6683
6684
6685
6686
6687
6688
6689
6690
6691
6692
6693
6694
6695
6696
6697
6698
6699
6700
6701
6702
6703
6704
6705
6706
6707
6708
6709
6710
6711
6712
6713
6714
6715
6716
6717
6718
6719
6720
6721
6722
6723
6724
6725
6726
6727
6728
6729
6730
6731
6732
6733
6734
6735
6736
6737
6738
6739
6740
6741
6742
6743
6744
6745
6746
6747
6748
6749
6750
6751
6752
6753
6754
6755
6756
6757
6758
6759
6760
6761
6762
6763
6764
6765
6766
6767
6768
6769
6770
6771
6772
6773
6774
6775
6776
6777
6778
6779
6780
6781
6782
6783
6784
6785
6786
6787
6788
6789
6790
6791
6792
6793
6794
6795
6796
6797
6798
6799
6800
6801
6802
6803
6804
6805
6806
6807
6808
6809
6810
6811
6812
6813
6814
6815
6816
6817
6818
6819
6820
6821
6822
6823
6824
6825
6826
6827
6828
6829
6830
6831
6832
6833
6834
6835
6836
6837
6838
6839
6840
6841
6842
6843
6844
6845
6846
6847
6848
6849
6850
6851
6852
6853
6854
6855
6856
6857
6858
6859
6860
6861
6862
6863
6864
6865
6866
6867
6868
6869
6870
6871
6872
6873
6874
6875
6876
6877
6878
6879
6880
6881
6882
6883
6884
6885
6886
6887
6888
6889
6890
6891
6892
6893
6894
6895
6896
6897
6898
6899
6900
6901
6902
6903
6904
6905
6906
6907
6908
6909
6910
6911
6912
6913
6914
6915
6916
6917
6918
6919
6920
6921
6922
6923
6924
6925
6926
6927
6928
6929
6930
6931
6932
6933
6934
6935
6936
6937
6938
6939
6940
6941
6942
6943
6944
6945
6946
6947
6948
6949
6950
6951
6952
6953
6954
6955
6956
6957
6958
6959
6960
6961
6962
6963
6964
6965
6966
6967
6968
6969
6970
6971
6972
6973
6974
6975
6976
6977
6978
6979
6980
6981
6982
6983
6984
6985
6986
6987
6988
6989
6990
6991
6992
6993
6994
6995
6996
6997
6998
6999
7000
7001
7002
7003
7004
7005
7006
7007
7008
7009
7010
7011
7012
7013
7014
7015
7016
7017
7018
7019
7020
7021
7022
7023
7024
7025
7026
7027
7028
7029
7030
7031
7032
7033
7034
7035
7036
7037
7038
7039
7040
7041
7042
7043
7044
7045
7046
7047
7048
7049
7050
7051
7052
7053
7054
7055
7056
7057
7058
7059
7060
7061
7062
7063
7064
7065
7066
7067
7068
7069
7070
7071
7072
7073
7074
7075
7076
7077
7078
7079
7080
7081
7082
7083
7084
7085
7086
7087
7088
7089
7090
7091
7092
7093
7094
7095
7096
7097
7098
7099
7100
7101
7102
7103
7104
7105
7106
7107
7108
7109
7110
7111
7112
7113
7114
7115
7116
7117
7118
7119
7120
7121
7122
7123
7124
7125
7126
7127
7128
7129
7130
7131
7132
7133
7134
7135
7136
7137
7138
7139
7140
7141
7142
7143
7144
7145
7146
7147
7148
7149
7150
7151
7152
7153
7154
7155
7156
7157
7158
7159
7160
7161
7162
7163
7164
7165
7166
7167
7168
7169
7170
7171
7172
7173
7174
7175
7176
7177
7178
7179
7180
7181
7182
7183
7184
7185
7186
7187
7188
7189
7190
7191
7192
7193
7194
7195
7196
7197
7198
7199
7200
7201
7202
7203
7204
7205
7206
7207
7208
7209
7210
7211
7212
7213
7214
7215
7216
7217
7218
7219
7220
7221
7222
7223
7224
7225
7226
7227
7228
7229
7230
7231
7232
7233
7234
7235
7236
7237
7238
7239
7240
7241
7242
7243
7244
7245
7246
7247
7248
7249
7250
7251
7252
7253
7254
7255
7256
7257
7258
7259
7260
7261
7262
7263
7264
7265
7266
7267
7268
7269
7270
7271
7272
7273
7274
7275
7276
7277
7278
7279
7280
7281
7282
7283
7284
7285
7286
7287
7288
7289
7290
7291
7292
7293
7294
7295
7296
7297
7298
7299
7300
7301
7302
7303
7304
7305
7306
7307
7308
7309
7310
7311
7312
7313
7314
7315
7316
7317
7318
7319
7320
7321
7322
7323
7324
7325
7326
7327
7328
7329
7330
7331
7332
7333
7334
7335
7336
7337
7338
7339
7340
7341
7342
7343
7344
7345
7346
7347
7348
7349
7350
7351
7352
7353
7354
7355
7356
7357
7358
7359
7360
7361
7362
7363
7364
7365
7366
7367
7368
7369
7370
7371
7372
7373
7374
7375
7376
7377
7378
7379
7380
7381
7382
7383
7384
7385
7386
7387
7388
7389
7390
7391
7392
7393
7394
7395
7396
7397
7398
7399
7400
7401
7402
7403
7404
7405
7406
7407
7408
7409
7410
7411
7412
7413
7414
7415
7416
7417
7418
7419
7420
7421
7422
7423
7424
7425
7426
7427
7428
7429
7430
7431
7432
7433
7434
7435
7436
7437
7438
7439
7440
7441
7442
7443
7444
7445
7446
7447
7448
7449
7450
7451
7452
7453
7454
7455
7456
7457
7458
7459
7460
7461
7462
7463
7464
7465
7466
7467
7468
7469
7470
7471
7472
7473
7474
7475
7476
7477
7478
7479
7480
7481
7482
7483
7484
7485
7486
7487
7488
7489
7490
7491
7492
7493
7494
7495
7496
7497
7498
7499
7500
7501
7502
7503
7504
7505
7506
7507
7508
7509
7510
7511
7512
7513
7514
7515
7516
7517
7518
7519
7520
7521
7522
7523
7524
7525
7526
7527
7528
7529
7530
7531
7532
7533
7534
7535
7536
7537
7538
7539
7540
7541
7542
7543
7544
7545
7546
7547
7548
7549
7550
7551
7552
7553
7554
7555
7556
7557
7558
7559
7560
7561
7562
7563
7564
7565
7566
7567
7568
7569
7570
7571
7572
7573
7574
7575
7576
7577
7578
7579
7580
7581
7582
7583
7584
7585
7586
7587
7588
7589
7590
7591
7592
7593
7594
7595
7596
7597
7598
7599
7600
7601
7602
7603
7604
7605
7606
7607
7608
7609
7610
7611
7612
7613
7614
7615
7616
7617
7618
7619
7620
7621
7622
7623
7624
7625
7626
7627
7628
7629
7630
7631
7632
7633
7634
7635
7636
7637
7638
7639
7640
7641
7642
7643
7644
7645
7646
7647
7648
7649
7650
7651
7652
7653
7654
7655
7656
7657
7658
7659
7660
7661
7662
7663
7664
7665
7666
7667
7668
7669
7670
7671
7672
7673
7674
7675
7676
7677
7678
7679
7680
7681
7682
7683
7684
7685
7686
7687
7688
7689
7690
7691
7692
7693
7694
7695
7696
7697
7698
7699
7700
7701
7702
7703
7704
7705
7706
7707
7708
7709
7710
7711
7712
7713
7714
7715
7716
7717
7718
7719
7720
7721
7722
7723
7724
7725
7726
7727
7728
7729
7730
7731
7732
7733
7734
7735
7736
7737
7738
7739
7740
7741
7742
7743
7744
7745
7746
7747
7748
7749
7750
7751
7752
7753
7754
7755
7756
7757
7758
7759
7760
7761
7762
7763
7764
7765
7766
7767
7768
7769
7770
7771
7772
7773
7774
7775
7776
7777
7778
7779
7780
7781
7782
7783
7784
7785
7786
7787
7788
7789
7790
7791
7792
7793
7794
7795
7796
7797
7798
7799
7800
7801
7802
7803
7804
7805
7806
7807
7808
7809
7810
7811
7812
7813
7814
7815
7816
7817
7818
7819
7820
7821
7822
7823
7824
7825
7826
7827
7828
7829
7830
7831
7832
7833
7834
7835
7836
7837
7838
7839
7840
7841
7842
7843
7844
7845
7846
7847
7848
7849
7850
7851
7852
7853
7854
7855
7856
7857
7858
7859
7860
7861
7862
7863
7864
7865
7866
7867
7868
7869
7870
7871
7872
7873
7874
7875
7876
7877
7878
7879
7880
7881
7882
7883
7884
7885
7886
7887
7888
7889
7890
7891
7892
7893
7894
7895
7896
7897
7898
7899
7900
7901
7902
7903
7904
7905
7906
7907
7908
7909
7910
7911
7912
7913
7914
7915
7916
7917
7918
7919
7920
7921
7922
7923
7924
7925
7926
7927
7928
7929
7930
7931
7932
7933
7934
7935
7936
7937
7938
7939
7940
7941
7942
7943
7944
7945
7946
7947
7948
7949
7950
7951
7952
7953
7954
7955
7956
7957
7958
7959
7960
7961
7962
7963
7964
7965
7966
7967
7968
7969
7970
7971
7972
7973
7974
7975
7976
7977
7978
7979
7980
7981
7982
7983
7984
7985
7986
7987
7988
7989
7990
7991
7992
7993
7994
7995
7996
7997
7998
7999
8000
8001
8002
8003
8004
8005
8006
8007
8008
8009
8010
8011
8012
8013
8014
8015
8016
8017
8018
8019
8020
8021
8022
8023
8024
8025
8026
8027
8028
8029
8030
8031
8032
8033
8034
8035
8036
8037
8038
8039
8040
8041
8042
8043
8044
8045
8046
8047
8048
8049
8050
8051
8052
8053
8054
8055
8056
8057
8058
8059
8060
8061
8062
8063
8064
8065
8066
8067
8068
8069
8070
8071
8072
8073
8074
8075
8076
8077
8078
8079
8080
8081
8082
8083
8084
8085
8086
8087
8088
8089
8090
8091
8092
8093
8094
8095
8096
8097
8098
8099
8100
8101
8102
8103
8104
8105
8106
8107
8108
8109
8110
8111
8112
8113
8114
8115
8116
8117
8118
8119
8120
8121
8122
8123
8124
8125
8126
8127
8128
8129
8130
8131
8132
8133
8134
8135
8136
8137
8138
8139
8140
8141
8142
8143
8144
8145
8146
8147
8148
8149
8150
8151
8152
8153
8154
8155
8156
8157
8158
8159
8160
8161
8162
8163
8164
8165
8166
8167
8168
8169
8170
8171
8172
8173
8174
8175
8176
8177
8178
8179
8180
8181
8182
8183
8184
8185
8186
8187
8188
8189
8190
8191
8192
8193
8194
8195
8196
8197
8198
8199
8200
8201
8202
8203
8204
8205
8206
8207
8208
8209
8210
8211
8212
8213
8214
8215
8216
8217
8218
8219
8220
8221
8222
8223
8224
8225
8226
8227
8228
8229
8230
8231
8232
8233
8234
8235
8236
8237
8238
8239
8240
8241
8242
8243
8244
8245
8246
8247
8248
8249
8250
8251
8252
8253
8254
8255
8256
8257
8258
8259
8260
8261
8262
8263
8264
8265
8266
8267
8268
8269
8270
8271
8272
8273
8274
8275
8276
8277
8278
8279
8280
8281
8282
8283
8284
8285
8286
8287
8288
8289
8290
8291
8292
8293
8294
8295
8296
8297
8298
8299
8300
8301
8302
8303
8304
8305
8306
8307
8308
8309
8310
8311
8312
8313
8314
8315
8316
8317
8318
8319
8320
8321
8322
8323
8324
8325
8326
8327
8328
8329
8330
8331
8332
8333
8334
8335
8336
8337
8338
8339
8340
8341
8342
8343
8344
8345
8346
8347
8348
8349
8350
8351
8352
8353
8354
8355
8356
8357
8358
8359
8360
8361
8362
8363
8364
8365
8366
8367
8368
8369
8370
8371
8372
8373
8374
8375
8376
8377
8378
8379
8380
8381
8382
8383
8384
8385
8386
8387
8388
8389
8390
8391
8392
8393
8394
8395
8396
8397
8398
8399
8400
8401
8402
8403
8404
8405
8406
8407
8408
8409
8410
8411
8412
8413
8414
8415
8416
8417
8418
8419
8420
8421
8422
8423
8424
8425
8426
8427
8428
8429
8430
8431
8432
8433
8434
8435
8436
8437
8438
8439
8440
8441
8442
8443
8444
8445
8446
8447
8448
8449
8450
8451
8452
8453
8454
8455
8456
8457
8458
8459
8460
8461
8462
8463
8464
8465
8466
8467
8468
8469
8470
8471
8472
8473
8474
8475
8476
8477
8478
8479
8480
8481
8482
8483
8484
8485
8486
8487
8488
8489
8490
8491
8492
8493
8494
8495
8496
8497
8498
8499
8500
8501
8502
8503
8504
8505
8506
8507
8508
8509
8510
8511
8512
8513
8514
8515
8516
8517
8518
8519
8520
8521
8522
8523
8524
8525
8526
8527
8528
8529
8530
8531
8532
8533
8534
8535
8536
8537
8538
8539
8540
8541
8542
8543
8544
8545
8546
8547
8548
8549
8550
8551
8552
8553
8554
8555
8556
8557
8558
8559
8560
8561
8562
8563
8564
8565
8566
8567
8568
8569
8570
8571
8572
8573
8574
8575
8576
8577
8578
8579
8580
8581
8582
8583
8584
8585
8586
8587
8588
8589
8590
8591
8592
8593
8594
8595
8596
8597
8598
8599
8600
8601
8602
8603
8604
8605
8606
8607
8608
8609
8610
8611
8612
8613
8614
8615
8616
8617
8618
8619
8620
8621
8622
8623
8624
8625
8626
8627
8628
8629
8630
8631
8632
8633
8634
8635
8636
8637
8638
8639
8640
8641
8642
8643
8644
8645
8646
8647
8648
8649
8650
8651
8652
8653
8654
8655
8656
8657
8658
8659
8660
8661
8662
8663
8664
8665
8666
8667
8668
8669
8670
8671
8672
8673
8674
8675
8676
8677
8678
8679
8680
8681
8682
8683
8684
8685
8686
8687
8688
8689
8690
8691
8692
8693
8694
8695
8696
8697
8698
8699
8700
8701
8702
8703
8704
8705
8706
8707
8708
8709
8710
8711
8712
8713
8714
8715
8716
8717
8718
8719
8720
8721
8722
8723
8724
8725
8726
8727
8728
8729
8730
8731
8732
8733
8734
8735
8736
8737
8738
8739
8740
8741
8742
8743
8744
8745
8746
8747
8748
8749
8750
8751
8752
8753
8754
8755
8756
8757
8758
8759
8760
8761
8762
8763
8764
8765
8766
8767
8768
8769
8770
8771
8772
8773
8774
8775
8776
8777
8778
8779
8780
8781
8782
8783
8784
8785
8786
8787
8788
8789
8790
8791
8792
8793
8794
8795
8796
8797
8798
8799
8800
8801
8802
8803
8804
8805
8806
8807
8808
8809
8810
8811
8812
8813
8814
8815
8816
8817
8818
8819
8820
8821
8822
8823
8824
8825
8826
8827
8828
8829
8830
8831
8832
8833
8834
8835
8836
8837
8838
8839
8840
8841
8842
8843
8844
8845
8846
8847
8848
8849
8850
8851
8852
8853
8854
8855
8856
8857
8858
8859
8860
8861
8862
8863
8864
8865
8866
8867
8868
8869
8870
8871
8872
8873
8874
8875
8876
8877
8878
8879
8880
8881
8882
8883
8884
8885
8886
8887
8888
8889
8890
8891
8892
8893
8894
8895
8896
8897
8898
8899
8900
8901
8902
8903
8904
8905
8906
8907
8908
8909
8910
8911
8912
8913
8914
8915
8916
8917
8918
8919
8920
8921
8922
8923
8924
8925
8926
8927
8928
8929
8930
8931
8932
8933
8934
8935
8936
8937
8938
8939
8940
8941
8942
8943
8944
8945
8946
8947
8948
8949
8950
8951
8952
8953
8954
8955
8956
8957
8958
8959
8960
8961
8962
8963
8964
8965
8966
8967
8968
8969
8970
8971
8972
8973
8974
8975
8976
8977
8978
8979
8980
8981
8982
8983
8984
8985
8986
8987
8988
8989
8990
8991
8992
8993
8994
8995
8996
8997
8998
8999
9000
9001
9002
9003
9004
9005
9006
9007
9008
9009
9010
9011
9012
9013
9014
9015
9016
9017
9018
9019
9020
9021
9022
9023
9024
9025
9026
9027
9028
9029
9030
9031
9032
9033
9034
9035
9036
9037
9038
9039
9040
9041
9042
9043
9044
9045
9046
9047
9048
9049
9050
9051
9052
9053
9054
9055
9056
9057
9058
9059
9060
9061
9062
9063
9064
9065
9066
9067
9068
9069
9070
9071
9072
9073
9074
9075
9076
9077
9078
9079
9080
9081
9082
9083
9084
9085
9086
9087
9088
9089
9090
9091
9092
9093
9094
9095
9096
9097
9098
9099
9100
9101
9102
9103
9104
9105
9106
9107
9108
9109
9110
9111
9112
9113
9114
9115
9116
9117
9118
9119
9120
9121
9122
9123
9124
9125
9126
9127
9128
9129
9130
9131
9132
9133
9134
9135
9136
9137
9138
9139
9140
9141
9142
9143
9144
9145
9146
9147
9148
9149
9150
9151
9152
9153
9154
9155
9156
9157
9158
9159
9160
9161
9162
9163
9164
9165
9166
9167
9168
9169
9170
9171
9172
9173
9174
9175
9176
9177
9178
9179
9180
9181
9182
9183
9184
9185
9186
9187
9188
9189
9190
9191
9192
9193
9194
9195
9196
9197
9198
9199
9200
9201
9202
9203
9204
9205
9206
9207
9208
9209
9210
9211
9212
9213
9214
9215
9216
9217
9218
9219
9220
9221
9222
9223
9224
9225
9226
9227
9228
9229
9230
9231
9232
9233
9234
9235
9236
9237
9238
9239
9240
9241
9242
9243
9244
9245
9246
9247
9248
9249
9250
9251
9252
9253
9254
9255
9256
9257
9258
9259
9260
9261
9262
9263
9264
9265
9266
9267
9268
9269
9270
9271
9272
9273
9274
9275
9276
9277
9278
9279
9280
9281
9282
9283
9284
9285
9286
9287
9288
9289
9290
9291
9292
9293
9294
9295
9296
9297
9298
9299
9300
9301
9302
9303
9304
9305
9306
9307
9308
9309
9310
9311
9312
9313
9314
9315
9316
9317
9318
9319
9320
9321
9322
9323
9324
9325
9326
9327
9328
9329
9330
9331
9332
9333
9334
9335
9336
9337
9338
9339
9340
9341
9342
9343
9344
9345
9346
9347
9348
9349
9350
9351
9352
9353
9354
9355
9356
9357
9358
9359
9360
9361
9362
9363
9364
9365
9366
9367
9368
9369
9370
9371
9372
9373
9374
9375
9376
9377
9378
9379
9380
9381
9382
9383
9384
9385
9386
9387
9388
9389
9390
9391
9392
9393
9394
9395
9396
9397
9398
9399
9400
9401
9402
9403
9404
9405
9406
9407
9408
9409
9410
9411
9412
9413
9414
9415
9416
9417
9418
9419
9420
9421
9422
9423
9424
9425
9426
9427
9428
9429
9430
9431
9432
9433
9434
9435
9436
9437
9438
9439
9440
9441
9442
9443
9444
9445
9446
9447
9448
9449
9450
9451
9452
9453
9454
9455
9456
9457
9458
9459
9460
9461
9462
9463
9464
9465
9466
9467
9468
9469
9470
9471
9472
9473
9474
9475
9476
9477
9478
9479
9480
9481
9482
9483
9484
9485
9486
9487
9488
9489
9490
9491
9492
9493
9494
9495
9496
9497
9498
9499
9500
9501
9502
9503
9504
9505
9506
9507
9508
9509
9510
9511
9512
9513
9514
9515
9516
9517
9518
9519
9520
9521
9522
9523
9524
9525
9526
9527
9528
9529
9530
9531
9532
9533
9534
9535
9536
9537
9538
9539
9540
9541
9542
9543
9544
9545
9546
9547
9548
9549
9550
9551
9552
9553
9554
9555
9556
9557
9558
9559
9560
9561
9562
9563
9564
9565
9566
9567
9568
9569
9570
9571
9572
9573
9574
9575
9576
9577
9578
9579
9580
9581
9582
9583
9584
9585
9586
9587
9588
9589
9590
9591
9592
9593
9594
9595
9596
9597
9598
9599
9600
9601
9602
9603
9604
9605
9606
9607
9608
9609
9610
9611
9612
9613
9614
9615
9616
9617
9618
9619
9620
9621
9622
9623
9624
9625
9626
9627
9628
9629
9630
9631
9632
9633
9634
9635
9636
9637
9638
9639
9640
9641
9642
9643
9644
9645
9646
9647
9648
9649
9650
9651
9652
9653
9654
9655
9656
9657
9658
9659
9660
9661
9662
9663
9664
9665
9666
9667
9668
9669
9670
9671
9672
9673
9674
9675
9676
9677
9678
9679
9680
9681
9682
9683
9684
9685
9686
9687
9688
9689
9690
9691
9692
9693
9694
9695
9696
9697
9698
9699
9700
9701
9702
9703
9704
9705
9706
9707
9708
9709
9710
9711
9712
9713
9714
9715
9716
9717
9718
9719
9720
9721
9722
9723
9724
9725
9726
9727
9728
9729
9730
9731
9732
9733
9734
9735
9736
9737
9738
9739
9740
9741
9742
9743
9744
9745
9746
9747
9748
9749
9750
9751
9752
9753
9754
9755
9756
9757
9758
9759
9760
9761
9762
9763
9764
9765
9766
9767
9768
9769
9770
9771
9772
9773
9774
9775
9776
9777
9778
9779
9780
9781
9782
9783
9784
9785
9786
9787
9788
9789
9790
9791
9792
9793
9794
9795
9796
9797
9798
9799
9800
9801
9802
9803
9804
9805
9806
9807
9808
9809
9810
9811
9812
9813
9814
9815
9816
9817
9818
9819
9820
9821
9822
9823
9824
9825
9826
9827
9828
9829
9830
9831
9832
9833
9834
9835
9836
9837
9838
9839
9840
9841
9842
9843
9844
9845
9846
9847
9848
9849
9850
9851
9852
9853
9854
9855
9856
9857
9858
9859
9860
9861
9862
9863
9864
9865
9866
9867
9868
9869
9870
9871
9872
9873
9874
9875
9876
9877
9878
9879
9880
9881
9882
9883
9884
9885
9886
9887
9888
9889
9890
9891
9892
9893
9894
9895
9896
9897
9898
9899
9900
9901
9902
9903
9904
9905
9906
9907
9908
9909
9910
9911
9912
9913
9914
9915
9916
9917
9918
9919
9920
9921
9922
9923
9924
9925
9926
9927
9928
9929
9930
9931
9932
9933
9934
9935
9936
9937
9938
9939
9940
9941
9942
9943
9944
9945
9946
9947
9948
9949
9950
9951
9952
9953
9954
9955
9956
9957
9958
9959
9960
9961
9962
9963
9964
9965
9966
9967
9968
9969
9970
9971
9972
9973
9974
9975
9976
9977
9978
9979
9980
9981
9982
9983
9984
9985
9986
9987
9988
9989
9990
9991
9992
9993
9994
9995
9996
9997
9998
9999
10000
10001
10002
10003
10004
10005
10006
10007
10008
10009
10010
10011
10012
10013
10014
10015
10016
10017
10018
10019
10020
10021
10022
10023
10024
10025
10026
10027
10028
10029
10030
10031
10032
10033
10034
10035
10036
10037
10038
10039
10040
10041
10042
10043
10044
10045
10046
10047
10048
10049
10050
10051
10052
10053
10054
10055
10056
10057
10058
10059
10060
10061
10062
10063
10064
10065
10066
10067
10068
10069
10070
10071
10072
10073
10074
10075
10076
10077
10078
10079
10080
10081
10082
10083
10084
10085
10086
10087
10088
10089
10090
10091
10092
10093
10094
10095
10096
10097
10098
10099
10100
10101
10102
10103
10104
10105
10106
10107
10108
10109
10110
10111
10112
10113
10114
10115
10116
10117
10118
10119
10120
10121
10122
10123
10124
10125
10126
10127
10128
10129
10130
10131
10132
10133
10134
10135
10136
10137
10138
10139
10140
10141
10142
10143
10144
10145
10146
10147
10148
10149
10150
10151
10152
10153
10154
10155
10156
10157
10158
10159
10160
10161
10162
10163
10164
10165
10166
10167
10168
10169
10170
10171
10172
10173
10174
10175
10176
10177
10178
10179
10180
10181
10182
10183
10184
10185
10186
10187
10188
10189
10190
10191
10192
10193
10194
10195
10196
10197
10198
10199
10200
10201
10202
10203
10204
10205
10206
10207
10208
10209
10210
10211
10212
10213
10214
10215
10216
10217
10218
10219
10220
10221
10222
10223
10224
10225
10226
10227
10228
10229
10230
10231
10232
10233
10234
10235
10236
10237
10238
10239
10240
10241
10242
10243
10244
10245
10246
10247
10248
10249
10250
10251
10252
10253
10254
10255
10256
10257
10258
10259
10260
10261
10262
10263
10264
10265
10266
10267
10268
10269
10270
10271
10272
10273
10274
10275
10276
10277
10278
10279
10280
10281
10282
10283
10284
10285
10286
10287
10288
10289
10290
10291
10292
10293
10294
10295
10296
10297
10298
10299
10300
10301
10302
10303
10304
10305
10306
10307
10308
10309
10310
10311
10312
10313
10314
10315
10316
10317
10318
10319
10320
10321
10322
10323
10324
10325
10326
10327
10328
10329
10330
10331
10332
10333
10334
10335
10336
10337
10338
10339
10340
10341
10342
10343
10344
10345
10346
10347
10348
10349
10350
10351
10352
10353
10354
10355
10356
10357
10358
10359
10360
10361
10362
10363
10364
10365
10366
10367
10368
10369
10370
10371
10372
10373
10374
10375
10376
10377
10378
10379
10380
10381
10382
10383
10384
10385
10386
10387
10388
10389
10390
10391
10392
10393
10394
10395
10396
10397
10398
10399
10400
10401
10402
10403
10404
10405
10406
10407
10408
10409
10410
10411
10412
10413
10414
10415
10416
10417
10418
10419
10420
10421
10422
10423
10424
10425
10426
10427
10428
10429
10430
10431
10432
10433
10434
10435
10436
10437
10438
10439
10440
10441
10442
10443
10444
10445
10446
10447
10448
10449
10450
10451
10452
10453
10454
10455
10456
10457
10458
10459
10460
10461
10462
10463
10464
10465
10466
10467
10468
10469
10470
10471
10472
10473
10474
10475
10476
10477
10478
10479
10480
10481
10482
10483
10484
10485
10486
10487
10488
10489
10490
10491
10492
10493
10494
10495
10496
10497
10498
10499
10500
10501
10502
10503
10504
10505
10506
10507
10508
10509
10510
10511
10512
10513
10514
10515
10516
10517
10518
10519
10520
10521
10522
10523
10524
10525
10526
10527
10528
10529
10530
10531
10532
10533
10534
10535
10536
10537
10538
10539
10540
10541
10542
10543
10544
10545
10546
10547
10548
10549
10550
10551
10552
10553
10554
10555
10556
10557
10558
10559
10560
10561
10562
10563
10564
10565
10566
10567
10568
10569
10570
10571
10572
10573
10574
10575
10576
10577
10578
10579
10580
10581
10582
10583
10584
10585
10586
10587
10588
10589
10590
10591
10592
10593
10594
10595
10596
10597
10598
10599
10600
10601
10602
10603
10604
10605
10606
10607
10608
10609
10610
10611
10612
10613
10614
10615
10616
10617
10618
10619
10620
10621
10622
10623
10624
10625
10626
10627
10628
10629
10630
10631
10632
10633
10634
10635
10636
10637
10638
10639
10640
10641
10642
10643
10644
10645
10646
10647
10648
10649
10650
10651
10652
10653
10654
10655
10656
10657
10658
10659
10660
10661
10662
10663
10664
10665
10666
10667
10668
10669
10670
10671
10672
10673
10674
10675
10676
10677
10678
10679
10680
10681
10682
10683
10684
10685
10686
10687
10688
10689
10690
10691
10692
10693
10694
10695
10696
10697
10698
10699
10700
10701
10702
10703
10704
10705
10706
10707
10708
10709
10710
10711
10712
10713
10714
10715
10716
10717
10718
10719
10720
10721
10722
10723
10724
10725
10726
10727
10728
10729
10730
10731
10732
10733
10734
10735
10736
10737
10738
10739
10740
10741
10742
10743
10744
10745
10746
10747
10748
10749
10750
10751
10752
10753
10754
10755
10756
10757
10758
10759
10760
10761
10762
10763
10764
10765
10766
10767
10768
10769
10770
10771
10772
10773
10774
10775
10776
10777
10778
10779
10780
10781
10782
10783
10784
10785
10786
10787
10788
10789
10790
10791
10792
10793
10794
10795
10796
10797
10798
10799
10800
10801
10802
10803
10804
10805
10806
10807
10808
10809
10810
10811
10812
10813
10814
10815
10816
10817
10818
10819
10820
10821
10822
10823
10824
10825
10826
10827
10828
10829
10830
10831
10832
10833
10834
10835
10836
10837
10838
10839
10840
10841
10842
10843
10844
10845
10846
10847
10848
10849
10850
10851
10852
10853
10854
10855
10856
10857
10858
10859
10860
10861
10862
10863
10864
10865
10866
10867
10868
10869
10870
10871
10872
10873
10874
10875
10876
10877
10878
10879
10880
10881
10882
10883
10884
10885
10886
10887
10888
10889
10890
10891
10892
10893
10894
10895
10896
10897
10898
10899
10900
10901
10902
10903
10904
10905
10906
10907
10908
10909
10910
10911
10912
10913
10914
10915
10916
10917
10918
10919
10920
10921
10922
10923
10924
10925
10926
10927
10928
10929
10930
10931
10932
10933
10934
10935
10936
10937
10938
10939
10940
10941
10942
10943
10944
10945
10946
10947
10948
10949
10950
10951
10952
10953
10954
10955
10956
10957
10958
10959
10960
10961
10962
10963
10964
10965
10966
10967
10968
10969
10970
10971
10972
10973
10974
10975
10976
10977
10978
10979
10980
10981
10982
10983
10984
10985
10986
10987
10988
10989
10990
10991
10992
10993
10994
10995
10996
10997
10998
10999
11000
11001
11002
11003
11004
11005
11006
11007
11008
11009
11010
11011
11012
11013
11014
11015
11016
11017
11018
11019
11020
11021
11022
11023
11024
11025
11026
11027
11028
11029
11030
11031
11032
11033
11034
11035
11036
11037
11038
11039
11040
11041
11042
11043
11044
11045
11046
11047
11048
11049
11050
11051
11052
11053
11054
11055
11056
11057
11058
11059
11060
11061
11062
11063
11064
11065
11066
11067
11068
11069
11070
11071
11072
11073
11074
11075
11076
11077
11078
11079
11080
11081
11082
11083
11084
11085
11086
11087
11088
11089
11090
11091
11092
11093
11094
11095
11096
11097
11098
11099
11100
11101
11102
11103
11104
11105
11106
11107
11108
11109
11110
11111
11112
11113
11114
11115
11116
11117
11118
11119
11120
11121
11122
11123
11124
11125
11126
11127
11128
11129
11130
11131
11132
11133
11134
11135
11136
11137
11138
11139
11140
11141
11142
11143
11144
11145
11146
11147
11148
11149
11150
11151
11152
11153
11154
11155
11156
11157
11158
11159
11160
11161
11162
11163
11164
11165
11166
11167
11168
11169
11170
11171
11172
11173
11174
11175
11176
11177
11178
11179
11180
11181
11182
11183
11184
11185
11186
11187
11188
11189
11190
11191
11192
11193
11194
11195
11196
11197
11198
11199
11200
11201
11202
11203
11204
11205
11206
11207
11208
11209
11210
11211
11212
11213
11214
11215
11216
11217
11218
11219
11220
11221
11222
11223
11224
11225
11226
11227
11228
11229
11230
11231
11232
11233
11234
11235
11236
11237
11238
11239
11240
11241
11242
11243
11244
11245
11246
11247
11248
11249
11250
11251
11252
11253
11254
11255
11256
11257
11258
11259
11260
11261
11262
11263
11264
11265
11266
11267
11268
11269
11270
11271
11272
11273
11274
11275
11276
11277
11278
11279
11280
11281
11282
11283
11284
11285
11286
11287
11288
11289
11290
11291
11292
11293
11294
11295
11296
11297
11298
11299
11300
11301
11302
11303
11304
11305
11306
11307
11308
11309
11310
11311
11312
11313
11314
11315
11316
11317
11318
11319
11320
11321
11322
11323
11324
11325
11326
11327
11328
11329
11330
11331
11332
11333
11334
11335
11336
11337
11338
11339
11340
11341
11342
11343
11344
11345
11346
11347
11348
11349
11350
11351
11352
11353
11354
11355
11356
11357
11358
11359
11360
11361
11362
11363
11364
11365
11366
11367
11368
11369
11370
11371
11372
11373
11374
11375
11376
11377
11378
11379
11380
11381
11382
11383
11384
11385
11386
11387
11388
11389
11390
11391
11392
11393
11394
11395
11396
11397
11398
11399
11400
11401
11402
11403
11404
11405
11406
11407
11408
11409
11410
11411
11412
11413
11414
11415
11416
11417
11418
11419
11420
11421
11422
11423
11424
11425
11426
11427
11428
11429
11430
11431
11432
11433
11434
11435
11436
11437
11438
11439
11440
11441
11442
11443
11444
11445
11446
11447
11448
11449
11450
11451
11452
11453
11454
11455
11456
11457
11458
11459
11460
11461
11462
11463
11464
11465
11466
11467
11468
11469
11470
11471
11472
11473
11474
11475
11476
11477
11478
11479
11480
11481
11482
11483
11484
11485
11486
11487
11488
11489
11490
11491
11492
11493
11494
11495
11496
11497
11498
11499
11500
11501
11502
11503
11504
11505
11506
11507
11508
11509
11510
11511
11512
11513
11514
11515
11516
11517
11518
11519
11520
11521
11522
11523
11524
11525
11526
11527
11528
11529
11530
11531
11532
11533
11534
11535
11536
11537
11538
11539
11540
11541
11542
11543
11544
11545
11546
11547
11548
11549
11550
11551
11552
11553
11554
11555
11556
11557
11558
11559
11560
11561
11562
11563
11564
11565
11566
11567
11568
11569
11570
11571
11572
11573
11574
11575
11576
11577
11578
11579
11580
11581
11582
11583
11584
11585
11586
11587
11588
11589
11590
11591
11592
11593
11594
11595
11596
11597
11598
11599
11600
11601
11602
11603
11604
11605
11606
11607
11608
11609
11610
11611
11612
11613
11614
11615
11616
11617
11618
11619
11620
11621
11622
11623
11624
11625
11626
11627
11628
11629
11630
11631
11632
11633
11634
11635
11636
11637
11638
11639
11640
11641
11642
11643
11644
11645
11646
11647
11648
11649
11650
11651
11652
11653
11654
11655
11656
11657
11658
11659
11660
11661
11662
11663
11664
11665
11666
11667
11668
11669
11670
11671
11672
11673
11674
11675
11676
11677
11678
11679
11680
11681
11682
11683
11684
11685
11686
11687
11688
11689
11690
11691
11692
11693
11694
11695
11696
11697
11698
11699
11700
11701
11702
11703
11704
11705
11706
11707
11708
11709
11710
11711
11712
11713
11714
11715
11716
11717
11718
11719
11720
11721
11722
11723
11724
11725
11726
11727
11728
11729
11730
11731
11732
11733
11734
11735
11736
11737
11738
11739
11740
11741
11742
11743
11744
11745
11746
11747
11748
11749
11750
11751
11752
11753
11754
11755
11756
11757
11758
11759
11760
11761
11762
11763
11764
11765
11766
11767
11768
11769
11770
11771
11772
11773
11774
11775
11776
11777
11778
11779
11780
11781
11782
11783
11784
11785
11786
11787
11788
11789
11790
11791
11792
11793
11794
11795
11796
11797
11798
11799
11800
11801
11802
11803
11804
11805
11806
11807
11808
11809
11810
11811
11812
11813
11814
11815
11816
11817
11818
11819
11820
11821
11822
11823
11824
11825
11826
11827
11828
11829
11830
11831
11832
11833
11834
11835
11836
11837
11838
11839
11840
11841
11842
11843
11844
11845
11846
11847
11848
11849
11850
11851
11852
11853
11854
11855
11856
11857
11858
11859
11860
11861
11862
11863
11864
11865
11866
11867
11868
11869
11870
11871
11872
11873
11874
11875
11876
11877
11878
11879
11880
11881
11882
11883
11884
11885
11886
11887
11888
11889
11890
11891
11892
11893
11894
11895
11896
11897
11898
11899
11900
11901
11902
11903
11904
11905
% -*- coding: utf-8; time-stamp-format: "%02d-%02m-%:y at %02H:%02M:%02S %Z" ; time-stamp-active: nil -*-
% N.B.: this dtx file does NOT use \DocInput.  It does NOT prefix the user
% manual part with percent characters.
%<*none>
\def\etocdtxtimestamp {Time-stamp: <30-04-2023 at 21:53:47 CEST>}%
%</none>
%<*!readme>
%%
%% Package: etoc
%% Version: 1.2a
%% License: LPPL 1.3c
%% Copyright (C) 2012-2023 Jean-Francois Burnol
%%                         <jfbu at free dot fr>
%</!readme>
%<*none>
\def\etocpkgdate        {2023/05/01}
\def\etocdocdate        {2023/05/01}
\def\etocpkgversion     {1.2a}
\def\etocpkgdescription {Completely customisable TOCs (JFB)}
%% Formerly this etoc.dtx also included source for a German translation
%% etoc-DE.pdf.  But all additions since April 2015 had been only in English.
%% Since 1.09f of 2022/08/30 etoc-DE.pdf is not produced anymore and the
%% existing translated sections have been removed from this etoc.dtx.
% Definition of \etocLicense
% --------------------------
\begingroup
    \long\def\firstofone #1{#1}\catcode1=14\catcode2=0
    \catcode`\%=12\catcode`\_=12\endlinechar13\catcode13=13 ^^A
    \catcode32=13\catcode`\\=12^^Brelax^^A
^^Bfirstofone{^^Bendgroup^^Bdef^^BetocLicense^^A
{% Package: etoc
% Version: 1.2a
% License: LPPL 1.3c
% Copyright (C) 2012-2023 Jean-Francois Burnol <jfbu at free dot fr>
%
%     This Work may be distributed and/or modified under the
%     conditions of the LaTeX Project Public License, in its
%     version 1.3c. 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.
%
% The Author of this Work is:
% Jean-Francois Burnol <jfbu at free dot fr>
%
% This Work consists of the main source file etoc.dtx and the derived
% files etoc.sty, etoc.tex, etoc.pdf, etoc.dvi, README.md.
%
% Running etex (or latex or pdflatex) on etoc.dtx extracts etoc.sty,
% etoc.tex and README.md. See README.md for further instructions.
}}%
\bgroup\catcode2 0 \catcode`\\ 12 ^^Biffalse
%</none>
%<*readme>
<!-- -->

    Source:  etoc.dtx (1.2a)
    Author:  Jean-Francois Burnol
    Info:    Completely customisable TOCs
    License: LPPL 1.3c
    Copyright (C) 2012-2023 Jean-Francois Burnol.
    <jfbu at free dot fr>

ABSTRACT
========

With `etoc` loaded, `\tableofcontents` can be used multiple times and
an added command `\localtableofcontents` allows to typeset "local"
tables of contents, i.e. having their scope limited to the last
sectioning command encountered.

No auxiliary file is used additionally to the standard `.toc` file.
Release 1.2 provides **experimental** additions `\locallistoffigures` and
`\locallistoftables` which also use only the `.toc` file.

Such local TOCs or "Lists Of" typically need to adopt a "display
style" (i.e. the way the title is rendered, whether it should add
itself an entry in the `.toc` file, ...) somewhat distinct from the
global TOC.  The release 1.2 default adapts automatically the titles
of local TOCs to their depths in the sectioning hierarchy.  Should the
need arise to customize such "display style", full control is allowed
by package commands.

Regarding how the individual "contents lines" are handled, here again
complete control is given to the user to define from the ground-up how
to use the *name*, *number*, and *page number* for each entry,
according to their "levels" (i.e. part, chapter, section, subsection,
...).  As this requires some LaTeX fluency, many examples which can
serve as starting points are attached to the PDF documentation as
extractible files.

Loading `etoc` per itself modifies nothing to "contents lines"
rendering from the class default or changes from other packages.  But
full usage of the package allows spectacular effects such as displaying
TOCs as trees or mind maps.


INSTALLATION
============

For manual installation do `etex etoc.dtx` to extract files then move
`etoc.sty` to a place where TeX can find it.

    etoc.sty    -> TDS:tex/latex/etoc/etoc.sty
    etoc.dtx    -> TDS:source/latex/etoc/etoc.dtx
    etoc.pdf    -> TDS:doc/latex/etoc/etoc.pdf
    README.md   -> TDS:doc/latex/etoc/README.md

To produce `etoc.pdf` run pdflatex on the extracted file `etoc.tex`
sufficiently many times (`latexmk -pdf etoc` is recommended).


LICENSE
=======

This Work may be distributed and/or modified under the
conditions of the LaTeX Project Public License, in its
version 1.3c. 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.

The Author of this Work is Jean-Francois Burnol <jfbu at free dot fr>

This Work consists of the main source file etoc.dtx and the derived files
etoc.sty, etoc.tex, etoc.pdf, etoc.dvi.


RECENT CHANGES
==============

This is `1.2a` of `2023/05/01`.

- `1.2a` lifted the requirement added at `1.1a` of a LaTeX kernel from
  2020-10-01 or later, and also the requirement added at `1.2` of
  availability of the `\expanded` engine primitive.  It also added a
  `deeplevels` option.

- `1.2` completed the core internal refactoring from `1.1a-d` and added
  **experimental** `\locallistoffigures` and `\locallistoftables`.  It also
  let `\localtableofcontents` by default auto-select a heading style
  adapted to location, and added options to control whether local TOCs
  and Lists Of add an entry corresponding to their heading in the `.toc`
  file.  Compatibility with `tocbibind` package, too.

- `1.1a` up to `1.1d` were mainly about refactoring core legacy code.
  In part, this is to prepare for future changes relative to how
  hyperref and the LaTeX kernel will interact in the future.

%</readme>
%<*tex>-------------------------------------------------------------------------
%% To produce the documentation etoc.pdf with source code included:
%%   latexmk -pdf etoc.tex
%% (or sufficiently many times pdflatex etoc.tex)
%% For customizations see comments and classe options below.
\tracinglostchars3
\chardef\Withdvipdfmx 0 % replace 0 by 1 for using latex+dvipdfmx
\chardef\NoSourceCode 0 % replace 0 by 1 for the doc *without* the source code
\NeedsTeXFormat{LaTeX2e}
\ProvidesFile {etoc.tex}[Driver for etoc documentation]%
\PassOptionsToClass   {a4paper,fontsize=10pt,twoside}{scrartcl}
\PassOptionsToPackage {ngerman,english}{babel}
\input etoc.dtx
%%% Local Variables:
%%% mode: latex
%%% End:
%</tex>-------------------------------------------------------------------------
%<*none>------------------------------------------------------------------------
^^Bfi^^Begroup
%
\chardef\noetex 0
\ifx\numexpr\undefined\chardef\noetex 1 \fi
\ifnum\noetex=1 \chardef\extractfiles 0 % extract files, then stop
\else
    \ifx\ProvidesFile\undefined
      \chardef\extractfiles 0 % etex etc.. on etoc.dtx, only file extraction.
    \else % latex/pdflatex on etoc.tex or on etoc.dtx
      \ifx\Withdvipdfmx\undefined
        % latex/pdflatex run is on etoc.dtx
        \chardef\extractfiles 1 % 1 = extract files and typeset manual, 2 = only typeset
        \chardef\Withdvipdfmx 0 % 0 = pdflatex or latex+dvips, 1 = dvipdfmx
        \chardef\NoSourceCode 1 % 0 =  include source code, 1 = do not
        \NeedsTeXFormat {LaTeX2e}%
        \PassOptionsToClass   {a4paper,fontsize=10pt,twoside}{scrartcl}%
        \PassOptionsToPackage {ngerman,english}{babel}%
      \else % latex run is on etoc.tex
        \chardef\extractfiles 2 % do not extract files, only typeset
      \fi
      \ProvidesFile{etoc.dtx}%
        [etoc source and documentation (\etocdtxtimestamp)]%
    \fi
\fi
\ifnum\extractfiles<2 % extract files
\def\MessageDeFin{\newlinechar10 \let\Msg\message
\Msg{********************************************************************^^J}%
\Msg{*^^J}%
\Msg{* To finish the installation you have to move the following^^J}%
\Msg{* file into a directory searched by TeX:^^J}%
\Msg{*^^J}%
\Msg{*\space\space\space\space etoc.sty^^J}%
\Msg{*^^J}%
\Msg{* To produce the documentation with source code included execute^^J}%
\Msg{* latexmk -pdf etoc.tex^^J}%
\Msg{*^^J}%
\Msg{* Happy TeXing!^^J}%
\Msg{*^^J}%
\Msg{********************************************************************^^J}%
}%
\begingroup
    \input docstrip.tex
    \askforoverwritefalse
    \generate{\nopreamble\nopostamble
    \file{README.md}{\from{etoc.dtx}{readme}}%
    \usepostamble\defaultpostamble
    \file{etoc.tex}{\from{etoc.dtx}{tex}}%
    \usepreamble\defaultpreamble
    \file{etoc.sty}{\from{etoc.dtx}{package}}}%
\endgroup
\fi % end of file extraction (from etex/latex/pdflatex run on etoc.dtx)
\ifnum\noetex=1 % warning for README.md
    \expandafter\def\expandafter\MessageDeFin\expandafter
{\MessageDeFin
\Msg{* warning: to get correct utf-8 encoded README.md ^^J}%
\Msg{* do etex etoc.dtx and not as here tex etoc.dtx   ^^J}%
\Msg{********************************************************************^^J}}%
\fi
\ifnum\extractfiles=0 % tex/etex/xetex/etc on etoc.dtx, files extracted, stop
      \MessageDeFin\expandafter\end
\fi
% From this point on, run is necessarily with e-TeX.
% Check if \MessageDeFin got defined, if yes put it at end of run.
\ifdefined\MessageDeFin\AtEndDocument{\MessageDeFin}\fi
%-------------------------------------------------------------------------------
% START OF USER MANUAL TEX SOURCE
\documentclass{scrartcl}

\makeatletter
%%% START OF CUSTOM doc.sty LOADING (May 21, 2022 in xint.dtx)
%%% (August 26, 2022 here, comments trimmed)
%
% For some legacy reason (because I started like this and it
% worked to my satisfaction) I had used scrdoc.cls all those
% years, without in fact needing most of its features.
%
% It loads ltxdoc class, from which again I need very little.  On
% testing May 20, 2022 the upcoming LaTeX 2022-06-01 I had some
% problems with ltxdoc not having suitable interface for rolling
% back to doc=V2.
%
% ...
%
% Thus it turns out I need very little of doc.sty, and almost
% nothing of ltxdoc.cls and scrdoc.cls.
%
% (maybe provisory, try to see if usage of cross-hyperlinking
%  as in sourcexint.pdf makes sense here for rendering of
%  implementation part - loading time of etoc.pdf in viewer
%  in increased, though. 2022/08/26)
%
% Let's load the doc=V2 version to avoid having to work around
% hypdoc loading interfering with my use of hyperref.
\ifdefined\IfFormatAtLeastTF
  \IfFormatAtLeastTF{2022/06/01}%
  {%
    \IfFileExists{doc-2021-06-01.sty}%
     {\usepackage{doc}[=v2]}%
% Why on earth do I lose my time doing this?
     {\GenericError
          {(etoc build doc)\@spaces}%
          {etoc build error: %
      Your LaTeX installation seems to be broken, format is\MessageBreak
      2022-06-01 or later but `doc' package in its `v2' version\MessageBreak
      seems to not be available. \space Will try with `doc' but if\MessageBreak
      its `v3' is used there will be an option clash error\MessageBreak
      regarding hyperref.}%
          {}%
          {Please make sure `doc' package matches your LaTeX format.}%
      \usepackage{doc}%
     }%
  }%
  {\usepackage{doc}}%
\else
\usepackage{doc}
\fi
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% MACROS OF doc.sty WILL BE HACKED (2022/06/06) FOR THE IMPLEMENTATION PART
%
% First we want to turn CodelineNo into a real LaTeX counter
% This will spare defining an extra counter for the hyperlinks with \hyperref
\begingroup\let\newcount\@gobble\@definecounter{CodelineNo}\endgroup
% Let's now reenact the doc.sty default for \theCodeLineNo
\def\theCodelineNo{\reset@font\scriptsize\arabic{CodelineNo}}
% But as we will reset CodelineNo at each style file we need some unique id
\def\theHCodelineNo{\the\value{section}.\the\value{CodelineNo}}
% This is all for now.
% The further hacks are to be found after the \StopEventually (i.e. a few
% thousands lines down from here if you don't have access to the private
% sources, which is probably the case if you are not the author).
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% As explained above I was formerly using scrdoc hence ltxdoc indirectly.
% Let's emulate here the little I appear to need from ltxdoc.cls and
% srcdoc.cls.
%
\AtBeginDocument{\MakeShortVerb{\|}}
\DeclareFontShape{OT1}{cmtt}{bx}{n}{<-> ssub * cmtt/m/n}{}
\DeclareFontFamily{OMS}{cmtt}{\skewchar\font 48}  % '60
\DeclareFontShape{OMS}{cmtt}{m}{n}{<-> ssub * cmsy/m/n}{}
\DeclareFontShape{OMS}{cmtt}{bx}{n}{<-> ssub * cmsy/b/n}{}
\DeclareFontShape{OT1}{cmss}{m}{it}{<->ssub*cmss/m/sl}{}
\ifnum\NoSourceCode=1
  \OnlyDescription
\fi
\CodelineNumbered
\EnableCrossrefs  % but this will be hacked
% \setcounter{StandardModuleDepth}{1} % we don't use this mechanism currently
\def\cmd#1{\cs{\expandafter\cmd@to@cs\string#1}}
\def\cmd@to@cs#1#2{\char\number`#2\relax}
% Here I am loading doc=v2 but formerly I was using ltxdoc via scrdoc
% which I dropped at release 1.4l (2022-05-29) and without much
% thinking I had kept this.
\DeclareRobustCommand\cs[1]{\texttt{\bslash#1}}
% As I may have the * active, or macro names with _ or ^, I should
% add \detokenize.  But see below for a redefinition anyhow.
%
% More urgent is that I am also using hyperref and this definition gives wrong
% bookmarks if \cs is used in section titles.  As I had very very few usags of
% \cs in the whole of xint.dtx, it took me a while to realize the problem
% here.  Turns out that doc=v3 by default loads hypdoc which includes this
% configuation for hyperref compatibility:
\AtBeginDocument{%
\pdfstringdefDisableCommands{\def\cs#1{\textbackslash\detokenize{#1}}}%
}%
% As I have not loaded hyperref yet I must delay it to AtBeginDocument.
\providecommand\marg[1]{%
  {\ttfamily\char`\{}\meta{#1}{\ttfamily\char`\}}}
\providecommand\oarg[1]{%
  {\ttfamily[}\meta{#1}{\ttfamily]}}
\providecommand\parg[1]{%
  {\ttfamily(}\meta{#1}{\ttfamily)}}
% \@addtoreset{CodelineNo}{part}% No need for this here
% \def\partname{File}% \partname is "fixed" somewhere further down anyhow
% No need for this, anyhow I don't build the indices
% \gdef\codeline@wrindex#1{\if@filesw
%       \begingroup
%         \let\protect\noexpand
%         \immediate\write\@indexfile
%             {\string\indexentry{#1}%
%             {\filesep\number\c@CodelineNo}}%
%       \endgroup\fi}
% \let\filesep\@empty

% There is very little we seem to need from the scrdoc extras: page geometry
% is set by geometry package and a4paper option from xint.tex file.  So it
% seems I only need the hologo loading:
\usepackage{hologo}
\DeclareRobustCommand*{\eTeX}{\hologo{eTeX}}%
\DeclareRobustCommand*{\LuaTeX}{\hologo{LuaTeX}}%
%
\makeatother
%%% end of ltxdoc+srcdoc emulation from June 2022 xint.dtx,
%%% copied over almost verbatim to etoc.dtx on 2022/08/26.
%%% See after \StopEventually for doc.sty hacks.

\makeatletter
% pour maintenir les % en début de ligne dans les blocs verbatim
   \let\original@check@percent\check@percent
   \let\check@percent\relax
\makeatother


% We got sensible result with attachfile or attachfile2
% only with pdflatex.  So this is remnant of earlier
% times when etoc.pdf was produced via latex+dvipdfmx

\usepackage{ifpdf}
\ifpdf\chardef\Withdvipdfmx 0 \fi

\makeatletter
\ifnum\Withdvipdfmx=1
   \@for\@tempa:=hyperref,bookmark,graphicx,xcolor,pict2e\do
            {\PassOptionsToPackage{dvipdfmx}\@tempa}
   %
   \PassOptionsToPackage{dvipdfm}{geometry}
   \PassOptionsToPackage{bookmarks=true}{hyperref}
   \PassOptionsToPackage{dvipdfmx-outline-open}{hyperref}
   \PassOptionsToPackage{dvipdfmx-outline-open}{bookmark}
   %
   \def\pgfsysdriver{pgfsys-dvipdfm.def}
\else
   \PassOptionsToPackage{bookmarks=true}{hyperref}
\fi
\makeatother

\usepackage[T1]{fontenc}
\usepackage[hscale=0.66,vscale=0.75]{geometry}

% Some problems with headers
\pagestyle{headings}
% \sectionmark uses \markboth in twoside but
% with an empty right mark!  As a result if a section starts
% on an odd page, it does not appear in the header mark.
% Perhaps there was a subsection of 3 lines on that page
% and it is the subsection which decides what is in the header.

% Some custom \sectionmark to get headers more to my taste.
% But it is hard to find algorithm giving satisfaction in all cases.

\makeatletter
\renewcommand *{\sectionmark }[1]{%
% Que c'est pénible cette syntaxe \markboth/\markright de LaTeX !
% Pourquoi est-ce que \markright n'a pas été définie comme #1#2-> truc avec #2 ??
  \if@twoside \expandafter \markboth \else
   \expandafter\expandafter\expandafter \markright\expandafter \@firstoftwo
  \fi
  {\MakeMarkcase {\Ifnumbered {section}{\sectionmarkformat }{}#1}}%
  {\MakeMarkcase {\Ifnumbered {section}{\sectionmarkformat }{}#1}}%
}

% Par ailleurs je vais remplacer \firstmark par \botmark dans \rightmark
% dont la définition par défaut est :

% \rightmark:
% macro:->\expandafter \@rightmark \firstmark \@empty \@empty

\renewcommand*\rightmark{\expandafter\@rightmark\botmark \@empty\@empty}
% Au passage l'output de latexdef à un : supplémentaire bizarre
% $ latexdef botmark
%
% \botmark:
% \botmark:
%

% Néanmoins pour les \part il ne faut clairement pas utiliser \botmark
% Tous mes \part sont après un \clearpage explicite
% Je crois que le plus simple est encore de faire ceci:
\def\ps@mypartheadings{%
    \ps@headings
    \let\@evenhead\@empty
    \let\@oddhead\@empty
}

% peut-être serait-ce mieux de mettre le \thispagestyle après mon \clearpage,
% explicitement dans la source
\def\part{\thispagestyle{mypartheadings}\scr@startpart {part}}
\makeatother

% pour les environnements verbatim
% uniformisé finalement, avec quelques exceptions, pour dtx du 3 déc 2013
%\def\MacroFont{\ttfamily\small\hyphenchar\font45 \baselineskip11pt\relax}
% Je supprime le small finalement 2023/02/28 mais passe en 10pt
\def\MacroFont{\ttfamily\hyphenchar\font45\relax\setstretch{1}}


%----
% better \verb pour doc.
% 12 octobre 2013, importé de xint.dtx
% je rajoute pour { afin que truc{machin puisse avoir hyphénation
% retire \leavemmode, pas nécessaire pour emploi ici

% NOTE 9 mars 2015. J'ai depuis une version plus aboutie dans xint.dtx
% mais je laisse ici tel quel.

\def\MicroFont{\ttfamily\hyphenchar\font45 }
% modif de \do@noligs: \char`#1} --> \char`#1 }
\makeatletter
\def\do@noligs #1%
{%
    \catcode `#1\active
    \begingroup \lccode `\~=`#1\relax
    \lowercase {\endgroup \def ~{\kern \z@ \char `#1 }}%
}%
\def\dobackslash
{%
    \catcode92 \active
    \begingroup \lccode `\~=92\relax
    \lowercase {\endgroup \def ~{\kern \z@ \char 92 }}%
}%
\def\dobraces
{%
    \catcode123 \active
    \begingroup \lccode `\~=123\relax
    \lowercase {\endgroup \def ~{\hskip \z@\@plus.1pt\@minus.1pt
                                 \char 123 }}%
    \catcode125 \active
    \begingroup \lccode `\~=125\relax
    \lowercase {\endgroup \def ~{\char 125 \hskip \z@\@plus.1pt\@minus.1pt }}%
}%
\def\verb
{%
  \relax \ifmmode\hbox\else\leavevmode\null\fi
  \bgroup \MicroFont
  \let\do\do@noligs  \verbatim@nolig@list
  \let\do\@makeother \dospecials
  \catcode32 10
  \dobackslash \dobraces \makestarlowast
  \@jfverb
}%
\def\@jfverb #1{\catcode`#1\active
                \lccode`\~`#1\lowercase{\def~{\egroup\unskip}}}%
% (\unskip ajouté le 14 octobre)
% \lowast est défini plus loin
\begingroup
   \lccode`\~=`\*
\lowercase{%
\endgroup
\def\makestarlowast {\catcode`\*\active\let~\lowast}}%
\makeatother
%

%%%% FONT CONFIGURATION

\usepackage{txfonts}

% (2013) rescale the monospace font to 92% and allow hyphenation
% (2023) fix the missing rescaling of bold series of txttt
\DeclareFontFamily{T1}{txtt}{\hyphenchar\font 45\relax}
%\DeclareFontFamily{T1}{txtt}{\hyphenchar\font -1\relax}
\DeclareFontShape{T1}{txtt}{m}{n}{  %medium
     <->s*[.96] t1xtt%
}{}
\DeclareFontShape{T1}{txtt}{m}{sc}{ %cap & small cap
     <->s*[.96] t1xttsc%
}{}
\DeclareFontShape{T1}{txtt}{m}{sl}{ %slanted
     <->s*[.96] t1xttsl%
}{}
\DeclareFontShape{T1}{txtt}{m}{it}{ %italic
     <->ssub * txtt/m/sl%
}{}
\DeclareFontShape{T1}{txtt}{m}{ui}{     %unslanted italic
     <->ssub * txtt/m/sl%
}{}
% ---- /added here missing scale factor 2023
\DeclareFontShape{T1}{txtt}{bx}{n}{ %bold extended
     <->s*[.96] t1xbtt%
}{}
% The above s*[.96] added 2023/01/18, next two untested
\DeclareFontShape{T1}{txtt}{bx}{sc}{    %bold extended cap & small cap
     <->s*[.96] t1xbttsc%
}{}
\DeclareFontShape{T1}{txtt}{bx}{sl}{    %bold extended slanted
     <->s*[.96] t1xbttsl%
}{}
% ---- /end of 2023 fix
\DeclareFontShape{T1}{txtt}{bx}{it}{    %bold extended italic
     <->ssub * txtt/bx/sl%
}{}
\DeclareFontShape{T1}{txtt}{bx}{ui}{    %bold extended unslanted italic
     <->ssub * txtt/bx/sl%
}{}
\DeclareFontShape{T1}{txtt}{b}{n}{  %bold
     <->ssub * txtt/bx/n%
}{}
\DeclareFontShape{T1}{txtt}{b}{sc}{ %bold cap & small cap
     <->ssub * txtt/bx/sc%
}{}
\DeclareFontShape{T1}{txtt}{b}{sl}{ %bold slanted
     <->ssub * txtt/bx/sl%
}{}
\DeclareFontShape{T1}{txtt}{b}{it}{     %bold italic
     <->ssub * txtt/bx/it%
}{}
\DeclareFontShape{T1}{txtt}{b}{ui}{     %bold unslanted italic
     <->ssub * txtt/bx/ui%
}{}

% (2023) also rescale the txss sans serif (Helvetica)
\DeclareFontFamily{T1}{txss}{}
\DeclareFontShape{T1}{txss}{m}{n}{	%medium
     <->s * [0.89]t1xss%
}{}
\DeclareFontShape{T1}{txss}{m}{sc}{	%cap & small cap
     <->s * [0.89]t1xsssc%
}{}
\DeclareFontShape{T1}{txss}{m}{sl}{	%slanted
     <->s * [0.89]t1xsssl%
}{}
\DeclareFontShape{T1}{txss}{m}{it}{	%italic
     <->ssub * txss/m/sl%
}{}
\DeclareFontShape{T1}{txss}{m}{ui}{   	%unslanted italic
     <->ssub * txss/m/sl%
}{}
\DeclareFontShape{T1}{txss}{bx}{n}{	%bold extended
     <->s * [0.89]t1xbss%
}{}
\DeclareFontShape{T1}{txss}{bx}{sc}{	%bold extended cap & small cap
     <->s * [0.89]t1xbsssc%
}{}
\DeclareFontShape{T1}{txss}{bx}{sl}{	%bold extended slanted
     <->s * [0.89]t1xbsssl%
}{}
\DeclareFontShape{T1}{txss}{bx}{it}{	%bold extended italic
     <->ssub * txss/bx/sl%
}{}
\DeclareFontShape{T1}{txss}{bx}{ui}{  	%bold extended unslanted italic
     <->ssub * txss/bx/sl%
}{}
\DeclareFontShape{T1}{txss}{b}{n}{	%bold
     <->ssub * txss/bx/n%
}{}
\DeclareFontShape{T1}{txss}{b}{sc}{	%bold cap & small cap
     <->ssub * txss/bx/sc%
}{}
\DeclareFontShape{T1}{txss}{b}{sl}{	%bold slanted
     <->ssub * txss/bx/sl%
}{}
\DeclareFontShape{T1}{txss}{b}{it}{   	%bold italic
     <->ssub * txss/bx/it%
}{}
\DeclareFontShape{T1}{txss}{b}{ui}{   	%bold unslanted italic
     <->ssub * txss/bx/ui%
}{}
%


% Use the Bitter typeface for the romanfamily
\usepackage[scale=0.87]{bitter}

\AddToHook{begin/document/after}{%
    \renewcommand{\familydefault}{\sfdefault}%
    \rmfamily
}

\usepackage{xspace}
% added svgnames 2022/08/26 on occasion of transfer from xint colouring scheme
\usepackage[dvipsnames,svgnames]{xcolor}
\usepackage{graphicx}
\usepackage[inline]{enumitem}
\usepackage{array}
\usepackage{longtable}

\definecolor{joli}{RGB}{225,95,0}
\definecolor{JOLI}{RGB}{225,95,0}
\definecolor{BLUE}{RGB}{0,0,255}
\colorlet{niceone}{green!35!blue!75}
\colorlet{optioncolor}{Maroon}

% These colours mostly used only after stopeventually
\definecolor{etocnamecolor}{RGB}{228,57,0}
\colorlet{verbcolor}{Maroon}
\colorlet{privatecommentcolor}{cyan}
\colorlet{macrocodecommentcolor}{gray}
\colorlet{macrocodenewmacrocolor}{verbcolor}
\colorlet{macrocodelinktouserdoccolor}{etocnamecolor}% and bold face
\colorlet{macrocodelinktosectioncolor}{DarkBlue}% and bold face
\colorlet{macrocodelinktocodelinecolor}{Blue}
\colorlet{macrocodenoncscolor}{Green}

\usepackage {babel} % ngerman and english options have been passed to babel
\AtBeginDocument {%
% this may be obsolete as I don't use scrdoc or ltxdoc classes anymore
  \renewcommand\partname{Part}%
  \addto\captionsenglish {\renewcommand\partname{Part}}
}

\usepackage{tikz}
\usetikzlibrary{trees}    % added for "cyclic" grow function 2013/03/02
\usepackage{forest}[2015/05/04]
% switched from tikz-qtree to forest 2013/09/09
% No problem with hyperlinks then, contrarily to tikz-qtree.



% 12 mars 2015, pour 1.08a, see http://tex.stackexchange.com/a/232584/4686
\usetikzlibrary{mindmap}
% Vendredi 13 mars 2015 à 18:10:40
% POUR LA TOC DE TITLE PAGE
\usepackage{eso-pic}
\usepackage{picture}
\usepackage{ragged2e}
% setspace usage added February 2023... (to accompany change of document font)
% It must be loaded before hyperref
\usepackage{setspace}

\usepackage{hyperref}% I had used [pdfencoding=pdfdoc] until 1.09f
\hypersetup{%
linktoc=all,%
%%linktoc=none,% STRESS TEST OF 1.1a
%% bookmarksdepth=3,% (not needeed anymore now, 1.07g)
breaklinks=true,%
colorlinks,%
linkcolor=RoyalBlue,% Orchid
urlcolor=OliveGreen,%
pdfauthor={Jean-François Burnol},% on peut y aller maintenant avec ç en 2022...
pdftitle={The etoc package},%
pdfsubject={Tables of contents with LaTeX},%
pdfkeywords={LaTeX, table of contents},%
pdfstartview=FitH,%
%%pdfpagemode=UseOutlines,% commented-out for 1.09h
}
% added usage of package bookmark 2013/10/10
\usepackage{bookmark}
\usepackage{varioref}

% Vendredi 16 septembre 2016
% pour rendre accessibles les exemples
% Fait package filecontentsdef le Samedi 17.
\usepackage{filecontentsdef}

%\ifnum\Withdvipdfmx=1
%% Attempts to use attachfile2 for latex+dvipdfmx fail:
%%
%% - 2016: (I did not record which version of attachfile2 was used)
%%         (this \the\value comment presumably refers to how I was using
%%         \attachfile at that time)
%%
%%   I have an issue that with \thesubsection or \the\value{section} in code
%%   snippet filename, the file is not correctly attached, it appears in the
%%   pdf interface but with a wrong filename and one can not obtain the file
%%   from the pdf (tested on Acrobat Reader 11 Vendredi 16 septembre 2016).
%%
%% - 2023 (January, 1.2, with 2019/11/26 v2.11):
%%
%%   I had to comment-out the mimetype, created and modified key settings.
%%   Then latex run passed but dvipdfmx complained with a dozen of
%%      dvipdfmx:warning: Object @atfi_obj_67 used, but not defined. Replaced by null.
%%   The Adobe Reader (same as in 2016...) Attachment panel lists a dozen of
%%      Inconnu in section 39
%%   lines clearly matching the dvipdfmx warnings.
%%
%%   The panel of Comments does display the list.  From there or from the
%%   Attachment panels one can recover the snippets.  The «etocsnippet» name
%%   is displayed in a strange greyed-out rendering, and one has to guess that
%%   CTRL-click gives access to the file.  (not different from pdflatex route)
%%
%%   I also tried with attachfile2.dtx from github at commit 660cea7 of May
%%   19, 2022, and the same problem with the Attachment panel was there.  Only
%%   difference I saw with attachfile2 from TL2022 was the ordering in the
%%   Attachment panel (with TL2022 attachfile2, the «Inconnu» lines were all
%%   grouped together).
%%
%%   So I can still not go via latex+dvipdfmx in 2023.  But the size reduction
%%   which is motivation for dvipdfmx was modest in this renewed testing,
%%   roughly 740Kb vs 840Kb with pdflatex.
%%
%  \usepackage[dvipdfmx]{attachfile2}
%% MEMO: I use \widthof in Linked list of the main package commands in
%%       a \makebox, since August 30, 2022, for 1.09f release.
%%       This requires calc, which is loaded only by attachfile among
%%       used packages; and calc is not loaded by attachfile2.
%  \usepackage{calc}
%\else
  \usepackage{attachfile}% no op with dvipdfmx
%\fi
%
\def\CEST{+02'00'}\def\CET{+01'00'}
\def\ExtractDateStamp #1<#2-#3-#4 at #5:#6:#7 #8>%
    {D:#4#3#2#5#6#7\csname#8\endcsname}
\edef\DateForSamples {\expandafter\ExtractDateStamp\etocdtxtimestamp}
\attachfilesetup{%icon=Paperclip,% attention Paperclip pas PaperClip !!
                 mimetype=application/x-tex,
                 %appearance=false,
% These comments and next are from November 19, 2022
%                 author={Jean-François Burnol},
%                 author={\pdfescapestring{Jean-François Burnol}},
% TODO: resolve this at some point in my future life
                 author={Jean-Francois Burnol},
% doing this has fixed the date shown in Acrobat annotation panel
% but now some strange seemingly unrelated date is printed in
% the "Comment panel"
                 created=\DateForSamples,
                 modified=\DateForSamples,
% allright this one next sets the dates shown in the "Comment Panel",
% whereas the above two (or only modified) impacts the panel of
% annotations on the left in my (very old) Adobe Reader.  Not yet
% tested with evince
                 date=\DateForSamples
                 }%

\colorlet{etocsnippet}{blue}
\newcommand\marginattach{%
  \noindent Depending on the PDF viewer\normalmarginpar
% syntaxe pénible n'y-a-t-il pas un moyen plus commode
% j'hésite à tester \value{page}
  \marginpar
  [% left
   {\hfill
   \textattachfile[description={in section \the\value{section}}]%
                  {etocsnippet-\snippetno.tex}%
                  {\textcolor{etocsnippet}{etocsnippet-\snippetno.tex}}%
   }%
  ]%
  {% right
   \textattachfile[description={in section \the\value{section}}]%
                  {etocsnippet-\snippetno.tex}%
                  {\textcolor{etocsnippet}{etocsnippet-\snippetno.tex}}%
   \hfill
  }%
  \stepcounter{snippet},
  a click (or CTRL-click) on the filename in the margin may allow to extract
  it.  Or check if an ``attachments'' or ``comments'' panel is available.
}
% Sadly, on non-attachement supporting viewers such as Skim.app,
% the filename is not even searchable : entering "etocsnippet"
% in the PDF viewer search form does not find the margin texts.

% But I did not want to add to the filename the section number,
% or perhaps even the page number (which could have been perilous
% and I did not want to have to test and experiment, as I have
% done enough for today with these code snippets).

% In Acrobat the description field gives rise to some "tooltip"
% display on hover, which displays the description field.

\newcounter{snippet}%[section]
\stepcounter{snippet}
\makeatletter
\newcommand\snippetno{%
  \ifnum\value{snippet}<10 0\fi\the\value{snippet}%
%%%  emulating former manual mark-up (with reset at each section) but I drop this
%%%  \ifnum\value{snippet}>0 -\@Alph{\numexpr\value{snippet}+\@ne\relax}\fi
}
\makeatother

\usepackage{colorframed}% fix color issues with framed.sty (JFB 2022)
\colorlet{shadecolor}{gray!10}
\usepackage{centeredline}% custom macro now in public package
\usepackage{xinttools}% for easier construction of the doubly hyperlinked cs names

\usepackage{etoc}  % (loads multicol)
% There is clearly a bug of \singlespacing to do this \vskip\baselineskip.
% What then if one goes from double to onehalf spacing? no such adjustment
% in \onehalfspacing? Not coherent.  And caused me a lost of half an hour
% to first spot the problem (with "inline" TOCs first), then understand
% that it originated into the setspace.sty commands, then waste time
% canceling the hook locally and finally do this after going into checking
% setspace.sty.
\def\etocbeforetitlehook{\setstretch{1}}

% for etoc's own default line styles. <1.08b had \partname by default but this
% does not work well with babel+frenchb hence the default is now simply Part.
% Here we can use \partname as we do (did) the documentation for English or German.
% Careful with the customization of \partname done by scrdoc class! (obsolete remark)
\renewcommand{\etocpartname}{\partname}
% see the \AtBeginDocument with \addto\captionsngerman etc...

%--------
% 10 octobre 2013:
\AtBeginDocument{\addtocontents{toc}{\protect\hypersetup{hidelinks}}}

%--------
% add-ons for the new section `surprising uses of etoc' (2013/01/24)
% use of \the\value rather than \arabic due to paranoia in 2023.
\newcounter{visibletoc}
\renewcommand{\etocaftertitlehook}
   {\stepcounter{visibletoc}%
    \phantomsection
    \etoctoccontentsline{visibletoc}{\the\value{visibletoc}}}
% at 1.2a \etocthemaxlevel for test of build with deeplevels option
\etocsetlevel{visibletoc}{\etocthemaxlevel}
%--------
% Statistics on sections and subsections in a part \thispartstats:
% 2 mars 2013
% cette version utilise des box, plutôt que des macros.
% mais on ne peut plus alors changer de police etc...

% 11 octobre 2013, je retire les \color{teal}.

\newsavebox\firstnamei
\newsavebox\firstnumberi
\newsavebox\lastnamei
\newsavebox\lastnumberi
\newsavebox\firstnameii
\newsavebox\firstnumberii
\newsavebox\lastnameii
\newsavebox\lastnumberii
\newcounter{mycounti}
\newcounter{mycountii}

\newcommand*{\thispartstatsauxi}{}
\newcommand*{\thispartstatsauxii}{}
\newcommand*{\oldtocdepth}{}

\newcommand*{\thispartstats}{%
  \setcounter{mycounti}{0}%
  \setcounter{mycountii}{0}%
  \def\thispartstatsauxi{%
         \sbox{\firstnamei}{\footnotesize\etocname}%
         \sbox{\firstnumberi}{\footnotesize\etocnumber}%
         \def\thispartstatsauxi{}}%
  \def\thispartstatsauxii{%
         \sbox{\firstnameii}{\footnotesize\etocname}%
         \sbox{\firstnumberii}{\footnotesize\etocnumber}%
         \def\thispartstatsauxii{}}%
  \begingroup
  \etocsetstyle{subsection}
    {}
    {}
    {\thispartstatsauxii
     \stepcounter{mycountii}%
     \sbox{\lastnameii}{\footnotesize\etocname}%
     \sbox{\lastnumberii}{\footnotesize\etocnumber}}
    {}
  \etocsetstyle{section}
    {}
    {}
    {\thispartstatsauxi
     \stepcounter{mycounti}%
     \sbox{\lastnamei}{\footnotesize\etocname}%
     \sbox{\lastnumberi}{\footnotesize\etocnumber}}
    {{\footnotesize\itshape
      Here are some statistics for this part: it contains \arabic{mycounti}
      section\ifnum\value{mycounti}>1 s\fi{} and
      \ifnum\value{mycountii}>1 \arabic{mycountii} \else no \fi
      subsection\ifnum\value{mycountii}>1 s\fi. The name of
     the first section is
     ``\unhbox\firstnamei{}'' and the corresponding number is
     ``\unhbox\firstnumberi''. The name of the last section is
     ``\unhbox\lastnamei{}'' and its number is
     ``\unhbox\lastnumberi''.
     \ifnum\value{mycountii}>0 The name of
     the first subsection is
     ``\unhbox\firstnameii{}'' and the corresponding number is
     ``\unhbox\firstnumberii''. The name of the last subsection is
     ``\unhbox\lastnameii{}'' and its number is
     ``\unhbox\lastnumberii''.\fi
     \par}}
  \etocinline
% october 10, 2013.
  \etocsetnexttocdepth {2}%
  \etocsettocstyle {\pdfbookmark[1]{Statistics}{\thepart.STATS}}{}
  \localtableofcontents
  \endgroup
}
%--------
% add-ons pour les TOC comme TikZ mind map, tree ou molécules
% hyperlinks to source code... added November 20, 2022
% works in sync with macrocode hacks explained after \StopEventually
% which were added in August 2022
% imported/adapted from code originally added to xint.dtx

% FINALLY, after many hesitations and great suffering with \marginpar
% I decide to simply divide the name into two parts and use two
% distinct hyperlinks, so as to not render the reading to painful.

% use a slightly different colour for second half?
% MEMO: we can change \ttfamily as hyperref uses a scope limiting group.
% Modified 2023/03/20 to devote the left two-thirds to linking to the user manual.
\makeatletter % for \on@line
\DeclareRobustCommand\csb[1]{%
    \edef\nbforuser{\the\numexpr2*\xintLength{#1}/3}%
    \ifcsname r@#1\endcsname
        \hyperref[#1]{\ttfamily\hyphenchar\font45 \char`\\ \xintKeepUnbraced{\nbforuser}{#1}}%
        \ifcsname r@etocmacro-#1\endcsname
          \hyperref[etocmacro-#1]{\ttfamily\hyphenchar\font45 \xintTrim{\nbforuser}{#1}}%
        \else
          % for .toc suffixed macros
          \ifcsname r@etocmacro-\xintTrimUnbraced{-4}{#1}\endcsname
            \hyperref[etocmacro-\xintTrimUnbraced{-4}{#1}]{\ttfamily\hyphenchar\font45
                                                           \xintTrim{\nbforuser}{#1}}%
          \else
% 2023/02/27 also catch non existing destinations in source code
            {\fboxsep-\fboxrule\color{Orchid}%
              \fbox{\ttfamily\hyphenchar\font45 \xintTrim{\nbforuser}{#1}#1}%
             }%
            \ifcsname r@etocname\endcsname
              \expanded{\noexpand\AtEndDocument
                         {\noexpand\PackageError{etoc}{Pas de référence dans
                             le code à #1\on@line}%
                                                      {Corriger!}
                         }%
                       }%
            \fi
%            \hyperref[#1]{\ttfamily\hyphenchar\font45 \xintTrim{\nbforuser}{#1}}%
          \fi
        \fi
    \else
% 1.1a, updated 2023/01/22 1.2
          {\fboxsep-\fboxrule\color{Orchid}%
           \fbox{\ttfamily\hyphenchar\font45 \char`\\ #1}%
          }%
% make second run of compilation raise an error if macro name has been
% misspelled so target (in the documentation) does not exist ; but this will
% trigger error first time the documentation is added, one has to make
% one compilation after adding the label and before continuing doc edits
% 2023/01/22 1.2
          \ifcsname r@etocname\endcsname
            \expanded{\noexpand\AtEndDocument
                       {\noexpand\PackageError{etoc}{Pas de référence à #1\on@line}%
                                                    {Corriger!}
                       }%
                     }%
          \fi
    \fi
}
\makeatother

\DeclareRobustCommand\csa [1]
                {{\ttfamily\hyphenchar\font45 \char`\\ #1}}

\newcommand\cshyp[1]{\texorpdfstring{\csa{#1}}{\textbackslash #1}}

\newcommand\csbhyp[1]{\texorpdfstring{\csa{#1}}{\textbackslash #1}}

\newcommand\etoc{%
        \texorpdfstring{{\color{joli}\ttfamily\bfseries etoc}}{etoc}\xspace}
\newcommand\toc{\csb{tableofcontents}\xspace}
\newcommand\localtoc{\csb{localtableofcontents}\xspace}
\newcommand\invisiblelocaltoc{\csb{invisiblelocaltableofcontents}\xspace}
\newcommand\localtocwrdp{\csb{localtableofcontentswithrelativedepth}\xspace}

\newcommand\lowast{\raisebox{-.25\height}{*}}
\newcommand\starit[1]{\csa{#1\lowast}}
\newcommand\staritb[1]{\csb{#1}\lowast}

% 2023/01/23, mais pas la peine de s'embêter avec robust et texorpdfstring
\newcommand\etocrelease[1]{\hyperlink{v#1}{\texttt{#1}}}

\DeclareRobustCommand\ctanpkg[1]
      {\texorpdfstring{\href{https://ctan.org/pkg/#1}{#1}}{#1}}


\hyphenation{
table-of-con-tents
local-table-of-con-tents
local-table-of-con-tents-with-rel-a-tive-depth
etoc-local-list-of-ta-bles-hook
etoc-local-list-of-fig-ures-hook
local-list-of-fig-ures
local-list-of-ta-bles
%
toc-depth
sec-num-depth
con-tents-line
%
etoc-stan-dard-lines
etoc-de-fault-lines
etoc-toc-lines
etoc-set-style
etoc-name
etoc-page
etoc-skip-first-pre-fix
etoc-num-ber
etoc-if-first
etoc-x-if-first
etoc-if-num-bered
etoc-x-if-num-bered
etoc-if-was-empty
etoc-x-if-was-empty
etoc-checks-empti-ness
etoc-no-toc-if-no-toc
etoc-the-name
etoc-the-num-ber
etoc-the-page
etoc-link
etoc-the-linked-name
etoc-the-linked-num-ber
etoc-the-linked-page
etoc-the-link
etoc-set-level
etoc-set-toc-depth
etoc-set-next-toc-depth
etoc-set-toc-depth
etoc-obey-toc-toc-depth
etoc-ig-nore-toc-depth
etoc-depth-tag
etoc-set-tag-depth
etoc-obey-depth-tags
etoc-ig-nore-depth-tags
etoc-toc-con-tents-line
etoc-set-local-top
etoc-stan-dard-dis-playstyle
etoc-ar-ti-cle-style
etoc-book-style
etoc-set-toc-style
etoc-mul-ti-col-style
etoc-mul-ti-col
etoc-lo-cal-mul-ti-col
etoc-toc-style
etoc-toc-style-with-marks
etoc-toc-style-with-marks-nouc
etoc-ruled-style
etoc-ruled
etoc-lo-cal-ruled
etoc-framed-style
etoc-framed
etoc-lo-cal-framed
etoc-in-line
etoc-af-ter-ti-tle-hook
etoc-af-ter-con-tents-hook
etoc-af-ter-toc-hook
etoc-skip-first-pre-fix
etoc-only-on-first
%
etoc-font-mi-nus-two
etoc-font-mi-nus-one
etoc-font-zero
etoc-font-one
etoc-font-two
etoc-font-three
etoc-sep-mi-nus-two
etoc-sep-mi-nus-one
etoc-sep-zero
etoc-sep-one
etoc-sep-two
etoc-sep-three
etoc-mi-nus-two-left-mar-gin
etoc-mi-nus-two-right-mar-gin
etoc-mi-nus-one-left-mar-gin
etoc-mi-nus-one-right-mar-gin
etoc-base-line-spread-mi-nus-two
etoc-base-line-spread-mi-nus-one
etoc-base-line-spread-zero
etoc-base-line-spread-one
etoc-base-line-spread-two
etoc-base-line-spread-three
etoc-toc-line-lead-ers
etoc-ab-brev-page-name
etoc-part-name
etoc-book-name
etoc-above-toc-skip
etoc-be-low-toc-skip
etoc-column-sep
etoc-mul-ti-col-sep
etoc-mul-ti-col-pre-tol-er-ance
etoc-mul-ti-col-tol-er-ance
etoc-de-fault-nb-col
etoc-in-ner-top-sep
etoc-top-rule
etoc-top-rule-col-or-cmd
etoc-in-ner-left-sep
etoc-in-ner-right-sep
etoc-in-ner-bot-tom-sep
etoc-left-rule
etoc-right-rule
etoc-bot-tom-rule
etoc-left-rule-col-or-cmd
etoc-right-rule-col-or-cmd
etoc-bot-tom-rule-col-or-cmd
etoc-bkg-col-or-cmd
etoc-framed-mp-hook
etoc-keep-orig-i-nal-table-of-con-tents
etoc-im-me-di-ate-set-toc-dep-th
etoc-im-me-di-ate-depth-tag
etoc-im-me-di-ate-toc-con-tents-line
etoc-im-me-di-ate-set-local-top
%
next-toc-with-tags
}

% no more \frenchspacing since 2022/08/26

% for illustration only. Not to be recommended in general.
\setcounter{secnumdepth}{4}

% Usage of microtype added for 1.2 release; now that for some time
% due to the business of attachfile I am tied with pdflatex.
\ifnum\Withdvipdfmx=1
\else
% should I check for xetex/luatex ?
\usepackage{microtype}
\fi

\def\etocoption#1{{\color{optioncolor}\bfseries\texttt{#1}}}

\begin{document}
\marginparsep 6bp
\thispagestyle{empty}

\bookmark[named=FirstPage,level=1]{Title page}
% depth tags for title page toc
\etocsettagdepth {preamble}    {part}
\etocsettagdepth {overview}    {section}
\etocsettagdepth {styling}     {section}
\etocsettagdepth {control}     {section}
\etocsettagdepth {examples}    {section}
\etocsettagdepth {advanced}    {section}
\etocsettagdepth {etocandworld}{part}
\etocsettagdepth {code}        {section}

% pour les TOC à la TikZ
\newtoks\treetok
\newtoks\parttok
\newtoks\sectiontok
\newtoks\subsectiontok
\newtoks\subsubsectiontok
\newtoks\tmptok

\newcommand*\appendtotok[2]{% #1=toks variable, #2=macro, expands once #2
  #1\expandafter\expandafter\expandafter{\expandafter\the\expandafter #1#2}}

% 12 et 13 mars 2015 pour la mind map de title page
% pour les Mindmap avec branch color
\def\appendpart #1#2#3{%
   \edef\tmpstuff {\the#1 child [branch color = #3]{\the#2}}%
   #1\expandafter {\tmpstuff }%
}
% for 1.09f mind map on title page
\def\prependpart #1#2#3{%
   \edef\tmpstuff {child [branch color = #3]{\the#2} \the#1}%
   #1\expandafter {\tmpstuff }%
}


% TOC MIND MAP ON TITLE PAGE
\newcount\tikznumberofcurrentgrandchild

% copied originally from http://tex.stackexchange.com/a/232914
%

% \newcount\tikzdeltaofcurrentgrandchild % not needed at 1.2

% 1.2 causes quite a few adjustments as the parts have been modified, there
% are now only 8 of them, and it is not same number of sections too.
% As I don't read TikZ well, I had some trouble, but I take this opportunity
% to clean up some complications from recent layouts which handled some
% sections to lie on circular arcs, as exception to the general rectangular
% rule.  This was because not everything could fit, but I could find
% satisfactorily layout this time, simply inhibiting via depth tags a few
% sections.

\def\tikzmycustomgrowth {%
    \pgftransformreset
    \ifnum\tikztreelevel=1
        \pgftransformrotate{(\pgfkeysvalueof{/tikz/sibling angle})
                             *
                             (\tikznumberofcurrentchild-2)}%
        \pgftransformxshift{\the\tikzleveldistance}%
    \fi
    \ifnum\tikztreelevel=2
        \pgfmathsetmacro\tikzoffsetofcurrentchild{%
          (\tikzsiblingdistance)*(\tikznumberofcurrentgrandchild)
        }%
        \ifdim\tikzoffsetofcurrentchild pt<\tikzlevelheight
            \pgftransformxshift{\tikzlevelwidth/2}
            \pgftransformyshift{-\tikzlevelheight/2+\tikzoffsetofcurrentchild}
        \else
        \pgfmathsetmacro\tikzoffsetofcurrentchild{\tikzoffsetofcurrentchild-\tikzlevelheight}%
        \ifdim\tikzoffsetofcurrentchild pt<\tikzlevelwidth
            \pgftransformxshift{\tikzlevelwidth/2-\tikzoffsetofcurrentchild}
            \pgftransformyshift{\tikzlevelheight/2}
        \else
        \pgfmathsetmacro\tikzoffsetofcurrentchild{\tikzoffsetofcurrentchild-\tikzlevelwidth}%
        \ifdim\tikzoffsetofcurrentchild pt<\tikzlevelheight
            \pgftransformxshift{-\tikzlevelwidth/2}
            \pgftransformyshift{\tikzlevelheight/2-\tikzoffsetofcurrentchild}
        \else
        \pgfmathsetmacro\tikzoffsetofcurrentchild{\tikzoffsetofcurrentchild-\tikzlevelheight}%
        \ifdim\tikzoffsetofcurrentchild pt<\tikzlevelwidth

            \pgftransformxshift{-\tikzlevelwidth/2+\tikzoffsetofcurrentchild}
            \pgftransformyshift{-\tikzlevelheight/2}
        \else
        \pgfmathsetmacro\tikzoffsetofcurrentchild{\tikzoffsetofcurrentchild-\tikzlevelwidth}%
            \pgftransformxshift{\tikzlevelwidth/2}
            \pgftransformyshift{-\tikzlevelheight/2+\tikzoffsetofcurrentchild}
        \fi\fi\fi\fi
        \pgftransformrotate {\pgfkeysvalueof{/tikz/sibling angle}
                             *
                             \tikznumberofcurrentgrandchild}%
      \global\advance\tikznumberofcurrentgrandchild by1
    \fi
}

% % % version circulaire utilisée avec les versions 1.08a--1.09e du manuel.
% \def\tikzmycustomgrowth {%
%   \pgftransformreset
%   \ifnum\tikztreelevel=1
%     \pgftransformrotate {126+(\pgfkeysvalueof{/tikz/sibling angle})*(\tikznumberofcurrentchild-1)}%
%   \fi
%   \ifnum\tikztreelevel=2
%     \pgftransformrotate {(\pgfkeysvalueof{/tikz/sibling angle})*(2+\tikznumberofcurrentgrandchild)}%
%     \global\advance\tikznumberofcurrentgrandchild by 1
%  \fi
%  \pgftransformxshift {\the\tikzleveldistance}%
% }

\newcounter{partco}
% 1,2,3,4,5,... -> 1,2,3,1,2,3,1,2,3
\def\pseudomodthree #1{\numexpr #1 + 3 - 3*((#1+1)/3)\relax}


\newbox\TitlePageMindmapTOC

\etocsetstyle{part}
  {\etocskipfirstprefix}
  {\ifcase\pseudomodthree{\value{partco}}%
   \or  \appendpart\treetok\parttok {Dandelion!50}%   first  (was teal!60 until 1.09f)
   \or  \appendpart\treetok\parttok {teal!40}% second (was yellow!80 until 1.2)
   \else\appendpart\treetok\parttok {green!40}%  third
   \fi
   }
  {\stepcounter{partco}%
   \edef\treenode{node
                  {\noexpand\textbf{\etocifnumbered{\unexpanded\expandafter{\etocthelinkednumber}.}{}
                   \unexpanded\expandafter{\etocthelinkedname}}}}%
   \parttok\expandafter{\treenode}}
  {% 1.09f used \prependpart for the last... reverted at 1.2,
   % better to append, avoids overlaps by rays of some balls
   \ifcase\pseudomodthree{\value{partco}}%
   \or  \appendpart\treetok\parttok {Dandelion!50}%   first
   \or  \appendpart\treetok\parttok {teal!40}% second
   \else\appendpart\treetok\parttok {green!40}%  third
   \fi
   }

\etocsetstyle{section}
  {}
  {}
  {% define the section node
     \edef\childnode{child {node
% The Bitter font does not have bold italic
% Adding \baselineskip setting, and \endgraf to activate because \par causes
% ! Paragraph ended before \tikz@collect@child@code was complete.
% There must be some way to configure the TikZ node but I don't have
% the time to go into its documentation.
       {\baselineskip10pt\noexpand\itshape%\noexpand\bfseries
        \unexpanded\expandafter{\etocthelinkedname}\hfil\break
         p. \unexpanded\expandafter{\etocthelinkedpage}\noexpand\endgraf
       }%
                           }%
                    }%
   \appendtotok\parttok\childnode
   }
  {}

% title page toc
% 1.09f used a prepend for last part so we needed to delay
% the insertion of the root node to after the treetok had
% been finished.
% 1.2 uses append always so we can initialize here
\treetok{\node [root concept]{\normalfont{The \etoc package}\par {\normalsize\textsc
    {Jean-François Burnol}\par \ttfamily jfbu (at) free (dot) fr}\par
    {\normalsize
     Package version:\par \hyperref[changelog]{\etocpkgversion{} (\etocpkgdate )}\par}}%
   }

\etocsettocstyle
  {\setcounter{partco}{0}}
  {\global\treetok\expandafter{\the\treetok;}}

\etocsetnexttocdepth{section}

% fill in the \treetok
\etocinline
\tableofcontents\label{toc:mindmaptitlepage}

% For debugging
% \newwrite\TOCasTree
% \immediate\openout\TOCasTree=\jobname.toctree
% \immediate\write\TOCasTree{\the\treetok}%
% \immediate\closeout\TOCasTree

\tikzset {branch color/.style={concept color=#1!white,
                               every child/.append style={concept color=#1!white!30!white,
                                                          opacity=0.3, text opacity=1},
                             },
          % ajout pour versions depuis 1.08g
          level width/.store in=\tikzlevelwidth,
          level height/.store in=\tikzlevelheight,
         }%
\global\setbox\TitlePageMindmapTOC\hbox {%
\resizebox{\dimexpr\paperwidth-1cm\relax}!{
\begin{tikzpicture}[mindmap,
                    text width=2cm,
                    align = flush center,
                    % pour 1.09 je reviens à version circulaire simplifiée
                    % pour 1.09f je reviens à version rectangulaire
                    growth function=\tikzmycustomgrowth,
                    nodes={concept},
% trying cyan I get some surprising brutal color change
% much more visible than with orange
                    concept color=yellow!50,% orange!60 until 1.2
                    % root concept/.append style={font=\huge, text width = 6cm},
                    root concept/.append style={font=\Large, text width = 5cm},
                    % level 1/.append style={level distance=7cm, sibling
                    level 1/.append style={level distance=6cm,
                                           sibling angle=360/8},% 8 parties
                    % level 1 concept/.append style={font=\Large, text width = 3cm},
                    % ancienne version circulaire
                    % level 2/.append style={level distance=12.5cm, sibling angle=360/39},%
        % pour version rectangulaire, par tâtonnements:
        % réactivée pour 1.09f (étonnamment, juste quelques petits ajustements, mais ça
        % a tout de même pris pas mal de temps...)
        level 2/.append style={level width=21cm,
                               level height=30cm,
                               sibling distance=2.12cm,% à ajuster manuellement
                               % 1.09f pour essayer certaines parties en
                               % circulaire; plus besoin pout 1.2
                               % level distance=10cm,% distance depuis le centre !
                               % sibling angle=12,% à ajuster manuellement
                               },
        level 2 concept/.append style={text width=2cm},
                   ]
\the\treetok
\end{tikzpicture}%
}%
}% end of \hbox
% On l'envoie au shipout
\AddToShipoutPictureFG*{\put(.5\paperwidth,.5\paperheight)
                        {\makebox(0,0){\box\TitlePageMindmapTOC}}}
% trigger first page
\noindent\null\par\vskip-5cm\hbox{\hypertarget{FRONTPAGE}{}}\vskip5cm

% % for standard TOC
% \etocstandardlines
% \etocclasstocstyle
% \tableofcontents

% reset toc global to class default and line styles to etoc default
\etocdefaultlines
\etocclasstocstyle

\clearpage
\etocdepthtag.toc {preamble}

%----
% MAIN TOC
% made invisible at 1.2
\invisibletableofcontents \label{toc:main}


\part*{\etoc}
\addcontentsline{toc}{part}{\etoc (read this first)}

\onehalfspacing

\begin{shaded}\small
  % lien pour pour les "attachment annotations"
  % https://helpx.adobe.com/acrobat/using/comments.html
  %
% Memo: https://english.stackexchange.com/questions/42370/is-two-thirds-plural
% Yes and no. Yes, when you're talking about multiples of fractions eg. two
% thirds they are plural. But when you're talking about a portion of a single
% item, that item is singular.
% 1). One third of the pizza was eaten. (part of one pizza was eaten)
% Two thirds of the pizza was eaten. (part of one pizza was eaten)
% The subject is pizza - singular. If you have one third of a pizza, and I have
% one third of that same pizza we have two thirds (plural) of one pizza
% (singular).
% Of course this changes when the subject becomes plural:
% One third of two pizzas were eaten. (part of two pizzas were eaten)
% 2). One third of the visitors were men. (multiple visitors were men)
% Two thirds of the visitors were men. (multiple visitors were men)
% The subject in this case - men - is plural.
%
% Cependant j'ai un doute à cause de «the first» qui en française se traduirait
% par un pluriel «les premiers deux-tiers» et ensuite on aurait envie de mettre
% un pluriel; mais de toute la Grammaire n'a pas de Logique ! Tout le monde le
% sait !
%
  The command names throughout
  the user documentation which are displayed
  {\textcolor{RoyalBlue}{with this colour}} are doubly hyperlinked:
  the first two-thirds of the command name hyperlinks to the user documentation, and the
  remaining third part hyperlinks to the source code.  You can try it out now:
  \csb{localtableofcontents}.  But read this first: if you get lost
  inside the source code, clicking on control sequences displayed
  {\textcolor{macrocodelinktouserdoccolor}{with this colour}} brings
  you back to the part of the user manual discussing that specific
  command.  \ifnum\NoSourceCode=1 (but this PDF does not include the
    source code) \fi
\end{shaded}


\section*{Abstract}

%\renewcommand\abstractname{}

%\begin{abstract}
\begingroup
\leftskip1cm
\rightskip1cm

With \etoc loaded, \csb{tableofcontents} can be used multiple times and
an added command \csb{localtableofcontents} allows to typeset ``local''
tables of contents, i.e. having their scope limited to the last
sectioning command encountered.

No auxiliary file is used additionally to the standard \texttt{.toc}
file.  Release \etocrelease{1.2} provides EXPERIMENTAL additions
\csb{locallistoffigures} and \csb{locallistoftables} which also use
only the \texttt{.toc} file.

Such local TOCs or ``Lists Of'' typically need to adopt a ``display
style'' (i.e. the way the title is rendered, whether it should add
itself an entry in the \texttt{.toc} file, ...) somewhat distinct from
the global TOC.  The release \etocrelease{1.2} default adapts
automatically the titles of local TOCs to their depths in the
sectioning hierarchy.  Should the need arise to customize such
``display style'', full control is allowed by package commands.

Regarding how the individual ``contents lines'' are handled, here again
complete control is given to the user to define from the ground-up how
to use the \emph{name}, \emph{number}, and \emph{page number} for each
entry, according to their ``levels'' (i.e. part, chapter, section,
subsection, ...).  As this requires some \LaTeX{} fluency, many examples
which can serve as starting points are attached to the PDF
documentation as extractible files.

Loading \etoc per itself modifies nothing to ``contents lines''
rendering from the class default or changes from other packages.  But
full usage of the package allows spectacular effects such as displaying
TOCs as trees or mind maps.

%\end{abstract}
\endgroup

%\clearpage

\setstretch{1}

\section*{License}
\addcontentsline{toc}{section}{License}

\begingroup
\ttfamily
\hyphenchar\font -1
           \parindent0pt
           \obeyspaces\obeylines %
\etocLicense\endgroup

\onehalfspacing
\clearpage
\onehalfspacing
\etocignoredepthtags
\etocsettocdepth {subsubsection}

\etocdepthtag.toc{overview}
\part{Overview}\label{part:overview}

\thispartstats

\etocdefaultlines
\etocsettocstyle{}{}
\localtableofcontents \label{toc:overview}

\section[\csbhyp{(local)\-tableofcontents}]{The \csbhyp{tableofcontents},
  \csbhyp{localtableofcontents} and other main package commands}

\begin{description}
\item [\csb{tableofcontents}] can be used arbitrarily many times in the
  document,

\item [\csb{localtableofcontents}] produces tables of contents which are
  limited in scope by the nearest preceding sectioning command,%
%
\footnote{After adding a \localtoc in-between existing ones, the first
  compilation will typeset at its location a pre-existing next one; only at
  second compilation will the contents match the location.  Hence often a
  third compilation is needed for document to stabilize.  And if the ``to toc''
  mechanism is active (see the discussion of \csb{etocsetup} option
  \etocoption{localtoctotoc} and
  similar options), only on second compilation is a new entry made in the
  \texttt{.toc} file so three compilations is always a minimum.  If one
  starts compilations from a given source, and no auxiliary files, the first
  compilation prepares the |.toc| file, the second typesets the main and local
  TOCs, possibly changing page numbers due to added contents, and only at the
  third compilation will things perhaps stabilize, and this third step is
  surely needed in case of \etocoption{localtoctotoc}. \ctanpkg{latexmk} is highly
  recommended.}


\item [\csb{etocsettocstyle}\marg{before\_toc}\marg{after\_toc}] defines
  (from the ground up, completely) the TOC titles, or more generally
  everything either before or after the actual TOC contents,

\item [\csb{etocsetstyle}\marg{levelname}%
  \marg{start}\marg{prefix}\marg{contents}\marg{finish}] defines (completely,
  from the ground up) arbitrarily the way the \csa{contentsline} entries in
  the |.toc| file are rendered, depending on their first argument, which is a
  `level name' such as |part|, |chapter|, |section|, |subsection|, \dots

  It is possible to create new levels or re-assign the numerical level of a
  named one via \csb{etocsetlevel}\marg{levelname}\marg{number}, thus opening
  the way for sophisticated (ab)-uses of the data stored in the |.toc| file.

\item [\csb{etocname}, \csb{etocnumber}, \csb{etocpage}] are free to use
  arbitrarily in the \csb{etocsetstyle} \marg{prefix} and \marg{contents}
  arguments for a given contents line level name, they stand for what will be
  extracted by \etoc from the actual data which is stored in the |.toc| file
  and is a bit entangled there (for the first two).
\end{description}

%% \vskip-\baselineskip\vskip0pt % sigh LaTeX spaces !

Throughout this documentation ``layout'', ``display'', ``TOC style'' always are
synonyms and refer roughly to how the TOC title is typeset.  And ``line
styles'' refer to how each individual entry in the TOC will be rendered
according to its ``level''.  Whenever ``TOC style'' is mentioned it is for the
title related things, else the documentation will say ``line styles''.

\csb{etocsetstyle} is for line styles and it requires \LaTeX{} fluency.  It is
however absolutely not required to use it: by default \etoc does not intervene
at all into the rendering of the contents lines.  For example, one can use
packages such as \ctanpkg{tocloft} to customize these contents lines as wished.

\csb{etocsettocstyle} is for styling the titles (and all things related to
material before and after the actual TOC contents).  It was originally
conceived mainly for being used after the main document TOC (assuming it comes
first).  By default \etoc renders the main TOC as specified by the class it
knows about.  But for example in a |book|-class document, one does not want to
use a chapter-like heading for a local TOC in a section.  Hence the need for
\csb{etocsettocstyle}.  But if used in the preamble it will apply to the main
TOC too (if it comes first in the document body), hence its usage has to be
delayed or stored into some command, else one has to insert branches in the
original definition to query the kind of TOC it is applied to.

With \etocrelease{1.2} some utilities facilitate using
\csb{etocsettocstyle} only once in the preamble and branch according to
whether it is handling a main document TOC or a local one.  But the macro was
really initially conceived to be used for local TOCs once the main TOC was
typeset (commands are provided to restore the default configuration in time
for a main TOC at end of document).  There is no command to customize the
titles only for local TOCs from the preamble.

With \etocrelease{1.2} an effort has been made to make using
\csb{etocsettocstyle} for local TOCs purely an option: by default the package
adopts a style for local headings which takes into account the local top
level.  This corresponds to the command \csb{etocetoclocaltocstyle}, which is emitted
by default by the package.

Furthermore \etocrelease{1.2} detects \ctanpkg{tocbibind}%
%
\footnote{Support for \ctanpkg{tocloft} customization of contents lines was
  already in place for many years; the compatibility with \ctanpkg{tocbibind}
  was added only at \etocrelease{1.2} and required to update the
  \ctanpkg{tocloft} related code.}
%
and executes a compatilibity layer so that this package can be used with
hopefully the same result as in the main document classes.  Package options
\etocoption{maintoctotoc}, \etocoption{localtoctotoc},
\etocoption{localloftotoc} and \etocoption{locallottotoc} trigger ``to toc''
mechanisms even without \ctanpkg{tocbibind} if desired, directly at \etoc
level.  The starred variants of the table of contents and ``list of'' commands
will ignore the status of these options, as in the \ctanpkg{memoir} class.


\section[\csbhyp{locallistof\-(figures\textbar\-tables)}]{The \protect\etocrelease{1.2}
  \csbhyp{locallistoffigures} and \csbhyp{locallistoftables} commands}
\label{locallistoffigures}
\label{locallistoftables}
\label{etocsetup}

The major novelty with \etocrelease{1.2} is the addition of
\csb{locallistoffigures} and \csb{locallistoftables}.

\begin{framed}
  The following major problem is known with the current implementation:
  \csb{locallistoffigures} and \csb{locallistoftables} actually list the
  figures, respectively the tables, say in a given \csa{section} which are
  \textbf{TYPESET THEREIN}, which is not necessarily the same figures, tables,
  which in the \LaTeX{} source are located \textbf{``WITHIN'' THAT SECTION}.

  Recall that \LaTeX{} does not have a structured representation of the
  document (despite what many people like to think), so there is no
  pre-existing official way from inside a table to know in which section or
  subsection it is defined.  And figures and tables are \emph{floating}.

  If a figure, for example, floats to next page, and the section were it was
  \emph{defined} is followed on the initial page by another one, then a
  \csb{locallistoffigures} in the first section will NOT see the figure which
  has drifted to next page! That floating figure will be listed by a
  \csb{locallistoffigures} in the NEXT section!

  Now, if all sections are equipped with \csb{locallistoffigures} this current
  ``feature'' of \etoc means that all figures will be accounted for and one
  will be able to see in which section they physically reside after
  typesetting!

   Which is nice but perhaps counter intuitive.

   The source of this problem is well-understood by package author but
   addressing the issue is delayed probably for some months, by lack of time
   and ressources; or may remain a permanent ``feature'' as the author does not
   intend to hack in any way into code for floats, or even captions.

   Here is a non-\etoc file you can play with and which illustrates the
   mechanism:
\begin{verbatim}
\documentclass{article}
\begin{document}
\tableofcontents % the table of contents will show the "table" entry
                 % as belonging to **second** section
\section{first}
\begin{table}[p]
  some tabular
  \makeatletter
  % add some entry in the toc file, like a subsection would do
  \write\@auxout{\string \@writefile {toc}
                         {\protect \contentsline {subsection}{table}{\thepage }{}}}
  \caption{table}
\end{table}

\section{second}
\end{document}
\end{verbatim}
\end{framed}
\begin{itemize}
\item This is experimental code and the user interface as well as the
  output may change.
\item It is mandatory to load \etoc with option \etocoption{lof} for
  \csb{locallistoffigures} and \etocoption{lot} for \csb{locallistoftables}.
\item \etoc does not interfere whatsoever with \csa{listoffigures} and
  \csa{listoftables}, and can not customize them in any way.
\item \etoc still uses no additional auxiliary file, it uses only the
  |.toc| file.
\item This is experimental code and the user interface as well as the
  output may change.
\item The new command \csb{etocsetup} allows to configure at any
  location in the preamble or in the document body the boolean options
  \etocoption{maintoctotoc}, \etocoption{localtoctotoc},
  \etocoption{localloftotoc}, \etocoption{locallottotoc}, and
  \etocoption{ouroboros} which can also be issued as package options.
  The first four default to |false|, except with the \ctanpkg{memoir}
  class, in which case they are set to |true|, or when
  \ctanpkg{tocbibind} is detected, in which case they are set to
  |true| depending on the setting of the \ctanpkg{tocbibind} options.
\item The \etocoption{ouroboros} option defaults to |true|.  When set
  to |false|, local TOCs which have been added to the |.toc| file due
  to \etocoption{localtoctotoc} will \emph{not} list themselves (they
  will still list entries from local TOCs at deeper levels in their
  scope, and the ``lists of'' at their same level, and are listed in
  the main TOC, the only thing is that they don't show themselves in
  themselves).%
%
\footnote{It is complex to try to anticipate all scenarii, but in general, it
  is expected this behavior may cause the |.toc| file to need more time to
  stabilize when a new local TOC is added in the midst of a document having
  already a bunch of them.}
%
The default is that they \emph{do} list themselves, hence the name
\etocoption{ouroboros}.  It has no impact on the main TOCs, use their
starred variant to inhibit the self-display, but then why have issued
\etocoption{maintoctotoc} in the first place?
\item An effort has been made to facilitate as much as possible
  customization by the user, i.e. via commands without |@| letter.
  However this documentation will only list their names with very
  brief comments at the appropriate place and the reader is expected
  to check in the source code to understand better what they are for.
\item This is experimental code and the user interface as well as the
  output may change.
\item For example, the actual figure entries or table entries use by
  default the code from the main LOF or LOT; but one may prefer to
  render them in a way taking into account the local ``list of''
  scope: for example in a section, perhaps use the same style as
  subsections.  This is possible and is explained briefly later.
\item Although the default ``\etoc'' choices for local titles should
  be hopefully satisfactory in most cases, it is also possible to tell
  \etoc to try to use emulation from the document class via the
  command \csb{etocclasstocstyle}.  An effort has been made to obtain
  something which works at one level deeper than the ones under
  \csa{part}.  For example with \ctanpkg{KOMA-script}, we use the
  option |leveldown|.  However this will not really work for deeper
  local ``lists of''.%
%
\footnote{And with \ctanpkg{KOMA-script} at version \texttt{3.30} or later the
  fact that unnumbered sections reset the subsection counter will cause bad
  problems in a \texttt{scrbook} document if a TOC, local to a \csa{subsection}
  uses a title which is un unnumbered section!}
%
But for some document using local ``lists of'' only for chapters or
for sections in classes without chapters, this \csb{etocclasstocstyle}
may be appropriate as it may allow the user to use the class interface
for advanced control of the marks or other details.
\item The \etoc document class agnostic default, from
  \csb{etocetoclocaltocstyle} which is automatically issued at package
  loading time, is completely customizable.
\item This is experimental code and the user interface as well as the
  output may change.
\item If using for example all three of \csb{localtableofcontents},
  \csb{locallistoffigures} and \csb{locallistoftables}, in the same
  location after a division heading, and if the ``to toc'' related
  options either from \etoc or from \ctanpkg{tocbibind} are used, then
  \csb{localtableofcontents} must be the first one in order to be able
  to list the other two (and itself).  It can not see the ``lists of''
  coming before itself at the same division level.
\item Regarding the TOC title style, \etoc knows the standard classes,
  the \ctanpkg{KOMA-script} main classes and the \ctanpkg{memoir}
  class.  In an unknown class it will use the code from the |article|
  class emulation.  For the local TOCs and local ``lists of'' it uses
  as with the known classes its own class-independent code from
  \csb{etocetoclocaltocstyle}.
\item One can tell \etoc to not replace the original
  \csa{tableofcontents} via \csb{etockeeporiginaltableofcontents} (it
  will still be possible to use \csb{etoctableofcontents}), but the
  non-etoc \csa{tableofcontents} is usable only if document does not
  use \csb{locallistoffigures} or \csb{locallistoftables} as the
  latter two insert entries for figures, resp.\@ tables, in the main
  |.toc| file and only \etoc's \csb{tableofcontents} knows to ignore
  them.
\item This is experimental code and the user interface as well as the
  output may change.
\end{itemize}

\section{The \csbhyp{etocsettocstyle} command}
\label{etocsettocstyleintro}

This is a command with two mandatory arguments:
\centeredline{\csb{etocsettocstyle}\marg{before\_toc}\marg{after\_toc}}
The \marg{before\_toc} part is responsible for typesetting the
heading, for example it can be something like
\starit{section}|{\contentsname}|.  Here is an example of input:
\begin{verbatim}
\etocsettocstyle
   {\section*{Local table of contents}}%
   {}% don't do anything special after the toc contents
\end{verbatim}

Once issued it will have an impact on all next usages of \localtoc (or \toc)
until it is used again (or some related command).

Generally speaking the \marg{before\_toc} part should leave \TeX{} in
``vertical mode'': the line styles (either from the standard classes or the
package default ones) all expect to get started in `vertical mode'.

For more documentation of this and related commands see first
\autoref{sec:compatoverview} then
\autoref{sec:tocstyle} for the more detailed pre-\etocrelease{1.2} documentation.

Only daring people will continue reading documentation as it now starts
telling how to truly activate \etoc power.

\section{The \csbhyp{etocsetstyle} command}
\label{etocsetstyleintro}

A distinction must be made between the \emph{line styles}, \emph{i.e.} the way
the name, number and page numbers (aka \etoc-provided \csb{etocname},
\csb{etocnumber}, and \csb{etocpage}) are used at each level, and the \emph{toc
  display style} (for lack of a better name) which tells how the title should
be set, whether an entry in the |.toc| file should be made, whether the
contents should be typeset with multiple columns, etc... the latter is governed
by the command \csb{etocsettocstyle} (and related commands) which has already
been mentioned, and the former by the command \csb{etocsetstyle} with is the
core of \etoc functionality.

It has five mandatory arguments.
%
\centeredline
{\csb{etocsetstyle}\color{blue}\marg{levelname}%
  \marg{start}\marg{prefix}\marg{contents}\marg{finish}}
%
The first one is the name of the sectional unit: a priori known names are
|book|, |part|, |chapter|, |section|, |subsection|, |subsubsection|,
|paragraph|, and |subparagraph|.  Any other name can be declared and
assigned to a (numeric) level via the \csb{etocsetlevel} command.%
%
\footnote{\etoc issues automatically
  \csb{etocsetlevel}\texttt{\string{appendix\string}\string{0\string}} (or wit
  h |1| if the document has no \csa{chapter} command), since
  \etocrelease{1.2}. Formerly this was done only with class
  \ctanpkg{memoir}.}

The four other arguments of \csb{etocsetstyle} specify: 1) \emph{what to do
  when this level is first encountered, down from a more general one,} then 2)
\& 3) (two arguments, a `prefix' and a `contents') \emph{how to use for this
  level the \csb{etocname}, \csb{etocnumber} and \csb{etocpage} parsed data,}
and 4) \emph{the last argument is the code to execute when a division unit of
  higher importance than the defined level style is encountered.}

Notice that this means that virtually \etoc manages a kind of tree-like
substratum which is abstracted from the `flat' structure of the |.toc| data.

You should now read \autoref{sec:linestyles} for the detailed documentation.

\section{No auxiliary file is used beyond the TOC file}
\label{sec:compatoverview}

An important characteristic of \etoc is that it is allows many different TOCs
in the same document, \emph{using only one} |.toc| \emph{file}!

\begingroup
\setcounter{mycounti}{0}%
  \etocinline
\etocsetlevel{part}{1}
\etocsetlevel{chapter}{1}
\etocsetlevel{visibletoc}{0}
\etocsetstyle{visibletoc}
    {}
    {\stepcounter{mycounti}}
    {}
    {}
\etocsettocstyle{}{}
\etocsetnexttocdepth{0}
\tableofcontents
The present documentation contains \arabic{mycounti} visible tables of
contents (and a few invisible ones) and uses only one |.toc| file!%
%
\footnote{and the counting itself has been achieved by a table of contents
  which was inserted in this paragraph! See \autoref{sec:tocoftocs}.}
\endgroup

However, each \localtoc or \toc command will trigger the execution of the
\emph{full contents} from the |.toc| file.  The effect of \localtoc as well as
the enforcement of the line styles as defined via \csb{etocsetstyle} are
achieved via suitable redefinition of the \csa{contentsline} \LaTeX{} macro.
But everything else present in the |.toc| file will be executed, as it is not
possible for \etoc to control in any way what is present in the |.toc|
file beyond \csa{contentsline} entries.

So one should think twice before adding manually extra commands to the |.toc|
file.  See \autoref{sec:addingtotoc} for further discussion.




\section{Compatibility mode}\label{subs:compat}
\label{etoctoclines}
\label{etocstandardlines}
\label{etocclasstocstyle}
\label{etocetoclocaltocstyle}
\label{etocusertocstyle}
\label{etoclocallistoffigureshook}
\label{etoclocallistoftableshook}

\etoc starts in a ``compatibility mode'', which means that it does not at all
interfere with how the commands from the |.toc| file get executed as long as
it has not been told explicitly to do so.%
%
\footnote{\label{fn:compat}for the ``toc display style'', by this we mean the
  aspects independant from the contents of the \texttt{.toc} file, \etoc checks
  if it knows the class, and then uses emulation code which was added manually
  to its source, and if not it defaults to the |article| class layout.  No
  automated way to recover the global toc display for arbitrary document
  classes is implemented. But \etoc will detect if \ctanpkg{tocloft} has
  customized the TOC title.}

This ``compatibility mode'' stops for matters of the ``toc display style'' as
soon as \csb{etocsettocstyle} is made use of, and for matters of the ``toc
line styles'' as soon as \csb{etocsetstyle} is used for \emph{any} level
(part, chapter, section, ...).  Levels not receiving explicit configurations
will use some pre-defined defaults which are in \etoc source code.

\begin{description}
\item[\csb{etocclasstocstyle}] sets the `main toc layout' to be as without
  |\usepackage{|\etoc\unskip|}|.  Local TOCs will also obey the document class
  style but with an attempt to use a heading one level down.  This tries to
  adapt to being in the top level below \csa{part} (i.e. in a \csa{chapter} or
  \csa{section}) but is not adapted to deeper local TOCs.

  At \etocrelease{1.2}, previously existing \csa{etocstandarddisplaystyle}
  was made into a deprecated synonym to this (the version from earlier
  releases made no attempt to adapt the style of the local TOCs to the level
  where it is located).

\item [\csb{etocetoclocaltocstyle}] (package default) Activates a heading
  style for local tables of contents (and ``lists of'') which tries to adapt
  automatically to the surrounding level.  It thus by-passes the configuration
  done by \csb{etocsettocstyle} which will then apply only to the main TOC.
  Using again \csb{etocsettocstyle} de-activates this behavior.

\item [\csb{etocusertocstyle}] means to obey the \csb{etocsettocstyle}
  configuration as previously in place, not only for the main TOC but also for
  local ones.  If \csb{etocsettocstyle} has never been used, this means that
  we return to the situation from \csb{etocclasstocstyle}.

\item [\csb{etocstandardlines}] (package default) Sets the `content lines' to be as without
  |\usepackage{|\etoc\unskip|}|.

\item [\csb{etoctoclines}] sets the `content lines' to match the last encountered
  \csb{etocsetstyle} specs.

\item [\csb{etocdefaultlines}] sets the `content lines' to use \etoc pre-defined
  ones.  The denomination is a bit confusing as `default' here means that
  these line styles are the ones defined by default, but not used by
  default\dots{} perhaps \csa{etocfallbacklines} would have been a better name.

  Please be aware that by design the |paragraph| and |subparagraph| linestyles
  are configured by \csb{etocdefaultlines} to display nothing at all.
\end{description}

Naturally \csb{etocsettocstyle} and \csb{etocsetstyle} can be used arbitrarily
many times in the document body (or already in the preamble but there one can
not typeset a TOC; however one can prepare commands which will be activated
later from inside the document body).  And they obey the scope-limiting effect
of \LaTeX{} environments.

For an illustration of using \etoc in compatibility mode see
\autoref{sec:testingcompat}.  And see \autoref{sec:anothercompat} for some
ways to let the line styles use the code from the document class but with some
custom changes.

During expansion  of \csb{locallistoffigures} or
\csb{locallistoftables}, the macros \csb{etoclocallistoffigureshook} resp.\@
\csb{etoclocallistoftableshook} are executed right before typesetting
the entries.  Their default definitions (refer to source code for more info):
\begin{verbatim}
\def\etoclocallistoffigureshook{\etocstandardlines}%
\def\etoclocallistoftableshook {\etocstandardlines}%
\end{verbatim}
means compatibility mode, i.e.\@ the macros \csa{l@figure} and \csa{l@table}
will be the ones involved, as if we were in the global \csa{listoffigures} or
\csa{listoftables}.

If you redefine these ``hook''-macros to do nothing, the figure/table entries
will use the style as appropriate for entries at numerical level one deeper
than the ``local top'': i.e. in a section they will be typeset as if being
subsections.  If you have both \csb{locallistoffigures} and a \localtoc, this
may align better vertically than the \LaTeX{} line style from the global
``Lists Of''.


Note that ``hook'' is used here in a very naive meaning of some macro which is
pre-located somewhere and that one can redefine to obtains various effects.

\section{A list of the commands added at \texorpdfstring{\protect\etocrelease{1.2}}{1.2}}
\label{etocstoretocstyleinto}
\label{etocstorelinestylesinto}
\label{etocstorethislinestyleinto}
\label{etocifislocal}
\label{etocifislocaltoc}
\label{etocifislocallof}
\label{etocifislocallot}
%%\label{etocsettocstyle}
\label{etocifmaintoctotoc}
\label{etociflocaltoctotoc}
\label{etociflocalloftotoc}
\label{etociflocallottotoc}
\label{etocifisstarred}
\label{etoclevel}
\label{etocthelevel}
%%\label{etocthemaxlevel}
\label{etocifunknownlevelTF}
\label{etocdivisionnameatlevel}
\label{etoclocalheadtotoc}
\label{etocglobalheadtotoc}
\label{etocetoclocaltocmaketitle}
%%\label{etocetoclocaltocstyle}
\label{localcontentsname}
\label{locallistfigurename}
\label{locallisttablename}
\label{etocetoclistoffiguresmaketitle}
\label{etocetoclistoftablesmaketitle}
\label{etocclasslocaltocmaketitle}
\label{etocclasslocallofmaketitle}
\label{etocclasslocallotmaketitle}
\label{etocclassmaintocaddtotoc}
\label{etocclasslocaltocaddtotoc}
\label{etocclasslocallofaddtotoc}
\label{etocclasslocallotaddtotoc}

\begin{shaded}\footnotesize
%\setstretch{1}
  One pre-existing command has been modified: \csa{etocstandarddisplaystyle}
  which is now deprecated and replaced by \csb{etocetoclocaltocstyle}.  The
  former behavior was to set also local TOCs to apply the style from the main
  TOC, which basically never works really well.  As explained already one can
  use \csb{etocclasstocstyle} to try to get for top local TOCs a suitable
  behavior, for example in the case of \ctanpkg{KOMA-script} classes, a
  behavior using their |leveldown| option.  But this will not be satisfactory
  for deeper local TOCs or ``lists of''.
\end{shaded}

\DeleteShortVerb\|

First there is \csb{etocsetup}:
\begin{description}
\item [\csb{etocsetup}\marg{key[=true|false],...}] has already been mentioned
  earlier.  It is usable with \etocoption{maintoctotoc},
  \etocoption{localtoctotoc}, \etocoption{localloftotoc},
  \etocoption{locallottotoc}, and \etocoption{ouroboros}, everywhere in the
  document after the package loading.
\end{description}

\MakeShortVerb\|

Then some utilities relative to the 
\csb{etocsetlevel} command:
\begin{itemize}
\item \csb{etoclevel}\marg{levelname} expands to a numeric quantity giving the
  level of a given string argument.  For example \csb{etoclevel}|{section}|
  will usually produce a \TeX{} number denotation of value one.  It is
  provided for matters of programming, as its output format is suitable for
  usage in \csa{ifnum} test.  For typesetting, it should be prefixed
  by the \TeX{} primitive \csa{number}.

\item \csb{etocthelevel}\marg{levelname} expands to a explicit digits
  (possibly prefixed by a minus sign), i.e.\@ it is equivalent to
  |\number|\csb{etoclevel}\marg{levelname} and is provided as a
  convenience. (added at \etocrelease{1.2a})

\item \csb{etocthemaxlevel} expands to either |12| or |6| (default) depending
  on whether the \etocoption{deeplevels} option was used or not.  See the
  documentation of \csb{etocsetlevel} for more. (added at \etocrelease{1.2a})

\item \csb{etocifunknownlevelTF}\marg{levelname}\marg{True}\marg{False} is a
  conditional to test if a level name has been declared to \etoc.
\end{itemize}

Then two utilities to help store and restore toc line styles:

\begin{description}
\item [\csb{etocstorelinestylesinto}\marg{control\_sequence}] This is a
  command with one mandatory argument which must be a control sequence such as
  \csa{foo}.  The macro \csa{foo} is then overwritten with no check if it
  exists already.  Its effect is to store inside \csa{foo} the current toc
  line styles configuration, for all levels at once.  Then inserting \csa{foo}
  in the document will restore all line styles to the state they were in at
  time of usage of \csb{etocstorelinestylesinto}.

\item [\csb{etocstorethislinestyleinto}\marg{name or
    number}\marg{control\_sequence}] Same principle but now \csa{foo} will
  store the line style for the specified level only.  This argumant can be
  numerical or a name.  And thus executing \csa{foo} will then have the same
  effect as re-doing the \csb{etocsetstyle} for that level.
\end{description}

The more numerous additions are relative to usage of \csb{etocsettocstyle},
i.e.\@ customizing the ``display'' style. This mainly means matters relative
to the title of the local TOCs or Lists Of, inclusive of whether they should
add an entry into the |.toc| file matching their titles.  Indeed, please be
aware that as soon as you use \csb{etocsettocstyle} you will have to handle
yourself the support for such behavior.  Of course, as you also control the
options, you don't have to use the provided command layer which tests the
status of these options, but it is provided anyway as public interface.
Indeed all of this is done via commands with no |@| letter in their names, and
the package itself uses this public interface in its implementation of the
default behavior, adjusted to the document class.  The documentation here is
brief, check for more the source code to which the listed commands are
hyperlinked (from the last third of their names).

Some of these commands are defined via batch processing done in loops in the
code, and the hyperlinks only point to some initial dummy definitions, which
were added only to provide such link targets, and one has to read the code
further to discover the actual definitions.

\begin{itemize}
\item \csb{etocifislocal}, \csb{etocifislocaltoc}, \csb{etocifislocallof},
  \csb{etocifislocallot} can be used from inside the \csb{etocsettocstyle}
  first or second argument to select either one of the \marg{True} and
  \marg{False} branches.

\item \csb{etocifmaintoctotoc}, \csb{etociflocaltoctotoc},
  \csb{etociflocalloftotoc}, \csb{etociflocallottotoc}, are conditionals
  matching the options and selecting one of the \marg{True} or \marg{False}
  branches.

\item \csb{etocifisstarred}\marg{True}\marg{False} says from inside the
  \csb{etocsettocstyle} arguments if the toc or `list of' command was in
  starred form.

  The \csb{etocetoclocaltocstyle} and \csb{etocclasstocstyle} have been
  configured so that when a |*| follows a \toc or \localtoc or local ``lists
  of'', its ``to toc'' behavior (if active from \ctanpkg{tocbibind} or \etoc
  own options) is canceled.  They use \csb{etocifisstarred} to this effect.

\item \csb{etoclocalheadtotoc}\marg{levelname}\marg{text} is a synonym for
  \centeredline{\csa{addcontentsline}|{toc}|\marg{@levelname}\marg{text}}
%
  Pay
  attention to automatically added |@| character.%
%
\footnote{Without this syntax, it would not be possible to have all three of
  \localtoc, \csb{locallistoffigures} and \csb{locallistoftables} one after
  the other following a given document heading, due to deep internals of the
  local TOC \etoc mechanism.  Notice that these internal details are
  susceptible to change with no advance notice and the actual implementation
  of \csb{etoclocalheadtotoc} may change.}


  Use this for example in the second argument of \csb{etoclocalmulticol}.%
%
\footnote{There is currently no analog of \csb{etoclocalmulticol} and similar
  commands which would be related to \csb{locallistoffigures} or
  \csb{locallistoftables} as \csb{etoclocalmulticol} is to \localtoc.}

\item \csb{etocglobalheadtotoc}\marg{levelname}\marg{text} is a synonym for
  \centeredline{\csa{addcontentsline}|{toc}|\marg{levelname}\marg{text}}
%
  We have so many commands we can define another useless one\dots{} for
  aesthetic reasons of coherent names\dots{}

\item \csb{etocdivisionnameatlevel}\marg{number} is an expandable construct
  which starts from a numerical level from |-2| to |5| and produces one of
  |book|, |part|, ..., up to |subparagraph| as per the built-in \LaTeX\
  (and standard classes) default assignments (and \ctanpkg{memoir} for
  |book|).

  Under option \etocoption{deeplevels} the numerical level can go up to |11|
  but as there is no standard default for documents with extra sectioning
  commands (e.g. is it using \csa{subsubsubparagraph}? or
  \csa{subsubsubsection}? or some \csa{subivsection}?), the user has probably
  to copy and redo with changes the package definition of
  \csb{etocdivisionnameatlevel} in that case.

\item \csb{etocetoclocaltocmaketitle} is the command used by
  \csb{etocetoclocaltocstyle} which typesets a local ``list of'' title using
  an un-numbered sectioning appropriate to its scope.  See the source code for
  how it looks.

\item \csb{etocetoclistoffiguresmaketitle} and
  \csb{etocetoclistoftablesmaketitle} are similar, see the source code.

\item \csb{localcontentsname}, \csb{locallistfigurename},
  \csb{locallisttablename} are self-explanatory.

\item \csb{etocclasslocaltocmaketitle}, \csb{etocclasslocallofmaketitle},
  \csb{etocclasslocallotmaketitle}, \csb{etocclassmaintocaddtotoc},
  \csb{etocclasslocaltocaddtotoc}, \csb{etocclasslocallofaddtotoc},
  \csb{etocclasslocallotaddtotoc}, well again see source code.
\end{itemize}

Finally there is a command to help store/restore a given display style configuration.
\begin{description}
\item [\csb{etocstoretocstyleinto}\marg{control\_sequence}] This is a command
  with one mandatory argument which must be a control sequence such as
  \csa{foo}.  The macro \csa{foo} is then overwritten with no check if it
  exists already.  Its effect is to store inside \csa{foo} the data configured
  by the last \csb{etocsettocstyle}.  Then inserting \csa{foo} in the document
  will restore the saved toc style.%
%
\footnote{It is impossible to store the style used by  the
  \csb{etocetoclocaltocstyle} for local TOCs.  Only the one for main TOCs,
  which was configured by last usage of \csb{etocsettocstyle} is saved in
  \csa{foo}.  After \csa{foo} is executed, one needs to again issue
  \csb{etocetoclocaltocstyle} if one wants the latter to be active.}
\end{description}



% {\footnotesize (clearing this page as next display must be on one page
%   only)\par}
% \clearpage

\section{A partial list of the package commands}

%\enlargethispage{2\baselineskip}

%\vskip-\baselineskip\vskip0pt




%\parshape 1 -1.5cm \dimexpr\linewidth+3cm\relax
%\begin{minipage}{\dimexpr\linewidth+3cm\relax}
\begin{multicols}{2}\parindent0pt\relax\setstretch{1}%
  \csb{etocbeforetitlehook}\par
  \csb{etocaftertitlehook}\par
  \csb{etocaftercontentshook}\par
  \csb{etocaftertochook}\par
  \csb{etocsettocstyle}\par
  \csb{etocclasstocstyle}\par
  \csb{etocetoclocaltocstyle}\par
  \csb{etocmulticol}\par
  \csb{etocframed}\par
  \csb{etocruled}\par
  \csb{etocsettocdepth}\par
  \csb{etocsettocdepth.toc}\par
  \csb{etocsetnexttocdepth}\par
  \csb{etocdepthtag.toc}\par
  \csb{etocsettagdepth}\par
  \csb{etocobeydepthtags}\par
  \csb{etocdefaultlines}\par
  \csb{etocstandardlines}\par
  \csb{etoctoclines}\par
  \csb{etocsetlevel}\par\columnbreak
\flushright
  \csb{etocsetstyle}\par
  \csb{etocskipfirstprefix}\par
  \csb{etocifnumbered}\par
  \csb{etociffirst}\par
  \csb{etoclink}\par
  \csb{etocthelink}\par
  \csb{etocname}\par
  \csb{etocnumber}\par
  \csb{etocpage}\par
  \csb{etocthename}\par
  \csb{etocthenumber}\par
  \csb{etocthepage}\par
  \csb{etocthelinkedname}\par
  \csb{etocthelinkednumber}\par
  \csb{etocthelinkedpage}\par
%  \csb{etocdisplay}\par
%  \csb{etocframedstyle}\par
%  \csb{etocignoredepthtags}\par
%  \csb{etocignoretoctocdepth}\par
%  \csb{etocimmediatedepthtag.toc}\par
%  \csb{etocimmediatesettocdepth.toc}\par
%  \csb{etocimmediatetoccontentsline}\par
%  \csb{etocinline}\par
%  \csb{etoclocalframed}\par
%  \csb{etoclocalmulticol}\par
%  \csb{etoclocalruled}\par
%  \csb{etocmulticolstyle}\par
%  \csb{etocobeytoctocdepth}\par
%  \csb{etocruledstyle}\par
%  \csb{etoctoccontentsline}\par
%\flushright
  \csb{localtableofcontents}\par
  \mbox{}\llap{\csb{localtableofcontentswithrelativedepth}}\par
  \csb{locallistoffigures}\par
  \csb{locallistoftables}\par
  \csb{tableofcontents}\par
%\vspace{5\baselineskip}\hrule height 0pt
\end{multicols}
%\end{minipage}\par


{\footnotesize\setstretch{1}
The above is not an exhaustive list of all the package user commands.
For example, it does not include most of those added at \etocrelease{1.2}
and which were listed in the previous section.\par
}

\clearpage


\etocdepthtag.toc {styling}
\part{The \etoc styling commands}
\label{part:styling}

\thispartstats

\etocsetstyle{section}
{\begin{enumerate}[leftmargin=.75cm, label=\etocifnumbered
      {{\fboxrule1pt\fcolorbox{green}{white}{\etocnumber}}}{}]}
{\normalsize\bfseries\rmfamily\item}
{\etocname{} (page \etocpage)}
{\end{enumerate}}

\etocsetstyle{subsection}
{\begin{enumerate}[leftmargin=0cm, label=\etocnumber]}
{\normalfont \item}
{\etocname{} (p.~\etocpage)}
{\end{enumerate}}

\etocsetstyle{subsubsection}
{\par\nobreak\begingroup\normalfont\footnotesize\itshape\etocskipfirstprefix}
{\allowbreak\,--\,}
{\etocname}
{.\hfil\par\endgroup\pagebreak[3]}

% 27 janvier 2013 22:30
% je définis les macros (non protégées)
% \etocthename, \etocthenumber, \etocthepage

\etocruledstyle[1]{\etocfontminusone\color{green}%
     \fboxrule1pt\fboxsep1ex
     \framebox[\linewidth]
              {\normalcolor\hss Contents of \autoref{part:styling}\hss}}

\localtableofcontents \label{toc:part:styling}

The two main commands \csb{etocsettocstyle} and \csb{etocsetstyle} can be used
anywhere in the document.  Typically one will render the main global TOC in
one style and local tables of contents in another.  So the commands to style
the local tables of contents will be executed after the main \toc (if it is
first in document) either by direct injection in the document source, or
encapsulated in user commands defined in the preamble.

All commands obey the scope limiting effect induced by \LaTeX{} environments
or the core \TeX |\begingroup/\endgroup| (or braces |{...}|) constructs.

\section{The \csbhyp{etocsettocstyle} and related commands}
\label{sec:tocstyle}

\begingroup
\etocsettocstyle{}{}
\etocstandardlines
\DeclareTOCStyleEntry[numwidth=3em,indent=0em]{tocline}{subsection}
\DeclareTOCStyleEntry[numwidth=3.5em,indent=3em]{tocline}{subsubsection}
\localtableofcontents \label{toc:tocstyle}
\endgroup



\subsection{The \csbhyp{etocsettocstyle} command}
\label{etocsettocstyle}

The basics are explained in \autoref{etocsettocstyleintro}.  Recall that the
syntax is
\centeredline{\csb{etocsettocstyle}\marg{before\_toc}\marg{after\_toc}} and
here is a typical example of use:
\begin{verbatim}
\etocsettocstyle
   {\section*{Local table of contents}}%
   {}% don't do anything special after the toc contents
\end{verbatim}

The first argument to \csb{etocsettocstyle} can also contain instructions to
mark the page headings.  Or it could check to see if two-column mode is on,
and switch to one-column style, and the \meta{after\_toc} part would then
reenact the two-column mode.


The commands to be described next \csb{etocmulticolstyle},
\csb{etocruledstyle}, and \csb{etocframedstyle} all call \csb{etocsettocstyle}
as a lower-level routine, to initiate a \texttt{multi\-cols} environment in
\marg{before\_toc} and close it in \marg{after\_toc}.

\subsubsection{The \csbhyp{etocarticlestyle}, \csbhyp{etocbookstyle},
  and others commands}
\label{etocarticlestyle}
\label{etocarticlestylenomarks}
\label{etocbookstyle}
\label{etocbookstylenomarks}
\label{etocreportstyle}
\label{etocreportstylenomarks}

These are the commands used internally by \etoc in compatibility mode
depending on the document class. For example \csb{etocarticlestyle} instructs
\etoc to use |\section*{\contentsname}| (with marks on the page) and
\csb{etocbookstyle} says to use |\chapter*{\contentsname}|. It can prove
useful to issue \csb{etocarticlestyle} for a \csa{localtableofcontents} inside
a chapter, in |book| class and compatibility mode for the global TOC display
style.

Here is the current list:
\begin{itemize}[nosep]
\item \csb{etocarticlestyle}
\item \csb{etocarticlestylenomarks}
\item \csb{etocreportstyle}
\item \csb{etocreportstylenomarks}
\item \csb{etocbookstyle}
\item \csb{etocbookstylenomarks}
\item \csb{etocmemoirstyle}
\item \csb{etocscrartclstyle}
\item \csb{etocscrreprtstyle}
\item \csb{etocscrbookstyle}
\end{itemize}
The command \csb{etocclasstocstyle} will adapt to the document class.
One can not use the \ctanpkg{KOMA-script} related commands or the
\ctanpkg{memoir} one in standard classes.


\subsubsection{The \csbhyp{etocinline} and \csbhyp{etocdisplay} commands}
\label{etocinline}
\label{etocnopar}
\label{etocdisplay}

With \csb{etocinline}, or its synonym |\etocnopar|, the \localtoc command and
its variants do \emph{not} first issue a |\par| to close the previous
paragraph. Hence, the table of contents can be printed in an inline style; or,
if used only for preparing some token list or macro, it will leave nothing in
the token stream on execution.

Issue \csb{etocdisplay} to return to the default situation that \localtoc and
variants issue a |\par| to switch to vertical mode before typesetting the TOC
title and contents.

Here is an example of an \emph{inline} table of contents, which has only
subsections and uses the |itemize*| environment from \ctanpkg{enumitem} for
them.  The code used is
\begin{verbatim}
And the output is:
\begingroup
    \etocglobaldefs
    \etocsetstyle {subsection}
          {\begin{itemize*}[itemjoin={{; }}, itemjoin*={{, and }}]}
          {}
          {\item [{\bfseries\etocnumber.}] \etocname\ (\emph{p. \etocpage })}
          {\end{itemize*}.}%
    \etocsetnexttocdepth {subsection}%
    \etocsettocstyle {a clone of a local table of contents, originally defined in
                      \autoref{sec:tocstyle}, but here rendered completely
                      differently via an inline \ctanpkg{enumitem} list: }{}%
    \etocinline\tableofcontents \ref{toc:tocstyle}
\endgroup
\end{verbatim}

(observe that on executing the above there is no extra space after the colon
beyond what is intended, and the current paragraph is simply continued)
And the output is:
\begingroup
    \etocglobaldefs
    \etocsetstyle {subsection}
          {\begin{itemize*}[itemjoin={{; }}, itemjoin*={{, and }}]}
          {}
          {\item [{\bfseries\etocnumber.}] \etocname\ (\emph{p. \etocpage })}
          {\end{itemize*}.}%
    \etocsetnexttocdepth {subsection}%
    \etocsettocstyle {a clone of a local table of contents, originally defined in
                      \autoref{sec:tocstyle}, but here rendered completely
                      differently via an inline \ctanpkg{enumitem} list: }{}%
    \etocinline\tableofcontents \ref{toc:tocstyle}
\endgroup

It was needed to use \csb{etocglobaldefs} because the \csa{item} command,
as modified by \ctanpkg{enumitem} closes a group, hence the meaning
of \csb{etocname}, \csb{etocnumber} and \csb{etocpage} would have been lost
after it.

A more impressive example of an inline table of contents (containing the full
contents of this document, which subsections rendered as page footnotes...) is
to be found in \autoref{sec:crazy}.

\subsection{The \csbhyp{etocmulticolstyle}, \csbhyp{etocmulticol},
  and \csbhyp{etoclocalmulticol} commands}
\label{etocmulticolstyle}
\label{etocmulticol}
\label{etoclocalmulticol}

This is a command with one optional and one mandatory argument:
\centeredline{\csb{etocmulticolstyle}\oarg{number\_of\_columns}\marg{heading}}
The
\meta{number\_of\_columns} can go from 1 to 10 (it defaults to 2; if its
value is 1, naturally no |multicols| environment is then created). The
\meta{heading} will typically be some `vertical' material like:
  \meta{heading} = |\section*|\marg{title}
but one may also have horizontal material like |\fbox{Hello World}| (\etoc
adds automatically a |\par| at the end of this ``heading'' argument to
\csb{etocmulticolstyle}). Here is an example:
\begin{verbatim}
\etocmulticolstyle{\noindent\bfseries\Large
                   \leaders\hrule height1pt\hfill
                   \MakeUppercase{Table of Contents}}
\localtableofcontents
\end{verbatim}
After \csb{etocmulticolstyle} all future \csa{tableofcontents} will use the
specified style until modified by renewed usage of \csb{etocsettocstyle} or variants.

A shortcut combining the style specification and the table of contents and not
impacting the styles of later TOCs is:%
%
\centeredline{\csb{etoclocalmulticol}\oarg{number\_of\_columns}\marg{heading}}
%
So the above example can be also obtained using:
\begin{verbatim}
\etoclocalmulticol{\noindent\bfseries\Large
                   \leaders\hrule height1pt\hfill
                   \MakeUppercase{Table of Contents}}
\end{verbatim}
%
It has the advantage that the TOC styling as specified applies only to this
sole local TOC.

And there is also
\csb{etocmulticol}\oarg{number\_of\_columns}\marg{heading} for global TOC.

\subsection{The \csbhyp{etoctocstyle} command}
\label{etoctocstyle}

\centeredline{\csb{etoctocstyle}\oarg{kind}\marg{number\_of\_columns}\marg{title}%
}
%
is the exact equivalent of doing
%
\centeredline{%
\csb{etocmulticolstyle}|[|{\itshape number\_of\_columns}|]|%
|{\kind*{|\itshape title\upshape|}}|}
%
where |kind| is one of |chapter|, |section|, . . . and defaults
to |chapter| or |section| depending on the document class.

As explained above one still has to issue \localtoc to typeset the TOC.  And
the styling, if not enclosed in a scope-limiting group or environment, applies
to subsequent local TOCs.

\subsubsection{The \csbhyp{etoctocstylewithmarks} command}
\label{etoctocstylewithmarks}
\label{etoctocstylewithmarksnouc}

\centeredline{\csb{etoctocstylewithmarks}\oarg{kind}%
              \marg{number\_of\_columns}\marg{title}\marg{mark}%
              }
%
is the exact equivalent of doing
%
\centeredline
{\csb{etocmulticolstyle}|[|{\itshape number\_of\_columns}|]|%
|{\kind*{|\itshape title \ttfamily\upshape\string\markboth%
|{\MakeUppercase{|{\rmfamily\itshape mark}|}}}}|}
%
where |kind| is one of |chapter|, |section|, ... The
actual display of the marks depends on the settings of the
page style.  There is variant \csb{etoctocstylewithmarksnouc}
which does not uppercase.

\paragraph{Do we really want paragraph entries in the TOC?}

\paragraph{really?}

\subsection{The \csbhyp{etocruledstyle}, \csbhyp{etocruled} and
  \csbhyp{etoclocalruled} commands}
\label{etocruledstyle}
\label{etocruled}
\label{etoclocalruled}

The general format of \csb{etocruledstyle} is:
%
\centeredline{\csb{etocruledstyle}%
              \oarg{number of columns}\marg{title of the toc}%
}%
\noindent
The title is horizontal material (the |LR| mode of
\emph{\LaTeX{}, a document preparation system}): if it
does not fit on one line it should be put in a \csa{parbox}  of
a given width.
The green frame for the heading of the table of contents at
the \hyperref[toc:part:styling]{the start of this part} was obtained with:
\begin{verbatim}
\etocruledstyle[1]{\etocfontminusone\color{green}%
     \fboxrule1pt\fboxsep1ex
     \framebox[\linewidth]
              {\normalcolor\hss Contents of this part\hss}}
\localtableofcontents
\end{verbatim}

As a shortcut to set the style with \csb{etocruledstyle} and then issue a
\localtoc, all inside a group so that future table of contents will not be
affected, there is:
%
\centeredline{\csb{etoclocalruled}\oarg{number\_of\_columns}\marg{title}}
%
And there is also \csb{etocruled} for the global TOC.

\subsection{The \csbhyp{etocframedstyle}, \csbhyp{etocframed}, and
  \csbhyp{etoclocalframed} commands}
\label{etocframedstyle}
\label{etocframed}
\label{etoclocalframed}

Same mechanism:
%
\centeredline{\csb{etocframedstyle}\oarg{number\_of\_columns}\marg{title}}
%
and the accompanying shortcut:
%
\centeredline{\csb{etoclocalframed}\oarg{number\_of\_columns}\marg{title}}
%
The
shortcut is used if one does not want to modify the style of the next
TOCs (the other way is to put the whole thing inside braces or a
|\begingroup...\endgroup|; there is also \csb{etocframed} for a
global table of contents).

The entire table of contents is framed.  The title itself is not framed:
if one wants a frame one should set it up inside the \meta{title}
argument to \csb{etocframedstyle} or \csb{etocframed}. The colors for
the background and for the components (top, left, right, bottom) of the
border are specified via suitable |\renewcommand|'s (see
\autoref{ssec:customdisplay}).

A |minipage| is used, hence the produced table of contents isn't compatible
with a page break. For allowing page breaks, use of the commands of
\ctanpkg{mdframed} or \ctanpkg{tcolorbox} in the arguments of
\csb{etocsettocstyle} is recommended.

Examples in this document are on pages \pageref{toc:d},
\pageref{toc:floating}, \pageref{toc:b}, and \pageref{toc:clone}.


\subsection{Customizing the pre-defined toc display styles}
\label{ssec:customdisplay}
\label{etocabovetocskip}
\label{etocbelowtocskip}
\label{etoccolumnsep}
\label{etocmulticolsep}
\label{etocmulticolpretolerance}
\label{etocmulticoltolerance}
\label{etocdefaultnbcol}
%\label{etocinnertopsep}% déjà défini
\label{etoctoprule}
\label{etoctoprulecolorcmd}
\label{etocinnerleftsep}
\label{etocinnerrightsep}
\label{etocinnerbottomsep}
\label{etocleftrule}
\label{etocrightrule}
\label{etocbottomrule}
\label{etocleftrulecolorcmd}
\label{etocrightrulecolorcmd}
\label{etocbottomrulecolorcmd}
\label{etocbkgcolorcmd}
\label{etocframedmphook}

We list the relevant macros, what they do should be legible from their
names. Note that dimensions are stored in macros so are modifed using
\csa{renewcommand}'s and not \csa{setlength}'s.  And color related commands
are not color definitions, they execute \csa{color}, and their effect gets canceled
by re-defining them to do \csa{relax} or \csa{empty}.
\begin{verbatim}
\newcommand*\etocabovetocskip{3.5ex plus 1ex minus .2ex}
\newcommand*\etocbelowtocskip{3.5ex plus 1ex minus .2ex}

\newcommand*\etoccolumnsep{2em}
\newcommand*\etocmulticolsep{0ex}
\newcommand*\etocmulticolpretolerance{-1}
\newcommand*\etocmulticoltolerance{200}
\newcommand*\etocdefaultnbcol{2}
\newcommand*\etocinnertopsep{2ex}
\newcommand*\etoctoprule{\hrule}
\newcommand*\etoctoprulecolorcmd{\relax}

% for the framed style only:
\newcommand*\etocinnerleftsep{2em}
\newcommand*\etocinnerrightsep{2em}
\newcommand*\etocinnerbottomsep{3.5ex}

\newcommand*\etocleftrule{\vrule}
\newcommand*\etocrightrule{\vrule}
\newcommand*\etocbottomrule{\hrule}
\newcommand*\etocleftrulecolorcmd{\relax}
\newcommand*\etocrightrulecolorcmd{\relax}
\newcommand*\etocbottomrulecolorcmd{\relax}

\newcommand*\etocbkgcolorcmd{\relax}

% hooks
\newcommand\etocframedmphook{\relax}
\end{verbatim}

The \csa{etocframedmphook} is positioned immediately
after the beginning of a minipage environment where the
contents of the framed TOC are typeset.

The \csa{...colorcmd} commands are initially set to expand to
\csa{relax} (hence do not require package |color| or |xcolor|
to be loaded). If one has modified a command such as
\csa{etocbkgcolorcmd} to expand to a color command and wants
to reset it to do nothing, one \emph{must} use
|\renewcommand{\etocbkgcolorcmd}{\relax}| and not
\csa{let}\csa{etocbkgcolorcmd}\csa{relax}.

Regarding the dimensions of the top rule they can be specified
in |ex|'s or |em|'s as in this example:
\centeredline{|\renewcommand{\etoctoprule}{\hrule height 1ex}|}
The package code is done in such a manner
that it is the font size in instance at the end of typesetting
the title argument to \csb{etocruled} or
\csb{etocframed} which will be used for the meaning of the
`1ex'. Of course also the other rule commands can have their
dimensions in font relative units, but their values are
decided on the basis of the font in effect just before the
table of contents.

The top and bottom rules do not have to be rules and can be
horizontal \emph{leaders} (of a specified height) in the general
\TeX{} sense. However the left and right rules are not
used as (horizontal) leaders but as objects of a given specified
width. Note that \emph{only} the Plain \TeX{} syntax for rules is
accepted here.


\subsection{Headings, titles, \csbhyp{etocoldpar}, \csbhyp{etocinnertopsep}}
\label{etocinnertopsep}
\label{etocoldpar}

For \csb{etocmulticolstyle} the mandatory \meta{heading} argument can be
either
vertical mode material like |\section*{\emph{Table of Contents}}| or
horizontal mode material like in the simple |\etocmulticolstyle{Hello World}|.

No explicit |\par| or empty line can be inserted in the mandatory
argument of \csb{etocmulticolstyle}, but \etoc provides \csb{etocoldpar}
as a substitute: it does |\let\etocoldpar\par| before the |multicols|
environment and inserts this |\etocoldpar|\footnote{this command
  \csb{etocoldpar} (= working \csa{par} in the argument to
  \csb{etocmulticolstyle}) is not related to the switch \csb{etocinline}
  whose purpose is to tell \etoc not to do a \csa{par} before the table
  of contents.} at the end of the heading, then does a vertical skip of
value \csb{etocinnertopsep}. The command \csb{etocoldpar} can also be
used explicitely if needed in the mandatory argument to
\csb{etocmulticolstyle} (it is not allowed to insert an empty line
in this argument).

On the other hand the commands \csb{etocruledstyle} and
\csb{etocframedstyle} expect an argument ``in LR mode'' (to use the
terminology from \emph{LaTeX, a document preparation system}). This
means that multiline titles are only possible if enclosing
them inside something like a \csa{parbox}.

An important dimension used by all three of \csb{etocmulticolstyle},
\csb{etocruledstyle} and \csb{etocframedstyle} is
\csb{etocinnertopsep}. It gives the amount of separation
between the heading and the start of the contents. Its default
value is |2ex| and it is changed with
|\renewcommand*{\etocinnertopsep}|\marg{new\_value}, not with
|\setlength|.


\section{Starred variants and hooks}
\label{tableofcontents*}
\label{localtableofcontents*}
\label{etocbeforetitlehook}
\label{etocaftertitlehook}
\label{etocaftercontentshook}
\label{etocaftertochook}

The \toc, \localtoc, \csb{etocmulticol}, and all their cousins have starred
variants (the star must be before the other arguments). The non-starred
variants execute the \csb{etocaftertitlehook}, whose default definition is to
do nothing. The starred variants do not execute this hook.

For example, imagine you are using |book| class and want \localtoc to use a
section-like title, but unnumbered. Assuming the main \toc comes first in the
document, you can insert this after it:
\begin{verbatim}
  \etocarticlestyle
  \renewcommand{\etocaftertitlehook}{\addcontentsline{toc}{section}{\contentsname}}
\end{verbatim}
This configures the way \localtoc will behave (or \toc) from now on in the
document.

The first line tells essentially to use |\section*{\contentsname}|, and the
second line says to insert the title in the |.toc| file itself (thus to be
displayed by the main table of contents). Notice that \ctanpkg{hyperref} package will
then automatically create suitable anchor and one should \emph{not} use
explicitly \cs{phantomsection} here (it would let the anchor be located below
not above the title).

% problème avec \xspace
With this set-up issuing \localtoc\unskip|*| will ignore the \csb{etocaftertitlehook}
hence not send the local toc title to the |.toc| file. This mimicks the
\ctanpkg{memoir} class behavior, and can also be used with it. For more on \ctanpkg{memoir}
class with \etoc, see \autoref{ssec:memoir}.

There are further hook macros:
\csb{etocaftercontentshook}, \csb{etocbeforetitlehook} and
\csb{etocaftertochook} which are initially defined to do nothing and can be
used for some special effects. They are executed whether or not the table of
contents command was starred.

For example, the present document executed
\begin{verbatim}
\renewcommand{\etocbeforetitlehook}{\setstretch{1}}
\end{verbatim}
as it is globally using the \ctanpkg{setspace} command \csa{onehalfspacing}.
Not using \csa{singlespacing} in the hook as it does a systematic vertical
skip of one baseline, which is unwanted in our usage.

\begin{framed}
  In recent years, the \LaTeX{} kernel has added a general ``hook'' mechanism
  with a user interface of the type |\AddToHook{...}{...}|.

  The \etoc macros with `hook' ending their names are much simpler things
  which are supposed to be manipulated only via \csa{renewcommand} or
  \csa{def} direct overwrites.

  In future, and to the extent the author has time for that addition, with its
  costly documentation updates collaterals, and thoughts about backward
  compatibility, \etoc should arguably tap into the general tools provided by
  recent \LaTeX{} kernels.
\end{framed}

\section{The \csbhyp{etocsetstyle} and related commands}
\label{sec:linestyles}
\label{etocsetstyle}
\label{etocname}
\label{etocpage}

\begingroup
\etocsettocstyle{}{}
\DeclareTOCStyleEntry[numwidth=3.2em,indent=0em]{tocline}{subsection}
\etocstandardlines
\localtableofcontents \label{toc:linestyles}
\endgroup

Let us explain how \etoc was used to produce the table of contents displayed
at the beginning of this \autoref{part:styling}.  This is a local table of
contents, and we used the command \localtoc.


The line styles were (essentially) obtained in the following manner:%
\footnote{the present document has {\ttfamily\string\renewcommand\string{%
      \string\familydefault\string}\string{\string\sfdefault\string}} in its
  preamble, hence \csa{normalfont} switches to the |sans| typeface; so in the
  section line-style, I wrote \csa{rmfamily} instead.}

\begingroup\small
\begin{filecontentshere}{etocsnippet-\snippetno.tex}
\etocsetstyle{section}
{\begin{enumerate}}
{\normalsize\bfseries\rmfamily\item}
{\etocname{} (page \etocpage)}
{\end{enumerate}}

\etocsetstyle{subsection}
{\begin{enumerate}}
{\normalfont\item}
{\etocname{} (p.~\etocpage)}
{\end{enumerate}}

\etocsetstyle{subsubsection}
{\par\nobreak\begingroup\normalfont
        \footnotesize\itshape\etocskipfirstprefix}
{\allowbreak\,--\,}
{\etocname}
{.\hfil\par\endgroup\pagebreak[3]}
\end{filecontentshere}
\endgroup
% Note 2023/02/22: pour une raison que je ne vais pas chercher à comprendre
% le etocsnippet-01 était mis du mauvais côté (dans la marge intérieure, pas
% extérieure) lorsque ce \marginattach était avant le \endgroup
\marginattach

These provisory style definitions rely on the automatic
numbering generated by the |enumerate| environments but it is
much better to use the further command \csb{etocnumber} inside
the item label, which gives the real thing. The improved
definitions will thus be explained later.

With this style, one would have
to be imaginative to design something then for paragraph and
subparagraph entries! perhaps as superscripts? Well, usually
one does not need paragraphs and subparagraphs numbered and
listed in the TOC, so our putative user here chose a design
where no provision is made for them and added the definitive:
\begin{verbatim}
\etocsetstyle{paragraph}{}{}{}{}
\etocsetstyle{subparagraph}{}{}{}{}
\end{verbatim}
This is also the situation with the default package line styles!

Each \csb{etocsetstyle} command has five mandatory arguments:
%
\centeredline{\csb{etocsetstyle}\color{blue}\marg{levelname}\marg{start}\marg{prefix}\marg{contents}\marg{finish}}
%
The initially recognized \meta{levelname}'s are the sectioning
levels of the standard document classes: from \emph{part} (or
\emph{book} which is used by the \ctanpkg{memoir} class) down to
\emph{subparagraph}.

The \meta{start} code is executed when a toc entry of that level is
encountered and the previous one was at a higher level. The
\meta{finish} code is executed when one again encounters a higher
level toc entry. In the meantime all entries for that level are
typeset by executing first the \meta{prefix} code and then the
\meta{contents} code.

The (robust) commands \csb{etocname}, \csb{etocnumber} and \csb{etocpage} are
provided for use inside the \meta{prefix} and \meta{contents} parts of the
\csb{etocsetstyle} specification. They represent of course, the name, number,
and page number of the corresponding toc entry. If package \ctanpkg{hyperref} is
active in the document and has added hyperlinks to the TOC data, then these
links are kept in the commands \csb{etocname}, \csb{etocnumber} and
\csb{etocpage} (this last one will have a link only if \ctanpkg{hyperref} was passed
either option \emph{linktoc=all} or option \emph{linktoc=page}.)%
%
\footnote{As expected, in case of \emph{linktoc=page}, only \csb{etocpage} is
an hyperlink, not \csb{etocname} nor \csb{etocnumber}.  See \csb{etoclink} on
how to create hyperlinks with the entry target.}
%
In accordance with the \ctanpkg{hyperref} native behavior, no
link gets incorporated into \csb{etocpage} if the page number is empty.

\subsection{The \csbhyp{etocskipfirstprefix} and \csbhyp{etociffirst} commands}
\label{etocskipfirstprefix}
\label{etociffirst}
\label{etocxiffirst}

The chosen |subsubsection| style made use of the command
\csb{etocskipfirstprefix}, which instructs \etoc to \emph{not} use
for the first item the specified \meta{prefix} code.


The command \csb{etociffirst}\marg{YES CODE}\marg{NO CODE}
is a more flexible way to customize the \meta{prefix}
(and \meta{contents}) specifications. It executes the \meta{YES
CODE} branch if this is the first unit at that level (inside a
lower level) and the \meta{NO CODE} if not. This is a robust
command which survives to expansion (for example in an |enumitem| label).

The variant \csb{etocxiffirst} does the same, but is expandable.


\subsection{The \csbhyp{etocnumber} command}
\label{etocnumber}

So far, our specifications would use the numbering generated
by the |enumerate| environments, but of course we generally want
the actual numbers as found in the |.toc| file. This is
available via the \csb{etocnumber} command. To get the labels
in the |enumerate| list to use it we can proceed with the
syntax {\ttfamily label=\char32} from the package |enumitem|:
\begin{verbatim}
\etocsetstyle{section}
{\begin{enumerate}[label=\etocnumber]}
{\normalsize\bfseries\rmfamily\item}
{\etocname{} (page \etocpage)}
{\end{enumerate}}
\end{verbatim}
Rather than just \csb{etocnumber} we then used something like
|\fbox{\etocnumber}|. Note that \csb{etocnumber} is a robust
command which explains why it can be used inside the label specification
without needing an added |\protect|.


\subsection{The \csbhyp{etocifnumbered} switch}
\label{etocifnumbered}
\label{etocxifnumbered}

The \csa{fbox} would give an unaesthetic result in the case of
an unnumbered section (which ended up in the table of
contents via an \csa{addcontentsline} command).\footnote{as
  seen we use \csa{fcolorbox} rather than \csa{fbox}. Due
  to some redefinition made by package |xcolor|, had we used
  \csa{fbox} (and not used \ctanpkg{hyperref}) we would have needed
  \csa{protect}\csa{fbox}.}

The \csb{etocifnumbered}\marg{A}\marg{B} command executes
\meta{A} if the number exists, and \meta{B} if not. So we use
it in the code which was finally chosen for the |section| level:
\begin{verbatim}
\etocsetstyle{section}
{\begin{enumerate}[leftmargin=.75cm, label=\etocifnumbered
      {{\fboxrule1pt\fcolorbox{green}{white}{\etocnumber}}}{}]}
{\normalsize\bfseries\rmfamily\item}
{\etocname{} (page \etocpage)}
{\end{enumerate}}

\etocsetstyle{subsection}
{\begin{enumerate}[leftmargin=0cm, label=\etocnumber]}
{\normalfont \item}
{\etocname{} (p.~\etocpage)}
{\end{enumerate}}
\end{verbatim}

If we had changed only the |section| level, and not the
|subsection| level, an error on compilation would have occurred
because the package style for subsections expects to start `in
vertical mode'. An additional \csa{par} token in the
\meta{contents} part of the |section| level would have fixed
this: |{...(page \etocpage)\par}|.

The command \csb{etocifnumbered} is robust;  \csb{etocxifnumbered}
has the same effect but is expandable.


\subsection{The \csbhyp{etocthename}, \csbhyp{etocthenumber}, and
\csbhyp{etocthepage} commands}
\label{etocthename}
\label{etocthenumber}
\label{etocthepage}

It is sometimes desirable to have access to the name, number and page
number without the hyperref link data: something similar to the starred
variant of the \csa{ref} command, when package \ctanpkg{hyperref} is used. For
example one may wish to use the unit or page number in some kind of
numeric context, or change its formatting. This is provided by
\csb{etocthename}, \csb{etocthenumber}, and \csb{etocthepage}.

These commands are not ``robust'', in fact it is expected they will be often
submitted to one expansion step so that their contents can easily be recovered
and stored perhaps for delayed usage.

\subsection{The \csbhyp{etoclink} command}
\label{etoclink}

The command \csb{etoclink}\marg{text} can be used in the line style
specifications in a manner analogous to \csb{etocname}, \csb{etocnumber} and
\csb{etocpage}.  It creates a link (if \ctanpkg{hyperref} is present%
%
\footnote{Prior to \etocrelease{1.1a}, no such link was added if the \texttt{.toc}
 file entry was encountered
 with  \ctanpkg{hyperref}'s option \texttt{linktoc} set to \texttt{none}.})
%
whose target is the corresponding document unit and
whose name is the given \meta{text} mandatory argument.

Hence |\etoclink{\etocthename}| is under default conditions of \ctanpkg{hyperref} like
the original \csb{etocname}, because the latter is already hyperlinked.  Under
\emph{linktoc=page} context |\etoclink{\etocthename}| adds the hyperlink which
is missing from \csb{etocname}.  Similarly under the default \ctanpkg{hyperref}
condition (i.e.\@ \emph{linktoc=section}) \csb{etocpage} is not an hyperlink, but one
can use |\etoclink{\etocthepage}|.

The command \csb{etoclink} is robust.

%  Since |etoc 1.08j| it contains the link
% destination in an already expanded form, so for example can be used even after
% a |&| in a tabular construction, if \csb{etocglobaldefs} was issued.




\makeatletter\scr@activate@xsection{1}\makeatother
% [] goes to head but {} to toc

% What would really be useful is an option for the length of {} to be measured
% and opt for [] only if does not fit on one header line
\subsection[The \csbhyp{etocthelinkedname} et al.\protect\@{} commands]
  {The \csbhyp{etocthelinkedname}, \csbhyp{etocthelinkednumber},
       \csbhyp{etocthelinkedpage} and \csbhyp{etocthelink} commands}
\label{etocthelinkedname}
\label{etocthelinkednumber}
\label{etocthelinkedpage}
\label{etocthelink}

\makeatletter\scr@activate@xsection{0}\makeatother

The meanings of these commands
can be stored for delayed usage. For example this is
done in the \hyperref[tocastree]{examples with trees}.

There has been a \textbf{breaking change} at \etocrelease{1.1a}.  Here is the behavior
\emph{prior} to this release:
\begin{itemize}[noitemsep]
\item \csb{etocthelinkedname} and \csb{etocthelinkednumber} were hyperlinks
  only if \ctanpkg{hyperref} was configured via |linktoc=all| or
  |linktoc=section| (the default),
\item \csb{etocthelinkedpage} was an hyperlink only if \ctanpkg{hyperref} was
  configured via |linktoc=all| or |linktoc=page| and the page number was not empty.
\end{itemize}
This behavior was coherent with the commands \csb{etocname}, \csb{etocnumber},
and \csb{etocpage} being the robust variants of \csb{etocthelinkedname},
\csb{etocthelinkednumber}, and \csb{etocthelinkedpage}.

At \etocrelease{1.1a} it was decided that the commands should match their denominations.%
%
\footnote{To tell the whole truth, the author in refactoring the code completely at \etocrelease{1.1a} was tricked by the names and forgot to read the old documentation so the new behavior was implemented and it was decided to keep the change.}
%
So they are now \emph{always} hyperlinks independently of |linktoc| \ctanpkg{hyperref}
option (\csb{etocthelinkedpage} has no hyperlink if the page number is empty,
to match \ctanpkg{hyperref} behavior):
\begin{itemize}[noitemsep]
\item \csb{etocthelinkedname} and \csb{etocthelinkednumber} and
  \csb{etocthelinkedpage} are always (in presence of \ctanpkg{hyperref})
  hyperlinks (for \csb{etocthelinkedpage} the page number must not be empty).
\end{itemize}


A further command is provided: \csb{etocthelink}, which wraps%
%
\footnote{Prior to \etocrelease{1.1a}, there was a link added only if \ctanpkg{hyperref} option \texttt{linktoc} was not \texttt{none}.}
%
an hyperlink around its argument: |\etocthelink|\marg{foo} hyperlinks an
arbitrary text \meta{foo} to the target sectioning unit in the document.
The command \csb{etoclink} is its robust variant.



\subsection{The \csbhyp{etocsetlevel} command}
\label{etocsetlevel}
\label{etocthemaxlevel}

One
can inform \etoc of a level to associate to a given sectioning
command with \csb{etocsetlevel}. For example:
\begin{verbatim}
\etocsetlevel{cell}{0}
\etocsetlevel{molecule}{1}
\etocsetlevel{atom}{2}
\etocsetlevel{nucleus}{3}
\end{verbatim}
In compatibility mode, it will be assumed that the commands |\l@cell|,
|\l@molecule|, ..., have been defined somewhere either by the user or a class:
doing only |\etocsetlevel| is not enough for the corresponding level to work
out-of-the-box in compatibility mode.

However, if table of contents are never using compatibility mode, then all
that matters is that the various line styles have been set. If, for example
|section| is at level |1|, then there is no need to do some
\csb{etocsetstyle}|{molecule}{..}{..}{..}{..}| after
\csb{etocsetlevel}|{molecule}{1}| if
\csb{etocsetstyle}|{section}{..}{..}{..}{..}| has already been done (and it
has been done by the package itself in its definition of its own line styles).

The accepted levels (but see the frame below) run from |-1| to |6| inclusive
(also |-2| with class \ctanpkg{memoir}).  Anything else is mapped to |6|,
which is a dummy level, never displayed.  The package does:
\begin{verbatim}
\etocsetlevel{book}{-2}% (only with class memoir)
\etocsetlevel{part}{-1}
\etocsetlevel{chapter}{0}
\etocsetlevel{appendix}{0}% or 1 if document has no \chapter
\etocsetlevel{section}{1}
\etocsetlevel{subsection}{2}
\etocsetlevel{subsubsection}{3}
\etocsetlevel{paragraph}{4}
\etocsetlevel{subparagraph}{5}
\end{verbatim}
\etoc own custom styles are activated by \csb{etocdefaultlines}.
\begin{framed}
  Boolean option \etocoption{deeplevels} added at \etocrelease{1.2a} has the
  effect of replacing \texttt{6} by \texttt{12} as the maximal numerical level
  (which, as has been said above, is never displayed).  The value |6|
  (default) or |12| (if \etocoption{deeplevels} is set to true) is held by
  \csb{etocthemaxlevel}.  With \etocoption{deeplevels} option one can for
  example do:
\begin{verbatim}
\etocsetlevel{subsubsubsection}{4}
\etocsetlevel{subsubsubsubsection}{5}
\etocsetlevel{subsubsubsubsubsection}{6}
\etocsetlevel{paragraph}{7}
\etocsetlevel{subparagraph}{8}
\end{verbatim}
  but it is up to user to actually define \LaTeX{} commands such as
  \csa{subsubsubsection}, and also to provide, if \etoc is left in
  ``compatibility mode'', the suitable \csa{l@subsubsubsection} et al. needed
  for TOC rendering.  If you use \csb{etocsetstyle} (even only for one level
  name) though, which quits ``compatiblity mode'', it is not
  \csa{l@subsubsubsection} which needs definition, but
  \csb{etocsetstyle}|{subsubsubsection}{..}{..}{..}{..}| which has to have
  been used.
\end{framed}
The numerical level assignments can be modified at anytime.  See
\autoref{part:surprising} for various applications of this technique.



\subsection{Using \texttt{enumerate} or \texttt{itemize} environments for
  line styles}

The code for the line styles of the \localtoc of this part was already
reproduced in \autoref{sec:linestyles}.  It is very simple and uses
\texttt{enumerate} environments for sections and subsections, then an
``inline'' paragraph style for subsubsection titles.

Actually, the very first version of \etoc from 2012 was originally motivated
by the aim to do exactly this kind of things, which necessitates to be aware
of when for example after a series of subsections, a section line appears in
the |.toc| file.%
%
\footnote{At the source code level, the legacy method dating back to the
  origins in 2012 was replaced
  by a completely new one at release \etocrelease{1.2}.}
%
Indeed, this should trigger the emission of an |\end{enumerate}|.

With the \marg{start} and \marg{finish} arguments of \csb{etocsetstyle}, \etoc
provides an easy systematic interface to accomplish this kind of task.

But there are some limitations to the use of list environments for typesetting
TOCs.  One of them is intrinsic to the scope limitations created by the groups
associated to the environments: the |.toc| file may contain, besides the
information to be typeset in the TOCs, some other commands, such as language
changing commands from \ctanpkg{babel}, and some such commands do not expect
to see their scope limited in this way by the presence of an environment
(which will not be visible in the |.toc| file itself but enacted dynamically
by the user-specified line styles).

The built-in ``default line styles'' provided with \etoc (see
\autoref{sec:custom}) do not make use of environments.  Actually, in this
user manual, only the \hyperref[toc:part:styling]{table of contents} at the start of this
\autoref{part:styling}, the \autoref{toc:allsubsections} (which is a TOC!) and
examples from \autoref{etocthelink} have their line styles expressed in terms
of \texttt{enumerate} or \texttt{itemize} environments.

\subsection{The\csbhyp{etocglobaldefs} and \csbhyp{etoclocaldefs} commands}
\label{etocglobaldefs}
\label{etoclocaldefs}

In \LaTeX{} the meaning of a command defined via |\newcommand\foo{...}| inside
an environment (or group) vanishes from \TeX's memory on exit from this
environment (or group). At times however it is needed to make definitions with
global scope, for this \TeX{} has the primitive prefix |\global|.

By default \etoc's definitions of \csb{etocname} etc... are local. This causes
problems in certain contexts such as TOC as tables (\autoref{sec:tocastable},
\autoref{ssec:tocastableold}) and also with |enumitem| \emph{inline} variants
of its standard environments, because the command |\item| then closes a group
(see \autoref{etocthelink}).

After \csb{etocglobaldefs} has been issued, the \csb{etocname},
\csb{etocnumber} and \csb{etocpage} will be defined during execution of \toc
and \localtoc with global scope.  For normal use this is not necessary.  It
does not hurt either to activate it systematically.

To return to the default, which lets \etoc only define them locally to the
context in place where the \csa{contentsline} is encountered, execute
\csb{etoclocaldefs}.  Both \csb{etocglobaldefs} and \csb{etoclocaldefs} have
an effect only locally to the environment or group where they are used.

\section{The \etoc fall-back line styles}
\label{sec:custom}

\etocdefaultlines
\renewcommand{\etoctoprule}{\hrule height2pt depth0pt}
\renewcommand{\etoctoprulecolorcmd}{\color{red}}

\etocruledstyle{\normalfont\normalsize\rmfamily\fboxrule1pt\color{red}%
  \fbox{\parbox{.8\linewidth}{\centering\normalcolor This is a table of
      contents for the (few) subsections of this section. It carries the label |toc:c|}}}

\localtableofcontents \label{toc:c}

\subsection{A demo of a TOC using \csbhyp{etocdefaultlines}}
\label{etocdefaultlines}

These line styles were written at an early stage in the
development of the package; although the next section explains how
to customize the font choicess or vertical spaces, etc\dots, used
by these line styles, most other changes would require copying
them from the sources and modify them directly. Admittedly they
have been written at a rather scary low-\TeX{} level, and will not
serve as a very friendly starting point.

Activating their use is done via \csb{etocdefaultlines}, or
\csb{etoctoclines} if the line styles have not been modified with
\csb{etocsetstyle}. Sections and sub-sections are printed in
essentially the same manner, except that the leading for
sub-sections is a bit smaller (with document classes lacking a
\csa{chapter} command, the sections are printed in bold typeface;
this is the case in the present document). Sub-sub-sections are
printed inline, in one paragraph, with no numbers or page numbers.
This style was designed and tested with documents having lots of
sub-sub-sections, and should be used on a two-column layout: it
provides (only in that situation with many sub-sub-sections) a
more compact presentation than what is achieved by the \LaTeX{}
default.\footnote{and there will never be a Part or Chapter entry
  alone at the bottom of a column or page (except if it has no
  sub-unit).} On the other hand, used with a one-column layout,
and with few sub-sub-sections, the style is a bit more spread out
vertically than the \LaTeX{} default, sub-sections are not
visually much different from sections (especially for document
classes with a \csa{chapter} command), so the result is less
hierarchical in appearance than in the \LaTeX{} default.

Let us typeset the global table of contents of the present document as if it
had been done with a class having the \csa{chapter} command: we will print
sections as chapters, and subsections as sections. We use \csb{etocsetlevel}
for that, and also we need to change the font style of ``sections'' (which in
truth are our subsections) to use not the bold but the medium series; we
modify the \csb{etocfontone} command for that. Also we use dot leaders which
are less spread out than in the package default.


\begin{filecontentshere}{etocsnippet-\snippetno.tex}
\etocruledstyle[2]{\normalfont\normalsize\rmfamily\itshape
  \fbox{\parbox{.6\linewidth}{
      \leftskip 0pt plus .5fil
      \rightskip 0pt plus -.5fil
      \parfillskip 0pt plus 1fil This is the global table of
      contents on two columns, using \etoc default line styles, but with
      sections as chapters, and subsections as sections.
      }}}
\etocdefaultlines
\etocsetnexttocdepth{1}
\begingroup
\etocsetlevel{section}{0}
\etocsetlevel{subsection}{1}
\renewcommand*{\etocfontone}{\normalfont \normalsize}
\renewcommand*{\etoctoclineleaders}
        {\hbox{\normalfont\normalsize\hbox to 1ex {\hss.\hss}}}
\sloppy
\tableofcontents
\endgroup
\end{filecontentshere}
\marginattach

\filecontentsexec\filecontentsheremacro

\subsection{Customizing  the \etoc pre-defined line styles}
\label{etocfontminustwo}
\label{etocfontminusone}
\label{etocfontzero}
\label{etocfontone}
\label{etocfonttwo}
\label{etocfontthree}
\label{etocsepminustwo}
\label{etocsepminusone}
\label{etocsepzero}
\label{etocsepone}
\label{etocseptwo}
\label{etocsepthree}
\label{etocminustwoleftmargin}
\label{etocminustworightmargin}
\label{etocminusoneleftmargin}
\label{etocminusonerightmargin}
\label{etocbaselinespreadminustwo}
\label{etocbaselinespreadminusone}
\label{etocbaselinespreadzero}
\label{etocbaselinespreadone}
\label{etocbaselinespreadtwo}
\label{etocbaselinespreadthree}
\label{etoctoclineleaders}
\label{etocabbrevpagename}
\label{etocpartname}
\label{etocbookname}


We will simply list the relevant commands as defined in the
package. Customizing them goes through suitable
\csa{renewcommand}s:
\begin{verbatim}
\newcommand*\etocfontminustwo{\normalfont \LARGE \bfseries}
\newcommand*\etocfontminusone{\normalfont \large \bfseries}
\newcommand*\etocfontzero{\normalfont \large \bfseries}
\newcommand*\etocfontone{\normalfont \normalsize \bfseries}
% (in classes with chapter, \etocfontone does not do \bfseries)
\newcommand*\etocfonttwo{\normalfont \normalsize}
\newcommand*\etocfontthree{\normalfont \footnotesize}

\newcommand*\etocsepminustwo{4ex plus .5ex minus .5ex}
\newcommand*\etocsepminusone{4ex plus .5ex minus .5ex}
\newcommand*\etocsepzero{2.5ex plus .4ex minus .4ex}
\newcommand*\etocsepone{1.5ex plus .3ex minus .3ex}
\newcommand*\etocseptwo{.5ex plus .1ex minus .1ex}
\newcommand*\etocsepthree{.25ex plus .05ex minus .05ex}

\newcommand*\etocminustwoleftmargin{1.5em plus 0.5fil}
\newcommand*\etocminustworightmargin{1.5em plus -0.5fil}
\newcommand*\etocminusoneleftmargin{1em}
\newcommand*\etocminusonerightmargin{1em}

\newcommand*\etocbaselinespreadminustwo{1}
\newcommand*\etocbaselinespreadminusone{1}
\newcommand*\etocbaselinespreadzero{1}
\newcommand*\etocbaselinespreadone{1}
\newcommand*\etocbaselinespreadtwo{1}
\newcommand*\etocbaselinespreadthree{.9}
\newcommand*\etoctoclineleaders
    {\hbox{\normalfont\normalsize\hbox to 2ex {\hss.\hss}}}
\newcommand*\etocabbrevpagename{p.~}  % initial of "page"
\newcommand*\etocpartname{Part}  % prior to 1.08b, was \partname
% but this didn't make sense e.g. with babel+frenchb whose \frenchpartname
% takes into account the value of the part counter.
\newcommand*\etocbookname{Book} % to be modified according to language
\end{verbatim}

No customizing of the standard line styles is possible from
within \etoc. As already explained, when
\csb{etocstandardlines} has been issued, the package just makes
itself very discrete and acts only at the global level, and
the TOC entries are (hopefully) formatted as would have
happened in the absence of \etoc.\footnote{with the
  \ctanpkg{KOMA-script} classes, we noticed that
  \csb{etocclasstocstyle} was apparently needed for the
  KOMA options |toc=left| to be active at the level of the line entries.}


The \csb{etocstandardlines} compatibility mode will work also with
sectioning commands made known to \etoc via \csb{etocsetlevel},
under the condition of course that these sectioning commands
are accompanied with all the relevant definitions for
typesetting toc entries in the \LaTeX{} default manner
(existence of the macros \csa{l@something} . . .).

Using the command \csb{etocsetstyle}, be it in the preamble or
in the body of the document, has the secondary effect of
switching off the compatibility mode.

\section{Summary of the main styling commands}

\subsection{Setting up local styles}

\hbox{\color{green}\fboxrule1pt\fboxsep1em
\setbox0\hbox{\csb{etocthename}, \csb{etocthenumber}, \csb{etocthepage}, \csb{etoclink}\marg{linkname}}%
\framebox[\linewidth][c]
{\vbox{\hsize\wd0\normalcolor\noindent
\csb{etocsetstyle}\marg{levelname}%
  \marg{start}\marg{prefix}\marg{contents}\marg{finish}\\
\csb{etocname}, \csb{etocnumber}, \csb{etocpage},
\csb{etocifnumbered}\marg{A}\marg{B}\\
\csb{etocthename}, \csb{etocthenumber}, \csb{etocthepage}, \csb{etoclink}\marg{linkname}
}}}

\subsection{Setting up toc display styles}

\medskip
\hbox{\color{green}\fboxrule1pt\fboxsep1em
\setbox0\hbox{\csb{etoctocstylewithmarksnouc}\oarg{kind}%
\marg{number\_of\_columns}\marg{title}\marg{mark}}%
\framebox[\linewidth][c]
{\vbox{\hsize\wd0
\normalcolor\noindent
\csb{etocmulticolstyle}\oarg{number\_of\_columns}\marg{heading}\\
\csb{etoctocstyle}\oarg{kind}\marg{number\_of\_columns}\marg{title}\\
\csb{etoctocstylewithmarks}\oarg{kind}\marg{number\_of\_columns}%
\marg{title}\marg{mark}\\
\csb{etoctocstylewithmarksnouc}\oarg{kind}\marg{number\_of\_columns}%
\marg{title}\marg{mark}\\
\csb{etocruledstyle}\oarg{number\_of\_columns}\marg{title}\\
\csb{etocframedstyle}\oarg{number\_of\_columns}\marg{title}\\
\csb{etocsettocstyle}\marg{before\_toc}\marg{after\_toc}}}}

\subsection{Displaying tables of contents}


\medskip \hbox{\color{green}\fboxrule1pt\fboxsep1em
  \setbox0\hbox{\csb{etocname}, \csb{etocnumber},
    \csb{etocpage}, \csb{etocifnumbered}\marg{A}\marg{B}}%
  \framebox[\linewidth][c]
  {\vbox{\hsize\wd0\normalcolor\noindent
      \toc\\
      \localtoc\\
      \csb{etocmulticol}\oarg{number\_of\_columns}\marg{heading}\\
      \csb{etoclocalmulticol}\oarg{number\_of\_columns}\marg{heading}\\
      \csb{etocruled}\oarg{number\_of\_columns}\marg{title}\\
      \csb{etoclocalruled}\oarg{number\_of\_columns}\marg{title}\\
      \csb{etocframed}\oarg{number\_of\_columns}\marg{title}\\
      \csb{etoclocalframed}\oarg{number\_of\_columns}\marg{title}\\
      \hbox{}{\itshape\ttfamily\ \ \ \  and their starred variants}
   }}}

\subsection{Labels and references}
\label{ssec:labelref}

The commands (starred or not) to actually display the table of contents
can be followed with optional labels or references:\par

\medskip \hbox{\color{green}\fboxrule1pt\fboxsep1em
  \setbox0\hbox{\csb{etocname}, \csb{etocnumber},
    \csb{etocpage}, \csb{etocifnumbered}\marg{A}\marg{B}}%
  \framebox[\linewidth][c]
  {\vbox{\hsize\wd0\normalcolor\noindent
      \toc \csa{label}|\{toc:here\}|\\
      \toc \csa{ref}|\{toc:far\}| \\
      \toc \csa{label}|\{toc:here\}| \csa{ref}|\{toc:far\}| \\
      \localtoc \csa{label}|\{toc:here\}|\\
      \localtoc \csa{ref}|\{toc:far\}| \\
      \localtoc \csa{label}|\{toc:here\}| \csa{ref}|\{toc:far\}| \\
      \hbox{}{\itshape\ttfamily\ \ \ \ similarly with\ }%
      \csb{etocmulticol}{\itshape\ttfamily\ etc . . . }
   }}}


\medskip

\localtoc \csa{ref}|{toc:far}| acts the same as \toc
\csa{ref}|{toc:far}|.
% <--- car à 1.2 cela permet d'éviter une page quasi vide...
When re-displaying another toc, only its contents are transferred:
both the line styles and the toc display style are the ones
currently defined, not the ones from the cloned toc.


\clearpage
\etocdepthtag.toc {control}
\part{Control of contents}
\label{part:control}

\thispartstats

\etocsettocstyle{}{}% maybe I should use \etocclasstocstyle here ?
                    % but then I probably need some extra KOMA stuff to
                    % counteract  the setspace effet
\begingroup
\DeclareTOCStyleEntry[numwidth=2em,indent=0pt]{tocline}{section}
\DeclareTOCStyleEntry[numwidth=2.5em,indent=2em]{tocline}{subsection}
\DeclareTOCStyleEntry[numwidth=3em,indent=4.5em]{tocline}{subsubsection}
\etocstandardlines
\localtableofcontents
\endgroup

\section[The \csbhyp{tableofcontents} et al. commands]{The
  \csbhyp{tableofcontents}, \csbhyp{localtableofcontents} and
  \csbhyp{localtableofcontentswithrelativedepths} commands}
\label{tableofcontents}
\label{etoctableofcontents}
\label{localtableofcontents}
\label{localtableofcontentswithrelativedepth}
\label{etockeeporiginaltableofcontents}

\begin{description}
\item[\toc] can be used arbitrarily many times in the document. Styling either
  globally the TOC or its individual entries is customizable at any time in
  the document.

  \csb{etoctableofcontents} is a synonym to \etoc's \toc.  The \toc command
  reverts to its non-\etoc definition if \csa{etockeeporiginaltableofcontents}
  is issued after loading the package.
%
\footnote{%
  This
  was added to fix a compatiblity issue with \ctanpkg{listings}'s
  \texttt{\string\lstlistoflistings}, as it needs the
  \texttt{\string\tableofcontents} macro to keep its original meaning.}

\item[\localtoc] will print local tables of
contents: \emph{i.e.} all sections and sub-units inside a
given chapter, or all subsubsections and lower inside a given
subsection, etc... (see also \csb{etocsetnexttocdepth}).%
%
\footnote{As is explained in \autoref{sec:labeling} the syntax allows to
  create somewhere a local table of contents and to display it at some other
  location either before or after its origin.}%
\textsuperscript{,}%
\footnote{As is explained in \autoref{sec:tocdepth} \etoc allows at anytime to
  locally redefine the numeric levels associated to named ones, which brings
  great flexibility to achieve special effects, all done using only a single
  auxiliary file, the standard |.toc| file.}
%
\item[\localtocwrdp\marg{number}]
%
\mbox{}\footnote{Thanks to Tony \textsc{Roberts} for feature request.}
%
  can be used to override the document or
  current tocdepth setting (see \autoref{sec:tocdepth} for a discussion of
  tocdepth) to become relative to where the local TOC originates. For example,
  assuming the default numeric level assignments to standard sectioning units
\begin{verbatim}
\section{This is a section}
\localtableofcontentswithrelativedepth{+2}
\end{verbatim}
  will create a local table of contents taking into account the subsections
  and subsubsections inside this section, independently of what is the value
  of the |tocdepth| counter at this position in the document. If the numeric
  argument had been |3|, the local TOC would have displayed also paragraphs.
  If the section had been a chapter, and again for a relative tocdepth of |2|,
  the taken into account levels would have been sections and subsections.
\end{description}

\section{Labeling and reusing elsewhere}
\label{sec:labeling}

\etoc allows to typeset at some location a local table of contents which is
defined elsewhere.  For this, two simple steps:
\begin{enumerate}
\item insert \localtoc at the distant place, and follow it by some
  |\label{foo}|.
\item insert \toc|\ref{foo}| (or \localtoc|\ref{foo}|, it does the same) at the
  place where you want this distant table of contents to appear.
\item in step \textbf{1}, if you use \invisiblelocaltoc in place of \localtoc,
  there will be no typesetting at its place of definition.
\end{enumerate}
At the place of use of \toc|\ref{foo}|, the layout and looks is entirely
configurable locally.  It may be completely different from how the same
contents are rendered elsewhere by another \toc|\ref{foo}| or by the original
label-decorated \localtoc|\label{foo}|.  The current value of the |tocdepth|
counter is obeyed.

As an example the table of contents corresponding to \autoref{part:styling}
has been cloned here in a
\hyperref[toc:d]{float} which appears \vpageref{toc:d}.
\begin{filecontentsdef}{etocsnippet-\snippetno.tex}{\foo}
\begin{figure}[ht!]
  \centering
  \begingroup
  % this is a KOMA-script specific customization
  \DeclareTOCStyleEntry[numwidth=2em,indent=0pt]{tocline}{section}
  \DeclareTOCStyleEntry[numwidth=3.2em,indent=2em]{tocline}{subsection}
  \etocstandardlines % <-- use the defaults from the document class
  \renewcommand{\etocbkgcolorcmd}{\color{green!5}}
  \renewcommand{\etocbelowtocskip}{0pt\relax}
  \fboxsep1ex
  \etocframedstyle [1]{\fbox{\makebox[.5\linewidth]{\etocfontminusone
        I am from \hyperref[toc:part:styling]{far away}}}}
  \etocsetnexttocdepth{subsection}
  \tableofcontents \label{toc:d} \ref{toc:part:styling}
  \endgroup
\end{figure}
\end{filecontentsdef}
\filecontentsexec\foo
We used this: \filecontentsprintviascan\foo
\marginattach

In the above example, not only did we use |\ref{toc:part:styling}| to print
here the distant (local) table of contents which has been labeled |toc:part:styling| but
we added a (possibly confusing) |\label{toc:d}|.  This is done for the
down-to-earth reason of being able to use, as we did in the previous
paragraph, |\vpageref{toc:d}|.  But if one wants to clone again the original
local table of contents, one must reference its original label:
\toc|\ref{toc:part:styling}|.%
%
\footnote{Why does this author always give
complicated examples rather than down-to-earth ones?}
%
This original local table of contents is to be found \vpageref{toc:part:styling}.

\section[\csbhyp{etocsetlevel}]{A powerful functionality of \etoc: the
  re-assignment of levels with \csbhyp{etocsetlevel}}
\label{sec:tocdepth}

The intrinsic levels manipulated by \etoc are numeric: from
|-2| (which corresponds to |book| in the \ctanpkg{memoir} class)
down (from the big to the small)
to |5| (|subparagraph|). But the assignment of a numeric level
to a given name can be modified at any time with the command
\csb{etocsetlevel}\marg{level\_name}\marg{number}. In conjunction
with the use of the \LaTeX{} |tocdepth| counter, this has
powerful applications: \meta{level\_name} does not have to
coincide with an actual document sectioning command, and \etoc
can be used to print arbitrary ``lists of things'', using no
other auxiliary file than the |.toc| file. This is
explained further in \autoref{part:surprising}.

\begin{framed}
  It is often said that in the standard classes, the sectioning
  level of |\part| is |0| in the classes not having a |\chapter|
  command, and |-1| in classes having a |\chapter| command. This
  is \emph{correct} for what regards the \emph{automatic
    numbering}, as is governed by the value of the |secnumdepth|
  counter; but it is \emph{wrong} for what regards the effect of
  the |tocdepth| counter: setting the |tocdepth| to |-1| in the
  |article| class just before |\tableofcontents| does \emph{not}
  prevent Parts from appearing in the Table of Contents. One has
  to set it to |-2| for that, whether in the |article| or in the
  |book| class.

  The canonical levels, a priori known to \etoc, are those of
  relevance to the \textbf{|tocdepth|} counter in the standard
  classes and are recapitulated in this table: \centeredline{
    \fbox{\begin{tabular}{rc}
        (\ctanpkg{memoir} class) book&-2\\ part&-1\\ chapter&0 \\
        section&1\\ subsection&2 \\
        subsubsection&3 \\ paragraph&4 \\ subparagraph& 5
    \end{tabular}}}

\smallskip With \etoc, the user can easily print a local table of
contents inside a given subsection, where subsubsections will be
printed in the style of sections, paragraphs in the style of
subsections, and subparagraphs in the style of subsubsections, if
so desired. One can also decide to set everything to be at the level
|6| (never displayed by \etoc), except for example
paragraphs, promoted to be at level |1|, and then one obtains a nice
table of contents of all the paragraphs from the document!
(|tocdepth| at least |1|)\footnotemark
\end{framed}

\footnotetext{and one should naturally not print this TOC of paragraphs in
  compatibility mode, which would insist on inserting a gigantic left
  margin.}

\section{The \csbhyp{etocsettocdepth} and \csbhyp{etocsetnexttocdepth} commands}
\label{etocsettocdepth}
\label{etocsetnexttocdepth}
\label{invisibletableofcontents}

The |tocdepth| counter has no bearing on what gets written to the |.toc| file;
its action is only on the actual typesetting of the table of
contents.\footnote{In the standard classes (at least), it also influences the
  \csa{listoftables} and \csa{listoffigures}, via \csa{@dottedtocline}.} In the
standard classes there is only one |\tableofcontents| possible, whereas with
\etoc, arbitrarily many are allowed, so one may change |tocdepth| to the
appropriate value (which decides the finest sectioning level displayed) again
and again each time a table of contents needs to be typeset.

\etoc provides \csb {etocsettocdepth}\marg{level} whose mandatory argument is
either
numeric (from |-3| to |5|) or a division name such as |subsection| or
|subsubsection| or any name previously declared to \etoc with
\csb{etocsetlevel} (the keywords |all| and |none| are recognized, although not
corresponding to a document division).
This does the appropriate |\setcounter{tocdepth}{numeric_level}|.

As is explained in the next subsection, |tocdepth| is used by \ctanpkg{hyperref}, and
one must take steps to prevent its changes from influencing the bookmarks, too.
So, \etoc has \csb {etocsetnexttocdepth}\marg{level} whose influence ceases
immediately after the next table of contents.  The package defines
\csb{invisibletableofcontents}
essentially as
\centeredline{\csb{etocsetnexttocdepth}|{none}|\csb{tableofcontents}}

The simplest organization is probably to have after |\begin{document}| and before the
  first |\tableofcontents| a single instance of the \csb{etocsettocdepth}
  command, with argument the deepest level (or most commonly used deepest level)
  among the tables of contents of the document, and to use locally,
  where needed, \csb{etocsetnexttocdepth} before |\tableofcontents| or
  |\localtableofcontents|.

\begin{framed}
  It is possible to use \csb{etocsettocdepth} inside the first argument of
  \csb{etocsettocstyle} (possibly in conjunction with checking the
  \csb{etoclocaltop} value, \emph{which however will be up-to-date there only if
  \csb{etocchecksemptiness} was executed}). There is no worry then about
  possible impact on hyperref bookmarks later on, because \etoc always resets
  the |tocdepth| counter after typesetting a TOC to the value it had before
  it.

  % Since \etocrelease{1.09}
  The macro \csb{etocsetnexttocdepth} works also if located in
  first argument of \csb{etocsettocstyle}, but there is no reason to use it
  there as \csb{etocsettocdepth} has no durable effet on the |tocdepth|
  counter if executed there.

  Check \csb{localtableofcontentswithrelativedepth} for a simpler way to
  control the depth of local tables of contents. This has the advantage of
  working reliably whether or not the \csb{etocchecksemptiness} is used.
\end{framed}

\subsection{The hyperref option \emph{bookmarksdepth}}
\label{ssec:bookmarksdepth}

When modifying the counter |tocdepth| for the purposes of
multiple uses of \toc or \localtoc, one should be aware that
package \ctanpkg{hyperref} by default takes into account the
\emph{current} value of the |tocdepth| counter to decide
whether the |pdf| file will contain a bookmark corresponding
to sectioning commands encountered in the source file. Thus,
one typically needs to reset |tocdepth| to its previous
value after having temporarily modified it for a given table of
contents.

Or, there is the \emph{bookmarksdepth=n} option of package
\ctanpkg{hyperref}, with \emph{n} the desired document bookmarks
maximal depth, which can be numeric or the name of a level known to
\ctanpkg{hyperref}. This documentation previously passed |bookmarksdepth=3| as
option to \ctanpkg{hyperref}, so even if |tocdepth| was left to |1|
by inadvertance after printing a certain table of contents
this did not modify the bookmark tree of the |pdf| file. Now that
\csb{etocsetnexttocdepth} has been added to the package, we have used it
systematically and there was no need for  |bookmarksdepth=3| anymore.

\section[The \csbhyp{etocsettocdepth.toc} command]{The
  \csbhyp{etocsettocdepth.toc} and
  \csbhyp{etocimmediatesettocdepth.toc} and commands}
\label{etocsettocdepth.toc}
\label{etocimmediatesettocdepth.toc}

This command \csb{etocsettocdepth.toc} implements some functionality of
\ctanpkg{tocvsec2}%
%
\footnote{I thank Denis \textsc{Bitouzé} for drawing
  my attention to the incompatibility of this package with \etoc.},
%
a package
which however was incompatible with \etoc (it can still be used for its
|secnumdepth|-related commands, but its |toc|-related activities will get
canceled by \etoc) and more-or-less designed for a single table of contents.

The action of \csb{etocsettocdepth.toc} is totally different than the one of
\csb{etocsettocdepth}. Rather than modifying the |tocdepth| counter immediately,
it adds a line to the |.toc| file which, when executed inside a table of
contents will enact this change.

The command \csb{etocsettocdepth.toc}, like
\csb{etocsettocdepth}, accepts both numeric and named
arguments. In the case of a named argument, the actual numeric
value to be used is not yet decided at the time the |.toc|
file is created; it will be the value currently specified for
the named level at the time each table of contents (not having
done |\etocignoretoctocdepth|) is typeset.

The |tocdepth| counter will never be set to a value finer than its initial value
at the start of the table of contents: so adding commands
\csb{etocsettocdepth.toc} in the document is a way to \emph{restrict} locally
the depth of the table of contents. For example to prevent inclusion in the
tables of contents of the sub-sub-sections of a given chapter.

This
{\fbox{gets executed in ALL tables of contents.}}

Also \csb{etocimmediatesettocdepth.toc} is provided.  For explanations,
refer to the discussion of \csb{etocimmediatedepthtag.toc} in the
next section.

\subsection{The \csbhyp{etocobeytoctocdepth} and
  \csbhyp{etocignoretoctocdepth} commands}
\label{etocobeytoctocdepth}
\label{etocignoretoctocdepth}


So \csb{etocignoretoctocdepth} is provided to cancel the
\csb{etocsettocdepth.toc} mechanism when
needed; and \csb{etocobeytoctocdepth} will
re-activate it. The package does initially \csb{etocobeytoctocdepth}.

\section[The \csbhyp{etocdepthtag.toc} and \csbhyp{etocsettagdepth} commands]{The
  \csbhyp{etocdepthtag.toc}, \csbhyp{etocimmediatedepthtag.toc} and
  \csbhyp{etocsettagdepth} commands}
\label{etocdepthtag.toc}
\label{etocimmediatedepthtag.toc}
\label{etocsettagdepth}



% Release \etocrelease{1.07h} has a
The command \csb{etocdepthtag.toc}
allows to control dynamically the which contents end up included in the
displayed TOCs (this documentation also decribed formerly a way
using \csb{etocsettocdepth.toc} with some dummy level name, which got
then set via \csb{etocsetlevel} according to what was locally needed,
but it was too hacky and I am not sure if it was understandable).

It is used as \csb{etocdepthtag.toc}\marg{tag\_name}, where the
\meta{tag\_name} is anything, and this will put the tag in the |.toc|
file. When typesetting a TOC, one issues a series of commands
\csb{etocsettagdepth}\marg{tag\_name}\marg{level} where the
\meta{level} may be either numeric (from |-3| to |5|) or the name of a
division unit known to \etoc, or |none| or |all|. The effect of the tag
inside the |.toc| file will then be to set the |tocdepth| counter to
the desired value, in real time (this can not get finer than the
initial value of |tocdepth| at the start of the TOC).

The added flexibility is thus that \csb{etocsetlevel} has not been used in a
kind of hacky way, that one may use named level depths, and the
keywords |none| and |all|.

As usual, once the tag depths have been set, they remain in effect until getting
redefined or seeing their scope expire via the closing of a group or of a
surrounding
environment. For an example, see \autoref{sec:tocwithdepthtags}.

When using \csb{etocdepthtag.toc} in combination with \LaTeX's |\include|,
data may not end up in the |.toc| file in the correct order.  For example in
this situation:
\begin{verbatim}
  \clearpage % or anything ending up causing its presence here right before
             % the \etocdepthtag.toc
  \etocdepthtag.toc{sometag}
  \include{some file containing sections}
\end{verbatim}
The tag will end up in the |.toc| file \emph{after} all section headings from
the included file.  The cause is that \LaTeX\ inserts immediately in the
main auxiliary file a command to input the auxiliary file of the included file
(which in turn, contains instructions to add data to the |.toc| file).  But
\csb{etocdepthtag.toc} does not internally use such immediateness, as it uses
the same interface as |\section| and alike commands when they want to write
extra data to the |.toc| file.

So%
%
\footnote{Thanks to Norman \textsc{Ramsey} who reported this problem, together
  with a fix, in July\dots 2016.  Sorry for long delay before updating
  \etoc six years later\dots}
%
% \etocrelease{1.09f} adds
there is \csb{etocimmediatedepthtag.toc} which will force the tag to be written
immediately to the |.toc| file (well, rather immediately to the |.aux| file,
so before the inclusion of the auxiliary file of the included file).

One should not use this variant systematically.  For example if your document
looks like:
\begin{verbatim}
\clearpage

\section{bbbb}

Some text

\etocdepthtag.toc{sometag}
\etocimmediatedepthtag.toc{someimmediatetag}
\section{cccc}

Some text

\end{document}
\end{verbatim}
then the |someimmediatetag| will end up being inserted in |.toc| file
\emph{before} the |bbbb| section.  This is because \LaTeX's |\section|
uses a \emph{delayed} write, not an \emph{immediate} one.  And
\csb{etocdepthtag.toc} wisely uses a \emph{delayed} write.

As it seems very hard programmatically to identify automatically if the
\emph{immediate} variant of \csb{etocdepthtag.toc} should be used, the package
provides two separate commands and it is up to user to make the correct
choice.


\subsection{The \csbhyp{etocobeydepthtags} and \csbhyp{etocignoredepthtags} commands}
\label{etocobeydepthtags}
\label{etocignoredepthtags}


After \csb{etocignoredepthtags}, the |.toc| depth tags are ignored (but
\csb{etocdepthtag.toc} still works). The package does initially
\csb{etocobeydepthtags} which makes \etoc react to the found tags in the
|.toc| file.

\section{Adding commands to the \texorpdfstring{\texttt{.toc}}{.toc} file}
\label{sec:addingtotoc}

We described above \csb{etocsettocdepth.toc} and \csb{etocdepthtag.toc} which
both insert commands inside the |.toc| file. An even more general mechanism of
adding ``action tags'' to the |.toc| file could be envisioned, but this would
just be a wrapper for direct use of |\addtocontents{toc}{\something}|.

One should be cautious when adding in this way
things
to the |.toc| file. For example, inserting
\csa{addtocontents}|{toc}{\string\clearpage}|
just
before a \csa{part} to fix the problem when some part entry (in
the table of contents) is isolated at the bottom of one page,
will cause problems with multiple TOCs: this \csa{clearpage}
will be executed by \etoc each time a \toc or \localtoc
command is encountered! The more prudent thing is to do
rather: {\csa{addtocontents}|{toc}{\string\myclearpage}|,}
to have a |\let\myclearpage\relax| at the top level of the
document and  to use where needed something like:
\begin{verbatim}
\let\myclearpage\clearpage
\tableofcontents
\let\myclearpage\relax
\end{verbatim}
The \ctanpkg{memoir} class has the command \csa{settocdepth} which
writes a \csa{changetoc\-depth} command inside the |.toc| file.
This will impact the typesetting by \etoc of \emph{all} tables
of contents, with (possibly) unexpected results: imagine the
document has \csa{settocdepth}|{chapter}| at some point to
avoid having the sections from subsequent chapters be listed
in the main table of contents. Then a local table of contents
in one of these chapters will print a title but will be
without any entry.

As the \ctanpkg{memoir} class by itself allows multiple\toc
  these issues already arise there,
  independently of \etoc, see page 170 of the \ctanpkg{memoir}
  manual.

For this specific issue, the commands \csb{etocsettocdepth.toc},
\csb{etocignoretoctocdepth} and \csb{etocobeytoctocdepth} are the way to go; or
their variants \csb{etocdepthtag.toc} and \csb{etocsettagdepth}.

As an aside, any |\setcounter{tocdepth}{n}| command added directly to the |.toc|
file will see its effect
% (since release \etocrelease{1.07g})
cease when the end of a table of contents is reached, as \etoc executes a
|\setcounter{tocdepth}{previous_value}| there, to reste the \texttt{tocdepth}
counter to the value it had on entering the table of contents.

\subsection{The hyperref option \emph{hidelinks}}\label{ssec:hidelinks}

The colored links (and also the rectangle links) are a bit
annoying when used in tables of contents, especially when
the document uses \etoc and has plenty of them! One may wish
for having colored links, \emph{except} for those within
table of contents!
Indeed, why would things in TOCs need to be either framed in
rectangles or colored, when the user \emph{already expects
  them to be links}?

I use the following trick:  either in the preamble using
|\AtBeginDocument|, or right after |\begin{document}|, I
  have the command
  \centeredline{|\addtocontents{toc}{\protect\hypersetup{hidelinks}}|}

  \begin{framed}
    All TOCs typeset by \etoc have their contents done
    within a group (as if enclosed in an environment). So
    the command \csa{hypersetup}|{hidelinks}| will be
    executed by \emph{each} TOC, but its effect will be
    limited to that TOC.
  \end{framed}

  I found out experimentally that the option |hidelinks| could
  indeed be set many times with |\hypersetup| (this is not the
  case of all \ctanpkg{hyperref} options).

\section[The \csbhyp{etocsetlocaltop.toc} command]
        {The \csbhyp{etocsetlocaltop.toc} and
          \csbhyp{etocimmediatesetlocaltop.toc} commands}
\label{etocsetlocaltop.toc}
\label{etocimmediatesetlocaltop.toc}

It is important to understand that \csb{localtableofcontents} works entirely
from data \emph{in the |.toc| file}. If the document, say with |article|
class, contains starred sectioning commands, which are not accompanied
by suitable \csa{addcontentsline}, then these units are completely
transparent to \csb{localtableofcontents}:
\begin{itemize}
\item If \localtoc is issued before |\section*{Foo}|, say locally to a |\section|,
  then the local TOC will include not only the |subsection|s between the
  |\section| and the |\section*{Foo}| but also those following, and it will
  stop only at encountering a later |\section| or |\part| from the document's body.
\item If the command is issued right after |\section*{Foo}| and the later was
  itself subsequent to a (numbered) |\subsection|, then \etoc will think it
  must display a TOC local to the \emph{subsection}.
\end{itemize}

% Since release \etocrelease{1.08k}, \etoc provides the one-argument
There is the command
\csb{etocsetlocaltop.toc} to insert into the |.toc| file a kind
of ``ghost'' of a given sectioning unit. Here is an example:

\begin{verbatim}
\part*{Extra unnumbered part}
\etocsetlocaltop.toc{part}
\localtableofcontents
\end{verbatim}

So with no |\part| heading inserted into the table of contents via an
|\addcontentsline|, still \localtoc will know it is local to a part.  In this
example the local contents will be delimited by the next numbered |\part|, or
|\part*| with |\addcontentsline|, or also by a later, second,
|\etocsetlocaltop.toc{part}|.

As a (counter)-example consider this document:
\begin{verbatim}
\documentclass{article}
\usepackage{etoc}
\begin{document}
\tableofcontents

\part*{A}
\etocsetlocaltop.toc{part}
\localtableofcontents

\section{I}

\section{II}

\part*{B}

\section{III}

\part*{C}

\section{IV}
\end{document}
\end{verbatim}
It uses only |\part*|.  Thanks to the \csb{etocsetlocaltop.toc} the \localtoc
knows it should report only sections.  But the other |\part*| are invisible to
it as nothing is recorded in the |.toc| file.  So the local table of contents
in this example will list \emph{all} sections not only |I| and |II|.  To fix thix one may
e.g.\@ insert another |\etocsetlocaltop.toc{part}|, this time after |\part*{B}|
(or make this a numbered part, or use |\addcontentsline| for it).

The above document amended with added  |\etocsetlocaltop.toc{part}| after each
unnumbered part will thus have its main TOC without any |Part| heading, but
each |\part| can show a correct \localtoc.  The simpler
approach would be to use |\addcontentsline| with each unnumbered |\part| so
that it ends up in the |.toc| file, but \etoc is keen on allowing the most
diverse point of views.

It should be stressed that the various |\etocsetlocaltop.toc|\marg{sect. unit}
do impact the global \toc: they really act like actual sectioning units,
except for not inducing any typesetting.  In usual document classes, this
would appear to mean that they are completely transparent to the global \toc.
Not the case with \etoc, which adds a virtual assembly of levels: the |.toc|
data originating in |\etocsetlocaltop.toc|\marg{sect. unit} will trigger the
execution of the \marg{finish} parts of the line styles of finer sectioning
units encountered before (either in the global \toc or in an active
\localtoc); and it triggers the \marg{start} parts of the line styles of finer
units encountered after it (again in the global \toc, but also in any
\localtoc which is already activated at a coarser lever).

Depending on how the toc line styles are configured this may translate into
some visual effect; for example with the \etoc own line styles the
\marg{start} and \marg{finish} mostly insert penalties or vertical spaces.

It is a matter of debate if this is good design; a variant serving purely to
influence boundaries of local table of contents with no collateral effects
could be provided.  And the name of the macro was perhaps not so well chosen
as it suggests it acts as would such an hypothetical variant.  In absence of
feature requests we leave the matter standing for now.%
%

Usage of \csb{etocsetlocaltop.toc} interacts with
\csb{etocchecksemptiness} in the expected way: it modifies (as explained
above) the selection made by \csb{localtableofcontents}, hence the decision
whether this local TOC will end up empty or not.

There is also \csb{etocimmediatesetlocaltop.toc}.  This may be useful in some
very special circumstances involving |\include|.  For related discussion see
the documentation of \csb{etocimmediatedepthtag.toc}.


\section{The \csbhyp{etoclocaltop} command}
\label{etoclocaltop}

Within either the TOC style
(\csb{etocsettocstyle}) or the local title styles (\csb{etocsetstyle}), the
control sequence \csb{etoclocaltop} is made equivalent for the duration of
\csb{localtableofcontents} to a numeric (self-delimiting) denotation of the
current top level.

Thus: it will in numeric contexts (|\ifnum|, |\ifcase|, ...) represent zero
for a local TOC corresponding to chapter, or one if in a section, or two if in
a subsection, etc..., assuming of course here that the default levels are
obeyed (see \autoref{sec:tocdepth}).

%\begin{framed}
  \csb{etoclocaltop} from inside the TOC heading (first argument of
  \csb{etocsettocstyle}) has the correct value \emph{only under
    \csb{etocchecksemptiness} regime}. Special circumstances correspond to
  some special values:
  \begin{description}[nolistsep]
  \item[|-3|] (|-\thr@@|)\newline
    signals that \etoc considers the local TOC to be
    ``unknown''; this happens at the last local TOC, for the first \LaTeX\ run
    after adding a new \localtoc to the document. In doubt, \etoc assumes the
    TOC will prove non empty, hence it prints (independently of whether the
    check for emptiness was activated or not) the heading as specified by
    \csb{etocsettocstyle}. Thus, check if \csb{etoclocaltop} gives |-3| as a
    a \meta{number} to detect that situation from within the first argument of
    \csb{etocsettocstyle}, if desired.
  \item[|-1000|](|-\@m|)\newline  is in case of a \localtoc
    being considered ``known'' (although it may still refer to the data in the
    |.toc| file from the previous run) but without the check for emptiness
    having been executed.
  \item[|-10000|](|-\@M|)\newline  is the value when accessed from the title
    of a global TOCs.
  \end{description}
%\end{framed}
%\begin{framed}

  When executed from within a local table of contents \textbf{line styles}
  (\csb{etocsetstyle}), \csb{etoclocaltop} always will hold the correct value,
  whether or not the emptiness check was executed.

  For a global table of contents however, it will always keep the value |-3|.
%\end{framed}

Attention! \cs{etoclocaltop} is only to be queried not set.



\section{Checking TOCs for emptiness}

\subsection{The \csbhyp{etocchecksemptiness} command}
\label{etocchecksemptiness}
\label{etocdoesnotcheckemptiness}

The user needs to issue \csb{etocchecksemptiness} to tell \etoc to check whether
local tables of contents are empty and in case of emptiness to print nothing
at all.\footnote{Thanks to Paul Gaborit who asked for
such a feature.} This
can be useful to authors of \LaTeX{} classes who for example wish to have a
|\chapter| command doing systematically a \localtoc, or for
people producing files via automatic conversions and some of those might have
sectioning commands and others not.

«Emptiness» means that no \csa{contentsline} command would get executed within
the scope of the local table of contents --- empty line styles by themselves do
not make the TOC empty. \etoc always executes the \csb{etocaftertochook}
command; and the test for emptiness itself executes everything else found in
the |.toc| file. See \autoref{sec:addingtotoc} in this context.
\begin{enumerate}
\item the \csb{etocifwasempty} command discussed below can be used from inside
\csb{etocaftertochook}, and even from inside \csb{etocbeforetitlehook}.
\item there is also \csb{etocdoesnotcheckemptiness}.%
% (since \etocrelease{1.08i}.)
\end{enumerate}

The suppression of the heading (more precisely of the toc display style
elements) may be effective only for the final \LaTeX{} runs. For example in
the situation of a \toc|\ref{foo}| where the label |foo| is
not yet recognized, the heading (but not the contents) is printed and the TOC
is declared non-empty. Or, if one adds a \localtoc to a document, on the next
run, the test for emptiness will in fact apply to the next one, and the last
local TOC of the document will have its contents temporarily unknown to \etoc,
hence will be declared non empty, and the heading will be printed.

For a finalized document compiled with initially no auxiliary files, the first
\LaTeX{} run will declare all local TOCs non empty and print for each of them a
heading (and no contents naturally). The second \LaTeX{} run will then
correctly decide which local TOC is empty or not.

\subsection{The \csbhyp{etocnotocifnotoc} command}
\label{etocnotocifnotoc}

The user can then extend the emptiness-checking to the global TOCs with
\csb{etocnotocifnotoc}. May I respectfully give the advice then to rather do
none of |\usepackage{etoc}| nor \toc ? |;-)|. Well, there is always the case
of batch conversions of documents having or not sectioning units.

\subsection{The \csbhyp{etocifwasempty} command}
\label{etocifwasempty}
\label{etocxifwasempty}

The command \csb{etocifwasempty}\marg{YES}\marg{NO} executes \meta{YES} if
the previous TOC was found to be empty and \meta{NO} if its was not so. This
may serve to act appropriately after a truly empty TOC. If
\csb{etocchecksemptiness} has not been issued, this conditional always
executes the \meta{NO} branch.

This command is robust, and \csb{etocxifwasempty} is its expandable
version.

\fbox{Do not forget the second argument: at least an empty pair of braces |{}|
  must be present.}

This conditional may wrongly say that the local TOC is empty or not empty
until \LaTeX{} compilations stabilize. But if it says that a local TOC is
empty, this does mean that \etoc considered the just encountered local table
of contents to be empty (for that run) and thus printed nothing (not even a
|\par|).


\clearpage
\etocdepthtag.toc {examples}
\part{Examples}\label{part:examples}

\thispartstats %% (pas de sous-section)

\etocdefaultlines
\etocsettocstyle {}{}
\localtableofcontents

To understand all code snippets in detail,
one will need to have first browsed through \autoref{sec:linestyles}
and \autoref{sec:tocstyle}.



\section{A first example}
\label{sec:firstexample}
\label{invisiblelocaltableofcontents}

Let us present a first example of specification for line styles.
Immediately after the start of \autoref{part:overview} we inserted in the
source file:
%
\centeredline{\csb{invisiblelocaltableofcontents} |\label{toc:overview}|}
%
This
sets-up the label |toc:overview|, and we can use it at any location in the
document:
%
\centeredline{|\tableofcontents \ref{toc:overview}|}
%
And as we used
|\invisible...|,\footnote{this is a shortcut for setting temporarily the
  |tocdepth| to |-3|, which has the effect to tell \etoc not to print the TOC,
  and not even the heading.} the local TOC will exist only through its clones
elsewhere in the document.

\begin{filecontentsdef}{etocsnippet-\snippetno.tex}{\foo}
\begingroup\parindent 0pt \parfillskip 0pt \leftskip 0cm \rightskip 1cm
\etocsetstyle {section}
              {}
              {\leavevmode\leftskip 0cm\relax}
              {\bfseries\normalsize\makebox[.5cm][l]{\etocnumber.}%
               \etocname\nobreak\hfill\nobreak
               \rlap{\makebox[1cm][r]{\mdseries\etocpage}}\par}
              {}
\etocsetstyle {subsection}
              {}
              {\leavevmode\leftskip .5cm\relax }
              {\mdseries\normalsize\makebox[1cm][l]{\etocnumber}%
               \etocname\nobreak\hfill\nobreak
               \rlap{\makebox[1cm][r]{\etocpage}}\par}
              {}
\etocsetstyle {subsubsection}
              {}
              {\leavevmode\leftskip 1.5cm\relax }
              {\mdseries\normalsize\makebox[1cm][l]{\etocnumber}%
               \etocname\nobreak\hfill\nobreak
               \rlap{\makebox[1cm][r]{\etocpage}}\par}
              {}
\etocruledstyle[1]{\bfseries \Large My first \etoc: TOC of
  \autoref{part:overview} (\nameref{part:overview})}
\tableofcontents \ref {toc:overview}
\endgroup
\end{filecontentsdef}

\filecontentsexec\foo

We could have used the line styles defined by \etoc, with
\csb{etocdefaultlines}, or the default document class styles with
\csb{etocstandardlines}, but we were a bit more ambitious here and wanted to
design our own. The technique is a simple one: each heading is in its own
paragraph, which may extend on multiple lines; it is responsible for setting
its own |\leftskip|.

This is a simple design which does not make provisions for page breaks
which should be discouraged in-between a section and a subsection
etc\dots{} as we only used it for the table of contents of this part, thus
with sections as top levels, there was no need to specify a style for
parts too (we defined a subsubsection line style but as it turns
out there are no subsubsections in this part). The two commands used are
\csb{etocsetstyle} for specifying the line styles, and
\csb{etocruledstyle} for the TOC global style.

The |\rightskip| is shared by all, and creates space where the page
numbers get printed. For an elaboration of this technique see the next
\autoref{sec:secondexample} as well as \autoref{sec:tocwithdepthtags}
which provides a TOC with parts and paragraphs. Both allow multi-line
headings and employ a technique for putting page numbers in the right margin
which was inspired from what \LaTeX2e's |\@dottedtocline| macro does.

Here is how it was produced:

\filecontentsprintviascan\foo
\marginattach

\section{A second example}
\label{sec:secondexample}

This second example displays only the contents from
\autoref{sec:linestyles} and \autoref{sec:tocstyle}. This selection
is done via the technique of \emph{depth tags}, described in
\autoref{etocsettagdepth} and \autoref{sec:tocwithdepthtags}.

\begin{filecontentsdef}{etocsnippet-\snippetno.tex}{\foo}
\begingroup
\newcommand*{\DotsAndPage}
{\nobreak\leaders\hbox{\bfseries\normalsize\hbox to .75ex {\hss.\hss}}%
         \hfill\nobreak
         \makebox[\rightskip][r]{\bfseries\normalsize\etocpage}\par}

\etocsetstyle {part}
{\parindent 0pt
 \nobreak
 \etocskipfirstprefix}
{\pagebreak[3]\bigskip}
{\large\rmfamily\bfseries\centering %\scshape
 \etocifnumbered{Part \etocnumber{} -- }{}\etocname\par}
{}

\etocsetstyle {section}
{\leftskip 0pt \rightskip .75cm \parfillskip-\rightskip
 \nobreak\medskip
 \etocskipfirstprefix}
{\leftskip 0pt \rightskip .75cm \parfillskip-\rightskip
 \pagebreak[1]\smallskip}
{\normalsize\rmfamily\bfseries %\scshape
 \etocnumber. \etocname\DotsAndPage }
{\parfillskip 0pt plus 1fil\relax }

\etocsetstyle {subsection}
{\leftskip1cm\rightskip .75cm \parfillskip 0pt plus 1fil\relax
 \nobreak\smallskip}
{}
{\footnotesize\sffamily\mdseries\itshape
 \etocname{} (\etocnumber, p. \etocpage). }
{\par\medskip}

\etocsettagdepth {preamble}   {none}
\etocsettagdepth {overview}   {none}
\etocsettagdepth {styling}    {subsection}
\etocsettagdepth {control}    {none}
\etocsettagdepth {examples}   {none}
\etocsettagdepth {advanced}   {none}
\etocsettagdepth {etocandworld}{none}
\etocsettagdepth {code}       {none}

\etocsettocstyle {\centering\LARGE\textsc{\contentsname}\par\nobreak\medskip}{}
\etocsetnexttocdepth {subsection}
\tableofcontents
\endgroup
\end{filecontentsdef}
\filecontentsexec\foo

The code:
\filecontentsprintviascan\foo
\marginattach

\section{A Beautiful Thesis example}

Here is a relatively  simple example of use of the package
functionalities.
Let us set up some line styles. We choose a style for sections and
sub-sections which would be suitable for, respectively, sections and
sub-sections in an average length memoir. The line style specifications have
some redundancy for clarity, and do not care about what to do at possible page
breaks. Also, they do not worry about potential multi-column use.

\begin{filecontentsdef}{etocsnippet-\snippetno.tex}{\foo}
\begingroup % we start a group to keep the style changes local
\newlength{\tocleftmargin}    \setlength{\tocleftmargin}{4cm}
\newlength{\tocrightmargin}   \setlength{\tocrightmargin}{1cm}

\etocsetstyle{section}              % will pretend to be a Chapter
{\addvspace{1ex}\parfillskip0pt
 \leftskip\tocleftmargin            % (already done in title)
 \rightskip\the\tocrightmargin plus 1fil
 \parindent0pt\color{cyan}}         % (already done)
{\bfseries\LARGE\upshape\addvspace{1ex}\leavevmode}
{\llap{Chapter\hspace{.5em}{\etocnumber}\hspace{.75cm}}\etocname
 \nobreak\hfill\kern1em\makebox[-\tocrightmargin][l]{\makebox[0pt]{\etocpage}}\par}
{}

\etocsetstyle{subsection}           % will pretend to be a Section
{}
{\mdseries\large\addvspace{.5ex}\leavevmode}
{\llap{\etocnumber\hspace{.75cm}}\textit{\etocname}%
 \hfill\makebox[-\tocrightmargin][l]{\makebox[0pt]{\etocpage}}\par}
{}

\def\tmptitle{My Beautiful Thesis}
\etocsettocstyle{\color{cyan}\parindent0pt \leftskip\tocleftmargin
  \leavevmode\leaders\hrule height 1pt\hfill\
  \huge\textit{\tmptitle}\par}{\bigskip}

\tableofcontents \ref{toc:overview}
\endgroup
\end{filecontentsdef}

\filecontentsexec\foo

\filecontentsprintviascan\foo
\marginattach


\section{Testing the compatibility mode}\label{sec:testingcompat}

As a further example we now print the local table of contents
of \autoref{sec:tocstyle}. First we will test the compatibility mode.\footnote{the
present document uses the \ctanpkg{scrartcl} class, and we check here that
the \etoc compatibility mode does respect the customizing done via the
class commands.}   The original is the local table of contents of
\autoref{sec:tocstyle}, to which we allocated the label |toc:tocstyle|.
\begin{verbatim}
\begingroup % to keep in particular toc=left with local effect
\KOMAoptions{toc=left}
\etocclasstocstyle % necessary for the display to obey toc=left
\etocstandardlines
\tableofcontents \ref{toc:tocstyle}
\endgroup
\end{verbatim}
\begingroup
\KOMAoptions{toc=left}
\etocclasstocstyle
\etocstandardlines
\tableofcontents \ref{toc:tocstyle}
\endgroup

\section{Another compatibility mode}
\label{sec:anothercompat}

As explained in \autoref{subs:compat}, the commands \csb{etocstandardlines}
and \csb{etocetoclocaltocstyle} tell \etoc to, essentially, act as an
observer.  And it starts in this state initially.  The document class layout
for the table of contents is then perfectly obeyed (well, hopefully).  There
is no way \emph{if remaining in this compatibility mode} to customize this
standard layout (change fonts, margins, vertical spacings, etc...) from within
the package.

For customizing \emph{while remaining in the compatibility mode}, use some
package dedicated to this task; because \etoc either is (temporarily perhaps)
in compatibility mode with no customization on its part possible, or the user
has specified the layout in \csb{etocsetstyle} commands (and
\csb{etocsettocstyle}) and is supposedly in complete control.

Well, there is actually an alternative. It is possible to use the
\csb{etocsetstyle} commands to recreate an artificial compatibility mode, in
order to achieve effects like the following, all things being otherwise equal
to the document class defaults:
\begin{enumerate}[noitemsep]
\item get the \ctanpkg{hyperref} link to encapsulate only the names, but not the numbers
  of each entry of the table of contents,
\item use the document class style for chapters and sections, but modify it only
  for subsections,
\item do either of the above only for some portions of the table of contents.
\end{enumerate}

One only needs
to use within the arguments of \csb{etocsetstyle} the \LaTeX{} standard
\csa{l@chapter}, \csa{l@section}, etc...  re-constituting their arguments using
\csb{etocname}, \csb{etocnumber}, \csb{etocpage} as one wishes.
Here is an example. Include in the preamble:

\begin{filecontentshere}{etocsnippet-\snippetno.tex}
\makeatletter
\newcommand{\MyLocalTOC}[1][section]{%
  \begingroup
  \etocsetstyle{section}{}{}
    {\l@section{\numberline{\etocnumber}\etocname}{\etocpage}}{}%
  \etocsetstyle{subsection}{}{}
    {\l@subsection{\numberline{\etocnumber}\etocname}{\etocpage}}{}%
  \etocsetstyle{subsubsection}{}{}
    {\l@subsubsection{\numberline{\etocnumber}\etocname}{\etocpage}}{}%
  % etc... if further sectioning units are needed
  %        (i.e. not excluded by tocdepth and actually there in document)
  % Here #1 defaults to section, meaning this is appropriate
  % for local TOC in a chapter
  \etocsettocstyle{\@nameuse{#1}*{Local contents}}
                  {}
  %
  \localtableofcontents
  \endgroup}
\makeatother
\end{filecontentshere}
\marginattach

Then use \csa{MyLocalTOC} in the document body.  It is prepared
for being  local to a \csa{chapter}'s as it typesets the heading of the TOC
by default as un unnumbered section.%
%
\footnote{Parts are handled somewhat differently according to whether
one uses the standard or other classes; please check the source of these
classes for what is to emulate here.}

One can add to the above arbitrary text formatting commands, for example
one can replace |\etocpage| in the code above by |\textcolor{blue}{\etocpage}|.

Only pay attention to using |\makeatletter/\makeatother| as we are handling
\LaTeX{} macros with the dangerous sign |@| in their names.

To give another example, one sees in \texttt{article.cls} the following
definition:
\begin{verbatim}
\newcommand*\l@subsection{\@dottedtocline{2}{1.5em}{2.3em}}
\end{verbatim}
The first argument is the level, the second the indent, and the third the
numwidth (see the \ctanpkg{tocloft} documentation).  So if we issue in a
document using the \texttt{article} class:
\begin{verbatim}
\makeatletter
\etocsetstyle{subsection}
    {]
    {}
    {\@dottedtocline{2}{1.5em}{2.3em}{\numberline{etocnumber}\etocname}{\etocpage}}
    {}
\makeatother
\end{verbatim}
we then basically reconstitute the default rendering.  Here is more careful
code:
\begin{verbatim}
\makeatletter
\etocsetstyle{subsection}
    {]
    {}
    {\@dottedtocline{2}{1.5em}{2.3em}{\etocifnumbered{\numberline{etocnumber}}{}%
                                      \etocname}{\etocpage}}
    {}
\makeatother
\end{verbatim}
Hence one can very easily without any (additional...) package modify the
hard-coded indent |1.5em| and numwidth |2.3em|.  But in general one has to do
this in a synchronized way also for subsubsections, and for sections.  The
definition of |\l@section| in the \texttt{article} class source is a bit more
complex.

Nevertheless this technique is probably the fastest (but see the example at
start of \autoref{sec:linestyles}) to get going with \etoc even if one is
primarily interested only in its \localtoc, as typesetting local tables of
contents exactly as global tables of contents is not ideal.  For example for a
local TOC in a section, it looks appropriate to modify the above into
\begin{verbatim}
\makeatletter
\etocsetstyle{subsection}
    {]
    {}
    {\@dottedtocline{2}{0}{2.3em}{\etocifnumbered{\numberline{etocnumber}}{}%
                                      \etocname}{\etocpage}}
    {}
\makeatother
\end{verbatim}
to cancel the indentation.  One will have to keep the indents and numwidths in
sync with similar changes to other line styles, if \csa{contentsline}'s of
various levels are to be executed.

%
%
The number and the name of each entry are each separately an \ctanpkg{hyperref}
links, as is always the case with \etoc, when not in compatibility
mode. Replacing \csb{etocnumber} with \csb{etocthenumber} will give a TOC where
the numbers are not links anymore, but the names still are. Or one may decide
to use \csb{etocthename} and keep an hyperlinked number with \csb{etocnumber}.

For a more sophisticated example see \autoref{sec:anothercompatadvanced}.

\begin{shaded}\footnotesize\itshape
  \textcolor{red}{Attention Please!}  The \LaTeX{} kernel is moving towards
  adding \emph{tagging} to the PDF, in a way mostly automated and transparent
  to user.  \etoc will in due time accompany that evolution but this may mean
  that it will use for its own the hooks that \LaTeX{} will place for example
  in \emph{\csa{@dottedtocline}}.  So, if the user explicitly also requires
  usage of \emph{\csa{@dottedtocline}}, this \emph{may} mean that some tagging
  code would be executed twice, possibly causing some havoc.

  My remark is \emph{purely hypothetical}, as a.t.t.o.w.\@ (2023/02/22) I have
  only started looking in the matter, and the \LaTeX{} and \ctanpkg{hyperref}
  TOC related changes have started being visible to developers only a few days
  ago.

  It may be however, that activating tagging could mean that the simple-minded
  recycling techniques described in this section will not work.  I guess \etoc
  will always have the possibility to let the user specify that \etoc should
  not take care itself of the tagging (which it has to do in general, because
  the \LaTeX{} hooks are located in places such as \emph{\csa{@dottedtocline}}
  which \etoc does not execute, except if asked to do so as in the example
  above), so perhaps the techniques here will still work but require some
  \emph{\csa{etocnotagging}} or some \emph{noetoctagging} option to the
  \localtoc or \toc commands.\par
\end{shaded}


\section{Emulating the book class}\label{sec:thirdexample}

As explained in \autoref{subs:compat}: without explicit use of an
\csb{etocsetstyle} command the package will leave to the document class the
hand regarding the ``toc line styles''. It is sometimes asked by users (for
example those using \etoc for its \csb{localtableofcontents}) how to stay
close to but not completely identical with the design implemented by the
standard classes, such as |book|. I can recommend package \ctanpkg{tocloft} for this,
as it is compatible with \etoc (see \autoref{subs:tocloft}) and thus \etoc will
obey the \ctanpkg{tocloft} customizations (as long as no use has been made of
\csb{etocsetstyle}). It is also possible to modify only the style for, say,
sections and leave the parts, chapters, subsections as in the document class,
via the technique from \autoref{sec:anothercompat}.

But for complete control, here is a translation of the |book| class code into
\etoc lingua. It is then easy to modify the relevant lengths or adjust the
used fonts. I thank \textsc{Denis Bitouzé} for prompting me to include this in
the \etoc manual, as it resulted from some conversation we had about this. The
code is not 100\% faithful to the |book| class, and particularly its rendering
of (multi-line) non-numbered units differs (... I think, as I copied pasted as
is the code from where I had stored it and did not do much thinking about it
again). Some proficiency in low-level \TeX\ and \LaTeX\ macros is needed to
understand what the code says, but for modifying fonts or some lengths such
in-depth understanding is not needed.

With some extra code one can \emph{automatically adjust the widths} assigned
to typesetting sectioning numbers in order to prevent overflows, even with for
example \MakeUppercase{\romannumeral 38}; but this is a more advanced feature
which I have moved to \autoref{sec:thirdexampleextra}.

First we set up some lengths. I use macro registers, not real \LaTeX\ lengths.
When using |em|'s however, this means that one must pay attention to when the
actual dimension assignment is made, as this will then depend upon the current
font settings. In the code below, at the location where the \csa{TOCnumwidthB}
and \csa{TOCnumwidthC} will be used, the |1em| from their specification will
be matched to the normal medium series font, not the bold font; this is
deliberate so that one can compare more readily with the other dimensions;
besides, with the \csa{TOCcomputenumwidths} from
\autoref{sec:thirdexampleextra} these macros will actually hold a dimension
using |pt| as dimensional unit.

\begin{filecontentshere}{etocsnippet-\snippetno.tex}
% it will be easy to globally shift the TOC horizontally if needed
\def\TOCleftmargin     {0pt}
\def\TOCrightmargin    {2.55em}% like LaTeX's \@tocrmarg

% this is for dotted leaders
\newbox\TOCleaderbox
\def\TOCleaderboxwidth {0.7777em}% about like what standard classes do

% vertical spacing
\def\TOCverysmallvskip {0pt plus .2pt}
\def\TOCmedvskip       {1em plus 1pt}
\def\TOCbigvskip       {2.25em plus 1pt}

% the ``numwidths'' for typesetting the numbering of division units.
% I don't recall exactly how (and for which fonts) these figures were chosen.
% They quickly prove too small if using Roman numerals (as do too the book
% class defaults even though they are a bit larger).
\def\TOCnumwidthB {1.5em} % chapter
\def\TOCnumwidthC {2.278em}% section, I think default is 2.3em
\def\TOCnumwidthD {3.056em}% analog in standard class is 3.2em
\def\TOCnumwidthE {3.833em}% analog in standard class is 4.1em
\def\TOCnumwidthF {4.611em}% analog in standard class is 5em
\def\TOCnumwidthG {5.389em}% analog in standard class is 6em

% The code for the ``global toc style''.

\newcommand*\TOCglobalstyle {%
\etocsettocstyle
   {\if@twocolumn \@restonecoltrue \onecolumn \else \@restonecolfalse \fi
    \parindent\z@ \leftskip\z@skip \rightskip \z@skip
    \setbox\TOCleaderbox\hbox to \TOCleaderboxwidth{\hss.\hss}%
    \chapter *{\noindent\kern\TOCleftmargin\relax % uses "pt"...
        \contentsname
        \@mkboth {\MakeUppercase \contentsname}{\MakeUppercase \contentsname}}%
    \rightskip    \TOCrightmargin\relax
    \parfillskip -\rightskip % or a smaller value if desired
    \leftskip     \TOCleftmargin \relax }
   {\if@restonecol \twocolumn \fi\cleardoublepage}%
%
\etocsetstyle{part}
 {}
 {\addpenalty {-\@highpenalty}%
  \addvspace \TOCbigvskip
  \leavevmode
   {\large \bfseries % use a group to limit font change
      \interlinepenalty\@M
      \etocifnumbered{\etocnumber\hspace{1em}}{}%
      \etocname
      \nobreak\hfil\makebox[-\parfillskip][r]{\etocpage}}\par
  \nobreak
  }
 {}
 {}%
%
\etocsetstyle{chapter}
 {\advance\leftskip\TOCnumwidthB\relax}
 {\addpenalty {-\@highpenalty }%
  \vskip \TOCmedvskip\relax
  \leavevmode
  {\interlinepenalty\@M
   \etocifnumbered
      {\llap{\makebox[\TOCnumwidthB][l]{\bfseries\etocnumber}}}
      {\advance\leftskip-\TOCnumwidthB\relax}%
   \bfseries\etocname
      \nobreak\hfil\makebox[-\parfillskip][r]{\etocpage}\par }%
  \penalty \@highpenalty
  }
 {}
 {\advance\leftskip-\TOCnumwidthB\relax}%
%
 \TOCsetlinestyle {section}      {\TOCnumwidthC}%
 \TOCsetlinestyle {subsection}   {\TOCnumwidthD}%
 \TOCsetlinestyle {subsubsection}{\TOCnumwidthE}%
 \TOCsetlinestyle {paragraph}    {\TOCnumwidthF}%
 \TOCsetlinestyle {subparagraph} {\TOCnumwidthG}%
}% end of \TOCglobalstyle

%The common code for line styles is abstracted into a macro:

\newcommand\TOCsetlinestyle [2]{% #1= unit, #2= numwidth as macro
\etocsetstyle{#1}
 {\advance\leftskip#2\relax}
 {\vskip \TOCverysmallvskip\relax
  \leavevmode
  {\interlinepenalty\@M
   \etocifnumbered
     {\llap{\makebox[#2][l]{\etocnumber}}}{\advance\leftskip-#2\relax}%
   \etocname
   \nobreak\leaders \copy\TOCleaderbox
   \hfil\makebox[-\parfillskip][r]{\etocpage}%
   \par }%
 }
 {}
 {\advance\leftskip-#2\relax}%
}
\makeatother
\end{filecontentshere}
\marginattach

Nota Bene: the code deliberately handles the non-numbered sectioning units
unlike the way of the standard document classes (particularly regarding the
alignment of multi-line headings.)

The whole thing was encapsulated in \csa{TOCglobalstyle}, because we also want
a \csa{TOClocalstyle} for local tables of contents which typically will want
to use |\section*| rather than |\chapter*| and not insert page marks in the
headers. The \csa{TOClocalstyle} is to be issued once, after the main document
TOC, or rather before using \localtoc. If one wants a full
TOC at end of document one will naturally have to issue again
\csa{TOCglobalstyle} there.

\begin{filecontentshere}{etocsnippet-\snippetno.tex}
\makeatletter
\newcommand*\TOClocalstyle {%
\etocsettocstyle
    {\if@twocolumn \@restonecoltrue \onecolumn \else \@restonecolfalse \fi
     \setbox\TOCleaderbox\hbox to \TOCleaderboxwidth{\hss.\hss}%
     \parindent\z@
     \dimen@ 2.25em % for left indenting
     \section *{\kern\dimen@ % use of \dimen@ works here by sheer luck
       \contentsname
       % un-comment this if marks are wanted:
       %\@mkboth {\MakeUppercase \contentsname}{\MakeUppercase \contentsname}%
       }% end of \section
     \parskip \z@skip
     \vspace{-1.25\baselineskip}% somewhat ad hoc
     \leftskip  2.25em
     \rightskip 4.5em
     \advance\rightskip-\TOCrightmargin\relax
     \leavevmode\leaders\hrule\@height\p@\hfill\kern\z@\par
     \rightskip 4.5em
     \parfillskip -\TOCrightmargin\relax }
    {\nobreak\vskip-.5\baselineskip
     \leavevmode\leaders\hrule\@height\p@\hfill\kern\z@\par
     \bigskip
     \if@restonecol \twocolumn \fi }%
%
\etocsetstyle{section}
 {\advance\leftskip\TOCnumwidthC\relax}
 {\addpenalty \@secpenalty
  \etociffirst{}{\addvspace{\TOCmedvskip}}%
  \leavevmode
  {\interlinepenalty\@M
   \bfseries\etocifnumbered
      {\llap{\makebox[\TOCnumwidthC][l]{\etocnumber}}}
      {\advance\leftskip-\TOCnumwidthC}%
   \etocname\nobreak\hfil\makebox[-\parfillskip][r]{\etocpage}\par }%
  \penalty \@highpenalty }
 {}
 {\advance\leftskip-\TOCnumwidthC\relax}%
% the rest is identical with code for global tocs:
 \TOCsetlinestyle {subsection}   {\TOCnumwidthD}%
 \TOCsetlinestyle {subsubsection}{\TOCnumwidthE}%
 \TOCsetlinestyle {paragraph}    {\TOCnumwidthF}%
 \TOCsetlinestyle {subparagraph} {\TOCnumwidthG}%
}% end of \TOClocalstyle
\makeatother
\end{filecontentshere}
\marginattach

As mentioned previously, this handles non-numbered (multi-line) sectioning
units somewhat differently from what happens in the standard document classes.

For some reason this code has some hard-coded |2.25em| and |4.5em| which were
not abstracted into macros or lengths. The code inserts horizontal rules above
and below the TOC contents in a non-separable by pagebreak way.

See \autoref{sec:thirdexampleextra} for more.

\section{A framed display}

We now opt for a ``framed'' style, using the package default
line styles and some colors added (it has been put in a float which appears
\vpageref{toc:b}).


\begin{filecontentshere}{etocsnippet-\snippetno.tex}
\etocdefaultlines
\begingroup
\renewcommand{\etoccolumnsep}{2em}
\renewcommand{\etocinnerleftsep}{1.5em}
\renewcommand{\etocinnerrightsep}{1.5em}
% specify a background color for the toc contents
\renewcommand{\etocbkgcolorcmd}{\color{yellow!10}}
% set up the top and bottom rules
\renewcommand{\etoctoprule}{\hrule height 1pt}
\renewcommand{\etoctoprulecolorcmd}{\color{red!25}}
\renewcommand{\etocbottomrule}{\hrule height 1pt}
\renewcommand{\etocbottomrulecolorcmd}{\color{red!25}}
% set up the left and right rules
\renewcommand{\etocleftrule}{\vrule width 5pt}
\renewcommand{\etocrightrule}{\vrule width 5pt}
\renewcommand{\etocleftrulecolorcmd}{\color{red!25}}
\renewcommand{\etocrightrulecolorcmd}{\color{red!25}}
% use \fcolorbox to set up a colored frame for the title
\fboxrule1pt
\renewcommand{\etocbelowtocskip}{0pt\relax}
\etocframedstyle {\normalsize\rmfamily\itshape
  \fcolorbox{red}{white}{\parbox{.8\linewidth}{\centering
      This is a table of contents \`a la \etoc, but for
      the subsections and subsubsections of \autoref{sec:tocstyle}.
      As it is put in a frame, it has to be small enough to fit on
      one page. It has the label |toc:b|.}}}
\begin{figure}[ht!]
  \centering
\tableofcontents \label{toc:b} \ref{toc:tocstyle}
\end{figure}
\endgroup
\end{filecontentshere}
\marginattach

\filecontentsexec\filecontentsheremacro




\section{Another TOC with background color}\label{ssec:again}

Let us now try out some more sophisticated line styles. The display will use
the \csb{etocframedstyle} package command, which requires that the produced
table of contents fits on a single page. We wrap it up in a
\hyperref[toc:floating]{figure environment} showing up
\vpageref{toc:floating}.

This design uses the \etoc `framed' style with a background color. The frame
borders have been set to have the same color as the one serving as background
for the entire thing. It would be advantageous to use rather inside
\csb{etocsettocstyle} commands from a package like |tcolorbox| as this allows
sophisticated breakable boxes (with |TikZ/pgf| for decoration.)

The details of the line styles used here are a bit involved, they were written
by the author at some early stage of this documentation and have only been
slightly revised to use more \LaTeX-commands and less \TeX-primitives. Similar
code is used also for \hyperref[toc:clone]{this other toc}.


\begin{filecontentshere}{etocsnippet-\snippetno.tex}
\begin{figure}[htbp!]\centering
\colorlet{subsecnum}{black}
\colorlet{secbackground}{green!30}
\colorlet{tocbackground}{red!20!green!20}

\renewcommand{\etocbkgcolorcmd}{\color{tocbackground}}
\renewcommand{\etocleftrulecolorcmd}{\color{tocbackground}}
\renewcommand{\etocrightrulecolorcmd}{\color{tocbackground}}
\renewcommand{\etocbottomrulecolorcmd}{\color{tocbackground}}
\renewcommand{\etoctoprulecolorcmd}{\color{tocbackground}}

\renewcommand{\etocleftrule}{\vrule width 3cm}
\renewcommand{\etocrightrule}{\vrule width 1cm}
\renewcommand{\etocbottomrule}{\hrule height 12pt}
\renewcommand{\etoctoprule}{\hrule height 12pt}

\renewcommand{\etocinnertopsep}{0pt}
\renewcommand{\etocinnerbottomsep}{0pt}
\renewcommand{\etocinnerleftsep}{0pt}
\renewcommand{\etocinnerrightsep}{0pt}

\newcommand\shiftedwhiterule[2]{%
    \hbox to \linewidth{\color{white}%
    \hskip#1\leaders\vrule height1pt\hfil}\nointerlineskip
    \vskip#2}

\etocsetstyle{subsubsection}
{\etocskipfirstprefix}
{\shiftedwhiterule{\leftskip}{6pt}}
{\sffamily\footnotesize
  \leftskip2.3cm\hangindent1cm\rightskip.5cm\relax
  \makebox[1cm][l]{\color{subsecnum}\etocnumber}%
  \color{black}\etocname
  \nobreak\leaders\hbox to.2cm{\hss.}\hfill
  \rlap{\makebox[.5cm][r]{\etocpage\hspace{.1cm}}}\par
  \nointerlineskip\vskip3pt}
{}

\etocsetstyle{subsection}
{\etocskipfirstprefix}
{\shiftedwhiterule{1.5cm}{6pt}}
{\sffamily\small
  \leftskip1.5cm\hangindent.8cm\rightskip.5cm\relax
  \makebox[.75cm][l]{\color{subsecnum}\etocnumber}%
  \color{black}\etocname
  \nobreak\leaders\hbox to.2cm{\hss.}\hfill
  \rlap{\makebox[.5cm][r]{\etocpage\hspace{.1cm}}}\par
  \nointerlineskip\vskip3pt}
{}

\newcommand{\coloredstuff}[2]{%
            \leftskip0pt\rightskip0pt\parskip0pt
            \fboxsep0pt % \colorbox uses \fboxsep also when no frame!
       \noindent\colorbox{secbackground}
               {\parbox{\linewidth}{%
                    \vskip5pt
                    {\noindent\color{#1}#2\par}\nointerlineskip
                    \vskip3pt}}%
       \par\nointerlineskip}

\etocsetstyle{section}
{\coloredstuff{blue}{\hfil \bfseries\large Contents of Part One\hfil}}
{\vskip3pt\sffamily\small}
{\coloredstuff{blue}
    {\leftskip1.5cm\rightskip.5cm\parfillskip-\rightskip
     \makebox[0pt][r]{\makebox[.5cm][l]{\etocnumber}}%
     \etocname\nobreak\hfill\makebox[.5cm][r]{\etocpage\hspace{.1cm}}}%
 \vskip6pt}
{}

\etocframedstyle[1]{}
\tableofcontents \label{toc:floating} \ref{toc:part:styling}
\vspace{-\baselineskip}
\centeredline{|\tableofcontents \ref{toc:part:styling}|
(\emph{cf.} \hyperref[toc:clone]{this other toc})}
\end{figure}
\end{filecontentshere}
\marginattach

\filecontentsexec\filecontentsheremacro
The table of contents produced by this code appears on \vpageref{toc:floating}.

\section{A (crazy) inline display}
\label{sec:crazy}

Let us construct some crazy inline display of the table of
contents of this entire document.  We will typeset the subsections as
footnotes... This kind of style is suitable for a hyperlinked
document, probably not for print! (although I like it, but my personal tastes in
many matters do not seem to be widely shared).

%%%% Note: 27 april 2014

%%%% except for a miraculous situation depending from the quantity of previous
%%%% material this TOC will have links extending accross pagebreaks, which
%%%% dvipdfmx does not know how to handle completely. Apart from that the output
%%%% is ok, thus no need to try seriously to avoid them.

\begin{filecontentsdef}{etocsnippet-\snippetno.tex}{\foo}
\begingroup
\newsavebox{\forsubsections}
\etocsetstyle{part}{\upshape. \etocskipfirstprefix}
                   {. \upshape}
                   {\bfseries\etocname:~~}
                   {}
\etocsetstyle{section}{\itshape\etocskipfirstprefix}
                      {, }
                      {\mdseries\etocname}
                      {}
\etocsetstyle{subsection}
    {\begin{lrbox}{\forsubsections}\footnotesize\upshape\etocskipfirstprefix}
    {; }
    {\etocname}
    {.\end{lrbox}\footnote{\unhbox\forsubsections}}
\etocsetstyle{subsubsection}
    { (\itshape\etocskipfirstprefix}
    {, }
    {\etocname}
    {\/\upshape)}
\etocsettocstyle{Here is the inline table of contents. }{.\par}
\tableofcontents \label{toc:crazyinline}
\endgroup
\end{filecontentsdef}

\filecontentsexec\foo

The code used:
\filecontentsprintviascan\foo
\marginattach

\section{One more example of colored TOC layout}
\label{ssec:tocclone}

The command \csb{etocframedstyle} puts the title on the top
rule in a centered position. This is not very convenient for
this example so we included the title as part of the
\meta{start} code at section level, to get it \emph{inside}
the frame.

\begin{filecontentshere}{etocsnippet-\snippetno.tex}
\begingroup
\definecolor{subsecnum}{RGB}{13,151,225}
\definecolor{secbackground}{RGB}{0,177,235}
\definecolor{tocbackground}{RGB}{212,237,252}

\renewcommand{\etocbkgcolorcmd}{\color{tocbackground}}
\renewcommand{\etocleftrulecolorcmd}{\color{tocbackground}}
\renewcommand{\etocrightrulecolorcmd}{\color{tocbackground}}
\renewcommand{\etocbottomrulecolorcmd}{\color{tocbackground}}
\renewcommand{\etoctoprulecolorcmd}{\color{tocbackground}}

\renewcommand{\etocleftrule}{\vrule width 1cm}
\renewcommand{\etocrightrule}{\vrule width .5cm}
\renewcommand{\etocbottomrule}{\hrule height 12pt}
\renewcommand{\etoctoprule}{\hrule height 12pt}

\renewcommand{\etocinnertopsep}{0pt}
\renewcommand{\etocinnerbottomsep}{0pt}
\renewcommand{\etocinnerleftsep}{0pt}
\renewcommand{\etocinnerrightsep}{0pt}

\newcommand\shiftedwhiterule[2]{%
    \hbox to \linewidth{\color{white}%
    \hskip#1\leaders\vrule height1pt\hfil}\nointerlineskip\vskip#2}

\etocsetstyle{subsubsection}{\etocskipfirstprefix}
  {\shiftedwhiterule{\leftskip}{6pt}}
  {\sffamily\footnotesize
     \leftskip2.5cm\hangindent1cm\rightskip1cm\noindent
     \hbox to 1cm{\color{subsecnum}\etocnumber\hss}%
     \color{black}\etocname\leaders\hbox to .2cm{\hss.}\hfill
     \rlap{\hbox to 1cm{\hss\etocpage\hskip.2cm}}\par
     \nointerlineskip\vskip3pt}
  {}

\etocsetstyle{subsection}{\etocskipfirstprefix}
  {\shiftedwhiterule{1.5cm}{6pt}}
  {\sffamily\small
     \leftskip1.5cm\hangindent1cm\rightskip1cm\noindent
     \hbox to 1cm{\color{subsecnum}\etocnumber\hss}%
     \color{black}\etocname\leaders\hbox to .2cm{\hss.}\hfill
     \rlap{\hbox to 1cm{\hss\etocpage\hskip.2cm}}\par
     \nointerlineskip\vskip6pt}
  {}

\newcommand{\coloredstuff}[2]{%
            \leftskip0pt\rightskip0pt\parskip0pt
            \fboxsep0pt % \colorbox uses \fboxsep also when no frame!
       \noindent\colorbox{secbackground}
               {\parbox{\linewidth}{%
                    \vskip5pt
                    {\noindent\color{#1}#2\par}\nointerlineskip
                    \vskip3pt}}%
       \par\nointerlineskip}

\etocsetstyle{section}
{\coloredstuff{white}
     {\hfil \hyperref[toc:b]{\bfseries\large I am a twin of
     that other TOC (click me!)}\hfil}}
{\vskip3pt\sffamily\small}
{\coloredstuff{white}
    {\leftskip1.5cm\rightskip.5cm\parfillskip-\rightskip
     \makebox[0pt][r]{\makebox[.5cm][r]{\etocnumber\hspace{.2cm}}}%
     \etocname\hfill\makebox[.5cm][r]{\etocpage\hspace{.2cm}}}%
 \vskip6pt }
{}

\etocframedstyle[1]{}
\tableofcontents \label{toc:clone} \ref{toc:tocstyle}
\endgroup
\end{filecontentshere}
\marginattach

\filecontentsexec\filecontentsheremacro
% 1.07l on the occasion of traduction into German documentation
     % APRIL 26, 2014 Improvement in the section style for better placement of
     % page number when the section name is more than one line long. Use of
     % \makebox rather than \hbox, to be more LaTeX like.

The TOC has been put in a \hyperref[toc:clone]{float} which appears
\vpageref{toc:clone}. The coding is a bit involved\footnote{and reveals the
  author's preference for the \TeX{} syntax...} as it does not use any
additional package. Also, it was written at some early stage and I have not
revised it since.

A better solution would be to use some package to set
up a background color possibly extending accross pages, as the
framed style (which we used to get this background
color) can only deal with material short enough to fit on one
page.

% 1.2 doc: commenté out to avoid a new page
% ah non finalement car cause TOC as a tree d'être sur page impaire,
% ce qui est moins bien à cause des overlap.
Regarding colors, generally speaking all color commands inside
\etoc are initially defined to do nothing, and the choice to
use or not colors is left to the user.

\clearpage
\etocdepthtag.toc {advanced}
\part{Advanced examples}
\label{part:surprising}

\thispartstats %% (pas de sous-section)

\etocdefaultlines
\etocsettocstyle {}{}
\localtableofcontents

\section{The TOC of TOCs}
\label{sec:tocoftocs}

\begingroup % \endgroup just after the \tableofcontents command
\etocinline
\etocsetlevel{part}{1}
\etocsetlevel{visibletoc}{0}
\etocsetstyle{visibletoc}
    {\etocskipfirstprefix}
    {, }
    {{\color{niceone}\etocname}}
    {}
\etocsettocstyle{}{}
\etocsetnexttocdepth{visibletoc}


Here is the numbered and linked list of all tables of contents which are
displayed within this document:\footnote{The TOCs put in
  floats may change the order: the numbers are listed
  in the order the TOCs are typeset in the document; but the numbering
  itself is from the order of the TOCs in the \emph{source} of
  this document... }
\tableofcontents
\endgroup. And to obtain
it here we just wrote:\par\smallskip
{\leftskip1cm\rightskip2cm
  \ttfamily\small\baselineskip11pt \noindent Here is the
  numbered and linked list of all tables of contents which are
  displayed within this
  document:~\string\tableofcontents.\par}

  The preparatory work was the following. First, we defined a
  counter |visibletoc| whose vocation is to get incremented at
  each displayed toc. \etoc has its own private counter but it
  counts all TOCs, even those not displayed because the |tocdepth|
  value was |-2| or |-3|.

  We could have added manually |\refstepcounter{visibletoc}|
  and |\label| commands at all suitable locations in the
  document source, and we would then have used here |\ref|
  commands, but this imposes heavy manual editing of the source.

  There is a much better way: there is a hook
  \csb{etocaftertitlehook} and we told it to increment the
  |visibletoc| counter and to write a line to the |.toc| file,
  in a manner analogous to what sectioning commands such as
  |chapter|, |section|, or |subsection| do. As \etoc
  increments its own private counter even before typesetting
  the title of a table of contents, this provides (most of the
  time) a better link destination than any counter manipulated
  from inside \csb{etocaftertitlehook} (for which the link
  would target the area just after the title). So, rather than
  including |\refstepcounter{visibletoc}| inside
  \csb{etocaftertitlehook}, we just put there
  |\stepcounter{visibletoc}| followed by the command
  \csb{etoctoccontentsline}|{visibletoc}{\thevisibletoc}|. This \etoc
  command \csb{etoctoccontentsline}\marg{level\_name}\marg{name} has the same
  effect as:
  \centeredline{|    ||\addcontentsline{toc}|\marg{level\_name}\marg{name}}
  but its usefulness is to circumvent\footnote{using \csa{addtocontents} rather
    than \csa{addcontentsline}} the patching for automatic creation
  of bookmarks done to \csa{addcontentsline} by the \ctanpkg{hyperref} package,
  as pdf bookmarks don't make
  much sense here (and would elicit a complaint
  of \ctanpkg{hyperref} that the bookmark level is `unknown').\footnote{%
  The package provides a starred variant
  \staritb{etoctoccontentsline}, which does allow the creation
  of bookmarks and has a third mandatory argument which is the
  Level to be used by these bookmarks; depending on the context
  the starred as well as the non-starred variants may be
  profitably preceded by \csa{phantomsection}.}

  Finally, the preamble of the document did
  \csb{etocsetlevel}|{visibletoc}{6}|. The level |6| (or anything
  with a higher number) is ignored, even if |tocdepth| has
  value |10| for example; this is independently of whether \etoc
  uses the document class default line styles or its own line
  styles, or the ones defined by the user with the
  \csb{etocsetstyle} command. So there is no need to worry that
  something could go wrong.

  \emph{The example actually uses \csb{etocthemaxlevel}, see the
    \etocrelease{1.2a} change log entry.}

  Then, only here we have set \csb{etocsetlevel}|{visibletoc}{0}|. And to display
  only this kind of entries we assign temporarily to |part| and |chapter| level
  |1| (or anything higher than zero) and set |tocdepth| to the value |0|. We
  also did%
%
\centeredline{\csb{etocsetstyle}\{visibletoc\}\{\csb{etocskipfirstprefix}\}%
   \{, \}\{\string\etocname\}\{\}}
%
  which defines an inline display with the comma (plus space)
  as separator. Finally, as \etoc issues |\par| automatically by default just
  before typesetting a table of contents, we used the command \csb{etocinline}
  (also known as \cs{etocnopar}) which turns off this behavior.

Here are the implementation details:

\begingroup
\begin{filecontentshere}{etocsnippet-\snippetno.tex}
   < in the preamble >
\newcounter{visibletoc}
\renewcommand{\etocaftertitlehook}
   {\stepcounter{visibletoc}\etoctoccontentsline{visibletoc}{\thevisibletoc}}
\etocsetlevel{visibletoc}{\etocthemaxlevel}
\begin{document}
   < document body >
\subsection{Surprising uses of etoc}
\begingroup
    \etocinline
    \etocsetlevel{part}{1}
    % \etocsetlevel{chapter}{1} % (no chapters in scrartcl class)
    \etocsetlevel{visibletoc}{0}
    \etocsetstyle{visibletoc}
        {\etocskipfirstprefix}{, }{{\color{niceone}\etocname}}{}
    \etocsettocstyle{}{}     % don't set any title, rules or frame or multicol!
    \etocsetnexttocdepth{visibletoc} % display only the `visibletoc' entries from .toc

Here is the numbered and linked list of all tables of contents which are
displayed within this document: \tableofcontents.
\endgroup
\end{filecontentshere}
\marginattach
\endgroup

After |\etocsetstyle{visibletoc}{..}{..}{..}{..}|, all future TOCs (not in
compatibility mode) will use the
defined style for level |0| (which is normally the level for
chapters). To keep these changes strictly local the simplest
manner is to put everything inside a group.

The \autoref{subsec:interverting} gives another use of the
shuffling of levels.


\section[Arbitrary ``Lists Of...'', \csbhyp{etoctoccontentsline}]{%
         Arbitrary ``Lists Of...'', \csbhyp{etoctoccontentsline} and
         \csbhyp{etocimmediatetoccontentsline}}
\label{etoctoccontentsline}
\label{etocimmediatetoccontentsline}

This idea of interverting the levels is very powerful and allows
to let \etoc display lists of arbitrary things contained in the
document. All of that still
using nothing else than the |.toc| file!
Example: imagine a document with dozens of
exercises, perhaps defined as |\newtheorem{exercise}{}[section]|. Let
us explain how to instruct \etoc to display an hyperlinked list
of all these exercises. For this we put in the preamble: (but see
\etocrelease{1.2a} change log entry)
\begin{verbatim}
 \newtheorem{exerci}{}[section]
    % the exercice number will be recoverable via \etocname: v--here--v
 \newcommand*{\exercisetotoc}{\etoctoccontentsline{exercise}{\theexerci}}
 \newenvironment{exercise}{\begin{exerci}\exercisetotoc}{\end{exerci}}
 \etocsetlevel{exercise}{6}
\end{verbatim}
In this way, \csb{etocname} will give the exercise number (but \csb{etocnumber}
will be empty). Had we used instead
\begin{verbatim}
 \newcommand*{\exercisetotoc}
    {\etoctoccontentsline{exercise}{\protect\numberline{\theexerci}}}
\end{verbatim}
the exercise number would then have been available via \csb{etocnumber}, and
\csb{etocname} would have been empty. It doesn't matter which one of the two
methods is used. The \etoc command \csb{etoctoccontentsline}|{..}{..}| is
provided as a substitute to \csa{addcon\-tentsline}|{toc}{..}{..}|: this is to
avoid the patching which is done by \ctanpkg{hyperref} to \csa{addcontentsline} in its
process of creation of bookmarks. If one wants to authorize \ctanpkg{hyperref} to create
bookmarks at a specific level \meta{n}, one can use (here with \meta{n}$=$|2|)
the starred variant \starit{etoctoccontentsline} which has an additional
argument:
\begin{verbatim}
\newcommand{\exercisetotoc}{\etoctoccontentsline*{exercise}{\theexerci}{2}}
\end{verbatim}

The counter |exerci| is already
incremented by the |exerci| theorem environment, and
provides the correct destination for the link added by package
\ctanpkg{hyperref}. The command \csa{exercisetotoc} adds for each exercise a line
to the |.toc| file, corresponding to a fictitious document
unit with name `|exercise|'. A
four-column list, including the sections, can then be
typeset with the following code:
\begin{filecontentshere}{etocsnippet-\snippetno.tex}
  \etocsetnexttocdepth{2}     % sections are at level 1 and will show up
\begingroup
  \etocsetlevel{exercise}{2}   % but:
  \etocsetlevel{chapter}{3}    %     no chapters
  \etocsetlevel{subsection}{3} %     no subsections
  \etocsetlevel{part}{3}       %     no parts
  \etocsetstyle{exercise}{}{}  % \etocname = exercise number
    {\noindent\etocname\strut\leaders\etoctoclineleaders\hfill\etocpage\par}
    {\pagebreak[2]\vskip\baselineskip}
  \etocsetstyle{section}{}{}
    {\noindent\strut{\bfseries\large\etocnumber\hskip.5em\etocname}\par
     \nopagebreak[3]}{}
  \etocruledstyle[4]{\Large\bfseries List of the exercises}
  \setlength{\columnseprule}{.4pt}
  \tableofcontents
\endgroup
\end{filecontentshere}
\marginattach

A related command \csb{etocimmediatetoccontentsline} (and its starred version)
is also provided.  For discussion and the meaning of ``immediate'', refer to
the analogous case of \csb{etocimmediatedepthtag.toc}.

\section{The TOC as a tree}\label{tocastree}

Using \ctanpkg{tikz} and the package \ctanpkg{forest} we shall display the
table of contents of \autoref{part:styling} as a tree. The technique is to use
the \etoc modified command \toc not for typesetting, but to prepare a macro,
or rather here a \csa{toks} variable, with all the instructions to be executed
later. \textsc{Leslie Lamport}'s book has no mention whatsoever of such token
lists registers, and \LaTeX{} gives the impression to not really expect the
general user to ever hear about them (or delimited macros); this whole section
and the next are thus for advanced users.

Putting the \csb{etocnumber} and \csb{etocname} commands in \csa{treetok}
would be of no use: to which number or name would they then refer to, in a
delayed execution?

We need to store, not the macro names, but the macro contents. And also we wish
to maintain the correct \ctanpkg{hyperref} hyperlinks.
The
commands \csb{etocname}, etc\dots, are robust, it is easier to work with
\csb{etocthelinkednumber}, \csb{etocthelinkedname}, and \csb{etocthelinkedpage}
which contain the same information in an easier accessible form.%
%
\normalmarginpar\marginpar{\footnotesize\rmfamily\itshape\RaggedRight
At \etocrelease{1.1a} the commands \csa{etocthelinkedname}, etc\dots, are
always providing an hyperlink, so it is not true that \csb{etocname}, etc\dots,
are always simply their robust variants.}

For this |forest| tree we have designed very special \etoc styles for sections
and subsections. They use a token list register called |\treetok| and a
macro |\appendtotok| whose r\^ole is to append to a given token list variable
the contents of a macro given as second argument. All this will happen in
reaction to a |\tableofcontents| command, but \emph{nothing} has yet been
printed in the process.\footnote{There is always a \csa{par}, which here is not
a problem, but can be suppressed if need be via the command \csb{etocinline} or
its synonym \csb{etocnopar}.} This is the later job of a |forest| environment
which will be given the contents of |\treetok|.



\let\appendtotok\relax

\begin{filecontentsdef}{etocsnippet-\snippetno.tex}{\foo}
% \newtoks\treetok % put this (uncommented) preferably in the preamble
% \newtoks\tmptok  % (idem)
\begingroup
\newcommand*\appendtotok[2]{% #1=toks variable, #2=macro, expands once #2
  #1\expandafter\expandafter\expandafter
    {\expandafter\the\expandafter #1#2}}

\newcommand*\PrepareSectionNode{%
  \tmptok {\centering\bfseries}%
  \appendtotok\tmptok\etocthelinkedname
  \edef\foresttreenode{ [{\noexpand\parbox{2cm}{\the\tmptok}}}%
}

\newcommand*{\PrepareSubsectionNode}{%
  \tmptok {\raggedright}%
  \appendtotok\tmptok\etocthelinkedname
  \edef\foresttreenode{ [{\noexpand\parbox{6cm}{\the\tmptok}}}%
}

\etocsetstyle{section}
  {\etocskipfirstprefix}
  {\appendtotok\treetok{ ]}}
  {\PrepareSectionNode \appendtotok\treetok\foresttreenode}
  {\appendtotok\treetok{ ]}}

\etocsetstyle{subsection}
  {\etocskipfirstprefix}
  {\appendtotok\treetok{ ]}}
  {\PrepareSubsectionNode \appendtotok\treetok\foresttreenode}
  {\appendtotok\treetok{ ]}}

\etocsettocstyle
    {\treetok{[{\hyperref[part:styling]{The \etoc styling commands}}}}
    {\global\appendtotok\treetok{ ]}}

% forest does not like @\the\treetok if \treetok is empty. On first latex
% run, this will be the case because the TOC style defined above will not
% have been executed, as the label {toc:overview} does not refer to a valid
% TOC yet. So we must give a safe default value to \treetok
\treetok{[{run latex again}]}

\begin{figure}[htbp!]
\centering
     \etocsetnexttocdepth{subsection}
     \tableofcontents \label{toc:forest}\ref{toc:part:styling}
     \hypersetup{hidelinks}%
     \bracketset{action character=@}
% manual adjustments to fit the printed page
% \kern-1cm
\noindent\kern-3cm
     \begin{forest}
                  for tree={anchor=center,child anchor=west,
                            grow'=east,draw,thick,
                            edge={draw,thick,dashed,color=teal}},
                  where={level()==1}{circle,thick,fill=blue!5,
                                    before computing xy={l=6cm}}{},
                  where={level()==2}{fill=red!5,
                                    before computing xy={l=6cm}}{},
                  rectangle, thick, fill=cyan!5, inner sep=6pt,
     @\the\treetok
     \end{forest}
\end{figure}
\endgroup
\end{filecontentsdef}
\filecontentsexec\foo

The resulting tree has been put in a \hyperref[toc:forest]{float}, which
appears \vpageref[above]{toc:forest}.  Here is the code used for its
production: \filecontentsprintviascan\foo \marginattach

Why |\hypersetup{hidelinks}|? as explained in
\autoref{ssec:hidelinks}, I prefer the links in TOCs not to be
colorized, nor framed, so this document inserts a command
%\csa{hypersetup}\texttt{\{hidelinks\}} % ok pour hyphénation
%\csa{hypersetup}|{hidelinks}| % pas ok
|\hypersetup{hidelinks}| % ok maintenant 12 octobre 2013
 in the |.toc| file. But at the time the
|\treetok| contents are unpacked the |\hyperlink| commands
originating in
|\etocthelinkedname|, etc\dots{} will be executed in the normal
environment for links (which, in this document, is to colorize
them). Rather than having \etoc's code try to guess what the current ``style''
for links is (a concept not really provided by \ctanpkg{hyperref} it
seems) and store it in |\etocthelinkedname|, etc\dots, I opted for
the simpler solution to leave it up to the user to recreate
whatever conditions are desired. So here  it is necessary to re-issue
|\hypersetup{hidelinks}| in the |figure| environment.

There are some other examples in this documentation where
|\tableofcontents| is used to prepare material for later
typesetting:
\begin{itemize}
\item printing the statistics at the start of each Part (see
  \autoref{ssec:statistics}) is done using save boxes (so the problem of the
  appearance of the links does not arise then).
\item typesetting of the TOC as a table without benefiting from
  \csb{etocglobaldefs} (see \autoref{ssec:tocastableold}).
\item and the examples in the next section.
\end{itemize}


\section{The TOC as a molecule}\label{sec:molecule}

It is also possible to construct a TOC tree obeying the TikZ
syntax for trees: but this is a more complicated task for the
\etoc line styles for reasons related to the way braces are
handled by \TeX{} (they need, when filling up the token list to be
always balanced at each step, else complicated tricks must be
employed.)

The simplest strategy is to allocate a token list (or use a macro) for each
level used: we may need a \csa{parttok}, a \csa{chaptertok}, a
\csa{sectiontok} and a \csa{subsectiontok}, to help in the task of filling
up the total \csa{treetok}. As we are interested here in the table of
contents of this (or another) document part, only a \csa{sectiontok} and a
\csa{subsectiontok} will be needed.

\let\appendtotok\relax
\let\treenode\relax
\let\appendchildtree\relax
\let\preparetreenode\relax
\begin{filecontentshere}{etocsnippet-\snippetno.tex}
% \newtoks\treetok % put this (uncommented) preferably in the preamble
% \newtoks\subsectiontok
% \newtoks\subsubsectiontok
% Attention: this code has been prepared only for subsections
% and subsubsections.

\newcommand*{\treenode}{}% only to make sure our \edef's do not overwrite
                         % an existing command

% expands 2nd argument (macro) and appends it to 1st argument (toks)
\newcommand*\appendtotok[2]{% #1=toks variable, #2=macro, expands once #2
  #1\expandafter\expandafter\expandafter
    {\expandafter\the\expandafter #1#2}}

% appends 2nd argument contents (toks) as child of first argument (toks)
\newcommand*{\appendchildtree}[2]{% token list t1 becomes: t1 child {t2}
   \edef\tmp{\the#1 child {\the#2}}%
   #1\expandafter{\tmp}%
}
% prepare the (hyperlinked) number in the "node (number)" shape
\newcommand*{\preparetreenode}{%
  \tmptok\expandafter{\etocthelinkednumber}% expanded once (needed)
  \edef\treenode{node {\the\tmptok}}%
}

\etocsetstyle{subsection}
  {\etocskipfirstprefix}
  {\appendchildtree\treetok\subsectiontok}
  {\preparetreenode
   \subsectiontok\expandafter{\treenode}}
  {\appendchildtree\treetok\subsectiontok}

\etocsetstyle{subsubsection}
  {\etocskipfirstprefix}
  {\appendchildtree\subsectiontok\subsubsectiontok}
  {\preparetreenode
   \subsubsectiontok\expandafter{\treenode}}
  {\appendchildtree\subsectiontok\subsubsectiontok}

\etocsettocstyle
  {\treetok{\node {\hyperref[sec:linestyles]{Line styles}}}}
  {\global\appendtotok\treetok{ ;}}

\centeredline{% from package centeredline (limits scope of \hypersetup)
   \etocsetnexttocdepth{subsubsection}
   \etocinline\tableofcontents \label{toc:molecule} \ref{toc:tocstyle}
   \hypersetup{hidelinks}%
   \begin{tikzpicture}
              [grow cyclic,
               level 1/.style={level distance=4cm,sibling angle=72},
               level 2/.style={level distance=2cm,sibling angle=60},
               every node/.style={ball color=red,circle,text=SkyBlue},
               edge from parent path={[dashed,very thick,color=cyan]
                           (\tikzparentnode) --(\tikzchildnode)}]
   \the\treetok
   \end{tikzpicture}%
}
\end{filecontentshere}
\marginattach

\filecontentsexec\filecontentsheremacro



The |\tableofcontents| command is executed prior to the |tikzpicture|
environment which will actually typeset it via insertion of the accumulated
data in the \csa{toks} register \csa{treetok}.  This
\hyperref[toc:molecule]{TikZ TOC} is fully hyperlinked, like the previous
\hyperref[toc:forest]{Forest TOC}.

% Mercredi 01 mars 2023 à 23:27:29
% arrrrrrgggghhh
% desperate attempt to avoid an annoying varioref "may loop" error.
% at last minute, arose from a suppression of a paragraph a few
% dozen pages earlier.
% [76]

% ! Package varioref Error: \vref or \vpageref at page boundary 65-66 (may loop).

% See the varioref package documentation for explanation.
% Type  H <return>  for immediate help.
%  ...
%
% l.6114 appears \vpageref{toc:mindmap}

% mais ça n'a pas suffit.  Bon 10 minutes de perdues je vais déplacer la ligne.

\enlargethispage{3\baselineskip}
Another example:

\etocsettocstyle
  {\treetok{\node {\autoref{sec:tocstyle}}}}
  {\global\appendtotok\treetok{ ;}}

\etocsetnexttocdepth {subsubsection}
\tableofcontents \ref{toc:tocstyle}

\centeredline{%
\hypersetup{hidelinks}
    \begin{tikzpicture}
              [grow cyclic,
               level 1/.style={level distance=2.5cm,sibling angle=60},
               level 2/.style={level distance=1cm,sibling angle=45},
               every node/.style={ball color=red!50,circle,text=black},
               edge from parent path={[very thick,color=cyan]
                       (\tikzparentnode) --(\tikzchildnode)}]
     \the\treetok
   \end{tikzpicture}
}%
%
The above is the fully hyperlinked table of contents of
\autoref{sec:tocstyle}.

\section{The TOC as a TikZ mind map}
\label{sec:mindmap}

This is in the same spirit as the ``molecule'' example. The use of the \eTeX{}
primitive \csa{unexpanded} will simplify the code.%
%


\let\partnode\relax
\let\childnode\relax
\let\appendtotok\relax
\let\appendchildtree\relax
\expandafter\let\csname c@partco\endcsname\relax

\begin{filecontentsdef}{etocsnippet-\snippetno.tex}{\foo}
% \newtoks\treetok % done in preamble
% \newtoks\parttok
\newcommand*\partnode {}  % check with \newcommand we will not overwrite something
\newcommand*\childnode {}

\newcommand*\tmprotate {} % (idem)
\newcommand*\tmpoption {} %
\newcommand*\tmpstuff  {} %

\newcommand*\appendtotok[2]{% #1=toks variable, #2=macro, expands once #2
   #1\expandafter\expandafter\expandafter{\expandafter\the\expandafter #1#2}}

\newcommand*{\appendchildtree}[3]{%
% this is to construct "t1 child [#3]{t2}" from #1=t1 and #2=t2
% t1 and t2 are two toks variable (not macros)
% #3 = for example teal!60
   \edef\tmpstuff {\the#1 child [#3]{\the#2}}%
   #1\expandafter {\tmpstuff }%
}

\newcounter{partco}

% 1,2,3,4,5,... -> 1,2,3,1,2,3,1,2,3
\def\pseudomodthree #1{\numexpr #1 + 3 - 3*((#1+1)/3)\relax}

\etocsetstyle{part}
  {\etocskipfirstprefix}
% This updates the global tree with the data  from the previous
% part and all its children sections. Moved here because for some parts the
% sections are not displayed due to depth tags.
  {\ifnum\value{partco}=3
     \appendchildtree\treetok\parttok {branch color= green!50,level distance=10cm}%
   \else
\ifcase\pseudomodthree{\value{partco}}%
   \or \appendchildtree\treetok\parttok {branch color= teal!30}%   first
   \or \appendchildtree\treetok\parttok {branch color= yellow!80}% second
   \else\appendchildtree\treetok\parttok {branch color= green!50}% third and next ...
   \fi\fi
   }
  {\stepcounter{partco}%
% customize manually  some TikZ set-up (should be done inside the TikZ thing I guess)
   \def\tmpoption {}%
   \def\tmprotate {}% first
   %\ifnum\value{partco}=5 \def\tmprotate {[counterclockwise from =-40]}\fi
   %\ifnum\value{partco}=8 \def\tmprotate {[counterclockwise from =-50]}\fi
% define the part node
   \edef\partnode{node \tmpoption
                  {\unexpanded\expandafter{\etocthelinkednumber}.
                   \unexpanded\expandafter{\etocthelinkedname}}\tmprotate }%
% this is a starting point which will be filled it by the section children
   \parttok\expandafter{\partnode}}
  {\ifcase\pseudomodthree{\value{partco}}%
   \or \appendchildtree\treetok\parttok {branch color= teal!60}%   first
   \or \appendchildtree\treetok\parttok {branch color= yellow!80}% second
   \else\appendchildtree\treetok\parttok {branch color= green!50}% third and next ...
   \fi
   }

\etocsetstyle{section}
  {}
  {}
  {% define the section node
   \edef\childnode{child {node {\unexpanded\expandafter{\etocthelinkednumber}
                        \unexpanded\expandafter{\etocthelinkedname}}}}%
   % append it to the current \parttok
   \appendtotok\parttok\childnode
    }
  {}

\etocsettocstyle
  {\setcounter{partco}{0}%
   \treetok{\node [root concept]{\textbf{The \etoc documentation}}}}
  {\global\appendtotok\treetok{ ;}}
% The \global above is mandatory because etoc always typesets TOC inside a group

\etocsetnexttocdepth{section}
% use of depth tags to cut out sections for most parts, the sections
% are too numerous to fit well with the circular growth
\etocsettagdepth {preamble}   {part}
\etocsettagdepth {overview}   {part}
\etocsettagdepth {styling}    {part}
\etocsettagdepth {control}    {part}
\etocsettagdepth {examples}   {part}
\etocsettagdepth {advanced}   {part}
\etocsettagdepth {etocandworld}{part}
\etocsettagdepth {code}       {section}

\tikzset{
    branch color/.style={
        concept color=#1!white,
        every child/.append style={concept color=#1!white!30!white, font=\normalsize},
    }
}%

\begin{figure}[htbp!]
\etocobeydepthtags % obey the depth tags restrictions (which is default anyhow)
\tableofcontents\label{toc:mindmap}%
\centeredline{\resizebox{.85\paperwidth}{!}%
{\begin{tikzpicture}[mindmap,
                    grow cyclic,
                    text width=2cm,
                    align=flush center,
                    nodes={concept},
                    concept color=orange!60,
                    root concept/.append style={text width=4cm, font=\Large},
   level 1/.append style={level distance=5cm,sibling angle=45, text width=3cm},
   level 2/.append style={level distance=7cm,sibling angle=30, text width=3cm},
   level 1 concept/.append style={font=\normalsize},
                    ]
\the\treetok
\end{tikzpicture}}}
\end{figure}
\end{filecontentsdef}
\filecontentsexec\foo

It is difficult to get everything to fit on one page. However \csa{resizebox}
comes to the rescue. And it preserves hyperlinks. Nevertheless for this
example I excluded some sections from the display, using the technique of the
\etoc \hyperref[etocdepthtag.toc]{depth tags}.

%  The fully hyperlinked TOC
% appears \vpageref{toc:mindmap}.

\filecontentsprintviascan\foo
\marginattach

The fully hyperlinked TOC appears \vpageref{toc:mindmap}.

An interesting alternative is to use \etoc rather to convert the entire TOC
into a TikZ tree (perhaps excluding some parts) and print it out to a file
from which it can be recovered and manipulated directly by the author of the
document. Things written to the |.log| file get broken into lines. Here is a
technique to get non-broken output. Once the \csa{treetok} has been computed
by \etoc (as in the \hyperref[toc:molecule]{molecule} example, or the current
example), this demo will write it out to file with extension
|.toctree|:
\begin{verbatim}
  \newwrite\TOCasTree
  \immediate\openout\TOCasTree=\jobname.toctree
  \immediate\write\TOCasTree{\the\treetok}%
\end{verbatim}


\section{The TOC as a (long) table}
\label{sec:tocastable}

% With release \etocrelease{1.08} it is easier to typeset a TOC as a table.
It is possible to open a \texttt{tabular} (or \texttt{longtable}) in the title part of the TOC
(first argument to \csb{etocsettocstyle}) and then close it after the contents
(second argument to \csb{etocsettocstyle}), and specify in the line styles how
to use the tabulation |&| and tabular end of row |\\|.

But there are some conditions and a few caveats:
\begin{enumerate}
\item it is \textbf{mandatory} to issue \csb{etocglobaldefs} for \etoc's
  definitions of  \csb{etocname} et al. to have global scope, i.e. not be
  extinguished on encountering a |&|,
\item it is impossible to start one of the \meta{start}, \meta{prefix},
  \meta{contents} or \meta{finish} specification with a sole |\hline|,
  \emph{i.e.} one not preceded by a |\\|,
 % (it is however possible to put
 %  |\\| at the end of \meta{prefix} and the |\hline| at the start of
 %  \meta{contents}).
\item as is explained next, it is recommended to put the
  |\\| at the start of the \meta{prefix} or \meta{contents}
  specifications in order to close the \emph{previous} row, rather
  that at the end with the idea to close the \emph{current} row;
  and when the TOC is a partial one (a \csa{localtableofcontents}) this
  is (in almost all situations) mandatory.
\end{enumerate}

Here is an example of a TOC as a |longtable|. Yes this is only \emph{one} table!
The code follows.

\begin{filecontentsdef}{etocsnippet-\snippetno.tex}{\foo}
\begingroup
\etocglobaldefs % necessary for \etocname etc... to survive &
\makeatletter
% hack into longtable \hline to avoid annoying (here) stray lines at top
\def\LT@@hline{%
  \ifx\@let@token\hline
    \global\let\@gtempa\@gobble
    \global\let\@gtempb\@firstofone %%% ADDED
    \gdef\LT@sep{\penalty-\@medpenalty\vskip\doublerulesep}%
  \else
    \global\let\@gtempa\@empty
    \global\let\@gtempb\@gobble     %%% ADDED
    \gdef\LT@sep{\penalty-\@lowpenalty\vskip-\arrayrulewidth}%
  \fi
  \ifnum0=`{\fi}%
  \multispan\LT@cols
     \unskip\leaders\hrule\@height\arrayrulewidth\hfill\cr
  \@gtempb{%                        %%% ADDED
  \noalign{\LT@sep}%
  \multispan\LT@cols
     \unskip\leaders\hrule\@height\arrayrulewidth\hfill\cr
  \noalign{\penalty\@M}%
  }%                                %%% ADDED
  \@gtempa}
\makeatother

% observe the locations of the \\
\etocsetstyle{part}
  {}
  {}
  {\\\hline\multicolumn{3}{c}{\bfseries\vrule height6ex depth3ex width0pt
                              \makebox[0pt]{\etocifnumbered{\etocnumber. }{}\etocname}}}
  {}

\etocsetstyle{section}
  {}
  {\etociffirst{\\\hline}{\\}}
  {\etocnumber&\etocname &\etocpage }
  {}

\etocsetstyle{subsection}
  {}
  {\\}
  {&\makebox[1cm][c]{\etocnumber}%
    \parbox[t]{\dimexpr6cm-\tabcolsep\relax}{\sloppy\itshape\etocname\strut}%
   &\itshape\etocpage }
  {}

\etocsettocstyle
    {\hypersetup{hidelinks}%
     \begin{longtable}{|>{\bfseries}c|p{7cm}|r|}
     \hline
     \multicolumn{3}{|c|}{\Large\bfseries\strut\strut TABLE OF CONTENTS}%
     }
    {\\\hline\end{longtable}}

\etocsetnexttocdepth {subsection}

\tableofcontents
\endgroup
\end{filecontentsdef}

\filecontentsexec\foo

\filecontentsprintviascan\foo
\marginattach

Examining the code above the reader will wonder why the |\\| are
always given first in \meta{prefix+contents} and not, as is more
intuitive, rather last. In some favorable cases (but almost never
for local tables of contents) one may indeed construct
TOC-as-tables with the |\\| located at the end of the style
specifications. The problem in the previous example was with the
positioning of the |\hline|'s.

Due to technical aspects of how \TeX{} constructs alignments any
definition or assignment done after an |\\| starts a new row, and
thus makes |\hline| an illegal token (this shows as a |misplaced
\noalign| error.) Not only does \etoc have to do such definitions
to construct \csb{etocname} etc..., it is furthermore the case that
some packages put things in the |.toc| file and as a result there
is never any guarantee that between two \csa{contentsline} there
will not be such a token like |\relax| which in the contexts of
alignments forces \TeX{} to start a cell and thus makes it
impossible then to insert an |\hline|.

The safest way is thus to start with an |\\| each line style
specification in order to close the \emph{previous} table row. We
had a little problem with the fact that we wanted parts not only
to have a rule above them (easy, they do |\\\hline|) but also
below them: after each part there is a section, and it is these
sections which are used to insert the missing |\hline|
(this is done with the help of the \csb{etociffirst}
conditional).


Last technical note: because we put the |\\\hline| inside the branches, there
was no need to employ the expandable variants \csb{etocxiffirst} and
\csb{etocxifnumbered}.

For the hardliner's old way see \autoref{ssec:tocastableold}.

Here is also a much simpler example. It is a local table of
contents.

\begin{filecontentsdef}{etocsnippet-\snippetno.tex}{\foo}
\begin{center}
\etocsetstyle{section}
             {}
             {\etociffirst{\\\hline\hline}{\\\hline}}
             {\etocname & \etocnumber & \etocpage }
             {}

\etocsettocstyle
   {\hypersetup{hidelinks}\begin{tabular}{|>{\RaggedRight}p{4.5cm}|c|c|}\hline
    \multicolumn{1}{|c|}{\bfseries Section title}&
    \bfseries number&
    \bfseries page}
   {\\\hline\end{tabular}}

\etocglobaldefs % MANDATORY !!
\etocsetnexttocdepth{1}

\tableofcontents\ref{toc:overview}
\end{center}
\end{filecontentsdef}

\filecontentsexec\foo

\filecontentsprintviascan\foo
\marginattach

\section{A TOC self-adjusting widths for its typesetting}
\label{sec:thirdexampleextra}

This is a continuation of \autoref{sec:thirdexample}. The goal is to adjust
automatically the ``numwidths'' used for typesetting the unit numbers in the
(local) tables of contents.
\begin{filecontentshere}{etocsnippet-\snippetno.tex}
\makeatletter
\newcommand*\TOCcompute@numwidths [2]{% #1=empty/"local", #2=minimal indent
  \begingroup
    \def\TOCnumwidthB {0pt}%
    \def\TOCnumwidthC {0pt}%
    \def\TOCnumwidthD {0pt}%
    \def\TOCnumwidthE {0pt}%
    \def\TOCnumwidthF {0pt}%
    \def\TOCnumwidthG {0pt}%
    \etocsetstyle{part}{}{}{}{}%
    \etocsetstyle{chapter}{}
      {\setbox0\hbox{\bfseries\etocthenumber\kern#2}}
      {\ifdim\wd0>\TOCnumwidthB\edef\TOCnumwidthB{\the\wd0}\fi}{}%
    \etocsetstyle{section}{}
      {\setbox0\hbox{\bfseries\etocthenumber\kern#2}}
      {\ifdim\wd0>\TOCnumwidthC\edef\TOCnumwidthC{\the\wd0}\fi}{}%
    \etocsetstyle{subsection}{}
      {\setbox0\hbox{\etocthenumber\kern#2}}
      {\ifdim\wd0>\TOCnumwidthD\edef\TOCnumwidthD{\the\wd0}\fi}{}%
    \etocsetstyle{subsubsection}{}
      {\setbox0\hbox{\etocthenumber\kern#2}}
      {\ifdim\wd0>\TOCnumwidthE\edef\TOCnumwidthE{\the\wd0}\fi}{}%
    \etocsetstyle{paragraph}{}
      {\setbox0\hbox{\etocthenumber\kern#2}}
      {\ifdim\wd0>\TOCnumwidthF\edef\TOCnumwidthF{\the\wd0}\fi}{}%
    \etocsetstyle{subparagraph}{}
      {\setbox0\hbox{\etocthenumber\kern#2}}
      {\ifdim\wd0>\TOCnumwidthG\edef\TOCnumwidthG{\the\wd0}\fi}{}%
    %
    \etocsettocstyle
     {}
     {\global\let\TOCnumwidthB\TOCnumwidthB
      \global\let\TOCnumwidthC\TOCnumwidthC
      \global\let\TOCnumwidthD\TOCnumwidthD
      \global\let\TOCnumwidthE\TOCnumwidthE
      \global\let\TOCnumwidthF\TOCnumwidthF
      \global\let\TOCnumwidthG\TOCnumwidthG
     }% make the found maximal widths have global scope
    \etocnopar
    \csname #1tableofcontents\endcsname
\typeout{Next TOCs will use \TOCnumwidthB\space for chapter number width}%
\typeout{Next TOCs will use \TOCnumwidthC\space for section number width}%
\typeout{Next TOCs will use \TOCnumwidthD\space for subsection number width}%
\typeout{Next TOCs will use \TOCnumwidthE\space for subsubsection number width}%
\typeout{Next TOCs will use \TOCnumwidthF\space for paragraph number width}%
\typeout{Next TOCs will use \TOCnumwidthG\space for subparagraph number width}%
  \endgroup % matches \begingroup at start of definition
}%
\newcommand*\TOCcomputenumwidths [1][0.5em]{%
  \TOCcompute@numwidths {}{#1}%
}%
\newcommand*\TOCcomputelocalnumwidths [1][0.5em]{%
  \TOCcompute@numwidths {local}{#1}%
}%
\makeatother
\end{filecontentshere}
\marginattach

The optional parameter to \csa{TOCcomputenumwidths} specifies the minimal
indent. In case nothing is numbered you may wish a higher value than |0.5em|.
For each local table of contents to have its own width computations, the macro
\csa{TOCcomputelocalnumwidths} is provided. As the code makes global
assignments, either use (once) \csa{TOCcomputenumwidths} or do
\csa{TOCcomputelocalnumwidths} for each local table of contents.
\begin{verbatim}
  \TOCcomputelocalnumwidths  % may use optional argument to replace 0.5em
  \localtableofcontents
\end{verbatim}
Notes:
\begin{enumerate}[nosep]
\item naturally these are only suggestions. For example one could put
  everything in single macros \csa{TOCtoc} and \csa{TOClocaltoc} to
  simultaneously compute the numwidths and then typeset the (local) table of
  contents.
\item if you want to adjust the |tocdepth| recall from
  \autoref{ssec:bookmarksdepth} that it influences \ctanpkg{hyperref} hence you may
  need to use a group |\begingroup...\endgroup|. Or, one can use
  \csb{etocsetnexttocdepth}\marg{level} but (with the code as here) this must
  then be issued twice, once for \csa{TOCcomputelocalnumwidths}, once for
  \csa{localtableofcontents}.
\item the bold font serves above for both chapter and section numwidth
  computations, but the code from \autoref{sec:thirdexample} uses |\bfseries|
  only in local TOCs. Thus the \csa{TOCcomputenumwidth} will set the parameter
  \csa{TOCnumwidthC} to a value slightly larger than needed in the main TOC.
  Hence the section style in \csa{TOCcompute@numwidths} should possibly insert
  the |\bfseries| in the box only after testing for the optional parameter
  |local|.
\end{enumerate}



\section{Interverting the levels}
\label{subsec:interverting}

Let us display and count all subsections occurring in this
document (see \autoref{part:surprising} for other uses of
this technique):
\begin{verbatim}
\etocsetnexttocdepth{2}
\begingroup
\etocsetlevel{part}{3}
\etocsetlevel{section}{3}
\etocsetstyle{subsection}
    {\small\begin{enumerate}[itemsep=0pt,label=,leftmargin=0pt]}
    {\normalfont\bfseries\item}
    {\roman{enumi}. \mdseries\etocname{} (\etocnumber, p.~\etocpage)}
    {\end{enumerate}}
\renewcommand{\etoccolumnsep}{2.75em}
\renewcommand{\columnseprule}{1pt}
\etocmulticol[3]{\subsection{All subsections of this document}}
\endgroup
\end{verbatim}

\etocsetnexttocdepth{2}

\begingroup
\etocdefaultlines
\etocclasstocstyle
\etocsetlevel{book}{3}
\etocsetlevel{part}{3}
\etocsetlevel{chapter}{3}
\etocsetlevel{section}{3}
\etocsetstyle{subsection}{\small
\begin{enumerate}[itemsep=0pt,label=,leftmargin=0pt]}
{\normalfont\bfseries\item}
{\roman{enumi}. \mdseries\etocname{} (\etocnumber, p.~\etocpage)}
{\end{enumerate}}

\renewcommand{\etoccolumnsep}{2.75em}
\renewcommand{\columnseprule}{1pt}

%%\etocmarkbothnouc{List of all subsections}
%% le mark (\markright) est fait par \subsection

\etocmulticol[3]{\subsection{All subsections of this document}\label{toc:allsubsections}}

\endgroup

\section{Displaying statistics}\label{ssec:statistics}

Each part of this document starts with a paragraph telling how many
sections and subsections it has. Well, each one of this paragraph is a
table of contents! We designed a macro \csa{thispartstats} to do that.
It uses ``storage'' boxes to keep the information about the first and
last section or subsection. Using boxes is the simplest manner to
encapsulate the \ctanpkg{hyperref} link for later use (whether there is one or
none). However, one cannot modify then the font or the color.
%  (using the
% \TeX{} primitive \csa{setbox} rather than the \LaTeX{} \csa{sbox} would
% allow to change the color of the un-boxed saved box)
If such a need
arises, one must switch from using boxes to using macros, and store the
\ctanpkg{hyperref} data for later use as was done in the code presented in
\autoref{sec:molecule}. We present also this second method.

But first, the code of \csa{thispartstats}:\par
\begin{filecontentshere}{etocsnippet-\snippetno.tex}
\newsavebox\firstnamei  \newsavebox\firstnumberi
\newsavebox\lastnamei   \newsavebox\lastnumberi
\newsavebox\firstnameii \newsavebox\firstnumberii
\newsavebox\lastnameii  \newsavebox\lastnumberii
\newcounter{mycounti}   \newcounter{mycountii}
\newcommand*{\thispartstatsauxi}{} \newcommand*{\thispartstatsauxii}{}
\newcommand*{\oldtocdepth}{}
\newcommand*{\thispartstats}{%
  \setcounter{mycounti}{0}%
  \setcounter{mycountii}{0}%
  \def\thispartstatsauxi{%
         \sbox{\firstnamei}{\footnotesize\etocname}%
         \sbox{\firstnumberi}{\footnotesize\etocnumber}%
         \def\thispartstatsauxi{}}%
  \def\thispartstatsauxii{%
         \sbox{\firstnameii}{\footnotesize\etocname}%
         \sbox{\firstnumberii}{\footnotesize\etocnumber}%
         \def\thispartstatsauxii{}}%
  \begingroup
  \etocsetstyle{subsection} {} {}
    {\thispartstatsauxii
     \stepcounter{mycountii}%
     \sbox{\lastnameii}{\footnotesize\etocname}%
     \sbox{\lastnumberii}{\footnotesize\etocnumber}} {}%
  \etocsetstyle{section} {} {}
    {\thispartstatsauxi
     \stepcounter{mycounti}%
     \sbox{\lastnamei}{\footnotesize\etocname}%
     \sbox{\lastnumberi}{\footnotesize\etocnumber}}
    {{\footnotesize\itshape
    Here are some statistics for this part: it contains \arabic{mycounti}
    section\ifnum\value{mycounti}>1 s\fi{} and \arabic{mycountii}
    subsection\ifnum\value{mycountii}>1 s\fi. The name of the first section is
    \unhbox\firstnamei{} and the corresponding number is \unhbox\firstnumberi.
    The name of the last section is \unhbox\lastnamei{} and its number is
    \unhbox\lastnumberi. The name of the first subsection is \unhbox\firstnameii{}
    and the corresponding number is \unhbox\firstnumberii. The name of the last
    subsection is \unhbox\lastnameii{} and its number is \unhbox\lastnumberii.\par}}%
  \etocinline % cancels the automatic \par automatically before the TOC
  \etocsettocstyle {}{}
  \etocsetnexttocdepth{2}%
  \localtableofcontents  % to be used at the top level of a Part.
  \endgroup
}
\end{filecontentshere}
\marginattach

And now, the variant with macros rather than boxes (this variant as it
stands here is for using within a section).
\begin{filecontentshere}{etocsnippet-\snippetno.tex}
\makeatletter
\newcommand*\firstsubname   {}  \newcommand*\lastsubname    {}
\newcommand*\firstsubnumber {}  \newcommand*\lastsubnumber  {}
\newcommand*\thisspecialstatsaux{}
\newcommand*{\thisspecialstats}{%
  \setcounter{mycounti}{0}%
  \def\thisspecialstatsaux{%
         \let\firstsubname\etocthelinkedname
         \let\firstsubnumber\etocthelinkednumber
         \def\thisspecialstatsaux{}}
  \begingroup
  \etocsetstyle{subsection} {} {}
    {\thisspecialstatsaux
     \stepcounter{mycounti}%
     \let\lastsubname\etocthelinkedname
     \let\lastsubnumber\etocthelinkednumber }
    {Here are some statistics for this section. It contains \arabic{mycounti}
      subsections. The name of its first is \emph{\firstsubname{}} and the
      corresponding number is {\firstsubnumber}. The name of the last
      subsection is \emph{\lastsubname{}} and its number is {\lastsubnumber}.}%
   \etocsettocstyle {}{}
   \etocinline
   \etocsetnexttocdepth {1}%
   \localtableofcontents % to be used within a section
  \endgroup
}
\makeatother
\end{filecontentshere}
\marginattach

\section{Using depth tags}
\label{sec:tocwithdepthtags}

We want a TOC which will have a heading for each |\part| (except
the last part with the code source, which we decide not to
include), and will additionally open up \autoref{sec:tocstyle}
up to paragraphs. To achieve this we added to this source various
\csb{etocdepthtag.toc} commands, and it remains now to set the
levels for each tag using \csb{etocsettagdepth} (this was used
earlier in this document, in \autoref{sec:secondexample}, within a
group hence it did not affect the other tables of contents).

However, the package line styles do not display paragraphs, and the
standard line styles of the document class give too much vertical
spacing (in this context) when displaying a Part heading in the TOC. So
we cook up our own, quickly designed line styles, in the style of
\autoref{sec:firstexample} (but with a way to put page numbers on the
right which is more like the method used by \LaTeX2e's
|\@dottedtocline|; and multi-line headings now leave empty the area
underneath the numbers contrarily to the code from
\autoref{sec:firstexample}). And after a few minutes for choosing
lengths (now that this has been done once, it can be recycled easily) we
get:

\begin{filecontentsdef}{etocsnippet-\snippetno.tex}{\foo}
\etocsetnexttocdepth {all}
\begingroup
\parindent 0pt \leftskip 0cm \rightskip .75cm \parfillskip -\rightskip
\newcommand*{\EndParWithPagenoInMargin}
    {\nobreak\hfill
     \makebox[0.75cm][r]{\mdseries\normalsize\etocpage}%
     \par}
\renewcommand*\etoctoclineleaders
    {\hbox{\normalfont\normalsize\hbox to .75ex {\hss.\hss}}}
\newcommand*{\EndParWithPagenoInMarginAndLeaders}
    {\nobreak\leaders\etoctoclineleaders\hfill
     \makebox[0.75cm][r]{\mdseries\normalsize\etocpage}%
     \par }
\etocsetstyle {part}
              {}
              {\leavevmode\leftskip 1cm\relax}
              {\bfseries\large\llap{\makebox[1cm][r]{\etocnumber\ \ }}%
               \etocname\EndParWithPagenoInMargin\smallskip}
              {}
\etocsetstyle {section}
              {}
              {\leavevmode\leftskip 1.75cm\relax}
              {\bfseries\normalsize\llap{\makebox[.75cm][l]{\etocnumber}}%
               \etocname\EndParWithPagenoInMarginAndLeaders}
              {}
\etocsetstyle {subsection}
              {}
              {\leavevmode\leftskip 2.75cm\relax }
              {\mdseries\normalsize\llap{\makebox[1cm][l]{\etocnumber}}%
               \etocname\EndParWithPagenoInMarginAndLeaders}
              {}
\etocsetstyle {subsubsection}
              {}
              {\leavevmode\leftskip 4cm\relax }
              {\mdseries\normalsize\llap{\makebox[1.25cm][l]{\etocnumber}}%
               \etocname\EndParWithPagenoInMarginAndLeaders}
              {}
\etocsetstyle {paragraph}
              {}
              {\leavevmode\leftskip 5.5cm\relax }
              {\mdseries\normalsize\llap{\makebox[1.5cm][l]{\etocnumber}}%
               \etocname\EndParWithPagenoInMarginAndLeaders}
              {}
\etocsettagdepth {preamble}    {all}
\etocsettagdepth {overview}    {part}
\etocsettagdepth {styling}     {subsection}
\etocsettagdepth {control}     {subsubsection}
\etocsettagdepth {examples}    {part}
\etocsettagdepth {advanced}    {part}
\etocsettagdepth {etocandworld}{all}
\etocsettagdepth {code}        {all}
\renewcommand\etoctoprule {\hrule height 3pt\relax }
\renewcommand\etoctoprulecolorcmd {\color{blue}}
\renewcommand\etocaftercontentshook
   {\medskip\begingroup \color{blue}\hrule height 3pt \endgroup }
\etocruledstyle [1]{\Large\bfseries
                    \fbox{\makebox[8cm]{A TOC using depth tags}}}
\sloppy
\etocobeydepthtags % let's not forget to activate this (default anyhow)
\tableofcontents
\endgroup
\end{filecontentsdef}

\filecontentsexec\foo

\filecontentsprintviascan\foo
\marginattach

\section{Sections styling subsections}
\label{sec:anothercompatadvanced}

Here is a subtler example where one only marginally modifies the sections
(adding color to the number, removing the \ctanpkg{hyperref} link, changing
the color for one specific section) but let them decide almost one by one
of the style which will be followed by their subsections.  Furthermore one
configures some sections to decide they will not display subsections at all or
only count how many there are!

% modified for 1.2 doc to make the argument optional and update number
% of exceptional section

\begin{filecontentshere}{etocsnippet-\snippetno.tex}
\makeatletter
\newcommand*{\MyQuasiStandardTOC}[2][]{%
  % #1 is an optional "\ref{somelabeltoanothertoc}"
  % #2 is the number of some exceptional section
  \begingroup
  \etocsetstyle{section}
    {}
    {\etociffirst{% Suppress display of subsections for the first section!
                  \etocsetlevel{subsection}{\etocthemaxlevel}}
                 {\etocsetlevel{subsection}{2}}%
     \ifnum\etocthenumber=#2 % Handle especially section number #2 !
      \etocsetstyle{subsection}
        {\def\foo{}\par\nopagebreak\begingroup
         \leftskip2em \rightskip\@tocrmarg
         \parfillskip \@flushglue
         \parindent 0pt
         \normalfont\normalsize\rmfamily\itshape
         \etocskipfirstprefix}
        {\allowbreak\,--\,}
        {\edef\foo{\the\numexpr\foo+1}\etocname\ \textup{(\etocnumber)}}
        {.\par \upshape My AI counted circa \foo\space subsections,
                        was it right?\par\endgroup}%
     \else
      \ifnum\etocthenumber>#2 % Only count subsections in those sections !
        \etocsetstyle{subsection}
        {\def\foo{}}%
        {\edef\foo{\the\numexpr\foo+1}}%
        {}%
        {\leftskip2em \emph{There are \foo\space subsections here,
                      but I will need payment to display them.}\par}%
      \else
        \etocsetstyle{subsection}
        {}%
        {}%
        {\l@subsection{\numberline{\etocnumber}\etocname}{\etocpage}}%
        {}%
      \fi
    \fi
    }%
    {% Display in a special color the number of the special section!
     \l@section{\numberline{{\ifnum\etocthenumber=#2
                             \color{red}\else\color{cyan}\fi\etocthenumber}}%
                \etociffirst{\etocname\space (SUBSECTIONS SKIPPED)}{\etocname}}
               {\etocpage}}%
    {}%
  \etocclasstocstyle % will use the ambient document class
     % special KOMA-script customization as this document uses scrartcl
     % and we need to enlarge numwidth for some subsections
     \DeclareTOCStyleEntry[numwidth=2em,indent=0pt]{tocline}{section}
     \DeclareTOCStyleEntry[numwidth=2.5em,indent=2em]{tocline}{subsection}
  \etocsetnexttocdepth {subsection}%
  \tableofcontents #1
  \endgroup
}
\makeatother
\end{filecontentshere}

\marginattach
\filecontentsexec\filecontentsheremacro

The optional argument stands for a suitable |\ref|, see \autoref{sec:labeling}.
Here is what
\begin{verbatim}
\MyQuasiStandardTOC[\ref{toc:part:styling}]{11}% treat especially section 11
\end{verbatim}
gives:
\MyQuasiStandardTOC[\ref{toc:part:styling}]{11}%

\vskip.5\baselineskip

The page heading (on the page where this TOC appears) may have been modified
as is expected from usage of \csb{etocclasstocstyle} in the code.

Sections are printed exactly as in the default, \emph{except} that a special
section number is displayed especially and that its subsections are then
displayed inline! And other sections may only count subsections or
ignore them altogether!

Note: for this code to work the macro \csa{thesection} \emph{must} not have
been modified from its default which produces simply arabic digits.  In other
terms it must be usable as \TeX{} number denotation.  Typically this would
fail if we were handling subsections as their number in the |.toc| file will
be typically something like |3.7| which does not work in a \TeX{} integer-only
context.  But it is possible to use a counter and configure the line styles to
increment it, and use its value.



\section{The TOC as a (long) table (alternative)}
\label{ssec:tocastableold}

Due to, among other things, the fact that alignment cells create and close
groups, and that by default definitions of \csb{etocname}, \csb{etocnumber},
\csb{etocpage} made by \etoc are local, it was not easy to typeset a TOC as
table with \etoc, prior to release to the addition of \csb{etocglobaldefs} at
\etocrelease{1.08}.

Not only \csb{etocname} etc... caused a problem, but also the basic
redefinition of \csa{contentsline} was made by \etoc only after the
first argument to \csb{etocsettocstyle} had been executed, hence if this
argument were to open a tabular, the \etoc redefinition of
\csa{contentsline} would be done in the first cell of the first row and
get lost thereafter.

Thus one had to resort to the technique explained in \autoref{tocastree}
of using the execution of \csa{tableofcontents} as a way to store data
which was then displayed later.

For the record, here is how the TOC from \autoref{sec:tocastable} was
coded in the old days.%
%
\footnote{At release \etocrelease{1.09f} the design anb contents of the TOC
  from \autoref{sec:tocastable} were modified; the code here, if executed,
  which will not, reproduces the
  former looks.}
%
We don't have here the problems with the
positioning of |\hline|'s we face with the newer method; on the other
hand we must manipulate token registers which are not familiar to most
\LaTeX{} users (macros could be used, but would be more cumbersome,
except perhaps if using the \eTeX{} \csa{unexpanded}).

The method here is the most powerful because it filters out of the
|.toc| file only the data we want (the other things are not ignored,
they are executed but hopefully do not create havoc; typically they are
language changing instructions, etc...),
and we are less susceptible to fall potential victims of various
external macros inserted in the |.toc| file by other packages.

Note: rather than |\toks| registers it would be easier here to use \eTeX{}
\csa{unexpanded} primitive. See for example \autoref{sec:mindmap}.

\let\appendtotok\relax
\let\PreparePart\relax
\let\PrepareSection\relax
\let\PrepareSubsection\relax
\begin{filecontentshere}{etocsnippet-\snippetno.tex}
\newtoks\toctabletok
\newcommand*\appendtotok[2]{% #1=toks variable, #2=macro, expands once #2
  #1\expandafter\expandafter\expandafter {\expandafter\the\expandafter #1#2}}

\newcommand*\PreparePart{%
  \toks0 \expandafter{\etocthelinkednumber}%
  \toks2 \expandafter{\etocthelinkedname}%
  \toks4 \expandafter{\etocthelinkedpage}%
  \edef\toctablepiece {\noexpand\hline
                      \noexpand\strut\the\toks0 &\noexpand\bfseries\the\toks2
                                 &\the\toks4 \noexpand\\\noexpand\hline}%
}
\newcommand*\PrepareSection{%
  \toks0 \expandafter{\etocthelinkednumber}%
  \toks2 \expandafter{\etocthelinkedname}%
  \toks4 \expandafter{\etocthelinkedpage}%
  \edef\toctablepiece {\the\toks0 &\the\toks2 &\the\toks4 \noexpand\\}%
}
%
\newcommand*{\PrepareSubsection}{%
  \toks0 \expandafter{\etocthelinkednumber}%
  \toks2 \expandafter{\expandafter\itshape\etocthelinkedname\strut}%
  \toks4 \expandafter{\expandafter\itshape\etocthelinkedpage}%
  \edef\toctablepiece{&\noexpand\makebox[1cm][c]{\the\toks0}%
                      \noexpand\parbox[t]{\dimexpr6cm-\tabcolsep\relax}
                                         {\noexpand\sloppy\the\toks2}%
                      &\the\toks4 \noexpand\\}%
}

\begingroup
\etocsetstyle{part}{}{}{\PreparePart \appendtotok\toctabletok\toctablepiece}{}

\etocsetstyle{section}{}{}{\PrepareSection \appendtotok\toctabletok\toctablepiece}{}

\etocsetstyle{subsection}{}{}{\PrepareSubsection\appendtotok\toctabletok\toctablepiece}{}

\etocsettocstyle
    {\toctabletok{\hypersetup{hidelinks}%
                 \begin{longtable}{|>{\bfseries}c|p{7cm}|r|}\hline
                 \multicolumn{3}{|c|}{\Large\bfseries\strut TABLE OF CONTENTS}%
                 \\\hline\hline}}
    {\global\toctabletok\expandafter{\the\toctabletok\hline\end{longtable}}}
\etocsettocdepth {subsection}
\tableofcontents
\the\toctabletok
\endgroup
\end{filecontentshere}
\marginattach

\clearpage
\etocdepthtag.toc {etocandworld}
\part{\etoc and the world}

\etocsettocstyle{}{}
\etocdefaultlines % etoc own default
\localtableofcontents

\section{Constraints on the \texttt{.toc} file constitution}

The contents of the |.toc| file (if it already exists) are read into memory by
\etoc once, at the time of |\begin{document}|.%
%
\footnote{%
    Versions earlier than \etocrelease{1.07m} read the |.toc| file at the time of
    \csa{usepackage\{etoc\}}. Thanks to Denis Bitouzé who signaled a Babel
    related problem, which turned out to be caused by this.}

The |.toc| file remains available
  to other packages for read operations until the location of the first table
  of contents at which time a write stream is opened by \etoc and from that
  point the file is erased until its contents are again written to the disk by
  \LaTeX{} at the end of the compilation.

Don't use |\if<condition> stuff \tableofcontents\fi|, but:
\centeredline{|\if<condition> stuff \expandafter\tableofcontents\fi|}
Also a |\else| immediately following \csa{tableofcontents} or
\csa{localtableofcontents} requires a previous \csa{expandafter}.


\etoc can not really cohabit with packages modifying the \csa{tableofcontents}
  command: some sort of truce can be achieved if \etoc is loaded last, hence is
  the winner.

\begin{framed}
    Do not modify the |\tableofcontents| command like this:
    \centeredline{|\let\oldtableofcontents\tableofcontents|}
    \centeredline{|\renewcommand\tableofcontents{\oldtableofcontents foo}|}
    as this will make the |\label/\ref| mechanism impossible.

    Rather, redefine  \csb{etocaftertochook}
\centeredline{|\renewcommand\etocaftertochook{foo}|} and there
    is also \csb{etocaftercontentshook} which is executed a bit
    earlier\footnotemark{} just before the closing part of the toc display
    style (and thus still within a group.)

    Prepending is less of a problem (and anyhow there is also
    \csb{etocbeforetitlehook} available to the user).

    Under certain circumstances \etoc imposes its views on
    \csa{tableofcontents} at the time of |\begin{document}|. You may thus have
    to use \csa{AtBeginDocument} to delay your (necessarily ugly and
    non-recommendable) patches. Patching after |\begin{document}| is
    naturally possible but I feel almost a rebel to mention this to \LaTeX{} users!
\end{framed}
\footnotetext{Contrarily to \csb{etocaftertochook},
      \csb{etocaftercontentshook} is not executed if the |tocdepth| did not
      allow the printing of the TOC.}

\etoc \textbf{requires} the |.toc| file to use the \csa{contentsline}
    macro. It \textbf{can not} work if there is no |.toc| file or if the
    |.toc| file does
    not use the \csa{contentsline} macro or if the \csa{contentsline} macro
    second argument mixes number and name in a manner unexpected by \etoc.%
%
\footnote{Prior to \etocrelease{1.1a}, \etoc required the \csa{contentsline} macro
  expansion to invoke \csa{l@section} et al.  It now does not expand
  \csa{contentsline} hence is immune to whatever would happen during this
  expansion, and does not use nor modify the \csa{l@section} et al.\@ macros.}

\section{Compatibility with document classes}

\etoc has mainly been tested with the |article| and |book| standard classes.
Some compatibility layer with the \ctanpkg{KOMA-script} and \ctanpkg{memoir} classes was added at
\etocrelease{1.05} of |2012/12/01|.%
%
\footnote{That this is still in the doc on \texttt{2023/02/22} shows
  the frequency of \etoc syncing with upstream changes... but let me reassure
  the reader there has
  been indeed some occasional, although admittedly rare, internal updates
  in the more than ten years elapsed since.}
%
A compatibility layer is required for what this
document designates as the ``global display style'': \etoc tries to emulate the
default behaviour of the document class when \csb{etocsettocstyle} has not
been used, so that it is still in ``compatibility mode''.  There does not seem
to be an easy
way to extract this in an automated manner dynamically, so it is basically
some manual work which the author initiated in 2012 and which got sporadically
updated since.

\subsection{Compatibility with the \ctanpkg{KOMA-script} classes}
\label{etocscrartclstyle}
\label{etocscrbookstyle}
\label{etocscrreprtstyle}

Not really tested... well, tested by this document with its dozens of \etoc
TOCs and which uses \ctanpkg{scrartcl}!  The package code contains
\begin{verbatim}
\@ifclassloaded{scrartcl}
    {\renewcommand*\etocclasstocstyle{\etocscrartclstyle}}{}
\end{verbatim}
with \cs{etocscrartclstyle} trying to emulate the global display style of the
\cs{tableofcontents} within the class \ctanpkg{scrartcl}.  Thus \etoc is ready
for basic usage in compatibility mode.  See further \autoref{ssec:tocbasic}.

\subsection{Compatibility with the \ctanpkg{memoir} class}
\label{ssec:memoir}
\label{etocmemoirtoctotocfmt}
\label{etocmemoirstyle}

Release \etocrelease{1.07l} has also improved the compatibility with the \ctanpkg{memoir} class: its
|appendix| level has been made known to \etoc. It is at the same level as
|chapter|, thus the chapter line style should possibly do a test for some user
defined boolean whose activation may be added to the |.toc| file at the suitable
location via |\addtocontents{toc}{..}|, if one needs to distinguish the two
kinds of divisions.

The \ctanpkg{memoir} mechanism relative to \toc versus \toc|*| is obeyed
automatically, and applies with \localtoc too.

With release \etocrelease{1.2} some issues which were previously described here
when the ``to toc'' feature of \ctanpkg{memoir} was left acting on local TOCs
have been resolved, as an after-effect of the support for
\etocoption{localtoctotoc} etc..., see \csb{etocsetup}.

\subsection{Compatibility with \ctanpkg{beamer}}

For the reasons mentioned already regarding the constraints on the |.toc| file
constitution, \etoc is incompatible with the
\ctanpkg{beamer} class. However, if \ctanpkg{beamer} is used in an article mode, i.e., with
the article class in conjunction with the \ctanpkg{beamerarticle} package, then \etoc
should work.

\section{Compatibility with other packages}

\subsection{Compatibility with \ctanpkg{babel}}

\begin{framed}
  One must load \etoc \emph{after} \ctanpkg{babel}. This is in order for
  \ctanpkg{babel}'s shorthands to be active at the time when \etoc loads the |.toc|
  file.
\end{framed}

\subsection{Compatibility with \ctanpkg{hyperref}}

Please inform the author in case of issues: \etoc was from the start designed
to be |100%| compatible with package \ctanpkg{hyperref}.

The macros \csb{etocname}, \csb{etocnumber}, and \csb{etocpage} contain the
\ctanpkg{hyperref} links, if present (note that the \emph{linktoc=all} option of
\ctanpkg{hyperref} tells it to put a link also in the page number corresponding to a
given toc entry). For example, the tables of contents of the present document
are all fully linked. It doesn't matter whether \etoc or \ctanpkg{hyperref} is loaded
first.

% 2015/11/12
% Pour une raison que j'ignore dans la TOC principale j'ai un problème avec
% cette sous-section.
% \subsection{Com\-pat\-i\-bil\-ity with \ctanpkg{multicol}}

\subsection{Compatibility with \ctanpkg{multicol}}

\etoc loads the package \ctanpkg{multicol}.

\subsection{Compatibility with \ctanpkg{tocloft}}\label{subs:tocloft}

Release \etocrelease{1.07k} added compatibility with package
\ctanpkg{tocloft}: steps are
taken to prevent the redefinition of |\tableofcontents| done by
\ctanpkg{tocloft} at |\begin{document}|.
%
As long as \etoc is left in compatibility mode the customization done by
\ctanpkg{tocloft} will be obeyed, for both the line styles and the TOC title.
One may still benefit from the \emph{depth tags} management by \etoc,
from its |\localtableofcontents|, from its |\label+\ref| mechanism. One
may use |\etocsetstyle| to define via \etoc the layout for one TOC and
then use rather \ctanpkg{tocloft} for another one, if |\tableofcontents| follows
\csb{etocstandardlines} and \csb{etocclasstocstyle}. In this
compatibility mode \csb{etocsetlevel}\marg{division unit}|{|\csb{etocthemaxlevel}|}| will render
invisible the chosen division level, but exchanging levels is otherwise
not possible.

\begin{framed}
  One should load \etoc \emph{after} \ctanpkg{tocloft}. A warning is
  issued if otherwise, because if \etoc is loaded before it will realize that at
  the time of |\begin{document}| and trick \ctanpkg{tocloft} into believing
  having been loaded with the |titles| option.
\end{framed}

It is possible to modify midway in the document the macros \csa{l@section},
\csa{l@subsection} ... but the effect will be seen only in table of contents
typeset by \etoc in compatibility mode (and of course after those
customizations).  It will have no effect on true \etoc TOCs.

\subsection{Compatibility with \ctanpkg{tocbibind}}\label{subs:tocbibind}

Added at \etocrelease{1.2}. See also \csb{etocsetup} for a discussion of the
  package options which are all related to this (they will achieve the
  \ctanpkg{tocbibind} ``to toc'' features without requiring the package).

Thanks to Denis Bitouzé for feature request.

\subsection{Compatibility with \ctanpkg{tocvsec2}}

  \etoc used to be incompatible with package
  \ctanpkg{tocvsec2}; it now cohabits, sort
  of, as it deactivates \ctanpkg{tocvsec2}'s modification of |\tableofcontents|
  and also cancels its other |toc|-related macros, but
  reimplements partially their functionality with \csb{etocsettocdepth.toc}. By
  the way, at least two latex runs are necessary for new uses of this command in
  a document to have an effect in tables of contents.

\subsection{Compatibility with \ctanpkg{tableof}}

It is possible to use simultaneously \etoc and
\ctanpkg{tableof}. Release
\etocrelease{1.08} of \etoc requires at least version |1.4a| of \ctanpkg{tableof}. If
\csb{etocglobaldefs} is put in the preamble, this must be after the loading of
package \ctanpkg{tableof}. {\color{niceone}\ctanpkg{tableof}} command \csa{nexttocwithtags}
should work as expected.

\ctanpkg{tableof} commands \csa{tableof}, \csa{tablenotof}, ... will
typeset the (a priori global) table of contents according to the document
class defaults, obeying the \etoc depth tags; as explained in the \ctanpkg{tableof}
documentation they do not typeset a TOC title. They should \emph{not} be used
in case \csb{etocglobaldefs} was issued before, except if its scope has been
terminated since then, or \csb{etoclocaldefs} has cancelled its influence.

\subsection{Compatibility with \ctanpkg{tocbasic}}
\label{ssec:tocbasic}

(doc last updated for \etocrelease{1.2})

This has only been tested to the extent of production of this PDF file (which
does have dozens of TOCs, among them a few in compatibility mode).  I
noticed that some things required the global display style to also be set
to compatiblity mode for some \ctanpkg{KOMA-script} user interface to produce
the desired effect.  As an example, the local table of contents of
\autoref{sec:testingcompat} uses |\KOMAoptions{toc=left}| and
\csb{etocstandardlines} but it had to use also \csb{etocclasstocstyle}:
\begin{verbatim}
\begingroup % to keep in particular toc=left with local effect
\KOMAoptions{toc=left}
\etocclasstocstyle % necessary for the display to obey toc=left
\etocstandardlines
\tableofcontents \ref{toc:tocstyle}
\endgroup
\end{verbatim}
On the other hand I could use some other interface without having to activate
the compatibility for the global display style.  See \hyperref[toc:d]{the example} from
\autoref{sec:labeling} or the one from the \autoref{part:control} which uses
\begin{verbatim}
\begingroup
\etocsettocstyle{}{}
\DeclareTOCStyleEntry[numwidth=2em,indent=0pt]{tocline}{section}
\DeclareTOCStyleEntry[numwidth=2.5em,indent=2em]{tocline}{subsection}
\DeclareTOCStyleEntry[numwidth=3em,indent=4.5em]{tocline}{subsubsection}
\etocstandardlines
\localtableofcontents
\endgroup
\end{verbatim}
and demonstrates that this interface works also when not using the
compatibility mode from \csb{etocclasstocstyle}.  Of course, here the
display style is a bit plain... but the \hyperref[toc:d]{example} of
\autoref{sec:labeling} less so; it uses about the same TOCStyleEntry lines as
above with some more width for the numbers of subsections.

\section{\TeX nical matters}

The \csb{etocname}, \csb{etocnumber}, \csb{etocpage} commands are protected
against premature expansion. They are hyperlinks if package \ctanpkg{hyperref}
is loaded and depending on its option |linktoc| value; under the default
|linktoc=section|, only name and number are hyperlinked, not the page
number.

On the other hand \csb{etocthename}, \csb{etocthenumber}, \csb{etocthepage}
are \emph{not} protected against expansion. And neither are
\csb{etocthelinkedname}, \csb{etocthelinkednumber}, \csb{etocthelinkedpage}.
They were modified at \etocrelease{1.1a} and now are always hyperlinks (except for the
latter if the page number is empty), if
\ctanpkg{hyperref} is present, independently of |linktoc| status.

The commands \csb{etoclink} and \csb{etocifnumbered} are also
protected against premature expansion. Also \csb{etociffirst} and
\csb{etoctoccontentsline}.

Commands such as \csb{etocsetstyle}, \csb{etocsetlevel},
\csb{etocsettocstyle}, \csb{etocmulticolstyle},
\csb{etocruledstyle}, \csb{etocframedstyle} obey \LaTeX{}'s
groups. All TOCs are typeset inside groups.

When a \localtoc is inserted by the user in the document, a
line containing an \etoc inner command and an identification
number is added to the |.toc| file on first subsequent compilation.
The correct local table of
contents will be displayed only on the second compilation.


%%% de-\section this for matters of avoiding too cramped mindmap TOC
%%%\section{Errors and catastrophes}

  After using \csb{etocsetstyle} for one level, the remaining
  uncustomized levels use the \etoc default styles (those
  which are activated by \csb{etocdefaultlines}). One has to
  make sure that \textbf{all levels} needed for the next table of
  contents are mutually compatible: in particular the \etoc
  default line styles expect each to be started in ``vertical mode''.

  When using multiple \toc commands in a document, one should beware from
  adding typesetting instructions directly in the |.toc| file, as they will be
  executed by \etoc for \textbf{all TOCs}: even for a \localtoc it doesn't
  matter if that instruction seems to concern material outside of its scope,
  it will get executed nevertheless. If absolutely necessary to add extra
  commands to the |.toc| file, make it in such a way that they can be
  activated or deactivated easily from the document source, e.g.\@ via some
  booleans.

  As is usual with toc and labels, after each change, one has
  to run latex a certain number of times to let the produced
  document get its final appearance (at least twice).\par

\clearpage
\etocdepthtag.toc {code}
\normalmarginpar\marginparwidth72bp
\part{The code}

% return to single spacing
\setstretch{1}

\etocdefaultlines
\etocsettocstyle{}{}

\localtableofcontents

% IL FAUT METTRE AVANT \section{Timestamps} SINON FOUTU
% (non plus maintenant puisque j'utilise \botmark pas \firstmark
%  dans le \rightmark)
% Que c'est pénible cette syntaxe \markboth/\markright de LaTeX !
% Pourquoi est-ce que \markright n'a pas été définie comme #1#2-> truc avec #2 ??
\makeatletter
\if@twoside
\renewcommand *{\sectionmark }[1]{%
  \markboth
         {\unexpanded{\ifodd\value{page}(\hyperref[imp]{implementation},
                                         \hyperlink{FRONTPAGE}{user manual
                                           front page})\hfill\fi
          \hyperref[changelog]{\thesection. Change history}%
          \ifodd\value{page}\else\hfill(\hyperref[imp]{implementation},
                                        \hyperlink{FRONTPAGE}{user manual
                                          front page})\fi}}%
         {\unexpanded{\ifodd\value{page}(\hyperref[imp]{implementation},
                                         \hyperlink{FRONTPAGE}{user manual
                                           front page})\hfill\fi
          \hyperref[changelog]{\thesection. Change history}%
          \ifodd\value{page}\else\hfill(\hyperref[imp]{implementation},
                                        \hyperlink{FRONTPAGE}{user manual
                                          front page})\fi}}%
}
\else\error
% faudrait cependant que je réfléchisse à quoi faire exactement en oneside
% mais comme ceci ne peut arriver que si quelqu'un customise etoc.tex
% ce qui n'arrivera JAMAIS, je laisse tomber
\renewcommand *{\sectionmark }[1]{%
  \markright
         {\unexpanded{\ifodd\value{page}(\hyperref[imp]{implementation},
                                         \hyperlink{FRONTPAGE}{user manual
                                           front page})\hfill\fi
          \hyperref[changelog]{\thesection. Change history}%
          \ifodd\value{page}\else\hfill(\hyperref[imp]{implementation},
                                        \hyperlink{FRONTPAGE}{user manual
                                          front page})\fi}}%
}
\fi
\makeatother

\section{Timestamp}

This is the documentation as of \texttt{\etocdocdate}, printed from the
source file with the time stamp \texttt{\etocdtxtimestamp}. The package
version is \texttt{\etocpkgversion}, of \texttt{\etocpkgdate}.

\catcode1 13

\begingroup
\renewcommand\lowast{{\normalsize\raisebox{-.4\height}{*}}}
\small

    \section{Change history}\label{changelog}

\setlength{\columnsep}{\etoccolumnsep}

\makeatletter

% 27 avril 2014 un petit hack pour hyphénation (éventuelle) en allemand
% j'ai déjà ~ qui sera de catcode 0, cependant il faudrait aussi les accolades,
% donc finalement pour aller vite, je rends le + actif. Je modifie aussi le test
% fait par \jfverbaspace (n'ayant pas commenté mon code, j'ai dû réfléchir pour
% me rappeler à peu près ce que c'était censé faire).

\def\jfverbatim{\@beginparpenalty \predisplaypenalty
  \parindent \z@
  \parfillskip \@flushglue
  \parskip \tw@\p@ plus 1fil\relax
  \let \do \@makeother
  \dospecials
  \makestarlowast
  \catcode`$ \active
  \begingroup\lccode`~`$
  \lowercase{\endgroup\def~[##1]{\foreignlanguage{ngerman}{##1}}}%
  \catcode`^ \active
  \begingroup\lccode`~`^
  \lowercase{\endgroup\def~{\nopagebreak}}% ajouté 2014/04/28, oblige à un peu
                                % plus de mark-up cependant
  \catcode`\~\z@
  \footnotesize\normalfont\baselineskip10pt\relax
%  \def\v{\vskip\baselineskip v}% ajouté 2015/05/09; faudra trouver mieux.
% 2022/08/30, I remove all "v"'s from version numbers.
% 2023/01/25, creating hypertargets
  \begingroup\lccode`~32
  \lowercase{\endgroup
             \def\1##1~{\vskip\baselineskip\hypertarget{v1##1}{1##1}~}}%
% 2022/08/26, stop using \frenchspacing
  % \frenchspacing
% 2023/01/14
  \def\2##1.{\ctanpkg{##1}}%
% 2022/08/26.  I realized that rendering was broken, and finally identified
% the bad commit to be in LaTeX 2022/06/01 release.  Its \obeyspaces not only
% makes the ascii32 \active but it also redefines it!  Solution could be to
% actually use \obeyedspace in the definition of active space about 20 lines
% below but this would tie to LaTeX 2022/06/01 or later for building etoc.pdf
  \catcode`\ \active %  was \obeyspaces
  \jf@xverbatim
}

\begingroup
\catcode `|=0 \catcode `[= 1 \catcode`]=2
\catcode `\{=12 \catcode `\}=12 \catcode`\\=12
|long|gdef|jf@xverbatim#1\end{jfverbatim}[#1|end[jfverbatim]]
|endgroup

\def\endjfverbatim{}

\newdimen\jfverbadim
\makeatother

\begin{multicols}{2}
% un \raggedcolumns ne fonctionne pas vraiment pour faire de l'alignement
% de grid à cause du \parskip
\makeatletter
\everypar{\leftskip\jfverbadim\bgroup
          \def\par{\egroup\jfverbadim\z@\@@par}%
          \def\jfverbaspace#1{\if\@sptoken\string#1\unskip\else\ \fi#1}}
%
% see 2022/08/26 above note
\begingroup\obeyspaces\def\x{\endgroup%
\def {\ifvmode\advance\jfverbadim.5em\relax\else\expandafter\jfverbaspace\fi}}\x
\makeatother
\vskip-\baselineskip
\begin{jfverbatim}
~1.2a [2023/05/01]^

    The requirements (added respectively at 1.1a and 1.2) of a LaTeX
    kernel at least as recent as 2020-10-01 and of availability of
    \expanded engine primitive have been lifted.  Due to lack of time
    and ressources, etoc is not retro-tested on old LaTeX installations,
    though.

    Boolean option `deeplevels' extends the maximal allowed numerical
    level from 6 to 12.  Adapted from a patch courtesy of Matthew
    Trescott.  See

    https://github.com/doxygen/doxygen/pull/9936

    for context.

    Using this option does not change anything to tocdepth and
    secnumdepth LaTeX counters, nor does it do any of the needed extras
    to let a sectioning level be known to LaTeX (if etoc is used in
    "compatibility mode", the suitable \l@<levelname> macros must have
    been declared to LaTeX for TOC rendering).  Whether or not using
    etoc in compatibility mode (i.e. whether or not using
    \etocsetstyle{<levelname>}{...}{...}{...}{...}), recall that all new
    levels must be declared to etoc at least once via
    \etocsetlevel{<levelname>}{<number>}.

    The macro \etocthemaxlevel expands accordingly to either 6 (default)
    or 12 (if option `deeplevels').  So
    \etocsetlevel{foo}{\etocthemaxlevel} should now be used in place of
    \etocsetlevel{foo}{6} when one wants to make foo entries invisible
    in a document context which may have used, or not, the `deeplevels'
    option.

    The auto-selection-of-heading-by-local-tocs from 1.2 uses a macro
    \etocdivisionnameatlevel which will need most probably user
    adaptation with `deeplevels', as etoc can not know what are the
    standard names chosen by user, and how many deep levels were
    actually added.  So it opted to the choices done by the Doxygen
    project.  Check the etoc source code for this macro and redefine it
    appropriately.  Note though that this only matters if your documents
    has local TOCs located under division units at least as deep as
    subsubsection.

    Fix a 1.2 bug: using `six' as first argument of `\etocsetlevel'
    caused an internal control sequence to be redefined, with various
    strange potential aftereffects.

~1.2 [2023/03/01]^

    \locallistoffigures and \locallistoftables.

    MAKE SURE TO READ THE FRAMED TEXT IN THE DOCUMENTATION AT START OF
    SECTION 2 WHICH DESCRIBES THESE NEW COMMANDS.

    It is for time being required to pass options `lof', resp. `lot'
    at package loading time to activate these features.  Whether or
    not these features are enabled, etoc interferes in absolutely no
    way with \listoffigures and \listoftables and their respective
    auxiliary files.

    Boolean options (and utility \etocsetup) `maintoctotoc',
    `localtoctotoc', `localloftotoc', `locallottotoc', and
    `ouroboros'.  For above reasons, no `mainloftotoc' or
    `mainlottotoc'.  With `ouroboros=false` local TOCs whose heading
    has been added to the `.toc' file due to `localtoctotoc` will show
    deeper ones and the local `lists of' from their own level, but not
    themselves.

    Compatibility layer with `tocbibind'.  Thanks to Denis Bitouzé for
    feature request many years ago.  Sorry for the delay!

    New feature (and breaking change): local tables of contents
    in the default package configuration auto-adapt their titles
    to use the appropriate unnumbered division heading (for example
    a \subsection* if inside a \section).

    Formerly, it was intended one would use \etocsettocstyle (or
    higher level commands), else local TOCs were rendered using the
    same emulation of the document class as for the main TOC.  One can
    still require this document class emulation but then etoc tries at
    least to adapt to the division unit one level below \part (i.e.
    \chapter or \section).  E.g., for KOMA-script the option
    `leveldown' is used.  But this is not appropriate for deeper
    levels in general.

    Ultimate control of toc titling can still be achieved via
    \etocsettocstyle.  Many commands have been added to ease its
    usage.  It is also possible to customize the default behavior
    without \etocsettocstyle.

    Details of the user interface and produced output from these novel
    commands and options are susceptible to change.  Use at own risk.

    Bugfix: the emptiness check could fail for
    \localtableofcontentswithrelativedepth as it ignored tocdepth changes
    originating from inside the .toc file, contrarily to the actual
    typesetting (and behavior with other local tocs)

    Bugfix: the \tableofcontents\ref{foo} syntax caused a
    ``Missing number'' after \vpageref{foo} from package varioref
    in certain circumstances due to \r@foo having then acquired a
    value with an unexpected non-numerical first chunk.

    Breaking change: the \etocsavedsectiontocline et al. macros
    which raised a deprecation warning since 1.1a now use an
    error message.

    \expanded primitive is required. [reverted at 1.2a]

~1.1d (not released, part of 1.2)^

    Complete internal refactoring of the legacy core code behind
    the concept of ``start'' and ``finish'' parts for line styles.

    \etocifunknownlevelTF and \etoclevel abstract away some
    internals and may be useful for class or package authors.

    \etocsetlevel filters out forbidden keywords `all', `none' and
    others.  Its second argument can be an expression.

    \etocsetstyle checks and warns appropriately if the level is
    unknown to etoc or has a non-accepted numerical value.

    Extensive refactoring of the documentation.

~1.1c [2023/01/20]^

    Fix a brace removal bug in the construction of \etocname.  It
    remained without visible effects in documents using hyperref and
    default settings, thanks to the hyperlink wrapper, but e.g.
    \section{{\color{blue}Blue}} in a document not using hyperref,
    and not using etoc only in "compatibility mode", could cause a
    color leak in the table of contents.

    With the KOMA-script numberline toc feature, unnumbered entries in
    TOCs typeset via etoc user-defined or package provided line styles
    but using compatibility mode for the global display style were
    (knowingly) considered to be numbered with an empty number.  They
    are now considered by \etocifnumbered to be not numbered and the
    empty \etocnumber will carry no hyperlink.

    Fix a 1.1a regression in the context of KOMA-script unnumbered TOC
    entries: \etocthelinkedname could lose its hyperlink.

    Continue internal trimming of old code branches which became
    un-needed after the 1.1a refactoring.  Add relatively decent
    code comments to accompany the 1.1a-c refactoring.  Update
    warning messages to use more consistently LaTeX's templates.

~1.1b [2023/01/15]^

    Documentation fix, 1.1a forgot to mention the following change:
    \etocthelinkedname, \etocthelinkednumber, \etocthelinkedpage
    are now always hyperlinks independently of linktoc status.

~1.1a [2023/01/14]^

    This version brings no new functionality, despite the number bump.
    It implements a complete rewrite of old legacy core internals.
    Formerly, etoc waited for ~2hyperref. (if present) to have added
    hyperlinks via its patch to LaTeX's \contentsline.
    etoc examined the arguments of \l@section and other commands to extract
    hyperlinking information, if any.
    With this release etoc decides earlier according to
    ~2hyperref. linktoc status whether section names and page numbers
    should be hyperlinked, and adds links itself via \hyperlink.  etoc
    is thus now immune to the details of how ~2hyperref. patches the
    \contentsline command, which is not executed anymore.
    Overall, the code is greatly simplified.

    \etoclink now wraps its argument in an hyperlink even if
    ~2hyperref. is configured via
    linktoc=none.  Formerly no hyperlink was added then.

    Deprecation of \etocsavedsectiontocline and similarly named
    commands.  They are not needed as \l@section et al. are with this
    release left unmodified during the table of contents typesetting.

    ~LaTeX kernel from 2020-10-01 or later is required (to allow
    assuming the \contentsline entries in the TOC file always have
    four arguments). [reverted at 1.2a]

~1.09i [2022/11/21]^

   Fix bug showing when a document uses both \etocchecksemptiness and
   \etocsetlocaltop.toc: the start and finish parts of some levels were
   executed possibly causing extra printed output.

   More hyperlinking in the implementation part of the documentation.

~1.09h [2022/11/20]^

   Documentation improvements.  In particular, attached code snippets
   are now visible via their filenames in the page margins.  Also,
   command names are doubly hyperlinked: first half links to the devoted
   part of the user manual, second half links to the implementation part.

~1.09g [2022/11/17]^

   Compatibility hotfix with recent hyperref 7.00u of 2022-11-13.
   Thanks to Denis Bitouzé for signaling the breakage to the author.

~1.09f [2022/08/30]^

   No more shipping of a German translation of the documentation,
   as it was last updated in April 2015.

   (etoc.pdf) User level commands hyperlink from their code source definitions
   to their descriptions in the documentation part.  Macros used in the code
   source hyperlink to where they first got defined there.

   Wrap the \etocpartname (from etoc's package provided toc line style)
   together with the part number in a potential common hyperlink.

   Try to sync the emulation of the global display style with KOMA-script
   v3.37 (in particular regarding the noparskipfake KOMA toc feature).

   Improve documentation of some aspects under memoir class.

   Remove the \nonumberline token, even though empty, from the meaning of
   \etocthename (KOMA-script classes).

   Add \etocimmediatedepthtag.toc to work around problems related to
   \include (see user doc).  Thanks to Norman Ramsey who reported the problem
   and proposed a work-around in July 2016.  Apologies for the somewhat longish
   delay in incorporating it...

   Also add \etocimmediatesettocdepth.toc.

   Also add \etocimmediatetoccontentsline and its starred variant.

   Also add \etocimmediatesetlocaltop.toc.

   Fix an obscure bug (see source code comments) in the
   \etocsetlocaltop.toc mechanism.

~1.09e [2021/09/23]^

   Needed (if etoc is used without hyperref) updates to
   internal macros to prepare for the upcoming LaTeX November
   2021 change to \contentsline.

   Related updates to the user macro \etoctoccontentsline.

~1.09d [2021/07/13]^

   Some minor synching with tableof 1.4c.

   Add \etockeeporiginaltableofcontents to provide a work-around to a
   compatibility issue with listings's \lstlistoflistings, which abuses
   \tableofcontents for doing something unrelated to the actual contents.
   Thanks to Denis Bitouzé for report.

   Usage: \usepackage{etoc}\etockeeporiginal-tableofcontents, then
   however you must employ \etoctableofcontents, not \tableofcontents.

~1.09c [2020/05/15]^

   Syncs with KOMA-script deprecation of \iftocfeature.

~1.09b [2019/11/17]^~par~nobreak~vskip-~parskip~vskip-~baselineskip
~1.09a ^

   Sync with memoir v3.7i which has a better location of the TOC
   hyperref anchor. The \etocaftertitlehook can now freely be
   used also with memoir class (formerly its usage in case of
   memoir class was preempted by etoc itself). For more details
   refer to the section "Compatibility with the memoir class".

~1.09 [2019/03/09]^

   New features: \etoclocaltop, \localtableofcontentswithrelativedepth. Thanks
   to Tony Roberts for feature request.

   Note to hackers: internal control sequence \Etoc@localtop is gone.

   etoc now requires e-TeX (\numexpr, \unless).

~1.08p [2018/07/04]^

   Fixed bug surfacing in case of linktoc=page option of hyperref.
   Thanks to Denis Bitouzé for report. Cf:~\
   https://github.com/ho-tex/hyperref/issues/65~\
   https://github.com/dbitouze/yathesis/issues/61

~1.08o [2018/06/15]^

   Fixed bug showing up if an unnumbered TOC entry starts with a brace,
   and document uses hyperref. Caused by a typo in a macro name at
   previous release.


~1.08n [2018/02/23]^

   Refactoring of core macros detecting \numberline and its variants.


~1.08m [2018/02/07]^

   Fix to 1.08k's introduced incompatibility with KOMA-script
   and tocbasic's \nonumberline.


~1.08l [2017/10/23]^

   Workaround an issue with Emacs/AUCTeX wrongly reporting about
   actually non-existent LaTeX errors, which was triggered by some
   strings written (indirectly) to log file by etoc under some
   circumstances.


~1.08k [2017/09/28]^

   Adds \etocsetlocaltop.toc. See corresponding manual section for
   details.

   Adds \etocsavedparttocline, \etocsavedchaptertocline,
   \etocsavedsectiontocline, ... They can be used in the context of
   the technique explained in section "Another compatibility mode".

   Formerly, etoc redefined for the duration of the TOC the memoir
   macro \chapternumberline and its likes to have same meaning as
   \numberline (of course, not when executed in compatibility mode),
   for the sake of extraction of \etocnumber.

   New method detects presence of any \<foo>numberline macro without
   any change to originals; they can thus be used as is when applying
   the approach of "Another compatibility mode" section from manual.


~1.08j [2017/09/21]^

   Since 1.08a-2015/03/13 \etocname, \etocnumber, \etocpage
   contain, if hyperref is present and configured for using
   hyperlinks in the TOC, the link destination in already expanded
   form. This means one can use them even if the style closes a
   group (for example from a & in a tabular), if \etocglobaldefs
   was issued; also one can save their meaning for delayed usage
   (with for example \LetLtxMacro as they are robust).

   But for some legacy reason \etoclink, contrarily to
   \etocthelink, was handled differently. Now, \etoclink also
   contains the link destination in already expanded form, and can
   thus be used even if the line style issues a &, as long as
   \etocglobaldefs is issued.

   Also, bugs dating back to the early days of the package, but
   surfacing only under relatively rare conditions such as usage
   of hyperref with its option "linktoc=page" got fixed.


~1.08i [2016/09/29]^

   This fixes an issue dating back to 1.08e-2015/04/17: under
   \etocchecksemptiness regime, some circumstances (such as
   adding to an already compiled document a \localtableofcontents
   before the main \tableofcontents) created an "Undefined
   control sequence \Etoc@localtop" error. Thanks to Denis Bitouzé
   for reporting the problem.

   On this occasion, \etocdoesnotcheckemptiness
   has been added to unset the flag.

   A rather more exotic issue was fixed: the emptiness check for
   local tocs could get confused if the tocdepth counter was varying
   in some specific ways from inside the toc file.

   After adding to a document a \localtableofcontents, two LaTeX
   passes are needed for etoc to get a chance to print the
   correct local contents. Formerly, etoc issued a Warning on
   the first pass; it now also induces LaTeX into
   announcing "There were undefined references", as this is nearer
   to the end of the log file and console output.


~1.08h [2016/09/25]^

   New functioning of \etocsetnexttocdepth: the tocdepth counter is
   modified only at the time of the table of contents, not before.
   This fixes an issue which arose when \etocsetnexttocdepth was
   used multiple times with no intervening table of contents.
   Thanks to Denis Bitouzé for reporting the problem.

   The PDF documentation includes about 25 LaTeX code snippets also
   as file attachment annotations, additionally to their verbatim
   typesetting. The ordering of the documentation contents has been
   slightly re-organized.

   A previous documentation-only update on 2016/09/09 added a new
   section with the (approximate) translation into etoc lingua of the
   book class toc style, for easy customizability.


~1.08g [2015/08/29]^

   Downgraded to a mere info message the etoc-issued warning
   (relative to \settocdepth/\maxtocdepth) under class memoir.


~1.08f [2015/04/28]^

   Minor changes to the documentation. \etocsetlevel more economical.


~1.08e [2015/04/17]^

   The command \etocchecksemptiness tells etoc to not print, from
   that point on, the headings of the local tables of contents if
   they have empty contents. This is mainly for class authors who
   might want to have their \section or \chapter automatically do
   a \localtableofcontents. Could prove also useful for batch
   conversions of documents. Thanks to Paul Gaborit who asked for
   such a feature.

   The command \etocnotocifnotoc extends this behaviour to global
   TOCs: indeed why should documents with no sectioning units take
   this as an excuse not to use package etoc ?

   The command \etocifwasempty{yes}{no} can be used for
   suitable extra action.

   A \tableofcontents\ref{foo} now expects foo to be a label to a
   _local_ TOC. The use with foo a label to a _global_ TOC is not
   supported anymore as it had no utility and made the code more
   complex.

   The syntax \localtableofcontents\ref{foo} is now accepted as a
   synonym to the earlier syntax \tableofcontents\ref{foo}.


~1.08d [2015/04/09]^

   Translation into German of the additions made to the documentation
   for the 1.08x series of releases.

   Thanks to Christine Römer!


~1.08c [2015/03/30]^

   - removed a few unneeded \long from the code.

   - removed use of \arabic at one location of the code, as it may get
  redefined by some language modules for babel or polyglossia.


~1.08b [2015/03/18]^

   Bug fixes:

   - extra space token removed from `\localtableofcontents` (showed
   only for inline TOCs.)

   - \etocpartname (a macro used by the package own default line
   styles) was defined to be \partname, but this is not compatible
   at least with babel+french context. Now simply expands to Part.

   - some problems fixed in the German documentation.

   - [2015/03/28] some more problems fixed in the documentation. Added
   mention of \etocarticlestyle and \etocbookstyle.


~1.08a [2015/03/13]^

   \etocname, \etocnumber and \etocpage are now the robust
   variants of \etocthelinkedname, \etocthelinkednumber and
   \etocthelinkedpage. This should arguably have been done since
   the addition of the latter to etoc with 1.07f [2013/03/07].
   The earlier robust commands \etocname etc... contained
   the hyperlink destination only in an unexpanded form.

   The documentation has a brand new title page and a new section
   The TOC as a TikZ mind map both illustrating further uses of
   etoc to display tables of contents as trees in an automatic
   manner.


~1.08 [2015/03/10]^

   \etocskipfirstprefix may now appear anywhere in the <start>
   part of a level style.

   New commands \etociffirst, \etocxiffirst, \etocxifnumbered,
   \etocglobaldefs and \etoclocaldefs.

   It is now possible to issue line style specifications directly
   with & and \\ tokens, in order to typeset a TOC as a tabular
   or longtable with the opening for example in the first
   argument of \etocsettocstyle and the closing in its second
   argument.

   It is mandatory for such uses to issue \etocglobaldefs which
   tells etoc to proceed globally for certain definitions. This
   is also useful in the context of the inline environments of
   package enumitem.

   On this occasion, various old parts of the code have been
   improved.


~1.07n [2015/03/05]^

   No more use of \toks@ when etoc constructs \etocthelinkedname
   etc... Thus \toks@ can be put in the line styles in order to
   accumulate information. Only useful if it is certain nothing
   else will change \toks@ either.

   In the documentation: list of main commands now in alphabetic
   order.


~1.07m [2015/01/23]^

   Reading of .toc file is delayed to \begin{document} to account for
   possible Babel active characters used therein. Thanks to Denis
   Bitouzé who reported a Babel related problem.

   Improved global toc display emulation under KOMA-script classes.

   New command \etocbeforetitlehook. New command \etocdisplay.


~1.07l [doc of 2014/04/29]^

   Added to the documentation an example of use of \etocthelinkedname together
   with an enumitem inline itemize* environment; moved main TOC to immediately
   after the title, and license to the first pages.

   Incorporation of the translation into German done on the initiative of
   $[Christine Römer] by $[Felix Baral-Weber, Jenny Rothkrämer-Vogt, Daniel
   Büttner, Claudia Dahl, Christian Otto and Christine Römer (FSU Jena).] My
   grateful thanks to all!


~vskip~baselineskip1.07l [2014/04/22]^

   Fixes a bug with the 1.07k compatibility layer with tocloft which had broken
   the 1.07k (sic) compatibility with memoir (yes, memoir class 1.07k testing
   had been done before adding the tocloft thing to the source code . . . ).
   Also, etoc when detecting tocvsec2 now checks if this is under the memoir
   class, as then nothing special needs to be done to rescue \tableofcontents,
   contrarily to the situation with the native tocvsec2.


~1.07k [2014/03/06]^

   Compatibility with package tocloft; and improved compatibility with
   class memoir. Novel TOC example in Overview.


~1.07j [2013/12/03]^

   Some issues with the documentation formatting (now two-sided) have been
   addressed, and a novel documentation section ``Typesetting the TOC as a
   table'' has been added. Very minor code change (\Etoc@readtoc).


~1.07i [2013/10/21]^

   Changes to the \etocmulticolstyle and \etocruledstyle codes
   to lessen the risk of a page break after the title (in the one-column case).


~1.07h [2013/10/16]^

   New commands \etocdepthtag.toc, \etocsettagdepth, \etocobeydepthtags,
   \etocignoredepthtags.


~1.07g [2013/10/13]^

   New commands \etocsettocdepth, \etocsettocdepth.toc,
   \etocobeytoctocdepth, \etoc~-ignoretoctocdepth which
   emulate part of tocvsec2 functionality ; measures to
   make tocvsec2 partially compatible with etoc.

   New commands \etocsetnexttocdepth, \invisibletableofcontents,
   \invisiblelocaltableofcontents.

   Switched from tikz-qtree to forest for the first `toc as
   tree' example.

   Command names are linked to their descriptions, and many
   other changes in the documentation.

   Removed printing of temporary message when the local toc
   id is not yet stabilized; indeed \localtableofcontents
   can have many uses, such as filling up some token list
   register and one may wish to not have anything typeset,
   even in an intermediate run.

   All of tex etoc.dtx, etex etoc.dtx, xetex etoc.dtx, latex
   etoc.dtx, pdflatex etoc.dtx are now possible, and the
   extracted file etoc.tex allows easy customization of
   compilation options for the documentation (default is via
   dvipdfmx which produces the smallest file).


~1.07f [2013/03/07]^

   New macros \etocthelinkedname, \etocthelinkednumber,
   \etocthelinkedpage, and \etocthelink.


~1.07e [2013/03/01]^

   Improvements in the package own line styles with
   regards to penalties and vertical spaces.

   Addition to the documentation of an example of
   a tree-like table of contents (uses tikz).

   More such examples added 2013/03/03.


~1.07d [2013/02/24]^

   Minor code improvements and new documentation
   section ``Another compatibility mode''.


~1.07b [2013/02/02]^

   Removal of the \xspace from the macros \etocname,
   \etocnumber, \etocpage.

   Additional examples in the documentation.


~1.07 [2013/01/29]^

   New commands:

      \etocthename, \etocthenumber, \etocthe~-page, \etoclink,

      \etoctoccontentsline, \etoctoccontentsline~lowast

      \etocnopar, \etocaftercontentshook

   Modified command: \etocmulticolstyle

   New documentation section ``Surprising uses of etoc'' which
   explains how to do  ``Lists of arbitrary things'', in
   addition to the tables of contents.


~1.06 [2012/12/07]^

   The standard macros \l@section etc... are modified only
   during the calls to \tableofcontents; they can thus be
   customized as will by the user (with the help of a
   package like tocloft) and this will be taken into account
   by etoc for the TOCs typeset in compatibility mode.


~1.05 [2012/12/01]^

   \localtableofcontents replaces \tableofcontents~lowast (for
   compatibility with the memoir class).

   Compatibility with KOMA-script and memoir document
   classes.


~1.04 [2012/11/24]^

   A (possibly local) table of contents can be labeled:

       \tableofcontents \label{toc:1}

   and reproduced elsewhere in the document (with a possibly
   completely different layout):

       \tableofcontents \ref{toc:1}


~1.02 [2012/11/18]^

   Initial version.

\end{jfverbatim}
\end{multicols}
\endgroup  % group for modified verbatim printing of the changes log

\makeatletter
    \let\check@percent\original@check@percent
\makeatother

\small

% Que c'est pénible cette syntaxe \markboth/\markright de LaTeX !
% Pourquoi est-ce que \markright n'a pas été définie comme #1#2-> truc avec #2 ??
\makeatletter
\if@twoside
\renewcommand *{\sectionmark }[1]{%
  \markboth
         {\unexpanded{{%
% counteract some changes done by my macrocode hooks
% so we must make sure it is in a scope limiting context
% (perhaps it is already, will not check, wasted already
% too much time on this header matter) November 2022
          \hypersetup{linkcolor=RoyalBlue}%
          \ifodd\value{page}(\hyperref[changelog]{change log},
                                         \hyperlink{FRONTPAGE}{user manual
                                           front page})\hfill\fi
          \hyperref[imp]{\thesection. Implementation}%
          \ifodd\value{page}\else\hfill(\hyperref[changelog]{change log},
                                        \hyperlink{FRONTPAGE}{user manual
                                          front page})\fi
          }}%
         }
         {\unexpanded{{%
          \hypersetup{linkcolor=RoyalBlue}%
          \ifodd\value{page}(\hyperref[changelog]{change log},
                                         \hyperlink{FRONTPAGE}{user manual
                                           front page})\hfill\fi
          \hyperref[imp]{\thesection. Implementation}%
          \ifodd\value{page}\else\hfill(\hyperref[changelog]{change log},
                                        \hyperlink{FRONTPAGE}{user manual
                                          front page})\fi
           }}%
          }%
}
\else
% faudrait cependant que je réfléchisse à quoi faire exactement en oneside
% mais comme ceci ne peut arriver que si quelqu'un customise etoc.tex
% ce qui n'arrivera JAMAIS, je laisse tomber
\renewcommand *{\sectionmark }[1]{%
  \markright
         {\unexpanded{{%
          \hypersetup{linkcolor=RoyalBlue}%
          \ifodd\value{page}(\hyperref[changelog]{change log},
                                         \hyperlink{FRONTPAGE}{user manual
                                           front page})\hfill\fi
          \hyperref[imp]{\thesection. Implementation}%
          \ifodd\value{page}\else\hfill(\hyperref[changelog]{change log},
                                        \hyperlink{FRONTPAGE}{user manual
                                          front page})\fi
          }}%
         }%
}
\fi
\makeatother

\section{Implementation}\label{imp}

% ce \noindent est obsolète 2022/08/26 à cause des hooks à macrocode plus bas
% transférés depuis xint.dtx.  Il est doublement obsolète car je rajoute un
% paragraphe de texte de toute façon avant le premier macrocode.
% \indent % !!!!!!!!!!!!!!!!! Lundi 09 mars 2015 à 09:32:22
% il faut faire un paragraphe après \section sinon pas d'espacement
% vertical en sortie de blocs macrocode. Pas évident à trouver, vu que
% je customisais différentes choses qui pouvaient affecter macrocode.

% 9 mars 2015
% Pour rappel on avait dans le préambule:
% \def\MacroFont{\ttfamily\small\hyphenchar\font45 \baselineskip11pt\relax}
% 28 février 2023
% Mis à jour
% \def\MacroFont{\ttfamily\hyphenchar\font45\relax\setstretch{1}}
% ce qui donne donc le \macro@font qui sera utilisé.
% J'ai déjà fait \setstretch{1} au déput de la partie The code, donc
% je peux le supprimer ici
\def\macro@font{\ttfamily\hyphenchar\font45\relax}

% 26 septembre 2021
\catcode1 14 % pour pouvoir utiliser ^^A, car je l'avais mis à \active

\StopEventually{\normalsize
  \ifnum\NoSourceCode=1
     \texttt{\parindent 0pt\rightskip 1cm minus 1cm
     This documentation has been compiled without inclusion of the source
     code. To produce the documentation with source code included:\endgraf
     \ \ \ \ run etex on etoc.dtx to produce etoc.tex,\endgraf
     \ \ \ \ then thrice pdflatex on etoc.tex.\endgraf
}%
  \fi
\end{document}}

%%%%%%%%%%%%
% 26 août 2022, transfert depuis xint de hack de doc
%
% This worked remarkably well with almost no changes! Particularly for
% hyperlinking to the documentation part from the macro definitions! But
% also for internall cross-links in implementation part despite no usage
% there of any sectioning mark-up (so I don't need the \@sect hack, and
% related \csa, \csan, \csh, \cshn, \cshintitle, \cshnintitle macros).
% I noticed in passing that I never used any \begin{macro} mark-up here
% in the etoc.dtx. Perhaps I should and should one day look at what doc=V3
% brings...
%
% See xint.dtx for comments, as I have removed most when copying.
\makeatletter
\def\odef #1{\expandafter\def\expandafter#1\expandafter}% needed from xintkernel

%%% xint.dtx does \def\macro@font {\ttfamily }% (with a font allowing hyphenation)
%%% Our \macro@font has been defined earlier from \MacroFont in preamble and
%%% is \ttfamily\small\hyphenchar\font45 \baselineskip11pt\relax
%%% etoc.dtx: see further below for how the * is handled in \macro@finish
\renewcommand\lowast{{\iflabelmacro@allowed\xintdocMacrocodeFallbackColorCmd\fi
                      \raisebox{-.25\height}{*}}}
\AddToHook{env/macrocode/begin}{\makestarlowast}
% https://github.com/latex3/latex2e/issues/563
% (but I don't use sectioning commands in implementation part of etoc.dtx so far)
\AddToHook{env/macrocode/after}{\@nobreakfalse}
\AddToHook{env/macrocode/begin}{\partopsep0pt\relax}
\begingroup
\catcode`\|=\z@ \catcode`\[=\@ne \catcode`\]=\tw@
\catcode`\{=12 \catcode`\}=12
% Let % be active to use a color for it and gray-out
% comments left in code (there are few)
\catcode`\%=13 \catcode`\ =\active \catcode`\\=\active
|gdef|xmacro@code#1%    \end{macrocode}[#1|end[macrocode]]
|endgroup
%%% 2022/08/27: for etoc.dtx try to really use comment color in comments
%%%             this is not a complete solution, but enough for use case
\begingroup\catcode`\%=\active\catcode`\^^M 13
\gdef%{\begingroup\color{macrocodecommentcolor}^^A
                  \let\xintdocMacrocodeFallbackColorCmd\@empty^^A
       \@percentchar\odef
{\expandafter\endgroup
}}\endgroup
\begingroup\let\newcount\@gobble\@definecounter{CodelineNo}\endgroup
\def\theCodelineNo{\reset@font\scriptsize\arabic{CodelineNo}}
\def\theHCodelineNo{\the\value{section}.\the\value{CodelineNo}}
%%% not needed for etoc.dtx
%%%%%%% attention j'utilise plus bas \MakePrivateLetters pour
%%%%%%% problème de straight quotes depuis 2023/01/18 (1.1c)
%%% \def\xintMakePrivateLetters{\catcode`: 11 \catcode`? 11 \catcode`@ 11
%%%                             \catcode`^ 11 \catcode`_ 11 }
%%% \def\xintexprMakePrivateLetters{\xintMakePrivateLetters \catcode`! 11 }
%%% \let\MakePrivateLetters\xintMakePrivateLetters
% \definecolor{etocnamecolor}{RGB}{228,57,0}
% \colorlet{verbcolor}{Maroon}
%
% \colorlet{privatecommentcolor}{cyan}
% \colorlet{macrocodecommentcolor}{gray}
% \colorlet{macrocodenewmacrocolor}{verbcolor}
% \colorlet{macrocodelinktouserdoccolor}{etocnamecolor}% and bold face
% \colorlet{macrocodelinktosectioncolor}{DarkBlue}% and bold face
% \colorlet{macrocodelinktocodelinecolor}{DarkBlue}
% \colorlet{macrocodenoncscolor}{Green}
\def\xintdocMacrocodeFallbackColorCmd{\normalcolor}
\odef\init@crossref{\init@crossref%
     \everypar{\refstepcounter{CodelineNo}%
               \llap{{\xintdocMacrocodeFallbackColorCmd\theCodelineNo}\
                      \hskip\@totalleftmargin}%
               }%
     \catcode`\%\active
}%
\def\scan@macro{%
   % we do not insert it yet
   % \special@escape@char
   \step@checksum
%   \ifscan@allowed
      \let\macro@namepart\@empty
      % we need this for reasons explained below
      \let\macro@spacepart\@empty
      \def\next{\futurelet\next\macro@switch}%
%   \else \let\next\@empty \fi
   \next
}
% unchanged:
% \def\macro@switch{\ifcat\noexpand\next a%
%      \let\next\macro@name
%      \else \let\next\short@macro  \fi
%    \next}
\def\short@macro#1{\special@escape@char#1}
% \def\macro@name#1{\edef\macro@namepart{\macro@namepart#1}%
%      \futurelet\next\more@macroname}
% \def\more@macroname{\ifcat\noexpand\next a%
%      \let\next\macro@name
%      \else \let\next\macro@finish \fi
%      \next}
\def\more@macroname{\ifcat\noexpand\next a%
     \expandafter\macro@name
     % we keep the \next for usage later and start filtering out of the way spaces
     % this is caused by necessity of handling things such as \let<space>\foo\bar
     % but also not be fooled by \let<space>#6\macro
     \else \expandafter\macro@gatherspaces \fi
     }
\def\macro@gatherspaces{%
    \ifx\next\@xobeysp
        \expandafter\macro@gatherspaces@i
    \else
        \expandafter\macro@finish
    \fi}%
\def\macro@gatherspaces@i#1{%
    \odef\macro@spacepart{\macro@spacepart#1}% #1 = active space
    \futurelet\next\macro@gatherspaces}%
\newif\iflabelmacro@allowed
\newcounter{xintMacroCnt}
%%% pour l'instant pas relevant pour etoc, pas de mark-up par \subsection etc...
\def\xintimplabelprefix{src-}
\let\xintdoclabelprefix\empty
%%% next thing is used in xint.dtx in a hack of \@sect but we don't have so
%%% far sectioning mark-up in etoc.dtx implementation part
%%% \let\xintlabelprefix\xintimplabelprefix
\catcode`_ 11 \catcode`* 11
\def\macro@finish{%
  \iflabelmacro@allowed
   \expandafter\in@\expandafter{\expandafter.\macro@namepart,}%
   {.csname,.expandafter,.noexpand,.else,%
    %.t,.w,.x,.y,.z,.XINT_x,.XINT_y,%
    %.XINT_tmpa,.XINT_tmpb,.XINT_tmpc,.XINT_tmpd,.XINT_tmpe,% _ is letter here
    %.XINT_expr_defbin_b,.XINT_expr_defbin_c,.XINT_expr_defbin_d,%
    .empty,.space,.protect,}%
   \ifin@
     {\xintdocMacrocodeFallbackColorCmd\special@escape@char\macro@namepart}%
   \else
     \ifcsname alreadydefined-\macro@namepart\endcsname
       \hyperref[etocmacro-\macro@namepart]{\special@escape@char\macro@namepart}%
     \else
       % this will make a rather large number of macro names in the string pool...
       \global\expandafter\let\csname alreadydefined-\macro@namepart\endcsname\@empty
       \label{etocmacro-\macro@namepart}%
       \stepcounter{xintMacroCnt}%
       % try to link to a labeled reference in the user documentation (xint-all.pdf)
       \ifcsname r@\xintdoclabelprefix\macro@namepart\endcsname
          {\hypersetup{linkcolor=macrocodelinktouserdoccolor}%
           \hyperref[\xintdoclabelprefix\macro@namepart]%
                    {\textbf{\special@escape@char\macro@namepart}}}%
       \else
       % try to link to a labeled section in implementation part
       %% THIS BRANCH WILL NEVER BE USED IN etoc.dtx FROM ABSENCE OF
       %% ASSOCIATED MARK-UP
       \ifcsname r@\xintimplabelprefix\macro@namepart\endcsname
          {\hypersetup{linkcolor=macrocodelinktosectioncolor}%
           \hyperref[\xintimplabelprefix\macro@namepart]%
                    {\textbf{\special@escape@char\macro@namepart}}}%
       \else
          \textcolor{macrocodenewmacrocolor}{\textbf{\special@escape@char\macro@namepart}}%
       \fi\fi
     \fi
   \fi
   \labelmacro@allowedfalse
   \expandafter\in@\expandafter{\expandafter.\macro@namepart,}{.expandafter,}%
   \ifin@
      \ifx\next\scan@macro\labelmacro@allowedtrue\fi
   \fi
  \else % end of labelmacro@allowedtrue branch
%%% etoc.dtx adds complications to handle \newcommand*
    \if0\ifx\next\scan@macro0\else\ifx\next\lowast0\else1\fi\fi
      \expandafter\in@\expandafter{\expandafter.\macro@namepart,}%
                {.def,.edef,.let,.gdef,.xdef,%.odef,.oodef,.fdef,
                 .chardef,.newif,.newtoks,.newcommand,.DeclareRobustCommand,%
                 .newread,.newwrite,}%
      \ifin@\labelmacro@allowedtrue\fi
    \fi
    \ifcsname r@etocmacro-\macro@namepart\endcsname
      \hyperref[etocmacro-\macro@namepart]{\special@escape@char\macro@namepart}%
    \else
      {\xintdocMacrocodeFallbackColorCmd\special@escape@char\macro@namepart}%
    \fi
  \fi
  % \ifnot@excluded
  %    \edef\@tempa{\noexpand\SpecialIndex{\bslash\macro@namepart}}%
  %    \@tempa
  % \fi
  \macro@spacepart
}%
\catcode`_ 8 \catcode`* 11
%%% In order mainly to colorize #1, #2, etc... we do this rather
%%% non-economical thing of colorizing all of macrocode with
%%% the "non control sequence color", hence this means all
%%% control sequences will have their own color command...
%%% This is because when doing this in June 2022 for xint, I did
%%% not want to hack more doc.sty scanning process of tokens,
%%% but perhaps I should, it would be more economical.  Kept as is
%%% when transferring to etoc.dtx 2022/08/26
{\sbox0{\color{macrocodenoncscolor}\xdef\foo{\current@color}}}
\ifpdf
   \edef\xintdoc@macrocode@pushcolor
      {\pdfcolorstack\noexpand\@pdfcolorstack push{\foo}\relax}
   \def\xintdoc@macrocode@popcolor{\pdfcolorstack\@pdfcolorstack pop\relax}
\else
\ifxetex
   \edef\xintdoc@macrocode@pushcolor{\special{color push \foo}}
   \def\xintdoc@macrocode@popcolor{\special{color pop}}
\else
\ifnum\Withdvipdfmx=1
     \edef\xintdoc@macrocode@pushcolor{\special{color push \foo}}
     \def\xintdoc@macrocode@popcolor{\special{color pop}}
\fi\fi\fi
%%% 2022/08/26 \par added for etoc.dtx
\AddToHook{env/macrocode/before}{\xintdoc@macrocode@pushcolor\par}
\AddToHook{env/macrocode/end}{\xintdoc@macrocode@popcolor}
% let's use some more quiet color for links inside the code
\AddToHook{env/macrocode/begin}{\hypersetup{linkcolor=macrocodelinktocodelinecolor}}
% let code line numbers really be fully in the margin
\MacroIndent\z@

% 2023/02/22, 1.2 uses setspace
% 2023/02/27, I return to single line spacing finally
%\AddToHook{env/macrocode/before}{\vskip.5\baselineskip}

\makeatother

% 18 janvier 2023 fix d'un problème de guillements courbes et d'inutilité de upquote,
% import de mon code de lgrmath de novembre 2022
% useless with doc.sty as \verb, verbatim and macrocode do not use \@noligs
% \usepackage{upquote}
%
\begingroup
\catcode`\'\active\catcode`\`\active
\gdef\MakePrivateLetters{\makeatletter\def`{\textasciigrave}\def'{\textquotesingle}}
\endgroup
% https://github.com/latex3/latex2e/issues/953, for the record

% will be used in code comments
% I could re-define \csb, but perhaps better as the mark-up is not yet there
% when I define this to opt for a new name
\makeatletter
\DeclareRobustCommand\csbc[1]{{\hypersetup{linkcolor=macrocodelinktocodelinecolor}%
    \ifcsname r@etocmacro-#1\endcsname
       \hyperref[etocmacro-#1]{\ttfamily\hyphenchar\font45 \char`\\ #1}%
    \else
       % for .toc suffixed macros
       \ifcsname r@etocmacro-\xintTrimUnbraced{-4}{#1}\endcsname
          \hyperref[etocmacro-\xintTrimUnbraced{-4}{#1}]
                   {\ttfamily\hyphenchar\font45 \char`\\ #1}%
       \else
% red color was not enough for me to identify misspelled macro names
% but I should have a warning mechanism, the problem is how to
% have it activated only at right time?
          {\fboxsep-\fboxrule\color{Orchid}%
           %\fbox{\textcolor{red}{\ttfamily\hyphenchar\font45 \char`\\ #1}}%
           \fbox{\ttfamily\hyphenchar\font45 \char`\\ #1}%
          }%
% ah ok let's do this (2023/01/22, 1.2)
          \ifcsname r@etocmacro-etocname\endcsname
            \expanded{\noexpand\AtEndDocument
                       {\noexpand\PackageError{etoc}{Pas de référence à #1\on@line}%
                                                    {Corriger!}
                       }%
                     }%
          \fi
       \fi
    \fi }%
}
\makeatother

\setcounter{secnumdepth}{3}

\paragraph{About the syntax highlighting of the code:}
Control\normalmarginpar\marginpar{\footnotesize\rmfamily\itshape\RaggedRight
  The ``syntax highlighting'' was added at release \etocrelease{1.09f} of 2022/08/30.\par}
sequences are mostly hyperlinks.  When a user level command gets defined it
hyperlinks to the user documentation with bold face and
\textbf{\textcolor{macrocodelinktouserdoccolor}{using this colour}}.  Further
instances if they occur will use \textcolor{macrocodelinktocodelinecolor}{this
  colour} to link to their place of first definition inside the code lines.
Package macros with no user level documentation hyperlink to their first
place of definition in the code.
And such non-user level macros, at the location of
their first definitions will have their names displayed using bold face and
\textbf{\textcolor{macrocodenewmacrocolor}{this colour}} (it is not
an hyperlink then). Comments located \emph{inside} the code source (very little are
left at \etocrelease{1.1a}) have been configured
\textcolor{macrocodecommentcolor}{to be rendered in their own colour}, and
\textcolor{macrocodenoncscolor}{non commented-out and non-control sequences
  tokens use this colour}.  Other tokens use the fall-back normal colour.
A package macro mentioned in code comments also hyperlinks
to the location of its first definition  using
{\textcolor{macrocodelinktocodelinecolor}{this colour}}.

Known limitations:
\begin{enumerate}[nosep]
\item The location of first definition may be disappointing as it may be a
  provisory definition.
\item Macros such as \csbc{Etoc@next} are there for matters of code branching
  only, and the first encountered definition has no relevant significance.
\item Macros defined using |\csname...\endcsname| or alike constructs are not
  detected by the syntax highlighting automatization.  Apart from manual
  intervention, this appears complex to solve as moreover the macro name may be
  there indirectly as an argument such as |#1|.
%%%% This was caused by a ... 2013 oversight in my way of customizing txtt,
%%%% see in preamble near loading of txfonts... fixed 2023/01/18
%%%% \item Bold face has an increased character width, somewhat offsetting the
%%%%   codelines alignment.
\end{enumerate}

\paragraph{An apology:}
the code comments served mainly as a record for the author's benefit
of the historical evolution of the package and rarely as a description of what
the macros do.  At \etocrelease{1.1a} I have removed almost all code comments which had
accumulated as in a palimpsest.  As a result, very few comments actually
remain.  \etocrelease{1.1c} re-added comments to those parts of the code which
got refactored at and since \etocrelease{1.1a}, revigorating the palimpsest stratification.

\paragraph{About \etoc and the processing of \texttt{.toc} file data:}
\etoc,%
%
\normalmarginpar\marginpar{\footnotesize\rmfamily\itshape\RaggedRight
  This paragraph and the next were added very late in the history of the
  package, at \etocrelease{1.09h} and later.\par}
%
when not left in compatibility mode, hijacks the \csa{contentsline} expansion
so as to not execute \csa{l@chapter}, \csa{l@section} etc..., but rather to
parse the data and extract from it the \emph{name}, \emph{number}, and
\emph{page number}.
%
The \LaTeX{} |.toc| data
is \emph{not structured}, but contains already typesetting mark-up.
The
\etoc maneuvers to disentangle \emph{name} and \emph{number} are somewhat
fragile as they expect the |.toc| file to contain the
\csa{contentsline} arguments to be arranged in a certain manner.
Of course \etoc can be easily broken if changes happen to how data is stored
there. Things would have been much easier for \etoc in 2012 if the
\csa{contentsline} arguments had considered the section titles (aka
\emph{name} for \etoc) and their numbers (which are not numbers in the sense
of things with which \TeX\ can compute, in general) separately, each providing
an argument to \csa{contentsline}.  But some mix is prepared, which may depend
on the document class also, and besides usually handles \csa{part} levels very
differently.  Fortunately upstream changes happen rarely.%
%
\normalmarginpar\marginpar{\footnotesize\rmfamily\itshape\RaggedRight
  Prior to \etocrelease{1.1a}, \etoc aliased \csa{l@chapter},
  \csa{l@section}, etc... (at the time of TOC typesetting only)
  to its own \csbc{Etoc@lxyz} in order to leave time to
  \ctanpkg{hyperref} to add its mark-up.  Thus the disentangling
  of name from number
  was more complex than it is now.  With \etocrelease{1.1a}, \etoc
  leaves \csa{l@chapter} etc... unmodified (and unused) and
  only hijacks \csa{contentsline}.}
%

The other core part of \etoc present from day one of the package is that it
creates a tree-like structure of the sectioning levels present in the |.toc|
file.  But this is purely virtual, and handled via a notion of ``level'' and
\TeX\ conditionals.  It could be fun to implement officially such a tree
(where the children of a sectioning title are the sectioning levels at a
greater depth such as subsections versus a section).  Let us recall that
\LaTeX{} provides zero means to know from a subsection for example, what is
the title of the section containing it, or chapter, or part.  To do this one
has to create a really structured document which neither core \LaTeX{} nor the
main document classes do.  This remark was given for document body, but it
also applies to the |.toc| data.  But \etoc adds at least some kind of
follow-up to the successive encountered sectioning titles, and is thus able,
to ``on-the-fly'' add some kind of structure and follow the chaining of
levels.  Ultimately this is why the \csbc{etocsetstyle} offers \marg{start}
and \marg{finish} parts in additions to \marg{contents} (which I divided into
a \marg{prefix} and a \marg{contents}).  At some point one could imagine that
a really \emph{structured} document (in opposition to what core \LaTeX{} from
thirty years ago up to nowadays realizes) would store in the |.toc| data
directly a tree structure, where each node would have attributes name, number,
page number, completely separated from any typesetting.  Once this exists then
basically \etoc disappears.  In brief, once \etoc ideas will have permeated
the society, it will disappear as its was born only to palliate the absence of
real structure in the |.toc| file (which is sort of inherited from the absence
of real structure in a \LaTeX{} document body).

%  9 avril 2015 (1.08d) pour forcer indentation après macrocode
% par un effet particulier si avant macrocode un enumerate, inefficient,
% mais vraiment pas envie d'investiguer.
%
% l'esthétique est un peu douteuse mais je laisse ?

% non finalement je supprime

% \makeatletter
% \def\endmacrocode{%
%                  \ifpm@module \endgroup \pm@modulefalse \fi
%                  \everypar{}%
%                  \global\@inlabelfalse
%                  \endtrivlist\@endpefalse % <<-- ajouté
%                  \close@crossref}
% \makeatother


% This is obsolete as 1.09g of 2022/11/17 has removed this hack, also
% for colorizing reasons from 1.09n.
% November 2012
% I don't want to have to type at this location (far from the top of the
% file) explicitly the package version or version date, as it is
% inconvenient to have to remember to do this when updating the package.
% Also, I prefer not to add macros to the |.sty| file giving the package
% date, name, or version. So I extracted this from the real macrocode
% environment (leaving out the \init@crossref.)

% The catcode hackery next is to avoid to have <*package> to be listed
% in the commented source code...
% (c) 2012/11/19 jf burnol ;-)

\MakePercentIgnore

%
% \catcode`\<=0 \catcode`\>=11 \catcode`\*=11 \catcode`\/=11
% \let</none>\relax
% \def<*package>{\catcode`\<=12 \catcode`\>=12 \catcode`\*=12 \catcode`\/=12}
%
%</none>
%<*package>
% \etocrelease{1.1a} implements a radical change to legacy core internals for
% compatibility with some (future) \ctanpkg{hyperref} changes.  In order to
% facilitate this overhaul, it required \LaTeX{} 2020-10-01 for the fourth
% argument to \cs{contentsline} lines in the |.toc| file to be always present.
%
% At \etocrelease{1.2a}, this requirement has been lifted so that we
% re-incorporated compatibility with old \cs{contentsline} fetching 4 or only
% 3 arguments depending on presence or not of \ctanpkg{hyperref}.  Fortunately
% the code refactoring completed at \etocrelease{1.2} made this easier.
% Testing on ``old'' \LaTeX{} was limited to one single check on a TL2019
% install.
%
% Also \etocrelease{1.2} use \csa{expanded}, we now test for its existence and
% provide alternative code if it is not provided by the engine.
%
% TeXLive started producing \LaTeX{} format incorporating by default the
% \eTeX{} extensions I think twenty years ago with TL2003, so let's require at
% least the \LaTeX{} of December of 2003 (but its is no guarantee that it will
% actually be with engine providing \csa{ifdefined}, \csa{unless},
% \csa{numexpr} or \csa{unexpanded} or maybe others yet that we use).
%    \begin{macrocode}
\NeedsTeXFormat{LaTeX2e}[2003/12/01]
\ProvidesPackage{etoc}[2023/05/01 v1.2a Completely customisable TOCs (JFB)]
%    \end{macrocode}
% Gentle Info message in the log to mention no testing is done of current
% \etoc on old \LaTeX{} installations.
%    \begin{macrocode}
\newif\ifEtoc@oldLaTeX
\@ifl@t@r\fmtversion{2020/10/01}
  {}
  {\Etoc@oldLaTeXtrue
   \PackageInfo{etoc}{Old LaTeX (\fmtversion) detected!\MessageBreak
   Since 1.1a (2023/01/14), etoc prefers LaTeX at least\MessageBreak
   as recent as 2020-10-01, for reasons of the .toc file,\MessageBreak
   and used to require it (from 1.1a to 1.2).\MessageBreak
   This etoc (1.2a) does not *require* it, but has not been\MessageBreak
   tested thoroughly on old LaTeX (especially if document\MessageBreak
   does not use hyperref) and retrofitting was done only\MessageBreak
   on basis of author partial remembrances of old context.\MessageBreak
   Reported}}
%    \end{macrocode}
% \etocrelease{1.2} adds experimental support (only tested with standard
% classes and few packages) for \csbc{locallistoffigures} and
% \csbc{locallistoftables}.  Did I say this is experimental? When \LaTeX{}
% will have added official hook to \csa{addcontentsline}, I will probably
% revise the way \etoc hacks into it for this \emph{experimental}
% functionality.
%
% As it is \textbf{experimental}, I think we can all agree I don't have
% to spend too much space documenting it in user manual.  So I shall be
% brief when I will get to it.  And I will remain brief here too.
%
% Now that \etoc uses package options, I will use \ctanpkg{kvoptions} as I am
% familiar with it.  I understand upstream \LaTeX{} now has support for
% key-value input, put I simply have had no time to read the interface.
% Besides not sure it was there for the |2020-10-01| required release.
%    \begin{macrocode}
\RequirePackage{kvoptions}
\SetupKeyvalOptions{prefix=Etoc@}
\newif\ifEtoc@lof
\DeclareVoidOption{lof}{\Etoc@loftrue
  \PackageInfo{etoc}{Experimental support for \string\locallistoffigures.\MessageBreak
                     Barely tested, use at own risk}%
}
\newif\ifEtoc@lot
\DeclareVoidOption{lot}{\Etoc@lottrue
  \PackageInfo{etoc}{Experimental support for \string\locallistoftables.\MessageBreak
                     Barely tested, use at own risk}%
}
\@ifclassloaded{memoir}{
\PackageInfo{etoc}
   {As this is with memoir class, all `...totoc' options\MessageBreak
    are set true by default.  Reported}
\DeclareBoolOption[true]{maintoctotoc}
\DeclareBoolOption[true]{localtoctotoc}
\DeclareBoolOption[true]{localloftotoc}
\DeclareBoolOption[true]{locallottotoc}
}{
\DeclareBoolOption[false]{maintoctotoc}
\DeclareBoolOption[false]{localtoctotoc}
\DeclareBoolOption[false]{localloftotoc}
\DeclareBoolOption[false]{locallottotoc}
}
\DeclareBoolOption[true]{ouroboros}
%    \end{macrocode}
% The \etocoption{deeplevels} option added at \etocrelease{1.2a}.  Adapted
% from an intial patch contributed by Matthew Trescott in the context of
% the \href{https://github.com/doxygen/doxygen}{Doxygen} project.
% It sets the maximum level usable with \csbc{etocsetlevel} (and never
% displayed) at |12| rather than |6|.
%
% Such an extension of the number of levels handled by \etoc would have been
% much more cumbersome to achieve prior to the \etocrelease{1.2} refactoring
% which replaced usage of a booleans by a stack storage of the succession of
% levels seen in the |.toc| file (from which \etoc creates virtual nesting
% structure), which actually is completely scalable and can handle unlimited
% number of levels.  Basically we only needed to replace the formerly used
% \csa{Etoc@@six@@} by a \csbc{Etoc@maxlevel} set to have value |12| but this
% simple change caused also many modification to messages involved in
% \etoc-user interactions, and a disproportionate quantity of time passed on
% updating the documentation, even though in a minimal way, and of course a
% minimal amount of testing but \etoc is lacking a strong regression test
% suite which for lack of time has not yet been put into place.  As it is so
% simple we could do some option |maxlevel=<number>| but well, there is no
% real need, because the extra potential levels do not cause any overhead to
% the actual \etoc handling of tables of contents, so it is even tempting to
% adopt |12| (which is way beyond any realistic needs of a real document) as
% default, but this would break the documents in the wild which have used the
% advanced techniques based on hiding one or more levels via setting it at
% numerical depth |6|.
%    \begin{macrocode}
\DeclareBoolOption[false]{deeplevels}
\DeclareDefaultOption{\PackageWarning{etoc}{Option `\CurrentOption' is unknown.}}
\ProcessKeyvalOptions*
\DisableKeyvalOption[action=error,package=etoc]{etoc}{lof}
\DisableKeyvalOption[action=error,package=etoc]{etoc}{lot}
\DisableKeyvalOption[action=error,package=etoc]{etoc}{deeplevels}
%    \end{macrocode}
% The real verbosity problem of \LaTeX{} is not so much the log, which should
% actually be as detailed as possible (and the default \csa{errorcontexlines}
% setting of \LaTeX{} is to my view misguided), but the humongous output to
% console, most of it being perfectly useless in 99\% of cases.  Despite
% \csa{PackageInfo} adding stuff to the log only, I finally decided not to use
% this next hunk.
%    \begin{macrocode}
% \PackageInfo{etoc}{Status of options at loading time:\MessageBreak
%   lof = \ifEtoc@lof true\else false\fi\MessageBreak
%   lot = \ifEtoc@lot true\else false\fi\MessageBreak
%   maintototoc   = \ifEtoc@maintoctotoc true\else false\fi\MessageBreak
%   localtoctotoc = \ifEtoc@localtoctotoc true\else false\fi\MessageBreak
%   localloftotoc = \ifEtoc@localloftotoc true\else false\fi\MessageBreak
%   locallottotoc = \ifEtoc@locallottotoc true\else false\fi\MessageBreak
%   ouroboros     = \ifEtoc@ouroboros true\else false\fi\MessageBreak
%   deeplevels    = \ifEtoc@deeplevels true\else false\fi\@gobble
% }
%    \end{macrocode}
% For many many years \etoc had no options.  Let's be modern and provide an
% \csbc{etocsetup}.
%    \begin{macrocode}
\def\etocsetup#1{\setkeys{etoc}{#1}}
\def\etocifmaintoctotoc{\ifEtoc@maintoctotoc
                           \expandafter\@firstoftwo
                         \else
                           \expandafter\@secondoftwo
                         \fi}
\def\etociflocaltoctotoc{\ifEtoc@localtoctotoc
                           \expandafter\@firstoftwo
                         \else
                           \expandafter\@secondoftwo
                         \fi}
\def\etociflocalloftotoc{\ifEtoc@localloftotoc
                           \expandafter\@firstoftwo
                         \else
                           \expandafter\@secondoftwo
                         \fi}
\def\etociflocallottotoc{\ifEtoc@locallottotoc
                           \expandafter\@firstoftwo
                         \else
                           \expandafter\@secondoftwo
                         \fi}
\RequirePackage{multicol}
\def\etoc@{\etoc@}
\long\def\Etoc@gobtoetoc@ #1\etoc@{}
\newtoks\Etoc@toctoks
\def\Etoc@par{\par}
\def\etocinline{\def\Etoc@par{}}
\let\etocnopar\etocinline
\def\etocdisplay{\def\Etoc@par{\par}}
%    \end{macrocode}
% \csbc{etocglobaldefs} should be used only for special things such as TOC as
% a table; it should be put in a group to limit its scope. If used in the
% preamble, it must come \emph{after} \ctanpkg{tableof} if the latter is
% loaded too.
%    \begin{macrocode}
\let\Etoc@global\@empty
\def\etocglobaldefs{\let\Etoc@global\global\let\tof@global\global}
\def\etoclocaldefs {\let\Etoc@global\@empty\let\tof@global\@empty}
%    \end{macrocode}
% Some have been renamed at \etocrelease{1.2}.
%    \begin{macrocode}
\newif\ifEtoc@numbered
\newif\ifEtoc@hyperref
\newif\ifEtoc@parskip
\newif\ifEtoc@tocwithid
\newif\ifEtoc@standardlines
%    \end{macrocode}
% These next three added at \etocrelease{1.2}.  The latter two for handling
% compatibility layer with \ctanpkg{tocloft}
% and \ctanpkg{tocbibind}.\par^^A encore ce problème de ligne supp si plein!
%    \begin{macrocode}
\newif\ifEtoc@etocstyle
\newif\ifEtoc@classstyle
\newif\ifEtoc@keeporiginaltoc
\newif\ifEtoc@skipprefix
\newif\ifEtoc@isfirst
\newif\ifEtoc@localtoc
\newif\ifEtoc@skipthisone
\newif\ifEtoc@stoptoc
\newif\ifEtoc@notactive
\newif\ifEtoc@mustclosegroup
\newif\ifEtoc@isemptytoc
\newif\ifEtoc@checksemptiness
\def\etocchecksemptiness       {\Etoc@checksemptinesstrue }
\def\etocdoesnotcheckemptiness {\Etoc@checksemptinessfalse }
\newif\ifEtoc@notocifnotoc
\def\etocnotocifnotoc {\Etoc@checksemptinesstrue\Etoc@notocifnotoctrue }
\newcounter{etoc@tocid}
\def\Etoc@tocext{toc}
\def\Etoc@lofext{lof}
\def\Etoc@lotext{lot}
\let\Etoc@currext\Etoc@tocext
\def\etocifislocal{\ifEtoc@localtoc\expandafter\@firstoftwo\else
                                   \expandafter\@secondoftwo\fi
                  }
\def\etocifislocaltoc{\etocifislocal{\ifx\Etoc@currext\Etoc@tocext
                                     \expandafter\@firstoftwo\else
                                     \expandafter\@secondoftwo\fi}%
                                    {\@secondoftwo}%
                     }
\def\etocifislocallof{\etocifislocal{\ifx\Etoc@currext\Etoc@lofext
                                     \expandafter\@firstoftwo\else
                                     \expandafter\@secondoftwo\fi}%
                                    {\@secondoftwo}%
                     }
\def\etocifislocallot{\etocifislocal{\ifx\Etoc@currext\Etoc@lotext
                                     \expandafter\@firstoftwo\else
                                     \expandafter\@secondoftwo\fi}%
                                    {\@secondoftwo}%
                     }
%    \end{macrocode}
% Formerly a \LaTeX{} counter |etoc@tocdepth| was declared here but at
% \etocrelease{1.2} it has been replaced by macro storage.\par
%    \begin{macrocode}
\expandafter\def\csname Etoc@-3@@\endcsname {-\thr@@}
\expandafter\def\csname Etoc@-2@@\endcsname {-\tw@}
\expandafter\let\csname Etoc@-1@@\endcsname \m@ne
\expandafter\let\csname Etoc@0@@\endcsname  \z@
\expandafter\let\csname Etoc@1@@\endcsname  \@ne
\expandafter\let\csname Etoc@2@@\endcsname  \tw@
\expandafter\let\csname Etoc@3@@\endcsname  \thr@@
\expandafter\chardef\csname Etoc@4@@\endcsname  4
\expandafter\chardef\csname Etoc@5@@\endcsname  5
\expandafter\chardef\csname Etoc@6@@\endcsname  6
%    \end{macrocode}
% \etocoption{deeplevels} option needs a few extra declarations.
%    \begin{macrocode}
\ifEtoc@deeplevels
  \expandafter\chardef\csname Etoc@7@@\endcsname  7
  \expandafter\chardef\csname Etoc@8@@\endcsname  8
  \expandafter\chardef\csname Etoc@9@@\endcsname  9
  \expandafter\chardef\csname Etoc@10@@\endcsname  10
  \expandafter\chardef\csname Etoc@11@@\endcsname  11
  \expandafter\chardef\csname Etoc@12@@\endcsname  12
\fi
%    \end{macrocode}
% \etocrelease{1.2a} adds \csbc{Etoc@maxlevel} which replaces formerly
% used \csa{Etoc@@six@@}.   It adds also \csbc{etocthemaxlevel} as
% user interface to its explicit numerical value.
%    \begin{macrocode}
\expandafter\let\expandafter\Etoc@maxlevel
  \csname Etoc@\ifEtoc@deeplevels12\else6\fi @@\endcsname
\edef\etocthemaxlevel{\number\Etoc@maxlevel}
%    \end{macrocode}
% For \csbc{etocsetlevel}, \etocrelease{1.2a} uses a comparison with
% \csbc{Etoc@minf} so that only levels suitable for the document class can be
% used.  So \etoc now will not define unneeded `book' levelname with numerical
% level |-2| except if with \ctanpkg{memoir}.
%    \begin{macrocode}
\@ifclassloaded{memoir}{\def\Etoc@minf{-\thr@@}}{\def\Etoc@minf{-\tw@}}
\let\Etoc@none@@  \Etoc@minf
\expandafter\let\expandafter\Etoc@all@@
  \csname Etoc@\ifEtoc@deeplevels11\else5\fi @@\endcsname
%    \end{macrocode}
% \csa{Etoc@dolevels} will hold the names of all declared levels
% (independently of their numerical levels), in a traditional
% \LaTeX{} |\do| separated manner, except that for some reason
% I used \csa{Etoc@do}.  TODO: maybe use |\do|.
%    \begin{macrocode}
\let\Etoc@dolevels\@empty
\def\Etoc@newlevel #1{\expandafter\def\expandafter\Etoc@dolevels\expandafter
        {\Etoc@dolevels\Etoc@do{#1}}}
%    \end{macrocode}
% \etocrelease{1.2} has done some refactoring here (and above), reducing
% the number of definitions.  Formerly each defined sectioning level got two
% macros assigned to it: one holding the numerical level (as chardef or count,
% or even tokens for |-\tw@|), the other in a textual representation such as
% |minusone|.  The latter do not get defined anymore.
%
% MEMO: the legacy name space here is rather poor as anything can happen after
% \csa{Etoc@} with the sole and only characteristic that it terminates with
% |@@|.  So this means no package control sequence is allowed to end in |@@|
% else it is in risk of being overwritten, were it not for the special
% filtering done by \csbc{etocsetlevel}.  For matters of
% \csbc{etocsetnexttocdepth} allowing both name and numerical arguments, we
% employed the cheap device to define ourselves special levels named by
% explicit integers for internal usage, hence we need to filter them out here
% from being redefined.  We also filter out names starting with |@| for other
% reasons, but still it was not true at \etocrelease{1.2} that the package
% could safely use |\Etoc@@...@@| macros, as \csbc{etocsetlevel} creates since
% then also a |\Etoc@@|\meta{name}|@@|.  There was in particular a chardef
% \csa{Etoc@@six@@} hence if user chose ``|six|'' as level name
% \csa{Etoc@@six@@} acquired a new meaning and this could cause strange
% symptoms, the main one being the disappearance from TOCs of levels at same
% numerical depth than the one now given by the modified
% \csa{Etoc@@six@@}. (There was no \csa{Etoc@six@@} so the bug was really only
% one of \etocrelease{1.2} not of earlier releases).
%
% \etocrelease{1.2} adds here \csbc{etocifunknownlevelTF} and
% \csbc{etoclevel} for a higher level interface, which may be used by third
% parties such as the \ctanpkg{yathesis} class and will allow \etoc at some
% point to modify its internal naming conventions.
%
% The |-\tw@| case needed for \csbc{Etoc@minf} (or for \ctanpkg{memoir}) means
% that two expansions of \csbc{etoclevel} do not always deliver a single
% token, it is at any rate always self-delimiting in assignments and
% \csa{ifnum} tests.  I hesitated using only explicit digit tokens by the way.
%
% The dummy sectioning levels ``all'' and ``none'' play a special role and
% will be declared by \csbc{etocifunknownlevelTF} as ``known''.
%
% TODO: is it worthwile to still allow `7' to `12` as level ``names''? This is
% done here for perfact backward compatibility but they have to be excluded
% under \etocoption{deeplevels} option, and it would be better to do something
% not depending on whether that option is used or not.
%    \begin{macrocode}
\ifdefined\expanded
  \def\etocsetlevel#1#2{\expanded{\noexpand\etoc@setlevel{#1}{#2}}}%
\else
   \def\etocsetlevel#1#2{{\edef\Etoc@tmp{\noexpand\etoc@setlevel{#1}{#2}}\expandafter}\Etoc@tmp}%
\fi
\def\etoc@setlevel#1#2{%
   \edef\Etoc@tmp{\the\numexpr#2}%
   \if1\ifnum\Etoc@tmp>\Etoc@maxlevel0\fi\unless\ifnum\Etoc@minf<\Etoc@tmp;\fi1%
      \ifEtoc@deeplevels
        \in@{.#1,}{.none,.all,.figure,.table,.-3,.-2,.-1,.0,.1,.2,.3,.4,.5,.6,%
                                              .7,.8,.9,.10,.11,.12,}%
      \else
        \in@{.#1,}{.none,.all,.figure,.table,.-3,.-2,.-1,.0,.1,.2,.3,.4,.5,.6,}%
      \fi
%    \end{macrocode}
% Letter or other agnostic test.  First time I ever use \csa{@car} as I never
% paid attention to its existence and in more macro-coding intensive context
% such as \ctanpkg{xint} I use my own.
%    \begin{macrocode}
      \ifin@\else\if\@car#1\@nil @\in@true\fi\fi
      \ifin@
         \PackageWarning{etoc}
            {Sorry, but `#1' is forbidden as level name.\MessageBreak
             \if\@car#1\@nil @%
                (because of the @ as first character)\MessageBreak\fi
             Reported}%
      \else
        \etocifunknownlevelTF{#1}{\Etoc@newlevel{#1}}{}%
        \expandafter\let\csname Etoc@#1@@\expandafter\endcsname
                        \csname Etoc@\Etoc@tmp @@\endcsname
%    \end{macrocode}
% This is to allow ``to toc'' entries to not break the core mechanism
% used to let local tables of contents (now also lists of)
% know their scope, in case for example we have one after the other
% \csbc{localtableofcontents}, \csbc{locallistoffigures},
% \csbc{locallistoftables} and each has created its ``to toc'' entry:
% main TOC will handle the |@<division>| as aliases to |<division>| and local
% TOCs and Lists Of will ignore them.
%
% So we create |@<levelname>| as aliases to |<levelname>|.  This is really
% needed only for the level names actually involved by ``to toc'' thing, but
% let's do it systematically to avoid implementation complications.
%    \begin{macrocode}
        \expandafter\edef\csname Etoc@@#1@@\endcsname
                         {\expandafter\noexpand\csname Etoc@#1@@\endcsname}%
%    \end{macrocode}
% As ``to toc'' will use some \csa{addcontentsline}, we must make
% \ctanpkg{hyperref} happy and also define the suitable |toclevel@| prefixed
% extra macros.
%    \begin{macrocode}
        \expandafter\edef\csname toclevel@@#1\endcsname
                         {\expandafter\noexpand\csname toclevel@#1\endcsname}%
%    \end{macrocode}
% But we don't set \ctanpkg{hyperref}'s \csa{toclevel@\string#1} to be
% numerically \csa{Etoc@tmp}, with some hesitation.  The level defined by
% \csbc{etocsetlevel} should only be for interpretation by \etoc for the
% contents of the |.toc| file.  If it also influences how \ctanpkg{hyperref}
% hooks into \csa{section} and like commands influence the PDF bookmarks,
% unexpected results could follow.  It is up to user to set-up by themself
% possibly needed extra \ctanpkg{hyperref} configuration in this regard.
%    \begin{macrocode}
      \fi
   \else
      \PackageWarning{etoc}
         {Argument `\detokenize{#2}' of \string\etocsetlevel\space should
          represent one of\MessageBreak
          \ifnum\Etoc@minf=-\thr@@-2, \fi-1, 0, 1, 2, \ifEtoc@deeplevels ...\else3, 4\fi,
          \the\numexpr\Etoc@maxlevel-1, or \number\Etoc@maxlevel\space
          but evaluates to \Etoc@tmp.\MessageBreak
          The level of `#1' will be set to \number\Etoc@maxlevel.\MessageBreak
          Tables of contents will ignore `#1' as long\MessageBreak
          as its level is \number\Etoc@maxlevel\space (=\string\etocthemaxlevel).%
          \MessageBreak
          Reported}%
      \etocifunknownlevelTF{#1}{\Etoc@newlevel{#1}}{}%
      \expandafter\let\csname Etoc@#1@@\endcsname\Etoc@maxlevel
   \fi
}
%    \end{macrocode}
% Maybe let it first use \csbc{etocifunknownlevelTF} and raise in the
% ``unknown'' branch a suitable expandable error message (and return say |-3|)?
%
% I may also need for internal usage a variant for only numerical |#1| which be
% submitted to a \csa{the}\csa{numexpr}.  Not so far.
%
% Unfortunately the name ``level'' here does not convey to user the fact that
% the argument of \csbc{etocifunknownlevelTF} is a ``name'' not a numerical
% thing.
%    \begin{macrocode}
\def\etoclevel#1{\csname Etoc@#1@@\endcsname}
\def\etocthelevel#1{\number\csname Etoc@#1@@\endcsname}
\def\etocifunknownlevelTF#1{\@ifundefined{Etoc@#1@@}}
\@ifclassloaded{memoir}{\etocsetlevel{book}{-2}}{}
\etocsetlevel{part}{-1}
\etocsetlevel{chapter}{0}
\etocsetlevel{section}{1}
\etocsetlevel{subsection}{2}
\etocsetlevel{subsubsection}{3}
\etocsetlevel{paragraph}{4}
\etocsetlevel{subparagraph}{5}
%    \end{macrocode}
% Prior to \etocrelease{1.2}, only under class \ctanpkg{memoir} was
% \csbc{etocsetlevel} used with |appendix|.  It does not seem to hurt to do it
% generally, with a check whether document class provides chapters.
%    \begin{macrocode}
\ifdefined\c@chapter
  \etocsetlevel{appendix}{0}
\else
  \etocsetlevel{appendix}{1}
\fi
%    \end{macrocode}
% The ``to toc'' mechanism will add to the |.toc| file \csa{contentsline} entries
% with first argument such as |@section| or |@subsection|.  They will
% generally behave as |section|, resp. |subsection|, etc\dots\ This special
% mark-up is needed for ``to toc'' inclusions to not break the \etoc mechanism
% for delimiting the scope of local tables of contents.
%    \begin{macrocode}
\def\Etoc@do#1{\@namedef{l@@#1}{\csname l@#1\endcsname}}
\Etoc@dolevels
%    \end{macrocode}
% We do not issue \csbc{etocsetlevel}|{figure}{6}| (or |{12}|) as anyhow the
% \csbc{etocsetlevel} interface forbids |figure| and |table| as first
% argument.
%    \begin{macrocode}
\let\Etoc@figure@@\Etoc@maxlevel
\let\Etoc@table@@ \Etoc@maxlevel
%    \end{macrocode}
% \etocrelease{1.09g} adapts to \ctanpkg{hyperref} depending on whether the
% latter is at |7.00u| or earlier.  Indeed internal changes to
% \ctanpkg{hyperref} at |7.00u| broke \etoc.  Thanks to Denis~\textsc{Bitouzé}
% for reporting the issue.
%
% \etocrelease{1.1a} radically simplifies matters at \etoc core, and if these
% changes had been in place earlier there would have been no incompatibility
% with the \ctanpkg{hyperref} |7.00u| release.
%
% At \etocrelease{1.2a} we drop the \etocrelease{1.1a} requirement of \LaTeX
% from |2020-10-01| and must cater for \csa{contentsline} with 3 or 4
% arguments.  Fortunately, the code refactorings engaged at
% \etocrelease{1.1a} and completed at \etocrelease{1.2} made such a retro-fit
% relatively simple.  Let's hope nothing was overlooked, though.
%
% But we can not assume anymore \csa{@gobblethree} exists... hesitation here
% whether to use a \csbc{Etoc@gobblethree} or directly name it
% \csa{@gobblethree}.
%    \begin{macrocode}
\let\Etoc@gobblethreeorfour\@gobblefour
\ifdefined\@gobblethree
  \let\Etoc@gobblethree\@gobblethree
\else
  \long\def\Etoc@gobblethree#1#2#3{}%
\fi
\AtBeginDocument{%
\@ifpackageloaded{parskip}{\Etoc@parskiptrue}{}%
\@ifpackageloaded{hyperref}
    {\Etoc@hyperreftrue}
    {\ifEtoc@oldLaTeX
        \let\Etoc@gobblethreeorfour\Etoc@gobblethree
        \let\Etoc@etoccontentsline@fourargs\Etoc@etoccontentsline@
        \long\def\Etoc@etoccontentsline@#1#2#3{%
            \Etoc@etoccontentsline@fourargs{#1}{#2}{#3}{}%
        }%
     \fi
    }%
}
\def\etocskipfirstprefix {\global\Etoc@skipprefixtrue }
%    \end{macrocode}
% Start of heart of \etoc's hacks into the execution of the |.toc| file
% commands.  It goes via a redefinition of \csa{contentsline} which will
% launch an extraction process leading to the construction of \csbc{etocname},
% \csbc{etocnumber}, and \csbc{etocpage}, then the styles as defined by user
% via \csbc{etocsetstyle} get executed in accordance to the levels.
%
% In passing \etoc is witness to the linear succession of sectioning levels
% and executes the \marg{start} and \marg{finish} parts of each used level at
% the right time (they are rather called ``|begin|'' and ``|end|'' in the code
% though).
%
% \etocrelease{1.2} did a complete rewrite of how \etoc creates virtually a
% nesting structure out of the flat succession of the \csa{contentsline}'s for
% various levels.  Ever since the first release this was based on using
% boolean flags, one for each level.  The flag was on if the level had been
% seen, hence its ``begin'' macro executed, but not yet its ``end'' macro.
% This is now replaced by a stack storage \csbc{Etoc@stackofends} which is
% simply, e.g. |{2}{0}{-3}{}|, to mean that first a chapter (|0|) was seen
% then a subsection (|2|).  The |{-3}{}| trail is for matters of avoiding
% brace removal in the implementation next (I could have replaced it by a
% single token being numerically |-3|).  This structure made implementing the
% \etocoption{deeplevels} painless (but time-consumingly documented) at
% \etocrelease{1.2a}.
%
% When a new level is encountered and set in \csbc{Etoc@level}, it is compared
% to the left most entry in the stack.  If higher, the ``begin'' macro is
% executed and the \csbc{Etoc@level} is pushed (as a digit with possibly a
% minus sign) to the left of the stack to record that the ``end'' macro is now
% on the queue for execution (sic).  If equal, nothing has to be done, if
% lower, the ``end'' macro of the left-most stored level is executed then this
% level is removed, and one proceeds with the next one, etc... legacy code was
% using a bunch of TeX conditionals rather, and I recall how in 2012 I was
% unfamiliar with its strange syntax and had lots of troubles; once I got
% something working it got frozen and basically did not change since then.
% The \etocrelease{1.2} implementation has replaced all of this by
% maintenance of a single ``stack'', which is more economical in terms of
% used macros and potentially more scalable too.
%
% About \csbc{Etoc@level} I have hesitated using only digit and sign tokens,
% but it is currently let to some \csa{chardef} (in exceptional
% \ctanpkg{memoir} case of |book| level it can expand to |-\tw@|, and there is
% also the \csa{m@ne} count).  \etocrelease{1.2} thus keeps defining such
% \csa{chardef}'s but has at least dropped auxiliary macros (see the
% definitions prior to \csbc{etocsetlevel}) which held some alphabetical
% denotations such as ``minusone'' or ``zero'', and the \emph{begin},
% \emph{prefix}, \emph{content} and \emph{end} macros associated with each
% level now use a digit (and sign perhaps) (see \csbc{etocsetstyle}).  With
% \csbc{Etoc@level} already storing directly such a digit, one would avoid a
% \csa{number} or \csa{the}\csa{numexpr} at some places, but would have to be
% more careful in the various \csa{ifnum}.
%
% This (always globally defined) \csbc{Etoc@level} must now never be set to
% the numerical value \texttt{6} (or \texttt{12} if option
% \etocoption{deeplevels}): it is legal to add to the |.toc| file dummy
% sectioning levels associated to the maximal numerical level
% \csbc{etocthemaxlevel} (such dummy sectioning will be ignored but can be
% assigned locally a non-ignored level for special effects) and if
% \csbc{Etoc@level} was, as prior to \etocrelease{1.2}, systematically set to
% the numerical level of the last seen \csa{contentsline}, this could cause
% \csbc{Etoc@@startlocaltoc} to fail to correctly set the ``local top''.
% Indeed it now only has \csbc{Etoc@level} at his disposal, the legacy boolean
% flags being gone.
%
% The \csa{Etoc@isfirsttrue} was formally incorporated as last token of the
% ``begin'' macros as defined by \csbc{etocsetstyle}, but has been displaced
% by \etocrelease{1.2} to the code below.
%    \begin{macrocode}
\def\Etoc@updatestackofends#1\etoc@{\gdef\Etoc@stackofends{#1}}
\def\Etoc@stackofends{{-3}{}}
\def\Etoc@doendsandbegin{%
    \expandafter\Etoc@traversestackofends\Etoc@stackofends\etoc@
}
%    \end{macrocode}
% We compare the new level with those for which the \marg{start} parts of the
% \csbc{etocsetstyle} declarations have been executed to decide if it is time
% to execute their \marg{finish} parts.  In passing we set the boolean
% \csbc{ifEtoc@isfirst} which is needed for \csbc{etociffirst} and
% \csbc{etocxiffirst}.
%    \begin{macrocode}
\def\Etoc@traversestackofends#1{%
  \ifnum#1>\Etoc@level
    \csname Etoc@end@#1\endcsname
    \expandafter\Etoc@traversestackofends
  \else
    \Etoc@traversestackofends@done{#1}%
  \fi
}
\def\Etoc@traversestackofends@done#1#2{#2%
  \ifnum#1<\Etoc@level
    \csname Etoc@begin@\the\numexpr\Etoc@level\endcsname
    \Etoc@global\Etoc@isfirsttrue
    \edef\Etoc@tmp{{\the\numexpr\Etoc@level}}%
  \else
    \Etoc@global\Etoc@isfirstfalse
    \let\Etoc@tmp\@empty
  \fi
  \expandafter\Etoc@updatestackofends\Etoc@tmp{#1}%
}
%    \end{macrocode}
% Ever since the first release of \etoc, the code has to be careful that the
% |\Etoc@end@<level>| user defined macros may close groups. This is the reason
% why some assignments have to be done globally (|2015/03/08|).
%
% \etocrelease{1.1a} of |2023/01/14| implements a radical change to legacy
% core internals for compatibility with (attow future) \ctanpkg{hyperref}.
% Formerly \csbc{Etoc@etoccontentsline@} fetched only the first argument.  It
% now also fetches all four (the fourth argument of \csa{contentsline} is
% always present since \LaTeX{} |2020-10-01|).  The \csbc{Etoc@lxyz} used to
% receive only the two arguments (possibly hacked by \ctanpkg{hyperref}) of
% \csa{l@chapter}, \csa{l@section}, etc..., (these macros had been |\let| to
% \csbc{Etoc@lxyz}), and examined them to see if they were carrying
% hyperlinking data.  The \etocrelease{1.1a} and later version receives as
% third argument the fourth one of \csa{contentsline}, i.e.\@ the hyperlinking
% target, and adds the hyperlinking according to the status of
% \ctanpkg{hyperref}'s \csa{Hy@linktoc}.
%
% This is a breaking change if a user hacked \csa{contentsline} to do some
% specific pre-processing of the data, as this extra will now be ignored.  The
% kind of hack one can think of is perhaps to pre-process the section title to
% turn it into uppercase, this kind of things, but why do such things when one
% is using \etoc which precisely provides a general interface for such
% customization? Besides as the \LaTeX{} legacy set-up already mixes up in
% various ways name and number in the second argument of \csa{contentsline},
% doing such hacks in a non-breaking way was not easy, and could have broken
% \etoc easily anyhow.
%
% The major hacker was \ctanpkg{hyperref}...  Indeed in 2012 when I started
% work on \etoc, it was not clear to me how \ctanpkg{hyperref} would end up
% using the fourth argument of \csa{contentsline} and I did not want to spend
% too much time tracing hyperref code.  So I simply let \ctanpkg{hyperref} do
% its stuff, and added specific post-processing branches to unravel it.
% It looks quite dumb in retrospect (at this time the |.toc| file lines
% with \csa{contentsline} had either three or four arguments which contributed
% for the design decisions back then).
%
% All \ctanpkg{hyperref} specific branches are now gone, replaced by extra
% code added depending on the status of the \csbc{ifEtoc@hyperref} boolean.
% We also check the \csa{Hy@linktoc} \csa{chardef} status and, imitating
% \ctanpkg{hyperref}, do not hyperlink the page number argument if it turns out
% empty.  This maintains backwards-compatibility with earlier releases of
% \etoc.
%
% TODO: should this code ensure |#1| is actually a legit level name and if not
% issue some nice error message? This would add system-level overhead only for
% careless people who do not read docs...
%    \begin{macrocode}
\def\Etoc@etoccontentsline #1{%
  \let\Etoc@next\Etoc@gobblethreeorfour
  \ifnum\csname Etoc@#1@@\endcsname=\Etoc@maxlevel
  \else
   \Etoc@skipthisonefalse
%    \end{macrocode}
% MEMO: the mechanism added to make
% added toc entries from ``list of'' titles invisible to the local tocs,
% goes via such a |#1| starting with an |@|.  In that case \csa{Etoc@\string#1@@}
% is not a \csa{chardef} but expands to one (or to a count or |-\tw@| perhaps,
% or a |\numexpr...\relax|).
%    \begin{macrocode}
   \global\expandafter\let\expandafter\Etoc@level\csname Etoc@#1@@\endcsname
%    \end{macrocode}
% The trick goes through a slight overhead here to filter out such special
% ``|@|``-level names and not make them update what will serve as top level for
% local tocs or listsof.  Formerly this was managed by booleans, then for
% \etocrelease{1.1d} (released as \etocrelease{1.2}) it got replaced by
% sole usage of \csbc{Etoc@level}, and finally a specific
% \csbc{Etoc@virtualtop} which gets its updates here.
%    \begin{macrocode}
   \if @\@car#1\@nil\else\global\let\Etoc@virtualtop\Etoc@level\fi
   \ifEtoc@localtoc
    \ifEtoc@stoptoc
      \Etoc@skipthisonetrue
    \else
     \ifEtoc@notactive
       \Etoc@skipthisonetrue
     \else
      \unless\ifnum\Etoc@level>\etoclocaltop
        \Etoc@skipthisonetrue
        \global\Etoc@stoptoctrue
      \fi
     \fi
    \fi
   \fi
   \ifEtoc@skipthisone
   \else
    \unless\ifnum\Etoc@level>\c@tocdepth
     \ifEtoc@standardlines
         \let\Etoc@next\Etoc@savedcontentsline
     \else
         \let\Etoc@next\Etoc@etoccontentsline@
     \fi
    \fi
   \fi
  \fi
  \Etoc@next{#1}%
}
%    \end{macrocode}
% Hesitation at \etocrelease{1.2} about having \csbc{Etoc@level} being
% always explicit digit and perhaps negative sign.  For now is a
% \csa{chardef} or \csa{m@ne} \csa{count} (perhaps |-\tw@| also).
%    \begin{macrocode}
\def\Etoc@etoccontentsline@ #1#2#3#4{%
    \Etoc@doendsandbegin
    \Etoc@global\edef\Etoc@prefix  {\expandafter\noexpand
         \csname Etoc@prefix@\the\numexpr\Etoc@level\endcsname }%
    \Etoc@global\edef\Etoc@contents{\expandafter\noexpand
         \csname Etoc@contents@\the\numexpr\Etoc@level\endcsname }%
    \ifEtoc@skipprefix \Etoc@global\def\Etoc@prefix{\@empty}\fi
    \global\Etoc@skipprefixfalse
    \Etoc@lxyz{#2}{#3}{#4}%
    \Etoc@prefix
    \Etoc@contents
}
%    \end{macrocode}
% A \textbf{breaking change} is made at \etocrelease{1.1a}: \csbc{etoclink}
% will always create an hyperlink, even in case of \ctanpkg{hyperref} being
% (possibly locally) configured to obey |linktoc=none|.  Formerly, in such
% case, \csbc{etoclink} added no hyperlink because \etoc identified the
% hyperlink target from the \ctanpkg{hyperref} hacked arguments of
% \csa{l@section} et al, rather than picking it from the fourth argument of
% \csa{contentsline}.
%
% Another \textbf{breaking change} (documented only at \etocrelease{1.1b}):
% all three of \csbc{etocthelinkedname}, \csbc{etocthelinkednumber}, and
% \csbc{etocthelinkedpage} are always hyperlinks (for the latter, only if page
% number is not empty to match \ctanpkg{hyperref} ways).  Formerly they obeyed
% the |linktoc| status, somewhat counterintuitively, but this meant that
% \csbc{etocname} etc...  were their robust variants, which meant one could
% store easily for later usage (see the documentation examples with
% ``treetoks'') their precise meaning.  The breaking change happened in part
% because I was fooled myself by the macro names, and refactored the code in
% two steps separated by months so in second step I forgot I had only
% provisory code.  And I decided finally to keep the breaking change.
%
% Under |linktoc=page| option, \ctanpkg{hyperref} has a ``feature'' to add one
% level of bracing to first argument of the \csa{l@section} etc macros.  So
% for \etoc |<1.1a| this meant some extra work to dig into such a possible
% brace pair to check if the entry was numbered.  At \etocrelease{1.1a}, the
% \ctanpkg{hyperref} modified \csa{contentsline} is not executed, hence there
% is no such complication.  But the trimming of the now unneeded branches was
% not yet done at \etocrelease{1.1a}, \etocrelease{1.1b}, and got completed
% only at \etocrelease{1.1c}, together with some renamings and refactoring.
%    \begin{macrocode}
\def\Etoc@lxyz #1#2#3{%
    \ifEtoc@hyperref
       \Etoc@global\def\etocthelink##1{\hyperlink{#3}{##1}}%
    \else
       \Etoc@global\let\etocthelink\@firstofone
    \fi
    \Etoc@global\def\etocthepage {#2}%
%    \end{macrocode}
% Prior to \etocrelease{1.1a} an hyperlink was incorporated into
% \csbc{etocthelinkedpage} only if \ctanpkg{hyperref} added an hyperlink to
% the page number, i.e.\@ under |linktoc=page| or |linktoc=all| (and a non
% empty page number).  With \etocrelease{1.1a}, the hyperlink is always added
% (if a non empty page number).
%    \begin{macrocode}
    \ifEtoc@hyperref
       \ifx\etocthepage\@empty
         \Etoc@global\let\etocthelinkedpage\@empty
       \else
         \Etoc@global\def\etocthelinkedpage{\hyperlink {#3}{#2}}%
       \fi
    \else
       \Etoc@global\let\etocthelinkedpage\etocthepage
    \fi
%    \end{macrocode}
% Define \csbc{etocthename} but this will perhaps be adjusted later if it is
% found out that the entry was numbered.
%    \begin{macrocode}
    \Etoc@global\def\etocthename{#1}%
%    \end{macrocode}
% Now we check if the entry is numbered and disentangle the number from the
% name to define correctly \csbc{etocthename} and \csbc{etocthenumber}.  The
% delimiter tokens were modified at \etocrelease{1.1c} for a slight
% optimization.  And secondary macros have less to do since the
% \etocrelease{1.1a} initiated refactoring.
%    \begin{macrocode}
    \futurelet\Etoc@getnb@token\Etoc@@getnb #1\hspace\etoc@
%    \end{macrocode}
% Even if \csbc{etocthenumber} was let to \csa{@empty}, it may happen in
% special circumstances (related to KOMA-script, see below) that
% \csbc{etocthename} got redefined.  We will thus use its current contents to
% define appropriately \csbc{etocthelinkedname}.
%
% In presence of \ctanpkg{hyperref} we let always \csbc{etocthelinkedname} and
% \csbc{etocthelinkednumber} (for a numbered entry) carry an hyperlink.  This
% is a \textbf{breaking change} at \etocrelease{1.1a}: formerly if the TOC (or
% the specific entry in the |.toc| file, as it is always possibly to inject
% \csa{hypersetup}) was typeset under |linktoc=none| or |linktoc=page| status,
% then no hyperlinks were incorporated.  This is how \csbc{etocthename} and
% \csbc{etocthenumber} are configured, but \csbc{etocthelinkedname} and
% \csbc{etocthelinkednumber} will since \etocrelease{1.1a} always be
% hyperlinked in presence of \ctanpkg{hyperref}.
%    \begin{macrocode}
    \ifEtoc@hyperref
      \def\Etoc@tmp##1##2{\Etoc@global\def##2{\hyperlink{#3}{##1}}}%
      \expandafter\Etoc@tmp\expandafter{\etocthename}\etocthelinkedname
      \ifEtoc@numbered
         \expandafter\Etoc@tmp\expandafter{\etocthenumber}\etocthelinkednumber
      \else
         \Etoc@global\let\etocthelinkednumber\@empty
      \fi
    \else
      \Etoc@global\let\etocthelinkedname  \etocthename
      \Etoc@global\let\etocthelinkednumber\etocthenumber
    \fi
%    \end{macrocode}
% Defaults in absence of \ctanpkg{hyperref}.  We externalize to another
% macro the \ctanpkg{hyperref} case switch.
%    \begin{macrocode}
    \Etoc@global\expandafter\let\csname etoclink \endcsname  \etocthelink
    \Etoc@global\expandafter\let\csname etocname \endcsname  \etocthename
    \Etoc@global\expandafter\let\csname etocnumber \endcsname\etocthenumber
    \Etoc@global\expandafter\let\csname etocpage \endcsname  \etocthepage
    \ifEtoc@hyperref
      \Etoc@lxyz@linktoc
    \fi
}
%    \end{macrocode}
% In presence of \ctanpkg{hyperref}, \etoc \etocrelease{1.1a} imports the
% \ctanpkg{hyperref} own logic and tests \csa{Hy@linktoc} to decide if
% \emph{name}, \emph{number} and \emph{page} get hyperlinks.  This adds a
% dependency that \csa{Hy@linktoc} should exist and have the expected
% interpretation.
% \begin{shaded}
% \setstretch{1}%
% \textbf{MEMO:} \emph{Matters of tagging will have to wait for \LaTeX\ itself
% to show me what it does in \csa{l@section} etc... so that I can imitate.}
%
% Updated 2023/02/26: this is now partly available and gave me an idea of
% what will be needed here.  As the \etoc way goes through none of the
% \LaTeX{} hook points, I will have to add the suitable \csa{UseHook} at
% various places, after having stored the \csa{contentsline} original
% arguments in the same macros as the \LaTeX{} new kernel code will do.
%
% Some difficulties though in perspective as \etoc separates name and number
% and has no concept akin to \csa{@dottedtocline}.  Also if the user employs
% \csbc{etocsetstyle} with \csa{l@section}, hooks may be executed twice if I
% put them not in \csbc{etocname} but in the \marg{prefix} and \marg{content}
% parts for each level.\par
% \end{shaded}
%    \begin{macrocode}
\def\Etoc@lxyz@linktoc{%
    \ifcase\Hy@linktoc
        % none: nothing to do
    \or % section (aka name for etoc): link name and number
      \Etoc@global\expandafter\let\csname etocname   \endcsname\etocthelinkedname
      \Etoc@global\expandafter\let\csname etocnumber \endcsname\etocthelinkednumber
    \or % page
      \Etoc@global\expandafter\let\csname etocpage   \endcsname\etocthelinkedpage
    \else % all
      \Etoc@global\expandafter\let\csname etocname   \endcsname\etocthelinkedname
      \Etoc@global\expandafter\let\csname etocnumber \endcsname\etocthelinkednumber
      \Etoc@global\expandafter\let\csname etocpage   \endcsname\etocthelinkedpage
    \fi
}
%    \end{macrocode}
% Now for the disentangling of the ``number'' from the ``name''.
%
% At some point we will pick up the first token and check if it is
% \csa{numberline} or like token to identify a numbered entry.
% But this step can cause brace removal so we \csa{futurelet} to
% peek ahead.
%
% Prior to \etocrelease{1.1a} it could be possible that the first token following
% \csbc{Etoc@@getnb} was an opening brace and nevertheless the entry was
% numbered, because of a \ctanpkg{hyperref} ``feature'' in case of
% |linktoc=page| option.  But at \etocrelease{1.1a}, \etoc handles directly the argument
% of \csa{contentsline} so the presence of an opening brace implies the entry
% is not numbered.  For some reason \etocrelease{1.1a} kept the extra code to check in
% case the next token was an opening brace whether the whole entry was braced,
% which would have been indicative in the past (but not at \etocrelease{1.1a}) of a
% |linktoc=page| context (\etoc prior to \etocrelease{1.1a} never tested the value of
% \csa{Hy@linktoc} as it did not want to be dependent on details of
% \ctanpkg{hyperref} handling of options).  This legacy, now superfluous, code
% branch is removed at \etocrelease{1.1c}, bringing some simplification here, in
% particular the removal of an \csa{ifEtoc@bracedname} boolean.  Also, when
% branching from here to the \csbc{Etoc@getnb@nonbr}, we won't need to check
% if the entry had a special ``Part'' syntax, which is another simplification.
%
% The |@nonbr| means ``no number'', and is not to be misinterpreted as
% ``non braced''... (this was more confusing to the author on return to
% \etoc code, when it still had branches
% handling issues described above with an extra brace pair).
%    \begin{macrocode}
\def\Etoc@@getnb {%
    \let\Etoc@next\Etoc@getnb
    \ifx\Etoc@getnb@token\@sptoken\let\Etoc@next\Etoc@getnb@nonbr\fi
    \ifx\Etoc@getnb@token\bgroup  \let\Etoc@next\Etoc@getnb@nonbr\fi
    \Etoc@next
}
%    \end{macrocode}
% \etocrelease{1.08n} tries to handle reasonably the \csa{nonumberline} of
% \ctanpkg{KOMA-script}.  If it expands to |\numberline{}|, \etoc will
% consider the line numbered with an empty number (afaict, the meaning of
% \csa{nonumberline} is either empty or \csa{numberline}|{}|).  This got
% modified at \etocrelease{1.1c} (see below).
%
% At \etocrelease{1.09f} we get rid of the \csa{nonumberline} from inside
% \csbc{etocthename} when it has empty meaning, so the expansion of the latter
% can safely be delayed by custom section styles (for example if the build up
% some token list to be executed later not immediately).  \etocrelease{1.1c} fixes a
% regression committed at \etocrelease{1.1a}: for a \csa{nonumberline} with empty
% meaning the \csbc{etocthelinkedname} did not end up hyperlinked.
%
% A change, almost a bug fix, but the former behavior was actually
% deliberate, at \etocrelease{1.1c} regarding the KOMA-script \csa{nonumberline}
% token: formerly, when it expanded to \csa{numberline}|{}| (this
% can happen only when the TOC is typeset in compatibility mode for
% the global display) then \csbc{ifEtoc@numbered} was set to true.
% But this is only a KOMA-script typesetting thing, and should not
% have influenced \etoc's decisions when its (user or package) own
% line styles are used: at \etocrelease{1.1c} it is thus decided that in such
% circumstances the \csbc{etocifnumbered} will pick the false
% branch, and the empty \csbc{etocthelinkednumber} will not be
% hyperlinked.
%
% No brace removal of the |#1| here a priori possible because we took care to
% check that \csbc{Etoc@getnb} was not followed by either a space or an
% opening brace.
%
% The \csbc{Etoc@@getit} branch for ``Parts'' used to be executed from inside
% \csbc{Etoc@lxyz}.  At \etocrelease{1.1c} we jump directly to it from here.
%    \begin{macrocode}
\def\Etoc@getnb #1{%
    \in@{#1}{\numberline\chapternumberline\partnumberline\booknumberline}%
    \ifin@
       \let\Etoc@next\Etoc@getnb@nmbrd
    \else
       \ifnum\Etoc@level=\m@ne
           \let\Etoc@next\Etoc@@getit
       \else
           \let\Etoc@next\Etoc@getnb@nonbr
       \fi
%    \end{macrocode}
% Remove a KOMA-script \csa{nonumberline} token if present and process the
% entry always as not numbered (see above comments).  Prior to \etocrelease{1.1c}, the
% code branched according to the meaning of the \csa{nonumberline} token,
% which was a bit silly.
%    \begin{macrocode}
       \in@{#1}{\nonumberline}%
       \ifin@
         \let\Etoc@next\Etoc@getnb@nonumberline
       \fi
    \fi
    \Etoc@next #1%
}
%    \end{macrocode}
% Prior to \etocrelease{1.1a}, \csbc{etocthelinkedname} and \csbc{etocthelinkednumber}
% (for a numberd entry) were defined to carry links only if an hyperlink was
% actually found, now they are defined in \csbc{Etoc@lxyz} to always provide
% the hyperlinking to the target title in the document.
%
% \etocrelease{1.1a} and \etocrelease{1.1b} still had here some superfluous
% code which was trimmed at \etocrelease{1.1c}.
%
% Also, \etocrelease{1.1c} fixes here a brace removal bug (which had always been there I
% guess): if the numbered heading title was braced one level of bracing was
% removed.  The bug had no effect in a document using \ctanpkg{hyperref} (and
% its default |linktoc| setting) as the \csa{hyperlink} wrapper limited the
% scope.  But in a document without hyperref it would have been seen with
% input such as |\section{{\color{blue}Stuff}}|.
%    \begin{macrocode}
\def\Etoc@getnb@nmbrd #1#2{%
    \Etoc@global\Etoc@numberedtrue
    \Etoc@global\def\etocthenumber {#2}%
    \Etoc@getnb@nmbrd@getname\@empty
}%
%    \end{macrocode}
% We added an \csa{@empty} token to prevent brace removal.
%    \begin{macrocode}
\def\Etoc@getnb@nmbrd@getname #1\hspace\etoc@ {%
    \Etoc@global\expandafter\def\expandafter\etocthename\expandafter{#1}%
}
%    \end{macrocode}
% Not numbered entry.
%    \begin{macrocode}
\def\Etoc@getnb@nonbr #1\etoc@ {%
    \Etoc@global\Etoc@numberedfalse
    \Etoc@global\let\etocthenumber \@empty
}
%    \end{macrocode}
% Special KOMA branch: |#1| starts with \csa{nonumberline} (prior to \etocrelease{1.1c}
% the |#1| would have already lost this token, and this branch was executed
% only in case \csa{nonumberline} had empty meaning).  We need to remove this
% token from |#1| and redefine \csbc{etocthename}.
%
% \etocrelease{1.1a} code still had here some complications with a ``braced name'' branch
% which was in fact never executed at \etocrelease{1.1a}, as the \ctanpkg{hyperref} hacks
% into the expansion of \csa{contentsline} were not executed.  These now
% unneeded complications got removed at \etocrelease{1.1c}.
%
% \etocrelease{1.1c} also fixes a regression caused by \etocrelease{1.1a} in this branch: the
% \csbc{etocthelinkedname} had lost its hyperlink.
%
% The \csa{nonumberline} extra token guarantees no brace stripping here.
%    \begin{macrocode}
\def\Etoc@getnb@nonumberline #1\hspace\etoc@ {%
    \Etoc@global\Etoc@numberedfalse
    \Etoc@global\let\etocthenumber \@empty
    \Etoc@global\expandafter\def\expandafter\etocthename\expandafter{\@gobble#1}%
}
%    \end{macrocode}
% This branch handles the peculiar ``Part'' syntax.  No brace stripping
% possible here when grabbing |#1|, due to previous checks that it does
% not start by a space token or an opening brace.
%
% \etocrelease{1.1c} handles this as a sub-branch from \csbc{Etoc@@getnb} which brings
% simplifications.  Also the code has been somewhat strengthened so as to
% avoid in later processing a brace removal issue on the name (which was a bug
% of legacy earlier code), when it turns our we are handling a numbered Part
% indeed.
%
% The whole thing is anyhow quite fragile due to \LaTeX{}'s handling by
% standard classes of |.toc| file entries for parts being even more already
% pre-formatted for typesetting than for other levels.
%    \begin{macrocode}
\def\Etoc@@getit #1\hspace#2{%
    \ifx\etoc@#2%
      \Etoc@global\Etoc@numberedfalse
      \Etoc@global\let\etocthenumber \@empty
    \else
      \Etoc@global\Etoc@numberedtrue
      \Etoc@global\def\etocthenumber {#1}%
      \expandafter\Etoc@getit@getname \expandafter\@empty
    \fi
}
%    \end{macrocode}
% Chain of \csa{expandafter}'s to get rid of the added \csa{@empty} token to
% avoid a brace removal.  And this is the end of the \etocrelease{1.1a} refactoring,
% completed at \etocrelease{1.1c}.
%    \begin{macrocode}
\def\Etoc@getit@getname #1\hspace\etoc@ {%
    \Etoc@global\expandafter\def\expandafter\etocthename\expandafter{#1}%
}
%    \end{macrocode}
% place-holder
%    \begin{macrocode}
\let\etocthename   \@empty
\let\etocthenumber \@empty
\let\etocthepage   \@empty
\let\etocthelinkedname   \@empty
\let\etocthelinkednumber \@empty
\let\etocthelinkedpage   \@empty
\let\etocthelink   \@firstofone
\DeclareRobustCommand*{\etocname}  {}
\DeclareRobustCommand*{\etocnumber}{}
\DeclareRobustCommand*{\etocpage}  {}
\DeclareRobustCommand*{\etoclink}  {\@firstofone}
\DeclareRobustCommand*{\etocifnumbered}
   {\ifEtoc@numbered\expandafter\@firstoftwo\else\expandafter\@secondoftwo\fi}
\expandafter\let\expandafter\etocxifnumbered\csname etocifnumbered \endcsname
\DeclareRobustCommand*{\etociffirst}
   {\ifEtoc@isfirst\expandafter\@firstoftwo\else\expandafter\@secondoftwo\fi}
\expandafter\let\expandafter\etocxiffirst\csname etociffirst \endcsname
\def\Etoc@readtoc {%
  \ifeof \Etoc@tf
  \else
     \read \Etoc@tf to \Etoc@buffer
     \Etoc@toctoks=\expandafter\expandafter\expandafter
       {\expandafter\the\expandafter\Etoc@toctoks\Etoc@buffer}%
     \expandafter\Etoc@readtoc
  \fi
}
%    \end{macrocode}
% \etocrelease{1.07m} moves the reading of the toc file At Begin Document. Needed for
% Babel activated characters.\par^^A extra \par needed to avoid empty line...
%    \begin{macrocode}
\Etoc@toctoks {}% (superfluous, but for clarity)
\AtBeginDocument{\IfFileExists{\jobname.toc}
    {{\endlinechar=\m@ne
      \makeatletter
      \newread\Etoc@tf
      \openin\Etoc@tf\@filef@und
      \Etoc@readtoc
      \global\Etoc@toctoks=\expandafter{\the\Etoc@toctoks}%
      \closein\Etoc@tf}}
    {\typeout{No file \jobname.toc.}}}
\def\Etoc@openouttoc{%
  \ifEtoc@hyperref
   \ifx\hyper@last\@undefined
    \IfFileExists{\jobname .toc}
      {\Hy@WarningNoLine
         {old toc file detected; run LaTeX again (cheers from `etoc')}%
       \global\Etoc@toctoks={}%
      }
      {}%
   \fi
  \fi
  \if@filesw
   \newwrite \tf@toc
   \immediate \openout \tf@toc \jobname .toc\relax
  \fi
  \global\let\Etoc@openouttoc\empty
}
%    \end{macrocode}
% The |\gdef\Etoc@stackofends{{-3}{}}| is in theory superfluous as normally
% this stack should always have been restored on exit to its initial state,
% but...
%
% It would perhaps be better to issue here \csa{Etoc@notactivetrue}, prior to
% |\the\Etoc@toctoks| but it is up to the caller macros to do it.
% \csbc{Etoc@minf} is a level which is lower (i.e. more encompassing than all
% others), so numerically \texttt{-2} for standard classes and \texttt{-3} for
% \ctanpkg{memoir} class.
%
% The \csbc{Etoc@doendsandbegin} will not try to execute a (non-existing)
% ``begin'' macro for the level \texttt{-3}.
%    \begin{macrocode}
\def\Etoc@toctoc{%
  \gdef\Etoc@stackofends{{-3}{}}%
  \global\let\Etoc@level\Etoc@minf
  \global\let\Etoc@virtualtop\Etoc@minf
  \the\Etoc@toctoks
  \ifEtoc@notactive
  \else
   \gdef\Etoc@level{-\thr@@}%
   \Etoc@doendsandbegin
  \fi
}
%    \end{macrocode}
% Memo: \csbc{etoclocaltop} has only meaningful meaning when the toc is local
% and is ``active''. Except that I used a "notactive" flag to torture myself,
% so: has the \csbc{ifEtoc@notactive} flag set to |false|.
%
% The \etocrelease{1.2} removal of usage of boolean flags associated to
% the levels has made the next definition more succinct.  Their former r\^ole is
% picked up by \csbc{Etoc@level}.
%
% MEMO: the \csbc{etoclocaltableofcontentshook} has been added during development
% \etocrelease{1.2} probably for reasons of symmetry with handling of the
% local ``lists of'' code, but at time of release I can't remember clearly.
% Hesitation where to put it exactly.
%
% \etocrelease{1.2} adds a \csbc{Etoc@@startlocaltochook} for a refactoring of
% \csbc{localtableofcontentswithrelativedepth}.  It also serves to make the
% emptiness check with local ``lists of'', as will be seen further down.
%    \begin{macrocode}
\def\Etoc@@startlocaltoc#1#2{%
    \ifEtoc@localtoc
       \ifnum #1=#2\relax
          \global\let\etoclocaltop\Etoc@virtualtop
          \Etoc@@startlocaltochook
          \etoclocaltableofcontentshook
%    \end{macrocode}
% The \csbc{ifEtoc@etocstyle} boolean is true when \etoc is left in its default
% mode (no usage of \csbc{etocsettocstyle} or \csbc{etocclasstocstyle}).  It
% inhibits \csbc{Etoc@tableofcontents} from using the specified
% \marg{before\string_toc} and \marg{after\string_toc} from usage of
% \csbc{etocsettocstyle}.  And here we can insert the code we wish to do the
% title.
%
% \begin{shaded}
% \setstretch{1}%
% \textbf{MEMO}: for legacy reason \etoc shares a lot of code between global TOC and
% local TOCs.  But it would probably have been better to separate the two and
% provide an \csa{etocsetlocaltocstyle} that the user can use in preamble.
% As it stands \csbc{etocsettocstyle} if used in preamble also influences the
% global TOC, so basically one has to use it again after it (if it comes first
% in the document).
% \end{shaded}
%
% The \csa{ifEtoc@ouroboros} mechanism when it is set to false appears rather
% audacious.
%    \begin{macrocode}
          \ifEtoc@etocstyle
              \etocetoclocaltocmaketitle
          \fi
          \ifx\Etoc@aftertitlehook\@empty
          \else
            \ifEtoc@localtoctotoc
              \ifEtoc@ouroboros
              \else
                \let\Etoc@tmp\contentsline
                \def\contentsline{\let\contentsline\Etoc@tmp\Etoc@gobblethreeorfour}%
              \fi
            \fi
          \fi
          \global\Etoc@notactivefalse
       \fi
    \fi
}
\let\etoc@startlocaltoc\@gobble
\let\Etoc@@startlocaltoc@toc\Etoc@@startlocaltoc
\let\Etoc@@startlocaltochook\@empty
\unless\ifEtoc@deeplevels
%    \end{macrocode}
% This only hard-codes the built-in \LaTeX\ defaults.
%    \begin{macrocode}
  \def\etocdivisionnameatlevel#1{%
    \ifcase\numexpr#1\relax
             \ifdefined\c@chapter chapter\else section\fi%
         \or section%
         \or subsection%
         \or subsubsection%
         \or paragraph%
         \or subparagraph%
         \or empty%
    \else\ifnum\numexpr#1<\m@ne
             book%
         \else
             part%
         \fi
    \fi
  }
\else
%    \end{macrocode}
% The definition given to \csbc{etocdivisionnameatlevel} in the
% \etocoption{deeplevels} branch is only needed if one wants to locate a
% local table of contents at a deep place, and one has not made use of
% \csbc{etocsettocstyle} to configure the heading by oneself.  I have
% used in the default definition the headings as in the
% \href{https://github.com/doxygen/doxygen/}{Doxygen} \LaTeX{} templates
% originating in the
% \href{https://github.com/doxygen/doxygen/pull/9936}{Doxygen\#9936} PR.
%    \begin{macrocode}
  \def\etocdivisionnameatlevel#1{%
    \ifcase\numexpr#1\relax
             \ifdefined\c@chapter chapter\else section\fi%
         \or section%
         \or subsection%
         \or subsubsection%
         \or subsubsubsection%
         \or subsubsubsubsection%
         \or subsubsubsubsubsection%
         \or subsubsubsubsubsubsection%
         \or paragraph%
         \or subparagraph%
    \else\ifnum\numexpr#1>\z@
             empty%
         \else\ifnum\numexpr#1=\m@ne
             part%
         \else
             book%
         \fi\fi
    \fi
  }
\fi
\def\etoclocalheadtotoc#1#2{\addcontentsline{toc}{@#1}{#2}}
\def\etocglobalheadtotoc{\addcontentsline{toc}}
%    \end{macrocode}
% I have coded this so that it can be copied pasted to a user document and
% customized at will.  \etocrelease{1.2a} uses a better test for knowing if
% the starred command of previous line created an inline heading with
% \csa{everypar}: \etocrelease{1.2} simply tested if \csbc{etoclocaltop} was
% at least |3| but this does not scale well with \etocoption{deeplevels}.
% Only worry here is whether the \csa{if@noskipsec} thing really works with
% all document classes.  At least it is in \LaTeX{} kernel.\par^^A pénible
%    \begin{macrocode}
\providecommand*\UseName{\@nameuse}
\def\etocetoclocaltocmaketitle{%
    \UseName{\etocdivisionnameatlevel{\etoclocaltop+1}}*{\localcontentsname}%
    \if@noskipsec\leavevmode\par\fi
    \etociflocaltoctotoc
      {\etocifisstarred
         {}% star variant, do not add to toc
         {\etoclocalheadtotoc
           {\etocdivisionnameatlevel{\etoclocaltop+1}}%
           {\localcontentsname}%
         }%
      }%
      {}%
}%
%    \end{macrocode}
% In dev, I used \csa{etoc} prefix for the next two, but I
% decided to drop it for release.
%    \begin{macrocode}
\def\localcontentsname  {\contentsname}%
\let\etoclocaltableofcontentshook\@empty
%    \end{macrocode}
% The big thing at \etocrelease{1.2}: experimental support code for
% \csbc{locallistoffigures} and \csbc{locallistoftables}!  There were two
% possibilities to implement the `localtoc' mechanism: either add some extra
% things to the |.lof| and |.lot| files, or get their data duplicated in the
% |.toc| file.  I have chosen for time being the latter path, hence this goes
% via hacking into \csa{addcontentsline} and it must be the case that the
% document class uses it (from \csa{caption}).  If some package has modified
% the implementation of captions of figures and tables and insertes data in
% the |.lof| or |.lot| files directly via \csa{addtocontents} for example
% and not via \csa{addcontentsline}, then the \etoc mechanism will fail.
%    \begin{macrocode}
\if1\ifEtoc@lof0\fi\ifEtoc@lot0\fi1%
\else
\AtBeginDocument{%
  \let\Etoc@originaladdcontentsline\addcontentsline
  \def\addcontentsline{\Etoc@hackedaddcontentsline}%
}%
\fi
%    \end{macrocode}
% For optimization of execution speed we define the macro conditionnally on
% the option status (wihch is frozen). In the first case, |#1=lof,.lot| would
% work but this is not realistic.
%    \begin{macrocode}
\ifEtoc@lof
  \ifEtoc@lot
    \def\Etoc@hackedaddcontentsline#1{%
      \expanded{\noexpand\in@{.#1,}}{.lof,.lot,}%
      \ifin@\expandafter\Etoc@hackedaddcontentsline@i
      \else\expandafter\Etoc@originaladdcontentsline
      \fi {#1}}
  \else
    \def\Etoc@hackedaddcontentsline#1{%
      \expanded{\noexpand\in@{.#1,}}{.lof,}%
      \ifin@\expandafter\Etoc@hackedaddcontentsline@i
      \else\expandafter\Etoc@originaladdcontentsline
      \fi {#1}}
  \fi
\else
  \def\Etoc@hackedaddcontentsline#1{%
    \expanded{\noexpand\in@{.#1,}}{.lot,}%
    \ifin@\expandafter\Etoc@hackedaddcontentsline@i
    \else\expandafter\Etoc@originaladdcontentsline
    \fi {#1}}
\fi
%    \end{macrocode}
% This business of \csa{protected@file@percent} is not really needed as anyhow
% \etoc reads the |.toc| file with no space token from end of lines.
%    \begin{macrocode}
\def\Etoc@hackedaddcontentsline@i#1#2#3{%
    \expanded{\noexpand\in@{.#1;#2,}}{.lof;figure,.lot;table,}%
    \ifin@
    \addtocontents {toc}{%
      \protect\contentsline{#2}{#3}{\thepage}{\ifEtoc@hyperref\@currentHref\fi}%
      \ifdefined\protected@file@percent\protected@file@percent\fi
    }%
    \fi
    \Etoc@originaladdcontentsline{#1}{#2}{#3}%
}
%    \end{macrocode}
% The two macros need to be redefined if \csa{expanded} is not provided by the
% engine.  Here we leave some tests done at execution time although they could
% have been done (as above) here at definition time.
%    \begin{macrocode}
\unless\ifdefined\expanded
  \def\Etoc@hackedaddcontentsline#1{%
    {\edef\Etoc@tmp{\noexpand\in@{.#1,}{\ifEtoc@lof.lof,\fi\ifEtoc@lot.lot,\fi}}\expandafter}%
    \Etoc@tmp
    \ifin@\expandafter\Etoc@hackedaddcontentsline@i
    \else\expandafter\Etoc@originaladdcontentsline
    \fi {#1}%
  }
  \def\Etoc@hackedaddcontentsline@i#1#2#3{%
    {\edef\Etoc@tmp{\noexpand\in@{.#1;#2,}}\expandafter}%
    \Etoc@tmp{.lof;figure,.lot;table,}%
    \ifin@
    \addtocontents {toc}{%
      \protect\contentsline{#2}{#3}{\thepage}{\ifEtoc@hyperref\@currentHref\fi}%
      \ifdefined\protected@file@percent\protected@file@percent\fi
    }%
    \fi
    \Etoc@originaladdcontentsline{#1}{#2}{#3}%
  }
\fi
%    \end{macrocode}
% We will simply let \csbc{locallistoffigures} and \csbc{locallistoftables}
% use \csbc{localtableofcontents}.  We need some dedicated variant of
% \csbc{Etoc@@startlocaltoc}.  Hesitation where to put
% \csbc{Etoc@@startlocaltochook} which has multiple usages.
%    \begin{macrocode}
\def\Etoc@@startlocallistof#1#2#3{%
    \ifEtoc@localtoc
       \ifnum #2=#3\relax
          \global\let\etoclocaltop\Etoc@virtualtop
          \global\Etoc@notactivefalse
          \Etoc@@startlocaltochook
          \csname etoclocallistof#1shook\endcsname
          \ifEtoc@etocstyle
              \csname etocetoclistof#1smaketitle\endcsname
          \fi
       \fi
    \fi
}
\def\Etoc@@startlocallistof@setlevels#1{%
%    \end{macrocode}
% |#1| is |figure| or |table|.
%
% \csbc{etoclocaltop} represents the level which will stop the local ``list
% of'' contents.  I hesitated whether local ``lists of'' should obey the
% |tocdepth|, especially a varying one.  Finally at last minute I opted for
% ``Yes'', so in the end no alteration of |tocdepth| will be done here.  We
% will set the level to have value
% \centeredline{|min(1, |\csbc{etoclocaltop}|+1)|}
% At least |1|, because it really would not make
% sense to show figure entries as chapter entries for a local list of figures
% in a Part (if the user has for example set the
% \csbc{etoclocallistoffigureshook} to do nothing, so that the line styles as
% configured via \csbc{etocsetstyle} are not avoided).  And it must be greater
% than \csbc{etoclocaltop} else such an entry would terminate the scope of the
% local contents.
%
% In the default context which has issued via
% \csbc{etoclocallistoffigureshook} a local \csbc{etocstandardlines}, the
% actual value of the level only has a ``all or nothing'' meaning: if it is
% greater than |tocdepth| then the \csbc{Etoc@etoccontentsline} will not call
% \csa{contentsline}, else it will and then the code from document class will
% kick in.  The |article| class defines \csa{l@figure} as
% \centeredline{|\@dottedtocline {1}{1.5em}{2.3em}|}
% And we are here in a context where necessarily |tocdepth| is at least |1|
% (if it was |0| or less, as the level has been set to at least |1|, the entry
% would have been filtered out earlier by \csbc{Etoc@etoccontentsline}), so
% the line will show.  And if \csbc{etoclocallistoffigureshook} was modified
% and did not issue \csbc{etocstandardlines} and we are in this situation that
% the |tocdepth| comparison did not inhibit the entry, then it will show too,
% at least if the line style does not say to do nothing (notice that the \etoc
% fall-back line styles are configured to do nothing for paragraph and
% subparagraph entries).
%
% On the other hand if the |tocdepth| inhibits entries of level
% \csbc{etoclocaltop}|+1|, then a \csbc{localtableofcontents} at this level
% would display no contents, so why should it not also mute
% \csbc{locallistoffigures}?
%
% This change to the level \csbc{Etoc@figure@@} or \csbc{Etoc@table@@} is done
% only locally, no need to worry about collaterals after the ``List of''.
%    \begin{macrocode}
          \ifnum\etoclocaltop<\z@
              \expandafter\let\csname Etoc@#1@@\endcsname\@ne
          \else
              \expandafter\let\csname Etoc@#1@@\expandafter\endcsname
                              \csname Etoc@\the\numexpr\etoclocaltop+\@ne @@\endcsname
          \fi
%    \end{macrocode}
% We now make invisible all level names whose numerical level would have
% allowed them to show in these contents.  |figure| and |table| are never
% included in the \csbc{Etoc@dolevels} no danger to cancel them out.  The
% special level names |@section| etc... which are inserted by headings of
% local ``lists of'' or local TOCs under \etocoption{localloftotoc} and other
% options have been made invisible by \csbc{Etoc@listofhook}, no need to do
% anything about them here.
%    \begin{macrocode}
          \def\Etoc@do##1{%
              \ifnum\etoclevel{##1}>\etoclocaltop
                     \expandafter\let\csname Etoc@##1@@\endcsname\Etoc@maxlevel
              \fi}%
          \Etoc@dolevels
}
%    \end{macrocode}
% Let's for time being configure the figure and table lines to be rendered as
% in class default.
%
% Ah, I remember why I added \csbc{etoclocaltableofcontentshook} above.  It is
% by symmetry as I had defined those next two already.
%    \begin{macrocode}
\def\etoclocallistoffigureshook{\etocstandardlines}
\def\etoclocallistoftableshook {\etocstandardlines}
%    \end{macrocode}
% Here is some info about usage of \csbc{etoclocallistoffigureshook}, for
% those who end up here from having clicked on the name from the user
% manual.  Its default as above means to use the class default for lines in
% \csa{listoffigures}.  If you redefine it to be empty, the effect is that
% (except of course if \csbc{etocstandardlines} has been issued globally) the
% figure lines will adopt the style configured for level
% \csbc{etoclocaltop}|+1| (or more precisely the minimum of that and of |1|).
% You can definitely put into the hook some
% \centeredline{\csbc{etocsetstyle}|{\number\etoclevel{figure}}{}{}{...}{}|}
% where the dots represent some code with \csbc{etocnumber}, \csbc{etocname},
% \csbc{etocpage}, itself possibly querying \csbc{etoclevel}|{figure}|, or
% perhaps \csbc{etoclocaltop} to know the actual depth (which may the one of a
% Part which can thus be distinguished from being in a Chapter, whereas
% \csa{number}\csbc{etoclevel}|{figure}| will give |1| in both cases).
%
% There is variant which is to maintain the default \csbc{etocstandardlines}
% in the hook and then re-define the kernel macro \csa{l@figure} to do the
% desired thing.  For example the default with |article| is for \csa{l@figure}
% to do {|\@dottedtocline {1}{1.5em}{2.3em}|} so you can do some variant where
% the second and third argument (indent and numwidth) are set according to
% \csbc{etoclocaltop}.
%
% I hope the above explanations help, they appear too advanced for inclusion
% in the user manual so I give them here.
%
% In dev, I used \csa{etoc} prefix here, but I decided to drop it for release.
%    \begin{macrocode}
\def\locallistfigurename{\listfigurename}
\def\locallisttablename {\listtablename}
%    \end{macrocode}
% Same observations as for \csbc{etocetoclocaltocmaketitle}.
%    \begin{macrocode}
\def\etocetoclistoffiguresmaketitle{%
    \UseName{\etocdivisionnameatlevel{\etoclocaltop+1}}*{\locallistfigurename}%
    \ifnum\etoclocaltop>\tw@\mbox{}\par\fi
    \etociflocalloftotoc
      {\etocifisstarred
         {}% star variant, do not add to toc
         {\etoclocalheadtotoc
           {\etocdivisionnameatlevel{\etoclocaltop+1}}%
           {\locallistfigurename}%
         }%
      }%
      {}%
}%
\def\etocetoclistoftablesmaketitle{%
    \UseName{\etocdivisionnameatlevel{\etoclocaltop+1}}*{\locallisttablename}%
    \ifnum\etoclocaltop>\tw@\mbox{}\par\fi
    \etociflocallottotoc
      {\etocifisstarred
         {}% star variant, do not add to toc
         {\etoclocalheadtotoc
           {\etocdivisionnameatlevel{\etoclocaltop+1}}%
           {\locallisttablename}%
         }%
      }%
      {}%
}%
%    \end{macrocode}
% The local lists of do support the |\label/\ref| syntax as we are careful
% here to position \csbc{localtableofcontents} as last token.
%
% The reset to \csa{@empty} of the \csa{Etoc@listofreset} is not strictly
% needed as the other things can always be done with no harm.
%    \begin{macrocode}
\let\Etoc@listofreset\@empty
%    \end{macrocode}
% Memo: \csa{ext@toc} defined in KOMA and memoir but not in the standard classes.
%    \begin{macrocode}
\ifEtoc@lof
  \def\locallistoffigures{%
      \def\Etoc@listofreset{%
          \let\Etoc@currext\Etoc@tocext
          \let\Etoc@@startlocaltoc\Etoc@@startlocaltoc@toc
          \let\Etoc@@startlocaltochook\@empty
          \let\Etoc@listofreset\@empty
%    \end{macrocode}
% The \csbc{Etoc@listofhook} is executed by \csbc{localtableofcontents}.  It
% will be used here to let local ``lists of'' ignore all the special |.toc|
% entries whose level names start with a |@|.  This is to avoid the scope
% limiting detection of the local list of figures or tables from being
% influenced by another list of, such as a list of tables following a list of
% figures which has put its title inside the |.toc| due to |locallottotoc|
% option of \etoc.
%    \begin{macrocode}
          \let\Etoc@listofhook\@empty
          }%
      \let\Etoc@currext\Etoc@lofext
      \def\Etoc@@startlocaltoc{\Etoc@@startlocallistof{figure}}%
      \def\Etoc@@startlocaltochook{\Etoc@@startlocallistof@setlevels{figure}}%
      \def\Etoc@listofhook{%
        \def\Etoc@do####1{%
          \expandafter\let\csname Etoc@@####1@@\endcsname\Etoc@maxlevel
        }%
        \Etoc@dolevels
      }%
      \localtableofcontents
  }
\else
  \def\locallistoffigures{%
      \PackageError{etoc}{%
        \string\locallistoffigures \on@line\space but\MessageBreak
        package was loaded without `lof' option}%
        {Try again with \string\usepackage[lof]{etoc}}%
      }
\fi
\ifEtoc@lot
  \def\locallistoftables{%
      \def\Etoc@listofreset{%
          \let\Etoc@currext\Etoc@tocext
          \let\Etoc@@startlocaltoc\Etoc@@startlocaltoc@toc
          \let\Etoc@@startlocaltochook\@empty
          \let\Etoc@listofreset\@empty
          \let\Etoc@listofhook\@empty
          }%
      \let\Etoc@currext\Etoc@lotext
      \def\Etoc@@startlocaltoc{\Etoc@@startlocallistof{table}}%
      \def\Etoc@@startlocaltochook{\Etoc@@startlocallistof@setlevels{table}}%
      \def\Etoc@listofhook{%
        \def\Etoc@do####1{%
          \expandafter\let\csname Etoc@@####1@@\endcsname\Etoc@maxlevel
        }%
        \Etoc@dolevels
      }%
      \localtableofcontents
  }
\else
  \def\locallistoftables{%
      \PackageError{etoc}{%
        \string\locallistoftable \on@line\space but\MessageBreak
        package was loaded without `lot' option}%
        {Try again with \string\usepackage[lot]{etoc}}%
      }
\fi
%    \end{macrocode}
% \csbc{Etoc@tocid} is the number of the toc (possibly gotten via a |\ref|
% following a \csbc{tableofcontents}), or it is |\z@| if the emptiness test is
% from a global toc. Until the compilations stabilize, some local TOCs can get
% printed at wrong locations naturally and emptiness tests can not be trusted
% either.
%
% Note: (\etocrelease{1.08i} |2016/09/29|) the code has to handle both local
% and total toc.  Hence the flag \csbc{ifEtoc@notactive} has to be set prior
% to it. For a global toc, the \csbc{Etoc@tocid} was set to |\z@|, and the
% |\ifnum| in \csbc{etoc@startlocaltoc} did always fail, but I now prefer to
% simply nullify the \csbc{etoc@startlocaltoc}. As its default fallback is
% |\@gobble| I simply test here for the \csbc{ifEtoc@localtoc} flag. The
% \csbc{Etoc@tocid} will be undefined for a global toc but it is not tested
% anymore.
%
% The initialization such as |\global\let\Etoc@level\Etoc@minf| is needed in
% case the |.toc| file contains an \csbc{etoc@startlocaltoc} before any
% \csa{contentsline}.
%
% Local list of figures and tables set especially the tocdepth and a hook is
% added here for emptiness check to work correctly with them.
%
% MEMO: Should I also execute \csbc{etoclocaltableofcontentshook}?
% Then I would need to set \csbc{etoclocallistoffigureshook} to redefine it,
% rather than be inserted as itself.
%    \begin{macrocode}
\def\Etoc@checkifempty {%
    \global\Etoc@isemptytoctrue
    \global\Etoc@stoptocfalse
    \global\let\Etoc@level\Etoc@minf
    \global\let\Etoc@virtualtop\Etoc@minf
    \gdef\Etoc@stackofends{{-3}{}}%
    \begingroup
      \ifEtoc@localtoc
        \def\etoc@startlocaltoc##1{%
          \ifnum##1=\Etoc@tocid\relax
              \global\let\etoclocaltop\Etoc@virtualtop
              \Etoc@@startlocaltochook
              \global\Etoc@notactivefalse
          \fi
        }%
%    \end{macrocode}
% The mechanism is to check if any \csa{contentsline} triggers execution.
% For this we replace the \etoc replacement by another replacement.
%    \begin{macrocode}
        \let\contentsline\Etoc@testingcontentslinelocal
      \else
        \let\contentsline\Etoc@testingcontentsline
      \fi
      \Etoc@storetocdepth
%    \end{macrocode}
% This here is a \etocrelease{1.09i} added work-around to avoid usage of
% \csbc{etocsetlocaltop.toc} which could cause the test of emptiness of a
% global TOC to actually execute some start and finish parts in some cases.
%    \begin{macrocode}
        \let\Etoc@setlocaltop@doendsandbegin\@empty
        \the\Etoc@toctoks
      \Etoc@restoretocdepth
    \endgroup
}
\DeclareRobustCommand*\etocifwasempty
  {\ifEtoc@isemptytoc\expandafter\@firstoftwo\else\expandafter\@secondoftwo\fi }
\expandafter\let\expandafter\etocxifwasempty\csname etocifwasempty \endcsname
\def\Etoc@testingcontentslinelocal #1{%
  \ifEtoc@stoptoc
  \else
   \ifnum\csname Etoc@#1@@\endcsname=\Etoc@maxlevel
   \else
    \global\expandafter\let\expandafter\Etoc@level\csname Etoc@#1@@\endcsname
    \if @\@car#1\@nil\else\global\let\Etoc@virtualtop\Etoc@level\fi
    \ifEtoc@notactive
    \else
%    \end{macrocode}
% \csbc{ifEtoc@notactive} is \csa{iffalse} in case of a local TOC once it has
% encountered the \csbc{etoc@startlocaltoc} with matching id.  So here
% \csbc{etoclocaltop} has been set by \csbc{Etoc@@startlocaltoc} and we
% compare to the new level encountered.  If the latter is at most equal to
% \csbc{etoclocaltop} this means the local TOC ends there and is empty, so we
% set the \csbc{ifEtoc@stoptoc} to true, which will cause the subsequent
% parsing to abort immediately.  If it is greater we check how it compares to
% the local required toc depth.  If lower or equal we conclude the toc is not
% empty, and toggle the flag to stop the parsing; if greater, we are still in
% doubt and must continue.
%    \begin{macrocode}
     \ifnum\Etoc@level>\etoclocaltop
      \unless\ifnum\Etoc@level>\c@tocdepth
       \global\Etoc@isemptytocfalse
       \global\Etoc@stoptoctrue
      \fi
     \else
      \global\Etoc@stoptoctrue
     \fi
    \fi
   \fi
  \fi
%    \end{macrocode}
% The \csa{@gobblethree} was added to the \LaTeX{} kernel for its 2020-02-02
% PL 5 release and we require 2020-10-01 since \etocrelease{1.1a}.
%    \begin{macrocode}
  \Etoc@gobblethreeorfour{}%
}
%    \end{macrocode}
% Test of emptiness of the global TOC (according to current setting of the
% levels and a possibly evolving tocdepth).
%    \begin{macrocode}
\def\Etoc@testingcontentsline #1{%
  \ifEtoc@stoptoc
  \else
   \ifnum\csname Etoc@#1@@\endcsname=\Etoc@maxlevel
   \else
    \unless\ifnum\csname Etoc@#1@@\endcsname>\c@tocdepth
     \global\Etoc@isemptytocfalse
     \global\Etoc@stoptoctrue
    \fi
   \fi
  \fi
  \Etoc@gobblethreeorfour{}%
}
%    \end{macrocode}
% \etocrelease{1.08e} lets \csbc{localtableofcontents} do a
% first scan of the |.toc| file (as stored in \csbc{Etoc@toctoks}) to
% determine if the table of contents will in fact end up empty.  Only,
% however if user has added \csbc{etocchecksemptiness} to document.
%
% If this optional emptiness check is positive, nothing is typeset.
% The command \csbc{etocaftertochook} is still executed though. Other
% ways were envisioned (like delimited macros) to determine this potential
% emptiness, but in the end I opted for execution of the |.toc| file with
% suitable definitions for \csa{contentsline} and
% \csbc{etoc@startlocaltoc}. Notice though that if emptiness would result from
% empty line styles, this can not be detected.  Emptiness means ``no
% \csa{contentsline} under the TOC scope''.
%
% For this detection of emptiness, assignments (here and in
% \csbc{Etoc@testingcontentsline}) are made globally, I think this is the best
% (just in case some portions of the |.toc| file turn out to be inside some
% groups --- perhaps for some silly color assignments, etc... --- whose
% boundaries do not necessarily respect unit levels).
%
% The flag \csbc{ifEtoc@tocwithid} discriminates between a \localtoc and a
% \toc|\ref{foo}|; the latter could so far possibly refer to a local or also to
% a global table of contents but release \etocrelease{1.08e} has deprecated the latter use
% as it complicated the code, for something truly silly. Thus |\ref{foo}| must
% now be with |foo| a label of a \emph{local} TOC. As a result \csbc{ifEtoc@tocwithid} is
% less used now.
%
% In the case of a |\ref|ed-to toc whose label was just added hence is not yet
% in the |.aux| file, \csbc{Etoc@tocid} is |0|. \etoc used to issue a warning to
% run latex again and did no printing at all. Release \etocrelease{1.08e} in such cases
% prints the heading (this may gain one compilation step). Emptiness test is
% not executed as it would necessarily turn out positive and can not be
% trusted anyhow. The TOC is declared non empty, which it probably is...
%
% Emptiness detection for local tables of contents (either from a
% \csbc{localtableofcontents} or from a \csbc{tableofcontents}|\ref{localtoc}|)
% can be trusted only when the |.toc| file has stabilized.The emptiness status
% of a local TOC whose Id is not yet in the |.toc| is by necessity undecided
% yet (and not to be trusted really as the numbering may have changed; only
% when compilation runs settle is the emptiness status to be trusted). The
% code declares the TOC non empty, as it will be in 95\% of use cases.
%
% Dropping support for \toc|\ref{globaltoc}| means here that when a TOC id is
% not found in the |.toc| file we can assume it definitely has to be a local
% TOC needing more compilations. The emptiness status is undecided, the code
% declares the TOC non empty.
%
% \etocrelease{1.08i} |2016/09/29| now does \csa{Etoc@localtoctrue} right at the start (the
% earlier code could have to handle table of contents which were actually
% global, via the |\label/\ref| mechanism.) It does not rely on the |\ifnum|
% automatically false in \csbc{Etoc@@startlocaltoc} due to the special values |0|
% or |\z@| for \csbc{Etoc@tocid}, but simply leaves \csbc{etoc@startlocaltoc} to its
% default |\@gobble|. The \csa{Etoc@isemptytocfalse} is upfront in case some
% code using \csbc{etocifwasempty} is in user hooks. The default is to assume the
% TOC non-empty as its contents are actually still unknown. Under the
% \csa{Etoc@stoptoctrue} flag, the \csbc{Etoc@etoccontentsline} is more efficient now.
%
% The \csbc{ifEtoc@notactive} flag needs to be set before calling
% \csbc{Etoc@checkifempty}.
%
% I hesitated with \etocrelease{1.08i} to write something to aux file in order to let
% \LaTeX\ prompt the user for extra pass, after insertion of some new
% \csa{localtableofcontents}, but finally I prefer to only trick \LaTeX\ into
% telling about undefined references.
%
% The \csa{PackageWarning} approach has the advantage
% that at least in Emacs/AUCTeX the |C-cC-c| will propose |LaTeX|, not |View|.
% But perhaps some automated scripts checking |aux| file will not like the
% extra line which is then removed in next pass, and could possibly do one
% extra unneeded compilation to check |aux| file remains identical. Hence the
% second approach. (edit |2017/10/23|: good thing I documented that! I had
% completely forgotten that rationale, but I wonder if it is correct.)
%
% Also the \csa{PackageWarning} does not trigger a visible message
% near the end of the log file or console output, contrarily to a
% \centeredline{|LaTeX Warning: There were undefined references.|}
% followed by a
% \centeredline{|LaTeX Warning: Label(s) may have changed. Rerun to get cross-references right.|}
%
% Method used here seems to work fine also with |latexmk|: it does not seem to
% induce it into making too many runs.
%    \begin{macrocode}
\def\Etoc@localtableofcontents#1{%
    \gdef\etoclocaltop{-\@m}%
    \Etoc@localtoctrue
    \global\Etoc@isemptytocfalse
    \edef\Etoc@tocid{#1}%
    \ifnum\Etoc@tocid<\@ne
      \setbox0\hbox{\ref{Unknown toc ref \@secondoftwo#1. \space Rerun LaTeX}}%
%    \end{macrocode}
% Do only heading, skip all the rest.
%    \begin{macrocode}
      \global\Etoc@stoptoctrue
      \gdef\etoclocaltop{-\thr@@}%
      \Etoc@tableofcontents
      \expandafter\Etoc@gobtoetoc@
    \fi
    \global\Etoc@notactivetrue
    \ifEtoc@checksemptiness
       \Etoc@checkifempty
    \fi
    \ifEtoc@isemptytoc
       \ifEtoc@notactive
         \setbox0\hbox{\ref{Unknown toc ID \number\Etoc@tocid. \space Rerun LaTeX}}%
%    \end{macrocode}
% Assume real one will be non-empty and print only heading for this pass.
%    \begin{macrocode}
         \global\Etoc@isemptytocfalse
         \global\Etoc@stoptoctrue
         \gdef\etoclocaltop{-\thr@@}%
         \Etoc@tableofcontents
         \expandafter\expandafter\expandafter\Etoc@gobtoetoc@
       \fi
    \else
       \global\Etoc@stoptocfalse
       \global\Etoc@notactivetrue
%    \end{macrocode}
% We can end up here either if the emptiness check was done and turned
% negative (then \csbc{etoclocaltop} has the correct level for usage in first
% argument of \csbc{etocsettocstyle}), or if the emptiness check was not done.
% For the latter case \csbc{etoclocaltop} has setting |-\@m|.
%    \begin{macrocode}
       \edef\etoc@startlocaltoc##1%
           {\noexpand\Etoc@@startlocaltoc{##1}{\Etoc@tocid}}%
       \Etoc@tableofcontents
    \fi
    \@gobble\etoc@
    \endgroup\ifEtoc@mustclosegroup\endgroup\fi
    \Etoc@tocdepthreset
    \Etoc@listofreset
    \etocaftertochook
}% \Etoc@localtableofcontents
%    \end{macrocode}
% |2013/03/07|: I discover a \csa{@namedef} trick to construct the
% \csbc{Etoc@again} space delimited macro:\\
% |    \@namedef {Etoc@again} {...stuff...}|\\
%  Original version was (copied from analogous stuff in |source2e|):\\
% |    {\def\1{\Etoc@again}\expandafter\gdef\1 {...stuff...}}|\\
% and in the end (now that I think about it) I simply use \csa{@firstofone}.
%
% \etocrelease{1.2} has a removed a \csa{Etoc@getrefno} as the author now
% knows about \csa{@car} so need to define a similar utility here!
%
% Much more importantly (and embarrassingly) \etocrelease{1.2} fixes a bug
% which had been here for ever. The code in its innocence 2012 birth year
% assumed that the first entry of \csa{r@foo}, if the latter is defined, is
% always numerical! But this is broken by \ctanpkg{varioref} if one used for
% example \csa{vpageref}|{foo}| before!  The first brace pair will then be
% |{??}|... causing in \etoc a ``Missing number'' error.
%
% About the current fixed code, there is no strong reason that
% \csbc{Etoc@getref} should work expandably.  Later
% \csbc{Etoc@localtableofcontents} does
% \centeredline{|\edef\Etoc@tocid{#1}\iffnum\Etoc@tocid<\@ne|} but I certainly
% could organize things differently.
%
% Maybe I should investigate more on what nasty things car be in
% first argument.  Or submit it to an \csa{expanded}?
%    \begin{macrocode}
\def\Etoc@getref #1{%
    \@ifundefined{r@#1}
         {0}
         {\expandafter\Etoc@getref@i\romannumeral-`0%
          \expandafter\expandafter\expandafter
          \@car\csname r@#1\endcsname0\@nil\@etoc
         }%
}
\def\Etoc@getref@i#1#2\@etoc{\ifnum9<1\string#1 #1#2\else 0\fi}
\def\Etoc@ref#1{\Etoc@localtableofcontents{\Etoc@getref{#1}}}
\def\Etoc@label#1{\label{#1}\futurelet\Etoc@nexttoken\Etoc@t@bleofcontents}
\@firstofone{\def\Etoc@again} {\futurelet\Etoc@nexttoken\Etoc@t@bleofcontents}
%    \end{macrocode}
% |\ref{foo}| expects |foo| to be a label to a \emph{local} TOC.
%
% The syntax \csbc{localtableofcontents}|\ref{foo}| is supported.
%    \begin{macrocode}
\def\Etoc@dothis #1#2\etoc@ {\fi #1}
\def\Etoc@t@bleofcontents{%
    \gdef\etoclocaltop{-\@M}%
    \ifx\Etoc@nexttoken\label\Etoc@dothis{\expandafter\Etoc@label\@gobble}\fi
    \ifx\Etoc@nexttoken\@sptoken\Etoc@dothis{\Etoc@again}\fi
%    \end{macrocode}
% \csbc{Etoc@ref} will hand over directly to \csbc{Etoc@localtableofcontents}.
% Argument will be (or rather expand to) zero if the reference is non-existent
% yet.
%    \begin{macrocode}
    \ifx\Etoc@nexttoken\ref\Etoc@dothis{\expandafter\Etoc@ref\@gobble}\fi
%    \end{macrocode}
% Flag to check if we were called from a \csbc{localtableofcontents}.
%    \begin{macrocode}
    \ifEtoc@tocwithid\Etoc@dothis{\Etoc@localtableofcontents{\c@etoc@tocid}}\fi
%    \end{macrocode}
% From now on we are handling a global TOC. Earlier, I used the trick of
% setting \csbc{Etoc@tocid} to |\z@| for compatibility with expansion of
% \csbc{etoc@startlocaltoc}. But since \etocrelease{1.08i} \csbc{etoc@startlocaltoc} is left to be
% |\@gobble|, and \csbc{Etoc@tocid} is never tested. We don't need to set the
% \csbc{ifEtoc@notactive} flag as now \csbc{Etoc@testingcontentsline} tests first the
% \csbc{ifEtoc@localtoc} flag (was already the case of \csbc{Etoc@etoccontentsline}). I change
% a bit the style of conditionals here for clarity of code.
%    \begin{macrocode}
    \global\Etoc@isemptytocfalse
    \ifEtoc@checksemptiness\Etoc@checkifempty\fi
    \ifEtoc@isemptytoc
     \ifEtoc@notocifnotoc
      \expandafter\expandafter\expandafter\@gobble
     \fi
    \fi
    \Etoc@tableofcontents
    \endgroup
    \ifEtoc@mustclosegroup\endgroup\fi
    \Etoc@tocdepthreset
    \Etoc@listofreset
    \etocaftertochook
    \@gobble\etoc@
    }% \Etoc@t@bleofcontents
%    \end{macrocode}
% \etocrelease{1.08c} does not use |\arabic| in the \csa{addtocontents} since I have seen
% that in some circumstances (for some right to left languages with
% polyglossia or babel), one can not rely on |\arabic| having its default
% definition. As the number written here will be used later in an \csa{ifnum}, I
% should not have used it in the first place (done |2015/03/30|).
%    \begin{macrocode}
\def\Etoc@table@fcontents{%
    \refstepcounter{etoc@tocid}%
    \Etoc@tocwithidfalse
    \futurelet\Etoc@nexttoken\Etoc@t@bleofcontents
}
\def\Etoc@localtable@fcontents{%
    \refstepcounter{etoc@tocid}%
    \addtocontents{toc}{\string\etoc@startlocaltoc{\the\c@etoc@tocid}}%
    \Etoc@tocwithidtrue
    \futurelet\Etoc@nexttoken\Etoc@t@bleofcontents
}
%    \end{macrocode}
% Attention that there could be a |\ref| following, thus we don't yet know
% whether this is a local or global table of contents.
%
% The \csbc{Etoc@tocdepthset} is for \csbc{etocsetnexttocdepth} mechanism.
%    \begin{macrocode}
\def\etoctableofcontents{%
   \Etoc@openouttoc
   \Etoc@tocdepthset
   \begingroup
%    \end{macrocode}
% This group will be closed in \csbc{Etoc@t@bleofcontents} or
% \csbc{Etoc@localtableofcontents}.
%
% Prior to its release |1.4c|, \ctanpkg{tableof} added a group pair via \csa{tof@begin}
% and \csa{tof@finish}. It was removed at |1.4c|, so no need to do anything now
% here about silencing \csa{tof@begingroup} and \csa{tof@endgroup}: they are
% inserted only in the \ctanpkg{tableof} private copy of the |.toc| file which is
% used by its own table of contents typesetting command.
%
% \etocrelease{1.09b} uses a |\def| in non-starred variant for allowing tricks to
% recognize later on if we are in a starred or non-starred case, whatever the
% user definition of \csbc{etocaftertitlehook} may be.
%    \begin{macrocode}
      \@ifstar
      {\let\Etoc@aftertitlehook\@empty\Etoc@table@fcontents}
      {\def\Etoc@aftertitlehook{\etocaftertitlehook}\Etoc@table@fcontents}%
}% \etoctableofcontents
\def\etocifisstarred{\ifx\Etoc@aftertitlehook\@empty
                         \expandafter\@firstoftwo\else
                         \expandafter\@secondoftwo
                     \fi}
\let\etocoriginaltableofcontents\tableofcontents
\let\tableofcontents\etoctableofcontents
%    \end{macrocode}
% The \csbc{Etoc@listofhook} is configured by \csbc{locallistoffigures} and
% \csbc{locallistoftables}.  The latter two use hooks rather than
% |\begingroup...\endgroup| to manage local configuration, in part because
% they want to support the |\label/\ref| special \etoc mechanism, so need to
% issue \csbc{localtableofcontents} last for it to be able to pick up a
% following |\label| or |\ref|.
%    \begin{macrocode}
\let\Etoc@listofhook\@empty
\newcommand*\localtableofcontents{%
   \Etoc@openouttoc
   \Etoc@tocdepthset
%    \end{macrocode}
% This group closed in \csbc{Etoc@t@bleofcontents} or \csbc{Etoc@localtableofcontents}.
% Same comment relative to \ctanpkg{tableof}. No need to do anything here.
%    \begin{macrocode}
   \begingroup
      \Etoc@listofhook
      \@ifstar
      {\let\Etoc@aftertitlehook\@empty\Etoc@localtable@fcontents}
      {\def\Etoc@aftertitlehook{\etocaftertitlehook}\Etoc@localtable@fcontents}%
}% \localtableofcontents
%    \end{macrocode}
% \etocrelease{1.09} adds \localtocwrdp.  Note that changes to the tocdepth
% from inside the |.toc| file during duration of local toc will remain without
% effect as a substitute is used which gets a frozen non-dynamical value.
%
% It seems \etocrelease{1.09} actually forgot a change to
% \csbc{Etoc@etoccontentsline} and the previous sentence was false and
% described only what happened during the emptiness check which thus could
% give false positives or false negatives.  But if I had done the needed
% change in \csbc{Etoc@etoccontentsline} to keep the two in sync, even if
% |tocdepth| evolves from the |.toc| file, I would have created a divergence
% between local TOCs (not only the
% \csbc{localtableofcontentswithrelativedepth} ones) under
% \csbc{etocstandardlines} and those not with standard lines.
%
% Redoing the whole thing at \etocrelease{1.2}.  I needed to insert a suitable
% hook in \csbc{Etoc@@startlocaltoc} (and also in the version used by
% \csbc{Etoc@checkifempty}).  And I have now at my disposal
% \csbc{Etoc@listofreset} to reset it (it will be expanded after both the
% emptiness check and the typesetting are completed, and at same grouping
% level as the trigger command defined here).  I do not want to add tokens
% after \csbc{localtableofcontents} to not break the |\label/\ref| thing,
% which is one reason for this way of proceeding.
%    \begin{macrocode}
\newcommand*\localtableofcontentswithrelativedepth[1]{%
   \def\Etoc@@startlocaltochook{%
       \global\c@tocdepth\numexpr\etoclocaltop+#1\relax
   }%
   \def\Etoc@listofreset{\let\Etoc@@startlocaltochook\@empty
                         \let\Etoc@listofreset\@empty}%
   \localtableofcontents
}% \localtableofcontentswithrelativedepth
%    \end{macrocode}
% Prior to \etocrelease{1.2}, \csbc{Etoc@tableofcontents} was constructed
% by \csbc{etocsettocstyle} as one big macro where |#1| and |#2| had been
% inserted.  It now simply stores |#1| and |#2| each in a macro and
% \csbc{Etoc@tableofcontents} is defined once and for all.  Also the boolean
% \csbc{ifEtoc@etocstyle} is added which helps keeping the emulation of
% the document class only for the global document TOC but use a better choice
% for local tables of contents (especially those in deeper sub-levels),
% which is activated via \csbc{etocetoclocaltocstyle} (near end of code).
%
% \csbc{etocstoretocstyleinto} added at \etocrelease{1.2}.  Too lazy
% to check if |#1| pre-exists.  Well, rather, too annoying to do this check
% as one may want to redefine |#1| without further ado.
%    \begin{macrocode}
\newcommand\etocsettocstyle[2]{%
   \Etoc@etocstylefalse
   \Etoc@classstylefalse
   \def\Etoc@tableofcontents@user@before{#1}%
   \def\Etoc@tableofcontents@user@after {#2}%
}%
\def\etocstoretocstyleinto#1{%
%%    \@ifdefinable#1{%
      \edef#1{\noexpand\Etoc@etocstylefalse\noexpand\Etoc@classstylefalse
              \def\noexpand\Etoc@tableofcontents@user@before{%
                  \unexpanded\expandafter{\Etoc@tableofcontents@user@before}%
                }%
              \def\noexpand\Etoc@tableofcontents@user@after{%
                  \unexpanded\expandafter{\Etoc@tableofcontents@user@after}%
                }%
             }%
%%    }%
}%
%    \end{macrocode}
% The macro names added here at \etocrelease{1.2} are provisory.  Next
% release will probably do a complete renaming of various internals because
% this is currently a complete mess with some names differing only by an |@|
% versus a voyel, but not necessarily being at a deeper level of expansion the
% more |@|'s they have... the deepest one being this \csbc{Etoc@tableofcontents}...
%    \begin{macrocode}
\def\Etoc@tableofcontents {%
    \Etoc@tableofcontents@etoc@before
    \ifEtoc@localtoc\ifEtoc@etocstyle\expandafter\expandafter\expandafter\@gobble\fi\fi
    \Etoc@tableofcontents@user@before
    \Etoc@tableofcontents@contents
    \ifEtoc@localtoc\ifEtoc@etocstyle\expandafter\expandafter\expandafter\@gobble\fi\fi
    \Etoc@tableofcontents@user@after
    \Etoc@tableofcontents@etoc@after
    \@gobble\etoc@
}
\def\Etoc@tableofcontents@etoc@before{%
    \ifnum\c@tocdepth>\Etoc@minf
    \else
     \expandafter\Etoc@gobtoetoc@
    \fi
    \Etoc@par
    \Etoc@beforetitlehook
    \etocbeforetitlehook
    \Etoc@storetocdepth
    \let\Etoc@savedcontentsline\contentsline
    \let\contentsline\Etoc@etoccontentsline
    \ifEtoc@standardlines
    \else
%    \end{macrocode}
% \etocrelease{1.1a}'s \csbc{Etoc@lxyz} now fetches 3 not 2 arguments and the
% \csa{l@section} etc... are not |\let| to it anymore, as they used to be here
% formerly.
%
% For backwards compatibility the \csa{etocsavedchaptertocline}
% etc... are still defined but issue a warning since \etocrelease{1.1a}
% and an error since \etocrelease{1.2}.
%    \begin{macrocode}
        \def\Etoc@do##1{%
            \expandafter\def\csname etocsaved##1tocline\endcsname
             {\PackageError{etoc}{%
              \expandafter\string\csname etocsaved##1tocline\endcsname\space
              has been deprecated\MessageBreak
              at 1.1a and is removed at 1.2.\MessageBreak
              Use \expandafter\string\csname l@##1\endcsname\space directly.\MessageBreak
              Reported \on@line}%
                                {I will use \expandafter\string
              \csname l@##1\endcsname\space myself for this time.%
                               }%
              \csname l@##1\endcsname
            }%
        }%
        \Etoc@dolevels
    \fi
}%
%    \end{macrocode}
% \etocrelease{1.09} makes \csbc{etocsetnexttocdepth} usable in |#1| (but this
% is not 100\% compatible with the emptiness check).  It makes an
% \csbc{etoclocaltop} usable in |#1| if under checksemptiness regime.
%
% (|#1| above now means \csbc{Etoc@tableofcontents@user@before} since \etocrelease{1.2})
%    \begin{macrocode}
\def\Etoc@tableofcontents@contents{%
    \Etoc@tocdepthset
    \ifEtoc@parskip\parskip\z@skip\fi
    \Etoc@aftertitlehook
%    \end{macrocode}
% \etocrelease{1.09} has replaced former \csa{Etoc@localtop} (\emph{minus one}) by
% \csbc{etoclocaltop}. Under checksemptinesstrue regime its value is already
% known, but it will be obtained again from the toc file execution. As it is
% used only if TOC is active, resetting it here this way is decorative and
% could be removed.
%    \begin{macrocode}
    \gdef\etoclocaltop{-\thr@@}%
    \Etoc@toctoc
    \etocaftercontentshook
}%
\def\Etoc@tableofcontents@etoc@after{%
    \@nobreakfalse
    \Etoc@restoretocdepth
%    \end{macrocode}
% \csa{contentsline} was set to \csbc{Etoc@etoccontentsline} by a non-global |\let|,
% and it will recover its normal value from exiting a scope limiting group.
% But \ctanpkg{tableof} (since |1.4a|) under \csbc{etocglobaldefs} does a global
% redefinition of \csa{contentsline}.  Its \csa{tof@finish} then does a global
% restore of \csa{contentsline}, but it will be to the \etoc set
% value. \csa{tof@finish} is active only if either the table of contents was
% typeset using \csa{tableof}, \csa{tablenotof}, \csa{tableoftaggedcontents}, or
% \csa{nextocwithtags} was used.  If not active it is either undefined (no
% package \ctanpkg{tableof}) or |\@empty|. Prior to \ctanpkg{tableof} |1.4c|, the
% \csa{tof@finish} closed a group and could be undefined as well, but not if
% \csbc{etocglobaldefs}.
%
% If rather than |\@empty| the \csa{tof@finish} fall-back was |\relax| we could
% use here \csa{@ifundefined} to check in one go (matters of speaking because
% expansion of \csa{@ifundefined} is not in "one-go"). Maybe I should update
% \ctanpkg{tableof}, but for time being I will simply add an extra test. All this is
% probably lots of time on irrelevant issue.
%    \begin{macrocode}
    \ifx\Etoc@global\global
     \@ifundefined{tof@finish}
     {}
     {\ifx\tof@finish\@empty
      \else
       \global\let\contentsline\Etoc@savedcontentsline
      \fi
     }%
    \fi
}
%    \end{macrocode}
% Refactored at \etocrelease{1.2} to check if the style is actually known
% and its level is from |-1| (|-2| in memoir class) to |5| inclusive.
% If not raise a warning.
%    \begin{macrocode}
\def\etocsetstyle#1{\ifcsname Etoc@#1@@\endcsname
                      \expandafter\Etoc@setstyle@a
                    \else
                      \expandafter\Etoc@setstyle@error
                    \fi {#1}%
}
\def\Etoc@setstyle@error #1{%
    \PackageWarning{etoc}{`#1' is unknown to etoc. \space Did you\MessageBreak
                    forget some \string\etocsetlevel{#1}{<level>}?\MessageBreak
                    Reported}%
    \@gobblefour
}
\def\Etoc@setstyle@a #1{%
    \edef\Etoc@tmp{\the\numexpr\csname Etoc@#1@@\endcsname}%
    \if1\unless\ifnum\Etoc@tmp<\Etoc@maxlevel 0\fi
        \unless\ifnum\Etoc@tmp>\Etoc@minf 0\fi1%
      \Etoc@standardlinesfalse
      \expandafter\Etoc@setstyle@b\expandafter\Etoc@tmp
    \else
      \ifnum\Etoc@tmp=\Etoc@maxlevel
        \in@{.#1,}{.figure,.table,}%
        \ifin@
           \PackageWarning{etoc}
              {You can not use \string\etocsetstyle\space with `#1'.\MessageBreak
               Check the package documentation (in particular about\MessageBreak
               \string\etoclocallistoffigureshook/\string\etoclocallistoftableshook)%
               \MessageBreak on how to customize
               figure and table entries in local\MessageBreak lists. Reported}%
        \else
           \PackageInfo{etoc}
              {Attempt to set the style of `#1',\MessageBreak
               whose level is currently the maximal one \etocthemaxlevel,\MessageBreak
               which is never displayed. \space This will be ignored\MessageBreak
               but note that we do quit compatibility mode.\MessageBreak
               Reported}%
           \Etoc@standardlinesfalse
        \fi
      \else
%    \end{macrocode}
% This branch was actually in the end only for the case of a level equal to
% |-2|, with a document class not \ctanpkg{memoir}, but \etocrelease{1.2a}
% prevents \csbc{etocsetlevel} to use numerical level |-2| in such case.
%    \begin{macrocode}
        \PackageWarning{etoc}{This should not happen.  Reported}%
      \fi
      \expandafter\@gobblefour
    \fi
}
%    \end{macrocode}
% Prior to \etocrelease{1.2} the |#1| here was some alphabetical string
% such as |minusone|.  We now use digit tokens (and minus sign) in the macro
% names.  The ``begin'' macros formerly incorporated
% \csa{Etoc@global}\csa{Etoc@isfirsttrue}.  They are now located in
% \csbc{Etoc@traversestackofends}.
%
% \etocrelease{1.2} adds \csbc{etocstorelinestylesinto}.  And
% \csbc{etocstorethislinestyleinto}.  No error check on the level.
%    \begin{macrocode}
\long\def\Etoc@setstyle@b#1#2#3#4#5{%
     \expandafter\def\csname Etoc@begin@#1\endcsname    {#2}%
     \expandafter\def\csname Etoc@prefix@#1\endcsname   {#3}%
     \expandafter\def\csname Etoc@contents@#1\endcsname {#4}%
     \expandafter\def\csname Etoc@end@#1\endcsname      {#5}%
}
\def\Etoc@setstyle@e#1{%
     \expandafter\let\csname Etoc@begin@#1\endcsname    \@empty
     \expandafter\let\csname Etoc@prefix@#1\endcsname   \@empty
     \expandafter\let\csname Etoc@contents@#1\endcsname \@empty
     \expandafter\let\csname Etoc@end@#1\endcsname      \@empty
}
\def\Etoc@storelines@a#1{%
   \noexpand\Etoc@setstyle@b{#1}%
     {\expandafter\Etoc@expandonce\csname Etoc@begin@#1\endcsname}%
     {\expandafter\Etoc@expandonce\csname Etoc@prefix@#1\endcsname}%
     {\expandafter\Etoc@expandonce\csname Etoc@contents@#1\endcsname}%
     {\expandafter\Etoc@expandonce\csname Etoc@end@#1\endcsname}%
}
\def\Etoc@expandonce#1{\unexpanded\expandafter{#1}}
\def\etocstorelinestylesinto#1{%
    \edef#1{\Etoc@storelines@a{-2}\Etoc@storelines@a{-1}\Etoc@storelines@a{0}%
            \Etoc@storelines@a {1}\Etoc@storelines@a {2}\Etoc@storelines@a{3}%
            \Etoc@storelines@a {4}\Etoc@storelines@a {5}%
            \ifEtoc@deeplevels
              \Etoc@storelines@a{6}\Etoc@storelines@a{7}\Etoc@storelines@a{8}%
              \Etoc@storelines@a{9}\Etoc@storelines@a{10}\Etoc@storelines@a{11}%
            \fi
    }%
}
\def\etocstorethislinestyleinto#1#2{%
    \edef#2{\expandafter\Etoc@storelines@a\expandafter{\number\etoclevel{#1}}}%
}%
%    \end{macrocode}
% Customization macros of the package default line styles.
%    \begin{macrocode}
\def\etocfontminustwo {\normalfont \LARGE \bfseries}
\def\etocfontminusone {\normalfont \large \bfseries}
\def\etocfontzero     {\normalfont \large \bfseries}
\def\etocfontone      {\normalfont \normalsize \bfseries}
\def\etocfonttwo      {\normalfont \normalsize}
\def\etocfontthree    {\normalfont \footnotesize}
%    \end{macrocode}
% placeholder for comments
%    \begin{macrocode}
\def\etocsepminustwo  {4ex \@plus .5ex \@minus .5ex}
\def\etocsepminusone  {4ex \@plus .5ex \@minus .5ex}
\def\etocsepzero      {2.5ex \@plus .4ex \@minus .4ex}
\def\etocsepone       {1.5ex \@plus .3ex \@minus .3ex}
\def\etocseptwo       {.5ex \@plus .1ex \@minus .1ex}
\def\etocsepthree     {.25ex \@plus .05ex \@minus .05ex}
%    \end{macrocode}
% placeholder for comments
%    \begin{macrocode}
\def\etocbaselinespreadminustwo {1}
\def\etocbaselinespreadminusone {1}
\def\etocbaselinespreadzero     {1}
\def\etocbaselinespreadone      {1}
\def\etocbaselinespreadtwo      {1}
\def\etocbaselinespreadthree    {.9}
%    \end{macrocode}
% placeholder for comments
%    \begin{macrocode}
\def\etocminustwoleftmargin  {1.5em plus 0.5fil}
\def\etocminustworightmargin {1.5em plus -0.5fil}
\def\etocminusoneleftmargin  {1em}
\def\etocminusonerightmargin {1em}
\def\etoctoclineleaders
        {\hbox{\normalfont\normalsize\hb@xt@2ex {\hss.\hss}}}
\def\etocabbrevpagename {p.~}
%    \end{macrocode}
% Versions earlier than \etocrelease{1.08b} (and since \etocrelease{1.05} |2012/12/01|) defined
% \csbc{etocpartname} (for use by \etoc's own line styles) to expand to
% \csa{partname}. But this didn't make sense in the context for example of
% \ctanpkg{babel} and \ctanpkg{babel-french}, because \csa{frenchpartname} does things depending on
% the current value of the counter |part|. The code in recent \ctanpkg{babel-french} (but
% not yet |v2.5a| when \csbc{etocpartname} was introduced) constructs control
% sequences \csa{ordinali}, etc... If the part counter is zero, this gives
% \csa{ordinal}. Usually this is not defined, hence no error happens (as it is
% constructed via |\csname|), but under class \ctanpkg{memoir} the bug showed up. All
% this to explain that I found out about this long lasting problem only on
% |2015/03/14|. Probably a sign that \etoc's own line styles are rarely
% used...
%    \begin{macrocode}
\def\etocpartname       {Part}
\def\etocbookname       {Book}
%    \end{macrocode}
% The macro \csbc{etocdefaultlines} was initially called \csbc{etoctoclines}. Now
% \csbc{etoctoclines} just does \csa{Etoc@standardlinesfalse}.
%
% Version \etocrelease{1.09f} wraps \csbc{etocbookname}, respectively
% \csbc{etocpartname}, in the book, resp. part, line styles inside a
% (potential) hyperlink together with the number.
%
% \etocrelease{1.2a} does not define a `book' style if not with
% \ctanpkg{memoir} class as the numerical level |-2| is made available only
% with that class.
%
% Unfortunately \csa{@ifclassloaded} was preamble-only until the |2021-11-15|
% LaTeX release (and also \csa{@ifpackageloaded}).  Anyway let's refactor this
% \csbc{etocdefaultlines} at \etocrelease{1.2a} to use encapsulating macros
% rather than be a single one with gigantic contents.
%    \begin{macrocode}
\def\etocdefaultlines{%
    \Etoc@standardlinesfalse
    \etocdefaultlines@setbook
    \etocdefaultlines@setpart
    \etocdefaultlines@setchapter
    \etocdefaultlines@setsection
    \etocdefaultlines@setsubsection
    \etocdefaultlines@setsubsubsection
    \etocdefaultlines@setdeeperones
}
\@ifclassloaded{memoir}{%
 \def\etocdefaultlines@setbook{%
 \Etoc@setstyle@b
  {-2}%
  {\addpenalty\@M\etocskipfirstprefix}
  {\addpenalty\@secpenalty}
  {\begingroup
   \etocfontminustwo
   \addvspace{\etocsepminustwo}%
   \parindent \z@
   \leftskip  \etocminustwoleftmargin
   \rightskip \etocminustworightmargin
   \parfillskip \@flushglue
   \vbox{\etocifnumbered{\etoclink{\etocbookname\enspace\etocthenumber:\quad}}{}%
         \etocname
         \baselineskip\etocbaselinespreadminustwo\baselineskip
         \par}%
   \addpenalty\@M\addvspace{\etocsepminusone}%
   \endgroup}
  {}%
 }
 }{\let\etocdefaultlines@setbook\@empty}
\def\etocdefaultlines@setpart{%
\Etoc@setstyle@b
  {-1}%
  {\addpenalty\@M\etocskipfirstprefix}
  {\addpenalty\@secpenalty}
  {\begingroup
   \etocfontminusone
   \addvspace{\etocsepminusone}%
   \parindent \z@
   \leftskip  \etocminusoneleftmargin
   \rightskip \etocminusonerightmargin
   \parfillskip \@flushglue
   \vbox{\etocifnumbered{\etoclink{\etocpartname\enspace\etocthenumber.\quad}}{}%
         \etocname
         \baselineskip\etocbaselinespreadminusone\baselineskip
         \par}%
   \addpenalty\@M\addvspace{\etocsepzero}%
   \endgroup}
  {}%
}
\def\etocdefaultlines@setchapter{%
\Etoc@setstyle@b
  {0}%
  {\addpenalty\@M\etocskipfirstprefix}
  {\addpenalty\@itempenalty}
  {\begingroup
   \etocfontzero
   \addvspace{\etocsepzero}%
   \parindent \z@ \parfillskip \@flushglue
   \vbox{\etocifnumbered{\etocnumber.\enspace}{}\etocname
         \baselineskip\etocbaselinespreadzero\baselineskip
         \par}%
   \endgroup}
  {\addpenalty{-\@highpenalty}\addvspace{\etocsepminusone}}%
}
\def\etocdefaultlines@setsection{%
\Etoc@setstyle@b
  {1}%
  {\addpenalty\@M\etocskipfirstprefix}
  {\addpenalty\@itempenalty}
  {\begingroup
   \etocfontone
   \addvspace{\etocsepone}%
   \parindent \z@ \parfillskip \z@
   \setbox\z@\vbox{\parfillskip\@flushglue
                   \etocname\par
                   \setbox\tw@\lastbox
                   \global\setbox\@ne\hbox{\unhbox\tw@\ }}%
   \dimen\z@=\wd\@ne
   \setbox\z@=\etoctoclineleaders
   \advance\dimen\z@\wd\z@
   \etocifnumbered
     {\setbox\tw@\hbox{\etocnumber, \etocabbrevpagename\etocpage}}
     {\setbox\tw@\hbox{\etocabbrevpagename\etocpage}}%
   \advance\dimen\z@\wd\tw@
   \ifdim\dimen\z@ < \linewidth
       \vbox{\etocname~%
             \leaders\box\z@\hfil\box\tw@
             \baselineskip\etocbaselinespreadone\baselineskip
             \par}%
   \else
       \vbox{\etocname~%
             \leaders\copy\z@\hfil\break
             \hbox{}\leaders\box\z@\hfil\box\tw@
             \baselineskip\etocbaselinespreadone\baselineskip
             \par}%
   \fi
   \endgroup}
  {\addpenalty\@secpenalty\addvspace{\etocsepzero}}%
}
\def\etocdefaultlines@setsubsection{%
\Etoc@setstyle@b
  {2}%
  {\addpenalty\@medpenalty\etocskipfirstprefix}
  {\addpenalty\@itempenalty}
  {\begingroup
   \etocfonttwo
   \addvspace{\etocseptwo}%
   \parindent \z@ \parfillskip \z@
   \setbox\z@\vbox{\parfillskip\@flushglue
                   \etocname\par\setbox\tw@\lastbox
                   \global\setbox\@ne\hbox{\unhbox\tw@}}%
   \dimen\z@=\wd\@ne
   \setbox\z@=\etoctoclineleaders
   \advance\dimen\z@\wd\z@
   \etocifnumbered
     {\setbox\tw@\hbox{\etocnumber, \etocabbrevpagename\etocpage}}
     {\setbox\tw@\hbox{\etocabbrevpagename\etocpage}}%
   \advance\dimen\z@\wd\tw@
   \ifdim\dimen\z@ < \linewidth
       \vbox{\etocname~%
             \leaders\box\z@\hfil\box\tw@
             \baselineskip\etocbaselinespreadtwo\baselineskip
             \par}%
   \else
       \vbox{\etocname~%
             \leaders\copy\z@\hfil\break
             \hbox{}\leaders\box\z@\hfil\box\tw@
             \baselineskip\etocbaselinespreadtwo\baselineskip
             \par}%
   \fi
   \endgroup}
  {\addpenalty\@secpenalty\addvspace{\etocsepone}}%
}
\def\etocdefaultlines@setsubsubsection{%
\Etoc@setstyle@b
  {3}%
  {\addpenalty\@M
   \etocfontthree
   \vspace{\etocsepthree}%
   \noindent
   \etocskipfirstprefix}
  {\allowbreak\,--\,}
  {\etocname}
  {.\hfil
    \begingroup
     \baselineskip\etocbaselinespreadthree\baselineskip
     \par
    \endgroup
   \addpenalty{-\@highpenalty}}
}
\def\etocdefaultlines@setdeeperones{%
\Etoc@setstyle@e{4}%
\Etoc@setstyle@e{5}%
\ifEtoc@deeplevels
  \Etoc@setstyle@e{6}%
  \Etoc@setstyle@e{7}%
  \Etoc@setstyle@e{8}%
  \Etoc@setstyle@e{9}%
  \Etoc@setstyle@e{10}%
  \Etoc@setstyle@e{11}%
\fi
}
%    \end{macrocode}
% The \csbc{etocinnertopsep} default value is too big as well as \csbc{etocbelowtocskip}
% and \csbc{etocabovetocskip}, I guess, but if I am remember correctly I chose them
% to mimick the standard TOC spacings in |article| class.
%    \begin{macrocode}
\def\etocabovetocskip{3.5ex \@plus 1ex \@minus .2ex}
\def\etocbelowtocskip{3.5ex \@plus 1ex \@minus .2ex}
\def\etoccolumnsep{2em}
\def\etocmulticolsep{0ex}
\def\etocmulticolpretolerance{-1}
\def\etocmulticoltolerance{200}
\def\etocdefaultnbcol{2}
\def\etocinnertopsep{2ex}
\newcommand\etocmulticolstyle[2][\etocdefaultnbcol]{%
\etocsettocstyle
   {\let\etocoldpar\par
    \addvspace{\etocabovetocskip}%
    \ifnum #1>\@ne
          \expandafter\@firstoftwo
    \else \expandafter\@secondoftwo
    \fi
    {\multicolpretolerance\etocmulticolpretolerance
    \multicoltolerance\etocmulticoltolerance
    \setlength{\columnsep}{\etoccolumnsep}%
    \setlength{\multicolsep}{\etocmulticolsep}%
    \begin{multicols}{#1}[#2\etocoldpar\addvspace{\etocinnertopsep}]}
    {#2\ifvmode\else\begingroup\interlinepenalty\@M\parskip\z@skip
                    \@@par\endgroup
       \fi
       \nobreak\addvspace{\etocinnertopsep}%
       \pretolerance\etocmulticolpretolerance
       \tolerance\etocmulticoltolerance}%
   }%
   {\ifnum #1>\@ne
          \expandafter\@firstofone
    \else \expandafter\@gobble
    \fi
    {\end{multicols}}%
    \addvspace{\etocbelowtocskip}}%
}
%    \end{macrocode}
% placeholder for comments
%    \begin{macrocode}
\def\etocinnerbottomsep{3.5ex}
\def\etocinnerleftsep{2em}
\def\etocinnerrightsep{2em}
\def\etoctoprule{\hrule}
\def\etocleftrule{\vrule}
\def\etocrightrule{\vrule}
\def\etocbottomrule{\hrule}
\def\etoctoprulecolorcmd{\relax}
\def\etocbottomrulecolorcmd{\relax}
\def\etocleftrulecolorcmd{\relax}
\def\etocrightrulecolorcmd{\relax}
%    \end{macrocode}
% placeholder
%    \begin{macrocode}
\def\etoc@ruledheading #1{%
   \hb@xt@\linewidth{\color@begingroup
          \hss #1\hss\hskip-\linewidth
          \etoctoprulecolorcmd\leaders\etoctoprule\hss
          \phantom{#1}%
          \leaders\etoctoprule\hss\color@endgroup}%
          \nointerlineskip\nobreak\vskip\etocinnertopsep}
\newcommand*\etocruledstyle[2][\etocdefaultnbcol]{%
\etocsettocstyle
   {\addvspace{\etocabovetocskip}%
    \ifnum #1>\@ne
          \expandafter\@firstoftwo
    \else \expandafter\@secondoftwo
    \fi
       {\multicolpretolerance\etocmulticolpretolerance
        \multicoltolerance\etocmulticoltolerance
        \setlength{\columnsep}{\etoccolumnsep}%
        \setlength{\multicolsep}{\etocmulticolsep}%
        \begin{multicols}{#1}[\etoc@ruledheading{#2}]}
       {\etoc@ruledheading{#2}%
         \pretolerance\etocmulticolpretolerance
         \tolerance\etocmulticoltolerance}}
   {\ifnum #1>\@ne\expandafter\@firstofone
         \else \expandafter\@gobble
    \fi
    {\end{multicols}}%
    \addvspace{\etocbelowtocskip}}}
%    \end{macrocode}
% placeholder
%    \begin{macrocode}
\def\etocframedmphook{\relax}
\long\def\etocbkgcolorcmd{\relax}
\long\def\Etoc@relax{\relax}
%    \end{macrocode}
% placeholder for comments
%    \begin{macrocode}
\newbox\etoc@framed@titlebox
\newbox\etoc@framed@contentsbox
\newcommand*\etocframedstyle[2][\etocdefaultnbcol]{%
\etocsettocstyle{%
    \addvspace{\etocabovetocskip}%
    \sbox\z@{#2}%
    \dimen\z@\dp\z@
    \ifdim\wd\z@<\linewidth \dp\z@\z@ \else \dimen\z@\z@ \fi
    \setbox\etoc@framed@titlebox=\hb@xt@\linewidth{\color@begingroup
        \hss
        \ifx\etocbkgcolorcmd\Etoc@relax
        \else
            \sbox\tw@{\color{white}%
            \vrule\@width\wd\z@\@height\ht\z@\@depth\dimen\z@}%
            \ifdim\wd\z@<\linewidth \dp\tw@\z@\fi
            \box\tw@
            \hskip-\wd\z@
        \fi
        \copy\z@
        \hss
        \hskip-\linewidth
        \etoctoprulecolorcmd\leaders\etoctoprule\hss
        \hskip\wd\z@
        \etoctoprulecolorcmd\leaders\etoctoprule\hss\color@endgroup}%
    \setbox\z@\hbox{\etocleftrule\etocrightrule}%
    \dimen\tw@\linewidth\advance\dimen\tw@-\wd\z@
        \advance\dimen\tw@-\etocinnerleftsep
        \advance\dimen\tw@-\etocinnerrightsep
    \setbox\etoc@framed@contentsbox=\vbox\bgroup
        \hsize\dimen\tw@
        \kern\dimen\z@
        \vskip\etocinnertopsep
        \hbox\bgroup
        \begin{minipage}{\hsize}%
        \etocframedmphook
    \ifnum #1>\@ne
          \expandafter\@firstoftwo
    \else \expandafter\@secondoftwo
    \fi
        {\multicolpretolerance\etocmulticolpretolerance
        \multicoltolerance\etocmulticoltolerance
        \setlength{\columnsep}{\etoccolumnsep}%
        \setlength{\multicolsep}{\etocmulticolsep}%
        \begin{multicols}{#1}}
        {\pretolerance\etocmulticolpretolerance
         \tolerance\etocmulticoltolerance}}
    {\ifnum #1>\@ne\expandafter\@firstofone
         \else \expandafter\@gobble
     \fi
      {\end{multicols}\unskip }%
    \end{minipage}%
    \egroup
    \vskip\etocinnerbottomsep
    \egroup
    \vbox{\hsize\linewidth
        \ifx\etocbkgcolorcmd\Etoc@relax
        \else
            \kern\ht\etoc@framed@titlebox
            \kern\dp\etoc@framed@titlebox
            \hb@xt@\linewidth{\color@begingroup
            \etocleftrulecolorcmd\etocleftrule
            \etocbkgcolorcmd
            \leaders\vrule
                   \@height\ht\etoc@framed@contentsbox
                   \@depth\dp\etoc@framed@contentsbox
            \hss
            \etocrightrulecolorcmd\etocrightrule
            \color@endgroup}\nointerlineskip
            \vskip-\dp\etoc@framed@contentsbox
            \vskip-\ht\etoc@framed@contentsbox
            \vskip-\dp\etoc@framed@titlebox
            \vskip-\ht\etoc@framed@titlebox
        \fi
    \box\etoc@framed@titlebox\nointerlineskip
    \hb@xt@\linewidth{\color@begingroup
    {\etocleftrulecolorcmd\etocleftrule}%
    \hss\box\etoc@framed@contentsbox\hss
    \etocrightrulecolorcmd\etocrightrule\color@endgroup}
    \nointerlineskip
    \vskip\ht\etoc@framed@contentsbox
    \vskip\dp\etoc@framed@contentsbox
    \hb@xt@\linewidth{\color@begingroup\etocbottomrulecolorcmd
          \leaders\etocbottomrule\hss\color@endgroup}}
    \addvspace{\etocbelowtocskip}}}
%    \end{macrocode}
% For time being I will not however add the versions for ``lists of'', as
% anyhow probably nobody apart myself ever uses these things.
%
% It is impossible to know what kind of division heading |#2| uses, so there
% is not much I can do here at \etocrelease{1.2} apart from providing a
% user interface for adding the suitable thing to the |.toc| file.  And I
% discover at time of writing (finishing the \etocrelease{1.2}
% documentation) that I already have \csbc{etoclocalheadtotoc}.  I only need to
% add \csbc{etocglobalheadtotoc}.
%    \begin{macrocode}
\newcommand\etoc@multicoltoc[2][\etocdefaultnbcol]{%
    \etocmulticolstyle[#1]{#2}%
    \tableofcontents}
\newcommand\etoc@multicoltoci[2][\etocdefaultnbcol]{%
    \etocmulticolstyle[#1]{#2}%
    \tableofcontents*}
\newcommand\etoc@local@multicoltoc[2][\etocdefaultnbcol]{%
    \etocmulticolstyle[#1]{#2}%
    \localtableofcontents}
\newcommand\etoc@local@multicoltoci[2][\etocdefaultnbcol]{%
    \etocmulticolstyle[#1]{#2}%
    \localtableofcontents*}
%    \end{macrocode}
% placeholder for comments
%    \begin{macrocode}
\newcommand*\etoc@ruledtoc[2][\etocdefaultnbcol]{%
    \etocruledstyle[#1]{#2}%
    \tableofcontents}
\newcommand*\etoc@ruledtoci[2][\etocdefaultnbcol]{%
    \etocruledstyle[#1]{#2}%
    \tableofcontents*}
\newcommand*\etoc@local@ruledtoc[2][\etocdefaultnbcol]{%
    \etocruledstyle[#1]{#2}%
    \localtableofcontents}
\newcommand*\etoc@local@ruledtoci[2][\etocdefaultnbcol]{%
    \etocruledstyle[#1]{#2}%
    \localtableofcontents*}
%    \end{macrocode}
% placeholder for comments
%    \begin{macrocode}
\newcommand*\etoc@framedtoc[2][\etocdefaultnbcol]{%
    \etocframedstyle[#1]{#2}%
    \tableofcontents}
\newcommand*\etoc@framedtoci[2][\etocdefaultnbcol]{%
    \etocframedstyle[#1]{#2}%
    \tableofcontents*}
\newcommand*\etoc@local@framedtoc[2][\etocdefaultnbcol]{%
    \etocframedstyle[#1]{#2}%
    \localtableofcontents}
\newcommand*\etoc@local@framedtoci[2][\etocdefaultnbcol]{%
    \etocframedstyle[#1]{#2}%
    \localtableofcontents*}
%    \end{macrocode}
% placeholder for comments
%    \begin{macrocode}
\def\etocmulticol{\begingroup
    \Etoc@mustclosegrouptrue
    \@ifstar
    {\etoc@multicoltoci}
    {\etoc@multicoltoc}}
\def\etocruled{\begingroup
    \Etoc@mustclosegrouptrue
    \@ifstar
    {\etoc@ruledtoci}
    {\etoc@ruledtoc}}
\def\etocframed{\begingroup
    \Etoc@mustclosegrouptrue
    \@ifstar
    {\etoc@framedtoci}
    {\etoc@framedtoc}}
\def\etoclocalmulticol{\begingroup
    \Etoc@mustclosegrouptrue
    \@ifstar
    {\etoc@local@multicoltoci}
    {\etoc@local@multicoltoc}}
\def\etoclocalruled{\begingroup
    \Etoc@mustclosegrouptrue
    \@ifstar
    {\etoc@local@ruledtoci}
    {\etoc@local@ruledtoc}}
\def\etoclocalframed{\begingroup
    \Etoc@mustclosegrouptrue
    \@ifstar
    {\etoc@local@framedtoci}
    {\etoc@local@framedtoc}}
%    \end{macrocode}
% \etocrelease{1.2} makes local TOCs in compatibility display style use
% |\subsection*| rather than |\section*|.  This is not good for local TOCs to
% a |\part| but anyhow the default is via \csbc{etocetoclocaltocstyle} which
% will do the right thing and the change here is irrelevant.  More comments
% below about handling \ctanpkg{memoir} and \ctanpkg{KOMA-script}.
%
% The macros next will be modified if under |book| or \ctanpkg{memoir} class.
% The \ctanpkg{KOMA-script} case uses rather the |leveldown| mechanism.
% These local TOCs things are used only under \csbc{etocclasstocstyle}.
% With \csbc{etocetoclocaltocstyle}, they are not used.
%    \begin{macrocode}
\def\etocmemoirtoctotocfmt #1#2{%
    \PackageWarning{etoc}
        {\string\etocmemoirtoctotocfmt\space is deprecated.\MessageBreak
         Use in its place \string\etocsettoclineforclasstoc,\MessageBreak
         and \string\etocsettoclineforclasslistof{toc} (or {lof}, {lot}).
         I will do this now.\MessageBreak
         Reported}%
    \etocsettoclineforclasstoc{#1}{#2}%
    \etocsettoclineforclasslistof{toc}{#1}{#2}%
}
\def\etocsettoclineforclasstoc #1#2{%
    \def\etocclassmaintocaddtotoc{\etocglobalheadtotoc{#1}{#2}}%
}
\def\etocsettoclineforclasslistof #1#2#3{%
    \@namedef{etocclasslocal#1addtotoc}{\etoclocalheadtotoc{#2}{#3}}%
}
\let\etocclasslocaltocaddtotoc\@empty
\let\etocclasslocallofaddtotoc\@empty
\let\etocclasslocallotaddtotoc\@empty
\ifdefined\c@chapter
  \def\etocclasslocaltocmaketitle{\section*{\localcontentsname}}
  \def\etocclasslocallofmaketitle{\section*{\locallistfigurename}}
  \def\etocclasslocallotmaketitle{\section*{\locallisttablename}}
  \etocsettoclineforclasstoc        {chapter}{\contentsname}
  \etocsettoclineforclasslistof{toc}{section}{\localcontentsname}
  \etocsettoclineforclasslistof{lof}{section}{\locallistfigurename}
  \etocsettoclineforclasslistof{lot}{section}{\locallisttablename}
\else
  \def\etocclasslocaltocmaketitle{\subsection*{\localcontentsname}}%
  \def\etocclasslocallofmaketitle{\subsection*{\locallistfigurename}}%
  \def\etocclasslocallotmaketitle{\subsection*{\locallisttablename}}%
  \etocsettoclineforclasstoc        {section}{\contentsname}
  \etocsettoclineforclasslistof{toc}{subsection}{\localcontentsname}
  \etocsettoclineforclasslistof{lof}{subsection}{\locallistfigurename}
  \etocsettoclineforclasslistof{lot}{subsection}{\locallisttablename}
\fi
%    \end{macrocode}
% This is moved to a macro to localize complications with conditionals.
%    \begin{macrocode}
\def\etocclasslocalperhapsaddtotoc #1{%
    \etocifisstarred
      {}
      {\csname ifEtoc@local#1totoc\endcsname
         \csname etocclasslocal#1addtotoc\endcsname
       \fi
      }%
}
%    \end{macrocode}
% No need for a \csa{phantomsection} if the \csa{addcontentsline} is after
% |\section*|.  For the standard classes, I make no effort to adjust level
% used for the local heading if it is local to a \csa{part}, not a
% \csa{section}.  Anyhow this code will not be used by default for
% local TOCs due to \csbc{etocetoclocaltocstyle}.
%    \begin{macrocode}
\def\etocarticlestyle{%
    \etocsettocstyle
    {\ifEtoc@localtoc
       \@nameuse{etocclasslocal\Etoc@currext maketitle}%
       \etocclasslocalperhapsaddtotoc\Etoc@currext
     \else
       \section *{\contentsname
                  \@mkboth {\MakeUppercase \contentsname}
                           {\MakeUppercase \contentsname}}%
       \etocifisstarred{}{\etocifmaintoctotoc{\etocclassmaintocaddtotoc}{}}%
     \fi
    }
    {}%
}
\def\etocarticlestylenomarks{%
    \etocsettocstyle
    {\ifEtoc@localtoc
       \@nameuse{etocclasslocal\Etoc@currext maketitle}%
       \etocclasslocalperhapsaddtotoc\Etoc@currext
     \else
       \section *{\contentsname}%
       \etocifisstarred{}{\etocifmaintoctotoc{\etocclassmaintocaddtotoc}{}}%
     \fi
    }
    {}%
}
%    \end{macrocode}
% Make definitions with |book| in the macro names or redefine them
% for |book|? Chose the latter.
%    \begin{macrocode}
\def\etocbookstyle{%
    \etocsettocstyle
    {\if@twocolumn \@restonecoltrue \onecolumn \else \@restonecolfalse \fi
     \ifEtoc@localtoc
       \@nameuse{etocclasslocal\Etoc@currext maketitle}%
       \etocclasslocalperhapsaddtotoc\Etoc@currext
     \else
       \chapter *{\contentsname
                  \@mkboth {\MakeUppercase \contentsname}
                           {\MakeUppercase \contentsname}}%
       \etocifisstarred{}{\etocifmaintoctotoc{\etocclassmaintocaddtotoc}{}}%
     \fi
    }%
    {\if@restonecol \twocolumn \fi}%
}
\def\etocbookstylenomarks{%
    \etocsettocstyle
    {\if@twocolumn \@restonecoltrue \onecolumn \else \@restonecolfalse \fi
     \ifEtoc@localtoc
       \@nameuse{etocclasslocal\Etoc@currext maketitle}%
       \etocclasslocalperhapsaddtotoc\Etoc@currext
     \else
       \chapter *{\contentsname}%
       \etocifisstarred{}{\etocifmaintoctotoc{\etocclassmaintocaddtotoc}{}}%
     \fi
    }%
    {\if@restonecol \twocolumn \fi}%
}
\let\etocreportstyle\etocbookstyle
\let\etocreportstylenomarks\etocbookstylenomarks
%    \end{macrocode}
% |v3.7i| of memoir has moved the \csa{phantomsection} to a better location,
% before typesetting the title and we follow suit at \etocrelease{1.09a}, and
% at \etocrelease{1.09b}.  Formerly \etoc used \csbc{etocaftertitlehook} to
% mimick the memoir code but as its name indicate, it is supposedly executed
% after the title... and this also had the defect of making
% \csbc{etocaftertitlehook} not anymore a user command.  Thus we here use some
% refactoring of the \csbc{Etoc@aftertitlehook} internal mechanism to help
% recognize if we are in the starred case or not.
%
% \csa{phantomsection} is always defined by memoir, empty if hyperref absent.
%
% Updates at \etocrelease{1.2} for the standard display style inherited
% from the class to actually be usable with local table of contents.
% Unfortunately the printing of the title rigidly hard-codes a
% |\thispagestyle{chapter}|:
% \begin{verbatim}
% \@lofmaketitle ->\@nameuse {lofheadstart} {\parindent \z@ \parskip \z@ \interli
% nepenalty \@M \@nameuse {printlofnonum}\@nameuse {printloftitle}{\listfigurenam
% e }\@nameuse {lofmark}\thispagestyle {chapter}\@nameuse {afterloftitle} } \@aft
% erheading
% \end{verbatim}
% \vskip-\baselineskip
% Oh well I discover there is a \csa{chapterheadstart} but not
% \csa{sectionheadstart}...
%
% Actually now \etoc will by default not use the class inherited style for the
% local TOC titles, so maybe I should have not wasted time on this.  From the
% \csbc{etocsettocstyle} arguments one can know if this is for a local TOC,
% but one can not know the level, which is inferred from the actual execution
% of the TOC data.  There is a problem though that the \ctanpkg{memoir}
% default would be usable for a local TOC in a |\part|.  Although one can
% argue if it makes sense to display a TOC as prominently as a chapter anyway.
% Again, the default with \etoc will anyhow not use this as
% \csbc{etocetoclocaltocstyle} deactivates the \csbc{etocsettocstyle} for
% local TOCs.
%
% MEMO: would it make sense to have an \csa{etocsetlocaltocstyle}?  As
% explained above this would however induced dramatic internal \etoc changes as one
% would have to wait for title insertion until the time one knows the local
% level.  Which is exactly what \csbc{etocetoclocaltocstyle}  via the
% \csbc{ifEtoc@etocstyle} does.
%
% Update at \etocrelease{1.2} to account for \csbc{locallistoffigures} and
% \csbc{locallistoftables}.
%    \begin{macrocode}
\def\etocmemoirstyle{%
    \etocsettocstyle
        {\ensureonecol \par \begingroup \phantomsection
         \ifx\Etoc@aftertitlehook\@empty
         \else
%    \end{macrocode}
% This branch executed for the non-starred variant
%    \begin{macrocode}
           \ifmem@em@starred@listof
           \else
%    \end{macrocode}
% Global case is only for \csa{tableofcontents} as \etoc does not hack into
% \csa{listofpictures} and \csa{listoftables}.
%
% Local case will not be executed in default configurations (cf
% \csbc{etocetoclocaltocstyle}).
%
% \csbc{etocclasslocalperhapsaddtotoc} is to avoid worries with conditionals.
%    \begin{macrocode}
             \ifEtoc@localtoc
                  \etocclasslocalperhapsaddtotoc\Etoc@currext
             \else
               \ifEtoc@maintoctotoc
                  \etocclassmaintocaddtotoc
               \fi
             \fi
           \fi
         \fi
         \ifEtoc@localtoc
         % trying to mimick a section title but there is no \sectionheadstart
         % there is no \printsectiontitle etc... Oh well I will be more
         % radical then
            \@namedef{@\Etoc@currext maketitle}{%
               \@nameuse{etocclasslocal\Etoc@currext maketitle}%
            }%
         \fi
         \@nameuse {@\Etoc@currext maketitle} %<< space token here from memoir code
         \ifx\Etoc@aftertitlehook\@empty
          \else
%    \end{macrocode}
% Execute etoc hook before the \csa{cfttocbeforelisthook} and keep distinction
% between starred and non-starred contexts for other hooks (by testing if
% \csbc{Etoc@aftertitlehook} is empty or not). Notice that the memoir class
% way of implementing \csbc{tableofcontents} leaves no way for code executed
% by the TOC code to know if it is executed in starred or non-starred context.
%    \begin{macrocode}
          \Etoc@aftertitlehook \let \Etoc@aftertitlehook \relax
         \fi
         \parskip \cftparskip \@nameuse {cft\Etoc@currext beforelisthook}%
        }%
        {\@nameuse {cft\Etoc@currext afterlisthook}%
         \endgroup\restorefromonecol
        }%
}
%    \end{macrocode}
% Compatibility layer for the \ctanpkg{KOMA-script} classes:
%
% \etocrelease{1.09c} (|2020/05/15|) did an update as \ctanpkg{KOMA-script}
% deprecated \csa{iftocfeature}.  Thanks to Bilel Omrani for report.  I
% did not check if cloning of KOMA code required some further updates.
% \etocrelease{1.09f} added more updates.
%
% At \etocrelease{1.2} this is further updated to be usable also for list
% of figures and tables.  However, this update is somewhat theoretical because
% \etoc does not interfere at all with \csa{listoffigures} and
% \csa{listoftables}: the update is useful only to make \etoc's
% \csbc{locallistoffigures} and \csbc{locallistoftables} usable in display
% style compatibility mode.
%
% But during development on this I became aware that \ctanpkg{KOMA-script}
% since its |3.30| release has the feature that an unnumbered section resets
% the counters of subsections.  This creates a problem (whose description I
% have moved to the user manual) which can be alleviated for local TOCs at the
% highest level below global one by using KOMA's |\setuptoc{toc}{leveldown}|.
% So I decided to do this systematically, as in the code next via a new
% private hook, but the problem will remain for local TOCs at lower levels,
% and there does not seem to be any way to tell KOMA to use say
% |\subsubsection*|, barring, from what I understand from the manual, usage of
% its \csa{deftocheading}.  So in a second stage I decided that per default
% \etoc would rather use for local TOCs, and not only for KOMA classes but all
% classes, an adaptive heading fitted to the ``local top''.  As this ``local
% top'' can only be determined from inside the expansion of \csbc{Etoc@toctoc}
% which contains the |.toc| file data, the boolean \csbc{ifEtoc@etocstyle}
% was added which will make \csbc{etocsettocstyle} configuration ignored.  In
% this way, with \csbc{etocetoclocaltocstyle}, the document class emulation
% will apply to the global TOC whereas local TOCs will use the adaptive
% scheme.  To avoid duplication other relevant info is moved to the user
% manual.
%
% We put the trigger of |leveldown| for KOMA classes in
% \csbc{Etoc@beforetitlehook}.  So there will be no test with
% \csbc{ifEtoc@localtoc} here contrarily to the case of standard classes
% and memoir.  Again, all of this normally is not relevant as by default \etoc
% \etocrelease{1.2} will use its \csbc{etocetoclocaltocstyle} which
% for local TOCs ignores the emulation code of the main TOC.
%    \begin{macrocode}
\let\Etoc@beforetitlehook\@empty
\if1\@ifclassloaded{scrartcl}0{\@ifclassloaded{scrbook}0{\@ifclassloaded{scrreprt}01}}%
\expandafter\@gobble
\else
%    \end{macrocode}
% Surely paranoid here but I don't have time to go through KOMA documentation
% (I am not really familiar with these classes).
%
% MEMO: I do not know if \ctanpkg{KOMA-script}'s \csa{setuptoc} sets options
% locally or globally.  If globally the code below must be modifed to unset
% the |totoc| option depending on at time of use status of the \etoc own
% |totoc| options.
%    \begin{macrocode}
   \ifdefined\setuptoc
     \def\Etoc@beforetitlehook{%
         \ifEtoc@localtoc
            \etocclasslocalperhapsaddtotoc\Etoc@currext
            \setuptoc{\Etoc@currext}{leveldown}%
         \else
            \etocifisstarred{}{\etocifmaintoctotoc{\setuptoc{toc}{totoc}}}%
         \fi
     }%
   \fi
\expandafter\@firstofone
\fi
{\def\etocclasslocalperhapsaddtotoc #1{%
    \etocifisstarred
    {}%
    {\csname ifEtoc@local#1totoc\endcsname
      \setuptoc{\Etoc@currext}{totoc}%
     \fi
    }%
  }%
}
\ifdefined\Iftocfeature
  \def\etoc@Iftocfeature{\Iftocfeature}%
\else
  \def\etoc@Iftocfeature{\iftocfeature}%
\fi
%    \end{macrocode}
% Peut-être en fait je devrais toujours faire |\let\if@dynlist\if@tocleft|?
% Mais je ne l'ai pas vu dans le code de KOMA pour les LOF et LOT (globales,
% évidemment).  Mais cela m'obligerait à lire vraiment le code source de KOMA.
% Pas le temps.
%    \begin{macrocode}
\def\etocscrartclstyle{%
    \etocsettocstyle
        {\ifx\Etoc@currext\Etoc@tocext
             \expandafter\@firstofone
         \else
             \expandafter\@gobble
         \fi
         {\let\if@dynlist\if@tocleft}%
         \edef\@currext{\Etoc@currext}%
         \@ifundefined{listof\@currext name}%
            {\def\list@fname{\listofname~\@currext}}%
            {\expandafter\let\expandafter\list@fname
                         \csname listof\@currext name\endcsname}%
         \etoc@Iftocfeature {\@currext}{onecolumn}
             {\etoc@Iftocfeature {\@currext}{leveldown}
              {}
              {\if@twocolumn \aftergroup \twocolumn \onecolumn \fi }}
             {}%
         \etoc@Iftocfeature {\@currext}{numberline}%
                            {\def \nonumberline {\numberline {}}}{}%
         \expandafter\tocbasic@listhead\expandafter {\list@fname}%
         \begingroup \expandafter \expandafter \expandafter
         \endgroup \expandafter
         \ifx
             \csname microtypesetup\endcsname \relax
         \else
             \etoc@Iftocfeature {\@currext}{noprotrusion}{}
                 {\microtypesetup {protrusion=false}%
                  \PackageInfo {tocbasic}%
                  {character protrusion at \@currext\space deactivated}}%
         \fi
         \etoc@Iftocfeature{\@currext}{noparskipfake}{}{%
               \ifvmode \@tempskipa\lastskip \vskip-\lastskip
               \addtolength{\@tempskipa}{\parskip}\vskip\@tempskipa\fi
               }%
         \setlength {\parskip }{\z@ }%
         \setlength {\parindent }{\z@ }%
         \setlength {\parfillskip }{\z@ \@plus 1fil}%
         \csname tocbasic@@before@hook\endcsname
         \csname tb@\@currext @before@hook\endcsname
      }% end of before_toc
      {% start of after_toc
%    \end{macrocode}
% (This next discussion has not been revised at \etocrelease{1.2} so let's
% hope it is fine).
%
% At \etocrelease{1.09f} I considered adding this \csa{BeforeClosingMainAux} hunk
% to the second argument of \csbc{etocsettocstyle}-emulation of \ctanpkg{KOMA-script}.
% But:
% \begin{itemize}
% \item there seems to be no interface to \csa{tocbasic@end@toc@file},
%
% \item
%   it defaults to issuing a \csa{par}, but we want etoc to still be able
%   to produce other TOCs, possibly inline, and they should not be
%   influenced by it and I don't want at this stage to add an interface
%   to enable/disable and have to document it,
%
% \item
%   the whole thing appears to me to be ill-conceived in so far as it
%   sort of implies the \csbc{tableofcontents} is used only once, as each
%   instance will again add this \csa{tocbasic@end@toc@file} to end of
%   toc file, which may thus end up being executed multiple times.
% \end{itemize}
% So rather than putting the thing in the |.toc| file, we will execute
% it here.  This way it will not impact other TOCs typeset via etoc
% design facilities in the document.
%    \begin{macrocode}
%          \BeforeClosingMainAux
%          {\addtocontents
%            {toc}{\string\providecommand\string\tocbasic@end@toc@file{}%
%                  \string\tocbasic@end@toc@file}%
%          }%
         \providecommand\tocbasic@end@toc@file{}\tocbasic@end@toc@file
         \edef\@currext{\Etoc@currext}%
         \csname tb@\@currext @after@hook\endcsname
         \csname tocbasic@@after@hook\endcsname
     }% end of after_toc
}
\let\etocscrbookstyle\etocscrartclstyle
\let\etocscrreprtstyle\etocscrartclstyle
%    \end{macrocode}
% The \csbc{etocclasstocstyle} will be redefined according to document
% class.  Then, later, it will be extended with an
% \csa{Etoc@classstyletrue}.
%    \begin{macrocode}
\def\etocclasstocstyle{\etocarticlestyle}
\newcommand*\etocmarkboth[1]{%
    \@mkboth{\MakeUppercase{#1}}{\MakeUppercase{#1}}}
\newcommand*\etocmarkbothnouc[1]{\@mkboth{#1}{#1}}
\newcommand\etoctocstyle[3][section]{\etocmulticolstyle[#2]%
    {\csname #1\endcsname *{#3}}}
\newcommand\etoctocstylewithmarks[4][section]{\etocmulticolstyle[#2]%
    {\csname #1\endcsname *{#3\etocmarkboth{#4}}}}
\newcommand\etoctocstylewithmarksnouc[4][section]{\etocmulticolstyle[#2]%
    {\csname #1\endcsname *{#3\etocmarkbothnouc{#4}}}}
\def\Etoc@redefetocstylesforchapters{%
    \renewcommand\etoctocstylewithmarks[4][chapter]{%
          \etocmulticolstyle[##2]{\csname ##1\endcsname *{##3\etocmarkboth{##4}}}%
    }
    \renewcommand\etoctocstylewithmarksnouc[4][chapter]{%
          \etocmulticolstyle[##2]{\csname ##1\endcsname *{##3\etocmarkbothnouc{##4}}}%
    }
    \renewcommand\etoctocstyle[3][chapter]{%
          \etocmulticolstyle[##2]{\csname ##1\endcsname *{##3}}
    }
}
\@ifclassloaded{scrartcl}
    {\renewcommand*\etocclasstocstyle{\etocscrartclstyle}}{}
\@ifclassloaded{book}
    {\renewcommand*\etocfontone{\normalfont\normalsize}
     \renewcommand*\etocclasstocstyle{\etocbookstyle}
     \Etoc@redefetocstylesforchapters}{}
\@ifclassloaded{report}
    {\renewcommand*\etocfontone{\normalfont\normalsize}
     \renewcommand*\etocclasstocstyle{\etocreportstyle}
     \Etoc@redefetocstylesforchapters}{}
\@ifclassloaded{scrbook}
    {\renewcommand*\etocfontone{\normalfont\normalsize}
     \renewcommand*\etocclasstocstyle{\etocscrbookstyle}
     \Etoc@redefetocstylesforchapters}{}
\@ifclassloaded{scrreprt}
    {\renewcommand*\etocfontone{\normalfont\normalsize}
     \renewcommand*\etocclasstocstyle{\etocscrreprtstyle}
     \Etoc@redefetocstylesforchapters}{}
\@ifclassloaded{memoir}
    {\renewcommand*\etocfontone{\normalfont\normalsize}
     \renewcommand*\etocclasstocstyle{\etocmemoirstyle}
     \Etoc@redefetocstylesforchapters}{}
\def\etoctocloftstyle {%
    \etocsettocstyle{%
      \@cfttocstart
      \par
      \begingroup
        \parindent\z@ \parskip\cftparskip
%    \end{macrocode}
% I don't feel like redefining \csa{@cftmaketoctitle} etc to apply ``level
% down''.  Up to the user to use the tocloft interface after the main TOC
% to do appropriate actions.  I consider emitting a warning, but then if
% the user has customize \csa{@cftmaketoctitle} or variant, how to know?
% (apart from numerous ifx tests).
%    \begin{macrocode}
        \@nameuse{@cftmake\Etoc@currext title}%
%    \end{macrocode}
% But for adding an appropriate entry to the toc file I can intervene silently.
% I can remove the test \csa{if@cfttocbibind} here as anyhow I have to test
% status of \etoc `to toc' options.
%    \begin{macrocode}
        \ifEtoc@localtoc
           \etoctocloftlocalperhapsaddtotoc\Etoc@currext
        \else
           \etocifisstarred {}{\ifEtoc@maintoctotoc\@cftdobibtoc\fi}%
        \fi
    }%
    {%
      \endgroup
      \@cfttocfinish
    }%
}
\def\etoctocloftlocalperhapsaddtotoc#1{%
    \etocifisstarred
      {}%
      {\csname ifEtoc@local#1totoc\endcsname
        \ifdefined\c@chapter\def\@tocextra{@section}\else\def\@tocextra{@subsection}\fi
        \csname @cftdobib#1\endcsname
       \fi
      }%
}
%    \end{macrocode}
% This is active only if \ctanpkg{tocbibind} boolean \csa{if@dotoctoc} is found
% true at begin document and there was no use of \csbc{etocsettocstyle} in the
% preamble.  The part on local TOC also applies to local LOF and LOT but is
% executed only if \csbc{etocclasstocstyle} was present in the preamble.  Under
% the default \csbc{etocetoclocaltocstyle}, only the global TOC is under
% influence of this (assuming thus that \ctanpkg{tocbibind} was loaded without
% its |nottoc| or |none| option).
%    \begin{macrocode}
\def\etoctocbibindstyle {%
    \etocsettocstyle {%
      \toc@start
      \ifEtoc@localtoc
          \@nameuse{etocclasslocal\Etoc@currext maketitle}%
          \etocclasslocalperhapsaddtotoc\Etoc@currext
      \else
          \etoc@tocbibind@dotoctitle
      \fi
      }%
    {\toc@finish}%
}
\def\etoc@tocbibind@dotoctitle {%
%    \end{macrocode}
% If \ctanpkg{tocbibind} is loaded but later between |\begin{document}| and
% \csa{tableofcontents} the user does \csbc{etocsetup}|{maintoctotoc=afalse}|
% we have to catch this.
%    \begin{macrocode}
       \if@bibchapter
        \etocifisstarred
          {\chapter*{\contentsname}\prw@mkboth{\contentsname} % id.
          }%
          {\ifEtoc@maintoctotoc
             \toc@chapter{\contentsname} %<-space from original
           \else
             \chapter*{\contentsname}\prw@mkboth{\contentsname} % id.
           \fi
           }%
       \else
        \etocifisstarred
          {\@nameuse{\@tocextra}*{\contentsname\prw@mkboth{\contentsname}} %<-space
          }
          {\ifEtoc@maintoctotoc
             \toc@section{\@tocextra}{\contentsname} %<-space from original
           \else
             \@nameuse{\@tocextra}*{\contentsname\prw@mkboth{\contentsname}} % id.
          \fi
          }%
       \fi
}%
\@ifclassloaded{memoir}
{}
{% memoir not loaded
 \@ifpackageloaded{tocloft}
    {\if@cftnctoc\else
                 \ifEtoc@keeporiginaltoc
                   \else
                   \let\tableofcontents\etoctableofcontents
                 \fi
     \fi }
    {\AtBeginDocument
      {\@ifpackageloaded{tocloft}
       {\if@cftnctoc\else
         \PackageWarningNoLine {etoc}
         {Package `tocloft' was loaded after `etoc'.\MessageBreak
          To prevent it from overwriting \protect\tableofcontents, it will\MessageBreak
          be tricked into believing to have been loaded with its\MessageBreak
          option `titles'. \space But this will cause the `tocloft'\MessageBreak
          customization of the titles of the main list of figures\MessageBreak
          and list of tables to not apply either.\MessageBreak
          You should load `tocloft' before `etoc'.}%
        \AtEndDocument{\PackageWarning{etoc}
                       {Please load `tocloft' before `etoc'!\@gobbletwo}}%
        \fi
        \@cftnctoctrue }%
       {}%
      }%
     }%
}
\@ifclassloaded{memoir}
{}
{% memoir not loaded
  \AtBeginDocument{%
  \@ifpackageloaded{tocloft}
   {%
     \def\etocclasstocstyle{%
       \etoctocloftstyle
       \Etoc@classstyletrue
     }%
     \ifEtoc@etocstyle
        \ifEtoc@classstyle
          \etocclasstocstyle
          \Etoc@etocstyletrue
        \fi
     \else
        \ifEtoc@classstyle
          \etocclasstocstyle
        \fi
     \fi
   }%
   {% no tocloft
    \@ifpackageloaded {tocbibind}
     {\if@dotoctoc
        \def\etocclasstocstyle{%
          \etoctocbibindstyle
          \Etoc@classstyletrue
         }%
        \ifEtoc@etocstyle
           \ifEtoc@classstyle
             \etocclasstocstyle
             \Etoc@etocstyletrue
           \fi
        \else
           \ifEtoc@classstyle
             \etocclasstocstyle
           \fi
        \fi
%    \end{macrocode}
% Not clear if I should interpret \csa{Etoc@keeporiginaltoctrue} in this sense
% to not modify \ctanpkg{tocbibind} overwrite of \csbc{tableofcontents}.  But
% let's obey this interpretation.
%    \begin{macrocode}
        \ifEtoc@keeporiginaltoc
        \else
           \let\tableofcontents\etoctableofcontents
        \fi
     }%
     {}%
   }%
%    \end{macrocode}
% Maybe I should check if the options were already set.  I will simply
% make the message more generic.
%    \begin{macrocode}
   \@ifpackageloaded{tocbibind}
   {% tocbibind, perhaps with tocloft
      \if@dotoctoc
                 \ifEtoc@keeporiginaltoc
                   \else
                   \let\tableofcontents\etoctableofcontents
                 \fi
        \etocsetup{maintoctotoc,localtoctotoc}%
         \PackageInfo{etoc}{%
            Setting (or re-setting) the options `maintoctotoc' and\MessageBreak
            `localtoctotoc' to true as tocbibind was detected and\MessageBreak
            found to be configured for `TOC to toc'.\MessageBreak
            Reported at begin document}%
      \fi
      \if@dotoclof
       \ifEtoc@lof
        \etocsetup{localloftotoc}%
        \PackageInfo{etoc}{%
            Setting (or re-setting) `localloftotoc=true' as the\MessageBreak
            package tocbibind was detected and is configured for\MessageBreak
            `LOF to toc'. Reported at begin document}%
       \fi
      \fi
      \if@dotoclot
       \ifEtoc@lot
        \etocsetup{locallottotoc}%
        \PackageInfo{etoc}{%
            Setting (or re-setting) `locallottotoc=true' as the\MessageBreak
            package tocbibind was detected and is configured for\MessageBreak
            `LOT to toc'. Reported at begin document}%
       \fi
      \fi
   }% end of tocbibind branch
   {}%
  }% end of at begin document
}% end of not with memoir branch
%    \end{macrocode}
% \LaTeX\ 2021 fall release lets \csa{contentsline} always grab four
% arguments, so with \etocrelease{1.09e} |2021/09/23| we make sure our
% \csa{addtocontents} will always provide \csa{contentsline} with four
% arguments. This extra |{}| is done without checking LaTeX's version by
% laziness, as an impact on documents compiled with former LaTeX could be
% visible only with very special contexts that only the author himself would
% ever consider.
%
% Let's also add \csa{protected@file@percent} at \etocrelease{1.09e} although
% this is a priori of no relevance as \etoc reads the toc file with
% |\endlinechar=-1| regime.
%
% When using \csa{addcontentsline} nothing needs to be done as both things are
% handled by \LaTeX\ upstream.
%
% \etocrelease{1.2} executes the \csbc{ifEtoc@hyperref} test inside the fourth
% argument, rather than using one \csa{addtocontents} in each branch.
%    \begin{macrocode}
\def\Etoc@addtocontents #1#2{%
    \addtocontents {toc}{%
      \protect\contentsline{#1}{#2}{\thepage}{\ifEtoc@hyperref\@currentHref\fi}%
      \ifdefined\protected@file@percent\protected@file@percent\fi
    }%
}
\def\Etoc@addcontentsline@ #1#2#3{%
    \@namedef{toclevel@#1}{#3}\addcontentsline {toc}{#1}{#2}%
}
\DeclareRobustCommand*{\etoctoccontentsline}
    {\@ifstar{\Etoc@addcontentsline@}{\Etoc@addtocontents}}
\def\Etoc@addtocontents@immediately#1#2{%
    \begingroup
       \let\Etoc@originalwrite\write
       \def\write{\immediate\Etoc@originalwrite}%
       \Etoc@addtocontents{#1}{#2}%
    \endgroup
}
\def\Etoc@addcontentsline@@immediately#1#2#3{%
    \begingroup
       \let\Etoc@originalwrite\write
       \def\write{\immediate\Etoc@originalwrite}%
       \Etoc@addcontentsline@{#1}{#2}{#3}%
    \endgoroup
}
\DeclareRobustCommand*{\etocimmediatetoccontentsline}
    {\@ifstar{\Etoc@addcontentsline@@immediately}{\Etoc@addtocontents@immediately}}
%    \end{macrocode}
% Formerly a \LaTeX{} counter |etoc@tocdepth| was used but at
% \etocrelease{1.2} it has been replaced by macro-storage.
%    \begin{macrocode}
\def\Etoc@storetocdepth   {\xdef\Etoc@savedtocdepth{\number\c@tocdepth}}
\def\Etoc@restoretocdepth {\global\c@tocdepth\Etoc@savedtocdepth\relax}
\def\etocobeytoctocdepth {\def\etoc@settocdepth
                          {\afterassignment\Etoc@@nottoodeep \global\c@tocdepth}}
\def\Etoc@@nottoodeep {\ifnum\Etoc@savedtocdepth<\c@tocdepth
                          \global\c@tocdepth\Etoc@savedtocdepth\relax\fi }
\def\etocignoretoctocdepth {\let\etoc@settocdepth\@gobble }
\def\etocsettocdepth   {\futurelet\Etoc@nexttoken\Etoc@set@tocdepth }
\def\Etoc@set@tocdepth {\ifx\Etoc@nexttoken\bgroup
                            \expandafter\Etoc@set@tocdepth@
                       \else\expandafter\Etoc@set@toctocdepth
                       \fi }
\def\Etoc@set@tocdepth@ #1{\@ifundefined {Etoc@#1@@}
      {\PackageWarning{etoc}
          {Unknown sectioning unit #1, \protect\etocsettocdepth\space ignored}}
      {\global\c@tocdepth\csname Etoc@#1@@\endcsname}%
}
\def\Etoc@set@toctocdepth  #1#{\Etoc@set@toctocdepth@ }
\def\Etoc@set@toctocdepth@ #1{%
  \@ifundefined{Etoc@#1@@}%
   {\PackageWarning{etoc}
        {Unknown sectioning depth #1, \protect\etocsettocdepth.toc ignored}}%
   {\addtocontents {toc}
   {\protect\etoc@settocdepth\expandafter\protect\csname Etoc@#1@@\endcsname}}%
}
%    \end{macrocode}
% placeholder
%    \begin{macrocode}
\def\etocimmediatesettocdepth #1#{\Etoc@set@toctocdepth@immediately}
\def\Etoc@set@toctocdepth@immediately #1{%
  \@ifundefined{Etoc@#1@@}%
   {\PackageWarning{etoc}
        {Unknown sectioning depth #1, \protect\etocimmediatesettocdepth.toc ignored}}%
   {\begingroup
      \let\Etoc@originalwrite\write
      \def\write{\immediate\Etoc@originalwrite}%
      \addtocontents {toc}
      {\protect\etoc@settocdepth\expandafter\protect
       \csname Etoc@#1@@\endcsname}%
    \endgroup
   }%
}
%    \end{macrocode}
% placeholder
%    \begin{macrocode}
\def\etocdepthtag   #1#{\Etoc@depthtag }
\def\Etoc@depthtag  #1{\addtocontents {toc}{\protect\etoc@depthtag {#1}}}
%    \end{macrocode}
% \etocrelease{1.09f} adds \csbc{etocimmediatedepthtag.toc}.  This can serve in some
% circumstances, see user documentation.  Apologies for long delay to Norman
% Ramsey who reported problem and his fix in July... 2016!
%    \begin{macrocode}
\def\etocimmediatedepthtag   #1#{\Etoc@depthtag@immediately }
\def\Etoc@depthtag@immediately #1{%
  \begingroup
    \let\Etoc@originalwrite\write
    \def\write{\immediate\Etoc@originalwrite}%
    \addtocontents {toc}{\protect\etoc@depthtag {#1}}%
  \endgroup
}
\def\etocignoredepthtags {\let\etoc@depthtag \@gobble }
\def\etocobeydepthtags   {\let\etoc@depthtag \Etoc@depthtag@ }
\def\Etoc@depthtag@ #1{\@ifundefined{Etoc@depthof@#1}%
       {}% ignore in silence if tag has no associated depth
       {\afterassignment\Etoc@@nottoodeep
                 \global\c@tocdepth\csname Etoc@depthof@#1\endcsname}%
}
\def\etocsettagdepth #1#2{\@ifundefined{Etoc@#2@@}%
       {\PackageWarning{etoc}
         {Unknown sectioning depth #2, \protect\etocsettagdepth\space ignored}}%
       {\@namedef{Etoc@depthof@#1}{\@nameuse{Etoc@#2@@}}}%
}
%    \end{macrocode}
% We must cancel all \ctanpkg{tocvsec2} toc-related actions. But a check must be done
% for the memoir class, as its \ctanpkg{tocvsec2} emulation does not have the
% incompatible things etoc needs to revert.
%    \begin{macrocode}
\def\Etoc@tocvsec@err #1{\PackageError {etoc}
        {The command \protect#1\space is incompatible with `etoc'}
        {Use \protect\etocsettocdepth.toc as replacement}%
}%
\AtBeginDocument {%
  \@ifclassloaded{memoir}
    {\PackageInfo {etoc}
     {Regarding `memoir' class command \protect\settocdepth, consider\MessageBreak
     \protect\etocsettocdepth.toc as a drop-in replacement with more\MessageBreak
     capabilities (see `etoc' manual). \space
     Also, \protect\etocsettocdepth\MessageBreak
     and \protect\etocsetnexttocdepth\space should be used in place of\MessageBreak
     `memoir' command \protect\maxtocdepth\@gobble}%
    }%
    {\@ifpackageloaded {tocvsec2}{%
      \def\maxtocdepth  #1{\Etoc@tocvsec@err \maxtocdepth   }%
      \def\settocdepth  #1{\Etoc@tocvsec@err \settocdepth   }%
      \def\resettocdepth  {\@ifstar {\Etoc@tocvsec@err \resettocdepth }%
                                    {\Etoc@tocvsec@err \resettocdepth }%
                          }%
%    \end{macrocode}
% If \etoc is added to a \LaTeX{} document using already \ctanpkg{tocvsec2}.
%    \begin{macrocode}
      \def\save@tocdepth #1#2#3{}%
      \let\reset@tocdepth\relax
      \let\remax@tocdepth\relax
      \let\tableofcontents\etoctableofcontents
      \PackageWarningNoLine {etoc}
      {Package `tocvsec2' detected and its modification of\MessageBreak
       \protect\tableofcontents\space reverted. \space Use
       \protect\etocsettocdepth.toc\MessageBreak as a replacement
       for `tocvsec2' toc-related commands}%
     }% tocvsec2 loaded
     {}% tocvsec2 not loaded
    }%
}%
%    \end{macrocode}
% placeholder
%    \begin{macrocode}
\def\invisibletableofcontents {\etocsetnexttocdepth {-3}\tableofcontents }%
\def\invisiblelocaltableofcontents
                         {\etocsetnexttocdepth {-3}\localtableofcontents }%
\def\etocsetnexttocdepth #1{%
    \@ifundefined{Etoc@#1@@}
     {\PackageWarning{etoc}
       {Unknown sectioning unit #1, \protect\etocsetnextocdepth\space ignored}}
     {\Etoc@setnexttocdepth{\csname Etoc@#1@@\endcsname}}%
}%
\def\Etoc@setnexttocdepth#1{%
    \def\Etoc@tocdepthset{%
        \Etoc@tocdepthreset
        \edef\Etoc@tocdepthreset {%
               \global\c@tocdepth\the\c@tocdepth\space
               \global\let\noexpand\Etoc@tocdepthreset\noexpand\@empty
         }%
        \global\c@tocdepth#1%
        \global\let\Etoc@tocdepthset\@empty
    }%
}%
\let\Etoc@tocdepthreset\@empty
\let\Etoc@tocdepthset  \@empty
\def\etocsetlocaltop #1#{\Etoc@set@localtop}%
\def\Etoc@set@localtop #1{%
  \@ifundefined{Etoc@#1@@}%
   {\PackageWarning{etoc}
        {Unknown sectioning depth #1, \protect\etocsetlocaltop.toc ignored}}%
   {\addtocontents {toc}
   {\protect\etoc@setlocaltop\expandafter\protect\csname Etoc@#1@@\endcsname}}%
}%
%    \end{macrocode}
% placeholder
%    \begin{macrocode}
\def\etocimmediatesetlocaltop #1#{\Etoc@set@localtop@immediately}%
\def\Etoc@set@localtop@immediately #1{%
  \@ifundefined{Etoc@#1@@}%
   {\PackageWarning{etoc}
        {Unknown sectioning depth #1, \protect\etocimmediatesetlocaltop.toc ignored}}%
   {\begingroup
       \let\Etoc@originalwrite\write
       \def\write{\immediate\Etoc@originalwrite}%
       \addtocontents {toc}
           {\protect\etoc@setlocaltop\expandafter\protect
                                     \csname Etoc@#1@@\endcsname}%
    \endgroup
   }%
}%
%    \end{macrocode}
% \etocrelease{1.09i} would like to rename this to \csa{Etoc@setlocaltop}, for
% consistency with internal macros, but too late it is already in user |.toc| files.
%    \begin{macrocode}
\def\etoc@setlocaltop #1{%
  \ifnum#1=\Etoc@maxlevel
   \Etoc@skipthisonetrue
  \else
   \Etoc@skipthisonefalse
%    \end{macrocode}
% MEMO: the \csbc{Etoc@level} thus continues receiving updates from various
% \csbc{etoc@setlocaltop} present in the |.toc| file even once the local toc
% is already done, but this has no importance, as the code in
% \csbc{Etoc@toctoc} after executing the code contents is not influenced by
% this but only by the final status of \csbc{Etoc@stackofends} remains the
% same.  And this gets updated via \csbc{Etoc@setlocaltop@doendsandbegin} (see
% below).
%
% I should check if not worthwile to move the \csbc{ifEtoc@stoptoc} test
% earlier.
%
% There should be two notions of local top.  One for a potential barrier,
% stopping a toc, the other for setting a local top.  These two should be
% distinct.  Or at least additional to this one which does both.  But then I
% would have to document.  And test.  And implement first.
%    \begin{macrocode}
   \global\let\Etoc@level #1%
   \global\let\Etoc@virtualtop #1%
   \ifEtoc@localtoc
    \ifEtoc@stoptoc
     \Etoc@skipthisonetrue
    \else
     \ifEtoc@notactive
      \Etoc@skipthisonetrue
     \else
      \unless\ifnum\Etoc@level>\etoclocaltop
       \Etoc@skipthisonetrue
       \global\Etoc@stoptoctrue
      \fi
     \fi
    \fi
   \fi
  \fi
  \let\Etoc@next\@empty
  \ifEtoc@skipthisone
  \else
   \ifnum\Etoc@level>\c@tocdepth
   \else
    \ifEtoc@standardlines
    \else
%    \end{macrocode}
% So here the \csbc{etocsetlocaltop}|.toc| will cause various starts and
% finish parts to get executed, even for the somewhat fictitious levels.  But
% this may cause collaterals, in particular we have to be careful about the
% \csbc{ifEtoc@skipprefix} Boolean, which may be set to \csa{iftrue} in
% the \marg{start} part of the level style and thus needs to be reset to
% \csa{iffalse}.  This is done automatically in \csbc{Etoc@etoccontentsline@}
% but here we are not executing it so we need to add somewhere a
% |\global\Etoc@skipprefixfalse| (else we may impact rendering of subsequent
% level).  So we put it together with \csbc{Etoc@doendsandbegin} in a wrapper.
% This wrapper is also there to avoid a problem when the TOC is checked for
% emptiness, as we need then to be able to tell \csbc{etoc@setlocaltop} to
% not execute anything.
%
% This also stresses
% that the name of the macro is a bit of a misnomer, yes it serves to delimit
% local table of contents, but really it is implemented as a ghost of a
% sectioning unit which does have an impact (on the global TOC or local TOCs
% from encompassing levels), as it triggers when encountered the \marg{finish}
% portions of previous finer levels (and the \marg{finish} code of its own
% level will be executed sooner or later), and the \marg{start} code of
% subsequent finer levels (as well as its own \marg{start} code at least once,
% depending on how levels are nested).
%    \begin{macrocode}
     \let\Etoc@next\Etoc@setlocaltop@doendsandbegin
    \fi
   \fi
  \fi
  \Etoc@next
}%
%    \end{macrocode}
% It is important to reset the \csbc{ifEtoc@skipprefix} boolean, as is done in
% \csbc{Etoc@etoccontentsline@}.\par
%    \begin{macrocode}
\def\Etoc@setlocaltop@doendsandbegin{%
    \Etoc@doendsandbegin
    \global\Etoc@skipprefixfalse
}
\addtocontents {toc}{\protect\@ifundefined{etoctocstyle}%
           {\let\protect\etoc@startlocaltoc\protect\@gobble
            \let\protect\etoc@settocdepth\protect\@gobble
            \let\protect\etoc@depthtag\protect\@gobble
            \let\protect\etoc@setlocaltop\protect\@gobble}{}}%
%    \end{macrocode}
% Initializations.
%    \begin{macrocode}
\def\etocstandardlines {\Etoc@standardlinestrue}
\def\etoctoclines      {\Etoc@standardlinesfalse}
\etocdefaultlines
\etocstandardlines
\def\etocstandarddisplaystyle{%
    \PackageWarningNoLine{etoc}{%
      \string\etocstandarddisplaystyle \on@line\MessageBreak
      is deprecated. \space Please use \string\etocclasstocstyle}%
}
\expandafter\def\expandafter\etocclasstocstyle\expandafter{%
    \etocclasstocstyle
    \Etoc@classstyletrue
}
\def\etocetoclocaltocstyle{\Etoc@etocstyletrue}
\def\etocusertocstyle{\Etoc@etocstylefalse}
\etocclasstocstyle
\etocetoclocaltocstyle
\etocobeytoctocdepth
\etocobeydepthtags
\let\etocbeforetitlehook   \@empty
\let\etocaftertitlehook    \@empty
\let\etocaftercontentshook \@empty
\let\etocaftertochook      \@empty
%    \end{macrocode}
% |listings| abuses \csa{tableofcontents} for its \csa{lstlistoflistings}. It
% doesn't seem worth to let my version of \csbc{tableofcontents} have to check for
% this special circumstance. So at \etocrelease{1.09d}, simply add this (the
% boolean was added at \etocrelease{1.2}):
%    \begin{macrocode}
\def\etockeeporiginaltableofcontents
   {\Etoc@keeporiginaltoctrue\let\tableofcontents\etocoriginaltableofcontents}%
\endinput
%    \end{macrocode}
% \MakePercentComment
\Finale
%%
%% End of file `etoc.dtx'.