summaryrefslogtreecommitdiff
path: root/graphics/pgf/contrib/zx-calculus/zx-calculus.tex
blob: 5531da1e9ce4fea1739dfc94607a085d95a7cf8f (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
\documentclass[a4paper,doc2]{ltxdoc} % doc2 is needed to force the old version, or links get colored in a weird red way even with hidelinks. https://github.com/latex3/latex2e/issues/822

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% Packages
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Warning: if you compile and get:
%% ERROR: Argument of \tikz@lib@matrix@with@options has an extra }.
%% make sure to fix catcodes around it as | is given a different meaning in ltxdoc.

\usepackage{amsmath}
\usepackage[margin=3cm]{geometry}
\usepackage{calc}
\usepackage{braket}
\usepackage{tikz}
\usetikzlibrary{shadows,fit}
\usetikzlibrary{snakes}
\usetikzlibrary{nfold} % needs very recent CTAN > 2023, or manually copy the .tex files
% \usetikzlibrary fails because file is not in current directory, lazy to setup TEXINPUTS
\makeatletter
  \usetikzlibrary{zx-calculus}
\makeatother
% Loads the great package that produces tikz-like manual (see also tikzcd for examples)
\input{pgfmanual-en-macros.tex} % Is supposed to be included in recent TeX distributions, but I get errors...
\usepackage{makeidx} % Produces an index of commands.
\makeindex % Useful or not index will be created
\usepackage{alertmessage} % For warning, info...
\usepackage[hidelinks]{hyperref}
\newcommand{\mylink}[2]{\href{#1}{#2}\footnote{\url{#1}}}
\usepackage{verbatim}
\usepackage{cleveref}
\usepackage{mathtools}
\usepackage{listings}
\usepackage [
n,
lambda,
advantage,
operators,
sets,
adversary,
landau,
probability,
notions,
logic,
ff,
mm,
primitives,
events,
complexity,
asymptotics,
keys
] {cryptocode}

%%%% Bibliography
% I want to have separate references for appendix and main body
% https://tex.stackexchange.com/questions/98660/
\usepackage[style=trad-alpha,
  sortcites=true,
  doi=false,
  url=false,
  giveninits=true, % Bob Foo --> B. Foo
  isbn=false,
  url=false,
  eprint=false,
  sortcites=false, % \cite{B,A,C}: [A,B,C] --> [B,A,C]
]{biblatex}
\renewcommand{\multicitedelim}{, } % [ABC96; DEF12] -> [ABC96, DEF12]
% [unknown_ref] => [??]
% https://tex.stackexchange.com/a/352573
\makeatletter
\protected\def\abx@missing#1{\textbf{??}}
\makeatother
\renewcommand*{\bibfont}{\normalfont\small} % BibLatex font seems bigger than Bibtex?
\addbibresource{biblio.bib}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% Documentation
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\begin{document}
%%% Title: thanks tikzcd for the styling
\begin{center}
  \vspace*{1em} % Thanks tikzcd
  \tikz\node[scale=1.2]{%
    \color{gray}\Huge\ttfamily \char`\{\raisebox{.09em}{\textcolor{red!75!black}{zx\raisebox{-0.1em}{-}calculus}}\char`\}};

  \vspace{0.5em}
  {\Large\bfseries ZX-calculus with \tikzname}

  \vspace{1em}
  {Léo Colisson \quad Version 2.0}\\[3mm]
  {\href{https://github.com/leo-colisson/zx-calculus}{\texttt{github.com/leo-colisson/zx-calculus}}}
\end{center}

\tableofcontents

\section{Introduction}

This library (based on the great \tikzname{} and \tikzname-cd packages) allows you to typeset ZX-calculus and diagrams for diagrammatic reasoning~\cite{CK17_PicturingQuantumProcesses,van20_ZXcalculusWorkingQuantum} directly in \LaTeX{}. It comes with a default---but highly customizable---style:
\begin{codeexample}[]
  \begin{ZX}
    \zxZ{\alpha} \arrow[r] & \zxFracX-{\pi}{4}
  \end{ZX}
\end{codeexample}
Even if this has not yet been tested a lot, you can also use a ``phase in label'' style, without really changing the code:
\begin{codeexample}[]
  \begin{ZX}[phase in label right]
    \zxZ{\alpha} \arrow[d] \\
    \zxFracX-{\pi}{4}
  \end{ZX}
\end{codeexample}

Since 24/02/2023, we also provide ways to easily create new, highly customizable shapes, with text, anchors, sub-nodes, rotations, and more:
{\catcode`\|=12 % Ensures | is not anymore \verb|...|
\begin{codeexample}[width=0pt]
% Define a reusable node
\zxNewNodeFromPic{MyDivider}[][zx create anchors={\zxVirtualCenterWest, \zxVirtualCenterEast},
  every node/.append style={transform shape}
  ]{
  \node[regular polygon, regular polygon sides=3,shape border rotate=90,%shape border rotate=90,
        draw=black,fill=gray!50, inner sep=1.6pt, rounded corners=0.8mm,zx main node] {};
  \coordinate(\zxVirtualCenterEast) at (.2mm,0); % Used to start lines on the side of the shape
  \coordinate(\zxVirtualCenterWest) at (-1mm,0);
}
% Use the node
\begin{ZX}
                            & [2mm]                           & [3mm] \zxN{} \\[\zxZeroRow]
 \zxZ[B]{} \rar[Bn'=n+m, wc] & \zxMyDivider{}
                              \rar[<',ru,Bn'Args={n}{pos=.7}]
                              \rar[Bn.Args={m}{pos=.7},<.,rd] &\\[\zxZeroRow]
                            &                                 & \zxN{}
\end{ZX}
\end{codeexample}
}

Since 2023-09-27, you can also do advanced operations on multi-gate elements or use our default style:
\begin{codeexample}[]
\begin{ZX}[circuit, thick lines]
  \rar & \zxGate{H} \rar & \zxGateMulti{2}{3}{H} &  & \rar & \\
  \rar & \zxGate{H} \rar &                       &  & \rar & 
\end{ZX}
\end{codeexample}

and create more traditional circuits:

{\catcode`\|=12 % Ensures | is not anymore \verb|...|
\begin{codeexample}[width=0pt]
\begin{ZX}[circuit, thick lines]
  \zxInput{\ket{\psi}} \rar & \zxBox{H} \rar         & \zxCtrl{} \dar \rar & \zxCross{} \dar \rar
                            & \zxBox[add label={Measure}]{\zxMeter{}} \ar[dr,classical,--|] \\
  \ar[r]                    & \zxOCtrl{} \rar \ar[u] & \zxNot{} \rar       & \zxCross{} \ar[rr]
                            &                        & \zxBox{H} \rar      & \zxOutput{\ket{\phi}}
\end{ZX}
\end{codeexample}

\begin{codeexample}[width=0pt]
\begin{ZX}[circuit]
  \ar[rr]                           &  & [\zxZeroCol] \zxCtrl{} \dar \ar[rr]    & [\zxZeroCol] &                   \\
  \rar \zxInputMulti{2}{\ket{\psi}} & \zxGateMulti{3}{3}{U} \zxGateInputMulti{2}{x}
                                    &  & \rar \zxGateOutputMulti{2}{x \oplus y} & \zxOutputMulti{2}{\text{Output}} \\
  \rar                              & 
                                    &  & \rar                                   &                                  \\
  \rar \zxInput{\ket{0}}            & \zxGateInput{y}
                                    &  & \rar \zxGateOutput{y \oplus 1}         & \zxOutput{\ket{1}}
\end{ZX}
\end{codeexample}

\begin{codeexample}[width=0cm]
  \begin{ZX}[circuit]
    \ar[rr] && \zxCtrl{} \ar[dl, end subnode=wrapper] \ar[rr] && \\
    \rar    & \zxCtrl{} \dar \rar \zxGroupGates{2}{3}{below:\textsc{swap}} & \zxNot{} \dar \rar                             & \zxCtrl{} \dar \rar & \\
    \rar    & \zxNot{} \rar                                                & \zxCtrl{} \rar                                 & \zxNot{} \rar       & 
  \end{ZX}
\end{codeexample}
}

The goal is to provide an alternative to the great |tikzit| package: we wanted a solution that does not require the creation of an additional file, the use of an external software, and which automatically adapts the width of columns and rows depending on the content of the nodes (in |tikzit| one needs to manually tune the position of each node, especially when dealing with large nodes). Our library also provides a default style and tries to separate the content from the style: that way it should be easy to globally change the styling of a given project without redesigning all diagrams. However, it should be fairly easy to combine tikzit and this library: when some diagrams are easier to design in tikzit, then it should be possible to directly load the style of this library inside tikzit.

This library is quite young, so feel free to propose improvements or report issues on \href{https://github.com/leo-colisson/zx-calculus/issues}{\texttt{github.com/leo-colisson/zx-calculus/issues}}. We will of course try to maintain backward compatibility as much as possible, but we can't guarantee at 100\% that small changes (spacing, wire looks\dots{}) won't be made later. In case you want a completely unalterable style, just copy the two files of this library in your project forever (see installation)!

\section{Installation}

If your CTAN distribution is recent enough, you can directly insert in your file:
% verse indents stuff, index adds to the index of command at the end of the file, || is a shortcut of \verb||
\begin{verse}
  \index{zx@\protect\texttt{zx-calculus} package}%
  \index{Packages and files!zx-calculus@\protect\texttt{zx-calculus}}%
  |\usepackage{zx-calculus}|%
\end{verse}
or load \tikzname{} and then use:
\begin{verse}%
   \index{cd@\protect\texttt{zx-calculus} library}%
   \index{Libraries!cd@\protect\texttt{zx-calculus}}%
   |\usetikzlibrary{zx-calculus}|%
\end{verse}
If this library is not yet packaged into CTAN (which is very likely in 2021), you must first download \mylink{https://github.com/leo-colisson/zx-calculus/blob/main/tikzlibraryzx-calculus.code.tex}{\texttt{tikzlibraryzx-calculus.code.tex}} and \mylink{https://github.com/leo-colisson/zx-calculus/blob/main/zx-calculus.sty}{\texttt{zx-calculus.sty}} (right-click on ``Raw'' and ``Save link as'') and save them at the root of your project.

\section{Quickstart}

You can create a diagram either with |\zx[options]{matrix}|, |\zxAmp[options]{matrix}| or with:
\begin{verse}
  |\begin{ZX}[options]|\\
    |  matrix|\\
  |\end{ZX}|
\end{verse}
The matrix is composed of rows separated by |\\| and columns separated by |&| (except in |\zxAmp| where columns are separated with |\&|).

% \alertwarning{ % Can't use |...| or \verb|...| in this environment :'(
%   Due to \LaTeX{} restrictions, \texttt{\&} can sometimes cause some troubles. \texttt{\textbackslash{}zxAmp} is always guaranteed to work (just make sure to use \texttt{\textbackslash{}\&} instead of \texttt{\&}). See \cref{subsec:addDiagram} for more details.
% }

This matrix is basically a \tikzname{} matrix of nodes (even better, a |tikz-cd| matrix, so you can use all the machinary of |tikz-cd|), so cells can be created using \verb#|[tikz style]| content#. However, the users does not usually need to use this syntax since many nodes like |\zxZ{spider phase}| have been created for them (including |\zxN{}| which is an empty node):

\begin{codeexample}[width=0pt]
\begin{ZX}
  \zxZ{} & \zxZ{\alpha} & \zxZ-{\alpha} & \zxZ{\alpha+\beta} & \zxFracZ{\pi}{2} & \zxFracZ-{\pi}{2}\\
  \zxX{} & \zxX{\alpha} & \zxX-{\alpha} & \zxX{\alpha+\beta} & \zxFracX{\pi}{2} & \zxFracX-{\pi}{2}\\
  \zxN{} & \zxH{}
\end{ZX}
\end{codeexample}

Note that if a node has no argument like |\zxN|, you should still end it like |\zxN{}| to make sure you code will be backward compatible and will behave correctly.

To link the nodes, you should use |\arrow[options]| (|\ar[options]| for short) at the end of a cell (you can put many arrows). The options can contain a direction, made of a string of |r| (for ``right''), |l| (for ``left''), |d| (for `down''), |u| (for ``up'') letters. That way, |\ar[rrd]| would be an arrow going right, right, and down:
\begin{codeexample}[]
\begin{ZX}
  \zxZ{} \ar[rrd] & \zxX{}\\
                  &        & \zxX-{\alpha}
\end{ZX}
\end{codeexample}
See how the alignment of your matrix helps reading it: in emacs |M-x align| is your friend (or even better, if you are tired of selecting the lines to align, bind \mylink{https://tex.stackexchange.com/a/64566/116348}{this \texttt{align-environment} function} to some shortcuts, like |C-<tab>| and you will just have to do a single key-press to align your matrix).

You may also encounter some shortcuts, like |\rar| instead of |\ar[r]|. Since straight lines are boring, we created many styles that you can just add in the options. For instance, a measured Bell-pair can be created using the |C| style (note also how the |*| argument forces the node to be tighter), as the name of the style tries to mimic the shape of the wire:
\begin{codeexample}[]
\begin{ZX}
  \zxZ*{a \pi} \ar[d,C]\\
  \zxZ*{b \pi}
\end{ZX}
\end{codeexample}

\alertinfo{
  \textbf{Tips}: on small diagrams, describing the arrow position using relative position like \texttt{rrb} works really nicely, but on big diagrams that you need to rewrite, it can quickly be hard to manage, as moving a node will break all links to it. While it is possible to specify both |from| and |to| in an absolute way, the experience shows that it is easier to work with a ``semi-relative'' addressing, where only the |to| is specified in an absolute setting, while the |from| is automatically derived from the current position of the arrow. You can use \texttt{a=somename} to give a name for a node (\texttt{a} being the short name of alias).}

This way, on non-trivial diagrams, we recommend to format graphs like:
\begin{codeexample}[]
\begin{ZX}
  \zxN{}                                      & \zxZ[a=beta]{\beta} \\
  \zxZ{\alpha} \ar[to=beta,N] \ar[to=gamma,N] &                     \\
                                              & \zxZ[a=gamma]{\gamma}
\end{ZX}
\end{codeexample}
Note that you can also set |debug mode| to display the name of the nodes for an easier addressing:
\begin{codeexample}[]
\begin{ZX}[debug mode]
  % See how the code stayed unchanged despite changing the position of the nodes
  \zxN{}                                      & \zxZ[a=beta]{\beta} \\
  \zxZ{\alpha} \ar[to=beta,N] \ar[to=gamma,N] &                     \\
                                              &                     \\
                                              &  & \zxZ[a=gamma]{\gamma}
\end{ZX}
\end{codeexample}

We also introduce many other styles, like |N| for wires that arrive and leave at wide angle (yeah, the |N| is the best letter I could find to fit that shape):
\begin{codeexample}[]
\begin{ZX}
  \zxN{}                           & \zxZ{\beta}\\
  \zxZ{\alpha} \ar[ru,N] \ar[rd,N] &\\
                                   & \zxZ{\gamma}
\end{ZX}
\end{codeexample}
Or |s| for wires that arrive and leave at sharp angles\footnote{Note: on older versions, a |\textbackslash zxN\{\}| might be needed on the first cell as it seems that the first cell of a matrix can't be empty… this should be fixed in latest versions.}:
\begin{codeexample}[]
\begin{ZX}
                                   & \zxZ{\beta} \\
  \zxZ{\alpha} \ar[ru,s] \ar[rd,s] &             \\
                                   & \zxZ{\gamma}
\end{ZX}
\end{codeexample}
You have then different variations of a style depending on the shape and/or direction of it. For instance, if we want the arrival of the |N| wire to be flat, use |N-|:
\begin{codeexample}[]
\begin{ZX}
  \zxZ{\alpha} \ar[rd,N-] \\
                         & \zxZ{\beta}
\end{ZX}
\end{codeexample}
Similarly |o'| is a style for wires that have the shape of the top part of the circle, and comes with variations depending on the part of the circle that must be kept:
\begin{codeexample}[width=0pt]
\begin{ZX}
  \zxZ{\alpha} \ar[r,o',green] \ar[r,o.,red] \ar[d,o-,blue] \ar[d,-o,purple] & \zxZ{\beta}\\
  \zxZ{\beta}
\end{ZX}
\end{codeexample}
Note that the position of the embellishments (|'|, |-|, |.|\dots{}) tries to graphically represent the shape of the node. That way |-o| means ``take the left part (position of |-|) of the circle |o|''. Applied to |C|, this gives:
\begin{codeexample}[]
\begin{ZX}
  \zxX{} \ar[d,C] \ar[r,C']  & \zxZ{} \ar[d,C-]\\
  \zxZ{} \ar[r,C.]           & \zxX{}
\end{ZX}
\end{codeexample}

You also have styles which automatically add another node in between, for instance |H| adds a Hadamard node in the middle of the node:
\begin{codeexample}[]
\begin{ZX}
  \zxZ{\alpha} \ar[r,o',H] \ar[r,o.,H] &[\zxHCol] \zxZ{\beta}
\end{ZX}
\end{codeexample}
Note that we used also |&[\zxHCol]| instead of |&| (on the first line). This is useful to add an extra space between the columns to have a nicer look. The same applies for rows (see the |*Row| instead of |*Col|):
\begin{codeexample}[]
\begin{ZX}
  \zxZ{\alpha} \ar[d,-o,Z] \ar[d,o-,X] \\[\zxSRow]
  \zxX{\beta}
\end{ZX}
\end{codeexample}
The reason for this is that it is hard to always get exactly the good spacing by default (for instance here \tikzname{} has no idea that a |H| node will be inserted when it starts to build the diagram), and sometimes the spacing needs some adjustments. However, while you could manually tweak this space using something like |&[1mm]| (it adds |1mm| to the column space), it is better to use some pre-configured spaced that can be (re)-configured document-wise to keep a uniform spacing. You could define your own spacing, but we already provide a list for the most important spacings. They all start with |zx|, then you find the type of space: |H| for Hadamard, |S| for spiders, |W| when you connect only |\zxNone| nodes (otherwise the diagram will be too shrinked), |w| when one side of the row contains only |\zxNone|\dots{} and then you find |Col| (for columns spacing) or |Row| (for rows spacing). For instance we can use the |\zxNone| style (|\zxN| for short) style and the above spacing to obtain this:
\begin{codeexample}[]
\begin{ZX}
  \zxN{} \rar &[\zxwCol] \zxH{} \rar &[\zxwCol] \zxN{}
\end{ZX}
\end{codeexample}
\noindent or that:
\begin{codeexample}[]
\begin{ZX}
  \zxN{} \ar[d,C] \ar[dr,s] &[\zxWCol] \zxN{} \\[\zxWRow]
  \zxN{} \ar[ru,s]          &          \zxN{} \\
\end{ZX}
\end{codeexample}


When writing equations, you may also want to change the baseline to align properly your diagrams on a given line like that (since march 2023):
\begin{codeexample}[]
  $\zx[mbr=2]{ % mbr is a shortcut for "math baseline row"
    \zxX{}\\
    \zxZ[a=myZ]{}
  }
  = \zx{\zxX{} & \zxZ{}}$
\end{codeexample}
You can also specify (this works on older versions) a specific node like that (|a=blabla| gives the alias name |blabla| to the node, and configure tools useful for debugging):
\begin{codeexample}[]
  $\zx[math baseline=myZ]{
    \zxX{}\\
    \zxZ[a=myZ]{}
  }
  = \zx{\zxX{} & \zxZ{}}$
\end{codeexample}

We also provide easy methods like |phase in label right| to change the labelling of a note (per-node, per-picture or document wise) to move the phase in a label automatically:
\begin{codeexample}[]
  \begin{ZX}[phase in label right]
    \zxZ{\alpha} \arrow[d] \\
    \zxFracX-{\pi}{4}
  \end{ZX}
\end{codeexample}

Now you should know enough to start your first diagrams. The rest of the documentation will go through all the styles, customizations and features, including the one needed to obtain:
\begin{codeexample}[width=3cm]
\begin{ZX}
  \leftManyDots{n} \zxX{\alpha} \zxLoopAboveDots{} \middleManyDots{} \ar[r,o'={a=75}]
      & \zxX{\beta} \zxLoopAboveDots{} \rightManyDots{m}
\end{ZX}
\end{codeexample}
\noindent You will also see some tricks (notably based on alias) to create clear bigger diagrams, like this debug mode which turns
{
\begin{ZX}[zx row sep=1pt,
  execute at begin picture={%
    %%% Definition of long items (the goal is to have a small and readable matrix
    % (warning: macro can't have numbers in TeX. Also, make sure not to use existing names)
    \def\Zpifour{\zxFracZ[a=Zpi4]-{\pi}{4}}%
    \def\mypitwo{\zxFracX[a=mypi2]{\pi}{2}}%
  }
  ]
  %%% Matrix: in emacs "M-x align" is practical to automatically format it. a is for 'alias'
  & \zxN[a=n]{}  & \zxZ[a=xmiddle]{}       &            & \zxN[a=out1]{} \\
  \zxN[a=in1]{} & \Zpifour{}   & \zxX[a=Xdown]{}         & \mypitwo{} &                \\
  &              &                         &            & \zxN[a=out2]{} \\
  \zxN[a=in2]{} & \zxX[a=X1]{} & \zxZ[a=toprightpi]{\pi} &            & \zxN[a=out3]{}
  %%% Arrows
  % Column 1
  \ar[from=in1,to=X1,s]
  \ar[from=in2,to=Zpi4,.>]
  % Column 2
  \ar[from=X1,to=xmiddle,N']
  \ar[from=X1,to=toprightpi,H]
  \ar[from=Zpi4,to=n,C] \ar[from=n,to=xmiddle,wc]
  \ar[from=Zpi4,to=Xdown]
  % Column 3
  \ar[from=xmiddle,to=Xdown,C-]
  \ar[from=xmiddle,to=mypi2,)]
  % Column 4
  \ar[from=mypi2,to=toprightpi,(']
  \ar[from=mypi2,to=out1,<']
  \ar[from=mypi2,to=out2,<.]
  \ar[from=Xdown,to=out3,<.]
\end{ZX} into %
{%
  \def\zxDebugMode{}%%%%
  \begin{ZX}[zx row sep=1pt,
    execute at begin picture={%
      %%% Definition of long items (the goal is to have a small and readable matrix
      % (warning: macro can't have numbers in TeX. Also, make sure not to use existing names)
      \def\Zpifour{\zxFracZ[a=Zpi4]-{\pi}{4}}%
      \def\mypitwo{\zxFracX[a=mypi2]{\pi}{2}}%
    }
    ]
    %%% Matrix: in emacs "M-x align" is practical to automatically format it. a is for 'alias'
    & \zxN[a=n]{}  & \zxZ[a=xmiddle]{}       &            & \zxN[a=out1]{} \\
    \zxN[a=in1]{} & \Zpifour{}   & \zxX[a=Xdown]{}         & \mypitwo{} &                \\
    &              &                         &            & \zxN[a=out2]{} \\
    \zxN[a=in2]{} & \zxX[a=X1]{} & \zxZ[a=toprightpi]{\pi} &            & \zxN[a=out3]{}
    %%% Arrows
    % Column 1
    \ar[from=in1,to=X1,s]
    \ar[from=in2,to=Zpi4,.>]
    % Column 2
    \ar[from=X1,to=xmiddle,N']
    \ar[from=X1,to=toprightpi,H]
    \ar[from=Zpi4,to=n,C] \ar[from=n,to=xmiddle,wc]
    \ar[from=Zpi4,to=Xdown]
    % Column 3
    \ar[from=xmiddle,to=Xdown,C-]
    \ar[from=xmiddle,to=mypi2,)]
    % Column 4
    \ar[from=mypi2,to=toprightpi,(']
    \ar[from=mypi2,to=out1,<']
    \ar[from=mypi2,to=out2,<.]
    \ar[from=Xdown,to=out3,<.]
  \end{ZX}
} \ (of course it only helps during the construction).\\

You will also see how you can customize the styles, and how you can easily extend this library to get any custom diagram:
{\catcode`\|=12 % Ensures | is not anymore \verb|...|
\begin{codeexample}[width=0pt]
{ % \usetikzlibrary{shadows}
  \tikzset{
    my bloc/.style={
      anchor=center,
      inner sep=2pt,
      inner xsep=.7em,
      minimum height=3em,
      draw,
      thick,
      fill=blue!10!white,
      double copy shadow={opacity=.5},tape,
    }
  }
  \zx{|[my bloc]| f \rar &[1mm] |[my bloc]| g \rar &[1mm] \zxZ{\alpha} \rar & \zxNone{}}
}
\end{codeexample}
}

If you have some questions, suggestions, or bugs, please report them on \texttt{\url{https://github.com/leo-colisson/zx-calculus/issues}}.

\textbf{Tips}: if you are unsure of the definition of a style in an example, just click on it, a link will point to its definition. Also, if your pdf viewer does not copy/paste these examples correctly, you can copy them from the source code of this documentation available \mylink{https://github.com/leo-colisson/zx-calculus/blob/main/doc/zx-calculus.tex}{here} (to find the example, just use the ``search'' function of your web browser).

\section{Usage}

\subsection{Add a diagram}\label{subsec:addDiagram}
\begin{pgfmanualentry}
  \extractcommand\zx\opt{\oarg{options}}\marg{your diagram}\@@
  \extractenvironement{ZX}\opt{\oarg{options}}\@@
  \extractcommand\zxAmp\opt{\oarg{options}}\marg{your diagram}\@@
  \pgfmanualbody
  You can create a new ZX-diagram either with a macro (quicker for inline diagrams) or with an environment. All these commands are mostly equivalent, except that in |\zxAmp| columns are separated with |\&| instead of |&| (this was useful before as |&| was not usable in |align| or inside macros. Now it should be fixed.). The \meta{options} can be used to locally change the style of the diagram, using the same options as the |{tikz-cd}| environment (from the \mylink{https://www.ctan.org/pkg/tikz-cd}{\texttt{tikz-cd} package}). The \meta{your diagram} argument, or the content of |{ZX}| environment is a \tikzname{} matrix of nodes, exactly like in the |tikz-cd| package: rows are separated using |\\|, columns using |&| (except for |\zxAmp| where columns are separated using |\&|), and nodes are created using \verb#|[tikz style]| node content# or with shortcut commands presented later in this document (recommended). Wires can be added like in |tikz-cd| (see more below) using |\arrow| or |\ar|: we provide later recommended styles to quickly create different kinds of wires which can change with the configured style. Content is typeset in math mode by default, and diagrams can be included in any equation.
{\catcode`\|=12 % Ensures | is not anymore \verb|...|
% Do not indent not to put space in final code
\begin{codeexample}[]
Spider \zx{\zxZ{\alpha}}, equation $\zx{\zxZ{}} = \zx{\zxX{}}$ %
and custom diagram: %
\begin{ZX}[red]
  \zxZ{\beta} \arrow[r]                           & \zxZ{\alpha} \\
  |[fill=pink,draw]| \gamma \arrow[ru,bend right]
\end{ZX}
\end{codeexample}
}
\end{pgfmanualentry}

\begin{stylekey}{/zx/defaultEnv/amp}
  In a previous version (before 2022/02/09), it was not possible to use |&| inside macros and |align| due to \LaTeX{} limitations. However, we found a solution by re-scanning the tokens, so now no special care should be taken in align or macros. But in case you need to deal with an environment having troubles with |&|, either use the |ampersand replacement=\&| option (whose shortcut is |amp|) or |\zxAmp| (in any case, replace |&| with |\&|).
\begin{codeexample}[vbox]
An aligned equation:
\begin{align}
  \zxAmp{\zxZ{} \arrow[r] \& \zxX{}} &= \begin{ZX}[amp] \zxX{} \arrow[r] \& \zxZ{} \end{ZX}
\end{align}
This limitation does not apply anymore:
\begin{align}
  \zx{\zxZ{} \arrow[r] & \zxX{}} &= \begin{ZX} \zxX{} \arrow[r] & \zxZ{} \end{ZX}
\end{align}
even in macros: {\setlength{\fboxsep}{0pt} \fbox{\zx{\zxZ{} \rar & \zxX{}}}}
\end{codeexample}
\end{stylekey}

\subsection{Nodes}
\subsubsection{Spiders}
The following commands are useful to create different kinds of nodes. Always add empty arguments like |\example{}| if none are already present, otherwise if you type |\example| we don't guarantee backward compatibility.

\begin{command}{\zxEmptyDiagram{}}
  Create an empty diagram.
\begin{codeexample}[width=3cm]
\begin{ZX}
  \zxEmptyDiagram{}
\end{ZX}
\end{codeexample}
\end{command}


\begin{pgfmanualentry}
  \extractcommand\zxNone\opt{-\textbar+}\marg{text}\@@
  \extractcommand\zxN\opt{-\textbar+}\marg{text}\@@
  \extractcommand\zxNL\@@
  \extractcommand\zxNR\@@
  \pgfmanualbody
  Adds an empty node with |\zxNone{}| (alias |\zxN{}|). The \verb#-|+# decorations are used to add a bit of horizontal (\verb#\zxNone-{}#), vertical (\verb#\zxNone|{}#) and both (\verb#\zxNone+{}#) spacing.

  |\zxNone| is just a coordinate (and therefore can't have any text inside, but when possible this node should be preferred over the other versions since it has really zero width), but |\zxNone-{}| and \verb#\zxNone|{}# are actually nodes with |inner sep=0| along one direction. For that reason, they still have a tiny height or width (impossible to remove as far as I know). If you don't want to get holes when connecting multiple wires to them, it is therefore necessary to use |\zxNone{}| or the |wire centered| style (alias |wc|) (if you are using the |IO| mode, see also the |between none| style). But anyway you should mostly use |\zxNone|.

  Moreover, you should also add column and row spacing |&[\zxWCol]| and |\\[\zxWRow]| to avoid too shrinked diagrams when only wires are involved.
\begin{codeexample}[width=3cm]
\begin{ZX}
  \zxNone{} \ar[C,d] \ar[rd,s] &[\zxWCol] \zxNone{}\\[\zxWRow]
  \zxNone{}          \ar[ru,s] &          \zxNone{}
\end{ZX}
\end{codeexample}
Use |&[\zxwCol]| (on the first line) and/or |\\[\zxwRow]| when a single None node is connected to the wire to add appropriate spacing (this spacing can of course be redefined to your preferences):
\begin{codeexample}[]
Compare \begin{ZX}
  \zxN{} \rar & \zxZ{} \rar & \zxN{}
\end{ZX} with \begin{ZX}
  \zxN{} \rar &[\zxwCol] \zxZ{} \rar &[\zxwCol] \zxN{}
\end{ZX}
\end{codeexample}
This kind of code is so common that there is an alias for it: |\zxNL| and |\zxNR| automatically add a |\zxN{}| node, configure the column space (for this reason don't add an additional |&|, and be aware that emacs won't align them properly. Note also that the space will only be taken into account if it is on the first line) and add a straight arrow. The |L/R| part of the name is just to specify if the node is on the right or left of the diagram to put the column and arrow on the right side:
\begin{codeexample}[]
\zx{\zxNL \zxX{} \zxNR}
\end{codeexample}
Note that these two alias can be used without |{}|. But they are the only ones.

The \verb!\zxN|{text}! and \verb!\zxN-{text}! may be useful to display some texts:
{\catcode`\|=12 % Ensures | is not anymore \verb|...|
\begin{codeexample}[]
  \begin{ZX}[content fixed baseline]
    & \zxN|{\dots} \dar                                                                 \\
    \zxZ{\theta_i} \rar & \zxZ{} \dar \rar & \zxZ{-(\delta_i+\theta_i+r\pi)}\rar & \zxH{} \rar & \zxX{a\pi} \\
    & \zxN|{\dots}                                                                      \\
  \end{ZX}
\end{codeexample}
}

When the top left cell is empty, you may get an error at the compilation |Single ampersand used with wrong catcode| (this error should be fixed in latest releases) or |<symbol> allowed only in math mode| (not sure why). To solve this issue, you can add an empty node on the very first cell:
\begin{codeexample}[]
\begin{ZX}
  \zxN{}         &[\zxwCol] \zxN{} \ar[d]\\[\zxwRow]
  \zxNone{} \rar & \zxZ{}
\end{ZX}
\end{codeexample}
\end{pgfmanualentry}

You may also get the error |Single ampersand used with wrong catcode| when |&| has already a different meaning, for instance in |align|, in that case you may change the |&| character into |\&| using |[ampersand replacement=\&]|. Note however that in recent versions ($\geq$ 2022/02/09) this should not happen anymore.
\begin{codeexample}[vbox]
\begin{align}
  \begin{ZX}[ampersand replacement=\&]
    \zxN{} \rar \&[\zxWCol] \zxN{}
  \end{ZX}
  &= \begin{ZX}[ampersand replacement=\&]
    \zxN{} \rar \&[\zxwCol] \zxZ{} \rar \&[\zxwCol] \zxN{}
  \end{ZX}\\
  &= \begin{ZX}[ampersand replacement=\&]
    \zxN{} \rar \&[\zxwCol] \zxX{} \rar \&[\zxwCol] \zxN{}
  \end{ZX}
\end{align}
\end{codeexample}

\begin{command}{\zxNoneDouble\opt{-\textbar+}\marg{text}}
  Like |\zxNone|, but the spacing for \verb#-|+# is large enough to fake two lines in only one. Not extremely useful (or one needs to play with |start anchor=south,end anchor=north|).
{\catcode`\|=12 % Ensures | is not anymore \verb|...|
\begin{codeexample}[width=3cm]
\begin{ZX}
  \zxNoneDouble|{} \ar[r,s,start anchor=north,end anchor=south] \ar[r,s,start anchor=south,end anchor=north] &[\zxWCol] \zxNoneDouble|{}
\end{ZX}
\end{codeexample}
}
\end{command}

\begin{command}{\zxFracZ\opt{-}\marg{numerator}\opt{\oarg{numerator with parens}\oarg{denominator with parens}}\marg{denominator}}
  Adds a Z node with a fraction, use the minus decorator to add a small minus in front (a normal minus would be too big, but you can configure the symbol).
\begin{codeexample}[width=3cm]
\begin{ZX}
  \zxFracZ{\pi}{2} & \zxFracZ-{\pi}{2}
\end{ZX}
\end{codeexample}
The optional arguments are useful when the numerator or the denominator need parens when they are written inline (in that case optional arguments must be specified): it will prove useful when using a style that writes the fraction inline, for instance the default style for labels:
\begin{codeexample}[]
Compare %
\begin{ZX}
  \zxFracZ{a+b}[(a+b)][(c+d)]{c+d}
\end{ZX} with %
\begin{ZX}[phase in label right]
  \zxFracZ{a+b}[(a+b)][(c+d)]{c+d}
\end{ZX}
\end{codeexample}
\end{command}

\begin{command}{\zxFracX\opt{-}\marg{numerator}\marg{denominator}}
  Adds an X node with a fraction.
\begin{codeexample}[width=3cm]
\begin{ZX}
  \zxFracX{\pi}{2} & \zxFracX-{\pi}{2}
\end{ZX}
\end{codeexample}
\end{command}

\begin{command}{\zxZ\opt{\oarg{other styles}*-}\marg{text}}
  Adds a Z node. \meta{other styles} are optional \tikzname{} arguments (the same as the one provided to |tikz-cd|) They should be use with care, and if possible moved to the style directly to keep a consistent look across the paper.
\begin{codeexample}[width=3cm]
\begin{ZX}
  \zxZ{} & \zxZ{\alpha} & \zxZ{\alpha + \beta} & \zxZ[fill=blue!50!white,text=red]{(a \oplus b)\pi}
\end{ZX}
\end{codeexample}
The optional |-| optional argument is to add a minus sign (customizable, see |\zxMinusInShort|) in front of a very short expression and try to keep a circular shape. This is recommended notably for single letter expressions.
\begin{codeexample}[width=3cm]
  Compare \zx{\zxZ{-\alpha}} with \zx{\zxZ-{\alpha}}. Labels:
  \zx[pila]{\zxZ{-\alpha}} vs \zx[pila]{\zxZ-{\alpha}}.
\end{codeexample}
The |*| optional argument is to force a condensed style, no matter what is the text inside. This can be practical \emph{sometimes}:
\begin{codeexample}[width=3cm]
  Compare \zx{\zxN{} \rar &[\zxwCol] \zxZ{a\pi}} with \zx{\zxN{} \rar &[\zxwCol] \zxZ*{a\pi}}.
\end{codeexample}
\noindent but you should use it as rarely as possible (otherwise, change the style directly). See that it does not always give nice results:
\begin{codeexample}[width=3cm]
  Compare \zx{\zxZ{-\alpha} \rar & \zxZ{\alpha+\beta}}
  with \zx{\zxZ*{-\alpha} \rar & \zxZ*{\alpha+\beta}}.
  Labels:
  \zx[pila]{\zxZ{-\alpha} \rar & \zxZ{\alpha+\beta}}
  vs \zx[pila]{\zxZ*{-\alpha} \rar & \zxZ*{\alpha+\beta}}.
\end{codeexample}
\end{command}


\begin{command}{\zxX\opt{\oarg{other styles}*-}\marg{text}}
  Adds an X node, like for the Z node.
\begin{codeexample}[width=3cm]
\begin{ZX}
  \zxX{} & \zxX{\alpha} & \zxX-{\alpha} & \zxX{\alpha + \beta}
  & \zxX[text=green]{(a \oplus b)\pi}
\end{ZX}
\end{codeexample}
\end{command}

\begin{command}{\zxH\opt{\oarg{other styles}}}
  Adds an Hadamard node. See also |H| wire style.
\begin{codeexample}[width=3cm]
\begin{ZX}
  \zxNone{} \rar & \zxH{} \rar & \zxNone{}
\end{ZX}
\end{codeexample}
\end{command}



\begin{command}{\leftManyDots\opt{\oarg{text scale}\oarg{dots scale}}\marg{text}}
  Shortcut to add a dots and a text next to it. It automatically adds the new column, see more examples below. Internally, it uses |3 dots| to place the dots, and can be reproduced using the other nodes around. Note that this node automatically adds a new cell, so you should \emph{not} use |&|.
\begin{codeexample}[]
\begin{ZX}
  \leftManyDots{n} \zxX{\alpha}
\end{ZX}
\end{codeexample}
\end{command}

\begin{command}{\leftManyDots\opt{\oarg{text scale}\oarg{dots scale}}\marg{text}}
  Shortcut to add a dots and a text next to it. It automatically adds the new column, see more examples below.
\begin{codeexample}[width=3cm]
\begin{ZX}
  \zxX{\alpha} \rightManyDots{m}
\end{ZX}
\end{codeexample}
\end{command}

\begin{command}{\middleManyDots{}}
  Shortcut to add a dots and a text next to it, see more examples below.
\begin{codeexample}[width=3cm]
\begin{ZX}
  \zxX{\alpha} \middleManyDots{} & \zxX{\beta}
\end{ZX}
\end{codeexample}
\end{command}

\begin{command}{\zxLoop\opt{\oarg{direction angle}\oarg{opening angle}\oarg{other styles}}}
  Adds a loop in \meta{direction angle} (defaults to $90$), with opening angle \meta{opening angle} (defaults to $20$).
\begin{codeexample}[width=3cm]
\begin{ZX}
  \zxX{\alpha} \zxLoop{} & \zxX{} \zxLoop[45]{} & \zxX{} \zxLoop[0][30][red]{}
\end{ZX}
\end{codeexample}
\end{command}

\begin{command}{\zxLoopAboveDots\opt{\oarg{opening angle}\oarg{other styles}}}
  Adds a loop above the node with some dots.
\begin{codeexample}[width=3cm]
\begin{ZX}
  \zxX{\alpha} \zxLoopAboveDots{}
\end{ZX}
\end{codeexample}
\end{command}

\noindent The previous commands can be useful to create this figure:
\begin{codeexample}[width=0pt]% Forces code/example on two lines.
\begin{ZX}
  \leftManyDots{n} \zxX{\alpha} \zxLoopAboveDots{} \middleManyDots{} \ar[r,o'={a=75}]
      & \zxX{\beta} \zxLoopAboveDots{} \rightManyDots{m}
\end{ZX}
\end{codeexample}


\begin{pgfmanualentry}
  \makeatletter
  \def\extrakeytext{style, }
  \extractkey/zx/styles/rounded style/content vertically centered\@nil%
  \extractkey/zx/styles/rounded style/content fixed baseline\@nil%
  \extractkey/zx/styles/rounded style preload/content vertically centered\@nil%
  \extractkey/zx/styles/rounded style preload/content fixed baseline\@nil%
  \extractkey/zx/styles/rounded style preload/content fixed also frac\@nil%
  \makeatother
  \pgfmanualbody
  By default the content of the nodes are vertically centered. This can be nice to have as much space as possible around the text, but when using several nodes with letters having different height or depth, the baseline of each node won't be aligned (this is particularly visible on nodes with very high text, like |b'|):
\begin{codeexample}[width=0pt]
\begin{ZX}
  \zxX[a=start]{\alpha} & \zxX{\beta} & \zxX{a} & \zxX{b} & \zxX*{a\pi} & \zxX*{b\pi}
  & \zxX*{b'\pi} & \zxZ*{'b\pi} & \zxZ{(a \oplus b )\pi} & \zxFracX-{\pi}{4}
  & \zxFracZ{\pi}{4} & \zxZ-{\delta} & \zxZ[a=end]-{\gamma}
   \ar[from=start,to=end,on layer=background]
\end{ZX}
\end{codeexample}
Using |content fixed baseline|, it is however possible to fix the height and depth of the text to make sure the baselines are aligned (|content vertically centered| is use to come back to the default behavior). When used as a ZX option, it avoids setting this on fractions since it renders poorly. Use |content fixed baseline also frac| if you also want to fix the baseline of all fractions as well (this last style is useful only as a ZX option, since |content fixed baseline| works on all nodes).
\begin{codeexample}[width=0pt]
\begin{ZX}[content fixed baseline]
  \zxX[a=start]{\alpha} & \zxX{\beta} & \zxX{a} & \zxX{b} & \zxX*{a\pi} & \zxX*{b\pi}
  & \zxX*{b'\pi} & \zxZ*{'b\pi} & \zxZ{(a \oplus b )\pi} & \zxFracX-{\pi}{4}
  & \zxFracZ{\pi}{4} & \zxZ-{\delta} & \zxZ[a=end]-{\gamma}
   \ar[from=start,to=end,on layer=background]
\end{ZX}
\end{codeexample}
Note however that the height is really hardcoded (not sure how to avoid that) and is quite small (otherwise nodes quickly become too large), so too large content may overlay on top of the node (this is visible on the |'b\pi| node). You can use this style either on a per-picture basis (it's what we just did), on a per-node basis (just use it in the options of the node), or globally:
\begin{codeexample}[width=0pt]
\tikzset{
  /zx/user overlay/.style={
    content fixed baseline,
  },
}
\begin{ZX}
  \zxX[a=start]{\alpha} & \zxX{\beta} & \zxX{a} & \zxX{b} & \zxX*{a\pi} & \zxX*{b\pi}
  & \zxX*{b'\pi} & \zxZ*{'b\pi} & \zxZ{(a \oplus b )\pi} & \zxFracX-{\pi}{4}
  & \zxFracZ{\pi}{4} & \zxZ-{\delta} & \zxZ[a=end]-{\gamma}
   \ar[from=start,to=end,on layer=background]
\end{ZX}
\end{codeexample}
It can also be practical to combine it with |small minus|:
\begin{codeexample}[]
\begin{ZX}
  \zxZ-{\delta_j} & \zxZ[content fixed baseline]-{\delta_j} &
  \zxZ[small minus]-{\delta_j} & \zxZ[content fixed baseline,small minus]-{\delta_j}
\end{ZX}
\end{codeexample}
\end{pgfmanualentry}

\subsubsection{Phase in label style}

We also provide styles to place the phase on a label next to an empty node (not yet very well tested):

\begin{pgfmanualentry}
  \makeatletter
  \def\extrakeytext{style, }
  \extractkey/zx/styles/rounded style/phase in content\@nil%
  \extractkey/zx/styles/rounded style/phase in label=style (default {})\@nil%
  \extractkey/zx/styles/rounded style/pil=style (default {})\@nil%
  \extractkey/zx/styles/rounded style/phase in label above=style (default {})\@nil%
  \extractkey/zx/styles/rounded style/pila=style (default {})\@nil%
  \extractkey/zx/styles/rounded style/phase in label below=style (default {})\@nil%
  \extractkey/zx/styles/rounded style/pilb=style (default {})\@nil%
  \extractkey/zx/styles/rounded style/phase in label right=style (default {})\@nil%
  \extractkey/zx/styles/rounded style/pilr=style (default {})\@nil%
  \extractkey/zx/styles/rounded style/phase in label left=style (default {})\@nil%
  \extractkey/zx/styles/rounded style/pill=style (default {})\@nil%
  \makeatother
  \pgfmanualbody
  The above styles are useful to place a spider phase in a label outside the node. They can either be put on the style of a node to modify a single node at a time:
\begin{codeexample}[]
  \zx{\zxX[phase in label]{\alpha} \rar & \zxX{\alpha}}
\end{codeexample}
\noindent It can also be configured on a per-figure basis:
\begin{codeexample}[]
\zx[phase in label right]{
  \zxZ{\alpha} \dar \\
  \zxX{\alpha} \dar \\
  \zxZ{}}
\end{codeexample}
\noindent or globally:
\begin{codeexample}[]
\tikzset{
  /zx/user overlay/.style={
    phase in label={label position=-45, text=purple,fill=none}
  }
}
\zx{
  \zxFracX-{\pi}{2}
}
\end{codeexample}
Note that we must use |user post preparation labels| and not |/zx/user overlay nodes| because this will be run after all the machinery for labels has been setup.

  While |phase in content| forces the content of the node to be inside the node instead of inside a label (which is the default behavior), all other styles are special cases of |phase in label|. The \meta{style} parameter can be any style made for a tikz label:
\begin{codeexample}[width=3cm]
  \zx{
    \zxX[phase in label={label position=45, text=purple}]{\alpha}
  }
\end{codeexample}

For ease of use, the special cases of label position |above|, |below|, |right| and |left| have their respective shortcut style. The |pil*| versions are shortcuts of the longer style written above. For instance, |pilb| stands for |phase in label below|. Note also that by default labels will take some space, but it's possible to make them overlay without taking space using the |overlay| label style\dots{} however do it at your own risks as it can overlay the content around (also the text before and after):
\begin{codeexample}[width=0pt]
  \zx{
    \zxZ[pilb]{\alpha+\beta} \rar & \zxX[pilb]{\gamma} \rar & \zxZ[pilb=overlay]{\gamma+\eta}
  }
\end{codeexample}
The above also works for fractions:
\begin{codeexample}[]
\zx{\zxFracX[pilr]-{\pi}{2}}
\end{codeexample}
For fractions, you can configure how you want the label text to be displayed, either in a single line (default) or on two lines, like in nodes. The function |\zxConvertToFracInLabel| is in charge of that conversion, and can be changed to your needs to change this option document-wise. To use the same notation in both content and labels, you can do:
\begin{codeexample}[width=0pt]
  Compare
  \begin{ZX}[phase in label right]
    \zxFracZ{\pi}{2} \dar \\
    \zxFracZ{a+b}[(a+b)][(c+d)]{c+d}
  \end{ZX} with
{\RenewExpandableDocumentCommand{\zxConvertToFracInLabel}{mmmmm}{
    \zxConvertToFracInContent{#1}{#2}{#3}{#4}{#5}%
  }
  \begin{ZX}[phase in label right]
    \zxFracZ{\pi}{2} \dar \\
    \zxFracZ{a+b}[(a+b)][(c+d)]{c+d}
  \end{ZX} (exact same code!)
}
\end{codeexample}
Note that in |\zxFracZ{a+b}[(a+b)][(c+d)]{c+d}| the optional arguments are useful to put parens appropriately when the fraction is written inline.
\end{pgfmanualentry}

\begin{stylekey}{/zx/defaultEnvdebug mode}
  If this macro is defined, debug mode is active. See below how it can be useful (here is a quick example).
\begin{codeexample}[width=3cm]
\begin{ZX}[debug mode]
  \rar[B] & [\zxwCol] \zxDivider[a=divTop]{} & \\
  &                                  & \zxZ[a=Ztopleft]{}
  \ar[from=divTop, to=Ztopleft]
\end{ZX}
\end{codeexample}
\end{stylekey}

\begin{command}{\zxDebugMode{}}
  If this macro is defined, debug mode is active. See below how it can be useful.
\end{command}
\begin{stylekey}{/tikz/every node/a=alias}
  Shortcut to add an |alias| to a wire, and in debug mode it also displays the alias of the nodes next to it (very practical to quickly add wires as we will see later). To enable debug mode, just type |\def\zxDebugMode{}| before your drawing, potentially in a group like |{\def\zxDebugMode{} your diagram...}| if you want to apply it to a single diagram.

  This will be very practical later when using names instead of directions to connect wires (this can improve readability and maintainability). This is added automatically in |/tikz/every node| style. Note that debug mode is effective only for |a| and not |alias|.
\begin{codeexample}[width=3cm]
  \begin{ZX}
    \zxX[a=A]{} & \zxZ[a=B]{\beta}
    \ar[from=A,to=B]
  \end{ZX}
  {\def\zxDebugMode{} %% Enable debug mode for next diagram%
    \begin{ZX}
      \zxX[a=A]{} & \zxZ[a=B]{\beta}
      \ar[from=A,to=B]
    \end{ZX}
  }
\end{codeexample}
\end{stylekey}

\begin{stylekey}{/zx/defaultEnv/math baseline=node alias}
  You can easily change the default baseline which defaults to:
  \begin{verse}
    |baseline={([yshift=-axis_height]current bounding box.center)}|
  \end{verse}
  (|axis_height| is the distance to use to center equations on the ``mathematical axis'') by using this in the \meta{options} field of |\zx[options]{...}|. However, this can be a bit long to write, so |math baseline=yourAlias| is a shorcut to |baseline={([yshift=-axis_height]yourAlias)}|:
\begin{codeexample}[width=0pt]
  Compare $\begin{ZX}
    \leftManyDots{n} \zxX{\alpha} \zxLoopAboveDots{} \middleManyDots{} \ar[r,o'={a=75}]
    & \zxX{\beta} \zxLoopAboveDots{} \rightManyDots{m}
  \end{ZX}
  = {\def\zxDefaultSoftAngleS{20} % useful to make the angle in \leftManyDots{} nicer.
    \begin{ZX}
      \leftManyDots{n} \zxX{\alpha+\beta} \rightManyDots{m}
    \end{ZX}}$ with $\begin{ZX}[math baseline=wantedBaseline]
    \leftManyDots{n} \zxX{\alpha} \zxLoopAboveDots{} \middleManyDots{} \ar[r,o'={a=75}]
    %% See here --v the node chosen as the baseline
    & \zxX[a=wantedBaseline]{\beta} \zxLoopAboveDots{} \rightManyDots{m}
  \end{ZX}
  = {\def\zxDefaultSoftAngleS{20} % useful to make the angle in \leftManyDots{} nicer.
    \begin{ZX}
      \leftManyDots{n} \zxX{\alpha+\beta} \rightManyDots{m}
    \end{ZX}}$
\end{codeexample}
Also, if you find your diagram a bit ``too high'', check that you did not forget to remove a trailing |\\| at the end of the last line:
\begin{codeexample}[width=3cm]
  Compare $\begin{ZX}
    \zxZ{} \rar[o'] \rar[o.]      & \zxX{}\\
    \zxZ{} \rar[o'] \rar[o.] \rar & \zxX{}\\ %% <--- remove last \\
  \end{ZX} = \zx{\zxEmptyDiagram}$ with $\begin{ZX}
    \zxZ{} \rar[o'] \rar[o.]      & \zxX{}\\
    \zxZ{} \rar[o'] \rar[o.] \rar & \zxX{}
  \end{ZX}  = \zx{\zxEmptyDiagram}$
\end{codeexample}
\end{stylekey}

\begin{pgfmanualentry}
  \def\extrakeytext{style, }
  \makeatletter% should not be letter for \@@... strange
  \extractkey/zx/defaultEnv/math baseline row=row to center (default {1})\@nil%
  \extractkey/zx/defaultEnv/mbr=row to center (default {1})\@nil%
  \makeatother
  You can also choose directly a line to center on: for instance to center on the first line, use: |math baseline row=1|, or, equivalently |mbr=1| or directly |mbr|:
\begin{codeexample}[width=0pt]
  $\begin{ZX}[mbr]
    \zxN{} \rar[B] & [\zxwCol] \zxMatrix{A} \rar[B] &[\zxwCol] \zxN{}
  \end{ZX} = A$
\end{codeexample}
Since 2023/10/03 you can also use a float value to specify that you want to set the center between two lines:
\begin{codeexample}[width=0pt]
  Compare $G = \begin{ZX}[circuit]
    \rar     & \zxGate{G} \rar & \zxGate{H} \rar & \\
    \ar[rrr] &                 &                 & 
  \end{ZX}$ with $G = \begin{ZX}[circuit,mbr=1.5]
    \rar     & \zxGate{G} \rar & \zxGate{H} \rar & \\
    \ar[rrr] &                 &                 & 
  \end{ZX}$.
\end{codeexample}
\end{pgfmanualentry}

\subsubsection{Ground}

\textbf{NB}: this functionality, based on custom nodes (\cref{subsec:customNodes}) was added on 13/03/2023.

\begin{pgfmanualentry}
  \def\extrakeytext{style, }
  \extractcommand\zxGround\oarg{picture style}\opt{.}\opt{-}\opt{'}\marg{}\@@
  \extractcommand\zxGroundScale\@@
  \pgfmanualbody
The ground symbol can be used to denote a discarding operation… but is also useful to compute the norm of a state or denote a measurement by first copying the state and discarding one copy. This way, a measurement in the computational basis can be represented as:
\begin{codeexample}[width=0pt]
  \begin{ZX}
              & [\zxwCol]                    & [\zxwCol] \zxN{} \rar & \zxN{} \\
    \zxN{} \rar & \zxZ{} \ar[ur,<'] \ar[dr,<'] &                            \\[\zxZeroRow]
              &                              & \zxGround{}              
  \end{ZX}
\end{codeexample}
You can also change the direction using the alternative names:
\begin{codeexample}[]
  \begin{ZX}
    \zxGround-{}\rar & \zxGround{} \\
    \zxGround'{}\dar\\
    \zxGround.{}
  \end{ZX}
\end{codeexample}
Internally, the ground symbol is drawn using a |pic|, so you can customize it as any other pic:
\begin{codeexample}[]
  \begin{ZX}
    \zxN{} \rar &[\zxwCol] \zxGround[scale=1.5,red,rotate=45]{}
  \end{ZX}
\end{codeexample}
Note that you can also redefine |\def\zxGroundScale{1.8}| to change the default scale on a whole document.
Moreover, by default the |pic| takes some space (this way it will not overlap with the next symbol, or the text below/after), but you want sometimes to make it |overlay|, for instance to preserve the symmetry with an empty wire (then, you might need to add some column space |&[yourspace]| or row space |\\[yourspace]| to avoid overlap with text around it):
\begin{codeexample}[width=0pt]
  Compare
  \begin{ZX}
                & [\zxwCol]                    & [\zxwCol] \zxN{} \rar & \zxN{} \\
    \zxN{} \rar & \zxZ{} \ar[ur,<'] \ar[dr,<'] &                            \\
                &                              & \zxGround[overlay]{}           
  \end{ZX}
  with
  \begin{ZX}
                & [\zxwCol]                    & [\zxwCol] \zxN{} \rar & \zxN{} \\
    \zxN{} \rar & \zxZ{} \ar[ur,<'] \ar[dr,<'] &                            \\
                &                              & \zxGround{}              
  \end{ZX}
\end{codeexample}
\end{pgfmanualentry}

\subsubsection{Scalable ZX}

We provide some notations coming from the scalable ZX calculus~\cite{CHP19_SZXcalculusScalableGraphical}. 

\begin{pgfmanualentry}
  \def\extrakeytext{style, }
  \extractcommand\zxDivider\oarg{picture style}\oarg{picture style}\opt{.}\opt{-}\opt{'}\marg{}\@@
  \pgfmanualbody
  Dividers can be used to split (or gather) groups of wires. The |.|,|-|,|'| modifiers are used, respectively, to denote the bottom/right/top versions:
{\catcode`\|=12 % Ensures | is not anymore \verb|...|
\begin{codeexample}[width=0pt]
We provide some pre-defined symbols in both horizontal: %
\begin{ZX}
  \zxZ[B]{} \rar[Bn'=n+m, wc] &[\zxwCol] \zxDivider{} 
                                  \rar[o',Bn'Args={n}{}]
                                  \rar[o.,Bn.Args={m}{}] &[\zxWCol] \zxDivider-{} \rar[B,wc] & \zxZ[B]{}
\end{ZX}
 and vertical mode:
\begin{ZX}
  \zxZ[B]{} \dar[Bn=n+m, wc] \\[\zxwRow]
  \zxDivider'{} \dar[-o,BnArgs={n}{}] \dar[o-,Bn-Args={m}{}] \\[\zxWRow]
  \zxDivider.{} \dar[B,wc]\\
  \zxZ[B]{}
\end{ZX}
\end{codeexample}
}
\end{pgfmanualentry}


\begin{pgfmanualentry}
  \def\extrakeytext{style, }
  \extractcommand\zxMatrix\oarg{pic style}\oarg{node style}\opt{.}\opt{-}\opt{'}\opt{/}\opt{*}\opt{\_\{text in pmatrix\}}\marg{matrix name}\@@
  \pgfmanualbody
  Matrices are represented using arrows: |matrix name| is the content of the label of the node:
{\catcode`\|=12 % Ensures | is not anymore \verb|...|
\begin{codeexample}[]
\begin{ZX}
  \zxN{} \rar & \zxMatrix{A} \rar & \zxN{}
\end{ZX}
\end{codeexample}
}
The |*| option is used to reverse the direction of the arrow, typically for the transpose (note how we can give an alias (with |a| in |node style|) to combine with |math baseline|, or its quicker variants |mbr=nb line to center on| to properly vertically align the node):
{\catcode`\|=12 % Ensures | is not anymore \verb|...|
\begin{codeexample}[width=0pt]
We define %
$\begin{ZX}[mbr]
  \zxN{} \rar[B] & \zxMatrix*{A} \rar[B] & \zxN{}
\end{ZX} \coloneqq
\begin{ZX}[mbr=2]
            & [\zxWCol] \zxN{} \ar[B,dr,s]        & [\zxWCol] \zxN{} \\[\zxZeroCol+.3mm]
\ar[B,dr,s] & \zxMatrix{A} \ar[B,u,C] \ar[B,d,C-] &                  \\
            &                                     & \zxN{}           \\
\end{ZX}$.
\end{codeexample}
}
The position of the label can be changed with |-| is in horizontal wires, and in vertical wires we use |'| and |.| (putting the label respectively on right and left).
{\catcode`\|=12 % Ensures | is not anymore \verb|...|
\begin{codeexample}[width=0pt]
\begin{ZX}
  \zxN{} \rar & \zxMatrix{} \rar & \zxMatrix{A} \rar & \zxMatrix*{A} \rar
  & \zxMatrix-{A} \rar & \zxMatrix-*{A} \rar & \zxN{}
\end{ZX}
\end{codeexample}
}
Similarly in horizontal wires:
{\catcode`\|=12 % Ensures | is not anymore \verb|...|
\begin{codeexample}[]
\begin{ZX}
  \zxN{} \dar \\
  \zxMatrix'{} \dar \\
  \zxMatrix.{A} \dar \\
  \zxMatrix'*{A} \dar \\
  \zxMatrix'{A} \dar \\
  \zxMatrix.*{A} \dar \\
  \zxN{}
\end{ZX}
\end{codeexample}
}
If you want to change the position of the label to a more advanced position (e.g.\ with an angle), the simpler solution is to add |yourAngle:| in front of the label (see tikz labels for more details):
{\catcode`\|=12 % Ensures | is not anymore \verb|...|
\begin{codeexample}[]
\begin{ZX}
  \zxZ{} \rar & \zxMatrix{45:A} \rar & \zxN{}
\end{ZX}
\end{codeexample}
}
Note that it might be useful to put the label as an overlay using |/| (i.e. it is not counted in the bounding box of the cell, and might overlap with content around) in order to reduce space if we know there is nothing on the nearby cell: (we can also manually change the row/colum sep with negative values… but it might be better to avoid this kind of manual tweaks):
{\catcode`\|=12 % Ensures | is not anymore \verb|...|
\begin{codeexample}[]
Compare %
\begin{ZX}
  \zxZ{} \rar \dar & \zxMatrix-{A} \rar & \zxN{} \\
  \zxX{}
\end{ZX} with %
\begin{ZX}
  \zxZ{} \rar \dar & \zxMatrix-/{A} \rar & \zxN{} \\
  \zxX{}
\end{ZX}
\end{codeexample}
}
It is also useful to put a |pmatrix| inside. While it is possible to write the full |pmatrix|, we can use the |_{}| embelishment to automatically wrap the text with |\begin{bmatrix} \end{bmatrix}|:
{\catcode`\|=12 % Ensures | is not anymore \verb|...|
\begin{codeexample}[width=0pt]
This %
\begin{ZX}[mbr]
  \zxN{} \rar & \zxMatrix_{A & B \\ C & D}{} \rar & \zxN{}
\end{ZX} %
is a shortcut for %
\begin{ZX}[math baseline row=1]
  \zxN{} \rar & \zxMatrix{\begin{bmatrix} A & B \\ C & D \end{bmatrix}} \rar & \zxN{}
\end{ZX}
\end{codeexample}
}
Note that it seems that some environments do not play well with the way we handle |&| (our changes were needed to make them compatible with |align|, and to provide an easy interface with the |external| library… but it seems to not fit well with all environments, e.g.\ arrays). In that case you should use |\begin{ZXNoExt}| together with |[ampersand replacement=\&]| (of course, use |\&| instead of |&| in the rest of the matrix):
{\catcode`\|=12 % Ensures | is not anymore \verb|...|
\begin{codeexample}[width=0pt]
$\begin{ZXNoExt}[ampersand replacement=\&]
  \zxN{} \rar \& \zxMatrix{
    \begin{bmatrix}
      \begin{array}{c|c}
        A & B \\
        \hline
        C & D
      \end{array}
    \end{bmatrix}} \rar \& \zxN{}
\end{ZXNoExt}$
\end{codeexample}
}
Here is a demo to check if the true north etc anchors are placed correctly:
{\catcode`\|=12 % Ensures | is not anymore \verb|...|
\begin{codeexample}[width=0pt]
\begin{ZX}
  \zxH{} \ar[to=Gll,C'] \ar[to=Gll,C.] & \zxMatrix[a=Gll]'{G}
\end{ZX} %
\begin{ZX}
  \zxH{} \ar[to=Gll,C'] \ar[to=Gll,C.] & \zxMatrix[a=Gll]'*{G}
\end{ZX} %
\begin{ZX}
  \zxH{} \ar[to=Gll,C'] \ar[to=Gll,C.] & \zxMatrix[a=Gll].{G}
\end{ZX} %
\begin{ZX}
  \zxH{} \ar[to=Gll,C'] \ar[to=Gll,C.] & \zxMatrix[a=Gll].*{G}
\end{ZX} %
\begin{ZX}
  \zxH{} \ar[to=Gll,C] \ar[to=Gll,C-] \\
  \zxMatrix[a=Gll]{G}
\end{ZX} %
\begin{ZX} %
  \zxH{} \ar[to=Gll,C] \ar[to=Gll,C-] \\
  \zxMatrix[a=Gll]*{G}
\end{ZX} %
\begin{ZX}
  \zxH{} \ar[to=Gll,C-] \ar[to=Gll,C] \\
  \zxMatrix[a=Gll]-{G}
\end{ZX} %
\begin{ZX}
  \zxH{} \ar[to=Gll,C] \ar[to=Gll,C-] \\
  \zxMatrix[a=Gll]-*{G}
\end{ZX}
\end{codeexample}
}


\end{pgfmanualentry}

\begin{pgfmanualentry}
  \def\extrakeytext{style, }
  \makeatletter% should not be letter for \@@... strange
  \extractkey/zx/picCustomStyleMatrixMainNode\@nil%
  \extractkey/zx/picCustomStyleMatrixLabel\@nil%
  \extractkey/zx/picCustomStyleBeforeUserMatrix\@nil%
  \extractkey/zx/picCustomStyleAterUserMatrix\@nil%
  \extractkey/zx/picCustomStyleLastPicMatrix\@nil%
  \makeatother
  \pgfmanualbody
If you would like to override some settings, note that you can use all customization options provided by our custom node system (\cref{subsec:customNodes}). In particular, you can use |pic style| to change the options of the pic used to draw the node, including scale, rotation…, |node style| to style the parent node of the pic (less used, mostly to give alias names to the shape). We additionally provide special styles to configure the nodes more precisely: |/zx/picCustomStyleMatrixMainNode| and |/zx/picCustomStyleMatrixLabel| to configure more specifically the :
{\catcode`\|=12 % Ensures | is not anymore \verb|...|
\begin{codeexample}[width=0pt]
\begin{ZX}
  \zxN{} \rar & \zxMatrix{A} \rar &
  \zxMatrix[
    scale=2,
    /zx/picCustomStyleMatrixMainNode/.style={fill=blue!50},
    /zx/picCustomStyleMatrixLabel/.style={red}]{A}
  \rar & \zxN{}
\end{ZX}
\end{codeexample}
}
You can also set globally the styles like |/zx/picCustomStyleBeforeUserMatrix| (automatically provided, see details in \cref{subsec:customNodes}) to automatically add a style to your picture :
{\catcode`\|=12 % Ensures | is not anymore \verb|...|
\begin{codeexample}[width=0pt]
\tikzset{
  /zx/picCustomStyleBeforeUserMatrix/.style={
    scale=2,
    /zx/picCustomStyleMatrixMainNode/.style={fill=blue!50},
    /zx/picCustomStyleMatrixLabel/.style={red,circle,draw,inner sep=1pt},
    % \zxCustomPicAdditionalPic can be any tikz code to run after the creation of the pic:
    /utils/exec={\def\zxCustomPicAdditionalPic{%
        % the main node has empty name, so .center is the center of the main node
        \node[draw,circle,inner sep=2pt,fill=pink] at (.center) {};%
      }%
    },
  },
}
\begin{ZX}
  \zxZ{} \rar & \zxMatrix{A} \rar & \zxMatrix*{B} \rar & \zxN{}
\end{ZX}
\end{codeexample}
}
\end{pgfmanualentry}

\subsubsection{Circuit-related}

Since 2023-09-17, we provide a number of options to typeset circuits.

\begin{pgfmanualentry}
  \def\extrakeytext{style, }
  \extractcommand\zxBox\opt{\oarg{style}}\marg{box text}\@@
  \extractcommand\zxGate\opt{\oarg{style}}\marg{box text}\@@
  \makeatletter
  \def\extrakeytext{style, }
  \extractkey/zx/every box=style\@nil%
  \extractkey/zx/boxes=\marg{style to add}\@nil%
  \makeatother
  \pgfmanualbody
  (both commands are alias) You can add simple gates using |\zxGate{X}| (the content is typeset in math mode by default), possibly adding additional styling to the main box using the optional argument or |/zx/every box/.style={your replacement style}| or |/zx/boxes={your style to add}|:
{\catcode`\|=12 % Ensures | is not anymore \verb|...|
\begin{codeexample}[]
\begin{ZX}
  \zxBox{G} \rar[B]                      & [\zxwCol] \zxN{} \\
  \zxBox[fill=green]{G_A} \rar[B] & [\zxwCol] \zxN{}
\end{ZX}
\end{codeexample}
}
\begin{codeexample}[width=0pt]
\begin{ZX}[circuit, thick lines]
  \rar & \zxGate[add label={below:\text{Hadamard}}]{H} \rar & 
\end{ZX}
\end{codeexample}
Note that you can also use matrices inside:
\begin{codeexample}[width=0pt]
\begin{ZX}[circuit]
  \rar & \zxGate{
    \begin{pmatrix}
      a & b\\
      c & d
    \end{pmatrix}
  } \rar & \zxGate{f} \rar &
\end{ZX}
\end{codeexample}
\end{pgfmanualentry}

\begin{pgfmanualentry}
  \extractcommand\zxDefaultColumnSepCircuit\@@
  \extractcommand\zxDefaultRowSepCircuit\@@
  \makeatletter
  \def\extrakeytext{style, }
  \extractkey/zx/defaultEnv/circuit\@nil%
  \makeatother
  \pgfmanualbody
  This style enables the circuit mode, which is simply changing the default spacing between lines and columns. Compare:
{\catcode`\|=12 % Ensures | is not anymore \verb|...|
\begin{codeexample}[]
\begin{ZX}
  \rar & \zxGate{H} \rar & \zxGateMulti{2}{3}{H} &  & \rar & \\
  \rar & \zxGate{H} \rar &                       &  & \rar & 
\end{ZX}
\end{codeexample}
}
with
{\catcode`\|=12 % Ensures | is not anymore \verb|...|
\begin{codeexample}[]
\begin{ZX}[circuit]
  \rar & \zxGate{H} \rar & \zxGateMulti{2}{3}{H} &  & \rar & \\
  \rar & \zxGate{H} \rar &                       &  & \rar & 
\end{ZX}
\end{codeexample}
}
You can customize the default spacing with |\def\zxDefaultColumnSepCircuit{4mm}| and |\def\zxDefaultRowSepCircuit{4mm}|.
\end{pgfmanualentry}

\begin{pgfmanualentry}
  \def\extrakeytext{style, }
  \extractcommand\zxGateMulti\opt{\oarg{style fit node}}\opt{\oarg{advanced styling}}\marg{number rows}\marg{number columns}\marg{box text}\@@
  \makeatletter
  \def\extrakeytext{style, }
  \extractkey/zx/generic multi/add label=\marg{label}\@nil%
  \extractkey/zx/generic multi/add label advanced=\marg{style}\marg{label}\@nil%
  \extractkey/zx/generic multi/content inner nodes=\marg{content inner nodes}\@nil%
  \extractkey/zx/generic multi/main=\marg{style}\@nil%
  \extractkey/zx/generic multi/main text=\marg{style}\@nil%
  \extractkey/zx/generic multi/additional code=\marg{code to add new nodes}\@nil%
  \extractkey/zx/generic multi/fit content=\opt{\marg{additional row margin}\marg{additional column margin}\marg{minimum height inner nodes}\marg{minimum width inner nodes}}\@nil%
  \extractkey/zx/generic multi/safe fit\@nil%
  \makeatother
  \pgfmanualbody
  Create a multi-line/row gate:
{\catcode`\|=12 % Ensures | is not anymore \verb|...|
\begin{codeexample}[]
\begin{ZX}[circuit]
  \rar & \zxGate{H} \rar & \zxGateMulti{2}{3}{H} &  & \rar & \\
  \rar & \zxGate{H} \rar &                       &  & \rar & 
\end{ZX}
\end{codeexample}
}
{\catcode`\|=12 % Ensures | is not anymore \verb|...|
\begin{codeexample}[]
  \begin{ZX}
    \rar & \zxBox{H} \rar & \zxGateMulti{1}{3}{H} \dar &           & \rar      & \zxBox{H} &  & \\
         &                & \zxBox{H} \rar             & \zxBox{H} & \zxBox{H} &           &  & 
  \end{ZX}
\end{codeexample}
}
Note that the column will adapt to fit the content if it is too long:
\begin{codeexample}[]
\begin{ZX}[circuit]
  \rar       & \zxGateMulti{1}{2}{HHHHHHHHHH} & \rar       & \\
  \zxGate{H} & \zxGate{H}                     & \zxGate{H} & \zxGate{H} & 
\end{ZX}
\end{codeexample}
You can also customize the style of a gate in a simple way using the first argument (the style will only be applied to the fitting box and to the box when computing its dimensions, but not to the content itself that is added in a separate node, see below for more fine-tuned configuration):
\begin{codeexample}[]
\begin{ZX}[circuit]
A                                 & B                                    & C & D    & E              &  & \\
\zxBox{H} \rar                    & \zxGateMulti[a=secondGate]{2}{3}{H}  &   & \rar & \zxBox{X}      &  & \\
\zxBox{H} \rar                    &                                      &   &      & \zxBox{X} \lar &  & \\
\zxBox{H} \rar \ar[dr,bend right] & \zxBox{H} \rar[to=secondGate]        &   &      &                &  & \\
                                  & \zxGateMulti[,fill=orange!50!white]{1}{2}{H} & & 
\end{ZX}
\end{codeexample}
You can also customize its behavior more precisely using the second optional argument using the above listed styles. |main| and |main text| allows you to change the style of the main node and the main text:
\begin{codeexample}[]
\begin{ZX}[circuit]
A                                 & B                                    & C & D    & E              &  & \\
\zxBox{H} \rar                    & \zxGateMulti[a=secondGate]{2}{3}{H}  &   & \rar & \zxBox{X}      &  & \\
\zxBox{H} \rar                    &                                      &   &      & \zxBox{X} \lar &  & \\
\zxBox{H} \rar \ar[dr,bend right] & \zxBox{H} \rar[to=secondGate]        &   &      &                &  & \\
                                  & \zxGateMulti[][main={fill=orange!50!white}, main text={red}]{1}{2}{H} & & 
\end{ZX}
\end{codeexample}
while |additional code| allows you to write arbitrary code after the creation of the main node (|zxMainNode| and |zxMainNodeText| are the alias of the main node and text node):
\begin{codeexample}[]
\begin{ZX}[circuit]
  \zxBox{H} \rar       & \zxGateMulti[][
    main={fill=orange!50!white},
    main text={red},
    additional code={
      \node[
        circle,
        inner sep=2pt,
        fill=red,
        at={($(zxMainNode.east)+(0mm,1.5mm)$)},
        zx subnode={redCircle}
      ]
      {};
    }%
    ]{1}{2}{H}         & \rar[start subnode={redCircle}, to=lastH, C-] & \\
    \zxBox[a=lastH]{H} &                                              
\end{ZX}
\end{codeexample}

The |add label| and |add label advanced| allows you to add labels:
\begin{codeexample}[width=0pt]
\begin{ZX}[circuit]
  \rar & \zxGateMulti[add label={Bell \\measurement}]{2}{1}{\zxMeter{}} \rar[classical] & \\
  \rar & \rar[cl]                                                                       & 
\end{ZX}
\end{codeexample}
Internally, in order to place the matrix, we place a number of inner nodes in the region of the matrix. You can customize them using |content inner nodes| and |style inner nodes|. This can be practical if you want to force the node to take less space for instance (but the content might go outside of the node):
\begin{codeexample}[width=0pt]
  \begin{ZX}[circuit]
    &  &                       &  &  &  &  & \\
    & \zxGate{H} \rar & \zxGateMulti[][
      content inner nodes={},
      main={opacity=.5},
      style inner nodes={
        red,
        minimum width=2pt,
        minimum height=2pt,
        test/.style={fill=#1,opacity=.7}, test=red
      }]{2}{3}{HHHH} &  &  &  &  & \\
    &  &                       &  &  &  &  & 
  \end{ZX}
\end{codeexample}

By default, we run |fit content/.default={0mm}{0mm}{\zxBoxMinimumHeight}{\zxBoxMinimumWidth}| which works by evaluating the width of the content, and by automatically setting the size of the inner nodes so that the content fits nicely at the end (it takes the default column sep of the matrix, so it will not see custom adjustment of the column size with |&[1cm]|), with a minimum size. You can also call instead |safe fit| in the second argument, that will just set all inner nodes to be equal to the size of the content (which might not be optimal in term of space). While it is faster and works well with nodes of small size, it gives weird results on large nodes:
Compare
\begin{codeexample}[width=0pt]
\begin{ZX}[circuit]
 & A              & B                        & C         & D         & E         &  & \\
 & \zxBox{H} \rar & \zxGateMulti{1}{3}{HHHH} &           & \rar      & \zxBox{H} &  & \\
 &                & \zxBox{H}                & \zxBox{H} & \zxBox{H} &           &  & \\
 &                &                          &           &           &           &  & \\
 &                &                          &           &           &           &  & \\
\end{ZX}
\end{codeexample}
with
\begin{codeexample}[width=0pt]
\begin{ZX}[circuit]
  & A              & B                                        & C         & D         & E         &  & \\
  & \zxBox{H} \rar & \zxGateMulti[][safe fit]{1}{3}{HHHH} &           & \rar      & \zxBox{H} &  & \\
  &                & \zxBox{H}                                & \zxBox{H} & \zxBox{H} &           &  & \\
  &                &                                          &           &           &           &  & \\
  &                &                                          &           &           &           &  & \\
\end{ZX}
\end{codeexample}
Note that if time is an issue for you, see the section on externalization \cref{sec:externalization}.
\end{pgfmanualentry}

%{\catcode`\|=12 % Ensures | is not anymore \verb|...|
\begin{pgfmanualentry}
  \def\extrakeytext{style, }
  \extractcommand\zxElt\opt{\oarg{style}}\marg{box text}\@@
  \extractcommand\zxCtrl\opt{\oarg{style}}\marg{}\@@
  \extractcommand\zxOCtrl\opt{\oarg{style}}\marg{}\@@
  \extractcommand\zxNot\opt{\oarg{style}}\marg{}\@@
  \extractcommand\zxCross\opt{\oarg{style}}\marg{}\@@
  \extractcommand\zxMeter\opt{\oarg{scale}}\marg{}\@@
  \makeatletter
  \def\extrakeytext{style, }
  \extractkey/zx/wires definition/classical\@nil%
  \extractkey/zx/wires definition/cl\@nil%
  \extractkey/zx/wires definition/=--\textbar\@nil%
  \extractkey/zx/wires definition/=\textbar--\@nil%
  \makeatother
  \pgfmanualbody
  |\zxElt| is like |\zxGate| but without any border (useful to add spacing around elements like |\ket{\psi}|, but you might prefer |\zxInput| that does not reserve any space in the matrix for the content and allows an easier align of wires), and the other commands just create the corresponding symbols that you can link together as you want as usual using |\ar| (note that |\zxMeter{}| is node a node but just an icon, so place it yourself inside |\zxGate| or |\zxGateMulti|). The style are wire styles, and are useful to print classical wires (|cl| is an alias for |classical|) and wires bent with a 90 degrees angle. Note that I could not write the right name in the doc, you should remove the equal sign like in \texttt{--\textbar}.
{\catcode`\|=12 % Ensures | is not anymore \verb|...|
\begin{codeexample}[width=0pt]
\begin{ZX}[circuit]
  \zxElt{\ket{\psi}} \rar & \zxBox{H} \rar         & \zxCtrl{} \dar \rar & \zxCross{} \dar \rar
  & \zxBox[add label={Measure}]{\zxMeter{}} \ar[dr,classical,--|] \\
  \ar[r]                  & \zxOCtrl{} \rar \ar[u] & \zxNot{} \rar       & \zxCross{} \ar[rr]
  &  & \zxBox{H} \rar & 
\end{ZX}    
\end{codeexample}
}
\end{pgfmanualentry}

\begin{pgfmanualentry}
  \def\extrakeytext{style, }
  \extractcommand\zxInput\opt{\oarg{style}}\marg{text}\@@
  \extractcommand\zxInputMulti\opt{\oarg{style}}\opt{\oarg{label style}}\marg{nb rows}\marg{text}\@@
  \extractcommand\zxOutput\opt{\oarg{style}}\marg{text}\@@
  \extractcommand\zxOutputMulti\opt{\oarg{style}}\opt{\oarg{label style}}\marg{nb rows}\marg{text}\@@
  \extractcommand\zxGateInput\opt{\oarg{style}}\marg{text}\@@
  \extractcommand\zxGateInputMulti\opt{\oarg{style}}\opt{\oarg{label style}}\marg{nb rows}\marg{text}\@@
  \extractcommand\zxGateOutput\opt{\oarg{style}}\marg{text}\@@
  \extractcommand\zxGateOutputMulti\opt{\oarg{style}}\opt{\oarg{label style}}\marg{nb rows}\marg{text}\@@
  \makeatletter
  \def\extrakeytext{style, }
  \extractkey/zx/enlarge brace=\marg{+ or - distance}\@nil%
  \extractkey/zx/input style=\marg{style}\@nil%
  \extractkey/zx/output style=\marg{style}\@nil%
  \extractkey/zx/input multi style=\marg{style}\@nil%
  \extractkey/zx/output multi style=\marg{style}\@nil%
  \extractkey/zx/input multi label style=\marg{style}\@nil%
  \extractkey/zx/output multi label style=\marg{style}\@nil%
  \extractkey/zx/gate input style=\marg{style}\@nil%
  \extractkey/zx/gate output style=\marg{style}\@nil%
  \extractkey/zx/gate input multi style=\marg{style}\@nil%
  \extractkey/zx/gate output multi style=\marg{style}\@nil%
  \extractkey/zx/gate input multi label style=\marg{style}\@nil%
  \extractkey/zx/gate output multi label style=\marg{style}\@nil%
  \makeatother
  \pgfmanualbody

Use these functions in order to label the input or outputs of circuits (you can also label any diagram made with this library) or gates (the variant you want to use should be clear from the name. You can customize the arrow and label using the optional arguments or globally using the corresponding style (note that the style for the gate inputs was inspired by the great Quantikz package). The command should be located on the row where the brace should start (either in the cell containing the wire or inside the gate directly):
{\catcode`\|=12 % Ensures | is not anymore \verb|...|
\begin{codeexample}[]
\begin{ZX}[circuit]
  \rar \zxInputMulti[blue]{2}{\ket{\psi}}   & \zxGateMulti{3}{2}{U} \zxGateInputMulti{2}{x}
   & \rar \zxGateOutputMulti{2}{x \oplus y} & \zxOutputMulti[red][green]{2}{\text{Output}} \\
  \rar                                      & 
   & \rar                                   &                                           \\
  \rar \zxInput{\ket{0}}                    & \zxGateInput{y}
   & \rar \zxGateOutput{y \oplus 1}                  & \zxOutput{\ket{1}}
\end{ZX}
\end{codeexample}
}

You can enlarge or reduce the distance of the braces (set by default to |\zxDefaultEnlargeBraceOne| for braces on single wires, and |\zxDefaultEnlargeBraceMulti| for braces on multiple wires) using |enlarge brace|:
\begin{codeexample}[width=0pt]
\begin{ZX}
  \zxBox[a=A]{A} \rar & \zxOutputMulti{1}{\parbox{2.2cm}{\raggedright\tiny
      This is the default spacing for one multi-output}} \\
  \zxBox{B} \rar &  \zxOutputMulti{2}{\parbox{2.2cm}{\raggedright\tiny
      This is the default spacing for multiple outputs}} \\
  \zxBox[a=B]{B} \rar & \\
  \zxBox[a=A]{A} \rar & \zxOutputMulti[enlarge brace=1mm]{1}{\parbox{2.2cm}{\raggedright\tiny
      You can increase or decrease the spacing}} \\
  \zxBox{B} \rar &  \zxOutputMulti[enlarge brace=-\zxDefaultEnlargeBraceMulti]{2}{\parbox{2.2cm}{
      \raggedright\tiny You can increase or decrease the spacing}} \\
  \zxBox[a=B]{B} \rar & \\
\end{ZX}
\end{codeexample}

You can prefix the above commands with |V| (for vertical) when reading from bottom to top (the associated style starts with |vertical|):

{\catcode`\|=12 % Ensures | is not anymore \verb|...|
\begin{codeexample}[width=0pt]
\begin{ZX}[circuit]
  \dar \zxVOutputMulti{2}{\text{Output}}                   & \dar & \dar \zxVOutput{\ket{1}} \\ 
  \zxGateMulti{2}{3}{U} \zxVGateOutputMulti{2}{x \oplus y} &      & \zxVGateOutput{y \oplus 1}        \\
  \dar \zxVGateInputMulti{2}{x}                            & \dar & \dar \zxVGateInput{y}    \\
  \zxVInputMulti{2}{\ket{\psi}}                            &      & \zxVInput{\ket{0}}
\end{ZX}
\end{codeexample}
}

You can also use |\zxT| (for Top) instead of |\zxV| if you prefer the convention where inputs are located at the top of the diagram):
{\catcode`\|=12 % Ensures | is not anymore \verb|...|
\begin{codeexample}[width=0pt]
\begin{ZX}[circuit]
  \dar \zxTInputMulti{2}{\ket{\psi}}             & \dar & \dar \zxTInput{\ket{0}}         \\ 
  \zxGateMulti{2}{3}{U} \zxTGateInputMulti{2}{x} &      & \zxTGateInput{y}                \\
  \dar \zxTGateOutputMulti{2}{x\oplus y}         & \dar & \dar \zxTGateOutput{y \oplus 1} \\
  \zxTOutputMulti{2}{\text{Output}}              &      & \zxTOutput{\ket{1}}
\end{ZX}
\end{codeexample}
}
Note that these labels are not taken into account when computing the width of the gate box, so you might need to manually adapt their width of the column, for instance by setting the content of an individual cell like:
{\catcode`\|=12 % Ensures | is not anymore \verb|...|
\begin{codeexample}[width=0pt]
\begin{ZX}[circuit]
  \dar \zxTInputMulti{2}{\ket{\psi}}             & \dar & \dar \zxTInput{\ket{0}}                                                                                                 \\ 
  \zxGateMulti{2}{3}{U} \zxTGateInputMulti{2}{x} &      & \zxTGateInput{y}                                                                                                        \\
  \dar \zxTGateOutputMulti{2}{x\oplus y}         & \dar
    %% We replace the cell with a larger cell:
    & \zxGate[zxTinyFontAndSpacing]{\phantom{y \oplus 1 \oplus x}};
    %% This is useful or the cell will be replaced by another cell during the fit:
   \zxMainNodeAlreadySet{} \dar \zxTGateOutput{y \oplus 1 \oplus x} \\
  \zxTOutputMulti{2}{\text{Output}}              &      & \zxTOutput{\ket{1}}
\end{ZX}
\end{codeexample}
}
\end{pgfmanualentry}

\begin{pgfmanualentry}
  \def\extrakeytext{style, }
  \extractcommand\zxSlice\opt{\oarg{style label}}\opt{\oarg{style line}}\opt{position percent}\marg{text}\@@
  \extractcommand\zxVSlice\opt{\oarg{style label}}\opt{\oarg{style line}}\opt{position percent}\marg{text}\@@
  \makeatletter
  \def\extrakeytext{style, }
  \extractkey/zx/slice label style=\marg{style}\@nil%
  \extractkey/zx/slice line style=\marg{style}\@nil%
  \extractkey/zx/vertical slice label style=\marg{style}\@nil%
  \extractkey/zx/vertical slice line style=\marg{style}\@nil%
  \makeatother
  \pgfmanualbody

  You can add a slice in your diagram or circuit using |\zxSlice{text}| at the corresponding column:
\begin{codeexample}[width=0pt]
  \begin{ZX}[circuit]
    \rar & \zxGate{X} \zxSlice{1} \rar & \zxGate{Y} \zxSlice{Part\\2} \rar & \zxGate{\zxMeter{}} \\
    \rar & \zxGate{H} \rar                       & \zxGate{Y} \rar & 
  \end{ZX}
\end{codeexample}
We also provide a style |rotated=angle| to rotate the label (the default angle is 30 degrees):
\begin{codeexample}[width=0pt]
\begin{ZX}[circuit]
  \rar & \zxGate{X} \zxSlice[rotated]{First part} \rar
       & \zxGate{Y} \zxSlice[rotated]{Second part} \rar & \zxGate{\zxMeter{}} \\
  \rar & \zxGate{H} \rar                       & \zxGate{Y} \rar & 
\end{ZX}
\end{codeexample}
You can change the position using the 3rd optional argument (default to .5):
\begin{codeexample}[width=0pt]
  \begin{ZX}[circuit]
    \rar & \zxGate{X} \zxSlice[][][.2]{1} \rar & \zxGate{Y} \zxSlice[][][.8]{Part\\2} \rar & \zxGate{\zxMeter{}} \\
    \rar & \zxGate{H} \rar                       & \zxGate{Y} \rar & 
  \end{ZX}
\end{codeexample}
You can also customize it as you want using the two optional arguments (for the label first and for the line after):
\begin{codeexample}[width=0pt]
  \begin{ZX}[circuit]
  \rar
   & \zxGate{Y} \rar
    \zxSlice[rotate=90,anchor=east,pos=1,blue][solid,blue,decorate,decoration={snake}]{Why not \\below?}
   & \zxGate{\zxMeter{}} \\
  \rar & \zxGate{H} \rar & \zxGate{Y} \rar & 
\end{ZX}
\end{codeexample}
Finally, the |\zxVSlice| version works similarly, but for vertical slices (make sure to insert it \textbf{before} the newline):
\begin{codeexample}[width=0pt]
  \begin{ZX}[circuit]
    \zxElt{\text{Alice}} &[\zxZeroCol] \rar & \zxGate{X} \rar & \zxGate{Y} \rar & \zxGate{\zxMeter{}}
    \zxVSlice{No communication}\\
    \zxElt{\text{Bob}} & \rar & \zxGate{H} \rar & \zxGate{Y} \rar & 
  \end{ZX}
\end{codeexample}
You can configure it as before, for instance to obtain this fancy effect:
\begin{codeexample}[width=0pt]
  \begin{ZX}[circuit]
    \rar & \zxCtrl{} \rar \dar & \zxGate{Y} \rar & \zxGate{\zxMeter{}}
    \zxVSlice[][
      black,
      double distance=4pt,
      double,
      solid,
      decorate,
      decoration={snake,segment length=2cm},
      % Also funny:
      % decoration={random steps,segment length=.2cm},
      on layer=foreground
    ]{Repeat $n$ times}\\[3mm]
    \rar & \zxCtrl{} \dar \rar & \zxGate{Y} \rar & \zxGate{\zxMeter{}}\\
    \rar & \zxGate{X} \rar & \zxGate{Y} \rar & \zxGate{\zxMeter{}}
  \end{ZX}
\end{codeexample}
\end{pgfmanualentry}

\begin{pgfmanualentry}
  \makeatletter
  \def\extrakeytext{style, }
  \extractkey/tikz/zx filling style=\marg{your style} (default {fill=white})\@nil%
  \makeatother
  \pgfmanualbody
We can also disable or set any custom filling using this style:
\begin{codeexample}[width=0pt]
\begin{ZX}[circuit,/tikz/zx filling style/.style={}]
  \zxInput{\ket{\psi}} \rar & \zxBox{H} \rar         & \zxCtrl{} \dar \rar & \zxCross{} \dar \rar
                            & \zxBox[add label={Measure}]{\zxMeter{}} \ar[dr,classical,--|] \\
  \ar[r]                    & \zxOCtrl{} \rar \ar[u] & \zxNot{} \rar       & \zxCross{} \ar[rr]
                            &                        & \zxBox{H} \rar      & \zxOutput{\ket{\phi}}
\end{ZX}
\end{codeexample}
\end{pgfmanualentry}


\begin{pgfmanualentry}
  \makeatletter
  \def\extrakeytext{style, }
  \extractkey/tikz/every node/block\@nil%
  \makeatother
This is useful if you wish to typeset a block that must be wrapped inside a minipage-like environment (actually we use varwidth):
\begin{codeexample}[width=0pt]
\begin{ZX}[circuit]
  \rar & \zxGate[block]{
    \procedureblock[linenumbering]{$\indcpa_\enc^\adv(\secpar)$}{
      b \sample \bin\\
      (\pk,\sk)\sample \kgen(\secparam)
    }
  } \rar & \zxGate{f} \rar &
\end{ZX}
\end{codeexample}
\begin{codeexample}[width=0pt]
\begin{ZX}[circuit, zx column sep=6mm]
  \rar["k"] & \zxGateMulti[block]{2}{3}{
    \procedureblock[linenumbering]{$\mathsf{Enc}(k,m)$}{
      \pclinecomment{This is the standard one-time pad:} \\
      \pcreturn k \oplus m
    }
  }         &  & \rar["c"] & \zxGate{\mathcal{A}} \rar["\tilde{m}"] & \\
  \rar["m"]&&  &      &                 & 
\end{ZX}
\end{codeexample}
\end{pgfmanualentry}


\subsection{Wires}

\subsubsection{Creating wires and debug mode}

\begin{pgfmanualentry}
  \extractcommand\arrow\opt{\oarg{options}}\@@
  \extractcommand\ar\opt{\oarg{options}}\@@
  \extractcommand\zxWire\marg{options}\@@
  \pgfmanualbody
  These synonym commands (actually coming from |tikz-cd|, except for the last |\zxWire| that is introduced in this library in 2023-10-03 for readability, note that |\zxWire| additionally adds by default a |r| to go right) are used to draw wires between nodes. We refer to |tikz-cd| for an in-depth documentation, but what is important for our purpose is that the direction of the wires can be specified in the \meta{options} using a string of letters |r| (right), |l| (left), |u| (up), |d| (down). It's also possible to specify a node alias as a source or destination as shown below.
\begin{codeexample}[]
\zx{\zxZ{} \ar[r] & \zxX{}} = \zx{\zxX{} \arrow[rd] \\ & \zxZ{}}
\end{codeexample}
  \meta{options} can also be used to add any additional style, either custom ones, or the ones defined in this library (this is recommended since it can be easily changed document-wise by simply changing the style). Multiple wires can be added in the same cell. Other shortcuts provided in |tikz-cd| like |\rar|\dots{} can be used.
{\catcode`\|=12 % Ensures | is not anymore \verb|...|
\begin{codeexample}[width=0pt]
\begin{ZX}
  \zxZ{\alpha} \arrow[d, C] % C = Bell-like wire
               \ar[r,H,o']  % o' = top part of circle
               % H adds Hadamard, combine with \zxHCol
               \ar[r,H,o.] &[\zxHCol] \zxZ{\gamma}\\
  \zxZ{\beta}  \rar        & \zxX{} \ar[ld,red,"\circ" {marking,blue}] \ar[rd,s] \\
  \zxFracX-{\pi}{4}        & &\zxZ{}
\end{ZX}
\end{codeexample}
}
The |\zxWire| can be used as follows:
\begin{codeexample}[width=0pt]
\begin{ZX}[circuit, row sep={.6cm,between origins}]
\zxWire{} & \zxCross{} \zxWire{} \zxWire{d} & \\
\zxWire{} & \zxCross{} \zxWire{}          & 
\end{ZX}
\end{codeexample}
\end{pgfmanualentry}

As explained in |tikz-cd|, there are further shortened forms:
\begin{pgfmanualentry}
  \extractcommand\rar\opt{\oarg{options}}\@@
  \extractcommand\lar\opt{\oarg{options}}\@@
  \extractcommand\dar\opt{\oarg{options}}\@@
  \extractcommand\uar\opt{\oarg{options}}\@@
  \extractcommand\drar\opt{\oarg{options}}\@@
  \extractcommand\urar\opt{\oarg{options}}\@@
  \extractcommand\dlar\opt{\oarg{options}}\@@
  \extractcommand\ular\opt{\oarg{options}}\@@
  \pgfmanualbody
\end{pgfmanualentry}
The first one is equivalent to
\begin{verse}
  |\arrow|{\oarg{options}}|{r}|
\end{verse}
and the other ones work analogously.

Note that sometimes, it may be practical to properly organize big diagrams to increase readability. To that end, one surely wants to have a small and well indented matrix (emacs |M-x align-current| or |M-x align| (for selected lines) commands are very practical to indent matrices automatically). Unfortunately, adding wires inside the matrix can make the line really long and hard to read. Similarly, some nodes involving fractions or long expressions can also be quite long. It is however easy to increase readability (and maintainability) by moving the wires at the very end of the diagram, using |a| (like |alias|, but with a debug mode) to connect nodes and |\def| to create shortcuts. Putting inside a macro with |\def| long node definitions can also be useful to keep small items in the matrix:
\begin{codeexample}[width=0pt]
\begin{ZX}[zx row sep=1pt,
  execute at begin picture={%
    %%% Definition of long items (the goal is to have a small and readable matrix
    % (warning: macro can't have numbers in TeX. Also, make sure not to use existing names)
    \def\Zpifour{\zxFracZ[a=Zpi4]-{\pi}{4}}%
    \def\mypitwo{\zxFracX[a=mypi2]{\pi}{2}}%
  }
  ]
  %%% Matrix: in emacs "M-x align-current" is practical to automatically format it.
  %%% a is for 'alias'... but also provides a debug mode, see below.
                &              &                   &                 & \zxZ[a=toprightpi]{\pi} \\
  \zxN[a=in1]{} & \zxX[a=X1]{} &                   &                 &  & \zxN[a=out1]{}       \\
                &              & \zxZ[a=xmiddle]{} & \mypitwo{}      &  & \zxN[a=out2]{}       \\
  \zxN[a=in2]{} & \Zpifour{}   &                   & \zxX[a=Xdown]{} &  & \zxN[a=out3]{}
  %%% Arrows
  % Column 1
  \ar[from=in1,to=X1]
  \ar[from=in2,to=Zpi4]
  % Column 2
  \ar[from=X1,to=xmiddle,(.]
  \ar[from=X1,to=toprightpi,<',H]
  \ar[from=Zpi4,to=xmiddle,(']
  \ar[from=Zpi4,to=Xdown,o.]
  % Column 3
  \ar[from=xmiddle,to=Xdown,s.]
  \ar[from=xmiddle,to=mypi2]
  % Column 4
  \ar[from=mypi2,to=toprightpi,(']
  \ar[from=mypi2,to=out1,<']
  \ar[from=mypi2,to=out2]
  \ar[from=Xdown,to=out3]
\end{ZX}
\end{codeexample}
In that setting, it is often useful to enable the debug mode via |\def\zxDebugMode{}| as explained above to quickly visualize the alias given to each node (note that debug mode works with |a=| but not with |alias=|). For instance, it was easy to rewrite the above diagram by moving nodes in the matrix and arrows after checking their name on the produced pdf (NB: you can increase |column sep| and |row sep| temporarily to make the debug information more visible):
\begin{codeexample}[width=0pt]
{
  \def\zxDebugMode{}%%%%
  \begin{ZX}[zx row sep=1pt,
    execute at begin picture={%
      %%% Definition of long items (the goal is to have a small and readable matrix
      % (warning: macro can't have numbers in TeX. Also, make sure not to use existing names)
      \def\Zpifour{\zxFracZ[a=Zpi4]-{\pi}{4}}%
      \def\mypitwo{\zxFracX[a=mypi2]{\pi}{2}}%
    }
    ]
    %%% Matrix: in emacs "M-x align" is practical to automatically format it. a is for 'alias'
    & \zxN[a=n]{}  & \zxZ[a=xmiddle]{}       &            & \zxN[a=out1]{} \\
    \zxN[a=in1]{} & \Zpifour{}   & \zxX[a=Xdown]{}         & \mypitwo{} &                \\
    &              &                         &            & \zxN[a=out2]{} \\
    \zxN[a=in2]{} & \zxX[a=X1]{} & \zxZ[a=toprightpi]{\pi} &            & \zxN[a=out3]{}
    %%% Arrows
    % Column 1
    \ar[from=in1,to=X1,s]
    \ar[from=in2,to=Zpi4,.>]
    % Column 2
    \ar[from=X1,to=xmiddle,N']
    \ar[from=X1,to=toprightpi,H]
    \ar[from=Zpi4,to=n,C] \ar[from=n,to=xmiddle,wc]
    \ar[from=Zpi4,to=Xdown]
    % Column 3
    \ar[from=xmiddle,to=Xdown,C-]
    \ar[from=xmiddle,to=mypi2,)]
    % Column 4
    \ar[from=mypi2,to=toprightpi,(']
    \ar[from=mypi2,to=out1,<']
    \ar[from=mypi2,to=out2,<.]
    \ar[from=Xdown,to=out3,<.]
  \end{ZX}
}
\end{codeexample}

\begin{pgfmanualentry}
  \def\extrakeytext{style, }
  \makeatletter% should not be letter for \@@... strange
  \extractkey/zx/wires definition/3d above\@nil%
  \makeatother
  \pgfmanualbody
This style is useful to fake a 3D effect to put a wire above another one like \begin{ZX}[]
 \zxN{} \ar[d,C] \ar[rd,s] & [\zxWCol] \zxN{} \dar[C-] \\[\zxWRow]
 \zxN{} \ar[ru,s,3d above] & \zxN{}                     
\end{ZX} using:
\begin{codeexample}[width=0pt]
\begin{ZX}[]
 \zxN{} \ar[d,C] \ar[rd,s] & [\zxWCol] \zxN{} \dar[C-] \\[\zxWRow]
 \zxN{} \ar[ru,s,3d above,very thick] & \zxN{}                     
\end{ZX}
\end{codeexample}
\end{pgfmanualentry}

\begin{pgfmanualentry}
  \def\extrakeytext{style, }
  \makeatletter% should not be letter for \@@... strange
  \extractkey/zx/defaultEnv/thick lines\@nil%
  \extractkey/tikz/zx thickness wires style=your style\@nil%
  \makeatother
When designing circuits, you might prefer a thicker line style, following the style of Quantikz. This is not enabled by default since for ZX diagrams we want to maintain an important difference between this version and the bold version, but you can enable it with |thick lines|, that internally sets the style |zx thickness wires style| to |thick, line cap=round|.
{\catcode`\|=12 % Ensures | is not anymore \verb|...|
\begin{codeexample}[width=0pt]
Compare \begin{ZX}[circuit, thick lines]
  \zxInput{\ket{\psi}} \rar & \zxBox{H} \rar         & \zxCtrl{} \dar \rar & \zxCross{} \dar \rar
                            & \zxBox[add label={Measure}]{\zxMeter{}} \ar[dr,classical,--|] \\
  \ar[r]                    & \zxOCtrl{} \rar \ar[u] & \zxNot{} \rar       & \zxCross{} \ar[rr]
                            &                        & \zxBox{H} \rar      & \zxOutput{\ket{\phi}}
\end{ZX} with \begin{ZX}[circuit]
  \zxInput{\ket{\psi}} \rar & \zxBox{H} \rar         & \zxCtrl{} \dar \rar & \zxCross{} \dar \rar
                            & \zxBox[add label={Measure}]{\zxMeter{}} \ar[dr,classical,--|] \\
  \ar[r]                    & \zxOCtrl{} \rar \ar[u] & \zxNot{} \rar       & \zxCross{} \ar[rr]
                            &                        & \zxBox{H} \rar      & \zxOutput{\ket{\phi}}
\end{ZX}
\end{codeexample}
}
\end{pgfmanualentry}

\subsubsection{Wire styles (new generation)}

We give now a list of wire styles provided in this library (|/zx/wires definition/| is an automatically loaded style). We recommend using them instead of manual styling to ensure they are the same document-wise, but they can of course be customized to your need. Note that the name of the styles are supposed (ahah, I do my best with what ASCII provides) to graphically represent the action of the style, and some characters are added to precise the shape: typically |'| means top, |.| bottom, |X-| is right to X (or should arrive with angle 0), |-X| is left to X (or should leave with angle zero). These shapes are usually designed to work when the starting node is left most (or above of both nodes have the same column). But they may work both way for some of them.

Note that the first version of that library (which appeared one week before this new version\dots{} hopefully backward compatibility won't be too much of a problem) was using |in=| and |out=| to create these styles. However, it turns out to be not very reliable since the shape of the wire was changing (sometimes importantly) depending on the position of the nodes. This new version should be more reliable, but the older styles are still available by using |IO, nameOfWirestyle| (read more in \cref{subsub:IOwires}).

{\catcode`\|=12 % Ensures | is not anymore \verb|...|
\begin{pgfmanualentry}
  \makeatletter
  \def\extrakeytext{style, }
  % not sure how to do it in a cleaner way without manually defining everything
  \pgfmanualentryheadline{{\ttfamily\declare{/zx/wires definition/|--}}\hfill(style, no default)}%
  \pgfmanualpdflabel[\catcode`\|=12 ]{|--}{}
  % the space after \textt is important or we get two different sections
  % the 2 is just a random char since | does not work (the syntax is "stuff to group@actual text to print" as
  % I understand)
  \index{zx@\texttt {/zx/}!wires definition@\texttt {wires definition/}!2--@\texttt {\protect\pgfmanualbar--}}
  \pgfmanualentryheadline{{\ttfamily\declare{/zx/wires definition/--|}}\hfill(style, no default)}%
  \pgfmanualpdflabel[\catcode`\|=12 ]{--|}{}
  % the space after \textt is important or we get two different sections
  % the 2 is just a random char since | does not work (the syntax is "stuff to group@actual text to print" as
  % I understand)
  \index{zx@\texttt {/zx/}!wires definition@\texttt {wires definition/}!--2@\texttt {--\protect\pgfmanualbar}}
  \makeatother
  \pgfmanualbody
  This gives a wire bent with a 90 degrees angle (respectively starting horizontally then vertically, or first vertically then horizontally).
{\catcode`\|=12 % Ensures | is not anymore \verb|...|
\begin{codeexample}[width=0pt]
\begin{ZX}[circuit]
  \zxElt{\ket{\psi}} \rar & \zxBox{H} \rar         & \zxCtrl{} \dar \rar & \zxCross{} \dar \rar
  & \zxBox[add label={Measure}]{\zxMeter{}} \ar[dr,classical,--|] \\
  \ar[r]                  & \zxOCtrl{} \rar \ar[u] & \zxNot{} \rar       & \zxCross{} \ar[rr]
  &  & \zxBox{H} \rar & 
\end{ZX}    
\end{codeexample}
}
\end{pgfmanualentry}
}

{\catcode`\|=12 % Ensures | is not anymore \verb|...|
  % I can't find a cleaner solution than manually calling pdflabel, pgfmanualentryheadline etc due to the |
  % character
\begin{pgfmanualentry}
  \makeatletter
  \def\extrakeytext{style, }\catcode`\|=12
  \pgfmanualentryheadline{{\ttfamily\declare{/zx/wires definition/horizontal |--}}\hfill(style, no default)}%
  \pgfmanualpdflabel[\catcode`\|=12 ]{horizontal |--}{}
  % the space after \textt is important or we get two different sections
  % the 2 is just a random char since | does not work (the syntax is "stuff to group@actual text to print" as
  % I understand)
  \index{zx@\texttt {/zx/}!wires definition@\texttt {wires definition/}!horizontal 2--@\texttt {horizontal \protect\pgfmanualbar--}}
  \pgfmanualentryheadline{{\ttfamily\declare{/zx/wires definition/horizontal --|}}\hfill(style, no default)}%
  \pgfmanualpdflabel[\catcode`\|=12 ]{horizontal --|}{}
  \index{zx@\texttt {/zx/}!wires definition@\texttt {wires definition/}!horizontal --2@\texttt {horizontal --\protect\pgfmanualbar}}
  \pgfmanualentryheadline{{\ttfamily\declare{/zx/wires definition/vertical |--}}\hfill(style, no default)}%
  \pgfmanualpdflabel[\catcode`\|=12 ]{vertical |--}{}
  % the space after \textt is important or we get two different sections
  % the 2 is just a random char since | does not work (the syntax is "stuff to group@actual text to print" as
  % I understand)
  \index{zx@\texttt {/zx/}!wires definition@\texttt {wires definition/}!vertical 2--@\texttt {vertical \protect\pgfmanualbar--}}
  \pgfmanualentryheadline{{\ttfamily\declare{/zx/wires definition/vertical --|}}\hfill(style, no default)}%
  \pgfmanualpdflabel[\catcode`\|=12 ]{vertical --|}{}
  \index{zx@\texttt {/zx/}!wires definition@\texttt {wires definition/}!vertical --2@\texttt {vertical --\protect\pgfmanualbar}}
  \makeatother
  \pgfmanualbody
Like \texttt{--\textbar} \texttt{\textbar--} except that it only keeps the horizontal/vertical part. This is mostly useful when you want an horizontal/vertical wire starting/ending at a point without having to bother about shifting the other point to maintain horizontality:
{\catcode`\|=12 % Ensures | is not anymore \verb|...|
\begin{codeexample}[width=0pt]
\begin{ZX}
  \rar[horizontal |--, end subnode=A] \rar[horizontal |--, end subnode=B] &
  \node[circle,fill=blue,zx subnode=A,yshift=2mm]{a}; \node[circle,fill=green,zx subnode=B,yshift=-2mm]{b};
  \rar[horizontal --|, start subnode=A] \rar[horizontal --|, start subnode=B] &
\end{ZX} and %
\begin{ZX}
  \dar[vertical --|, end subnode=A]
  \dar[vertical --|, end subnode=B] \\
  \node[circle,fill=blue,zx subnode=A,xshift=-2mm]{a};
  \node[circle,fill=green,zx subnode=B,xshift=2mm]{b};
  \dar[vertical |--, start subnode=A] \dar[vertical |--, start subnode=B] \\
\end{ZX}
\end{codeexample}
}
\end{pgfmanualentry}
}

\begin{pgfmanualentry}
  \makeatletter
  \def\extrakeytext{style, }
  \extractkey/zx/wires definition/C=radius ratio (default 1)\@nil%
  \extractkey/zx/wires definition/C.=radius ratio (default 1)\@nil%
  \extractkey/zx/wires definition/C'=radius ratio (default 1)\@nil%
  \extractkey/zx/wires definition/C-=radius ratio (default 1)\@nil%
  \makeatother
  \pgfmanualbody
  Bell-like wires with an arrival at ``right angle'', |C| represents the shape of the wire, while |.| (bottom), |'| (top) and |-| (side) represent (visually) its position. Combine with |wire centered| (|wc|) to avoid holes when connecting multiple wires (not required with |\zxNone{}|, alias |\zxN{}|).
\begin{codeexample}[]
  A Bell pair \zx{\zxNone{} \ar[d,C] \\[\zxWRow]
                \zxNone{}}
  , a swapped Bell pair
  \begin{ZX}
    \zxN{} \ar[d,C] \ar[rd,s] &[\zxWCol] \zxN{} \\[\zxWRow]
    \zxN{}          \ar[ru,s] &          \zxN{}
  \end{ZX}
  and a funny graph
  \begin{ZX}
    \zxX{} \ar[d,C] \ar[r,C']  & \zxZ{} \ar[d,C-]\\
    \zxZ{} \ar[r,C.]           & \zxX{}
  \end{ZX}.
\end{codeexample}
Note that this style is actually connecting the nodes using a perfect circle (it is \emph{not} based on |curve to|), and therefore should \emph{not} be used together with |in|, |out|, |looseness|\dots{} (this is the case also for most other styles except the ones in |IO|). It has the advantage of connecting nicely nodes which are not aligned or with different shapes:
\begin{codeexample}[]
  \begin{ZX}
    \zxX{\alpha} \ar[dr,C]\\
    & \zxNone{}
  \end{ZX}
\end{codeexample}
The \meta{radius ratio} parameter can be used to turn the circle into an ellipse using this ratio between both axis:
\begin{codeexample}[]
  \begin{ZX}
    \zxX{\alpha}
      \ar[dr,C=0.5,red]
      \ar[dr,C,green]
      \ar[dr,C=2,blue]
      \ar[dr,C=3,purple]\\
                        & \zxNone{}
  \end{ZX}
  \begin{ZX}
    \zxX{} \ar[d,C=2] \ar[r,C'=2]  & \zxZ{} \ar[d,C-=2,H]\\
    \zxZ{} \ar[r,C.=2]           & \zxX{}
  \end{ZX}.
\end{codeexample}

Note that you can customize like for other nodes the direction of the wire using something like |\ar[d, C, end anchor=south]| or |\ar[d, C, end subnode=mySubnode]|. For more advanced users, you can create your own gates and specify directly inside the gate where the |C|-like shapes should connect to. The algorithm followed is:
\begin{itemize}
\item First, it tries to connect to the center of a |true west|, |true east|, |true north|, |true south| subnode (depending on the variation of |C|).
\item Then, it tries to connect to a |true west|, |true east|, |true north|, |true south| \textbf{anchor}
\item Otherwise, it falls back to the |west|, |east|, |north|, |south| anchors.
\end{itemize}

\begin{codeexample}[width=0pt]
\NewExpandableDocumentCommand{\myWeirdGate}{}{
  \zxBox[a=foo]{D}
  \node[circle,fill=green,zx subnode=true west,inner sep=2pt,at=(foo.south west)]{};
}

\begin{ZX}
  A \dar[C]  \\
 \myWeirdGate
\end{ZX}
\end{codeexample}

\end{pgfmanualentry}


\begin{pgfmanualentry}
  \makeatletter
  \def\extrakeytext{style, }
  \extractkey/zx/wires definition/o'=angle (default 40)\@nil%
  \extractkey/zx/wires definition/o.=angle (default 40)\@nil%
  \extractkey/zx/wires definition/o-=angle (default 40)\@nil%
  \extractkey/zx/wires definition/-o=angle (default 40)\@nil%
  \makeatother
  \pgfmanualbody
  Curved wire, similar to |C| but with a soften angle (optionally specified via \meta{angle}, and globally editable with |\zxDefaultLineWidth|). Again, the symbols specify which part of the circle (represented with |o|) must be kept.
\begin{codeexample}[width=3cm]
  \begin{ZX}
    \zxX{} \ar[d,-o] \ar[d,o-]\\
    \zxZ{} \ar[r,o'] \ar[r,o.] & \zxX{}
  \end{ZX}.
\end{codeexample}
 Note that these wires can be combined with |H|, |X| or |Z|, in that case one should use appropriate column and row spacing as explained in their documentation:
\begin{codeexample}[width=3cm]
  \begin{ZX}
    \zxX{\alpha} \ar[d,-o,H] \ar[d,o-,H]\\[\zxHRow]
    \zxZ{\beta} \rar & \zxZ{} \ar[r,o',X] \ar[r,o.,Z] &[\zxSCol] \zxX{}
  \end{ZX}.
\end{codeexample}
\end{pgfmanualentry}

\begin{pgfmanualentry}
  \makeatletter
  \def\extrakeytext{style, }
  \extractkey/zx/wires definition/(=angle (default 30)\@nil%
  \extractkey/zx/wires definition/)=angle (default 30)\@nil%
  \extractkey/zx/wires definition/('=angle (default 30)\@nil%
  \extractkey/zx/wires definition/('=angle (default 30)\@nil%
  \makeatother
  \pgfmanualbody
  Curved wire, similar to |o| but can be used for diagonal items. The angle is, like in |bend right|, the opening angle from the line which links the two nodes. For the first two commands, the |(| and |)| symbols must be imagined as if the starting point was on top of the parens, and the ending point at the bottom.
\begin{codeexample}[width=3cm]
  \begin{ZX}
    \zxX{} \ar[rd,(] \ar[rd,),red]\\
    & \zxZ{}
  \end{ZX}.
\end{codeexample}
Then, |('|=|(| and |(.|=|)|; this notation is, I think, more intuitive when linking nodes from left to right. |('| is used when going to top right and |(.| when going to bottom right.
\begin{codeexample}[width=3cm]
\begin{ZX}
  \zxN{}                       & \zxX{}\\
  \zxZ{} \ar[ru,('] \ar[rd,(.] & \\
                               & \zxX{}
\end{ZX}
\end{codeexample}
When the nodes are too far appart, the default angle of |30| may produce strange results as it will go above (for |('|) the vertical line. Either choose a shorter angle, or see |<'| instead. Note that for now this node is based on |in| and |out|, but it may change later. So if you want to change looseness, or really rely on the precise specified angle, prefer to use |IO,(| instead (which takes the |IO| version, guaranteed to stay untouched).
\end{pgfmanualentry}

\begin{pgfmanualentry}
  \makeatletter
  \def\extrakeytext{style, }
  \extractkey/zx/wires definition/start fake center north\@nil%
  \extractkey/zx/wires definition/start fake center south\@nil%
  \extractkey/zx/wires definition/start fake center east\@nil%
  \extractkey/zx/wires definition/start fake center west\@nil%
  \extractkey/zx/wires definition/start real center\@nil
  \extractkey/zx/wires definition/end fake center north\@nil%
  \extractkey/zx/wires definition/end fake center south\@nil%
  \extractkey/zx/wires definition/end fake center east\@nil%
  \extractkey/zx/wires definition/end fake center west\@nil%
  \extractkey/zx/wires definition/end real center\@nil
  \extractkey/zx/wires definition/left to right\@nil%
  \extractkey/zx/wires definition/right to left\@nil%
  \extractkey/zx/wires definition/up to down\@nil%
  \extractkey/zx/wires definition/down to up\@nil%
  \extractkey/zx/wires definition/force left to right\@nil%
  \extractkey/zx/wires definition/force right to left\@nil%
  \extractkey/zx/wires definition/force up to down\@nil%
  \extractkey/zx/wires definition/force down to up\@nil%
  \extractkey/zx/wires definition/no fake center\@nil%
  \makeatother
  \pgfmanualbody
  Usually each wire should properly use these functions, so the end user should not need that too often (during a first reading, you can skip this paragraph). We added 4 anchors to nodes: |fake center north|, |fake center south|, |fake center east| and |fake center west|. These anchors are used to determine the starting point of the wires depending on the direction of the wire. Because some nodes may not have these anchors, we can't directly set |start anchor=fake center north, on layer=edgelayer| (but the user can do that if they are using only nodes with these anchors) or the code may fail on some nodes. For that reason, we check that these anchors exist while drawing our wires (which, at the best of my knowledge, can only be done while drawing the path). The |start/end fake center *| code is responsible to configure that properly (|start real center| will use the real center), and |left to right| (and similar) just configure both the |start| and |end| point to ensure the node starts at the appropriate anchor. However this won't work for style not defined in this library: in case you are sure that these anchors exists and want to use your own wire styles, you can then set the anchors manually and use |on layer=edgelayer|, or use |force left to right| (and similar) which will automatically do that for the |start| and |end| points.
\begin{codeexample}[]
\begin{ZX}
  \zxX{\alpha+\beta} \ar[r,o',no fake center] & \zxZ{\alpha+\beta}\\
  \zxX{\alpha+\beta} \ar[r,o'] & \zxZ{\alpha+\beta}
\end{ZX}
\end{codeexample}
\end{pgfmanualentry}

\begin{pgfmanualentry}
  \makeatletter
  \def\extrakeytext{style, }
  \extractkey/zx/args/-andL/-=x\@nil%
  \extractkey/zx/args/-andL/1-=x\@nil%
  \extractkey/zx/args/-andL/2-=x\@nil%
  \extractkey/zx/args/-andL/L=y\@nil%
  \extractkey/zx/args/-andL/1L=y\@nil%
  \extractkey/zx/args/-andL/2L=y\@nil%
  \extractkey/zx/args/-andL/1 angle and length=\marg{angle}\marg{length}\@nil%
  \extractkey/zx/args/-andL/1al=\marg{angle}\marg{length}\@nil%
  \extractkey/zx/args/-andL/2 angle and length=\marg{angle}\marg{length}\@nil%
  \extractkey/zx/args/-andL/2al=\marg{angle}\marg{length}\@nil%
  \extractkey/zx/args/-andL/angle and length=\marg{angle}\marg{length}\@nil%
  \extractkey/zx/args/-andL/al=\marg{angle}\marg{length}\@nil%
  \extractkey/zx/args/-andL/1 angle=\marg{angle}\@nil%
  \extractkey/zx/args/-andL/1a=\marg{angle}\@nil%
  \extractkey/zx/args/-andL/2 angle=\marg{angle}\@nil%
  \extractkey/zx/args/-andL/1a=\marg{angle}\marg{length}\@nil%
  \extractkey/zx/args/-andL/angle=\marg{angle}\@nil%
  \extractkey/zx/args/-andL/a=\marg{angle}\@nil%
  \extractkey/zx/args/-andL/symmetry-L\@nil%
  \extractkey/zx/args/-andL/symmetry\@nil%
  \extractkey/zx/args/-andL/negate1L\@nil%
  \extractkey/zx/args/-andL/negate2L\@nil%
  \extractkey/zx/args/-andL/negateL\@nil%
  \extractkey/zx/args/-andL/negate1-\@nil%
  \extractkey/zx/args/-andL/negate2-\@nil%
  \extractkey/zx/args/-andL/negate-\@nil%
  \extractkey/zx/args/-andL/oneMinus1-\@nil%
  \extractkey/zx/args/-andL/oneMinus2-\@nil%
  \extractkey/zx/args/-andL/oneMinus1L\@nil%
  \extractkey/zx/args/-andL/oneMinus2L\@nil%
  \makeatother
  \pgfmanualbody
  The next wires can take multiple options. They are all based on the same set of options for now, namely |/zx/args/-andL/|. The |1*| options are used to configure the starting point, the |2*| to configure the ending point, if no number is given both points are updated. |-| and |L| are used to place two anchors of a Bezier curve. They are expressed in relative distance (so they are typically between $0$ and $1$, but can be pushed above $1$ or below $0$ for stronger effects), |-| is typically on the |x| axis and |L| on the |y| axis (the name represents ``graphically'' the direction). They are however not named |x| and |y| because some wires use them slighlty differently, notably |o| which uses |-| for the direction of the arrow and |L| for the direction perpendicular to the arrow (again the shape of |L| represents a perpendicular line). Each wire interprets |-| and |L| to ensure that $0$ should lead to a straight line, and that a correct shape is obtained when |1-| equals |2-|, |1L| equals |2L| (except for non-symmetric shapes of course), and both |-| and |L| are positive.

  The other expressions involving |angle| (or the shortcut |a|) allow you to define |1-|,|1L|\dots{} using a maybe more intuitive ``polar'' notation, i.e.\ an ``angle'' and a relative length (if not specified, like in |1 angle|, the length defaults to $0.6$). Note that the angle is not really an angle (it is an angle only when the nodes are placed at $45$ degrees, or for the |bezier x/y| variations), but a ``squeezed angle'' (when nodes are not at $45$ degrees, the shape is squeezed horizontally or vertically not to change the wire) and similarly for the length. In the above list, the meaning of each expression should be clear from the name: for instance |1angle and length={45}{.8}| will setup a squeezed angle of $45$ and a relative length of $.8$ for the first point, i.e.\ this is equivalent to $1-=.8\cos(45)$ and $1L=.8\sin(45)$, and |angle=45| will change the angle of both points to $45$, with a relative length of $.6$. In the above list, each long expression has below it a shorter version, for intance |a=45| is equivalent to |angle=45|.

  The last expressions (|symmetry-L|, |symmetry|\dots) are used internally to do some math. Of course if you need to do symmetries at some point you can use these keys (|symmetry-L| exchange |-| and |L|, and |symmetry| exchanges |1| and |2|), |negateX| just negates |X| and |oneMinusX| replaces |X| with |1-X|. Each of the following nodes have default values which can be configured as explained in \cref{subsec:wirecustom}.
\end{pgfmanualentry}

\begin{pgfmanualentry}
  \makeatletter
  \def\extrakeytext{style, }
  \extractkey/zx/wires definition/s=-andL config (default defaultS)\@nil%
  \extractkey/zx/wires definition/s'=-andL config (default defaultS')\@nil%
  \extractkey/zx/wires definition/s.=-andL config (default defaultS')\@nil%
  \extractkey/zx/wires definition/-s=-andL config (default default-S)\@nil%
  \extractkey/zx/wires definition/-s'=-andL config (default \{defaultS',default-S\})\@nil%
  \extractkey/zx/wires definition/-s.=-andL config (default \{defaultS',default-S\})\@nil%
  \extractkey/zx/wires definition/s-=-andL config (default \{defaultS',default-S,symmetry\})\@nil%
  \extractkey/zx/wires definition/s'-=-andL config (default \{defaultS',default-S,symmetry\})\@nil%
  \extractkey/zx/wires definition/s.-=-andL config (default \{defaultS',default-S,symmetry\})\@nil%
  \extractkey/zx/wires definition/-S=-andL config (default \{defaultS',default-S\})\@nil%
  \extractkey/zx/wires definition/-S'=-andL config (default \{defaultS',default-S\})\@nil%
  \extractkey/zx/wires definition/-S.=-andL config (default \{defaultS',default-S\})\@nil%
  \extractkey/zx/wires definition/S-=-andL config (default \{defaultS',default-S,symmetry\})\@nil%
  \extractkey/zx/wires definition/S'-=-andL config (default \{defaultS',default-S,symmetry\})\@nil%
  \extractkey/zx/wires definition/S.-=-andL config (default \{defaultS',default-S,symmetry\})\@nil%
  \makeatother
  \pgfmanualbody
  |s| and |S| are used to create a s-like wire (|s| is smoother than |S| that arrives and leave horizontally), to have nicer diagonal lines between nodes. Other versions are soften versions (the input and output angles are not as sharp. Adding |'| or |.| specifies if the wire is going up-right or down-right, however as of today if it mostly used for backward compatibility since, for instance, |-s'| is the same as |-s| (but some styles may want to do a difference later). The only exception is for |s|/|s'|/|s.|: |s| has a sharper output angle than |s'| and |s.| (which are both equals).
\begin{codeexample}[width=3cm]
  \begin{ZX}
    \zxX{\alpha} \ar[s,rd] \\
                           & \zxZ{\beta}\\
    \zxX{\alpha} \ar[s.,rd] \\
                           & \zxZ{\beta}\\
                           & \zxZ{\alpha}\\
    \zxX{\beta} \ar[S,ru] \\
                           & \zxZ{\alpha}\\
    \zxX{\beta} \ar[s',ru] \\
  \end{ZX}
\end{codeexample}
|-| forces the angle on the side of |-| to be horizontal. Because for now the wires start inside the node, this is not very visible. For that reason, versions with a capital |S| have an anchor on the side of |-| lying on the surface of the node (|S| has two such anchors since both inputs and outputs arrives horizontally) instead of on the |fake center *| anchor (see explanation on |fake center| anchors above).
\begin{codeexample}[width=3cm]
  \begin{ZX}
    \zxX{\alpha} \ar[s.,rd] \\
                           & \zxZ{\beta}\\
    \zxX{\alpha} \ar[-s.,rd] \\
                           & \zxZ{\beta}\\
    \zxX{\alpha} \ar[s.-,rd] \\
                           & \zxZ{\beta}\\
    \zxX{\alpha} \ar[S,rd] \\
                           & \zxZ{\beta}\\
  \end{ZX}
\end{codeexample}
It is possible to configure it using the options in |-andL config| as explained above (default values are given in \cref{subsec:wirecustom}), where |-| is the (relative) position of the horizontal Bezier anchor and |L| its relative vertical position (to keep a |s|-shape, you should have |-|$>$|L|).
\begin{codeexample}[width=3cm]
\begin{ZX}
  \zxX{\alpha} \ar[rd,s.] \\
  & \zxZ{\beta}\\
  % same as s., configure globally using defaultS'\\
  \zxX{\alpha} \ar[rd,s.={-=.8,L=.2}]\\
                 & \zxZ{\beta}\\
  \zxX{\alpha} \ar[rd,s.={L=.4}] \\
                 & \zxZ{\beta}\\
  \zxX{\alpha} \ar[rd,s.={L=0.1,-=1}] \\
                 & \zxZ{\beta}\\
  \zxX{\alpha} \ar[rd,edge above, control points visible,s.={-=2}] \\
                 & \zxZ{\beta}
\end{ZX}
\end{codeexample}
For the non-symmetric versions (involving a vertical arrival), you can configure each point separately using |1-| and |1L| (first point) and |2-| and |2L| (second points). You can also specify the ``squeezed angle'' and ``length'' of each point, for instance using the |1 angle and length={10}{.8}| option (short version is |1al={10}{.8}|) or both at the same time using |al={10}{.6}| (this last command being itself equivalent to |a=10|). As explained later |edge above| and |control points visible| can help you to visualize the control points of the underlying Bezier curve.
\begin{codeexample}[width=3cm]
  \begin{ZX}
    \zxZ{} \ar[dr,s.={al={10}{.8}}]\\ &\zxZ{}\\
    \zxZ{} \ar[edge above,control points visible,dr,s.={a=10}]\\ &\zxZ{}
  \end{ZX}
\end{codeexample}
\end{pgfmanualentry}

\begin{pgfmanualentry}
  \makeatletter
  \def\extrakeytext{style, }
  \extractkey/zx/wires definition/ss=-andL config (default \{defaultS,symmetry-L\})\@nil%
  \extractkey/zx/wires definition/SS=-andL config (default \{defaultS,symmetry-L\})\@nil%
  \extractkey/zx/wires definition/ss.=-andL config (default \{defaultS',symmetry-L\})\@nil%
  \extractkey/zx/wires definition/.ss=-andL config (default \{defaultS',symmetry-L\}30)\@nil%
  \extractkey/zx/wires definition/sIs.=-andL config (default defaultSIS)\@nil%
  \extractkey/zx/wires definition/.sIs=-andL config (default \{defaultS',defaultSIS\})\@nil%
  \extractkey/zx/wires definition/ss.I-=-andL config (default \{defaultS',defaultSIS,symmetry\})\@nil%
  \extractkey/zx/wires definition/I.ss-=-andL config (default \{defaultS',defaultSIS,symmetry\})\@nil%
  \extractkey/zx/wires definition/SIS=-andL config (default \{defaultS',defaultSIS\})\@nil%
  \extractkey/zx/wires definition/.SIS=-andL config (default \{defaultS',defaultSIS\})\@nil%
  \extractkey/zx/wires definition/ISS=-andL config (default \{defaultS',defaultSIS,symmetry\})\@nil%
  \extractkey/zx/wires definition/SS.I=-andL config (default \{defaultS',defaultSIS,symmetry\})\@nil%
  \extractkey/zx/wires definition/I.SS=-andL config (default \{defaultS',defaultSIS,symmetry\})\@nil%
  \extractkey/zx/wires definition/SSI=-andL config (default \{defaultS',defaultSIS,symmetry\})\@nil%
  \makeatother
  \pgfmanualbody
  |ss| is similar to |s| except that we go from top to bottom instead of from left to right. The position of |.| says if the node is wire is going bottom right (|ss.|) or bottom left (|.ss|).
\begin{codeexample}[width=3cm]
  \begin{ZX}
    \zxX{\alpha} \ar[ss,rd] \\
                           & \zxZ{\beta}\\
    \zxX{\alpha} \ar[ss.,rd] \\
                           & \zxZ{\beta}\\
                           & \zxX{\beta} \ar[.ss,dl] \\
    \zxZ{\alpha}\\
                           & \zxX{\beta} \ar[.ss={},dl] \\
    \zxZ{\alpha}\\
  \end{ZX}
\end{codeexample}
|I| forces the angle above (if in between the two |s|) or below (if on the same side as |.|) to be vertical.
\begin{codeexample}[width=3cm]
  \begin{ZX}
    \zxX{\alpha} \ar[ss,rd] \\
                           & \zxZ{\beta}\\
    \zxX{\alpha} \ar[sIs.,rd] \\
                           & \zxZ{\beta}\\
    \zxX{\alpha} \ar[ss.I,rd] \\
                           & \zxZ{\beta}\\
                           & \zxX{\beta} \ar[.sIs,dl] \\
    \zxZ{\alpha}\\
                           & \zxX{\beta} \ar[I.ss,dl] \\
    \zxZ{\alpha}\\
  \end{ZX}
\end{codeexample}
The |S| version forces the anchor on the vertical line to be on the boundary.
\begin{codeexample}[width=3cm]
  \begin{ZX}
    \zxX{\alpha} \ar[SS,rd] \\
                           & \zxZ{\beta}\\
    \zxX{\alpha} \ar[SIS,rd] \\
                           & \zxZ{\beta}\\
    \zxX{\alpha} \ar[SSI,rd] \\
                           & \zxZ{\beta}\\
                           & \zxX{\beta} \ar[.sIs,dl] \\
    \zxZ{\alpha}\\
                           & \zxX{\beta} \ar[I.ss,dl] \\
    \zxZ{\alpha}\\
  \end{ZX}
\end{codeexample}
As for |s| it can be configured:
\begin{codeexample}[width=3cm]
\begin{ZX}
  \zxX{\alpha} \ar[rd,SIS] \\
                             & \zxZ{\beta}\\
  \zxX{\alpha} \ar[rd,SIS={1L=.4}] \\
                             & \zxZ{\beta}\\
  \zxX{\alpha} \ar[rd,SIS={1L=.8}] \\
                             & \zxZ{\beta}\\
  \zxX{\alpha} \ar[rd,SIS={1L=1,2L=1}] \\
                             & \zxZ{\beta}\\
\end{ZX}
\end{codeexample}
\end{pgfmanualentry}

\begin{pgfmanualentry}
  \makeatletter
  \def\extrakeytext{style, }
  \extractkey/zx/wires definition/N=-andL config (default defaultN)\@nil%
  \extractkey/zx/wires definition/N'=-andL config (default defaultN)\@nil%
  \extractkey/zx/wires definition/N.=-andL config (default defaultN)\@nil%
  \extractkey/zx/wires definition/-N=-andL config (default \{defaultN,defaultN-\})\@nil%
  \extractkey/zx/wires definition/-N'=-andL config (default \{defaultN,defaultN-\})\@nil%
  \extractkey/zx/wires definition/-N.=-andL config (default \{defaultN,defaultN-\})\@nil%
  \extractkey/zx/wires definition/N-=-andL config (default \{defaultN,defaultN-,symmetry\})\@nil%
  \extractkey/zx/wires definition/N'-=-andL config (default \{defaultN,defaultN-,symmetry\})\@nil%
  \extractkey/zx/wires definition/N.-=-andL config (default \{defaultN,defaultN-,symmetry\})\@nil%
  \extractkey/zx/wires definition/Nbase=-andL config (default defaultN)\@nil%
  \makeatother
  \pgfmanualbody
  |N| is used to create a left-to-right wire leaving at wide angle and arriving at wide angle (it's named |N| because it roughly have the shape of a capital |N|). In older versions, |'| and |.| was required to specify if the wire should go up-right or down-right, but it is not useful anymore (we keep it for compatibilty with |IO| styles and in case some styles want to do a distinction later).
\begin{codeexample}[width=3cm]
  \begin{ZX}
    \zxX{\alpha} \ar[N,rd] \\
                               & \zxZ{\beta}\\
                               & \zxZ{\alpha}\\
    \zxX{\beta} \ar[N,ru]
  \end{ZX}
\end{codeexample}
|-| forces the angle on the side of |-| to be horizontal.
\begin{codeexample}[width=3cm]
  \begin{ZX}
    \zxX{\alpha} \ar[-N,rd] \\
                               & \zxZ{\beta}\\
                               & \zxZ{\alpha}\\
    \zxX{\beta} \ar[N-,ru]
  \end{ZX}
\end{codeexample}
Like other wires, it can be configured using |-| (horizontal relative position of anchor points) and |L| (vertical relative position of anchor points, make sure to have |-|$<$|L| to have a |N|-looking shape), |al={angle}{relative length}|\dots{}
\begin{codeexample}[width=3cm]
  \begin{ZX}
    \zxX{\alpha} \ar[N,rd] \\
                               & \zxZ{\beta}\\
    \zxX{\alpha} \ar[N={L=1.2},rd] \\
                               & \zxZ{\beta}
  \end{ZX}
\end{codeexample}
All these styles are based on Nbase (which should not be used directly), including the styles like |<|. If you wish to overwrite later |N|-like commands, but not |<|-like, then change |N|. If you wish to also update |<| commands, use |Nbase|.
\end{pgfmanualentry}



\begin{pgfmanualentry}
  \makeatletter
  \def\extrakeytext{style, }
  \extractkey/zx/wires definition/NN=-andL config (default \{defaultN,symmetry-L,defaultNN\})\@nil%
  \extractkey/zx/wires definition/NN.=-andL config (default \{defaultN,symmetry-L,defaultNN\})\@nil%
  \extractkey/zx/wires definition/.NN=-andL config (default \{defaultN,symmetry-L,defaultNN\})\@nil%
  \extractkey/zx/wires definition/NIN=-andL config (default \{defaultN,symmetry-L,defaultNN,defaultNIN\})\@nil%
  \extractkey/zx/wires definition/INN=-andL config (default \{defaultN,symmetry-L,defaultNN,defaultNIN,symmetry\})\@nil%
  \extractkey/zx/wires definition/NNI=-andL config (default \{defaultN,symmetry-L,defaultNN,defaultNIN,symmetry\})\@nil%
  \makeatother
  \pgfmanualbody
  Like |N| but for diagrams read up-to-down or down-to-up. The |.| are maintly used for backward compatibility with |IO| style.
% \begin{codeexample}[width=3cm]
%   \begin{ZX}
%     \zxX{\alpha} \ar[NN,rd] \\
%                                & \zxZ{\beta}\\
%                                & \zxZ{\alpha}\\
%     \zxX{\beta} \ar[NN,ru]
%   \end{ZX}
% \end{codeexample}
% |I| forces the angle on the side of |I| to be vertical.
% \begin{codeexample}[width=3cm]
%   \begin{ZX}
%     \zxX{\alpha} \ar[NIN,rd] \\
%                                & \zxZ{\beta}\\
%                                & \zxZ{\alpha}\\
%     \zxX{\beta} \ar[NNI,ru]
%   \end{ZX}
% \end{codeexample}
% It can be configured like |N| using |-|, |L|\dots{}
\end{pgfmanualentry}

\begin{pgfmanualentry}
  \makeatletter
  \def\extrakeytext{style, }
  \extractkey/zx/wires definition/<'=-andL config (default like N-)\@nil%
  \extractkey/zx/wires definition/<.=-andL config (default like N-)\@nil%
  \extractkey/zx/wires definition/'>=-andL config (default like -N)\@nil%
  \extractkey/zx/wires definition/.>=-andL config (default like -N)\@nil%
  %\extractkey/zx/wires definition/^.=-andL config (default 60)\@nil%
  %\extractkey/zx/wires definition/.^=-andL config (default 60)\@nil%
  \extractkey/zx/wires definition/'v=-andL config (default like INN)\@nil%
  \extractkey/zx/wires definition/v'=-andL config (default like NNI)\@nil%
  \makeatother
  \pgfmanualbody
  |<'| and |<.| are similar to |N-|, except that the anchor of the vertical line is put on the boundary (similarly for |*>| and |-N|, |*v*| and |INN|, and |*^*| and |NIN|: |.^| and |^.| were not possible to put in this documentation since the documentation package does not like the |^| character). The position of |'| and |.| does not really matters anymore in new versions, but for backward compatibility with |IO| styles, and maybe forward compatibility (another style may need this information), it's cleaner to put |.| or |'| on the direction of the wire. It also helps the reader of your diagrams to see the shape of the wire.
\begin{codeexample}[width=0cm]
\begin{ZX}
  \zxN{}                         & \zxZ{}\\
  \zxX{} \ar[ru,<'] \ar[rd,<.] \\
  \zxN{}                         & \zxZ{}\\
\end{ZX}
\end{codeexample}
\begin{codeexample}[width=0cm]
\begin{ZX}
  \zxN{}                         & \zxZ{}\\
  \zxX{} \ar[ru,.>] \ar[rd,'>] \\
  \zxN{}                         & \zxZ{}\\
\end{ZX}
\end{codeexample}
\begin{codeexample}[width=0cm]
\begin{ZX}
  \zxN{} & \zxFracX{\pi}{2} \ar[dl,.^] \ar[dr,^.] & \\
  \zxZ{} &                                & \zxX{}
\end{ZX}
\end{codeexample}
\begin{codeexample}[width=0cm]
\begin{ZX}
  \zxZ{} &                                & \zxX{}\\
  \zxN{} & \zxX{} \ar[ul,'v] \ar[ur,v'] &
\end{ZX}
\end{codeexample}
\end{pgfmanualentry}


\begin{pgfmanualentry}
  \makeatletter
  \def\extrakeytext{style, }
  \extractkey/zx/wires definition/3 dots=text (default =)\@nil%
  \extractkey/zx/wires definition/3 vdots=text (default =)\@nil%
  \makeatother
  \pgfmanualbody
  The styles put in the middle of the wire (without drawing the wire) $\dots$ (for |3 dots|) or $\vdots$ (for |3 vdots|). The dots are scaled according to |\zxScaleDots| and the text \meta{text} is written on the left. Use |&[\zxDotsRow]| and |\\[\zxDotsRow]| to properly adapt the spacing of columns and rows.
\begin{codeexample}[width=3cm]
\begin{ZX}
  \zxZ{\alpha} \ar[r,o'] \ar[r,o.]
               \ar[r,3 dots]
               \ar[d,3 vdots={$n$\,}] &[\zxDotsCol] \zxFracX{\pi}{2}\\[\zxDotsRow]
  \zxZ{\alpha} \rar             & \zxFracX{\pi}{2}
\end{ZX}
\end{codeexample}
\end{pgfmanualentry}

\begin{pgfmanualentry}
  \makeatletter
  \def\extrakeytext{style, }
  \extractkey/zx/wires definition/H=style (default {})\@nil%
  \extractkey/zx/wires definition/Z=style (default {})\@nil%
  \extractkey/zx/wires definition/X=style (default {})\@nil%
  \makeatother
  \pgfmanualbody
  Adds a |H| (Hadamard), |Z| or |X| node (without phase) in the middle of the wire. Width of column or rows should be adapted accordingly using |\zxNameRowcolFlatnot| where |Name| is replaced by |H|, |S| (for ``spiders'', i.e.\ |X| or |Z|), |HS| (for both |H| and |S|) or |W|, |Rowcol| is either |Row| (for changing row sep) or |Col| (for changing column sep) and |Flatnot| is empty or |Flat| (if the wire is supposed to be a straight line as it requires more space). For instance:
\begin{codeexample}[width=3cm]
\begin{ZX}
  \zxZ{\alpha} \ar[d] \ar[r,o',H] \ar[r,o.,H] &[\zxHCol] \zxX{\beta}\\
  \zxZ{\alpha}  \ar[d,-o,X] \ar[d,o-,Z]                        \\[\zxHSRow]
  \zxX{\gamma}
\end{ZX}
\end{codeexample}
The \meta{style} parameter can be used to add additional \tikzname{} style to the nodes, notably a position using |\ar[rd,-N.,H={pos=.35}]|. The reason for using that is that the wires start inside the nodes, therefore the ``middle'' of the wire is closer to the node when the other side is on an empty node.
\begin{codeexample}[width=0pt]
\begin{ZX}[zx row sep=0pt]
 \zxN{} \ar[rd,-N.,H={pos=.35}] &[\zxwCol,\zxHCol]  &[\zxwCol,\zxHCol] \zxN{} \\[\zxNRow]%%
                                & \zxX{\alpha}
                                     \ar[ru,N'-,H={pos=1-.35}]
                                     \ar[rd,N.-,H={pos=1-.35}] &  \\[\zxNRow]
 \zxN{} \ar[ru,-N',H={pos=.35}]                                &  & \zxN{}
\end{ZX}
\end{codeexample}
Note that it's possible to automatically start wires on the border of the node, but it is slower and create other issues, see \cref{subsec:wiresInsideOutside} for more details. The second option (also presented in this section) is to manually define the |start anchor| and |end anchor|, but it can change the shape of the wire).
\end{pgfmanualentry}

\begin{pgfmanualentry}
  \makeatletter
  \def\extrakeytext{style, }
  \extractkey/zx/wires definition/wire centered\@nil%
  \extractkey/zx/wires definition/wc\@nil%
  \extractkey/zx/wires definition/wire centered start\@nil%
  \extractkey/zx/wires definition/wcs\@nil%
  \extractkey/zx/wires definition/wire centered end\@nil%
  \extractkey/zx/wires definition/wce\@nil%
  \makeatother
  \pgfmanualbody
  Forces the wires to start at the center of the node (|wire centered start|, alias |wcs|), to end at the center of the node (|wire centered end|, alias |wce|) or both (|wire centered|, alias |wc|). This may be useful, for instance in the old |IO| mode (see below) when nodes have different sizes (the result looks strange otherwise), or with some wires (like |C|) connected to |\ZxNone+| (if possible, use |\zxNone| (without any embellishment) since it does not suffer from this issue as it is a coordinate).

  See also |between none| to also increase looseness when connecting only wires (use |between none| \emph{only} in |IO| mode).
\begin{codeexample}[width=3cm]
\begin{ZX}
  \zxZ{} \ar[IO,o',r] \ar[IO,o.,r]       & \zxX{\alpha}\\
  \zxZ{} \ar[IO,o',r,wc] \ar[IO,o.,r,wc] & \zxX{\alpha}
\end{ZX}
\end{codeexample}
% Without |wc| (note that because there is no node, we need to use |&[\zxWCol]| (for columns) and |\\[\zxWRow]| (for rows) to get nicer spacing):
% \begin{codeexample}[width=3cm]
% \zx{\zxNone{} \rar &[\zxWCol] \zxNone{} \rar &[\zxWCol] \zxNone{} }
% \end{codeexample}
% With |wc|:
% \begin{codeexample}[width=3cm]
% \zx{\zxNone{} \rar[wc] &[\zxWCol] \zxNone{} \rar[wc] &[\zxWCol] \zxNone{}}
% \end{codeexample}
\end{pgfmanualentry}


\begin{pgfmanualentry}
  \makeatletter
  \def\extrakeytext{style, }
  \extractkey/zx/wires definition/bezier=-andL config \@nil%
  \extractkey/zx/wires definition/bezier x=-andL config \@nil%
  \extractkey/zx/wires definition/bezier y=-andL config \@nil%
  \extractkey/zx/wires definition/bezier 4=\{x1\}\{y1\}\{x2\}\{y2\} \@nil%
  \extractkey/zx/wires definition/bezier 4 x=\{x1\}\{y1\}\{x2\}\{y2\} \@nil%
  \extractkey/zx/wires definition/bezier 4 y=\{x1\}\{y1\}\{x2\}\{y2\} \@nil%
  \makeatother
  \pgfmanualbody
  To create a bezier wire. These styles are not really meant to be used for the final user because they are long to type and would not be changed document-wise when the style is changed, but most styles are based on these styles. For the |bezier 4 *| versions, the two first arguments are the relative position of the first anchor (|x| and |y| position), the next two of the second anchor. In the |bezier *| versions, the value of |1-| will be the relative |x| position of the first point, |1L| the relative position of the second, and |2-| and |2L| will be for the second point (the advantage of this is that it is also possible to specify angles using |1al={angle}{length}|\dots{} as explained in the |-andL| syle). They are said to be relative in the sense that |{0}{0}| is the coordinate of the first point, and |{1}{1}| the second point. The |bezier x| and |bezier 4 y| are useful when the node are supposed to be horizontally or vertically aligned: the distance are now expressed as a fraction of the horizontal (respectively vertical) distance between the two nodes. Using relative coordinates has the advantage that if the nodes positions are moved, the aspect of the wire does not change (it is just squeezed), while this is not true with |in|/|out| wires which preserves angles but not shapes.
Note that all arrows that are based on the |bezier| style (most of the keys: |o|-like, |N|-like, |<|-like, |s|-like) can try to connect to subnodes or anchors called |fake center {east/north/west/south}| in order to start the wire in between the real center and an |east/...| coordinate (note that some variations can use another anchor, for instance |<'| will set the end anchor to |west| by default). Since adding manually an anchor to a node can be quite tedious, it is often easier to create a subnode, using either |zx subnode=name of subnode| or |\zxCoordinateSubnode{name of subnode}|. For instance, we show how to create a node such that bezier arriving from right will be connected to the south east part of the node while bezier leaving from the left will start at the north east anchor:
\begin{codeexample}[width=0pt]
\NewExpandableDocumentCommand{\myWeirdNode}{m}{%
  \node[zx main node,alias=tmp,fill=pink,rounded corners,inner sep=2pt]{A};
  % will be used by bezier curves to know how to connect:
  \zxCoordinateSubnode[at={(tmp.north east)}]{fake center east}
  \zxCoordinateSubnode[at={(tmp.south west)}]{fake center west}
}

\begin{ZX}
  \myWeirdNode{A} \ar[rd, s] \ar[C,dr] &                                               & \myWeirdNode{B} \\
                                       & \zxZ{a \oplus b \oplus c \oplus d} \ar[ru, s] & 
\end{ZX}
\end{codeexample}
\end{pgfmanualentry}


\subsubsection{IO wires, the old styles}\label{subsub:IOwires}

\begin{stylekey}{/zx/wires definition/IO}
As explained above, wires were first defined using |in|, |out| and |looseness|, but this turned out to be sometimes hard to use since the shape of the wire was changing depending on the position. For example consider the differences between the older version:
\begin{codeexample}[]
\begin{ZX}
  \zxN{}                       & \zxZ{} \\
  \zxZ{} \ar[ru,IO,N'] \ar[rd,IO,N.] &\\
                               & \zxZ{} \\
\end{ZX}
\begin{ZX}
  \zxN{}                       & \zxZ{} \\[-3pt]
  \zxZ{} \ar[ru,IO,N'] \ar[rd,IO,N.] &\\[-3pt]
                               & \zxZ{} \\
\end{ZX}
\begin{ZX}
  \zxN{}                       & \zxZ{} \\[-5pt]
  \zxZ{} \ar[ru,IO,N'] \ar[rd,IO,N.] &\\[-5pt]
                               & \zxZ{} \\
\end{ZX}
\end{codeexample}
\begin{codeexample}[]
\begin{ZX}
  \zxN{}                       & \zxZ{} \\
  \zxZ{} \ar[ru,N'] \ar[rd,N.] &\\
                               & \zxZ{} \\
\end{ZX}
and the newer:
\begin{ZX}
  \zxN{}                       & \zxZ{} \\[-3pt]
  \zxZ{} \ar[ru,N'] \ar[rd,N.] &\\[-3pt]
                               & \zxZ{} \\
\end{ZX}
\begin{ZX}
  \zxN{}                       & \zxZ{} \\[-5pt]
  \zxZ{} \ar[ru,N'] \ar[rd,N.] &\\[-5pt]
                               & \zxZ{} \\
\end{ZX}
\end{codeexample}
Here is another example:
\begin{codeexample}[]
Before \begin{ZX}
  \zxNone{} \ar[IO,C,d,wc] \ar[rd,IO,s] &[\zxWCol] \zxNone{} \\[\zxWRow]
  \zxNone{}                \ar[ru,IO,s] &          \zxNone{}
\end{ZX} after \begin{ZX}
  \zxNone{} \ar[C,d] \ar[rd,s] &[\zxWCol] \zxNone{} \\[\zxWRow]
  \zxNone{}          \ar[ru,s] &          \zxNone{}
\end{ZX}
\end{codeexample}
This example led to the creation of the |bn| style, in order to try to find appropriate looseness values depending on the case\dots{} but it is harder to use and results are less predictable.

The new method also allowed us to use |N| for both |N.| and |N'| styles (however we kept both versions for backward compatibility and in case later we want to make a distinction between nodes going doing or up).

However, if you prefer the old style, you can just use them by adding |IO,| in front of the style name (styles are nested inside |IO|). Note however that the customization options are of course different.
\end{stylekey}

We list now the older |IO| styles:

\begin{pgfmanualentry}
  \makeatletter
  \def\extrakeytext{style, }
  \extractkey/zx/wires definition/IO/C\@nil%
  \extractkey/zx/wires definition/IO/C\@nil%
  \extractkey/zx/wires definition/IO/C'\@nil%
  \extractkey/zx/wires definition/IO/C-\@nil%
  \makeatother
  \pgfmanualbody
  |IO| mode for the |C| wire (used for Bell-like shapes).
\begin{codeexample}[]
  Bell pair \zx{\zxNone{} \ar[d,IO,C] \\[\zxWRow]
                \zxNone{}}
  and funny graph
  \begin{ZX}
    \zxX{} \ar[d,IO,C] \ar[r,C']  & \zxZ{} \ar[d,IO,C-]\\
    \zxZ{} \ar[r,IO,C.]           & \zxX{}
  \end{ZX}.
\end{codeexample}
Note that the |IO| version cannot really be used when nodes are not aligned (using |wc| can sometimes help with the alignment):
\begin{codeexample}[]
  Normal \begin{ZX}
    \zxX{\alpha} \ar[dr,C]\\
    & \zxNone{}
  \end{ZX}, and IO \begin{ZX}
    \zxX{\alpha} \ar[dr,IO,C]\\
    & \zxNone{}
  \end{ZX}
\end{codeexample}
\end{pgfmanualentry}

\begin{pgfmanualentry}
  \makeatletter
  \def\extrakeytext{style, }
  \extractkey/zx/wires definition/IO/o'=angle (default 40)\@nil%
  \extractkey/zx/wires definition/IO/o.=angle (default 40)\@nil%
  \extractkey/zx/wires definition/IO/o-=angle (default 40)\@nil%
  \extractkey/zx/wires definition/IO/-o=angle (default 40)\@nil%
  \makeatother
  \pgfmanualbody
  |IO| version of |o|. Curved wire, similar to |C| but with a soften angle (optionally specified via \meta{angle}, and globally editable with |\zxDefaultLineWidth|). Again, the symbols specify which part of the circle (represented with |o|) must be kept.
\begin{codeexample}[width=3cm]
  \begin{ZX}
    \zxX{} \ar[d,IO,-o] \ar[d,IO,o-]\\
    \zxZ{} \ar[r,IO,o'] \ar[r,IO,o.] & \zxX{}
  \end{ZX}.
\end{codeexample}
 Note that these wires can be combined with |H|, |X| or |Z|, in that case one should use appropriate column and row spacing as explained in their documentation:
\begin{codeexample}[width=3cm]
  \begin{ZX}
    \zxX{\alpha} \ar[d,IO,-o,H] \ar[d,IO,o-,H]\\[\zxHRow]
    \zxZ{\beta} \rar & \zxZ{} \ar[r,IO,o',X] \ar[r,IO,o.,Z] &[\zxSCol] \zxX{}
  \end{ZX}.
\end{codeexample}
\end{pgfmanualentry}

\begin{pgfmanualentry}
  \makeatletter
  \def\extrakeytext{style, }
  \extractkey/zx/wires definition/IO/(=angle (default 30)\@nil%
  \extractkey/zx/wires definition/IO/)=angle (default 30)\@nil%
  \extractkey/zx/wires definition/IO/('=angle (default 30)\@nil%
  \extractkey/zx/wires definition/IO/('=angle (default 30)\@nil%
  \makeatother
  \pgfmanualbody
  |IO| version of |(| (so far they are the same, but it may change later, use this version if you want to play with |looseness|). Curved wire, similar to |o| but can be used for diagonal items. The angle is, like in |bend right|, the opening angle from the line which links the two nodes. For the first two commands, the |(| and |)| symbols must be imagined as if the starting point was on top of the parens, and the ending point at the bottom.
\begin{codeexample}[width=3cm]
  \begin{ZX}
    \zxX{} \ar[rd,IO,(] \ar[rd,IO,),red]\\
    & \zxZ{}
  \end{ZX}.
\end{codeexample}
Then, |('|=|(| and |(.|=|)|; this notation is, I think, more intuitive when linking nodes from left to right. |('| is used when going to top right and |(.| when going to bottom right.
\begin{codeexample}[width=3cm]
\begin{ZX}
  \zxN{}                       & \zxX{}\\
  \zxZ{} \ar[ru,IO,('] \ar[IO,rd,(.] & \\
                               & \zxX{}
\end{ZX}
\end{codeexample}
When the nodes are too far appart, the default angle of |30| may produce strange results as it will go above (for |('|) the vertical line. Either choose a shorter angle, or see |<'| instead.
\end{pgfmanualentry}

\begin{pgfmanualentry}
  \makeatletter
  \def\extrakeytext{style, }
  \extractkey/zx/wires definition/IO/s\@nil%
  \extractkey/zx/wires definition/IO/s'=angle (default 30)\@nil%
  \extractkey/zx/wires definition/IO/s.=angle (default 30)\@nil%
  \extractkey/zx/wires definition/IO/-s'=angle (default 30)\@nil%
  \extractkey/zx/wires definition/IO/-s.=angle (default 30)\@nil%
  \extractkey/zx/wires definition/IO/s'-=angle (default 30)\@nil%
  \extractkey/zx/wires definition/IO/s.-=angle (default 30)\@nil%
  \makeatother
  \pgfmanualbody
  |IO| version of |s|. |s| is used to create a s-like wire, to have nicer soften diagonal lines between nodes. Other versions are soften versions (the input and output angles are not as sharp, and the difference angle can be configured as an argument or globally using |\zxDefaultSoftAngleS|). Adding |'| or |.| specifies if the wire is going up-right or down-right.
\begin{codeexample}[width=3cm]
  \begin{ZX}
    \zxX{\alpha} \ar[IO,s,rd] \\
                               & \zxZ{\beta}\\
    \zxX{\alpha} \ar[IO,s.,rd] \\
                               & \zxZ{\beta}\\
                               & \zxZ{\alpha}\\
    \zxX{\beta} \ar[IO,s,ru] \\
                               & \zxZ{\alpha}\\
    \zxX{\beta} \ar[IO,s',ru] \\
  \end{ZX}
\end{codeexample}
|-| forces the angle on the side of |-| to be horizontal.
\begin{codeexample}[width=3cm]
  \begin{ZX}
    \zxX{\alpha} \ar[IO,s.,rd] \\
                           & \zxZ{\beta}\\
    \zxX{\alpha} \ar[IO,-s.,rd] \\
                           & \zxZ{\beta}\\
    \zxX{\alpha} \ar[IO,s.-,rd] \\
                           & \zxZ{\beta}\\
  \end{ZX}
\end{codeexample}
\end{pgfmanualentry}

\begin{pgfmanualentry}
  \makeatletter
  \def\extrakeytext{style, }
  \extractkey/zx/wires definition/IO/ss\@nil%
  \extractkey/zx/wires definition/IO/ss.=angle (default 30)\@nil%
  \extractkey/zx/wires definition/IO/.ss=angle (default 30)\@nil%
  \extractkey/zx/wires definition/IO/sIs.=angle (default 30)\@nil%
  \extractkey/zx/wires definition/IO/.sIs=angle (default 30)\@nil%
  \extractkey/zx/wires definition/IO/ss.I-=angle (default 30)\@nil%
  \extractkey/zx/wires definition/IO/I.ss-=angle (default 30)\@nil%
  \makeatother
  \pgfmanualbody
  |IO| version of |ss|. |ss| is similar to |s| except that we go from top to bottom instead of from left to right. The position of |.| says if the node is wire is going bottom right (|ss.|) or bottom left (|.ss|).
\begin{codeexample}[width=3cm]
  \begin{ZX}
    \zxX{\alpha} \ar[IO,ss,rd] \\
                           & \zxZ{\beta}\\
    \zxX{\alpha} \ar[IO,ss.,rd] \\
                           & \zxZ{\beta}\\
                           & \zxX{\beta} \ar[IO,.ss,dl] \\
    \zxZ{\alpha}\\
                           & \zxX{\beta} \ar[IO,.ss,dl] \\
    \zxZ{\alpha}\\
  \end{ZX}
\end{codeexample}
|I| forces the angle above (if in between the two |s|) or below (if on the same side as |.|) to be vertical.
\begin{codeexample}[width=3cm]
  \begin{ZX}
    \zxX{\alpha} \ar[IO,ss,rd] \\
                           & \zxZ{\beta}\\
    \zxX{\alpha} \ar[IO,sIs.,rd] \\
                           & \zxZ{\beta}\\
    \zxX{\alpha} \ar[IO,ss.I,rd] \\
                           & \zxZ{\beta}\\
                           & \zxX{\beta} \ar[IO,.sIs,dl] \\
    \zxZ{\alpha}\\
                           & \zxX{\beta} \ar[IO,I.ss,dl] \\
    \zxZ{\alpha}\\
  \end{ZX}
\end{codeexample}
\end{pgfmanualentry}

\begin{pgfmanualentry}
  \makeatletter
  \def\extrakeytext{style, }
  \extractkey/zx/wires definition/IO/<'=angle (default 60)\@nil%
  \extractkey/zx/wires definition/IO/<.=angle (default 60)\@nil%
  \extractkey/zx/wires definition/IO/'>=angle (default 60)\@nil%
  \extractkey/zx/wires definition/IO/.>=angle (default 60)\@nil%
  %\extractkey/zx/wires definition/IO/^.=angle (default 60)\@nil%
  %\extractkey/zx/wires definition/IO/.^=angle (default 60)\@nil%
  \extractkey/zx/wires definition/IO/'v=angle (default 60)\@nil%
  \extractkey/zx/wires definition/IO/v'=angle (default 60)\@nil%
  \makeatother
  \pgfmanualbody
  These keys are a bit like |('| or |(.| but the arrival angle is vertical (or horizontal for the |^| (up-down) and |v| (down-up) versions). As before, the position of the decorator |.|,|'| denote the direction of the wire.
\begin{codeexample}[width=0cm]
\begin{ZX}
  \zxN{}                         & \zxZ{}\\
  \zxX{} \ar[IO,ru,<'] \ar[IO,rd,<.] \\
  \zxN{}                         & \zxZ{}\\
\end{ZX}
\end{codeexample}
\begin{codeexample}[width=0cm]
\begin{ZX}
  \zxN{} & \zxFracX{\pi}{2} \ar[IO,dl,.^] \ar[IO,dr,^.] & \\
  \zxZ{} &                                & \zxX{}
\end{ZX}
\end{codeexample}
\begin{codeexample}[width=0cm]
\begin{ZX}
  \zxZ{} &                                & \zxX{}\\
  \zxN{} & \zxX{} \ar[IO,ul,'v] \ar[IO,ur,v'] &
\end{ZX}
\end{codeexample}
\end{pgfmanualentry}

\begin{pgfmanualentry}
  \makeatletter
  \def\extrakeytext{style, }
  \extractkey/zx/wires definition/IO/N'=angle (default 60)\@nil%
  \extractkey/zx/wires definition/IO/N.=angle (default 60)\@nil%
  \extractkey/zx/wires definition/IO/-N'=angle (default 60)\@nil%
  \extractkey/zx/wires definition/IO/-N.=angle (default 60)\@nil%
  \extractkey/zx/wires definition/IO/N'-=angle (default 60)\@nil%
  \extractkey/zx/wires definition/IO/N.-=angle (default 60)\@nil%
  \makeatother
  \pgfmanualbody
  |IO| version of |N|. |N| is used to create a wire leaving at wide angle and arriving at wide angle. Adding |'| or |.| specifies if the wire is going up-right or down-right.
\begin{codeexample}[width=3cm]
  \begin{ZX}
    \zxX{\alpha} \ar[IO,N.,rd] \\
                               & \zxZ{\beta}\\
                               & \zxZ{\alpha}\\
    \zxX{\beta} \ar[IO,N',ru] \\
  \end{ZX}
\end{codeexample}
|-| forces the angle on the side of |-| to be horizontal.
\begin{codeexample}[width=3cm]
  \begin{ZX}
    \zxX{\alpha} \ar[IO,-N.,rd] \\
                               & \zxZ{\beta}\\
                               & \zxZ{\alpha}\\
    \zxX{\beta} \ar[IO,N'-,ru] \\
  \end{ZX}
\end{codeexample}
\end{pgfmanualentry}

\begin{stylekey}{/zx/wires definition/ls=looseness}
  Shortcut for |looseness|, allows to quickly redefine looseness. Use with care (or redefine style directly), and \emph{do not use on styles that are not in |IO|}, since they don't use the |in|/|out| mechanism (only |(|-like styles use |in|/|out|\dots{} for now. In case you want to change looseness of |(|, prefer to use |IO,(| as it is guaranteed to be backward compatible). We may try later to give a key |looseness| for these styles, but it's not the case for now. For |IO| styles, you can also change yourself other values, like |in|, |out|\dots
\begin{codeexample}[]
\begin{ZX}
  \zxZ{} \ar[rd,s] \\
                   & \zxX{}\\
  \zxZ{} \ar[rd,IO,s] \\
                   & \zxX{}\\
  \zxZ{} \ar[rd,IO,s,ls=3] \\
                   & \zxX{}
\end{ZX}
\end{codeexample}
\end{stylekey}

\begin{pgfmanualentry}
  \makeatletter
  \def\extrakeytext{style, }
  \extractkey/zx/wires definition/between none\@nil%
  \extractkey/zx/wires definition/bn\@nil%
  \makeatother
  \pgfmanualbody
  When drawing only |IO| wires (normal wires would suffer from this parameter), the default looseness may not be good looking and holes may appear in the line. This style (whose alias is |bn|) should therefore be used when curved wires \emph{from the |IO| path} are connected together. In that case, also make sure to separate columns using |&[\zxWCol]| and rows using |\\[\zxWRow]|.
\begin{codeexample}[width=3cm]
A swapped Bell pair is %
\begin{ZX}
  \zxNone{} \ar[IO,C,d,wc] \ar[rd,IO,s,bn] &[\zxWCol] \zxNone{} \\[\zxWRow]
  \zxNone{}                \ar[ru,IO,s,bn] &          \zxNone{}
\end{ZX}
\end{codeexample}
\end{pgfmanualentry}

\begin{pgfmanualentry}
  \makeatletter
  \def\extrakeytext{style, }
  \extractkey/zx/wires definition/bold\@nil%
  \extractkey/zx/wires definition/B\@nil%
  \extractkey/zx/wires definition/non bold\@nil%
  \extractkey/zx/wires definition/NB\@nil%
  \extractkey/zx/wires definition/boldn\@nil%
  \extractkey/zx/wires definition/boldn-\@nil%
  \extractkey/zx/wires definition/boldn'\@nil%
  \extractkey/zx/wires definition/boldn.\@nil%
  \extractkey/zx/wires definition/Bn=message (default n)\@nil%
  \extractkey/zx/wires definition/Bn-=message (default n)\@nil%
  \extractkey/zx/wires definition/Bn'=message (default n)\@nil%
  \extractkey/zx/wires definition/Bn.=message (default n)\@nil%
  \extractkey/zx/wires definition/BnArgs=\{message\}\{style\} (default \{n\}\{\})\@nil%
  \extractkey/zx/wires definition/Bn-Args=\{message\}\{style\} (default \{n\}\{\})\@nil%
  \extractkey/zx/wires definition/Bn'Args=\{message\}\{style\} (default \{n\}\{\})\@nil%
  \extractkey/zx/wires definition/Bn.Args=\{message\}\{style\} (default \{n\}\{\})\@nil%
  \makeatother
  \pgfmanualbody
  Creates a bold (or non-bold) wire (|B| and |NB| being short aliases). The versions with a |n| at the end adds a $n$ on the right/left/above/below (for the respective symbols empty, |-|, |'|, |.|), that you can overwrite by providing an option:
{\catcode`\|=12 % Ensures | is not anymore \verb|...|
\begin{codeexample}[width=0pt]
\begin{ZX}
  \zxX[bold]{} \rar[Bn',o'] \rar[Bn.=m,o.] &[\zxwCol] \zxZ{} \rar &[\zxwCol] \zxN{}
\end{ZX}
\end{codeexample}
}
Finally, the last variations with args like |BnArgs| allows you to provide an additional label style, notably arguments like |pos=.7| to change the position of the line in the path (when the lines are drawn from the middle of the nodes, which is the case for many styles by default for efficiency reasons, the middle of the path may appear poorly centered: using |pos| is one method to center it back, see also \cref{subsec:wiresInsideOutside}).
{\catcode`\|=12 % Ensures | is not anymore \verb|...|
\begin{codeexample}[width=0pt]
\begin{ZX}
  \zxX[bold]{} \rar[<.,Bn.Args={n}{pos=.6},dr] &[\zxwCol] \\
                                               & \zxN{}
\end{ZX}
\end{codeexample}
}
Note that |bold| and its alias |B| can also be used as an argument to the |ZX| environment to turn all spiders and wires in bold:
\begin{codeexample}[width=0pt]
\begin{ZX}[bold]
  \zxX{} \rar[o'] \rar[o.] & \zxZ{} \rar &[\zxwCol] \zxN{}
\end{ZX}
\end{codeexample}
You might also want to combine it with the |non bold| option to temporarily set a wire non-bold:
\begin{codeexample}[width=0pt]
\begin{ZX}[bold]
  \zxX{} \rar[o'] \rar[o.] & \zxZ{} \rar[non bold] &[\zxwCol] \zxN{}
\end{ZX}
\end{codeexample}
\end{pgfmanualentry}

\begin{pgfmanualentry}
  \makeatletter
  \def\extrakeytext{style, }
  \extractkey/zx/styles/rounded style/wires bold\@nil%
  \extractkey/zx/styles/rounded style/Bw\@nil%
  \extractkey/zx/styles/rounded style/BBw\@nil%
  \makeatother
  \pgfmanualbody
  If you set |wires bold| (alias |Bw|) to a node, all wired connected to that node will be bold. |BBw| additionally turn the current node bold.
\begin{codeexample}[width=0pt]
\begin{ZX}
  \zxX{} \rar[o'] \rar[o.] & \zxZ[BBw]{} \rar &[\zxwCol] \zxN{}
\end{ZX}
\end{codeexample}
\end{pgfmanualentry}


\subsection{Custom nodes}\label{subsec:customNodes}

\textbf{NB}: a number of functionalities needed in this section were added on 24/02/2023 and 03/10/2023, so be sure to have the latest version.

\subsubsection{Creating your own node: method 1}

Technically, you can create any tikz style to create custom nodes like:
{\catcode`\|=12 % Ensures | is not anymore \verb|...|
\begin{codeexample}[width=0pt]
  \begin{ZX}
    \zxN{} \rar & |[draw,fill=blue!50,draw=blue,inner sep=3mm]| \text{my custom node}
  \end{ZX}
\end{codeexample}
}
possibly using |\tikzset| and/or |\NewExpandableDocumentCommand| to avoid repetitions:
{\catcode`\|=12 % Ensures | is not anymore \verb|...|
\begin{codeexample}[width=0pt]
  \tikzset{
    my custom node/.style={
      draw,fill=blue!50,draw=blue,inner sep=3mm
    },
  }
  \NewExpandableDocumentCommand{\myCustomNode}{m}{|[my custom node]| \text{#1}}
  \begin{ZX}
    \zxN{} \rar & \myCustomNode{Hey}
  \end{ZX}
\end{codeexample}
}

\begin{pgfmanualentry}
  \def\extrakeytext{style, }
  \extractcommand\zxCoordinateSubnode\opt{\oarg{style}}\marg{name of subnode}\@@
  \extractcommand\zxCoordinateMain\opt{\oarg{style}}\marg{}\@@
  \makeatletter% should not be letter for \@@... strange
  \extractkey/tikz/zx main node\@nil%
  \extractkey/tikz/zx subnode=\marg{name of subnode}\@nil%
  \extractkey/tikz/zx at origin\@nil%
  \extractkey/tikz/start subnode=\marg{name of subnode}\@nil%
  \extractkey/tikz/end subnode=\marg{name of subnode}\@nil%
  \makeatother
  \pgfmanualbody%

However, we recommend users to use the |\node[zx main node,zx at origin, ...]{...};| syntax rather than:
\begin{verbatim}
|[...]| ...
\end{verbatim}
for multiple reasons: first, it will be more robust (for instance you need the |\node| syntax if you plan to insert this in |zxExecuteAtEndPicture| or in a regular tikz picture which is not contained in a matrix), but you also have more freedom since you can create nodes having multiples subnodes, anchors etc.
You should note the |zx main node| that is needed to give a name to the current node so that |\arrow| can find it, otherwise you will get an error saying that the node does not exists when you try to link to it, and |zx at origin| that will just do |at={(0,0)}| (which is the default position anyway) but that might be useful later in order to easily place a node outside of a matrix. We also provide |\zxCoordinateMain| as the equivalent of |zx main node| for coordinates since they would not accept a name via a style.

Subnodes are a kind of generalization of anchors: you can define an existing node as a subnode with |zx subnode=your subnode| and link from/to this node using |start subnode=your subnode| and |end subnode=your subnode|:

\begin{codeexample}[width=0pt]
\NewExpandableDocumentCommand{\zxMyDoubleNode}{O{}m}{
  \node[fill=blue!20, zx main node, inner sep=3mm,alias=zxtmp,#1] {\text{#2}};
  \node[circle,fill=red!70, inner sep=.8mm,zx subnode=redNode] at ([shift={(0mm,1.5mm)}]zxtmp.west) {};
  \node[circle,fill=orange!70, inner sep=.8mm,zx subnode=orangeNode] at ([shift={(0mm,-1.5mm)}]zxtmp.west) {};
  \node[circle,fill=green!70, inner sep=.8mm,zx subnode=greenNode] at ([shift={(0mm,-1.5mm)}]zxtmp.east) {};
}
\begin{ZX}
  A \rar[end subnode=redNode] \rar[end subnode=orangeNode]
    & [5mm] \zxMyDoubleNode{Hey} \dar \rar[start subnode=greenNode,end subnode=orangeNode]
    & \zxMyDoubleNode[fill=pink]{Hey}\\
  B \ar[ru, end subnode=orangeNode]                        & 
\end{ZX}
\end{codeexample}
Node that you can also set some special subnodes called |fake center {north,south,east,west}| in order to help bezier-based wires to find where to start, and |true {north,south,east,west}| to say to |C| where to start (see the corresponding section for more details). Since we often want to specify coordinates here to be precise, you can use |\zxCoordinateSubnode| to place the coordinate at the right place.
\end{pgfmanualentry}


\subsubsection{Method 2: using pic}

We also provide a second approach to create custom nodes (the syntax is actually very close) based on |pic|. This has pro and cons compared to the above approach: it is a bit more complicated and involve more dark magic under the hood, but only creates a single node, provides reusable styles that might be easier to integrate in a tikz picture, and we also provide some automatic way to deal with rotations, scaling etc... Historically, this was created before we realized that cells could contain multiple nodes and that it was possible to use subnodes to anchors, but now that subnodes have been introduced both approaches are relatively close. Nonetheless, all tricks introduced here can be used with the first method, except that anchors should be replaced with subnodes.

\begin{pgfmanualentry}
  \def\extrakeytext{style, }
  \extractcommand\zxNewNodeFromPic\marg{name new node}\oarg{style before user}\oarg{style after user}\marg{code}\@@
  \makeatletter% should not be letter for \@@... strange
  \extractkey/tikz/zx create anchors=\marg{list, of, coordinates, to, turn, in, anchor}\@nil%
  \extractkey/tikz/invert top bottom\@nil%
  \extractkey/tikz/start subnode=\marg{name of subnode}\@nil%
  \extractkey/tikz/stop subnode=\marg{name of subnode}\@nil%
  \makeatother
  \pgfmanualbody
  |\zxNewNodeFromPic{Name}[style before][style after]{code}| is used to create a new command with name |\zxName|. |code| is the code to draw the node (that you would use in a |\pic| environment, and that will be centered on |(0,0)|):
{\catcode`\|=12 % Ensures | is not anymore \verb|...|
\begin{codeexample}[width=0pt]
  \zxNewNodeFromPic{MyNode}{
    \node[draw,fill=blue!50,draw=blue,inner sep=3mm, zx main node, alias=mynode] at (0,0) {};
    \node[draw,fill=red!50,draw=blue,inner sep=1mm] at (mynode.north east) {};
  }
  \begin{ZX}
    \zxN{} \rar & \zxMyNode{} \rar & \zxMyNode{}
  \end{ZX}
\end{codeexample}
}
Note how giving |zx main node| to a node makes it the target of arrows (note that you should make sure that your picture has at least one main node if you want features like |debug mode| to work). Without this, the lines would go to the coordinate |(0,0)|, and go through all the nodes:
{\catcode`\|=12 % Ensures | is not anymore \verb|...|
\begin{codeexample}[width=0pt]
  \zxNewNodeFromPic{MyNode}{
    \node[draw,fill=blue!50,draw=blue,inner sep=3mm, alias=mynode] at (0,0) {};
    \node[draw,fill=red!50,draw=blue,inner sep=1mm] at (mynode.north east) {};
  }
  \begin{ZX}
    \zxN{} \rar & \zxMyNode{}
  \end{ZX}
\end{codeexample}
}
Note that sometimes, one might want to draw lines to a fixed point, while leaving the line below the object (for instance if you use a |rounded corners| option and try to enter by the corner, tikz will actually stop before which is not beautiful). A simple solution is to use |wc| (short for |wire centered|) on the arrow, and it will automatically move the path on a layer behind (see also |wcs| and |wce| to configure only the starting or ending points, and some other nodes also use this, notably most styles based on |bezier|, like |s|):
{\catcode`\|=12 % Ensures | is not anymore \verb|...|
\begin{codeexample}[width=0pt]
\zxNewNodeFromPic{MyDivider}{
  \node[regular polygon, regular polygon sides=3, shape border rotate=90,
        draw=black,fill=gray!50, inner sep=1.6pt, rounded corners=0.8mm,zx main node] {};
}
Compare %
\begin{ZX}
  \zxZ{} \rar[very thick]  &\zxMyDivider{} \rar[very thick] & \zxN{}
\end{ZX} %
and %
\begin{ZX}
  \zxZ{} \rar[very thick,wce]  &\zxMyDivider{} \rar[very thick] & \zxN{} 
\end{ZX}
\end{codeexample}
}
Note that I'm working on a better solutions to move nodes on different layers, or automatically see which anchor to choose depending on the custom node… but it's not that \mylink{https://tex.stackexchange.com/questions/618823/node-on-layer-style-in-tikz-matrix-tikzcd}{easy}.

We can similarly put the |zx main node| on the other node to point to the other node by default:
{\catcode`\|=12 % Ensures | is not anymore \verb|...|
\begin{codeexample}[width=0pt]
  \zxNewNodeFromPic{MyNode}{
    \node[draw,fill=blue!50,draw=blue,inner sep=3mm, alias=mynode] at (0,0) {};
    \node[draw,fill=red!50,draw=blue,inner sep=1mm, zx main node] at (mynode.north east) {};
  }
  \begin{ZX}
    A \rar[end anchor=center,on layer=main] & \zxMyNode{} \rar & B & \zxMyNode{} & \zxMyNode{}
  \end{ZX}
\end{codeexample}
}

\paragraph{Add margin around nodes.} You might want to add empty paths to increase the ``margin'' around your picture, or |overlay| some nodes if you don't want them to be counted when computing the bounding box. For simplicity, we provide a command |\zxExtendBoundingBox| that extends the current bounding box. This command takes as argument a list of arguments like |left|, |right|, |top|, |bottom|, |horizontal|, |vertical|, |extend|, where each argument takes a distance and extends to the corresponding direction (|extend| extends in all directions). For instance, below we increase the box by 1cm horizontally and by 3mm on each side on the y axis:
{\catcode`\|=12 % Ensures | is not anymore \verb|...|
\begin{codeexample}[width=0pt]
  \zxNewNodeFromPic{MyNode}{
    \node[draw,fill=blue!50,draw=blue,inner sep=3mm, zx main node] at (0,0) {};
    \zxExtendBoundingBox{horizontal=1cm, vertical=3mm}
  }
  \begin{ZX}
    A \rar & \zxMyNode{} \rar & B\\
  \end{ZX}
\end{codeexample}
}

\paragraph{Give text as argument.} It is also possible to pass text as an argument by simply adding |\tikzpictext| where you want the text to appear, and calling then |\zxMyNode{your text}|:
{\catcode`\|=12 % Ensures | is not anymore \verb|...|
\begin{codeexample}[width=0pt]
  \zxNewNodeFromPic{MyNode}{
    \node[draw,fill=blue!50,draw=blue,inner sep=3mm, zx main node, alias=mynode] at (0,0) {\tikzpictext};
    \node[draw,fill=red!50,draw=blue,inner sep=1mm] at (mynode.north east) {};
  }
  \begin{ZX}
    \zxMyNode{Hello} & \zxMyNode{do you see} & \zxMyNode{the text} & ?
  \end{ZX}
\end{codeexample}
}

\paragraph{Pass arbitrary arguments.} You can actually pass virtually any argument(s) by using the optional argument of the created |\zxMyNode| (that is just an additional argument to the pic options, inserted before \emph{style after user}, but after \emph{style before user} that we can use to create additional arguments with default values using the tikz/pgf power):
{\catcode`\|=12 % Ensures | is not anymore \verb|...|
\begin{codeexample}[width=0pt]
% Requires \usetikzlibrary {shapes.geometric} for the star shape
\zxNewNodeFromPic{MyStar}[
  nb spikes/.store in=\myNbSides, % When users type nb spikes=42, this puts 42 into \myNbSides
  nb spikes=5, % <- Default value
]{
  \node[star, star points=\myNbSides, minimum size=6mm, draw, fill=red] at (0,0) {};
}
\begin{ZX}
  \text{Default:} & \zxMyStar{} & \text{More !} & \zxMyStar[nb spikes=8]{} & \zxMyStar[nb spikes=12]{}
\end{ZX}
\end{codeexample}
}

\paragraph{Overriding existing parameters.}

You might want to override a custom node, for instance because this custom node was provided by an external library (e.g.\ the ground and scalable ZX symbols are made using custom-nodes, and you might want to customize them). We provide for that a series of styles: if |XXXX| is the name on the node (e.g.\ |Ground|), the |/zx/picCustomStyleBeforeUserXXXX| style is sent to the picture style before loading the options of the user, |/zx/picCustomStyleAfterUserXXXX| is loaded after the input of the user, |/zx/picCustomStyleLastPicXXXX| is loaded as the last argument to the picture (after the default style). You can also set the command |\zxCustomPicAdditionalPic| to any code to draw at the end of the picture:
{\catcode`\|=12 % Ensures | is not anymore \verb|...|
\begin{codeexample}[width=0pt]
\tikzset{
  /zx/picCustomStyleBeforeUserMatrix/.style={
    scale=2,
    % \zxCustomPicAdditionalPic can be any tikz code to run after the creation of the pic:
    /utils/exec={\def\zxCustomPicAdditionalPic{%
        % the main node has empty name, so .center is the center of the main node
        \node[draw,circle,inner sep=2pt,fill=pink] at (.center) {};%
      }%
    },
  },
}
\begin{ZX}
  \zxZ{} \rar & \zxMatrix{A} \rar & \zxMatrix*{B} \rar & \zxN{}
\end{ZX}
\end{codeexample}
}

When designing your own custom nodes, you can also put:\\
|NameOfYourStyle/.append style={}, NameOfYourStyle,|\\
where you want to allow users to load |NameOfYourStyle| (|NameOfYourStyle/.append style={}| is used to create the style if it does not exist).

If you want to change a create a new node style without overriding a style, you can of course create your own command that sets the parameters for you:
{\catcode`\|=12 % Ensures | is not anymore \verb|...|
\begin{codeexample}[width=0pt]
\tikzset{
  /zx/picCustomStyleBeforeUserMatrix/.style={
    scale=2,
    % \zxCustomPicAdditionalPic can be any tikz code to run after the creation of the pic:
    /utils/exec={\def\zxCustomPicAdditionalPic{%
        % the main node has empty name, so .center is the center of the main node
        \node[draw,circle,inner sep=2pt,fill=pink] at (.center) {};%
      }%
    },
  },
}
\begin{ZX}
  \zxZ{} \rar & \zxMatrix{A} \rar & \zxMatrix*{B} \rar & \zxN{}
\end{ZX}
\end{codeexample}
}

\paragraph{Local style.}

Sometimes, you might want to define styles that are available only locally: for instance, you might prefer to type |main={fill=green}| instead of:\\
|/zx/picCustomStyleBoxMainNode/.append style={fill=green}|\\
Nothing prevents you from doing so directly in the default style. Just, make sure to use, e.g.\ |####1|, if you want to call an argument (internally we use nested styles and functions):

{\catcode`\|=12 % Ensures | is not anymore \verb|...|
\begin{codeexample}[width=0pt]
\zxNewNodeFromPic{MyBox}[
  main/.style={
    /zx/picCustomStyleMyBoxMainNode/.append style={####1},
  },
]{%
  \node[draw, inner sep=1.3mm, rectangle, zx main node, execute at begin node=$, execute at end node=$,
    /zx/picCustomStyleMyBoxMainNode/.append style={}, % Make sure it exists to avoid errors
    /zx/picCustomStyleMyBoxMainNode,
  ]{\tikzpictext};%
}

\begin{ZX}
  \zxMyBox{G} \rar[B]                    & [\zxwCol] \zxN{}\\
  \zxMyBox[main={fill=green}]{G} \rar[B] & [\zxwCol] \zxN{}
\end{ZX}
\end{codeexample}
}

\paragraph{Rotations.} Note that often, we want to rotate the nodes. The automatically generated macro to add new nodes comes with multiple flavors by adding the usual symbols |-|,|'|,|.|: by default, |\myNode-| will ``rotate'' by 180 degrees the pic, |\myNode'| will rotate it by 270 degrees to fake a node put ``above'', and |\myNode.| will rotate it by 90 degrees to fake a node put below. Importantly, by default tikz rotates/scales the coordinates, but \textbf{not the nodes or text}, so you might want to specify \textbf{transform shape} on each node you want to rotate and scale according to the parent transform, or using the |every node/.append style={transform shape}| (\textbf{WARNING}: make sure to use |append| or otherwise |zx main node| you not work and you will not be able to give a name to a node) option to apply it on all nodes:
{\catcode`\|=12 % Ensures | is not anymore \verb|...|
\begin{codeexample}[width=0pt]
  \zxNewNodeFromPic{MyTriangle}[
    % To also rotate/scale the node, otherwise only it's coordinate is rotated
    every node/.append style={transform shape},
    % Just to show how to quickly scale a node by default, to quickly update the size of a whole picture:
    scale=1.3
  ]{
      \node[regular polygon, regular polygon sides=3, shape border rotate=90, draw=black,fill=blue!50, inner sep=1mm,rounded corners, zx main node] {};
  }
  \begin{ZX}
    \zxMyTriangle{} \rar & \zxMyTriangle-{} & \zxMyTriangle'{} \dar \\
                         &                  & \zxMyTriangle.{}
  \end{ZX}
\end{codeexample}
}
Note however that you can customize how rotations is applied. By default, the |'-.| variants updates |\zxCurrentRotationMode| to the rotation angle (from 0 to 90,180,270), and do |rotate=\zxCurrentRotationMode|. You can however easily change that behavior, by first undoing this rotation (in the \emph{style before user}) with |rotate=-\zxCurrentRotationMode| and do any action you like depending on the value of |\zxCurrentRotationMode|. Here is a nice use-case: if you rotate a node with |transform shape|, it will also rotate the text inside:
{\catcode`\|=12 % Ensures | is not anymore \verb|...|
\begin{codeexample}[width=0pt]
  \zxNewNodeFromPic{MyTriangle}[
    every node/.append style={transform shape},
  ]{
      \node[regular polygon, regular polygon sides=3, shape border rotate=90, draw=black,fill=blue!50, font=\footnotesize,inner sep=1pt,rounded corners, zx main node] {\tikzpictext};
  }
  \begin{ZX}
    \zxMyTriangle{A} \rar   & \zxMyTriangle-{A}   & \zxMyTriangle'{A} \dar   \\
                            &                     & \zxMyTriangle.{A}        \\
  \end{ZX}
\end{codeexample}
}
To avoid that issue, we will undo the default rotation, and apply on the node of interest a rotation with |shape border rotate| (that rotates the border but not the text inside):
{\catcode`\|=12 % Ensures | is not anymore \verb|...|
\begin{codeexample}[width=0pt]
  \zxNewNodeFromPic{MyTriangle}[
    % We undo the default rotation:
    rotate=-\zxCurrentRotationMode,
  ]{
    \node[
      regular polygon, regular polygon sides=3, draw=black,fill=blue!50, font=\footnotesize,
      inner sep=1pt,rounded corners, zx main node,
      shape border rotate=90+\zxCurrentRotationMode, % Rotates the shape but not the text
    ] {\tikzpictext};
  }
  \begin{ZX}
    \zxMyTriangle{A} \rar   & \zxMyTriangle-{A}   & \zxMyTriangle'{A} \dar   \\
                            &                     & \zxMyTriangle.{A}        \\
  \end{ZX}
\end{codeexample}
}
Note that one might want to exchange |\zxMyNode|/|\zxMyNode-| or |\zxMyNode'|/|\zxMyNode.| (for instance, it might be more natural to denote |'| in place of |.| and |.| in place |'|, since these symbols visually represent the top/bottom place of the node). In that case, you just need to apply the style |invert top bottom| or |invert right left| in your \emph{style before user} and it will invert them automatically.

\paragraph{Add anchors to node.} We can automatically (and easily) add multiple anchors to our nodes (the |fake center east/…| anchors are used for instance by shapes like |\ar[<']| to see where the node should start from, while the |true north/…| anchors are used to notify where is the true north after the rotation (after rotating a node, the east might actually be on the north etc), which is for instance used by shapes like |C'|): just add coordinates with the name of the desired anchor in your graph (say |anchorA| and |anchorB|), and in \emph{style \textbf{after} user} add this list of anchor like: |zx create anchors={anchorA,anchorB}| (actually this list is expanded using the |\foreach| syntax so you can use more advanced syntax like |anchor1,anchor...,anchor10| to avoid repeating the 10 names of the anchor). For instance, we can do this way:
{\catcode`\|=12 % Ensures | is not anymore \verb|...|
\begin{codeexample}[width=0pt]
  \zxNewNodeFromPic{MyStar}[][
    % Note that this is the SECOND optional argument!
    zx create anchors={anchorA,anchorB},
  ]{
      \node[star, minimum size=6mm, draw, alias=mystar, fill=red, zx main node] at (0,0) {};
      \coordinate (anchorA) at (mystar.outer point 1);
      \coordinate (anchorB) at (mystar.outer point 2);
  }
  \begin{ZX}
    A \rar \rar[->,end anchor=anchorA,bend left] \rar[->,end anchor=anchorB,bend left]  &[5mm] \zxMyStar{}
  \end{ZX}
\end{codeexample}
}
The ZX library typically uses some special anchors like |fake center east/…| and |true east/…| to determine where some wires should start (not all kinds of wires follow this convention, for instance |<'| uses |fake center| since the wire is supposed to leave close to the center, while |C| follows |true west| since the wire is supposed to leave from the west). Because the north anchor is not anymore in the north after applying a rotation, we provide also |\zxVirtualCenterWest| (same for |East|, |North|, |South|) that will ``counter balance'' the rotation, to ensure the real north anchor is always in the north, by renaming the anchors appropriately. This way, by using these ``virtual anchors'', you only need to place your anchor when the shape is not rotated, and it should automatically rotate the anchors appropriately when needed (see remarks regarding |every node/.append style={transform shape}|):
{\catcode`\|=12 % Ensures | is not anymore \verb|...|
\begin{codeexample}[width=0pt]
% Define a reusable node
  \zxNewNodeFromPic{MyDivider}[][zx create anchors={\zxVirtualCenterWest, \zxVirtualCenterEast},
  every node/.append style={transform shape}
  ]{
  \node[regular polygon, regular polygon sides=3,shape border rotate=90,%shape border rotate=90,
        draw=black,fill=gray!50, inner sep=1.6pt, rounded corners=0.8mm,zx main node] {};
  \coordinate(\zxVirtualCenterEast) at (.2mm,0); % Used to start lines on the side of the shape
  \coordinate(\zxVirtualCenterWest) at (-1mm,0);
}
% Use the node horizontally
\begin{ZX}
  \zxZ[B]{} \rar[Bn'=n+m, wc] & \zxMyDivider{} 
                                  \rar[o',Bn'Args={n}{}]
                                  \rar[o.,Bn.Args={m}{}] &[\zxWCol] \zxMyDivider-{} \rar[B,wc] & \zxZ[B]{}
\end{ZX}
% Use the node vertically                         
\begin{ZX}
  \zxZ[B]{} \dar[Bn=n+m, wc] \\
  \zxMyDivider'{} \dar[-o,BnArgs={n}{}] \dar[o-,Bn-Args={m}{}] \\[\zxWRow]
  \zxMyDivider.{} \dar[B,wc]\\
  \zxZ[B]{}
\end{ZX}
\end{codeexample}
}

You can even dynamically add anchors depending on the input of the user. For instance, if the user can choose the number of spikes of the star, you might want to create as many anchors as there are spikes:
{\catcode`\|=12 % Ensures | is not anymore \verb|...|
\begin{codeexample}[width=0pt]
\zxNewNodeFromPic{MyStar}[
  nb spikes/.store in=\myNbSides,
  nb spikes=5,
  every node/.append style={transform shape},
  ][
    % zx create anchors is parsed ultimately by \foreach so we can use lists like
    % this to create anchors spike-1, spike-2...
    zx create anchors/.expanded={spike-1,spike-...,spike-\myNbSides},
  ]{%
    \node[star, fill=red, star points=\myNbSides, minimum size=1cm, draw, alias=mystar]
      at (0,0) {\tikzpictext};
    % We need to place coordinates where we want to final anchors to be.
    \foreach \i in {1,...,\myNbSides}{
      \coordinate (spike-\i) at (mystar.outer point \i);
    }%
}
\begin{ZX}
  B \foreach \i in {1,...,8}{\expanded{\noexpand\rar[->,end anchor=spike-\i,bend left]}}  &[5cm] \zxMyStar[nb spikes=8]{?!?}
\end{ZX}
\end{codeexample}
}

Note that this library uses some anchors called |fake center {east,west,north,south}|, to indicate for some curve style where the line should start and stop (|\ar| alone does not use any anchor, and not all curves use them: |S| for instance does not use it, while |s| does: in any case, you can force it for any curve with |force left to right| and alike, see the corresponding documentation Note also that in this mode the curve is drawn by default below the shapes, but this can be changed, see the corresponding section for details). 
{\catcode`\|=12 % Ensures | is not anymore \verb|...|
\begin{codeexample}[width=0pt]
\zxNewNodeFromPic{MyNode}[][zx create anchors/.expanded={fake center west}]{
  \node[draw,fill=blue!50,draw=blue,inner sep=3mm, zx main node, alias=mynode] at (0,0) {};
  \node[draw,fill=red!50,draw=blue,inner sep=1mm] at (mynode.north east) {};
  \coordinate(fake center west) at (mynode.north east);
}
\begin{ZX}
  \zxZ{} \ar[rd,s] & \\
  A \rar           & \zxMyNode{}  
\end{ZX}
\end{codeexample}
}

\paragraph{Link to a sub-node.} Sometimes, we might prefer to draw a link to a node instead of an anchor (an anchor can only be a single coordinate). To that end, just name your nodes as usual, and use |start subnode| or |end subnode| to do the link
{\catcode`\|=12 % Ensures | is not anymore \verb|...|
\begin{codeexample}[width=0pt]
  \zxNewNodeFromPic{MyDoubleNode}{
      \node[fill=blue!20, zx main node, inner sep=3mm] at (0,0) {};
      \node[circle,fill=red!70, inner sep=.8mm,name=redNode] at (0,1.5mm) {};
      \node[circle,fill=orange!70, inner sep=.8mm, name=orangeNode] at (0,-1.5mm) {};
  }
  \begin{ZX}
    A \rar[end subnode=redNode] \rar[end subnode=orangeNode] &[5mm] \zxMyDoubleNode{}\\
    B \ar[ru, end subnode=orangeNode]
  \end{ZX}
\end{codeexample}
}

Note that you can also combine it with |to| and |alias|:
{\catcode`\|=12 % Ensures | is not anymore \verb|...|
\zxNewNodeFromPic{MyDoubleNode}{
  \node[fill=blue!20, zx main node, inner sep=3mm] at (0,0) {};
  \node[circle,fill=red!70, inner sep=.8mm,name=redNode] at (0,1.5mm) {};
  \node[circle,fill=orange!70, inner sep=.8mm, name=orangeNode] at (0,-1.5mm) {};
}
\begin{ZX}
  \zxZ{} \ar[to=buttons, end subnode=orangeNode]  \\
  \zxX{} \rar & \zxMyDoubleNode[a=buttons]{} \rar & 
\end{ZX}
}

\end{pgfmanualentry}




\subsubsection{Create your own multi-column/row gate}

We provide since 2023/09/23 a number of functions in order to deal with gates spawning multiple rows or columns, including to create your own multi-columns/rows gates. We present first the individual functions, and show after how to combine them to create more advanced styles. Note that the following define commands, but you can easily insert them in a style using:
\begin{verbatim}
/utils/exec={\yourCommands}
\end{verbatim}
or by creating a new style with |my style/.code={\yourCommand}|.

\begin{pgfmanualentry}
  \extractcommand\zxGetNameAbsoluteNode\marg{row}\marg{column}\@@
  \pgfmanualbody%
  Function to get the name of a cell using its absolute coordinate in the matrix (start at 1):
\begin{codeexample}[]
\begin{ZX}[
  execute at end picture={
    \node[draw, rounded corners, fill=orange,
    node on layer=background,
    fit=(\zxGetNameAbsoluteNode{1}{1})(\zxGetNameAbsoluteNode{1}{2})
    ]{};
  }]
  A & B
\end{ZX}
\end{codeexample}
\end{pgfmanualentry}

\begin{pgfmanualentry}
  \extractcommand\zxExecuteAtEndPicture\marg{code}\@@
  \extractcommand\zxOriginalRow\@@
  \extractcommand\zxOriginalCol\@@
  \extractcommand\zxGetNameRelativeNode\marg{relative row}\marg{relative column}\@@
  \extractcommand\zxGetNameRelativeNodeStartOne\marg{relative row}\marg{relative column}\@@
  \pgfmanualbody%
  |execute at end picture| is first annoying to use, but it also runs after the definition of the wires, meaning that it is not possible to point to nodes defined in that portion of the code. To solve these issues, we define |\zxExecuteAtEndPicture{your code}| that you can insert inside a node. Note that in |your code| you can use |\zxOriginalRow| and |\zxOriginalCol| that will contain the position of the column and row where you inserted that command, and |\zxGetNameRelativeNode| will allow you to get the name of the neighbour nodes by specifying the difference of columns and the difference of lines. Note that these variables and commands are usable in |\zxExecuteAtCellRelative| and |\zxExecuteAtCellAbsolute| as well.
\begin{codeexample}[]
\NewExpandableDocumentCommand{\myFitWithBelowNeighbour}{}{
  \zxExecuteAtEndPicture{%
    \node[draw, rounded corners, fill=orange,
      node on layer=background,
      fit=(\zxGetNameRelativeNode{0}{0})(\zxGetNameRelativeNode{1}{0})
    ]{};
  }%
}
\begin{ZX}
  A & B                          & C & D \\
  A & B \myFitWithBelowNeighbour & C & D \\
  A & B                          & C & D \\
\end{ZX}
\end{codeexample}
The |zxGetNameRelativeNodeStartOne| variant index elements from $1$ instead of $0$.
\end{pgfmanualentry}

\begin{pgfmanualentry}
  \def\extrakeytext{style, }
  \extractcommand\zxExecuteAtCellAbsolute\marg{row}\marg{column}\marg{code}\@@
  \extractcommand\zxExecuteAtCellRelative\marg{relative row}\marg{relative column}\marg{code}\@@
  \extractcommand\zxExecuteAtRegionRelative\marg{relative row}\marg{relative column}\marg{code}\@@
  \pgfmanualbody%
  Often, just adding some nodes at the end of the picture is not enough: you might want to add other nodes automatically in the matrix. For instance, if you want to implement yourself a gate spawning multiple rows, a simple way to achieve that would be to add invisible boxes inside the matrix and use them to fit the final component. You can place nodes where you want using something like this (note that you should use |zx main node| that is basically a shortcut for:
\begin{verbatim}
\tikzset{name=\zxCurrentDiagram-\the\pgfmatrixcurrentrow-\the\pgfmatrixcurrentcolumn}
\end{verbatim}
otherwise |\rar| will not be able to know which node to join: note that it is automatically added in nodes like |\zxX{}|):
\begin{codeexample}[]
\NewExpandableDocumentCommand{\mySimpleMultigate}{m}{
  \zxBox{#1}
  \zxExecuteAtCellRelative{1}{-1}{\node[zx main node, green]{\text{I am relative}};}
  \zxExecuteAtCellRelative{0}{1}{\node[zx main node, green]{\text{I am also relative}};}
  \zxExecuteAtCellAbsolute{2}{4}{\node[zx main node, red]{\text{I am absolute}};}
}
\begin{ZX}
A & B                     & C  \\
  & \mySimpleMultigate{X} &  & \\
  &                       &    \\
\end{ZX}
\end{codeexample}
(note that the relative version adds it to cells relative to the current cell while the absolute version executes it at the absolute cell coordinate)
\textbf{Important}: for all these manipulation to work, be sure to only specify coordinates after the main node, either later on the same line or on next rows since previous cells have already been parsed.

You can also do it for a whole region of size $n \times m$ using |\zxExecuteAtRegionRelative{n}{m}{code}| like this (just make sure that the cells exist):
\begin{codeexample}[]
\NewExpandableDocumentCommand{\myRegion}{}{
  \zxExecuteAtRegionRelative{2}{3}{%
    \zxBox{\text{\tiny Original row: \zxOriginalRow{}, column:\zxOriginalCol{}
        % We compute the relative position to print it:
        (rel: \the\numexpr\the\pgfmatrixcurrentrow  -\zxOriginalRow\relax
        x\the\numexpr\the\pgfmatrixcurrentcolumn-\zxOriginalCol\relax).}}}
}
\begin{ZX}
  A & B & C         & D & E & F & G \\
  &   & \myRegion &   &   &   &   \\
  &   &           &   &   &   &   \\
  &   &           &   &   &   & 
\end{ZX}
\end{codeexample}
(note that if you use |\zxExecuteAtRegionRelative| and want to define one alias for the top-left node, you should use |a if origin=alias for the node| instead of |a=alias name for the node| since it would give the alias to the last node instead of the first node). Note that if you execute it multiple times on the same cell, both codes will be executed.
\end{pgfmanualentry}

\begin{pgfmanualentry}
  \def\extrakeytext{style, }
  \extractcommand\zxSetVariable\marg{name variable}\marg{content variable}\@@
  \extractcommand\zxSetVariableExpandOnce\marg{name variable}\marg{content variable}\@@
  \extractcommand\zxSetVariableExpand\marg{name variable}\marg{content variable}\@@
  \extractcommand\zxGetVariable\marg{name variable}\@@
  \makeatletter% should not be letter for \@@... strange
  \extractkey/tikz/zx style from variable=\marg{name variable}\@nil%
  \makeatother
  \pgfmanualbody%
  You might want at some point to pass data to the node you placed elsewhere, for instance the style it should take etc. For simple setups, you can directly pass the argument like:
\begin{codeexample}[]
  \NewExpandableDocumentCommand{\mySimpleMultigate}{mmmm}{
    \zxBox{#1}
    \zxExecuteAtCellRelative{1}{-1}{\node[zx main node, #2]{\text{I am relative}};}
    \zxExecuteAtCellRelative{0}{1}{\zxBox[zx main node]{\text{I am also relative}}}
    \zxExecuteAtCellAbsolute{2}{4}{\node[zx main node, #4]{\text{I am absolute}};}
  }
  \begin{ZX}
 &                    &    \\
 & \mySimpleMultigate{X}{red}{pink}{orange} &  & \\
 &                    &    \\
  \end{ZX}
\end{codeexample}
but for more complicated setups, you might want to use some variables. This can be done using the above commands (set it in the main node, and get it in other nodes) (or you can also directly give it the argument): this should just create a new macro and evaluate it.
\begin{codeexample}[]
\NewExpandableDocumentCommand{\mySimpleMultigate}{mmm}{
  \zxX{#1}
  \zxSetVariable{my variable}{Hey #2}
  \zxSetVariable{my style}{#3}
  \zxExecuteAtCellRelative{1}{-1}{\node[zx style from variable={my style}]{\text{\zxGetVariable{my variable}}};}
}
\begin{ZX}
A & B                                         & C  \\
  & \mySimpleMultigate{\alpha}{Alice}{purple,opacity={.3}} &  & \\
  &                                           &    \\
\end{ZX}
\end{codeexample}
The difference between |\zxSetVariable|, |\zxSetVariableExpandOnce| and |\zxSetVariableExpand| is that they respectively don't expand their input like |\gdef|, expand it once, or expand it completely like |\gxdef|. This can be useful in more complex setups, for instance if you store the style/variable in a macro first using pgfkeys:
\begin{codeexample}[width=0pt]
\NewExpandableDocumentCommand{\MyGateMulti}{O{}mmm}{
  % The path; here is useful to help tikzcd to see that it is a node as it tries to search for path and \pgfkeys does not look like a path
  % If you forget it, you will get something like \node is not defined
  \path;\pgfkeys{
    /zx/gateMulti/.cd,
    content inner nodes/.store in=\myContent,
    content inner nodes=#4,
    a/.store in=\zxGateMultiAlias,
    a=,
    style inner nodes/.store in=\zxGateMultiStyle,
    style inner nodes={},
    #1,
  }%
  % Store the content for letter use
  \zxSetVariableExpandOnce{content inner nodes}{\myContent}
  \zxSetVariableExpandOnce{style inner nodes}{\zxGateMultiStyle}
  \zxExecuteAtRegionRelativeAndOrigin{#2}{#3}{%
  \zxBox[zx main node,
    % a if origin=\zxGateMultiAlias,
    draw,
    zx style from variable={style inner nodes},
    %/zx/gateMulti/style inner nodes aux
  ]{\zxGetVariable{content inner nodes}};
  }%
}

\begin{ZX}
 &  &                       &  &  &  &  & \\
 &  & \MyGateMulti[style inner nodes={red,test/.style={fill=#1,opacity=.3},test=red}]{2}{3}{H} &  &  &  &  & \\
 &  &                       &  &  &  &  & \\
 &  &                       &  &  &  &  & \\
 &  &                       &  &  &  &  & \\
\end{ZX}
\end{codeexample}
\end{pgfmanualentry}

With all of this, we can now create a simple multi-columns/rows gate mechanism (but you certainly want to use the one provided by this library if you actually care about multi-columns/rows gates:


\begin{codeexample}[width=0pt]
  % \mySimpleMultigate{rows}{cols}{content}
  \NewExpandableDocumentCommand{\mySimpleMultigate}{mmm}{
    \node[zx main node, inner sep=1mm]{#3};
    \zxExecuteAtCellRelative{#1}{#2}{%
      \node[zx main node, inner sep=1mm]{#3};
    }
    \zxExecuteAtEndPicture{
      \node[node on layer=foreground,
        fill=white, inner sep=0pt, draw,
        fit=(\zxGetNameRelativeNode{0}{0})(\zxGetNameRelativeNode{#1}{#2}),
        label={[node on layer=foreground]center:{#3}}]{};
    }
  }
  \begin{ZX}
A                             & B                           & C & D & E & F                          \\
\rar                          & \mySimpleMultigate{2}{3}{X} &   &   &   & \lar                       \\
\rar                          &                             &   &   &   & \lar                       \\
\zxN{} \dar[C] \rar           &                             &   &   &   & \zxN[a=bottomright]{} \lar \\
\zxN{} \ar[to=bottomright,C-] &                                                                      
\end{ZX}
\end{codeexample}

Note that you can also define subnodes in the final node and point to them. You can either use its alias, or point to any node added via region relative or cell relative, it will automatically find the parent node:

\begin{codeexample}[width=0pt]
  % \mySimpleMultigate{rows}{cols}{content}
  \NewExpandableDocumentCommand{\myFancyGate}{O{}mmm}{
    % a=#1 make sure to add the alias on the first element
    \node[zx main node, inner sep=1mm, a=#1]{#4};
    \zxExecuteAtRegionRelative{#2}{#3}{%
      \node[zx main node, inner sep=1mm]{#4};
    }%
    \zxExecuteAtEndPicture{
      \node[node on layer=foreground,
        alias=tmp,
        opacity=.5,
        fill=white, inner sep=0pt, draw,
        fit=(\zxGetNameRelativeNode{0}{0})(\zxGetNameRelativeNode{\the\numexpr#2-1\relax}{\the\numexpr#3-1\relax}),
        label={[node on layer=foreground]center:{#4}}]
        {};
      \node[node on layer=foreground, fill=red, inner sep=.9mm, circle, zx subnode=redCircle] at (tmp.south east) {};
    }
  }
  \begin{ZX}
A                                                     & B                                  & C & D & E    & F    \\
\rar[end subnode=redCircle, blue, bend right]         & \myFancyGate[aliasMyGate]{3}{4}{X} &   &   & \rar &      \\
\rar[purple]                                          &                                    &   &   &      & \lar \\
\rar[end subnode=redCircle, pink, bend right]         &                                    &   &   &      & \lar \\
\ar[to=aliasMyGate,red]                               &                                                          \\
\ar[to=aliasMyGate,end subnode=redCircle,green,bend right] & 
\end{ZX}
\end{codeexample}

You can also force all nodes pointing to a region-relative or cell-relative to point to a specific anchor:

\begin{pgfmanualentry}
  \def\extrakeytext{style, }
  \makeatletter% should not be letter for \@@... strange
  \extractkey/every node/pre arrow style if start node=\marg{style, to, apply}\@nil%
  \extractkey/every node/pre arrow style if end node=\marg{style, to, apply}\@nil%
  \extractkey/every node/post arrow style if start node=\marg{style, to, apply}\@nil%
  \extractkey/every node/post arrow style if end node=\marg{style, to, apply}\@nil%
  \makeatother
  \pgfmanualbody%
  This will apply the corresponding style to any wire leaving from the current cell or arriving to the current cell depending on the variation (node that you can use these functions in any node, there is no special role played by |zxExecuteAtRegionRelativeAndOrigin| here), |pre| variants being run before the user input (\textbf{WARNING}: at the step, the target of the node is not known!) while |post| variants are run after the user input:

\begin{codeexample}[width=0pt]
% \myFancyGate[alias]{rows}{cols}{content}
\NewExpandableDocumentCommand{\myFancyGate}{O{}mmm}{
  \zxExecuteAtRegionRelativeAndOrigin{#2}{#3}{%
    \node[zx main node, inner sep=1mm, a if origin=#1,
      %% These two lines says to connect any line coming/leaving from here to the redCircle subnode
      post arrow style if start node={start subnode=redCircle},
      post arrow style if end node={end subnode=redCircle},
    ]{#4};
  }%
  \zxExecuteAtEndPicture{
    \node[node on layer=foreground,
      alias=tmp,
      opacity=.5,
      fill=white, inner sep=0pt, draw,
      % The expression "\the\numexpr#3-1\relax" removes 1 to the current column or it will draw too many
      % columns (size n x m means that we stop at element (n-1) x (m-1) since we start from zero
      fit=(\zxGetNameRelativeNode{0}{0})(\zxGetNameRelativeNode{\the\numexpr#2-1\relax}{\the\numexpr#3-1\relax}),
      label={[node on layer=foreground]center:{#4}}]
      {};
    \node[node on layer=foreground, fill=red, inner sep=.9mm, circle, zx subnode=redCircle] at (tmp.south east) {};
  }
}
\begin{ZX}
A                                             & B                                  & C & D & E    & F    \\
\rar                                          & \myFancyGate[aliasMyGate]{3}{4}{X} &   &   & \rar &      \\
\rar[purple]                                  &                                    &   &   &      & \lar \\
\rar[end subnode=redCircle, pink, bend right] &                                    &   &   &      & \lar \\
\ar[to=aliasMyGate,red]                       &                                                          \\
\ar[to=aliasMyGate,end subnode=redCircle,green,bend right] 
\end{ZX}
\end{codeexample}
\end{pgfmanualentry}


\subsection{Caching pictures via an externalization library}\label{sec:externalization}

The pictures built with this package can easily take maybe 0.5 seconds per picture to be built, which can easily add up to a long compilation time. Caching externalization can save you a lot of time: I went from a tiny draft taking 30 seconds to be built to a built time of 2.5 seconds.

\subsubsection{robust-externalize: recommended}

While \tikzname{} provides an external library, it has many drawbacks that make it unusable in practice. To solve that issue, I created my own library called \mylink{https://github.com/leo-colisson/robust-externalize}{\texttt{robust-externalize}}. It's still very young, but has been working really reliably in my tests (note that a major update occurred in september 2023, so we updated the instruction accordingly).

To use it, first install |robust-externalize| by copy/pasting robust-externalize.sty in your project (unless your \LaTeX{} distribution already has it), make sure you have version 1.1, and load it using:
\begin{codeexample}[code only]
\usepackage{robust-externalize}
\robExtConfigure{
  % We create a new preset for zx pictures
  new preset={ZX}{
    latex, % we inherit from the latex preset
    % make sure to use the same font as the document, or the equations will not be properly aligned
    add to latex options={11pt},
    add to preamble={  % we make sure the zx library is loaded when building cached images
      \usepackage{amsmath}
      \usepackage{zx-calculus}
    },
    dependencies={}, % Add here any file that must induce a recompilation of your file if it changes.
  },
}

% say to cache by default all ZX environments (can be changed later) and \zx{} commands
\cacheEnvironment{ZX}{ZX}
\cacheCommand{zx}{ZX}

% You can pass options to robust-externalize via <>
\begin{ZX}<add to preamble={\def\name{Alice}}>
  \zxX{\text{\name}}
\end{ZX}
\end{codeexample}

Now, just recompile your project: it should cache the pictures. See \mylink{https://github.com/leo-colisson/robust-externalize}{\texttt{robust-externalize}} for more details.

\subsubsection{Tikz external: not recommended}

\textbf{WARNING}: I added some options to use tikz |external| library to save compilation time... And then I realized that tikz |external| was quite close to be unusable in practice as it has many caveats. I ended up coding my own replacement to externalize any operation, and it works much better! See comment in the previous section.

Since 2022/02/08, it is possible to use the tikz |external| library to save compilation time. To load it, you need to add the following tikz libraries:
\begin{verse}
  |\usetikzlibrary{external}|\\
  |\usetikzlibrary{zx-calculus}|\\
  |\tikzexternalize|\\
  |\zxConfigureExternalSystemCallAuto|\\
\end{verse}
Then, compile with shell-escape, for instance using |pdflatex -shell-escape yourfile.tex|.

\textbf{WARNING}: if |external| is loaded before |zx-calculus|, you don't need to run |\zxConfigureExternalSystemCallAuto|. This command is only useful to ensure the system call used by |external| displays errors appropriately by configuring the interaction mode to match the one used by the parent compilation command. If you prefer to disable this feature to use |external|'s default, define `\def\zxDoNotPatchSystemCall{}` before loading the |zx-calculus| library.

\alertwarning{Note however that this has not yet being extensively tested, and the \texttt{external} library has a few caveats presented below}
\begin{itemize}
\item If you change the order of the diagrams, or add a diagram in the middle of the document, all subsequent diagrams will be recompiled. This issue has been reported \mylink{https://github.com/pgf-tikz/pgf/issues/758}{here} and is caused by the fact that the figures are called \texttt{figure0},\dots,\texttt{figureN}. To limit this issue, you can regularly insert \texttt{\textbackslash{}tikzsetfigurename\{nameprefix\}} in your document with different names to avoid a full recompilation of the file (or using groups to change it for a single newly added equation).
\item The \texttt{external} library uses the main file to recompile each picture, so if your file is large or loads a lot of libraries, it may \mylink{https://tex.stackexchange.com/questions/633175/tikz-externalize-is-much-slower-than-tikz-on-first-run}{take a while to compile a single diagram} (to give an example, this library takes 41 seconds to compile without the externalize library, with the externalize library it takes 14mn for the first run and 3 seconds for the next runs). For this reason, you may want to use \texttt{\textbackslash{}tikzset\{external/export=false\}} or |\tikzexternaldisable| (the latter won't fail if your elements are not parsable by tikz external) in a group to disable temporarily the external library while you are writing your diagram. You may like the |list and make| option of tikz external that produces a Makefile that one can compile separately to build in parallel all pictures.
\item If you compile once a diagram without any error, and recompile it after inserting an error, you will see an error while compiling. But if you recompile again, the error will disappear and the diagram that lastly succeeded to build will be inserted instead of the newly buggy diagram. This has been reported \mylink{https://github.com/pgf-tikz/pgf/issues/1137}{here}.
\item Sometimes, |external| cuts some parts of the picture, namely when parts are drawn outside of the bounding box. I've not experienced that with zx diagrams directly (we don't go beyond the bounding box), but the example at the end of this document with the |double copy shadow| has such issues because the shadow is drawn outside of the bounding box. One should therefore disable the externalization (or increase the bounding box) in these cases.
\item It seems that sometimes the inner sep of some labels in |external| mode defaults to zero (see the CNOT example below), I'm not sure why. Adding explicitly the value of the label fixes this.
\end{itemize}

\begin{pgfmanualentry}
  \extractcommand\zxExternalAuto\@@
  \extractcommand\zxExternalWrap\@@
  \extractcommand\zxExternalNoWrap\@@
  \extractcommand\zxExternalNoWrapNoExt\@@
  \extractcommand\zxExternalWrapForceExt\@@
  \pgfmanualbody
  Also, the library |external| forces us to wrap our diagrams into a basically empty tikz-pictures to make it work. The current library will automatically wrap the diagrams when the |external| library is enabled, but you can customize how diagrams are wrapped manually: |\zxExternalAuto| (default) will wrap it automatically if |external| is enabled, |\zxExternalWrap| will always wrap it, |\zxExternalNoWrap| will never wrap it (you will get errors if you use |external|), |\zxExternalNoWrapNoExt| will not wrap the figure, but will disable temporary the externalization for diagrams to avoid errors and |\zxExternalWrapForceExt| will wrap the figures and enable tikz |external| locally only for zx-diagrams (using |\tikzexternalenable|). This last option is particularly useful when using |external| while most other environments are not compatible with externalization (like tikzcd, quantikz, blochsphere, maybe cryptocode\dots{}): the idea is to disable tikzexternalize everywhere, except for zx diagrams:
\begin{verse}
|\tikzexternalize|\\
|\tikzexternaldisable|\\
|\zxExternalWrapForceExt|
\end{verse}
\end{pgfmanualentry}

\begin{pgfmanualentry}
  \extractcommand\zxExternalSuffix\marg{suffix}\@@
  \pgfmanualbody
By default, the library adds a suffix |zx| to figures corresponding to zx diagrams (it avoids to recompile diagrams when a normal figure is added in between two zx diagrams). You can change (or remove) this suffix using |\zxExternalSuffix{yoursuffix}|, where the suffix can also be empty.
\end{pgfmanualentry}

Note that if you get an error:\\
|Argument of \tikzexternal@laTeX@collect@until@end@tikzpicture has an extra }|\\
it is likely that you have an element that is not handled by tikz external, like a raw |tikzcd| environment, a |blochsphere| environment\dots{} Either disable temporary tikz external around it:\\
|{\tikzexternaldisable your code not compatible with external}|\\
or wrap your element around |\begin{tikzpicture}\node{your figure};\end{tikzpicture}| (people usually don't like nested tikz pictures\dots{} but it often works nicely). In case you also care about the baseline, you may prefer to wrap it using:\\
|\begin{tikzpicture}[baseline=(mynode.base)]\node(mynode){your figure};\end{tikzpicture}|

\subsection{How to visually group multiple nodes}\label{subsec:decoration}


\begin{pgfmanualentry}
  \def\extrakeytext{style, }
  \extractcommand\zxCont\oarg{style}\oarg{color}\marg{nb rows}\marg{nb columns}\oarg{label style}\oarg{(other)(nodes)(to)(fit)}\marg{Text of label}\@@
  \extractcommand\zxGroupGates\oarg{style}\marg{nb rows}\marg{nb columns}\oarg{label style}\oarg{(other)(nodes)(to)(fit)}\marg{Text of label}\@@
  \extractcommand\zxContName\oarg{style}\oarg{color}\marg{(nodes)(to)(fit)}\oarg{label style}\marg{Text of label}\@@
  \extractcommand\zxNamedBox\oarg{style}\oarg{color}\marg{(nodes)(to)(fit)}\oarg{label style}\marg{Text of label}\@@
  \pgfmanualbody
  These commands are used to highlight a part of a diagram (|Cont| is for ``Container''), or, for |\zxGroupGates|, to group gates together (it is like |Cont| but with a different style), the main difference is that the |Cont| version can be used inside the matrix and will automatically contain the current node (you must then either by specifying the size of the box or the name of the other nodes to fit), while |\zxNamedBox| must be inserted later (so you might not use it much), like:
\begin{codeexample}[width=0cm]
  \begin{ZX}
    \zxN{} \rar & [\zxwCol] \zxZ{} \zxCont{2}{1}{\textsc{cnot}} \dar \rar & [\zxwCol] \zxN{} \\
    \zxN{} \rar & \zxX{} \rar                                             & [\zxwCol] \zxN{} \\
  \end{ZX}
\end{codeexample}
\begin{codeexample}[width=0cm]
  \begin{ZX}
    \zxN{} \rar & [\zxwCol] \zxZ{} \zxContName{(endCnot)}{\textsc{cnot}} \dar \rar & [\zxwCol] \zxN{} \\
    \zxN{} \rar & \zxX[a=endCnot]{} \rar                                             & [\zxwCol] \zxN{} \\
  \end{ZX}
\end{codeexample}
\begin{codeexample}[width=0cm]
  \begin{ZX}[
    % \zxCont offers a more practical interface
    execute at end picture={
      \zxNamedBox{(cnot1)(cnot2)}{
        below:\textsc{cnot}
      }
    }
    ]
    \zxN{} \rar &[\zxwCol] \zxZ[alias=cnot1]{} \dar \rar &[\zxwCol] \zxN{}\\
    \zxN{} \rar & \zxX[alias=cnot2]{} \rar      &[\zxwCol] \zxN{}\\
  \end{ZX}
\end{codeexample}

Note that the |fit| library cannot fit a wire. So if you want to include the wires around a node, the simpler thing might be to manually increase the size of the box in the style. We provide for that an helper command |fit margins={top=1mm,bottom=2mm,right=2.2mm,left=2.2mm}| (the |inner sep| and |shift| commands of tikz are not really practical to move a single border), you can also use |horizontal|, |vertical|, or |all|, and |l| is a shorcut to add larger margins instead of |fit margins={all=1mm}|.
\begin{codeexample}[width=0cm]
  \begin{ZX}[
    execute at end picture={
      \zxNamedBox[fit margins={right=2.2mm}]{(measX)(measZ)}{
        below:\footnotesize Bell measurement
      }
      \zxNamedBox[fit margins={bottom=2pt,top=2pt,left=2.0mm}][green!80!black]{(bellA)(bellB)}{
        left:\footnotesize Bell pair:
      }
    }
    ]
    \zxN[a=bellA]{} \rar \dar[C] & [\zxwCol] \zxX*{x\pi} \rar   & \zxZ*{z\pi} \rar & \zxN{} \\[\zxwCol]
    \zxN[a=bellB]{} \rar         & \zxX[a=measX]{x\pi} \dar[C-] &                           \\
    \zxN{} \rar                  & \zxZ[a=measZ]{z\pi}
  \end{ZX}
\end{codeexample}
This will automatically create a subnode |wrapper| pointing to the wrapping node. You can use it to link to that node (note that you should be sure that the wire points to the top left element of the group):
\begin{codeexample}[width=0cm]
  \begin{ZX}[circuit]
    \ar[rr] && \zxCtrl{} \ar[dl, end subnode=wrapper] \ar[rr] && \\
    \rar    & \zxCtrl{} \dar \rar \zxGroupGates{2}{3}{below:\textsc{swap}} & \zxNot{} \dar \rar                             & \zxCtrl{} \dar \rar & \\
    \rar    & \zxNot{} \rar                                                & \zxCtrl{} \rar                                 & \zxNot{} \rar       & 
  \end{ZX}
\end{codeexample}
\end{pgfmanualentry}

\section{Advanced styling}

\subsection{Overlaying or creating styles}

It is possible to arbitrarily customize the styling, create or update ZX or tikz styles\dots{} First, any option that can be given to a |tikz-cd| matrix can also be given to a |ZX| environment (we refer to the manual of |tikz-cd| for more details). We also provide overlays to quickly modify the ZX style.

\begin{stylekey}{/zx/default style nodes}
  This is where the default style must be loaded. By default, it simply loads the (nested) style packed with this library, |/zx/styles/rounded style|. You can change the style here if you would like to globally change a style.

  Note that a style must typically define at least |zxZ4|, |zxX4|, |zxFracZ6|, |zxFracX6|, |\zxH|, |zxHSmall|, |zxNoPhaseSmallZ|, |zxNoPhaseSmallX|, |zxNone{,+,-,I}|, |zxNoneDouble{,+,-,I}| and all the |phase in label*|, |pil*| styles (see code on how to define them). Because the above styles (notably |zxZ*| and |zxFrac*|) are slightly complex to define (this is needed in order to implement |phase in label|, |-| versions\dots{}), it may be quite long to implement them all properly by yourself.

  For that reason, it may be easier to load our default style and overlay only some of the styles we use (see example in |/zx/user overlay nodes| right after). You can check our code in |/zx/styles/rounded style| to see what you can redefine (intuitively, the styles like |my style name| should be callable by the end user, |myStyleName| may be redefined by users or used in tikzit, and |my@style@name| are styles that should not be touched by the user). The styles that have most interests are |zxNoPhase| (for Z and X nodes without any phase inside), |zxShort| (for Z and X nodes for fractions typically), |zxLong| (for other Z and X nodes) and |stylePhaseInLabel| (for labels when using |phase in label|). These basic styles are extended to add colors (just add |Z|/|X| after the name) like |zxNoPhaseZ|\dots{} You can change them, but if you just want to change the color, prefer to redefine |colorZxZ|/|colorZxZ| instead (note that this color does not change |stylePhaseInLabelZ/X|, so you are free to redefine these styles as well). All the above styles can however be called from inside a tikzit style, if you want to use tikzit internally (make sure to load this library then in |*.tikzdefs|).

  Note however that you should avoid to call these styles from inside |\zx{...}| since |\zx*| and |\zxFrac*| are supposed to choose automatically the good style for you depending on the mode (fractions, labels in phase\dots{}). For more details, we encourage the advanced users too look at the code of the library, and examples for simple changes will be presented now.
\end{stylekey}

\begin{stylekey}{/zx/user overlay nodes}
  If a user just wants to overlay some parts of the node styles, add your changes here.
\begin{codeexample}[]
  {\tikzset{
      /zx/user overlay nodes/.style={
        zxH/.append style={dashed,inner sep=2mm}
      }}
    \zx{\zxNone{} \rar & \zxH{} \rar & \zxNone{}}
  }
\end{codeexample}
You can also change it on a per-diagram basis:
\begin{codeexample}[]
  \zx[text=yellow,/zx/user overlay nodes/.style={
    zxSpiders/.append style={thick,draw=purple}}
  ]{\zxX{} \rar & \zxX{\alpha} \rar & \zxFracZ-{\pi}{2}}
\end{codeexample}
The list of keys that can be changed will be given below in |/zx/styles/rounded style/*|.
\end{stylekey}

\begin{stylekey}{/zx/user overlay}
  This key will be loaded like it if were inside the options of the picture |\zx[options]{...}|. To avoid always typing |\zx[content vertically centered]{...}|, you can therefore use:
\begin{codeexample}[width=0pt]
\tikzset{
  /zx/user overlay/.style={
    content vertically centered,
  },
}
\begin{ZX}
  \zxX{\alpha} & \zxX{\beta} & \zxX{a} & \zxX{b} & \zxX*{a\pi} & \zxX*{b\pi} & \zxX*{b'\pi} & \zxX*{'b\pi} & \zxZ{(a \oplus b )\pi}
\end{ZX}
\end{codeexample}
\end{stylekey}

\begin{stylekey}{/zx/default style wires}
  Default style for wires. Note that |/zx/wires definition/| is always loaded by default, and we don't add any other style for wires by default. But additional styles may use this functionality.
\end{stylekey}

\begin{stylekey}{/zx/user overlay wires}
  The user can add here additional styles for wires.
\begin{codeexample}[]
\begin{ZX}[/zx/user overlay wires/.style={thick,->,C/.append style={dashed}}]
  \zxNone{} \ar[d,C] \rar[] &[\zxWCol] \zxNone{}\\[\zxWRow]
  \zxNone{} \rar[] & \zxNone{}
\end{ZX}
\end{codeexample}
\end{stylekey}

\begin{stylekey}{/zx/styles/rounded style}
  This is the style loaded by default. It contains internally other (nested) styles that must be defined for any custom style.
\end{stylekey}

We present now all the properties that a new node style must have (and that can overlayed as explained above).
\begin{stylekey}{/zx/styles/rounded style/zxAllNodes}
  Style applied to all nodes.
\end{stylekey}

\begin{stylekey}{/zx/styles/rounded style/zxEmptyDiagram}
  Style to draw an empty diagram.
\end{stylekey}

\begin{pgfmanualentry}
  \makeatletter
  \def\extrakeytext{style, }
  \extractkey/zx/styles/rounded style/zxNone\@nil%
  \extractkey/zx/styles/rounded style/zxNone+\@nil%
  \extractkey/zx/styles/rounded style/zxNone-\@nil%
  \extractkey/zx/styles/rounded style/zxNoneI\@nil%
  \makeatother
  \pgfmanualbody
  Styles for None wires (no inner sep, useful to connect to wires). The |-|,|I|,|+| have additional horizontal, vertical, both spaces.
\end{pgfmanualentry}

\begin{pgfmanualentry}
  \makeatletter
  \def\extrakeytext{style, }
  \extractkey/zx/styles/rounded style/zxNoneDouble\@nil%
  \extractkey/zx/styles/rounded style/zxNoneDouble+\@nil%
  \extractkey/zx/styles/rounded style/zxNoneDouble-\@nil%
  \extractkey/zx/styles/rounded style/zxNoneDoubleI\@nil%
  \makeatother
  \pgfmanualbody
  Like |zxNone|, but with more space to fake two nodes on a single line (not very used).
\end{pgfmanualentry}

\begin{stylekey}{/zx/styles/rounded style/zxSpiders}
  Style that apply to all circle spiders.
\end{stylekey}

\begin{stylekey}{/zx/styles/rounded style/zxNoPhase}
  Style that apply to spiders without any angle inside. Used by |\zxX{}| when the argument is empty.
\end{stylekey}

\begin{stylekey}{/zx/styles/rounded style/zxNoPhaseSmall}
  Like |zxNoPhase| but for spiders drawn in between wires.
\end{stylekey}

\begin{stylekey}{/zx/styles/rounded style/zxShort}
  Spider with text but no inner space. Used notably to obtain nice fractions.
\end{stylekey}

\begin{stylekey}{/zx/styles/rounded style/zxLong}
  Spider with potentially large text. Used by |\zxX{\alpha}| when the argument is not empty.
\end{stylekey}

\begin{pgfmanualentry}
  \makeatletter
  \def\extrakeytext{style, }
  \extractkey/zx/styles/rounded style/zxNoPhaseZ\@nil%
  \extractkey/zx/styles/rounded style/zxNoPhaseX\@nil%
  \extractkey/zx/styles/rounded style/zxNoPhaseSmallZ\@nil%
  \extractkey/zx/styles/rounded style/zxNoPhaseSmallX\@nil%
  \extractkey/zx/styles/rounded style/zxShortZ\@nil%
  \extractkey/zx/styles/rounded style/zxShortX\@nil%
  \extractkey/zx/styles/rounded style/zxLongZ\@nil%
  \extractkey/zx/styles/rounded style/zxLongX\@nil%
  \makeatother
  \pgfmanualbody
  Like above styles, but with colors of |X| and |Z| spider added. The color can be changed globally by updating the |colorZxX| color. By default we use:
  \begin{verse}
    |\definecolor{colorZxZ}{RGB}{204,255,204}|\\
    |\definecolor{colorZxX}{RGB}{255,136,136}|\\
    |\definecolor{colorZxH}{RGB}{255,255,0}|
  \end{verse}
  as the second recommendation in \href{https://zxcalculus.com/accessibility.html}{\texttt{zxcalculus.com/accessibility.html}}.
\end{pgfmanualentry}

\begin{stylekey}{/zx/styles/rounded style/zxH}
  Style for Hadamard spiders, used by |\zxH{}| and uses the color |colorZxH|.
\end{stylekey}

\begin{stylekey}{/zx/styles/rounded style/zxHSmall}
  Like |zxH| but for Hadamard on wires, (see |H| style).
\end{stylekey}

\begin{pgfmanualentry}
  \extractcommand\zxConvertToFracInContent\marg{sign}\marg{num no parens}\marg{denom no parens}\marg{nom parens}\marg{denom parens}\@@
  \extractcommand\zxConvertToFracInLabel\@@
  \pgfmanualbody
  These functions are not meant to be used, but redefined using something like (we use |\zxMinus| as a shorter minus compared to $-$):
\begin{verse}
  |\RenewExpandableDocumentCommand{\zxConvertToFracInLabel}{mmmmm}{%|\\
  |  \ifthenelse{\equal{#1}{-}}{\zxMinus}{#1}\frac{#2}{#3}%|\\
  |}|
\end{verse}
This is used to change how the library does the conversion between |\zxFrac| and the actual written text (either in the node content or in the label depending on the function). The first argument is the sign (string |-| for minus, anything else must be written in place of the minus), the second and third argument are the numerator and denominator of the fraction when used in |\frac{}{}| while the last two arguments are the same except that they include the parens which should be added when using an inline version. For instance, one could get a call |\zxConvertToFracInLabel{-}{a+b}{c+d}{(a+b)}{(c+d)}|. See part on labels to see an example of use.
\end{pgfmanualentry}

\begin{pgfmanualentry}
  \def\extrakeytext{style, }
  \extractcommand\zxMinusUnchanged\@@
  \extractcommand\zxMinus\@@
  \extractcommand\zxMinusInShort\@@
  \makeatletter% should not be letter for \@@... strange
  \extractkey/zx/defaultEnv/zx column sep=length\@nil%
  \extractkey/zx/styles/rounded style preload/small minus\@nil%
  \extractkey/zx/styles/rounded style preload/big minus\@nil%
  \extractkey/zx/styles/rounded style/small minus\@nil%
  \extractkey/zx/styles/rounded style/big minus\@nil%
  \makeatother
  \pgfmanualbody
  |\zxMinus| is the minus sign used in fractions, |\zxMinusInShort| is used in |\zxZ-{\alpha}| and |\zxMinusUnchanged| is a minus sign shorter than $-$. You can redefine them, for instance:
\begin{codeexample}[]
Compare {\def\zxMinusInShort{-}
  \zx{\zxZ-{\alpha}}
} and
{\def\zxMinusInShort{\zxMinus}
  \zx{\zxZ-{\alpha}}
}
\end{codeexample}
You can also choose to always use a big or a small minus, either on a per-node, per-figure, or document-wise.
\begin{codeexample}[]
\begin{ZX}
  \zxFracZ-{\pi}{4} & \zxZ-{\alpha} & \zxZ-{\delta_i} & \zxZ[small minus]-{\delta_i}
\end{ZX} Picture-wise %
\begin{ZX}[small minus]
  \zxZ-{\alpha} & \zxZ-{\delta_i} & \zxZ-{\delta_i} & \zxFracZ-{\pi}{4}
\end{ZX} Document-wise %
\tikzset{/zx/user overlay/.style={small minus}}%
\begin{ZX}
  \zxZ-{\alpha} & \zxZ-{\delta_i} & \zxZ[big minus]-{\delta_i} & \zxFracZ[big minus]-{\pi}{4}
\end{ZX}
\end{codeexample}
\end{pgfmanualentry}

\noindent We also define several spacing commands that can be redefined to your needs:
\begin{pgfmanualentry}
  \extractcommand\zxHCol{}\@@
  \extractcommand\zxHRow{}\@@
  \extractcommand\zxHColFlat{}\@@
  \extractcommand\zxHRowFlat{}\@@
  \extractcommand\zxSCol{}\@@
  \extractcommand\zxSRow{}\@@
  \extractcommand\zxSColFlat{}\@@
  \extractcommand\zxSRowFlat{}\@@
  \extractcommand\zxHSCol{}\@@
  \extractcommand\zxHSRow{}\@@
  \extractcommand\zxHSColFlat{}\@@
  \extractcommand\zxHSRowFlat{}\@@
  \extractcommand\zxWCol{}\@@
  \extractcommand\zxWRow{}\@@
  \extractcommand\zxwCol{}\@@
  \extractcommand\zxwRow{}\@@
  \extractcommand\zxDotsCol{}\@@
  \extractcommand\zxDotsRow{}\@@
  \extractcommand\zxZeroCol{}\@@
  \extractcommand\zxZeroRow{}\@@
  \extractcommand\zxNCol{}\@@
  \extractcommand\zxNRow{}\@@
  \pgfmanualbody
  These are spaces, to use like |&[\zxHCol]| or |\\[\zxHRow]| in order to increase the default spacing of rows and columns depending on the style of the wire. |H| stands for Hadamard, |S| for Spiders, |W| for Wires only, |w| is you link a |zxNone| to a spider (goal is to increase the space), |N| is when you have a |\zxN| and want to reduce the space between columns, |HS| for both Spiders and Hadamard, |Dots| for the 3 dots styles, |Zero| completely resets the default column sep. And of course |Col| for columns, |Row| for rows.
\begin{codeexample}[width=3cm]
\begin{ZX}
 \zxN{} \ar[rd,-N.] &[\zxwCol]    &[\zxwCol] \zxN{} \\[\zxNRow]%%
                    & \zxX{\alpha}
                      \ar[ru,N'-]
                      \ar[rd,N.-] &  \\[\zxNRow]
 \zxN{} \ar[ru,-N']               &  & \zxN{}
\end{ZX}
\end{codeexample}
Note that you can add multiple of them by separating with commas (see |\pgfmatrixnextcell|'s documentation for more details). For instance to have a column separation of exactly |2mm|, do |&[\zxZeroCol,2mm]| (if you just do |&[2mm]| the column will be |2mm| larger). This can also be useful to avoid having a huge space when nodes have multiple empty outputs:
\begin{codeexample}[]
  Compare:
  \begin{ZX}
    \zxN{}      &                              & \zxN{} \\
    \zxN{} \rar & \zxZ{} \ar[ur,<'] \ar[dr,<'] &        \\
                &                              & \zxN{} \\
  \end{ZX}
  with
  \begin{ZX}
    \zxN{}      &                              & \zxN{} \\[\zxZeroRow]
    \zxN{} \rar & \zxZ{} \ar[ur,<'] \ar[dr,<'] &        \\[\zxZeroRow]
                &                              & \zxN{} 
  \end{ZX}
\end{codeexample}
\end{pgfmanualentry}

\begin{pgfmanualentry}
  \def\extrakeytext{style, }
  \extractcommand\zxDefaultColumnSep{}\@@
  \extractcommand\zxDefaultRowSep{}\@@
  \makeatletter% should not be letter for \@@... strange
  \extractkey/zx/defaultEnv/zx column sep=length\@nil%
  \extractkey/zx/defaultEnv/zx row sep=length\@nil%
  \makeatother
  \pgfmanualbody
  |\zxDefaultColumn/RowSep| are the column and row space, and the corresponding styles are to change a single matrix. Prefer to change these parameters compared to changing the |row sep| and |column sep| (without |zx|) of the matrix directly since other spacing styles like |\zxZeroCol| or |\zxNCol| depend on |\zxDefaultColumn|.
\end{pgfmanualentry}


\begin{pgfmanualentry}
  \extractcommand\zxDefaultSoftAngleS{}\@@
  \extractcommand\zxDefaultSoftAngleO{}\@@
  \extractcommand\zxDefaultSoftAngleChevron{}\@@
  \pgfmanualbody
  Default opening angles of |S|, |o| and |v|/|<| wires. Defaults to respectively $30$, $40$ and $45$.
\end{pgfmanualentry}

\subsection{Wire customization}\label{subsec:wirecustom}

\begin{pgfmanualentry}
  \makeatletter
  \def\extrakeytext{style, }
  \extractkey/zx/args/-andL/\@nil%
  \extractkey/zx/args/-andL/defaultO (default {-=.2,L=.4})\@nil%
  \extractkey/zx/args/-andL/defaultN (default {-=.2,L=.8})\@nil%
  \extractkey/zx/args/-andL/defaultN- (default {1-=.4,1L=0})\@nil%
  \extractkey/zx/args/-andL/defaultNN (default {})\@nil%
  \extractkey/zx/args/-andL/defaultNIN (default {1-=0,1L=.6})\@nil%
  \extractkey/zx/args/-andL/defaultS (default {-=.8,L=0})\@nil%
  \extractkey/zx/args/-andL/defaultS' (default {-=.8,L=.2})\@nil%
  \extractkey/zx/args/-andL/default-S (default {1-=.8,1L=0})\@nil%
  \extractkey/zx/args/-andL/defaultSIS (default {1-=0,1L=.8})\@nil%
  \makeatother
  \pgfmanualbody
  Default values used by wires (). You can customize them globally using something like:
  \begin{verse}
    |\tikzset{|\\
    |  /zx/args/-andL/.cd,|\\
    |  defaultO/.style={-=.2,L=.4}|\\
    |}|
   \end{verse}
   Basically |defaultO| will configure all the |o| familly, |defaultS'| will configure all the ``soft'' versions of |s|, |default-S| will configure the anchor on the side of the vertical arrival\dots{} For more details or which wire uses which configuration, check the default value given in each style definition.
\end{pgfmanualentry}

\subsection{Wires starting inside or on the boundary of the node}\label{subsec:wiresInsideOutside}

This library provides multiple methods to draw the wires between the nodes (for all curves depending on |bezier|, which is basically everything but |C| and straight lines).

\paragraph{Default drawing method.}
By default the lines will be drawn behind the node and the starting and ending points will be defined to be a |fake center *| anchor (if it exists, the exact chosen anchors (north, south\dots{}) depending on the direction). Because this anchor lies behind the node, we put them on the |edgelayer| layer. For debugging purpose, it can be practical to display them:
\begin{pgfmanualentry}
  \def\extrakeytext{style, }
  \extractcommand\zxEdgesAbove\@@
  \makeatletter% should not be letter for \@@... strange
  \extractkey/zx/wires definition/edge above\@nil%
  \extractkey/zx/wires definition/edge not above\@nil%
  \makeatother
  \pgfmanualbody
  If the macro |\zxEdgesAbove| is undefined (using |\let\zxEdgesAbove\undefined|) edges will be drawn above the nodes. To change it on a per-edge basis, use |edge above| (or its contrary |edge not above|) \emph{before the name of the wire}. This is mostly useful to understand how lines are drawn and for debugging purpose.
\begin{codeexample}[]
  What you see:
  \zx{\zxZ{\alpha+\beta} \ar[dr,s] \\
                         & \zxZ{\alpha+\beta}}
  What is drawn:
  \zx{\zxZ{\alpha+\beta} \ar[dr,edge above,s] \\
                         & \zxZ{\alpha+\beta}}
\end{codeexample}
(you can note the fact that the wire does not start at the center but at a |fake center *| anchor to provide a nicer look)
\end{pgfmanualentry}

\begin{pgfmanualentry}
  \def\extrakeytext{style, }
  \extractcommand\zxControlPointsVisible\@@
  \makeatletter% should not be letter for \@@... strange
  \extractkey/zx/wires definition/control points visible\@nil%
  \extractkey/zx/wires definition/control points not visible\@nil%
  \makeatother
  \pgfmanualbody
  Similarly, it can be useful for debugging to see the control points of the curves (note that |C|, straight lines and |(| wires are not based on our curve system, so it won't do anything for them). If the macro |\zxControlPointsVisible| is defined (using |\def\zxEdgesAbove{}|) control points will be drawn. To change it on a per-edge basis, use |control points visible| (or its contrary |control points not visible|). This is mostly useful to understand how lines are drawn and for debugging purpose.
\begin{codeexample}[]
  Controls not visible:
  \zx{\zxZ{\alpha+\beta} \ar[dr,s] \\
                         & \zxZ{\alpha+\beta}}
  Control visible:
  \zx{\zxZ{\alpha+\beta} \ar[dr,control points visible,s] \\
                         & \zxZ{\alpha+\beta}}
  Control visible + edge above:
  \zx{\zxZ{\alpha+\beta} \ar[dr,edge above,control points visible,s] \\
                         & \zxZ{\alpha+\beta}}
\end{codeexample}
\textbf{WARNING}: this command adds some points in the wire path, and in particular if you have a |H| wire (Hadamard in the middle of the wire), this option will not place it correctly. But it's not really a problem since it's just to do a quick debugging.
\end{pgfmanualentry}

Unfortunately, the default drawing method also has drawbacks. For instance, when using the |H| edge between a spider and an empty node, the ``middle'' of the edge will appear too close to the center by default (we draw the first edge above to illustrate the reason of this visual artifact):
\begin{codeexample}[width=0cm]
\begin{ZX}
 \zxN{} \ar[rd,edge above,-N.,H] &[\zxwCol,\zxHCol]  &[\zxwCol,\zxHCol] \zxN{} \\[\zxNRow]%%
                                 & \zxX{\alpha}
                                   \ar[ru,N'-,H]
                                   \ar[rd,N.-,H] &  \\[\zxNRow]
 \zxN{} \ar[ru,-N',H]                        &  & \zxN{}
\end{ZX}
\end{codeexample}
To solve that issue, you need to manually position the |H| node as shown before:
\begin{codeexample}[width=0cm]
\begin{ZX}
 \zxN{} \ar[rd,edge above,-N.,H={pos=.35}] &[\zxwCol,\zxHCol]  &[\zxwCol,\zxHCol] \zxN{} \\[\zxNRow]%%
                                           & \zxX{\alpha}
                                             \ar[ru,N'-,H={pos=1-.35}]
                                             \ar[rd,N.-,H={pos=1-.35}] &  \\[\zxNRow]
 \zxN{} \ar[ru,-N',H={pos=.35}]                                  &  & \zxN{}
\end{ZX}
\end{codeexample}
Or manually position the anchor outside the node (you can use angles, centered on the real center on the shape), but be aware that it can change the shape of the node (see below):
\begin{codeexample}[width=0cm]
\begin{ZX}
 \zxN{} \ar[rd,edge above,-N.,H,end anchor=180-45] &[\zxwCol,\zxHCol]  &[\zxwCol,\zxHCol] \zxN{} \\[\zxNRow]%%
                                           & \zxX{\alpha}
                                             \ar[ru,N'-,H,start anchor=45]
                                             \ar[rd,N.-,H,start anchor=-45] &  \\[\zxNRow]
 \zxN{} \ar[ru,-N',H,end anchor=180+45]                                  &  & \zxN{}
\end{ZX}
\end{codeexample}

A second drawback is that it is not possible to add arrows on the curved wires (except |C| which uses a different approach), since they will be hidden behind the node:
\begin{codeexample}[]
  What you see:
  \zx{\zxZ{\alpha+\beta} \ar[dr,s,<->] \\
                         & \zxZ{\alpha+\beta}}
  What is drawn:
  \zx{\zxZ{\alpha+\beta} \ar[dr,edge above,s,<->] \\
                         & \zxZ{\alpha+\beta}}
\end{codeexample}
Here, the only solution (without changing the drawing mode) is to manually position the anchor as before\dots{} but note that on nodes with a large content |45| degrees is actually nearly on the top since the angle is not taken from a fake center but from the real center of the node.
\begin{codeexample}[]
  \zx{\zxZ{\alpha+\beta} \ar[dr,s,<->,start anchor=-45,end anchor=180-45] \\
                         & \zxZ{\alpha+\beta}}
  \zx{\zxZ{\alpha+\beta} \ar[dr,s,<->,start anchor=-15,end anchor=180-15] \\
                         & \zxZ{\alpha+\beta}}
\end{codeexample}
 Note that the shape of the wire may be a bit different since the ending and leaving parts was hidden before, and the current styles are not designed to look nicely when starting on the border of a node. For that reason, you may need to tweak the style of the wire yourself using |-|, |L| options.

 \paragraph{The ``intersection'' drawing methods}

 We also define other modes to draw wires (they are very new and not yet tested a lot). In the first mode, appropriate |fake center *| is taken, then depending on the bezier control points, a point is taken on the border of the shape (starting from the fake center and using the direction of the bezier control point). Then the node is drawn. Here is how to enable this mode:

\begin{pgfmanualentry}
  \def\extrakeytext{style, }
  \extractcommand\zxEnableIntersections\marg{}\@@
  \extractcommand\zxDisableIntersections\marg{}\@@
  \extractcommand\zxEnableIntersectionsNodes\@@
  \extractcommand\zxEnableIntersectionsWires\@@
  \makeatletter% should not be letter for \@@... strange
  \extractkey/zx/wires definition/use intersections\@nil%
  \extractkey/zx/wires definition/dont use intersections\@nil%
  \makeatother
  \pgfmanualbody
  The simpler method to enables or disable intersections is to call |\zxEnableIntersections{}| or |\zxDisableIntersections{}| (potentially in a group to have a local action only). Note that \emph{this does not automatically adapt the styles}, see |ui| to adapt the styles automatically.
\begin{codeexample}[width=0cm]
{% Enable intersections (but does not load our custom "intersections" style, see ui).
  \zxEnableIntersections{}% Small space left = artifact of the documentation
  \begin{ZX}
    \zxN{} \ar[rd,edge above,-N.,H] &[\zxwCol,\zxHCol] &[\zxwCol,\zxHCol] \zxN{} \\[\zxNRow]%%
                                    & \zxX{\alpha}
                                      \ar[ru,N'-,H]
                                      \ar[rd,N.-,H]    &  \\[\zxNRow]
    \zxN{} \ar[ru,-N',H]            &                  & \zxN{}
  \end{ZX}
}
\end{codeexample}
(The |edge above| is just to show that the wire does not go inside.) However, this method enable intersections for the whole drawing. You can disable it for a single arrow using the |dont use intersections| style. But it is possible instead to enable it for a single wire. To do that, first define |\def\zxEnableIntersectionsNodes{}| (it will automatically add a |name path| on each node. If you don't care about optimizations, you can just define it once at the beginning of your project), and then use |use intersections| on the wires which should use intersections:
\begin{codeexample}[width=0cm]
{% Create the machinary needed to compute intersections, but does not enable it.
  \def\zxEnableIntersectionsNodes{}% Small space left = artifact of the documentation
  \begin{ZX}
    \zxN{} \ar[rd,edge above,-N.,H, %% "use intersections" does not load any style, cf ui.
            use intersections] &[\zxwCol,\zxHCol]  &[\zxwCol,\zxHCol] \zxN{} \\[\zxNRow]%%
                                                   & \zxX{\alpha}
                                                     \ar[ru,edge above,N'-,H,use intersections]
                                                        \ar[rd,edge above,N.-,H]  &  \\[\zxNRow]
    \zxN{} \ar[ru,edge above,-N',H]                &                              & \zxN{}
  \end{ZX}
}
\end{codeexample}
\end{pgfmanualentry}

\begin{pgfmanualentry}
  \def\extrakeytext{style, }
  \makeatletter% should not be letter for \@@... strange
  \extractkey/zx/wires definition/ui\@nil%
  \makeatother
  \pgfmanualbody
  This method has however a few drawbacks. One of the first reason that explains why we don't use it by default is that it is quite long to compute (it involves the |intersections| library to obtain the bezier point to start at and my code may also be not very well optimized as I'm a beginner with \LaTeX{} and \tikzname{} programming\dots{} and what a strange language!). Secondly, it has not yet been tested a lot. Note also that the default wire styles have not been optimized for this setup and the results may vary compared to the default drawing mode (sometimes they are ``better'', sometimes they are not). We have however tried to define a second style |/zx/args/-andL/ui/| that have nicer results. To load it, just type |ui| \emph{before the wire style name}, it will automatically load |use intersections| together with our custom styles (see below how to use |user overlay wires| to load it by default):
%%% I'm not sure why, but inside codeexample if I write zxEnableIntersections{}%<go to line>\begin{ZX}... then an additional space is added... Not sure why.
\begin{codeexample}[]
{%
  \def\zxEnableIntersectionsNodes{}
  Before \begin{ZX}
    \zxX{\beta} \ar[r,o'] & \zxX{}
  \end{ZX} after \begin{ZX}
    \zxX{\beta} \ar[r,o',use intersections] & \zxX{}
  \end{ZX} corrected manually \begin{ZX}
    \zxX{\beta} \ar[r,edge above, use intersections, o'={-=.2,L=.15}] & \zxX{}
  \end{ZX} or with our custom style \begin{ZX}
    \zxX{\beta} \ar[r,edge above, ui, o'] & \zxX{}
  \end{ZX}.
}
\end{codeexample}
Here are further comparisons:
\begin{codeexample}[]
{%
  \def\zxEnableIntersectionsNodes{}
  Before \begin{ZX}
    \zxX{} \ar[r,o'] & \zxX{}
  \end{ZX} ui \begin{ZX}
    \zxX{} \ar[r, ui, o'] & \zxX{}
  \end{ZX}. Before \begin{ZX}
    \zxX{\alpha} \ar[r,o'] & \zxZ{\beta}
  \end{ZX} ui \begin{ZX}
    \zxX{\alpha} \ar[r, ui, o'] & \zxZ{\beta}
  \end{ZX}. Before \begin{ZX}
    \zxX{\alpha+\beta} \ar[r,o'] & \zxZ{\alpha+\beta}
  \end{ZX} ui \begin{ZX}
    \zxX{\alpha+\beta} \ar[r, ui, o'] & \zxZ{\alpha+\beta}
  \end{ZX}.
}
\end{codeexample}
With |N|:
\begin{codeexample}[]
{%
  \def\zxEnableIntersectionsNodes{}
  \begin{ZX}
    \zxX{} \ar[rd,N]\\ & \zxX{}
  \end{ZX} $\Rightarrow $ ui \begin{ZX}
    \zxX{} \ar[rd,ui,N]\\ & \zxX{}
  \end{ZX}.
  \begin{ZX}
    \zxX{\alpha} \ar[rd,N]\\ & \zxX{}
  \end{ZX} $\Rightarrow $ ui \begin{ZX}
    \zxX{\alpha} \ar[rd,ui,N]\\ & \zxX{}
  \end{ZX}.
  \begin{ZX}
    \zxX{\alpha} \ar[rd,N]\\ & \zxX{\beta}
  \end{ZX} $\Rightarrow $ ui \begin{ZX}
    \zxX{\alpha} \ar[rd,ui,N]\\ & \zxX{\beta}
  \end{ZX}.
  \begin{ZX}
    \zxX{\alpha+\beta} \ar[rd,N]\\ & \zxX{\alpha+\beta}
  \end{ZX} $\Rightarrow $ ui \begin{ZX}
    \zxX{\alpha+\beta} \ar[rd,ui,N]\\ & \zxX{\alpha+\beta}
  \end{ZX}.
}
\end{codeexample}

With |N-|:
\begin{codeexample}[]
{%
  \def\zxEnableIntersectionsNodes{}
  \begin{ZX}
    \zxX{} \ar[rd,N-]\\ & \zxX{}
  \end{ZX} $\Rightarrow $ ui \begin{ZX}
    \zxX{} \ar[rd,ui,N-]\\ & \zxX{}
  \end{ZX}.
  \begin{ZX}
    \zxX{\alpha} \ar[rd,N-]\\ & \zxX{}
  \end{ZX} $\Rightarrow $ ui \begin{ZX}
    \zxX{\alpha} \ar[rd,ui,N-]\\ & \zxX{}
  \end{ZX}.
  \begin{ZX}
    \zxX{\alpha} \ar[rd,N-]\\ & \zxX{\beta}
  \end{ZX} $\Rightarrow $ ui \begin{ZX}
    \zxX{\alpha} \ar[rd,ui,N-]\\ & \zxX{\beta}
  \end{ZX}.
  \begin{ZX}
    \zxX{\alpha+\beta} \ar[rd,N-]\\ & \zxX{\alpha+\beta}
  \end{ZX} $\Rightarrow $ ui \begin{ZX}
    \zxX{\alpha+\beta} \ar[rd,ui,N-]\\ & \zxX{\alpha+\beta}
  \end{ZX}.
}
\end{codeexample}

With |<.|:
\begin{codeexample}[]
{%
  \def\zxEnableIntersectionsNodes{}
  \begin{ZX}
    \zxX{} \ar[rd,<.]\\ & \zxX{}
  \end{ZX} $\Rightarrow $ ui \begin{ZX}
    \zxX{} \ar[rd,ui,<.]\\ & \zxX{}
  \end{ZX}.
  \begin{ZX}
    \zxX{\alpha} \ar[rd,<.]\\ & \zxX{}
  \end{ZX} $\Rightarrow $ ui \begin{ZX}
    \zxX{\alpha} \ar[rd,ui,<.]\\ & \zxX{}
  \end{ZX}.
  \begin{ZX}
    \zxX{\alpha} \ar[rd,<.]\\ & \zxX{\beta}
  \end{ZX} $\Rightarrow $ ui \begin{ZX}
    \zxX{\alpha} \ar[rd,ui,<.]\\ & \zxX{\beta}
  \end{ZX}.
  \begin{ZX}
    \zxX{\alpha+\beta} \ar[rd,<.]\\ & \zxX{\alpha+\beta}
  \end{ZX} $\Rightarrow $ ui \begin{ZX}
    \zxX{\alpha+\beta} \ar[rd,ui,<.]\\ & \zxX{\alpha+\beta}
  \end{ZX}.
}
\end{codeexample}

With |NIN|:
\begin{codeexample}[]
{%
  \def\zxEnableIntersectionsNodes{}
  \begin{ZX}
    \zxX{} \ar[rd,NIN]\\ & \zxX{}
  \end{ZX} $\Rightarrow $ ui \begin{ZX}
    \zxX{} \ar[rd,ui,NIN]\\ & \zxX{}
  \end{ZX}.
  \begin{ZX}
    \zxX{\alpha} \ar[rd,NIN]\\ & \zxX{}
  \end{ZX} $\Rightarrow $ ui \begin{ZX}
    \zxX{\alpha} \ar[rd,ui,NIN]\\ & \zxX{}
  \end{ZX}.
  \begin{ZX}
    \zxX{\alpha} \ar[rd,NIN]\\ & \zxX{\beta}
  \end{ZX} $\Rightarrow $ ui \begin{ZX}
    \zxX{\alpha} \ar[rd,ui,NIN]\\ & \zxX{\beta}
  \end{ZX}.
  \begin{ZX}
    \zxX{\alpha+\beta} \ar[rd,NIN]\\ & \zxX{\alpha+\beta}
  \end{ZX} $\Rightarrow $ ui \begin{ZX}
    \zxX{\alpha+\beta} \ar[rd,ui,NIN]\\ & \zxX{\alpha+\beta}
  \end{ZX}.
}
\end{codeexample}

With this mode |s| behaves basically like |S| since the only difference is the anchor:
\begin{codeexample}[]
{%
  \def\zxEnableIntersectionsNodes{}
  \begin{ZX}
    \zxX{} \ar[rd,s]\\ & \zxX{}
  \end{ZX} $\Rightarrow $ ui \begin{ZX}
    \zxX{} \ar[rd,ui,s]\\ & \zxX{}
  \end{ZX}.
  \begin{ZX}
    \zxX{\alpha} \ar[rd,s]\\ & \zxX{}
  \end{ZX} $\Rightarrow $ ui \begin{ZX}
    \zxX{\alpha} \ar[rd,ui,s]\\ & \zxX{}
  \end{ZX}.
  \begin{ZX}
    \zxX{\alpha} \ar[rd,s]\\ & \zxX{\beta}
  \end{ZX} $\Rightarrow $ ui \begin{ZX}
    \zxX{\alpha} \ar[rd,ui,s]\\ & \zxX{\beta}
  \end{ZX}.
  \begin{ZX}
    \zxX{\alpha+\beta} \ar[rd,s]\\ & \zxX{\alpha+\beta}
  \end{ZX} $\Rightarrow $ ui \begin{ZX}
    \zxX{\alpha+\beta} \ar[rd,ui,s]\\ & \zxX{\alpha+\beta}
  \end{ZX}.
}
\end{codeexample}

With |s'|:
\begin{codeexample}[]
{%
  \def\zxEnableIntersectionsNodes{}
  \begin{ZX}
    \zxX{} \ar[rd,s']\\ & \zxX{}
  \end{ZX} $\Rightarrow $ ui \begin{ZX}
    \zxX{} \ar[rd,ui,s']\\ & \zxX{}
  \end{ZX}.
  \begin{ZX}
    \zxX{\alpha} \ar[rd,s']\\ & \zxX{}
  \end{ZX} $\Rightarrow $ ui \begin{ZX}
    \zxX{\alpha} \ar[rd,ui,s']\\ & \zxX{}
  \end{ZX}.
  \begin{ZX}
    \zxX{\alpha} \ar[rd,s']\\ & \zxX{\beta}
  \end{ZX} $\Rightarrow $ ui \begin{ZX}
    \zxX{\alpha} \ar[rd,ui,s']\\ & \zxX{\beta}
  \end{ZX}.
  \begin{ZX}
    \zxX{\alpha+\beta} \ar[rd,s']\\ & \zxX{\alpha+\beta}
  \end{ZX} $\Rightarrow $ ui \begin{ZX}
    \zxX{\alpha+\beta} \ar[rd,ui,s']\\ & \zxX{\alpha+\beta}
  \end{ZX}.
}
\end{codeexample}

With |-s|:
\begin{codeexample}[]
{%
  \def\zxEnableIntersectionsNodes{}
  \begin{ZX}
    \zxX{} \ar[rd,-s]\\ & \zxX{}
  \end{ZX} $\Rightarrow $ ui \begin{ZX}
    \zxX{} \ar[rd,ui,-s]\\ & \zxX{}
  \end{ZX}.
  \begin{ZX}
    \zxX{\alpha} \ar[rd,-s]\\ & \zxX{}
  \end{ZX} $\Rightarrow $ ui \begin{ZX}
    \zxX{\alpha} \ar[rd,ui,-s]\\ & \zxX{}
  \end{ZX}.
  \begin{ZX}
    \zxX{\alpha} \ar[rd,-s]\\ & \zxX{\beta}
  \end{ZX} $\Rightarrow $ ui \begin{ZX}
    \zxX{\alpha} \ar[rd,ui,-s]\\ & \zxX{\beta}
  \end{ZX}.
  \begin{ZX}
    \zxX{\alpha+\beta} \ar[rd,-s]\\ & \zxX{\alpha+\beta}
  \end{ZX} $\Rightarrow $ ui \begin{ZX}
    \zxX{\alpha+\beta} \ar[rd,ui,-s]\\ & \zxX{\alpha+\beta}
  \end{ZX}.
}
\end{codeexample}

With |SIS|:
\begin{codeexample}[]
{%
  \def\zxEnableIntersectionsNodes{}
  \begin{ZX}
    \zxX{} \ar[rd,SIS]\\ & \zxX{}
  \end{ZX} $\Rightarrow $ ui \begin{ZX}
    \zxX{} \ar[rd,ui,SIS]\\ & \zxX{}
  \end{ZX}.
  \begin{ZX}
    \zxX{\alpha} \ar[rd,SIS]\\ & \zxX{}
  \end{ZX} $\Rightarrow $ ui \begin{ZX}
    \zxX{\alpha} \ar[rd,ui,SIS]\\ & \zxX{}
  \end{ZX}.
  \begin{ZX}
    \zxX{\alpha} \ar[rd,SIS]\\ & \zxX{\beta}
  \end{ZX} $\Rightarrow $ ui \begin{ZX}
    \zxX{\alpha} \ar[rd,ui,SIS]\\ & \zxX{\beta}
  \end{ZX}.
  \begin{ZX}
    \zxX{\alpha+\beta} \ar[rd,SIS]\\ & \zxX{\alpha+\beta}
  \end{ZX} $\Rightarrow $ ui \begin{ZX}
    \zxX{\alpha+\beta} \ar[rd,ui,SIS]\\ & \zxX{\alpha+\beta}
  \end{ZX}.
}
\end{codeexample}

With |^.|:
\begin{codeexample}[]
{%
  \def\zxEnableIntersectionsNodes{}
  \begin{ZX}
    \zxX{} \ar[rd,^.]\\ & \zxX{}
  \end{ZX} $\Rightarrow $ ui \begin{ZX}
    \zxX{} \ar[rd,ui,^.]\\ & \zxX{}
  \end{ZX}.
  \begin{ZX}
    \zxX{\alpha} \ar[rd,^.]\\ & \zxX{}
  \end{ZX} $\Rightarrow $ ui \begin{ZX}
    \zxX{\alpha} \ar[rd,ui,^.]\\ & \zxX{}
  \end{ZX}.
  \begin{ZX}
    \zxX{\alpha} \ar[rd,^.]\\ & \zxX{\beta}
  \end{ZX} $\Rightarrow $ ui \begin{ZX}
    \zxX{\alpha} \ar[rd,ui,^.]\\ & \zxX{\beta}
  \end{ZX}.
  \begin{ZX}
    \zxX{\alpha+\beta} \ar[rd,^.]\\ & \zxX{\alpha+\beta}
  \end{ZX} $\Rightarrow $ ui \begin{ZX}
    \zxX{\alpha+\beta} \ar[rd,ui,^.]\\ & \zxX{\alpha+\beta}
  \end{ZX}.
}
\end{codeexample}

Now using our favorite drawing. Here we illustrate how we apply our custom style to all arrows.
\begin{codeexample}[width=0pt]
\def\zxEnableIntersectionsNodes{}%
\tikzset{
  /zx/user overlay wires/.style={
    ui, % Other method
  }
}
\begin{ZX}[
  execute at begin picture={%
    %%% Definition of long items (the goal is to have a small and readable matrix
    % (warning: macro can't have numbers in TeX. Also, make sure not to use existing names)
    \def\Zpifour{\zxFracZ[a=Zpi4]-{\pi}{4}}%
    \def\mypitwo{\zxFracX[a=mypi2]{\pi}{2}}%
  }
  ]
  %%% Matrix: in emacs "M-x align" is practical to automatically format it. a is for 'alias'
  & \zxN[a=n]{}  & \zxZ[a=xmiddle]{}       &            & \zxN[a=out1]{} \\
  \zxN[a=in1]{} & \Zpifour{}   & \zxX[a=Xdown]{}         & \mypitwo{} &                \\
  &              &                         &            & \zxN[a=out2]{} \\
  \zxN[a=in2]{} & \zxX[a=X1]{} & \zxZ[a=toprightpi]{\pi} &            & \zxN[a=out3]{}
  %%% Arrows
  % Column 1
  \ar[from=in1,to=X1,s]
  \ar[from=in2,to=Zpi4,.>]
  % Column 2
  \ar[from=X1,to=xmiddle,N']
  \ar[from=X1,to=toprightpi,H]
  \ar[from=Zpi4,to=n,C] \ar[from=n,to=xmiddle,wc]
  \ar[from=Zpi4,to=Xdown]
  % Column 3
  \ar[from=xmiddle,to=Xdown,C-]
  \ar[from=xmiddle,to=mypi2,'>]
  % Column 4
  \ar[from=toprightpi,to=mypi2,-N]
  \ar[from=mypi2,to=out1,<']
  \ar[from=mypi2,to=out2,<.]
  \ar[edge above,use intersections,from=Xdown,to=out3,<.]
\end{ZX}
\end{codeexample}

The same using |control points visible| to check if the good styles are applied:
\begin{codeexample}[width=0pt]
\def\zxEnableIntersectionsNodes{}%
\tikzset{
  /zx/user overlay wires/.style={
    ui, % Enable our style on all
    edge above, % For debugging
    control points visible % For debugging
  }
}
\def\zxDebugMode{}
\def\zxControlPointsVisible{}
\begin{ZX}[
  execute at begin picture={%
    %%% Definition of long items (the goal is to have a small and readable matrix
    % (warning: macro can't have numbers in TeX. Also, make sure not to use existing names)
    \def\Zpifour{\zxFracZ[a=Zpi4]-{\pi}{4}}%
    \def\mypitwo{\zxFracX[a=mypi2]{\pi}{2}}%
  }
  ]
  %%% Matrix: in emacs "M-x align" is practical to automatically format it. a is for 'alias'
  & \zxN[a=n]{}  & \zxZ[a=xmiddle]{}       &            & \zxN[a=out1]{} \\
  \zxN[a=in1]{} & \Zpifour{}   & \zxX[a=Xdown]{}         & \mypitwo{} &                \\
  &              &                         &            & \zxN[a=out2]{} \\
  \zxN[a=in2]{} & \zxX[a=X1]{} & \zxZ[a=toprightpi]{\pi} &            & \zxN[a=out3]{}
  %%% Arrows
  % Column 1
  \ar[from=in1,to=X1,s]
  \ar[from=in2,to=Zpi4,.>]
  % Column 2
  \ar[from=X1,to=xmiddle,N']
  \ar[from=X1,to=toprightpi,H]
  \ar[from=Zpi4,to=n,C] \ar[from=n,to=xmiddle,wc]
  \ar[from=Zpi4,to=Xdown]
  % Column 3
  \ar[from=xmiddle,to=Xdown,C-]
  \ar[from=xmiddle,to=mypi2,'>]
  % Column 4
  \ar[from=toprightpi,to=mypi2,-N]
  \ar[from=mypi2,to=out1,<']
  \ar[from=mypi2,to=out2,<.]
  \ar[edge above,use intersections,from=Xdown,to=out3,<.]
\end{ZX}
\end{codeexample}

Now, we can also globally enable the |ui| style and the intersection only for some kinds of arrows. For instance (here we enable it for all styles based on |N|, i.e.\ |*N*| and |>|-like wires). See that the |s| node is note using the intersections mode:
\begin{codeexample}[width=0pt]
\def\zxEnableIntersectionsNodes{}%
\tikzset{
  /zx/user overlay wires/.style={
    %% Nbase changes both N-like and >-like styles.
    %% Use N/.append to change only N-like.
    Nbase/.append style={%
      ui, % intersection only for arrows based on N (N and <)
    },
    edge above, % For debugging
    control points visible % For debugging
  }
}
\def\zxDebugMode{}
\def\zxControlPointsVisible{}
\begin{ZX}[
  execute at begin picture={%
    %%% Definition of long items (the goal is to have a small and readable matrix
    % (warning: macro can't have numbers in TeX. Also, make sure not to use existing names)
    \def\Zpifour{\zxFracZ[a=Zpi4]-{\pi}{4}}%
    \def\mypitwo{\zxFracX[a=mypi2]{\pi}{2}}%
  }
  ]
  %%% Matrix: in emacs "M-x align" is practical to automatically format it. a is for 'alias'
  & \zxN[a=n]{}  & \zxZ[a=xmiddle]{}       &            & \zxN[a=out1]{} \\
  \zxN[a=in1]{} & \Zpifour{}   & \zxX[a=Xdown]{}         & \mypitwo{} &                \\
  &              &                         &            & \zxN[a=out2]{} \\
  \zxN[a=in2]{} & \zxX[a=X1]{} & \zxZ[a=toprightpi]{\pi} &            & \zxN[a=out3]{}
  %%% Arrows
  % Column 1
  \ar[from=in1,to=X1,s]
  \ar[from=in2,to=Zpi4,.>]
  % Column 2
  \ar[from=X1,to=xmiddle,N']
  \ar[from=X1,to=toprightpi,H]
  \ar[from=Zpi4,to=n,C] \ar[from=n,to=xmiddle,wc]
  \ar[from=Zpi4,to=Xdown]
  % Column 3
  \ar[from=xmiddle,to=Xdown,C-]
  \ar[from=xmiddle,to=mypi2,'>]
  % Column 4
  \ar[from=toprightpi,to=mypi2,-N]
  \ar[from=mypi2,to=out1,<']
  \ar[from=mypi2,to=out2,<.]
  \ar[edge above,use intersections,from=Xdown,to=out3,<.]
\end{ZX}
\end{codeexample}

\end{pgfmanualentry}

\begin{pgfmanualentry}
  \def\extrakeytext{style, }
  \extractcommand\zxIntersectionLineBetweenStartEnd\@@
  \makeatletter% should not be letter for \@@... strange
  \extractkey/zx/wires definition/intersections mode between start end\@nil%
  \extractkey/zx/wires definition/intersections mode bezier controls\@nil%
  \makeatother
  \pgfmanualbody

Node that we also defined another intersection mechanism, in which the intersection with the node boundary is computed using the line that links the two fake centers of the starting and ending point. To use it, either define |\def\zxIntersectionLineBetweenStartEnd{}| or use the style |intersections between start end| (or to come back to the normal intersection mode |intersections bezier controls|). Note that this just changes the mode of computing intersections, but does not enable intersections, you still need to enable intersections as explained above (for instance using |use intersection|, or |ui| if you also want to load our style). Note however that we don't spent too much effort in this mode as the result is often not really appealing, in particular the |o| shapes, and therefore we designed no special style for it and made only a few tests.
\begin{codeexample}[]
{%
  \def\zxEnableIntersectionsNodes{}
  \begin{ZX}
    \zxX{\alpha} \ar[rd,N]\\ & \zxX{\beta}
  \end{ZX} $\Rightarrow $ between start end \begin{ZX}
    \zxX{\alpha} \ar[edge above,rd,ui,intersections mode between start end,N]\\ & \zxX{\beta}
  \end{ZX}.
  \begin{ZX}
    \zxX{\alpha} \ar[r,o'] \ar[r,o.] & \zxX{\beta}
  \end{ZX} $\Rightarrow $ between start end \begin{ZX}
    \zxX{\alpha} \ar[r,ui,intersections mode between start end,o']
                 \ar[r,ui,intersections mode between start end,o.] & \zxX{\beta}
  \end{ZX}.
}
\end{codeexample}
\end{pgfmanualentry}

\subsection{Nested diagrams}


If you consider this example:

\begin{codeexample}[]
Alone \begin{ZX}
  \zxX{} \rar \ar[r,o'] \ar[r,o.] & \zxZ{}
\end{ZX} %
in a diagram %
\begin{ZX}[math baseline=myb]
                     &[\zxwCol] \zxFracX-{\pi}{2} & \zxX{}
                                                    \rar
                                                    \ar[r,o']
                                                    \ar[r,o.] & \zxZ{} &[\zxwCol]\\
  \zxN[a=myb]{} \rar & \zxFracZ{\pi}{2} \rar & \zxFracX{\pi}{2} \rar & \zxFracZ{\pi}{2} \rar & \zxN{}
\end{ZX}
\end{codeexample}

You can see that the constant looks much wider in the second picture, due to the fact that the nodes below increase the column size. One solution I found for this problem is to use |savebox| to create your drawing \emph{before} the diagram, and then use the |fit| library to include it where you want in the matrix (see below for a command that does that automatically):

\begin{codeexample}[width=0pt]
%% Create a new box
\newsavebox{\myZXbox}
%% Save our small diagram.
%% Warning: on older versions, you needed to use \& instead of &
%% (the char '&' cause troubles in functions), but I fixed it 2022/02/09
\sbox{\myZXbox}{%
  % add \tikzset{external/optimize=false} if you use tikz "external" library %
  \zx{ % you may need 
    \zxX{} \rar \ar[r,o'] \ar[r,o.] & \zxZ{}
  }%
}

$x = \begin{ZX}[
  execute at end picture={
    %% Add our initial drawing at the end:
    \node[fit=(start)(end),yshift=-axis_height] {\usebox{\myZXbox}};
  },
  math baseline=myb]
                     &[\zxwCol] \zxFracX-{\pi}{2} & \zxN[a=start]{}       & \zxN[a=end]{}\\
  \zxN[a=myb]{} \rar & \zxFracZ{\pi}{2} \rar      & \zxFracX{\pi}{2} \rar & \zxFracZ{\pi}{2} \rar & \zxN{}
\end{ZX}$
\end{codeexample}

Note that this has the advantage of preserving the baseline of the big drawing. However, it is a bit cumbersome to use, so we provide here a wrapper that automatically does the following code (this has not been tested extensively, and may be subject to changes):

\begin{pgfmanualentry}
  \def\extrakeytext{style, }
  \extractcommand\zxSaveDiagram\marg{name with backslash}\opt{\oarg{zx options}}\marg{diagram with ampersand \textbackslash\&}\@@
  \makeatletter% should not be letter for \@@... strange
  \extractkey/zx/wires definition/use diagram=\marg{name with \textbackslash}\marg{(nodes)(to)(fit)}\@nil%
  \makeatother
  \pgfmanualbody
  Use |\zxSaveDiagram| to save and name a diagram (must be done before the diagram you want to insert this diagram into, also \textbf{do not forget the backslash before the name} (note that before 2022/09/02, you needed to use |\&| instead of |&|, but this has been fixed after 2022/02/09. In case you really care about backward compatibility, either download the sty file in your folder, or add |ampersand replacement=\&| in the options of the |\zxSaveDiagram| function and use |\&| as before). Then, |use diagram| to insert it inside a diagram (the second argument is a list of nodes given to the |fit| library):
\begin{codeexample}[width=0pt]
%%             v---- note the backslash
\zxSaveDiagram{\myZXconstant}{\zxX{} \rar \ar[r,o'] \ar[r,o.] & \zxZ{}}
$x = \begin{ZX}[use diagram={\myZXconstant}{(start)(end)}, math baseline=myb]
                     &[\zxwCol] \zxFracX-{\pi}{2} & \zxN[a=start]{}       & \zxN[a=end]{}\\
  \zxN[a=myb]{} \rar & \zxFracZ{\pi}{2} \rar      & \zxFracX{\pi}{2} \rar & \zxFracZ{\pi}{2} \rar & \zxN{}
\end{ZX}$
\end{codeexample}
Note that if you need more space to insert the drawing, you can use |\zxN+[a=start,minimum width=2cm]{}| instead of |\zxN|.
\end{pgfmanualentry}

Sometimes, you may also find useful to stack diagram (for instance because the matrix of the first diagram is not related to the matrix of the second diagram), or position multiple diagrams relative to each others. You can use arrays to do that, but it will not preserve the baseline. Another solution is to put the |ZX| environment inside nodes contained in |tikzpicture| (I know that tikz does not like nesting\dots{} but it works nice for what I tried. I will also try to provide an helper function to do that later). For example here we use it to add the constants below the second diagram:
\begin{codeexample}[vbox]
\begin{equation*}
  \begin{ZX}
    &[\zxwCol]       &                                      &[\zxwCol] \zxN{} \ar[dd,3 vdots] \\[\zxNCol]
    \zxN{} \rar & \zxZ{\pi} \rar & \zxX{\alpha} \ar[ru,N'-] \ar[rd,N.-] &                        \\[\zxNCol]
    &                &                                      & \zxN{}
  \end{ZX} =
  \begin{tikzpicture}[
    baseline=(A.base)
    ]
    \node[inner sep=0pt](A){%
      \begin{ZX}
        &[\zxwCol]                              & \zxZ{\pi} \ar[dd,3 vdots] \rar &[\zxwCol] \zxN{} \\[\zxNCol]
        \zxN{} \rar & \zxX-{\alpha} \ar[ru,N'-] \ar[rd,N.-] &                                        \\[\zxNCol]
        &                                       & \zxZ{\pi} \rar & \zxN{}
      \end{ZX}
    };
    \node[inner sep=0pt,below=\zxDefaultColumnSep of A](B){
      \begin{ZX}
        \zxOneOverSqrtTwo{} & \zxX{\alpha} \rar & \zxZ{\pi}
      \end{ZX}
    };
  \end{tikzpicture}
\end{equation*}
\end{codeexample}

\subsection{Further customization}

You can further customize your drawings using any functionality from \tikzname{} and |tikz-cd| (but it is of course at your own risk). For instance, we can change the separation between rows and/or columns for a whole picture (but prefer to use |zx row sep| as it also updates pre-configured column spaces):
\begin{codeexample}[width=0pt]
  \begin{ZX}[row sep=1mm]
                &                                         &                        & & \zxZ{\pi} \\
    \zxN{} \rar & \zxX{} \ar[rd,(.] \ar[urrr,(',H]        &                        & &  & \zxN{} \\
                &                                         & \zxZ{} \ar[rd,s.] \rar &
       \zxFracX{\pi}{2} \ar[uur,('] \ar[rru,<'] \ar[rr] &  & \zxN{} \\
    \zxN{} \rar & \zxFracZ-{\pi}{4} \ar[ru,('] \ar[rr,o.] &            & \zxX{} \ar[rr] &  & \zxN{}
  \end{ZX}
\end{codeexample}
You can also use the tikz |between origins| option in order to specify the distance between the center of the rows and not between their borders. This is particularly practical when gates have different heights, or if you want to compare two diagram with different content (you might also want to use something like |mbr=1.5| to set the math baseline between two lines):
\begin{codeexample}[width=0pt]
$\begin{ZX}[circuit, row sep={.6cm,between origins}]
\rar & \zxCross{} \rar \dar & \\
\rar & \zxCross{} \rar      & 
\end{ZX} =
\begin{ZX}[circuit, row sep={.6cm,between origins}]
\rar & \zxN{} \ar[rd,s] & \zxN{} \rar & \\
\rar & \zxN{} \ar[ru,s] & \zxN{} \rar & 
\end{ZX}$
\end{codeexample}

Or we can define our own style to create blocks:
{\catcode`\|=12 % Ensures | is not anymore \verb|...|
\begin{codeexample}[width=0pt]
{ % \usetikzlibrary{shadows}
  \tikzset{
    my bloc/.style={
      anchor=center,
      inner sep=2pt,
      inner xsep=.7em,
      minimum height=3em,
      draw,
      thick,
      fill=blue!10!white,
      double copy shadow={opacity=.5},tape,
    }
  }
  \zx{|[my bloc]| f \rar &[1mm] |[my bloc]| g \rar &[1mm] \zxZ{\alpha} \rar & \zxNone{}}
}
\end{codeexample}
}
We can also use for instance |fit|, |alias|, |execute at end picture| and layers (the user can use |background| for things behind the drawing, |box| for special nodes above the drawings (like multi-column nodes, see below), and |foreground| which is even higher) to do something like that:
{\catcode`\|=12 % Ensures | is not anymore \verb|...|
\begin{codeexample}[width=3cm]
% \usetikzlibrary{fit}
\begin{ZX}[
  execute at end picture={
    \node[
      inner sep=2pt,
      node on layer=background, %% Ensure the node is behind the drawing
      rounded corners,
      draw=blue,
      dashed,
      fill=blue!50!white,
      opacity=.5,
      fit=(cnot1)(cnot2), %% position of the node, thanks fit library
      "\textsc{cnot}" {above, inner sep=1mm} %% Adds label, thanks quote library. Not sure why, inner sep is set to 0 when using tikz "external" library.
    ] {};
  }
  ]
  \zxNone{} \rar & \zxZ[alias=cnot1]{} \dar \rar & \zxNone{}\\
  \zxNone{} \rar & \zxX[alias=cnot2]{} \rar      & \zxNone{}\\
\end{ZX}
\end{codeexample}
Because this code is quite lengthy and useful, we provide in \cref{subsec:decoration} a shorter syntax.
}

You can also use other libraries, in particular |nfold| can be practical to insert many wires at once (note that you need a recent version since it was introduced in CTAN 2023, or you need to manually install the library):
{\catcode`\|=12 % Ensures | is not anymore \verb|...|
\begin{codeexample}[width=0pt]
% \usetikzlibrary{nfold} % needs very recent CTAN > 2023, or manually copy the .tex files
\begin{ZX}[circuit]
 \rar[scaling nfold=5]
 & \zxGate{X} \rar[rd, line join=round, double distance=2pt, scaling nfold=3,--|] & \\
 &                                                                                & \zxGate{Y}
\end{ZX}
\end{codeexample}
}


\section{Future works}

There is surely many things to improve in this library, and given how young it is there is surely many undiscovered bugs. So feel free to propose ideas or report bugs \mylink{https://github.com/leo-colisson/zx-calculus/issues}{one the github page}. The intersections code is also quite slow, so I would be curious to check if I can optimize it (the first goal was to make it work). I should also work on the compatibility with tikzit (basically just write tikz configuration files that you can just use and document how to use tikzit with it), or even write a dedicated graphical tool (why not based on tikzit itself, or \mylink{https://tikzcd.yichuanshen.de/}{this tool}). I also want to find a nicer way to merge cells (for now I propose to use the |fit| library but it's not very robust against overlays) and to nest ZX diagrams. And of course fix typos in the documentation and write other styles, including notations not specific to ZX-calculus. Feel free to submit Pull Requests to solve that, or to submit bug reports to explain uncovered use-cases!

\section{Acknowledgement}

I'm very grateful of course to everybody that worked on these amazing field which made diagramatic quantum computing possible, and to the many StackExchange users that helped me to understand a bit more \LaTeX{} and \tikzname{} (sorry, I don't want to risk an incomplete list, but many thanks to egreg, David Carlisle, cfr, percusse, Andrew Stacey, Henri Menke, SebGlav, Qrrbrbirlbel\dots{}). I also thank Robert Booth for making me realize how my old style was ugly, and for giving advices on how to improve it. Thanks to John van de Wetering and Alastair Kay (author of Quantikz), whose styles have also been a source of inspiration~\cite{van20_ZXcalculusWorkingQuantum}, and to Augusto Stoffel for the great tikzcd package on which this library is built.

\section{Changelog}

\begin{itemize}
\item 2023/09/26:
  Many updates in the past months:
  \begin{itemize}
  \item Custom nodes are made easy
  \item Multi-gates nodes and many circuit-related functions
  \item Added |post arrow style if start node| and other similar commands
  \item updated the doc to use the latest version of robust-externalize that is much simpler to use now\dots
  \item Some nodes can also now be usable outside tikzcd, but I've not tried (I should provide more options for this).
  \item Group gates
  \item 
  \end{itemize}
\item 2022/02/09:
  \begin{itemize}
  \item Added compatibility with external tikz library
  \item More robust handling of |&|: align and macros does not need |\&| anymore.
  \item |\&| in |\zxSaveDiagram| is replaced with |&|. This introduces a small backward incompatibility, but hey, I said it was still subject to changes :-)
  \end{itemize}
\end{itemize}

\section{TODO}
\begin{itemize}
\item I think that some anchors are not properly configured in stuff like |\zxBox| etc, so a nice sanity check should be done
\item Clean the code, eventually
\item Consider subnodes as anchors (fake center etc)
\item more circuit related stuff
\item multigate invisible element
\item curly braces made easy
\item lstick
\end{itemize}

\printindex

\printbibliography[heading=bibintoc]

\end{document}