summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/source/latex/witharrows/witharrows.dtx
blob: 5dd68ff86aba07277db1ee19173afe369528521b (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
% \iffalse meta-comment
%
% Copyright (C) 2017 by F. Pantigny
% -----------------------------------
%
% This file may be distributed and/or modified under the
% conditions of the LaTeX Project Public License, either version 1.3
% of this license or (at your option) any later version.
% The latest version of this license is in:
%
% http://www.latex-project.org/lppl.txt
%
% and version 1.3 or later is part of all distributions of LaTeX
% version 2005/12/01 or later.
%
% \fi
% \iffalse
\def\myfileversion{1.2}
\def\myfiledate{2017/11/29}
%
%
%<*batchfile>
\begingroup
\input l3docstrip.tex
\keepsilent
\usedir{tex/latex/witharrows}
\preamble

Copyright (C) 2017 by F. Pantigny
-----------------------------------

This file may be distributed and/or modified under the
conditions of the LaTeX Project Public License, either version 1.3
of this license or (at your option) any later version.
The latest version of this license is in:

http://www.latex-project.org/lppl.txt

and version 1.3 or later is part of all distributions of LaTeX
version 2005/12/01 or later.

\endpreamble
\askforoverwritefalse
\endgroup
%</batchfile>
%
%<@@=wa>
%<*driver>
\documentclass{l3doc} % load fancyvrb, amsmath, array, color, etc.
\usepackage{xltxtra}
\usepackage{lmodern}
\usepackage{geometry}
\usepackage[dvipsnames]{xcolor} % color is already loaded with l3doc (?)
\geometry{left=2.8cm,right=2.8cm,top=2.5cm,bottom=2.5cm,papersize={21cm,29.7cm}}
\usepackage{witharrows}
\usepackage{mathtools}
\usepackage{amsfonts}
\usepackage{stmaryrd}
\NewDocumentEnvironment {scope} {} {} {}
\def\interitem{\vskip 7mm plus 2 mm minus 3mm}          
\def\emphase#1{{\color{RoyalPurple}#1}}
\fvset{commandchars=\~\#\@,formatcom={\color{gray}}}
\DeclareMathOperator{\re}{Re}
\parindent 0pt
\DisableCrossrefs
\begin{document}
\DocInput{witharrows.dtx}
\end{document}
%</driver>
% \fi 
% \title{The package \pkg{witharrows}\thanks{This document corresponds to the version~\myfileversion\space of \pkg{witharrows},
% at the date of~\myfiledate.}} \author{F. Pantigny \\ \texttt{fpantigny@wanadoo.fr}}
%
% \maketitle
%
% \begin{abstract}
% The LaTeX package \pkg{witharrows} gives an environment |{WithArrows}| which is similar to environment
% |{aligned}| of \pkg{amsmath} (and \pkg{mathtools}) but gives the possibility to draw arrows on the right side of
% the alignment. These arrows are usually used to give explanations concerning the mathematical calculus presented.
% \end{abstract}
%
%
% \vskip1cm
% This package can be used with |xelatex|, |lualatex|, |pdflatex| but also by the classical workflow
% |latex|-|dvips|-|ps2pdf| (or Adobe Distiller). Two compilations may be necessary. This package requires the
% packages \pkg{expl3}, \pkg{xparse}, \pkg{footnote}\footnote{The package footnote is used to extract the notes
% from the environments \texttt{\{WithArrows\}}.} and \pkg{tikz}. The following Tikz libraries are also required:
% \pkg{calc}, \pkg{arrows.meta} and \pkg{bending}.
%
% \bigskip
% This package gives an environment |{WithArrows}| to construct alignments of equations with arrows for the
% explanations on the right side:
% %
% \begin{Verbatim}
% $\begin{WithArrows}
% A & = (a+1)^2 ~emphase#\Arrow{we expand}@ \\
%   & = a^2 + 2a + 1  
% \end{WithArrows}$
% \end{Verbatim}
%
% $\begin{WithArrows}
% A & = (a+1)^2 \Arrow{we expand} \\
%   & = a^2 + 2a + 1 
% \end{WithArrows}$
%
%
% \medskip
% The arrow has been drawn with the command |\Arrow| on the line from which it starts. The command |\Arrow| can be
% used anywhere on the line but the best way is to put it at the end.
%
%
% \section{Options for the shape of the arrows}
%
% The commande |\Arrow| has several options. These options can be put between square brackets, before, or after the
% mandatory argument.
%
% The option |jump| gives the number\footnote{It's not possible to give a non-positive value to \texttt{jump}. See
% below the way to draw an arrow which goes backwards.} of lines the arrow must jump (the default value is, of
% course,~$1$).
%
% 
% \begin{Verbatim}
% $\begin{WithArrows}
% A & = \bigl((a+b)+1\bigr)^2 \Arrow[~emphase#jump=2@]{we expand} \\
%   & = (a+b)^2 + 2(a+b) +1 \\
%   & = a^2 + 2ab + b^2 + 2a + 2b +1 
% \end{WithArrows}$
% \end{Verbatim}
%
% 
%
% $\begin{WithArrows}
% A & = \bigl((a+b)+1\bigr)^2 \Arrow[jump=2]{we expand} \\
%   & = (a+b)^2 + 2(a+b) +1 \\
%   & = a^2 + 2ab + b^2 + 2a + 2b +1 
% \end{WithArrows}$
%
%
% \interitem
% It's possible to put several arrows which start from the same line.
% %
% \begin{Verbatim}
% $\begin{WithArrows}
% A & = \bigl((a+b)+1\bigr)^2 ~emphase#\Arrow{}\Arrow{}[jump=2]@ \\
%   & = (a+b)^2 + 2(a+b) +1 \\
%   & = a^2 + 2ab + b^2 + 2a + 2b +1 
% \end{WithArrows}$
% \end{Verbatim}
%
% $\begin{WithArrows}
% A & = \bigl((a+b)+1\bigr)^2 \Arrow{}\Arrow{}[jump=2] \\
%   & = (a+b)^2 + 2(a+b) +1 \\
%   & = a^2 + 2ab + b^2 + 2a + 2b +1 
% \end{WithArrows}$
%
% \interitem
% The option |xoffset| shift the arrows to the right (we usually don't want the arrows to be stucked on the text).
% The default value of |xoffset| is $3$~mm.
% 
% \begin{Verbatim}
% $\begin{WithArrows}
% A & = \bigl((a+b)+1\bigr)^2 
% \Arrow[~emphase#xoffset=1cm@]{with \texttt{xoffset=1cm}} \\
%   & = (a+b)^2 + 2(a+b) +1 
% \end{WithArrows}$
% \end{Verbatim}
%
% $\begin{WithArrows}
% A & = \bigl((a+b)+1\bigr)^2 
% \Arrow[xoffset=1cm]{with \texttt{xoffset=1cm}} \\
%   & = (a+b)^2 + 2(a+b) +1 
% \end{WithArrows}$
%
%
% \interitem 
% The arrows are drawn with Tikz. That's why the command |\Arrow| has an option |tikz| which can be used to give to
% the arrow (in fact, the command |\path| of Tikz) the options proposed by Tikz for such an arrow. The following
% example gives an blue thick arrow.
% %
% \begin{Verbatim}
% $\begin{WithArrows}
% A & = (a+1)^2 \Arrow[~emphase#tikz={blue,thick}@]{we expand} \\
%   & = a^2 + 2a + 1 
% \end{WithArrows}$
% \end{Verbatim}
%
% $\begin{WithArrows}
% A & = (a+1)^2 \Arrow[tikz={blue,thick}]{we expand} \\
%   & = a^2 + 2a + 1 
% \end{WithArrows}$
%
% \interitem
% It's also possible to change the arrowheads. For example, we can draw an arrow which goes backwards with the Tikz
% option~|<-|.
% %
% \begin{Verbatim}
% $\begin{WithArrows}
% A & = (a+1)^2 \Arrow~emphase#[tikz=<-]@{we factorize} \\
%   & = a^2 + 2a + 1 
% \end{WithArrows}$
% \end{Verbatim}
%
% $\begin{WithArrows}
% A & = (a+1)^2 \Arrow[tikz=<-]{we factorize} \\
%   & = a^2 + 2a + 1 
% \end{WithArrows}$
%
% \interitem
% It's also possible to suppress both tips of the arrow with the Tikz option |-|.
% %
% \begin{Verbatim}
% $\begin{WithArrows}
% A & = (a+1)^2 \Arrow[~emphase#tikz=-@]{very classical} \\
%   & = a^2 + 2a + 1 
% \end{WithArrows}$
% \end{Verbatim}
%
% $\begin{WithArrows}
% A & = (a+1)^2 \Arrow[tikz=-]{very classical} \\
%   & = a^2 + 2a + 1 
% \end{WithArrows}$
%
% \interitem
% In order to have straight arrows instead of curved ones, we must use the Tikz option ``|bend left = 0|''.
% %
% \begin{Verbatim}
% $\begin{WithArrows}
% A & = (a+1)^2 \Arrow~emphase#[tikz={bend left=0}]@{we expand} \\
%   & = a^2 + 2a + 1 
% \end{WithArrows}$
% \end{Verbatim}
%
% $\begin{WithArrows}
% A & = (a+1)^2 \Arrow[tikz={bend left=0}]{we expand} \\
%   & = a^2 + 2a + 1 
% \end{WithArrows}$
%
% \interitem
% One of the most useful options is ``|text width|'' to control the width of the text associated to the arrow. 
% %
% \begin{Verbatim}
% $\begin{WithArrows}
% A & = \bigl((a+b)+1\bigr)^2 
% \Arrow[jump=2,~emphase#tikz={text width=5.3cm}@]{We have done...} \\
%   & = (a+b)^2 + 2(a+b) +1 \\
%   & = a^2 + 2ab + b^2 + 2a + 2b +1 
% \end{WithArrows}$
% \end{Verbatim}
%
% $\begin{WithArrows}
% A & = \bigl((a+b)+1\bigr)^2 
% \Arrow[jump=2,tikz={text width=5.3cm}]{We have done a two-stages expansion but it would have been clever
% to expand with the multinomial theorem.} \\
%   & = (a+b)^2 + 2(a+b) +1 \\
%   & = a^2 + 2ab + b^2 + 2a + 2b +1 
% \end{WithArrows}$
%
% \interitem
% If we want to change the font of the text associated to the arrow, we can, of course, put a command like
% |\bfseries|, |\large| or |\sffamily| at the beginning of the text. But, by default, the texts are composed with a
% combination of |\small| and |\itshape|. When adding |\bfseries| at the beginning of the text, we won't suppress
% the |\small| and the |\itshape| and we will consequently have a text in a bold, italic and small font.
% %
% \begin{Verbatim}
% $\begin{WithArrows}
% A & = (a+1)^2 \Arrow{~emphase#\bfseries@ we expand} \\
%   & = a^2 + 2a + 1 
% \end{WithArrows}$
% \end{Verbatim}
%
% $\begin{WithArrows}
% A & = (a+1)^2 \Arrow{\bfseries we expand} \\
%   & = a^2 + 2a + 1 
% \end{WithArrows}$
%
% \interitem 
% If we put commands |\\| in the text to force newlines, a command of font placed in the beginning of the text will
% have effect only until the first command |\\| (like in an environment |{tabular}|). That's why Tikz gives a option
% |font| to modify the font of the whole text. Nevertheless, if we use the option |tikz={font={\bfseries}}|, the
% default specification of |\small| and |\itshape| will be overwritten.
% %
% \begin{Verbatim}
% $\begin{WithArrows}
% A & = (a+1)^2 \Arrow[~emphase#tikz={font={\bfseries}}@]{we expand} \\
%   & = a^2 + 2a + 1 
% \end{WithArrows}$
% \end{Verbatim}
%
% $\begin{WithArrows}
% A & = (a+1)^2 \Arrow[tikz={font={\bfseries}}]{we expand} \\
%   & = a^2 + 2a + 1 
% \end{WithArrows}$
%
% \medskip
% If we want exactly the same result as previously, we have to give to the option |font| the value
% |{\itshape\small\bfseries}|.
%
%
% \interitem 
% Almost all the options can be given directly to the environment |{WithArrows}| (between square brackets). In this
% case, they apply to all the arrows of the environment.\footnote{They also apply to the nested environments
% \texttt{\{WithArrows\}} with the notable exception of \texttt{interline}.}
% %
% \begin{Verbatim}
% $\begin{WithArrows}[~emphase#tikz=blue@]
% A & = \bigl((a+b)+1\bigr)^2 \Arrow{First expansion.} \\
%   & = (a+b)^2 + 2(a+b) +1 \Arrow{Second expansion.} \\
%   & = a^2 + 2ab + b^2 + 2a + 2b +1 
% \end{WithArrows}$
% \end{Verbatim}
%
% $\begin{WithArrows}[tikz=blue]
% A & = \bigl((a+b)+1\bigr)^2 \Arrow{First expansion.} \\
%   & = (a+b)^2 + 2(a+b) +1 \Arrow{Second expansion.} \\
%   & = a^2 + 2ab + b^2 + 2a + 2b +1 
% \end{WithArrows}$
%
%
% \interitem
% The environment |{WithArrows}| has an option |displaystyle|. With this option, all the elements are composed in
% |\displaystyle| (like in an environment |{aligned}| of \pkg{amsmath}).
%
% \medskip
% Without the option |displaystyle|:
% %
% \begin{Verbatim}
% $\begin{WithArrows}
% \int_0^1 (x+1)^2 dx 
% & = \int_0^1 (x^2+2x+1) dx
% \Arrow{linearity of integration}     \\
% & = \int_0^1 x^2 dx + 2 \int_0^1 x dx + \int_0^1 dx \\
% & = \frac13 + 2\frac12 + 1 \\
% & = \frac73
% \end{WithArrows}$
% \end{Verbatim}
%
% $\begin{WithArrows}
% \int_0^1 (x+1)^2 dx 
% & = \int_0^1 (x^2+2x+1) dx
% \Arrow{linearity of integration}     \\
% & = \int_0^1 x^2 dx + 2 \int_0^1 x dx + \int_0^1 dx \\
% & = \frac13 + 2\frac12 + 1 \\
% & = \frac73
% \end{WithArrows}$
%
%
% \medskip
% The same example with the option |displaystyle|:\par\nobreak
%
% $\begin{WithArrows}[displaystyle]
% \int_0^1 (x+1)^2 dx 
% & = \int_0^1 (x^2+2x+1) dx
% \Arrow{linearity of integration}     \\
% & = \int_0^1 x^2 dx + 2 \int_0^1 x dx + \int_0^1 dx \\
% & = \frac13 + 2\frac12 + 1 \\
% & = \frac73
% \end{WithArrows}$
%
%
% \interitem 
% Almost all the options can also be set at the document level with the command |\WithArrowsOptions|. In this case,
% the scope of the declarations is the current TeX group (these declarations are ``semi-global''). For example, if
% we want all the environments |{WithArrows}| composed in |\displaystyle| with blue arrows, we can write
% |\WithArrowsOptions{displaystyle,tikz=blue}|.\footnote{It's also possible to give the options directly when
% loading the package, \emph{i.e.} with the command \texttt{\string\usepackage} in the preamble.}
% %
% \begin{Verbatim}
% ~emphase#\WithArrowsOptions{displaystyle,tikz=blue}@
% $\begin{WithArrows}
% \sum_{i=1}^n (x_i+1)^2 
% & = \sum_{i=1}^n (x_i^2+2x_i+1) \Arrow{by linearity}\\
% & = \sum_{i=1}^n x_i^2 + 2\sum_{i=1}^nx_i+ n
% \end{WithArrows}$
% \end{Verbatim}
%
% \begin{scope}
% \WithArrowsOptions{displaystyle,tikz=blue}
% $\begin{WithArrows}
% \sum_{i=1}^n (x_i+1)^2 
% & = \sum_{i=1}^n (x_i^2+2x_i+1) \Arrow{by linearity}\\
% & = \sum_{i=1}^n x_i^2 + 2\sum_{i=1}^nx_i+ n
% \end{WithArrows}$
% \end{scope}
%
%
% \interitem
% The command |\Arrow| is recognized only in the environments |{WithArrows}|. If we have a command |\Arrow|
% previously defined, it's possible to go on using it outside the environments |{WithArrows}|.
%
% However, a previouly defined command |\Arrow| may still be useful in an environment |{WithArrows}|. If we want to
% use it in such an environment, it's possible to change the name of the command |\Arrow| of the package
% \pkg{witharrows}: there is an option |CommandName| for this purpose. The new name of the command must be given to
% the option \emph{without} the leading backslash.
% %
% \begin{Verbatim}
% \newcommand{\Arrow}{\longmapsto}
% $\begin{WithArrows}[~emphase#CommandName=Explanation@]
% f & = \bigl(x \Arrow (x+1)^2\bigr)
% ~emphase#\Explanation{we work directly on fonctions}@\\
% & = \bigl(x \Arrow x^2+2x+1\bigr)
% \end{WithArrows}$
% \end{Verbatim}
% %
% \begin{scope}
% \newcommand{\Arrow}{\longmapsto}
% $\begin{WithArrows}[CommandName=Explanation]
% f & = \bigl(x \Arrow (x+1)^2\bigr)
% \Explanation{we work directly on fonctions}\\
% & = \bigl(x \Arrow x^2+2x+1\bigr)
% \end{WithArrows}$
% \end{scope}
%
%
% \interitem 
% It's possible to use directly the nodes created by |{WithArrows}| with explicit Tikz instructions (in order, for
% example, to draw something that can't be drawn with the command |\Arrow|). That's why a style for the tips of the
% arrows has be created: |TipsOfWithArrows|. By using this style, we will have homogeneous tips for the arrows of
% the document.
%
% Therefore, if we want to modify the tips of the arrows of |{WithArrows}|, we have to modify the style
% |TipsOfWithArrows|.
% %
% \begin{Verbatim}
% \tikzset{TipsOfWithArrows/.style= { > = {Latex[scale=1.2,bend]}} }
% \end{Verbatim}
%
% The names of the Tikz nodes created by \pkg{witharrows} in the whole document are explained below.
%
%
% \section{Precise positioning of the arrows}
%
%
% The environment |{WithArrows}| defines, during the composition of the array, two series of nodes materialized in
% red in the following example.\footnote{The option \texttt{shownodes} can be used to materialize the nodes.}
%
% \smallskip
% $\begin{WithArrows}[displaystyle,shownodes]
% I
% & = \int_{\frac{\pi}4}^0 \ln\Bigl(1+\tan\left(\tfrac{\pi}4-u\right)\Bigr)(-d u) \\
% & = \int_0^{\frac{\pi}4} \ln\Bigl(1+\tan\left(\tfrac{\pi}4-u\right)\Bigr)d u \\
% & = \int_0^{\frac{\pi}4}\ln\left(1+\frac{1-\tan u}{1+\tan u}\right)\, d u \\
% & =\int_0^{\frac{\pi}4}\ln\left(\frac{1+\tan u+1-\tan u}{1+\tan u}\right) d u \\
% & =\int_0^{\frac{\pi}4} \ln\left(\frac2{1+\tan u}\right)\, d u\\
% & =\int_0^{\frac{\pi}4}\bigl(\ln2-\ln(1+\tan u)\bigr)\, d u \\
% & =\frac{\pi}4\ln2-\int_0^{\frac{\pi}4}\ln(1+\tan u)\, d u  \\
% & =\frac{\pi}4\ln2-I 
% \end{WithArrows}$
%
% \bigskip
% The nodes of the left are at the end of each line of text. These nodes will be called \emph{left nodes}. The
% nodes of the right side are aligned vertically on the right side of the array. These nodes will be called
% \emph{right nodes}.
%
% By default, the arrows use the right nodes. We will say that they are in |rr| mode ($r$ for \emph{right}). These
% arrows are |vertical| (we will say that an arrow is \emph{vertical} when its two ends have the same abscissa).
%
%
% \smallskip
% However, it's possible to use the left nodes, or a combination of left and right nodes, with one of the options
% |lr|, |rl| and |ll| ($l$ for \emph{left}). Those arrows are, usually, not vertical.
%
%
% Therefore
% $\begin{WithArrows}[displaystyle]
% I
% & = \int_{\frac{\pi}4}^0 \ln\Bigl(1+\tan\left(\tfrac{\pi}4-u\right)\Bigr)(-d u) 
% \Arrow[lr]{This arrow uses the \texttt{lr} option.}\\
% & = \int_0^{\frac{\pi}4} \ln\Bigl(1+\tan\left(\tfrac{\pi}4-u\right)\Bigr)d u \\
% & = \int_0^{\frac{\pi}4}\ln\left(1+\frac{1-\tan u}{1+\tan u}\right)\, d u \\
% & =\int_0^{\frac{\pi}4}\ln\left(\frac{1+\tan u+1-\tan u}{1+\tan u}\right) d u 
% \Arrow[ll,jump=2,tikz={text width = 5cm}]{This arrow uses a \texttt{ll} option and a \texttt{jump} equal to $2$}\\
% & =\int_0^{\frac{\pi}4} \ln\left(\frac2{1+\tan u}\right)\, d u\\
% & =\int_0^{\frac{\pi}4}\bigl(\ln2-\ln(1+\tan u)\bigr)\, d u \\
% & =\frac{\pi}4\ln2-\int_0^{\frac{\pi}4}\ln(1+\tan u)\, d u  \\
% & =\frac{\pi}4\ln2-I 
% \end{WithArrows}$
%
%
%
% \interitem
% There is also an option called \texttt{i} ($i$ for \emph{intermediate}). With this option, the arrow is vertical
% and at the leftmost position.
%
% \begin{Verbatim}
% $\begin{WithArrows}
% (a+b)(a+ib)(a-b)(a-ib) 
% & = (a+b)(a-b)\cdot(a+ib)(a-ib) \\
% & = (a^2-b^2)(a^2+b^2) \Arrow~emphase#[i]@{because $(x-y)(x+y)=x^2-y^2$}\\
% & = a^4-b^4 
% \end{WithArrows}$
% \end{Verbatim}
%
% $\begin{WithArrows}
% (a+b)(a+ib)(a-b)(a-ib) 
% & = (a+b)(a-b)\cdot(a+ib)(a-ib) \\
% & = (a^2-b^2)(a^2+b^2) \Arrow[i]{because $(x-y)(x+y)=x^2-y^2$}\\
% & = a^4-b^4 
% \end{WithArrows}$
%
%
% \interitem 
% The environment |{WithArrows}| gives also a |group| option. With this option, \emph{all} the arrows of the
% environment are grouped on a same vertical line and at a leftmost position.
% %
% \begin{Verbatim}[formatcom=\small\color{gray}]
% $\begin{WithArrows}[~emphase#displaystyle,group@]
% 2xy'-3y=\sqrt x
% & \Longleftrightarrow 2x(K'y_0+Ky_0')-3Ky_0 = \sqrt x \\
% & \Longleftrightarrow 2xK'y_0 + K(2xy_0'-3y_0) = \sqrt x \\
% & \Longleftrightarrow 2x K'y_0 = \sqrt x \Arrow{...}\\
% ...
% \end{WithArrows}$
% \end{Verbatim}
%
%
% $\begin{WithArrows}[displaystyle,group]
% 2xy'-3y=\sqrt x
% & \Longleftrightarrow 2x(K'y_0+Ky_0')-3Ky_0 = \sqrt x \\
% & \Longleftrightarrow 2xK'y_0 + K(2xy_0'-3y_0) = \sqrt x \\
% & \Longleftrightarrow 2x K'y_0 = \sqrt x \Arrow{We replace $y_0$ by its value.}\\
% & \Longleftrightarrow 2xK'x^{\frac32} = x^{\frac12} \Arrow{simplification of the $x$}\\
% & \Longleftrightarrow K' = \tfrac1{2x^2} \Arrow{antiderivation}\\
% & \Longleftrightarrow K = -\tfrac1{2x} 
% \end{WithArrows}$
%
%
% \bigskip
% The environment |{WithArrows}| gives also a |groups| option (with a \emph{s} in the name). With this option, the
% arrows are divided into several ``groups''. Each group is a set of connected\footnote{More precisely : for each
% arrow $a$, we note $i(a)$ the number of its initial line and $f(a)$ the number of its final line ; for two arrows
% $a$ and $b$, we say that $a \sim b$ when
% $\llbracket i(a),f(a)\rrbracket \cap \llbracket i(b),f(b)\rrbracket \neq \emptyset$ ; the groups are the
% equivalence classes of the transitive closure of $\sim$.} arrows. All the arrows of a given group are grouped on
% a same vertical line and at a leftmost position.
%
% \bigskip
% $\begin{WithArrows}[groups]
% A & = B \Arrow{one} \\
%   & = C+D \Arrow{two} \\
%   & = D' \\
%   & = E+F+G+H+I \\
%   & = K + L + M \Arrow{three}\\
%   & = N \Arrow{four}\\
%   & = O
% \end{WithArrows}$
%
% \bigskip
% If desired, the option |group| or the option |groups| can be given to the command |\WithArrowsOptions| so that it will become
% the default value. In this case, it's still possible to come back to the default behaviour for a given
% environment |{WithArrows}| with the option |rr|: |\begin{WithArrows}{rr}|
%
% \section{Comparison with the environment \{aligned\}}
%
%
%
% |{WithArrows}| bears similarities with the environment |{aligned}| of the extension \pkg{amsmath}. These are only
% similarities because |{WithArrows}| has not been written upon the environment |{aligned}|.\footnote{In fact, it's
% possible to use the package \pkg{witharrows} without the package \pkg{amsmath}.}
%
% \interitem
% As in the environments of \pkg{amsmath}, it's possible to change the spacing between two given lines with the
% option of the command |\\| of end of line (it's also possible to use |\\*| but is has exactly the same effect as
% |\\| since an environment |{WithArrows}| is always unbreakable).
% %
% \begin{Verbatim}
% $\begin{WithArrows}
% A & = (a+1)^2 \Arrow{we expand} ~emphase#\\[2ex]@
%   & = a^2 + 2a + 1 
% \end{WithArrows}$
% \end{Verbatim}
%
% $\begin{WithArrows}
% A & = (a+1)^2 \Arrow{we expand} \\*[2ex]
% \noalign{\vspace{3mm}}
%   & = a^2 + 2a + 1 
% \end{WithArrows}$
%
%
% \interitem 
% In the environments of \pkg{amsmath} (or \pkg{mathtools}), the spacing between lines is fixed by a parameter
% called |\jot| (it's a dimension and not a skip). That's also the case for the environment |{WithArrows}|. An
% option |jot| has been given to the environment |{WithArrows}| in order to change the value of this parameter
% |\jot| for an given environment.\footnote{It's also possible to change \texttt{\string\jot} with the environment
% \texttt{\{spreadlines\}} of \pkg{mathtools}.}
% %
% \begin{Verbatim}
% $\begin{WithArrows}[displaystyle,~emphase#jot=2ex@]
% F & = \frac12G     \Arrow{we expand}\\
%   & = H + \frac12K \Arrow{we go on}\\
%   & = K 
% \end{WithArrows}$
% \end{Verbatim}
%
% $\begin{WithArrows}[displaystyle,jot=2ex]
% F & = \frac12G     \Arrow{we expand}\\
%   & = H + \frac12K \Arrow{we go on}\\
%   & = K 
% \end{WithArrows}$
%
% \bigskip
% However, this new value of |\jot| will also be used in other alignments included in the
% environment~|{WithArrows}|:
% %
% \begin{Verbatim}
% $\begin{WithArrows}[jot=2ex]
% \varphi(x,y) = 0  & \Leftrightarrow (x+y)^2 + (x+2y)^2 = 0 
% \Arrow{$x$ and $y$ are real}\\
% & \Leftrightarrow \left\{
% \begin{aligned}
% x+y & = 0 \\
% x+2y & = 0 \\
% \end{aligned}
% \right.
% \end{WithArrows}$
% \end{Verbatim}
%
%
% $\begin{WithArrows}[jot=2ex]
% \varphi(x,y) = 0  & \Leftrightarrow (x+y)^2 + (x+2y)^2 = 0 
% \Arrow{$x$ and $y$ are real}\\
% & \Leftrightarrow \left\{
% \begin{aligned}
% x+y & = 0 \\
% x+2y & = 0 \\
% \end{aligned}
% \right.
% \end{WithArrows}$
%
% \bigskip
% Maybe this doesn't correspond to the desired outcome. That's why an option |interline| is proposed. It's possible
% to use a skip (=glue) for this option.
% %
% \begin{Verbatim}
% $\begin{WithArrows}[~emphase#interline=2ex@]
% \varphi(x,y) = 0  & \Leftrightarrow (x+y)^2 + (x+2y)^2 = 0 
% \Arrow{$x$ and $y$ are real}\\
% & \Leftrightarrow \left\{
% \begin{aligned}
% x+y & = 0 \\
% x+2y & = 0 \\
% \end{aligned}
% \right.
% \end{WithArrows}$
% \end{Verbatim}
%
%
% $\begin{WithArrows}[interline=2ex]
% \varphi(x,y) = 0  & \Leftrightarrow (x+y)^2 + (x+2y)^2 = 0 
% \Arrow{$x$ and $y$ are real}\\
% & \Leftrightarrow \left\{
% \begin{aligned}
% x+y & = 0 \\
% x+2y & = 0 \\
% \end{aligned}
% \right.
% \end{WithArrows}$
%
%
% \interitem
% Like the environment |{aligned}|, |{WithArrows}| has an option of placement which can assume the values |t|, |c|
% or |b|. However, the default value is not |c| but |t|. If desired, it's possible to have the |c| value as the
% default with the command |\WithArrowsOptions{c}| at the beginning of the document.
% %
% \begin{Verbatim}
% ~emphase#Et donc\enskip@
% $\begin{WithArrows}
% A & = (a+1)^2 \Arrow{we expand} \\
%   & = a^2 + 2a + 1 
% \end{WithArrows}$
% \end{Verbatim}
%
% So\enskip 
% $\begin{WithArrows}
% A & = (a+1)^2 \Arrow{we expand} \\
%   & = a^2 + 2a + 1 
% \end{WithArrows}$
%
% \bigskip
% The value |c| may be useful, for example, if we want to add curly braces:
%
% \smallskip
% \begin{Verbatim}
% On pose\enskip $~emphase#\left\{@
% \begin{WithArrows}[~emphase#c@]
% f(x) & = 3x^3+2x^2-x+4 
% \Arrow[tikz=-]{both are polynoms}\\
% g(x) & = 5x^2-5x+6
% \end{WithArrows}
% ~emphase#\right.@$
% \end{Verbatim}
%
%
% On pose\enskip $\left\{
% \begin{WithArrows}[c]
% f(x) & = 3x^3+2x^2-x+4 
% \Arrow[tikz=-]{both are polynoms}\\
% g(x) & = 5x^2-5x+6
% \end{WithArrows}
% \right.$
%
%
% \interitem
% Unlike |{aligned}|, the environment |{WithArrows}| uses |\textstyle| by default.
%
% Once again, it's possible to change this behaviour with |\WithArrowsOptions|:
%
% \quad |\WithArrowsOptions{displaystyle}|.
%
%
% \smallskip
% The following example is composed with |{aligned}|:\par\nobreak
%
% \smallskip
% $\left\{
% \begin{aligned}
% \sum_{i=1}^n (x_i+1)^2  
% & = \sum_{i=1}^n (x_i^2 + 2x_i+1) \\
% & = \sum_{i=1}^n x_i^2 + 2 \sum_{i=1}^nx_i + n 
% \end{aligned}
% \right.$
%
%
% \medskip 
% The following is composed with |{WithArrows}[c,displaystyle]|. The results are stricly identical.\footnote{In
% versions of \texttt{amsmath} older than the 5~nov.~2016, an thin space was added on the left of an environment
% \texttt{\{aligned\}}. The new versions do not add this space and neither do \texttt{\{WithArrows\}}.}\par\nobreak
%
% \smallskip
% $\left\{
% \begin{WithArrows}[c,displaystyle]
% \sum_{i=1}^n (x_i+1)^2 
% & = \sum_{i=1}^n (x_i^2 + 2x_i+1) \\
% & = \sum_{i=1}^n x_i^2 + 2 \sum_{i=1}^nx_i + n 
% \end{WithArrows}
% \right.$
%
%
%
%
% \section{Examples}
%
% \subsection{With only one column}
%
% It's possible to use the environment |{WithArrows}| with making use of the left column only, or the right column
% only.
% %
% \begin{Verbatim}
% $\begin{WithArrows}
% &f(x) \ge g(x) \Arrow{by squaring both sides} \\
% & f(x)^2 \ge g(x)^2 \Arrow{by moving to left side} \\
% & f(x)^2 - g(x)^2 \ge 0 
% \end{WithArrows}$
% \end{Verbatim}
%
% $\begin{WithArrows}
% &f(x) \ge g(x) \Arrow{by squaring both sides} \\
% & f(x)^2 \ge g(x)^2 \Arrow{by moving to left side} \\
% & f(x)^2 - g(x)^2 \ge 0 
% \end{WithArrows}$
%
%
% \subsection{MoveEqLeft}
%
% It's possible to use |\MoveEqLeft| of \pkg{mathtools} (if we don't want ampersand on the firt line):
% %
% \begin{Verbatim}[formatcom=\small\color{gray}]
% $\begin{WithArrows}[jot=2mm]
% ~emphase#\MoveEqLeft@ \arccos(x) = \arcsin \frac45 + \arcsin \frac5{13} 
% \Arrow{because both are in $[-\frac{\pi}2,\frac{\pi}2]$} \\
% & \Leftrightarrow x = \sin\left(\arcsin\frac45 + \arcsin\frac5{13}\right) \\
% & \Leftrightarrow x = \frac45\cos\arcsin\frac5{13} + \frac5{13} \cos\arcsin\frac45 
% \Arrow{$\forall x \in [-1,1], \cos(\arcsin x) = \sqrt{1-x^2}$} \\
% & \Leftrightarrow x = \frac45\sqrt{1-\bigl(\frac5{13}\bigr)^2}
% + \frac5{13}\sqrt{1-\bigl(\frac45\bigr)^2} \\
% \end{WithArrows}$
% \end{Verbatim}
%
%
% \medskip
% $\begin{WithArrows}[jot=2mm]
% \MoveEqLeft \arccos(x) = \arcsin \frac45 + \arcsin \frac5{13} 
% \Arrow{because both are in $[-\frac{\pi}2,\frac{\pi}2]$} \\
% & \Leftrightarrow x = \sin\left(\arcsin\frac45 + \arcsin\frac5{13}\right) \\
% & \Leftrightarrow x = \frac45\cos\arcsin\frac5{13} + \frac5{13} \cos\arcsin\frac45 
% \Arrow{$\forall x \in [-1,1], \cos(\arcsin x) = \sqrt{1-x^2}$} \\
% & \Leftrightarrow x = \frac45\sqrt{1-\bigl(\frac5{13}\bigr)^2}
% + \frac5{13}\sqrt{1-\bigl(\frac45\bigr)^2} \\
% \end{WithArrows}$
%
%
%
% \subsection{Nested environments}
%
%
% The environments |{WithArrows}| can be nested. In this case, the options given to the encompassing environment
% applies also to the inner ones (with the notable exception of |interline|).
% %
% \begin{Verbatim}[formatcom=\small\color{gray}]
% $~emphase#\begin{WithArrows}@[tikz=blue]
% \varphi(x,y)=0
%   & \Leftrightarrow (x+2y)^2+(2x+4y)^2 = 0 \Arrow{the numbers are real}\\
%   & \Leftrightarrow
%   \left\{~emphase#\begin{WithArrows}@[c]
%   x+2y & = 0 \\
%   2x+4y & = 0 
%   ~emphase#\end{WithArrows}@\right. \\
%   & \Leftrightarrow
%   \left\{~emphase#\begin{WithArrows}@[c]
%   x+2y & = 0 \Arrow[tikz=-]{the same équation}\\
%   x+2y & = 0 
%   ~emphase#\end{WithArrows}@\right. \\
%   & \Leftrightarrow x+2y=0 
% ~emphase#\end{WithArrows}@$
% \end{Verbatim}
%
% $\begin{WithArrows}[tikz=blue]
% \varphi(x,y)=0
%   & \Leftrightarrow (x+2y)^2+(2x+4y)^2 = 0 \Arrow{the numbers are real}\\
%   & \Leftrightarrow
%   \left\{\begin{WithArrows}[c]
%   x+2y & = 0 \\
%   2x+4y & = 0 
%   \end{WithArrows}\right. \\
%   & \Leftrightarrow
%   \left\{\begin{WithArrows}[c]
%   x+2y & = 0 \Arrow[tikz=-]{the same equation}\\
%   x+2y & = 0 
%   \end{WithArrows}\right. \\
%   & \Leftrightarrow x+2y=0 
% \end{WithArrows}$
%
%
%
% \subsection{A loop flow}
%
% Here is an example with a loop flow.\par\nobreak
% %
% \begin{Verbatim}[formatcom=\small\color{gray}]
% $\begin{WithArrows}[tikz={font={\tiny}}]
% a.\;& f \text{ est continuous on } E 
% \Arrow{(1)}\Arrow[tikz=<-,jump=4,xoffset=1cm]{(5)}\\
% b.\;& f \text{ est continuous in } 0 
% \Arrow{(2)}\\
% c.\;& f \text{ is bounded on the unit sphere} 
% \Arrow{(3)}\\
% d.\;& \exists K > 0\quad \forall x \in E\quad \|f(x)\| \le K \|x\| 
% \Arrow{(4)}\\
% e.\;& f \text{ is lipschitzian} 
% \end{WithArrows}$
% \end{Verbatim}
%
% $\begin{WithArrows}[tikz={font={\tiny}}]
% a.\;& f \text{ est continuous on } E 
% \Arrow{(1)}\Arrow[tikz=<-,jump=4,xoffset=1cm]{(5)}\\
% b.\;& f \text{ est continuous in } 0 
% \Arrow{(2)}\\
% c.\;& f \text{ is bounded on the unit sphere} 
% \Arrow{(3)}\\
% d.\;& \exists K > 0\quad \forall x \in E\quad \|f(x)\| \le K \|x\| 
% \Arrow{(4)}\\
% e.\;& f \text{ is lipschitzian} 
% \end{WithArrows}$
%
%
% \subsection{Automatic numerotation}
%
% The option |font| of Tikz contains in fact a list of tokens which will be placed at the beginning of the text.
%
% These tokens can be true commands for a change of font (like |\bfseries| or |\sffamily|) but can also be, in
% fact, any TeX command.
%
% In the following example, the argument of |font| is the token list |\tiny\counter| where |\counter| is a command
% which increments a counter previously defined and displays its new value. Thus, the arrows are automatically
% numbered.
% %
% \begin{Verbatim}[formatcom=\small\color{gray}]
% \newcounter{MyCounter}
% \newcommand{\counter}{\stepcounter{MyCounter}\theMyCounter.}
% $\begin{WithArrows}[tikz={~emphase#font={\tiny\counter}@}]
% A(x) 
% & = B(x) \Arrow{} \\
% & = C(x) \Arrow{} \\
% & = C(x) \Arrow{} \\
% & = E(x) \Arrow{} \\
% & = F(x) \Arrow{} \\
% & = G(x)   
% \end{WithArrows}$
% \end{Verbatim}
%
% \begin{scope}
% \newcounter{MyCounter}
% \newcommand{\counter}{\stepcounter{MyCounter}\theMyCounter.}
% $\begin{WithArrows}[tikz={font={\tiny\counter}}]
% A(x) 
% & = B(x) \Arrow{} \\
% & = C(x) \Arrow{} \\
% & = C(x) \Arrow{} \\
% & = E(x) \Arrow{} \\
% & = F(x) \Arrow{} \\
% & = G(x)   
% \end{WithArrows}$
% \end{scope}
%
%
% \section{An technical remark about the names of the nodes}
%
% Environments |{WithArrows}| can be nested, and, therefore, we have a ``nesting tree'' for the environments
% |{WithArrows}| of the whole document. This nesting tree is used to give a unique name to each node in the
% document.
%
% \smallskip 
% The Tikz name of a node created by \pkg{witharrows} is prefixed by |wa-|. Then, we have a list of numbers which
% give the position in the nesting tree and the number of the line in the environment. At the end, we have the
% suffixe |l| for a ``left node'' and |r| for a ``right node''.
% 
% \smallskip
% For illustrative purposes, we give an example of nested environments |{WithArrows}|, and, for each ``right
% node'', the name of that node.\footnote{There is an option \texttt{shownodenames} to show the names of these nodes.}
% 
% \medskip
% \[\begin{WithArrows}[shownodes,shownodenames]
% A & \vartriangleleft B+B+B+B+B+B+B+B+B+B+B+B+B \\
% & \vartriangleleft \left\{
% \begin{WithArrows}[c]
% C & \vartriangleleft D \\
% E & \vartriangleleft F 
% \end{WithArrows}
% \right. \\
%  & \vartriangleleft 
% \left\{
% \begin{WithArrows}[c]
% G & \vartriangleleft H+H+H+H+H+H+H \\
% I & \vartriangleleft 
% \left\{
% \begin{WithArrows}
% J &\vartriangleleft K \\
% L &\vartriangleleft M 
% \end{WithArrows}
% \right.
% \end{WithArrows}
% \right. \\
%  & \vartriangleleft 
% \left\{
% \begin{WithArrows}[c]
% N & \vartriangleleft O \\
% P & \vartriangleleft Q 
% \end{WithArrows}
% \right.
% \end{WithArrows}\]
%
% \bigskip
% The command |\WithArrowsLastEnv| gives the number of the last environment of level~$0$. For example, we can draw
% an arrow from the node \texttt{wa-\WithArrowsLastEnv-1} to the node \texttt{wa-\WithArrowsLastEnv-2-1} with the
% following Tikz command.\footnote{The command \texttt{\string\WithArrowsLastEnv} is \emph{fully expandable} and
% thus, can be used directly in the name of a Tikz node.}
%
% \begin{Verbatim}
% \begin{tikzpicture}[remember picture,overlay,->,TipsOfWithArrows]
% \draw (wa-\WithArrowsLastEnv-1-r) to (wa-\WithArrowsLastEnv-2-1-r) ;
% \end{tikzpicture}
% \end{Verbatim}
%
% \section{Implementation}
%
% \subsection{Declaration of the package and extensions loaded}
%
%
% First, \pkg{tikz} and some Tikz libraries are loaded before the |\ProvidesExplPackage|.
% They are loaded this way because |\usetikzlibrary| in |expl3| code fails.\footnote{cf.
% |tex.stackexchange.com/questions/57424/using-of-usetikzlibrary-in-an-expl3-package-fails|} 
% 
%    \begin{macrocode}
\RequirePackage{tikz}
\usetikzlibrary{calc,arrows.meta,bending}
%    \end{macrocode}
%
% \bigskip
% Then, we can give the traditionnal declaration of a package written with |expl3|:
%    \begin{macrocode}
\RequirePackage{l3keys2e}
\ProvidesExplPackage
  {witharrows}
  {\myfiledate}
  {\myfileversion}
  {Draws arrows for explanations on the right}
%    \end{macrocode}
%
% \bigskip
% The package \pkg{xparse} will be used to define the environment |{WithArrows}| and the document-level commands
% (|\Arrow|, |\WithArrowsOptions| ans |\WithArrowsLastEnv|).
%    \begin{macrocode}
\RequirePackage{xparse}
%    \end{macrocode}
%
% \bigskip
% The package \pkg{footnote} will be used to extract footnotes of the environments |{WithArrows}| via the pair
% |\savenotes|-|\spewnotes|.
%    \begin{macrocode}
\RequirePackage{footnote}
%    \end{macrocode}
%
% \subsection{Some technical definitions}
%
% We define a Tikz style |@@_node_style| for the nodes that will be created in the |\halign|.
%    \begin{macrocode}
\tikzstyle{@@_node_style}=[rectangle,
                           inner~sep = 0 pt,
                           minimum~height = 3 pt,
                           minimum~width = 0pt,
                           red,
                           \bool_if:NT \l_@@_shownodes_bool {draw}]
%    \end{macrocode}
% The color of the nodes is red, but in fact, the nodes will be drawn only when the option |shownodes| is used
% (this option is useful for debugging).
%
% \bigskip
% We also define a style for the tips of arrow. The final user of the extension \pkg{witharrows} will use this
% style if he wants to draw an arrow directly with a Tikz command in his document (probably using the Tikz nodes
% created by |{WithArrows}| in the |\halign|).
%    \begin{macrocode}
\tikzset{TipsOfWithArrows/.style= { > = {Straight~Barb[scale=1.2,bend]}} }
%    \end{macrocode}
%
% \bigskip
% In order to increase the interline in the environments |{WithArrows}|, we will use the command |\spread@equation|
% of \pkg{amsmath}. When used, this command becomes no-op (in the current TeX group). Therefore, it will be
% possible to use the environments of \pkg{amsmath} (e.g. |{aligned}|) in an environment |{WithArrows}|.
% 
% Nevertheless, we want the extension \pkg{witharrows} available without \pkg{amsmath}. That's why we give a
% definition of |\spread@equation| (this definition will be loaded only if \pkg{amsmath} --- or \pkg{mathtools} --- has
% not been loaded yet).
%    \begin{macrocode}
\cs_if_free:NT \spread@equation
    {\cs_set:Npn \spread@equation{\openup\jot   
                                  \cs_set_eq:NN \spread@equation \prg_do_nothing}}
%    \end{macrocode}
%
%
% \subsection{Variables}
%
% \bigskip
% The following sequence is the position of the last environment |{WithArrows}| in the tree of the nested
% environments |{WithArrows}|. 
%    \begin{macrocode}
\seq_new:N \g_@@_position_in_the_tree_seq
\seq_gput_right:Nn \g_@@_position_in_the_tree_seq 1
%    \end{macrocode}
%
% \bigskip
% The following counter will give the number of the last environment |{WithArrows}| of level~$0$. This
% counter will be used only in the definition of |\WithArrowsLastEnv|.
%    \begin{macrocode}
\int_new:N \g_@@_last_env_int
%    \end{macrocode}
%
% \bigskip
% The following counter will be use to specify the level when we set keys: $0$~(global level as with
% |\WithArrowsOptions|), $1$~(environment level with the |\begin{WithArrows}|) or $2$~(local level with the
% |\Arrow| command).
%    \begin{macrocode}
\int_new:N \l_@@_level_int
%    \end{macrocode}
% \bigskip
% The following skip (=glue) is the vertical space inserted between two lines of the |\halign|.
%    \begin{macrocode}
\skip_new:N \l_@@_interline_skip
%    \end{macrocode}
%
% \bigskip
% If the following flag is raised, then the user can use more than two columns.
%    \begin{macrocode}
\bool_new:N \l_@@_MoreColumns_bool
%    \end{macrocode}
%
% \bigskip
% The following integer indicates the position of the box that will be created: 0 (=|t|=|\vtop|), 1~(=|c|=|\vcenter|) or 2 (=|b|=|\vbox|).
%    \begin{macrocode}
\int_new:N \l_@@_pos_env_int 
%    \end{macrocode}
%
% \bigskip
% The integer |\l_@@_pos_arrows_int| indicates the position of the arrows with the following code:
%
% \begin{center}
% \begin{tabular}{|l|c|c|c|c|c|c|c|}
% \hline
% option                 & |rr| & |ll| & |rl| & |lr| & |i| & |group| & |groups| \\
% \hline
% |\l_@@_pos_arrows_int| & $0$  & $1$  & $2$  & $3$  & $4$ & $5$     & $6$      \\
% \hline
% \end{tabular}
% \end{center}
% 
%    \begin{macrocode}
\int_new:N \l_@@_pos_arrows_int
%    \end{macrocode}
%
% \medskip
% When we scan a list of options, we want to be able to raise an error if two options of position of the arrows
% are present. That's why we keep the code of the first option of position in a variable called
% |\l_@@_previous_pos_arrows_int|. This variable will be set to $-1$ each time we start the scanning of a list of options.
%
%    \begin{macrocode}
\int_new:N \l_@@_previous_pos_arrows_int
%    \end{macrocode}
%
% \bigskip
% The following dimension is the value of the translation of the whole arrow to the right (of course, it's a
% dimension and not a skip).
%    \begin{macrocode}
\dim_new:N \l_@@_xoffset_dim 
\dim_set:Nn \l_@@_xoffset_dim {3mm}
%    \end{macrocode}
%
% \bigskip
% If the following flag is raised, the nodes will be drawn in red (useful for debugging).
%    \begin{macrocode}
\bool_new:N \l_@@_shownodes_bool
%    \end{macrocode}
%
% \bigskip
% If the following flag is raised, the name of the ``right nodes'' will be shown in the document (useful for
% debugging). 
%    \begin{macrocode}
\bool_new:N \l_@@_shownodenames_bool
%    \end{macrocode}
% 
% \bigskip
% If the following flag is raised, the elements of the |\halign| will be composed with |\displaystyle|:
%    \begin{macrocode}
\bool_new:N \l_@@_displaystyle_bool
%    \end{macrocode}
%
% \bigskip
% The following token list variable will contains the Tikz options used to draw the arrows.
%    \begin{macrocode}
\tl_clear_new:N \l_@@_options_tikz_tl
%    \end{macrocode}
%
% At each possible level for the options (\emph{global}, \emph{environment} or \emph{local}: see below), the new
% values will be appended on the right of this token list.
%
% \bigskip
% The dimension |\g_@@_x_dim| will be used to compute the $x$-value for some verticals arrows when one of the
% options |i|, |group| and |groups| (values 4, 5 and 6 of |\l_@@_pos_arrows_int|) is used.
%    \begin{macrocode}
\dim_new:N \g_@@_x_dim
%    \end{macrocode}
%
% \bigskip
% In the |\halign| of an environment |{WithArrows}|, we will have to use three counters:
% \begin{itemize}
% \item |\g_@@_arrow_int| to count the arrows created in the environment ;
% \item |\g_@@_line_int| to count the lines of the |\halign| ;
% \item |\g_@@_line_bis_int| to count the lines of the |\halign| which have a second column.\footnote{This counter
% is used in order to raise an error if there is a line without the second column (such an situation could raise a
% \textsc{pgf} error for an undefined node).}
% \end{itemize}
%
% These three counters will be incremented in a cell of the |\halign| and, therefore, the incrementation must be
% global. However, we want to be able to include a |{WithArrows}| in another |{WithArrows}|. To do so, we must
% restore the previous value of these counters at the end of an environment |{WithArrows}| and we decide to manage
% a stack for each of these counters.
%    \begin{macrocode}
\seq_new:N \g_@@_arrow_int_seq
\int_new:N \g_@@_arrow_int
\seq_new:N \g_@@_line_int_seq
\int_new:N \g_@@_line_int
\seq_new:N \g_@@_line_bis_int_seq
\int_new:N \g_@@_line_bis_int
%    \end{macrocode}

%
% \subsection{The definition of the options}
% There are three levels where options can be set:
% \begin{itemize}
% \item with |\WithArrowsOptions{...}|: this level will be called \emph{global} level (number~0);
% \item with |\begin{WithArrows}[...]|: this level will be called \emph{environment} level (number~1);
% \item with |\Arrow[...]|: this level will be called \emph{local} level (number~2).
% \end{itemize}
%
% The level is specified in the variable |\l_@@_level_int| and the code attached to the options can use this
% information to alter their actions.
%
% \bigskip
% We begin with a first submodule which will be loaded only at the global or the environment level.
%
% \medskip
% The options |t|, |c| and |b| indicate if we will create a |\vtop|, a |\vcenter| of a |\vbox|. This information is
% stored in the variable |\l_@@_pos_env_int|.
%    \begin{macrocode}
\keys_define:nn {WithArrows/GlobalOrEnv}
   {  t   .code:n            = {\int_set:Nn \l_@@_pos_env_int 0},
      t   .value_forbidden:n = true,
      c   .code:n            = {\int_set:Nn \l_@@_pos_env_int 1},
      c   .value_forbidden:n = true,
      b   .code:n            = {\int_set:Nn \l_@@_pos_env_int 2},
      b   .value_forbidden:n = true,
%    \end{macrocode}
%
% \bigskip
% Usually, the number of columns in a |{WithArrows}| environment is limited to 2. Nevertheless, it's possible to
% have more columns with the option |MoreColumns|.
%    \begin{macrocode}
      MoreColumns .bool_set:N        = \l_@@_MoreColumns_bool,
      MoreColumns .value_forbidden:n = true,
%    \end{macrocode}
%
% \bigskip
% If the user wants to give a new name to the |\Arrow| command (and the name |\Arrow| remains free).
%    \begin{macrocode}
      CommandName .tl_set:N         = \l_@@_CommandName_tl,
      CommandName .initial:n        = {Arrow},
      CommandName .value_required:n = true,
%    \end{macrocode}
%
% \bigskip
% With the option |displaystyle|, the environments will be composed in |\displaystyle|.
%    \begin{macrocode}
      displaystyle .bool_set:N     = \l_@@_displaystyle_bool,
%    \end{macrocode}
%
% \bigskip
% With the option |shownodes|, the nodes will be drawn in red (useful only for debugging).
%    \begin{macrocode}
      shownodes .bool_set:N        = \l_@@_shownodes_bool,
%    \end{macrocode}
% 
% \bigskip
% With the option |shownodenames|, the name of the ``right nodes'' will be written in the document (useful only
% for debugging). 
%    \begin{macrocode}
      shownodenames .bool_set:N    = \l_@@_shownodenames_bool,
%    \end{macrocode}
%
% \bigskip
% With the option |group|, \emph{all} the arrows of the environment are vertical with the same abscissa and at a
% leftmost position.
%    \begin{macrocode}
      group    .code:n    = {\int_compare:nNnT \l_@@_previous_pos_arrows_int > {-1}
                                    {\msg_error:nn {witharrows} 
                                                   {Two~options~are~incompatible}}
                             \int_set:Nn \l_@@_previous_pos_arrows_int 5
                             \int_set:Nn \l_@@_pos_arrows_int 5},
      group    .value_forbidden:n = true,
%    \end{macrocode}
%
% \bigskip
% With the option |groups| (with a \emph{s}), the arrows of the environment are divided in groups by an argument of
% connexity, and, in each group, the arrows are vertical with the same abscissa and at a leftmost position. When
% the option |group| or |groups| is used, it's not possible to an other option of position like |ll|, |lr|, etc.
% for a individual key.
%    \begin{macrocode}
      groups   .code:n   = {\int_compare:nNnT \l_@@_previous_pos_arrows_int > {-1}
                                   {\msg_error:nn {witharrows} 
                                                  {Two~options~are~incompatible}}
                            \int_set:Nn \l_@@_previous_pos_arrows_int 6
                            \int_set:Nn \l_@@_pos_arrows_int 6},
      groups   .value_forbidden:n = true}
%    \end{macrocode}
%
%
%
% \bigskip
% Then we define the main module called |WithArrows| which will be loaded at all the levels.
%
% \medskip
% The option |tikz| gives Tikz parameters that will be given to the arrow when it is drawn (more precisely, the
% parameters will be given to the command |\path| of Tikz).
%    \begin{macrocode}
\keys_define:nn {WithArrows}
     {tikz     .code:n            = {\tl_put_right:Nn \l_@@_options_tikz_tl {,#1}},
      tikz     .value_required:n  = true,
%    \end{macrocode}
%
% \bigskip
% The other options are for the position of the arrows. The treatment is the same for the options |ll|, |rr|, |lr|,
% |lr| and |i| and that's why a dedicated fonction |\@@_analyze_option_position:n| has been written (see below).
%    \begin{macrocode}
      rr       .value_forbidden:n = true,
      rr       .code:n            = {\@@_analyze_option_position:n 0},
      ll       .value_forbidden:n = true,
      ll       .code:n            = {\@@_analyze_option_position:n 1},
      rl       .value_forbidden:n = true,
      rl       .code:n            = {\@@_analyze_option_position:n 2},
      lr       .value_forbidden:n = true,
      lr       .code:n            = {\@@_analyze_option_position:n 3},
      i        .value_forbidden:n = true,
      i        .code:n            = {\@@_analyze_option_position:n 4},
%    \end{macrocode}
%
% \bigskip
% The option |xoffset| change the $x$-offset of the arrows (towards the right). It's a dimension and not a skip.
% It's not possible to change the value of this parameter for a individual arrow if the option |group| or the
% option |groups| is used.
%    \begin{macrocode}
      xoffset  .code:n  = {\bool_if:nTF {\int_compare_p:nNn \l_@@_level_int = 2 &&
                                         \int_compare_p:nNn \l_@@_pos_arrows_int > 4}
                               {\msg_error:nn {witharrows}
                                              {Option~incompatible~with~"group(s)"}}
                               {\dim_set:Nn \l_@@_xoffset_dim {#1}}},
      xoffset  .value_required:n  = true,
%    \end{macrocode}
%
% \bigskip
% The option |jot| exists for compatibility. It changes directly the value of the parameter |\jot|, which is a
% LaTeX parameter and not a parameter specific to \pkg{witharrows}. It's allowed only at the level of the
% environment (maybe we should suppress completely this option in the future).
%    \begin{macrocode}
      jot       .code:n     = {\int_compare:nNnTF \l_@@_level_int = 1
                                  {\dim_set:Nn \jot {#1}}
                                  {\msg_error:nn {witharrows} {Option~will~be~ignored} }}, 
      jot       .value_required:n  = true,
%    \end{macrocode}
%
% \bigskip
% The option |interline| gives the vertical skip (=glue) inserted between two lines (independently of |\jot|). It's
% accepted only at the level of the environment (this last point is a kind of security). Futhermore, this option has a
% particular behaviour: it applies only to the current environment and doesn't apply to the nested environments.
%    \begin{macrocode}
      interline   .code:n       = {\int_compare:nNnTF \l_@@_level_int = 1
                                      {\skip_set:Nn \l_@@_interline_skip {#1}}
                                      {\msg_error:nn {witharrows} {Option~will~be~ignored}}},
      interline   .value_required:n = true,
%    \end{macrocode}
%
% \bigskip
% Eventually, a key |jump| (see below) and a key for unknown keys.
%    \begin{macrocode}
      jump    .code:n  = {\msg_error:nn {witharrows} {Option~will~be~ignored}},
      unknown .code:n  = {\msg_error:nn {witharrows} {Option~unknown}}
}
%    \end{macrocode}
%
% \bigskip
% The key |jump| indicates the number of lines jumped by the arrow (1 by default). This key will be extracted when
% the command |\Arrow| will be executed. That's why there is a special module for this key. The key |jump| is
% extracted in the command |\Arrow| because we want to compute right away the final line of the arrow (this will be
% useful for the options |group| and |groups|).
%    \begin{macrocode}
\keys_define:nn {WithArrows/jump}
     {jump  .code:n     = {\int_set:Nn \l_@@_jump_int {#1}
                           \int_compare:nNnF \l_@@_jump_int > 0
                               {\msg_error:nn {witharrows}
                                              {The~option~"jump"~must~be~non~negative}}},
      jump  .value_required:n  = true}
%    \end{macrocode}
%
% \bigskip
% The following command is for technical reasons. It's used for the following options of position: |ll|,
% |lr|, |rl|, |rr| and |i|. The argument is the corresponding code for the position of the arrows.
%    \begin{macrocode}
\cs_new_protected:Nn \@@_analyze_option_position:n
     {\int_compare:nNnT \l_@@_previous_pos_arrows_int > {-1}
        {\msg_error:nn {witharrows}
                       {Two~options~are~incompatible}}
      \int_set:Nn \l_@@_previous_pos_arrows_int {#1}
%    \end{macrocode}
%
% It's not possible to use one of the considered options at the level of an arrow (level~2) when the option |group|
% or the option |groups| is used. However, if we are at the level of an environment, it's possible to override a
% previous option |group| or |groups| (this previous option |group| or |groups| would necessarily have been set at
% a global level by |\WithArrowsOptions|).
%    \begin{macrocode}
      \bool_if:nTF { \int_compare_p:nNn \l_@@_level_int = 2 &&
                     \int_compare_p:nNn \l_@@_pos_arrows_int > 4}
         {\msg_error:nn {witharrows}
                        {Option~incompatible~with~"group(s)"}}
         {\int_set:Nn \l_@@_pos_arrows_int {#1}}}
%    \end{macrocode}
%
% \bigskip
% We process the options when the package is loaded (with |\usepackage|) but we recommend to use |\WithArrowsOptions| instead.
%    \begin{macrocode}
\ProcessKeysOptions {WithArrows}
%    \end{macrocode}
%
% \bigskip
% |\WithArrowsOptions| is the command of the \pkg{witharrows} package to fix options at the document level.
%    \begin{macrocode}
\NewDocumentCommand \WithArrowsOptions {m}
    {\int_set:Nn \l_@@_previous_pos_arrows_int {-1}
     \keys_set_known:nnN {WithArrows} {#1} \l_tmpa_tl
     \keys_set:nV {WithArrows/GlobalOrEnv} \l_tmpa_tl}
%    \end{macrocode}
%
% 
% \subsection{The command Arrow}
%
% In fact, the internal command is not named |\Arrow| but |\@@_Arrow|. Usually, at the beginning of an environment
% |{WithArrows}|, |\Arrow| is set to be equivalent to |\@@_Arrow|. However, the user can change the name with the
% option |CommandName| and the user command for |\@@_Arrow| will be different. This mechanism can be useful when
% the user has already a command named |\Arrow| he wants to still be able to use in the environment |{WithArrows}|.
%
% \medskip
%    \begin{macrocode}
\NewDocumentCommand \@@_Arrow {O{} m O{}}
         {\tl_if_eq:noF {WithArrows} {\@currenvir} 
                  {\msg_error:nn {witharrows} {Arrow~used~outside~{WithArrows}~environment}}
%    \end{macrocode}
%
% The counter |\g_@@_arrow_int| counts the arrows in the environment. The incrementation must be global (|gincr|)
% because the command |\Arrow| will be used in the cell of a |\halign|. It's recalled that we manage a stack for
% this counter.
%    \begin{macrocode}
          \int_gincr:N \g_@@_arrow_int
%    \end{macrocode}
%
% We decide to extract immediatly the key |jump| in order to compute the end line. That's the reason why there is a
% module |WithArrows/jump| with this sole key. The remainded key-value pairs are stored in |\l_tmpa_tl| and will be
% stored further in the properly list of the arrow.
%    \begin{macrocode}
          \int_zero_new:N \l_@@_jump_int
          \int_set:Nn \l_@@_jump_int 1
          \keys_set_known:nnN {WithArrows/jump} {#1,#3} \l_tmpa_tl
%    \end{macrocode}
%
% \medskip
% We will construct a global property list to store the informations of the considered arrow. The four fields of
% this property list are ``initial'', ``final'', ``options'' and ``label''.
%
% \smallskip
% \begin{enumerate}
% \item First, the line from which the arrow starts:
%    \begin{macrocode}
          \prop_put:NnV \l_tmpa_prop {initial} \g_@@_line_int
%    \end{macrocode}
%
% \item The line where the arrow ends (that's why it was necessary to extract the key |jump|):
%    \begin{macrocode}
          \int_set:Nn \l_tmpa_int {\g_@@_line_int + \l_@@_jump_int}
          \prop_put:NnV \l_tmpa_prop {final} \l_tmpa_int
%    \end{macrocode}
%
% \item All the options of the arrow (it's a token list):
%    \begin{macrocode}
          \prop_put:NnV \l_tmpa_prop {options} \l_tmpa_tl
%    \end{macrocode}
%
% \item The label of the arrow (it's also a token list):
%    \begin{macrocode}
          \prop_put:Nnn \l_tmpa_prop {label} {#2}
%    \end{macrocode}
% \end{enumerate}
%
% The property list has been created in a local variable for convenience. Now, it will be stored in a global
% variable indicating both the position-in-the-tree and the number of the arrow. 
% 
%    \begin{macrocode}
          \prop_gclear_new:c 
                {g_@@_arrow_\l_@@_prefix_tl _\int_use:N\g_@@_arrow_int _prop}
          \prop_gset_eq:cN 
                {g_@@_arrow_\l_@@_prefix_tl _\int_use:N\g_@@_arrow_int _prop} 
                \l_tmpa_prop
          }       
%    \end{macrocode}
%
%
% \subsection{The environnement \{WithArrows\}}
%
%
% The environment |{WithArrows}| starts with the initialisation of the three counters |\g_@@_arrow_int|,
% |\g_@@_line_int| dans |\g_@@_line_bis_int|. However, we have to save their previous values with the three stacks
% created for this end.
%    \begin{macrocode}
\NewDocumentEnvironment {WithArrows} {O{}}
         { \seq_gput_right:NV \g_@@_arrow_int_seq \g_@@_arrow_int
           \int_gzero:N \g_@@_arrow_int 
           \seq_gput_right:NV \g_@@_line_int_seq \g_@@_line_int
           \int_gzero:N \g_@@_line_int 
           \seq_gput_right:NV \g_@@_line_bis_int_seq \g_@@_line_bis_int
           \int_gzero:N \g_@@_line_bis_int 
%    \end{macrocode}
% 
% \bigskip
% We also have to update the position on the nesting tree.
%    \begin{macrocode}
           \seq_gput_right:Nn \g_@@_position_in_the_tree_seq 1
%    \end{macrocode}
%
% The nesting tree is used to create a prefix which will be used in the names of the Tikz nodes and in the names of
% the arrows (each arrow is a property list of four fields). If we are in the second environment |{WithArrows}|
% nested in the third environment |{WithArrows}| of the document, the prefix will be |3-2| (although the position
% in the tree is $[3,2,1]$ since such a position always ends with a~$1$). First, we do a copy of the
% position-in-the-tree and then we pop the last element of this copy (in order to drop the last~$1$).
%    \begin{macrocode}
           \seq_set_eq:NN \l_tmpa_seq \g_@@_position_in_the_tree_seq
           \seq_pop_right:NN \l_tmpa_seq \l_tmpa_tl
           \tl_clear_new:N \l_@@_prefix_tl
           \tl_set:Nx \l_@@_prefix_tl {\seq_use:Nnnn \l_tmpa_seq {-} {-} {-}}
%    \end{macrocode}
%
%

% 
% \bigskip
% The environment |{WithArrows}| must be used in math mode.
%    \begin{macrocode}
           \reverse_if:N \if_mode_math:
                             \msg_error:nn {witharrows} {{WithArrows}~used~outside~math~mode}
                         \fi
%    \end{macrocode}
%
% \bigskip
% We extract the footnotes of the environments |{WithArrows}| with the pair |\savenotes-\spewnotes| of the
% extension \pkg{footnote} (of course, we have put a |\spewnotes| at the end of the environment).
%    \begin{macrocode}
           \savenotes
%    \end{macrocode}
%
% \bigskip
% We define the command |\\| to be the command |\@@_cr:| (defined below). 
%    \begin{macrocode}
           \cs_set_eq:NN \\ \@@_cr:
           \mathsurround = \c_zero_dim
%    \end{macrocode}
%
% \bigskip
% These counters will be used later as variables.
%    \begin{macrocode}
           \int_zero_new:N \l_@@_initial_int
           \int_zero_new:N \l_@@_final_int
           \int_zero_new:N \l_@@_arrow_int
%    \end{macrocode}
%
% \bigskip
% The value corresponding to the key |interline| is put to zero before the treatment of the options of the
% environment.\footnote{It's recalled that, by design, the option \texttt{interline} of a environment doesn't apply
% in the nested environments.}
%    \begin{macrocode}
           \skip_zero:N \l_@@_interline_skip
%    \end{macrocode}
%
% \bigskip
% We process the options given to the |{WithArrows}| environment. The level of options is set to 1.
%    \begin{macrocode}
           \int_set:Nn \l_@@_previous_pos_arrows_int {-1}
           \int_set:Nn \l_@@_level_int 1
           \keys_set_known:nnN {WithArrows} {#1} \l_tmpa_tl
           \keys_set:nV {WithArrows/GlobalOrEnv} \l_tmpa_tl
%    \end{macrocode}
%
% \bigskip
% If the user has given a value for the option |CommandName| (at the global or at the \emph{environment} level), a
% command with this name is defined locally in the environment with meaning |\@@_Arrow|. The default value of the
% option |CommandName| is ``|Arrow|'' and thus, by default, the name of the command will be |\Arrow|.
%    \begin{macrocode}
           \cs_set_eq:cN \l_@@_CommandName_tl \@@_Arrow
%    \end{macrocode}
%
% \bigskip
% The environment begins with a |\vtop|, a |\vcenter| or a |\vbox|\footnote{Notice that the use of
% \texttt{\string\vtop} seems color-safe here...} depending of the value of |\l_@@_pos_env_int| (fixed by the options
% |t|, |c| or |b|). The environment |{WithArrows}| must be used in math mode\footnote{An error is raised if the
% environment is used outside math mode.} and therefore, we can use |\vcenter|.
%    \begin{macrocode}
           \int_case:nn \l_@@_pos_env_int 
                   {0 {\vtop}
                    1 {\vcenter}
                    2 {\vbox}}
           \bgroup
%    \end{macrocode}
%
% \bigskip
% The command |\spread@equation| is the command used by \pkg{amsmath} in the beginning of an alignment to fix the
% interline. When used, it becomes no-op. However, it's possible to use \pkg{witharrows} without \pkg{amsmath}
% since we have redefined |\spread@equation| (if it is not defined yet). 
%    \begin{macrocode}
           \spread@equation
%    \end{macrocode}
%
% \bigskip
% We begin the |\halign| and the preamble.
%    \begin{macrocode}
           \ialign\bgroup
%    \end{macrocode}
%
% \bigskip 
% We increment the counter |\g_@@_line_int| which will be used in the names of the Tikz nodes created in the array.
% This incrementation must be global (|gincr|) because we are in the cell of a |\halign|. It's recalled that we
% manage a stack for this counter.
%    \begin{macrocode}
           \int_gincr:N \g_@@_line_int 
           \strut\hfil
           $\bool_if:NT \l_@@_displaystyle_bool \displaystyle {##}$
           & 
%    \end{macrocode}
% 
% \bigskip
% In the second column, we increment the counter |\g_@@_line_bis_int| because we want to count the lines with a
% second column and raise an error if there is lines without a second column. Once again, the incrementation must
% be global and it's recalled that we manage a stack for this counter too.
%    \begin{macrocode}
           \int_gincr:N \g_@@_line_bis_int 
           $\bool_if:NT \l_@@_displaystyle_bool \displaystyle {{}##}$
%    \end{macrocode}
%
% \bigskip
% We create the ``left node'' of the line (when using macros in Tikz node names, the macros have to be fully
% expandable: here, |\tl_use:N| and |\int_use:N| are fully expandable).
%    \begin{macrocode}
           \tikz[remember~picture] 
                  \node [@@_node_style] 
                  (wa-\tl_use:N\l_@@_prefix_tl-\int_use:N\g_@@_line_int-l) {} ;
           \hfil
%    \end{macrocode}
%
% \bigskip
% Now, after the |\hfil|, we create the ``right node'' and, if the option |shownodenames| is raised, the name of
% the node is written in the document (useful for debugging).
%    \begin{macrocode}
           \tikz[remember~picture,label~position=right] 
                  \node [@@_node_style] 
                  (wa-\tl_use:N\l_@@_prefix_tl-\int_use:N\g_@@_line_int-r) {} ;
           \bool_if:NT \l_@@_shownodenames_bool
                {\hbox_overlap_right:n {\small wa-\tl_use:N\l_@@_prefix_tl
                                                 -\int_use:N\g_@@_line_int}}
%    \end{macrocode}
% 
% \bigskip
% Usually, the |\halign| of an environment |{WithArrows}| will have exactly two columns. Nevertheless, if the user
% wants to use more columns (without arrows) it's possible with the option |MoreColumns|.
%    \begin{macrocode}
           && \bool_if:NF \l_@@_MoreColumns_bool
                {\msg_error:nn {witharrows} {Third~column~in~a~{WithArrows}~environment}}
           $\bool_if:NT \l_@@_displaystyle_bool \displaystyle {##}$
           \cr
          }
%    \end{macrocode}
%
% \bigskip
% We begin the second part of the environment |{WithArrows}|. We have two |\egroup|: one for the |\halign| and
% one for the |\vtop| (or |\vcenter| or |\vbox|).
%    \begin{macrocode}
          {\crcr
           \egroup 
           \egroup
%    \end{macrocode}
%
% \bigskip
% If there is a line without the second column, we raise an error (a line without the second column could generate
% an \textsc{pgf} error for an unknown node since the nodes are created in the second column).
%    \begin{macrocode}
           \int_compare:nNnT \g_@@_line_bis_int < \g_@@_line_int
                  {\msg_error:nn {witharrows} {All~lines~must~have~an~ampersand}}
%    \end{macrocode}
%
% \bigskip 
% It there is really arrows in the environment, we draw the arrows:
% \begin{itemize}
% \item if neither option |group| or |groups| is used, we can draw directly ;
% \item if option |group| or option |groups| is used (|\l_@@_pos_arrows_int| > 4), we have to draw the
% arrows group by group ; the macro |\@@_draw_arrows:| does the work.
% \end{itemize}
%
%    \begin{macrocode}
            \int_compare:nNnT \g_@@_arrow_int > 0 
                  {\int_compare:nNnTF \l_@@_pos_arrows_int > 4
                    \@@_draw_arrows:
                    {\@@_draw_arrows:nn 1 \g_@@_arrow_int}}
%    \end{macrocode}
%
% \bigskip
% We use |\spewnotes| of \pkg{footnote} to spew the footnotes of the environment (a |\savenotes| has been put at
% the beginning of the environment).
%    \begin{macrocode}
           \spewnotes
%    \end{macrocode}
%
% \bigskip
% We update the position-in-the-tree. First, we drop the last component and then we increment the last element.
%    \begin{macrocode}
           \seq_gpop_right:NN \g_@@_position_in_the_tree_seq \l_tmpa_tl
           \seq_gpop_right:NN \g_@@_position_in_the_tree_seq \l_tmpa_tl
           \seq_gput_right:Nx \g_@@_position_in_the_tree_seq {\int_eval:n {\l_tmpa_tl + 1}}
%    \end{macrocode}
%
% \bigskip
% We update the value of the counter |\g_@@_last_env_int|. This counter is used only by the user function |\WithArrowsLastEnv|.
%    \begin{macrocode}
           \int_compare:nNnT {\seq_count:N \g_@@_position_in_the_tree_seq} = 1
                      {\int_gincr:N \g_@@_last_env_int}
%    \end{macrocode}
%
% \bigskip
% Finally, we restore the previous values of the three counters |\g_@@_arrow_int|, |\g_@@_line_int| and
% |\g_@@_line_bis_int|. It is recalled that we manage three stacks in order to be able to do such a restoration.
%    \begin{macrocode}
           \seq_gpop_right:NN \g_@@_arrow_int_seq {\l_tmpa_tl}
           \int_gset:Nn \g_@@_arrow_int {\l_tmpa_tl}
           \seq_gpop_right:NN \g_@@_line_int_seq \l_tmpa_tl
           \int_gset:Nn \g_@@_line_int {\l_tmpa_tl}
           \seq_gpop_right:NN \g_@@_line_bis_int_seq \l_tmpa_tl
           \int_gset:Nn \g_@@_line_bis_int {\l_tmpa_tl}
           }
%    \end{macrocode}
% That's the end of the environment |{WithArrows}|.
%
% \bigskip
% We give now the definition of |\@@_cr:| which is the definition of |\\| in an environment |{WithArrows}|. The two
% \pkg{expl3} commands |\group_align_safe_begin:| and |\group_align_safe_end:| are specifically designed for this
% purpose: test the token that follows in a |\halign| structure.
%
% First, we remove an eventual token |*| since the commands |\\| and |\\*| are equivalent in an environment
% |{WithArrows}| (an environment |{WithArrows}|, like an environment |{aligned}| of \pkg{amsmath} is always unbreakable).
%    \begin{macrocode}
\cs_set_protected:Nn \@@_cr:
      {\scan_stop:
       \group_align_safe_begin:
       \peek_meaning_remove:NTF * \@@_cr_i: \@@_cr_i:}
%    \end{macrocode}
%
% \medskip
% Then, we peek the next token to see if it's a |[|. In this case, the command |\\| has an optional argument which
% is the vertical skip (=glue) to put.
%    \begin{macrocode}
\cs_set_protected:Nn \@@_cr_i:
      {\peek_meaning:NTF [ {\@@_cr_ii:} {\@@_cr_ii:[\c_zero_dim]} }
\cs_new_protected:Npn \@@_cr_ii:[#1]
      {\group_align_safe_end:
       \cr\noalign{\skip_vertical:n {#1 + \l_@@_interline_skip}
       \scan_stop:}}
%    \end{macrocode}
% According of the documentation of \pkg{expl3}, the previous addition in ``|#1 + \l_@@_interline_skip|'' is really
% an addition of skips (=glues).
%
% \subsection{We draw the arrows}
%
% \bigskip
% |\@@_draw_arrows:| draws the arrows when the option |group| or the option |groups| is used. In both cases, we have
% to compute the $x$-value of a group of arrows before actually drawing the arrows of that group. The arrows will
% actually be drawn by the macro |\@@_draw_arrows:nn|.
% 
%    \begin{macrocode}
\cs_new_protected:Nn \@@_draw_arrows:
  { \group_begin:
%    \end{macrocode}
%
% \bigskip
% |\l_@@_first_arrow_of_group_int| will be the first arrow of the current group. 
%
% |\l_@@_first_line_of_group_int| will be the first line involved in the group of arrows (equal to the initial line
% of the first arrow of the group because the option |jump| is always positive).
%
% |\l_@@_last_line_of_group_int| will be the last line involved in the group (impossible to guess in advance).
%    \begin{macrocode}
    \int_zero_new:N \l_@@_first_arrow_of_group_int 
    \int_zero_new:N \l_@@_first_line_of_group_int
    \int_zero_new:N \l_@@_last_line_of_group_int
    \bool_set_true:N \l_@@_new_group_bool
%    \end{macrocode}
%
% \bigskip
% We begin a loop over all the arrows of the environment. Inside this loop, if a group is finished, we will draw
% the lines of that group.
%    \begin{macrocode}
    \int_set:Nn \l_@@_arrow_int 1
    \int_until_do:nNnn \l_@@_arrow_int > \g_@@_arrow_int
     { 
%    \end{macrocode}
%
% \bigskip 
% We extract from the property list of the current arrow the fields ``initial'' and ``final'' and we store these
% values in |\l_@@_initial_int| and |\l_@@_final_int|. However, we have to do a conversion because the components
% of a property list are token lists.
%    \begin{macrocode}
       \prop_get:cnN {g_@@_arrow_\l_@@_prefix_tl _\int_use:N\l_@@_arrow_int _prop}
                     {initial} \l_tmpa_tl
       \int_set:Nn \l_@@_initial_int {\l_tmpa_tl}
       \prop_get:cnN {g_@@_arrow_\l_@@_prefix_tl _\int_use:N\l_@@_arrow_int _prop}
                     {final} \l_tmpa_tl
       \int_set:Nn \l_@@_final_int {\l_tmpa_tl}
%    \end{macrocode}
%
% \bigskip
% We test if the previous arrow was in fact the last arrow of a group. In this case, we have to draw all the arrows
% of that group (with the $x$-value computed in |\g_@@_x_dim|).
%    \begin{macrocode}
       \bool_if:nT {     \int_compare_p:nNn \l_@@_pos_arrows_int = 6
                      && \int_compare_p:nNn \l_@@_arrow_int > 1
                      && \int_compare_p:nNn \l_@@_initial_int > \l_@@_last_line_of_group_int}
              {\@@_draw_arrows:nn \l_@@_first_arrow_of_group_int {\l_@@_arrow_int - 1}
               \bool_set_true:N \l_@@_new_group_bool}
%    \end{macrocode}
%
% \bigskip
% The flag |\l_@@_new_group_bool| indicates if we have to begin a new group of arrows. In fact, We have to begin a
% new group in two circonstancies : if we are at the first arrow of the environment (that's why the flag is raised
% before the beginning of the loop) an if we have just finished a group (that's why the flag is raised in the
% previous conditionnal). At the beginning of a group, we have to initialize four variables:
% |\l_@@_first_arrow_int|, |\l_@@_first_line_of_group_int|, |\l_@@_last_line_of_group| dans |\g_@@_x_dim| (global
% for technical reasons). The last two will evolve during the construction of the group.
%    \begin{macrocode}
       \bool_if:nTF \l_@@_new_group_bool
              {\bool_set_false:N \l_@@_new_group_bool
               \int_set:Nn \l_@@_first_arrow_of_group_int \l_@@_arrow_int
               \int_set:Nn \l_@@_first_line_of_group_int \l_@@_initial_int
               \int_set:Nn \l_@@_last_line_of_group_int \l_@@_final_int
               \tikz[remember~picture]
                  \path let \p1 = (wa-\tl_use:N\l_@@_prefix_tl-\int_use:N\l_@@_initial_int-l)
                        in \pgfextra {\dim_gset:Nn \g_@@_x_dim {\x1}} ;
              }
%    \end{macrocode}
%
% \bigskip
% If we are not at the beginning of a new group, we actualize |\l_@@_last_line_of_group_int|.
%    \begin{macrocode}
              {\int_set:Nn \l_@@_last_line_of_group_int
                     {\int_max:nn \l_@@_last_line_of_group_int \l_@@_final_int}}
%    \end{macrocode}
%
% \bigskip
% We actualise the current $x$-value (in |\g_@@_x_dim|) even if we are at the beginning of a group. Indeed, the
% previous initialisation of |\g_@@_x_dim| only considers the initial line of the arrows and now we consider all
% the lines between the initial and the final line. This is done with |\@@_actualise_x_value:nn|. We have written a
% command for this because it is also used with the option |i| (|\l_@@_pos_arrows_int| = 4).
%    \begin{macrocode}
       \@@_actualise_x_value:nn \l_@@_initial_int \l_@@_final_int
%    \end{macrocode}
%
% \bigskip
% Incrementation of the index of the loop (and end of the loop).
%    \begin{macrocode}
       \int_incr:N \l_@@_arrow_int
     }
%    \end{macrocode}
%
% \bigskip
% After the last arrow of the environment, you have to draw the last group of arrows.
%    \begin{macrocode}
     \@@_draw_arrows:nn \l_@@_first_arrow_of_group_int \g_@@_arrow_int
     \group_end:
  }
%    \end{macrocode}
%
% \bigskip
% The following code is necessary because we will have to expand an argument exactly 3 times.
%    \begin{macrocode}
\cs_generate_variant:Nn \keys_set:nn {no}
\cs_new_protected:Nn \keys_set_WithArrows: {\keys_set:no {WithArrows}}
%    \end{macrocode}
%
%
% \bigskip
% The macro |\@@_draw_arrows:nn| draws all the arrows whose numbers are between |#1| and |#2|. |#1| and |#2|
% must be expressions that expands to an integer (they are expanded in the beginning of the macro).
%    \begin{macrocode}
\cs_new_protected:Nn \@@_draw_arrows:nn
  {\group_begin:
   \int_zero_new:N \l_@@_first_arrow_int
   \int_set:Nn \l_@@_first_arrow_int {#1}
   \int_zero_new:N \l_@@_last_arrow_int
   \int_set:Nn \l_@@_last_arrow_int {#2}
%    \end{macrocode}
%
%
% \bigskip
% We begin a loop over the arrows of the environment. The variable |\l_@@_arrow_int| (local in the environment
% |{WithArrows}|) will be used as index for the loop.
%    \begin{macrocode}
   \int_set:Nn \l_@@_arrow_int \l_@@_first_arrow_int
   \int_until_do:nNnn \l_@@_arrow_int > \l_@@_last_arrow_int
     {
%    \end{macrocode}
%
% \bigskip 
% We extract from the property list of the current arrow the fields ``initial'' and ``final'' and we store these
% values in |\l_@@_initial_int| and |\l_@@_final_int|. However, we have to do a conversion because the components
% of a property list are token lists.
% 
%    \begin{macrocode}
      \prop_get:cnN {g_@@_arrow_\l_@@_prefix_tl _\int_use:N\l_@@_arrow_int _prop} 
                    {initial} \l_tmpa_tl
      \int_set:Nn \l_@@_initial_int {\l_tmpa_tl}
      \prop_get:cnN {g_@@_arrow_\l_@@_prefix_tl _\int_use:N\l_@@_arrow_int _prop} 
                    {final} \l_tmpa_tl
      \int_set:Nn \l_@@_final_int {\l_tmpa_tl}
%    \end{macrocode}
%
% \bigskip
% If the arrow ends after the last line of the environment, we raise an error.
%    \begin{macrocode}
      \int_compare:nNnT \l_@@_final_int > \g_@@_line_int
             {\msg_error:nn {witharrows} {Too~few~lines~for~an~arrow}}
%    \end{macrocode}
%
% \bigskip
% We prepare the process of the options of the current arrow.
%    \begin{macrocode}
           \group_begin:
           \int_set:Nn \l_@@_previous_pos_arrows_int {-1}
           \int_set:Nn \l_@@_level_int 2
%    \end{macrocode}
%
% \bigskip
% We process the options of the current arrow. The second argument of |\keys_set:nn| must be expanded exactly
% three times. An x-expansion is not possible because there can be tokens like |\bfseries| in the option |font| of
% the option |tikz|. This expansion is a bit tricky.
%    \begin{macrocode}
           \prop_get:cnN {g_@@_arrow_\l_@@_prefix_tl 
                             _\int_use:N\l_@@_arrow_int _prop} {options} \l_tmpa_tl
           \exp_args:NNo \exp_args:No \keys_set_WithArrows: {\l_tmpa_tl}
%    \end{macrocode}
%
%
% We create two booleans to indicate the position of the initial node and final node of the arrow in cases of
% options |rr|, |rl|, |lr| or |ll|:
%    \begin{macrocode}
\bool_set_false:N \l_@@_initial_r_bool
\bool_set_false:N \l_@@_final_r_bool
\int_case:nn \l_@@_pos_arrows_int 
       {0 {\bool_set_true:N \l_@@_initial_r_bool
           \bool_set_true:N \l_@@_final_r_bool}
        2 {\bool_set_true:N \l_@@_initial_r_bool}
        3 {\bool_set_true:N \l_@@_final_r_bool}}
%    \end{macrocode}
%
% \bigskip
% In case of option |i| (|\l_@@_pos_arrows_int| = 4), we have to compute the $x$-value of the arrow (which is
% vertical). The computed $x$-value is stored in |\g_@@_x_dim| (the same variable used when the option |group| or
% the option |groups| is used). This variable is global for technical reasons: we have to do assignments in a Tikz
% node.
%    \begin{macrocode}
           \int_compare:nNnT \l_@@_pos_arrows_int = 4
                  {
%    \end{macrocode}
% 
% \medskip
% First, we calculate the initial value for |\g_@@_x_dim|. We use a Tikz command, but, in fact, nothing is drawn.
% We use this Tikz command only to read the abscissa of a Tikz node.
%    \begin{macrocode}
                   \tikz[remember~picture]
                   \path let \p1 = (wa-\tl_use:N\l_@@_prefix_tl-\int_use:N\l_@@_initial_int-l)
                         in \pgfextra {\dim_gset:Nn \g_@@_x_dim {\x1}} ;
%    \end{macrocode}
% A global assignment is necessary because of Tikz.
%
% Then, we will loop to determine the maximal length of all the lines between the lines |\l_@@_initial_int| and
% |\l_@@_final_int|... but we have written a command dedicated to this work because it will also be used in 
% |\@@_draw_arrows:|.
%    \begin{macrocode}
                   \@@_actualise_x_value:nn \l_@@_initial_int \l_@@_final_int
                   }
%    \end{macrocode}
%
% \bigskip
% |\l_@@_initial_tl| contains the name of the Tikz node from which the arrow starts (in normal cases...
% because with option |group| or option |i|, the point will perhaps have an other $x$-value --- but always the
% same |y|-value). Idem for |\l_@@_final_tl|.
%    \begin{macrocode}
           \tl_set:Nx \l_@@_initial_tl 
                   {wa-\tl_use:N\l_@@_prefix_tl-\int_use:N\l_@@_initial_int-
                            \bool_if:NTF\l_@@_initial_r_bool rl} 
           \tl_set:Nx \l_@@_final_tl 
                   {wa-\tl_use:N\l_@@_prefix_tl-\int_use:N\l_@@_final_int-
                            \bool_if:NTF\l_@@_final_r_bool rl . north}
%    \end{macrocode}
% We use ``|. north|'' because we want a small gap between two consecutive arrows (and the Tikz nodes created have
% the shape of small vertical segments: use option |shownodes| to visualize the nodes).
%
% \bigskip
% We can now draw the arrow in a |{tikzpicture}|:
%    \begin{macrocode}
           \begin{tikzpicture}[remember~picture,
                               overlay,
                               align=left,
                               auto=left,
                               font = {\small\itshape},
                               TipsOfWithArrows,
                               ->,
                               looseness=1,
                               bend~left=45]
%    \end{macrocode}
%
% Of course, the arrow is drawn with the command |\draw| of Tikz. The syntax for this command is:
%
% \qquad |\draw| $(x_1,y_1)$ |to node| (\textsl{name}) |{|\textsl{contents}|}| $(x_2,y_2)$
% 
% The surprising aspect of this syntax is the position of \textsl{contents} which is the label of the arrow.
%
% |\p1| and |\p2| are the two ends of the arrow (in fact, if the option |i| or the option |group| is used, it's not
% exactly the two ends of the arrow because, in this case, the abscissa used is the value previously calculated in
% |g_@@_x_dim|).
%
% The ability to define |\p1| and |\p2| is given by the library |calc| of Tikz. When |\p1| and |\p2| are defined,
% the $x$-value and $y$-value of these two points can be read in |\x1|, |\x2|, |\y1| and |\y2|. This is the way to
% have the coordinates of a node defined in Tikz.
%    \begin{macrocode}
           \prop_get:cnN {g_@@_arrow_\l_@@_prefix_tl _\int_use:N\l_@@_arrow_int _prop} 
                         {label} \l_tmpa_tl
           \draw \exp_after:wN [\l_@@_options_tikz_tl]
                 let \p1 = (\tl_use:N \l_@@_initial_tl),
                     \p2 = (\tl_use:N \l_@@_final_tl) in 
                   (\int_compare:nNnTF \l_@@_pos_arrows_int > 3 
                     {\dim_use:N \g_@@_x_dim + \dim_use:N \l_@@_xoffset_dim, \y1}
                     {\x1 + \dim_use:N \l_@@_xoffset_dim, \y1} )
%    \end{macrocode}
% There are two ways to give the content of the node: the classical way, with curly braces, and the option ``node
% contents''. However, both are not strictly equivalent: when |\usetikzlibrary{babel}| is used, the tokens of the
% contents are rescanned in the first way but not in the second. We don't want the tokens to be rescanned (because
% this would lead to an error due of the characters |_| and |:| of the \pkg{expl3} syntax) and that's why we use
% the second method. \footnote{cf.:
% |tex.stackexchange.com/questions/298177/how-to-get-around-a-problem-with-usetikzlibrarybabel|}
%    \begin{macrocode}
                   to node [node~contents = {\tl_use:N \l_tmpa_tl}] {}
                   (\int_compare:nNnTF \l_@@_pos_arrows_int > 3 
                     {\dim_use:N \g_@@_x_dim + \dim_use:N \l_@@_xoffset_dim, \y2}
                     {\x2 + \dim_use:N \l_@@_xoffset_dim, \y2} ) ; 
           \end{tikzpicture}
%    \end{macrocode}
%
% \smallskip
% We close the TeX group opened for the options given to |\Arrow[...]| (local level of the options).
%    \begin{macrocode}
       \group_end: 
       \int_incr:N \l_@@_arrow_int
      } 
      \group_end:
     }
%    \end{macrocode}
%
% \bigskip
% The command |\@@_actualise_x_value:nn| will analyze the lines between |#1| and |#2| in order to modify
% |\g_@@_x_dim| in consequence. More precisely, |\g_@@_x_dim| is increased if a line longer than the current value
% of |\g_@@_x_dim| is found. |\@@_actualise_x_value:nn| is used in |\@@_draw_arrows:| (for options |group| and
% |groups|) and in |\@@_draw_arrows:nn| (for option |i|).
%    \begin{macrocode}
\cs_new_protected:Nn \@@_actualise_x_value:nn
    {\group_begin:
     \int_set:Nn \l_@@_initial_int {#1}
     \int_set:Nn \l_@@_final_int {#2}
     \int_compare:nNnT \l_@@_final_int > \g_@@_line_int
             {\msg_error:nn {witharrows} {Too~few~lines~for~an~arrow}}
%    \end{macrocode}
%
% We begin a loop with |\l_tmpa_int| as index. In this loop, we use a Tikz command, but, in fact, nothing is drawn.
% We use this Tikz command only to read the abscissa of a Tikz node.
%    \begin{macrocode}
     \int_set:Nn \l_tmpa_int \l_@@_initial_int
     \int_until_do:nNnn \l_tmpa_int > \l_@@_final_int
         {\tikz[remember~picture]
             \path let \p1 = (wa-\tl_use:N\l_@@_prefix_tl-\int_use:N\l_tmpa_int-l) 
                   in \pgfextra {\dim_gset:Nn \g_@@_x_dim {\dim_max:nn \g_@@_x_dim {\x1}}} ;
          \int_incr:N \l_tmpa_int
         }
     \group_end:
    }   
%    \end{macrocode}
%
%    \begin{macrocode}
\cs_generate_variant:Nn \tl_if_eq:nnF {noF}
%    \end{macrocode}
%
%
% \bigskip
% The command |\WithArrowsLastEnv| is not used by the package \pkg{witharrows}. It's only a facility given to the
% final user. It gives the number of the last environment |{WithArrows}| at level~$0$ (to the sens of the nested
% environments). This macro is fully expandable and, thus, can be used directly in the name of a Tikz node.
%    \begin{macrocode}
\NewDocumentCommand \WithArrowsLastEnv {}
     {\int_use:N \g_@@_last_env_int}
%    \end{macrocode}
%
% \subsection{The error messages of the package}
%    \begin{macrocode}          
\msg_new:nnn {witharrows}
             {Third~column~in~a~{WithArrows}~environment}
             {By~default,~a~\{WithArrows\}~environment~can~only~have~two~columns.~
              Maybe~you~have~forgotten~a~newline~symbol.~If~you~really~want~
              more~than~two~columns,~you~should~use~the~option~"MoreColumns"~at~
              a~global~level~or~for~an~environment.~However,~you~can~go~one~for~this~time.}
%    \end{macrocode}
%             
%    \begin{macrocode}          
\msg_new:nnn {witharrows}
             {Arrow~used~outside~{WithArrows}~environment}
             {The~command~\string\Arrow\space~should~be~used~only~directly~
              in~\{WithArrows\}~environment~and~not~in~a~subenvironment.~However,~you~
              can~go~on.}
%    \end{macrocode}
%
%    \begin{macrocode}          
\msg_new:nnn {witharrows}
             {The~option~"jump"~must~be~non~negative}
             {You~can't~use~a~strictly~negative~value~for~the~option~"jump"~of~command~
              \string\Arrow.~ You~can~create~an~arrow~going~backwards~with~
              the~option~"<-"~of~Tikz.}
%    \end{macrocode}
%
%    \begin{macrocode}          
\msg_new:nnn {witharrows}          
             {Too~few~lines~for~an~arrow}
             {There~is~at~least~an~arrow~that~can't~be~drawn~because~it~arrives~after~the~
              last~line~of~the~environment.}
%    \end{macrocode}
%
%    \begin{macrocode}          
\msg_new:nnn {witharrows}
             {{WithArrows}~used~outside~math~mode}
             {The~environment~\{WithArrows\}~should~be~used~only~in~math~mode.~
              Nevertheless,~you~can~go~on.}
%    \end{macrocode}
%
%    \begin{macrocode}          
\msg_new:nnn  {witharrows}
              {Two~options~are~incompatible}
              {You~try~to~use~the~option~"\tl_use:N\l_keys_key_tl"~but~
              this~option~is~incompatible~or~redundant~with~the~option~"
              \int_case:nn\l_@@_previous_pos_arrows_int
                  {0 {rr}
                   1 {ll}
                   2 {rl}
                   3 {lr}
                   4 {i}
                   5 {group}
                   6 {groups}}"~
              previously~set~in~the~same~
              \int_case:nn\l_@@_level_int 
                   {0 {command~\string\WithArrowsOptions}
                    1 {declaration~of~options~of~the~environment~\{WithArrows\}}
                    2 {command~\string\Arrow}}.~
              If~you~go~on,~I~will~overwrite~the~first~option.}
%    \end{macrocode}
%
%    \begin{macrocode}          
\msg_new:nnnn {witharrows}
              {All~lines~must~have~an~ampersand}
              {All~lines~of~an~environment~\{WithArrows\}~must~have~an~second~column~
               (because~the~nodes~are~created~in~the~second~column).~You~can~go~on~but~maybe~
               you~will~have~an~pgf~error~for~an~undefined~shape.}
              {The~ampersand~can~be~implicit~
               (e.g.~if~you~use~\string\MoveEqLeft\space~of~mathtools).}
%    \end{macrocode}
%
%    \begin{macrocode}          
\msg_new:nnn {witharrows}
             {Option~incompatible~with~"group(s)"}
             {You~try~to~use~the~option~"\tl_use:N\l_keys_key_tl"~while~
              you~are~using~the~option~"
              \int_compare:nNnTF \l_@@_pos_arrows_int = 5
                   {group} 
                   {groups}".~
              It's~incompatible.~You~can~go~on~ignoring~this~option~
              "\tl_use:N\l_keys_key_tl"~but~you~should~correct~your~code.}
%    \end{macrocode}
%
%    \begin{macrocode}          
\msg_new:nnn {witharrows}
             {Option~will~be~ignored}
             {The~option~"\tl_use:N\l_keys_key_tl"~can't~be~used~here.~
              If~you~go~on,~it~will~be~ignored.}
%    \end{macrocode}
% 
%
%    \begin{macrocode}          
\msg_new:nnn {witharrows}
             {Option~unknown}
             {The~option~"\tl_use:N\l_keys_key_tl"~is~unknown~or~meaningless~in~the~context.~
              If~you~go~on,~it~will~be~ignored.}
%    \end{macrocode}
% 
%
%
%
% \section{History}
%
% \subsection{Changes between versions 1.0 and 1.1}
% 
% Option for the command |\\| and option |interline|
% 
% Compatibility with |\usetikzlibrary{babel}|
%
% Possibility of nested environments |{WithArrows}|
% 
% Better error messages 
% 
% Creation of a \textsc{dtx} file
%
% \subsection{Changes between versions 1.1 and 1.2}
%
% The package \pkg{witharrows} can now be loaded without having loaded previously \pkg{tikz} and the Tikz libraries |calc|,
% |arrow.meta| and |bending|.
%
% New option |groups| (with a \emph{s})
%
% Better error messages
% \endinput
%
% Local Variables:
% TeX-fold-mode: nil
% End: