summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/source/latex/forest/forest.dtx
blob: 671f73854bdf4ef6fb9ad3298a501d0161b3d2f7 (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
% \CheckSum{12832}
% \iffalse meta-comment
% forest.dtx
%% `forest' is a `pgf/tikz'-based package for drawing (linguistic) trees.
%%
%% Copyright (c) 2013 Saso Zivanovic
%%                    (Sa\v{s}o \v{Z}ivanovi\'{c})
%% saso.zivanovic@guest.arnes.si
%%
%% This work may be distributed and/or modified under the
%% conditions of the LaTeX Project Public License, either version 1.3
%% of this license or (at your option) any later version.
%% The latest version of this license is in
%% 
%%   http://www.latex-project.org/lppl.txt
%%   
%% and version 1.3 or later is part of all distributions of LaTeX
%% version 2005/12/01 or later.
%%
%% This work has the LPPL maintenance status `maintained'.
%% 
%% The Current Maintainer of this work is Saso Zivanovic.
%%
%% This work consists of the files forest.dtx and forest.ins
%% and the derived file forest.sty.
%%
%
%<*driver>
\documentclass[a4paper]{ltxdoc}
\usepackage{fullpage}

\usepackage[external]{forest}
%\tikzexternalize
\tikzset{
  external/prefix={forest.for.dir/},
  external/system call={
    pdflatex \tikzexternalcheckshellescape -halt-on-error -interaction=nonstopmode
    -jobname "\image" "\texsource"},
}
%\usepackage[trace]{trace-pgfkeys}

\usepackage[colorlinks=true,linkcolor=blue,citecolor=blue,hyperindex=false]{hyperref}
\usepackage{url}
\usepackage[numbers]{natbib}
\usepackage[multiple]{footmisc}
\usepackage{tipa}
\usepackage{paralist}
\usepackage{printlen}

\makeatletter
\DeleteShortVerb\|
\newcommand\OR{\ensuremath{\,|\,}}%

%%%%%%%% 
%\usepackage{lstdoc} %%% copy/paste most of the file, but omit and adjust some stuff like
%section-modifications 
\usepackage{listings}
\def\lst@sampleInput{%
    \MakePercentComment\catcode`\^^M=10\relax
    \small\lst@sample
    {\setkeys{lst}{SelectCharTable=\lst@ReplaceInput{\^\^I}%
                                  {\lst@ProcessTabulator}}%
     \leavevmode \input{\jobname.tmp}}\MakePercentIgnore}
\definecolor{darkgreen}{rgb}{0,0.5,0}
\def\rstyle{\color{red}}
\def\advise{\par\list\labeladvise
    {\advance\linewidth\@totalleftmargin
     \@totalleftmargin\z@
     \@listi
     \let\small\footnotesize \small\sffamily
     \parsep \z@ \@plus\z@ \@minus\z@
     \topsep6\p@ \@plus1\p@\@minus2\p@
     \def\makelabel##1{\hss\llap{##1}}}}
\let\endadvise\endlist
\def\advisespace{\hbox{}\qquad}
\def\labeladvise{$\to$}
\newenvironment{syntax}
   {\list{}{\itemindent-\leftmargin
    \def\makelabel##1{\hss\lst@syntaxlabel##1,,,,\relax}}}
   {\endlist}
\def\lst@syntaxlabel#1,#2,#3,#4\relax{%
    \llap{\scriptsize\itshape#3}%
    \def\lst@temp{#2}%
    \expandafter\lst@syntaxlabel@\meaning\lst@temp\relax
    \rlap{\hskip-\itemindent\hskip\itemsep\hskip\linewidth
          \llap{\ttfamily\lst@temp}\hskip\labelwidth
          \def\lst@temp{#1}%
          \ifx\lst@temp\lstdoc@currversion#1\fi}}
\def\lst@syntaxlabel@#1>#2\relax
    {\edef\lst@temp{\zap@space#2 \@empty}}
\newcommand*\syntaxnewline{\newline\hbox{}\kern\labelwidth}
\newcommand*\syntaxor{\qquad or\qquad}
\newcommand*\syntaxbreak
    {\hfill\kern0pt\discretionary{}{\kern\labelwidth}{}}
\let\syntaxfill\hfill
\def\alternative#1{\lst@true \alternative@#1,\relax,}
\def\alternative@#1,{%
    \ifx\relax#1\@empty
        \expandafter\@gobble
    \else
        \ifx\@empty#1\@empty\else %\if
            \lst@if \lst@false \else $\vert$\fi
            \textup{\texttt{#1}}%
        \fi
    \fi
    \alternative@}
\lst@RequireAspects{writefile}
\lst@InstallKeywords{p}{point}{pointstyle}\relax{keywordstyle}{}ld
\def\pstyle{\color{darkgreen}}
\lstset{language={[LaTeX]TeX},tabsize=4,gobble=4,%
  basicstyle=\small\ttfamily,basewidth=0.51em,boxpos=t,pointstyle=\pstyle,moredelim=[is][\pstyle]{~}{~}}%
\newbox\sampleoutputbox
\newbox\lst@samplebox
\newdimen\forestexample@code
\newdimen\forestexample@sample
\newdimen\forestexample@hsep
\forestexample@hsep=1em
\lst@Key{hsep}\relax{\forestexample@hsep=#1}%
\pgfqkeys{/forestexample}{%
  samplebox/.code={\let\sampleoutputbox#1},
  codebox/.code={\let\lst@samplebox#1},
  pos/.initial=l, % example is left of the code
  before/.code={\gdef\lst@sample{#1}},
  labelformat/.initial={\def\@currentlabel{#1}},
  no numbering/.code={\addtocounter{lstlisting}{-1}\pgfkeysalso{labelformat={}}},
  .unknown/.code={\lstset{\pgfkeyscurrentname={#1}}},
  ekeynames/.code={\def\myindex@for@temp##1{\ekeyname[example]{##1}}\forcsvlist\myindex@for@temp{#1}},
  ecmdnames/.code={\forcsvlist{\ecmdname[example]}{#1}},
  filename/.initial={},
}
\lstnewenvironment{forestexample}[1][]{%
  \global\let\lst@intname\@empty
  \def\@currentlabel{(\arabic{lstlisting})}%
  \addtocounter{lstlisting}{1}%
  \gdef\lst@sample{}%
  \pgfqkeys{/forestexample}{#1}%
  \setbox\lst@samplebox=\hbox\bgroup
  \xdef\samplebox@baselineskip{\the\baselineskip}%
  \catcode`~=9\relax
  \lst@BeginAlsoWriteFile{\jobname.tmp}%
}{%
  \lst@EndWriteFile\egroup
  \immediate\write18{cat \jobname.tmp}%
  \pgfkeysgetvalue{/forestexample/pos}\fe@pos
  \if x\fe@pos   %%%%%%%%  user position: boxes are stored in cs given in samplebox and codebox args
    \forest@temp@count=\@listdepth
    \pgfutil@tempdima=0pt
    \loop
    \ifnum\forest@temp@count>0
      \advance\pgfutil@tempdima\csname leftmargin\romannumeral\the\forest@temp@count\endcsname\relax
      \advance\forest@temp@count-1
    \repeat
    \global\setbox\lst@samplebox=\hbox{\hskip-\pgfutil@tempdima\box\lst@samplebox\hskip\pgfutil@tempdima}%
    \global\setbox\sampleoutputbox=\hbox{\lst@sampleInput}%
  \else
    \if l\fe@pos %%%% example is left of the code
  % move the code left for each list's \leftmargin ... have no idea why this must be done
      \forest@temp@count=\@listdepth
      \pgfutil@tempdima=0pt
      \loop
      \ifnum\forest@temp@count>0
        \advance\pgfutil@tempdima\csname leftmargin\romannumeral\the\forest@temp@count\endcsname\relax
        \advance\forest@temp@count-1
      \repeat
      \setbox\lst@samplebox=\hbox{\hskip-\pgfutil@tempdima\box\lst@samplebox\hskip\pgfutil@tempdima}%
      \setbox\sampleoutputbox=\hbox{\lst@sampleInput}%
      \pgfutil@tempdima=\wd\sampleoutputbox
      \advance\pgfutil@tempdima\wd\lst@samplebox
      \advance\pgfutil@tempdima\forestexample@hsep
      \ifdim\pgfutil@tempdima>\linewidth
        \forestexample@code=\linewidth
        \advance\forestexample@code-\wd\lst@samplebox
        \forestexample@sample=\forestexample@code
        \advance\forestexample@sample-\forestexample@hsep
        \advance\forestexample@sample-\wd\sampleoutputbox
      \else
        \pgfutil@tempdima=\wd\sampleoutputbox
        \advance\pgfutil@tempdima\forestexample@hsep
        \ifdim\pgfutil@tempdima>.5\linewidth
          \forestexample@sample=0pt
          \forestexample@code=\wd\sampleoutputbox
          \advance\forestexample@code\forestexample@hsep
        \else
          \pgfutil@tempdima=\wd\lst@samplebox
          \advance\pgfutil@tempdima\forestexample@hsep
          \ifdim\pgfutil@tempdima>.5\linewidth
            \forestexample@code=\linewidth
            \advance\forestexample@code-\wd\lst@samplebox
            \forestexample@sample=0pt
          \else
            \forestexample@sample=0pt
            \forestexample@code=.5\linewidth
          \fi
        \fi
      \fi
      \begin{trivlist}\item\relax
        $%
          \vcenter{
            \hbox{%
              \hbox to 0pt{\hskip\linewidth\llap{\@currentlabel}}%
              \hbox to 0pt{%
                \hskip\forestexample@code
                \raise\samplebox@baselineskip\box\lst@samplebox
              }%
            }%
          }%
          \vcenter{%
            \hbox to 0pt{%
              \hskip\forestexample@sample
              \box\sampleoutputbox
            }%
          }%
        $%
      \end{trivlist}%
    \else
      \if t\fe@pos %%%% example is above the code
        \forest@temp@count=\@listdepth
        \pgfutil@tempdima=0pt
        \loop
        \ifnum\forest@temp@count>0
          \advance\pgfutil@tempdima\csname leftmargin\romannumeral\the\forest@temp@count\endcsname\relax
          \advance\forest@temp@count-1
        \repeat
        \setbox\lst@samplebox=\hbox{\hskip-\pgfutil@tempdima\box\lst@samplebox\hskip\pgfutil@tempdima}%
        \setbox\sampleoutputbox=\hbox{\lst@sampleInput}%
        \begin{trivlist}%
        \item
          \hfil\box\sampleoutputbox\hfil
        \item
          \hbox{%
            \hbox to 0pt{\hskip\linewidth\llap{\@currentlabel}}%
            \hbox to 0pt{%
              \raise\samplebox@baselineskip\box\lst@samplebox
            }%
          }%
        \end{trivlist}%
      \else
        \if b\fe@pos %%% example is below the code
          \forest@temp@count=\@listdepth
          \pgfutil@tempdima=0pt
          \loop
          \ifnum\forest@temp@count>0
            \advance\pgfutil@tempdima\csname leftmargin\romannumeral\the\forest@temp@count\endcsname\rel                                    ax
            \advance\forest@temp@count-1
          \repeat
          \setbox\lst@samplebox=\hbox{\hskip-\pgfutil@tempdima\box\lst@samplebox\hskip\pgfutil@tempdima}%
          \setbox\sampleoutputbox=\hbox{\lst@sampleInput}%
          \begin{trivlist}%
          \item
            \hbox{%
              \hbox to 0pt{\hskip\linewidth\llap{\@currentlabel}}%
              \hbox to 0pt{%
                \raise\samplebox@baselineskip\box\lst@samplebox
              }%
            }%
          \item
            \hfil\box\sampleoutputbox\hfil
          \end{trivlist}%
        \else %%% insert other pos here.... 
        \fi
      \fi
    \fi
  \fi
}%
\def\myisaspect#1#2#3{% #1=aspect id, #2=aspect display, #3=entry ids
  \csdef{myaspect@display@#1}{#2}%
  \edef\myisaspect@##1{%
    \csdef{myaspect@of@##1}{#1}%
  }%
  \forcsvlist\myisaspect@{#3}%
}
\def\my@index#1#2#3#4{% #1=entry id,#2=entry display,#3=aspect id,#4=pagestyle
  \ifstrempty{#3}{%
    \edef\mytemp{%
      \noexpand\index{#1=\unexpanded{#2}#4}%
    }%
  }{%
    \edef\mytemp{%
      \noexpand\index{%
        #1=\unexpanded{#2}\protect\noexpand\space
        {\protect\noexpand\scriptsize
          \expandafter\expandafter\expandafter\unexpanded
          \expandafter\expandafter\expandafter
          {\csname myaspect@display@#3\endcsname}%
        }%
        #4%
      }%
      \noexpand\index{#3=\expandafter\expandafter\expandafter\unexpanded
        \expandafter\expandafter\expandafter
        {\csname myaspect@display@#3\endcsname}\levelchar
        #1=\unexpanded{#2}%
        #4%
      }%
    }%
  }%
  \mytemp
}%
\newcommand\myindex[1]{%
  \@bsphack
  \pgfqkeys{/myindex}{#1}%
  \pgfkeysgetvalue{/myindex/id}\myindex@temp@entryid
  \pgfkeysgetvalue{/myindex/display}\myindex@temp@entrydisplay
  \pgfkeysgetvalue{/myindex/aspect}\myindex@temp@aspectid
  \pgfkeysgetvalue{/myindex/pagestyle}\myindex@temp@pagestyle
  \edef\myindex@temp{\noexpand\my@index
    {\expandonce{\myindex@temp@entryid}}{\expandonce{\myindex@temp@entrydisplay}}{\expandonce{\myindex@temp@aspectid}}{\myindex@temp@pagestyle}%
  }\myindex@temp
  \@esphack
  \pgfkeysvalueof{/myindex/text}%
}
\def\stripfirst#1#2\stripfirst{#2}%
\pgfqkeys{/myindex}{%
  /handlers/.wrap/.code={%
    \edef\myindex@currentpath{\pgfkeyscurrentpath}%
    \pgfkeysgetvalue{\myindex@currentpath}\myindex@keyvalue
    \forest@def@with@pgfeov\myindex@wrap@code{#1}%
    \expandafter\edef\expandafter\myindex@wrapped@value\expandafter{\expandafter\expandonce\expandafter{\expandafter\myindex@wrap@code\myindex@keyvalue\pgfeov}}%
    \pgfkeysalso{\myindex@currentpath/.expand once=\myindex@wrapped@value}%
  },
  /handlers/.ewrap/.code={% not used!
    \edef\myindex@currentpath{\pgfkeyscurrentpath}%
    \pgfkeysgetvalue{\myindex@currentpath}\myindex@keyvalue
    \forest@def@with@pgfeov\myindex@wrap@code{#1}%
    \edef\myindex@wrapped@value{\expandafter\myindex@wrap@code\expandafter{\myindex@keyvalue}\pgfeov}%
    \pgfkeysalso{\myindex@currentpath/.expand once=\myindex@wrapped@value}%
  },
  id/.code={%
    \pgfkeyssetvalue{/myindex/id}{#1}%
    \pgfkeysgetvalue{/myindex/id}\myindex@temp
    \pgfkeyslet{/myindex/display}\myindex@temp
    \pgfkeyslet{/myindex/text}\myindex@temp
    \pgfkeyssetvalue{/myindex/pagestyle}{}%
    \pgfkeyssetvalue{/myindex/version}{}%
    \ifcsname myaspect@of@#1\endcsname
      \pgfkeysalso{aspect/.expand once=\csname myaspect@of@#1\endcsname}%
    \else
      \pgfkeyssetvalue{/myindex/aspect}{}%
      \pgfkeyssetvalue{/myindex/margin}{}%
    \fi
  },
  id'/.code={\pgfkeyssetvalue{/myindex/id}{#1}},
  .unknown/.code={%
    \edef\myindex@temp{%
      \noexpand\pgfkeysalso{id={\pgfkeyscurrentname}}%
    }\myindex@temp
  },
  display/.initial={},
  pagestyle/.initial={},
  text/.initial={},
  aspect/.code={%
    \edef\myindex@temp{%
      \noexpand\pgfkeyssetvalue{/myindex/aspect}{#1}%
    }\myindex@temp
    \ifcsname myaspect@display@#1\endcsname
      \edef\myindex@temp{%
        \noexpand\pgfkeyslet{/myindex/margin}\expandonce{\csname myaspect@display@#1\endcsname}%
      }\myindex@temp
    \else
      \pgfkeyssetvalue{/myindex/margin}{}%
    \fi
  },
  nfc/.style={% no first char (in id)
    id'/.expanded={\expandafter\stripfirst\romannumeral-`0\pgfkeysvalueof{/myindex/id}\stripfirst}
  },
  rstyle/.style={text/.wrap={\begingroup\rstyle##1\endgroup}},
  example/.style={pagestyle=|indextextexample},
  def/.style={pagestyle=|indextextdef},
  normal/.style={pagestyle=|indextextnormal},
  item/.style={% #1=default
    text/.wrap={% ##1=current text
      \item[\pgfkeysvalueof{/myindex/version},#1,\pgfkeysvalueof{/myindex/margin}]{##1}%
    }
  },
  item/.default={},
  version/.initial={},
  margin/.initial={},
}
\newcommand\indextextexample[1]{\hyperlink{page.#1}{\textcolor{darkgreen}{#1}}}
\newcommand\indextextdef[1]{\hyperlink{page.#1}{\textcolor{red}{#1}}}
\newcommand\indextextnormal[1]{\hyperlink{page.#1}{\textcolor{blue}{#1}}}
\let\keyname\texttt
\newcommand\rkeyname[2][]{\myindex{%
    #2,
    display/.wrap=\protect\texttt{##1},
    text/.wrap=\hypertarget{\pgfkeysvalueof{/myindex/id}}{{\rstyle\keyname{##1}}},
    def,
    #1
  }}
\newcommand\ikeyname[2][]{\myindex{%
    #2,
    display/.wrap=\protect\texttt{##1},
    text/.wrap=\hyperlink{\pgfkeysvalueof{/myindex/id}}{\keyname{##1}},
    normal,
    #1
  }}
\newcommand\ekeyname[2][]{\myindex{%
    #2,
    display/.wrap=\protect\texttt{##1},
    text={},
    normal,
    #1
  }}
\newcommand\rmeta[2][]{\myindex{%
    #2,
    display/.wrap=\protect\meta{##1},
    %text/.wrap=\begingroup\rstyle\meta{##1}\endgroup,
    text/.wrap=\hypertarget{\pgfkeysvalueof{/myindex/id}}{{\rstyle\meta{##1}}},
    def,
    #1
  }}
\newcommand\imeta[2][]{\myindex{%
    #2,
    display/.wrap=\protect\meta{##1},
    text/.wrap=\hyperlink{\pgfkeysvalueof{/myindex/id}}{\meta{##1}},
    normal,
    #1
  }}
\newcommand\cmdname[1]{\expandafter\texttt\expandafter{\expandafter\string\csname#1\endcsname}}
\newcommand\rcmdname[2][]{\myindex{%
    #2,
    id'/.expanded=\pgfkeysvalueof{/myindex/id} macro,
    display/.wrap=\protect\cmdname{##1},
    text/.wrap=\hypertarget{\pgfkeysvalueof{/myindex/id}}{{\rstyle\cmdname{##1}}},
    def,
    #1
  }}
\newcommand\icmdname[2][]{\myindex{%
    #2,
    id'/.expanded=\pgfkeysvalueof{/myindex/id} macro,
    text/.wrap=\hyperlink{\pgfkeysvalueof{/myindex/id}}{\cmdname{##1}},
    normal,
    #1
  }}
\newcommand\ecmdname[2][]{\myindex{%
    #2,
    id'/.expanded=\pgfkeysvalueof{/myindex/id} macro,
    display/.wrap=\protect\cmdname{##1},
    text={},
    normal,
    #1
  }}
\makeatother
\myisaspect{environment}{environment}{forest}
\myisaspect{option}{option}{align,content,content format,node format,base,node options,phantom,anchor,calign,calign primary angle,calign secondary angle,calign primary child,calign secondary child,fit,grow,ignore,ignore edge,reversed,l,s,l sep,s sep,tier,x,y,child anchor,edge,edge label,edge path,parent anchor,name,tikz,anchor,level,n,n',n children,id,max x,max y,min x,min y}
\myisaspect{propagator}{propagator}{for,if,where,for tree,repeat,delay,delay n,if have delayed,for ancestors,for ancestors',for children,for descendants,for descendants',for all next,for all previous,for previous siblings,before typesetting nodes,before packing,before computing xy,before drawing tree,repeat}
\myisaspect{type}{type}{toks,autowrapped toks,keylist,dimen,count,boolean}%relative node name,node walk,step}
\myisaspect{handler}{handler}{.pgfmath,.wrap value,.wrap pgfmath arg,.wrap $n$ pgfmath args,.wrap 2 pgfmath args,.wrap 3 pgfmath args,.wrap 4 pgfmath args,.wrap 5 pgfmath args,.wrap 6 pgfmath args,.wrap 7 pgfmath args,.wrap 8 pgfmath args,.wrap 9 pgfmath args}
\myisaspect{key prefix}{key prefix}{if in ,where in ,if ,where ,not ,for }
\myisaspect{key suffix}{key suffix}{',+,-,*,:,'+,'-,'*,':}
\myisaspect{key}{}{afterthought,baseline,label,pin,alias,TeX,TeX',TeX'',no edge,typeset node,repeat,use as bounding box,use as bounding box',draw tree box}
\myisaspect{style}{style}{stages,typeset nodes stage,pack stage,compute xy stage,draw tree
  stage,math content}
\myisaspect{stage}{stage}{typeset nodes,typeset nodes',pack,compute xy,draw tree,draw tree'}
\myisaspect{package option}{package option}{external,tikzcshack,tikzinstallkeys}
\myisaspect{dynamic tree}{dynamic tree}{create,remove,prepend,append,insert after,insert before,set
  root,replace by,prepend',append',insert after',insert before',replace by',prepend'',append'',insert after'',insert before'',replace by'',copy name template}
\myisaspect{forest cs}{forest cs}{}

\myisaspect{calign}{\keyname{calign} value}{}%{child,first,last,child edge,midpoint,center,edge midpoint,fixed angles,fixed edge angles}
\myisaspect{align}{\keyname{align} value}{}%{left,center,right}
\myisaspect{fit}{\keyname{fit} value}{}%{tight,rectangle,band}
\myisaspect{base}{\keyname{base} value}{}%{top,bottom}

\myisaspect{step}{\meta{step}}{current,next,previous,parent,sibling,previous leaf,next leaf,
  linear next,linear previous,first leaf,last leaf,to tier,next on tier,previous on tier,
  root,embed,trip,group,first,last
  %,n,n',name,id,   % these equal option names
}
\myisaspect{short step}{\meta{short step}}{1,2,3,4,5,6,7,8,9,u,p,%
  %,n,l,s equal option names
  P,N,F,L,<,%> is a level char
  c,r}
\myisaspect{generic anchor}{generic anchor}{}%
{\catcode`\|=12 \gdef\myindexgt{\texttt{>}}}
{\makeatletter % an dirty patch: \lst@nolig can sneak in the name...
\gdef\myexampleindex#1{{\def\lst@nolig{}\lstaspectindex{#1}{}}}
}
\lstset{indexstyle={[1]\myexampleindex}}
\makeindex
%%% end lst-related stuff

\EnableCrossrefs         
 %\DisableCrossrefs     % Say \DisableCrossrefs if index is ready
 %\CodelineIndex
 %\RecordChanges          % Gather update information
 %\OnlyDescription      % comment out for implementation details
\setlength\hfuzz{15pt}  % dont make so many
\hbadness=7000          % over and under full box warnings

\def\partname{Part}

\def\TikZ;{{\rm Ti\emph{k}Z}}\def\PGF;{\textsc{pgf}}\def\foRest;{\textsc{Forest}}\def\FoRest;{\textsc{Forest}}
\usetikzlibrary{intersections}
\tikzset{>=latex}
\forestset{
  background tree/.style={
    for tree={text opacity=0.2,draw opacity=0.2,edge={draw opacity=0.2}}}
}

\def\getforestversion#1/#2/#3 v#4 #5\getforestversion{v#4}
\edef\forestversion{\expandafter\expandafter\expandafter\getforestversion\csname ver@forest.sty\endcsname\getforestversion}

\def\getforestdate#1/#2/#3 v#4 #5\getforestdate{#1/#2/#3}
\edef\forestdate{\expandafter\expandafter\expandafter\getforestdate\csname ver@forest.sty\endcsname\getforestdate}

\title{\FoRest;: a \PGF;/\TikZ;-based package for drawing linguistic trees\\\normalsize\forestversion}
\author{Sa\v so \v Zivanovi\'c\footnote{e-mail:
    \href{mailto:saso.zivanovic@guest.arnes.si}{saso.zivanovic@guest.arnes.si};
    web:
    \href{http://spj.ff.uni-lj.si/zivanovic/}{http://spj.ff.uni-lj.si/zivanovic/}}}
\def\settodayfromforestdateA#1/#2/#3 v#4 #5\settodayfromforestdateA{\def\year{#1}\def\month{#2}\def\day{#3}}
\def\settodayfromforestdate{\expandafter\expandafter\expandafter\settodayfromforestdateA\csname ver@forest.sty\endcsname\settodayfromforestdateA}

\begin{document}
  \DocInput{forest.dtx}
\end{document}
%</driver>
% \fi
%
% ^^A short verbatim: | (changes spaces into _)
% \DeleteShortVerb\|
% {\catcode`\_=12 \def\marshal{^^A
% \lstMakeShortInline[basicstyle=\ttfamily,literate={_}{ }1 {__}{_}1]}^^A
% \expandafter}\marshal |
% 
% \newbox\treebox
% \newbox\codebox
%
%
%
% {\settodayfromforestdate\maketitle}
%
% \begin{abstract}
% \FoRest; is a \PGF;/\TikZ;-based package for drawing linguistic (and
% other kinds of) trees.  Its main features are 
% \begin{inparaenum}[(i)]
% \item a packing algorithm which can produce very compact trees;
% \item a user-friendly interface consisting of the familiar bracket encoding of trees plus the
%   key--value interface to option-setting;
% \item many tree-formatting options, with control over option values of individual nodes and
%   mechanisms for their manipulation;
% \item the possibility to decorate the tree using the full power of \PGF;/\TikZ;;
% \item an externalization mechanism sensitive to code-changes.
% \end{inparaenum}
% \end{abstract}
%
% {\lstset{basicstyle=\ttfamily\scriptsize}^^A
% \begin{forestexample}[samplebox=\treebox,codebox=\codebox,pos=x,ekeynames={content,{id=.pgfmath,nfc},if,repeat,append,before drawing tree,where,y,alias,for ,name,for children,edge,before typesetting nodes,for tree,s sep,l,+,,for ancestors',typeset node}]
%   \pgfmathsetseed{14285}
%   \begin{forest}
%     random tree/.style n args={3}{% #1=max levels, #2=max children, #3=max content
%       content/.pgfmath={random(0,#3)},
%       if={#1>0}{repeat={random(0,#2)}{append={[,random tree={#1-1}{#2}{#3}]}}}{}},
%     for deepest/.style={before drawing tree={
%         alias=deepest,
%         where={y()<y("deepest")}{alias=deepest}{},
%         for name={deepest}{#1}}},
%     colorone/.style={fill=yellow,for children=colortwo}, colortwo/.style={fill=green,for children=colorone},
%     important/.style={draw=red,line width=1.5pt,edge={red,line width=1.5pt,draw}},
%     before typesetting nodes={colorone, for tree={draw,s sep=2pt,rotate={int(30*rand)},l+={5*rand}}},
%     for deepest={for ancestors'={important,typeset node}}
%     [,random tree={9}{3}{100}]
%   \end{forest}
% \end{forestexample}%
% \begin{center}\mbox{}\box\treebox\\\box\codebox\end{center}}
% \newpage
% {\parskip 0pt                ^^A We have to reset \parskip
%                              ^^A (bug in \LaTeX)
% \tableofcontents
% }
%
% \newpage
% \part{User's Guide}
% \section{Introduction}
%
% Over several years, I had been a grateful user of various packages
% for typesetting linguistic trees.  My main experience was with
% |qtree| and |synttree|, but as far as I can tell, all of the tools
% on the market had the same problem: sometimes, the trees were just
% too wide.  They looked something like the tree on the left,
% while I wanted something like the tree on the right.
% \begin{center}
%   \begin{forest}
%     baseline,
%     for tree={parent anchor=south,child anchor=north,l=7ex,s sep=10pt},
%     for children={fit=rectangle}
%     [CP
%       [DP
%         [D][NP[N][CP[C][TP[T][vP[v][VP[DP][V'[V][DP]]]]]]]]
%       [TP
%         [T][vP[v][VP[DP][V'[V][DP]]]]]
%     ]
%   \end{forest}
%   \hfill
%   \begin{forest}
%     baseline,
%     for tree={parent anchor=south,child anchor=north,l=7ex,s sep=10pt},
%     [CP
%       [DP
%         [D][NP[N][CP[C][TP[T][vP[v][VP[DP][V'[V][DP]]]]]]]]
%       [TP
%         [T][vP[v][VP[DP][V'[V][DP]]]]]
%     ]
%   \end{forest}
% \end{center}
%
% Luckily, it was possible to tweak some parameters by hand to get a
% narrower tree, but as I quite dislike constant manual adjustments, I
% eventually started to develop \foRest;.  It started out as
% xyforest, but lost the xy prefix as I became increasingly fond
% of \PGF;/\TikZ;, which offered not only a drawing package but also a
% `programming paradigm.'  It is due to the awesome power of the
% supplementary facilities of \PGF;/\TikZ; that \foRest; is now, I
% believe, the most flexible tree typesetting package for \LaTeX\ you can get. 
% 
% After all the advertising, a disclaimer.  Although the present version
% is definitely usable (and has been already used), the package and
% its documentation are still under development: comments, criticism,
% suggestions and code are all very welcome!
%
% \FoRest; is \href{http://www.ctan.org/pkg/forest}{available} at \href{http://www.ctan.org}{CTAN},
% and I have also started a \href{https://github.com/sasozivanovic/forest-styles}{style repository}
% at \href{https://github.com}{GitHub}.
% 
% \section{Tutorial}
% \label{sec:tutorial}
%
% This short tutorial progresses from basic through useful to
% obscure \dots
% 
% \subsection{Basic usage}
% \label{sec:basic-usage}
%
% A tree is input by enclosing its specification in a \ikeyname{forest}
% environment.  The tree is encoded by \emph{the bracket syntax}:
% every node is enclosed in square brackets; the children of a
% node are given within its brackets, after its content.
% {\lstdefinelanguage[my]{TeX}[LaTeX]{TeX}{keywords=forest,
%   otherkeywords={[,]},keywordstyle=\pstyle,texcsstyle={}}^^A
% \lstset{language={[my]TeX}}^^A
% \begin{forestexample}
%   \begin{forest}
%     [VP
%       [DP]
%       [V'
%         [V]
%         [DP]
%       ]
%     ]
%   \end{forest}
% \end{forestexample}}
% Binary trees are nice, but not the only thing this package can draw.
% Note that by default, the children are vertically centered with
% respect to their parent, i.e.\ the parent is vertically aligned with the midpoint between the
% first and the last child.
% \begin{forestexample}
%   \begin{forest}
%     [VP
%       [DP[John]]
%       [V'
%         [V[sent]]
%         [DP[Mary]]
%         [DP[D[a]][NP[letter]]]
%       ]
%     ]
%   \end{forest}
% \end{forestexample}
% Spaces around brackets are ignored --- format your code as you
% desire!
% \begin{forestexample}
%   \begin{forest}
%     [VP[DP][V'[V][DP]]]
%   \end{forest}
%   \quad
%   \begin{forest}[VP
%     [DP ] [ V'[V][ DP]]
%     ]\end{forest}
% \end{forestexample}
% If you need a square bracket as part of a node's content, use
% braces.  The same is true for the other characters which have a
% special meaning in the \foRest; package: comma
% |,| and equality sign |=|.
% \begin{forestexample}
%   \begin{forest}
%     [V{P,}
%       [{[DP]}]
%       [V'
%         [V]
%         [{===DP===}]]]
%   \end{forest}
% \end{forestexample}
% Macros in a node specification will be expanded when the node is
% drawn --- you can freely use formatting commands inside nodes!
% \begin{forestexample}
%   \begin{forest}
%     [VP
%       [{~\textbf~{DP}}]
%       [V'
%         [V]
%         [DP]]]
%   \end{forest}
% \end{forestexample}
%
% \newbox\GPone
% \begin{forestexample}[pos=x,samplebox=\treebox,codebox=\GPone]
%   \newbox\standardnodestrutbox
%   \setbox\standardnodestrutbox=\hbox to 0pt{\phantom{\forestOve{standard node}{content}}}
%   \def\standardnodestrut{\copy\standardnodestrutbox}
%   \forestset{
%     ~GP1~/.style 2 args={
%       for n={1}{baseline},
%       s sep=0pt, l sep=0pt,
%       for descendants={
%         l sep=0pt, l={#1},
%         anchor=base,calign=first,child anchor=north,
%         inner xsep=1pt,inner ysep=2pt,outer sep=0pt,s sep=0pt,
%       },
%       delay={
%         if content={}{phantom}{for children={no edge}},
%         for tree={
%           if content={O}{tier=OR}{},
%           if content={R}{tier=OR}{},
%           if content={N}{tier=N}{},
%           if content={x}{
%             tier=x,content={$\times$},outer xsep={#2},
%             for tree={calign=center},
%             for descendants={content format={\standardnodestrut\forestoption{content}}},
%             before drawing tree={outer xsep=0pt,delay={typeset node}},
%             s sep=4pt
%           }{},
%         },
%       },
%       before drawing tree={where content={}{parent anchor=center,child anchor=center}{}},
%     },
%     GP1/.default={5ex}{8.0pt},
%     associate/.style={%
%       tikz+={\draw[densely dotted](!)--(!#1);}},
%     spread/.style={
%       before drawing tree={tikz+={\draw[dotted](!)--(!#1);}}},
%     govern/.style={
%       before drawing tree={tikz+={\draw[->](!)--(!#1);}}},
%     p-govern/.style={
%       before drawing tree={tikz+={\draw[->](.north) to[out=150,in=30] (!#1.north);}}},
%     no p-govern/.style={
%       before drawing tree={tikz+={\draw[->,loosely dashed](.north) to[out=150,in=30] (!#1.north);}}},
%     encircle/.style={before drawing tree={circle,draw,inner sep=0pt}},
%     fen/.style={pin={[font=\footnotesize,inner sep=1pt,pin edge=<-]10:\textsc{Fen}}},
%     el/.style={content=\textsc{\textbf{##1}}},
%     head/.style={content=\textsc{\textbf{\underline{##1}}}}
%   }
% \end{forestexample}
% \input{\jobname.tmp}
% 
% All the examples given above produced top-down trees with centered
% children.  The other sections of this manual explain how various
% properties of a tree can be changed, making it possible to typeset
% radically different-looking trees.  However, you don't have to learn
% everything about this package to profit from its power.  Using
% styles, you can draw predefined types of trees with ease.  For
% example, a phonologist can use the \ikeyname{GP1} style from \S\ref{sec:gallery} to easily typeset
% (Government Phonology) phonological 
% representations.  The style is applied simply by writing its name
% before the first (opening) bracket of the tree.
% \begin{forestexample}[label=ex:gp1-frost]
%   \begin{forest} ~GP1~ [
%     [O[x[f]][x[r]]]
%     [R[N[x[o]]][x[s]]]
%     [O[x[t]]]
%     [R[N[x]]]
%   ]\end{forest}
% \end{forestexample}
% Of course, someone needs to develop the style --- you, me, your
% local \TeX nician \dots\@ Furtunately, designing styles is not very
% difficult once you know your \foRest; options.  If you write one,
% please contribute!
%
% I have started a \href{https://github.com/sasozivanovic/forest-styles}{style repository} at
% GitHub.  Hopefully, it will grow \dots\@ Check it out, download the styles \dots\ and contribute
% them! 
%
% \subsection{Options}
% \label{sec:options}
% 
% A node can be given various options, which control various
% properties of the node and the tree.  For example, at the end of
% section~\ref{sec:basic-usage}, we have seen that the \ikeyname{GP1} style
% vertically aligns the parent with the first
% child.  This is achieved by setting option \ikeyname{calign} (for
% \emph{c}hild-\emph{align}ment) to \ikeyname{first,aspect=calign} (child).
%
% Let's try.  Options are given inside the brackets, following the
% content, but separated from it by a comma.  (If multiple options are
% given, they are also separated by commas.)  A single option
% assignment takes the form \meta{option name}|=|\meta{option value}.  (There are
% also options which do not require a value or have a default value:
% these are given simply as \meta{option name}.)
% \begin{forestexample}[label=ex:numerals-simple,ekeynames={calign,{first,aspect=calign}}]
%   \begin{forest}
%     [\LaTeX\ numerals, ~calign=first~
%       [arabic[1][2][3][4]]
%       [roman[i][ii][iii][iv]]
%       [alph[a][b][c][d]]
%     ]
%   \end{forest}
% \end{forestexample}
%
% The experiment has succeeded only partially.  The root node's
% children are aligned as desired (so \ikeyname{calign}|=|\ikeyname{first,aspect=calign} applied to the
% root node), but the value of the \ikeyname{calign} option didn't get
% automatically assigned to the root's children! \emph{An option given
% at some node applies only to that node.} In \foRest;, the options
% are passed to the node's relatives via special options, called
% \emph{propagators}.  (We'll
% call the options that actually change some property of the node
% \emph{node options}.) What we need above is the \ikeyname{for tree} propagator.  Observe:
% \begin{forestexample}[label=ex:numerals-manual]
%   \begin{forest}
%     [\LaTeX\ numerals,
%          ~for tree~={calign=first}
%       [arabic[1][2][3][4]]
%       [roman[i][ii][iii][iv]]
%       [alph[a][b][c][d]]
%     ]
%   \end{forest}
% \end{forestexample}
% The value of propagator \ikeyname{for tree} is the option string that we
% want to process.  This option string is propagated to all the nodes in
% the subtree\footnote{It might be more precise to call this option
% \texttt{for subtree} \dots\@ but this name at least saves some typing.}
% rooted in the current node (i.e.\ the node where \ikeyname{for tree} was
% given), including the node itself.  (Propagator \ikeyname{for descendants} is
% just like \ikeyname{for tree}, only that it excludes the node itself.  There
% are many other \ikeyname{id={{for }}}|...| propagators; for the complete list, see
% sections~\ref{ref:propagators} and \ref{ref:node-walk}.)
%
% Some other useful options are \ikeyname{parent anchor}, \ikeyname{child anchor}
% and \ikeyname{tier}.  The \ikeyname{parent anchor} and \ikeyname{child anchor} options tell
% where the parent's and child's endpoint of the edge between them
% should be, respectively: usually, the value is either empty
% (meaning a smartly determined border point \citep[see][\S16.11]{tikzpgf2.10};  this is the default)
% or a compass direction \citep[see][\S16.5.1]{tikzpgf2.10}.  (Note: the \ikeyname{parent anchor}
% determines where the
% edge from the child will arrive to this node, not where the node's
% edge to its parent will start!)
%
% Option \ikeyname{tier} is what makes the
% skeletal points $\times$ in example \ref{ex:gp1-frost} align horizontally although they
% occur at different levels in the logical structure of the tree.
% Using option \ikeyname{tier} is very simple: just set |tier=tier_name| at
% all the nodes that you want to align horizontally.  Any tier name
% will do, as long as the tier names of different tiers are
% different \dots\@ (Yes, you can have multiple tiers!)
% \begin{forestexample}[point={tier},ekeynames={parent anchor,child anchor,tier},label=ex:tier-manual]
%   \begin{forest} 
%     [VP, for tree={~parent anchor~=south, ~child anchor~=north}
%       [DP[John,tier=word]]
%       [V'
%         [V[sent,tier=word]]
%         [DP[Mary,tier=word]]
%         [DP[D[a,tier=word]][NP[letter,tier=word]]]
%       ]
%     ]
%   \end{forest}
% \end{forestexample}
% Before discussing the variety of \foRest;'s options, it is worth
% mentioning that \foRest;'s node accepts all options \citep[see
% \S16]{tikzpgf2.10} that \TikZ;'s node does --- mostly, it just passes
% them on to \TikZ;.  For example, you can easily encircle a node like
% this:\footnote{If option \texttt{draw} was not given, the shape of the node
% would still be circular, but the edge would not be drawn.  For
% details, see \cite[\S16]{tikzpgf2.10}.}
% \begin{forestexample}
%   \begin{forest}
%     [VP,~circle~,~draw~
%       [DP][V'[V][DP]]
%     ]
%   \end{forest}
% \end{forestexample}
% 
% Let's have another look at example \ref{ex:gp1-frost}.  You will note that the skeletal
% positions were input by typing |x|s, while the result looks like
% this: $\times$ (input as |\times| in math mode). Obviously, the
% content of the node can be changed.  Even more, it can be
% manipulated: added to, doubled, boldened, emphasized, etc.  We will
% demonstrate this by making example \ref{ex:numerals-manual} a bit
% fancier: we'll write the input in the arabic numbers and have
% \LaTeX\ convert it to the other formats.  We'll start with the
% easiest case of roman numerals: to get them, we can use the (plain)
% \TeX\ command |\romannumeral|.  To change the content of the node,
% we use option \ikeyname{content}.  When specifying its new value, we can use
% |#1| to insert the current content.\footnote{This mechanism is called
% \emph{wrapping}. \ikeyname{content} is the only option where wrapping works implicitely (simply
% because I assume that wrapping will be almost exclusively used with this option).  To wrap values
% of other options, use handler \ikeyname{id=.wrap value,nfc}; see~\S\ref{ref:handlers}.}
% \begin{forestexample}[point={content,delay},ekeynames={for children,content,delay},label=ex:romannumeral]
%   \begin{forest}
%     [roman, delay={for children={content=\romannumeral#1}}
%       [1][2][3][4]
%     ]
%   \end{forest}
% \end{forestexample}
% This example introduces another option: \ikeyname{delay}.  Without it, the
% example wouldn't work: we would get arabic numerals.  This is so
% because of the order in which the options are processed.  The
% processing proceeds through the tree in a depth-first, parent-first fashion (first
% the parent is processed, and then its children, recursively).  The option string of a node is
% processed linearly, in the order they were given.  (Option \keyname{content}
% is specified implicitely and is always the first.) If a propagator
% is encountered, the options given as its value are propagated \emph{immediately}.  The net effect
% is that if the 
% above example contained simply |roman,for_children={content=...}|, the
% \keyname{content} option given there would be processed \emph{before} the
% implicit content options given to the children (i.e.\ numbers |1|,
% |2|, |3| and |4|).  Thus, there would be nothing for the
% |\romannumeral| to change --- it would actually crash; more generally, the content assigned
% in such a way would get overridden by the implicit content.  Option
% \ikeyname{delay} is true to its name.  It delays the processing of its option
% string argument until the whole tree was processed.  In other words,
% it introduces cyclical option processing.  Whatever is delayed in
% one cycle, gets processed in the next one.  The number of cycles is
% not limited --- you can nest \ikeyname{delay}s as deep as you need.
%
% Unlike \ikeyname{id={{for }}}|_...| options we have met before, option \ikeyname{delay} is not a
% spatial, but a temporal propagator.  Several other temporal propagators options exist, see
% \S\ref{ref:stages}.
%
% We are now ready to learn about simple conditionals.  Every node option has the corresponding
% \ikeyname{id={{if }}}|...| and \ikeyname{id={{where }}}|...| keys.
% \ikeyname{id={{if }}}\meta{option}|=|\meta{value}\meta{true options}\meta{false options} checks whether
% the value of \meta{option} equals \meta{value}.  If so, \meta{true options} are
% processed, otherwise \meta{false options}.  The \ikeyname{id={{where }}}|_...| keys are
% the same, but do this for the every node in the subtree; informally
% speaking, |where| = |for_tree| + |if|.  To see this in action,
% consider the rewrite of the \ikeyname{tier} example \ref{ex:tier-manual} from above.  We don't set
% the tiers manually, but rather put the terminal nodes (option
% \ikeyname{n children} is a read-only option containing the number
% of children) on tier \keyname{word}.\footnote{We could omit the braces around \texttt{0} because
% it is a single character. If we were hunting for nodes with 42 children, we'd have to write 
% \texttt{where n children=\{42\}...}.}
% \begin{forestexample}[ekeynames={tier,where ,n children}]
%   \begin{forest}
%     ~where n children~=0{tier=word}{}
%     [VP
%       [DP[John]]
%       [V'
%         [V[sent]]
%         [DP[Mary]]
%         [DP[D[a]][NP[letter]]]
%       ]
%     ]
%   \end{forest}
% \end{forestexample}
%
% Finally, let's talk about styles. Styles are simply collections of
% options.  (They are not actually defined in the \foRest; package, but
% rather inherited from |pgfkeys|.)  If you often want to have non-default 
% parent/child anchors, say south/north as in example \ref{ex:tier-manual}, you would save some
% typing by defining a style.  Styles are defined using \PGF;'s handler 
% |.style|. (In the example below, style |ns_edges| is first defined and then used.)
% \begin{forestexample}[ekeynames={tier,parent anchor,child anchor}]
%   \begin{forest}
%     ~sn edges~/~.style~={for tree={
%             parent anchor=south, child anchor=north}},
%     ~sn edges~
%     [VP, 
%       [DP[John,tier=word]]
%       [V'
%         [V[sent,tier=word]]
%         [DP[Mary,tier=word]]
%         [DP[D[a,tier=word]][NP[letter,tier=word]]]]]
%   \end{forest}
% \end{forestexample}
% If you want to use a style in more than one tree, you have to define it outside the \ikeyname{forest}
% environment.  Use macro \icmdname{forestset} to do this.
% \begin{lstlisting}
%   ~\forestset~{
%     sn edges/.style={for tree={parent anchor=south, child anchor=north}},
%     background tree/.style={for tree={
%                 text opacity=0.2,draw opacity=0.2,edge={draw opacity=0.2}}}
%   }
% \end{lstlisting}
%
% You might have noticed that the last two examples contain options (actually, keys) even before the
% first opening bracket, contradicting was said at the beginning of this section.  This is mainly
% just syntactic sugar (it can separate the design and the content): such preamble
% keys behave as if they were given in the root node, the only difference (which often does not
% matter) being that they get processed before all other root node options, even the implicit
% content.
% 
% \subsection{Decorating the tree}
% \label{sec:decorating}
%
% The tree can be decorated (think movement arrows) with arbitrary
% \TikZ; code.
% \begin{forestexample}
%   \begin{forest}
%     [XP
%       [specifier]
%       [X$'$
%         [X$^0$]
%         [complement]
%       ]
%     ]
%     ~\node at (current bounding box.south)
%       [below=1ex,draw,cloud,aspect=6,cloud puffs=30]
%       {\emph{Figure 1: The X' template}};~
%   \end{forest}
% \end{forestexample}
% 
% However, decorating the tree would make little sense if one could
% not refer to the nodes.  The simplest way to do so is to give them a
% \TikZ; name using the \ikeyname{name} option, and then use this name in \TikZ;
% code as any other (\TikZ;) node name.
% \begin{forestexample}[point=name,ekeynames={phantom,name}]
%   \begin{forest}
%     [CP
%       [DP,name=spec CP]
%       [\dots
%         [,phantom]
%         [VP
%           [DP]
%           [V'
%             [V]
%             [DP,name=object]]]]]
%     \draw[->,dotted] ~(object)~ to[out=south west,in=south] ~(spec CP)~;
%   \end{forest}
% \end{forestexample}
% 
% It gets better than this, however! In the previous examples, we put
% the \TikZ; code after the tree specification, i.e.\ after the closing
% bracket of the root node.  In fact, you can put \TikZ; code after
% \emph{any} closing bracket, and \foRest; will know what the current
% node is. (Putting the code after a node's bracket is actually just a
% special way to provide a value for option \ikeyname{tikz} of that node.)  To
% refer to the current node, simply use an empty node name.  This works both with and without
% anchors \citep[see][\S16.11]{tikzpgf2.10}: below, |(.south east)| and |()|. 
% \begin{forestexample}[ekeynames={phantom,name}]
%   \begin{forest}
%     [CP
%       [DP,name=spec CP]
%       [\dots
%         [,phantom]
%         [VP
%           [DP]
%           [V'
%             [V]
%             [DP,draw] ~{~
%               \draw[->,dotted] ~()~ to[out=south west,in=south] (spec CP);
%               \draw[<-,red] ~(.south east)~--++(0em,-4ex)--++(-2em,0pt)
%                    node[anchor=east,align=center]{This guy\\has moved!};
%                  ~}~
%           ]]]]
%   \end{forest}
% \end{forestexample}
%
% Important: \emph{the \TikZ; code should usually be enclosed in braces} to hide
% it from the bracket parser.  You don't want all the bracketed code
% (e.g.\ |[->,dotted]|) to become tree nodes, right? (Well, they
% probably wouldn't anyway, because \TeX\ would spit out a thousand
% errors.)
%
% \bigskip
% 
% Finally, the most powerful tool in the node reference toolbox:
% \emph{relative nodes}.  It is possible to refer to other nodes which stand
% in some (most often geometrical) relation to the current node.  To
% do this, follow the node's name with a |!| and a \emph{node walk}
% specification.
%
% A node walk is a concise\footnote{Actually, \foRest; distinguishes two kinds of
% steps in node walks: long and short steps.  This section introduces only short steps.  See 
% \S\ref{ref:node-walk}.} way of expressing node
% relations.  It is simply a string of steps, which are represented by single
% characters, where: \ikeyname{u} stands for the parent node (up); \ikeyname{p} for the
% previous sibling; \ikeyname{n,aspect=short step} for the next sibling; \ikeyname{s,aspect=short step} for \emph{the}
% sibling (useful only in binary trees);\ekeyname{3} \ikeyname{1}, \ikeyname{2},
% \ekeyname{3}\ekeyname{4}\ekeyname{5}\ekeyname{6}\ekeyname{7}\ekeyname{8}\dots\
% \ikeyname{9} for first,
% second, \dots\ ninth child; \ikeyname{l,aspect=short step}, for the last child, etc.  For the
% complete specification, see section~\ref{ref:node-walk}.
%
% To see the node walk in action, consider the following examples.
% In the first example, the agree arrow connects the V node, specified
% simply as |()|, since the \TikZ; code follows |[V]|, and the DP node,
% which is described as ``a sister of V's parent'': |!us| = up +
% sibling. 
% \begin{forestexample}
%   \begin{forest}
%     [VP
%       [DP] 
%       [V'
%         [V] {\draw[<->] ~()~
%              .. controls +(left:1cm) and +(south west:0.4cm) ..
%              node[very near start,below,sloped]{\tiny agree}
%              ~(!us)~;}
%         [DP]
%       ]
%     ]
%   \end{forest}
% \end{forestexample}
%
% {\footnotesize\begin{forestexample}[ekeynames={phantom,tikz,fit to tree},samplebox=\treebox,codebox=\codebox,pos=x,basicstyle=\footnotesize\ttfamily]
%   \begin{forest}
%     [CP
%       [DP$_1$]
%       [\dots
%         [,phantom]
%         [VP,tikz={\node [draw,red,~fit to tree~]{};}
%           [DP$_2$] 
%           [V'
%             [V]
%             [DP$_3$]
%     ]]]]
%   \end{forest}
% \end{forestexample}}
% The second example uses \TikZ;'s fitting library to compute the
% smallest rectangle containing node VP, its first child (DP$_2$) and its last grandchild (DP$_3$).
% The example also illustrates that the \TikZ; code 
% can be specified via the ``normal'' option syntax, i.e.\ as a value
% to option \ikeyname{tikz}.\footnote{\label{fn:fit-to-tree}Actually, there's a simpler way to do this: use \ikeyname{fit to tree}!\\\raisebox{\dimexpr-\dp\codebox+1ex\relax}{\box\treebox}\hfill\box\codebox}
% \begin{forestexample}[point=tikz,ekeynames={phantom,tikz}]
%   \begin{forest}
%     [CP
%       [DP$_1$]
%       [\dots
%         [,phantom]
%         [VP,tikz={\node [draw,red,fit=~()(!1)(!ll)~] {};}
%           [DP$_2$] 
%           [V'
%             [V]
%             [DP$_3$]
%     ]]]]
%   \end{forest}
% \end{forestexample}
% 
%
% \subsection{Node positioning}
% \label{sec:node-positioning}
%
% \FoRest; positions the nodes by a recursive bottom-up algorithm which, for every non-terminal node,
% computes the positions of the node's children relative to their parent.  By default, all the
% children will be aligned horizontally some distance down from their parent: the ``normal'' tree
% grows down.  More generally, however, the direction of growth can change from node to node; this is
% controlled by option \ikeyname{grow}=\meta{direction}.\footnote{The direction can be specified either in
%   degrees (following the standard mathematical convention that $0$ degrees is to the right, and that
%   degrees increase counter-clockwise) or by the compass directions: \texttt{east}, \texttt{north east},
%   \texttt{north}, etc.}  The system thus computes and stores the positions of children using a
% coordinate system dependent on the parent, called an \emph{ls-coordinate system}: the origin is the
% parent's anchor; l-axis is in the direction of growth in the parent; s-axis is orthogonal to the
% l-axis (positive side in the counter-clockwise direction from $l$-axis); l stands for \emph{l}evel,
% s for \emph{s}ibling.  The example shows the ls-coordinate system for a node with |grow=45|.
%
% \begin{forestexample}[point=grow,ekeynames=grow]
%   \begin{forest} background tree
%     [parent, grow=45
%       [child 1][child 2][child 3][child 4][child 5]
%     ]
%     \draw[,->](-135:1cm)--(45:3cm) node[below]{$l$};
%     \draw[,->](-45:1cm)--(135:3cm) node[right]{$s$};
%   \end{forest}
% \end{forestexample}
%
% \begin{forestexample}[basicstyle=\scriptsize\ttfamily,samplebox=\treebox,codebox=\codebox,pos=x]
%   \newcommand\measurexdistance[5][####1]{\measurexorydistance{#2}{#3}{#4}{#5}{\x}{-|}{(5pt,0)}{#1}}
%   \newcommand\measureydistance[5][####1]{\measurexorydistance{#2}{#3}{#4}{#5}{\y}{|-}{(0,5pt)}{#1}}
%   \tikzset{dimension/.style={<->,>=latex,thin,every rectangle node/.style={midway,font=\scriptsize}},
%     guideline/.style=dotted}
%   \newdimen\absmd
%   \def\measurexorydistance#1#2#3#4#5#6#7#8{%
%     \path #1 #3 #6 coordinate(md1) #1; \draw[guideline] #1 --  (md1);
%     \path (md1) #6 coordinate(md2) #2; \draw[guideline] #2 -- (md2);
%     \path let \p1=($(md1)-(md2)$), \n1={abs(#51)} in \pgfextra{\xdef\md{#51}\global\absmd=\n1\relax};
%     \def\distancelabelwrapper##1{#8}%
%     \ifdim\absmd>5mm
%       \draw[dimension] (md1)--(md2) node[#4]{\distancelabelwrapper{\uselengthunit{mm}\rndprintlength\absmd}};
%     \else
%       \ifdim\md>0pt
%         \draw[dimension,<-] (md1)--+#7; \draw[dimension,<-] let \p1=($(0,0)-#7$) in (md2)--+(\p1);
%       \else
%         \draw[dimension,<-] let \p1=($(0,0)-#7$) in (md1)--+(\p1); \draw[dimension,<-] (md2)--+#7;
%       \fi
%       \draw[dimension,-] (md1)--(md2) node[#4]{\distancelabelwrapper{\uselengthunit{mm}\rndprintlength\absmd}};
%     \fi}
% \end{forestexample}
% \input{\jobname.tmp}
% 
% The l-coordinate of children is (almost) completely under your control, i.e.\ you set what is
% often called the level distance by yourself.  Simply set option \ikeyname{l} to change the
% distance of a node from its parent.  More precisely, \ikeyname{l}, and the related option
% \ikeyname{s}, control the distance between the (node) anchors of a node and its parent.  The
% anchor of a node can be changed using option \ikeyname{anchor}: by default, nodes are anchored at
% their base; see \cite[\S16.5.1]{tikzpgf2.10}.)  In the example below, positions of the anchors are
% shown by dots: observe that anchors of nodes with the same \ikeyname{l} are aligned and that the
% distances between the anchors of the children and the parent are as specified in the
% code.\footnote{Here are the definitons of the macros for measuring distances.  Args: the x or y
% distance between points \#2 and \#3 is measured; \#4 is where the distance line starts (given as an
% absolute coordinate or an offset to \#2); \#5 are node options; the optional arg \#1 is the format of
% label. (Lengths are printed using package \texttt{printlen}.)
%
% \vskip-2ex \box\codebox}
% \begin{forestexample}[pos=t,ekeynames={for tree,tikz,l,anchor}]
%   \begin{forest} background tree,
%     for tree={draw,tikz={\fill[](.anchor)circle[radius=1pt];}}
%     [parent
%       [child 1, ~l~=10mm, ~anchor~=north west]
%       [child 2, ~l~=10mm, ~anchor~=south west]
%       [child 3, ~l~=12mm, ~anchor~=south]
%       [child 4, ~l~=12mm, ~anchor~=base east]
%     ]
%     \measureydistance[\texttt{l(child)}=#1]{(!2.anchor)}{(.anchor)}{(!1.anchor)+(-5mm,0)}{left}
%     \measureydistance[\texttt{l(child)}=#1]{(!3.anchor)}{(.anchor)}{(!4.anchor)+(5mm,0)}{right}
%     \measurexdistance[\texttt{s sep(parent)}=#1]{(!1.south east)}{(!2.south west)}{+(0,-5mm)}{below}
%     \measurexdistance[\texttt{s sep(parent)}=#1]{(!2.south east)}{(!3.south west)}{+(0,-5mm)}{below}
%     \measurexdistance[\texttt{s sep(parent)}=#1]{(!3.south east)}{(!4.south west)}{+(0,-8mm)}{below}
%   \end{forest}
% \end{forestexample}
%
% Positioning the chilren in the s-dimension is the job and \emph{raison d'etre} of the package.  As a
% first approximation: the children are positioned so that the distance between them is at least the
% value of option \ikeyname{s sep} (s-separation), which defaults to double \PGF;'s |inner_xsep| (and this
% is 0.3333em by default).  As you can see from the example above, s-separation is the distance
% between the borders of the nodes, not their anchors!
%
% A fuller story is that \ikeyname{s sep} does not control the s-distance between two siblings, but rather
% the distance between the subtrees rooted in the siblings.  When the green and the yellow child of
% the white node are s-positioned in the example below, the horizontal
% distance between the green and the yellow subtree is computed.  It can be seen with the naked eye
% that the closest nodes of the subtrees are the TP and the DP with a red border.  Thus, the children
% of the root CP (top green DP and top yellow TP) are positioned so that the horizontal distance
% between the red-bordered TP and DP equals \ikeyname{s sep}.
% \begin{forestexample}[ekeynames={for tree,s sep}]
%   \begin{forest}
%     important/.style={name=#1,draw={red,thick}}
%     [CP, ~s sep~=3mm, for tree=draw
%       [DP, for tree={fill=green}
%         [D][NP[N][CP[C][TP,important=left
%         [T][vP[v][VP[DP][V'[V][DP]]]]]]]]
%       [TP,for tree={fill=yellow}
%         [T][vP[v][VP[DP,important=right][V'[V][DP]]]]]
%     ]
%     \measurexdistance[\texttt{s sep(root)}=#1]
%       {(left.north east)}{(right.north west)}{(.north)+(0,3mm)}{above}
%   \end{forest}
% \end{forestexample}
%
% Note that \foRest; computes the same distances between nodes
% regardless of whether the nodes are filled or not, or whether their
% border is drawn or not.  Filling the node or drawing its border does
% not change its size.  You can change the size by adjusting \TikZ;'s
% |inner_sep| and |outer_sep| \citep[\S16.2.2]{tikzpgf2.10}, as shown
% below:
% \begin{forestexample}[ekeynames={for tree,s sep}]
%   \begin{forest}
%     important/.style={name=#1,draw={red,thick}}
%     [CP, s sep=3mm, for tree=draw
%       [DP, for tree={fill=green,~inner sep~=0}
%         [D][NP,important=left[N][CP[C][TP[T][vP[v]
%         [VP[DP][V'[V][DP]]]]]]]]
%       [TP,for tree={fill=yellow,~outer sep~=2pt}
%         [T,important=right][vP[v][VP[DP][V'[V][DP]]]]]
%     ]
%     \measurexdistance[\texttt{s sep(root)}=#1]
%       {(left.north east)}{(right.north west)}{(.north)+(0,3mm)}{above}
%   \end{forest}
% \end{forestexample}
% (This looks ugly!) Observe that having increased |outer sep| makes the edges stop touching
% borders of the nodes. By (\PGF;'s) default, the |outer sep| is exactly half of the border
% line width, so that the edges start and finish precisely at the border.
%
% Let's play a bit and change the \ikeyname{l} of the root of the yellow subtree.  Below, we set the
% vertical 
% distance of the yellow TP to its parent to 3\,cm: and the yellow submarine sinks diagonally \dots\@
% Now, the closest nodes are the higher yellow DP and the green VP.
% \begin{forestexample}[ekeynames={l,s sep,for tree}]
%   \begin{forest}
%     important/.style={name=#1,draw={red,thick}}
%     [CP, s sep=3mm, for tree=draw
%       [DP, for tree={fill=green}
%         [D][NP[N][CP[C][TP
%         [T][vP[v][VP,important=left[DP][V'[V][DP]]]]]]]]
%       [TP,for tree={fill=yellow}, l=3cm
%         [T][vP[v][VP[DP,important=right][V'[V][DP]]]]]
%     ]
%     \measurexdistance[\texttt{s sep(root)}=#1]
%       {(left.north east)}{(right.north west)}{(.north)+(0,3mm)}{above}
%   \end{forest}
% \end{forestexample}
%
% Note that the yellow and green nodes are not vertically aligned anymore.  The positioning algorithm
% has no problem with that.  But you, as a user, might have, so here's a neat trick.  (This only works
% in the ``normal'' circumstances, which are easier to see than describe.)
% \begin{forestexample}[label=ex:l*,ekeynames={l,*,phantom,for tree}]
%   \begin{forest}
%     [CP, for tree=draw
%       [DP, for tree={fill=green},~l*~=3
%         [D][NP]]
%       [TP,for tree={fill=yellow}
%         [T][VP[DP][V'[V][DP]]]]
%     ]
%   \end{forest}
% \end{forestexample}
% We have changed DP's \ikeyname{l}'s value via ``augmented assignment'' known from
% many programming languages: above, we have used |l*=3| to triple
% \ekeyname{l}'s value; we could have also said |l+=5mm| or |l-=5mm| to
% increase or decrease its value by 5\,mm, respectively.  This
% mechanism works for every numeric and dimensional option in \foRest;.
%
% Let's now play with option \ikeyname{s sep}.
% \begin{forestexample}[ekeynames={s sep,l,*,for tree}]
%   \begin{forest}
%     [CP, for tree=draw, ~s sep~=0
%       [DP, for tree={fill=green},l*=3
%         [D][NP]]
%       [TP,for tree={fill=yellow}
%         [T][VP[DP][V'[V][DP]]]]
%     ]
%   \end{forest}
% \end{forestexample}
% Surprised? You shouldn't be. The value of \ikeyname{s sep} at a given node controls the s-distance
% \emph{between the subtrees rooted in the children of that node}!  It has no influence over the
% internal geometry of these subtrees. In the above example, we have set |s_sep=0| only for the root
% node, so the green and the yellow subtree are touching, although internally, their nodes are not.
% Let's play a bit more.  In the following example, we set the \ikeyname{s sep} to: $0$ at the last
% branching level (level 3; the root is level 0), to 2\,mm at level 2, to 4\,mm at level 1 and to
% 6\,mm at level 0.
% 
% \begin{forestexample}[label=ex:spread-s,point={level},ekeynames={level,for tree,s sep}]
%   \begin{forest}
%     for tree={~s sep~=(3-level)*2mm}
%     [CP, for tree=draw
%       [DP, for tree={fill=green},l*=3
%         [D][NP]]
%       [TP,for tree={fill=yellow}
%         [T][VP[DP][V'[V][DP]]]]
%     ]
%     \measurexdistance{(!11.south east)}{(!12.south west)}{+(0,-5mm)}{below}
%     \path(md2)-|coordinate(md)(!221.south east);
%     \measurexdistance{(!221.south east)}{(!222.south west)}{(md)}{below}
%     \measurexdistance{(!21.north east)}{(!22.north west)}{+(0,2cm)}{above}
%     \measurexdistance{(!1.north east)}{(!221.north west)}{+(0,-2.4cm)}{below}
%   \end{forest}
% \end{forestexample}
% As we go up the tree, the nodes ``spread.'' At the lowest level, V and DP are touching.  In the
% third level, the \ikeyname{s sep} of level 2 applies, so DP and V' are 2\,mm apart.  At the second
% level we 
% have two pairs of nodes, D and NP, and T and TP: they are 4\,mm apart.  Finally, at level 1, the
% \ikeyname{s sep} of level 0 applies, so the green and yellow DP are 6\,mm apart.  (Note that D and NP are
% at level 2, not 4! Level is a matter of structure, not geometry.)
%
% As you have probably noticed, this example also demostrated that we can compute the value of an
% option using an (arbitrarily complex) formula.  This is thanks to \PGF;'s module |pgfmath|.
% \FoRest; provides an interface to |pgfmath| by defining |pgfmath| functions for every node option,
% and some other information, like the \ikeyname{level} we have used above, the number of children
% \ikeyname{n children}, the sequential number of the child \ikeyname{n}, etc.  For details, see
% \S\ref{ref:pgfmath}. 
%
% The final separation parameter is \ikeyname{l sep}.  It determines the minimal
% separation of a 
% node from its descendants.  It the value of \ikeyname{l} is too small, then \emph{all} the
% children (and thus their subtrees)
% are pushed 
% away from the parent (by increasing their \ikeyname{l}s), so that the distance between the node's
% and each child's subtree
% boundary is at least \ikeyname{l sep}.  The initial \ikeyname{l} can be too small for
% two reasons: either 
% some child is too high, or the parent is too deep.  The first problem is easier to see: we force the
% situation using a bottom-aligned multiline node.  (Multiline nodes can be easily created using |\\|
% as a line-separator.  However, you must first specify the horizontal alignment using option
% \ikeyname{align} (see \S\ref{ref:node-appearance}). 
% Bottom vertical alignment is achieved by setting \ikeyname{base}|=|\ikeyname{bottom,aspect=base};
% the default, unlike in \TikZ;, is \ikeyname{base}|=|\ikeyname{top,aspect=base}). 
% \begin{forestexample}[point={align,base},ekeynames={align,base}]
%   \begin{forest}
%     [parent
%       [child]
%       [child]
%       [a very\\tall\\child, align=center, base=bottom]
%     ]
%   \end{forest}
% \end{forestexample}
%
% The defaults for \ikeyname{l} and \ikeyname{l sep} are set so that they ``cooperate.''
% What this 
% means and why it is necessary is a complex issue explained in \S\ref{sec:defaults}, which you will
% hopefully never have to read \dots\@ You might be out of luck, however.  What if you 
% needed to decrease the level distance? And nothing happened, like below on the left?  Or, what if
% you used lots of parenthesis in your nodes?  And got a strange vertical misalignment, like below
% on the right?  Then rest assured that these (at least) are features not bugs and read
% \S\ref{sec:defaults}.
% \begin{forestexample}[pos=t,label=ex:misalignments,ekeynames={phantom,for children,fit,for,baseline,edge,for descendants,content,{id=.pgfmath,nfc}}]
%   \begin{forest}
%     [,phantom,for children={l sep=1ex,fit=band,
%       for=1{edge'=,l=0},baseline}
%       [{l+=5mm},for descendants/.pgfmath=content
%         [AdjP[AdvP][Adj'[Adj][PP]]]]
%       [default
%         [AdjP[AdvP][Adj'[Adj][PP]]]]
%       [{l-=5mm},for descendants/.pgfmath=content
%         [AdjP[AdvP][Adj'[Adj][PP]]]]
%     ]
%     \path (current bounding box.west)|-coordinate(l1)(!212.base);
%     \path (current bounding box.west)|-coordinate(l2)(!2121.base);
%     \path (current bounding box.east)|-coordinate(r1)(!212.base);
%     \path (current bounding box.east)|-coordinate(r2)(!2121.base);
%     \draw[dotted] (l1)--(r1) (l2)--(r2);
%   \end{forest}
%   \hspace{4cm}
%   \raisebox{0pt}[\height][0pt]{\begin{forest}
%     [x forest, baseline
%       [x[x[x[x[x[x[x[x[x[x[x[x[x]]]]]]]]]]]]]
%       [(x)[(x)[(x)[(x)[(x)[(x)[(x)[(x)[(x)[(x)[(x)[(x)[(x)]]]]]]]]]]]]]
%     ]
%   \end{forest}}
% \end{forestexample}
% 
% \subsubsection{The defaults, or the hairy details of vertical alignment}
% \label{sec:defaults}
% 
% In this section we discuss the default values of options controlling the l-alignment of the nodes.
% The defaults are set with top-down trees in mind, so l-alignment is actually vertical alignment.
% There are two desired effects of the defaults.  First, the spacing between the nodes of a tree
% should adjust to the current font size.  Second, the nodes of a given level should be vertically
% aligned (at the base), if possible.
% 
% Let us start with the base alignment: \TikZ;'s default is to anchor the nodes at their center,
% while \foRest;, given the usual content of nodes in linguistic representations, rather anchors them
% at the base \cite[\S16.5.1]{tikzpgf2.10}.  The difference is particularly clear for a ``phonological''
% representation:
% \begin{forestexample}[ekeynames={for tree,anchor}]
%   \begin{forest} for tree={anchor=center}
%     [maybe[m][a][y][b][e]]
%   \end{forest}\quad
%   \begin{forest}
%     [maybe[m][a][y][b][e]]
%   \end{forest}
% \end{forestexample}
% The following example shows that the vertical distance between nodes depends on the current font size.
% \begin{forestexample}
%   \hbox{\small A small tree
%   \begin{forest} baseline
%     [VP[DP][V'[V][DP]]]
%   \end{forest}
%   \normalsize and
%   \large
%   a large tree
%   \begin{forest} baseline
%     [VP[DP][V'[V][DP]]]
%   \end{forest}}
% \end{forestexample}
% Furthermore, the distance between nodes also depends on the value of \PGF;'s |inner_sep| (which
% also depends on the font size by default: it equals 0.3333\,em).
% \[\ikeyname{l sep}=\mbox{height}(\mbox{strut})+\mbox{\texttt{inner ysep}}\]
% The default value of \ikeyname{s sep} depends on |inner_xsep|: more precisely, it equals double
% |inner_xsep|). 
% \begin{forestexample}[ekeynames={baseline,for tree}]
%   \begin{forest} baseline,for tree=draw
%     [VP[DP][V'[V][DP]]]
%   \end{forest}    
%   \pgfkeys{/pgf/inner sep=0.6666em}
%   \begin{forest} baseline,for tree=draw
%     [VP[DP][V'[V][DP]]]
%   \end{forest}    
% \end{forestexample}
% Now a hairy detail: the formula for the default \ikeyname{l}.
% \[\ikeyname{l}=\ikeyname{l sep}+2\cdot\mbox{\texttt{outer ysep}}+\mbox{total
% height}(\mbox{`dj'})\]
%
% To understand what this is all about we must first explain why it is necessary to set the default
% \ikeyname{l} at all?  Wouldn't it be enough to simply set \ikeyname{l sep} (leaving
% \ikeyname{l} at 0)?
% The problem is that not all letters have the same height and depth.  A tree where the vertical
% position of the nodes would be controlled solely by (a constant) \ikeyname{l sep} could
% result in a ragged tree (although the height of the child--parent edges would be constant).
% \begin{forestexample}[ekeynames={baseline,for children,no edge,name,for descendants,l}]
%   \begin{forest}
%     [default,baseline,for children={no edge}
%       [DP
%         [AdjP[Adj]]
%         [D'[D][NP,name=np]]]]
%     \path (current bounding box.west)|-coordinate(l)(np.base);
%     \path (current bounding box.east)|-coordinate(r)(np.base);
%     \draw[dotted] (l)--(r);
%   \end{forest}
%   \begin{forest}
%     [{l=0},baseline,for children={no edge}    
%       [DP,for descendants={l=0}
%         [AdjP[Adj]]
%         [D'[D][NP,name=np]]]]
%     \path (current bounding box.west)|-coordinate(l)(np.base);
%     \path (current bounding box.east)|-coordinate(r)(np.base);
%     \draw[dotted] (l)--(r);
%   \end{forest}
% \end{forestexample}
% The vertical misalignment of Adj in the right tree is a consequence of the fact that letter j is the
% only letter with non-zero depth in the tree.  Since only \ikeyname{l sep} (which is constant
% throughout the tree) controls the vertical positioning, Adj, child of Ad\emph{j}P, is pushed lower
% than the other nodes on level 2.  If the content of the nodes is variable enough (various heights
% and depths), the cumulative effect can be quite strong, see the right tree of example
% \ref{ex:misalignments}.
% 
% Setting only a default \ikeyname{l sep} thus does not work well enough in general.  The same
% is true for the reverse possibility, setting a default \ikeyname{l} (and leaving \ikeyname{l sep} at 0).  In the example below, the depth of the multiline node (anchored at the top
% line) is such that the child--parent edges are just too short if the level distance is kept constant.
% Sometimes, misalignment is much preferred \dots
% \begin{forestexample}[ekeynames={align,{center,aspect=align},for tree,l sep}]
%   \mbox{}\begin{forest}
%     [default
%       [first child[a][b][c]]
%       [second child\\\scriptsize(a copy),
%        align=center[a][b][c]]
%     ]
%   \end{forest}\\
%   \begin{forest} for tree={l sep=0}
%     [{\texttt{l sep}=0}
%       [first child[a][b][c]]
%       [second child\\\scriptsize(a copy),
%                    align=center[a][b][c]]
%     ]
%   \end{forest}
% \end{forestexample}
% 
% Thus, the idea is to make \ikeyname{l} and \ikeyname{l sep} work as a team:
% \ikeyname{l} prevents 
% misalignments, if possible, while \ikeyname{l sep} determines the minimal vertical distance
% between levels.  Each of the two options deals with a certain kind of a ``deviant'' node, i.e.\ a
% node which is too high or too deep, or a node which is not high or deep enough, so we need to
% postulate what a \emph{standard} node is, and synchronize them so that their effect on standard
% nodes is the same.
% 
% By default, \foRest; sets the standard node to be a node containing letters d and j.  Linguistic
% representations consist mainly of letters, and in the \TeX's default Computer Modern font, d is the
% highest letter (not character!), and j the deepest, so this decision guarantees that trees
% containing only letters will look nice.  If the tree contains many parentheses, like the right
% tree of example \ref{ex:misalignments}, the default will of course fail
% and the standard node needs to be modified.  But for many applications, including nodes with
% indices, the default works.
% 
% The standard node can be changed using macro \icmdname{forestStandardNode};
% see \ref{ref:standard-node}. 
% 
% \subsection{Advanced option setting}
% \label{sec:advanced-option-setting}
%
% We have already seen that the value of options can be manipulated: in \ref{ex:romannumeral} we have
% converted numeric content from arabic into roman numerals using the \emph{wrapping} mechanism
% |content=\romannumeral#1|; in \ref{ex:l*}, we have tripled the value of |l|
% by saying |l*=3|.  In this section, we will learn about the mechanisms for setting and
% referring to option values offered by \foRest;.
%
% One other way to access an option value is using macro \icmdname{forestoption}.  The macro takes a
% single argument: an option name.  (For details, see \S\ref{ref:options-and-keys}.)  In the
% following example, the node's child sequence number is appended to the existing content. (This is
% therefore also an example of wrapping.)
% \begin{forestexample}[label=ex:forestoption,ekeynames={phantom,delay,for descendants,content,n},ecmdnames={forestoption}]
%   \begin{forest}
%     [,phantom,delay={for descendants={
%       content=#1$_{~\forestoption~{n}}$}}
%     [c][o][u][n][t]]
%   \end{forest}
% \end{forestexample}
%
% However, only options of the current node can be accessed using \icmdname{forestoption}.  To
% access option values of other nodes, \foRest;'s extensions to the \PGF;'s mathematical library
% |pgfmath|, documented in \citep[part VI]{tikzpgf2.10}, must be used.  To see |pgfmath| in action,
% first take a look at the crazy tree on the title page, and observe how the nodes are
% rotated: the value given to (\TikZ;) option \texttt{rotate} is a full-fledged |pgfmath| expression
% yielding an integer
% in the range from $-30$ to $30$.  Similiarly, \ikeyname{l}\ikeyname{+} adds a random float
% in the $[-5,5]$ range to the current value of \ikeyname{l}.
%
% Example \ref{ex:spread-s} demonstrated that information about
% the node, like the node's level, can be accessed within |pgfmath| expressions.  All
% options are accessible in this way, i.e.\ every option has a corresponding |pgfmath| function.
% For example, we could rotate the node based on its content:
% \begin{forestexample}[ekeynames={delay,for tree,rotate,content}]
%   \begin{forest}
%     delay={for tree={~rotate=content~}}
%     [30[-10[5][0]][-90[180]][90[-60][90]]]
%   \end{forest}
% \end{forestexample}
% 
% All numeric, dimensional and boolean options of \foRest; automatically pass the given value
% through |pgfmath|.  If you need pass the value through |pgfmath| 
% for a string option, use the \ikeyname{id=.pgfmath,nfc} handler.  The following example sets the node's
% content to its child sequence number (the root has child sequence number 0).
% \begin{forestexample}[ekeynames={delay,for tree,content,n,{id=.pgfmath,nfc}}]
%   \begin{forest}
%     delay={for tree={content/~.pgfmath~=int(n)}}
%     [[[][][]][[][]]]
%   \end{forest}
% \end{forestexample}
%
% As mentioned above, using |pgfmath| it is possible to access options of non-current nodes.  This
% is achieved by providing the option function with a \imeta{relative node name}
% (see~\S\ref{ref:relative-node-names}) argument.\footnote{The form without
% parentheses \texttt{option\string_name} that we have been using until now to refer to an option of
% the 
% current node is just a short-hand notation for \texttt{option\string_name()} --- note that in some
% contexts, like preceding \texttt{+} or \texttt{-}, the short form does not work! (The same
% seems to be true for all pgfmath functions with ``optional'' arguments.)}  In the next example, we
% rotate the node based on the content of its parent.
% \begin{forestexample}[ekeynames={delay,for tree,rotate,content,u}]
%   \begin{forest}
%     delay={for descendants={rotate=content~("!u")~}}
%     [30[-10[5][0]][-90[180]][90[-60][90]]]
%   \end{forest}
% \end{forestexample}
% Note that the argument of the option function is surrounded by double quotation marks: this is
% to prevent evaluation of the relative node name as a |pgfmath| function --- which it is not.
%
% Handlers \ikeyname{id=.wrap pgfmath arg,nfc} and \ikeyname{id=.wrap $n$ pgfmath args,nfc}
% (for $n=2,\dots,8$) combine the wrapping mechanism with the |pgfmath| evaluation.  The
% idea is to compute (most often, just access option values) arguments using |pgfmath| and then
% wrap them with the given macro.  Below, this is used to include the number of parent's children in
% the index. 
% \begin{forestexample}[ekeynames={phantom,delay,for descendants,content,n,n children,{id=.wrap 3 pgfmath args,nfc}}]
%   \begin{forest} [,phantom,delay={for descendants={
%               ~content/.wrap 3 pgfmath args=
%               {#1$_{#2/#3}$}{content}{n}{n_children("!u")}~}}
%     [c][o][u][n][t]]
%   \end{forest}
% \end{forestexample}
% Note the underscore |__| character in |n__children|: in |pgfmath| function names, spaces,
% apostrophes and other non-alphanumeric characters from option names are all replaced by
% underscores. 
% 
% As another example, let's make the numerals example \ref{ex:numerals-simple} a bit fancier.
% The numeral type is read off the parent's content and used to construct the appropriate control
% sequence (|\@arabic|, |\@roman| and |\@alph|).  (Also, the numbers are not specified in content
% anymore: we simply read the sequence number \ikeyname{n}.  And, to save some horizontal space for the
% code, each child of the root is pushed further down.)
% \begin{forestexample}[ekeynames={delay,where ,level,content,n,for children,l,{id=.wrap 2 pgfmath args,nfc}}]
%   \begin{forest}
%     delay={where level={2}{~content/.wrap 2 pgfmath args=
%         {\csname @#1\endcsname{#2}}{content("!u")}{n}~}{}},
%     for children={l*=n},
%     [\LaTeX numerals,
%       [arabic[][][][]]
%       [roman[][][][]]
%       [alph[][][][]]
%     ]
%   \end{forest}
% \end{forestexample}
%
% The final way to use |pgfmath| expressions in \foRest;: \ikeyname{if} clauses.  In
% section~\ref{sec:options}, we have seen that every option has a corresponding \ikeyname{id={{if }}}|...|
% (and \ikeyname{id={{where }}}|...|) option.  However, these are just a matter of convenience.  The full
% power resides 
% in the general \ikeyname{if} option, which takes three arguments: 
% |if=|\meta{condition}\meta{true options}\meta{false options}, where \meta{condition} can be any
% |pgfmath| expression 
% (non-zero means true, zero means false).  (Once again, option \ikeyname{where} is an abbreviation
% for \ikeyname{for tree}|={|\ikeyname{if}|=...}|.)  In the following example, \ikeyname{if} option
% is used to orient the 
% arrows from the smaller number to the greater, and to color the odd and even numbers differently.
%
% \forestset{random tree/.style n args={3}{^^A #1=max levels, #2=max children, #3=max content
%       content/.pgfmath={random(0,#3)},
%       if={#1>0}{repeat={random(0,#2)}{append={[,random tree={#1-1}{#2}{#3}]}}}{}}}
% \begin{forestexample}[ekeynames={before typesetting nodes,for descendants,if,content,edge,edge label,for tree,if},point=if]
%   \pgfmathsetseed{314159}
%   \begin{forest}
%     before typesetting nodes={
%       for descendants={
%         if={content()>content("!u")}{edge=->}{
%           if={content()<content("!u")}{edge=<-}{}},
%           edge label/.wrap pgfmath arg=
%             {node[midway,above,sloped,font=\scriptsize]{+#1}}
%             {int(abs(content()-content("!u")))}
%       },
%       for tree={circle,if={mod(content(),2)==0}
%                           {fill=yellow}{fill=green}}
%     }
%     [,random tree={3}{3}{100}]
%   \end{forest}
% \end{forestexample}
%
% This exhausts the ways of using |pgfmath| in forest.  We continue by introducing \emph{relative
% node setting}: write \imeta{relative node name}|.|\meta{option}|=|\meta{value} to set the
% value of \meta{option} of the specified relative node. Important: computation (pgfmath or wrap) of
% the value is 
% done in the context of the original node.  The following example defines style \keyname{move} which
% not only draws an arrow from the source to the target, but also moves the content of the source
% to the target (leaving a trace).  Note the difference between |#1| and |##1|: |#1| is the argument
% of the style \keyname{move}, i.e.\ the given node walk, while |##1| is the original option value
% (in this case, content).
% \begin{forestexample}[ekeynames={for tree,calign,tikz,delay,content}]
%   \begin{forest}
%     for tree={calign=fixed edge angles},
%     move/.style={
%       tikz={\draw[->] () to[out=south west,in=south] (#1);},
%       delay={~#1.content~={##1},content=$t$}},
%     [CP[][C'[C][\dots[,phantom][VP[DP][V'[V][DP,move=!r1]]]]]]
%   \end{forest}
% \end{forestexample}
%
% In the following example, the content of the branching nodes is computed by \foRest;: a branching
% node is a sum of its 
% children.  Besides the use of the relative node setting, this example notably uses a recursive
% style: for each child of the node, style \keyname{calc} first applies itself to the child and then
% adds the result to the node; obviously, recursion is made to stop at terminal nodes. 
% \begin{forestexample}[ekeynames={id={{if }},n children,content,for children,delay,{id=.pgfmath,nfc}}]
%   \begin{forest}
%     calc/.style={if n children={0}{}{content=0,for children={
%           calc,~!u.content~/.pgfmath=int(content("!u")+content())}}},
%     delay=calc,
%     [[[3][4][5]][[3][9]][8][[[1][2][3]]]]
%   \end{forest}
% \end{forestexample}
% 
% 
% \subsection{Externalization}
% \label{tut:externalization}
%
% \FoRest; can be quite slow, due to the slowness of both \PGF;/\TikZ; and its own computations.
% However, using \emph{externalization}, the amount of time spent in \foRest; in everyday life can
% be reduced dramatically.  The idea is to typeset the trees only once, saving them in separate
% PDFs, and then, on the subsequent compilations of the document, simply include these PDFs instead
% of doing the lenghty tree-typesetting all over again.
%
% \FoRest;'s externalization mechanism is built on top of \TikZ;'s |external| library.  It
% enhances it by automatically detecting the code and context changes: the tree is recompiled if and
% only if either the code in the \ikeyname{forest} environment or the context (arbitrary parameters; by
% default, the parameters of the standard node) changes.
%
% To use \foRest;'s externalization facilities, say:\footnote{When you switch on
% the externalization for a document containing many \keyname{forest} environments, the first
% compilation can take quite a while, much more than the compilation without externalization. (For
% example, more than ten minutes for the document you are reading!)  Subsequent compilations,
% however, will be very fast.}\ekeyname{external}
% \begin{lstlisting}[point=external]
%   \usepackage[external]{forest}
%   ~\tikzexternalize~
% \end{lstlisting}
%
% If your \ikeyname{forest} environment contains some macro, you will probably want the externalized
% tree to be recompiled when the definition of the macro changes.  To achieve this, use
% \icmdname{forestset}|{|\ikeyname{id={external/depends on macro}}|=|\cmdname{macro}|}|.  The effect is
% local to the \TeX\ group.
%
% \TikZ;'s externalization library promises a |\label| inside the externalized graphics to work
% out-of-box, while |\ref| inside the externalized graphics should work only if the externalization
% is run manually or by |make| \citep[\S32.4.1]{tikzpgf2.10}.  A bit surprisingly perhaps, the
% situation is roughly reversed in \foRest;.  |\ref| inside the externalized graphics will work
% out-of-box.  |\label| inside the externalized graphics will not work at all.  Sorry.  (The reason
% is that \foRest; prepares the node content in advance, before merging it in the whole tree, which
% is when \TikZ;'s externalization is used.)
%
% \subsection{Expansion control in the bracket parser}
% \label{tut:bracket}
%
% By default, macros in the bracket encoding of a tree are not
% expanded until nodes are being drawn --- this way, node
% specification can contain formatting instructions, as illustrated in
% section~\ref{sec:basic-usage}.  However, sometimes it is useful to
% expand macros while parsing the bracket representation, for example to
% define tree templates such as the X-bar template, familiar
% to generative grammarians:\footnote{Honestly, dynamic node creation might be a better way to do
% this; see~\S\ref{ref:dynamic}.}
% \begin{forestexample}[ecmdnames=bracketset,ekeynames={action character}]
%   ~\bracketset{action character=@}~
%   \def\XP#1#2#3{#1P[#2][#1'[#1][#3]]}
%   \begin{forest}
%     [~@~\XP T{DP}{~@~\XP V{DP}{DP}}]
%   \end{forest}
% \end{forestexample}
% In the above example, the |\XP| macro is preceded by the \emph{action character} |@|: as
% the result, the token following the action character was expanded before the parsing proceeded.
%
% The action character is not hard coded into \foRest;.  Actually, there is no action character by
% default.  (There's enough special characters in \foRest; already, anyway, and the situations where
% controlling the expansion is preferable to using the pgfkeys interface are not numerous.)  It is
% defined at the top of the example by processing key \ikeyname{action character} in the
% \ikeyname{id={/bracket},nfc} path; the definition is local to the \TeX\ group.
% 
% Let us continue with the description of the expansion control facilities of the bracket parser.
% The expandable token following the
% action character is expanded only once.  Thus, if one defined macro
% |\VP| in terms of the general |\XP| and tried to use it in the same
% fashion as |\XP| above, he would fail.  The correct way is to follow
% the action character by a braced expression: the braced expression
% is fully expanded before bracket-parsing is resumed.
% \begin{forestexample}[ecmdnames=bracketset,ekeynames=action character]
%   \bracketset{action character=@}
%   \def\XP#1#2#3{#1P[#2][#1'[#1][#3]]}
%   \def\VP#1#2{\XP V{#1}{#2}}
%   \begin{forest}
%     [@\XP T{DP}{~@{~\VP{DP}{DP}~}~}]
%   \end{forest}
% \end{forestexample}
%
% In some applications, the need for macro expansion might be much
% more common than the need to embed formatting instructions.
% Therefore, the bracket parser provides commands |@+| and |@-|: |@+|
% switches to full expansion mode --- all tokens are fully expanded
% before parsing them; |@-| switches back to the default mode, where
% nothing is automatically expanded.
% \begin{forestexample}[ecmdnames=bracketset,ekeynames=action character]
%   \bracketset{action character=@}
%   \def\XP#1#2#3{#1P[#2][#1'[#1][#3]]}
%   \def\VP#1#2{\XP V{#1}{#2}}
%   \begin{forest} ~@+~
%     [\XP T{DP}{\VP{DP}{DP}}]
%   \end{forest}
% \end{forestexample}
% 
% All the action commands discussed above were dealing only with
% \TeX's macro expansion.  There is one final action command, |@@|,
% which yields control to the user code and expects it to call
% |\bracketResume| to resume parsing.  This is useful to e.g.\
% implement automatic node enumeration:
% \begin{forestexample}[ecmdnames=bracketset,ekeynames={action character,phantom,for
% ,n,baseline,delay,where ,level,content}]
%   \bracketset{action character=@}
%   \newcount\xcount
%   \def\x#1{~@@~\advance\xcount1
%     \edef\xtemp{[$\noexpand\times_{\the\xcount}$[#1]]}%
%     \expandafter\bracketResume\xtemp
%   }
%   \begin{forest}
%     phantom,
%     delay={where level=1{content={\strut #1}}{}}
%     ~@+~
%     [\x{f}\x{o}\x{r}\x{e}\x{s}\x{t}]
%   \end{forest}
% \end{forestexample}
% This example is fairly complex, so let's discuss how it works.  |@+| switches to the full
% expansion mode, so that macro |\x| can be easily run.  The real magic hides in this macro.  In
% order to be able to advance the node counter |\xcount|, the macro takes control from \foRest; by
% the |@@| command.  Since we're already in control, we can use |\edef| to define the node content.
% Finally, the |\xtemp| macro containing the node specification is expanded with the resume command
% sticked in front of the expansion.
%
% \section{Reference}
% \label{sec:reference}
%
% \subsection{Environments}
% \label{ref:environments}
%
% \begin{syntax}
% \item[,,environment]|\begin{|\rkeyname{forest}|}|\meta{tree}|\end{|\rkeyname{forest}|}|
% \rcmdname[item]{Forest}[*]\marg{tree}
%
% The environment and the starless version of the macro introduce a group; the starred macro does
% not, so the created nodes can be used afterwards.  (Note that this will leave a lot of temporary
% macros lying around.  This shouldn't be a problem, however, since all of them reside in the
% |\forest| namespace.)
% \end{syntax}
%
% \subsection{The bracket representation}
% \label{ref:bracket}
%
% A bracket representation of a tree is a token list with the following syntax:
% \begin{eqnarray*}
%   \meta{tree}&=&\left[\meta{preamble}\right]\meta{node}\\
%   \meta{node}&=&\texttt{[}\left[\meta{content}\right]\left[\texttt{,}\meta{keylist}\right]
%                  \left[\meta{children}\right]\texttt{]}\meta{afterthought}\\
%   \meta{preamble}&=&\meta{keylist}\\
%   \meta{keylist}&=&\meta{key--value}\left[,\meta{keylist}\right]\\
%   \meta{key--value}&=&\meta{key}\OR\meta{key}\texttt{=}\meta{value}\\
%   \meta{children}&=&\meta{node}\left[\meta{children}\right]
% \end{eqnarray*}
% 
% The actual input might be different, though, since expansion may have occurred during the input
% reading.  Expansion control sequences of \foRest;'s bracket parser are shown below.
% \begin{center}
%   \begin{tabular}{ll}
%     \rstyle\meta{action character}\texttt{-}&no-expansion mode (default): nothing is expanded\\
%     \rstyle\meta{action character}\texttt{+}&expansion mode: everything is fully expanded\\
%     \rstyle\meta{action character}\texttt{}\meta{token}&expand \meta{token}\\
%     \rstyle\meta{action character}\texttt{}\meta{\TeX-group}&fully expand \meta{\TeX-group}\\
%     \rstyle\meta{action character}\meta{action character}&yield control;\\&upon finishing its job,
%     user's code should call \texttt{\string\bracketResume}
%   \end{tabular}
% \end{center}
% 
% \paragraph{Customization} To customize the bracket parser, call
% \rcmdname{bracketset}\meta{keylist}, where the keys can be the following. 
% \begin{syntax}
% \rkeyname[item={[}]{opening bracket}|=|\meta{character}
% \rkeyname[item={{{{]}}}}]{closing bracket}|=|\meta{character}
% \rkeyname[item=none]{action character}|=|\meta{character}
% \end{syntax}
% 
% By redefining the following two keys, the bracket parser can be used outside \foRest;.
% \begin{syntax}
% \rkeyname[item]{new node}|=|\meta{preamble}\meta{node specification}\meta{csname}.
%   Required semantics: create a new node given the preamble (in the case of a new
%   root node) and the node specification and store the new node's id into \meta{csname}. 
% \rkeyname[item]{set afterthought}|=|\meta{afterthought}\meta{node id}.
%   Required semantics: store the afterthought in the node with given id.
% \end{syntax}
%
% \subsection{Options and keys}
% \label{ref:option-types}
% \label{ref:options-and-keys}
% 
% The position and outlook of nodes is controlled by \emph{options}.  Many options can be set for a
% node.  \emph{Each node's options are set independently of other nodes:} in particular, setting an
% option of a node does \emph{not} set this option for the node's descendants.  
%
% Options are set using \PGF;'s key management utility |pgfkeys| \citep[\S55]{tikzpgf2.10}.  In the
% bracket representation of a tree (see~\S\ref{ref:bracket}), each node can be given a
% \meta{keylist}.  After parsing the representation of the tree, the keylists of the 
% nodes are processed (recursively, in a depth-first, parent-first fashion).  The preamble is
% processed first, in 
% the context of the root node.\footnote{The value of a key (if it is given) is interpreted as one
% or more arguments to the key command. 
% If there is only one argument, the situation is simple: the whole value is the argument.  When the
% key takes more than one argument, each argument should be enclosed in braces, unless, as usual in
% \TeX, the argument is a single token.  (The pairs of braces can be separated by whitespace.)  An
% argument should also be enclosed in braces if it contains a special character: a comma \texttt{,}, an
% equal sign \texttt{=} or a bracket \texttt{[]}.}
%
% The node whose keylist is being processed is the \emph{current node}.  During the processing of
% the keylist, the current node can temporarily change.  This mainly happens when propagators
% (\S\ref{ref:propagators}) are being processed.
% 
% Options can be set in various ways, depending on the option type (the types are listed below).
% The most straightforward way is to use the key with the same name as the option:
% \begin{syntax}
% \item \meta{option}|=|\meta{value}  Sets the value of \meta{option} of the current node to
% \meta{value}.
%
%   Notes: (i) Obviously, this does not work for read-only options.  (ii) Some option types override
%   this behaviour.
% \end{syntax}
% It is also possible to set a non-current option:
% \begin{syntax}
% \item
%   \imeta{relative node name}|.|\meta{option}|=|\meta{value}  Sets the value of
%   \meta{option} of the node specified by \meta{relative node name} to \meta{value}.
%
%   Notes: \begin{inparaenum}[(i)]
%   \item\emph{\meta{value} is evaluated in the context of the current node.}
%   \item In general, the resolution of \meta{relative node name} depends on the
%     current node; see \S\ref{ref:relative-node-names}.
%   \item \meta{option} can also be an ``augmented operator'' (see below) or an additional
%     option-setting key defined for a specific option.
%   \end{inparaenum}
% \end{syntax}
% The option values can be not only set, but also read.
% \begin{itemize}
% \item Using macros \rcmdname{forestoption}|{|\meta{option}|}| and
%   \rcmdname{foresteoption}|{|\meta{option}|}|, options of the current node can be accessed in \TeX\
%   code.  (``\TeX\ code'' includes \meta{value} expressions!).
%
%   In the context of |\edef| or \PGF;'s handler |.expanded| \citep[\S55.4.6]{tikzpgf2.10},
%   \cmdname{forestoption} expands precisely to the token list of the option value, while
%   \cmdname{foresteoption} allows the option value to be expanded as well.
% \item Using |pgfmath| functions defined by \foRest;, options of both current and non-current nodes
%   can be accessed.  For details, see \S\ref{ref:pgfmath}.
% \end{itemize}
%
% We continue with listing of all keys defined for every option.  The set of defined keys and their
% meanings depends on the option type.  Option types and the type-specific keys can be found in the
% list below.  Common to all types are two simple conditionals, \ikeyname{id={{if }}}\meta{option}
% and \ikeyname{id={{where }}}\meta{option}, which are  
% defined for every \meta{option}; for details, see \S\ref{ref:conditionals}.  
% 
% \begin{syntax}
% \rmeta[item]{toks} contains \TeX's \meta{balanced text} \citep[275]{texbook}.
%
%   A toks \meta{option} additionally defines the following keys:
%   \begin{syntax}
%   \item {\rstyle\meta{option}}\rkeyname{+}|=|\meta{toks} appends the given \meta{toks} to the
%     current value of the option.
%     
%   \item {\rstyle\meta{option}}\rkeyname{-}|=|\meta{toks} prepends the given \meta{toks} to the
%     current value of the option.
%     
%     \rkeyname[margin={},item]{id={{if in }}}{\rstyle\meta{option}}|=|\meta{toks}\meta{true
%     keylist}\meta{false keylist} checks if \meta{toks} occurs in the option value; if it does,
%     \meta{true keylist} are executed, otherwise \meta{false keylist}.
%     
%     \rkeyname[margin={},item]{id={{where in }}}\meta{option}|=|\meta{toks}\meta{true
%     keylist}\meta{false keylist} is a style equivalent to \ikeyname{for tree}|={|\keyname{if in }\meta{option}=\meta{toks}\meta{true keylist}\meta{false keylist}|}|: for every node in
%     the subtree rooted in the current node, \keyname{if in }\meta{option} is executed in
%     the context of that node.
%   \end{syntax}
% 
% \rmeta[item]{autowrapped toks} is a subtype of \imeta{toks} and contains \TeX's \meta{balanced
% text} \citep[275]{texbook}. 
%
%   {\rstyle\meta{option}}|=|\meta{toks} of an autowrapped \meta{option} is equivalent to
%   \meta{option}|/|\ikeyname{id=.wrap value,nfc}|=|\meta{toks} of a normal \meta{toks} option.
%   
%   Keyvals {\rstyle\meta{option}}\rkeyname{+}|=|\meta{toks} and
%   {\rstyle\meta{option}\rkeyname{-}}|=|\meta{toks} are equivalent to
%   \meta{option}\keyname{+}|/|\ikeyname{id=.wrap value,nfc}|=|\meta{toks} and
%   \meta{option}\keyname{-}|/|\ikeyname{id=.wrap value,nfc}|=|\meta{toks}, respectively.  The
%   normal toks behaviour can be accessed via keys {\rstyle\meta{option}|'|},
%   {\rstyle\meta{option}|+'|} and {\rstyle\meta{option}|-'|}.  
%
% \rmeta[item]{keylist} is a subtype of \imeta{toks} and contains a comma-separated list of
%   \meta{key}[|=|\meta{value}] pairs.
% 
%   Augmented operators {\rstyle\meta{option}\keyname{+}} and {\rstyle\meta{option}\keyname{-}} automatically
%   insert a comma before/after the appended/prepended material.
%
%   {\rstyle\meta{option}}|=|\meta{keylist} of a keylist option is equivalent to
%   \meta{option}\keyname{+}|=|\meta{keylist}.  In other words, keylists behave additively by
%   default.  The rationale is that one usually wants to add keys to a keylist.  The usual,
%   non-additive behaviour can be accessed by {\rstyle\meta{option}\rkeyname{'}}|=|\meta{keylist}.
%
% \rmeta[item]{dimen} contains a dimension.
%
%   The value given to a dimension option is automatically evaluated by pgfmath.  In other words:
%
%   {\rstyle\meta{option}}|=|\meta{pgfmath} is an implicit \meta{option}|/.pgfmath=|\meta{pgfmath}.
%
%   For a \meta{dimen} option \meta{option}, the following additional keys (``augmented
%   assignments'') are defined:
%   \begin{itemize}
%   \item {\rstyle\meta{option}\rkeyname{+}}|=|\meta{value} is equivalent to \meta{option}|=|\meta{option}|()+|\meta{value}
%   \item {\rstyle\meta{option}\rkeyname{-}}|=|\meta{value} is equivalent to \meta{option}|=|\meta{option}|()-|\meta{value}
%   \item {\rstyle\meta{option}\rkeyname{*}}|=|\meta{value} is equivalent to \meta{option}|=|\meta{option}|()*|\meta{value}
%   \item {\rstyle\meta{option}\rkeyname{:}}|=|\meta{value} is equivalent to \meta{option}|=|\meta{option}|()/|\meta{value}
%   \end{itemize}
% 
%   The evaluation of \meta{pgfmath} can be quite slow.  There are two tricks to speed things up
%   \emph{if} the \meta{pgfmath} expression is simple, i.e.\ just a \TeX\ \meta{dimen}:
%   \begin{enumerate}
%   \item |pgfmath| evaluation of simple values can be sped up by prepending \ikeyname{+} to the value
%     \citep[\S62.1]{tikzpgf2.10};
%   \item use the key {\rstyle\meta{option}\rkeyname{'}}|=|\meta{value} to invoke a normal \TeX\ assignment.
%   \end{enumerate}
%
%   The two above-mentioned speed-up tricks work for the augmented assignments as well.  The keys
%   for the second, \TeX-only trick are: {\rstyle\meta{option}\rkeyname{'+}},
%   {\rstyle\meta{option}\rkeyname{'-}}, {\rstyle\meta{option}\rkeyname{'*}} and
%   {\rstyle\meta{option}\rkeyname{':}} --- note that for the latter two, the value should be an
%   integer.
% 
% \rmeta[item]{count} contains an integer.
%
%   The additional keys and their behaviour are the same as for the \meta{dimen} options.
%
% \rmeta[item]{boolean} contains $0$ (false) or $1$ (true).
%
%   In the general case, the value given to a \meta{boolean} option is automatically
%   parsed by pgfmath (just as for \meta{count} and \meta{dimen}): if the computed value is
%   non-zero, $1$ is stored; otherwise, $0$ is stored.  Note that |pgfmath| recognizes constants
%   |true| and |false|, so it is possible to write \meta{option}|=true| and
%   \meta{option}|=false|.
%
%   If key \meta{option} is given no argument, pgfmath evaluation does not apply and a true value is
%   set.  To quickly set a false value, use key {\rstyle\rkeyname{id={{not }}}\meta{option}} (with
%   no arguments). 
% \end{syntax}
% 
% The following subsections are a complete reference to the part of the user interface residing in
% the |pgfkeys|' path \keyname{/forest}.  In plain language, they list all the options known to
% \foRest;.  More precisely, however, not only options are listed, but also other keys, such as
% propagators, conditionals, etc.
%
% Before listing the keys, it is worth mentioning that users can also define their own keys.  The
% easiest way to do this is by using \emph{styles}.  Styles are a feature of the |pgfkeys| package.
% They are 
% named keylists, whose usage ranges from mere abbreviations through templates to devices
% implementing recursion.  To define a style, use \PGF;'s handler \keyname{.style}
% \citep[\S55.4.4]{tikzpgf2.10}: \meta{style name}|/.style=|\meta{keylist}.
%
% Using the following keys, users can also declare their own options.  The new options will behave
% exactly like the predefined ones.
% \begin{syntax}
% \rkeyname[item]{declare toks}|=|\meta{option name}\meta{default value}  Declares a \meta{toks} option.
% \rkeyname[item]{declare autowrapped toks}|=|\meta{option name}\meta{default value} Declares an
% \meta{autowrapped toks} option.
% \rkeyname[item]{declare keylist}|=|\meta{option name}\meta{default value} Declares a
% \meta{keylist} option. 
% \rkeyname[item]{declare dimen}|=|\meta{option name}\meta{default value} Declares a \meta{dimen} option.
% \rkeyname[item]{declare count}|=|\meta{option name}\meta{default value} Declares a \meta{count} option.
% \rkeyname[item]{declare boolean}|=|\meta{option name}\meta{default value} Declares a
% \meta{boolean} option.
% \end{syntax}
%
% The style definitions and option declarations given
% among the other keys in the bracket specification are local to the current tree.  To define
% globally accessible styles and options (well, definitions are always local to the current \TeX\
% group), use macro |\forestset| outside the
% \ikeyname{forest} environment:\footnote{\cmdname{forestset}\meta{keylist} is equivalent to
% \cmdname{pgfkeys}\texttt{\{}/forest,\meta{keylist}\texttt{\}}.}
% \begin{syntax}
% \rcmdname[item]{forestset}\marg{keylist}
%   
%   Execute \meta{keylist} with the default path set to \keyname{/forest}.
%   \begin{advise}
%   \item Usually, no current node is set when this macro is called.  Thus, executing node options
%     in this place will \emph{fail}. However, if you have some nodes lying around, you can use
%     propagator \ikeyname{for name}|=|\meta{node name} to set the node with the given name as
%     current.
%   \end{advise}
% \end{syntax}
%
% \subsubsection{Node appearance}
% \label{ref:node-appearance}
%
% The following options apply at stage \ikeyname{typesetting nodes}. Changing them
% afterwards has no effect in the normal course of events. 
%
% \begin{syntax}
%   \rkeyname[item={{{{{}}}}}]{align}|=|\keyname{left,aspect=align}\OR\keyname{center,aspect=align}\OR\keyname{right,aspect=align}\OR\meta{toks: tabular header} 
%
%   Creates a left/center/right-aligned multiline node, or a tabular node.  In the
%   \ikeyname{content} option, the lines of the node should separated by |\\| and the columns (if
%   any) by |&|, as usual.
%
%   The vertical alignment of the multiline/tabular node can be specified by option \ikeyname{base}.
%
% \begin{forestexample}[ekeynames={l sep,align,base}]
%   \begin{forest} l sep+=2ex
%     [special value&actual value\\\hline
%       \rkeyname{left,aspect=align}&||\texttt{@\{\}l@\{\}}\\
%       \rkeyname{center,aspect=align}&||\texttt{@\{\}c@\{\}}\\
%       \rkeyname{right,aspect=align}&||\texttt{@\{\}r@\{\}}\\
%       ,~align~=ll,draw
%       [top base\\right aligned, ~align~=right,~base~=top]
%       [left aligned\\bottom base, ~align~=left,~base~=bottom]
%     ]
%   \end{forest}
% \end{forestexample}
% 
%   Internally, setting this option has two effects:
%   \begin{enumerate}
%   \item The option value (a |tabular| environment header specification) is set.  The special
%     values \keyname{left}, \keyname{center} and \keyname{right} invoke styles setting the actual
%     header to the value shown in the above example.
%     \begin{advise}
%     \item If you know that the \keyname{align} was set with a special value, you can easily check
%       the value using \ikeyname{id={{if in }}}\ikeyname{align}.
%     \end{advise}
%   \item Option \ikeyname{content format} is set to the following value:
%     \begin{lstlisting}
%       \noexpand\begin{tabular}[\forestoption{base}]{\forestoption{align}}%
%         \forestoption{content}%
%       \noexpand\end{tabular}%
%     \end{lstlisting}
%     As you can see, it is this value that determines that options \keyname{base}, \keyname{align} and
%     \keyname{content} specify the vertical alignment, header and content of the table.
%   \end{enumerate}
% 
% \rkeyname[item=t]{base}|=|\meta{toks: vertical alignment}
%
% This option controls the vertical alignment of multiline (and in general, \texttt{tabular}) nodes
% created with \ikeyname{align}.  Its value becomes the optional argument to the \texttt{tabular}
% environment.  Thus, sensible values are \rkeyname{t,aspect=base} (the top line of the table will
% be the baseline) and \rkeyname{b,aspect=base} (the bottom line of the table will be the baseline).
% Note that this will only have effect if the node is anchored on a baseline, like in the default
% case of \ikeyname{anchor}|=base|.
%
% For readability, you can use \rkeyname{top,aspect=base} and \rkeyname{bottom,aspect=base} instead
% of \keyname{t} and \keyname{b}.  (\keyname{top} and \keyname{bottom} are still stored as
% \keyname{t} and \keyname{b}.) 
%
%   \rkeyname[item={{{{{}}}}}]{content}|=|\meta{autowrapped toks} The content of the node.
%
%   Normally, the value of option \keyname{content} is given implicitely by virtue of the special
%   (initial) position of content in the bracket representation (see~\S\ref{ref:bracket}).  However,
%   the option also be set explicitely, as any other option.
%
% \begin{forestexample}[ekeynames={for tree,id={{if }},n,n'},point={content,delay},ekeynames={content,delay}]
%   \begin{forest}
%     delay={for tree={
%         if n=1{content=L}
%              {if n'=1{content=R}
%                       {content=C}}}}
%     [[[][][]][[][][]]]
%   \end{forest}
% \end{forestexample}
%   Note that the execution of the \keyname{content} option should usually be delayed: otherwise, the
%   implicitely given content (in the example below, the empty string) will override the explicitely
%   given content.
%
% \begin{forestexample}[ekeynames={for tree,id={{if }},n,n',content},point={content}]
%   \begin{forest}
%     for tree={
%         if n=1{content=L}
%              {if n'=1{content=R}
%                       {content=C}}}
%     [[[][][]][[][][]]]
%   \end{forest}
% \end{forestexample}
%
%   \rkeyname[item=\forestoption{content}]{content format}|=|\meta{toks}  
%
%   When typesetting the node under the default conditions (see option \ikeyname{node format}), the
%   value of this option is passed to the \TikZ; \texttt{node} operation as its \meta{text} argument
%   \citep[\S16.2]{tikzpgf2.10}.  The default value of the option simply puts the content in the
%   node.
% 
%   This is a fairly low level option, but sometimes you might still want to change its value.  If
%   you do so, take care of what is expanded when.  For details, read the documentation of option
%   \ikeyname{node format} and macros \icmdname{forestoption} and \icmdname{foresteoption}; for an
%   example, see option \ikeyname{align}.
%
% \rkeyname[item]{math content}  The content of the node will be typeset in a math environment.
%
% This style is just an abbreviation for \ikeyname{content
% format}|={\ensuremath{\forestoption{content}}}|. 
%
% \rkeyname[item]{node format}|=|\meta{toks}
%   \hfill|\noexpand\node|\\
%   \mbox{}\hfill|[\forestoption{node options},anchor=\forestoption{anchor}]|\\
%   \mbox{}\hfill|(\forestoption{name}){\foresteoption{content format}};|
%
%   The node is typeset by executing the expansion of this option's value in a |tikzpicture|
%   environment.
%
%   Important: the value of this option is first expanded using |\edef| and only then executed. Note
%   that in its default value, \ikeyname{content format} is fully expanded using
%   \icmdname{foresteoption}: this is necessary for complex content formats, such as |tabular|
%   environments.
%
%   This is a low level option.  Ideally, there should be no need to change its value.  If you do,
%   note that the \TikZ; node you create should be named using the value of option \ikeyname{name};
%   otherwise, parent--child edges can't be drawn, see option \ikeyname{edge path}. 
%
%   \rkeyname[item={{{{{}}}}}]{node options}|=|\meta{keylist}
% 
%   When the node is being typeset under the default conditions (see option \ikeyname{node format}),
%   the content of this option is passed to \TikZ; as options to the 
%   \TikZ; |node| operation \citep[\S16]{tikzpgf2.10}.
%
%   This option is rarely manipulated manually: almost all options unknown to \foRest; are
%   automatically appended to \keyname{node options}.  Exceptions are (i) \ikeyname{label} and
%   \ikeyname{pin}, which require special attention in order to work; and (ii) \ikeyname{anchor},
%   which is saved in order to retain the information about the selected anchor.
%
% \begin{forestexample}[ekeynames={for descendants,anchor,child anchor,parent anchor,grow,l sep,for tree,where,delay,content,node options,rotate,{id=.pgfmath,nfc}}]
%   \begin{forest}
%     for descendants={anchor=east,child anchor=east},
%     grow=west,anchor=north,parent anchor=north,
%     l sep=1cm,
%     for tree={~fill=yellow~},where={n()>3}{~draw=red~}{},
%     delay={for tree={content/.pgfmath=~node_options~}}
%     [root,rotate=90,
%       [,~fill=white~]
%       [,~node options'~]
%       []
%       []
%       [,~node options~={~ellipse~}]
%     ]
%   \end{forest}
% \end{forestexample} 
%
%
%
%   \rkeyname[item=false]{phantom}|=|\meta{boolean}
%
%   A phantom node and its surrounding edges are taken into account when packing, but not
%   drawn. (This option applies in stage \ikeyname{draw tree}.)
% \begin{forestexample}[point=phantom,ekeynames=phantom]
%   \begin{forest}
%     [VP[DP][V',phantom[V][DP]]]
%   \end{forest}
% \end{forestexample}
%
% \end{syntax}
%
%
%
% \subsubsection{Node position}
% \label{ref:ref-node-position}
%
% Most of the following options apply at stage \ikeyname{pack}. Changing them
% afterwards has no effect in the normal course of events.  (Options \ikeyname{l},
% \ikeyname{s}, \ikeyname{x}, \ikeyname{y} and \ikeyname{anchor} are exceptions; see their documentation for
% details).
%
% \begin{syntax}
%
%   \rkeyname[item=base]{anchor}|=|\meta{toks: \TikZ; anchor name}
%
%   This is essentially a \TikZ; option \citep[see][\S16.5.1]{tikzpgf2.10} --- it is passed to
%   \TikZ; as a node option when the node is typeset (this option thus applies in stage
%   \ikeyname{typeset nodes}) --- but it is also saved by \foRest;.
%
%   The effect of this option is only observable when a node has a sibling: the anchors of all
%   siblings are s-aligned (if their \ikeyname{l}s have not been modified after packing).
%
%   In the \TikZ; code, you can refer to the node's anchor using the generic anchor
%   \rkeyname{anchor,aspect=generic anchor}.
%
%   \rkeyname[item=center]{calign}|=|\alternative{child,child edge,midpoint,edge midpoint,fixed
%   angles,fixed edge angles}\\\alternative{first,last,center}.
%   
%   The packing algorithm positions the children so that they don't overlap, effectively computing
%   the minimal distances between the node anchors of the children.  This option (\keyname{calign}
%   stands for child alignment) specifies how the children are positioned
%   with respect to the parent (while respecting the above-mentioned minimal distances).
%
%   The child alignment methods refer to the primary and the secondary child, and to the primary and
%   the secondary angle.  These are set using the keys described just after \keyname{calign}.
%
%   \let\outerleftmargin\leftmargin
%   \begin{syntax}
%   \item\keyname{calign}|=|\rkeyname{child,aspect=calign} s-aligns the node anchors of the parent and
%     the primary child.
%   \item\keyname{calign}|=|\rkeyname{child edge,aspect=calign} s-aligns the parent anchor of the parent 
%     and the child anchor of the primary child.
%   \item \keyname{calign}|=|\rkeyname{first,aspect=calign} is an abbreviation for
%     |calign=child,calign_child=1|.
%   \item \keyname{calign}|=|\rkeyname{last,aspect=calign} is an abbreviation for
%     |calign=child,calign_child=-1|.
%   \item\keyname{calign}|=|\rkeyname{midpoint,aspect=calign} s-aligns the parent's node anchor and the
%     midpoint between the primary and the secondary child's node anchor.
%   \item\keyname{calign}|=|\rkeyname{edge midpoint,aspect=calign} s-aligns the parent's parent anchor
%     and the midpoint between the primary and the secondary child's child anchor.
%   \item \keyname{calign}|=|\rkeyname{center,aspect=calign} is an abbreviation for\\
%     |calign=midpoint,| |calign_primary_child=1,| |calign_secondary_child=-1|. 
% \begin{forestexample}
%   \begin{forest}
%     [center,calign=center[1]
%       [first,calign=first[A][B][C]][3][4][5][6]
%       [last,calign=last[A][B][C]][8]]
%   \end{forest}
% \end{forestexample}
%   \item\keyname{calign}|=|\rkeyname{fixed angles,aspect=calign}: The angle between the direction of
%   growth at the current node (specified by option \ikeyname{grow}) and the line through the node
%   anchors of the parent and the primary/secondary child will equal the primary/secondary angle.
%
%   To achieve this, the block of children might be spread or further distanced from the parent.
%   \item\keyname{calign}|=|\rkeyname{fixed edge angles,aspect=calign}: The angle between the direction of
%   growth at the current node (specified by option \ikeyname{grow}) and the line through the
%   parent's parent anchor and the primary/secondary child's child anchor will equal the
%   primary/secondary angle.
%   
%   To achieve this, the block of children might be spread or further distanced from the parent.
% \begin{forestexample}[point=calign,ekeynames={calign,fixed edge angles,calign primary angle,calign secondary angle,for tree,l}]
%   \begin{forest}
%     calign=fixed edge angles,
%     calign primary angle=-30,calign secondary angle=60,
%     for tree={l=2cm}
%     [CP[C][TP]]
%     \draw[dotted] (!1) -| coordinate(p) () (!2) -| ();
%     \path ()--(p) node[pos=0.4,left,inner sep=1pt]{-30};
%     \path ()--(p) node[pos=0.1,right,inner sep=1pt]{60};
%   \end{forest}
% \end{forestexample}
%   \end{syntax}
% \rkeyname[item]{calign child}|=|\meta{count} is an abbreviation for \ikeyname{calign primary
%   child}|=|\meta{count}.
% \rkeyname[item=1]{calign primary child}|=|\meta{count} Sets the primary child.  
%   (See \ikeyname{calign}.)
%
%   \meta{count} is the child's sequence number.  Negative numbers start counting at the last child.
% \rkeyname[item=-1]{calign secondary child}|=|\meta{count} Sets the secondary child. 
%   (See \ikeyname{calign}.)
%
%   \meta{count} is the child's sequence number.  Negative numbers start counting at the last child.
% \rkeyname[item]{calign angle}|=|\meta{count} is an abbreviation for \ikeyname{calign primary
%   angle}|=-|\meta{count}, \ikeyname{calign secondary angle}|=|\meta{count}.
% \rkeyname[item=-35]{calign primary angle}|=|\meta{count} Sets the primary angle.
%   (See \ikeyname{calign}.) 
% \rkeyname[item=35]{calign secondary angle}|=|\meta{count} Sets the secondary angle. 
%   (See \ikeyname{calign}.)
% \rkeyname[item]{calign with current} s-aligns the node anchors of the current node and its
%   parent.  This key is an abbreviation for:\\   
%   |for_parent/.wrap_pgfmath_arg={calign=child,calign primary child=##1}{n}|.
% \rkeyname[item]{calign with current edge} s-aligns the child anchor of the current node and the
%   parent anchor of its parent.  This key is an abbreviation for:\\
%   |for_parent/.wrap_pgfmath_arg={calign=child edge,calign primary child=##1}{n}|.
%
%   \rkeyname[item=tight]{fit}|=|\alternative{tight,rectangle,band}
%
% \begin{forestexample}[pos=x,samplebox=\treebox,codebox=\codebox,basicstyle=\footnotesize\ttfamily]
%   \makeatletter\tikzset{use path/.code={\tikz@addmode{\pgfsyssoftpath@setcurrentpath#1}
%     \appto\tikz@preactions{\let\tikz@actions@path#1}}}\makeatother
%   \forestset{show boundary/.style={
%     before drawing tree={get min s tree boundary=\minboundary, get max s tree boundary=\maxboundary},
%     tikz+={\draw[red,use path=\minboundary]; \draw[red,use path=\maxboundary];}}}
% \end{forestexample}
% \input{\jobname.tmp}
%
% This option sets the type of the (s-)boundary that will be computed for the subtree rooted in the
% node, thereby determining how it will be packed into the subtree rooted in the node's parent.
% There are three choices:\footnote{Below is the definition of style \keyname{show boundary}. The
% \keyname{use path} trick is adjusted from \TeX\ Stackexchange question
% \href{http://tex.stackexchange.com/questions/26382/calling-a-previously-named-path-in-tikz}{Calling
% a previously named path in tikz}.
%
% \vskip-2ex \box\codebox}
%   \begin{itemize}
%   \item\keyname{fit}|=|\rkeyname{tight,aspect=fit}: an exact boundary of the node's subtree is computed,
%     resulting in a compactly packed tree.  Below, the boundary of subtree L is drawn.
% \begin{forestexample}[point={fit,tight},ekeynames={fit,{tight,aspect=fit},delay,for tree,name,content,{id=.pgfmath,nfc}}]
%   \begin{forest}
%     delay={for tree={name/.pgfmath=content}}
%     [root
%       [L,fit=tight, % default
%          show boundary
%         [L1][L2][L3]]
%       [R]
%     ]
%   \end{forest}
% \end{forestexample}
% \makeatletter\tikzset{use path/.code={%
%   \tikz@addmode{\pgfsyssoftpath@setcurrentpath#1}%
%   \appto\tikz@preactions{\let\tikz@actions@path#1}%
%   }}\makeatother
% \item\keyname{fit}|=|\rkeyname{rectangle,aspect=fit}: puts the node's subtree in a rectangle and effectively
%   packs this rectangle; the resulting tree will usually be wider.
% \begin{forestexample}[point={fit,rectangle},ekeynames={fit,{rectangle,aspect=fit},delay,for tree,name,content,{id=.pgfmath,nfc}}]
%   \begin{forest}
%     delay={for tree={name/.pgfmath=content}}
%     [root
%       [L,fit=rectangle,
%          show boundary
%         [L1][L2][L3]]
%       [R]
%     ]
%   \end{forest}
% \end{forestexample}
% \item\keyname{fit}|=|\rkeyname{band,aspect=fit}: puts the node's subtree in a rectangle of ``infinite
%   depth'': the space under the node and its descendants will be kept clear.
% \begin{forestexample}[point={fit,band},ekeynames={fit,{band,aspect=fit},delay,for tree,name,content,{id=.pgfmath,nfc}}]
%   \begin{forest}
%     delay={for tree={name/.pgfmath=content}}
%     [root
%       [L[L1][L2][L3]]
%       [C,fit=band]
%       [R[R1][R2][R3]]
%     ]
%     \draw[thin,red]
%       (C.south west)--(C.north west)
%       (C.north east)--(C.south east);
%     \draw[thin,red,dotted]
%       (C.south west)--+(0,-1)
%       (C.south east)--+(0,-1);
%   \end{forest}
% \end{forestexample}
%   \end{itemize}
%
%   \rkeyname[item=270]{grow}|=|\meta{count}  The direction of the tree's growth at the node.
%
%   The growth direction is understood as in \TikZ;'s tree library \citep[\S18.5.2]{tikzpgf2.10}
%   when using the default growth method: the (node anchor's of the) children of the node are placed
%   on a line orthogonal to the current direction of growth. (The final result might be different,
%   however, if \ikeyname{l} is changed after packing or if some child undergoes tier alignment.)
%
%   This option is essentially numeric (|pgfmath| function \keyname{grow} will always return an
%   integer), but there are some twists.  The growth direction can be specified either numerically
%   or as a compass direction (|east|, |north east|, \dots).  Furthermore, like in \TikZ;, setting
%   the growth direction using key \keyname{grow} additionally sets the value of option
%   \ikeyname{reversed} to |false|, while setting it with \rkeyname{grow'} sets it to |true|; to
%   change the growth direction without influencing \ikeyname{reversed}, use key \rkeyname{grow''}.
%
%   Between stages \ikeyname{pack} and \ikeyname{compute xy}, the value of \keyname{grow} should not
%   be changed.
%
% \begin{forestexample}[ekeynames={delay,id={{where in }},content,for ,current,grow,grow',grow'',{id=.pgfmath,nfc}}]
%   \begin{forest}
%     delay={where in content={~grow~}{
%         for current/.pgfmath=content,
%         content=\texttt{#1}
%       }{}
%     }
%     [{~grow~=south}
%       [{~grow'~=west}[1][2][3]
%         [{~grow''~=90}[1][2][3]]]
%       [2][3][4]
%       [{~grow~=east}[1][2][3]
%         [{~grow''~=90}[1][2][3]]]]
%   \end{forest}
% \end{forestexample}
%
% \rkeyname[item=false]{ignore}|=|\meta{boolean}
%
% If this option is set, the packing mechanism ignores the node, i.e.\ it pretends that the node has
% no boundary. Note: this only applies to the node, not to the tree.
%
% Maybe someone will even find this option useful for some reason \dots
% 
% \rkeyname[item=false]{ignore edge}|=|\meta{boolean}
%
% If this option is set, the packing mechanism ignores the edge from the node to the parent, i.e.\
% nodes and other edges can overlap it. (See \S\ref{sec:bugs} for some problematic situations.)
%
% \begin{forestexample}[ekeynames={ignore edge,l,*}]
%   \begin{forest}
%     [A[B[B][B][B][B]][C
%       [\texttt{not ignore edge},l*=2]]]
%   \end{forest}
%   \begin{forest}
%     [A[B[B][B][B][B]][C
%       [\texttt{ignore edge},l*=2,~ignore edge~]]]
%   \end{forest}
% \end{forestexample}
%
% \rkeyname[item]{l}|=|\meta{dimen} The l-position of the node, in the parent's ls-coordinate system.  (The
% origin of a node's ls-coordinate system is at its (node) anchor.  The l-axis points in the
% direction of the tree growth at the node, which is given by option \ikeyname{grow}. The s-axis is
% orthogonal to the l-axis; the positive side is in the counter-clockwise direction from |l| axis.)
%
% The initial value of \keyname{l} is set from the standard node.  By default, it equals:
% \[\ikeyname{l sep}+2\cdot\mbox{\texttt{outer ysep}}+\mbox{total
% height(standard node)}\]
%
% The value of \keyname{l} can be changed at any point, with different effects.  
% \begin{itemize}
% \item The value of \keyname{l} at the beginning of stage \ikeyname{pack} determines the minimal
%   l-distance between the anchors of the node and its parent.  Thus, changing \keyname{l} before
%   packing will influence this process.  (During packing, \keyname{l} can be increased due to
%   parent's \ikeyname{l sep}, tier alignment, or \ikeyname{calign} method \keyname{fixed (edge)
%   angles}\ekeyname{fixed angles},\ekeyname{fixed edge angles}.)
%
% \item Changing \keyname{l} after packing but before stage \ikeyname{compute xy} will result in a
%   manual adjustment of the computed position.  (The augmented operators can be useful here.)
%
% \item Changing \keyname{l} after the absolute positions have been computed has no effect in the
%   normal course of events.
% \end{itemize}
% 
% \rkeyname[item]{l sep}|=|\meta{dimen} The minimal l-distance between the node and its
% descendants.
%
% This option determines the l-distance between the \emph{boundaries} of the node and its descendants,
% not node anchors.  The final effect is that there will be a \keyname{l sep} wide band,
% in the l-dimension, between the node and all its descendants.
%
% The initial value of \keyname{l sep} is set from the standard node and equals
% \[\mbox{height}(\mbox{strut})+\mbox{\texttt{inner ysep}}\]
%
% Note that despite the similar name, the semantics of \keyname{l sep} and \keyname{s sep} are
% quite different.
%
% \rkeyname[item=false]{reversed}|=|\meta{boolean}
%
% If |false|, the children are positioned around the node in the counter-clockwise direction; if
% |true|, in the clockwise direction.  See also \ikeyname{grow}. 
%
% \rkeyname[item]{s}|=|\meta{dimen} The s-position of the node, in the parent's ls-coordinate system.
% (The origin of a node's ls-coordinate system is at its (node) anchor.  The l-axis points in the
% direction of the tree growth at the node, which is given by option \ikeyname{grow}.  The s-axis is
% orthogonal to the l-axis; the positive side is in the counter-clockwise direction from |l| axis.)
%
% The value of \keyname{s} is computed by the packing mechanism.  Any value given before packing is
% overridden.  In short, it only makes sense to (inspect and) change this option after stage
% \ikeyname{pack}, which can be useful for manual corrections, like below.  (B is closer to A than C
% because packing proceeds from the first to the last child --- the position of B would be the same
% if there was no C.)  Changing the value of \keyname{s} after stage \ikeyname{compute xy} has no
% effect.
% \begin{forestexample}[point=s,ekeynames={before computing xy,s}]
%   \begin{minipage}{.5\linewidth}
%   \begin{forest}
%     [no manual correction of B
%       [A[1][2][3][4]]
%       [B]
%       [C[1][2][3][4]]
%     ]
%   \end{forest}
%   
%    \begin{forest}
%     [manual correction of B
%       [A[1][2][3][4]]
%       [B,before computing xy={s=(s("!p")+s("!n"))/2}]
%       [C[1][2][3][4]]
%     ]
%   \end{forest}
%   \end{minipage}
% \end{forestexample}
%
% \rkeyname[item]{s sep}|=|\meta{dimen}
%
% The subtrees rooted in the node's children will be kept at least \keyname{s sep} apart in the
% s-dimension.  Note that \keyname{s sep} is about the minimal distance between node
% \emph{boundaries}, not node anchors.
%
% The initial value of \keyname{s sep} is set from the standard node and equals
% $2\cdot\mbox{\texttt{inner xsep}}$. 
%
% Note that despite the similar name, the semantics of \keyname{s sep} and \keyname{l sep} are
% quite different.
%
% \rkeyname[item={{{{{}}}}}]{tier}|=|\meta{toks}
%
% Setting this option to something non-empty ``puts a node on a tier.''  All the nodes on the same
% tier are aligned in the l-dimension.
%
% Tier alignment across changes in growth direction is impossible.  In the case of incompatible
% options, \foRest; will yield an error.
%
% Tier alignment also does not work well with \ikeyname{calign}|=|\keyname{fixed (edge)
% angles}\ekeyname{fixed angles}\ekeyname{fixed edge angles}, because these child alignment methods
% may change the l-position of the children.  When this might happen, \foRest; will yield a warning.
%
% \rkeyname[item]{x}=\meta{dimen}
% \vspace{-\parskip}
% \rkeyname[item]{y}=\meta{dimen}
%
% \keyname{x} and \keyname{y} are the coordinates of the node in the ``normal'' (paper) coordinate
% system, relative to the root of the tree that is being drawn.  So, essentially, they are absolute
% coordinates.
%
% The values of \keyname{x} and \keyname{y} are computed in stage \ikeyname{compute xy}.  It only
% makes sense to inspect and change them (for manual adjustments) afterwards (normally, in the
% \ikeyname{before drawing tree} hook, see \S\ref{ref:stages}.)
% \begin{forestexample}[label=ex:adjustxy,ekeynames={y,-,grow',l,for tree,before drawing tree}]
%   \begin{forest}
%     for tree={grow'=45,l=1.5cm}
%     [A[B][C][D,before drawing tree={~y-~=4mm}[1][2][3][4][5]][E][F]]
%   \end{forest}
% \end{forestexample}
% 
% \end{syntax}
% 
% \subsubsection{Edges}
% \label{ref:ref-edge}
%
% These options determine the shape and position of the edge from a node to its parent.  They apply
% at stage \ikeyname{draw tree}.
%
% \begin{syntax}
% \rkeyname[item={{{{{}}}}}]{child anchor}|=|\meta{toks} See \ikeyname{parent anchor}.
% 
% \rkeyname[item=draw]{edge}|=|\meta{keylist}
%
%   When \ikeyname{edge path} has its default value, the value of this option is passed as options to
%   the \TikZ; |\path| expression used to draw the edge between the node and its parent.
%
%   Also see key \ikeyname{no edge}.
%
% \begin{forestexample}[point=edge,ekeynames={edge,no edge,for tree,grow',l,anchor,child anchor}]
%   \begin{forest} for tree={grow'=0,l=2cm,anchor=west,child anchor=west},
%     [root
%       [normal]
%       [none,~no~ edge]
%       [dotted,edge=dotted]
%       [dashed,edge=dashed]
%       [dashed,edge={dashed,red}]
%     ]
%   \end{forest}
% \end{forestexample}
%
% \rkeyname[item={{{{{}}}}}]{edge label}|=|\meta{toks: \TikZ; code}
%
% When \ikeyname{edge path} has its default value, the value of this option is used at the end of
% the edge path specification to typeset a node (or nodes) along the edge.
% 
% The packing mechanism is not sensitive to edge labels.
% 
% \begin{forestexample}[ekeynames={edge label}]
%   \begin{forest}
%     [VP
%       [V,~edge label~={node[midway,left,font=\scriptsize]{head}}]
%       [DP,~edge label~={node[midway,right,font=\scriptsize]{complement}}]
%     ]
%   \end{forest}
% \end{forestexample}
%
% \rkeyname[item]{edge path}|=|\meta{toks: \TikZ; code}
%  \hfill |\noexpand\path[\forestoption{edge}]|\\
%  \mbox{}\hfill |(!u.parent anchor)--(.child anchor)\forestoption{edge label};|
%
% This option contains the code that draws the edge from the node to its parent.  By default, it
% creates a path consisting of a single line segment between the node's \ikeyname{child anchor} and
% its parent's \ikeyname{parent anchor}. Options given by \ikeyname{edge} are passed to the path; by
% default, the path is simply drawn.  Contents of \ikeyname{edge label} are used to potentially place
% a node (or nodes) along the edge.
%
% When setting this option, the values of options \ikeyname{edge} and \ikeyname{edge label} can be
% used in the edge path specification to include the values of options \ikeyname{edge} and \ikeyname{edge
% node}.  Furthermore, two generic anchors, \ikeyname{parent anchor,aspect=generic anchor} and \ikeyname{child anchor,aspect=generic anchor}, are defined, 
% to facilitate access to options \ikeyname{parent anchor} and \ikeyname{child anchor} from the \TikZ; code.
%
% The node positioning algorithm is sensitive to edges, i.e.\ it will avoid a node overlapping an
% edge or two edges overlapping. However, the positioning algorithm always behaves as if the
% \keyname{edge path} had the default value --- \emph{changing the \keyname{edge path} does not
% influence the packing!}  Sorry.  (Parent--child edges can be ignored, however: see option
% \ikeyname{ignore edge}.)
%
% \rkeyname[item={{{{{}}}}}]{parent anchor}|=|\meta{toks: \TikZ; anchor} (Information also applies to
% option \ikeyname{child anchor}.)
%
% \FoRest; defines generic anchors \rkeyname{parent anchor,aspect=generic anchor} and
% \rkeyname{child anchor,aspect=generic anchor} (which work only for \foRest; and not also \TikZ;
% nodes, of course) to facilitate reference to the desired endpoints of child--parent edges.
% Whenever one of these anchors is invoked, it looks up the value of the \keyname{parent anchor} or
% \keyname{child anchor} of the node named in the coordinate specification, and forwards the request
% to the (\TikZ;) anchor given as the value.
%
% The indented use of the two anchors is chiefly in \ikeyname{edge path} specification, but they can
% used in any \TikZ; code.
% \begin{forestexample}[ekeynames={parent anchor,child anchor,for tree}]
%   \begin{forest}
%     for tree={~parent anchor~=south,~child anchor~=north}
%     [VP[V][DP]]
%     \path[fill=red] (.parent anchor) circle[radius=2pt]
%                     (!1.child anchor) circle[radius=2pt]
%                     (!2.child anchor) circle[radius=2pt];
%   \end{forest}
% \end{forestexample}
%
% The empty value (which is the default) is interpreted as in \TikZ;: as an edge to the appropriate
% border point.
%
%
% \rkeyname[item]{no edge} Clears the edge options (\ikeyname{edge}|'={}|) and sets \ikeyname{ignore
% edge}.
%
% \rkeyname[item]{triangle} Makes the edge to parent a triangular roof.  Works only for south-growing
% trees.  Works by changing the value of \ikeyname{edge path}.
% 
% \end{syntax}
%
% \subsubsection{Readonly}
% \label{ref:readonly-options}
%
% The values of these options provide various information about the tree and its nodes.
% 
% \begin{syntax}
% \rkeyname[item]{id=id}|=|\meta{count}) The internal id of the node.
%
% \rkeyname[item]{level}|=|\meta{count}  The hierarchical level of the node.  The root is on level $0$. 
%
% \rkeyname[item]{max x}|=|\meta{dimen} \vspace{-\parskip}
% \rkeyname[item]{max y}|=|\meta{dimen} \vspace{-\parskip}
% \rkeyname[item]{min x}|=|\meta{dimen} \vspace{-\parskip}
% \rkeyname[item]{min y}|=|\meta{dimen}
%   Measures of the node, in the shape's coordinate system
%   \citep[see][\S16.2,\S48,\S75]{tikzpgf2.10} shifted so that the node anchor is at the origin.
%
%   In |pgfmath| expressions, these options are accessible as |max__x|, |max__y|, |min__x| and |min__y|.
%
% \rkeyname[item]{n}|=|\meta{count}  The child's sequence number in the list of its parent's
%   children. 
%
%   The enumeration starts with 1.  For the root node, \keyname{n} equals $0$. 
%
% \rkeyname[item]{n'}|=|\meta{count}  Like \ikeyname{n}, but starts counting at the last child.
%
%   In |pgfmath| expressions, this option is accessible as |n__|.
%
% \rkeyname[item]{n children}|=|\meta{count} The number of children of the node.
%   
%   In |pgfmath| expressions, this option is accessible as |n__children|.
% \end{syntax}
% 
% \subsubsection{Miscellaneous}
% \label{ref:miscellaneous}
%
% \begin{syntax}
%   \rkeyname[item]{afterthought}|=|\meta{toks}  Provides the afterthought explicitely.
%
%   This key is normally not used by the end-user, but rather called by the bracket parser.  By
%   default, this key is a style defined by |afterthought/.style={tikz+={#1}}|: afterthoughts are
%   interpreted as (cumulative) \TikZ; code.  If you'd like to use afterthoughts for some other
%   purpose, redefine the key --- this will take effect even if you do it in the tree preamble.
%
% \rkeyname[item]{alias}|=|\meta{toks} Sets the alias for the node's name.
%
%   Unlike \ikeyname{name}, \keyname{alias} is \emph{not} an option: you cannot e.g.\ query it's
%   value via a |pgfmath| expression.
%
%   Aliases can be used as the \meta{forest node name} part of a relative node name and as the
%   argument to the \ikeyname{name,aspect=step} step of a node walk.  The latter includes the usage
%   as the argument of the \ikeyname{id={{for }}}\ikeyname{name} propagator.
%
%   Technically speaking, \foRest; alias is \emph{not} a \TikZ; alias!  However, you can still use
%   it as a ``node name'' in \TikZ; coordinates, since \foRest; hacks \TikZ;'s implicit node
%   coordinate system to accept relative node names; see \S\ref{ref:forest-cs}.
%
%   \rkeyname[item]{baseline} The node's anchor becomes the baseline of the whole tree
%   \citep[cf.][\S69.3.1]{tikzpgf2.10}.
%
%   In plain language, when the tree is inserted in your (normal \TeX) text, it will be vertically
%   aligned to the anchor of the current node.
%
%   Behind the scenes, this style sets the alias of the current node to \keyname{forest@baseline@node}.
% \begin{forestexample}[ekeynames={baseline,use as bounding box'}]
%   {\tikzexternaldisable
%   Baseline at the
%   \begin{forest}
%     [parent,~baseline~,use as bounding box'
%       [child]]
%   \end{forest}
%   and baseline at the
%   \begin{forest}
%     [parent
%       [child,~baseline~,use as bounding box']]
%   \end{forest}.}
% \end{forestexample}
%
% \rkeyname[item=\begin{tikzpicture}]{begin draw}|/.code=|\meta{toks: \TeX\ code}  \vspace{-\parskip}
% \rkeyname[item=\end{tikzpicture}]{end draw}|/.code=|\meta{toks: \TeX\ code}
%
% The code produced by \ikeyname{draw tree} is put in the environment specified by \keyname{begin
% draw} and \keyname{end draw}.  Thus, it is this environment, normally a |tikzpicture|, that does
% the actual drawing.
%
% A common use of these keys might be to enclose the |tikzpicture| environment in a |center|
% environment, thereby automatically centering all trees; or, to provide the \TikZ; code to execute
% at the beginning and/or end of the picture.
%
% Note that \keyname{begin draw} and \keyname{end draw} are \emph{not} node options: they are
% |\pgfkeys|' code-storing keys \citep[\S55.4.3--4]{tikzpgf2.10}.
%
%
% \rkeyname[item={{{{{}}}}}]{begin forest}|/.code=|\meta{toks: \TeX\ code}  \vspace{-\parskip}
% \rkeyname[item={{{{{}}}}}]{end forest}|/.code=|\meta{toks: \TeX\ code}
%
% The code stored in these (|\pgfkeys|) keys is executed at the beginning and end of the
% \ikeyname{forest} environment / \icmdname{Forest} macro.  
%
% Using these keys is only effective \emph{outside} the \ikeyname{forest} environment, and the
% effect lasts until the end of the current \TeX\ group.
%
% For example, executing \icmdname{forestset}|{begin forest/.code=\small}| will typeset all trees (and only
% trees) in the small font size.  
%
%
% \rkeyname[item]{fit to tree}  Fits the \TikZ; node to the current node's subtree.
%
% This key should be used like \keyname{/tikz/fit} of the \TikZ;'s fitting library
% \citep[see][\S34]{tikzpgf2.10}: as an option to \emph{\TikZ;'s} |node| operation, the obvious
% restriction being that \keyname{fit to tree} must be used in the context of some \foRest; node.
% For an example, see footnote~\ref{fn:fit-to-tree}.
%
% This key works by calling \keyname{/tikz/fit} and providing it with the the coordinates of the
% subtree's boundary.
%
% \rkeyname[item]{get min s tree boundary}|=|\meta{cs} \vspace{-\parskip}
% \rkeyname[item]{get max s tree boundary}|=|\meta{cs}
%
% Puts the boundary computed during the packing process into the given \meta{cs}.  The boundary is
% in the form of \PGF; path.  The |min| and |max| versions give the two sides of the node.  For an
% example, see how the boundaries in the discussion of \ikeyname{fit} were drawn.
%
%   \rkeyname[item]{label}|=|\meta{toks: \TikZ; node}  The current node is labelled by a \TikZ; node.
%
%   The label is specified as a \TikZ; option \texttt{label} \citep[\S16.10]{tikzpgf2.10}.
%   Technically, the value of this option is passed to \TikZ;'s as a late option
%   \citep[\S16.14]{tikzpgf2.10}.  (This is so because \foRest; must first typeset the nodes
%   separately to measure them (stage \ikeyname{typeset nodes}); the preconstructed nodes are inserted
%   in the big picture later, at stage \ikeyname{draw tree}.)  Another option with the same
%   technicality is \ikeyname{pin}. 
%
%   \rkeyname[item]{name}|=|\meta{toks} Sets the name of the node.\hfill\texttt{node@}\meta{id}
%
%   The expansion of \meta{toks} becomes the \meta{forest node name} of the node.  Node names must
%   be unique.  The \TikZ; node created from the \foRest; node will get the name specified by this
%   option.
%
% \rkeyname[item]{node walk}|=|\meta{node walk}  This key is the most general way to use a \meta{node
%   walk}.
%
%   Before starting the \meta{node walk}, key \rkeyname{id={node walk/before walk}} is processed.
%   Then, the \meta{step}s composing the \meta{node walk} are processed: making a step (normally)
%   changes the current node.  After every step, key \rkeyname{id={node walk/every step}} is
%   processed.  After the walk, key \rkeyname{id={node walk/after walk}} is processed.
%
%   \keyname{node walk/before walk}, \keyname{node walk/every step} and \keyname{node walk/after
%   walk} are processed with \keyname{/forest} as the default path: thus, \foRest;'s options and
%   keys described in \S\ref{ref:options-and-keys} can be used normally inside their definitions.
%
%   \begin{advise}
%   \item Node walks can be tail-recursive, i.e.\ you can call another node walk from \keyname{node
%     walk/after walk} --- embedding another node walk in \keyname{node walk/before walk} or
%     \keyname{node walk/every step} will probably fail, because the three node walk styles are not
%     saved and restored (a node walk doesn't create a \TeX\ group).
%   \item \keyname{every step} and \keyname{after walk} can be redefined even during the walk.
%     Obviously, redefining \keyname{before walk} during the walk has no effect (in the current
%     walk).
%   \end{advise}
%
%   \rkeyname[item]{pin}|=|\meta{toks: \TikZ; node}  The current node gets a pin, see
%   \citep[\S16.10]{tikzpgf2.10}. 
%
%   The technical details are the same as for \ikeyname{label}.
%
%   \rkeyname[item]{use as bounding box} The current node's box is used as a bounding box for the
%   whole tree.
%
%   \rkeyname[item]{use as bounding box'} Like \ikeyname{use as bounding box}, but subtracts the
%   (current) inner and outer sep from the node's box.  For an example, see \ikeyname{baseline}.
%   
%   \rkeyname[item]{TeX}|=|\meta{toks: \TeX\ code} The given code is executed immediately.
%
%   This can be used for e.g.\ enumerating nodes:
% \begin{forestexample}[point=TeX,ekeynames={TeX,delay,where ,tier,content,GP1},label=ex:enumerate]
%   \newcount\xcount
%   \begin{forest} GP1,
%     delay={TeX={\xcount=0},
%       where tier={x}{TeX={\advance\xcount1},
%          content/.expanded={##1$_{\the\xcount}$}}{}}
%     [
%       [O[x[f]]]
%       [R[N[x[o]]]]
%       [O[x[r]]]
%       [R[N[x[e]]][x[s]]]
%       [O[x[t]]]
%       [R[N[x]]]
%     ]
%   \end{forest}
% \end{forestexample}
%
% \rkeyname[item]{TeX'}|=|\meta{toks: \TeX\ code} This key is a combination of keys \ikeyname{TeX}
% and \ikeyname{TeX''}: the given code is both executed and externalized.
%
% \rkeyname[item]{TeX''}|=|\meta{toks: \TeX\ code} The given code is externalized, i.e.\ it will be
% executed when the externalized images are loaded.
%
% The image-loading and \keyname{TeX'(')} produced code are intertwined.
%
%   \rkeyname[item={{{{{}}}}}]{tikz}|=|\meta{toks: \TikZ; code}  ``Decorations.''
%
%   The code given as the value of this option will be included in the |tikzpicture| environment
%   used to draw the tree.  The code given to various nodes is appended in a depth-first,
%   parent-first fashion.  The code is included after all nodes of the tree have been drawn, so it
%   can refer to any node of the tree.  Furthermore, relative node names can be used to refer to
%   nodes of the tree, see \S\ref{ref:relative-node-names}.
%
%   By default, bracket parser's afterthoughts feed the value of this option.  See
%   \ikeyname{afterthought}. 
%
% \end{syntax}
% 
% \subsubsection{Propagators}
% \label{ref:propagators}
% 
% Propagators pass the given \meta{keylist} to other node(s), delay their processing, or cause them
% to be processed only under certain conditions.
%
% A propagator can never fail --- i.e.\ if you use \keyname{for next} on the last child of some node,
% no error will arise: the \meta{keylist} will simply not be passed to any node. (The generic
% node walk propagator \keyname{for} is
% an exception.  While it will not fail if the final node of the walk does not exist (is null), its node walk
% can fail when trying to walk away from the null node.)
%
% \paragraph{Spatial propagators}
% pass the given \meta{keylist} to other node(s) in the tree.  (\keyname{for} and \keyname{for
% }\meta{step} always pass the \meta{keylist} to a single node.)
%
% \begin{syntax}
% \rkeyname[item]{for}|=|\meta{node walk}\meta{keylist}  Processes \meta{keylist} in the context of the final
%   node in the \meta{node walk} starting at the current node.
%
% \rkeyname[item]{id={{for }}}\meta{step}|=|\meta{keylist}  Walks a single-step node-walk
% \meta{step} from the current node and passes the given \meta{keylist} to the final (i.e.\ second) node.
%
% \meta{step} must be a long node walk step; see \S\ref{ref:node-walk}. \keyname{for
% }\meta{step}|=|\meta{keylist} is equivalent to \ikeyname{for}|=|\meta{step}{keylist}.
%
% Examples: |for_parent={l_sep+=3mm}|, |for_n=2{circle,draw}|.
% 
% \rkeyname[item]{for ancestors}|=|\meta{keylist}
% \rkeyname[item]{for ancestors'}|=|\meta{keylist}  Passes the \meta{keylist} to itself, too.
% \begin{forestexample}[ekeynames={for ancestors',delay,content,edge}]
%   \pgfkeys{/forest,
%     inptr/.style={%
%       red,delay={content={\textbf{##1}}},
%       edge={draw,line width=1pt,red}},
%     ptr/.style={~for ancestors'~=inptr}
%   }
%   \begin{forest}
%     [x
%       [x[x[x][x]][x[x,ptr][x]]]
%       [x[x[x][x]][x[x][x]]]]
%   \end{forest}
% \end{forestexample}
%
%   \rkeyname[item]{for all next}|=|\meta{keylist} Passes the \meta{keylist} to all the following siblings.
%   
%   \rkeyname[item]{for all previous}|=|\meta{keylist} Passes the \meta{keylist} to all the preceding siblings.
%
%   \rkeyname[item]{for children}|=|\meta{keylist}
% 
%   \rkeyname[item]{for descendants}|=|\meta{keylist}
%     
%   \rkeyname[item]{for tree}|=|\meta{keylist}
%
%   Passes the key to the current node and its the descendants.
%
%   This key should really be named \keyname{for subtree} \dots  
%
% \end{syntax}
%
% \paragraph{Conditionals}
% \label{ref:conditionals}
% 
% For all conditionals, both the true and the false keylist are obligatory! Either keylist can be
% empty, however --- but don't omit the braces!
% 
% \begin{syntax}
% \rkeyname[item]{if}|=|\meta{pgfmath condition}\meta{true keylist}\meta{false keylist}
%
% If \meta{pgfmath condition} evaluates to |true| (non-zero), \meta{true keylist} is processed (in
% the context of the current node); otherwise, \meta{false keylist} is processed.
%
% For a detailed description of
% |pgfmath| expressions, see \cite[part VI]{tikzpgf2.10}.  (In short: write the usual mathematical
% expressions.)
% 
% \rkeyname[item]{id={{if }}}\meta{option}|=|\meta{value}\meta{true keylist}\meta{false keylist}
%
% A simple conditional is defined for every \meta{option}: if \meta{value} equals the value of the
% option at the current node, \meta{true keylist} is executed; otherwise, \meta{false keylist}.
%
% \rkeyname[item]{where}|=|\meta{value}\meta{true keylist}\meta{false keylist}
%
% Executes conditional \ikeyname{if} for every node in the current subtree.
%
% \rkeyname[item]{id={{where }}}\meta{option}|=|\meta{value}\meta{true keylist}\meta{false keylist}
%
% Executes simple conditional \ikeyname{id={{if }}}\meta{option} for every node in the current subtree.
%
% \rkeyname[item]{id={{if in }}}\meta{option}|=|\meta{toks}\meta{true keylist}\meta{false
%   keylist}
%
%   Checks if \meta{toks} occurs in the option value; if it does, \meta{true keylist} are executed,
%   otherwise \meta{false keylist}.
%
%   This conditional is defined only for \meta{toks} options, see \S\ref{ref:options-and-keys}.
%   
% \rkeyname[item]{id={{where in }}}\meta{toks option}|=|\meta{toks}\meta{true keylist}\meta{false keylist}
% 
% A style equivalent to \ikeyname{for tree}|=|\ikeyname{id={{if in }}}\meta{option}=\meta{toks}\meta{true
% keylist}\meta{false keylist}: for every node in the subtree rooted in the current node,
% \ikeyname{id={{if in }}}\meta{option} is executed in the context of that node.  
% 
% This conditional is defined only for \meta{toks} options, see \S\ref{ref:options-and-keys}.
% \end{syntax}
%
% \paragraph{Temporal propagators}
% There are two kinds of temporal propagators.  The |before_...| propagators defer the processing of
% the given keys to a hook just before some stage in the computation.  The \keyname{delay}
% propagator is ``internal'' to the current hook (the first hook, the given options, is
% implicit): the keys in a hook are processed cyclically, and \keyname{delay} delays the
% processing of the given options until the next cycle.  All these keys can be nested without
% limit. For details, see~\S\ref{ref:stages}.
% \begin{syntax}
% \rkeyname[item]{delay}|=|\meta{keylist} Defers the processing of the \meta{keylist} until the next
%   cycle.
% \rkeyname[item]{delay n}|=|\meta{integer}\meta{keylist} Defers the processing of the
%   \meta{keylist} for $n$ cycles.  $n$ may be $0$, and it may be given as a |pgfmath| expression.
% \rkeyname[item]{if have delayed}|=|\meta{true keylist}\meta{false keylist}  If any options were
%   delayed in the current cycle (more precisely, up to the point of the execution of this key),
%   process \meta{true keylist}, otherwise process \meta{false keylist}.  (\ikeyname{delay n} will
%   trigger ``true'' for the intermediate cycles.)
% \rkeyname[item]{before typesetting nodes}|=|\meta{keylist}  Defers the processing of the
%   \meta{keylist} to until just before the nodes are typeset.
% \rkeyname[item]{before packing}|=|\meta{keylist}  Defers the processing of the
%   \meta{keylist} to until just before the nodes are packed.
% \rkeyname[item]{before computing xy}|=|\meta{keylist}  Defers the processing of the
%   \meta{keylist} to until just before the absolute positions of the nodes are computed.
% \rkeyname[item]{before drawing tree}|=|\meta{keylist}  Defers the processing of the
%   \meta{keylist} to until just before the tree is drawn.
% \end{syntax}
%
% \paragraph{Other propagators}
% \begin{syntax}
%   \rkeyname[item]{repeat}|=|\meta{number}\meta{keylist}  The \meta{keylist} is processed \meta{number}
%   times.
%
%   The \meta{number} expression is evaluated using |pgfmath|.  Propagator \keyname{repeat} also
%   works in node walks.
% \end{syntax}
%
% \subsubsection{Stages}
% \label{ref:stages}
%
% \FoRest; does its job in several steps.  The normal course of events is the following:
% \begin{enumerate}
% \item\label{step:parsing-bracket} The bracket representation of the tree if parsed and stored in a
%   data structure.
% \item\label{step:given-options} The given options are processed, including the options in the
%   preamble, which are processed first (in the context of the root node).
% \item\label{step:typeset-nodes} Each node is typeset in its own |tikzpicture| environment, saved
%   in a box and its measures are taken.
% \item\label{step:pack} The nodes of the tree are \emph{packed}, i.e.\ the relative positions of the nodes are
%   computed so that the nodes don't overlap.  That's difficult.  The result: option \ikeyname{s} is
%   set for all nodes.  (Sometimes, the value of \ikeyname{l} is adjusted as well.)
% \item\label{step:compute-xy} Absolute positions, or rather, positions of the nodes relative to the
%   root node are computed.  That's easy.  The result: options \ikeyname{x} and \ikeyname{y} are
%   set.
% \item\label{step:draw-tree} The \TikZ; code that will draw the tree is produced.  (The nodes are
%   drawn by using the boxes typeset in step~\ref{step:typeset-nodes}.)
% \end{enumerate}
%
% Steps~\ref{step:parsing-bracket} and \ref{step:given-options} collect user input and are thus
% ``fixed''.  However, the other steps, which do the actual work, are under user's control.
%
% First, hooks exist which make it possible (and easy) to change node's properties between the
% processing stages.  For a simple example, see example~\ref{ex:adjustxy}: the manual adjustment of
% \ikeyname{y} can only be done after the absolute positions have been computed, so the processing
% of this option is deferred by \ikeyname{before drawing tree}.  For a more realistic example, see
% the definition of style \ikeyname{GP1}: before packing, \texttt{outer xsep} is set to a high (user
% determined) value to keep the $\times$s uniformly spaced; before drawing the tree, the
% \texttt{outer xsep} is set to \texttt{0pt} to make the arrows look better.
% 
% Second, the execution of the processing stages \ref{step:typeset-nodes}--\ref{step:draw-tree} is
% \emph{completely} under user's control.  To facilitate adjusting the processing flow, the approach
% is twofold.  The outer level: \foRest; initiates the processing by executing style
% \keyname{stages}, which by default executes the processing stages
% \ref{step:typeset-nodes}--\ref{step:draw-tree}, preceding the execution of each stage by
% processing the options embedded in temporal propagators \keyname{before ...} (see
% \S\ref{ref:propagators}).  The inner level: each processing step is the sole resident of a
% stage-style, which makes it easy to adjust the workings of a single step.  What follows is the
% default content of style \keyname{stages}, including the default content of the individual
% stage-styles.  
% \begin{syntax}
%   \rkeyname[item]{stages}
%   \begin{syntax}
%     \item \ikeyname{process keylist}|=|\ikeyname{before typesetting nodes}
%     \rkeyname[item]{typeset nodes stage}\hfill
%       |{|\ikeyname{id={{for }}}\ikeyname{root'}|=|\ikeyname{typeset nodes}|}|
%     \item \ikeyname{process keylist}|=|\ikeyname{before packing}
%     \rkeyname[item]{pack stage}\hfill
%       |{|\ikeyname{id={{for }}}\ikeyname{root'}|=|\ikeyname{pack}|}|
%     \item \ikeyname{process keylist}|=|\ikeyname{before computing xy}
%     \rkeyname[item]{compute xy stage}\hfill
%       |{|\ikeyname{id={{for }}}\ikeyname{root'}|=|\ikeyname{compute xy}|}|
%     \item \ikeyname{process keylist}|=|\ikeyname{before drawing tree}
%     \rkeyname[item]{draw tree stage}\hfill
%       |{|\ikeyname{id={{for }}}\ikeyname{root'}|=|\ikeyname{draw tree}|}|
%   \end{syntax}
% \end{syntax}
%
% Both style \keyname{stages} and the individual stage-styles may be freely modified by the user.
% Obviously, a style must be redefined before it is processed, so it is safest to do so either
% outside the \ikeyname{forest} environment (using macro \icmdname{forestset}) or in the preamble
% (in a non-deferred fashion).
% 
% Here's the list of keys used either in the default processing or useful in an alternative
% processing flow.
% \begin{syntax}
% \rkeyname[item]{typeset nodes} Typesets each node of the current node's subtree in its own
%   |tikzpicture| environment.  The result is saved in a box and its measures are taken.
% 
% \rkeyname[item]{typeset nodes'}  Like \ikeyname{typeset nodes}, but the node box's content is not
%   overwritten if the box already exists.
%   
% \rkeyname[item]{typeset node}  Typesets the \emph{current} node, saving the result in the node box.
%
%   This key can be useful also in the default \ikeyname{stages}.  If, for example, the node's content
%   is changed and the node retypeset just before drawing the tree, the node will be positioned as if
%   it contained the ``old'' content, but have the new content: this is how the constant distance
%   between $\times$s is implemented in the \ikeyname{GP1} style.
%
% \rkeyname[item]{pack} The nodes of the tree are \emph{packed}, i.e.\ the relative positions of
%   the nodes are computed so that the nodes don't overlap.  The result: option \ikeyname{s} is set
%   for all nodes; sometimes (in tier alignment and for some values of \ikeyname{calign}), the value
%   of some nodes' \ikeyname{l} is adjusted as well.
%
% \rkeyname[item]{pack'} ``Non-recursive'' packing: packs the children of the current node only.
%   (Experimental, use with care, especially when combining with tier alignment.)
%
% \rkeyname[item]{compute xy} Computes the positions of the nodes relative to the (formal) root
%   node.  The results are stored into options \ikeyname{x} and \ikeyname{y}.
%
% \rkeyname[item]{draw tree} Produces the \TikZ; code that will draw the tree.  First, the nodes
%   are drawn (using the boxes typeset in step~\ref{step:typeset-nodes}), followed by edges and
%   custom code (see option \ikeyname{tikz}).
%   
% \rkeyname[item]{draw tree'} Like \ikeyname{draw tree}, but the node boxes are included in the
%   picture using \cmdname{copy}, not \cmdname{box}, thereby preserving them.     
%   
% \rkeyname[item]{draw tree box}|=|[\meta{\TeX\ box}]  The picture drawn by the subsequent
%   invocations of \ikeyname{draw tree} and \ikeyname{draw tree'} is put into \meta{\TeX\ box}.  If
%   the argument is omitted, the subsequent pictures are typeset normally (the default).
%
% \rkeyname[item]{process keylist}|=|\meta{keylist option name}  Processes the keylist saved in
%   option \meta{keylist option name} for all the nodes in the \emph{whole} tree.
%
%   This key is not sensitive to the current node: it processes the keylists for the whole tree.
%   The calls of this key should \emph{not} be nested.
%
%   Keylist-processing proceeds in cycles.  In a given cycle, the value of option \meta{keylist
%   option name} is processed for every node, in a recursive (parent-first, depth-first) fashion.
%   During a cycle, keys may be \emph{delayed} using key \ikeyname{delay}.  (Keys of the dynamically
%   created nodes are automatically delayed.) Keys delayed in a cycle are processed in the next
%   cycle.  The number of cycles in unlimited.  When no keys are delayed in a cycle, the processing
%   of a hook is finished.
% \end{syntax}
%
% \subsubsection{Dynamic tree}
% \label{ref:dynamic}
%
% The following keys can be used to change the geometry of the tree by creating new nodes and
% integrating them into the tree, moving and copying nodes around the tree, and removing nodes from
% the tree.
% 
% The node that will be (re)integrated into the tree can be specified in the following ways:
% \begin{syntax}
% \item \meta{empty}: uses the last (non-integrated, i.e.\ created/removed/replaced) node.
% \item \meta{node}: a new node is created using the given bracket representation (the node may
%   contain children, i.e.\ a tree may be specified), and used as the argument to the key.
%
%   The bracket representation must be enclosed in brackets, which will usually be enclosed in
%   braces to prevent them being parsed while parsing the ``host tree.''
% \item \imeta{relative node name}: the node \meta{relative node name} resolves to will be used.
% \end{syntax}
%
% Here is the list of dynamic tree keys:
% 
% \begin{syntax}
% \rkeyname[item]{append}|=|\meta{empty}\OR|[|\meta{node}|]|\OR\meta{relative node name}
% 
%   The specified node becomes the new final child of the current node.  If the specified node had a
%   parent, it is first removed from its old position.
%   
% \begin{forestexample}[label=ex:append,point=append,ekeynames={append,delay,for tree,n,content,n',repeat}]
%   \begin{forest}
%     before typesetting nodes={for tree={
%       if n=1{content=L}
%            {if n'=1{content=R}
%                     {content=C}}}}
%     [,repeat=2{append={[
%       ,repeat=3{append={[]}}
%     ]}}]
%   \end{forest}
% \end{forestexample}
%
% \rkeyname[item]{create}|=[|\meta{node}|]|
%
% Create a new node. The new node becomes the last node.
% 
% \rkeyname[item]{insert after}|=|\meta{empty}\OR|[|\meta{node}|]|\OR\meta{relative node name}
% 
%   The specified node becomes the new following sibling of the current node.  If the specified node had a
%   parent, it is first removed from its old position.
%   
% \rkeyname[item]{insert before}|=|\meta{empty}\OR|[|\meta{node}|]|\OR\meta{relative node name}
% 
%   The specified node becomes the new previous sibling of the current node.  If the specified node had a
%   parent, it is first removed from its old position.
%   
% \rkeyname[item]{prepend}|=|\meta{empty}\OR|[|\meta{node}|]|\OR\meta{relative node name}
% 
%   The specified node becomes the new first child of the current node.  If the specified node had a
%   parent, it is first removed from its old position.
%   
% \rkeyname[item]{remove}
%
% The current node is removed from the tree and becomes the last node.
%
% The node itself is not deleted: it is just not integrated in the tree anymore.  Removing the root
% node has no effect.
% 
% \rkeyname[item]{replace by}|=|\meta{empty}\OR|[|\meta{node}|]|\OR\meta{relative node name}
% 
%   The current node is replaced by the specified node.  The current node becomes the last node.
%
%   It the specified node is a new node containing a dynamic tree key, it can refer to the replaced
%   node by the \meta{empty} specification.  This works even if multiple replacements are made.
%   
%   If \keyname{replace by} is used on the root node, the ``replacement'' becomes the root node
%   (\ikeyname{set root} is used). 
%
%   \rkeyname[item]{set root}
%
% The current node becomes the new \emph{formal} root of the tree.
%
% Note: If the current node has a parent, it is \emph{not} removed from it.  The node becomes the
% root only in the sense that the default implementation of stage-processing will consider it a
% root, and thus typeset/pack/draw the (sub)tree rooted in this root.  The processing of keys such
% as \ikeyname{for parent} and \ikeyname{for root} is not affected: \ikeyname{for root} finds the
% real, geometric root of the current node.  To access the formal root, use node walk step
% \ikeyname{root'}, or the corresponding propagator \ikeyname{id={{for }}}\ikeyname{root'}.
% \end{syntax}
%
% If given an existing node, most of the above keys \emph{move} this node
% (and its subtree, of course).  Below are the versions of these operations which rather \emph{copy}
% the node: either the whole subtree (|'|) or just the node itself (|''|).
% \begin{syntax}
% \rkeyname[item]{append'}, \rkeyname{insert after'}, \rkeyname{insert before'}, \rkeyname{prepend'},
%   \rkeyname{replace by'}
%
%   Same as versions without |'| (also the same arguments), but it is the copy of the specified node
%   and its subtree that is integrated in the new place.
% \rkeyname[item]{append''}, \rkeyname{insert after''}, \rkeyname{insert before''}, \rkeyname{prepend''},
%   \rkeyname{replace by''}
%
%   Same as versions without |''| (also the same arguments), but it is the copy of the specified node
%   (without its subtree) that is integrated in the new place.
% \rkeyname[item]{copy name template}|=|\meta{empty}\OR\meta{macro definition} \hfill\meta{empty}
% 
% Defines a template for constructing the \ikeyname{name} of the copy from the name of the
% original.  \meta{macro definition} should be either empty (then, the \ikeyname{name} is
% constructed from the \ikeyname{id=id}, as usual), or an expandable macro taking one argument (the
% name of the original).
% \end{syntax}
%
% \begin{advise}
% \item You might want to \ikeyname{delay} the processing of the copying operations, giving the
%   original nodes the chance to process their keys first!
% \end{advise}
% 
% \begin{forestexample}
%   \begin{forest}
%     copy name template={copy of #1}
%     [CP,delay={prepend'=subject}
%       [VP[DP,name=subject[D][NP]][V'[V][DP]]]]
%     \draw[->,dotted] (subject)--(copy of subject);
%   \end{forest}
% \end{forestexample}
%
% A dynamic tree operation is made in two steps:
% \begin{itemize}
% \item If the argument is given by a \meta{node} argument, the new node is created immediately,
%   i.e.\ while the dynamic tree key is being processed.  Any options of the new node are
%   implicitely \ikeyname{delay}ed. 
% \item The requested changes in the tree structure are actually made between the cycles of keylist
%   processing.
% \end{itemize}
% 
% \begin{advise}
% \item Such a two-stage approach is employed because changing the tree structure during the dynamic
%   tree key processing would lead to an unmanageable order of keylist processing.
% \item A consequence of this approach is that nested dynamic tree keys take several cycles to
%   complete.  Therefore, be careful when using \ikeyname{delay} and dynamic tree keys
%   simultaneously: in such a case, it is often safer to use \ikeyname{before typesetting nodes}
%   instead of \ikeyname{delay}, see example \ref{ex:append}.
% \item Further examples: title page (in style |random tree|), \ref{ex:xlist}.
% \end{advise}
%
% \subsection{Handlers}
% \label{ref:handlers}
%
% \begin{syntax}
% \rkeyname[item]{id=.pgfmath,nfc}|=|\meta{pgfmath expression}
%
% The result is the evaluation of \meta{pgfmath expression} in the context of the current node.
% 
% \rkeyname[item]{id=.wrap value,nfc}|=|\meta{macro definition}
%
% The result is the (single) expansion of the given
%   \meta{macro definition}.  The defined macro takes one parameter.  The current value of the
%   handled option will be passed as that parameter.
%   
% \rkeyname[item]{id=.wrap $n$ pgfmath args,nfc}|=|\meta{macro definition}\meta{arg $1$}\dots\meta{arg $n$}
% 
%   The result is the (single) expansion of the given \meta{macro definition}.  The defined macro
%   takes $n$ parameters, where $n\in\{2,\dots,8\}$.  Expressions \meta{arg $1$} to \meta{arg $n$}
%   are evaluated using |pgfmath| and passed as arguments to the defined macro.
%   
% \rkeyname[item]{id=.wrap pgfmath arg,nfc}|=|\meta{macro definition}\meta{arg}
%
% Like \ikeyname{id=.wrap $n$ pgfmath args,nfc} for $n=1$. 
% \end{syntax}
% 
% \subsection{Relative node names}
% \label{ref:relative-node-names}
%
% \begin{syntax}
% \item\rmeta{relative node name}|=|[\meta{forest node name}][|!|\meta{node walk}]
%
%   \meta{relative node name} refers to the \foRest; node at the end of the \meta{node walk}
%   starting at node named \meta{forest node name}.  If \meta{forest node name} is omitted, the walk
%   starts at the current node.  If \meta{node walk} is omitted, the ``walk'' ends at the start
%   node.   (Thus, an empty \meta{relative node name} refers to the current node.)
% \end{syntax}
%
% Relative node names can be used in the following contexts:
% \begin{itemize}
% \item \FoRest;'s |pgfmath| option functions (\S\ref{ref:pgfmath}) take a relative node name as
%   their argument, e.g.\ |content("!u")| and |content("!parent")| refer to the content of the
%   parent node.
% \item An option of a non-current node can be set by \meta{relative node name}|.|\meta{option
%   name}|=|\meta{value}, see \S\ref{ref:options-and-keys}.
% \item The |forest| coordinate system, both explicit and implicit; see \S\ref{ref:forest-cs}.
% \end{itemize}
%
% \subsubsection{Node walk}
% \label{ref:node-walk}
%
% A \rmeta{node walk} is a sequence of \rmeta{step}s describing a path through the tree.  
% The primary use of node walks is in relative node names.  However, they can also be used in a
% ``standalone'' way, using key \ikeyname{node walk}; see \S\ref{ref:miscellaneous}.
%
% Steps are keys in the \keyname{/forest/node walk} path.  (\foRest; always sets this path as
% default when a node walk is to be used, so step keynames can be used.)  Formally, a \meta{node
% walk} is thus a keylist, and steps must be separated by commas.  There is a twist, however.  Some
% steps also have \emph{short} names, which consist of a single character.  The comma between two
% adjacent short steps can be omitted.  Examples:
% \begin{itemize}
% \item |parent,parent,n=2| or |uu2|: the grandparent's second child (of the current node)
% \item |first leaf,uu|: the grandparent of the first leaf (of the current node)
% \end{itemize}
% The list of long steps:
% \newcommand\nwritem[1]{\rkeyname[item]{#1,aspect=step}\ekeyname{for #1,aspect=propagator,def}}
% \begin{syntax}
% \nwritem{current} an ``empty'' step: the current node remains the same\footnote{While it
%   might at first sight seem stupid to have an empty step, this is not the case.  For example,
%   using propagator \ikeyname{for current} derived from this step, one can process a \meta{keylist}
%   constructed using \texttt{.wrap (n) pgfmath arg(s)}\ekeyname{id=.wrap 
%   pgfmath arg,nfc}\ekeyname{id=.wrap $n$ pgfmath args,nfc} or \ikeyname{id=.wrap value,nfc}.} 
% \nwritem{first} the primary child
% \nwritem{first leaf} the first leaf (terminal node)
% \rkeyname[item]{group,aspect=step}|=|\meta{node walk}  treat the given \meta{node walk} as a single step
% \nwritem{last} the last child
% \nwritem{last leaf} the last leaf
% \nwritem{id=id}|=|\meta{id} the node with the given id
% \nwritem{linear next} the next node, in the processing order 
% \nwritem{linear previous} the previous node, in the processing order 
% \nwritem{n}|=|$n$ the $n$th child; counting starts at $1$ (not $0$)
% \nwritem{n'}|=|$n$ the $n$th child, starting the count from the last child
% \nwritem{name} the node with the given name
% \nwritem{next} the next sibling 
% \nwritem{next leaf} the next leaf
%
% (the current node need not be a leaf) 
% \nwritem{next on tier} the next node on the same tier as the current node 
% \rkeyname[item]{node walk,aspect=step}|=|\meta{node walk}  embed the given \meta{node walk}
%
% (the \ikeyname{id={node walk/before walk}} and \ikeyname{id={node walk/after walk}} are processed)
% \nwritem{parent} the parent 
% \nwritem{previous} the previous sibling 
% \nwritem{previous leaf} the previous leaf
%
% (the current node need not be a leaf) 
% \nwritem{previous on tier} the next node on the same tier as the current node 
% \rkeyname[item]{repeat}|=|$n$\meta{node walk} repeat the given \meta{node walk} $n$ times
%
% (each step in every repetition counts as a step)
% \nwritem{root} the root node
% \nwritem{root'} the formal root node (see \ikeyname{set root} in \S\ref{ref:dynamic})
% \nwritem{sibling} the sibling
%
% (don't use if the parent doesn't have exactly two children \dots)
% \nwritem{to tier}|=|\meta{tier} the first ancestor of the current node on the given \meta{tier}
% \rkeyname[item]{trip,aspect=step}|=|\meta{node walk}  after walking the embedded \meta{node walk}, return to the
%   current node; the return does not count as a step
% \end{syntax}
%
% For each long \meta{step} except \keyname{node walk}, \keyname{group}, \keyname{trip} and
% \keyname{repeat}, propagator \ikeyname{id={{for }}}\meta{step} is also defined.  Each such
% propagator takes a \meta{keylist} argument.  If the step takes an argument, then so does its
% propagator; this argument precedes the \meta{keylist}.  See also \S\ref{ref:propagators}.
% 
% Short steps are single-character keys in the \keyname{/forest/node walk} path.  They are defined
% as styles resolving to long steps, e.g.\ |1/.style={n=1}|.  The list of predefined short steps
% follows. 
% \begin{syntax}
% \rkeyname[item]{1},
%   \rkeyname{2},
%   \rkeyname{3},
%   \rkeyname{4},
%   \rkeyname{5},
%   \rkeyname{6},
%   \rkeyname{7},
%   \rkeyname{8},
%   \rkeyname{9} the first, \dots, ninth child
% \rkeyname[item]{l,aspect=short step} the last child
% \rkeyname[item]{u} the parent (up)
% \rkeyname[item]{p} the previous sibling
% \rkeyname[item]{n,aspect=short step} the next sibling
% \rkeyname[item]{s,aspect=short step} the sibling
% \rkeyname[item]{P} the previous leaf
% \rkeyname[item]{N} the next leaf
% \rkeyname[item]{F} the first leaf
% \rkeyname[item]{L} the last leaf
% \rkeyname[item]{id=<<<,display=\protect\myindexgt,text=>,aspect=short step}
%   the next node on the current tier
% \rkeyname[item]{<} the previous node on the current tier
% \rkeyname[item]{c} the current node
% \rkeyname[item]{r} the root node
% \end{syntax}
% \begin{advise}
% \item You can define your own short steps, or even redefine predefined short steps!
% \end{advise}
% 
% \subsubsection{The \texttt{forest} coordinate system}
% \label{ref:forest-cs}
% 
% Unless package options \ikeyname{tikzcshack} is set to |false|, \TikZ;'s implicit node coordinate
% system \citep[\S13.2.3]{tikzpgf2.10} is hacked to accept relative node names.\footnote{Actually,
% the hack can be switched on and off on the fly, using \cmdname{i}\keyname{fforesttikzcshack}.}.
% 
% The explicit \texttt{forest} coordinate system is called simply |forest| and used like this:
% |(forest_cs:|\meta{forest cs spec}|)|; see \citep[\S13.2.5]{tikzpgf2.10}.  \meta{forest cs spec}
% is a keylist; the following keys are accepted.
% 
% \begin{syntax}
% \rkeyname[item]{name,aspect=forest cs}|=|\meta{node name}  The node with the given name becomed the current node.  The
% resulting point is its (node) anchor.
% \rkeyname[item]{id=id,aspect=forest cs}|=|\meta{node id}  The node with the given name becomed the current node. The
% resulting point is its (node) anchor.
% \rkeyname[item]{go,aspect=forest cs}|=|\meta{node walk}  Walk the given node walk, starting at the current node.  The node
% at the end of the walk becomes the current node.  The resulting point is its (node) anchor.
% \rkeyname[item]{anchor,aspect=forest cs}|=|\meta{anchor}  The resulting point is the given anchor of the current node.
% \rkeyname[item]{l,aspect=forest cs}|=|\meta{dimen} \vspace{-\parskip}
% \rkeyname[item]{s,aspect=forest cs}|=|\meta{dimen}  Specify the \ikeyname{l} and \ikeyname{s}
% coordinate of the resulting point.
%
% The coordinate system is the node's ls-coordinate system: its origin is at its (node) anchor; the
% l-axis points in the direction of the tree growth at the node, which is given by option
% \ikeyname{grow};  the s-axis is orthogonal to the l-axis; the positive side is in the
% counter-clockwise direction from |l| axis.
%
% The resulting point is computed only after both \ikeyname{l} and \ikeyname{s} were given. 
% \item Any other key is interpreted as a \imeta{relative node name}[.\meta{anchor}].
% \end{syntax}
% 
% \subsection{New \texttt{pgfmath} functions}
% \label{ref:pgfmath}
%
% For every option, \foRest; defines a pgfmath function with the same name, with the
% proviso that all non-alphanumeric characters in the option name are replaced by an underscore
% |__| in the pgfmath function name.
%
% Pgfmath functions corresponding to options take one argument, a \imeta{relative node name}
% (see~\S\ref{ref:relative-node-names}) expression, making it possible to refer to option values of
% non-current nodes.  The \meta{relative node name} expression must be enclosed in double quotes in
% order to 
% prevent pgfmath evaluation: for example, to refer to the content of the parent, write
% \ikeyname{content}|("!u")|.  To refer to the option of the current node, use empty parentheses:
% \ikeyname{content}|()|.\footnote{In most cases, the parentheses are optional, so \texttt{content}
% is ok.  A known case where this doesn't work is preceding an operator: \texttt{l+1cm} will fail.}
% 
% Three string functions are also added to |pgfmath|: \rkeyname{strequal} tests the equality of
% its two arguments; \rkeyname{instr} tests if the first string is a substring of the second one;
% \rkeyname{strcat} joins an arbitrary number of strings.
%
% Some random notes on |pgfmath|: \begin{inparaenum}[(i)]
% \item |&&|, \verb!||! and |!| are boolean ``and'', ``or'' and ``not'', respectively.
% \item The equality operator (for numbers and dimensions) is |==|, \emph{not} |=|.
% \end{inparaenum}  And some examples:
% 
% \begin{forestexample}[pos=t,ekeynames={for tree,grow',calign,l,l sep,child
% anchor,anchor,fit,tier,level,delay,before typesetting nodes,content,{id=.wrap 2 pgfmath args,nfc},{id=.pgfmath,nfc}}]
%   \begin{forest}
%     for tree={grow'=0,calign=first,l=0,l sep=2em,child anchor=west,anchor=base
%       west,fit=band,tier/.pgfmath=~level~()},
%     fullpath/.style={if n=0{}{content/.wrap 2
%         pgfmath args={##1/##2}{~content~("!u")}{~content~()}}},
%     delay={for tree=fullpath,content=/},
%     before typesetting nodes={for tree={content=\strut#1}}
%     [
%       [home
%         [joe
%           [\TeX]]
%         [saso
%           [\TeX]]
%         [a user with a long name
%           [\TeX]]]
%       [usr]]
%   \end{forest}
% \end{forestexample}
%
% \begin{forestexample}[point=instr,ekeynames={delay,for tree,if,content,n children}]
%   \begin{forest}
%     delay={for tree={if=
%       {!instr("!P",~content~) && ~n_children~==0}
%       {fill=yellow}
%       {}
%     }}
%     [CP[DP][C'[C][TP[DP][T'[T][VP[DP][V'[V][DP]]]]]]]
%   \end{forest}
% \end{forestexample}
%
% \begin{forestexample}[point=instr,ekeynames={where ,n children,tier,content,no edge,tikz}]
%   \begin{forest}
%     where n children=0{tier=word,
%       if={~instr~("!P",~content~("!u"))}{no edge,
%         tikz={\draw (!.north west)--
%         (!.north east)--(!u.south)--cycle;
%       }}{}
%     }{},
%     [VP[DP[John]][V'[V[loves]][DP[Mary]]]]
%   \end{forest}
% \end{forestexample}
%
%
% \subsection{Standard node}
% \label{ref:standard-node}
%
% \begin{syntax}
% \item\rcmdname{forestStandardNode}\meta{node}\meta{environment fingerprint}\meta{calibration
%   procedure}\meta{exported options}
%
%   This macro defines the current \emph{standard node}.  The standard node declares some options as
%   \emph{exported}.  When a new node is created, the values of the exported options are initialized
%   from the standard node.  At the beginning of every \ikeyname{forest} environment, it is checked whether
%   the \emph{environment fingerprint} of the standard node has changed.  If it did, the standard
%   node is \emph{calibrated}, adjusting the values of exported options.  The \emph{raison d'etre} for
%   such a system is given in \S\ref{sec:defaults}.
%
%   In \meta{node}, the standard node's content and possibly other options are specified, using the
%   usual bracket representation.  The \meta{node}, however, \emph{must not contain children}.  The
%   default: \texttt{[dj]}.
%
%   The \meta{environment fingerprint} must be an expandable macro definition.  It's expansion
%   should change whenever the calibration is necessary.
%
%   \meta{calibration procedure} is a keylist (processed in the |/forest| path) which calculates the
%   values of exported options.
%
%   \meta{exported options} is a comma-separated list of exported options.
%
%   This is how the default standard node is created:
% \begin{lstlisting}
%   \forestStandardNode[dj]
%     {%
%       \forestOve{\csname forest@id@of@standard node\endcsname}{content},%
%       \the\ht\strutbox,\the\pgflinewidth,%
%       \pgfkeysvalueof{/pgf/inner ysep},\pgfkeysvalueof{/pgf/outer ysep},%
%       \pgfkeysvalueof{/pgf/inner xsep},\pgfkeysvalueof{/pgf/outer xsep}%
%     }
%     {
%       l sep={\the\ht\strutbox+\pgfkeysvalueof{/pgf/inner ysep}},
%       l={l_sep()+abs(max_y()-min_y())+2*\pgfkeysvalueof{/pgf/outer ysep}},
%       s sep={2*\pgfkeysvalueof{/pgf/inner xsep}}
%     }
%     {l sep,l,s sep}
%   \end{lstlisting}
% \end{syntax}
%
% \subsection{Externalization}
% \label{ref:externalization}
%
% Externalized tree pictures are compiled only once. The result of the compilation is saved into a
% separate |.pdf| file and reused on subsequent compilations of the document.  If the code of the
% tree (or the context, see below) is changed, the tree is automatically recompiled.
%
% Externalization is enabled by:
% \begin{lstlisting}
%   \usepackage[~external~]{forest}
%   ~\tikzexternalize~
% \end{lstlisting}
% Both lines are necessary.  \TikZ;'s externalization library is automatically loaded if necessary.
%
% \begin{syntax}
% \rkeyname[item]{id={external/optimize}} Parallels \keyname{/tikz/external/optimize}: if |true| (the
% default), the processing of non-current trees is skipped during the embedded compilation.
% \rkeyname[item]{id={external/context}} If the expansion of the macro stored in
% this option changes, the tree is recompiled.
% \rkeyname[item]{id={external/depends on macro}}|=|\meta{cs} Adds the definition of macro \meta{cs} to
% \keyname{external/context}.  Thus, if the definition of \meta{cs} is changed, the tree will be
% recompiled. 
% \end{syntax}
%
% \foRest; respects or is compatible with several (not all) keys and commands of \TikZ;'s
% externalization library.  In particular, the following keys and commands might be useful; see
% \cite[\S32]{tikzpgf2.10}.
% \begin{itemize}
% \item\keyname{/tikz/external/remake next}
% \item\keyname{/tikz/external/prefix}
% \item\keyname{/tikz/external/system call}
% \item\cmdname{tikzexternalize}
% \item\cmdname{tikzexternalenable}
% \item\cmdname{tikzexternaldisable}
% \end{itemize}
% \FoRest; does not disturbe the externalization of non-\foRest; pictures. (At least it
% shouldn't \dots)
%
% The main auxiliary file for externalization has suffix |.for|.  The externalized pictures have
% suffices |-forest-|$n$ (their prefix can be set by \keyname{/tikz/external/prefix}, e.g.\ to a
% subdirectory).  Information on all trees that were ever externalized in the document (even if
% they were changed or deleted) is kept.  If you need a ``clean'' |.for| file, delete it and
% recompile.  Deleting |-forest-|$n$|.pdf| will result in recompilation of a specific tree.
%
% Using \keyname{draw tree} and \keyname{draw tree'} multiple times \emph{is} compatible with
% externalization, as is drawing the tree in the box (see \ikeyname{draw tree box}).  If you are
% trying to externalize a \ikeyname{forest} environment which utilizes \ikeyname{TeX} to produce a
% visible effect, you will probably need to use \ikeyname{TeX'} and/or \ikeyname{TeX''}.
% 
% \subsection{Package options}
% \label{ref:package-options}
%
% \begin{syntax}
% \rkeyname[item=false]{external}|=|\alternative{true,false}
%
% Enable/disable externalization, see \S\ref{ref:externalization}.
% \rkeyname[item=true]{tikzcshack}|=|\alternative{true,false}
%
% Enable/disable the hack into \TikZ;'s implicite coordinate syntax hacked, see
% \S\ref{ref:relative-node-names}.
%
% \rkeyname[item=true]{tikzinstallkeys}|=|\alternative{true,false}
%
% Install certain keys into the \keyname{/tikz} path.  Currently: \ikeyname{fit to tree}.
% \end{syntax}
%
% \section{Gallery}
% \label{sec:gallery}
%
%
% \subsection{Styles}
% \label{sec:gallery-styles}
%
% \paragraph{\rkeyname{GP1}}
% For Government Phonology (v1) representations. Here, the big trick
% is to evenly space $\times$s by having a large enough |outer_xsep|
% (adjustable), and then, before drawing (timing control option
% |before_drawing_tree|), setting |outer_xsep| back to 0pt.  The last step
% is important, otherwise the arrows between $\times$s won't draw!
%
% \box\GPone
%
% An example of an ``embedded'' |GP1| style:
% \begin{forestexample}[pos=b,ekeynames={where ,tier,for children,content,tikz,l,+,no edge}]
%   \begin{forest}
%     myGP1/.style={
%       ~GP1~,
%       delay={where tier={x}{
%           for children={content=\textipa{##1}}}{}},
%       tikz={\draw[dotted](.south)--
%             (!1.north west)--(!l.north east)--cycle;},
%       for children={l+=5mm,no edge}
%     }
%     [VP[DP[John,tier=word,myGP1
%             [O[x[dZ]]]
%             [R[N[x[6]]]]
%             [O[x[n]]]
%             [R[N[x]]]
%     ]][V'[V[loves,tier=word,myGP1
%              [O[x[l]]]
%              [R[N[x[a]]]]
%              [O[x[v]]]
%              [R[N[x]]]
%              [O[x[z]]]
%              [R[N[x]]]
%     ]][DP[Mary,tier=word,myGP1
%            [O[x[m]]]
%            [R[N[x[e]]]]
%            [O[x[r]]]
%            [R[N[x[i]]]]
%     ]]]]
%   \end{forest}%
% \end{forestexample}
%
% And an example of annotations.
% \begin{forestexample}
%   \begin{forest}[,phantom,s sep=1cm
%     [{[ei]}, GP1
%       [R[N[x[A,~el~[I,~head~,~associate=N~]]][x]]]
%     ]
%     [{[mars]}, GP1
%       [O[x[m]]]
%       [R[N[x[a]]][x,~encircle~,densely dotted[r]]]
%       [O[x,~encircle~,~govern=<~[s]]]
%       [R,~fen~[N[x]]]
%     ]
%   ]\end{forest} 
% \end{forestexample}
%
%
% \paragraph{rlap and llap}  The \foRest; versions of \TeX's \cmdname{rlap}\ and \cmdname{llap}: the
% ``content'' added by these styles will influence neither the packing algorithm nor the anchor
% positions. 
% \begin{forestexample}[pos=b,point={rlap,llap},ekeynames={TeX,delay,where ,tier,content,GP1}]
%   \forestset{
%     llap/.style={tikz+={
%         \edef\forest@temp{\noexpand\node[\forestoption{node options},
%           anchor=base east,at=(.base east)]}
%         \forest@temp{#1\phantom{\forestoption{content format}}};
%       }},
%     rlap/.style={tikz+={
%         \edef\forest@temp{\noexpand\node[\forestoption{node options},
%           anchor=base west,at=(.base west)]}
%         \forest@temp{\phantom{\forestoption{content format}}#1};
%       }}
%   }
%   \newcount\xcount
%   \begin{forest} GP1,
%     delay={
%       TeX={\xcount=0},
%       where tier={x}{TeX={\advance\xcount1},rlap/.expanded={$_{\the\xcount}$}}{}
%     }
%     [
%       [O[x[f]]]
%       [R[N[x[o]]]]
%       [O[x[r]]]
%       [R[N[x[e]]][x[s]]]
%       [O[x[t]]]
%       [R[N[x]]]
%     ]
%   \end{forest}
% \end{forestexample}
%
% \paragraph{xlist} This style makes it easy to put ``separate''
% trees in a picture and enumerate them.  For an example, see the |nice_empty_nodes|
% style.
% \begin{forestexample}[pos=t,label=ex:xlist]
%   \makeatletter
%   \forestset{
%     xlist/.style={
%       phantom,
%       for children={no edge,replace by={[,append,
%           delay={content/.wrap pgfmath arg={\@alph{##1}.}{n()+#1}}
%           ]}}
%     },
%     xlist/.default=0
%   }
%   \makeatother
% \end{forestexample}
% \input{\jobname.tmp}
% 
% \paragraph{nice empty nodes} 
% We often need empty nodes: tree (a) shows how they look like by
% default: ugly.
%
% First, we don't want the gaps: we change the shape of empty nodes to coordinate.  We get tree (b).
%
% Second, the empty nodes seem too close
% to the other (especially empty) nodes (this is a result of a small
% default |s_sep|).  We could use a greater \ikeyname{s sep}, but a better solution seems
% to be to use |calign=node_angle|.  The result is shown in (c). 
%
% However, at the transitions from empty to non-empty nodes, tree (d)
% above seems to zigzag (although the base points of the spine nodes
% are perfectly in line), and the edge to the empty node left to VP
% seems too long (it reaches to the level of VP's base, while we'd
% prefer it to stop at the same level as the edge to VP itself).  The
% first problem is solved by substituting |node_angle| for
% |edge_angle|; the second one, by anchoring siblings of
% empty nodes at north.
% \begin{forestexample}[pos=b,ekeynames={fixed angles,fixed edge angles,calign,for tree,delay,where
% ,content,for ,parent,for children,anchor}]
%   \forestset{
%     ~nice empty nodes~/.style={
%       for tree={calign=fixed edge angles},
%       delay={where content={}{shape=coordinate,for parent={for children={anchor=north}}}{}}
%     }}
%   \begin{forest}
%     [,~xlist~
%       [CP,                                                               %(a)
%         [][[][[][VP[DP[John]][V'[V[loves]][DP[Mary]]]]]]]
%       [CP, delay={where content={}{shape=coordinate}{}}                  %(b)
%         [][[][[][VP[DP[John]][V'[V[loves]][DP[Mary]]]]]]]
%       [CP, for tree={calign=fixed angles},                                 %(c)
%            delay={where content={}{shape=coordinate}{}}
%         [][[][[][VP[DP[John]][V'[V[loves]][DP[Mary]]]]]]]
%       [CP, ~nice empty nodes~                                              %(d)
%         [][[][[][VP[DP[John]][V'[V[loves]][DP[Mary]]]]]]]
%     ]
%   \end{forest}
% \end{forestexample}
%
%
% \subsection{Examples}
% \label{sec:examples}
%
% The following example was inspired by a question on \TeX\ Stackexchange:
% \href{http://tex.stackexchange.com/questions/39103/how-to-change-the-level-distance-in-tikz-qtree-for-one-level-only}{How to change the level distance in tikz-qtree for one level only?}.  The question is about |tikz-qtree|: how to adjust the level distance for the first level only, in order to avoid first-level labels crossing the parent--child edge.  While this example solves the problem (by manually shifting the offending labels; see \texttt{elo} below), it does more: the preamble is setup so that inputing the tree is very easy.
%
% \begin{forestexample}[pos=t,ekeynames={id={{if }},n,no edge,tikz,strequal,strcat,child anchor,parent
% anchor,anchor,calign,for tree,s sep,l,n children,declare toks,delay,content,before typesetting nodes,for descendants,+,{id=.wrap pgfmath arg,nfc},{id=.wrap 2 pgfmath args,nfc}}]
%   \def\getfirst#1;#2\endget{#1}
%   \def\getsecond#1;#2\endget{#2}
%   \forestset{declare toks={elo}{}} % edge label options
%   \begin{forest}
%     anchors/.style={anchor=#1,child anchor=#1,parent anchor=#1},
%     for tree={
%       s sep=0.5em,l=8ex,
%       if n children=0{anchors=north}{
%         if n=1{anchors=south east}{anchors=south west}},
%       content format={$\forestoption{content}$}
%     },
%     anchors=south, outer sep=2pt,
%     nomath/.style={content format=\forestoption{content}},
%     dot/.style={tikz+={\fill (.child anchor) circle[radius=#1];}},
%     dot/.default=2pt,
%     dot=3pt,for descendants=dot,
%     decision edge label/.style n args=3{
%       edge label/.expanded={node[midway,auto=#1,anchor=#2,\forestoption{elo}]{\strut$#3$}}
%     },
%     decision/.style={if n=1
%       {decision edge label={left}{east}{#1}}
%       {decision edge label={right}{west}{#1}}
%     },
%     delay={for descendants={
%         decision/.expanded/.wrap pgfmath arg={\getsecond#1\endget}{content},
%         content/.expanded/.wrap pgfmath arg={\getfirst#1\endget}{content},
%     }},
%     [N,nomath
%       [I;{p_1=0.5},nomath,elo={yshift=4pt}
%         [{5,1};a]
%         [II;b,nomath
%           [{1,2};m]
%           [{2,3};n]
%         ]
%       ]
%       [II;{p_2=0.5},nomath,elo={yshift=4pt}
%         [;c
%           [{1,0};z]
%           [{2,2};t]
%         ]
%         [;d
%           [{3,1};z]
%           [{0,0};t]
%         ]
%       ] {\draw[dashed](!1.anchor)--(!2.anchor) node[pos=0.5,above]{I};}
%     ]
%   \end{forest}
% \end{forestexample}
% 
%
% \section{Known bugs}
% \label{sec:bugs}
%
% If you find a bug (there are bound to be some \dots), please contact
% me at \href{mailto:saso.zivanovic@guest.arnes.si}{saso.zivanovic@guest.arnes.si}.
%
% \paragraph{System requirements} This package requires \LaTeX\ and e\TeX.  If you use something
% else: sorry.
%
% The requirement for \LaTeX\ might be dropped in the future, when I get some time and energy for a
% code-cleanup (read: to remedy the consequences of my bad programming practices and general
% disorganization).
%
% The requirement for e\TeX\ will probably stay.  If nothing else, \foRest; is heavy on boxes: every
% node requires its own \dots\ and consequently, I have freely used e\TeX\ constructs in the code
% \dots
%
% \paragraph{\PGF; internals} \FoRest; relies on some details of \PGF; implementation, like the name
% of the ``not yet positioned'' nodes.  Thus, a new bug might appear with the development of \PGF;.
% If you notice one, please let me know.
%
% \paragraph{Edges cutting through sibling nodes}
% \label{sec:cutting-edge}
%
% In the following example, the R--B edge crosses the AAA node, although \ikeyname{ignore edge} is
% set to the default |false|.
% \begin{forestexample}[ekeynames={calign,{first,aspect=calign},align,{center,aspect=align},base,{bottom,aspect=base}}]
%   \begin{forest}
%     calign=first
%     [R[AAAAAAAAAA\\AAAAAAAAAA\\AAAAAAAAAA,align=center,base=bottom][B]]
%   \end{forest}
% \end{forestexample}
% This happens because s-distances between the adjacent children are
% computed before child alignment  (which is obviously the correct order in the general case), but
% child alignment non-linearly influences the edges.  Observe that the with a different value of
% \ikeyname{calign}, the problem does not arise. 
% \begin{forestexample}[ekeynames={calign,{last,aspect=calign},align,{center,aspect=align},base,{bottom,aspect=base}}]
%   \begin{forest}
%     calign=last
%     [R[AAAAAAAAAA\\AAAAAAAAAA\\AAAAAAAAAA,align=center,base=bottom][B]]
%   \end{forest}
% \end{forestexample}
% While it would be possible to fix the situation after child alignment (at least for some child
% alignment methods), I have decided against that, since the distances between siblings would soon
% become too large.  If the AAA node in the example above was large enough, B could easily be pushed
% off the paper.  The bottomline is, please use manual adjustment to fix such situations. 
%
% \paragraph{Orphans}
% \label{sec:orphans}
%
% If the \ikeyname{l} coordinates of adjacent children are too different (as a result of manual adjustment or
% tier alignment), the packing algorithm might have nothing so say about the desired distance
% between them: in this sense, node C below is an ``orphan.'' 
% \begin{forestexample}[ekeynames={for tree,s sep,l,*}]
%   \begin{forest}
%     for tree={s sep=0,draw},
%     [R[A][B][C,l*=2][D][E]]
%   \end{forest}
% \end{forestexample}
% To prevent orphans from ending up just anywhere, I have decided to vertically align them with
% their preceding sibling --- although I'm not certain that's really the best solution.  In other
% words, you can rely that the sequence of s-coordinates of siblings is non-decreasing.
%
% The decision also incluences a similar situation, illustrated below.  The packing algorithm puts
% node E immediately next to B (i.e.\ under C): however, the monotonicity-retaining mechanism then
% vertically aligns it with its preceding sibling, D.
% \begin{forestexample}[ekeynames={for tree,s sep,tier}]
%   \begin{forest}
%     for tree={s sep=0,draw},
%     [R[A[B,tier=bottom]][C][D][E,tier=bottom]]
%   \end{forest}
% \end{forestexample}
%
% Obviously, both examples also create the situation of an edge crossing some sibling node(s).
% Again, I don't think anything sensible can be done about this, in general.
%
% \section{Changelog}
% 
% \begin{description}
% \item[v1.05 (2014/03/07)] \mbox{}
%   \begin{compactitem}
%   \item Fix the node boundary code for rounded rectangle.  (Patch contributed by Paul Gaborit.)
%   \end{compactitem}
% \item[v1.04 (2013/10/17)] \mbox{}
%   \begin{compactitem}
%   \item Fixed an \href{http://tex.stackexchange.com/questions/138986/error-using-tikzexternalize-with-forest/139145}{externalization bug}.
%   \end{compactitem}
% \item[v1.03 (2013/01/28)] \mbox{}
%   \begin{compactitem}
%   \item Bugfix: options of dynamically created nodes didn't get processed.
%   \item Bugfix: the bracket parser was losing spaces before opening braces.
%   \item Bugfix: a family of utility macros dealing with affixing token lists was not expanding
%     content correctly.
%   \item Added style \ikeyname{math content}.
%   \item Replace key \keyname{tikz preamble} with more general \ikeyname{begin draw} and
%     \ikeyname{end draw}.
%   \item Add keys \ikeyname{begin forest} and \ikeyname{end forest}.
%   \end{compactitem}
% \item[v1.02 (2013/01/20)] \mbox{}
%   \begin{compactitem}
%   \item Reworked style \ikeyname{stages}: it's easier to modify the processing flow now.
%   \item Individual stages must now be explicitely called in the context of some (usually root)
%     node. 
%   \item Added \ikeyname{delay n} and \ikeyname{if have delayed}.
%   \item Added (experimental) \ikeyname{pack'}.
%   \item Added reference to the \href{https://github.com/sasozivanovic/forest-styles}{style
%     repository}.
%   \end{compactitem}
% \item[v1.01 (2012/11/14)] \mbox{}
% 
%   \begin{compactitem}
%   \item Compatibility with the |standalone| package: temporarily disable the effect of
%     |standalone|'s package option |tikz| while typesetting nodes.
%   \item Require at least the [2010/08/21] (v2.0) release of package |etoolbox|.
%   \item Require version [2010/10/13] (v2.10, rcs-revision 1.76) of \PGF;/\TikZ;.  Future
%     compatibility: adjust to the change of the ``not yet positioned'' node name (2.10 |@|
%     $\rightarrow$ 2.10-csv |PGFINTERNAL|).
%   \item Add this changelog.
%   \end{compactitem}
% \item[v1.0 (2012/10/31)] First public version
% \end{description}
%
% \paragraph{Acknowledgements} Many thanks to the people who have reported bugs! In the
% chronological order: Markus P\"ochtrager, Timothy Dozat, Ignasi Furio.\footnote{If you're in the
% list but don't want to be, my apologies and please let me know about it!}
%
% \newpage
% \part{Implementation}
%
% A disclaimer: the code could've been much cleaner and better-documented \dots
% 
% Identification.
%    \begin{macrocode}
\ProvidesPackage{forest}[2014/03/07 v1.05 Drawing (linguistic) trees]

\RequirePackage{tikz}[2010/10/13]
\usetikzlibrary{shapes}
\usetikzlibrary{fit}
\usetikzlibrary{calc}
\usepgflibrary{intersections}

\RequirePackage{pgfopts}
\RequirePackage{etoolbox}[2010/08/21]
\RequirePackage{environ}

 %\usepackage[trace]{trace-pgfkeys}
%    \end{macrocode}
%
% |/forest| is the root of the key hierarchy.
%    \begin{macrocode}
\pgfkeys{/forest/.is family}
\def\forestset#1{\pgfqkeys{/forest}{#1}}
%    \end{macrocode}
%
% \section{Patches}
% These patches apply to pgf/tikz 2.10.
% 
% Serious: forest cannot load if this is not patched; disable
% \texttt{/handlers/.wrap n pgfmath} for n=6,7,8 if you cannot patch.
%    \begin{macrocode}
\long\def\forest@original@pgfkeysdefnargs@#1#2#3#4{%
  \ifcase#2\relax
	  \pgfkeyssetvalue{#1/.@args}{}%
  \or
	  \pgfkeyssetvalue{#1/.@args}{##1}%
  \or
	  \pgfkeyssetvalue{#1/.@args}{##1##2}%
  \or
	  \pgfkeyssetvalue{#1/.@args}{##1##2##3}%
  \or
	  \pgfkeyssetvalue{#1/.@args}{##1##2##3##4}%
  \or
	  \pgfkeyssetvalue{#1/.@args}{##1##2##3##4##5}%
  \or
	  \pgfkeyssetvalue{#1/.@args}{##1##2##3##4##5##6}%
  \or
	  \pgfkeyssetvalue{#1/.@args}{##1##2##3##4##5##6}%
  \or
	  \pgfkeyssetvalue{#1/.@args}{##1##2##3##4##5##6##7}%
  \or
	  \pgfkeyssetvalue{#1/.@args}{##1##2##3##4##5##6##7##8}%
  \or
	  \pgfkeyssetvalue{#1/.@args}{##1##2##3##4##5##6##7##8##9}%
  \else
	  \pgfkeys@error{\string\pgfkeysdefnargs: expected  <= 9 arguments, got #2}%
  \fi
  \pgfkeysgetvalue{#1/.@args}\pgfkeys@tempargs
  \def\pgfkeys@temp{\expandafter#4\csname pgfk@#1/.@@body\endcsname}%
  \expandafter\pgfkeys@temp\pgfkeys@tempargs{#3}%
  % eliminate the \pgfeov at the end such that TeX gobbles spaces
  % by using
  % \pgfkeysdef{#1}{\pgfkeysvalueof{#1/.@@body}##1}
  % (with expansion of '#1'):
  \edef\pgfkeys@tempargs{\noexpand\pgfkeysvalueof{#1/.@@body}}%
  \def\pgfkeys@temp{\pgfkeysdef{#1}}%
  \expandafter\pgfkeys@temp\expandafter{\pgfkeys@tempargs##1}%
  \pgfkeyssetvalue{#1/.@body}{#3}%
}

\long\def\forest@patched@pgfkeysdefnargs@#1#2#3#4{%
  \ifcase#2\relax
	  \pgfkeyssetvalue{#1/.@args}{}%
  \or
	  \pgfkeyssetvalue{#1/.@args}{##1}%
  \or
	  \pgfkeyssetvalue{#1/.@args}{##1##2}%
  \or
	  \pgfkeyssetvalue{#1/.@args}{##1##2##3}%
  \or
	  \pgfkeyssetvalue{#1/.@args}{##1##2##3##4}%
  \or
	  \pgfkeyssetvalue{#1/.@args}{##1##2##3##4##5}%
  \or
	  \pgfkeyssetvalue{#1/.@args}{##1##2##3##4##5##6}%
  %%%%% removed:
  %%%%% \or
  %%%%% \pgfkeyssetvalue{#1/.@args}{##1##2##3##4##5##6}%
  \or
	  \pgfkeyssetvalue{#1/.@args}{##1##2##3##4##5##6##7}%
  \or
	  \pgfkeyssetvalue{#1/.@args}{##1##2##3##4##5##6##7##8}%
  \or
	  \pgfkeyssetvalue{#1/.@args}{##1##2##3##4##5##6##7##8##9}%
  \else
	  \pgfkeys@error{\string\pgfkeysdefnargs: expected  <= 9 arguments, got #2}%
  \fi
  \pgfkeysgetvalue{#1/.@args}\pgfkeys@tempargs
  \def\pgfkeys@temp{\expandafter#4\csname pgfk@#1/.@@body\endcsname}%
  \expandafter\pgfkeys@temp\pgfkeys@tempargs{#3}%
  % eliminate the \pgfeov at the end such that TeX gobbles spaces
  % by using
  % \pgfkeysdef{#1}{\pgfkeysvalueof{#1/.@@body}##1}
  % (with expansion of '#1'):
  \edef\pgfkeys@tempargs{\noexpand\pgfkeysvalueof{#1/.@@body}}%
  \def\pgfkeys@temp{\pgfkeysdef{#1}}%
  \expandafter\pgfkeys@temp\expandafter{\pgfkeys@tempargs##1}%
  \pgfkeyssetvalue{#1/.@body}{#3}%
}
\ifx\pgfkeysdefnargs@\forest@original@pgfkeysdefnargs@
  \let\pgfkeysdefnargs@\forest@patched@pgfkeysdefnargs@
\fi
%    \end{macrocode}
%
% Minor: a leaking space in the very first line.
%    \begin{macrocode}
\def\forest@original@pgfpointintersectionoflines#1#2#3#4{%
  {
    % 
    % Compute orthogonal vector to #1--#2
    % 
    \pgf@process{#2}%
    \pgf@xa=\pgf@x%
    \pgf@ya=\pgf@y%
    \pgf@process{#1}%
    \advance\pgf@xa by-\pgf@x%
    \advance\pgf@ya by-\pgf@y%
    \pgf@ya=-\pgf@ya%
    % Normalise a bit
    \c@pgf@counta=\pgf@xa%
    \ifnum\c@pgf@counta<0\relax%
      \c@pgf@counta=-\c@pgf@counta\relax%
    \fi%
    \c@pgf@countb=\pgf@ya%
    \ifnum\c@pgf@countb<0\relax%
      \c@pgf@countb=-\c@pgf@countb\relax%
    \fi%
    \advance\c@pgf@counta by\c@pgf@countb\relax%
    \divide\c@pgf@counta by 65536\relax%
    \ifnum\c@pgf@counta>0\relax%
      \divide\pgf@xa by\c@pgf@counta\relax%
      \divide\pgf@ya by\c@pgf@counta\relax%
    \fi%
    %
    % Compute projection
    %
    \pgf@xc=\pgf@sys@tonumber{\pgf@ya}\pgf@x%
    \advance\pgf@xc by\pgf@sys@tonumber{\pgf@xa}\pgf@y%
    % 
    % The orthogonal vector is (\pgf@ya,\pgf@xa)
    % 
    % 
    % Compute orthogonal vector to #3--#4
    % 
    \pgf@process{#4}%
    \pgf@xb=\pgf@x%
    \pgf@yb=\pgf@y%
    \pgf@process{#3}%
    \advance\pgf@xb by-\pgf@x%
    \advance\pgf@yb by-\pgf@y%
    \pgf@yb=-\pgf@yb%
    % Normalise a bit
    \c@pgf@counta=\pgf@xb%
    \ifnum\c@pgf@counta<0\relax%
      \c@pgf@counta=-\c@pgf@counta\relax%
    \fi%
    \c@pgf@countb=\pgf@yb%
    \ifnum\c@pgf@countb<0\relax%
      \c@pgf@countb=-\c@pgf@countb\relax%
    \fi%
    \advance\c@pgf@counta by\c@pgf@countb\relax%
    \divide\c@pgf@counta by 65536\relax%
    \ifnum\c@pgf@counta>0\relax%
      \divide\pgf@xb by\c@pgf@counta\relax%
      \divide\pgf@yb by\c@pgf@counta\relax%
    \fi%
    %
    % Compute projection
    %
    \pgf@yc=\pgf@sys@tonumber{\pgf@yb}\pgf@x%
    \advance\pgf@yc by\pgf@sys@tonumber{\pgf@xb}\pgf@y%
    % 
    % The orthogonal vector is (\pgf@yb,\pgf@xb)
    % 
    % Setup transformation matrx (this is just to use the matrix
    % inversion)
    % 
    \pgfsettransform{{\pgf@sys@tonumber\pgf@ya}{\pgf@sys@tonumber\pgf@yb}{\pgf@sys@tonumber\pgf@xa}{\pgf@sys@tonumber\pgf@xb}{0pt}{0pt}}%
    \pgftransforminvert%
    \pgf@process{\pgfpointtransformed{\pgfpoint{\pgf@xc}{\pgf@yc}}}%
  }%
}
\def\forest@patched@pgfpointintersectionoflines#1#2#3#4{%
  {% added the percent sign in this line
    % 
    % Compute orthogonal vector to #1--#2
    % 
    \pgf@process{#2}%
    \pgf@xa=\pgf@x%
    \pgf@ya=\pgf@y%
    \pgf@process{#1}%
    \advance\pgf@xa by-\pgf@x%
    \advance\pgf@ya by-\pgf@y%
    \pgf@ya=-\pgf@ya%
    % Normalise a bit
    \c@pgf@counta=\pgf@xa%
    \ifnum\c@pgf@counta<0\relax%
      \c@pgf@counta=-\c@pgf@counta\relax%
    \fi%
    \c@pgf@countb=\pgf@ya%
    \ifnum\c@pgf@countb<0\relax%
      \c@pgf@countb=-\c@pgf@countb\relax%
    \fi%
    \advance\c@pgf@counta by\c@pgf@countb\relax%
    \divide\c@pgf@counta by 65536\relax%
    \ifnum\c@pgf@counta>0\relax%
      \divide\pgf@xa by\c@pgf@counta\relax%
      \divide\pgf@ya by\c@pgf@counta\relax%
    \fi%
    %
    % Compute projection
    %
    \pgf@xc=\pgf@sys@tonumber{\pgf@ya}\pgf@x%
    \advance\pgf@xc by\pgf@sys@tonumber{\pgf@xa}\pgf@y%
    % 
    % The orthogonal vector is (\pgf@ya,\pgf@xa)
    % 
    % 
    % Compute orthogonal vector to #3--#4
    % 
    \pgf@process{#4}%
    \pgf@xb=\pgf@x%
    \pgf@yb=\pgf@y%
    \pgf@process{#3}%
    \advance\pgf@xb by-\pgf@x%
    \advance\pgf@yb by-\pgf@y%
    \pgf@yb=-\pgf@yb%
    % Normalise a bit
    \c@pgf@counta=\pgf@xb%
    \ifnum\c@pgf@counta<0\relax%
      \c@pgf@counta=-\c@pgf@counta\relax%
    \fi%
    \c@pgf@countb=\pgf@yb%
    \ifnum\c@pgf@countb<0\relax%
      \c@pgf@countb=-\c@pgf@countb\relax%
    \fi%
    \advance\c@pgf@counta by\c@pgf@countb\relax%
    \divide\c@pgf@counta by 65536\relax%
    \ifnum\c@pgf@counta>0\relax%
      \divide\pgf@xb by\c@pgf@counta\relax%
      \divide\pgf@yb by\c@pgf@counta\relax%
    \fi%
    %
    % Compute projection
    %
    \pgf@yc=\pgf@sys@tonumber{\pgf@yb}\pgf@x%
    \advance\pgf@yc by\pgf@sys@tonumber{\pgf@xb}\pgf@y%
    % 
    % The orthogonal vector is (\pgf@yb,\pgf@xb)
    % 
    % Setup transformation matrx (this is just to use the matrix
    % inversion)
    % 
    \pgfsettransform{{\pgf@sys@tonumber\pgf@ya}{\pgf@sys@tonumber\pgf@yb}{\pgf@sys@tonumber\pgf@xa}{\pgf@sys@tonumber\pgf@xb}{0pt}{0pt}}%
    \pgftransforminvert%
    \pgf@process{\pgfpointtransformed{\pgfpoint{\pgf@xc}{\pgf@yc}}}%
  }%
}

\ifx\pgfpointintersectionoflines\forest@original@pgfpointintersectionoflines
  \let\pgfpointintersectionoflines\forest@patched@pgfpointintersectionoflines
\fi

 % hah: hacking forest --- it depends on some details of PGF implementation
\def\forest@pgf@notyetpositioned{not yet positionedPGFINTERNAL}%
\expandafter\ifstrequal\expandafter{\pgfversion}{2.10}{%
  \def\forest@pgf@notyetpositioned{not yet positioned@}%
}{}
%    \end{macrocode}
% 
% \section{Utilities}
%
% Escaping |\if|s.
%    \begin{macrocode}
\long\def\@escapeif#1#2\fi{\fi#1}
\long\def\@escapeifif#1#2\fi#3\fi{\fi\fi#1}
%    \end{macrocode}
% 
% A factory for creating |\...loop...| macros.
%    \begin{macrocode}
\def\newloop#1{%
  \count@=\escapechar
  \escapechar=-1
  \expandafter\newloop@parse@loopname\string#1\newloop@end
  \escapechar=\count@
}%
{\lccode`7=`l \lccode`8=`o \lccode`9=`p
  \lowercase{\gdef\newloop@parse@loopname#17889#2\newloop@end{%
      \edef\newloop@marshal{%
        \noexpand\csdef{#1loop#2}####1\expandafter\noexpand\csname #1repeat#2\endcsname{%
          \noexpand\csdef{#1iterate#2}{####1\relax\noexpand\expandafter\expandafter\noexpand\csname#1iterate#2\endcsname\noexpand\fi}%
          \expandafter\noexpand\csname#1iterate#2\endcsname
          \let\expandafter\noexpand\csname#1iterate#2\endcsname\relax
        }%
      }%
      \newloop@marshal
    }%
  }%
}%
%    \end{macrocode}
%    
% Additional loops (for embedding).
%    \begin{macrocode}
\newloop\forest@loop
\newloop\forest@loopa
\newloop\forest@loopb
\newloop\forest@loopc
\newloop\forest@sort@loop
\newloop\forest@sort@loopA
%    \end{macrocode}
% New counters, dimens, ifs.
%    \begin{macrocode}
\newdimen\forest@temp@dimen
\newcount\forest@temp@count
\newcount\forest@n
\newif\ifforest@temp
\newcount\forest@temp@global@count
%    \end{macrocode}
%
% Appending and prepending to token lists.
%    \begin{macrocode}
\def\apptotoks#1#2{\expandafter#1\expandafter{\the#1#2}}
\long\def\lapptotoks#1#2{\expandafter#1\expandafter{\the#1#2}}
\def\eapptotoks#1#2{\edef\pot@temp{#2}\expandafter\expandafter\expandafter#1\expandafter\expandafter\expandafter{\expandafter\the\expandafter#1\pot@temp}}
\def\pretotoks#1#2{\toks@={#2}\expandafter\expandafter\expandafter#1\expandafter\expandafter\expandafter{\expandafter\the\expandafter\toks@\the#1}}
\def\epretotoks#1#2{\edef\pot@temp{#2}\expandafter\expandafter\expandafter#1\expandafter\expandafter\expandafter{\expandafter\pot@temp\the#1}}
\def\gapptotoks#1#2{\expandafter\global\expandafter#1\expandafter{\the#1#2}}
\def\xapptotoks#1#2{\edef\pot@temp{#2}\expandafter\expandafter\expandafter\global\expandafter\expandafter\expandafter#1\expandafter\expandafter\expandafter{\expandafter\the\expandafter#1\pot@temp}}
\def\gpretotoks#1#2{\toks@={#2}\expandafter\expandafter\expandafter\global\expandafter\expandafter\expandafter#1\expandafter\expandafter\expandafter{\expandafter\the\expandafter\toks@\the#1}}
\def\xpretotoks#1#2{\edef\pot@temp{#2}\expandafter\expandafter\expandafter\global\expandafter\expandafter\expandafter#1\expandafter\expandafter\expandafter{\expandafter\pot@temp\the#1}}
%    \end{macrocode}
%    
% Expanding number arguments.
%    \begin{macrocode}
\def\expandnumberarg#1#2{\expandafter#1\expandafter{\number#2}}
\def\expandtwonumberargs#1#2#3{%
  \expandafter\expandtwonumberargs@\expandafter#1\expandafter{\number#3}{#2}}
\def\expandtwonumberargs@#1#2#3{%
  \expandafter#1\expandafter{\number#3}{#2}}
\def\expandthreenumberargs#1#2#3#4{%
  \expandafter\expandthreenumberargs@\expandafter#1\expandafter{\number#4}{#2}{#3}}
\def\expandthreenumberargs@#1#2#3#4{%
  \expandafter\expandthreenumberargs@@\expandafter#1\expandafter{\number#4}{#2}{#3}}
\def\expandthreenumberargs@@#1#2#3#4{%
  \expandafter#1\expandafter{\number#4}{#2}{#3}}
%    \end{macrocode}
%
% A macro converting all non-letters in a string to |__|.  |#1| =
% string, |#2| = receiving macro.  Used for declaring pgfmath
% functions. 
%    \begin{macrocode}
\def\forest@convert@others@to@underscores#1#2{%
  \def\forest@cotu@result{}%
  \forest@cotu#1\forest@end
  \let#2\forest@cotu@result
}
\def\forest@cotu{%
  \futurelet\forest@cotu@nextchar\forest@cotu@checkforspace
}
\def\forest@cotu@checkforspace{%
  \expandafter\ifx\space\forest@cotu@nextchar
    \let\forest@cotu@next\forest@cotu@havespace
  \else
    \let\forest@cotu@next\forest@cotu@nospace
  \fi
  \forest@cotu@next
}
\def\forest@cotu@havespace#1{%
  \appto\forest@cotu@result{_}%
  \forest@cotu#1%
}
\def\forest@cotu@nospace{%
  \ifx\forest@cotu@nextchar\forest@end
    \@escapeif\@gobble
  \else
    \@escapeif\forest@cotu@nospaceB
  \fi
}
\def\forest@cotu@nospaceB{%
  \ifcat\forest@cotu@nextchar a%
    \let\forest@cotu@next\forest@cotu@have@alphanum
  \else
    \ifcat\forest@cotu@nextchar 0%
      \let\forest@cotu@next\forest@cotu@have@alphanum
    \else
      \let\forest@cotu@next\forest@cotu@haveother
    \fi
  \fi
  \forest@cotu@next
}
\def\forest@cotu@have@alphanum#1{%
  \appto\forest@cotu@result{#1}%
  \forest@cotu
}
\def\forest@cotu@haveother#1{%
  \appto\forest@cotu@result{_}%
  \forest@cotu
}
%    \end{macrocode}
%
% Additional list macros.
%    \begin{macrocode}
\def\forest@listedel#1#2{% #1 = list, #2 = item
  \edef\forest@marshal{\noexpand\forest@listdel\noexpand#1{#2}}%
  \forest@marshal
}
\def\forest@listcsdel#1#2{%
  \expandafter\forest@listdel\csname #1\endcsname{#2}%
}
\def\forest@listcsedel#1#2{%
  \expandafter\forest@listedel\csname #1\endcsname{#2}%
}
\edef\forest@restorelistsepcatcode{\noexpand\catcode`|\the\catcode`|\relax}%
\catcode`\|=3
\gdef\forest@listdel#1#2{%
  \def\forest@listedel@A##1|#2|##2\forest@END{%
    \forest@listedel@B##1|##2\forest@END%|
  }%
  \def\forest@listedel@B|##1\forest@END{%|
    \def#1{##1}%
  }%
  \expandafter\forest@listedel@A\expandafter|#1\forest@END%|
}
\forest@restorelistsepcatcode
%    \end{macrocode}
%
% Strip (the first level of) braces from all the tokens in the argument.
%    \begin{macrocode}
\def\forest@strip@braces#1{%
  \forest@strip@braces@A#1\forest@strip@braces@preend\forest@strip@braces@end
}
\def\forest@strip@braces@A#1#2\forest@strip@braces@end{%
  #1\ifx\forest@strip@braces@preend#2\else\@escapeif{\forest@strip@braces@A#2\forest@strip@braces@end}\fi
}
%    \end{macrocode}
%
% \subsection{Sorting}
%
% Macro |\forest@sort| is the user interface to sorting.
%
% The user should prepare the data in an arbitrarily encoded
% array,\footnote{In forest, arrays are encoded as families of
% macros. An array-macro name consists of the (optional, but
% recommended) prefix, the index, and the (optional) suffix (e.g.\
% \texttt{$\backslash$forest@42x}). Prefix establishes the ``namespace'',
% while using more than one suffix simulates an array of named tuples.
% The length of the array is stored in macro \texttt{$\backslash$<prefix>n}.}
% and provide the sorting macro (given in |#1|) and the array let
% macro (given in |#2|): these are the only ways in which sorting
% algorithms access the data.  Both user-given macros should take two
% parameters, which expand to array indices.  The comparison macro
% should compare the given array items and call |\forest@sort@cmp@gt|,
% |\forest@sort@cmp@lt| or |\forest@sort@cmp@eq| to signal that the
% first item is greater than, less than, or equal to the second item.
% The let macro should ``copy'' the contents of the second item onto
% the first item.
% 
% The sorting direction is be given in |#3|: it can one of
% |\forest@sort@ascending| and |\forest@sort@descending|.  |#4| and
% |#5| must expand to the lower and upper (both inclusive) indices of
% the array to be sorted.
%
% |\forest@sort| is just a wrapper for the central sorting macro
% |\forest@@sort|, storing the comparison macro, the array let macro
% and the direction.  The central sorting macro and the
% algorithm-specific macros take only two arguments: the array bounds.
%    \begin{macrocode}
\def\forest@sort#1#2#3#4#5{%
  \let\forest@sort@cmp#1\relax
  \let\forest@sort@let#2\relax
  \let\forest@sort@direction#3\relax
  \forest@@sort{#4}{#5}%
}
%    \end{macrocode}
% The central sorting macro.  Here it is decided which sorting
% algorithm will be used: for arrays at least
% |\forest@quicksort@minarraylength| long, quicksort is used;
% otherwise, insertion sort.
%    \begin{macrocode}
\def\forest@quicksort@minarraylength{10000}
\def\forest@@sort#1#2{%
  \ifnum#1<#2\relax\@escapeif{%
    \forest@sort@m=#2
    \advance\forest@sort@m -#1
    \ifnum\forest@sort@m>\forest@quicksort@minarraylength\relax\@escapeif{%
      \forest@quicksort{#1}{#2}%
    }\else\@escapeif{%
      \forest@insertionsort{#1}{#2}%
    }\fi
  }\fi
}
%    \end{macrocode}
% Various counters and macros needed by the sorting algorithms.
%    \begin{macrocode}
\newcount\forest@sort@m\newcount\forest@sort@k\newcount\forest@sort@p
\def\forest@sort@ascending{>}
\def\forest@sort@descending{<}
\def\forest@sort@cmp{%
  \PackageError{sort}{You must define forest@sort@cmp function before calling
    sort}{The macro must take two arguments, indices of the array
    elements to be compared, and return '=' if the elements are equal
    and '>'/'<' if the first is greater /less than the secong element.}%
}
\def\forest@sort@cmp@gt{\def\forest@sort@cmp@result{>}}
\def\forest@sort@cmp@lt{\def\forest@sort@cmp@result{<}}
\def\forest@sort@cmp@eq{\def\forest@sort@cmp@result{=}}
\def\forest@sort@let{%
  \PackageError{sort}{You must define forest@sort@let function before calling
    sort}{The macro must take two arguments, indices of the array:
    element 2 must be copied onto element 1.}%
}
%    \end{macrocode}
% Quick sort macro (adapted from
% \href{http://www.ctan.org/pkg/laansort}{laansort}).
%    \begin{macrocode}
\def\forest@quicksort#1#2{%
%    \end{macrocode}
% Compute the index of the middle element (|\forest@sort@m|).
%    \begin{macrocode}
  \forest@sort@m=#2
  \advance\forest@sort@m -#1
  \ifodd\forest@sort@m\relax\advance\forest@sort@m1 \fi
  \divide\forest@sort@m 2
  \advance\forest@sort@m #1
%    \end{macrocode}
% The pivot element is the median of the first, the middle and the
% last element.
%    \begin{macrocode}
  \forest@sort@cmp{#1}{#2}%
  \if\forest@sort@cmp@result=%
    \forest@sort@p=#1
  \else
    \if\forest@sort@cmp@result>%
      \forest@sort@p=#1\relax
    \else
      \forest@sort@p=#2\relax
    \fi
    \forest@sort@cmp{\the\forest@sort@p}{\the\forest@sort@m}%
    \if\forest@sort@cmp@result<%
    \else
      \forest@sort@p=\the\forest@sort@m
    \fi    
  \fi
%    \end{macrocode}
% Exchange the pivot and the first element.
%    \begin{macrocode}
  \forest@sort@xch{#1}{\the\forest@sort@p}%
%    \end{macrocode}
% Counter |\forest@sort@m| will hold the final location of the pivot
% element.
%    \begin{macrocode}
  \forest@sort@m=#1\relax
%    \end{macrocode}
% Loop through the list.
%    \begin{macrocode}
  \forest@sort@k=#1\relax
  \forest@sort@loop
  \ifnum\forest@sort@k<#2\relax
    \advance\forest@sort@k 1
%    \end{macrocode}
% Compare the pivot and the current element.
%    \begin{macrocode}
    \forest@sort@cmp{#1}{\the\forest@sort@k}%
%    \end{macrocode}
% If the current element is smaller (ascending) or greater
% (descending) than the pivot element, move it into the first part of
% the list, and adjust the final location of the pivot.
%    \begin{macrocode}
    \ifx\forest@sort@direction\forest@sort@cmp@result
      \advance\forest@sort@m 1
      \forest@sort@xch{\the\forest@sort@m}{\the\forest@sort@k}
    \fi
  \forest@sort@repeat
%    \end{macrocode}
% Move the pivot element into its final position.
%    \begin{macrocode}
  \forest@sort@xch{#1}{\the\forest@sort@m}%
%    \end{macrocode}
% Recursively call sort on the two parts of the list: elements before
% the pivot are smaller (ascending order) / greater (descending order)
% than the pivot; elements after the pivot are greater (ascending
% order) / smaller (descending order) than the pivot.
%    \begin{macrocode}
  \forest@sort@k=\forest@sort@m
  \advance\forest@sort@k -1
  \advance\forest@sort@m 1
  \edef\forest@sort@marshal{%
    \noexpand\forest@@sort{#1}{\the\forest@sort@k}%
    \noexpand\forest@@sort{\the\forest@sort@m}{#2}%
  }%
  \forest@sort@marshal
}
% We defines the item-exchange macro in terms of the (user-provided)
% array let macro.
%    \begin{macrocode}
\def\forest@sort@xch#1#2{%
  \forest@sort@let{aux}{#1}%
  \forest@sort@let{#1}{#2}%
  \forest@sort@let{#2}{aux}%
}
%    \end{macrocode}
% Insertion sort.
%    \begin{macrocode}
\def\forest@insertionsort#1#2{%
  \forest@sort@m=#1
  \edef\forest@insertionsort@low{#1}%
  \forest@sort@loopA
  \ifnum\forest@sort@m<#2
    \advance\forest@sort@m 1
    \forest@insertionsort@Qbody
  \forest@sort@repeatA
}
\newif\ifforest@insertionsort@loop
\def\forest@insertionsort@Qbody{%
  \forest@sort@let{aux}{\the\forest@sort@m}%  
  \forest@sort@k\forest@sort@m
  \advance\forest@sort@k -1
  \forest@insertionsort@looptrue
  \forest@sort@loop
  \ifforest@insertionsort@loop
    \forest@insertionsort@qbody
  \forest@sort@repeat
  \advance\forest@sort@k 1
  \forest@sort@let{\the\forest@sort@k}{aux}%
}
\def\forest@insertionsort@qbody{%
  \forest@sort@cmp{\the\forest@sort@k}{aux}%
  \ifx\forest@sort@direction\forest@sort@cmp@result\relax
    \forest@sort@p=\forest@sort@k
    \advance\forest@sort@p 1
    \forest@sort@let{\the\forest@sort@p}{\the\forest@sort@k}%
    \advance\forest@sort@k -1
    \ifnum\forest@sort@k<\forest@insertionsort@low\relax
      \forest@insertionsort@loopfalse
    \fi
  \else
    \forest@insertionsort@loopfalse
  \fi
}
%    \end{macrocode}
%
% Below, several helpers for writing comparison macros are
% provided. They take take two (pairs of) control sequence names and
% compare their contents.
% 
% Compare numbers.
%    \begin{macrocode}
\def\forest@sort@cmpnumcs#1#2{%
  \ifnum\csname#1\endcsname>\csname#2\endcsname\relax
   \forest@sort@cmp@gt
 \else
   \ifnum\csname#1\endcsname<\csname#2\endcsname\relax
     \forest@sort@cmp@lt
   \else
     \forest@sort@cmp@eq
   \fi
 \fi
}
%    \end{macrocode}
% Compare dimensions.
%    \begin{macrocode}
\def\forest@sort@cmpdimcs#1#2{%
  \ifdim\csname#1\endcsname>\csname#2\endcsname\relax
   \forest@sort@cmp@gt
 \else
   \ifdim\csname#1\endcsname<\csname#2\endcsname\relax
     \forest@sort@cmp@lt
   \else
     \forest@sort@cmp@eq
   \fi
 \fi
}
%    \end{macrocode}
% Compare points (pairs of dimension) |(#1,#2)| and |(#3,#4)|.
%    \begin{macrocode}
\def\forest@sort@cmptwodimcs#1#2#3#4{%
  \ifdim\csname#1\endcsname>\csname#3\endcsname\relax
   \forest@sort@cmp@gt
 \else
   \ifdim\csname#1\endcsname<\csname#3\endcsname\relax
     \forest@sort@cmp@lt
   \else
     \ifdim\csname#2\endcsname>\csname#4\endcsname\relax
       \forest@sort@cmp@gt
     \else
       \ifdim\csname#2\endcsname<\csname#4\endcsname\relax
         \forest@sort@cmp@lt
       \else
         \forest@sort@cmp@eq
       \fi
     \fi
   \fi
 \fi  
}
%    \end{macrocode}
%    
% The following macro reverses an array. The arguments: |#1| is
% the array let macro; |#2| is the start index (inclusive), and
% |#3| is the end index (exclusive).
%    \begin{macrocode}
\def\forest@reversearray#1#2#3{%
  \let\forest@sort@let#1%
  \c@pgf@countc=#2
  \c@pgf@countd=#3
  \advance\c@pgf@countd -1
  \forest@loopa
  \ifnum\c@pgf@countc<\c@pgf@countd\relax
    \forest@sort@xch{\the\c@pgf@countc}{\the\c@pgf@countd}%
    \advance\c@pgf@countc 1
    \advance\c@pgf@countd -1
  \forest@repeata
}
%    \end{macrocode}
%
% \section{The bracket representation parser}
% \label{imp:bracket}
%
% \subsection{The user interface macros}
%
% Settings.
%    \begin{macrocode}
\def\bracketset#1{\pgfqkeys{/bracket}{#1}}%
\bracketset{%
  /bracket/.is family,
  /handlers/.let/.style={\pgfkeyscurrentpath/.code={\let#1##1}},
  opening bracket/.let=\bracket@openingBracket,
  closing bracket/.let=\bracket@closingBracket,
  action character/.let=\bracket@actionCharacter,
  opening bracket=[,
  closing bracket=],
  action character,
  new node/.code n args={3}{% #1=preamble, #2=node spec, #3=cs receiving the id
    \forest@node@new#3%
    \forestOset{#3}{given options}{content'=#2}%
    \ifblank{#1}{}{%
      \forestOpreto{#3}{given options}{#1,}%
    }%
  },
  set afterthought/.code 2 args={% #1=node id, #2=afterthought
    \ifblank{#2}{}{\forestOappto{#1}{given options}{,afterthought={#2}}}%
  }
}
%    \end{macrocode}
%
% |\bracketParse| is the macro that should be called to parse a
% balanced bracket representation.  It takes five parameters: |#1| is the code that will be run
% after parsing the bracket; |#2| is a control sequence that will receive the id of the root of the
% created tree structure. (The bracket representation should follow (after optional spaces), but is
% is not a formal parameter of the macro.)
%    \begin{macrocode}
\newtoks\bracket@content
\newtoks\bracket@afterthought
\def\bracketParse#1#2={%
  \def\bracketEndParsingHook{#1}%
  \def\bracket@saveRootNodeTo{#2}%
%    \end{macrocode}
% Content and afterthought will be appended to these macros.  (The |\bracket@afterthought| toks register is
% abused for storing the preamble as well --- that's ok, the preamble comes before any afterhoughts.)
%    \begin{macrocode}
  \bracket@content={}%
  \bracket@afterthought={}%
%    \end{macrocode}
% The parser can be in three states: in content (0), in afterthought
% (1), or starting (2).  While in the content/afterthought state, the
% parser appends all non-control tokens to the content/afterthought macro.
%    \begin{macrocode}
  \let\bracket@state\bracket@state@starting
  \bracket@ignorespacestrue
%    \end{macrocode}
% By default, don't expand anything.
%    \begin{macrocode}
  \bracket@expandtokensfalse
%    \end{macrocode}
% We initialize several control sequences that are used to store some
% nodes while parsing.
%    \begin{macrocode}
  \def\bracket@parentNode{0}%
  \def\bracket@rootNode{0}%
  \def\bracket@newNode{0}%
  \def\bracket@afterthoughtNode{0}%
%    \end{macrocode}
% Finally, we start the parser.
%    \begin{macrocode}
  \bracket@Parse
}
%    \end{macrocode}
% The other macro that an end user (actually a power user) can use, is
% actually just a synonym for |\bracket@Parse|. It should be used to
% resume parsing when the action code has finished its work.
%    \begin{macrocode}    
\def\bracketResume{\bracket@Parse}%
%    \end{macrocode}
%    
% \subsection{Parsing}
% 
% We first check if the next token is a space. Spaces need special
% treatment because they are eaten by both the |\romannumeral| trick
% and \TeX s (undelimited) argument parsing algorithm. If a space is
% found, remember that, eat it up, and restart the parsing.
%    \begin{macrocode}
\def\bracket@Parse{%
  \futurelet\bracket@next@token\bracket@Parse@checkForSpace
}
\def\bracket@Parse@checkForSpace{%
  \expandafter\ifx\space\bracket@next@token\@escapeif{%
    \ifbracket@ignorespaces\else
      \bracket@haveSpacetrue
    \fi
    \expandafter\bracket@Parse\romannumeral-`0%
  }\else\@escapeif{%
    \bracket@Parse@maybeexpand
  }\fi
}
%    \end{macrocode}
% 
% We either fully expand the next token (using a popular \TeX nical
% trick \dots) or don't expand it at all, depending on the state of
% |\ifbracket@expandtokens|.
%    \begin{macrocode}
\newif\ifbracket@expandtokens
\def\bracket@Parse@maybeexpand{%
  \ifbracket@expandtokens\@escapeif{%
    \expandafter\bracket@Parse@peekAhead\romannumeral-`0%
  }\else\@escapeif{%
    \bracket@Parse@peekAhead
  }\fi
}
%    \end{macrocode}
% We then look ahead to see what's coming.
%    \begin{macrocode}
\def\bracket@Parse@peekAhead{%
  \futurelet\bracket@next@token\bracket@Parse@checkForTeXGroup
}
%    \end{macrocode}
% If the next token is a begin-group token, we append the whole group to
% the content or afterthought macro, depending on the state.
%    \begin{macrocode}
\def\bracket@Parse@checkForTeXGroup{%
  \ifx\bracket@next@token\bgroup%
    \@escapeif{\bracket@Parse@appendGroup}%
  \else
    \@escapeif{\bracket@Parse@token}%
  \fi
}
%    \end{macrocode}
% This is easy: if a control token is found, run the appropriate
% macro; otherwise, append the token to the content or afterthought
% macro, depending on the state.
%    \begin{macrocode}
\long\def\bracket@Parse@token#1{%
  \ifx#1\bracket@openingBracket
    \@escapeif{\bracket@Parse@openingBracketFound}%
  \else
    \@escapeif{%
      \ifx#1\bracket@closingBracket
        \@escapeif{\bracket@Parse@closingBracketFound}%
      \else
        \@escapeif{%
          \ifx#1\bracket@actionCharacter
            \@escapeif{\futurelet\bracket@next@token\bracket@Parse@actionCharacterFound}%
          \else
            \@escapeif{\bracket@Parse@appendToken#1}%
          \fi
        }%
      \fi
    }%
  \fi
}
%    \end{macrocode}
% Append the token or group to the content or afterthought macro. If a
% space was found previously, append it as well.
%    \begin{macrocode}
\newif\ifbracket@haveSpace
\newif\ifbracket@ignorespaces
\def\bracket@Parse@appendSpace{%
  \ifbracket@haveSpace
    \ifcase\bracket@state\relax
      \eapptotoks\bracket@content\space
    \or
      \eapptotoks\bracket@afterthought\space
    \or
      \eapptotoks\bracket@afterthought\space
    \fi    
    \bracket@haveSpacefalse
  \fi
}
\long\def\bracket@Parse@appendToken#1{%
  \bracket@Parse@appendSpace
  \ifcase\bracket@state\relax
    \lapptotoks\bracket@content{#1}%
  \or
    \lapptotoks\bracket@afterthought{#1}%
  \or
    \lapptotoks\bracket@afterthought{#1}%
  \fi
  \bracket@ignorespacesfalse
  \bracket@Parse
}
\def\bracket@Parse@appendGroup#1{%
  \bracket@Parse@appendSpace
  \ifcase\bracket@state\relax
    \apptotoks\bracket@content{{#1}}%
  \or
    \apptotoks\bracket@afterthought{{#1}}%
  \or
    \apptotoks\bracket@afterthought{{#1}}%
  \fi
  \bracket@ignorespacesfalse
  \bracket@Parse
}
%    \end{macrocode}
% Declare states.
%    \begin{macrocode}
\def\bracket@state@inContent{0}
\def\bracket@state@inAfterthought{1}
\def\bracket@state@starting{2}
%    \end{macrocode}
%    
% Welcome to the jungle.  In the following two macros, new nodes are
% created, content and afterthought are sent to them, parents and
% states are changed\dots\@  Altogether, we distinguish six cases, as
% shown below: in the schemas, we have just crossed the symbol after
% the dots. (In all cases, we reset the |\if| for spaces.)
%    \begin{macrocode}
\def\bracket@Parse@openingBracketFound{%
  \bracket@haveSpacefalse
  \ifcase\bracket@state\relax% in content [ ... [
%    \end{macrocode}
% |[...[|: we have just finished gathering the content and are about
% to begin gathering the content of another node. We create a
% new node (and put the content (\dots) into 
% it). Then, if there is a parent node, we append the new node to the
% list of its children. Next, since we have just crossed an opening
% bracket, we declare the newly created node to be the parent of the
% coming node.  The state does not change. Finally, we continue parsing.
%    \begin{macrocode}
    \@escapeif{%
      \bracket@createNode
      \ifnum\bracket@parentNode=0 \else
        \forest@node@Append{\bracket@parentNode}{\bracket@newNode}%
      \fi
      \let\bracket@parentNode\bracket@newNode
      \bracket@Parse
    }%
  \or % in afterthought   ] ... [
%    \end{macrocode}
% |]...[|: we have just finished gathering the afterthought and are
% about to begin gathering the content of another node. We add the
% afterthought (\dots) to the ``afterthought node'' and change into the
% content state. The parent does not change. Finally, we continue
% parsing.
%    \begin{macrocode}
    \@escapeif{%  
      \bracket@addAfterthought
      \let\bracket@state\bracket@state@inContent
      \bracket@Parse
    }%
  \else % starting
%    \end{macrocode}
% |{start}...[|: we have just started. Nothing to do yet (we couldn't
% have collected any content yet), just get into the content state and
% continue parsing.
%    \begin{macrocode}
    \@escapeif{%
      \let\bracket@state\bracket@state@inContent
      \bracket@Parse
    }%
  \fi 
}
\def\bracket@Parse@closingBracketFound{%
  \bracket@haveSpacefalse
  \ifcase\bracket@state\relax % in content [ ... ]
%    \end{macrocode}
% |[...]|: we have just finished gathering the content of a node and
% are about to begin gathering its afterthought. We create a new node
% (and put the content (\dots) into it). If there is no parent node,
% we're done with parsing. Otherwise, we set the newly created
% node to be the ``afterthought node'', i.e.\ the node that will
% receive the next afterthought, change into the afterthought mode,
% and continue parsing.
%    \begin{macrocode}
    \@escapeif{%
      \bracket@createNode
      \ifnum\bracket@parentNode=0
        \@escapeif\bracketEndParsingHook
      \else
        \@escapeif{%
          \let\bracket@afterthoughtNode\bracket@newNode
          \let\bracket@state\bracket@state@inAfterthought
          \forest@node@Append{\bracket@parentNode}{\bracket@newNode}%
          \bracket@Parse
        }%
      \fi
    }%
  \or % in afterthought ] ... ]
%    \end{macrocode}
% |]...]|: we have finished gathering an afterthought of some node and
% will begin gathering the afterthought of its parent. We first add
% the afterthought to the afterthought node and set the current parent
% to be the next afterthought node.  We change the parent to the
% current parent's parent and check if that node is null.  If it is,
% we're done with parsing (ignore the trailing spaces), otherwise we continue.
%    \begin{macrocode}
    \@escapeif{%
      \bracket@addAfterthought
      \let\bracket@afterthoughtNode\bracket@parentNode
      \edef\bracket@parentNode{\forestOve{\bracket@parentNode}{@parent}}%
      \ifnum\bracket@parentNode=0
        \expandafter\bracketEndParsingHook
      \else
        \expandafter\bracket@Parse
      \fi
    }%
  \else % starting
%    \end{macrocode}
% |{start}...]|: something's obviously wrong with the input here\dots
%    \begin{macrocode}
    \PackageError{forest}{You're attempting to start a bracket representation
      with a closing bracket}{}%
  \fi
}
%    \end{macrocode}
%
% The action character code.  What happens is determined by the next token.
%    \begin{macrocode}
\def\bracket@Parse@actionCharacterFound{%
%    \end{macrocode}
% If a braced expression follows, its contents will be fully expanded.
%    \begin{macrocode}
  \ifx\bracket@next@token\bgroup\@escapeif{%
    \bracket@Parse@action@expandgroup
  }\else\@escapeif{%
    \bracket@Parse@action@notagroup
  }\fi
}
\def\bracket@Parse@action@expandgroup#1{%
  \edef\bracket@Parse@action@expandgroup@macro{#1}%
  \expandafter\bracket@Parse\bracket@Parse@action@expandgroup@macro
}
\let\bracket@action@fullyexpandCharacter+
\let\bracket@action@dontexpandCharacter-
\let\bracket@action@executeCharacter!
\def\bracket@Parse@action@notagroup#1{%
%    \end{macrocode}
% If + follows, tokens will be fully expanded from this point on.
%    \begin{macrocode}
  \ifx#1\bracket@action@fullyexpandCharacter\@escapeif{%
    \bracket@expandtokenstrue\bracket@Parse
  }\else\@escapeif{%
%    \end{macrocode}
% If - follows, tokens will not be expanded from this point on. (This is the default behaviour.)
%    \begin{macrocode}
    \ifx#1\bracket@action@dontexpandCharacter\@escapeif{%
      \bracket@expandtokensfalse\bracket@Parse
    }\else\@escapeif{%
%    \end{macrocode}
% Inhibit expansion of the next token.
%    \begin{macrocode}
      \ifx#10\@escapeif{%
        \bracket@Parse@appendToken
      }\else\@escapeif{%
%    \end{macrocode}
% If another action characted follows, we yield the control.  The user is
% expected to resume the parser manually, using |\bracketResume|.
%    \begin{macrocode}
        \ifx#1\bracket@actionCharacter
        \else\@escapeif{%
%    \end{macrocode}
% Anything else will be expanded once.
%    \begin{macrocode}
          \expandafter\bracket@Parse#1%
        }\fi
      }\fi
    }\fi
  }\fi
}
%    \end{macrocode}
%
% \subsection{The tree-structure interface}
%
% This macro creates a new node and sets its content (and preamble, if it's a root node).  Bracket
% user must define a 3-arg key |/bracket/new node=|\meta{preamble}\meta{node
% specification}\meta{node cs}.  User's key must define \meta{node cs} to be a macro holding the
% node's id. 
%    \begin{macrocode}
\def\bracket@createNode{%
  \ifnum\bracket@rootNode=0
    % root node
    \bracketset{new node/.expanded=%
      {\the\bracket@afterthought}%
      {\the\bracket@content}%
      \noexpand\bracket@newNode
    }%
    \bracket@afterthought={}%
    \let\bracket@rootNode\bracket@newNode
    \expandafter\let\bracket@saveRootNodeTo\bracket@newNode
  \else
    % other nodes
    \bracketset{new node/.expanded=%
      {}%
      {\the\bracket@content}%
      \noexpand\bracket@newNode
    }%
  \fi
  \bracket@content={}%
}
%    \end{macrocode}
%
% This macro sets the afterthought.  Bracket user must define a 2-arg key
% |/bracket/set_afterthought=|\meta{node id}\meta{afterthought}.
%    \begin{macrocode}
\def\bracket@addAfterthought{%
  \bracketset{%
    set afterthought/.expanded={\bracket@afterthoughtNode}{\the\bracket@afterthought}%
  }%
  \bracket@afterthought={}%
}
%    \end{macrocode}
%
%
% \section{Nodes} 
%
% Nodes have numeric ids. The node option values of node $n$ are saved in the |\pgfkeys| tree in
% path |/forest/@node/|$n$.
%    
% \subsection{Option setting and retrieval}
%
% Macros for retrieving/setting node options of the current node.
%    \begin{macrocode}
 % full expansion expands precisely to the value
\def\forestov#1{\expandafter\expandafter\expandafter\expandonce
  \pgfkeysvalueof{/forest/@node/\forest@cn/#1}}
 % full expansion expands all the way
\def\forestove#1{\pgfkeysvalueof{/forest/@node/\forest@cn/#1}}
 % full expansion expands to the cs holding the value
\def\forestom#1{\expandafter\expandonce\expandafter{\pgfkeysvalueof{/forest/@node/\forest@cn/#1}}}\def\forestoget#1#2{\pgfkeysgetvalue{/forest/@node/\forest@cn/#1}{#2}}
\def\forestoget#1#2{\pgfkeysgetvalue{/forest/@node/\forest@cn/#1}{#2}}
\def\forestolet#1#2{\pgfkeyslet{/forest/@node/\forest@cn/#1}{#2}}
\def\forestoset#1#2{\pgfkeyssetvalue{/forest/@node/\forest@cn/#1}{#2}}
\def\forestoeset#1#2{%
  \edef\forest@option@temp{%
    \noexpand\pgfkeyssetvalue{/forest/@node/\forest@cn/#1}{#2}%
  }\forest@option@temp
}
\def\forestoappto#1#2{%
  \forestoeset{#1}{\forestov{#1}\unexpanded{#2}}%
}
\def\forestoifdefined#1#2#3{%
  \pgfkeysifdefined{/forest/@node/\forest@cn/#1}{#2}{#3}%
}
%    \end{macrocode}
% User macros for retrieving node options of the current node.
%    \begin{macrocode}
\let\forestoption\forestov
\let\foresteoption\forestove
%    \end{macrocode}
% Macros for retrieving node options of a node given by its id.
%    \begin{macrocode}
\def\forestOv#1#2{\expandafter\expandafter\expandafter\expandonce
  \pgfkeysvalueof{/forest/@node/#1/#2}}
\def\forestOve#1#2{\pgfkeysvalueof{/forest/@node/#1/#2}}
 % full expansion expands to the cs holding the value
\def\forestOm#1#2{\expandafter\expandonce\expandafter{\pgfkeysvalueof{/forest/@node/#1/#2}}}
\def\forestOget#1#2#3{\pgfkeysgetvalue{/forest/@node/#1/#2}{#3}}
\def\forestOget#1#2#3{\pgfkeysgetvalue{/forest/@node/#1/#2}{#3}}
\def\forestOlet#1#2#3{\pgfkeyslet{/forest/@node/#1/#2}{#3}}
\def\forestOset#1#2#3{\pgfkeyssetvalue{/forest/@node/#1/#2}{#3}}
\def\forestOeset#1#2#3{%
  \edef\forestoption@temp{%
    \noexpand\pgfkeyssetvalue{/forest/@node/#1/#2}{#3}%
  }\forestoption@temp
}
\def\forestOappto#1#2#3{%
  \forestOeset{#1}{#2}{\forestOv{#1}{#2}\unexpanded{#3}}%
}
\def\forestOeappto#1#2#3{%
  \forestOeset{#1}{#2}{\forestOv{#1}{#2}#3}%
}
\def\forestOpreto#1#2#3{%
  \forestOeset{#1}{#2}{\unexpanded{#3}\forestOv{#1}{#2}}%
}
\def\forestOepreto#1#2#3{%
  \forestOeset{#1}{#2}{#3\forestOv{#1}{#2}}%
}
\def\forestOifdefined#1#2#3#4{%
  \pgfkeysifdefined{/forest/@node/#1/#2}{#3}{#4}%
}
\def\forestOletO#1#2#3#4{% option #2 of node #1 <-- option #4 of node #3
  \forestOget{#3}{#4}\forestoption@temp
  \forestOlet{#1}{#2}\forestoption@temp}
\def\forestOleto#1#2#3{%
  \forestoget{#3}\forestoption@temp
  \forestOlet{#1}{#2}\forestoption@temp}
\def\forestoletO#1#2#3{%
  \forestOget{#2}{#3}\forestoption@temp
  \forestolet{#1}\forestoption@temp}
\def\forestoleto#1#2{%
  \forestoget{#2}\forestoption@temp
  \forestolet{#1}\forestoption@temp}
%    \end{macrocode}
% Node initialization.  Node option declarations append to |\forest@node@init|.
%    \begin{macrocode}
\def\forest@node@init{%
  \forestoset{@parent}{0}%
  \forestoset{@previous}{0}% previous sibling
  \forestoset{@next}{0}%     next sibling
  \forestoset{@first}{0}%  primary child
  \forestoset{@last}{0}%   last child
}
\def\forestoinit#1{%
  \pgfkeysgetvalue{/forest/#1}\forestoinit@temp
  \forestolet{#1}\forestoinit@temp
}
\newcount\forest@node@maxid
\def\forest@node@new#1{% #1 = cs receiving the new node id
  \advance\forest@node@maxid1
  \forest@fornode{\the\forest@node@maxid}{%
    \forest@node@init
    \forest@node@setname{node@\forest@cn}%
    \forest@initializefromstandardnode
    \edef#1{\forest@cn}%
  }%
}
\let\forestoinit@orig\forestoinit
\def\forest@node@copy#1#2{% #1=from node id, cs receiving the new node id
  \advance\forest@node@maxid1
  \def\forestoinit##1{\forestoletO{##1}{#1}{##1}}%
  \forest@fornode{\the\forest@node@maxid}{%
    \forest@node@init
    \forest@node@setname{\forest@copy@name@template{\forestOve{#1}{name}}}%
    \edef#2{\forest@cn}%
  }%  
  \let\forestoinit\forestoinit@orig
}
\forestset{
  copy name template/.code={\def\forest@copy@name@template##1{#1}},
  copy name template/.default={node@\the\forest@node@maxid},
  copy name template
}
\def\forest@tree@copy#1#2{% #1=from node id, #2=cs receiving the new node id
  \forest@node@copy{#1}\forest@node@copy@temp@id
  \forest@fornode{\forest@node@copy@temp@id}{%
    \expandafter\forest@tree@copy@\expandafter{\forest@node@copy@temp@id}{#1}%
    \edef#2{\forest@cn}%
  }%
}
\def\forest@tree@copy@#1#2{%
  \forest@node@Foreachchild{#2}{%
    \expandafter\forest@tree@copy\expandafter{\forest@cn}\forest@node@copy@temp@childid
    \forest@node@Append{#1}{\forest@node@copy@temp@childid}%
  }%
}
%    \end{macrocode}
% Macro |\forest@cn| holds the current node id (a number). Node 0 is a special ``null'' node which
% is used to signal the absence of a node.
%    \begin{macrocode}
\def\forest@cn{0}
\forest@node@init
%    \end{macrocode}
%
% \subsection{Tree structure}
% Node insertion/removal.
% 
% For the lowercase variants, |\forest@cn| is the parent/removed node.  For the uppercase variants,
% |#1| is the parent/removed node.  For efficiency, the public macros all expand the arguments
% before calling the internal macros.
%    \begin{macrocode}
\def\forest@node@append#1{\expandtwonumberargs\forest@node@Append{\forest@cn}{#1}}
\def\forest@node@prepend#1{\expandtwonumberargs\forest@node@Insertafter{\forest@cn}{#1}{0}}
\def\forest@node@insertafter#1#2{%
  \expandthreenumberargs\forest@node@Insertafter{\forest@cn}{#1}{#2}}
\def\forest@node@insertbefore#1#2{%
  \expandthreenumberargs\forest@node@Insertafter{\forest@cn}{#1}{\forestOve{#2}{@previous}}%
}
\def\forest@node@remove{\expandnumberarg\forest@node@Remove{\forest@cn}}
\def\forest@node@Append#1#2{\expandtwonumberargs\forest@node@Append@{#1}{#2}}
\def\forest@node@Prepend#1#2{\expandtwonumberargs\forest@node@Insertafter{#1}{#2}{0}}
\def\forest@node@Insertafter#1#2#3{% #2 is inserted after #3
  \expandthreenumberargs\forest@node@Insertafter@{#1}{#2}{#3}%
}
\def\forest@node@Insertbefore#1#2#3{% #2 is inserted before #3
  \expandthreenumberargs\forest@node@Insertafter{#1}{#2}{\forestOve{#3}{@previous}}%
}
\def\forest@node@Remove#1{\expandnumberarg\forest@node@Remove@{#1}}
\def\forest@node@Insertafter@#1#2#3{%
  \ifnum\forestOve{#2}{@parent}=0
  \else
    \PackageError{forest}{Insertafter(#1,#2,#3):
      node #2 already has a parent (\forestOve{#2}{@parent})}{}%
  \fi
  \ifnum#3=0
  \else
    \ifnum#1=\forestOve{#3}{@parent}
    \else
      \PackageError{forest}{Insertafter(#1,#2,#3): node #1 is not the parent of the
            intended sibling #3 (with parent \forestOve{#3}{@parent})}{}%
    \fi
  \fi
  \forestOeset{#2}{@parent}{#1}%
  \forestOeset{#2}{@previous}{#3}%
  \ifnum#3=0
    \forestOget{#1}{@first}\forest@node@temp
    \forestOeset{#1}{@first}{#2}%
  \else
    \forestOget{#3}{@next}\forest@node@temp
    \forestOeset{#3}{@next}{#2}%
  \fi
  \forestOeset{#2}{@next}{\forest@node@temp}%
  \ifnum\forest@node@temp=0
    \forestOeset{#1}{@last}{#2}%
  \else
    \forestOeset{\forest@node@temp}{@previous}{#2}%
  \fi
}
\def\forest@node@Append@#1#2{%
  \ifnum\forestOve{#2}{@parent}=0
  \else
    \PackageError{forest}{Append(#1,#2):
      node #2 already has a parent (\forestOve{#2}{@parent})}{}%
  \fi
  \forestOeset{#2}{@parent}{#1}%
  \forestOget{#1}{@last}\forest@node@temp
  \forestOeset{#1}{@last}{#2}%
  \forestOeset{#2}{@previous}{\forest@node@temp}%
  \ifnum\forest@node@temp=0
    \forestOeset{#1}{@first}{#2}%
  \else
    \forestOeset{\forest@node@temp}{@next}{#2}%
  \fi
}
\def\forest@node@Remove@#1{%
  \forestOget{#1}{@parent}\forest@node@temp@parent
  \ifnum\forest@node@temp@parent=0
  \else
    \forestOget{#1}{@previous}\forest@node@temp@previous
    \forestOget{#1}{@next}\forest@node@temp@next
    \ifnum\forest@node@temp@previous=0
      \forestOeset{\forest@node@temp@parent}{@first}{\forest@node@temp@next}%
    \else
      \forestOeset{\forest@node@temp@previous}{@next}{\forest@node@temp@next}%
    \fi
    \ifnum\forest@node@temp@next=0
      \forestOeset{\forest@node@temp@parent}{@last}{\forest@node@temp@previous}%
    \else
      \forestOeset{\forest@node@temp@next}{@previous}{\forest@node@temp@previous}%
    \fi
    \forestOset{#1}{@parent}{0}%
    \forestOset{#1}{@previous}{0}%
    \forestOset{#1}{@next}{0}%
  \fi
}
%    \end{macrocode}
% Looping methods.
%    \begin{macrocode}
\def\forest@forthis#1{%
  \edef\forest@node@marshal{\unexpanded{#1}\def\noexpand\forest@cn}%
  \expandafter\forest@node@marshal\expandafter{\forest@cn}%
}
\def\forest@fornode#1#2{%
  \edef\forest@node@marshal{\edef\noexpand\forest@cn{#1}\unexpanded{#2}\def\noexpand\forest@cn}%
  \expandafter\forest@node@marshal\expandafter{\forest@cn}%
}
\def\forest@fornode@ifexists#1#2{%
  \edef\forest@node@temp{#1}%
  \ifnum\forest@node@temp=0
  \else
    \@escapeif{\expandnumberarg\forest@fornode{\forest@node@temp}{#2}}%
  \fi
}
\def\forest@node@foreachchild#1{\forest@node@Foreachchild{\forest@cn}{#1}}
\def\forest@node@Foreachchild#1#2{%
  \forest@fornode{\forestOve{#1}{@first}}{\forest@node@@forselfandfollowingsiblings{#2}}%
}
\def\forest@node@@forselfandfollowingsiblings#1{%
  \ifnum\forest@cn=0
  \else
    \forest@forthis{#1}%
    \@escapeif{%
      \edef\forest@cn{\forestove{@next}}%
      \forest@node@@forselfandfollowingsiblings{#1}%
    }%
  \fi
}
\def\forest@node@foreach#1{\forest@node@Foreach{\forest@cn}{#1}}
\def\forest@node@Foreach#1#2{%
  \forest@fornode{#1}{\forest@node@@foreach{#2}}%
}
\def\forest@node@@foreach#1{%
  \forest@forthis{#1}%
  \ifnum\forestove{@first}=0
  \else\@escapeif{%
      \edef\forest@cn{\forestove{@first}}%
      \forest@node@@forselfandfollowingsiblings{\forest@node@@foreach{#1}}%
    }%
  \fi
}
\def\forest@node@foreachdescendant#1{\forest@node@Foreachdescendant{\forest@cn}{#1}}
\def\forest@node@Foreachdescendant#1#2{%
  \forest@node@Foreachchild{#1}{%
    \forest@node@foreach{#2}%
  }%
}
%    \end{macrocode}
% 
% Compute |n|, |n'|, |n children| and |level|.
%    \begin{macrocode}
\def\forest@node@Compute@numeric@ts@info@#1{%
  \forest@node@Foreach{#1}{\forest@node@@compute@numeric@ts@info}%
  \ifnum\forestOve{#1}{@parent}=0
  \else
    \fornode{#1}{\forest@node@@compute@numeric@ts@info@nbar}%
  \fi
  \forest@node@Foreachdescendant{#1}{\forest@node@@compute@numeric@ts@info@nbar}%
}
\def\forest@node@@compute@numeric@ts@info{%
  \forestoset{n children}{0}%
  %
  \edef\forest@node@temp{\forestove{@previous}}%
  \ifnum\forest@node@temp=0
    \forestoset{n}{1}%
  \else
    \forestoeset{n}{\number\numexpr\forestOve{\forest@node@temp}{n}+1}%
  \fi
  %
  \edef\forest@node@temp{\forestove{@parent}}%
  \ifnum\forest@node@temp=0
    \forestoset{n}{0}%
    \forestoset{n'}{0}%
    \forestoset{level}{0}%
  \else
    \forestOeset{\forest@node@temp}{n children}{%
      \number\numexpr\forestOve{\forest@node@temp}{n children}+1%
    }%
    \forestoeset{level}{%
      \number\numexpr\forestOve{\forest@node@temp}{level}+1%
    }%
  \fi
}
\def\forest@node@@compute@numeric@ts@info@nbar{%
  \forestoeset{n'}{\number\numexpr\forestOve{\forestove{@parent}}{n children}-\forestove{n}+1}%
}
\def\forest@node@compute@numeric@ts@info#1{%
  \expandnumberarg\forest@node@Compute@numeric@ts@info@{\forest@cn}%
}
\def\forest@node@Compute@numeric@ts@info#1{%
  \expandnumberarg\forest@node@Compute@numeric@ts@info@{#1}%
}
%    \end{macrocode}
%    
% Tree structure queries.
%    \begin{macrocode}
\def\forest@node@rootid{%
  \expandnumberarg\forest@node@Rootid{\forest@cn}%
}
\def\forest@node@Rootid#1{% #1=node
  \ifnum\forestOve{#1}{@parent}=0
    #1%
  \else
    \@escapeif{\expandnumberarg\forest@node@Rootid{\forestOve{#1}{@parent}}}%
  \fi
}
\def\forest@node@nthchildid#1{% #1=n
  \ifnum#1<1
    0%
  \else
    \expandnumberarg\forest@node@nthchildid@{\number\forestove{@first}}{#1}%
  \fi
}
\def\forest@node@nthchildid@#1#2{%
  \ifnum#1=0
    0%
  \else
    \ifnum#2>1
      \@escapeifif{\expandtwonumberargs
        \forest@node@nthchildid@{\forestOve{#1}{@next}}{\numexpr#2-1}}%
    \else
      #1%
    \fi
  \fi
}
\def\forest@node@nbarthchildid#1{% #1=n
  \expandnumberarg\forest@node@nbarthchildid@{\number\forestove{@last}}{#1}%
}
\def\forest@node@nbarthchildid@#1#2{%
  \ifnum#1=0
    0%
  \else
    \ifnum#2>1
      \@escapeifif{\expandtwonumberargs
        \forest@node@nbarthchildid@{\forestOve{#1}{@previous}}{\numexpr#2-1}}%
    \else
      #1%
    \fi
  \fi
}
\def\forest@node@nornbarthchildid#1{%
  \ifnum#1>0
    \forest@node@nthchildid{#1}%
  \else
    \ifnum#1<0
      \forest@node@nbarthchildid{-#1}%
    \else
      \forest@node@nornbarthchildid@error
    \fi
  \fi
}
\def\forest@node@nornbarthchildid@error{%
  \PackageError{forest}{In \string\forest@node@nornbarthchildid, n should !=0}{}%
}
\def\forest@node@previousleafid{%
  \expandnumberarg\forest@node@Previousleafid{\forest@cn}%
}
\def\forest@node@Previousleafid#1{%
  \ifnum\forestOve{#1}{@previous}=0
    \@escapeif{\expandnumberarg\forest@node@previousleafid@Goup{#1}}%
  \else
    \expandnumberarg\forest@node@previousleafid@Godown{\forestOve{#1}{@previous}}%
  \fi
}
\def\forest@node@previousleafid@Goup#1{%
  \ifnum\forestOve{#1}{@parent}=0
    \PackageError{forest}{get previous leaf: this is the first leaf}{}%
  \else
    \@escapeif{\expandnumberarg\forest@node@Previousleafid{\forestOve{#1}{@parent}}}%
  \fi
}
\def\forest@node@previousleafid@Godown#1{%
  \ifnum\forestOve{#1}{@last}=0
    #1%
  \else
    \@escapeif{\expandnumberarg\forest@node@previousleafid@Godown{\forestOve{#1}{@last}}}%
  \fi
}
\def\forest@node@nextleafid{%
  \expandnumberarg\forest@node@Nextleafid{\forest@cn}%
}
\def\forest@node@Nextleafid#1{%
  \ifnum\forestOve{#1}{@next}=0
    \@escapeif{\expandnumberarg\forest@node@nextleafid@Goup{#1}}%
  \else
    \expandnumberarg\forest@node@nextleafid@Godown{\forestOve{#1}{@next}}%
  \fi
}
\def\forest@node@nextleafid@Goup#1{%
  \ifnum\forestOve{#1}{@parent}=0
    \PackageError{forest}{get next leaf: this is the last leaf}{}%
  \else
    \@escapeif{\expandnumberarg\forest@node@Nextleafid{\forestOve{#1}{@parent}}}%
  \fi
}
\def\forest@node@nextleafid@Godown#1{%
  \ifnum\forestOve{#1}{@first}=0
    #1%
  \else
    \@escapeif{\expandnumberarg\forest@node@nextleafid@Godown{\forestOve{#1}{@first}}}%
  \fi
}
\def\forest@node@linearnextid{%
  \ifnum\forestove{@first}=0
    \expandafter\forest@node@linearnextnotdescendantid
  \else
    \forestove{@first}%
  \fi
}
\def\forest@node@linearnextnotdescendantid{%
  \expandnumberarg\forest@node@Linearnextnotdescendantid{\forest@cn}%
}
\def\forest@node@Linearnextnotdescendantid#1{%
  \ifnum\forestOve{#1}{@next}=0
    \@escapeif{\expandnumberarg\forest@node@Linearnextnotdescendantid{\forestOve{#1}{@parent}}}%
  \else
    \forestOve{#1}{@next}%
  \fi
}
\def\forest@node@linearpreviousid{%
  \ifnum\forestove{@previous}=0
    \forestove{@parent}%
  \else
    \forest@node@previousleafid
  \fi
}
\def\forest@ifancestorof#1{% is the current node an ancestor of #1? Yes: #2, no: #3
  \expandnumberarg\forest@ifancestorof@{\forestOve{#1}{@parent}}%
}
\def\forest@ifancestorof@#1#2#3{%
  \ifnum#1=0
    \def\forest@ifancestorof@next{\@secondoftwo}%
  \else
    \ifnum\forest@cn=#1
      \def\forest@ifancestorof@next{\@firstoftwo}%
    \else
      \def\forest@ifancestorof@next{\expandnumberarg\forest@ifancestorof@{\forestOve{#1}{@parent}}}%
    \fi
  \fi
  \forest@ifancestorof@next{#2}{#3}%
}
%    \end{macrocode}
%
%
% \subsection{Node walk}
%
%    \begin{macrocode}
\newloop\forest@nodewalk@loop
\forestset{
  @handlers@save@currentpath/.code={%
    \edef\pgfkeyscurrentkey{\pgfkeyscurrentpath}%
    \let\forest@currentkey\pgfkeyscurrentkey
    \pgfkeys@split@path
    \edef\forest@currentpath{\pgfkeyscurrentpath}%
    \let\forest@currentname\pgfkeyscurrentname
  },
  /handlers/.step 0 args/.style={
    /forest/@handlers@save@currentpath,
    \forest@currentkey/.code={#1\forestset{node walk/every step}},
    /forest/for \forest@currentname/.style/.expanded={%
      for={\forest@currentname}{####1}%
    }
  },
  /handlers/.step 1 arg/.style={%
    /forest/@handlers@save@currentpath,
    \forest@currentkey/.code={#1\forestset{node walk/every step}},
    /forest/for \forest@currentname/.style 2 args/.expanded={%
      for={\forest@currentname=####1}{####2}%
    }
  },
  node walk/.code={%
    \forestset{%
      node walk/before walk,%
      node walk/.cd,
      #1,%
      /forest/.cd,
      node walk/after walk
    }%
  },
  for/.code 2 args={%
    \forest@forthis{%
      \pgfkeysalso{%
        node walk/before walk/.style={},%
        node walk/every step/.style={},%
        node walk/after walk/.style={/forest,if id=0{}{#2}},%
        %node walk/after walk/.style={#2},%
        node walk={#1}%
      }%
    }%
  },
  node walk/.cd,  
  before walk/.code={},
  every step/.code={},
  after walk/.code={},
  current/.step 0 args={},
  current/.default=1,
  next/.step 0 args={\edef\forest@cn{\forestove{@next}}},
  next/.default=1,
  previous/.step 0 args={\edef\forest@cn{\forestove{@previous}}},
  previous/.default=1,
  parent/.step 0 args={\edef\forest@cn{\forestove{@parent}}},
  parent/.default=1,
  first/.step 0 args={\edef\forest@cn{\forestove{@first}}},
  first/.default=1,
  last/.step 0 args={\edef\forest@cn{\forestove{@last}}},
  last/.default=1,
  n/.step 1 arg={%
    \def\forest@nodewalk@temp{#1}%
    \ifx\forest@nodewalk@temp\pgfkeysnovalue@text
      \edef\forest@cn{\forestove{@next}}%
    \else
      \edef\forest@cn{\forest@node@nthchildid{#1}}%
    \fi
  },
  n'/.step 1 arg={\edef\forest@cn{\forest@node@nbarthchildid{#1}}},
  sibling/.step 0 args={%
    \edef\forest@cn{%
      \ifnum\forestove{@previous}=0
        \forestove{@next}%
      \else
        \forestove{@previous}%
      \fi
    }%
  },
  previous leaf/.step 0 args={\edef\forest@cn{\forest@node@previousleafid}},
  previous leaf/.default=1,
  next leaf/.step 0 args={\edef\forest@cn{\forest@node@nextleafid}},
  next leaf/.default=1,
  linear next/.step 0 args={\edef\forest@cn{\forest@node@linearnextid}},
  linear previous/.step 0 args={\edef\forest@cn{\forest@node@linearpreviousid}},
  first leaf/.step 0 args={%
    \forest@nodewalk@loop
      \edef\forest@cn{\forestove{@first}}%
    \unless\ifnum\forestove{@first}=0
    \forest@nodewalk@repeat
  },
  last leaf/.step 0 args={%
    \forest@nodewalk@loop
      \edef\forest@cn{\forestove{@last}}%
    \unless\ifnum\forestove{@last}=0
    \forest@nodewalk@repeat
  },
  to tier/.step 1 arg={%
    \def\forest@nodewalk@giventier{#1}%
    \forest@nodewalk@loop
      \forestoget{tier}\forest@nodewalk@tier
    \unless\ifx\forest@nodewalk@tier\forest@nodewalk@giventier
      \forestoget{@parent}\forest@cn
    \forest@nodewalk@repeat
  },
  next on tier/.step 0 args={\forest@nodewalk@nextontier},
  next on tier/.default=1,
  previous on tier/.step 0 args={\forest@nodewalk@previousontier},
  previous on tier/.default=1,
  name/.step 1 arg={\edef\forest@cn{\forest@node@Nametoid{#1}}},
  root/.step 0 args={\edef\forest@cn{\forest@node@rootid}},
  root'/.step 0 args={\edef\forest@cn{\forest@root}},
  id/.step 1 arg={\edef\forest@cn{#1}},
  % maybe it's not wise to have short-step sequences and names potentially clashing
  % .unknown/.code={%
  %   \forest@node@Ifnamedefined{\pgfkeyscurrentname}%
  %     {\pgfkeysalso{name=\pgfkeyscurrentname}}%
  %     {\expandafter\forest@nodewalk@shortsteps\pgfkeyscurrentname\forest@nodewalk@endshortsteps}%
  % }, 
  .unknown/.code={%
    \expandafter\forest@nodewalk@shortsteps\pgfkeyscurrentname\forest@nodewalk@endshortsteps
  },
  node walk/.style={/forest/node walk={#1}},
  trip/.code={\forest@forthis{\pgfkeysalso{#1}}},
  group/.code={\forest@go{#1}\forestset{node walk/every step}},
  % repeat is taken later from /forest/repeat
  p/.style={previous=1},
  %n/.style={next=1}, % defined in "long" n
  u/.style={parent=1},
  s/.style={sibling},
  c/.style={current=1},
  r/.style={root},
  P/.style={previous leaf=1},
  N/.style={next leaf=1},  
  F/.style={first leaf=1},
  L/.style={last leaf=1},  
  >/.style={next on tier=1},
  </.style={previous on tier=1},
  1/.style={n=1},
  2/.style={n=2},
  3/.style={n=3},
  4/.style={n=4},
  5/.style={n=5},
  6/.style={n=6},
  7/.style={n=7},
  8/.style={n=8},
  9/.style={n=9},
  l/.style={last=1},
  %{...} is short for group={...}
}
\def\forest@nodewalk@nextontier{%
  \forestoget{tier}\forest@nodewalk@giventier
  \edef\forest@cn{\forest@node@linearnextnotdescendantid}%
  \forest@nodewalk@loop
    \forestoget{tier}\forest@nodewalk@tier
  \unless\ifx\forest@nodewalk@tier\forest@nodewalk@giventier
    \edef\forest@cn{\forest@node@linearnextid}%
  \forest@nodewalk@repeat    
}
\def\forest@nodewalk@previousontier{%
  \forestoget{tier}\forest@nodewalk@giventier
  \forest@nodewalk@loop
    \edef\forest@cn{\forest@node@linearpreviousid}%
    \forestoget{tier}\forest@nodewalk@tier    
  \unless\ifx\forest@nodewalk@tier\forest@nodewalk@giventier
  \forest@nodewalk@repeat    
}
\def\forest@nodewalk@shortsteps{%
  \futurelet\forest@nodewalk@nexttoken\forest@nodewalk@shortsteps@
}
\def\forest@nodewalk@shortsteps@#1{%
  \ifx\forest@nodewalk@nexttoken\forest@nodewalk@endshortsteps
  \else
    \ifx\forest@nodewalk@nexttoken\bgroup
      \pgfkeysalso{group=#1}%
      \@escapeifif\forest@nodewalk@shortsteps
    \else
      \pgfkeysalso{#1}%
      \@escapeifif\forest@nodewalk@shortsteps
    \fi
  \fi
}
\def\forest@go#1{%
  {%
    \forestset{%
      node walk/before walk/.code={},%
      node walk/every step/.code={},%
      node walk/after walk/.code={},%
      node walk={#1}%
    }%
    \expandafter
  }%
  \expandafter\def\expandafter\forest@cn\expandafter{\forest@cn}%
}
%    \end{macrocode}
%
% \subsection{Node options}
%    
% \subsubsection{Option-declaration mechanism}
% 
% Common code for declaring options.
%    \begin{macrocode}
\def\forest@declarehandler#1#2#3{%#1=handler for specific type,#2=option name,#3=default value
  \pgfkeyssetvalue{/forest/#2}{#3}%
  \appto\forest@node@init{\forestoinit{#2}}%
  \forest@convert@others@to@underscores{#2}\forest@pgfmathoptionname
  \edef\forest@marshal{%
    \noexpand#1{/forest/#2}{/forest}{#2}{\forest@pgfmathoptionname}%
  }\forest@marshal
}
\def\forest@def@with@pgfeov#1#2{% \pgfeov mustn't occur in the arg of the .code handler!!!
  \long\def#1##1\pgfeov{#2}%
}
%    \end{macrocode}
% Option-declaration handlers.
%    \begin{macrocode}
\newtoks\forest@temp@toks
\def\forest@declaretoks@handler#1#2#3#4{%
  \forest@declaretoks@handler@A{#1}{#2}{#3}{#4}{}%
}
\def\forest@declarekeylist@handler#1#2#3#4{%
  \forest@declaretoks@handler@A{#1}{#2}{#3}{#4}{,}%
  \pgfkeysgetvalue{#1/.@cmd}\forest@temp
  \pgfkeyslet{#1'/.@cmd}\forest@temp
  \pgfkeyssetvalue{#1'/option@name}{#3}%
  \pgfkeysgetvalue{#1+/.@cmd}\forest@temp
  \pgfkeyslet{#1/.@cmd}\forest@temp
 }
\def\forest@declaretoks@handler@A#1#2#3#4#5{% #1=key,#2=path,#3=name,#4=pgfmathname,#5=infix
  \pgfkeysalso{%
    #1/.code={\forestOset{\forest@setter@node}{#3}{##1}},
    #1+/.code={\forestOappto{\forest@setter@node}{#3}{#5##1}},
    #1-/.code={\forestOpreto{\forest@setter@node}{#3}{##1#5}},
    #2/if #3/.code n args={3}{%
      \forestoget{#3}\forest@temp@option@value
      \edef\forest@temp@compared@value{\unexpanded{##1}}%
      \ifx\forest@temp@option@value\forest@temp@compared@value
        \pgfkeysalso{##2}%
      \else
        \pgfkeysalso{##3}%
      \fi
    },
    #2/if in #3/.code n args={3}{%
      \forestoget{#3}\forest@temp@option@value
      \edef\forest@temp@compared@value{\unexpanded{##1}}%
      \expandafter\expandafter\expandafter\pgfutil@in@\expandafter\expandafter\expandafter{\expandafter\forest@temp@compared@value\expandafter}\expandafter{\forest@temp@option@value}%
      \ifpgfutil@in@
        \pgfkeysalso{##2}%
      \else
        \pgfkeysalso{##3}%
      \fi
    },
    #2/where #3/.style n args={3}{for tree={#2/if #3={##1}{##2}{##3}}},
    #2/where in #3/.style n args={3}{for tree={#2/if in #3={##1}{##2}{##3}}}
  }%
  \pgfkeyssetvalue{#1/option@name}{#3}%  
  \pgfkeyssetvalue{#1+/option@name}{#3}%  
  \pgfmathdeclarefunction{#4}{1}{\forest@pgfmathhelper@attribute@toks{##1}{#3}}%
}
\def\forest@declareautowrappedtoks@handler#1#2#3#4{% #1=key,#2=path,#3=name,#4=pgfmathname,#5=infix
  \forest@declaretoks@handler{#1}{#2}{#3}{#4}%
  \pgfkeysgetvalue{#1/.@cmd}\forest@temp
  \pgfkeyslet{#1'/.@cmd}\forest@temp
  \pgfkeysalso{#1/.style={#1'/.wrap value={##1}}}%
  \pgfkeyssetvalue{#1'/option@name}{#3}%
  \pgfkeysgetvalue{#1+/.@cmd}\forest@temp
  \pgfkeyslet{#1+'/.@cmd}\forest@temp
  \pgfkeysalso{#1+/.style={#1+'/.wrap value={##1}}}%
  \pgfkeyssetvalue{#1+'/option@name}{#3}%
  \pgfkeysgetvalue{#1-/.@cmd}\forest@temp
  \pgfkeyslet{#1-'/.@cmd}\forest@temp
  \pgfkeysalso{#1-/.style={#1-'/.wrap value={##1}}}%
  \pgfkeyssetvalue{#1-'/option@name}{#3}%
}
\def\forest@declarereadonlydimen@handler#1#2#3#4{% #1=key,#2=path,#3=name,#4=pgfmathname
  \pgfkeysalso{%
    #2/if #3/.code n args={3}{%
      \forestoget{#3}\forest@temp@option@value
      \ifdim\forest@temp@option@value=##1\relax
        \pgfkeysalso{##2}%
      \else
        \pgfkeysalso{##3}%
      \fi
    },
    #2/where #3/.style n args={3}{for tree={#2/if #3={##1}{##2}{##3}}},
  }%
  \pgfmathdeclarefunction{#4}{1}{\forest@pgfmathhelper@attribute@dimen{##1}{#3}}%
}
\def\forest@declaredimen@handler#1#2#3#4{% #1=key,#2=path,#3=name,#4=pgfmathname
  \forest@declarereadonlydimen@handler{#1}{#2}{#3}{#4}%
  \pgfkeysalso{%
    #1/.code={%
      \pgfmathsetlengthmacro\forest@temp{##1}%
      \forestOlet{\forest@setter@node}{#3}\forest@temp
    },
    #1+/.code={%
      \pgfmathsetlengthmacro\forest@temp{##1}%
      \pgfutil@tempdima=\forestove{#3}
      \advance\pgfutil@tempdima\forest@temp\relax
      \forestOeset{\forest@setter@node}{#3}{\the\pgfutil@tempdima}%
    },
    #1-/.code={%
      \pgfmathsetlengthmacro\forest@temp{##1}%
      \pgfutil@tempdima=\forestove{#3}
      \advance\pgfutil@tempdima-\forest@temp\relax
      \forestOeset{\forest@setter@node}{#3}{\the\pgfutil@tempdima}%
    },
    #1*/.style={%
      #1={#4()*(##1)}%
    },
    #1:/.style={%
      #1={#4()/(##1)}%
    },
    #1'/.code={%
      \pgfutil@tempdima=##1\relax
      \forestOeset{\forest@setter@node}{#3}{\the\pgfutil@tempdima}%
    },
    #1'+/.code={%
      \pgfutil@tempdima=\forestove{#3}\relax
      \advance\pgfutil@tempdima##1\relax
      \forestOeset{\forest@setter@node}{#3}{\the\pgfutil@tempdima}%
    },
    #1'-/.code={%
      \pgfutil@tempdima=\forestove{#3}\relax
      \advance\pgfutil@tempdima-##1\relax
      \forestOeset{\forest@setter@node}{#3}{\the\pgfutil@tempdima}%
    },
    #1'*/.style={%
      \pgfutil@tempdima=\forestove{#3}\relax
      \multiply\pgfutil@tempdima##1\relax
      \forestOeset{\forest@setter@node}{#3}{\the\pgfutil@tempdima}%
    },
    #1':/.style={%
      \pgfutil@tempdima=\forestove{#3}\relax
      \divide\pgfutil@tempdima##1\relax
      \forestOeset{\forest@setter@node}{#3}{\the\pgfutil@tempdima}%
    },
  }%
  \pgfkeyssetvalue{#1/option@name}{#3}%  
  \pgfkeyssetvalue{#1+/option@name}{#3}%  
  \pgfkeyssetvalue{#1-/option@name}{#3}%  
  \pgfkeyssetvalue{#1*/option@name}{#3}%  
  \pgfkeyssetvalue{#1:/option@name}{#3}%  
  \pgfkeyssetvalue{#1'/option@name}{#3}%  
  \pgfkeyssetvalue{#1'+/option@name}{#3}%  
  \pgfkeyssetvalue{#1'-/option@name}{#3}%  
  \pgfkeyssetvalue{#1'*/option@name}{#3}%  
  \pgfkeyssetvalue{#1':/option@name}{#3}%  
}
\def\forest@declarereadonlycount@handler#1#2#3#4{% #1=key,#2=path,#3=name,#4=pgfmathname
  \pgfkeysalso{
    #2/if #3/.code n args={3}{%
      \forestoget{#3}\forest@temp@option@value
      \ifnum\forest@temp@option@value=##1\relax
        \pgfkeysalso{##2}%
      \else
        \pgfkeysalso{##3}%
      \fi
    },
    #2/where #3/.style n args={3}{for tree={#2/if #3={##1}{##2}{##3}}},
  }%
  \pgfmathdeclarefunction{#4}{1}{\forest@pgfmathhelper@attribute@count{##1}{#3}}%
}
\def\forest@declarecount@handler#1#2#3#4{% #1=key,#2=path,#3=name,#4=pgfmathname
  \forest@declarereadonlycount@handler{#1}{#2}{#3}{#4}%
  \pgfkeysalso{
    #1/.code={%
      \pgfmathtruncatemacro\forest@temp{##1}%
      \forestOlet{\forest@setter@node}{#3}\forest@temp
    },
    #1+/.code={%
      \pgfmathsetlengthmacro\forest@temp{##1}%
      \c@pgf@counta=\forestove{#3}\relax
      \advance\c@pgf@counta\forest@temp\relax
      \forestOeset{\forest@setter@node}{#3}{\the\c@pgf@counta}%
    },
    #1-/.code={%
      \pgfmathsetlengthmacro\forest@temp{##1}%
      \c@pgf@counta=\forestove{#3}\relax
      \advance\c@pgf@counta-\forest@temp\relax
      \forestOeset{\forest@setter@node}{#3}{\the\c@pgf@counta}%
    },
    #1*/.code={%
      \pgfmathsetlengthmacro\forest@temp{##1}%
      \c@pgf@counta=\forestove{#3}\relax
      \multiply\c@pgf@counta\forest@temp\relax
      \forestOeset{\forest@setter@node}{#3}{\the\c@pgf@counta}%
    },
    #1:/.code={%
      \pgfmathsetlengthmacro\forest@temp{##1}%
      \c@pgf@counta=\forestove{#3}\relax
      \divide\c@pgf@counta\forest@temp\relax
      \forestOeset{\forest@setter@node}{#3}{\the\c@pgf@counta}%
    },
    #1'/.code={%
      \c@pgf@counta=##1\relax
      \forestOeset{\forest@setter@node}{#3}{\the\c@pgf@counta}%
    },
    #1'+/.code={%
      \c@pgf@counta=\forestove{#3}\relax
      \advance\c@pgf@counta##1\relax
      \forestOeset{\forest@setter@node}{#3}{\the\c@pgf@counta}%
    },
    #1'-/.code={%
      \c@pgf@counta=\forestove{#3}\relax
      \advance\c@pgf@counta-##1\relax
      \forestOeset{\forest@setter@node}{#3}{\the\c@pgf@counta}%
    },
    #1'*/.style={%
      \c@pgf@counta=\forestove{#3}\relax
      \multiply\c@pgf@counta##1\relax
      \forestOeset{\forest@setter@node}{#3}{\the\c@pgf@counta}%
    },
    #1':/.style={%
      \c@pgf@counta=\forestove{#3}\relax
      \divide\c@pgf@counta##1\relax
      \forestOeset{\forest@setter@node}{#3}{\the\c@pgf@counta}%
    },
  }%
  \pgfkeyssetvalue{#1/option@name}{#3}%  
  \pgfkeyssetvalue{#1+/option@name}{#3}%  
  \pgfkeyssetvalue{#1-/option@name}{#3}%  
  \pgfkeyssetvalue{#1*/option@name}{#3}%  
  \pgfkeyssetvalue{#1:/option@name}{#3}%  
  \pgfkeyssetvalue{#1'/option@name}{#3}%  
  \pgfkeyssetvalue{#1'+/option@name}{#3}%  
  \pgfkeyssetvalue{#1'-/option@name}{#3}%  
  \pgfkeyssetvalue{#1'*/option@name}{#3}%  
  \pgfkeyssetvalue{#1':/option@name}{#3}%  
}
\def\forest@declareboolean@handler#1#2#3#4{% #1=key,#2=path,#3=name,#4=pgfmathname
  \pgfkeysalso{%
    #1/.code={%
      \ifstrequal{##1}{1}{%
        \forestOset{\forest@setter@node}{#3}{1}%
      }{%
        \pgfmathifthenelse{##1}{1}{0}%
        \forestOlet{\forest@setter@node}{#3}\pgfmathresult
      }%
    },
    #1/.default=1,
    #2/not #3/.code={\forestOset{\forest@setter@node}{#3}{0}},
    #2/if #3/.code 2 args={%
      \forestoget{#3}\forest@temp@option@value
      \ifnum\forest@temp@option@value=1
        \pgfkeysalso{##1}%
      \else
        \pgfkeysalso{##2}%
      \fi
    },
    #2/where #3/.style 2 args={for tree={#2/if #3={##1}{##2}}}
  }%
  \pgfkeyssetvalue{#1/option@name}{#3}%
  \pgfmathdeclarefunction{#4}{1}{\forest@pgfmathhelper@attribute@count{##1}{#3}}%
}
\pgfkeys{/forest,
  declare toks/.code 2 args={%
    \forest@declarehandler\forest@declaretoks@handler{#1}{#2}%
  },
  declare autowrapped toks/.code 2 args={%
    \forest@declarehandler\forest@declareautowrappedtoks@handler{#1}{#2}%
  },
  declare keylist/.code 2 args={%
    \forest@declarehandler\forest@declarekeylist@handler{#1}{#2}%
  },
  declare readonly dimen/.code={%
    \forest@declarehandler\forest@declarereadonlydimen@handler{#1}{}%
  },
  declare dimen/.code 2 args={%
    \forest@declarehandler\forest@declaredimen@handler{#1}{#2}%
  },
  declare readonly count/.code={%
    \forest@declarehandler\forest@declarereadonlycount@handler{#1}{}%
  },
  declare count/.code 2 args={%
    \forest@declarehandler\forest@declarecount@handler{#1}{#2}%
  },
  declare boolean/.code 2 args={%
    \forest@declarehandler\forest@declareboolean@handler{#1}{#2}%
  },
  /handlers/.pgfmath/.code={%
    \pgfmathparse{#1}%
    \pgfkeysalso{\pgfkeyscurrentpath/.expand once=\pgfmathresult}%
  },
  /handlers/.wrap value/.code={%
    \edef\forest@handlers@wrap@currentpath{\pgfkeyscurrentpath}%
    \pgfkeysgetvalue{\forest@handlers@wrap@currentpath/option@name}\forest@currentoptionname
    \expandafter\forestoget\expandafter{\forest@currentoptionname}\forest@option@value
    \forest@def@with@pgfeov\forest@wrap@code{#1}%
    \expandafter\edef\expandafter\forest@wrapped@value\expandafter{\expandafter\expandonce\expandafter{\expandafter\forest@wrap@code\forest@option@value\pgfeov}}%
    \pgfkeysalso{\forest@handlers@wrap@currentpath/.expand once=\forest@wrapped@value}%
  },
  /handlers/.wrap pgfmath arg/.code 2 args={%    
    \pgfmathparse{#2}\let\forest@wrap@arg@i\pgfmathresult
    \edef\forest@wrap@args{{\expandonce\forest@wrap@arg@i}}%
    \def\forest@wrap@code##1{#1}%
    \expandafter\expandafter\expandafter\forest@temp@toks\expandafter\expandafter\expandafter{\expandafter\forest@wrap@code\forest@wrap@args}%
    \pgfkeysalso{\pgfkeyscurrentpath/.expand once=\the\forest@temp@toks}%
  },
  /handlers/.wrap 2 pgfmath args/.code n args={3}{%
    \pgfmathparse{#2}\let\forest@wrap@arg@i\pgfmathresult
    \pgfmathparse{#3}\let\forest@wrap@arg@ii\pgfmathresult
    \edef\forest@wrap@args{{\expandonce\forest@wrap@arg@i}{\expandonce\forest@wrap@arg@ii}}%
    \def\forest@wrap@code##1##2{#1}%
    \expandafter\expandafter\expandafter\def\expandafter\expandafter\expandafter\forest@wrapped\expandafter\expandafter\expandafter{\expandafter\forest@wrap@code\forest@wrap@args}%
    \pgfkeysalso{\pgfkeyscurrentpath/.expand once=\forest@wrapped}%
  },
  /handlers/.wrap 3 pgfmath args/.code n args={4}{%
    \forest@wrap@n@pgfmath@args{#2}{#3}{#4}{}{}{}{}{}{3}%
    \forest@wrap@n@pgfmath@do{#1}{3}},
  /handlers/.wrap 4 pgfmath args/.code n args={5}{%
    \forest@wrap@n@pgfmath@args{#2}{#3}{#4}{#5}{}{}{}{}{4}%
    \forest@wrap@n@pgfmath@do{#1}{4}},
  /handlers/.wrap 5 pgfmath args/.code n args={6}{%
    \forest@wrap@n@pgfmath@args{#2}{#3}{#4}{#5}{#6}{}{}{}{5}%
    \forest@wrap@n@pgfmath@do{#1}{5}},
  /handlers/.wrap 6 pgfmath args/.code n args={7}{%
    \forest@wrap@n@pgfmath@args{#2}{#3}{#4}{#5}{#6}{#7}{}{}{6}%
    \forest@wrap@n@pgfmath@do{#1}{6}},
  /handlers/.wrap 7 pgfmath args/.code n args={8}{%
    \forest@wrap@n@pgfmath@args{#2}{#3}{#4}{#5}{#6}{#7}{#8}{}{7}%
    \forest@wrap@n@pgfmath@do{#1}{7}},
  /handlers/.wrap 8 pgfmath args/.code n args={9}{%
    \forest@wrap@n@pgfmath@args{#2}{#3}{#4}{#5}{#6}{#7}{#8}{#9}{8}%
    \forest@wrap@n@pgfmath@do{#1}{8}},
}
\def\forest@wrap@n@pgfmath@args#1#2#3#4#5#6#7#8#9{%
  \pgfmathparse{#1}\let\forest@wrap@arg@i\pgfmathresult
  \ifnum#9>1 \pgfmathparse{#2}\let\forest@wrap@arg@ii\pgfmathresult\fi
  \ifnum#9>2 \pgfmathparse{#3}\let\forest@wrap@arg@iii\pgfmathresult\fi
  \ifnum#9>3 \pgfmathparse{#4}\let\forest@wrap@arg@iv\pgfmathresult\fi
  \ifnum#9>4 \pgfmathparse{#5}\let\forest@wrap@arg@v\pgfmathresult\fi
  \ifnum#9>5 \pgfmathparse{#6}\let\forest@wrap@arg@vi\pgfmathresult\fi
  \ifnum#9>6 \pgfmathparse{#7}\let\forest@wrap@arg@vii\pgfmathresult\fi
  \ifnum#9>7 \pgfmathparse{#8}\let\forest@wrap@arg@viii\pgfmathresult\fi
  \edef\forest@wrap@args{%
    {\expandonce\forest@wrap@arg@i}
    \ifnum#9>1 {\expandonce\forest@wrap@arg@ii}\fi
    \ifnum#9>2 {\expandonce\forest@wrap@arg@iii}\fi
    \ifnum#9>3 {\expandonce\forest@wrap@arg@iv}\fi
    \ifnum#9>4 {\expandonce\forest@wrap@arg@v}\fi
    \ifnum#9>5 {\expandonce\forest@wrap@arg@vi}\fi
    \ifnum#9>6 {\expandonce\forest@wrap@arg@vii}\fi
    \ifnum#9>7 {\expandonce\forest@wrap@arg@viii}\fi
  }%
}
\def\forest@wrap@n@pgfmath@do#1#2{%
  \ifcase#2\relax
  \or\def\forest@wrap@code##1{#1}%
  \or\def\forest@wrap@code##1##2{#1}%
  \or\def\forest@wrap@code##1##2##3{#1}%
  \or\def\forest@wrap@code##1##2##3##4{#1}%
  \or\def\forest@wrap@code##1##2##3##4##5{#1}%
  \or\def\forest@wrap@code##1##2##3##4##5##6{#1}%
  \or\def\forest@wrap@code##1##2##3##4##5##6##7{#1}%
  \or\def\forest@wrap@code##1##2##3##4##5##6##7##8{#1}%
  \fi
  \expandafter\expandafter\expandafter\def\expandafter\expandafter\expandafter\forest@wrapped\expandafter\expandafter\expandafter{\expandafter\forest@wrap@code\forest@wrap@args}%
  \pgfkeysalso{\pgfkeyscurrentpath/.expand once=\forest@wrapped}%
}
%    \end{macrocode}
%
% \subsubsection{Declaring options}
%
%    \begin{macrocode}
\def\forest@node@setname#1{%
  \forestoeset{name}{#1}%
  \csedef{forest@id@of@#1}{\forest@cn}%
}
\def\forest@node@Nametoid#1{% #1 = name
  \csname forest@id@of@#1\endcsname
}
\def\forest@node@Ifnamedefined#1{% #1 = name, #2=true,#3=false
  \ifcsname forest@id@of@#1\endcsname
    \expandafter\@firstoftwo
  \else
    \expandafter\@secondoftwo
  \fi
}
\def\forest@node@setalias#1{%
  \csedef{forest@id@of@#1}{\forest@cn}%    
}
\def\forest@node@Setalias#1#2{%
  \csedef{forest@id@of@#2}{#1}%
}  
\forestset{
  TeX/.code={#1},
  TeX'/.code={\appto\forest@externalize@loadimages{#1}#1},
  TeX''/.code={\appto\forest@externalize@loadimages{#1}},
  declare toks={name}{},
  name/.code={% override the default setter
    \forest@node@setname{#1}%
  },
  alias/.code={\forest@node@setalias{#1}},
  begin draw/.code={\begin{tikzpicture}},
  end draw/.code={\end{tikzpicture}},
  begin forest/.code={},
  end forest/.code={},
  declare autowrapped toks={content}{},
  declare count={grow}{270},
  TeX={% a hack for grow-reversed connection, and compass-based grow specification
    \pgfkeysgetvalue{/forest/grow/.@cmd}\forest@temp
    \pgfkeyslet{/forest/grow@@/.@cmd}\forest@temp
  },
  grow/.style={grow@={#1},reversed=0},
  grow'/.style={grow@={#1},reversed=1},
  grow''/.style={grow@={#1}},
  grow@/.is choice,
  grow@/east/.style={/forest/grow@@=0},
  grow@/north east/.style={/forest/grow@@=45},
  grow@/north/.style={/forest/grow@@=90},
  grow@/north west/.style={/forest/grow@@=135},
  grow@/west/.style={/forest/grow@@=180},
  grow@/south west/.style={/forest/grow@@=225},
  grow@/south/.style={/forest/grow@@=270},
  grow@/south east/.style={/forest/grow@@=315},
  grow@/.unknown/.code={\let\forest@temp@grow\pgfkeyscurrentname
    \pgfkeysalso{/forest/grow@@/.expand once=\forest@temp@grow}},
  declare boolean={reversed}{0},
  declare toks={parent anchor}{},
  declare toks={child anchor}{},
  declare toks={anchor}{base},
  declare toks={calign}{midpoint},
  TeX={%
    \pgfkeysgetvalue{/forest/calign/.@cmd}\forest@temp
    \pgfkeyslet{/forest/calign'/.@cmd}\forest@temp
  },
  calign/.is choice,
  calign/child/.style={calign'=child},
  calign/first/.style={calign'=child,calign primary child=1},
  calign/last/.style={calign'=child,calign primary child=-1},
  calign with current/.style={for parent/.wrap pgfmath arg={calign=child,calign primary child=##1}{n}},
  calign with current edge/.style={for parent/.wrap pgfmath arg={calign=child edge,calign primary child=##1}{n}},
  calign/child edge/.style={calign'=child edge},
  calign/midpoint/.style={calign'=midpoint},
  calign/center/.style={calign'=midpoint,calign primary child=1,calign secondary child=-1},
  calign/edge midpoint/.style={calign'=edge midpoint},
  calign/fixed angles/.style={calign'=fixed angles},
  calign/fixed edge angles/.style={calign'=fixed edge angles},
  calign/.unknown/.code={\PackageError{forest}{unknown calign '\pgfkeyscurrentname'}{}},
  declare count={calign primary child}{1},
  declare count={calign secondary child}{-1},
  declare count={calign primary angle}{-35},
  declare count={calign secondary angle}{35},
  calign child/.style={calign primary child={#1}},
  calign angle/.style={calign primary angle={-#1},calign secondary angle={#1}},
  declare toks={tier}{},
  declare toks={fit}{tight},
  declare boolean={ignore}{0},
  declare boolean={ignore edge}{0},
  no edge/.style={edge'={},ignore edge},
  declare keylist={edge}{draw},
  declare toks={edge path}{%
    \noexpand\path[\forestoption{edge}]%
    (\forestOve{\forestove{@parent}}{name}.parent anchor)--(\forestove{name}.child anchor)\forestoption{edge label};},
  triangle/.style={edge path={%
      \noexpand\path[\forestoption{edge}]%
      (\forestove{name}.north east)--(\forestOve{\forestove{@parent}}{name}.south)--(\forestove{name}.north west)--(\forestove{name}.north east)\forestoption{edge label};}},
  declare toks={edge label}{},
  declare boolean={phantom}{0},
  baseline/.style={alias={forest@baseline@node}},
  declare readonly count={n},
  declare readonly count={n'},
  declare readonly count={n children},
  declare readonly count={level},
  declare dimen=x{},
  declare dimen=y{},
  declare dimen={s}{0pt},
  declare dimen={l}{6ex}, % just in case: should be set by the calibration
  declare dimen={s sep}{0.6666em},
  declare dimen={l sep}{1ex},  % just in case: calibration!
  declare keylist={node options}{},
  declare toks={tikz}{},
  afterthought/.style={tikz+={#1}},
  label/.style={tikz={\path[late options={%
        name=\forestoption{name},label={#1}}];}},
  pin/.style={tikz={\path[late options={%
        name=\forestoption{name},pin={#1}}];}},
  declare toks={content format}{\forestoption{content}},
  math content/.style={content format={\ensuremath{\forestoption{content}}}},
  declare toks={node format}{%
    \noexpand\node
    [\forestoption{node options},anchor=\forestoption{anchor}]%
    (\forestoption{name})%
    {\foresteoption{content format}};%
  },
  tabular@environment/.style={content format={%
    \noexpand\begin{tabular}[\forestoption{base}]{\forestoption{align}}%
      \forestoption{content}%
     \noexpand\end{tabular}%
  }},
  declare toks={align}{},
  TeX={\pgfkeysgetvalue{/forest/align/.@cmd}\forest@temp
    \pgfkeyslet{/forest/align'/.@cmd}\forest@temp},
  align/.is choice,
  align/.unknown/.code={%
    \edef\forest@marshal{%
      \noexpand\pgfkeysalso{%
        align'={\pgfkeyscurrentname},%
        tabular@environment
      }%
    }\forest@marshal
  },
  align/center/.style={align'={@{}c@{}},tabular@environment},
  align/left/.style={align'={@{}l@{}},tabular@environment},
  align/right/.style={align'={@{}r@{}},tabular@environment},
  declare toks={base}{t},
  TeX={\pgfkeysgetvalue{/forest/base/.@cmd}\forest@temp
    \pgfkeyslet{/forest/base'/.@cmd}\forest@temp},
  base/.is choice,
  base/top/.style={base'=t},
  base/bottom/.style={base'=b},
  base/.unknown/.style={base'/.expand once=\pgfkeyscurrentname},
  .unknown/.code={%
    \expandafter\pgfutil@in@\expandafter.\expandafter{\pgfkeyscurrentname}%
    \ifpgfutil@in@
      \expandafter\forest@relatednode@option@setter\pgfkeyscurrentname=#1\forest@END
    \else
      \edef\forest@marshal{%
        \noexpand\pgfkeysalso{node options={\pgfkeyscurrentname=\unexpanded{#1}}}%
      }\forest@marshal
    \fi
  },
  get node boundary/.code={%
    \forestoget{boundary}\forest@node@boundary
    \def#1{}%
    \forest@extendpath#1\forest@node@boundary{\pgfpoint{\forestove{x}}{\forestove{y}}}%
  },
  % get min l tree boundary/.code={%
  %   \forest@get@tree@boundary{negative}{\the\numexpr\forestove{grow}-90\relax}#1},
  % get max l tree boundary/.code={%
  %   \forest@get@tree@boundary{positive}{\the\numexpr\forestove{grow}-90\relax}#1},
  get min s tree boundary/.code={%
    \forest@get@tree@boundary{negative}{\forestove{grow}}#1},
  get max s tree boundary/.code={%
    \forest@get@tree@boundary{positive}{\forestove{grow}}#1},
  fit to tree/.code={%
    \pgfkeysalso{%
      /forest/get min s tree boundary=\forest@temp@negative@boundary,
      /forest/get max s tree boundary=\forest@temp@positive@boundary
    }%
    \edef\forest@temp@boundary{\expandonce{\forest@temp@negative@boundary}\expandonce{\forest@temp@positive@boundary}}%
    \forest@path@getboundingrectangle@xy\forest@temp@boundary
    \pgfkeysalso{inner sep=0,fit/.expanded={(\the\pgf@xa,\the\pgf@ya)(\the\pgf@xb,\the\pgf@yb)}}%
  },
  use as bounding box/.style={%
    before drawing tree={
      tikz+/.expanded={%
        \noexpand\pgfresetboundingbox
        \noexpand\useasboundingbox
        ($(.anchor)+(\forestoption{min x},\forestoption{min y})$)
        rectangle
        ($(.anchor)+(\forestoption{max x},\forestoption{max y})$)
        ;
      }
    }
  },
  use as bounding box'/.style={%
    before drawing tree={
      tikz+/.expanded={%
        \noexpand\pgfresetboundingbox
        \noexpand\useasboundingbox
        ($(.anchor)+(\forestoption{min x}+\pgfkeysvalueof{/pgf/outer xsep}/2+\pgfkeysvalueof{/pgf/inner xsep},\forestoption{min y}+\pgfkeysvalueof{/pgf/outer ysep}/2+\pgfkeysvalueof{/pgf/inner ysep})$)
        rectangle
        ($(.anchor)+(\forestoption{max x}-\pgfkeysvalueof{/pgf/outer xsep}/2-\pgfkeysvalueof{/pgf/inner xsep},\forestoption{max y}-\pgfkeysvalueof{/pgf/outer ysep}/2-\pgfkeysvalueof{/pgf/inner ysep})$)
        ;
      }
    }
  },
}%
\def\forest@get@tree@boundary#1#2#3{%#1=pos/neg,#2=grow,#3=receiving cs
  \def#3{}%
  \forest@node@getedge{#1}{#2}\forest@temp@boundary
  \forest@extendpath#3\forest@temp@boundary{\pgfpoint{\forestove{x}}{\forestove{y}}}%
}
\def\forest@setter@node{\forest@cn}%
\def\forest@relatednode@option@setter#1.#2=#3\forest@END{%
  \forest@forthis{%
    \forest@nameandgo{#1}%
    \let\forest@setter@node\forest@cn
  }%
  \pgfkeysalso{#2={#3}}%
  \def\forest@setter@node{\forest@cn}%
}%
%    \end{macrocode}
%
% \subsubsection{Option propagation}
% 
% The propagators targeting single nodes are automatically defined by node walk steps definitions. 
%
%    \begin{macrocode}
\forestset{
  for tree/.code={\forest@node@foreach{\pgfkeysalso{#1}}},
  if/.code n args={3}{%
    \pgfmathparse{#1}%
    \ifnum\pgfmathresult=0 \pgfkeysalso{#3}\else\pgfkeysalso{#2}\fi
  },
  where/.style n args={3}{for tree={if={#1}{#2}{#3}}},
  for descendants/.code={\forest@node@foreachdescendant{\pgfkeysalso{#1}}},
  for all next/.style={for next={#1,for all next={#1}}},
  for all previous/.style={for previous={#1,for all previous={#1}}},
  for siblings/.style={for all previous={#1},for all next={#1}},
  for ancestors/.style={for parent={#1,for ancestors={#1}}},
  for ancestors'/.style={#1,for ancestors={#1}},
  for children/.code={\forest@node@foreachchild{\pgfkeysalso{#1}}},
  for c-commanded={for sibling={for tree={#1}}},
  for c-commanders={for sibling={#1},for parent={for c-commanders={#1}}}
}
%    \end{macrocode}
%    
% A bit of complication to allow for nested \keyname{repeat}s without \TeX\ groups.
%    \begin{macrocode}
\newcount\forest@repeat@key@depth
\forestset{%
  repeat/.code 2 args={%
    \advance\forest@repeat@key@depth1
    \pgfmathparse{int(#1)}%
    \csedef{forest@repeat@key@\the\forest@repeat@key@depth}{\pgfmathresult}%
    \expandafter\newloop\csname forest@repeat@key@loop@\the\forest@repeat@key@depth\endcsname
    \def\forest@marshal{%
      \csname forest@repeat@key@loop@\the\forest@repeat@key@depth\endcsname
        \forest@temp@count=\csname forest@repeat@key@\the\forest@repeat@key@depth\endcsname\relax
      \ifnum\forest@temp@count>0
        \advance\forest@temp@count-1
        \csedef{forest@repeat@key@\the\forest@repeat@key@depth}{\the\forest@temp@count}%
        \pgfkeysalso{#2}%
    }%   
    \expandafter\forest@marshal\csname forest@repeat@key@repeat@\the\forest@repeat@key@depth\endcsname
    \advance\forest@repeat@key@depth-1
  },
}
\pgfkeysgetvalue{/forest/repeat/.@cmd}\forest@temp
\pgfkeyslet{/forest/node walk/repeat/.@cmd}\forest@temp
%    
%    \end{macrocode}
%
% \subsubsection{\texttt{pgfmath} extensions}
%
%    \begin{macrocode}
\pgfmathdeclarefunction{strequal}{2}{%
  \ifstrequal{#1}{#2}{\def\pgfmathresult{1}}{\def\pgfmathresult{0}}%
}
\pgfmathdeclarefunction{instr}{2}{%
  \pgfutil@in@{#1}{#2}%
  \ifpgfutil@in@\def\pgfmathresult{1}\else\def\pgfmathresult{0}\fi
}
\pgfmathdeclarefunction{strcat}{...}{%
  \edef\pgfmathresult{\forest@strip@braces{#1}}%
}
\def\forest@pgfmathhelper@attribute@toks#1#2{%
  \forest@forthis{%
    \forest@nameandgo{#1}%
    \forestoget{#2}\pgfmathresult
  }%
}
\def\forest@pgfmathhelper@attribute@dimen#1#2{%
  \forest@forthis{%
    \forest@nameandgo{#1}%
    \forestoget{#2}\forest@temp
    \pgfmathparse{+\forest@temp}%
  }%
}
\def\forest@pgfmathhelper@attribute@count#1#2{%
  \forest@forthis{%
    \forest@nameandgo{#1}%
    \forestoget{#2}\forest@temp
    \pgfmathtruncatemacro\pgfmathresult{\forest@temp}%
  }%
}
\pgfmathdeclarefunction{id}{1}{%
  \forest@forthis{%
    \forest@nameandgo{#1}%
    \let\pgfmathresult\forest@cn
  }%
}
\forestset{%
  if id/.code n args={3}{%
    \ifnum#1=\forest@cn\relax
      \pgfkeysalso{#2}%
    \else
      \pgfkeysalso{#3}%
    \fi
  },
  where id/.style n args={3}{for tree={if id={#1}{#2}{#3}}}
}
%    \end{macrocode}
%
%
% \subsection{Dynamic tree}
% \label{sec:impl:dynamic}
%
%    \begin{macrocode}
\def\forest@last@node{0}
\def\forest@nodehandleby@name@nodewalk@or@bracket#1{%
  \ifx\pgfkeysnovalue#1%
    \edef\forest@last@node{\forest@node@Nametoid{forest@last@node}}%
  \else
    \forest@nodehandleby@nnb@checkfirst#1\forest@END
  \fi
}
\def\forest@nodehandleby@nnb@checkfirst#1#2\forest@END{%
  \ifx[#1%]
    \forest@create@node{#1#2}%
  \else
    \forest@forthis{%
      \forest@nameandgo{#1#2}%
      \let\forest@last@node\forest@cn
    }%
  \fi
}
\def\forest@create@node#1{% #1=bracket representation
  \bracketParse{\forest@create@collectafterthought}%
               \forest@last@node=#1\forest@end@create@node
}
\def\forest@create@collectafterthought#1\forest@end@create@node{%
  \forestOletO{\forest@last@node}{delay}{\forest@last@node}{given options}%
  \forestOset{\forest@last@node}{given options}{}%
  \forestOeappto{\forest@last@node}{delay}{,\unexpanded{#1}}%
}
\def\forest@create@collectafterthought#1\forest@end@create@node{%
  \forest@node@Foreach{\forest@last@node}{%
    \forestoleto{delay}{given options}%
    \forestoset{given options}{}%
  }%
  \forestOeappto{\forest@last@node}{delay}{,\unexpanded{#1}}%
}
\def\forest@remove@node#1{%
  \forest@node@Remove{#1}%
}
\def\forest@append@node#1#2{%
  \forest@node@Remove{#2}%
  \forest@node@Append{#1}{#2}%
}
\def\forest@prepend@node#1#2{%
  \forest@node@Remove{#2}%
  \forest@node@Prepend{#1}{#2}%
}
\def\forest@insertafter@node#1#2{%
  \forest@node@Remove{#2}%
  \forest@node@Insertafter{\forestOve{#1}{@parent}}{#2}{#1}%
}
\def\forest@insertbefore@node#1#2{%
  \forest@node@Remove{#2}%
  \forest@node@Insertbefore{\forestOve{#1}{@parent}}{#2}{#1}%
}
\def\forest@appto@do@dynamics#1#2{%
   \forest@nodehandleby@name@nodewalk@or@bracket{#2}%
   \ifcase\forest@dynamics@copyhow\relax\or
     \forest@tree@copy{\forest@last@node}\forest@last@node
   \or
     \forest@node@copy{\forest@last@node}\forest@last@node
   \fi
   \forest@node@Ifnamedefined{forest@last@node}{%
     \forestOepreto{\forest@last@node}{delay}
       {for id={\forest@node@Nametoid{forest@last@node}}{alias=forest@last@node},}%
     }{}%
   \forest@havedelayedoptionstrue
   \edef\forest@marshal{%
     \noexpand\apptotoks\noexpand\forest@do@dynamics{%
       \noexpand#1{\forest@cn}{\forest@last@node}}%
   }\forest@marshal
}
\forestset{%
  create/.code={\forest@create@node{#1}},
  append/.code={\def\forest@dynamics@copyhow{0}\forest@appto@do@dynamics\forest@append@node{#1}},
  prepend/.code={\def\forest@dynamics@copyhow{0}\forest@appto@do@dynamics\forest@prepend@node{#1}},
  insert after/.code={\def\forest@dynamics@copyhow{0}\forest@appto@do@dynamics\forest@insertafter@node{#1}},
  insert before/.code={\def\forest@dynamics@copyhow{0}\forest@appto@do@dynamics\forest@insertbefore@node{#1}},
  append'/.code={\def\forest@dynamics@copyhow{1}\forest@appto@do@dynamics\forest@append@node{#1}},
  prepend'/.code={\def\forest@dynamics@copyhow{1}\forest@appto@do@dynamics\forest@prepend@node{#1}},
  insert after'/.code={\def\forest@dynamics@copyhow{1}\forest@appto@do@dynamics\forest@insertafter@node{#1}},
  insert before'/.code={\def\forest@dynamics@copyhow{1}\forest@appto@do@dynamics\forest@insertbefore@node{#1}},
  append''/.code={\def\forest@dynamics@copyhow{2}\forest@appto@do@dynamics\forest@append@node{#1}},
  prepend''/.code={\def\forest@dynamics@copyhow{2}\forest@appto@do@dynamics\forest@prepend@node{#1}},
  insert after''/.code={\def\forest@dynamics@copyhow{2}\forest@appto@do@dynamics\forest@insertafter@node{#1}},
  insert before''/.code={\def\forest@dynamics@copyhow{2}\forest@appto@do@dynamics\forest@insertbefore@node{#1}},
  remove/.code={%
    \pgfkeysalso{alias=forest@last@node}%
    \expandafter\apptotoks\expandafter\forest@do@dynamics\expandafter{%
      \expandafter\forest@remove@node\expandafter{\forest@cn}}%
  },
  set root/.code={%
    \forest@nodehandleby@name@nodewalk@or@bracket{#1}%
    \edef\forest@marshal{%
      \noexpand\apptotoks\noexpand\forest@do@dynamics{%
        \def\noexpand\forest@root{\forest@last@node}%
      }%
    }\forest@marshal
  },
  replace by/.code={\forest@replaceby@code{#1}{insert after}},
  replace by'/.code={\forest@replaceby@code{#1}{insert after'}},
  replace by''/.code={\forest@replaceby@code{#1}{insert after''}},
}
\def\forest@replaceby@code#1#2{%#1=node spec,#2=insert after['][']
  \ifnum\forestove{@parent}=0
    \pgfkeysalso{set root={#1}}%
  \else
    \pgfkeysalso{alias=forest@last@node,#2={#1}}%
    \eapptotoks\forest@do@dynamics{%
      \noexpand\ifnum\noexpand\forestOve{\forest@cn}{@parent}=\forestove{@parent}
        \noexpand\forest@remove@node{\forest@cn}%
      \noexpand\fi
    }%
  \fi
}
%    \end{macrocode}
%
% \section{Stages}
% 
%    \begin{macrocode}
\forestset{
  stages/.style={
    process keylist=before typesetting nodes,
    typeset nodes stage,
    process keylist=before packing,
    pack stage,
    process keylist=before computing xy,
    compute xy stage,
    process keylist=before drawing tree,
    draw tree stage,
  },
  typeset nodes stage/.style={for root'=typeset nodes},
  pack stage/.style={for root'=pack},
  compute xy stage/.style={for root'=compute xy},
  draw tree stage/.style={for root'=draw tree},
  process keylist/.code={\forest@process@hook@keylist{#1}},
  declare keylist={given options}{},
  declare keylist={before typesetting nodes}{},
  declare keylist={before packing}{},
  declare keylist={before computing xy}{},
  declare keylist={before drawing tree}{},
  declare keylist={delay}{},
  delay/.append code={\forest@havedelayedoptionstrue},
  delay n/.style 2 args={if={#1==0}{#2}{delay@n={#1}{#2}}},
  delay@n/.style 2 args={
    if={#1==1}{delay={#2}}{delay={delay@n/.wrap pgfmath arg={{##1}{#2}}{#1-1}}}
  },
  if have delayed/.code 2 args={%
    \ifforest@havedelayedoptions\pgfkeysalso{#1}\else\pgfkeysalso{#2}\fi
  },
  typeset nodes/.code={%
    \forest@drawtree@preservenodeboxes@false
    \forest@node@foreach{\forest@node@typeset}},
  typeset nodes'/.code={%
    \forest@drawtree@preservenodeboxes@true
    \forest@node@foreach{\forest@node@typeset}},
  typeset node/.code={%
    \forest@drawtree@preservenodeboxes@false
    \forest@node@typeset
  },  
  pack/.code={\forest@pack},
  pack'/.code={\forest@pack@onlythisnode},
  compute xy/.code={\forest@node@computeabsolutepositions},
  draw tree box/.store in=\forest@drawtreebox,
  draw tree box,
  draw tree/.code={%
    \forest@drawtree@preservenodeboxes@false
    \forest@node@drawtree
  },
  draw tree'/.code={%
    \forest@drawtree@preservenodeboxes@true
    \forest@node@drawtree
  },
}
\newtoks\forest@do@dynamics
\newif\ifforest@havedelayedoptions
\def\forest@process@hook@keylist#1{%
  \forest@loopa
    \forest@havedelayedoptionsfalse
    \forest@do@dynamics={}%
    \forest@fornode{\forest@root}{\forest@process@hook@keylist@{#1}}%
    \expandafter\ifstrempty\expandafter{\the\forest@do@dynamics}{}{%
      \the\forest@do@dynamics
      \forest@node@Compute@numeric@ts@info{\forest@root}%
      \forest@havedelayedoptionstrue
    }%
  \ifforest@havedelayedoptions
    \forest@node@Foreach{\forest@root}{%
      \forestoget{delay}\forest@temp@delayed
      \forestolet{#1}\forest@temp@delayed
      \forestoset{delay}{}%
    }%
  \forest@repeata
}
\def\forest@process@hook@keylist@#1{%
  \forest@node@foreach{%
    \forestoget{#1}\forest@temp@keys
    \ifdefvoid\forest@temp@keys{}{%
      \forestoset{#1}{}%
      \expandafter\forestset\expandafter{\forest@temp@keys}%
    }%
  }%
}
%    \end{macrocode}
%
%
% \subsection{Typesetting nodes}
%
%    \begin{macrocode}
\def\forest@node@typeset{%
  \let\forest@next\forest@node@typeset@
  \forestoifdefined{box}{%
    \ifforest@drawtree@preservenodeboxes@
      \let\forest@next\relax
    \fi
  }{%
    \locbox\forest@temp@box
    \forestolet{box}\forest@temp@box
  }%
  \def\forest@node@typeset@restore{}%
  \ifdefined\ifsa@tikz\forest@standalone@hack\fi
  \forest@next
  \forest@node@typeset@restore
}
\def\forest@standalone@hack{%
  \ifsa@tikz
    \let\forest@standalone@tikzpicture\tikzpicture
    \let\forest@standalone@endtikzpicture\endtikzpicture
    \let\tikzpicture\sa@orig@tikzpicture
    \let\endtikzpicture\sa@orig@endtikzpicture
    \def\forest@node@typeset@restore{%
      \let\tikzpicture\forest@standalone@tikzpicture
      \let\endtikzpicture\forest@standalone@endtikzpicture
    }%
  \fi
}
\newbox\forest@box
\def\forest@node@typeset@{%
  \forestoget{name}\forest@nodename
  \edef\forest@temp@nodeformat{\forestove{node format}}%
  \gdef\forest@smuggle{}%
  \setbox0=\hbox{%
    \begin{tikzpicture}%
      \pgfpositionnodelater{\forest@positionnodelater@save}%
      \forest@temp@nodeformat
      \pgfinterruptpath
      \pgfpointanchor{\forest@pgf@notyetpositioned\forest@nodename}{forestcomputenodeboundary}%
      \endpgfinterruptpath
      %\forest@compute@node@boundary\forest@temp
      %\xappto\forest@smuggle{\noexpand\forestoset{boundary}{\expandonce\forest@temp}}%
      \if\relax\forestove{parent anchor}\relax
        \pgfpointanchor{\forest@pgf@notyetpositioned\forest@nodename}{center}%
      \else
        \pgfpointanchor{\forest@pgf@notyetpositioned\forest@nodename}{\forestove{parent anchor}}%
      \fi
      \xappto\forest@smuggle{%
        \noexpand\forestoset{parent@anchor}{%
          \noexpand\noexpand\noexpand\pgf@x=\the\pgf@x\relax
          \noexpand\noexpand\noexpand\pgf@y=\the\pgf@y\relax}}%
      \if\relax\forestove{child anchor}\relax
        \pgfpointanchor{\forest@pgf@notyetpositioned\forest@nodename}{center}%
      \else      
        \pgfpointanchor{\forest@pgf@notyetpositioned\forest@nodename}{\forestove{child anchor}}%
      \fi
      \xappto\forest@smuggle{%
        \noexpand\forestoeset{child@anchor}{%
          \noexpand\noexpand\noexpand\pgf@x=\the\pgf@x\relax
          \noexpand\noexpand\noexpand\pgf@y=\the\pgf@y\relax}}%
      \if\relax\forestove{anchor}\relax
        \pgfpointanchor{\forest@pgf@notyetpositioned\forest@nodename}{center}%
      \else      
        \pgfpointanchor{\forest@pgf@notyetpositioned\forest@nodename}{\forestove{anchor}}%
      \fi
      \xappto\forest@smuggle{%
        \noexpand\forestoeset{@anchor}{%
          \noexpand\noexpand\noexpand\pgf@x=\the\pgf@x\relax
          \noexpand\noexpand\noexpand\pgf@y=\the\pgf@y\relax}}%
    \end{tikzpicture}%
  }%
  \setbox\forestove{box}=\box\forest@box % smuggle the box
  \forestolet{boundary}\forest@global@boundary
  \forest@smuggle % ... and the rest
}
\forestset{
  declare readonly dimen={min x},
  declare readonly dimen={min y},
  declare readonly dimen={max x},
  declare readonly dimen={max y},
}
\def\forest@patch@enormouscoordinateboxbounds@plus#1{%
  \expandafter\ifstrequal\expandafter{#1}{16000.0pt}{\def#1{0.0pt}}{}%
}
\def\forest@patch@enormouscoordinateboxbounds@minus#1{%
  \expandafter\ifstrequal\expandafter{#1}{-16000.0pt}{\def#1{0.0pt}}{}%
}
\def\forest@positionnodelater@save{%
  \global\setbox\forest@box=\box\pgfpositionnodelaterbox
  \xappto\forest@smuggle{\noexpand\forestoset{later@name}{\pgfpositionnodelatername}}%
  % a bug in pgf? ---well, here's a patch
  \forest@patch@enormouscoordinateboxbounds@plus\pgfpositionnodelaterminx
  \forest@patch@enormouscoordinateboxbounds@plus\pgfpositionnodelaterminy
  \forest@patch@enormouscoordinateboxbounds@minus\pgfpositionnodelatermaxx
  \forest@patch@enormouscoordinateboxbounds@minus\pgfpositionnodelatermaxy
  % end of patch
  \xappto\forest@smuggle{\noexpand\forestoset{min x}{\pgfpositionnodelaterminx}}%
  \xappto\forest@smuggle{\noexpand\forestoset{min y}{\pgfpositionnodelaterminy}}%
  \xappto\forest@smuggle{\noexpand\forestoset{max x}{\pgfpositionnodelatermaxx}}%
  \xappto\forest@smuggle{\noexpand\forestoset{max y}{\pgfpositionnodelatermaxy}}%
}
\def\forest@node@forest@positionnodelater@restore{%
  \ifforest@drawtree@preservenodeboxes@
    \let\forest@boxorcopy\copy
  \else
    \let\forest@boxorcopy\box
  \fi
  \forestoget{box}\forest@temp
  \setbox\pgfpositionnodelaterbox=\forest@boxorcopy\forest@temp
  \edef\pgfpositionnodelatername{\forestove{later@name}}%
  \edef\pgfpositionnodelaterminx{\forestove{min x}}%
  \edef\pgfpositionnodelaterminy{\forestove{min y}}%
  \edef\pgfpositionnodelatermaxx{\forestove{max x}}%
  \edef\pgfpositionnodelatermaxy{\forestove{max y}}%
}
%    \end{macrocode}
%
% \subsection{Packing}
% \label{imp:packing}
%
% Method |pack| should be called to calculate the positions of
% descendant nodes; the positions are stored in attributes |l| and |s|
% of these nodes, in a level/sibling coordinate system with origin at
% the parent's anchor.  
%    \begin{macrocode}
\def\forest@pack{%
  \forest@pack@computetiers
  \forest@pack@computegrowthuniformity
  \forest@@pack
}
\def\forest@@pack{%
  \ifnum\forestove{n children}>0
    \ifnum\forestove{uniform growth}>0
      \forest@pack@level@uniform
      \forest@pack@aligntiers@ofsubtree
      \forest@pack@sibling@uniform@recursive
    \else
      \forest@node@foreachchild{\forest@@pack}%
      \forest@pack@level@nonuniform
      \forest@pack@aligntiers
      \forest@pack@sibling@uniform@applyreversed
    \fi
  \fi
}
\def\forest@pack@onlythisnode{%
  \ifnum\forestove{n children}>0
    \forest@pack@computetiers
      \forest@pack@level@nonuniform
      \forest@pack@aligntiers
      \forest@pack@sibling@uniform@applyreversed  
  \fi  
}
%    \end{macrocode}
%    
% Compute growth uniformity for the subtree.  A tree grows uniformly is all its branching nodes have
% the same |grow|. 
%    \begin{macrocode}
\def\forest@pack@computegrowthuniformity{%
  \forest@node@foreachchild{\forest@pack@computegrowthuniformity}%
  \edef\forest@pack@cgu@uniformity{%
    \ifnum\forestove{n children}=0
    2\else 1\fi
  }%
  \forestoget{grow}\forest@pack@cgu@parentgrow
  \forest@node@foreachchild{%
    \ifnum\forestove{uniform growth}=0
      \def\forest@pack@cgu@uniformity{0}%
    \else
      \ifnum\forestove{uniform growth}=1
        \ifnum\forestove{grow}=\forest@pack@cgu@parentgrow\relax\else
          \def\forest@pack@cgu@uniformity{0}%
        \fi
      \fi
    \fi
  }%
  \forestolet{uniform growth}\forest@pack@cgu@uniformity
}
%    \end{macrocode}
%    
% Pack children in the level dimension in a uniform tree.
%    \begin{macrocode}
\def\forest@pack@level@uniform{%
  \let\forest@plu@minchildl\relax
  \forestoget{grow}\forest@plu@grow
  \forest@node@foreachchild{%
    \forest@node@getboundingrectangle@ls{\forest@plu@grow}%
    \advance\pgf@xa\forestove{l}\relax
    \ifx\forest@plu@minchildl\relax
      \edef\forest@plu@minchildl{\the\pgf@xa}%
    \else
      \ifdim\pgf@xa<\forest@plu@minchildl\relax
        \edef\forest@plu@minchildl{\the\pgf@xa}%
      \fi
    \fi
  }%
  \forest@node@getboundingrectangle@ls{\forest@plu@grow}%
  \pgfutil@tempdima=\pgf@xb\relax
  \advance\pgfutil@tempdima -\forest@plu@minchildl\relax
  \advance\pgfutil@tempdima \forestove{l sep}\relax
  \ifdim\pgfutil@tempdima>0pt
    \forest@node@foreachchild{%
      \forestoeset{l}{\the\dimexpr\forestove{l}+\the\pgfutil@tempdima}%
    }%
  \fi
  \forest@node@foreachchild{%
    \ifnum\forestove{n children}>0
      \forest@pack@level@uniform
    \fi
  }%
}
%    \end{macrocode}
% 
% Pack children in the level dimension in a non-uniform tree. (Expects
% the children to be fully packed.)
%    \begin{macrocode}
\def\forest@pack@level@nonuniform{%
  \let\forest@plu@minchildl\relax
  \forestoget{grow}\forest@plu@grow
  \forest@node@foreachchild{%
    \forest@node@getedge{negative}{\forest@plu@grow}{\forest@plnu@negativechildedge}%
    \forest@node@getedge{positive}{\forest@plu@grow}{\forest@plnu@positivechildedge}%
    \def\forest@plnu@childedge{\forest@plnu@negativechildedge\forest@plnu@positivechildedge}%
    \forest@path@getboundingrectangle@ls\forest@plnu@childedge{\forest@plu@grow}%
    \advance\pgf@xa\forestove{l}\relax
    \ifx\forest@plu@minchildl\relax
      \edef\forest@plu@minchildl{\the\pgf@xa}%
    \else
      \ifdim\pgf@xa<\forest@plu@minchildl\relax
        \edef\forest@plu@minchildl{\the\pgf@xa}%
      \fi
    \fi
  }%
  \forest@node@getboundingrectangle@ls{\forest@plu@grow}%
  \pgfutil@tempdima=\pgf@xb\relax
  \advance\pgfutil@tempdima -\forest@plu@minchildl\relax
  \advance\pgfutil@tempdima \forestove{l sep}\relax
  \ifdim\pgfutil@tempdima>0pt
    \forest@node@foreachchild{%
      \forestoeset{l}{\the\dimexpr\the\pgfutil@tempdima+\forestove{l}}%
    }%
  \fi
}
%    \end{macrocode}
%
% Align tiers.
%    \begin{macrocode}
\def\forest@pack@aligntiers{%
  \forestoget{grow}\forest@temp@parentgrow
  \forestoget{@tiers}\forest@temp@tiers
  \forlistloop\forest@pack@aligntier@\forest@temp@tiers
}
\def\forest@pack@aligntiers@ofsubtree{%
  \forest@node@foreach{\forest@pack@aligntiers}%
}
\def\forest@pack@aligntiers@computeabsl{%
  \forestoleto{abs@l}{l}%
  \forest@node@foreachdescendant{\forest@pack@aligntiers@computeabsl@}%
}
\def\forest@pack@aligntiers@computeabsl@{%
  \forestoeset{abs@l}{\the\dimexpr\forestove{l}+\forestOve{\forestove{@parent}}{abs@l}}%
}
\def\forest@pack@aligntier@#1{%
  \forest@pack@aligntiers@computeabsl
  \pgfutil@tempdima=-\maxdimen\relax
  \def\forest@temp@currenttier{#1}%
  \forest@node@foreach{%
    \forestoget{tier}\forest@temp@tier
    \ifx\forest@temp@currenttier\forest@temp@tier
      \ifdim\pgfutil@tempdima<\forestove{abs@l}\relax
        \pgfutil@tempdima=\forestove{abs@l}\relax
      \fi
    \fi
  }%
  \ifdim\pgfutil@tempdima=-\maxdimen\relax\else
    \forest@node@foreach{%
      \forestoget{tier}\forest@temp@tier
      \ifx\forest@temp@currenttier\forest@temp@tier
        \forestoeset{l}{\the\dimexpr\pgfutil@tempdima-\forestove{abs@l}+\forestove{l}}%
      \fi
    }%
  \fi
}
%    \end{macrocode}
% Pack children in the sibling dimension in a uniform tree:
% recursion.
%    \begin{macrocode}
\def\forest@pack@sibling@uniform@recursive{%
  \forest@node@foreachchild{\forest@pack@sibling@uniform@recursive}%
  \forest@pack@sibling@uniform@applyreversed
}
%    \end{macrocode}
% Pack children in the sibling dimension in a uniform tree: applyreversed.
%    \begin{macrocode}
\def\forest@pack@sibling@uniform@applyreversed{%
  \ifnum\forestove{n children}>1
    \ifnum\forestove{reversed}=0
      \pack@sibling@uniform@main{first}{last}{next}{previous}%
    \else
      \pack@sibling@uniform@main{last}{first}{previous}{next}%
    \fi
  \fi
}
%    \end{macrocode}
% Pack children in the sibling dimension in a uniform tree: the main
% routine.
%    \begin{macrocode}
\def\pack@sibling@uniform@main#1#2#3#4{%
%    \end{macrocode}
% Loop through the children. At each iteration, we compute the
% distance between the negative edge of the current child and the
% positive edge of the block of the previous children, and then set
% the |s| attribute of the current child accordingly.
%
% We start the loop with the second (to last) child, having
% initialized the positive edge of the previous children to the
% positive edge of the first child.
%    \begin{macrocode}
  \forestoget{@#1}\forest@child
  \edef\forest@temp{%
    \noexpand\forest@fornode{\forestove{@#1}}{%
      \noexpand\forest@node@getedge
        {positive}
        {\forestove{grow}}
        \noexpand\forest@temp@edge
    }%
  }\forest@temp
  \forest@pack@pgfpoint@childsposition\forest@child
  \let\forest@previous@positive@edge\pgfutil@empty
  \forest@extendpath\forest@previous@positive@edge\forest@temp@edge{}%
  \forestOget{\forest@child}{@#3}\forest@child
%    \end{macrocode}
% Loop until the current child is the null node.
%    \begin{macrocode}
  \edef\forest@previous@child@s{0pt}%
  \forest@loopb
  \unless\ifnum\forest@child=0
%    \end{macrocode}
% Get the negative edge of the child.
%    \begin{macrocode}
    \edef\forest@temp{%
      \noexpand\forest@fornode{\forest@child}{%
        \noexpand\forest@node@getedge
          {negative}
          {\forestove{grow}}
          \noexpand\forest@temp@edge
        }%
    }\forest@temp
%    \end{macrocode}
% Set |\pgf@x| and |\pgf@y| to the position of the child (in the
% coordinate system of this node).
%    \begin{macrocode}
    \forest@pack@pgfpoint@childsposition\forest@child
%    \end{macrocode}
% Translate the edge of the child by the child's position.
%    \begin{macrocode}
    \let\forest@child@negative@edge\pgfutil@empty
    \forest@extendpath\forest@child@negative@edge\forest@temp@edge{}%
%    \end{macrocode}
% Setup the grow line: the angle is given by this node's |grow|
% attribute. 
%    \begin{macrocode}
    \forest@setupgrowline{\forestove{grow}}%
%    \end{macrocode}
% Get the distance (wrt the grow line) between the positive edge of
% the previous children and the negative edge of the current
% child. (The distance can be negative!)
%    \begin{macrocode}
    \forest@distance@between@edge@paths\forest@previous@positive@edge\forest@child@negative@edge\forest@csdistance
%    \end{macrocode}
% If the distance is |\relax|, the projections of the edges onto the
% grow line don't overlap: do nothing. Otherwise, shift the current child so that its distance to the block
% of previous children is |s_sep|.
%    \begin{macrocode}
    \ifx\forest@csdistance\relax
      %\forestOeset{\forest@child}{s}{\forest@previous@child@s}%
    \else
      \advance\pgfutil@tempdimb-\forest@csdistance\relax
      \advance\pgfutil@tempdimb\forestove{s sep}\relax
      \forestOeset{\forest@child}{s}{\the\dimexpr\forestove{s}-\forest@csdistance+\forestove{s sep}}%
    \fi
%    \end{macrocode}
% Retain monotonicity (is this ok?).  (This problem arises when the adjacent children's |l| are too
% far apart.) 
%    \begin{macrocode}
    \ifdim\forestOve{\forest@child}{s}<\forest@previous@child@s\relax
      \forestOeset{\forest@child}{s}{\forest@previous@child@s}%
    \fi
%    \end{macrocode}
% Prepare for the next iteration: add the current child's positive
% edge to the positive edge of the previous children, and set up the
% next current child.
%    \begin{macrocode}
    \forestOget{\forest@child}{s}\forest@child@s
    \edef\forest@previous@child@s{\forest@child@s}%
    \edef\forest@temp{%
      \noexpand\forest@fornode{\forest@child}{%
        \noexpand\forest@node@getedge
          {positive}
          {\forestove{grow}}
          \noexpand\forest@temp@edge
      }%
    }\forest@temp
    \forest@pack@pgfpoint@childsposition\forest@child
    \forest@extendpath\forest@previous@positive@edge\forest@temp@edge{}%
    \forest@getpositivetightedgeofpath\forest@previous@positive@edge\forest@previous@positive@edge
    \forestOget{\forest@child}{@#3}\forest@child
  \forest@repeatb
%    \end{macrocode}
% Shift the position of all children to achieve the desired alignment
% of the parent and its children.
%    \begin{macrocode}
  \csname forest@calign@\forestove{calign}\endcsname
}
%    \end{macrocode}
% Get the position of child |#1| in the current node, in node's l-s
% coordinate system.
%    \begin{macrocode}
\def\forest@pack@pgfpoint@childsposition#1{%
  {%
    \pgftransformreset
    \pgftransformrotate{\forestove{grow}}%
    \forest@fornode{#1}{%
      \pgfpointtransformed{\pgfqpoint{\forestove{l}}{\forestove{s}}}%
    }%
  }%
}
%    \end{macrocode}
% Get the position of the node in the grow (|#1|)-rotated coordinate
% system.
%    \begin{macrocode}
\def\forest@pack@pgfpoint@positioningrow#1{%
  {%
    \pgftransformreset
    \pgftransformrotate{#1}%
    \pgfpointtransformed{\pgfqpoint{\forestove{l}}{\forestove{s}}}%
  }%
}
%    \end{macrocode}
%    
% Child alignment.
%    \begin{macrocode}
\def\forest@calign@s@shift#1{%
  \pgfutil@tempdima=#1\relax
  \forest@node@foreachchild{%
    \forestoeset{s}{\the\dimexpr\forestove{s}+\pgfutil@tempdima}%
  }%
}
\def\forest@calign@child{%
  \forest@calign@s@shift{-\forestOve{\forest@node@nornbarthchildid{\forestove{calign primary child}}}{s}}%
}
\csdef{forest@calign@child edge}{%
  {%
    \edef\forest@temp@child{\forest@node@nornbarthchildid{\forestove{calign primary child}}}%
    \pgftransformreset
    \pgftransformrotate{\forestove{grow}}%
    \pgfpointtransformed{\pgfqpoint{\forestOve{\forest@temp@child}{l}}{\forestOve{\forest@temp@child}{s}}}%
    \pgf@xa=\pgf@x\relax\pgf@ya=\pgf@y\relax
    \forestOve{\forest@temp@child}{child@anchor}%
    \advance\pgf@xa\pgf@x\relax\advance\pgf@ya\pgf@y\relax
    \forestove{parent@anchor}%
    \advance\pgf@xa-\pgf@x\relax\advance\pgf@ya-\pgf@y\relax
    \edef\forest@marshal{%
      \noexpand\pgftransformreset
      \noexpand\pgftransformrotate{-\forestove{grow}}%
      \noexpand\pgfpointtransformed{\noexpand\pgfqpoint{\the\pgf@xa}{\the\pgf@ya}}%
    }\forest@marshal
  }%
  \forest@calign@s@shift{\the\dimexpr-\the\pgf@y}%
}
\csdef{forest@calign@midpoint}{%
  \forest@calign@s@shift{\the\dimexpr 0pt -%
    (\forestOve{\forest@node@nornbarthchildid{\forestove{calign primary child}}}{s}%
    +\forestOve{\forest@node@nornbarthchildid{\forestove{calign secondary child}}}{s}%
    )/2\relax
  }%
}
\csdef{forest@calign@edge midpoint}{%
  {%
    \edef\forest@temp@firstchild{\forest@node@nornbarthchildid{\forestove{calign primary child}}}%
    \edef\forest@temp@secondchild{\forest@node@nornbarthchildid{\forestove{calign secondary child}}}%
    \pgftransformreset
    \pgftransformrotate{\forestove{grow}}%
    \pgfpointtransformed{\pgfqpoint{\forestOve{\forest@temp@firstchild}{l}}{\forestOve{\forest@temp@firstchild}{s}}}%
    \pgf@xa=\pgf@x\relax\pgf@ya=\pgf@y\relax
    \forestOve{\forest@temp@firstchild}{child@anchor}%
    \advance\pgf@xa\pgf@x\relax\advance\pgf@ya\pgf@y\relax
    \edef\forest@marshal{%
      \noexpand\pgfpointtransformed{\noexpand\pgfqpoint{\forestOve{\forest@temp@secondchild}{l}}{\forestOve{\forest@temp@secondchild}{s}}}%
    }\forest@marshal
    \advance\pgf@xa\pgf@x\relax\advance\pgf@ya\pgf@y\relax
    \forestOve{\forest@temp@secondchild}{child@anchor}%
    \advance\pgf@xa\pgf@x\relax\advance\pgf@ya\pgf@y\relax
    \divide\pgf@xa2 \divide\pgf@ya2
    \edef\forest@marshal{%
      \noexpand\pgftransformreset
      \noexpand\pgftransformrotate{-\forestove{grow}}%
      \noexpand\pgfpointtransformed{\noexpand\pgfqpoint{\the\pgf@xa}{\the\pgf@ya}}%
    }\forest@marshal
  }%
  \forest@calign@s@shift{\the\dimexpr-\the\pgf@y}%
}
%    \end{macrocode}
% Aligns the children to the center of the angles given by the options
% |calign_first_angle| and |calign_second_angle| and spreads them additionally if needed to fill the
% whole 
% space determined by the option.  The version |fixed_angles| calculates the
% angles between node anchors; the version |fixes_edge_angles| calculates the angles between the
% node edges. 
%    \begin{macrocode}
\csdef{forest@calign@fixed angles}{%
  \edef\forest@ca@first@child{\forest@node@nornbarthchildid{\forestove{calign primary child}}}%
  \edef\forest@ca@second@child{\forest@node@nornbarthchildid{\forestove{calign secondary child}}}%
  \ifnum\forestove{reversed}=1
    \let\forest@temp\forest@ca@first@child
    \let\forest@ca@first@child\forest@ca@second@child
    \let\forest@ca@second@child\forest@temp
  \fi
  \forestOget{\forest@ca@first@child}{l}\forest@ca@first@l
  \forestOget{\forest@ca@second@child}{l}\forest@ca@second@l
  \pgfmathsetlengthmacro\forest@ca@desired@s@distance{%
    tan(\forestove{calign secondary angle})*\forest@ca@second@l
    -tan(\forestove{calign primary angle})*\forest@ca@first@l
  }%
  \forestOget{\forest@ca@first@child}{s}\forest@ca@first@s
  \forestOget{\forest@ca@second@child}{s}\forest@ca@second@s
  \pgfmathsetlengthmacro\forest@ca@actual@s@distance{%
    \forest@ca@second@s-\forest@ca@first@s}%
  \ifdim\forest@ca@desired@s@distance>\forest@ca@actual@s@distance\relax
    \ifdim\forest@ca@actual@s@distance=0pt
      \pgfmathsetlength\pgfutil@tempdima{tan(\forestove{calign primary angle})*\forest@ca@second@l}%
      \pgfmathsetlength\pgfutil@tempdimb{\forest@ca@desired@s@distance/(\forestove{n children}-1)}%
      \forest@node@foreachchild{%
        \forestoeset{s}{\the\pgfutil@tempdima}%
        \advance\pgfutil@tempdima\pgfutil@tempdimb
      }%
      \def\forest@calign@anchor{0pt}%
    \else
      \pgfmathsetmacro\forest@ca@ratio{%
        \forest@ca@desired@s@distance/\forest@ca@actual@s@distance}%
      \forest@node@foreachchild{%
        \pgfmathsetlengthmacro\forest@temp{\forest@ca@ratio*\forestove{s}}%
        \forestolet{s}\forest@temp
      }%
      \pgfmathsetlengthmacro\forest@calign@anchor{%
        -tan(\forestove{calign primary angle})*\forest@ca@first@l}%
    \fi
  \else
    \ifdim\forest@ca@desired@s@distance<\forest@ca@actual@s@distance\relax
      \pgfmathsetlengthmacro\forest@ca@ratio{%
        \forest@ca@actual@s@distance/\forest@ca@desired@s@distance}%
      \forest@node@foreachchild{%
        \pgfmathsetlengthmacro\forest@temp{\forest@ca@ratio*\forestove{l}}%
        \forestolet{l}\forest@temp
      }%
      \forestOget{\forest@ca@first@child}{l}\forest@ca@first@l
      \pgfmathsetlengthmacro\forest@calign@anchor{%
        -tan(\forestove{calign primary angle})*\forest@ca@first@l}%
    \fi
  \fi
  \forest@calign@s@shift{-\forest@calign@anchor}%
}
\csdef{forest@calign@fixed edge angles}{%
  \edef\forest@ca@first@child{\forest@node@nornbarthchildid{\forestove{calign primary child}}}%
  \edef\forest@ca@second@child{\forest@node@nornbarthchildid{\forestove{calign secondary child}}}%
  \ifnum\forestove{reversed}=1
    \let\forest@temp\forest@ca@first@child
    \let\forest@ca@first@child\forest@ca@second@child
    \let\forest@ca@second@child\forest@temp
  \fi
  \forestOget{\forest@ca@first@child}{l}\forest@ca@first@l
  \forestOget{\forest@ca@second@child}{l}\forest@ca@second@l
  \forestoget{parent@anchor}\forest@ca@parent@anchor
  \forest@ca@parent@anchor
  \edef\forest@ca@parent@anchor@s{\the\pgf@x}%
  \edef\forest@ca@parent@anchor@l{\the\pgf@y}%
  \forestOget{\forest@ca@first@child}{child@anchor}\forest@ca@first@child@anchor
  \forest@ca@first@child@anchor
  \edef\forest@ca@first@child@anchor@s{\the\pgf@x}%
  \edef\forest@ca@first@child@anchor@l{\the\pgf@y}%
  \forestOget{\forest@ca@second@child}{child@anchor}\forest@ca@second@child@anchor
  \forest@ca@second@child@anchor
  \edef\forest@ca@second@child@anchor@s{\the\pgf@x}%
  \edef\forest@ca@second@child@anchor@l{\the\pgf@y}%
  \pgfmathsetlengthmacro\forest@ca@desired@second@edge@s{tan(\forestove{calign secondary angle})*%
    (\forest@ca@second@l-\forest@ca@second@child@anchor@l+\forest@ca@parent@anchor@l)}%
  \pgfmathsetlengthmacro\forest@ca@desired@first@edge@s{tan(\forestove{calign primary angle})*%
    (\forest@ca@first@l-\forest@ca@first@child@anchor@l+\forest@ca@parent@anchor@l)}
  \pgfmathsetlengthmacro\forest@ca@desired@s@distance{\forest@ca@desired@second@edge@s-\forest@ca@desired@first@edge@s}%
  \forestOget{\forest@ca@first@child}{s}\forest@ca@first@s
  \forestOget{\forest@ca@second@child}{s}\forest@ca@second@s
  \pgfmathsetlengthmacro\forest@ca@actual@s@distance{%
    \forest@ca@second@s+\forest@ca@second@child@anchor@s
    -\forest@ca@first@s-\forest@ca@first@child@anchor@s}%
  \ifdim\forest@ca@desired@s@distance>\forest@ca@actual@s@distance\relax
    \ifdim\forest@ca@actual@s@distance=0pt
      \forestoget{n children}\forest@temp@n@children
      \forest@node@foreachchild{%
        \forestoget{child@anchor}\forest@temp@child@anchor
        \forest@temp@child@anchor
        \edef\forest@temp@child@anchor@s{\the\pgf@x}%
        \pgfmathsetlengthmacro\forest@temp{%
          \forest@ca@desired@first@edge@s+(\forestove{n}-1)*\forest@ca@desired@s@distance/(\forest@temp@n@children-1)+\forest@ca@first@child@anchor@s-\forest@temp@child@anchor@s}%
        \forestolet{s}\forest@temp
      }%
      \def\forest@calign@anchor{0pt}%
    \else
      \pgfmathsetmacro\forest@ca@ratio{%
        \forest@ca@desired@s@distance/\forest@ca@actual@s@distance}%
      \forest@node@foreachchild{%
        \forestoget{child@anchor}\forest@temp@child@anchor
        \forest@temp@child@anchor
        \edef\forest@temp@child@anchor@s{\the\pgf@x}%
        \pgfmathsetlengthmacro\forest@temp{%
          \forest@ca@ratio*(%
            \forestove{s}-\forest@ca@first@s
            +\forest@temp@child@anchor@s-\forest@ca@first@child@anchor@s)%
          +\forest@ca@first@s
          +\forest@ca@first@child@anchor@s-\forest@temp@child@anchor@s}%
        \forestolet{s}\forest@temp
      }%
      \pgfmathsetlengthmacro\forest@calign@anchor{%
        -tan(\forestove{calign primary angle})*(\forest@ca@first@l-\forest@ca@first@child@anchor@l+\forest@ca@parent@anchor@l)%
        +\forest@ca@first@child@anchor@s-\forest@ca@parent@anchor@s
      }%
    \fi
  \else
    \ifdim\forest@ca@desired@s@distance<\forest@ca@actual@s@distance\relax
      \pgfmathsetlengthmacro\forest@ca@ratio{%
        \forest@ca@actual@s@distance/\forest@ca@desired@s@distance}%
      \forest@node@foreachchild{%
        \forestoget{child@anchor}\forest@temp@child@anchor
        \forest@temp@child@anchor
        \edef\forest@temp@child@anchor@l{\the\pgf@y}%
        \pgfmathsetlengthmacro\forest@temp{%
          \forest@ca@ratio*(%
            \forestove{l}+\forest@ca@parent@anchor@l-\forest@temp@child@anchor@l)
            -\forest@ca@parent@anchor@l+\forest@temp@child@anchor@l}%
        \forestolet{l}\forest@temp
      }%
      \forestOget{\forest@ca@first@child}{l}\forest@ca@first@l
      \pgfmathsetlengthmacro\forest@calign@anchor{%
        -tan(\forestove{calign primary angle})*(\forest@ca@first@l+\forest@ca@parent@anchor@l-\forest@temp@child@anchor@l)%
        +\forest@ca@first@child@anchor@s-\forest@ca@parent@anchor@s
      }%
    \fi
  \fi
  \forest@calign@s@shift{-\forest@calign@anchor}%
}
%    \end{macrocode}
%
% Get edge: |#1| = |positive|/|negative|, |#2| = grow (in degrees), |#3| = the control
% sequence receiving the resulting path.  The edge is taken from the
% cache (attribute |#1@edge@#2|) if possible; otherwise, both
% positive and negative edge are computed and stored in the cache.
%    \begin{macrocode}
\def\forest@node@getedge#1#2#3{%
  \forestoget{#1@edge@#2}#3%
  \ifx#3\relax
    \forest@node@foreachchild{%
      \forest@node@getedge{#1}{#2}{\forest@temp@edge}%
    }%
    \forest@forthis{\forest@node@getedges{#2}}%
    \forestoget{#1@edge@#2}#3%
  \fi
}
%    \end{macrocode}
% Get edges. |#1| = grow (in degrees).  The result is stored in
% attributes |negative@edge@#1| and |positive@edge@#1|.  This method
% expects that the children's edges are already cached.
%    \begin{macrocode}
\def\forest@node@getedges#1{%
%    \end{macrocode}
% Run the computation in a \TeX\ group.
%    \begin{macrocode}
  %{%
%    \end{macrocode}
% Setup the grow line.
%    \begin{macrocode}
    \forest@setupgrowline{#1}%
%    \end{macrocode}
% Get the edge of the node itself.
%    \begin{macrocode}
    \ifnum\forestove{ignore}=0
      \forestoget{boundary}\forest@node@boundary
    \else
      \def\forest@node@boundary{}%
    \fi
    \csname forest@getboth\forestove{fit}edgesofpath\endcsname
        \forest@node@boundary\forest@negative@node@edge\forest@positive@node@edge
    \forestolet{negative@edge@#1}\forest@negative@node@edge
    \forestolet{positive@edge@#1}\forest@positive@node@edge
%    \end{macrocode}
% Add the edges of the children.
%    \begin{macrocode}
    \get@edges@merge{negative}{#1}%
    \get@edges@merge{positive}{#1}%
  %}%
}
%    \end{macrocode}
% Merge the |#1| (=|negative| or |positive|) edge of the node with
% |#1| edges of the children. |#2| = grow angle.
%    \begin{macrocode}
\def\get@edges@merge#1#2{%
  \ifnum\forestove{n children}>0
    \forestoget{#1@edge@#2}\forest@node@edge
%    \end{macrocode}
% Remember the node's |parent anchor| and add it to the path (for breaking).
%    \begin{macrocode}
    \forestove{parent@anchor}%
    \edef\forest@getedge@pa@l{\the\pgf@x}%
    \edef\forest@getedge@pa@s{\the\pgf@y}%
    \eappto\forest@node@edge{\noexpand\pgfsyssoftpath@movetotoken{\forest@getedge@pa@l}{\forest@getedge@pa@s}}%
%    \end{macrocode}
% Switch to this node's |(l,s)| coordinate system (origin at the
% node's anchor).
%    \begin{macrocode}
    \pgftransformreset
    \pgftransformrotate{\forestove{grow}}%
%    \end{macrocode}
% Get the child's (cached) edge, translate it by the child's position,
% and add it to the path holding all edges.  Also add the edge from parent to the child to the path.
% This gets complicated when the child and/or parent anchor is empty, i.e.\ automatic border: we can
% get self-intersecting paths.  So we store all the parent--child edges to a safe place first,
% compute all the possible breaking points (i.e.\ all the points in node@edge path), and break the
% parent--child edges on these points.
%    \begin{macrocode}
    \def\forest@all@edges{}%
    \forest@node@foreachchild{%
      \forestoget{#1@edge@#2}\forest@temp@edge
      \pgfpointtransformed{\pgfqpoint{\forestove{l}}{\forestove{s}}}%
      \forest@extendpath\forest@node@edge\forest@temp@edge{}%
      \ifnum\forestove{ignore edge}=0
        \pgfpointadd
          {\pgfpointtransformed{\pgfqpoint{\forestove{l}}{\forestove{s}}}}%
          {\forestove{child@anchor}}%
        \pgfgetlastxy{\forest@getedge@ca@l}{\forest@getedge@ca@s}%
        \eappto\forest@all@edges{%
          \noexpand\pgfsyssoftpath@movetotoken{\forest@getedge@pa@l}{\forest@getedge@pa@s}%
          \noexpand\pgfsyssoftpath@linetotoken{\forest@getedge@ca@l}{\forest@getedge@ca@s}%
        }%
        % this deals with potential overlap of the edges:
        \eappto\forest@node@edge{\noexpand\pgfsyssoftpath@movetotoken{\forest@getedge@ca@l}{\forest@getedge@ca@s}}%
      \fi
    }%
    \ifdefempty{\forest@all@edges}{}{%
      \pgfintersectionofpaths{\pgfsetpath\forest@all@edges}{\pgfsetpath\forest@node@edge}%
      \def\forest@edgenode@intersections{}%
      \forest@merge@intersectionloop
      \eappto\forest@node@edge{\expandonce{\forest@all@edges}\expandonce{\forest@edgenode@intersections}}%
    }%
%    \end{macrocode}
% Process the path into an edge and store the edge.
%    \begin{macrocode}
    \csname forest@get#1\forestove{fit}edgeofpath\endcsname\forest@node@edge\forest@node@edge
    \forestolet{#1@edge@#2}\forest@node@edge
  \fi
}
\newloop\forest@merge@loop
\def\forest@merge@intersectionloop{%
  \c@pgf@counta=0
  \forest@merge@loop
  \ifnum\c@pgf@counta<\pgfintersectionsolutions\relax
    \advance\c@pgf@counta1
    \pgfpointintersectionsolution{\the\c@pgf@counta}%
    \eappto\forest@edgenode@intersections{\noexpand\pgfsyssoftpath@movetotoken
      {\the\pgf@x}{\the\pgf@y}}%
  \forest@merge@repeat
}
%    \end{macrocode}
% 
% Get the bounding rectangle of the node (without descendants). |#1| =
% grow.
%    \begin{macrocode}
\def\forest@node@getboundingrectangle@ls#1{%
  \forestoget{boundary}\forest@node@boundary
  \forest@path@getboundingrectangle@ls\forest@node@boundary{#1}%
}
%    \end{macrocode}
%
% Applies the current coordinate transformation to the points in the
% path |#1|. Returns via the current path (so that the coordinate
% transformation can be set up as local).
%    \begin{macrocode}
\def\forest@pgfpathtransformed#1{%
  \forest@save@pgfsyssoftpath@tokendefs
  \let\pgfsyssoftpath@movetotoken\forest@pgfpathtransformed@moveto
  \let\pgfsyssoftpath@linetotoken\forest@pgfpathtransformed@lineto
  \pgfsyssoftpath@setcurrentpath\pgfutil@empty
  #1%
  \forest@restore@pgfsyssoftpath@tokendefs
}
\def\forest@pgfpathtransformed@moveto#1#2{%
  \forest@pgfpathtransformed@op\pgfsyssoftpath@moveto{#1}{#2}%
}
\def\forest@pgfpathtransformed@lineto#1#2{%
  \forest@pgfpathtransformed@op\pgfsyssoftpath@lineto{#1}{#2}%
}
\def\forest@pgfpathtransformed@op#1#2#3{%
  \pgfpointtransformed{\pgfqpoint{#2}{#3}}%
  \edef\forest@temp{%
    \noexpand#1{\the\pgf@x}{\the\pgf@y}%
  }%
  \forest@temp
}
%    \end{macrocode}
%
% \subsubsection{Tiers}
% 
% Compute tiers to be aligned at a node. The result in saved in
% attribute |@tiers|.
%    \begin{macrocode}
\def\forest@pack@computetiers{%
  {%
    \forest@pack@tiers@getalltiersinsubtree
    \forest@pack@tiers@computetierhierarchy
    \forest@pack@tiers@findcontainers
    \forest@pack@tiers@raisecontainers
    \forest@pack@tiers@computeprocessingorder
    \gdef\forest@smuggle{}%
    \forest@pack@tiers@write
  }%
  \forest@node@foreach{\forestoset{@tiers}{}}%
  \forest@smuggle
}
%    \end{macrocode}
% Puts all tiers contained in the subtree into attribute
% |tiers|.  
%    \begin{macrocode}
\def\forest@pack@tiers@getalltiersinsubtree{%
  \ifnum\forestove{n children}>0
    \forest@node@foreachchild{\forest@pack@tiers@getalltiersinsubtree}%
  \fi
  \forestoget{tier}\forest@temp@mytier
  \def\forest@temp@mytiers{}%
  \ifdefempty\forest@temp@mytier{}{%
    \listeadd\forest@temp@mytiers\forest@temp@mytier
  }%
  \ifnum\forestove{n children}>0
    \forest@node@foreachchild{%
      \forestoget{tiers}\forest@temp@tiers
      \forlistloop\forest@pack@tiers@forhandlerA\forest@temp@tiers          
    }%
  \fi
  \forestolet{tiers}\forest@temp@mytiers
}
\def\forest@pack@tiers@forhandlerA#1{%
  \ifinlist{#1}\forest@temp@mytiers{}{%
    \listeadd\forest@temp@mytiers{#1}%
  }%
}
%    \end{macrocode}
% Compute a set of higher and lower tiers for each tier.  Tier A is
% higher than tier B iff a node on tier A is an ancestor of a
% node on tier B.
%    \begin{macrocode}
\def\forest@pack@tiers@computetierhierarchy{%
  \def\forest@tiers@ancestors{}%
  \forestoget{tiers}\forest@temp@mytiers
  \forlistloop\forest@pack@tiers@cth@init\forest@temp@mytiers
  \forest@pack@tiers@computetierhierarchy@
}
\def\forest@pack@tiers@cth@init#1{%
  \csdef{forest@tiers@higher@#1}{}%
  \csdef{forest@tiers@lower@#1}{}%
}
\def\forest@pack@tiers@computetierhierarchy@{%
  \forestoget{tier}\forest@temp@mytier
  \ifdefempty\forest@temp@mytier{}{%
    \forlistloop\forest@pack@tiers@forhandlerB\forest@tiers@ancestors
    \listeadd\forest@tiers@ancestors\forest@temp@mytier
  }%
  \forest@node@foreachchild{%
    \forest@pack@tiers@computetierhierarchy@
  }%
  \forestoget{tier}\forest@temp@mytier
  \ifdefempty\forest@temp@mytier{}{%
    \forest@listedel\forest@tiers@ancestors\forest@temp@mytier
  }%
}
\def\forest@pack@tiers@forhandlerB#1{%
  \def\forest@temp@tier{#1}%
  \ifx\forest@temp@tier\forest@temp@mytier
    \PackageError{forest}{Circular tier hierarchy (tier \forest@temp@mytier)}{}%
  \fi
  \ifinlistcs{#1}{forest@tiers@higher@\forest@temp@mytier}{}{%
    \listcsadd{forest@tiers@higher@\forest@temp@mytier}{#1}}%
  \xifinlistcs\forest@temp@mytier{forest@tiers@lower@#1}{}{%
    \listcseadd{forest@tiers@lower@#1}{\forest@temp@mytier}}%
}
\def\forest@pack@tiers@findcontainers{%
  \forestoget{tiers}\forest@temp@tiers
  \forlistloop\forest@pack@tiers@findcontainer\forest@temp@tiers
}
\def\forest@pack@tiers@findcontainer#1{%
  \def\forest@temp@tier{#1}%
  \forestoget{tier}\forest@temp@mytier
  \ifx\forest@temp@tier\forest@temp@mytier
    \csedef{forest@tiers@container@#1}{\forest@cn}%
  \else\@escapeif{%
    \forest@pack@tiers@findcontainerA{#1}%
  }\fi%
}
\def\forest@pack@tiers@findcontainerA#1{%
  \c@pgf@counta=0
  \forest@node@foreachchild{%
    \forestoget{tiers}\forest@temp@tiers
    \ifinlist{#1}\forest@temp@tiers{%
      \advance\c@pgf@counta 1
      \let\forest@temp@child\forest@cn
    }{}%
  }%
  \ifnum\c@pgf@counta>1
    \csedef{forest@tiers@container@#1}{\forest@cn}%
  \else\@escapeif{% surely =1
    \forest@fornode{\forest@temp@child}{%
      \forest@pack@tiers@findcontainer{#1}%
    }%
  }\fi
}
\def\forest@pack@tiers@raisecontainers{%
  \forestoget{tiers}\forest@temp@mytiers
  \forlistloop\forest@pack@tiers@rc@forhandlerA\forest@temp@mytiers
}
\def\forest@pack@tiers@rc@forhandlerA#1{%
  \edef\forest@tiers@temptier{#1}%
  \letcs\forest@tiers@containernodeoftier{forest@tiers@container@#1}%
  \letcs\forest@temp@lowertiers{forest@tiers@lower@#1}%
  \forlistloop\forest@pack@tiers@rc@forhandlerB\forest@temp@lowertiers
}
\def\forest@pack@tiers@rc@forhandlerB#1{%
  \letcs\forest@tiers@containernodeoflowertier{forest@tiers@container@#1}%
  \forestOget{\forest@tiers@containernodeoflowertier}{content}\lowercontent
  \forestOget{\forest@tiers@containernodeoftier}{content}\uppercontent
  \forest@fornode{\forest@tiers@containernodeoflowertier}{%
    \forest@ifancestorof
      {\forest@tiers@containernodeoftier}
      {\csletcs{forest@tiers@container@\forest@tiers@temptier}{forest@tiers@container@#1}}%
      {}%
  }%
}
\def\forest@pack@tiers@computeprocessingorder{%
  \def\forest@tiers@processingorder{}%
  \forestoget{tiers}\forest@tiers@cpo@tierstodo
  \forest@loopa
    \ifdefempty\forest@tiers@cpo@tierstodo{\forest@tempfalse}{\forest@temptrue}%
  \ifforest@temp
    \def\forest@tiers@cpo@tiersremaining{}%
    \def\forest@tiers@cpo@tiersindependent{}%
    \forlistloop\forest@pack@tiers@cpo@forhandlerA\forest@tiers@cpo@tierstodo
    \ifdefempty\forest@tiers@cpo@tiersindependent{%
      \PackageError{forest}{Circular tiers!}{}}{}%
    \forlistloop\forest@pack@tiers@cpo@forhandlerB\forest@tiers@cpo@tiersremaining
    \let\forest@tiers@cpo@tierstodo\forest@tiers@cpo@tiersremaining
  \forest@repeata
}
\def\forest@pack@tiers@cpo@forhandlerA#1{%
  \ifcsempty{forest@tiers@higher@#1}{%
    \listadd\forest@tiers@cpo@tiersindependent{#1}%
    \listadd\forest@tiers@processingorder{#1}%
  }{%
    \listadd\forest@tiers@cpo@tiersremaining{#1}%
  }%
}
\def\forest@pack@tiers@cpo@forhandlerB#1{%
  \def\forest@pack@tiers@cpo@aremainingtier{#1}%
  \forlistloop\forest@pack@tiers@cpo@forhandlerC\forest@tiers@cpo@tiersindependent
}
\def\forest@pack@tiers@cpo@forhandlerC#1{%
  \ifinlistcs{#1}{forest@tiers@higher@\forest@pack@tiers@cpo@aremainingtier}{%
    \forest@listcsdel{forest@tiers@higher@\forest@pack@tiers@cpo@aremainingtier}{#1}%
  }{}%
}
\def\forest@pack@tiers@write{%
  \forlistloop\forest@pack@tiers@write@forhandler\forest@tiers@processingorder
}
\def\forest@pack@tiers@write@forhandler#1{%
  \forest@fornode{\csname forest@tiers@container@#1\endcsname}{%
    \forest@pack@tiers@check{#1}%
  }%
  \xappto\forest@smuggle{%
    \noexpand\listadd
      \forestOm{\csname forest@tiers@container@#1\endcsname}{@tiers}%
      {#1}%
  }%
}
 % checks if the tier is compatible with growth changes and calign=node/edge angle
\def\forest@pack@tiers@check#1{%
  \def\forest@temp@currenttier{#1}%
  \forest@node@foreachdescendant{%
    \ifnum\forestove{grow}=\forestOve{\forestove{@parent}}{grow}
    \else
      \forest@pack@tiers@check@grow
    \fi
    \ifnum\forestove{n children}>1
      \forestoget{calign}\forest@temp
      \ifx\forest@temp\forest@pack@tiers@check@nodeangle
        \forest@pack@tiers@check@calign
      \fi
      \ifx\forest@temp\forest@pack@tiers@check@edgeangle
        \forest@pack@tiers@check@calign
      \fi
    \fi
  }%
}
\def\forest@pack@tiers@check@nodeangle{node angle}%
\def\forest@pack@tiers@check@edgeangle{edge angle}%
\def\forest@pack@tiers@check@grow{%
  \forestoget{content}\forest@temp@content
  \let\forest@temp@currentnode\forest@cn
  \forest@node@foreachdescendant{%
    \forestoget{tier}\forest@temp
    \ifx\forest@temp@currenttier\forest@temp
      \forest@pack@tiers@check@grow@error
    \fi
  }%
}
\def\forest@pack@tiers@check@grow@error{%
  \PackageError{forest}{Tree growth direction changes in node \forest@temp@currentnode\space
    (content: \forest@temp@content), while tier '\forest@temp' is specified for nodes both
    out- and inside the subtree rooted in node \forest@temp@currentnode.  This will not work.}{}%
}
\def\forest@pack@tiers@check@calign{%
  \forest@node@foreachchild{%
    \forestoget{tier}\forest@temp
    \ifx\forest@temp@currenttier\forest@temp
      \forest@pack@tiers@check@calign@warning
    \fi
  }%
}
\def\forest@pack@tiers@check@calign@warning{%
  \PackageWarning{forest}{Potential option conflict: node \forestove{@parent} (content:
    '\forestOve{\forestove{@parent}}{content}') was given 'calign=\forestove{calign}', while its
    child \forest@cn\space (content: '\forestove{content}') was given 'tier=\forestove{tier}'.
    The parent's 'calign' will only work if the child was the lowest node on its tier before the
    alignment.}{} 
}
%    \end{macrocode}
%
%
% \subsubsection{Node boundary}
%
% Compute the node boundary: it will be put in the pgf's current path.  The computation is done
% within a generic anchor so that the shape's saved anchors and macros are available.
%    \begin{macrocode}
\pgfdeclaregenericanchor{forestcomputenodeboundary}{%
  \letcs\forest@temp@boundary@macro{forest@compute@node@boundary@#1}%
  \ifcsname forest@compute@node@boundary@#1\endcsname
    \csname forest@compute@node@boundary@#1\endcsname
  \else
    \forest@compute@node@boundary@rectangle
  \fi
  \pgfsyssoftpath@getcurrentpath\forest@temp
  \global\let\forest@global@boundary\forest@temp
}
\def\forest@mt#1{%
  \expandafter\pgfpointanchor\expandafter{\pgfreferencednodename}{#1}%
  \pgfsyssoftpath@moveto{\the\pgf@x}{\the\pgf@y}%
}%
\def\forest@lt#1{%
  \expandafter\pgfpointanchor\expandafter{\pgfreferencednodename}{#1}%
  \pgfsyssoftpath@lineto{\the\pgf@x}{\the\pgf@y}%
}%
\def\forest@compute@node@boundary@coordinate{%
  \forest@mt{center}%
}
\def\forest@compute@node@boundary@circle{%
  \forest@mt{east}%
  \forest@lt{north east}%
  \forest@lt{north}%
  \forest@lt{north west}%
  \forest@lt{west}%
  \forest@lt{south west}%
  \forest@lt{south}%
  \forest@lt{south east}%
  \forest@lt{east}%
}
\def\forest@compute@node@boundary@rectangle{%
  \forest@mt{south west}%
  \forest@lt{south east}%
  \forest@lt{north east}%
  \forest@lt{north west}%
  \forest@lt{south west}%
}
\def\forest@compute@node@boundary@diamond{%
  \forest@mt{east}%
  \forest@lt{north}%
  \forest@lt{west}%
  \forest@lt{south}%
  \forest@lt{east}%
}
\let\forest@compute@node@boundary@ellipse\forest@compute@node@boundary@circle
\def\forest@compute@node@boundary@trapezium{%
  \forest@mt{top right corner}%
  \forest@lt{top left corner}%
  \forest@lt{bottom left corner}%
  \forest@lt{bottom right corner}%
  \forest@lt{top right corner}%
}
\def\forest@compute@node@boundary@semicircle{%
  \forest@mt{arc start}%
  \forest@lt{north}%
  \forest@lt{east}%
  \forest@lt{north east}%
  \forest@lt{apex}%
  \forest@lt{north west}%
  \forest@lt{west}%
  \forest@lt{arc end}%
  \forest@lt{arc start}%
}
\newloop\forest@computenodeboundary@loop
\csdef{forest@compute@node@boundary@regular polygon}{%
  \forest@mt{corner 1}%
  \c@pgf@counta=\sides\relax
  \forest@computenodeboundary@loop
  \ifnum\c@pgf@counta>0
    \forest@lt{corner \the\c@pgf@counta}%
    \advance\c@pgf@counta-1
  \forest@computenodeboundary@repeat
}%
\def\forest@compute@node@boundary@star{%
  \forest@mt{outer point 1}%
  \c@pgf@counta=\totalstarpoints\relax
  \divide\c@pgf@counta2
  \forest@computenodeboundary@loop
  \ifnum\c@pgf@counta>0
    \forest@lt{inner point \the\c@pgf@counta}%
    \forest@lt{outer point \the\c@pgf@counta}%
    \advance\c@pgf@counta-1
  \forest@computenodeboundary@repeat  
}%
\csdef{forest@compute@node@boundary@isosceles triangle}{%
  \forest@mt{apex}%
  \forest@lt{left corner}%
  \forest@lt{right corner}%
  \forest@lt{apex}%
}
\def\forest@compute@node@boundary@kite{%
  \forest@mt{upper vertex}%
  \forest@lt{left vertex}%
  \forest@lt{lower vertex}%
  \forest@lt{right vertex}%
  \forest@lt{upper vertex}%
}
\def\forest@compute@node@boundary@dart{%
  \forest@mt{tip}%
  \forest@lt{left tail}%
  \forest@lt{tail center}%
  \forest@lt{right tail}%
  \forest@lt{tip}%
}
\csdef{forest@compute@node@boundary@circular sector}{%
  \forest@mt{sector center}%
  \forest@lt{arc start}%
  \forest@lt{arc center}%
  \forest@lt{arc end}%
  \forest@lt{sector center}%
}  
\def\forest@compute@node@boundary@cylinder{%
  \forest@mt{top}%
  \forest@lt{after top}%
  \forest@lt{before bottom}%
  \forest@lt{bottom}%
  \forest@lt{after bottom}%
  \forest@lt{before top}%
  \forest@lt{top}%
}
\cslet{forest@compute@node@boundary@forbidden sign}\forest@compute@node@boundary@circle
\cslet{forest@compute@node@boundary@magnifying glass}\forest@compute@node@boundary@circle
\def\forest@compute@node@boundary@cloud{%
  \getradii
  \forest@mt{puff 1}%
  \c@pgf@counta=\puffs\relax
  \forest@computenodeboundary@loop
  \ifnum\c@pgf@counta>0
    \forest@lt{puff \the\c@pgf@counta}%
    \advance\c@pgf@counta-1
  \forest@computenodeboundary@repeat  
}
\def\forest@compute@node@boundary@starburst{
  \calculatestarburstpoints
  \forest@mt{outer point 1}%
  \c@pgf@counta=\totalpoints\relax
  \divide\c@pgf@counta2
  \forest@computenodeboundary@loop
  \ifnum\c@pgf@counta>0
    \forest@lt{inner point \the\c@pgf@counta}%
    \forest@lt{outer point \the\c@pgf@counta}%
    \advance\c@pgf@counta-1
  \forest@computenodeboundary@repeat  
}%
\def\forest@compute@node@boundary@signal{%
  \forest@mt{east}%
  \forest@lt{south east}%
  \forest@lt{south west}%
  \forest@lt{west}%
  \forest@lt{north west}%
  \forest@lt{north east}%
  \forest@lt{east}%
}
\def\forest@compute@node@boundary@tape{%
  \forest@mt{north east}%
  \forest@lt{60}%
  \forest@lt{north}%
  \forest@lt{120}%
  \forest@lt{north west}%
  \forest@lt{south west}%
  \forest@lt{240}%
  \forest@lt{south}%
  \forest@lt{310}%
  \forest@lt{south east}%
  \forest@lt{north east}%
}
\csdef{forest@compute@node@boundary@single arrow}{%
  \forest@mt{tip}%
  \forest@lt{after tip}%
  \forest@lt{after head}%
  \forest@lt{before tail}%
  \forest@lt{after tail}%
  \forest@lt{before head}%
  \forest@lt{before tip}%
  \forest@lt{tip}%
}
\csdef{forest@compute@node@boundary@double arrow}{%
  \forest@mt{tip 1}%
  \forest@lt{after tip 1}%
  \forest@lt{after head 1}%
  \forest@lt{before head 2}%
  \forest@lt{before tip 2}%
  \forest@mt{tip 2}%
  \forest@lt{after tip 2}%
  \forest@lt{after head 2}%
  \forest@lt{before head 1}%
  \forest@lt{before tip 1}%
  \forest@lt{tip 1}%
}
\csdef{forest@compute@node@boundary@arrow box}{%
  \forest@mt{before north arrow}%
  \forest@lt{before north arrow head}%
  \forest@lt{before north arrow tip}%
  \forest@lt{north arrow tip}%
  \forest@lt{after north arrow tip}%
  \forest@lt{after north arrow head}%
  \forest@lt{after north arrow}%
  \forest@lt{north east}%
  \forest@lt{before east arrow}%
  \forest@lt{before east arrow head}%
  \forest@lt{before east arrow tip}%
  \forest@lt{east arrow tip}%
  \forest@lt{after east arrow tip}%
  \forest@lt{after east arrow head}%
  \forest@lt{after east arrow}%
  \forest@lt{south east}%
  \forest@lt{before south arrow}%
  \forest@lt{before south arrow head}%
  \forest@lt{before south arrow tip}%
  \forest@lt{south arrow tip}%
  \forest@lt{after south arrow tip}%
  \forest@lt{after south arrow head}%
  \forest@lt{after south arrow}%
  \forest@lt{south west}% 
  \forest@lt{before west arrow}%
  \forest@lt{before west arrow head}%
  \forest@lt{before west arrow tip}%
  \forest@lt{west arrow tip}%
  \forest@lt{after west arrow tip}%
  \forest@lt{after west arrow head}%
  \forest@lt{after west arrow}%
  \forest@lt{north west}%
  \forest@lt{before north arrow}%
}
\cslet{forest@compute@node@boundary@circle split}\forest@compute@node@boundary@circle
\cslet{forest@compute@node@boundary@circle solidus}\forest@compute@node@boundary@circle
\cslet{forest@compute@node@boundary@ellipse split}\forest@compute@node@boundary@ellipse
\cslet{forest@compute@node@boundary@rectangle split}\forest@compute@node@boundary@rectangle
\def\forest@compute@node@boundary@@callout{%
  \beforecalloutpointer
  \pgfsyssoftpath@moveto{\the\pgf@x}{\the\pgf@y}%
  \calloutpointeranchor
  \pgfsyssoftpath@lineto{\the\pgf@x}{\the\pgf@y}%  
  \aftercalloutpointer
  \pgfsyssoftpath@lineto{\the\pgf@x}{\the\pgf@y}%  
}
\csdef{forest@compute@node@boundary@rectangle callout}{%
  \forest@compute@node@boundary@rectangle
  \rectanglecalloutpoints
  \forest@compute@node@boundary@@callout
}
\csdef{forest@compute@node@boundary@ellipse callout}{%
  \forest@compute@node@boundary@ellipse
  \ellipsecalloutpoints
  \forest@compute@node@boundary@@callout
}
\csdef{forest@compute@node@boundary@cloud callout}{%
  \forest@compute@node@boundary@cloud
  % at least a first approx...
  \forest@mt{center}%
  \forest@lt{pointer}%
}%
\csdef{forest@compute@node@boundary@cross out}{%
  \forest@mt{south east}%
  \forest@lt{north west}%
  \forest@mt{south west}%
  \forest@lt{north east}%
}%
\csdef{forest@compute@node@boundary@strike out}{%
  \forest@mt{north east}%
  \forest@lt{south west}%
}%  
\csdef{forest@compute@node@boundary@rounded rectangle}{%
  \forest@mt{east}%
  \forest@lt{north east}%
  \forest@lt{north}%
  \forest@lt{north west}%
  \forest@lt{west}%
  \forest@lt{south west}%
  \forest@lt{south}%
  \forest@lt{south east}%
  \forest@lt{east}%
}%
\csdef{forest@compute@node@boundary@chamfered rectangle}{%
  \forest@mt{before south west}%
  \forest@mt{after south west}%
  \forest@lt{before south east}%
  \forest@lt{after south east}%
  \forest@lt{before north east}%
  \forest@lt{after north east}%
  \forest@lt{before north west}%
  \forest@lt{after north west}%
  \forest@lt{before south west}%
}%
%    \end{macrocode}
%
%
%
%
% \subsection{Compute absolute positions}
%
% Computes absolute positions of descendants relative to this node.
% Stores the results in attributes |x| and |y|.
%    \begin{macrocode}
\def\forest@node@computeabsolutepositions{%
  \forestoset{x}{0pt}%
  \forestoset{y}{0pt}%
  \edef\forest@marshal{%
    \noexpand\forest@node@foreachchild{%
      \noexpand\forest@node@computeabsolutepositions@{0pt}{0pt}{\forestove{grow}}%
    }%
  }\forest@marshal
}
\def\forest@node@computeabsolutepositions@#1#2#3{%
  \pgfpointadd{\pgfpoint{#1}{#2}}{%
    \pgfpointadd{\pgfpolar{#3}{\forestove{l}}}{\pgfpolar{90 + #3}{\forestove{s}}}}%
  \pgfgetlastxy\forest@temp@x\forest@temp@y
  \forestolet{x}\forest@temp@x
  \forestolet{y}\forest@temp@y
  \edef\forest@marshal{%
    \noexpand\forest@node@foreachchild{%
      \noexpand\forest@node@computeabsolutepositions@{\forest@temp@x}{\forest@temp@y}{\forestove{grow}}%
    }%
  }\forest@marshal    
}
%    \end{macrocode}
%
%
% \subsection{Drawing the tree}
% \label{imp:drawing-the-tree}
%    \begin{macrocode}
\newif\ifforest@drawtree@preservenodeboxes@
\def\forest@node@drawtree{%
  \expandafter\ifstrequal\expandafter{\forest@drawtreebox}{\pgfkeysnovalue}{%
    \let\forest@drawtree@beginbox\relax
    \let\forest@drawtree@endbox\relax
  }{%
    \edef\forest@drawtree@beginbox{\global\setbox\forest@drawtreebox=\hbox\bgroup}%
    \let\forest@drawtree@endbox\egroup
  }%
  \ifforest@external@
    \ifforest@externalize@tree@
      \forest@temptrue
    \else
      \tikzifexternalizing{%
        \ifforest@was@tikzexternalwasenable
          \forest@temptrue
          \pgfkeys{/tikz/external/optimize=false}%
          \let\forest@drawtree@beginbox\relax
          \let\forest@drawtree@endbox\relax
        \else
          \forest@tempfalse
        \fi
      }{%
        \forest@tempfalse
      }%
    \fi
    \ifforest@temp
      \advance\forest@externalize@inner@n 1
      \edef\forest@externalize@filename{%
        \tikzexternalrealjob-forest-\forest@externalize@outer@n
        \ifnum\forest@externalize@inner@n=0 \else.\the\forest@externalize@inner@n\fi}%
      \expandafter\tikzsetnextfilename\expandafter{\forest@externalize@filename}%
      \tikzexternalenable
      \pgfkeysalso{/tikz/external/remake next,/tikz/external/export next}%
    \fi
    \ifforest@externalize@tree@
      \typeout{forest: Invoking a recursive call to generate the external picture
        '\forest@externalize@filename' for the following context+code:
        '\expandafter\detokenize\expandafter{\forest@externalize@id}'}%
    \fi
  \fi
  %
  \ifforesttikzcshack
    \let\forest@original@tikz@parse@node\tikz@parse@node
    \let\tikz@parse@node\forest@tikz@parse@node
  \fi
  \pgfkeysgetvalue{/forest/begin draw/.@cmd}\forest@temp@begindraw
  \pgfkeysgetvalue{/forest/end draw/.@cmd}\forest@temp@enddraw
  \edef\forest@marshal{%
    \noexpand\forest@drawtree@beginbox
    \expandonce{\forest@temp@begindraw\pgfkeysnovalue\pgfeov}%
    \noexpand\forest@node@drawtree@
    \expandonce{\forest@temp@enddraw\pgfkeysnovalue\pgfeov}%
    \noexpand\forest@drawtree@endbox
  }\forest@marshal
  \ifforesttikzcshack
    \let\tikz@parse@node\forest@original@tikz@parse@node
  \fi
  %
  \ifforest@external@
    \ifforest@externalize@tree@
      \tikzexternaldisable
      \eappto\forest@externalize@checkimages{%
        \noexpand\forest@includeexternal@check{\forest@externalize@filename}%
      }%
      \expandafter\ifstrequal\expandafter{\forest@drawtreebox}{\pgfkeysnovalue}{%
        \eappto\forest@externalize@loadimages{%
          \noexpand\forest@includeexternal{\forest@externalize@filename}%
        }%
      }{%
        \eappto\forest@externalize@loadimages{%
          \noexpand\forest@includeexternal@box\forest@drawtreebox{\forest@externalize@filename}%
        }%
      }%
    \fi
  \fi
}
\def\forest@node@drawtree@{%
  \forest@node@foreach{\forest@draw@node}%
  \forest@node@Ifnamedefined{forest@baseline@node}{%
    \edef\forest@temp{%
      \noexpand\pgfsetbaselinepointlater{%
        \noexpand\pgfpointanchor
          {\forestOve{\forest@node@Nametoid{forest@baseline@node}}{name}}
          {\forestOve{\forest@node@Nametoid{forest@baseline@node}}{anchor}}
      }%
    }\forest@temp
  }{}%
  \forest@node@foreachdescendant{\forest@draw@edge}%
  \forest@node@foreach{\forest@draw@tikz}%
}
\def\forest@draw@node{%
  \ifnum\forestove{phantom}=0
    \forest@node@forest@positionnodelater@restore
    \ifforest@drawtree@preservenodeboxes@
      \pgfnodealias{forest@temp}{\forestove{later@name}}%
    \fi
    \pgfpositionnodenow{\pgfqpoint{\forestove{x}}{\forestove{y}}}%
    \ifforest@drawtree@preservenodeboxes@
      \pgfnodealias{\forestove{later@name}}{forest@temp}%
    \fi
  \fi
}
\def\forest@draw@edge{%
  \ifnum\forestove{phantom}=0
    \ifnum\forestOve{\forestove{@parent}}{phantom}=0
      \edef\forest@temp{\forestove{edge path}}%
      \forest@temp
    \fi
  \fi
}
\def\forest@draw@tikz{%
  \forestove{tikz}%
}
%    \end{macrocode}
% A hack into \TikZ;'s coordinate parser: implements relative node names!
%    \begin{macrocode}
\def\forest@tikz@parse@node#1(#2){%
  \pgfutil@in@.{#2}%
  \ifpgfutil@in@
    \expandafter\forest@tikz@parse@node@checkiftikzname@withdot
  \else%
    \expandafter\forest@tikz@parse@node@checkiftikzname@withoutdot
  \fi%
  #1(#2)\forest@end
}
\def\forest@tikz@parse@node@checkiftikzname@withdot#1(#2.#3)\forest@end{%
  \forest@tikz@parse@node@checkiftikzname#1{#2}{.#3}}
\def\forest@tikz@parse@node@checkiftikzname@withoutdot#1(#2)\forest@end{%
  \forest@tikz@parse@node@checkiftikzname#1{#2}{}}  
\def\forest@tikz@parse@node@checkiftikzname#1#2#3{%
  \expandafter\ifx\csname pgf@sh@ns@#2\endcsname\relax
    \forest@forthis{%
      \forest@nameandgo{#2}%
      \edef\forest@temp@relativenodename{\forestove{name}}%
    }%
  \else
    \def\forest@temp@relativenodename{#2}%
  \fi
  \expandafter\forest@original@tikz@parse@node\expandafter#1\expandafter(\forest@temp@relativenodename#3)%
}
\def\forest@nameandgo#1{%
  \pgfutil@in@!{#1}%
  \ifpgfutil@in@
    \forest@nameandgo@(#1)%
  \else
    \ifstrempty{#1}{}{\edef\forest@cn{\forest@node@Nametoid{#1}}}%
  \fi
}
\def\forest@nameandgo@(#1!#2){%
  \ifstrempty{#1}{}{\edef\forest@cn{\forest@node@Nametoid{#1}}}%
  \forest@go{#2}%
}
%    \end{macrocode}
% |parent/child anchor| are generic anchors which forward to the real one.  There's a hack in there
% to deal with link pointing to the ``border'' anchor.
%    \begin{macrocode}
\pgfdeclaregenericanchor{parent anchor}{%
  \forest@generic@parent@child@anchor{parent }{#1}}
\pgfdeclaregenericanchor{child anchor}{%
  \forest@generic@parent@child@anchor{child }{#1}}
\pgfdeclaregenericanchor{anchor}{%
  \forest@generic@parent@child@anchor{}{#1}}
\def\forest@generic@parent@child@anchor#1#2{%
  \forestOget{\forest@node@Nametoid{\pgfreferencednodename}}{#1anchor}\forest@temp@parent@anchor
  \ifdefempty\forest@temp@parent@anchor{%
    \pgf@sh@reanchor{#2}{center}%
    \xdef\forest@hack@tikzshapeborder{%
      \noexpand\tikz@shapebordertrue
      \def\noexpand\tikz@shapeborder@name{\pgfreferencednodename}%
    }\aftergroup\forest@hack@tikzshapeborder
  }{%
    \pgf@sh@reanchor{#2}{\forest@temp@parent@anchor}%
  }%
}
%    \end{macrocode}
%
%
% \section{Geometry}
% \label{imp:geometry}
%
% A \emph{$\alpha$ grow line} is a line through the origin at angle
% $\alpha$. The following macro sets up the grow line, which can then
% be used by other code (the change is local to the \TeX\ group). More
% precisely, two normalized vectors are set up: one $(x_g,y_g)$ on the
% grow line, and one $(x_s,y_s)$ orthogonal to it---to get
% $(x_s,y_s$), rotate $(x_g,y_g)$ 90$^\circ$ counter-clockwise.
%    \begin{macrocode}
\newdimen\forest@xg
\newdimen\forest@yg
\newdimen\forest@xs
\newdimen\forest@ys
\def\forest@setupgrowline#1{%
  \edef\forest@grow{#1}%
  \pgfpointpolar\forest@grow{1pt}%
  \forest@xg=\pgf@x
  \forest@yg=\pgf@y
  \forest@xs=-\pgf@y
  \forest@ys=\pgf@x   
}
%    \end{macrocode}
%
% \subsection{Projections}
% \label{imp:projections}
% 
% The following macro belongs to the |\pgfpoint...| family: it
% projects point |#1| on the grow line.  (The result is returned via
% |\pgf@x| and |\pgf@y|.)  The implementation is based on code from
% |tikzlibrarycalc|, but optimized for projecting on grow lines, and
% split to optimize serial usage in |\forest@projectpath|.
%    \begin{macrocode}
\def\forest@pgfpointprojectiontogrowline#1{{%
  \pgf@process{#1}%
%    \end{macrocode}
% Calculate the scalar product of $(x,y)$ and $(x_g,y_g)$: that's the
% distance of $(x,y)$ to the grow line.
%    \begin{macrocode}
  \pgfutil@tempdima=\pgf@sys@tonumber{\pgf@x}\forest@xg%
  \advance\pgfutil@tempdima by\pgf@sys@tonumber{\pgf@y}\forest@yg%
%    \end{macrocode}
% The projection is $(x_g,y_g)$ scaled by the distance.
%    \begin{macrocode}
  \global\pgf@x=\pgf@sys@tonumber{\pgfutil@tempdima}\forest@xg%
  \global\pgf@y=\pgf@sys@tonumber{\pgfutil@tempdima}\forest@yg%
}}
%    \end{macrocode}
%
% The following macro calculates the distance of point |#2| to the
% grow line and stores the result in \TeX-dimension |#1|. The distance
% is the scalar product of the point vector and the normalized vector
% orthogonal to the grow line. 
%    \begin{macrocode}
\def\forest@distancetogrowline#1#2{%
  \pgf@process{#2}%
  #1=\pgf@sys@tonumber{\pgf@x}\forest@xs\relax
  \advance#1 by\pgf@sys@tonumber{\pgf@y}\forest@ys\relax
}
%    \end{macrocode}
% Note that the distance to the grow line is positive for points on
% one of its sides and negative for points on the other side. (It is
% positive on the side which $(x_s,y_s)$ points to.)  We thus say that
% the grow line partitions the plane into a \emph{positive} and a
% \emph{negative} side.
%
% The following macro projects all segment edges (``points'') of a
% simple\footnote{A path is \emph{simple} if it consists of only
% move-to and line-to operations.} path |#1| onto the grow line.
% The result is an array of tuples (|xo|, |yo|, |xp|, |yp|), where
% |xo| and |yo| stand for the \emph{o}riginal point, and |xp| and |yp|
% stand for its \emph{p}rojection. The prefix of the array is given by
% |#2|.  If the array already exists, the new items are appended to
% it.  The array is not sorted: the order of original points in the
% array is their order in the path.  The computation does not destroy
% the current path.  All result-macros have local scope.
%
% The macro is just a wrapper for |\forest@projectpath@process|.
%    \begin{macrocode}
\let\forest@pp@n\relax
\def\forest@projectpathtogrowline#1#2{%
  \edef\forest@pp@prefix{#2}%
  \forest@save@pgfsyssoftpath@tokendefs
  \let\pgfsyssoftpath@movetotoken\forest@projectpath@processpoint
  \let\pgfsyssoftpath@linetotoken\forest@projectpath@processpoint
  \c@pgf@counta=0
  #1%
  \csedef{#2n}{\the\c@pgf@counta}%
  \forest@restore@pgfsyssoftpath@tokendefs
}
%    \end{macrocode}
% For each point, remember the point and its projection to grow line.
%    \begin{macrocode}
\def\forest@projectpath@processpoint#1#2{%
  \pgfqpoint{#1}{#2}%
  \expandafter\edef\csname\forest@pp@prefix\the\c@pgf@counta xo\endcsname{\the\pgf@x}%
  \expandafter\edef\csname\forest@pp@prefix\the\c@pgf@counta yo\endcsname{\the\pgf@y}%
  \forest@pgfpointprojectiontogrowline{}%
  \expandafter\edef\csname\forest@pp@prefix\the\c@pgf@counta xp\endcsname{\the\pgf@x}%
  \expandafter\edef\csname\forest@pp@prefix\the\c@pgf@counta yp\endcsname{\the\pgf@y}%
  \advance\c@pgf@counta 1\relax
}
%    \end{macrocode}
% Sort the array (prefix |#1|) produced by
% |\forest@projectpathtogrowline| by |(xp,yp)|, in the ascending order.
%    \begin{macrocode}
\def\forest@sortprojections#1{%
  % todo: optimize in cases when we know that the array is actually a
  % merger of sorted arrays; when does this happen? in
  % distance_between_paths, and when merging the edges of the parent
  % and its children in a uniform growth tree
  \edef\forest@ppi@inputprefix{#1}%
  \c@pgf@counta=\csname#1n\endcsname\relax
  \advance\c@pgf@counta -1
  \forest@sort\forest@ppiraw@cmp\forest@ppiraw@let\forest@sort@ascending{0}{\the\c@pgf@counta}%
}
%    \end{macrocode}
%
% The following macro processes the data gathered by (possibly more
% than one invocation of) |\forest@projectpathtogrowline| into array
% with prefix |#1|.  The resulting data is the following.
% \begin{itemize}
% \item Array of projections (prefix |#2|)
%   \begin{itemize}
%   \item its items are tuples |(x,y)| (the array is sorted by |x|
%     and |y|), and
%   \item an inner array of original points (prefix |#2N@|, where $N$
%     is the index of the item in array |#2|.  The items of |#2N@|
%     are |x|, |y| and |d|: |x| and |y| are the coordinates of the
%     original point; |d| is its distance to the grow line. The inner
%     array is not sorted.
%   \end{itemize}
% \item A dictionary |#2|: keys are the coordinates |(x,y)| of
%   the original points; a value is the index of the original point's
%   projection in array |#2|.\footnote{At first sight, this
%   information could be cached ``at the source'': by
%   forest@pgfpointprojectiontogrowline.  However, due to imprecise
%   intersecting (in breakpath), we cheat and merge very adjacent
%   projection points, expecting that the points to project to the
%   merged projection point.  All this depends on the given path, so a
%   generic cache is not feasible.}
% \end{itemize}
%    \begin{macrocode}
\def\forest@processprojectioninfo#1#2{%
  \edef\forest@ppi@inputprefix{#1}%
%    \end{macrocode}
% Loop (counter |\c@pgf@counta|) through the sorted array of raw data.
%    \begin{macrocode}
  \c@pgf@counta=0
  \c@pgf@countb=-1
  \loop
  \ifnum\c@pgf@counta<\csname#1n\endcsname\relax
%    \end{macrocode}
% Check if the projection tuple in the current raw item equals the
% current projection.
%    \begin{macrocode}
    \letcs\forest@xo{#1\the\c@pgf@counta xo}%
    \letcs\forest@yo{#1\the\c@pgf@counta yo}%
    \letcs\forest@xp{#1\the\c@pgf@counta xp}%
    \letcs\forest@yp{#1\the\c@pgf@counta yp}%
    \ifnum\c@pgf@countb<0
      \forest@equaltotolerancefalse
    \else
      \forest@equaltotolerance
        {\pgfqpoint\forest@xp\forest@yp}%
        {\pgfqpoint
          {\csname#2\the\c@pgf@countb x\endcsname}%
          {\csname#2\the\c@pgf@countb y\endcsname}%
        }%
    \fi
    \ifforest@equaltotolerance\else
%    \end{macrocode}
% It not, we will append a new item to the outer result array.
%    \begin{macrocode}
      \advance\c@pgf@countb 1
      \cslet{#2\the\c@pgf@countb x}\forest@xp
      \cslet{#2\the\c@pgf@countb y}\forest@yp
      \csdef{#2\the\c@pgf@countb @n}{0}%
    \fi
%    \end{macrocode}
% If the projection is actually a projection of one a point in our path:
%    \begin{macrocode}
    % todo: this is ugly!
    \ifdefined\forest@xo\ifx\forest@xo\relax\else
      \ifdefined\forest@yo\ifx\forest@yo\relax\else
%    \end{macrocode}
% Append the point of the current raw item to the inner array of
% points projecting to the current projection.
%    \begin{macrocode}
        \forest@append@point@to@inner@array
          \forest@xo\forest@yo
          {#2\the\c@pgf@countb @}%
%    \end{macrocode}
% Put a new item in the dictionary: key = the original point, value =
% the projection index.
%    \begin{macrocode}
        \csedef{#2(\forest@xo,\forest@yo)}{\the\c@pgf@countb}%
      \fi\fi
    \fi\fi
%    \end{macrocode}
% Clean-up the raw array item.
%    \begin{macrocode}
    \cslet{#1\the\c@pgf@counta xo}\relax
    \cslet{#1\the\c@pgf@counta yo}\relax
    \cslet{#1\the\c@pgf@counta xp}\relax
    \cslet{#1\the\c@pgf@counta yp}\relax
    \advance\c@pgf@counta 1
  \repeat
%    \end{macrocode}
% Clean up the raw array length.
%    \begin{macrocode}
  \cslet{#1n}\relax
%    \end{macrocode}
% Store the length of the outer result array.
%    \begin{macrocode}
  \advance\c@pgf@countb 1
  \csedef{#2n}{\the\c@pgf@countb}%
}
%    \end{macrocode}
%    
% Item-exchange macro for quicksorting the raw projection data. (|#1|
% is copied into |#2|.)
%    \begin{macrocode}
\def\forest@ppiraw@let#1#2{%
  \csletcs{\forest@ppi@inputprefix#1xo}{\forest@ppi@inputprefix#2xo}%
  \csletcs{\forest@ppi@inputprefix#1yo}{\forest@ppi@inputprefix#2yo}%
  \csletcs{\forest@ppi@inputprefix#1xp}{\forest@ppi@inputprefix#2xp}%
  \csletcs{\forest@ppi@inputprefix#1yp}{\forest@ppi@inputprefix#2yp}%
}
%    \end{macrocode}
% Item comparision macro for quicksorting the raw projection data.
%    \begin{macrocode}
\def\forest@ppiraw@cmp#1#2{%
  \forest@sort@cmptwodimcs
    {\forest@ppi@inputprefix#1xp}{\forest@ppi@inputprefix#1yp}%
    {\forest@ppi@inputprefix#2xp}{\forest@ppi@inputprefix#2yp}%
}
%    \end{macrocode}
%    
% Append the point |(#1,#2)| to the (inner) array of points
% (prefix |#3|).
%    \begin{macrocode}
\def\forest@append@point@to@inner@array#1#2#3{%
  \c@pgf@countc=\csname#3n\endcsname\relax
  \csedef{#3\the\c@pgf@countc x}{#1}%
  \csedef{#3\the\c@pgf@countc y}{#2}%
  \forest@distancetogrowline\pgfutil@tempdima{\pgfqpoint#1#2}%
  \csedef{#3\the\c@pgf@countc d}{\the\pgfutil@tempdima}%
  \advance\c@pgf@countc 1
  \csedef{#3n}{\the\c@pgf@countc}%
}
%    \end{macrocode}
%    
% \subsection{Break path}
%
% The following macro computes from the given path (|#1|) a ``broken''
% path (|#3|) that contains the same points of the plane, but has
% potentially more segments, so that, for every point from a given set
% of points on the grow line, a line through this point perpendicular
% to the grow line intersects the broken path only at its edge
% segments (i.e.\ not between them).
%
% The macro works only for \emph{simple} paths, i.e.\ paths built
% using only move-to and line-to operations.  Furthermore,
% |\forest@processprojectioninfo| must be called before calling
% |\forest@breakpath|: we expect information with prefix |#2|.  The
% macro updates the information compiled by
% |\forest@processprojectioninfo| with information about points added
% by path-breaking.
%    \begin{macrocode}
\def\forest@breakpath#1#2#3{%
%    \end{macrocode}
% Store the current path in a macro and empty it, then process the
% stored path. The processing creates a new current path.
%    \begin{macrocode}
  \edef\forest@bp@prefix{#2}%
  \forest@save@pgfsyssoftpath@tokendefs
  \let\pgfsyssoftpath@movetotoken\forest@breakpath@processfirstpoint
  \let\pgfsyssoftpath@linetotoken\forest@breakpath@processfirstpoint
  %\pgfusepath{}% empty the current path. ok?
  #1%
  \forest@restore@pgfsyssoftpath@tokendefs
  \pgfsyssoftpath@getcurrentpath#3%
}
%    \end{macrocode}
% The original and the broken path start in the same way. (This code
% implicitely ``repairs'' a path that starts illegally, with a line-to
% operation.)
%    \begin{macrocode}
\def\forest@breakpath@processfirstpoint#1#2{%  
  \forest@breakpath@processmoveto{#1}{#2}%
  \let\pgfsyssoftpath@movetotoken\forest@breakpath@processmoveto
  \let\pgfsyssoftpath@linetotoken\forest@breakpath@processlineto
}
%    \end{macrocode}
% When a move-to operation is encountered, it is simply copied to the
% broken path, starting a new subpath. Then we remember the last
% point, its projection's index (the point dictionary is used here)
% and the actual projection point.
%    \begin{macrocode}
\def\forest@breakpath@processmoveto#1#2{%
  \pgfsyssoftpath@moveto{#1}{#2}%
  \def\forest@previous@x{#1}%
  \def\forest@previous@y{#2}%
  \expandafter\let\expandafter\forest@previous@i
    \csname\forest@bp@prefix(#1,#2)\endcsname
  \expandafter\let\expandafter\forest@previous@px
    \csname\forest@bp@prefix\forest@previous@i x\endcsname
  \expandafter\let\expandafter\forest@previous@py
    \csname\forest@bp@prefix\forest@previous@i y\endcsname
}
%    \end{macrocode}
%    
% This is the heart of the path-breaking procedure.
%    \begin{macrocode}
\def\forest@breakpath@processlineto#1#2{%
%    \end{macrocode}
% Usually, the broken path will continue with a line-to operation (to
% the current point |(#1,#2)|).
%    \begin{macrocode}
  \let\forest@breakpath@op\pgfsyssoftpath@lineto
%    \end{macrocode}
% Get the index of the current point's projection and the projection
% itself.  (The point dictionary is used here.)
%    \begin{macrocode}
  \expandafter\let\expandafter\forest@i
    \csname\forest@bp@prefix(#1,#2)\endcsname
  \expandafter\let\expandafter\forest@px
    \csname\forest@bp@prefix\forest@i x\endcsname
  \expandafter\let\expandafter\forest@py
    \csname\forest@bp@prefix\forest@i y\endcsname
%    \end{macrocode}
% Test whether the projections of the previous and the current point
% are the same.
%    \begin{macrocode}
  \forest@equaltotolerance
    {\pgfqpoint{\forest@previous@px}{\forest@previous@py}}%
    {\pgfqpoint{\forest@px}{\forest@py}}%
  \ifforest@equaltotolerance
%    \end{macrocode}
% If so, we are dealing with a segment, perpendicular to the grow
% line. This segment must be removed, so we change the operation to
% move-to.
%    \begin{macrocode}
    \let\forest@breakpath@op\pgfsyssoftpath@moveto
  \else
%    \end{macrocode}
% Figure out the ``direction'' of the segment: in the order of the
% array of projections, or in the reversed order? Setup the loop step
% and the test condition.
%    \begin{macrocode}
    \forest@temp@count=\forest@previous@i\relax
    \ifnum\forest@previous@i<\forest@i\relax
      \def\forest@breakpath@step{1}%
      \def\forest@breakpath@test{\forest@temp@count<\forest@i\relax}%
    \else
      \def\forest@breakpath@step{-1}%
      \def\forest@breakpath@test{\forest@temp@count>\forest@i\relax}%
    \fi
%    \end{macrocode}
% Loop through all the projections between (in the (possibly reversed)
% array order) the projections of the previous and the current point
% (both exclusive).
%    \begin{macrocode}
    \loop
      \advance\forest@temp@count\forest@breakpath@step\relax
    \expandafter\ifnum\forest@breakpath@test
%    \end{macrocode}
% Intersect the current segment with the line through the current (in
% the loop!) projection perpendicular to the grow line. (There
% \emph{will} be an intersection.)
%    \begin{macrocode}
      \pgfpointintersectionoflines
        {\pgfqpoint
          {\csname\forest@bp@prefix\the\forest@temp@count x\endcsname}%
          {\csname\forest@bp@prefix\the\forest@temp@count y\endcsname}%
        }%
        {\pgfpointadd
          {\pgfqpoint
            {\csname\forest@bp@prefix\the\forest@temp@count x\endcsname}%
            {\csname\forest@bp@prefix\the\forest@temp@count y\endcsname}%
          }%
          {\pgfqpoint{\forest@xs}{\forest@ys}}%
        }%
        {\pgfqpoint{\forest@previous@x}{\forest@previous@y}}%
        {\pgfqpoint{#1}{#2}}%
%    \end{macrocode}
% Break the segment at the intersection. 
%    \begin{macrocode}
      \pgfgetlastxy\forest@last@x\forest@last@y
      \pgfsyssoftpath@lineto\forest@last@x\forest@last@y
%    \end{macrocode}
% Append the breaking point to the inner array for the projection.
%    \begin{macrocode}
      \forest@append@point@to@inner@array
        \forest@last@x\forest@last@y
        {\forest@bp@prefix\the\forest@temp@count @}%
%    \end{macrocode}
% Cache the projection of the new segment edge.
%    \begin{macrocode}
      \csedef{\forest@bp@prefix(\the\pgf@x,\the\pgf@y)}{\the\forest@temp@count}%
    \repeat
  \fi
%    \end{macrocode}
% Add the current point.
%    \begin{macrocode}
  \forest@breakpath@op{#1}{#2}%
%    \end{macrocode}
% Setup new ``previous'' info: the segment edge, its projection's
% index, and the projection.
%    \begin{macrocode}
  \def\forest@previous@x{#1}%
  \def\forest@previous@y{#2}%
  \let\forest@previous@i\forest@i
  \let\forest@previous@px\forest@px
  \let\forest@previous@py\forest@py
}
%    \end{macrocode}
%
% \subsection{Get tight edge of path}
%
% This is one of the central algorithms of the package. Given a simple
% path and a grow line, this method computes its (negative and
% positive) ``tight edge'', which we (informally) define as follows.
%
% Imagine an infinitely long light source parallel to the grow line,
% on the grow line's negative/positive side.\footnote{For the
% definition of negative/positive side, see forest@distancetogrowline
% in \S\ref{imp:projections}} Furthermore imagine that the path is
% opaque. Then the negative/positive tight edge of the path is the
% part of the path that is illuminated.
%
% This macro takes three arguments: |#1| is the path; |#2| and |#3|
% are macros which will receive the negative and the positive edge,
% respectively.  The edges are returned in the softpath format.  Grow
% line should be set before calling this macro.
%
% Enclose the computation in a \TeX\ group. This is actually quite
% crucial: if there was no enclosure, the temporary data (the segment
% dictionary, to be precise) computed by the prior invocations of the
% macro could corrupt the computation in the current invocation.
%    \begin{macrocode}
\def\forest@getnegativetightedgeofpath#1#2{%
  \forest@get@onetightedgeofpath#1\forest@sort@ascending#2}
\def\forest@getpositivetightedgeofpath#1#2{%
  \forest@get@onetightedgeofpath#1\forest@sort@descending#2}
\def\forest@get@onetightedgeofpath#1#2#3{%
  {%
    \forest@get@one@tightedgeofpath#1#2\forest@gep@edge
    \global\let\forest@gep@global@edge\forest@gep@edge
  }%
  \let#3\forest@gep@global@edge
}
\def\forest@get@one@tightedgeofpath#1#2#3{%
%    \end{macrocode}
% Project the path to the grow line and compile some useful information.
%    \begin{macrocode}
  \forest@projectpathtogrowline#1{forest@pp@}%
  \forest@sortprojections{forest@pp@}%
  \forest@processprojectioninfo{forest@pp@}{forest@pi@}%
%    \end{macrocode}
% Break the path.
%    \begin{macrocode}
  \forest@breakpath#1{forest@pi@}\forest@brokenpath
%    \end{macrocode}
% Compile some more useful information.
%    \begin{macrocode}
  \forest@sort@inner@arrays{forest@pi@}#2%
  \forest@pathtodict\forest@brokenpath{forest@pi@}%
%    \end{macrocode}
% The auxiliary data is set up: do the work!
%    \begin{macrocode}
  \forest@gettightedgeofpath@getedge
  \pgfsyssoftpath@getcurrentpath\forest@edge
%    \end{macrocode}
% Where possible, merge line segments of the path into a single line
% segment. This is an important optimization, since the edges of the
% subtrees are computed recursively. Not simplifying the edge could
% result in a wild growth of the length of the edge (in the sense of
% the number of segments).
%    \begin{macrocode}
  \forest@simplifypath\forest@edge#3%
}
%    \end{macrocode}
% Get both negative (stored in |#2|) and positive (stored in |#3|)
% edge of the path |#1|.
%    \begin{macrocode}
\def\forest@getbothtightedgesofpath#1#2#3{%
  {%
    \forest@get@one@tightedgeofpath#1\forest@sort@ascending\forest@gep@firstedge
%    \end{macrocode}
% Reverse the order of items in the inner arrays.
%    \begin{macrocode}
    \c@pgf@counta=0
    \loop
    \ifnum\c@pgf@counta<\forest@pi@n\relax
      \forest@ppi@deflet{forest@pi@\the\c@pgf@counta @}%
      \forest@reversearray\forest@ppi@let
        {0}%
        {\csname forest@pi@\the\c@pgf@counta @n\endcsname}%
      \advance\c@pgf@counta 1
    \repeat
%    \end{macrocode}
% Calling |\forest@gettightedgeofpath@getedge| now will result in the
% positive edge.
%    \begin{macrocode}
    \forest@gettightedgeofpath@getedge
    \pgfsyssoftpath@getcurrentpath\forest@edge
    \forest@simplifypath\forest@edge\forest@gep@secondedge
%    \end{macrocode}
% Smuggle the results out of the enclosing \TeX\ group.
%    \begin{macrocode}
      \global\let\forest@gep@global@firstedge\forest@gep@firstedge
      \global\let\forest@gep@global@secondedge\forest@gep@secondedge
    }%
  \let#2\forest@gep@global@firstedge
  \let#3\forest@gep@global@secondedge
}
%    \end{macrocode}
% 
% Sort the inner arrays of original points wrt the distance to the
% grow line. |#2| =
% |\forest@sort@ascending|/|\forest@sort@descending|.  (|\forest@loopa| is
% used here because quicksort uses |\loop|.)
%    \begin{macrocode}
\def\forest@sort@inner@arrays#1#2{%
  \c@pgf@counta=0
  \forest@loopa
  \ifnum\c@pgf@counta<\csname#1n\endcsname
    \c@pgf@countb=\csname#1\the\c@pgf@counta @n\endcsname\relax
    \ifnum\c@pgf@countb>1
      \advance\c@pgf@countb -1
      \forest@ppi@deflet{#1\the\c@pgf@counta @}%
      \forest@ppi@defcmp{#1\the\c@pgf@counta @}%
      \forest@sort\forest@ppi@cmp\forest@ppi@let#2{0}{\the\c@pgf@countb}%
    \fi
    \advance\c@pgf@counta 1
  \forest@repeata
}
%    \end{macrocode}
%    
% A macro that will define the item exchange macro for quicksorting
% the inner arrays of original points.  It takes one argument: the
% prefix of the inner array.
%    \begin{macrocode}
\def\forest@ppi@deflet#1{%
  \edef\forest@ppi@let##1##2{%
    \noexpand\csletcs{#1##1x}{#1##2x}%
    \noexpand\csletcs{#1##1y}{#1##2y}%
    \noexpand\csletcs{#1##1d}{#1##2d}%
  }%
}
%    \end{macrocode}
% A macro that will define the item-compare macro for quicksorting the
% embedded arrays of original points. It takes one argument: the
% prefix of the inner array.
%    \begin{macrocode}
\def\forest@ppi@defcmp#1{%
  \edef\forest@ppi@cmp##1##2{%
    \noexpand\forest@sort@cmpdimcs{#1##1d}{#1##2d}%
  }%
}
%    \end{macrocode}
%    
% Put path segments into a ``segment dictionary'': for each segment of
% the path from $(x_1,y_1)$ to $(x_2,y_2)$ let
% |\forest@(x1,y1)--(x2,y2)| be |\forest@inpath| (which can be
% anything but |\relax|).
%    \begin{macrocode}
\let\forest@inpath\advance
%    \end{macrocode}
% This macro is just a wrapper to process the path.
%    \begin{macrocode}
\def\forest@pathtodict#1#2{%
  \edef\forest@pathtodict@prefix{#2}%
  \forest@save@pgfsyssoftpath@tokendefs
  \let\pgfsyssoftpath@movetotoken\forest@pathtodict@movetoop
  \let\pgfsyssoftpath@linetotoken\forest@pathtodict@linetoop
  \def\forest@pathtodict@subpathstart{}%
  #1%
  \forest@restore@pgfsyssoftpath@tokendefs
}
%    \end{macrocode}
% When a move-to operation is encountered:
%    \begin{macrocode}
\def\forest@pathtodict@movetoop#1#2{%
%    \end{macrocode}
% If a subpath had just started, it was a degenerate one (a point). No
% need to store that (i.e.\ no code would use this information).  So,
% just remember that a new subpath has started.
%    \begin{macrocode}
  \def\forest@pathtodict@subpathstart{(#1,#2)-}%
}
%    \end{macrocode}
% When a line-to operation is encountered:
%    \begin{macrocode}
\def\forest@pathtodict@linetoop#1#2{%
%    \end{macrocode}
% If the subpath has just started, its start is also the start of the
% current segment.
%    \begin{macrocode}
\if\relax\forest@pathtodict@subpathstart\relax\else
    \let\forest@pathtodict@from\forest@pathtodict@subpathstart
  \fi  
%    \end{macrocode}
% Mark the segment as existing.
%    \begin{macrocode}
  \expandafter\let\csname\forest@pathtodict@prefix\forest@pathtodict@from-(#1,#2)\endcsname\forest@inpath
%    \end{macrocode}
% Set the start of the next segment to the current point, and mark
% that we are in the middle of a subpath.
%    \begin{macrocode}
  \def\forest@pathtodict@from{(#1,#2)-}%
  \def\forest@pathtodict@subpathstart{}%
}
%    \end{macrocode}
%    
% In this macro, the edge is actually computed.
%    \begin{macrocode}
\def\forest@gettightedgeofpath@getedge{%
%    \end{macrocode}
% Clear the path and the last projection.
%    \begin{macrocode}
  \pgfsyssoftpath@setcurrentpath\pgfutil@empty
  \let\forest@last@x\relax
  \let\forest@last@y\relax
%    \end{macrocode}
% Loop through the (ordered) array of projections. (Since we will be
% dealing with the current and the next projection in each iteration
% of the loop, we loop the counter from the first to the
% second-to-last projection.)
%    \begin{macrocode}
  \c@pgf@counta=0
  \forest@temp@count=\forest@pi@n\relax  
  \advance\forest@temp@count -1
  \edef\forest@nminusone{\the\forest@temp@count}%
  \forest@loopa
  \ifnum\c@pgf@counta<\forest@nminusone\relax
    \forest@gettightedgeofpath@getedge@loopa
  \forest@repeata
%    \end{macrocode}
% A special case: the edge ends with a degenerate subpath (a
% point). 
%    \begin{macrocode}
  \ifnum\forest@nminusone<\forest@n\relax\else
    \ifnum\csname forest@pi@\forest@nminusone @n\endcsname>0
      \forest@gettightedgeofpath@maybemoveto{\forest@nminusone}{0}%
    \fi
  \fi
}
%    \end{macrocode}
% The body of a loop containing an embedded loop must be put in a
% separate macro because it contains the |\if...| of the embedded
% |\loop...| without the matching |\fi|: |\fi| is ``hiding'' in the
% embedded |\loop|, which has not been expanded yet.
%    \begin{macrocode}
\def\forest@gettightedgeofpath@getedge@loopa{%
    \ifnum\csname forest@pi@\the\c@pgf@counta @n\endcsname>0
%    \end{macrocode}
% Degenerate case: a subpath of the edge is a point.
%    \begin{macrocode}
      \forest@gettightedgeofpath@maybemoveto{\the\c@pgf@counta}{0}%
%    \end{macrocode}
% Loop through points projecting to the current projection. The
% preparations above guarantee that the points are ordered (either in
% the ascending or the descending order) with respect to their
% distance to the grow line.
%    \begin{macrocode}
      \c@pgf@countb=0
      \forest@loopb
      \ifnum\c@pgf@countb<\csname forest@pi@\the\c@pgf@counta @n\endcsname\relax
        \forest@gettightedgeofpath@getedge@loopb
      \forest@repeatb
    \fi
    \advance\c@pgf@counta 1
}
%    \end{macrocode}
% Loop through points projecting to the next projection.  Again, the
% points are ordered.
%    \begin{macrocode}
\def\forest@gettightedgeofpath@getedge@loopb{%
        \c@pgf@countc=0
        \advance\c@pgf@counta 1
        \edef\forest@aplusone{\the\c@pgf@counta}%
        \advance\c@pgf@counta -1
        \forest@loopc        
        \ifnum\c@pgf@countc<\csname forest@pi@\forest@aplusone @n\endcsname\relax
%    \end{macrocode}
% Test whether [the current point]--[the next point] or [the next
% point]--[the current point] is a segment in the (broken) path.  The
% first segment found is the one with the minimal/maximal distance
% (depending on the sort order of arrays of points projecting to the
% same projection) to the grow line.
%
% Note that for this to work in all cases, the original path should
% have been broken on its self-intersections.  However, a careful
% reader will probably remember that |\forest@breakpath| does
% \emph{not} break the path at its self-intersections.  This is
% omitted for performance reasons.  Given the intended use of the
% algorithm (calculating edges of subtrees), self-intersecting paths
% cannot arise anyway, if only the node boundaries are
% non-self-intersecting. So, a warning: if you develop a new shape and
% write a macro computing its boundary, make sure that the computed
% boundary path is non-self-intersecting!
%    \begin{macrocode}
          \forest@tempfalse
          \expandafter\ifx\csname forest@pi@(%
            \csname forest@pi@\the\c@pgf@counta @\the\c@pgf@countb x\endcsname,%
            \csname forest@pi@\the\c@pgf@counta @\the\c@pgf@countb y\endcsname)--(%
            \csname forest@pi@\forest@aplusone @\the\c@pgf@countc x\endcsname,%
            \csname forest@pi@\forest@aplusone @\the\c@pgf@countc y\endcsname)%
            \endcsname\forest@inpath
            \forest@temptrue
          \else
            \expandafter\ifx\csname forest@pi@(%
              \csname forest@pi@\forest@aplusone @\the\c@pgf@countc x\endcsname,%
              \csname forest@pi@\forest@aplusone @\the\c@pgf@countc y\endcsname)--(%
              \csname forest@pi@\the\c@pgf@counta @\the\c@pgf@countb x\endcsname,%
              \csname forest@pi@\the\c@pgf@counta @\the\c@pgf@countb y\endcsname)%
              \endcsname\forest@inpath
              \forest@temptrue
            \fi
          \fi
          \ifforest@temp
%    \end{macrocode}
% We have found the segment with the minimal/maximal distance to the
% grow line. So let's add it to the edge path.
%
% First, deal with the
% start point of the edge: check if the current point is the last
% point. If that is the case (this happens if the current point was
% the end point of the last segment added to the edge), nothing needs
% to be done; otherwise (this happens if the current point will start
% a new subpath of the edge), move to the current point, and update
% the last-point macros.
%    \begin{macrocode}
            \forest@gettightedgeofpath@maybemoveto{\the\c@pgf@counta}{\the\c@pgf@countb}%
%    \end{macrocode}
% Second, create a line to the end point.
%    \begin{macrocode}
            \edef\forest@last@x{%
              \csname forest@pi@\forest@aplusone @\the\c@pgf@countc x\endcsname}%
            \edef\forest@last@y{%
              \csname forest@pi@\forest@aplusone @\the\c@pgf@countc y\endcsname}%
            \pgfsyssoftpath@lineto\forest@last@x\forest@last@y
%    \end{macrocode}
% Finally, ``break'' out of the |\forest@loopc| and |\forest@loopb|.
%    \begin{macrocode}
            \c@pgf@countc=\csname forest@pi@\forest@aplusone @n\endcsname
            \c@pgf@countb=\csname forest@pi@\the\c@pgf@counta @n\endcsname
          \fi
          \advance\c@pgf@countc 1
        \forest@repeatc
        \advance\c@pgf@countb 1
}
%    \end{macrocode}
% |\forest@#1@| is an (ordered) array of points projecting to
% projection with index |#1|. Check if |#2|th point of that array
% equals the last point added to the edge: if not, add it.
%    \begin{macrocode}
\def\forest@gettightedgeofpath@maybemoveto#1#2{%
  \forest@temptrue
  \ifx\forest@last@x\relax\else
    \ifdim\forest@last@x=\csname forest@pi@#1@#2x\endcsname\relax
      \ifdim\forest@last@y=\csname forest@pi@#1@#2y\endcsname\relax
        \forest@tempfalse
      \fi
    \fi
  \fi
  \ifforest@temp
    \edef\forest@last@x{\csname forest@pi@#1@#2x\endcsname}%
    \edef\forest@last@y{\csname forest@pi@#1@#2y\endcsname}%
    \pgfsyssoftpath@moveto\forest@last@x\forest@last@y
  \fi
}
%    \end{macrocode}
%
% Simplify the resulting path by ``unbreaking'' segments where
% possible. (The macro itself is just a wrapper for path processing
% macros below.)
%    \begin{macrocode}
\def\forest@simplifypath#1#2{%
  \pgfsyssoftpath@setcurrentpath\pgfutil@empty
  \forest@save@pgfsyssoftpath@tokendefs
  \let\pgfsyssoftpath@movetotoken\forest@simplifypath@moveto
  \let\pgfsyssoftpath@linetotoken\forest@simplifypath@lineto
  \let\forest@last@x\relax
  \let\forest@last@y\relax
  \let\forest@last@atan\relax
  #1%
  \ifx\forest@last@x\relax\else
    \ifx\forest@last@atan\relax\else
      \pgfsyssoftpath@lineto\forest@last@x\forest@last@y
    \fi
  \fi  
  \forest@restore@pgfsyssoftpath@tokendefs
  \pgfsyssoftpath@getcurrentpath#2%
}
%    \end{macrocode}
% When a move-to is encountered, we flush whatever segment we were
% building, make the move, remember the last position, and set the
% slope to unknown.
%    \begin{macrocode}
\def\forest@simplifypath@moveto#1#2{%
  \ifx\forest@last@x\relax\else
    \pgfsyssoftpath@lineto\forest@last@x\forest@last@y
  \fi
  \pgfsyssoftpath@moveto{#1}{#2}%
  \def\forest@last@x{#1}%
  \def\forest@last@y{#2}%
  \let\forest@last@atan\relax
}
%    \end{macrocode}
% How much may the segment slopes differ that we can still merge them?
% (Ignore |pt|, these are degrees.)  Also, how good is this number?
%    \begin{macrocode}
\def\forest@getedgeofpath@precision{1pt}
%    \end{macrocode}
% When a line-to is encountered\dots
%    \begin{macrocode}
\def\forest@simplifypath@lineto#1#2{%
  \ifx\forest@last@x\relax
%    \end{macrocode}
% If we're not in the middle of a merger, we need to nothing but start
% it.
%    \begin{macrocode}
    \def\forest@last@x{#1}%
    \def\forest@last@y{#2}%
    \let\forest@last@atan\relax
  \else
%    \end{macrocode}
% Otherwise, we calculate the slope of the current segment (i.e.\ the
% segment between the last and the current point), \dots
%    \begin{macrocode}
    \pgfpointdiff{\pgfqpoint{#1}{#2}}{\pgfqpoint{\forest@last@x}{\forest@last@y}}%
    \ifdim\pgf@x<\pgfintersectiontolerance
      \ifdim-\pgf@x<\pgfintersectiontolerance
        \pgf@x=0pt
      \fi
    \fi
    \csname pgfmathatan2\endcsname{\pgf@x}{\pgf@y}%
    \let\forest@current@atan\pgfmathresult
    \ifx\forest@last@atan\relax
%    \end{macrocode}
% If this is the first segment in the current merger, simply remember
% the slope and the last point.
%    \begin{macrocode}
      \def\forest@last@x{#1}%
      \def\forest@last@y{#2}%      
      \let\forest@last@atan\forest@current@atan
    \else
%    \end{macrocode}
% Otherwise, compare the first and the current slope.
%    \begin{macrocode}
      \pgfutil@tempdima=\forest@current@atan pt
      \advance\pgfutil@tempdima -\forest@last@atan pt
      \ifdim\pgfutil@tempdima<0pt\relax
        \multiply\pgfutil@tempdima -1
      \fi
      \ifdim\pgfutil@tempdima<\forest@getedgeofpath@precision\relax 
      \else
%    \end{macrocode}
% If the slopes differ too much, flush the path up to the previous
% segment, and set up a new first slope.
%    \begin{macrocode}
        \pgfsyssoftpath@lineto\forest@last@x\forest@last@y        
        \let\forest@last@atan\forest@current@atan
      \fi
%    \end{macrocode}
% In any event, update the last point.
%    \begin{macrocode}
      \def\forest@last@x{#1}%
      \def\forest@last@y{#2}%
    \fi
  \fi
}
%    \end{macrocode}
%
%
% \subsection{Get rectangle/band edge}
%
%    \begin{macrocode}
\def\forest@getnegativerectangleedgeofpath#1#2{%
  \forest@getnegativerectangleorbandedgeofpath{#1}{#2}{\the\pgf@xb}}
\def\forest@getpositiverectangleedgeofpath#1#2{%
  \forest@getpositiverectangleorbandedgeofpath{#1}{#2}{\the\pgf@xb}}
\def\forest@getbothrectangleedgesofpath#1#2#3{%
  \forest@getbothrectangleorbandedgesofpath{#1}{#2}{#3}{\the\pgf@xb}}
\def\forest@bandlength{5000pt} % something large (ca. 180cm), but still manageable for TeX without producing `too large' errors
\def\forest@getnegativebandedgeofpath#1#2{%
  \forest@getnegativerectangleorbandedgeofpath{#1}{#2}{\forest@bandlength}}
\def\forest@getpositivebandedgeofpath#1#2{%
  \forest@getpositiverectangleorbandedgeofpath{#1}{#2}{\forest@bandlength}}
\def\forest@getbothbandedgesofpath#1#2#3{%
  \forest@getbothrectangleorbandedgesofpath{#1}{#2}{#3}{\forest@bandlength}}
\def\forest@getnegativerectangleorbandedgeofpath#1#2#3{%
  \forest@path@getboundingrectangle@ls#1{\forest@grow}%
  \edef\forest@gre@path{%
    \noexpand\pgfsyssoftpath@movetotoken{\the\pgf@xa}{\the\pgf@ya}%
    \noexpand\pgfsyssoftpath@linetotoken{#3}{\the\pgf@ya}%
  }%
  {%
    \pgftransformreset
    \pgftransformrotate{\forest@grow}%
    \forest@pgfpathtransformed\forest@gre@path
  }%
  \pgfsyssoftpath@getcurrentpath#2%
}
\def\forest@getpositiverectangleorbandedgeofpath#1#2#3{%
  \forest@path@getboundingrectangle@ls#1{\forest@grow}%
  \edef\forest@gre@path{%
    \noexpand\pgfsyssoftpath@movetotoken{\the\pgf@xa}{\the\pgf@yb}%
    \noexpand\pgfsyssoftpath@linetotoken{#3}{\the\pgf@yb}%
  }%
  {%
    \pgftransformreset
    \pgftransformrotate{\forest@grow}%
    \forest@pgfpathtransformed\forest@gre@path
  }%
  \pgfsyssoftpath@getcurrentpath#2%
}
\def\forest@getbothrectangleorbandedgesofpath#1#2#3#4{%
  \forest@path@getboundingrectangle@ls#1{\forest@grow}%
  \edef\forest@gre@negpath{%
    \noexpand\pgfsyssoftpath@movetotoken{\the\pgf@xa}{\the\pgf@ya}%
    \noexpand\pgfsyssoftpath@linetotoken{#4}{\the\pgf@ya}%
  }%
  \edef\forest@gre@pospath{%
    \noexpand\pgfsyssoftpath@movetotoken{\the\pgf@xa}{\the\pgf@yb}%
    \noexpand\pgfsyssoftpath@linetotoken{#4}{\the\pgf@yb}%
  }%
  {%
    \pgftransformreset
    \pgftransformrotate{\forest@grow}%
    \forest@pgfpathtransformed\forest@gre@negpath
  }%
  \pgfsyssoftpath@getcurrentpath#2%
  {%
    \pgftransformreset
    \pgftransformrotate{\forest@grow}%
    \forest@pgfpathtransformed\forest@gre@pospath
  }%
  \pgfsyssoftpath@getcurrentpath#3%
}
%    \end{macrocode}
%
% \subsection{Distance between paths}
% \label{imp:distance}
% 
% Another crucial part of the package.
%
%    \begin{macrocode}
\def\forest@distance@between@edge@paths#1#2#3{%
  % #1, #2 = (edge) paths
  %
  % project paths
  \forest@projectpathtogrowline#1{forest@p1@}%
  \forest@projectpathtogrowline#2{forest@p2@}%
  % merge projections (the lists are sorted already, because edge
  % paths are |sorted|)
  \forest@dbep@mergeprojections
    {forest@p1@}{forest@p2@}%
    {forest@P1@}{forest@P2@}%
  % process projections
  \forest@processprojectioninfo{forest@P1@}{forest@PI1@}%
  \forest@processprojectioninfo{forest@P2@}{forest@PI2@}%
  % break paths
  \forest@breakpath#1{forest@PI1@}\forest@broken@one
  \forest@breakpath#2{forest@PI2@}\forest@broken@two
  % sort inner arrays ---optimize: it's enough to find max and min
  \forest@sort@inner@arrays{forest@PI1@}\forest@sort@descending
  \forest@sort@inner@arrays{forest@PI2@}\forest@sort@ascending
  % compute the distance
  \let\forest@distance\relax
  \c@pgf@countc=0
  \loop
  \ifnum\c@pgf@countc<\csname forest@PI1@n\endcsname\relax
    \ifnum\csname forest@PI1@\the\c@pgf@countc @n\endcsname=0 \else
      \ifnum\csname forest@PI2@\the\c@pgf@countc @n\endcsname=0 \else
        \pgfutil@tempdima=\csname forest@PI2@\the\c@pgf@countc @0d\endcsname\relax
        \advance\pgfutil@tempdima -\csname forest@PI1@\the\c@pgf@countc @0d\endcsname\relax
        \ifx\forest@distance\relax
          \edef\forest@distance{\the\pgfutil@tempdima}%
        \else 
          \ifdim\pgfutil@tempdima<\forest@distance\relax
            \edef\forest@distance{\the\pgfutil@tempdima}%
          \fi
        \fi
      \fi
    \fi
    \advance\c@pgf@countc 1
  \repeat
  \let#3\forest@distance
}
  % merge projections: we need two projection arrays, both containing
  % projection points from both paths, but each with the original
  % points from only one path
\def\forest@dbep@mergeprojections#1#2#3#4{%
  % TODO: optimize: v bistvu ni treba sortirat, ker je edge path že sortiran
  \forest@sortprojections{#1}%
  \forest@sortprojections{#2}%
  \c@pgf@counta=0
  \c@pgf@countb=0
  \c@pgf@countc=0
  \edef\forest@input@prefix@one{#1}%
  \edef\forest@input@prefix@two{#2}%
  \edef\forest@output@prefix@one{#3}%
  \edef\forest@output@prefix@two{#4}%
  \forest@dbep@mp@iterate
  \csedef{#3n}{\the\c@pgf@countc}%
  \csedef{#4n}{\the\c@pgf@countc}%
}
\def\forest@dbep@mp@iterate{%
  \let\forest@dbep@mp@next\forest@dbep@mp@iterate
  \ifnum\c@pgf@counta<\csname\forest@input@prefix@one n\endcsname\relax
    \ifnum\c@pgf@countb<\csname\forest@input@prefix@two n\endcsname\relax
      \let\forest@dbep@mp@next\forest@dbep@mp@do
    \else
      \let\forest@dbep@mp@next\forest@dbep@mp@iteratefirst
    \fi
  \else
    \ifnum\c@pgf@countb<\csname\forest@input@prefix@two n\endcsname\relax
      \let\forest@dbep@mp@next\forest@dbep@mp@iteratesecond
    \else
      \let\forest@dbep@mp@next\relax
    \fi
  \fi
  \forest@dbep@mp@next
}
\def\forest@dbep@mp@do{%
  \forest@sort@cmptwodimcs%
    {\forest@input@prefix@one\the\c@pgf@counta xp}%
    {\forest@input@prefix@one\the\c@pgf@counta yp}%
    {\forest@input@prefix@two\the\c@pgf@countb xp}%
    {\forest@input@prefix@two\the\c@pgf@countb yp}%    
  \if\forest@sort@cmp@result=%
    \forest@dbep@mp@@store@p\forest@input@prefix@one\c@pgf@counta
    \forest@dbep@mp@@store@o\forest@input@prefix@one
        \c@pgf@counta\forest@output@prefix@one
    \forest@dbep@mp@@store@o\forest@input@prefix@two
        \c@pgf@countb\forest@output@prefix@two
    \advance\c@pgf@counta 1
    \advance\c@pgf@countb 1
  \else
    \if\forest@sort@cmp@result>%
      \forest@dbep@mp@@store@p\forest@input@prefix@two\c@pgf@countb
      \forest@dbep@mp@@store@o\forest@input@prefix@two
          \c@pgf@countb\forest@output@prefix@two
      \advance\c@pgf@countb 1
    \else%<
      \forest@dbep@mp@@store@p\forest@input@prefix@one\c@pgf@counta
      \forest@dbep@mp@@store@o\forest@input@prefix@one
          \c@pgf@counta\forest@output@prefix@one
      \advance\c@pgf@counta 1
    \fi
  \fi
  \advance\c@pgf@countc 1
  \forest@dbep@mp@iterate
}
\def\forest@dbep@mp@@store@p#1#2{%
  \csletcs
    {\forest@output@prefix@one\the\c@pgf@countc xp}%
    {#1\the#2xp}%
  \csletcs
    {\forest@output@prefix@one\the\c@pgf@countc yp}%
    {#1\the#2yp}%
  \csletcs
    {\forest@output@prefix@two\the\c@pgf@countc xp}%
    {#1\the#2xp}%
  \csletcs
    {\forest@output@prefix@two\the\c@pgf@countc yp}%
    {#1\the#2yp}%
}
\def\forest@dbep@mp@@store@o#1#2#3{%
  \csletcs{#3\the\c@pgf@countc xo}{#1\the#2xo}%
  \csletcs{#3\the\c@pgf@countc yo}{#1\the#2yo}%
}
\def\forest@dbep@mp@iteratefirst{%
  \forest@dbep@mp@iterateone\forest@input@prefix@one\c@pgf@counta\forest@output@prefix@one
}
\def\forest@dbep@mp@iteratesecond{%
  \forest@dbep@mp@iterateone\forest@input@prefix@two\c@pgf@countb\forest@output@prefix@two
}
\def\forest@dbep@mp@iterateone#1#2#3{%
  \loop
  \ifnum#2<\csname#1n\endcsname\relax
    \forest@dbep@mp@@store@p#1#2%
    \forest@dbep@mp@@store@o#1#2#3%
    \advance\c@pgf@countc 1
    \advance#21
  \repeat
}
%    \end{macrocode}
% 
% \subsection{Utilities}
%
% Equality test: points are considered equal if they differ less than
% |\pgfintersectiontolerance| in each coordinate.
%    \begin{macrocode}
\newif\ifforest@equaltotolerance
\def\forest@equaltotolerance#1#2{{%
  \pgfpointdiff{#1}{#2}%
  \ifdim\pgf@x<0pt \multiply\pgf@x -1 \fi
  \ifdim\pgf@y<0pt \multiply\pgf@y -1 \fi
  \global\forest@equaltotolerancefalse
  \ifdim\pgf@x<\pgfintersectiontolerance\relax
    \ifdim\pgf@y<\pgfintersectiontolerance\relax
      \global\forest@equaltotolerancetrue
    \fi
  \fi
}}
%    \end{macrocode}
%    
% Save/restore |pgf|s |\pgfsyssoftpath@...token| definitions.
%    \begin{macrocode}
\def\forest@save@pgfsyssoftpath@tokendefs{%
  \let\forest@origmovetotoken\pgfsyssoftpath@movetotoken
  \let\forest@origlinetotoken\pgfsyssoftpath@linetotoken
  \let\forest@origcurvetosupportatoken\pgfsyssoftpath@curvetosupportatoken
  \let\forest@origcurvetosupportbtoken\pgfsyssoftpath@curvetosupportbtoken
  \let\forest@origcurvetotoken\pgfsyssoftpath@curvetototoken
  \let\forest@origrectcornertoken\pgfsyssoftpath@rectcornertoken
  \let\forest@origrectsizetoken\pgfsyssoftpath@rectsizetoken
  \let\forest@origclosepathtoken\pgfsyssoftpath@closepathtoken  
  \let\pgfsyssoftpath@movetotoken\forest@badtoken
  \let\pgfsyssoftpath@linetotoken\forest@badtoken
  \let\pgfsyssoftpath@curvetosupportatoken\forest@badtoken
  \let\pgfsyssoftpath@curvetosupportbtoken\forest@badtoken
  \let\pgfsyssoftpath@curvetototoken\forest@badtoken
  \let\pgfsyssoftpath@rectcornertoken\forest@badtoken
  \let\pgfsyssoftpath@rectsizetoken\forest@badtoken
  \let\pgfsyssoftpath@closepathtoken\forest@badtoken
}
\def\forest@badtoken{%
  \PackageError{forest}{This token should not be in this path}{}%
}
\def\forest@restore@pgfsyssoftpath@tokendefs{%
  \let\pgfsyssoftpath@movetotoken\forest@origmovetotoken
  \let\pgfsyssoftpath@linetotoken\forest@origlinetotoken
  \let\pgfsyssoftpath@curvetosupportatoken\forest@origcurvetosupportatoken
  \let\pgfsyssoftpath@curvetosupportbtoken\forest@origcurvetosupportbtoken
  \let\pgfsyssoftpath@curvetototoken\forest@origcurvetotoken
  \let\pgfsyssoftpath@rectcornertoken\forest@origrectcornertoken
  \let\pgfsyssoftpath@rectsizetoken\forest@origrectsizetoken
  \let\pgfsyssoftpath@closepathtoken\forest@origclosepathtoken
}
%    \end{macrocode}
%
% Extend path |#1| with path |#2| translated by point |#3|.
%    \begin{macrocode}
\def\forest@extendpath#1#2#3{%
  \pgf@process{#3}%
  \pgfsyssoftpath@setcurrentpath#1%
  \forest@save@pgfsyssoftpath@tokendefs
  \let\pgfsyssoftpath@movetotoken\forest@extendpath@moveto
  \let\pgfsyssoftpath@linetotoken\forest@extendpath@lineto
  #2%
  \forest@restore@pgfsyssoftpath@tokendefs
  \pgfsyssoftpath@getcurrentpath#1%
}
\def\forest@extendpath@moveto#1#2{%
  \forest@extendpath@do{#1}{#2}\pgfsyssoftpath@moveto
}
\def\forest@extendpath@lineto#1#2{%
  \forest@extendpath@do{#1}{#2}\pgfsyssoftpath@lineto
}
\def\forest@extendpath@do#1#2#3{%
  {%
    \advance\pgf@x #1
    \advance\pgf@y #2
    #3{\the\pgf@x}{\the\pgf@y}%
  }%
}
%    \end{macrocode}
%
% Get bounding rectangle of the path. |#1| = the path, |#2| = grow.
% Returns (|\pgf@xa|=min x/l, |\pgf@ya|=max y/s, |\pgf@xb|=min x/l, |\pgf@yb|=max y/s).  (If path |#1|
% is empty, the result is undefined.)
%    \begin{macrocode}
\def\forest@path@getboundingrectangle@ls#1#2{%
  {%
    \pgftransformreset
    \pgftransformrotate{-(#2)}%
    \forest@pgfpathtransformed#1%
  }%
  \pgfsyssoftpath@getcurrentpath\forest@gbr@rotatedpath
  \forest@path@getboundingrectangle@xy\forest@gbr@rotatedpath
}
\def\forest@path@getboundingrectangle@xy#1{%
  \forest@save@pgfsyssoftpath@tokendefs
  \let\pgfsyssoftpath@movetotoken\forest@gbr@firstpoint
  \let\pgfsyssoftpath@linetotoken\forest@gbr@firstpoint
  #1%
  \forest@restore@pgfsyssoftpath@tokendefs
}
\def\forest@gbr@firstpoint#1#2{%
  \pgf@xa=#1 \pgf@xb=#1 \pgf@ya=#2 \pgf@yb=#2
  \let\pgfsyssoftpath@movetotoken\forest@gbr@point
  \let\pgfsyssoftpath@linetotoken\forest@gbr@point
}
\def\forest@gbr@point#1#2{%
  \ifdim#1<\pgf@xa\relax\pgf@xa=#1 \fi
  \ifdim#1>\pgf@xb\relax\pgf@xb=#1 \fi
  \ifdim#2<\pgf@ya\relax\pgf@ya=#2 \fi
  \ifdim#2>\pgf@yb\relax\pgf@yb=#2 \fi
}
%    \end{macrocode}
%
% \section{The outer UI}
% 
% \subsection{Package options}
%
%    \begin{macrocode}
\newif\ifforesttikzcshack
\foresttikzcshacktrue
\newif\ifforest@install@keys@to@tikz@path@
\forest@install@keys@to@tikz@path@true
\forestset{package@options/.cd,
  external/.is if=forest@external@,
  tikzcshack/.is if=foresttikzcshack,
  tikzinstallkeys/.is if=forest@install@keys@to@tikz@path@,
}
%    \end{macrocode}
% \subsection{Externalization}
%    \begin{macrocode}
\pgfkeys{/forest/external/.cd,
  copy command/.initial={cp "\source" "\target"},
  optimize/.is if=forest@external@optimize@,
  context/.initial={%
    \forestOve{\csname forest@id@of@standard node\endcsname}{environment@formula}},
  depends on macro/.style={context/.append/.expanded={%
      \expandafter\detokenize\expandafter{#1}}},
}
\def\forest@external@copy#1#2{%
  \pgfkeysgetvalue{/forest/external/copy command}\forest@copy@command
  \ifx\forest@copy@command\pgfkeysnovalue\else
    \IfFileExists{#1}{%
      {%
        \def\source{#1}%
        \def\target{#2}%
        \immediate\write18{\forest@copy@command}%
      }%
    }{}%
  \fi
}
\newif\ifforest@external@
\newif\ifforest@external@optimize@
\forest@external@optimize@true
\ProcessPgfPackageOptions{/forest/package@options}
\ifforest@install@keys@to@tikz@path@
  \tikzset{fit to tree/.style={/forest/fit to tree}}
\fi
\ifforest@external@
  \ifdefined\tikzexternal@tikz@replacement\else
    \usetikzlibrary{external}%
  \fi
  \pgfkeys{%
    /tikz/external/failed ref warnings for={},
    /pgf/images/aux in dpth=false,
  }%
  \tikzifexternalizing{}{%
    \forest@external@copy{\jobname.aux}{\jobname.aux.copy}%
  }%
  \AtBeginDocument{%
    \tikzifexternalizing{%
      \IfFileExists{\tikzexternalrealjob.aux.copy}{%
        \makeatletter
        \input \tikzexternalrealjob.aux.copy
        \makeatother
      }{}%
    }{%
      \newwrite\forest@auxout
      \immediate\openout\forest@auxout=\tikzexternalrealjob.for.tmp
    }%
    \IfFileExists{\tikzexternalrealjob.for}{%
      {%
        \makehashother\makeatletter
        \input \tikzexternalrealjob.for
      }%
    }{}%
  }%
  \AtEndDocument{%
    \tikzifexternalizing{}{%
      \immediate\closeout\forest@auxout
      \forest@external@copy{\jobname.for.tmp}{\jobname.for}%
    }%
  }%
\fi
%    \end{macrocode}
% 
% \subsection{The \texttt{forest} environment}
% \label{imp:forest-environment}
%
% There are three ways to invoke \foRest;: the environent and the starless and the starred version
% of the macro.  The latter creates no group.
% 
% Most of the code in this section deals with externalization. 
%
%    \begin{macrocode}
\newenvironment{forest}{\pgfkeysalso{/forest/begin forest}\Collect@Body\forest@env}{}
\long\def\Forest{\pgfkeysalso{/forest/begin forest}\@ifnextchar*{\forest@nogroup}{\forest@group}}
\def\forest@group#1{{\forest@env{#1}}}
\def\forest@nogroup*#1{\forest@env{#1}}
\newif\ifforest@externalize@tree@
\newif\ifforest@was@tikzexternalwasenable
\long\def\forest@env#1{%
  \let\forest@external@next\forest@begin
  \forest@was@tikzexternalwasenablefalse
  \ifdefined\tikzexternal@tikz@replacement
    \ifx\tikz\tikzexternal@tikz@replacement
      \forest@was@tikzexternalwasenabletrue
      \tikzexternaldisable
    \fi
  \fi
  \forest@externalize@tree@false
  \ifforest@external@
    \ifforest@was@tikzexternalwasenable
      \tikzifexternalizing{%
        \let\forest@external@next\forest@begin@externalizing
      }{%
        \let\forest@external@next\forest@begin@externalize
      }%
    \fi
  \fi
  \forest@standardnode@calibrate
  \forest@external@next{#1}%
}
%    \end{macrocode}
% We're externalizing, i.e.\ this code gets executed in the embedded call.
%    \begin{macrocode}
\long\def\forest@begin@externalizing#1{%
  \forest@external@setup{#1}%
  \let\forest@external@next\forest@begin
  \forest@externalize@inner@n=-1
  \ifforest@external@optimize@\forest@externalizing@maybeoptimize\fi
  \forest@external@next{#1}%
  \tikzexternalenable
}
\def\forest@externalizing@maybeoptimize{%
  \edef\forest@temp{\tikzexternalrealjob-forest-\forest@externalize@outer@n}%
  \edef\forest@marshal{%
    \noexpand\pgfutil@in@
      {\expandafter\detokenize\expandafter{\forest@temp}.}
      {\expandafter\detokenize\expandafter{\pgfactualjobname}.}%
  }\forest@marshal
  \ifpgfutil@in@
  \else
    \let\forest@external@next\@gobble
  \fi
}
%    \end{macrocode}
% Externalization is enabled, we're in the outer process, deciding if the picture is up-to-date.
%    \begin{macrocode}
\long\def\forest@begin@externalize#1{%
  \forest@external@setup{#1}%
  \iftikzexternal@file@isuptodate
    \setbox0=\hbox{%
      \csname forest@externalcheck@\forest@externalize@outer@n\endcsname
    }%
  \fi
  \iftikzexternal@file@isuptodate
    \csname forest@externalload@\forest@externalize@outer@n\endcsname
  \else
    \forest@externalize@tree@true
    \forest@externalize@inner@n=-1
    \forest@begin{#1}%
    \ifcsdef{forest@externalize@@\forest@externalize@id}{}{%
      \immediate\write\forest@auxout{%
        \noexpand\forest@external
        {\forest@externalize@outer@n}%
        {\expandafter\detokenize\expandafter{\forest@externalize@id}}%
        {\expandonce\forest@externalize@checkimages}%
        {\expandonce\forest@externalize@loadimages}%
      }%
    }%
  \fi
  \tikzexternalenable
}
\def\forest@includeexternal@check#1{%
  \tikzsetnextfilename{#1}%
  \tikzexternal@externalizefig@systemcall@uptodatecheck
}
\def\makehashother{\catcode`\#=12}%
\long\def\forest@external@setup#1{%
  % set up \forest@externalize@id and \forest@externalize@outer@n
  % we need to deal with #s correctly (\write doubles them)
  \setbox0=\hbox{\makehashother\makeatletter
    \scantokens{\forest@temp@toks{#1}}\expandafter
  }%
  \expandafter\forest@temp@toks\expandafter{\the\forest@temp@toks}%
  \edef\forest@temp{\pgfkeysvalueof{/forest/external/context}}%
  \edef\forest@externalize@id{%
    \expandafter\detokenize\expandafter{\forest@temp}%
    @@%
    \expandafter\detokenize\expandafter{\the\forest@temp@toks}%
  }%
  \letcs\forest@externalize@outer@n{forest@externalize@@\forest@externalize@id}%
  \ifdefined\forest@externalize@outer@n
    \global\tikzexternal@file@isuptodatetrue
  \else
    \global\advance\forest@externalize@max@outer@n 1
    \edef\forest@externalize@outer@n{\the\forest@externalize@max@outer@n}%
    \global\tikzexternal@file@isuptodatefalse
  \fi
  \def\forest@externalize@loadimages{}%
  \def\forest@externalize@checkimages{}%
}
\newcount\forest@externalize@max@outer@n
\global\forest@externalize@max@outer@n=0
\newcount\forest@externalize@inner@n
%    \end{macrocode}
% The \texttt{.for} file is a string of calls of this macro.
%    \begin{macrocode}
\long\def\forest@external#1#2#3#4{% #1=n,#2=context+source code,#3=update check code, #4=load code
  \ifnum\forest@externalize@max@outer@n<#1
    \global\forest@externalize@max@outer@n=#1
  \fi
  \global\csdef{forest@externalize@@\detokenize{#2}}{#1}%
  \global\csdef{forest@externalcheck@#1}{#3}%
  \global\csdef{forest@externalload@#1}{#4}%
  \tikzifexternalizing{}{%
    \immediate\write\forest@auxout{%
      \noexpand\forest@external{#1}%
      {\expandafter\detokenize\expandafter{#2}}%
      {\unexpanded{#3}}%
      {\unexpanded{#4}}%
    }%
  }%
}
%    \end{macrocode}
% These two macros include the external picture.
%    \begin{macrocode}
\def\forest@includeexternal#1{%
  \edef\forest@temp{\pgfkeysvalueof{/forest/external/context}}%
  \typeout{forest: Including external picture '#1' for forest context+code:
    '\expandafter\detokenize\expandafter{\forest@externalize@id}'}%
  {%
    %\def\pgf@declaredraftimage##1##2{\def\pgf@image{\hbox{}}}%
    \tikzsetnextfilename{#1}%
    \tikzexternalenable
    \tikz{}%
  }%
}
\def\forest@includeexternal@box#1#2{%
  \global\setbox#1=\hbox{\forest@includeexternal{#2}}%
}
%    \end{macrocode}
% This code runs the bracket parser and stage processing.
%    \begin{macrocode}
\long\def\forest@begin#1{%
  \iffalse{\fi\forest@parsebracket#1}%
}
\def\forest@parsebracket{%
  \bracketParse{\forest@get@root@afterthought}\forest@root=%
}
\def\forest@get@root@afterthought{%
  \expandafter\forest@get@root@afterthought@\expandafter{\iffalse}\fi
}
\long\def\forest@get@root@afterthought@#1{%
  \ifblank{#1}{}{%
    \forestOeappto{\forest@root}{given options}{,afterthought={\unexpanded{#1}}}%
  }%
  \forest@do
}
\def\forest@do{%
  \forest@node@Compute@numeric@ts@info{\forest@root}%
  \forestset{process keylist=given options}%
  \forestset{stages}%
  \pgfkeysalso{/forest/end forest}%
  \ifforest@was@tikzexternalwasenable
    \tikzexternalenable
  \fi
}
%    \end{macrocode}
%
% \subsection{Standard node}
% \label{impl:standard-node}
%
% The standard node should be calibrated when entering the forest env: ^^AAAAAAAAAAAAAAAAAAAAAAAA
% ^^A|\forestNodeHandle{standard node}.calibrate()|.  What the calibration does is defined in a call to
% ^^A|\forestStandardNode|.
% The standard node init does \emph{not} initialize options from a(nother) standard node!
%    \begin{macrocode}
\def\forest@standardnode@new{%
  \advance\forest@node@maxid1
  \forest@fornode{\the\forest@node@maxid}{%
    \forest@node@init
    \forest@node@setname{standard node}%
  }%
}
\def\forest@standardnode@calibrate{%
  \forest@fornode{\forest@node@Nametoid{standard node}}{%
    \edef\forest@environment{\forestove{environment@formula}}%
    \forestoget{previous@environment}\forest@previous@environment
    \ifx\forest@environment\forest@previous@environment\else
      \forestolet{previous@environment}\forest@environment
      \forest@node@typeset
      \forestoget{calibration@procedure}\forest@temp
      \expandafter\forestset\expandafter{\forest@temp}%
    \fi
  }%
}
%    \end{macrocode}
% Usage: |\forestStandardNode[#1]{#2}{#3}{#4}|.  |#1| = standard node specification --- specify it
% as any other node content (but without children, of course).  |#2| = the environment fingerprint:
% list the values of parameters that influence the standard node's height and depth; the standard
% will be adjusted whenever any of these parameters changes.  |#3| = the calibration procedure: a
% list of usual forest options which should calculating the values of exported options.  |#4| = a
% comma-separated list of exported options: every newly created node receives the initial values of
% exported options from the standard node.  (The standard node definition is local to the \TeX\
% group.)
%    \begin{macrocode}
\def\forestStandardNode[#1]#2#3#4{%
  \let\forest@standardnode@restoretikzexternal\relax
  \ifdefined\tikzexternaldisable
    \ifx\tikz\tikzexternal@tikz@replacement
      \tikzexternaldisable
      \let\forest@standardnode@restoretikzexternal\tikzexternalenable
    \fi
  \fi
  \forest@standardnode@new
  \forest@fornode{\forest@node@Nametoid{standard node}}{%
    \forestset{content=#1}%
    \forestoset{environment@formula}{#2}%
    \edef\forest@temp{\unexpanded{#3}}%
    \forestolet{calibration@procedure}\forest@temp
    \def\forest@calibration@initializing@code{}%
    \pgfqkeys{/forest/initializing@code}{#4}%
    \forestolet{initializing@code}\forest@calibration@initializing@code
    \forest@standardnode@restoretikzexternal
  }
}
\forestset{initializing@code/.unknown/.code={%
    \eappto\forest@calibration@initializing@code{%
      \noexpand\forestOget{\forest@node@Nametoid{standard node}}{\pgfkeyscurrentname}\noexpand\forest@temp
      \noexpand\forestolet{\pgfkeyscurrentname}\noexpand\forest@temp
    }%
  }
}
%    \end{macrocode}
% This macro is called from a new (non-standard) node's init.
%    \begin{macrocode}
\def\forest@initializefromstandardnode{%
  \forestOve{\forest@node@Nametoid{standard node}}{initializing@code}%
}
%    \end{macrocode}
% Define the default standard node.  Standard content: dj --- in Computer Modern font, d is the
% highest and j the deepest letter (not character!).  Environment fingerprint: the height of the
% strut and the values of inner and outer seps.  Calibration procedure: (i) \keyname{l sep}
% equals the height of the strut plus the value of \keyname{inner ysep}, implementing both font-size and
% inner sep dependency; (ii) The effect of \keyname{l} on the standard node should be the same as the
% effect of \keyname{l sep}, thus, we derive \keyname{l} from \keyname{l sep} by adding
% to the latter the total height of the standard node (plus the double outer sep, one for the parent
% and one for the child).  (iii) s sep is straightforward: a double inner xsep.  Exported options:
% options, calculated in the calibration.  (Tricks: to change the default anchor, set it in |#1| and
% export it; to set a non-forest node option (such as \keyname{draw} or \keyname{blue}) as default, set it
% in |#1| and export the (internal) option \keyname{node options}.)
%    \begin{macrocode}
\forestStandardNode[dj]
  {%
    \forestOve{\forest@node@Nametoid{standard node}}{content},%
    \the\ht\strutbox,\the\pgflinewidth,%
    \pgfkeysvalueof{/pgf/inner ysep},\pgfkeysvalueof{/pgf/outer ysep},%
    \pgfkeysvalueof{/pgf/inner xsep},\pgfkeysvalueof{/pgf/outer xsep}%
  }
  {
    l sep={\the\ht\strutbox+\pgfkeysvalueof{/pgf/inner ysep}},
    l={l_sep()+abs(max_y()-min_y())+2*\pgfkeysvalueof{/pgf/outer ysep}},
    s sep={2*\pgfkeysvalueof{/pgf/inner xsep}}
  }
  {l sep,l,s sep}
%    \end{macrocode}
%
%
% \subsection{\texttt{ls} coordinate system}
% \label{imp:ls-coordinates}
%
%    \begin{macrocode}
\pgfqkeys{/forest/@cs}{%
  name/.code={%
    \edef\forest@cn{\forest@node@Nametoid{#1}}%
    \forest@forestcs@resetxy},
  id/.code={%
    \edef\forest@cn{#1}%
    \forest@forestcs@resetxy},
  go/.code={%
    \forest@go{#1}%
    \forest@forestcs@resetxy},
  anchor/.code={\forest@forestcs@anchor{#1}},
  l/.code={%
    \pgfmathsetlengthmacro\forest@forestcs@l{#1}%
    \forest@forestcs@ls
  },
  s/.code={%
    \pgfmathsetlengthmacro\forest@forestcs@s{#1}%
    \forest@forestcs@ls
  },
  .unknown/.code={%
    \expandafter\pgfutil@in@\expandafter.\expandafter{\pgfkeyscurrentname}%
    \ifpgfutil@in@
      \expandafter\forest@forestcs@namegoanchor\pgfkeyscurrentname\forest@end
    \else
      \expandafter\forest@nameandgo\expandafter{\pgfkeyscurrentname}%
      \forest@forestcs@resetxy
    \fi
  }
}
\def\forest@forestcs@resetxy{%
  \ifnum\forest@cn=0
  \else
    \global\pgf@x\forestove{x}%
    \global\pgf@y\forestove{y}%
  \fi
}
\def\forest@forestcs@ls{%
  \ifdefined\forest@forestcs@l
    \ifdefined\forest@forestcs@s
      {%
        \pgftransformreset
        \pgftransformrotate{\forestove{grow}}%
        \pgfpointtransformed{\pgfpoint{\forest@forestcs@l}{\forest@forestcs@s}}%
      }%
      \global\advance\pgf@x\forestove{x}%
      \global\advance\pgf@y\forestove{y}%
    \fi
  \fi
}
\def\forest@forestcs@anchor#1{%
  \edef\forest@marshal{%
    \noexpand\forest@original@tikz@parse@node\relax
    (\forestove{name}\ifx\relax#1\relax\else.\fi#1)%
  }\forest@marshal
}
\def\forest@forestcs@namegoanchor#1.#2\forest@end{%
  \forest@nameandgo{#1}%
  \forest@forestcs@anchor{#2}%
}
\tikzdeclarecoordinatesystem{forest}{%
  \forest@forthis{%
    \forest@forestcs@resetxy
    \ifdefined\forest@forestcs@l\undef\forest@forestcs@l\fi
    \ifdefined\forest@forestcs@s\undef\forest@forestcs@s\fi
    \pgfqkeys{/forest/@cs}{#1}%
  }%
}
%    \end{macrocode}
%
% \addcontentsline{toc}{section}{References}
% \bibliography{tex}
% \bibliographystyle{plain}
%
% \newpage
% \addcontentsline{toc}{section}{Index}
% \makeatletter\c@IndexColumns=2 \makeatother
% \IndexPrologue{\section*{Index}}
% \PrintIndex
%
% \endinput
% 
% Local Variables: 
% mode: doctex
% fill-column: 100
% LaTeX-command: "forestlatex -shell-escape"
% End: