Debian Codegraph @

texmf-dist/source/generic/witharrows/witharrows.dtx

raw
1 %\iffalse meta-comment
2 %
3 % Copyright (C) 2017-2024 by F. Pantigny
4 % -----------------------------------
5 %
6 % This file may be distributed and/or modified under the
7 % conditions of the LaTeX Project Public License, either version 1.3
8 % of this license or (at your option) any later version.
9 % The latest version of this license is in:
10 %
11 % http://www.latex-project.org/lppl.txt
12 %
13 % and version 1.3 or later is part of all distributions of LaTeX
14 % version 2005/12/01 or later.
15 %
16 % \fi
17 % \iffalse
18 \def\myfileversion{2.9a}
19 \def\myfiledate{2024/10/19}
20 %
21 %
22 %<*batchfile>
23 \begingroup
24 \input l3docstrip.tex
25 \keepsilent
26 \usedir{tex/latex/witharrows}
27 \preamble
28
29 Copyright (C) 2017-2024 by F. Pantigny
30 -----------------------------------
31
32 This file may be distributed and/or modified under the
33 conditions of the LaTeX Project Public License, either version 1.3
34 of this license or (at your option) any later version.
35 The latest version of this license is in:
36
37 http://www.latex-project.org/lppl.txt
38
39 and version 1.3 or later is part of all distributions of LaTeX
40 version 2005/12/01 or later.
41
42 \endpreamble
43 \askforoverwritefalse
44 \endgroup
45 %</batchfile>
46 %
47 %<*driver>
48 \documentclass[dvipsnames]{l3doc}% dvipsnames is for xcolor (loaded by Tikz)
49 \VerbatimFootnotes
50 \usepackage{geometry}
51 \geometry{left=2.8cm,right=2.8cm,top=2.5cm,bottom=2.5cm,papersize={21cm,29.7cm}}
52 \usepackage[hyperfootnotes=false]{footnotehyper}
53 \usepackage{fontspec}
54 \usepackage[footnotehyper]{witharrows}
55 \usetikzlibrary{calc}
56 \usepackage{mathtools}
57 \usepackage{amssymb}
58 \usepackage[only,llbracket,rrbracket]{stmaryrd}
59 \usepackage{varwidth}
60 \usepackage{upquote}
61 \labelformat{equation}{(#1)}
62 \NewDocumentEnvironment {scope} {} {} {}
63
64 \NewDocumentCommand{\Definition}{m}
65 {{\setlength{\fboxsep}{1pt}\colorbox{gray!20}{\ttfamily \vphantom{gl}#1}}}
66
67 \NewDocumentCommand{\DefinitionCommand}{m}
68 {{\setlength{\fboxsep}{1pt}\colorbox{gray!20}{\ttfamily
69 \vphantom{gl}\textbackslash #1}}}
70
71
72 \usepackage{piton}
73 \PitonOptions
74 {
75 language = verbatim ,
76 detected-commands = {emph,textsl} ,
77 splittable = 4
78 }
79
80 \SetPitonStyle{ Number = , Comment = }
81
82 \ExplSyntaxOn
83
84 \dim_new:N \l__pantigny_width_dim
85
86 \keys_define:nn { pantigny }
87 { width .dim_set:N = \l__pantigny_width_dim }
88
89 \NewPitonEnvironment { Code } { O { } }
90 {
91 \medskip
92 \char_set_catcode_other:N |
93 \cs_set_eq:NN \emph \emphase
94 \dim_zero:N \l__pantigny_width_dim
95 \keys_set:nn { pantigny } { #1 }
96 \color{gray}
97 \PitonOptions { gobble = 2 }
98 \dim_compare:nNnT \l__pantigny_width_dim > \c_zero_dim
99 {
100 \PitonOptions { width = \l__pantigny_width_dim }
101 \begin{minipage}[c]{\l__pantigny_width_dim}
102 }
103 }
104 {
105 \dim_compare:nNnT \l__pantigny_width_dim > \c_zero_dim
106 { \end{minipage} }
107 \medskip
108 }
109
110 \ExplSyntaxOff
111
112
113
114
115
116 \def\interitem{\vspace{7mm plus 2 mm minus 3mm}}
117 \def\emphase{\bgroup\color{RoyalPurple}\let\next=}
118 \fvset{commandchars=\~\#\@,formatcom={\color{gray}}}
119 \DeclareMathOperator{\re}{Re}
120 \skip \footins = 2 \bigskipamount
121 \parindent 0pt
122 \DisableCrossrefs
123 \begin{document}
124 \DocInput{witharrows.dtx}
125 \end{document}
126 %</driver>
127 % \fi
128 % \VerbatimFootnotes
129 % \title{The package \pkg{witharrows} for plain-TeX and LaTeX\thanks{This
130 % document corresponds to the version~\myfileversion\space of \pkg{witharrows},
131 % at the date of~\myfiledate.}} \author{F. Pantigny \\
132 % \texttt{[email protected]}}
133 %
134 % \maketitle
135 %
136 % \hypersetup
137 % {
138 % pdfinfo =
139 % {
140 % Title = The extension 'witharrows' ,
141 % Subject = An extension for plain-TeX and LaTeX ,
142 % Author = F. Pantigny
143 % }
144 % }
145 %
146 %
147 % \begin{abstract}
148 % The LaTeX package \pkg{witharrows} provides environments |{WithArrows}| and
149 % |{DispWithArrows}| similar to the environments |{aligned}| and |{align}| of
150 % \pkg{amsmath} but with the possibility to draw arrows on the right side of the
151 % alignment. These arrows are usually used to give explanations concerning the
152 % mathematical calculus presented.
153 % \end{abstract}
154 %
155 %
156 % \vspace{1cm}
157 % The package \pkg{witharrows} is entirely contained in the file
158 % |witharrows.sty|. This file may be put in the current directory or in a
159 % |texmf| tree. However, the best is to install \pkg{witharrows} with a TeX
160 % distribution such as MiKTeX, TeX Live or MacTeX.
161 %
162 % \medskip
163 % In fact, \pkg{witharrows} may also be used with plain-TeX and, in that case,
164 % the only required file is |witharrows.tex|: see p.~\pageref{plain-TeX}. In what
165 % follows, we describe the LaTeX package.
166 %
167 % \medskip
168
169 % This package can be used with |xelatex|, |lualatex|, |pdflatex| but also by
170 % the classical workflow |latex|-|dvips|-|ps2pdf| (or Adobe Distiller).
171 % \textsl{However, the file witharrows.dtx of the present documentation should
172 % be compiled with LuaLaTeX.} This package loads the packages \pkg{l3keys2e},
173 % \pkg{varwidth}, \pkg{tikz} and the Tikz libraries \pkg{arrows.meta} and
174 % \pkg{bending}. The final user only has to load the package with the classical
175 % instruction: |\usepackage{witharrows}|.
176 %
177 % \medskip
178 % The arrows are drawn with Tikz and that's why \textbf{several compilations may
179 % be necessary}.\footnote{If you use Overleaf, Overleaf will do automatically
180 % a number compilations sufficient (by using |latexmk|).}
181 %
182 % \bigskip
183 % This package provides an environment \Definition{\{WithArrows\}} to construct
184 % alignments of equations with arrows for the explanations on the right side:
185 %
186 % \begin{Code}
187 % $\begin{WithArrows}
188 % A & = (a+1)^2 \emph{\Arrow{we expand}} \\
189 % & = a^2 + 2a + 1 % <------- don't put \\ here
190 % \end{WithArrows}$
191 % \end{Code}
192 %
193 % $\begin{WithArrows}
194 % A & = (a+1)^2 \Arrow{we expand} \\
195 % & = a^2 + 2a + 1
196 % \end{WithArrows}$
197 %
198 %
199 %
200 % \medskip
201 % The arrow has been drawn with the command \DefinitionCommand{Arrow} on the row
202 % from which it starts. The command |\Arrow| must be used in the second column
203 % (the best way is to put it at the end of the second cell of the row as in the
204 % previous example).
205 %
206 % \medskip
207 % The environment |{WithArrows}| bears similarities with the environment
208 % |{aligned}| of \pkg{amsmath} (and |mathtools|). The extension \pkg{witharrows}
209 % also provides two environments |{DispWithArrows}| and |{DispWithArrows*}|
210 % which are similar to the environments |{align}| and |{align*}| of the package
211 % \pkg{amsmath}: cf. p. \pageref{DispWithArrows}.
212 %
213 %
214 % \section{Options for the shape of the arrows}
215 %
216 % The command |\Arrow| has several options. These options can be put between
217 % square brackets, before, or after the mandatory argument.
218 %
219 % \medskip
220 % The option \Definition{jump} gives the number\footnote{It's not possible to
221 % give a non-positive value to |jump|. See below (p.~\pageref{Backwards}) the
222 % way to draw an arrow which goes backwards.} of rows the arrow must jump (the
223 % default value is, of course,~$1$).
224 %
225 %
226 % \begin{Code}
227 % $\begin{WithArrows}
228 % A & = \bigl((a+b)+1\bigr)^2 \Arrow[\emph{jump=2}]{we expand} \\
229 % & = (a+b)^2 + 2(a+b) +1 \\
230 % & = a^2 + 2ab + b^2 + 2a + 2b +1
231 % \end{WithArrows}$
232 % \end{Code}
233 %
234 % $\begin{WithArrows}
235 % A & = \bigl((a+b)+1\bigr)^2 \Arrow[jump=1+1]{we expand} \\
236 % & = (a+b)^2 + 2(a+b) +1 \\
237 % & = a^2 + 2ab + b^2 + 2a + 2b +1
238 % \end{WithArrows}$
239 %
240 % \interitem
241 % It's possible to put several arrows starting from the same row.
242 % \begin{Code}
243 % $\begin{WithArrows}
244 % A & = \bigl((a+b)+1\bigr)^2 \emph{\Arrow{}\Arrow{}[jump=2]} \\
245 % & = (a+b)^2 + 2(a+b) +1 \\
246 % & = a^2 + 2ab + b^2 + 2a + 2b +1
247 % \end{WithArrows}$
248 % \end{Code}
249 %
250 % $\begin{WithArrows}
251 % A & = \bigl((a+b)+1\bigr)^2 \Arrow{}\Arrow{}[jump=2] \\
252 % & = (a+b)^2 + 2(a+b) +1 \\
253 % & = a^2 + 2ab + b^2 + 2a + 2b +1
254 % \end{WithArrows}$
255 %
256 % \interitem
257 % The option \Definition{xoffset} shifts the arrow to the right (we usually
258 % don't want the arrows to be stucked on the text). The initial value of
259 % |xoffset| is $3$~mm.
260 % \begin{Code}
261 % $\begin{WithArrows}
262 % A & = \bigl((a+b)+1\bigr)^2
263 % \Arrow[\emph{xoffset=1cm}]{with \texttt{xoffset=1cm}} \\
264 % & = (a+b)^2 + 2(a+b) +1
265 % \end{WithArrows}$
266 % \end{Code}
267 %
268 % $\begin{WithArrows}
269 % A & = \bigl((a+b)+1\bigr)^2
270 % \Arrow[xoffset=1cm]{with \texttt{xoffset=1cm}} \\
271 % & = (a+b)^2 + 2(a+b) +1
272 % \end{WithArrows}$
273 %
274 %
275 % \interitem
276 % The arrows are drawn with Tikz. That's why the command |\Arrow| has an option
277 % \Definition{tikz} which can be used to give to the arrow (in fact, the command
278 % |\path| of Tikz) the options proposed by Tikz for such an arrow. The following
279 % example gives an thick arrow.
280 % \begin{Code}
281 % $\begin{WithArrows}
282 % A & = (a+1)^2 \Arrow[\emph{tikz=thick}]{we expand} \\
283 % & = a^2 + 2a + 1
284 % \end{WithArrows}$
285 % \end{Code}
286 %
287 % $\begin{WithArrows}
288 % A & = (a+1)^2 \Arrow[tikz=thick]{we expand} \\
289 % & = a^2 + 2a + 1
290 % \end{WithArrows}$
291 %
292 % \interitem
293 % It's also possible to change the arrowheads. For example, we can draw an arrow
294 % which goes backwards with the Tikz option~|<-|.
295 % \label{Backwards}
296 %
297 % \begin{Code}
298 % $\begin{WithArrows}
299 % A & = (a+1)^2 \Arrow\emph{[tikz=<-]}{we factorize} \\
300 % & = a^2 + 2a + 1
301 % \end{WithArrows}$
302 % \end{Code}
303 %
304 % $\begin{WithArrows}
305 % A & = (a+1)^2 \Arrow[tikz=<-]{we factorize} \\
306 % & = a^2 + 2a + 1
307 % \end{WithArrows}$
308 %
309 % \interitem
310 % It's also possible to suppress both tips of the arrow with the Tikz option
311 % ``|-|''.
312 % \begin{Code}
313 % $\begin{WithArrows}
314 % A & = (a+1)^2 \Arrow[\emph{tikz=-}]{very classical} \\
315 % & = a^2 + 2a + 1
316 % \end{WithArrows}$
317 % \end{Code}
318 %
319 % $\begin{WithArrows}
320 % A & = (a+1)^2 \Arrow[tikz=-]{very classical} \\
321 % & = a^2 + 2a + 1
322 % \end{WithArrows}$
323 %
324 % \interitem
325 % In order to have straight arrows instead of curved ones, we must use the Tikz
326 % option ``|bend left = 0|''.
327 % \begin{Code}
328 % $\begin{WithArrows}
329 % A & = (a+1)^2 \Arrow\emph{[tikz={bend left=0}]}{we expand} \\
330 % & = a^2 + 2a + 1
331 % \end{WithArrows}$
332 % \end{Code}
333 %
334 % $\begin{WithArrows}
335 % A & = (a+1)^2 \Arrow[tikz={bend left=0}]{we expand} \\
336 % & = a^2 + 2a + 1
337 % \end{WithArrows}$
338 %
339 % \smallskip
340 % In fact, it's possible to change more drastically the shape or the arrows with
341 % the option |tikz-code| (presented p.~\pageref{tikz-code}).
342 %
343 % \interitem
344 % It's possible to use the Tikz option ``|text width|'' to control the width of
345 % the text associated to the arrow.
346 % \newcounter{fnnohyphen}
347 % \setcounter{fnnohyphen}{\thefootnote}
348 %
349 % %
350 % \begin{Code}
351 % $\begin{WithArrows}
352 % A & = \bigl((a+b)+1\bigr)^2
353 % \Arrow[jump=2,\emph{tikz={text width=5.3cm}}]{We have done...} \\
354 % & = (a+b)^2 + 2(a+b) +1 \\
355 % & = a^2 + 2ab + b^2 + 2a + 2b +1
356 % \end{WithArrows}$
357 % \end{Code}
358 %
359 % $\begin{WithArrows}
360 % A & = \bigl((a+b)+1\bigr)^2
361 % \Arrow[jump=2,tikz={text width=5.3cm}]{We have done a two-stages expansion but
362 % it would have been clever
363 % to expand with the multinomial theorem.} \\
364 % & = (a+b)^2 + 2(a+b) +1 \\
365 % & = a^2 + 2ab + b^2 + 2a + 2b +1
366 % \end{WithArrows}$
367 %
368 %
369 % \bigskip
370 % In the environments |{DispWithArrows}| and |{DispWithArrows*}|, there is an
371 % option |wrap-lines|. With this option, the lines of the labels are
372 % automatically wrapped on the right: see p.~\pageref{wrap-lines}.
373 %
374 % \interitem
375 % If we want to change the font of the text associated to the arrow, we can, of
376 % course, put a command like |\bfseries|, |\large| or |\sffamily| at the
377 % beginning of the text. But, by default, the texts are composed with a
378 % combination of |\small| and |\itshape|. When adding |\bfseries| at the
379 % beginning of the text, we won't suppress the |\small| and the |\itshape| and
380 % we will consequently have a text in a bold, italic and small font.
381 % %
382 % \begin{Code}
383 % $\begin{WithArrows}
384 % A & = (a+1)^2 \Arrow{\emph{\bfseries} we expand} \\
385 % & = a^2 + 2a + 1
386 % \end{WithArrows}$
387 % \end{Code}
388 %
389 % $\begin{WithArrows}
390 % A & = (a+1)^2 \Arrow{\bfseries we expand} \\
391 % & = a^2 + 2a + 1
392 % \end{WithArrows}$
393 %
394 % \interitem
395 % It's possible to put commands |\\| in the text to force new lines\footnote{By
396 % default, this is not possible in a Tikz node. However, in \pkg{witharrows},
397 % the nodes are created with the option |align=left|, and, thus, it becomes
398 % possible.}. However, if we put a |\\| , a command of font placed in the
399 % beginning of the text will have effect only until the first command |\\| (like
400 % in an environment |{tabular}|). That's why Tikz provides an option
401 % \Definition{font} to modify the font of the whole text. Nevertheless, if we
402 % use the option |tikz={font={\bfseries}}|, the default specification of
403 % |\small| and |\itshape| will be overwritten.
404 % %
405 % \begin{Code}
406 % $\begin{WithArrows}
407 % A & = (a+1)^2 \Arrow[\emph{tikz={font={\bfseries}}}]{we expand} \\
408 % & = a^2 + 2a + 1
409 % \end{WithArrows}$
410 % \end{Code}
411 %
412 % $\begin{WithArrows}
413 % A & = (a+1)^2 \Arrow[tikz={font={\bfseries}}]{we expand} \\
414 % & = a^2 + 2a + 1
415 % \end{WithArrows}$
416 %
417 % \medskip
418 % If we want exactly the same result as previously, we have to give to the
419 % option |font| the value |\itshape\small\bfseries|.
420 %
421 %
422 % \interitem
423 % The options can be given directly between square brackets to the environment
424 % |{WithArrows}|. There must be no space between the |\begin{WithArrows}| and
425 % the opening bracket (|[|) of the options of the environment. Such options
426 % apply to all the arrows of the environment.\footnote{They also apply to the
427 % nested environments |{WithArrows}| (with the logical exceptions of
428 % |interline|, |code-before| and |code-after|).}
429 % %
430 % \begin{Code}
431 % $\begin{WithArrows}[\emph{tikz=blue}]
432 % A & = \bigl((a+b)+1\bigr)^2 \Arrow{first expansion.} \\
433 % & = (a+b)^2 + 2(a+b) +1 \Arrow{second expansion.} \\
434 % & = a^2 + 2ab + b^2 + 2a + 2b +1
435 % \end{WithArrows}$
436 % \end{Code}
437 %
438 % $\begin{WithArrows}[tikz=blue]
439 % A & = \bigl((a+b)+1\bigr)^2 \Arrow{first expansion.} \\
440 % & = (a+b)^2 + 2(a+b) +1 \Arrow{second expansion.} \\
441 % & = a^2 + 2ab + b^2 + 2a + 2b +1
442 % \end{WithArrows}$
443 %
444 %
445 % \interitem
446 % The environment |{WithArrows}| has an option \Definition{displaystyle}. With
447 % this option, all the elements are composed in |\displaystyle| (like in an
448 % environment |{aligned}| of \pkg{amsmath}).
449 %
450 % \medskip
451 % Without the option |displaystyle|:
452 % %
453 % \begin{Verbatim}
454 % $\begin{WithArrows}
455 % \int_0^1 (x+1)^2 dx
456 % & = \int_0^1 (x^2+2x+1) dx
457 % \Arrow{linearity of integration} \\
458 % & = \int_0^1 x^2 dx + 2 \int_0^1 x dx + \int_0^1 dx \\
459 % & = \frac{1}{3} + 2\frac{1}{2} + 1 \\
460 % & = \frac{7}{3}
461 % \end{WithArrows}$
462 % \end{Verbatim}
463 %
464 % $\begin{WithArrows}
465 % \int_0^1 (x+1)^2 dx
466 % & = \int_0^1 (x^2+2x+1) dx
467 % \Arrow{linearity of integration} \\
468 % & = \int_0^1 x^2 dx + 2 \int_0^1 x dx + \int_0^1 dx \\
469 % & = \frac{1}{3} + 2\frac{1}{2} + 1 \\
470 % & = \frac{7}{3}
471 % \end{WithArrows}$
472 %
473 %
474 % \medskip
475 % The same example with the option |displaystyle|:\par\nobreak
476 %
477 % $\begin{WithArrows}[displaystyle]
478 % \int_0^1 (x+1)^2 dx
479 % & = \int_0^1 (x^2+2x+1) dx
480 % \Arrow{linearity of integration} \\
481 % & = \int_0^1 x^2 dx + 2 \int_0^1 x dx + \int_0^1 dx \\
482 % & = \frac{1}{3} + 2\frac{1}{2} + 1 \\
483 % & = \frac{7}{3}
484 % \end{WithArrows}$
485 %
486 %
487 %
488 % \interitem
489 % Almost all the options can also be set at the document level with the command
490 % \DefinitionCommand{WithArrowsOptions}. In this case, the scope of the
491 % declarations is the current TeX group (these declarations are
492 % ``semi-global''). For example, if we want all the environments |{WithArrows}|
493 % composed in |\displaystyle| with blue arrows, we can write
494 % |\WithArrowsOptions{displaystyle,tikz=blue}|.\footnote{It's also possible to
495 % configure \pkg{witharrows} by modifying the Tikz style |WithArrows/arrow|
496 % which is the style used by \pkg{witharrows} when drawing an arrow. For
497 % example, to have the labels in blue with roman (upright) types, one can use
498 % the following instruction:
499 % |\tikzset{WithArrows/arrow/.append style = {blue,font = {}}}|.}
500 %
501 % \begin{Code}
502 % \emph{\WithArrowsOptions{displaystyle,tikz=blue}}
503 % $\begin{WithArrows}
504 % \sum_{i=1}^n (x_i+1)^2
505 % & = \sum_{i=1}^n (x_i^2+2x_i+1) \Arrow{by linearity}\\
506 % & = \sum_{i=1}^n x_i^2 + 2\sum_{i=1}^nx_i+ n
507 % \end{WithArrows}$
508 % \end{Code}
509 %
510 % \begin{scope}
511 % \WithArrowsOptions{displaystyle,tikz=blue}
512 % $\begin{WithArrows}
513 % \sum_{i=1}^n (x_i+1)^2
514 % & = \sum_{i=1}^n (x_i^2+2x_i+1) \Arrow{by linearity}\\
515 % & = \sum_{i=1}^n x_i^2 + 2\sum_{i=1}^nx_i+ n
516 % \end{WithArrows}$
517 % \end{scope}
518 %
519 %
520 % \interitem
521 % The command |\Arrow| is recognized only in the environments |{WithArrows}|. If
522 % we have a command |\Arrow| previously defined, it's possible to go on using it
523 % outside the environments |{WithArrows}|.
524 %
525 % However, a previouly defined command |\Arrow| may still be useful in an
526 % environment |{WithArrows}|. If we want to use it in such an environment, it's
527 % possible to change the name of the command |\Arrow| of the package
528 % \pkg{witharrows}: there is an option \Definition{command-name} for this
529 % purpose. The new name of the command must be given to the option
530 % \emph{without} the leading backslash.
531 % %
532 % \begin{Code}
533 % \NewDocumentCommand {\Arrow} {} {\longmapsto}
534 % $\begin{WithArrows}[\emph{command-name=Explanation}]
535 % f & = \bigl(x \Arrow (x+1)^2\bigr)
536 % \emph{\Explanation{we work directly on fonctions}}\\
537 % & = \bigl(x \Arrow x^2+2x+1\bigr)
538 % \end{WithArrows}$
539 % \end{Code}
540 % %
541 % \begin{scope}
542 % \NewDocumentCommand {\Arrow} {} {\longmapsto}
543 % $\begin{WithArrows}[command-name=Explanation]
544 % f & = \bigl(x \Arrow (x+1)^2\bigr)
545 % \Explanation{we work directly on fonctions}\\
546 % & = \bigl(x \Arrow x^2+2x+1\bigr)
547 % \end{WithArrows}$
548 % \end{scope}
549 %
550 %
551 % \interitem
552 % The environment |{WithArrows}| provides also two options
553 % \Definition{code-before} and \Definition{code-after} for LaTeX code that will
554 % be executed at the beginning and at the end of the environment. These options
555 % are not designed to be hooks (they are available only at the environment level
556 % and they do not apply to the nested environments).
557 % %
558 % \begin{Code}
559 % $\begin{WithArrows}[\emph{code-before = \color{blue}}]
560 % A & = (a+b)^2 \Arrow{we expand} \\
561 % & = a^2 + 2ab + b^2
562 % \end{WithArrows}$
563 % \end{Code}
564 %
565 % $\begin{WithArrows}[code-before = \color{blue}]
566 % A & = (a+b)^2 \Arrow{we expand} \\
567 % & = a^2 + 2ab + b^2
568 % \end{WithArrows}$
569 %
570 % \medskip
571 % Special commands are available in |code-after|: a command
572 % \DefinitionCommand{WithArrowsNbLines} which gives the number of lines (=rows)
573 % of the current environment (this is a command and not a counter), a special
574 % form of the command |\Arrow| and the command |\MultiArrow|: the latter two
575 % commands are described in the section concerning the nested environments,
576 % p.~\pageref{NestedEnv}.
577 %
578 % \interitem
579 % \section{Numbers of columns}
580 %
581 % So far, we have used the environment |{WithArrows}| with two columns. However,
582 % it's possible to use the environment with an arbitrary number of columns with
583 % the option \Definition{format}. The value given to this option is like the
584 % preamble of an environment |{array}|, that is to say a sequence of letters
585 % |r|, |c| and |l|, but also |R|, |C| and |L|.
586 %
587 % \smallskip
588 % The letters |R|, |C| and |L| add empty groups |{}| which provide correct
589 % spaces when these columns contain symbols with the type |\mathrel| (such as
590 % $=$, $\leq$, etc.) or |\mathbin| (such as $+$, $\times$, etc.). This system is
591 % inspired by the environment |{IEEEeqnarray}| of the package \pkg{IEEEtrantools}.
592 %
593 % \smallskip
594 % The initial value of the parameter |format| is, in fact, |rL|.
595 %
596 % \bigskip
597 % For exemple, if we want only one column left-aligned, we use the option
598 % |format=l|.
599 % \begin{Code}
600 % $\begin{WithArrows}\emph{[format = l]}
601 % f(x) \ge g(x) \Arrow{by squaring both sides} \\
602 % f(x)^2 \ge g(x)^2 \Arrow{by moving to left side} \\
603 % f(x)^2 - g(x)^2 \ge 0
604 % \end{WithArrows}$
605 % \end{Code}
606 %
607 % $\begin{WithArrows}[format = l]
608 % f(x) \ge g(x) \Arrow{by squaring both sides} \\
609 % f(x)^2 \ge g(x)^2 \Arrow{by moving to left side} \\
610 % f(x)^2 - g(x)^2 \ge 0
611 % \end{WithArrows}$
612 %
613 % \interitem
614 % In the following example, we use five columns all centered (the environment
615 % |{DispWithArrows*}| is presented p.~\pageref{DispWithArrows}).
616 %
617 % \begin{Code}
618 % \begin{DispWithArrows*}[\emph{format = cCcCc},
619 % wrap-lines,
620 % interline=1mm]
621 % k & \;\le\; & t & \;\le\; & k+1 \\
622 % \frac{1}{k+1} & \le & \frac{1}{t} & \le & \frac{1}{k}
623 % \Arrow{we can integrate the inequalities since $k \leq k+1$ } \\
624 % \int\limits_k^{k+1} \frac{d t}{k+1}
625 % & \le & \int\limits_k^{k+1} \frac{dt}{t}
626 % & \le & \int\limits_k^{k+1} \frac{dt}{k} \\
627 % \frac{1}{k+1} & \le & \ln(k+1)-\ln(k) & \le & \frac{1}{k}
628 % \end{DispWithArrows*}
629 % \end{Code}
630 % \begin{DispWithArrows*}[format = cCcCc,
631 % wrap-lines,
632 % interline=1mm]
633 % k & \;\le\; & t & \;\le\; & k+1 \\
634 % \frac{1}{k+1} & \le & \frac{1}{t} & \le & \frac{1}{k}
635 % \Arrow{we can integrate the inequalities since $k \leq k+1$ } \\
636 % \int\limits_k^{k+1} \frac{d t}{k+1}
637 % & \le & \int\limits_k^{k+1} \frac{dt}{t}
638 % & \le & \int\limits_k^{k+1} \frac{dt}{k} \\
639 % \frac{1}{k+1} & \le & \ln(k+1)-\ln(k) & \le & \frac{1}{k}
640 % \end{DispWithArrows*}
641 %
642 %
643 % \interitem
644 % \section{Precise positioning of the arrows}
645 %
646 %
647 % The environment |{WithArrows}| defines, during the composition of the array,
648 % two series of nodes materialized in red in the following example.\footnote{The
649 % option \Definition{show-nodes} can be used to materialize the nodes. The nodes
650 % are in fact Tikz nodes of shape ``rectangle'', but with zero width. An arrow
651 % between two nodes starts at the \emph{south} anchor of the first node and
652 % arrives at the \emph{north} anchor of the second node.}
653 %
654 % \smallskip
655 % $\begin{WithArrows}[displaystyle,show-nodes]
656 % I
657 % & = \int_{\frac{\pi}{4}}^0 \ln\Bigl(1+\tan\left(\tfrac{\pi}{4}-u\right)\Bigr)(-d u) \\
658 % & = \int_0^{\frac{\pi}{4}} \ln\Bigl(1+\tan\left(\tfrac{\pi}{4}-u\right)\Bigr)d u \\
659 % & = \int_0^{\frac{\pi}{4}}\ln\left(1+\frac{1-\tan u}{1+\tan u}\right)\, d u \\
660 % & =\int_0^{\frac{\pi}{4}}\ln\left(\frac{1+\tan u+1-\tan u}{1+\tan u}\right) d u \\
661 % & =\int_0^{\frac{\pi}{4}} \ln\left(\frac{2}{1+\tan u}\right)\, d u\\
662 % & =\int_0^{\frac{\pi}{4}}\bigl(\ln2-\ln(1+\tan u)\bigr)\, d u \\
663 % & =\frac{\pi}{4}\ln2-\int_0^{\frac{\pi}{4}}\ln(1+\tan u)\, d u \\
664 % & =\frac{\pi}{4}\ln2-I
665 % \end{WithArrows}$
666 %
667 % \bigskip
668 % The nodes of the left are at the end of each line of text. These nodes will be
669 % called \emph{left nodes}. The nodes of the right side are aligned vertically
670 % on the right side of the array. These nodes will be called \emph{right nodes}.
671 %
672 % By default, the arrows use the right nodes. We will say that they are in
673 % \Definition{rr} mode ($r$ for \emph{right}). These arrows are vertical (we
674 % will say that an arrow is \emph{vertical} when its two ends have the same
675 % abscissa).
676 %
677 %
678 % \smallskip
679 % However, it's possible to use the left nodes, or a combination of left and
680 % right nodes, with one of the options \Definition{lr}, \Definition{rl} and
681 % \Definition{ll} ($l$ for \emph{left}). Those arrows are, usually, not vertical.
682 %
683 %
684 % Therefore
685 % $\begin{WithArrows}[displaystyle]
686 % I
687 % & = \int_{\frac{\pi}{4}}^0 \ln\Bigl(1+\tan\left(\tfrac{\pi}{4}-u\right)\Bigr)(-d u)
688 % \Arrow[lr]{This arrow uses the |lr| option.}\\
689 % & = \int_0^{\frac{\pi}{4}} \ln\Bigl(1+\tan\left(\tfrac{\pi}{4}-u\right)\Bigr)d u \\
690 % & = \int_0^{\frac{\pi}{4}}\ln\left(1+\frac{1-\tan u}{1+\tan u}\right)\, d u \\
691 % & =\int_0^{\frac{\pi}{4}}\ln\left(\frac{1+\tan u+1-\tan u}{1+\tan u}\right) d u
692 % \Arrow[ll,jump=2,tikz={text width = 5cm}]{This arrow uses a |ll| option
693 % and a |jump| equal to $2$}\\
694 % & =\int_0^{\frac{\pi}{4}} \ln\left(\frac{2}{1+\tan u}\right)\, d u\\
695 % & =\int_0^{\frac{\pi}{4}}\bigl(\ln2-\ln(1+\tan u)\bigr)\, d u \\
696 % & =\frac{\pi}{4}\ln2-\int_0^{\frac{\pi}{4}}\ln(1+\tan u)\, d u \\
697 % & =\frac{\pi}{4}\ln2-I
698 % \end{WithArrows}$
699 %
700 %
701 %
702 % \interitem
703 % There is also an option called \Definition{i} (\emph{i} for
704 % \emph{intermediate}). With this option, the arrow is vertical and at the
705 % leftmost position.
706 %
707 % \begin{Code}
708 % $\begin{WithArrows}
709 % (a+b)(a+ib)(a-b)(a-ib)
710 % & = (a+b)(a-b)\cdot(a+ib)(a-ib) \\
711 % & = (a^2-b^2)(a^2+b^2) \Arrow\emph{[i]}{because $(x-y)(x+y)=x^2-y^2$}\\
712 % & = a^4-b^4
713 % \end{WithArrows}$
714 % \end{Code}
715 %
716 % $\begin{WithArrows}
717 % (a+b)(a+ib)(a-b)(a-ib)
718 % & = (a+b)(a-b)\cdot(a+ib)(a-ib) \\
719 % & = (a^2-b^2)(a^2+b^2) \Arrow[i]{because $(x-y)(x+y)=x^2-y^2$}\\
720 % & = a^4-b^4
721 % \end{WithArrows}$
722 %
723 %
724 % \interitem
725 % The environment |{WithArrows}| gives also a \Definition{group} option. With
726 % this option, \emph{all} the arrows of the environment are grouped on a same
727 % vertical line and at a leftmost position.
728 % \label{group}
729 % %
730 % \begin{Code}
731 % $\begin{WithArrows}[\emph{displaystyle,group}]
732 % 2xy'-3y=\sqrt{x}
733 % & \Longleftrightarrow 2x(K'y_0+Ky_0')-3Ky_0 = \sqrt{x} \\
734 % & \Longleftrightarrow 2xK'y_0 + K(2xy_0'-3y_0) = \sqrt{x} \\
735 % & \Longleftrightarrow 2x K'y_0 = \sqrt{x} \Arrow{...}\\
736 % ...
737 % \end{WithArrows}$
738 % \end{Code}
739 %
740 %
741 % $\begin{WithArrows}[displaystyle,group]
742 % 2xy'-3y=\sqrt{x}
743 % & \Longleftrightarrow 2x(K'y_0+Ky_0')-3Ky_0 = \sqrt{x} \\
744 % & \Longleftrightarrow 2xK'y_0 + K(2xy_0'-3y_0) = \sqrt{x} \\
745 % & \Longleftrightarrow 2x K'y_0 = \sqrt{x}
746 % \Arrow{we replace $y_0$ by its value}\\
747 % & \Longleftrightarrow 2xK'x^{\frac{3}{2}} = x^{\frac{1}{2}}
748 % \Arrow{simplification of the $x$}\\
749 % & \Longleftrightarrow K' = \tfrac{1}{2x^2} \Arrow{antiderivation} \\
750 % & \Longleftrightarrow K = -\tfrac{1}{2x}
751 % \end{WithArrows}$
752 %
753 %
754 % \bigskip
755 % The environment |{WithArrows}| gives also a \Definition{groups} option (with a \emph{s}
756 % in the name). With this option, the arrows are divided into several
757 % ``groups''. Each group is a set of connected\footnote{More precisely: for each
758 % arrow $a$, we note $i(a)$ the number of its initial row and $f(a)$ the number
759 % of its final row; for two arrows $a$ and $b$, we say that $a \sim b$ when
760 % $\llbracket i(a),f(a)\rrbracket \cap \llbracket i(b),f(b)\rrbracket \neq
761 % \varnothing$; the groups are the equivalence classes of the transitive closure
762 % of $\sim$.} arrows. All the arrows of a given group are grouped on a same
763 % vertical line and at a leftmost position.
764 %
765 % \bigskip
766 % $\begin{WithArrows}[groups]
767 % A & = B \Arrow{one} \\
768 % & = C+D \Arrow{two} \\
769 % & = D' \\
770 % & = E+F+G+H+I \\
771 % & = K + L + M \Arrow{three}\\
772 % & = N \Arrow{four}\\
773 % & = O
774 % \end{WithArrows}$
775 %
776 % \bigskip
777 % In an environment which uses the option |group| or the option |groups|, it's
778 % still possible to give an option of position (|ll|, |lr|, |rl|, |rr| or |i|)
779 % to an individual arrow\footnote{Such arrow will be called
780 % \emph{independent} in the technical documentation}. Such arrow will be drawn
781 % irrespective of the groups. It's also possible to start a new group by
782 % applying the option \Definition{new-group} to an given arrow.
783 %
784 % \bigskip
785 % If desired, the option |group| or the option |groups| can be given to the
786 % command |\WithArrowsOptions| so that it will become the default value. In this
787 % case, it's still possible to come back to the default behaviour for a given
788 % environment |{WithArrows}| with the option |rr|: |\begin{WithArrows}[rr]|
789 %
790 %
791 % \vspace{1cm}
792 % In the following example, we have used the option |groups| for the environment
793 % and the option |new-group| for the last arrow (that's why the last arrow is not
794 % aligned with the others).
795 %
796 % \bigskip
797 % $\begin{WithArrows}[interline=1mm,groups]
798 % \sum\limits_{k=0}^n\frac{\cos kx}{\cos^k x}
799 % & = \sum\limits_{k=0}^n \frac{\Re (e^{ikx})}{(\cos x)^k}
800 % \Arrow{$(\cos x)^k$ is real} \\
801 % & = \sum\limits_{k=0}^n \Re\left(\frac{e^{ikx}}{(\cos x)^k}\right)
802 % \Arrow{$\Re(z+z')=\Re(z)+\Re(z')$}\\
803 % & = \Re \left(\sum\limits_{k=0}^n \left(\frac{e^{ix}}{\cos x}\right)^k\right)
804 % \Arrow{sum of terms of a geometric progression} \\
805 % & = \Re \left(\frac{1-\left(\frac{e^{ix}}{\cos x}\right)^{n+1}}{1-\frac{e^{ix}}{\cos x}} \right)
806 % \Arrow{algebraic calculation} \\
807 % & = \Re \left(\frac{1-\frac{e^{i(n+1)x}}{\cos^{n+1}x}}{1-\frac{e^{ix}}{\cos x}}\right)
808 % \Arrow{reduction to common denominator} \\
809 % & = \Re \left(\frac{\frac{\cos^{n+1}x-e^{i(n+1)x}}{\cos^{n+1}x}}{\frac{\cos x-e^{ix}}{\cos x}}\right)
810 % \Arrow{$\Re(kz) = k\cdot\Re(z)$ if $k$ is real} \\
811 % & = \frac1{\cos^n x}\Re \left(\frac{\cos^{n+1}x-e^{i(n+1)x}}{\cos x-e^{ix}}\right)
812 % \Arrow[new-group]{algebraic form of the complexes} \\
813 % & =\frac1{\cos^n x}\Re\left(\frac{\cos^{n+1}x-(\cos(n+1)x+i\sin(n+1)x)}{\cos x-(\cos x+i\sin x)}\right) \\
814 % & =\frac1{\cos^n x}\Re\left(\frac{(\cos^{n+1}x-\cos(n+1)x)-i\sin(n+1)x}{-i\sin x}\right) \\
815 % & = \frac1{\cos^nx}\cdot\frac{\sin(n+1)x}{\sin x}
816 % \end{WithArrows}$
817 %
818 %
819 % \interitem
820 % \section[The option 'o' for individual arrows]%
821 % {The option ``o'' for individual arrows}
822 %
823 % \label{option-o}
824 %
825 % Let's consider, in a given environment, two arrows called $a$ and $b$.
826 % We will note $i_a$ and $i_b$ the numbers of the initial lines of $a$ et $b$
827 % dans $f_a$ and $f_b$ the numbers of the final lines. Of course, we have $i_a
828 % \le f_a$ and $i_b \le f_b$
829 %
830 % \smallskip
831 % We will say that the arrow~$a$ \emph{covers} the arrow~$b$ when $i_a \le i_b
832 % \le f_b \le f_a$. We will also say that the arrow $a$ is \emph{over} the arrow~$b$.
833 %
834 % \bigskip
835 % \parbox{8cm}{In the exemple on the right, the red arrow covers the blue
836 % one.}\hspace{3cm}
837 % $\begin{WithArrows}[c]
838 % A & = B \Arrow[tikz=red,jump=3]{}\\
839 % & = C \Arrow[tikz=blue]{}\\
840 % & = D \\
841 % & = E
842 % \end{WithArrows}$
843 %
844 % \medskip
845 % On the local level, there exists a key \Definition{o}. This key is available
846 % only when the option |group| or the option |groups| is in force
847 % (cf.~p.~\pageref{group}).
848 %
849 % An arrow of type |o| is drawn with an horizontal shift (such as those set by
850 % |xoffset|) automatically computed by taking into account the arrows covered by
851 % our arrow.\footnote{Among the covered arrows, the independent ones (that is to
852 % say with an explicit key |rr|, |ll|, |lr|, |rl|, |i|, |up| or |down|) are not
853 % taken into account in the computation of the value of |xoffset|.}
854 %
855 % \bigskip
856 % \begin{Code}[width=10cm]
857 % $\begin{WithArrows}[groups]
858 % A & = B \Arrow{one}\Arrow[\emph{o},jump=3]{direct} \\
859 % & = C + C \Arrow{two} \\
860 % & = D + D + D \Arrow{three} \\
861 % & = E + E \\
862 % & = F + F
863 % \end{WithArrows}$
864 % \end{Code}
865 % $\begin{WithArrows}[c,groups]
866 % A & = B \Arrow{one}\Arrow[o,jump=3]{direct} \\
867 % & = C + C \Arrow{two} \\
868 % & = D + D + D \Arrow{three} \\
869 % & = E + E \\
870 % & = F + F
871 % \end{WithArrows}$
872 %
873 %
874 % \interitem
875 % Arrows of type |o| may themselves be covered by other arrows of
876 % type~|o|.\par\nobreak
877 %
878 % \bigskip
879 % \begin{Code}
880 % $\begin{WithArrows}[groups]
881 % A & = B \Arrow{one}\Arrow[\emph{o},jump=2]{two}\Arrow[\emph{o},jump=3]{three}\\
882 % & = C \\
883 % & = D \\
884 % & = E + E + E + E + E + E + E
885 % \end{WithArrows}$
886 % \end{Code}
887 %
888 %
889 % \bigskip
890 % $\begin{WithArrows}[c,groups]
891 % A & = B \Arrow{one}\Arrow[o,jump=2]{two}\Arrow[o,jump=3]{three}\\
892 % & = C \\
893 % & = D \\
894 % & = E + E + E + E + E + E + E
895 % \end{WithArrows}$
896 %
897 % \bigskip
898 % The horizontal space between an arrow of type |o| and the arrows immediately
899 % covered is fixed by the dimension \Definition{xoffset-for-o-arrows} which can
900 % be set with the command |\WithArrowsOptions| (initial value: 2~mm).
901 %
902 %
903 % \interitem
904 %
905 % \section[The options 'up' and 'down' for individual arrows]%
906 % {The options ``up'' and ``down'' for individual arrows}
907 %
908 % \label{up-and-down}
909 % At the local level, there are also two options for individual arrows, called
910 % \Definition{up} and \Definition{down}. The following example illustrates these
911 % types of arrows:
912 %
913 % \begin{Code}
914 % \(\begin{WithArrows}
915 % A & = B
916 % \Arrow\emph{[up]}{an arrow of type \texttt{up}} \\
917 % & = C + C + C + C + C + C + C + C \\
918 % & = C + C + C + C + C + C + C + C
919 % \Arrow\emph{[down]}{an arrow of type \texttt{down}} \\
920 % & = E + E
921 % \end{WithArrows}\)
922 % \end{Code}
923 %
924 % \vspace{1cm}
925 % \(\begin{WithArrows}
926 % A & = B
927 % \Arrow[up]{an arrow of type \texttt{up}} \\
928 % & = C + C + C + C + C + C + C + C \\
929 % & = C + C + C + C + C + C + C + C
930 % \Arrow[down]{an arrow of type \texttt{down}} \\
931 % & = E + E
932 % \end{WithArrows}\)
933 %
934 %
935 % \vspace{1cm}
936 % The options |up| and |down| require the Tikz library \pkg{calc}. It it has not
937 % been previously loaded by the user, an error will be raised.
938 %
939 % \vspace{1cm}
940 % In fact, the options |up| and |down| may be used with a value which is a list
941 % of couples key-value.
942 % \begin{itemize}
943 % \item The key \Definition{radius} is the radius of the rounded corner of the
944 % arrow.\footnote{The initial value of this parameter is $4$~pt, which is the
945 % default value of the ``|rounded corners|'' of Tikz.}
946 % \item The key \Definition{width} is the width of the (horizontal part of) the
947 % arrow:
948 % \begin{itemize}
949 % \item with the value \Definition{max}, the width of the arrow is ajusted with
950 % respect of the position of the nodes (that's the behaviour by default of the
951 % arrows |up| and |down| as shown in the previous example);
952 % \item with a numerical value, the width of the arrow is directly fixed to that
953 % numerical value;
954 % \item with the value \Definition{min}, the width of the arrow is adjusted with
955 % respect to the contents of the label of the arrow.
956 % \end{itemize}
957 % \end{itemize}
958 %
959 % \vspace{1cm}
960 % \begin{Code}
961 % $\begin{WithArrows}
962 % A & = B
963 % \Arrow[\emph{up={radius=0pt,width=2cm}}]{we try} \\
964 % & = C + C + C + C + C + C + C + C
965 % \end{WithArrows}$
966 % \end{Code}
967 %
968 % \medskip
969 % $\begin{WithArrows}
970 % A & = B
971 % \Arrow[up={radius=0pt,width=2cm}]{we try} \\
972 % & = C + C + C + C + C + C + C + C
973 % \end{WithArrows}$
974 %
975 %
976 % \vspace{1cm}
977 % \begin{Code}
978 % $\begin{WithArrows}
979 % A & = B
980 % \Arrow[\emph{up={width=min}}]{we try} \\
981 % & = C + C + C + C + C + C + C + C
982 % \end{WithArrows}$
983 % \end{Code}
984 %
985 % \medskip
986 % $\begin{WithArrows}
987 % A & = B
988 % \Arrow[up={width=min}]{we try} \\
989 % & = C + C + C + C + C + C + C + C
990 % \end{WithArrows}$
991 %
992 % \vspace{1cm}
993 % The options relative to the arrows |up| and |down| can be fixed at the global
994 % or environment level with the key \Definition{up-and-down}. This key may also
995 % be used as prefix as illustrated now.
996 % %
997 % \begin{Verbatim}
998 % \WithArrowsOptions{up-and-down/width=min}
999 % \end{Verbatim}
1000 %
1001 % \interitem
1002 %
1003 % \section{Comparison with the environment \{aligned\}}
1004 %
1005 % |{WithArrows}| bears similarities with the environment |{aligned}| of the
1006 % extension \pkg{amsmath}. These are only similarities because |{WithArrows}|
1007 % has not been written upon the environment |{aligned}|.\footnote{In fact, it's
1008 % possible to use the package \pkg{witharrows} without the package
1009 % \pkg{amsmath}.}
1010 %
1011 % \interitem
1012 % As in the environments of \pkg{amsmath}, it's possible to change the spacing
1013 % between two given rows with the option of the command |\\| of end of line
1014 % (it's also possible to use |\\*| but it has exactly the same effect as |\\|
1015 % since an environment |{WithArrows}| is always unbreakable). This option is
1016 % designed to be used with positive values only.
1017 % %
1018 % \begin{Code}
1019 % $\begin{WithArrows}
1020 % A & = (a+1)^2 \Arrow{we expand} \emph{\\[2ex]}
1021 % & = a^2 + 2a + 1
1022 % \end{WithArrows}$
1023 % \end{Code}
1024 %
1025 % $\begin{WithArrows}
1026 % A & = (a+1)^2 \Arrow{we expand} \\*[2ex]
1027 % \noalign{\vspace{3mm}}
1028 % & = a^2 + 2a + 1
1029 % \end{WithArrows}$
1030 %
1031 %
1032 % \interitem
1033 % In the environments of \pkg{amsmath} (or \pkg{mathtools}), the spacing between
1034 % rows is fixed by a parameter called |\jot| (it's a dimension and not a skip).
1035 % That's also the case for the environment |{WithArrows}|. An option
1036 % \Definition{jot} has been given to the environment |{WithArrows}| in order to
1037 % change the value of this parameter |\jot| for a given
1038 % environment.\footnote{It's also possible to change |\jot| with the environment
1039 % |{spreadlines}| of \pkg{mathtools}.}
1040 % %
1041 % \begin{Code}
1042 % $\begin{WithArrows}[displaystyle,\emph{jot=2ex}]
1043 % F & = \frac{1}{2}G \Arrow{we expand}\\
1044 % & = H + \frac{1}{2}K \Arrow{we go on}\\
1045 % & = K
1046 % \end{WithArrows}$
1047 % \end{Code}
1048 %
1049 %
1050 % $\begin{WithArrows}[displaystyle,jot=2ex]
1051 % F & = \frac{1}{2}G \Arrow{we expand}\\
1052 % & = H + \frac{1}{2}K \Arrow{we go on}\\
1053 % & = K
1054 % \end{WithArrows}$
1055 %
1056 %
1057 % \bigskip
1058 % However, this new value of |\jot| will also be used in other alignments
1059 % included in the environment~|{WithArrows}|:
1060 % %
1061 % \begin{Code}
1062 % $\begin{WithArrows}[\emph{jot=2ex}]
1063 % \varphi(x,y) = 0 & \Leftrightarrow (x+y)^2 + (x+2y)^2 = 0
1064 % \Arrow{$x$ and $y$ are real}\\
1065 % & \Leftrightarrow \left\{
1066 % \begin{aligned}
1067 % x+y & = 0 \\
1068 % x+2y & = 0
1069 % \end{aligned}
1070 % \right.
1071 % \end{WithArrows}$
1072 % \end{Code}
1073 %
1074 %
1075 % $\begin{WithArrows}[jot=2ex]
1076 % \varphi(x,y) = 0 & \Leftrightarrow (x+y)^2 + (x+2y)^2 = 0
1077 % \Arrow{$x$ and $y$ are real}\\
1078 % & \Leftrightarrow \left\{
1079 % \begin{aligned}
1080 % x+y & = 0 \\
1081 % x+2y & = 0
1082 % \end{aligned}
1083 % \right.
1084 % \end{WithArrows}$
1085 %
1086 % \bigskip
1087 % Maybe this doesn't correspond to the desired outcome. That's why an option
1088 % \Definition{interline} is proposed. It's possible to use a skip (=glue) for
1089 % this option.
1090 % \begin{Code}
1091 % $\begin{WithArrows}[\emph{interline=2ex}]
1092 % \varphi(x,y) = 0 & \Leftrightarrow (x+y)^2 + (x+2y)^2 = 0
1093 % \Arrow{$x$ and $y$ are real}\\
1094 % & \Leftrightarrow \left\{
1095 % \begin{aligned}
1096 % x+y & = 0 \\
1097 % x+2y & = 0 \\
1098 % \end{aligned}
1099 % \right.
1100 % \end{WithArrows}$
1101 % \end{Code}
1102 %
1103 %
1104 % $\begin{WithArrows}[interline=2ex]
1105 % \varphi(x,y) = 0 & \Leftrightarrow (x+y)^2 + (x+2y)^2 = 0
1106 % \Arrow{$x$ and $y$ are real}\\
1107 % & \Leftrightarrow \left\{
1108 % \begin{aligned}
1109 % x+y & = 0 \\
1110 % x+2y & = 0 \\
1111 % \end{aligned}
1112 % \right.
1113 % \end{WithArrows}$
1114 %
1115 %
1116 % \interitem
1117 % Like the environment |{aligned}|, |{WithArrows}| has an option of placement
1118 % which can assume the values \Definition{t}, \Definition{c} or \Definition{b}.
1119 % However, the initial value is not |c| but |t|. If desired, it's possible to
1120 % have the |c| value as the default with the command |\WithArrowsOptions{c}| at
1121 % the beginning of the document.
1122 % %
1123 % \begin{Verbatim}
1124 % So\enskip
1125 % $\begin{WithArrows}
1126 % A & = (a+1)^2 \Arrow{we expand} \\
1127 % & = a^2 + 2a + 1
1128 % \end{WithArrows}$
1129 % \end{Verbatim}
1130 %
1131 % So\enskip
1132 % $\begin{WithArrows}
1133 % A & = (a+1)^2 \Arrow{we expand} \\
1134 % & = a^2 + 2a + 1
1135 % \end{WithArrows}$
1136 %
1137 % \bigskip
1138 % The value |c| may be useful, for example, if we want to add curly braces:
1139 %
1140 % \smallskip
1141 % \begin{Verbatim}
1142 % Let's set\enskip $~emphase#\left\{@
1143 % \begin{WithArrows}[~emphase#c@]
1144 % f(x) & = 3x^3+2x^2-x+4
1145 % \Arrow[tikz=-]{both are polynoms}\\
1146 % g(x) & = 5x^2-5x+6
1147 % \end{WithArrows}
1148 % ~emphase#\right.@$
1149 % \end{Verbatim}
1150 %
1151 %
1152 % Let's set\enskip $\left\{
1153 % \begin{WithArrows}[c]
1154 % f(x) & = 3x^3+2x^2-x+4
1155 % \Arrow[tikz=-]{both are polynoms}\\
1156 % g(x) & = 5x^2-5x+6
1157 % \end{WithArrows}
1158 % \right.$
1159 %
1160 %
1161 % \interitem
1162 % Unlike |{aligned}|, the environment |{WithArrows}| uses |\textstyle| by
1163 % default.
1164 %
1165 % Once again, it's possible to change this behaviour with |\WithArrowsOptions|:
1166 %
1167 % \smallskip
1168 % |\WithArrowsOptions{displaystyle}|.
1169 %
1170 %
1171 % \smallskip
1172 % The following example is composed with |{aligned}|:\par\nobreak
1173 %
1174 % \smallskip
1175 % $\left\{
1176 % \begin{aligned}
1177 % \sum_{i=1}^n (x_i+1)^2
1178 % & = \sum_{i=1}^n (x_i^2 + 2x_i+1) \\
1179 % & = \sum_{i=1}^n x_i^2 + 2 \sum_{i=1}^nx_i + n
1180 % \end{aligned}
1181 % \right.$
1182 %
1183 %
1184 % \medskip
1185 % The following is composed with |{WithArrows}[c,displaystyle]|. The results are
1186 % strictly identical.\par\nobreak
1187 %
1188 % \smallskip
1189 % $\left\{
1190 % \begin{WithArrows}[c,displaystyle]
1191 % \sum_{i=1}^n (x_i+1)^2
1192 % & = \sum_{i=1}^n (x_i^2 + 2x_i+1) \\
1193 % & = \sum_{i=1}^n x_i^2 + 2 \sum_{i=1}^nx_i + n
1194 % \end{WithArrows}
1195 % \right.$
1196 %
1197 %
1198 % \interitem
1199 % \section{Arrows in nested environments}
1200 %
1201 % \label{NestedEnv}
1202 %
1203 % The environments |{WithArrows}| can be nested. In this case, the options given
1204 % to the encompassing environment applies also to the inner ones (with logical
1205 % exceptions for |interline|, |code-before| and |code-after|). The command
1206 % |\Arrow| can be used as usual in each environment |{WithArrows}|.
1207 %
1208 % \begin{Code}
1209 % $\emph{\begin{WithArrows}}
1210 % \varphi(x,y)=0
1211 % & \Leftrightarrow (x+2y)^2+(2x+4y)^2 = 0 \Arrow{the numbers are real}\\
1212 % & \Leftrightarrow
1213 % \left\{\emph{\begin{WithArrows}}[c]
1214 % x+2y & = 0 \\
1215 % 2x+4y & = 0
1216 % \emph{\end{WithArrows}}\right. \\
1217 % & \Leftrightarrow
1218 % \left\{\emph{\begin{WithArrows}}[c]
1219 % x+2y & = 0 \Arrow[tikz=-]{the same equation}\\
1220 % x+2y & = 0
1221 % \emph{\end{WithArrows}}\right. \\
1222 % & \Leftrightarrow x+2y=0
1223 % \emph{\end{WithArrows}}$
1224 % \end{Code}
1225 %
1226 % $\begin{WithArrows}
1227 % \varphi(x,y)=0
1228 % & \Leftrightarrow (x+2y)^2+(2x+4y)^2 = 0 \Arrow{the numbers are real}\\
1229 % & \Leftrightarrow
1230 % \left\{\begin{WithArrows}[c]
1231 % x+2y & = 0 \\
1232 % 2x+4y & = 0
1233 % \end{WithArrows}\right. \\
1234 % & \Leftrightarrow
1235 % \left\{\begin{WithArrows}[c]
1236 % x+2y & = 0 \Arrow[tikz=-]{the same equation}\\
1237 % x+2y & = 0
1238 % \end{WithArrows}\right. \\
1239 % & \Leftrightarrow x+2y=0
1240 % \end{WithArrows}$
1241 %
1242 % \bigskip
1243 % However, one may want to draw an arrow between rows that are not in the same
1244 % environment. For example, one may want to draw the following arrow
1245 % :\par\nobreak
1246 %
1247 % \bigskip
1248 % $\begin{WithArrows}[code-after = \Arrow[v]{1-2}{2-2}{division by $2$} ]
1249 % \varphi(x,y)=0
1250 % & \Leftrightarrow (x+2y)^2+(2x+4y)^2 = 0 \\
1251 % & \Leftrightarrow
1252 % \left\{\begin{WithArrows}[c]
1253 % x+2y & = 0 \\
1254 % 2x+4y & = 0
1255 % \end{WithArrows}\right. \\
1256 % & \Leftrightarrow
1257 % \left\{\begin{WithArrows}[c]
1258 % x+2y & = 0 \\
1259 % x+2y & = 0
1260 % \end{WithArrows}\right. \\
1261 % & \Leftrightarrow x+2y=0
1262 % \end{WithArrows}$
1263 %
1264 %
1265 % \bigskip
1266 % Such a construction is possible by using |\Arrow| in the |code-after| option.
1267 % Indeed, in |code-after|, a special version of |\Arrow| is available (we will
1268 % call it ``|\Arrow| in |code-after|'').
1269 %
1270 % \smallskip
1271 % A command |\Arrow| in |code-after| takes three arguments :
1272 % \begin{itemize}[beginpenalty=10000]
1273 % \item a specification of the start row of the arrow ;
1274 % \item a specification of the end row of the arrow ;
1275 % \item the label of the arrow.
1276 % \end{itemize}
1277 % As usual, it's also possible to give options within square brackets before or
1278 % after the three arguments. However, these options are limited (see below).
1279 %
1280 % \bigskip
1281 % The specification of the row is constructed with the position of the concerned
1282 % environment in the nesting tree, followed (after an hyphen) by the number of
1283 % that row.
1284 %
1285 % \bigskip
1286 % In the previous example, there are two environments |{WithArrows}| nested in
1287 % the main environment |{WithArrows}|.
1288 %
1289 % $\begin{WithArrows}[tikz-code = {\path (#1) to node {#3} (#2) ; }]
1290 % \varphi(x,y)=0
1291 % & \Leftrightarrow (x+2y)^2+(2x+4y)^2 = 0 \\
1292 % & \Leftrightarrow \color{blue}
1293 % \left\{\begin{WithArrows}[c]
1294 % x+2y & = 0 \Arrow{environment number 1}\\
1295 % 2x+4y & = 0
1296 % \end{WithArrows}\right. \\
1297 % & \Leftrightarrow \color{red}
1298 % \left\{\begin{WithArrows}[c]
1299 % x+2y & = 0 \Arrow{environment number 2}\\
1300 % x+2y & = 0
1301 % \end{WithArrows}\right. \\
1302 % & \Leftrightarrow x+2y=0
1303 % \end{WithArrows}$
1304 %
1305 % \bigskip
1306 % The arrow we want to draw starts in the row~$2$ of the sub-environment
1307 % number~$1$ (and therefore, the specification is |1-2|) and ends in the row~$2$
1308 % of the sub-environment number~$2$ (and therefore, the specification is |2-2|).
1309 % We can draw the arrow with the following command |\Arrow| in |code-after| :
1310 % \begin{Code}
1311 % $\begin{WithArrows}[\emph{code-after = \Arrow{1-2}{2-2}{division by $2$}}]
1312 % \varphi(x,y)=0
1313 % & \Leftrightarrow (x+2y)^2+(2x+4y)^2 = 0 \\
1314 % .........
1315 % \end{WithArrows}$
1316 % \end{Code}
1317 %
1318 % $\begin{WithArrows}[code-after = \Arrow{1-2}{2-2}{division by $2$} ]
1319 % \varphi(x,y)=0
1320 % & \Leftrightarrow (x+2y)^2+(2x+4y)^2 = 0 \\
1321 % & \Leftrightarrow
1322 % \left\{\begin{WithArrows}[c]
1323 % x+2y & = 0 \\
1324 % 2x+4y & = 0
1325 % \end{WithArrows}\right. \\
1326 % & \Leftrightarrow
1327 % \left\{\begin{WithArrows}[c]
1328 % x+2y & = 0 \\
1329 % x+2y & = 0
1330 % \end{WithArrows}\right. \\
1331 % & \Leftrightarrow x+2y=0
1332 % \end{WithArrows}$
1333 %
1334 % \bigskip
1335 % The options allowed for a command |\Arrow| in |code-after| are: |ll|, |lr|,
1336 % |rl|, |rr|, |v|, |xoffset|, |tikz| and |tikz-code|. Except |v|, which is
1337 % specific to |\Arrow| in |code-after|, all these options have their usual
1338 % meaning.
1339 %
1340 % With the option |v|, the arrow drawn is vertical to an abscissa computed with
1341 % the start row and the end row only : the intermediate lines are not taken into
1342 % account unlike with the option |i|. Currently, the option |i| is not available
1343 % for the command~|\Arrow| in |code-after|. However, it's always possible to
1344 % translate an arrow with |xoffset| (or |xshift| of Tikz).
1345 % \begin{Code}
1346 % $\begin{WithArrows}[code-after=\Arrow\emph{[v]}{1-2}{2-2}{division by $2$}]
1347 % \varphi(x,y)=0
1348 % & \Leftrightarrow (x+2y)^2+(2x+4y)^2 = 0 \\
1349 % .........
1350 % \end{WithArrows}$
1351 % \end{Code}
1352 %
1353 % $\begin{WithArrows}[code-after = \Arrow[v]{1-2}{2-2}{division by $2$} ]
1354 % \varphi(x,y)=0
1355 % & \Leftrightarrow (x+2y)^2+(2x+4y)^2 = 0 \\
1356 % & \Leftrightarrow
1357 % \left\{\begin{WithArrows}[c]
1358 % x+2y & = 0 \\
1359 % 2x+4y & = 0
1360 % \end{WithArrows}\right. \\
1361 % & \Leftrightarrow
1362 % \left\{\begin{WithArrows}[c]
1363 % x+2y & = 0 \\
1364 % x+2y & = 0
1365 % \end{WithArrows}\right. \\
1366 % & \Leftrightarrow x+2y=0
1367 % \end{WithArrows}$
1368 %
1369 %
1370 % \interitem
1371 % The package \pkg{witharrows} provides also another command available only in
1372 % |code-after|: the command \DefinitionCommand{MultiArrow}. This command draws a
1373 % ``rak''. The list of the rows of the environment concerned by this rak are
1374 % given in the first argument of the command |\MultiArrow|. This list is given
1375 % with the syntax of the list in a |\foreach| command of \pkg{pgffor}.
1376 %
1377 %
1378 % \begin{Code}
1379 % $\begin{WithArrows}[tikz = rounded corners,
1380 % code-after = {\emph{\MultiArrow{1,...,4}{text}}} ]
1381 % A & = B \\
1382 % & = C \\
1383 % & = D \\
1384 % & = E \\
1385 % & = F
1386 % \end{WithArrows}$
1387 % \end{Code}
1388 %
1389 %
1390 % $\begin{WithArrows}[tikz = rounded corners,
1391 % code-after = {\MultiArrow{1,...,4}{text}}]
1392 % A & = B \\
1393 % & = C \\
1394 % & = D \\
1395 % & = E \\
1396 % & = F
1397 % \end{WithArrows}$
1398 %
1399 % \medskip
1400 % As of now, there is no option available for the command |\MultiArrow| (maybe
1401 % in a future release).
1402 %
1403 %
1404 % \interitem
1405 % \section{Arrows from outside environments \{WithArrows\}}
1406 %
1407 % If someone wants to draw arrows from outside the environments |{WithArrows}|,
1408 % he can use the Tikz nodes created in the environments.
1409 %
1410 % The Tikz name of a node created by \pkg{witharrows} is prefixed by |wa-|.
1411 % Then, we have a list of numbers which give the position in the nesting tree
1412 % and the row number in the environment. At the end, we have the suffixe |l| for
1413 % a ``left node'' and |r| for a ``right node''.
1414 %
1415 % \smallskip
1416 % For illustrative purposes, we give an example of nested environments
1417 % |{WithArrows}|, and, for each ``right node'', the name of that
1418 % node.\footnote{There is an option \Definition{show-node-names} to show the
1419 % names of these nodes.}
1420 %
1421 % \medskip
1422 % \[\begin{WithArrows}[show-nodes,show-node-names]
1423 % A & \vartriangleleft B+B+B+B+B+B+B+B+B+B+B+B+B \\
1424 % & \vartriangleleft \left\{
1425 % \begin{WithArrows}[c]
1426 % C & \vartriangleleft D \\
1427 % E & \vartriangleleft F
1428 % \end{WithArrows}
1429 % \right. \\
1430 % & \vartriangleleft
1431 % \left\{
1432 % \begin{WithArrows}[c]
1433 % G & \vartriangleleft H+H+H+H+H+H+H \\
1434 % I & \vartriangleleft
1435 % \left\{
1436 % \begin{WithArrows}
1437 % J &\vartriangleleft K \\
1438 % L &\vartriangleleft M
1439 % \end{WithArrows}
1440 % \right.
1441 % \end{WithArrows}
1442 % \right. \\
1443 % & \vartriangleleft
1444 % \left\{
1445 % \begin{WithArrows}[c]
1446 % N & \vartriangleleft O \\
1447 % P & \vartriangleleft Q
1448 % \end{WithArrows}
1449 % \right.
1450 % \end{WithArrows}\]
1451 %
1452 % \medskip
1453 % The package \pkg{witharrows} provides some tools facilitating the use of these
1454 % nodes:
1455 % \begin{itemize}[beginpenalty=10000]
1456 % \item the command \DefinitionCommand{WithArrowsLastEnv} gives the number of
1457 % the last environment of level~$0$ (\emph{i.e.} which is not included in
1458 % another environment of the package \pkg{witharrows});
1459 %
1460 % \item a name can be given to a given environment with the option
1461 % \Definition{name} and, in this case, the nodes created in the environment will
1462 % have aliases constructed with this name;
1463 %
1464 % \item the Tikz style \Definition{WithArrows/arrow} is the style used by
1465 % \pkg{witharrows} when drawing an arrow\footnote{More precisely, this style is
1466 % given to the Tikz option ``|every path|'' before drawing the arrow with the
1467 % code of the option |tikz-code|. This style is modified (in TeX scopes) by the
1468 % option |tikz| of \pkg{witharrows}.};
1469 %
1470 % \item the Tikz style \Definition{WithArrows/arrow/tips} is the style for the
1471 % tip of the arrow (loaded by |WithArrows/arrow|).
1472 % \end{itemize}
1473 %
1474 % For example, we can draw an arrow from
1475 % \texttt{wa-\WithArrowsLastEnv-2-1-2-r.south} to
1476 % \texttt{wa-\WithArrowsLastEnv-3-2-r.north} with the following Tikz command.
1477 %
1478 % \begin{Verbatim}
1479 % \begin{tikzpicture}[remember picture,overlay]
1480 % \draw [WithArrows/arrow]
1481 % ([xshift=3mm]wa-\WithArrowsLastEnv-2-1-2-r.south)
1482 % to ([xshift=3mm]wa-\WithArrowsLastEnv-3-2-r.north) ;
1483 % \end{tikzpicture}
1484 % \end{Verbatim}
1485 %
1486 % \[\begin{WithArrows}
1487 % A & \vartriangleleft B+B+B+B+B+B+B+B+B+B+B+B+B \\
1488 % & \vartriangleleft \left\{
1489 % \begin{WithArrows}[c]
1490 % C & \vartriangleleft D \\
1491 % E & \vartriangleleft F
1492 % \end{WithArrows}
1493 % \right. \\
1494 % & \vartriangleleft
1495 % \left\{
1496 % \begin{WithArrows}[c]
1497 % G & \vartriangleleft H+H+H+H+H+H+H \\
1498 % I & \vartriangleleft
1499 % \left\{
1500 % \begin{WithArrows}
1501 % J &\vartriangleleft K \\
1502 % L &\vartriangleleft M
1503 % \end{WithArrows}
1504 % \right.
1505 % \end{WithArrows}
1506 % \right. \\
1507 % & \vartriangleleft
1508 % \left\{
1509 % \begin{WithArrows}[c]
1510 % N & \vartriangleleft O \\
1511 % P & \vartriangleleft Q
1512 % \end{WithArrows}
1513 % \right.
1514 % \end{WithArrows}
1515 % \begin{tikzpicture}[remember picture,overlay]
1516 % \draw [WithArrows/arrow]
1517 % ([xshift=3mm]wa-\WithArrowsLastEnv-2-1-2-r.south)
1518 % to ([xshift=3mm]wa-\WithArrowsLastEnv-3-2-r.north) ;
1519 % \end{tikzpicture}\]
1520 %
1521 % \medskip
1522 % In this case, it would be easier to use a command |\Arrow| in |code-after| but
1523 % this is an example to explain how the Tikz nodes created by \pkg{witharrows}
1524 % can be used.
1525 %
1526 % \bigskip
1527 % In the following example, we create two environments |{WithArrows}| named
1528 % ``|first|'' and ``|second|'' and we draw a line between a node of the first
1529 % and a node of the second.
1530 %
1531 % \begin{Code}
1532 % $\begin{WithArrows}[\emph{first}]
1533 % A & = B \\
1534 % & = C
1535 % \end{WithArrows}$
1536 %
1537 % \bigskip
1538 % $\begin{WithArrows}[\emph{second}]
1539 % A' & = B' \\
1540 % & = C'
1541 % \end{WithArrows}$
1542 %
1543 % \begin{tikzpicture}[remember picture,overlay]
1544 % \draw [WithArrows/arrow]
1545 % ([xshift=3mm]\emph{first}-1-r.south)
1546 % to ([xshift=3mm]\emph{second}-1-r.north) ;
1547 % \end{tikzpicture}
1548 % \end{Code}
1549 %
1550 %
1551 % \begin{center}
1552 % $\begin{WithArrows}[name=first]
1553 % A & = B \\
1554 % & = C
1555 % \end{WithArrows}$
1556 %
1557 % \bigskip
1558 % $\begin{WithArrows}[name=second]
1559 % A' & = B' \\
1560 % & = C'
1561 % \end{WithArrows}$
1562 % \end{center}
1563 %
1564 % \begin{tikzpicture}[remember picture,overlay]
1565 % \draw [WithArrows/arrow]
1566 % ([xshift=3mm]first-1-r.south)
1567 % to ([xshift=3mm]second-1-r.north) ;
1568 % \end{tikzpicture}
1569 %
1570 % \interitem
1571 % \section{The environment \{DispWithArrows\}}
1572 % \label{DispWithArrows}
1573 %
1574 % As previously said, the environment |{WithArrows}| bears similarities with the
1575 % environment |{aligned}| of \pkg{amsmath} (and |mathtools|). This extension
1576 % also provides an environment \Definition{\{DispWithArrows\}} which is similar
1577 % to the environments |{align}| and |{flalign}| of \pkg{amsmath}.
1578 %
1579 % \medskip
1580 % The environment |{DispWithArrows}| must be used \emph{outside} math mode. Like
1581 % |{align}|, it should be used in horizontal mode.
1582 % \begin{Code}
1583 % \emph{\begin{DispWithArrows}}
1584 % A & = (a+1)^2 \Arrow{we expand} \\
1585 % & = a^2 + 2a + 1
1586 % \emph{\end{DispWithArrows}}
1587 % \end{Code}
1588 % \begin{DispWithArrows}
1589 % A & = (a+1)^2 \Arrow{we expand} \\
1590 % & = a^2 + 2a + 1
1591 % \end{DispWithArrows}
1592 %
1593 % \medskip
1594 % It's possible to use the command \DefinitionCommand{notag} (or
1595 % \DefinitionCommand{nonumber}) to suppress a tag.
1596 %
1597 % It's possible to use the command \DefinitionCommand{tag} to put a special tag
1598 % (e.g. $\star$).
1599 %
1600 % It's also possible to put a label to the line of an equation with the command
1601 % \DefinitionCommand{label}.
1602 %
1603 % These commands must be in the second column of the environment.
1604 % \begin{Code}
1605 % \begin{DispWithArrows}
1606 % A & = (a+1)^2 \Arrow{we expand} \emph{\notag} \\
1607 % & = a^2 + 2a + 1 \emph{\tag{$\star$} \label{my-equation}}
1608 % \end{DispWithArrows}
1609 % \end{Code}
1610 % \begin{DispWithArrows}
1611 % A & = (a+1)^2 \Arrow{we expand} \notag \\
1612 % & = a^2 + 2a + 1 \tag{$\star$} \label{my-equation}
1613 % \end{DispWithArrows}
1614 % A link to the equation \ref{my-equation}.\footnote{In this document, the
1615 % references have been customized with |\labelformat{equation}{(#1)}| in the preamble.}
1616 %
1617 %
1618 % \medskip
1619 % If \pkg{amsmath} (or \pkg{mathtools}) is loaded, it's also possible to use
1620 % |\tag*| which, as in \pkg{amsmath}, typesets the tag without the parentheses.
1621 % For example, it's possible to use it to put the symbol |\square| of
1622 % \pkg{amssymb}. This symbol is often used to mark the end of a
1623 % proof.\footnote{Notice that the environment |{DispWithArrows}| is compatible
1624 % with the command |\qedhere| of \pkg{amsthm}.}
1625 % \begin{Code}
1626 % \begin{DispWithArrows}
1627 % A & = (a+1)^2 \Arrow{we expand} \notag \\
1628 % & = a^2 + 2a + 1 \emph{\tag*{$\square$}}
1629 % \end{DispWithArrows}
1630 % \end{Code}
1631 % \begin{DispWithArrows}
1632 % A & = (a+1)^2 \Arrow{we expand} \notag \\
1633 % & = a^2 + 2a + 1 \tag*{$\square$}
1634 % \end{DispWithArrows}
1635 %
1636 % \medskip
1637 % It's also possible to suppress all the autogenerated numbers with the boolean
1638 % option \Definition{notag} (or \Definition{nonumber}), at the global or
1639 % environment level. There is also an environment
1640 % \Definition{\{DispWithArrows*\}} which suppresses all these
1641 % numbers.\footnote{Even in this case, it's possible to put a ``manual tag''
1642 % with the command |\tag|.}
1643 % \begin{Code}
1644 % \emph{\begin{DispWithArrows*}}
1645 % A & = (a+1)^2 \Arrow{we expand} \\
1646 % & = a^2 + 2a + 1
1647 % \emph{\end{DispWithArrows*}}
1648 % \end{Code}
1649 % \begin{DispWithArrows*}
1650 % A & = (a+1)^2 \Arrow{we expand} \\
1651 % & = a^2 + 2a + 1
1652 % \end{DispWithArrows*}
1653 %
1654 % \medskip
1655 % In fact, there is also another option \Definition{tagged-lines} which can be used to
1656 % control the lines that will be tagged. The value of this option is a list of
1657 % the numbers of the lines that must to be tagged. For example, with the option
1658 % |tagged-lines = {first,3,last}|, only the first, the third and the last line
1659 % of the environment will be tagged. There is also the special value |all| which
1660 % means that all the lines will be tagged.
1661 % \begin{Code}
1662 % \begin{DispWithArrows}[tagged-lines = last]
1663 % A & = A_1 \Arrow{first stage} \\
1664 % & = A_2 \Arrow{second stage} \\
1665 % & = A_3
1666 % \end{DispWithArrows}
1667 % \end{Code}
1668 % \begin{DispWithArrows}[tagged-lines = last]
1669 % A & = A_1 \Arrow{first stage} \\
1670 % & = A_2 \Arrow{second stage} \\
1671 % & = A_3
1672 % \end{DispWithArrows}
1673 %
1674 % \bigskip
1675 % With the option \Definition{fleqn}, the environment is composed flush left (in
1676 % a way similar to the option |fleqn| of the standard classes of LaTeX). In this
1677 % case, the left margin can be controlled with the option
1678 % \Definition{mathindent} (with a name inspired by the parameter |\mathindent|
1679 % of standard LaTeX. The initial value of this parameter is 25~pt. It's possible
1680 % to use as value for that key a \emph{skip} (=\emph{glue}).
1681 %
1682 % \begin{Code}
1683 % \begin{DispWithArrows}\emph{[fleqn,mathindent = 1cm]}
1684 % A & = (a+1)^2 \Arrow{we expand} \\
1685 % & = a^2 + 2a + 1
1686 % \end{DispWithArrows}
1687 % \end{Code}
1688 % \begin{DispWithArrows}[fleqn,mathindent = 1cm]
1689 % A & = (a+1)^2 \Arrow{we expand} \\
1690 % & = a^2 + 2a + 1
1691 % \end{DispWithArrows}
1692 %
1693 % \medskip
1694 % \emph{Remark}: By design, the option |fleqn| of \pkg{witharrows} is
1695 % independent of the option |fleqn| of LaTeX. Indeed, since the environments of
1696 % \pkg{witharrows} are meant to be used with arrows on the right side, the user
1697 % may want to use \pkg{witharrows} with the option |fleqn| (in order to have
1698 % more space on the right of the equations for the arrows) while still centering
1699 % the classical equations.
1700 %
1701 % \medskip
1702 % If the option |leqno| is used as a class option, the labels will be composed
1703 % on the left also for the environments |{DispWithArrows}| and
1704 % |{DispWithArrows*}|.\footnote{The package \pkg{amsmath} has an option |leqno|
1705 % but \pkg{witharrows}, of course, is not aware of that option: \pkg{witharrows}
1706 % only checks the option |leqno| of the document class.}
1707 %
1708 % \medskip
1709 % If the package \pkg{amsmath} is loaded, it's possible to use the command
1710 % |\intertext| in the environments |{DispWithArrows}|. It's also possible to use
1711 % the environment |{subequations}|. However, there is, for the environments
1712 % |{DispWithArrows}|, an option \Definition{subequations} to encapsulate the
1713 % environment in an environment |{subequations}|.
1714 %
1715 % \medskip
1716 % In the following example, the key |{subequations}| is fixed by the command
1717 % |\WithArrowsOptions|. Each environment |{DispWithArrows}| will be subnumerated
1718 % (in the scope of |\WithArrowsOptions|)
1719 % \begin{Code}
1720 % \emph{\WithArrowsOptions{subequations}}
1721 % First environment.
1722 % \begin{DispWithArrows}
1723 % A & = B \\
1724 % & = C
1725 % \end{DispWithArrows}
1726 % Second environment.
1727 % \begin{DispWithArrows}
1728 % D & = E \\
1729 % & = F
1730 % \end{DispWithArrows}
1731 % \end{Code}
1732 % %
1733 % \begin{scope}
1734 % \WithArrowsOptions{subequations}
1735 % First environment.
1736 % \begin{DispWithArrows}
1737 % A & = B \\
1738 % & = C
1739 % \end{DispWithArrows}
1740 % Second environment.
1741 % \begin{DispWithArrows}
1742 % D & = E \\
1743 % & = F
1744 % \end{DispWithArrows}
1745 % \end{scope}
1746 %
1747 % \bigskip
1748 % If there is not enough space to put the tag at the end of a line, there is no
1749 % automatic positioning of the label on the next line (as in the environments of
1750 % \pkg{amsmath}). However, in |{DispWithArrows}|, the user can use the command
1751 % \DefinitionCommand{tagnextline} to manually require the composition of the tag
1752 % on the following line.
1753 % \begin{Code}
1754 % \begin{DispWithArrows}[displaystyle]
1755 % S_{2(p+1)}
1756 % & =\sum_{k=1}^{2(p+1)} (-1)^k k^2 \\
1757 % & \smash[b]{=\sum_{k=1}^{2p}(-1)^kk
1758 % +(-1)^{2p+1}(2p+1)^2+(-1)^{2p+2}(2p+2)^2} \emph{\tagnextline} \\
1759 % &= S_{2p}-(2p+1)^2+(2p+2)^2\\
1760 % &=p(2p+1)-(2p+1)^2+(2p+2)^2\\
1761 % &= 2p^2+5p+3
1762 % \end{DispWithArrows}
1763 % \end{Code}
1764 % \begin{center}
1765 % \color{gray}\vrule%
1766 % \begin{minipage}{275pt}\color{black}
1767 % \begin{DispWithArrows}[displaystyle]
1768 % S_{2(p+1)}
1769 % & =\sum_{k=1}^{2(p+1)} (-1)^k k^2 \\
1770 % & \smash[b]{=\sum_{k=1}^{2p}(-1)^kk^2+(-1)^{2p+1}(2p+1)^2+(-1)^{2p+2}(2p+2)^2}
1771 % \tagnextline \\
1772 % &= S_{2p}-(2p+1)^2+(2p+2)^2\\
1773 % &= 2p^2+p-4p^2-4p-1+4p^2+8p+4\\
1774 % &= 2p^2+5p+3
1775 % \end{DispWithArrows}
1776 % \end{minipage}%
1777 % \color{gray}\vrule
1778 % \end{center}
1779 %
1780 %
1781 %
1782 % \bigskip
1783 % The environments |{DispWithArrows}| and |{DispWithArrows*}| provide an option
1784 % \Definition{wrap-lines}. With this option, the lines of the labels are
1785 % automatically wrapped on the
1786 % right.\footnotemark[\thefnnohyphen]\label{wrap-lines}
1787 %
1788 % \begin{Code}
1789 % \begin{DispWithArrows*}\emph{[displaystyle,wrap-lines]}
1790 % S_n
1791 % & = \frac{1}{n} \Re \left(\sum_{k=0}^{n-1}\bigl(e^{i\frac{\pi}{2n}}\bigr)^k\right)
1792 % \Arrow{sum of terms of a geometric progression of ratio $e^{i\frac{2\pi}n}$}\\
1793 % & = \frac{1}{n} \Re \left( \frac{1-\bigl(e^{i\frac{\pi}{2n}}\bigr)^n}
1794 % {1-e^{i\frac{\pi}{2n}}}\right)
1795 % \Arrow{This line has been wrapped automatically.} \\
1796 % & = \frac{1}{n} \Re \left(\frac{1-i}{1-e^{i\frac{\pi}{2n}}}\right)
1797 % \end{DispWithArrows*}
1798 % \end{Code}
1799 % \begin{DispWithArrows*}[displaystyle,wrap-lines]
1800 % S_n
1801 % & = \frac{1}{n} \Re \left(\sum_{k=0}^{n-1}\bigl(e^{i\frac{\pi}{2n}}\bigr)^k\right)
1802 % \Arrow{sum of terms of a geometric progression of ratio $e^{i\frac{2\pi}n}$}\\
1803 % & = \frac{1}{n} \Re \left(
1804 % \frac{1-\bigl(e^{i\frac{\pi}{2n}}\bigr)^n}{1-e^{i\frac{\pi}{2n}}} \right)
1805 % \Arrow{This line has been wrapped automatically.} \\
1806 % & = \frac{1}{n} \Re \left(\frac{1-i}{1-e^{i\frac{\pi}{2n}}}\right)
1807 % \end{DispWithArrows*}
1808 %
1809 % \bigskip
1810 % The option |wrap-lines| doesn't apply to the environments |{WithArrows}|
1811 % nested in an environment |{DispWithArrows}| or |{DispWithArrows*}|. However,
1812 % it applies to the instructions |\Arrow| and |\MultiArrow| of the |code-after|
1813 % of the environments |{DispWithArrows}| or |{DispWithArrows*}|.
1814 %
1815 % \vspace{1cm}
1816 % We have said that the environments |{DispWithArrows}| and |{DispWithArrows*}|
1817 % should be used in horizontal mode and not in vertical mode. However, there is
1818 % an exception. These environments can be used directly after a |\item| of a
1819 % LaTeX list. In this case, no vertical space is added before the
1820 % environment.\footnote{It's possible to disable this feature with the option |standard-behaviour-with-items|.}
1821 %
1822 % \medskip
1823 % Here is an example. The use of |{DispWithArrows}| gives the ability to tag an
1824 % equation (and also to use |wrap-lines|).
1825 %
1826 % \begin{Code}
1827 % \emph{\begin{enumerate}
1828 % \item }
1829 % \begin{DispWithArrows}%
1830 % [displaystyle, wrap-lines, tagged-lines = last, fleqn, mathindent = 0 pt]
1831 % S_n
1832 % & = \frac{1}{n} \Re \left(\sum_{k=0}^{n-1}\bigl(e^{i\frac{\pi}{2n}}\bigr)^k\right)
1833 % \Arrow{we use the formula for a sum of terms of a geometric progression of
1834 % ratio $e^{i\frac{2\pi}n}$}\\
1835 % & = \frac{1}{n} \Re \left( \frac{1-\bigl(e^{i\frac{\pi}{2n}}\bigr)^n}
1836 % {1-e^{i\frac{\pi}{2n}}}\right)
1837 % \Arrow{$\bigl(e^{i\frac{\pi}{2n}}\bigr)^n = e^{i\frac{\pi}{2}}=i$} \\
1838 % & = \frac{1}{n} \Re \left(\frac{1-i}{1-e^{i\frac{\pi}{2n}}}\right)
1839 % \end{DispWithArrows}
1840 % \emph{\end{enumerate}}
1841 % \end{Code}
1842 % \begin{enumerate}
1843 % \item
1844 % \begin{DispWithArrows}[displaystyle, wrap-lines, tagged-lines = last, fleqn, mathindent = 0 pt]
1845 % S_n
1846 % & = \frac{1}{n} \Re \left(\sum_{k=0}^{n-1}\bigl(e^{i\frac{\pi}{2n}}\bigr)^k\right)
1847 % \Arrow{we use the formula for a sum of terms of a geometric progression of
1848 % ratio $e^{i\frac{2\pi}n}$}\\
1849 % & = \frac{1}{n} \Re \left(
1850 % \frac{1-\bigl(e^{i\frac{\pi}{2n}}\bigr)^n}{1-e^{i\frac{\pi}{2n}}} \right)
1851 % \Arrow{$\bigl(e^{i\frac{\pi}{2n}}\bigr)^n = e^{i\frac{\pi}{2}}=i$} \\
1852 % & = \frac{1}{n} \Re \left(\frac{1-i}{1-e^{i\frac{\pi}{2n}}}\right)
1853 % \end{DispWithArrows}
1854 % \end{enumerate}
1855 %
1856 % \vspace{1cm}
1857 % The environment |{DispWithArrows}| is similar to the environment |{align}| of
1858 % \pkg{amsmath}. However, |{DispWithArrows}| is not constructed upon |{align}|
1859 % (in fact, it's possible to use \pkg{witharrows} without \pkg{amsmath}).
1860 %
1861 % There are differences between |{DispWithArrows}| and |{align}|.
1862 % \begin{itemize}[beginpenalty=10000]
1863 % \item The environment |{DispWithArrows}| cannot be inserted in an environment
1864 % |{gather}| of \pkg{amsmath}.
1865 % \item An environment |{DispWithArrows}| is always unbreakable (even with
1866 % |\allowdisplaybreaks| of \pkg{amsmath}).
1867 % \item The commands |\label|, |\tag|, |\notag| and |\nonumber| are allowed only
1868 % in the last column.
1869 % \item After an |\item| of a LaTeX list, no vertical space is added (this can
1870 % be changed with the option |standard-behaviour-with-items|).
1871 % \item
1872 % \begin{bfseries}
1873 % Last but not least, by default, the elements of a |\{DispWithArrows\}|
1874 % are composed in |textstyle| and not in |displaystyle| (it's possible to change
1875 % this point with the option |displaystyle|).
1876 % \end{bfseries}
1877 % \end{itemize}
1878 %
1879 % \bigskip
1880 % Concerning the references, the package \pkg{witharrows} is compatible with the
1881 % extensions \pkg{autonum}, \pkg{cleveref}, \pkg{fancyref},
1882 % \pkg{hyperref}, \pkg{listlbls}, \pkg{prettyref}, \pkg{refcheck},
1883 % \pkg{refstyle}, \pkg{showlabels}, \pkg{smartref}, \pkg{typedref} and
1884 % \pkg{varioref}, and with the options |showonlyrefs| and |showmanualtags| of
1885 % \pkg{mathtools}.\footnote{We recall that \pkg{varioref}, \pkg{hyperref},
1886 % \pkg{cleveref} and \pkg{autonum} must be loaded in this order. The package
1887 % \pkg{witharrows} can be loaded anywhere.}
1888 %
1889 % It is not compatible with \pkg{showkeys} (not all the labels are shown).
1890 %
1891 %
1892 %
1893 %
1894 % \subsection{The option <...> of DispWithArrows}
1895 %
1896 % The environment |{DispWithArrows}| provides an option \Definition{left-brace}.
1897 % When present, the value of this option is composed on the left, followed by a
1898 % curly brace (hence the name) and the body of the environment.\footnote{The
1899 % option |left-brace| can also be used without value: in this case, only the
1900 % brace is drawn...}
1901 %
1902 % For lisibility, this option |left-brace| is also available with a special
1903 % syntax: it's possible to give this option between angle brackets
1904 % (|<| and |>|) just after |{DispWithArrows}| (before the optional
1905 % arguments between square brackets).
1906 %
1907 % \bigskip
1908 % The following code is an example of multi-case equations.\footnote{The
1909 % environment |{cases}| of \pkg{amsmath} is a way to compose such multi-cases
1910 % equations. However, it's not possible to use the automatic numbering of
1911 % equations with this environment. The environment |{numcases}| of the extension
1912 % \pkg{cases} (written by Donald Arseneau) provides this possibility but, of
1913 % course, it's not possible to draw arrows with this extension.}
1914 %
1915 % \medskip
1916 %
1917 % \begin{Code}
1918 % \begin{DispWithArrows}\emph{< \binom{n}{p} = >}[format = ll,fleqn,displaystyle]
1919 % 0 & \quad \text{if } p > n
1920 % \Arrow{if fact, it's a special case\\ of the following one} \\
1921 % \frac{n(n-1)\cdots(n-p+1)}{p!} & \quad \text{if } 0 \leq p \leq n \\
1922 % 0 & \quad \text{if } p < 0
1923 % \end{DispWithArrows}
1924 % \end{Code}
1925 % %
1926 % \begin{DispWithArrows}< \binom{n}{p} = >[format = ll,fleqn,displaystyle]
1927 % 0 & \quad \text{if } p > n
1928 % \Arrow{if fact, it's a special case\\ of the following one} \\
1929 % \frac{n(n-1)\cdots(n-p+1)}{p!} & \quad \text{if } 0 \leq p \leq n \\
1930 % 0 & \quad \text{if } p < 0
1931 % \end{DispWithArrows}
1932 %
1933 % \interitem
1934 % In the following example, we subnumerate the equations with the option
1935 % |subequations| (available when the package \pkg{amsmath} is loaded).
1936 %
1937 % \begin{Code}
1938 % \begin{DispWithArrows}\emph{< \label{system} \ref*{system} \Leftrightarrow >}[
1939 % format = l, subequations ]
1940 % x+y+z = -3 \Arrow[tikz=-,jump=2]{3 equations} \\
1941 % xy+xz+yz=-2 \\
1942 % xyz = -15 \label{last-equation}
1943 % \end{DispWithArrows}
1944 % \end{Code}
1945 % %
1946 % \begin{DispWithArrows}< \label{system} \ref*{system} \Leftrightarrow >[
1947 % format = l, subequations]
1948 % x+y+z = -3 \Arrow[tikz=-,jump=2]{3 equations} \\
1949 % xy+xz+yz=-2 \\
1950 % xyz = -15 \label{last-equation}
1951 % \end{DispWithArrows}
1952 %
1953 %
1954 % \bigskip
1955 % The whole system is the equation \ref{system} (this reference has been coded
1956 % by |\ref{system}|) whereas the last equation is the equation
1957 % \ref{last-equation} (this reference has been coded by
1958 % |\ref{last-equation}|). The command |\ref*| used in the code above is a
1959 % variant of the command |\ref| which does not create interactive link (even when
1960 % \pkg{hyperref} is loaded).
1961 %
1962 % \bigskip
1963 % With the option \Definition{replace-left-brace-by}, it's possible to replace the
1964 % left curly brace by another extensible delimiter. For example,
1965 % ``|replace-left-brace-by = [\enskip|'' will compose with a bracket and add
1966 % also a |\enskip| after this bracket.
1967 %
1968 % \interitem
1969 % \section{Advanced features}
1970 %
1971 % \subsection{Utilisation with Beamer}
1972 %
1973 % \colorbox{yellow!50}{\textbf{New 2.9}}\par\nobreak
1974 %
1975 % \smallskip
1976 % If \pkg{witharrows} is used with Beamer, the command |\Arrow| takes in as
1977 % argument between angular brackets (after the optional argument in square
1978 % brackets) to specify the \emph{overlays} which are implied (internally,
1979 % \pkg{witharrows} merely uses the command |\only| of Beamer).
1980 %
1981 % \begin{Code}
1982 % \Arrow[jump=2]\emph{<3->}{Example}
1983 % \end{Code}
1984 %
1985 % \subsection{Use with plain-TeX}
1986 % \label{plain-TeX}
1987 %
1988 % The extension \pkg{witharrows} can be used with plain-TeX. In this case, the
1989 % extension must be loaded with |\input|:
1990 % \begin{Verbatim}
1991 % \input{witharrows}
1992 % \end{Verbatim}
1993 %
1994 % \medskip
1995 % In plain-TeX, there is not environments as in LaTeX. Instead of using the
1996 % environment |{Witharrows}|, with |\begin{WithArrows}| and |\end{WithArrows}|,
1997 % one should use a pseudo-environment delimited by |\WithArrows| and
1998 % |\endWithArrows| (idem for |{DispWithArrows}|).
1999 %
2000 % \begin{Verbatim}
2001 % $\WithArrows
2002 % A & = (a+1)^2 \Arrow{we expand} \\
2003 % & = a^2 + 2a + 1
2004 % \endWithArrows$
2005 % \end{Verbatim}
2006 %
2007 % \medskip
2008 % The version of \pkg{witharrows} for plain-TeX doesn't provide all the
2009 % functionalities of the LaTeX version. In particular, the functionalities which
2010 % deal with the number of the equations are not available (since they rely upon
2011 % the system of tags of LaTeX).
2012 %
2013 % \bigskip
2014 % \subsection{The option tikz-code : how to change the shape of the arrows}
2015 %
2016 % \label{tikz-code}
2017 %
2018 % The option \Definition{tikz-code} allows the user to change the shape of the
2019 % arrows.\footnote{If the option |wrap-lines| is used in an environment
2020 % |{DispWithArrows}| or |{DispWithArrows*}|, the option |tikz-code| will have no
2021 % effect for the arrows of this environment but only for the arrows in the
2022 % nested environments |{WithArrows}|.}
2023 %
2024 % \smallskip
2025 % For example, the options ``|up|'' and ``|down|'' described previously (cf.
2026 % p.~\pageref{up-and-down}) are programmed internally with |tikz-code|.
2027 %
2028 % \smallskip
2029 % The value of this option must be a valid Tikz drawing instruction (with the
2030 % final semicolon) with three markers |#1|, |#2| and |#3| for the start point,
2031 % the end point and the label of the arrow.
2032 %
2033 % \bigskip
2034 % The initial value is the following:
2035 %
2036 % \smallskip
2037 % \qquad |\draw (#1) to node {#3} (#2) ;|
2038 %
2039 %
2040 % \bigskip
2041 % In the following example, we replace this default path by a path with three
2042 % segments (and the node overwriting the second segment).
2043 % \begin{Code}
2044 % \begin{WithArrows}[format=c,ygap=5pt,interline=4mm,
2045 % \emph{tikz-code = {\draw[rounded corners]
2046 % (#1) -- ([xshift=5mm]#1)
2047 % -- node[circle,
2048 % draw,
2049 % auto = false,
2050 % fill = gray!50,
2051 % inner sep = 1pt] {\tiny #3}
2052 % ([xshift=5mm]#2)
2053 % -- (#2) ; }}]
2054 % 3 (2x+4) = 6 \Arrow{$\div 3$} \\
2055 % 2x+4 = 2 \Arrow{$-4$} \\
2056 % 2x = -2 \Arrow{$\div 2$} \\
2057 % x = -1
2058 % \end{WithArrows}
2059 % \end{Code}
2060 %
2061 %
2062 % \[\begin{WithArrows}[format=c,
2063 % ygap=5pt,
2064 % interline=4mm,
2065 % tikz-code = {\draw[rounded corners]
2066 % (#1)
2067 % --
2068 % ([xshift=5mm]#1)
2069 % -- node[circle,
2070 % draw,
2071 % auto=false,
2072 % fill=gray!50,
2073 % inner sep = 1pt] {\tiny #3}
2074 % ([xshift=5mm]#2)
2075 % --
2076 % (#2) ; }]
2077 % 3 (2x+4) = 6 \Arrow{$\div 3$} \\
2078 % 2x+4 = 2 \Arrow{$-4$} \\
2079 % 2x = -2 \Arrow{$\div 2$} \\
2080 % x = -1
2081 % \end{WithArrows}\]
2082 %
2083 % \bigskip
2084 % The environments |{DispWithArrows}| and its starred version
2085 % |{DispWithArrows*}| provide a command \DefinitionCommand{WithArrowsRightX}
2086 % which can be used in a definition of |tikz-code|. This command gives the
2087 % $x$-value of the right side of the composition box (taking into account the
2088 % eventual tags of the equations). For an example of use, see
2089 % p.~\pageref{example-WithArrowsRightX}.
2090 %
2091 %
2092 % \bigskip
2093 % \subsection{The command \textbackslash WithArrowsNewStyle}
2094 %
2095 % The extension \pkg{witharrows} provides a command |\WithArrowsNewStyle| to
2096 % define styles in a way similar to the ``styles'' of Tikz.
2097 %
2098 % \smallskip
2099 % The command |\WithArrowsNewStyle| takes two mandatory arguments. The first is
2100 % the name of the style and the second is a list of key-value pairs. The scope
2101 % of the definition done by |\WithArrowsNewStyle| is the current TeX
2102 % scope.\footnote{We recall that, in particular, every LaTeX environment is a
2103 % TeX group.}
2104 %
2105 % \smallskip
2106 % The style can be used as a key at the document level (with
2107 % |\WithArrowsOptions|) or at the environment level (in the optional arguments
2108 % of |{WithArrows}| and |{DispWithArrows}|). The style can also be used in
2109 % another command |\WithArrowsNewStyle|.
2110 %
2111 % \smallskip
2112 % For an example of use, see p.~\pageref{example-WithArrowsRightX}.
2113 %
2114 % \bigskip
2115 % At this time, there is no style for indivual arrows. However, it's, of course,
2116 % possible to define new commands based upton the command |\Arrow|. For example :
2117 %
2118 % \begin{Verbatim}
2119 % \newcommand{\ThickArrow}{\Arrow[tikz=thick]}
2120 % \end{Verbatim}
2121 %
2122 % This new command |\ThickArrow| still accepts options between square brackets.
2123 % It's possible to write |\ThickArrow[jump=2]| because, in fact,
2124 % |\Arrow[tikz=thick][jump=2]| is an allowed syntax for the command |\Arrow|
2125 % (it's possible to put an arbitrary number of optional arguments between square
2126 % brackets after |\Arrow|).
2127 %
2128 % \subsection{The key right-overlap}
2129 %
2130 %
2131 % The key \Definition{right-overlap} is a boolean key whose initial value is
2132 % |true|. It deals with the environments |{WithArrows}| only.
2133 %
2134 % When the key |right-overlap| is in force, the arrows (and their labels) are
2135 % drawn in an overlapping position and are not relevant for the computation of
2136 % the dimensions of the TeX box containing the environment |{WithArrows}|.
2137 %
2138 % When the key |right-overlap| is set to |false| (with |\WithArrowsOptions| or
2139 % whithin an individual environment |{WithArrows}|), the overlapping on the
2140 % right is taken into account in the dimensions of the encompassing box.
2141 %
2142 %
2143 % \begin{Code}
2144 % $\left\{\begin{WithArrows}[c,format = rCrCl,\emph{right-overlap=false}]
2145 % 2x & + & 3y & = & 5 \Arrow{we add $L_1$ to $L_2$}\\
2146 % -2x & - & 5y & = & 2
2147 % \end{WithArrows}\right.$\quad
2148 % $\left\{\begin{WithArrows}[c,format = rCrCl]
2149 % 2x & + & 3y & = & 5 \\
2150 % & - & 2y & = & 7
2151 % \end{WithArrows}\right.$
2152 % \end{Code}
2153 %
2154 % \medskip
2155 % $\left\{\begin{WithArrows}[c,format = rCrCl,right-overlap=false]
2156 % 2x & + & 3y & = & 5 \Arrow{we add $L_1$ to $L_2$}\\
2157 % -2x & - & 5y & = & 2
2158 % \end{WithArrows}\right.$\quad
2159 % $\left\{\begin{WithArrows}[c,format = rCrCl]
2160 % 2x & + & 3y & = & 5 \\
2161 % & - & 2y & = & 7
2162 % \end{WithArrows}\right.$
2163 %
2164 % \bigskip
2165 % The tuning |right-overlap = false| may also be useful in conjunction with the
2166 % class |standalone|.
2167 %
2168 %
2169 % \bigskip
2170 % \subsection{Vertical positioning of the arrows}
2171 %
2172 % There are four parameters for fine tuning of the vertical positioning of the
2173 % arrows : \Definition{ygap}, \Definition{ystart}, \Definition{start-adjust} and
2174 % \Definition{end-adjust}.
2175 %
2176 % \medskip
2177 % We first explain the behaviour when the parameters |start-adjust| and
2178 % |end-adjust| are equal to zero:
2179 % \begin{itemize}[beginpenalty=10000]
2180 % \item the option |ystart| sets the vertical distance between the base line of
2181 % the text and the start of the arrow (initial value: 0.4 ex);
2182 % \item the option |ygap| sets the vertical distance between two consecutive
2183 % arrows (initial value: 0.4~ex).
2184 % \end{itemize}
2185 %
2186 %
2187 % \bigskip
2188 % $\begin{WithArrows}[interline=1mm, adjust = 0pt]
2189 % (\cos x + \sin x)^2 &
2190 % = \cos^2 x +2 \cos x \sin x
2191 % + \sin^2 x\Arrow{}\tikz[remember picture] \coordinate (A) ; \\
2192 % & = \cos^2x + \sin^2x + 2\sin x\cos x \Arrow{} \\
2193 % & = 1 + \sin(2x)
2194 % \end{WithArrows}$
2195 %
2196 % \begin{tikzpicture}[remember picture,overlay,blue]
2197 % \draw (wa-\WithArrowsLastEnv-1-r.south) to ++(1,0) coordinate (B) to ++(0.1,0) ;
2198 % \draw (A) to ++(1,0) coordinate (C) to ++(0.1,0) ;
2199 % \draw (B) -- (C) ;
2200 % \draw[<-] (B) to ++(0,0.2) ;
2201 % \draw[<-] (C) to ++(0,-0.2) ;
2202 % \path (C) node[right=1mm] {|ystart|} ;
2203 % \draw (wa-\WithArrowsLastEnv-2-r.north) to ++(3,0) coordinate (E) to ++(0.1,0);
2204 % \draw (wa-\WithArrowsLastEnv-2-r.south) to ++(3,0) coordinate (F) to ++(0.1,0);
2205 % \draw (E) -- (F) ;
2206 % \draw[<-] (E) to ++(0,0.2) ;
2207 % \draw[<-] (F) to ++(0,-0.2) ;
2208 % \path (F) node[right=1mm] {|ygap|} ;
2209 % \end{tikzpicture}
2210 %
2211 % \interitem
2212 % However, for aesthetic reasons, when it's possible, \pkg{witharrows} starts
2213 % the arrow a bit higher (by an amount |start-adjust|) and ends the arrow a bit
2214 % lower (by an amount |end-adjust|). By default, both parameters |start-adjust|
2215 % and |end-adjust| are equal to $0.4$~ex.
2216 %
2217 % \bigskip
2218 % Here is for example the behaviour without the mechanism of |start-adjust| and
2219 % |end-adjust|:
2220 % \begin{Code}
2221 % $\begin{WithArrows}\emph{[start-adjust=0pt, end-adjust=0pt]}
2222 % A & = (a+1)^2 \Arrow{we expand} \\
2223 % & = a^2 + 2a + 1
2224 % \end{WithArrows}$
2225 % \end{Code}
2226 %
2227 % $\begin{WithArrows}[start-adjust=0pt, end-adjust=0pt]
2228 % A & = (a+1)^2 \Arrow{we expand} \\
2229 % & = a^2 + 2a + 1
2230 % \end{WithArrows}$
2231 %
2232 %
2233 % \bigskip
2234 % Here is the standard behaviour (the parameters |start-adjust| and |end-ajust|
2235 % are used with the initial value $0.4$~ex). The arrow is longer and the result
2236 % is more aesthetic.
2237 %
2238 % \medskip
2239 % $\begin{WithArrows}
2240 % A & = (a+1)^2 \Arrow{we expand} \\
2241 % & = a^2 + 2a + 1
2242 % \end{WithArrows}$
2243 %
2244 %
2245 % \bigskip
2246 % It's also possible to use the option \Definition{adjust} which sets both
2247 % |start-adjust| and |end-ajust|.
2248 %
2249 % \interitem
2250 % An arrow of |jump| equal to~$1$ has a maximal length\footnote{We call
2251 % \emph{length} of an arrow the difference between the $y$-value of its start
2252 % point and the $y$~value of its end point.} equal to the parameter
2253 % \Definition{max-length-of-arrow}. The initial value of this parameter is
2254 % $2$~cm.
2255 %
2256 % In the following example, the value of |max-length-of-arrow| has been fixed to
2257 % $1.5$~cm.
2258 % \begin{Code}
2259 % \[\begin{WithArrows}[\emph{max-length-of-arrow = 1.5cm}]
2260 % A
2261 % & =
2262 % \begin{vmatrix}
2263 % 1 & a & a^2 & a^3 & a^4 \\
2264 % 1 & b & b^2 & b^3 & b^4 \\
2265 % 1 & c & c^2 & c^3 & c^4 \\
2266 % 1 & d & d^2 & d^3 & d^4 \\
2267 % 1 & e & e^2 & e^3 & e^4
2268 % \end{vmatrix}
2269 % \Arrow{
2270 % $L_2 \gets L_2-L_1$ \\
2271 % $L_3 \gets L_3-L_1$ \\
2272 % $L_4 \gets L_4-L_1$ \\
2273 % $L_5 \gets L_5-L_1$ % don't put \\ here
2274 % } \\
2275 % & =
2276 % \begin{vmatrix}
2277 % 1 & a & a^2 & a^3 & a^4 \\
2278 % 0 & b-a & b^2-a^2 & b^3-a^3 & b^4-a^4 \\
2279 % 0 & c-a & c^2-a^2 & c^3-a^3 & c^4-a^4 \\
2280 % 0 & d-a & d^2-a^2 & d^3-a^3 & d^4-a^4 \\
2281 % 0 & e-a & e^2-a^2 & e^3-a^3 & e^4-a^4
2282 % \end{vmatrix}
2283 % \end{WithArrows}\]
2284 % \end{Code}
2285 %
2286 %
2287 % \bigskip
2288 % \[\begin{WithArrows}[max-length-of-arrow = 1.5cm]
2289 % A
2290 % & =
2291 % \begin{vmatrix}
2292 % 1 & a & a^2 & a^3 & a^4 \\
2293 % 1 & b & b^2 & b^3 & b^4 \\
2294 % 1 & c & c^2 & c^3 & c^4 \\
2295 % 1 & d & d^2 & d^3 & d^4 \\
2296 % 1 & e & e^2 & e^3 & e^4
2297 % \end{vmatrix}
2298 % \Arrow{
2299 % $L_2 \gets L_2-L_1$ \\
2300 % $L_3 \gets L_3-L_1$ \\
2301 % $L_4 \gets L_4-L_1$ \\
2302 % $L_5 \gets L_5-L_1$
2303 % } \\
2304 % & =
2305 % \begin{vmatrix}
2306 % 1 & a & a^2 & a^3 & a^4 \\
2307 % 0 & b-a & b^2-a^2 & b^3-a^3 & b^4-a^4 \\
2308 % 0 & c-a & c^2-a^2 & c^3-a^3 & c^4-a^4 \\
2309 % 0 & d-a & d^2-a^2 & d^3-a^3 & d^4-a^4 \\
2310 % 0 & e-a & e^2-a^2 & e^3-a^3 & e^4-a^4
2311 % \end{vmatrix}
2312 % \end{WithArrows}\]
2313 %
2314 %
2315 % \bigskip
2316 % \subsection{Footnotes in the environments of witharrows}
2317 %
2318 % If you want to put footnotes in an environment |{WithArrows}| or
2319 % |{DispWithArrows}|, you can use a pair |\footnotemark|--|\footnotetext|.
2320 %
2321 % \smallskip
2322 % It's also possible to extract the footnotes with the help of the package
2323 % \pkg{footnote} or the package \pkg{footnotehyper}.
2324 %
2325 % \smallskip
2326 % If \pkg{witharrows} is loaded with the option \Definition{footnote} (with
2327 % |\usepackage[footnote]{witharrows}| or with |\PassOptionsToPackage|), the
2328 % package \pkg{footnote} is loaded (if it is not yet loaded) and it is used to
2329 % extract the footnotes.
2330 %
2331 % \smallskip
2332 % If \pkg{witharrows} is loaded with the option \Definition{footnotehyper}, the
2333 % package \pkg{footnotehyper} is loaded (if it is not yet loaded) ant it is used
2334 % to extract footnotes.
2335 %
2336 % \smallskip
2337 % Caution: The packages \pkg{footnote} and \pkg{footnotehyper} are incompatible.
2338 % The package \pkg{footnotehyper} is the successor of the package \pkg{footnote}
2339 % and should be used preferently. The package \pkg{footnote} has some drawbacks,
2340 % in particular: it must be loaded after the package \pkg{xcolor} and it is not
2341 % perfectly compatible with \pkg{hyperref}.
2342 %
2343 % \medskip
2344 % In this document, the package \pkg{witharrows} has been loaded with the option
2345 % |footnotehyper| and we give an example with a footnote in the label of an
2346 % arrow:
2347 %
2348 % \smallskip
2349 % $\begin{WithArrows}
2350 % A & = (a+b)^2
2351 % \Arrow{We expand\,\footnote{A footnote.}} \\
2352 % & = a^2+b^2+2ab
2353 % \end{WithArrows}$
2354 %
2355 % \bigskip
2356 % \subsection{Option no-arrows}
2357 %
2358 % The option \Definition{no-arrows} is a convenience given to the user. With
2359 % this option the arrows are not drawn. However, an analyse of the arrows is
2360 % done and some errors can be raised, for example if an arrow would arrive after
2361 % the last row of the environment.
2362 %
2363 % \bigskip
2364 % \subsection{Note for the users of AUCTeX}
2365 %
2366 % In a editor of text with a LaTeX-oriented mode, the environments
2367 % |{DispWithArrows}| and |{DispWithArrows*}| should be formated like the
2368 % environment |equation| of LaTeX, that is to say with a formating adapted to
2369 % the math mode of TeX.
2370 %
2371 % In Emacs with the AUCTeX mode, it's possible to achieve such a customization
2372 % by adding the strings |"DispWithArrows"| and |"DispWithArrows*"| to the
2373 % variable |font-latex-math-environments|. It's possible to do that with the
2374 % ``easy customization'' interface of Emacs:
2375 %
2376 % |M-x customize| > |[Text]| > |[TeX]| > |[Font LaTeX]|
2377 %
2378 % \bigskip
2379 % \subsection{Note for the developpers}
2380 %
2381 % If you want to construct an environment upon an environment of
2382 % \pkg{witharrows}, we recommand to call the environment with the construction
2383 % |\WithArrows|-|\endWithArrows| (and not |\begin{WithArrows}| and
2384 % |\end{WithArrows}|).
2385 %
2386 % \smallskip
2387 % By doing so, the error messages generated by \pkg{witharrows} will (usually)
2388 % mention the name of your environment and they will be easier to understand by
2389 % the final user.
2390 %
2391 % \smallskip
2392 % By example, you can define an environment |{DWA}| which is an alias of
2393 % |{DispWithArrows}|:
2394 % \begin{BVerbatim}
2395 % \NewDocumentEnvironment {DWA} {} {\DispWithArrows}{\endDispWithArrows}
2396 % \end{BVerbatim}
2397 %
2398 % \smallskip
2399 % If you use this environment |{DWA}| in math mode, you will have the following
2400 % error message:
2401 %
2402 % \begin{BVerbatim}
2403 % The environment {DWA} should be used only outside math mode.
2404 % \end{BVerbatim}
2405 %
2406 % \interitem
2407 % Another example is the definition of the environment |{DispWithArrows*}|
2408 % internally in the package \pkg{witharrows} by the following code:
2409 % \begin{Verbatim}
2410 % \NewDocumentEnvironment {DispWithArrows*} {}
2411 % {\WithArrowsOptions{notag}%
2412 % \DispWithArrows}
2413 % {\endDispWithArrows}
2414 % \end{Verbatim}
2415 %
2416 %
2417 %
2418 % \interitem
2419 % \section{Examples}
2420 %
2421 % \subsection{\textbackslash MoveEqLeft}
2422 %
2423 % It's possible to use |\MoveEqLeft| of \pkg{mathtools}. Don't forget that
2424 % |\MoveEqLeft| has also the value of an ampersand (|&|). That's important for the
2425 % placement of an eventual command |\Arrow|.
2426 %
2427 %
2428 % \begingroup
2429 % \small
2430 % \begin{Code}
2431 % $\begin{WithArrows}[interline=0.5ex]
2432 % \emph{\MoveEqLeft} \arccos(x) = \arcsin \frac{4}{5} + \arcsin \frac{5}{13}
2433 % \Arrow{because both are in $[-\frac{\pi}{2},\frac{\pi}{2}]$} \\
2434 % & \Leftrightarrow x = \sin\left(\arcsin\frac{4}{5} + \arcsin\frac{5}{13}\right) \\
2435 % & \Leftrightarrow x
2436 % = \frac{4}{5}\cos\arcsin\frac{5}{13}+\frac{5}{13}\cos\arcsin\frac{4}{5}
2437 % \Arrow{$\forall x \in [-1,1], \cos(\arcsin x) = \sqrt{1-x^2}$} \\
2438 % & \Leftrightarrow x = \frac{4}{5}\sqrt{1-\bigl(\frac{5}{13}\bigr)^2}
2439 % + \frac{5}{13}\sqrt{1-\bigl(\frac{4}{5}\bigr)^2}
2440 % \end{WithArrows}$
2441 % \end{Code}
2442 % \endgroup
2443 %
2444 %
2445 % \medskip
2446 % $\begin{WithArrows}[interline=0.5ex]
2447 % \MoveEqLeft \arccos(x) = \arcsin \frac{4}{5} + \arcsin \frac{5}{13}
2448 % \Arrow{because both are in $[-\frac{\pi}{2},\frac{\pi}{2}]$} \\
2449 % & \Leftrightarrow x = \sin\left(\arcsin\frac{4}{5} + \arcsin\frac{5}{13}\right) \\
2450 % & \Leftrightarrow x
2451 % = \frac{4}{5}\cos\arcsin\frac{5}{13} + \frac{5}{13} \cos\arcsin\frac{4}{5}
2452 % \Arrow{$\forall x \in [-1,1], \cos(\arcsin x) = \sqrt{1-x^2}$} \\
2453 % & \Leftrightarrow x = \frac{4}{5}\sqrt{1-\bigl(\frac{5}{13}\bigr)^2}
2454 % + \frac{5}{13}\sqrt{1-\bigl(\frac{4}{5}\bigr)^2}
2455 % \end{WithArrows}$
2456 %
2457 %
2458 % \bigskip
2459 % \subsection{A command \textbackslash DoubleArrow}
2460 %
2461 % By using the key |o| (cf. p. \pageref{option-o}) available at the local level,
2462 % it's easy to write a command |\DoubleArrow| for two arrows going in opposite
2463 % directions.
2464 %
2465 % \bigskip
2466 % \begin{Code}
2467 % \NewDocumentCommand \DoubleArrow { O {} m m }
2468 % {
2469 % \Arrow[tikz=->,#1]{#2}%
2470 % \Arrow[o,tikz=<-,#1]{#3}
2471 % }
2472 % \end{Code}
2473 %
2474 %
2475 % \NewDocumentCommand \DoubleArrow { O {} m m }
2476 % {
2477 % \Arrow[tikz=->,#1]{#2}%
2478 % \Arrow[o,tikz=<-,#1]{#3}
2479 % }
2480 %
2481 %
2482 % \bigskip
2483 % Example of use:
2484 %
2485 % \begin{Code}
2486 % $\begin{WithArrows}[groups]
2487 % A & = (a+b)^2 \emph{\DoubleArrow[tikz={font=\bfseries}]{expansion}{factorization}} \\
2488 % & = a^2 + 2ab+b^2
2489 % \end{WithArrows}$
2490 % \end{Code}
2491 %
2492 % \bigskip
2493 % $\begin{WithArrows}[groups]
2494 % A & = (a+b)^2 \DoubleArrow[tikz={font=\bfseries}]{expansion}{factorization} \\
2495 % & = a^2 + 2ab+b^2
2496 % \end{WithArrows}$
2497 %
2498 %
2499 %
2500 %
2501 % \bigskip
2502 % \subsection{Modifying the shape of the nodes}
2503 %
2504 % It's possible to change the shape of the labels, which are Tikz nodes, by
2505 % modifying the key ``|every node|'' of Tikz.
2506 %
2507 % \begin{Code}
2508 % \begin{WithArrows}%
2509 % [format = c,
2510 % interline = 4mm,
2511 % tikz = {\emph{every node/.style = {circle,
2512 % draw,
2513 % auto = false,
2514 % fill = gray!50,
2515 % inner sep = 1pt,
2516 % font = \tiny}}}]
2517 % 3 (2x+4) = 6 \Arrow{$\div 3$} \\
2518 % 2x+4 = 2 \Arrow{$-4$} \\
2519 % 2x = -2 \Arrow{$\div 2$} \\
2520 % 2x = -1
2521 % \end{WithArrows}
2522 % \end{Code}
2523 %
2524 % \[\begin{WithArrows}[%
2525 % format = c,
2526 % interline = 4mm,
2527 % tikz = {every node/.style = {circle,
2528 % draw,
2529 % auto = false,
2530 % fill = gray!50,
2531 % inner sep = 1pt,
2532 % font = \tiny}}]
2533 % 3 (2x+4) = 6 \Arrow{$\div 3$} \\
2534 % 2x+4 = 2 \Arrow{$-4$} \\
2535 % 2x = -2 \Arrow{$\div 2$} \\
2536 % 2x = -1
2537 % \end{WithArrows}\]
2538 %
2539 %
2540 % \bigskip
2541 % \subsection{Examples with the option tikz-code}
2542 %
2543 % We recall that the option |tikz-code| is the Tikz code used by \pkg{witharrows}
2544 % to draw the arrows.\footnote{If an environment |{DispWithArrows}| or
2545 % |{DispWithArrows*}| is used with the option |wrap-lines|, the value of the
2546 % option |tikz-code| is not used for this environment (but is used for the
2547 % environments nested inside).}
2548 %
2549 % \smallskip
2550 % The value by defaut of |tikz-code| is |\draw (#1) to node {#3} (#2) ;|
2551 % where the three markers |#1|, |#2| and |#3| represent the start row, the end
2552 % row and the label of the arrow.
2553 %
2554 %
2555 % \bigskip
2556 % \subsubsection{Example 1}
2557 % In the following example, we define the value of |tikz-code| with two
2558 % instructions |\path| : the first instruction draws the arrow itself and the
2559 % second puts the label in a Tikz node in the rectangle delimited by the arrow.
2560 %
2561 % \begin{Code}
2562 % \begin{DispWithArrows*}%
2563 % [displaystyle,
2564 % ygap = 2mm,
2565 % ystart = 0mm,
2566 % \emph{tikz-code = {\draw (#1) -- ++(4.5cm,0) |- (#2) ;
2567 % \path (#1) -- (#2)
2568 % node[text width = 4.2cm, right, midway] {#3} ;}}]
2569 % S_n
2570 % & = \frac{1}{n} \sum_{k=0}^{n-1}\cos\bigl(\tfrac{\pi}{2}\cdot\tfrac{k}{n}\bigr)
2571 % ...........
2572 % \end{Code}
2573 %
2574 %
2575 % \bigskip
2576 % \begin{DispWithArrows*}[
2577 % displaystyle,
2578 % ygap = 2mm,
2579 % ystart = 0mm,
2580 % tikz-code = {\draw (#1) -- ++(4.5cm,0) |- (#2) ;
2581 % \path (#1) -- (#2)
2582 % node[text width = 4.2cm, right, midway] {#3} ;}]
2583 % S_n
2584 % & = \frac{1}{n} \sum_{k=0}^{n-1}\cos\bigl(\tfrac{\pi}{2}\cdot\tfrac{k}{n}\bigr)
2585 % \Arrow{$\cos x = \Re(e^{ix})$}\\
2586 % & = \frac{1}{n} \sum_{k=0}^{n-1} \Re\left(e^{i\frac{k\pi}{2n}}\right)
2587 % \Arrow{$\Re(z+z')=\Re(z)+\Re(z')$}\\
2588 % & = \frac{1}{n} \Re\left(\sum_{k=0}^{n-1} e^{i\frac{k\pi}{2n}}\right)
2589 % \Arrow{$\exp$ is a morphism for $\times$ and $+$} \\
2590 % & = \frac{1}{n} \Re \left(\sum_{k=0}^{n-1}\bigl(e^{i\frac{\pi}{2n}}\bigr)^k\right)
2591 % \Arrow{sum of terms of a geometric progression of ratio $e^{i\frac{2\pi}{n}}$}\\
2592 % & = \frac{1}{n} \Re \left( \frac{1-\bigl(e^{i\frac{\pi}{2n}}\bigr)^n}{1-e^{i\frac{\pi}{2n}}}\right)\\
2593 % & = \frac{1}{n} \Re \left(\frac{1-i}{1-e^{i\frac{\pi}{2n}}}\right)
2594 % \end{DispWithArrows*}
2595 %
2596 % \bigskip
2597 % \subsubsection{Example 2}
2598 %
2599 % \label{example-WithArrowsRightX}
2600 % It's possible to modify the previous example to have the ``|text width|''
2601 % automatically computed with the right margin (in a way similar as the
2602 % |wrap-lines| option) in the environments |{DispWithArrows}| and
2603 % |{DispWithArrows*}|. In the definition of |tikz-code|, we use the command
2604 % |\WithArrowsRightX| which is the $x$-value of the right margin of the current
2605 % composition box (it's a TeX command and not a dimension). For lisibility, we
2606 % use a style. This example requires the Tikz library \pkg{calc}.
2607 %
2608 % \begin{Code}
2609 % \WithArrowsNewStyle{MyStyle}
2610 % {displaystyle,
2611 % ygap = 2mm,
2612 % xoffset = 0pt,
2613 % ystart = 0mm,
2614 % tikz-code = {\path let \p1 = (#1)
2615 % in (#1)
2616 % -- node [anchor = west,
2617 % text width = {\emph{\WithArrowsRightX} - \x1 - 0.5 em}]
2618 % {#3}
2619 % (#2) ;
2620 % \draw let \p1 = (#1)
2621 % in (#1) -- ++(\emph{\WithArrowsRightX} - \x1,0) |- (#2) ; }}
2622 % \end{Code}
2623 %
2624 % \begin{Code}
2625 %\begin{DispWithArrows}[MyStyle]
2626 % S_n
2627 % & = \frac{1}{n} \sum_{k=0}^{n-1}\cos\bigl(\tfrac{\pi}{2}\cdot\tfrac{k}{n}\bigr)
2628 % \Arrow{$\cos x = \Re(e^{ix})$}\\
2629 % ...........
2630 % \end{Code}
2631 %
2632 % \WithArrowsNewStyle{MyStyle}
2633 % {displaystyle,
2634 % ygap = 2mm,
2635 % xoffset = 0pt,
2636 % ystart = 0mm,
2637 % tikz-code = {\path let \p1 = (#1)
2638 % in (#1)
2639 % -- node [anchor = west,
2640 % text width = {\WithArrowsRightX - \x1 - 0.5 em}] {#3}
2641 % (#2) ;
2642 % \draw let \p1 = (#1)
2643 % in (#1) -- ++(\WithArrowsRightX - \x1,0) |- (#2) ; }}
2644 %
2645 %\begin{DispWithArrows}[MyStyle]
2646 % S_n
2647 % & = \frac{1}{n} \sum_{k=0}^{n-1}\cos\bigl(\tfrac{\pi}{2}\cdot\tfrac{k}{n}\bigr)
2648 % \Arrow{$\cos x = \Re(e^{ix})$}\\
2649 % & = \frac{1}{n} \sum_{k=0}^{n-1} \Re\left(e^{i\frac{k\pi}{2n}}\right)
2650 % \Arrow{$\Re(z+z')=\Re(z)+\Re(z')$}\\
2651 % & = \frac{1}{n} \Re\left(\sum_{k=0}^{n-1} e^{i\frac{k\pi}{2n}}\right)
2652 % \Arrow{$\exp$ is a morphism for $\times$ and $+$} \\
2653 % & = \frac{1}{n} \Re \left(\sum_{k=0}^{n-1}\bigl(e^{i\frac{\pi}{2n}}\bigr)^k\right)
2654 % \Arrow{sum of terms of a geometric progression of ratio $e^{i\frac{2\pi}{n}}$}\\
2655 % & = \frac{1}{n}
2656 % \Re \left( \frac{1-\bigl(e^{i\frac{\pi}{2n}}\bigr)^n}{1-e^{i\frac{\pi}{2n}}}\right)\\
2657 % & = \frac{1}{n} \Re \left(\frac{1-i}{1-e^{i\frac{\pi}{2n}}}\right)
2658 % \end{DispWithArrows}
2659 %
2660 %
2661 %
2662 % \bigskip
2663 % \subsubsection{Example 3}
2664 %
2665 % In the following example, we change the shape of the arrow depending on whether
2666 % the start row is longer than the end row or not. This example requires the
2667 % Tikz library \pkg{calc}.
2668 %
2669 % \begin{Code}
2670 % \begin{WithArrows}[ll,interline=5mm,xoffset=5mm,
2671 % \emph{tikz-code = {\draw[rounded corners,
2672 % every node/.style = {circle,
2673 % draw,
2674 % auto = false,
2675 % inner sep = 1pt,
2676 % fill = gray!50,
2677 % font = \tiny }]
2678 % let \p1 = (~#1),
2679 % \p2 = (~#2)
2680 % in \ifdim \x1 > \x2
2681 % (\p1) -- node {~#3} (\x1,\y2) -- (\p2)
2682 % \else
2683 % (\p1) -- (\x2,\y1) -- node {~#3} (\p2)
2684 % \fi ;}}]
2685 % E & \Longleftrightarrow \frac{(x+4)}{3} + \frac{5x+3}{5} = 7
2686 % \Arrow{$\times 15$}\\
2687 % & \Longleftrightarrow 5(x+4) + 3(5x+3) = 105 \\
2688 % & \Longleftrightarrow 5x+20 + 15x+9 = 105 \\
2689 % & \Longleftrightarrow 20x+29 = 105
2690 % \Arrow{$-29$}\\
2691 % & \Longleftrightarrow 20x = 76
2692 % \Arrow{$\div 20$}\\
2693 % & \Longleftrightarrow x = \frac{38}{10}
2694 % \end{WithArrows}
2695 % \end{Code}
2696 %
2697 %
2698 % \[\begin{WithArrows}[ll,interline=5mm,xoffset=5mm,
2699 % tikz-code = {\draw[rounded corners,
2700 % every node/.style = {circle,
2701 % draw,
2702 % auto = false,
2703 % inner sep = 1pt,
2704 % fill = gray!50,
2705 % font = \tiny}]
2706 % let \p1 = (#1),
2707 % \p2 = (#2)
2708 % in \ifdim \x1 > \x2
2709 % (\p1) -- node {#3} (\x1,\y2) -- (\p2)
2710 % \else
2711 % (\p1) -- (\x2,\y1) -- node {#3} (\p2)
2712 % \fi ;}]
2713 % E & \Longleftrightarrow \frac{(x+4)}{3} + \frac{5x+3}{5} = 7
2714 % \Arrow{$\times 15$}\\
2715 % & \Longleftrightarrow 5(x+4) + 3(5x+3) = 105 \\
2716 % & \Longleftrightarrow 5x+20 + 15x+9 = 105 \\
2717 % & \Longleftrightarrow 20x+29 = 105
2718 % \Arrow{$-29$}\\
2719 % & \Longleftrightarrow 20x = 76
2720 % \Arrow{$\div 20$}\\
2721 % & \Longleftrightarrow x = \frac{38}{10}
2722 % \end{WithArrows}\]
2723 %
2724 %
2725 %
2726 % \subsection{Automatic numbered loop}
2727 %
2728 % Assume we want to draw a loop of numbered arrows. In this purpose, it's
2729 % possible to write a dedicated command |\NumberedLoop| which will do the job
2730 % when used in |code-after|. In the following example, we write this command with
2731 % |\NewDocumentCommand| (of L3) and |\foreach| of \pkg{pgffor} (which
2732 % is loaded when \pkg{witharrows} is loaded).
2733 %
2734 % \begin{Verbatim}
2735 % \NewDocumentCommand \NumberedLoop {}
2736 % {\foreach \j in {2,...,\WithArrowsNbLines}
2737 % { \pgfmathtruncatemacro{\i}{\j-1}
2738 % \Arrow[rr]{\i}{\j}{\i} }
2739 % \Arrow[rr,xoffset=1cm,tikz=<-]{1}{\WithArrowsNbLines}{\WithArrowsNbLines}}
2740 % \end{Verbatim}
2741 %
2742 % The command |\WithArrowsNbLines| is a command available in |code-after| which
2743 % gives the total number of lines (=rows) of the current environment (it's a
2744 % command and not a counter).
2745 %
2746 %
2747 % \bigskip
2748 % \begin{Code}
2749 % $\begin{WithArrows}[\emph{code-after = \NumberedLoop}]
2750 % a.\;& f \text{ est continuous on } E \\
2751 % b.\;& f \text{ est continuous in } 0 \\
2752 % c.\;& f \text{ is bounded on the unit sphere} \\
2753 % d.\;& \exists K > 0\quad \forall x \in E\quad \|f(x)\| \le K \|x\| \\
2754 % e.\;& f \text{ is lipschitzian}
2755 % \end{WithArrows}$
2756 % \end{Code}
2757 %
2758 % \bigskip
2759 % \begin{scope}
2760 % \NewDocumentCommand \NumberedLoop {}
2761 % {\foreach \j in {2,...,\WithArrowsNbLines}
2762 % { \pgfmathtruncatemacro{\i}{\j-1}
2763 % \Arrow[rr]{\i}{\j}{\i} }
2764 % \Arrow[rr,xoffset=1cm,tikz=<-]{1}{\WithArrowsNbLines}{\WithArrowsNbLines}}
2765 %
2766 %
2767 % $\begin{WithArrows}[code-after = \NumberedLoop]
2768 % a.\;& f \text{ est continuous on } E \\
2769 % b.\;& f \text{ est continuous in } 0 \\
2770 % c.\;& f \text{ is bounded on the unit sphere} \\
2771 % d.\;& \exists K > 0\quad \forall x \in E\quad \|f(x)\| \le K \|x\| \\
2772 % e.\;& f \text{ is lipschitzian}
2773 % \end{WithArrows}$
2774 %
2775 %
2776 % \bigskip
2777 % As usual, it's possible to change the characteristic of both arrows and nodes
2778 % with the option |tikz|. However, if we want to change the style to have, for
2779 % example, numbers in round brackets, the best way is to change the value of
2780 % |tikz-code|:
2781 %
2782 % \begin{Code}
2783 % tikz-code = {\draw (#1) to node {\footnotesize (#3)} (#2) ;}
2784 % \end{Code}
2785 %
2786 % \WithArrowsOptions{tikz-code = {\draw (#1) to node {\footnotesize (#3)} (#2) ;}}
2787 %
2788 % $\begin{WithArrows}[code-after = \NumberedLoop]
2789 % a.\;& f \text{ est continuous on } E \\
2790 % b.\;& f \text{ est continuous in } 0 \\
2791 % c.\;& f \text{ is bounded on the unit sphere} \\
2792 % d.\;& \exists K > 0\quad \forall x \in E\quad \|f(x)\| \le K \|x\| \\
2793 % e.\;& f \text{ is lipschitzian}
2794 % \end{WithArrows}$
2795 %
2796 % \end{scope}
2797 %
2798 % \vspace{2cm}
2799 %
2800 % \section{Implementation}
2801 %
2802 % \subsection{Declaration of the package and extensions loaded}
2803 %
2804 % The prefix |witharrows| has been registred for this extension.
2805 %
2806 % See: |http://mirrors.ctan.org/macros/latex/contrib/l3kernel/l3prefixes.pdf|
2807 %
2808 %<@@=witharrows>
2809 %
2810 % \bigskip
2811 % First, \pkg{tikz} and some Tikz libraries are loaded before the
2812 % |\ProvidesExplPackage|. They are loaded this way because |\usetikzlibrary| in
2813 % |L3| code fails.\footnote{cf.
2814 % |tex.stackexchange.com/questions/57424/using-of-usetikzlibrary-in-an-expl3-package-fails|}
2815 %
2816 %
2817 % \begin{macrocode}
2818 %<*LaTeX>
2819 \RequirePackage{tikz}
2820 %</LaTeX>
2821 %<*plain-TeX>
2822 \input tikz.tex
2823 \input expl3-generic.tex
2824 %</plain-TeX>
2825 \usetikzlibrary{arrows.meta}
2826 \usepgfmodule{bending} % https://texnique.fr/osqa/questions/12199
2827 % \end{macrocode}
2828 %
2829 % \bigskip
2830 % Then, we can give the traditional declaration of a package written with
2831 % |L3|:
2832 % \begin{macrocode}
2833 %<*LaTeX>
2834 \RequirePackage{l3keys2e}
2835 \ProvidesExplPackage
2836 {witharrows}
2837 {\myfiledate}
2838 {\myfileversion}
2839 {Draws arrows for explanations on the right}
2840 % \end{macrocode}
2841 %
2842 %
2843 % \bigskip
2844 % \begin{macrocode}
2845 \RequirePackage { varwidth }
2846 %</LaTeX>
2847 % \end{macrocode}
2848 %
2849 % \begin{macrocode}
2850 %<*plain-TeX>
2851 \ExplSyntaxOn
2852 \catcode `\@ = 11
2853 %</plain-TeX>
2854 % \end{macrocode}
2855 %
2856 %
2857 % \begin{macrocode}
2858 %<*LaTeX>
2859 \ProvideDocumentCommand{\IfPackageLoadedT}{mm}
2860 {\IfPackageLoadedTF{#1}{#2}{}}
2861 \ProvideDocumentCommand{\IfPackageLoadedF}{mm}
2862 {\IfPackageLoadedTF{#1}{}{#2}}
2863 %</LaTeX>
2864 % \end{macrocode}
2865 %
2866 %
2867 % \bigskip
2868 % \subsection{The packages footnote and footnotehyper}
2869 %
2870 % A few options can be given to the package \pkg{witharrows} when it is loaded
2871 % (with |\usepackage|, |\RequirePackage| or |\PassOptionsToPackage|). Currently
2872 % (version \myfileversion), there are two such options: |footnote| and
2873 % |footnotehyper|. With the option |footnote|, \pkg{witharrows} loads
2874 % \pkg{footnote} and uses it to extract the footnotes from the environments
2875 % |{WithArrows}|. Idem for the option |footnotehyper|.
2876 %
2877 % \medskip
2878 % The boolean |\c_@@_footnotehyper_bool| will indicate if the option
2879 % |footnotehyper| is used.
2880 % \begin{macrocode}
2881 %<*LaTeX>
2882 \bool_new:N \c_@@_footnotehyper_bool
2883 % \end{macrocode}
2884 %
2885 % \medskip
2886 % The boolean |\c_@@_footnote_bool| will indicate if the option |footnote| is
2887 % used, but quicky, it will also be set to |true| if the option |footnotehyper|
2888 % is used.
2889 % \begin{macrocode}
2890 \bool_new:N \c_@@_footnote_bool
2891 %</LaTeX>
2892 % \end{macrocode}
2893 %
2894 % \bigskip
2895 % \begin{macrocode}
2896 \cs_new_protected:Npn \@@_msg_new:nn { \msg_new:nnn { witharrows } }
2897 \cs_new_protected:Npn \@@_msg_new:nnn #1 #2 #3
2898 {
2899 \bool_if:NTF \c_@@_messages_for_Overleaf_bool
2900 { \msg_new:nnn { witharrows } { #1 } { #2 \\ #3 } }
2901 { \msg_new:nnnn { witharrows } { #1 } { #2 } { #3 } }
2902 }
2903 \cs_new_protected:Npn \@@_msg_redirect_name:nn
2904 { \msg_redirect_name:nnn { witharrows } }
2905 \cs_new_protected:Npn \@@_error:n { \msg_error:nn { witharrows } }
2906 \cs_new_protected:Npn \@@_warning:n { \msg_warning:nn { witharrows } }
2907 \cs_new_protected:Npn \@@_fatal:n { \msg_fatal:nn { witharrows } }
2908 \cs_new_protected:Npn \@@_error:nn { \msg_error:nnn { witharrows } }
2909 \cs_generate_variant:Nn \@@_error:nn { n e }
2910 % \end{macrocode}
2911 %
2912 % \bigskip
2913 % We also create a command which will genereate usually an error but only a
2914 % warning on Overleaf. The argument is given by currification.
2915 % \begin{macrocode}
2916 \cs_new_protected:Npn \@@_error_or_warning:n
2917 { \bool_if:NTF \c_@@_messages_for_Overleaf_bool \@@_warning:n \@@_error:n }
2918 % \end{macrocode}
2919 %
2920 % We try to detect whether the compilation is done on Overleaf. We use
2921 % |\c_sys_jobname_str| because, with Overleaf, the value of |\c_sys_jobname_str|
2922 % is always ``|output|''.
2923 % \begin{macrocode}
2924 \bool_set:Nn \c_@@_messages_for_Overleaf_bool
2925 {
2926 \str_if_eq_p:on \c_sys_jobname_str { _region_ } % for Emacs
2927 || \str_if_eq_p:on \c_sys_jobname_str { output } % for Overleaf
2928 }
2929 % \end{macrocode}
2930 %
2931 % \bigskip
2932 % \begin{macrocode}
2933 \bool_new:N \g_@@_beamer_bool
2934 % \end{macrocode}
2935 %
2936 % \medskip
2937 % We define a set of keys |WithArrows/package| for these options.
2938 % \begin{macrocode}
2939 %<*LaTeX>
2940 \keys_define:nn { WithArrows / package }
2941 {
2942 footnote .bool_set:N = \c_@@_footnote_bool ,
2943 footnotehyper .bool_set:N = \c_@@_footnotehyper_bool ,
2944 footnote .usage:n = load ,
2945 footnotehyper .usage:n = load ,
2946 beamer .bool_gset:N = \g_@@_beamer_bool ,
2947 beamer .default:n = true ,
2948 beamer .usage:n = load ,
2949 unknown .code:n = \@@_fatal:n { Option~unknown~for~package }
2950 }
2951 % \end{macrocode}
2952 %
2953 % \begin{macrocode}
2954 \@@_msg_new:nn { Option~unknown~for~package }
2955 {
2956 You~can't~use~the~option~'\l_keys_key_str'~when~loading~the~
2957 package~witharrows.~Try~to~use~the~command~
2958 \token_to_str:N\WithArrowsOptions.
2959 }
2960 % \end{macrocode}
2961 %
2962 %
2963 % \bigskip
2964 % We process the options when the package is loaded (with |\usepackage|).
2965 % \begin{macrocode}
2966 \ProcessKeysOptions { WithArrows / package }
2967 % \end{macrocode}
2968 %
2969 % \begin{macrocode}
2970 \IfClassLoadedT { beamer } { \bool_gset_true:N \g_@@_beamer_bool }
2971 \IfPackageLoadedT { beamerarticle } { \bool_gset_true:N \g_@@_beamer_bool }
2972 % \end{macrocode}
2973 %
2974 % \medskip
2975 % \begin{macrocode}
2976 \@@_msg_new:nn { footnote~with~footnotehyper~package }
2977 {
2978 Footnote~forbidden.\\
2979 You~can't~use~the~option~'footnote'~because~the~package~
2980 footnotehyper~has~already~been~loaded.~
2981 If~you~want,~you~can~use~the~option~'footnotehyper'~and~the~footnotes~
2982 within~the~environments~of~witharrows~will~be~extracted~with~the~tools~
2983 of~the~package~footnotehyper.\\
2984 If~you~go~on,~the~package~footnote~won't~be~loaded.
2985 }
2986 % \end{macrocode}
2987 %
2988 % \begin{macrocode}
2989 \@@_msg_new:nn { footnotehyper~with~footnote~package }
2990 {
2991 You~can't~use~the~option~'footnotehyper'~because~the~package~
2992 footnote~has~already~been~loaded.~
2993 If~you~want,~you~can~use~the~option~'footnote'~and~the~footnotes~
2994 within~the~environments~of~witharrows~will~be~extracted~with~the~tools~
2995 of~the~package~footnote.\\
2996 If~you~go~on,~the~package~footnotehyper~won't~be~loaded.
2997 }
2998 % \end{macrocode}
2999 %
3000 % \medskip
3001 % \begin{macrocode}
3002 \bool_if:NT \c_@@_footnote_bool
3003 {
3004 % \end{macrocode}
3005 % The class \cls{beamer} has its own system to extract footnotes and that's why
3006 % we have nothing to do if \cls{beamer} is used.
3007 % \begin{macrocode}
3008 \@ifclassloaded { beamer }
3009 { \bool_set_false:N \c_@@_footnote_bool }
3010 {
3011 \@ifpackageloaded { footnotehyper }
3012 { \@@_error:n { footnote~with~footnotehyper~package } }
3013 { \usepackage { footnote } }
3014 }
3015 }
3016 % \end{macrocode}
3017 %
3018 % \begin{macrocode}
3019 \bool_if:NT \c_@@_footnotehyper_bool
3020 {
3021 % \end{macrocode}
3022 % The class \cls{beamer} has its own system to extract footnotes and that's why
3023 % we have nothing to do if \cls{beamer} is used.
3024 % \begin{macrocode}
3025 \@ifclassloaded { beamer }
3026 { \bool_set_false:N \c_@@_footnote_bool }
3027 {
3028 \@ifpackageloaded { footnote }
3029 { \@@_error:n { footnotehyper~with~footnote~package } }
3030 { \usepackage { footnotehyper } }
3031 \bool_set_true:N \c_@@_footnote_bool
3032 }
3033 }
3034 % \end{macrocode}
3035 % The flag |\c_@@_footnote_bool| is raised and so, we will only have to test
3036 % |\c_@@_footnote_bool| in order to know if we have to insert an environment
3037 % |{savenotes}| (the |\begin{savenotes}| is in |\@@_pre_halign:n| and
3038 % |\end{savenotes}| at the end of the environments |{WithArrows}| and
3039 % |{DispWithArrows}|).
3040 %
3041 % \bigskip
3042 % \subsection{The class option leqno}
3043 %
3044 % The boolean |\c_@@_leqno_bool| will indicate if the class option |leqno| is
3045 % used. When this option is used in LaTeX, the command |\@eqnnum| is redefined
3046 % (as one can see in the file |leqno.clo|). That's enough to put the labels on
3047 % the left in our environments |{DispWithArrows}| and |{DispWithArrows*}|.
3048 % However, that's not enough when our option |wrap-lines| is used. That's why we
3049 % have to know if this option is used as a class option. With the following
3050 % programmation, |leqno| \emph{can't} be given as an option of \pkg{witharrows}
3051 % (by design).
3052 % \begin{macrocode}
3053 \bool_new:N \c_@@_leqno_bool
3054 \DeclareOption { leqno } { \bool_set_true:N \c_@@_leqno_bool }
3055 \DeclareOption* { }
3056 \ProcessOptions*
3057 %</LaTeX>
3058 % \end{macrocode}
3059 %
3060 % \bigskip
3061 % \subsection{Collecting options}
3062 %
3063 % The following technic allows to create user commands with the ability to put
3064 % an arbitrary number of |[|\textsl{list of (key=val)}|]| after the name of the
3065 % command.
3066 %
3067 % \medskip
3068 % \emph{Exemple} :\par\nobreak
3069 %
3070 % |\@@_collect_options:n { \F } [x=a,y=b] [z=c,t=d] { arg }|
3071 %
3072 % will be transformed in :\quad |\F{x=a,y=b,z=c,t=d}{arg}|
3073 %
3074 % \smallskip
3075 % Therefore, by writing : |\def\G{\@@_collect_options:n{\F}}|,
3076 %
3077 % the command |\G| takes in an arbitrary number of optional arguments between
3078 % square brackets.
3079 %
3080 % \bigskip
3081 % \begin{macrocode}
3082 %<*LaTeX>
3083 \cs_new_protected:Npn \@@_collect_options:n #1
3084 {
3085 \peek_meaning:NTF [
3086 { \@@_collect_options:nw { #1 } }
3087 { #1 { } }
3088 }
3089 % \end{macrocode}
3090 %
3091 % \bigskip
3092 % We use |\NewDocumentCommand| in order to be able to allow nested brackets
3093 % within the argument between |[| and |]|.
3094 % \begin{macrocode}
3095 \NewDocumentCommand \@@_collect_options:nw { m r[] }
3096 { \@@_collect_options:nn { #1 } { #2 } }
3097
3098 \cs_new_protected:Npn \@@_collect_options:nn #1 #2
3099 {
3100 \peek_meaning:NTF [
3101 { \@@_collect_options:nnw { #1 } { #2 } }
3102 { #1 { #2 } }
3103 }
3104
3105 \cs_new_protected:Npn \@@_collect_options:nnw #1#2[#3]
3106 { \@@_collect_options:nn { #1 } { #2 , #3 } }
3107 %</LaTeX>
3108 % \end{macrocode}
3109 %
3110 %
3111 %
3112 % \bigskip
3113 % \subsection{Some technical definitions}
3114 %
3115 %
3116 % \begin{macrocode}
3117 \cs_generate_variant:Nn \seq_set_split:Nnn { N e e }
3118 \cs_generate_variant:Nn \keys_precompile:nnN { n n c }
3119 \prg_generate_conditional_variant:Nnn \tl_if_novalue:n { o } { F }
3120 \exp_args_generate:n { N N N n o }
3121 % \end{macrocode}
3122 %
3123 %
3124 % \bigskip
3125 % We define a command |\@@_sort_seq:N| which will sort a sequence.
3126 % \begin{macrocode}
3127 \cs_new_protected:Npn \@@_sort_seq:N #1
3128 {
3129 \seq_sort:Nn #1
3130 {
3131 \str_compare:eNeTF
3132 { \str_lowercase:n { ##1 } } < { \str_lowercase:n { ##2 } }
3133 \sort_return_same:
3134 \sort_return_swapped:
3135 }
3136 }
3137 % \end{macrocode}
3138 %
3139 % \bigskip
3140 % The following command creates a sequence of strings (|str|) from a |clist|.
3141 %
3142 % \begin{macrocode}
3143 \cs_new_protected:Npn \@@_set_seq_of_str_from_clist:Nn #1 #2
3144 {
3145 \seq_set_from_clist:Nn #1 { #2 }
3146 \seq_set_map_e:NNn #1 #1 { \tl_to_str:n { ##1 } }
3147 }
3148 % \end{macrocode}
3149 %
3150 % \bigskip
3151 % The command |\@@_save:N| saves a L3 variable by creating a global
3152 % version of the variable. For a variable named |\l_|\texttt{\slshape
3153 % name}|_|\texttt{\slshape type}, the corresponding global variable will be
3154 % named |\g_|\texttt{\slshape name}|_|\texttt{\slshape type}. The type of the
3155 % variable is determinated by the suffix \texttt{\slshape type} and is used to
3156 % apply the corresponding L3 commands.
3157 % \begin{macrocode}
3158 \cs_new_protected:Npn \@@_save:N #1
3159 {
3160 \seq_set_split:Nee \l_tmpa_seq
3161 { \char_generate:nn { `_ } { 12 } }
3162 { \cs_to_str:N #1 }
3163 \seq_pop_left:NN \l_tmpa_seq \l_tmpa_tl
3164 % \end{macrocode}
3165 % The string |\l_tmpa_str| will contains the \emph{type} of the variable.
3166 % \begin{macrocode}
3167 \str_set:Ne \l_tmpa_str { \seq_item:Nn \l_tmpa_seq { -1 } }
3168 \use:c { \l_tmpa_str _if_exist:cF }
3169 { g _\seq_use:Nnnn \l_tmpa_seq _ _ _ }
3170 {
3171 \use:c { \l_tmpa_str _new:c }
3172 { g _\seq_use:Nnnn \l_tmpa_seq _ _ _ }
3173 }
3174 \use:c { \l_tmpa_str _gset_eq:cN }
3175 { g _\seq_use:Nnnn \l_tmpa_seq _ _ _ } #1
3176 }
3177 % \end{macrocode}
3178 %
3179 % \medskip
3180 % The command |\@@_restore:N| affects to the L3 variable the value of
3181 % the (previously) set value of the corresponding \emph{global} variable.
3182 % \begin{macrocode}
3183 \cs_new_protected:Npn \@@_restore:N #1
3184 {
3185 \seq_set_split:Nee \l_tmpa_seq
3186 { \char_generate:nn { `_ } { 12 } }
3187 { \cs_to_str:N #1 }
3188 \seq_pop_left:NN \l_tmpa_seq \l_tmpa_tl
3189 \str_set:Ne \l_tmpa_str { \seq_item:Nn \l_tmpa_seq { -1 } }
3190 \use:c { \l_tmpa_str _set_eq:Nc }
3191 #1 { g_\seq_use:Nnnn \l_tmpa_seq _ _ _ }
3192 }
3193 % \end{macrocode}
3194 %
3195 %
3196 % \bigskip
3197 % We define a Tikz style |@@_node_style| for the |l|-nodes and |r|-nodes that
3198 % will be created in the |\halign|. These nodes are Tikz nodes of shape
3199 % ``rectangle'' but with zero width. An arrow between two nodes starts from the
3200 % \emph{south} anchor of the first node and arrives at the \emph{north} anchor
3201 % of the second node.
3202 % \begin{macrocode}
3203 \tikzset
3204 {
3205 @@_node_style / .style =
3206 {
3207 above = \l_@@_ystart_dim ,
3208 inner~sep = \c_zero_dim ,
3209 minimum~width = \c_zero_dim ,
3210 minimum~height = \l_@@_ygap_dim
3211 }
3212 }
3213 % \end{macrocode}
3214 % If the user uses the option |show-nodes| (it's a \pkg{l3keys} option), the
3215 % Tikz options |draw| and |red| will be appended to this style. This feature may
3216 % be useful for debugging.\footnote{The |v|-nodes, created near the end of line
3217 % in |{DispWithArrows}| and |{DispWithArrows*}| are not shown with the option
3218 % |show-nodes|.}
3219 %
3220 %
3221 % \bigskip
3222 % The style |@@_standard| is loaded in standard in the |{tikzpicture}| we need.
3223 % The names of the nodes are prefixed by |wa| (by security) but also by a prefix
3224 % which is the position-in-the-tree of the nested environments.
3225 % \begin{macrocode}
3226 \tikzset
3227 {
3228 @@_standard / .style =
3229 {
3230 remember~picture ,
3231 overlay ,
3232 name~prefix = wa - \l_@@_prefix_str -
3233 } ,
3234 @@_standard_arrow / .style =
3235 {
3236 @@_standard ,
3237 every~path / .style = WithArrows / arrow
3238 }
3239 }
3240 % \end{macrocode}
3241 % The following line is a security when using |xelatex| and RTL language (cf.
3242 % question~683570 on TeX StackExchange).
3243 % \begin{macrocode}
3244 \sys_if_engine_xetex:T
3245 {
3246 \tikzset
3247 {
3248 @@_standard_arrow / .append~style =
3249 { every~node / .append~style = { text = . } }
3250 }
3251 }
3252 % \end{macrocode}
3253 %
3254 % \bigskip
3255 % We also define a style for the tips of arrow. The final user of the extension
3256 % \pkg{witharrows} will use this style if he wants to draw an arrow directly
3257 % with a Tikz command in his document (probably using the Tikz nodes created by
3258 % |{WithArrows}| in the |\halign|). This style is documented in the
3259 % documentation of \pkg{witharrows}.
3260 % \begin{macrocode}
3261 \tikzset
3262 {
3263 WithArrows / arrow / tips / .style =
3264 { > = { Straight~Barb [ scale = 1.2 , bend ] } }
3265 }
3266 % \end{macrocode}
3267 %
3268 % \bigskip
3269 % The style |WithArrows/arrow| will be used to draw the arrows (more precisely,
3270 % it will be passed to |every~path|). This style is documented in the
3271 % documentation of \pkg{witharrows}.
3272 % \begin{macrocode}
3273 \tikzset
3274 {
3275 WithArrows / arrow / .style =
3276 {
3277 align = flush~left ,
3278 % \end{macrocode}
3279 %
3280 % Before the version 2.7, it was |align = left|.
3281 % \begin{macrocode}
3282 auto = left ,
3283 %<*LaTeX>
3284 font = \small \itshape ,
3285 %</LaTeX>
3286 WithArrows / arrow / tips ,
3287 bend~left = 45 ,
3288 ->
3289 }
3290 }
3291 % \end{macrocode}
3292 %
3293 % \bigskip
3294 % The option |subequations| is an option which uses the environment
3295 % |{subequations}| of \pkg{amsmath}. That's why, if \pkg{amsmath} is loaded, we
3296 % add the key |subequations| to the list of the keys available in
3297 % |\WithArrowsOptions| and |{DispWithArrows}|.
3298 % \begin{macrocode}
3299 %<*LaTeX>
3300 \AtBeginDocument
3301 {
3302 \IfPackageLoadedTF { amsmath }
3303 {
3304 \seq_put_right:Nn \l_@@_options_WithArrowsOptions_seq { subequations }
3305 \seq_put_right:Nn \l_@@_options_DispWithArrows_seq { subequations }
3306 }
3307 % \end{macrocode}
3308 %
3309 % \bigskip
3310 % In order to increase the interline in the environments |{WithArrows}|,
3311 % |{DispWithArrows}|, etc., we will use the command |\spread@equation| of
3312 % \pkg{amsmath}. When used, this command becomes no-op (in the current TeX
3313 % group). Therefore, it will be possible to use the environments of
3314 % \pkg{amsmath} (e.g. |{aligned}|) in an environment |{WithArrows}|.
3315 %
3316 % Nevertheless, we want the extension \pkg{witharrows} available without
3317 % \pkg{amsmath}. That's why we give a definition of |\spread@equation| if
3318 % \pkg{amsmath} is not loaded.
3319 % \begin{macrocode}
3320 {
3321 %</LaTeX>
3322 \cs_new_protected:Npn \spread@equation
3323 {
3324 \openup \jot
3325 \cs_set_eq:NN \spread@equation \prg_do_nothing:
3326 }
3327 %<*LaTeX>
3328 }
3329 }
3330 %</LaTeX>
3331 % \end{macrocode}
3332 %
3333 % \bigskip
3334 % \begin{macrocode}
3335 \tl_new:N \l_@@_left_brace_tl
3336 \tl_set_eq:NN \l_@@_left_brace_tl \c_novalue_tl
3337 % \end{macrocode}
3338 %
3339 % \bigskip
3340 % \subsection{Variables}
3341 %
3342 % The boolean |\l_@@_in_WithArrows_bool| will be raised in an environment
3343 % |{WithArrows}| and the boolean |\l_@@_in_DispWithArrows_bool| will be raised
3344 % in an environment |{DispWithArrows}| or |{DispWithArrows*}|. The boolean
3345 % |\l_@@_in_code_after_bool| will be raised during the execution of the
3346 % |code-after| (option |code-after|).
3347 % \begin{macrocode}
3348 \bool_new:N \l_@@_in_WithArrows_bool
3349 \bool_new:N \l_@@_in_DispWithArrows_bool
3350 \bool_new:N \l_@@_in_code_after_bool
3351 % \end{macrocode}
3352 %
3353 % \bigskip
3354 % The following sequence is the position of the last environment |{WithArrows}|
3355 % in the tree of the nested environments |{WithArrows}|.
3356 % \begin{macrocode}
3357 \seq_new:N \g_@@_position_in_the_tree_seq
3358 \seq_gput_right:Nn \g_@@_position_in_the_tree_seq 1
3359 % \end{macrocode}
3360 %
3361 % \bigskip
3362 % The following counter will give the number of the last environment
3363 % |{WithArrows}| of level~$0$. This counter will be used only in the definition
3364 % of |\WithArrowsLastEnv|.
3365 % \begin{macrocode}
3366 \int_new:N \g_@@_last_env_int
3367 % \end{macrocode}
3368 %
3369 % \bigskip
3370 % The following integer indicates the position of the box that will be created
3371 % for an environment |{WithArrows}| (not an environment |{DispWithArrows}|) :
3372 % 0 (=|t|=|\vtop|), 1~(=|c|=|\vcenter|) or 2 (=|b|=|\vbox|).
3373 % \begin{macrocode}
3374 \int_new:N \l_@@_pos_env_int
3375 % \end{macrocode}
3376 %
3377 % \bigskip
3378 % The integer |\l_@@_pos_arrow_int| indicates the position of the arrow with the
3379 % following code (the option |v| is accessible only for the arrows in
3380 % |code-after| where the options |i|, |group| and |groups| are not available).
3381 %
3382 % \begin{center}
3383 % \begin{tabular}{l}
3384 % \begin{tabular}{@{}l*8c@{}}
3385 % \toprule
3386 % option & |lr| & |ll| & |rl| & |rr| & |v| & |i| & |groups| & |group| \\
3387 % \midrule
3388 % |\l_@@_pos_arrow_int| & $0$ & $1$ & $2$ & $3$ & $4$ & $5$ & $6$ & $7$ \\
3389 % \bottomrule
3390 % \end{tabular} \\
3391 % \footnotesize The option |v| can be used only in |\Arrow| in |code-after| (see
3392 % below).
3393 % \end{tabular}
3394 % \end{center}
3395 %
3396 % \begin{macrocode}
3397 \int_new:N \l_@@_pos_arrow_int
3398 \int_set:Nn \l_@@_pos_arrow_int 3
3399 % \end{macrocode}
3400 %
3401 %
3402 % \bigskip
3403 % In the |\halign| of an environment |{WithArrows}| or |{DispWithArrows}|, we
3404 % will have to use four counters:
3405 % \begin{itemize}[beginpenalty=10000]
3406 % \item |\g_@@_arrow_int| to count the arrows created in the environment ;
3407 % \item |\g_@@_line_int| to count the lines of the |\halign| ;
3408 % \item |\g_@@_col_int| to count the columns of the |\halign|.
3409 % \end{itemize}
3410 %
3411 %
3412 % These counters will be incremented in a cell of the |\halign| and, therefore,
3413 % the incrementation must be global. However, we want to be able to include a
3414 % |{WithArrows}| in another |{WithArrows}|. To do so, we must restore the
3415 % previous value of these counters at the end of an environment |{WithArrows}|
3416 % and we decide to manage a stack for each of these counters.
3417 % \begin{macrocode}
3418 \seq_new:N \g_@@_arrow_int_seq
3419 \int_new:N \g_@@_arrow_int
3420 \seq_new:N \g_@@_line_int_seq
3421 \int_new:N \g_@@_line_int
3422 \seq_new:N \g_@@_col_int_seq
3423 \int_new:N \g_@@_col_int
3424 % \end{macrocode}
3425 %
3426 % We will also use a ``static'' version of the counter of columns, called
3427 % |\g_@@_static_col_int|. The value will be set directly in each cell of the
3428 % array by an instruction in the template of the |\halign|. The aim of this
3429 % programmation is to try to detect some use of |\omit| (which should be
3430 % forbidden) in the cells of the |\halign|.
3431 % \begin{macrocode}
3432 \seq_new:N \g_@@_static_col_int_seq
3433 \int_new:N \g_@@_static_col_int
3434 % \end{macrocode}
3435 %
3436 %
3437 % \bigskip
3438 % For the environment |{DispWithArrows}|, the comma list |\l_@@_tags_clist| will
3439 % be the list of the numbers of lines to be tagged (with the counter |equation|
3440 % of LaTeX). In fact, |\l_@@_tags_clist| may contain non negative integers but
3441 % also three special values: |first|, |last| and |all|.
3442 % \begin{macrocode}
3443 %<*LaTeX>
3444 \clist_new:N \l_@@_tags_clist
3445 \clist_set:Nn \l_@@_tags_clist { all }
3446 % \end{macrocode}
3447 %
3448 % \bigskip
3449 % During the execution of an environment |{DispWithArrows}|, if a row must be
3450 % tagged, the (local) value of |\l_@@_tags_clist| will be put (by convention) to
3451 % |all|.
3452 % \begin{macrocode}
3453 \cs_new_protected:Npn \@@_test_if_to_tag:
3454 {
3455 \clist_if_in:NoT \l_@@_tags_clist \g_@@_line_int
3456 { \clist_set:Nn \l_@@_tags_clist { all } }
3457 }
3458 %</LaTeX>
3459 % \end{macrocode}
3460 %
3461 %
3462 % \bigskip
3463 % If the user has given a value for the option |command-name| (at the global or
3464 % at the \emph{environment} level), a command with this name is defined locally
3465 % in the environment with meaning |\@@_Arrow|. The initial value of the option
3466 % |command-name| is ``|Arrow|'' and thus, by default, the name of the command
3467 % will be |\Arrow|.
3468 % \begin{macrocode}
3469 \str_new:N \l_@@_command_name_str
3470 \str_set:Nn \l_@@_command_name_str { Arrow }
3471 % \end{macrocode}
3472 %
3473 % \bigskip
3474 % The string |\l_@@_string_Arrow_for_msg_str| is only a string that will be
3475 % displayed in some error messages. For example, if |command-name| is defined to
3476 % be |Explanation|, this string will contain ``|\Arrow alias \Explanation|''.
3477 % \begin{macrocode}
3478 \str_new:N \l_@@_string_Arrow_for_msg_str
3479 \str_set:Ne \l_@@_string_Arrow_for_msg_str { \token_to_str:N \Arrow }
3480 % \end{macrocode}
3481 %
3482 % \bigskip
3483 % The sequence |\g_@@_names_seq| will be the list of all the names of
3484 % environments used (via the option |name|) in the document: two environments
3485 % must not have the same name. However, it's possible to use the option
3486 % |allow-duplicate-names|.
3487 % \begin{macrocode}
3488 \seq_new:N \g_@@_names_seq
3489 % \end{macrocode}
3490 %
3491 % \bigskip
3492 % The boolean |\l_@@_sbwi_bool| corresponds to the option
3493 % |standard-behaviour-with-items|. Since the version 1.16 of \pkg{witharrows},
3494 % no vertical space is added between an |\item| of a LaTeX list and an
3495 % environment |{DispWithArrows}|. With the option
3496 % |standard-behaviour-with-items|, it's possible to restore the previous
3497 % behaviour (which corresponds to the standard behaviour of |{align}| of
3498 % \pkg{amsmath}). |\l_@@_sbwi_bool| is the boolean corresponding to this option.
3499 % \begin{macrocode}
3500 %<*LaTeX>
3501 \bool_new:N \l_@@_sbwi_bool
3502 %</LaTeX>
3503 % \end{macrocode}
3504 %
3505 % \bigskip
3506 % \begin{macrocode}
3507 %<*LaTeX>
3508 \bool_new:N \l_@@_tag_star_bool
3509 \bool_new:N \l_@@_tag_next_line_bool
3510 \bool_new:N \l_@@_qedhere_bool
3511 %</LaTeX>
3512 \bool_new:N \l_@@_in_first_columns_bool
3513 \bool_new:N \l_@@_new_group_bool
3514 \bool_new:N \l_@@_initial_r_bool
3515 \bool_new:N \l_@@_final_r_bool
3516 \tl_new:N \l_@@_initial_tl
3517 \tl_new:N \l_@@_final_tl
3518 \int_new:N \l_@@_nb_cols_int
3519 % \end{macrocode}
3520 %
3521 % \bigskip
3522 % The string |\l_@@_format_str| will contain the \emph{format} of the array
3523 % which is a succession of letters |r|, |c| and |l| specifying the type of the
3524 % columns of the |\halign| (except the column for the labels of the equations
3525 % in the environment |{DispWithArrows}|).
3526 % \begin{macrocode}
3527 \str_new:N \l_@@_format_str
3528 % \end{macrocode}
3529 %
3530 % \bigskip
3531 % The option |\l_@@_subequations_bool| corresponds to the option |subequations|.
3532 % \begin{macrocode}
3533 %<*LaTeX>
3534 \bool_new:N \l_@@_subequations_bool
3535 %</LaTeX>
3536 % \end{macrocode}
3537 %
3538 % \bigskip
3539 % The dimension |\l_@@_arrow_width_dim| is only for the arrows of type |up| and
3540 % |down|. A value of |\c_max_dim| means that the arrow has the maximal possible
3541 % width. A value of $0$~pt means that the the arrow has a width ajusted to the
3542 % content of the node.
3543 % \begin{macrocode}
3544 \dim_new:N \l_@@_arrow_width_dim
3545 \dim_set_eq:NN \l_@@_arrow_width_dim \c_max_dim
3546 % \end{macrocode}
3547 %
3548 % \bigskip
3549 % The parameter |\l_@@_up_and_down_radius_dim| corresponds to option
3550 % |radius_for_up_and_down|.
3551 % \begin{macrocode}
3552 \dim_new:N \l_@@_up_and_down_radius_dim
3553 \dim_set:Nn \l_@@_up_and_down_radius_dim { 4 pt }
3554 % \end{macrocode}
3555 %
3556 % \bigskip
3557 % The sequence |\l_@@_o_arrows_seq| will be used to store the numbers of the
3558 % arrows which are of type |o| (for \emph{over}) (they are drawn \emph{after}
3559 % the other arrows).
3560 % \begin{macrocode}
3561 \seq_new:N \l_@@_o_arrows_seq
3562 % \end{macrocode}
3563 %
3564 % \bigskip
3565 % The dimension |\l_@@_xoffset_for_o_arrows_dim| is the xoffset added when
3566 % drawing an arrow of type |o| (for \emph{over}).
3567 %
3568 % \begin{macrocode}
3569 \dim_new:N \l_@@_xoffset_for_o_arrows_dim
3570 \dim_set:Nn \l_@@_xoffset_for_o_arrows_dim { 2 mm }
3571 % \end{macrocode}
3572 %
3573 %
3574 % \bigskip
3575 % The following boolean corresponds to the key |right-overlap|. When that key is
3576 % |false|, the overlap on the right of the arrows (and their labels) is computed
3577 % and it is used to change the width of the environment |{WithArrows}| in order
3578 % to include the arrows on the right (and, hence, there is no overlap).
3579 % \begin{macrocode}
3580 \bool_new:N \l_@@_right_overlap_bool
3581 \bool_set_true:N \l_@@_right_overlap_bool
3582 % \end{macrocode}
3583 %
3584 % \bigskip
3585 % \subsection{The definition of the options}
3586 %
3587 % There are four levels where options can be set:
3588 % \begin{itemize}[beginpenalty=10000]
3589 % \item with |\usepackage[...]{witharrows}|: this level will be called
3590 % \emph{package} level;
3591 % \item with |\WithArrowsOptions{...}|: this level will be called \emph{global}
3592 % level\footnote{This level is called \emph{global level} but the settings done
3593 % by |\WithArrowsOptions| are local in the TeX sense: their scope corresponds to
3594 % the current TeX group.};
3595 % \item with |\begin{WithArrows}[...]|: this level will be called
3596 % \emph{environment} level;
3597 % \item with |\Arrow[...]| (included in |code-after|): this level will be called
3598 % \emph{local} level.
3599 % \end{itemize}
3600 %
3601 %
3602 % \bigskip
3603 % When we scan a list of options, we want to be able to raise an error if two
3604 % options of position (|ll|, |rl|, |i|, etc.) of the arrows are present. That's
3605 % why we keep the first option of position in a variable called
3606 % |\l_@@_previous_key_str|. The following function |\@@_eval_if_allowed:n| will
3607 % execute its argument only if a first key of position has not been set (and
3608 % raise an error elsewhere).
3609 %
3610 % \begin{macrocode}
3611 \cs_new_protected:Npn \@@_eval_if_allowed:n #1
3612 {
3613 \str_if_empty:NTF \l_@@_previous_key_str
3614 {
3615 \str_set_eq:NN \l_@@_previous_key_str \l_keys_key_str
3616 #1
3617 }
3618 { \@@_error:n { Incompatible~options } }
3619 }
3620 % \end{macrocode}
3621 %
3622 %
3623 % \begin{macrocode}
3624 \cs_new_protected:Npn \@@_fix_pos_option:n #1
3625 { \@@_eval_if_allowed:n { \int_set:Nn \l_@@_pos_arrow_int { #1 } } }
3626 % \end{macrocode}
3627 %
3628 % \bigskip
3629 % First a set of keys that will be used at the global or environment level of
3630 % options.
3631 % \begin{macrocode}
3632 \keys_define:nn { WithArrows / Global }
3633 {
3634 max-length-of-arrow .dim_set:N = \l_@@_max_length_of_arrow_dim ,
3635 max-length-of-arrow .value_required:n = true ,
3636 max-length-of-arrow .initial:n = 2 cm ,
3637 ygap .dim_set:N = \l_@@_ygap_dim ,
3638 ygap .initial:n = 0.4 ex ,
3639 ygap .value_required:n = true ,
3640 ystart .dim_set:N = \l_@@_ystart_dim ,
3641 ystart .value_required:n = true ,
3642 ystart .initial:n = 0.4 ex ,
3643 more-columns .code:n =
3644 \@@_msg_redirect_name:nn { Too~much~columns~in~WithArrows } { none } ,
3645 more-columns .value_forbidden:n = true ,
3646 command-name .code:n =
3647 \str_set:Nn \l_@@_command_name_str { #1 }
3648 \str_set:Ne \l_@@_string_Arrow_for_msg_str
3649 { \c_backslash_str Arrow~alias~\c_backslash_str #1 } ,
3650 command-name .value_required:n = true ,
3651 tikz-code .tl_set:N = \l_@@_tikz_code_tl ,
3652 tikz-code .initial:n = \draw~(#1)~to~node{#3}~(#2)~; ,
3653 tikz-code .value_required:n = true ,
3654 displaystyle .bool_set:N = \l_@@_displaystyle_bool ,
3655 displaystyle .default:n = true ,
3656 show-nodes .code:n =
3657 \tikzset { @@_node_style / .append~style = { draw , red } } ,
3658 show-node-names .bool_set:N = \l_@@_show_node_names_bool ,
3659 show-node-names .default:n = true ,
3660 group .code:n =
3661 \str_if_empty:NTF \l_@@_previous_key_str
3662 {
3663 \str_set:Nn \l_@@_previous_key_str { group }
3664 \seq_remove_all:Nn \l_@@_options_Arrow_seq { xoffset }
3665 \int_set:Nn \l_@@_pos_arrow_int 7
3666 }
3667 { \@@_error:n { Incompatible~options } } ,
3668 group .value_forbidden:n = true ,
3669 groups .code:n =
3670 \str_if_empty:NTF \l_@@_previous_key_str
3671 {
3672 \str_set:Nn \l_@@_previous_key_str { groups }
3673 \seq_if_in:NnF \l_@@_options_Arrow_seq { new-group }
3674 { \seq_put_right:Nn \l_@@_options_Arrow_seq { new-group } }
3675 \seq_remove_all:Nn \l_@@_options_Arrow_seq { xoffset }
3676 \int_set:Nn \l_@@_pos_arrow_int 6
3677 }
3678 { \@@_error:n { Incompatible~options } } ,
3679 groups .value_forbidden:n = true ,
3680 tikz .code:n = \tikzset { WithArrows / arrow / .append~style = { #1 } } ,
3681 tikz .value_required:n = true ,
3682 rr .code:n = \@@_fix_pos_option:n 3 ,
3683 rr .value_forbidden:n = true ,
3684 ll .code:n = \@@_fix_pos_option:n 1 ,
3685 ll .value_forbidden:n = true ,
3686 rl .code:n = \@@_fix_pos_option:n 2 ,
3687 rl .value_forbidden:n = true ,
3688 lr .code:n = \@@_fix_pos_option:n 0 ,
3689 lr .value_forbidden:n = true ,
3690 i .code:n = \@@_fix_pos_option:n 5 ,
3691 i .value_forbidden:n = true ,
3692 xoffset .dim_set:N = \l_@@_xoffset_dim ,
3693 xoffset .value_required:n = true ,
3694 xoffset .initial:n = 3 mm ,
3695 jot .dim_set:N = \jot ,
3696 jot .value_required:n = true ,
3697 interline .skip_set:N = \l_@@_interline_skip ,
3698 start-adjust .dim_set:N = \l_@@_start_adjust_dim ,
3699 start-adjust .initial:n = 0.4 ex ,
3700 start-adjust .value_required:n = true ,
3701 end-adjust .dim_set:N = \l_@@_end_adjust_dim ,
3702 end-adjust .initial:n = 0.4 ex ,
3703 end-adjust .value_required:n = true ,
3704 adjust .meta:n = { start-adjust = #1 , end-adjust = #1 } ,
3705 adjust .value_required:n = true ,
3706 up-and-down .code:n = \keys_set:nn { WithArrows / up-and-down } { #1 } ,
3707 up-and-down .value_required:n = true ,
3708 % \end{macrocode}
3709 %
3710 % \medskip
3711 % With the option |no-arrows|, the arrows won't be drawn. However, the ``first
3712 % pass'' of the arrows is done and some errors may be detected. The
3713 % nullification of |\@@_draw_arrows:nn| is for the standard arrows and the
3714 % nullification of |\@@_draw_arrow:nnn| is for ``Arrow in |code-after|''.
3715 % \begin{macrocode}
3716 no-arrows .code:n =
3717 \cs_set_eq:NN \@@_draw_arrows:nn \use_none:nn
3718 \cs_set_eq:NN \@@_draw_arrow:nnn \use_none:nnn ,
3719 no-arrows .value_forbidden:n = true
3720 }
3721 % \end{macrocode}
3722 %
3723 % \bigskip
3724 % Now a set of keys specific to the environments |{WithArrows}| (and not
3725 % |{DispWithArrow}}|). Despite its name, this set of keys will also be used in
3726 % |\WithArrowsOptions|.
3727 % \begin{macrocode}
3728 \keys_define:nn { WithArrows / WithArrowsSpecific }
3729 {
3730 t .code:n = \int_set:Nn \l_@@_pos_env_int O ,
3731 t .value_forbidden:n = true ,
3732 c .code:n = \int_set:Nn \l_@@_pos_env_int 1 ,
3733 c .value_forbidden:n = true ,
3734 b .code:n = \int_set:Nn \l_@@_pos_env_int 2 ,
3735 b .value_forbidden:n = true ,
3736 right-overlap .bool_set:N = \l_@@_right_overlap_bool ,
3737 right-overlap .value_required:n = true
3738 }
3739 % \end{macrocode}
3740 %
3741 % \bigskip
3742 % The following list of the (left) extensible delimiters of LaTeX is only for
3743 % the validation of the key |replace-left-brace-by|.
3744 % \begin{macrocode}
3745 \clist_new:N \c_@@_ext_delimiters_clist
3746 \clist_set:Nn \c_@@_ext_delimiters_clist
3747 {
3748 ., \{, (, [, \lbrace, \lbrack, \lgroup, \langle, \lmoustache, \lceil, \lfloor
3749 }
3750 %<*LaTeX>
3751 \AtBeginDocument
3752 {
3753 \bool_set_false:N \l_tmpa_bool
3754 \IfPackageLoadedT { amsmath } { \bool_set_true:N \l_tmpa_bool }
3755 \IfPackageLoadedT { unicode-math } { \bool_set_true:N \l_tmpa_bool }
3756 \bool_if:NT \l_tmpa_bool
3757 { \clist_put_right:Nn \c_@@_ext_delimiters_clist { \lvert, \lVert } }
3758 }
3759 %</LaTeX>
3760 % \end{macrocode}
3761 %
3762 %
3763 % \bigskip
3764 % Now a set of keys specific to the environments |{DispWithArrows}| and
3765 % |{DispWithArrows*}| (and not |{WithArrows}|). Despite its name, this set of
3766 % keys will also be used in |\WithArrowsOptions|.
3767 % \begin{macrocode}
3768 \keys_define:nn { WithArrows / DispWithArrowsSpecific }
3769 {
3770 fleqn .bool_set:N = \l_@@_fleqn_bool ,
3771 fleqn .default:n = true ,
3772 mathindent .skip_set:N = \l_@@_mathindent_skip ,
3773 mathindent .initial:n = 25 pt ,
3774 mathindent .value_required:n = true ,
3775 %<*LaTeX>
3776 notag .code:n =
3777 \str_if_eq:nnTF { #1 } { true }
3778 { \clist_clear:N \l_@@_tags_clist }
3779 { \clist_set:Nn \l_@@_tags_clist { all } } ,
3780 notag .default:n = true ,
3781 % \end{macrocode}
3782 % Since the option |subequations| is an option which insert the environment
3783 % |{DispWithArrows}| in an environment |{subequations}| of \pkg{amsmath}, we
3784 % must test whether the package \pkg{amsmath} is loaded.
3785 % \begin{macrocode}
3786 subequations .code:n =
3787 \IfPackageLoadedTF { amsmath }
3788 { \bool_set_true:N \l_@@_subequations_bool }
3789 {
3790 \@@_error:n { amsmath~not~loaded }
3791 \group_begin:
3792 \globaldefs = 1
3793 \@@_msg_redirect_name:nn { amsmath~not~loaded } { info }
3794 \group_end:
3795 } ,
3796 subequations .default:n = true ,
3797 subequations .value_forbidden:n = true ,
3798 nonumber .meta:n = notag ,
3799 allow-multiple-labels .code:n =
3800 \@@_msg_redirect_name:nn { Multiple~labels } { none } ,
3801 allow-multiple-labels .value_forbidden:n = true ,
3802 tagged-lines .code:n =
3803 \clist_set:Nn \l_@@_tags_clist { #1 }
3804 \clist_if_in:NnT \l_@@_tags_clist { first }
3805 {
3806 \clist_remove_all:Nn \l_@@_tags_clist { first }
3807 \clist_put_left:Nn \l_@@_tags_clist 1
3808 } ,
3809 tagged-lines .value_required:n = true ,
3810 %</LaTeX>
3811 wrap-lines .bool_set:N = \l_@@_wrap_lines_bool ,
3812 wrap-lines .default:n = true ,
3813 replace-left-brace-by .code:n =
3814 {
3815 \tl_set:Ne \l_tmpa_tl { \tl_head:n { #1 } }
3816 \clist_if_in:NoTF
3817 \c_@@_ext_delimiters_clist
3818 \l_tmpa_tl
3819 { \tl_set:Nn \l_@@_replace_left_brace_by_tl { #1 } }
3820 { \@@_error:n { Bad~value~for~replace~brace~by } }
3821 } ,
3822 replace-left-brace-by .initial:n = \lbrace ,
3823 % \end{macrocode}
3824 %
3825 % Since the version 1.16 of \pkg{witharrows}, no vertical space is added between
3826 % an |\item| of a LaTeX list and an environment |{DispWithArrows}|. With the
3827 % option |standard-behaviour-with-items|, it's possible to restore the previous
3828 % behaviour (which corresponds to the standard behaviour of |{align}| of
3829 % \pkg{amsmath}).
3830 % \begin{macrocode}
3831 %<*LaTeX>
3832 standard-behaviour-with-items .bool_set:N = \l_@@_sbwi_bool ,
3833 standard-behaviour-with-items .default:n = true
3834 %</LaTeX>
3835 }
3836 % \end{macrocode}
3837 %
3838 % \bigskip
3839 % Now a set of keys which will be used in all the environments (but not in
3840 % |\WithArrowsOptions}|).
3841 %
3842 % \begin{macrocode}
3843 \keys_define:nn { WithArrows / Env }
3844 {
3845 name .code:n =
3846 % \end{macrocode}
3847 % First, we convert the value in a |str| because the list of the names will be a
3848 % list of |str|.
3849 % \begin{macrocode}
3850 \str_set:Nn \l_tmpa_str { #1 }
3851 \seq_if_in:NoTF \g_@@_names_seq \l_tmpa_str
3852 { \@@_error:n { Duplicate~name } }
3853 { \seq_gput_left:No \g_@@_names_seq \l_tmpa_str }
3854 \str_set_eq:NN \l_@@_name_str \l_tmpa_str ,
3855 name .value_required:n = true ,
3856 code-before .code:n = \tl_put_right:Nn \l_@@_code_before_tl { #1 } ,
3857 code-before .value_required:n = true,
3858 CodeBefore .meta:n = { code-before = #1 } ,
3859 code-after .code:n = \tl_put_right:Nn \l_@@_code_after_tl { #1 } ,
3860 code-after .value_required:n = true ,
3861 CodeAfter .meta:n = { code-after = #1 } ,
3862 format .code:n =
3863 \tl_if_empty:nTF { #1 }
3864 { \@@_error:n { Invalid~option~format } }
3865 {
3866 \regex_match:nnTF { \A[rclRCL]*\Z } { #1 }
3867 { \tl_set:Nn \l_@@_format_str { #1 } }
3868 { \@@_error:n { Invalid~option~format } }
3869 } ,
3870 format .value_required:n = true
3871 }
3872 % \end{macrocode}
3873 %
3874 %
3875 % \bigskip
3876 % Now, we begin the construction of the major sets of keys, named
3877 % ``|WithArrows / WithArrows|'', ``|WithArrows / DispWithArrows|'' and
3878 % ``|WithArrows / WithArrowsOptions|''. Each of these sets of keys will be
3879 % completed after.
3880 % \begin{macrocode}
3881 \keys_define:nn { WithArrows }
3882 {
3883 WithArrows .inherit:n =
3884 {
3885 WithArrows / Global ,
3886 WithArrows / WithArrowsSpecific ,
3887 WithArrows / Env
3888 } ,
3889 WithArrows / up-and-down .inherit:n = WithArrows / up-and-down ,
3890 DispWithArrows .inherit:n =
3891 {
3892 WithArrows / DispWithArrowsSpecific ,
3893 WithArrows / Global ,
3894 WithArrows / Env ,
3895 } ,
3896 DispWithArrows / up-and-down .inherit:n = WithArrows / up-and-down ,
3897 WithArrowsOptions .inherit:n =
3898 {
3899 WithArrows / Global ,
3900 WithArrows / WithArrowsSpecific ,
3901 WithArrows / DispWithArrowsSpecific ,
3902 } ,
3903 WithArrowsOptions / up-and-down .inherit:n = WithArrows / up-and-down
3904 }
3905 % \end{macrocode}
3906 %
3907 %
3908 % \bigskip
3909 % A sequence of |str| for the options available in |{WithArrows}|. This sequence
3910 % will be used in the error messages and can be modified dynamically.
3911 % \begin{macrocode}
3912 \seq_new:N \l_@@_options_WithArrows_seq
3913 \@@_set_seq_of_str_from_clist:Nn \l_@@_options_WithArrows_seq
3914 {
3915 adjust, b, c, code-after, code-before, command-name,
3916 right-overlap, displaystyle, end-adjust,
3917 format, group, groups, i,
3918 interline, jot, ll,
3919 lr, max-length-of-arrow, more-columns, name,
3920 no-arrows, rl, rr, up-and-down,
3921 show-node-names, show-nodes, start-adjust,
3922 t, tikz, tikz-code,
3923 xoffset, ygap, ystart
3924 }
3925 % \end{macrocode}
3926 %
3927 % \medskip
3928 % \begin{macrocode}
3929 \keys_define:nn { WithArrows / WithArrows }
3930 {
3931 unknown .code:n =
3932 \@@_sort_seq:N \l_@@_options_WithArrows_seq
3933 \@@_error:n { Unknown~option~WithArrows }
3934 }
3935 % \end{macrocode}
3936 %
3937 % \bigskip
3938 % \begin{macrocode}
3939 \keys_define:nn { WithArrows / DispWithArrows }
3940 {
3941 left-brace .tl_set:N = \l_@@_left_brace_tl ,
3942 unknown .code:n =
3943 \@@_sort_seq:N \l_@@_options_DispWithArrows_seq
3944 \@@_error:n { Unknown~option~DispWithArrows } ,
3945 }
3946 % \end{macrocode}
3947 %
3948 % \bigskip
3949 % A sequence of the options available in |{DispWithArrows}|. This sequence will
3950 % be used in the error messages and can be modified dynamically.
3951 % \begin{macrocode}
3952 \seq_new:N \l_@@_options_DispWithArrows_seq
3953 \@@_set_seq_of_str_from_clist:Nn \l_@@_options_DispWithArrows_seq
3954 {
3955 code-after, code-before, command-name, tikz-code, adjust,
3956 displaystyle, end-adjust, fleqn, group, format, groups, i, interline, jot,
3957 left-brace, ll, lr, max-length-of-arrow, mathindent, name, no-arrows,
3958 up-and-down, replace-left-brace-by, rl, rr, show-node-names,
3959 show-nodes, start-adjust, tikz, wrap-lines, xoffset, ygap, ystart,
3960 %<*LaTeX>
3961 allow-multiple-labels, tagged-lines, nonumber, notag
3962 %</LaTeX>
3963 }
3964 % \end{macrocode}
3965 %
3966 %
3967 % \begin{macrocode}
3968 \keys_define:nn { WithArrows / WithArrowsOptions }
3969 {
3970 allow-duplicate-names .code:n =
3971 \@@_msg_redirect_name:nn { Duplicate~name } { none } ,
3972 allow-duplicate-names .value_forbidden:n = true ,
3973 xoffset-for-o-arrows .dim_set:N = \l_@@_xoffset_for_o_arrows_dim ,
3974 xoffset-for-o-arrows .value_required:n = true ,
3975 unknown .code:n =
3976 \@@_sort_seq:N \l_@@_options_WithArrowsOptions_seq
3977 \@@_error:n { Unknown~option~WithArrowsOptions }
3978 }
3979 % \end{macrocode}
3980 %
3981 %
3982 % \bigskip
3983 % A sequence of the options available in |\WithArrowsOptions|. This sequence
3984 % will be used in the error messages and can be modified dynamically.
3985 % \begin{macrocode}
3986 \seq_new:N \l_@@_options_WithArrowsOptions_seq
3987 \@@_set_seq_of_str_from_clist:Nn \l_@@_options_WithArrowsOptions_seq
3988 {
3989 allow-duplicate-names, b, c, command-name, right_overlap,
3990 more-columns, tikz-code, adjust,
3991 displaystyle, end-adjust, fleqn, group, groups, i, interline, jot, ll, lr,
3992 mathindent, max-length-of-arrow, no-arrows, up-and-down, rl, rr,
3993 show-node-names, show-nodes, start-adjust, t, tikz, wrap-lines, xoffset,
3994 xoffset-for-o-arrows, ygap, ystart,
3995 %<*LaTeX>
3996 allow-multiple-labels, nonumber, notag, standard-behaviour-with-items,
3997 tagged-lines
3998 %</LaTeX>
3999 }
4000 % \end{macrocode}
4001 %
4002 % \bigskip
4003 % The command |\@@_set_independent:| is a command without argument that will be
4004 % used to specify that the arrow will be ``independent'' (of the potential
4005 % groups of the option |group| or |groups|). This information will be stored in
4006 % the field ``status'' of the arrow. Another possible value of the field
4007 % ``status'' is ``new-group''.
4008 % \begin{macrocode}
4009 \cs_new_protected:Npn \@@_set_independent:
4010 {
4011 \str_if_eq:onF \l_keys_value_tl { NoValue }
4012 { \@@_error:n { Value~for~a~key } }
4013 \@@_set_independent_bis:
4014 }
4015 % \end{macrocode}
4016 %
4017 % \bigskip
4018 % The command |\@@_set_independent_bis:| is the same as |\@@_set_independent:|
4019 % except that the key may be used with a value.
4020 % \begin{macrocode}
4021 \cs_new_protected:Npn \@@_set_independent_bis:
4022 {
4023 \str_if_empty:NTF \l_@@_previous_key_str
4024 {
4025 \str_set_eq:NN \l_@@_previous_key_str \l_keys_key_str
4026 \str_set:Nn \l_@@_status_arrow_str { independent }
4027 }
4028 { \@@_error:n { Incompatible~options~in~Arrow } }
4029 }
4030 % \end{macrocode}
4031 %
4032 %
4033 % \bigskip
4034 % The options of an individual arrow are parsed twice. The first pass is when
4035 % the command |\Arrow| is read. The second pass is when the arrows are drawn
4036 % (after the end of the environment |{WithArrows}| or |{DispWithArrows}|). Now,
4037 % we present the set of keys for the first pass. The main goal is to extract
4038 % informations which will be necessary during the scan of the arrows. For
4039 % instance, we have to know if some arrows are ``independent'' or use the
4040 % option ``new-group''.
4041 % \begin{macrocode}
4042 \keys_define:nn { WithArrows / Arrow / FirstPass }
4043 {
4044 jump .code:n =
4045 \int_compare:nNnTF { #1 } > \c_zero_int
4046 { \int_set:Nn \l_@@_jump_int { #1 } }
4047 { \@@_error:n { Negative~jump } } ,
4048 jump .value_required:n = true,
4049 rr .code:n = \@@_set_independent: ,
4050 ll .code:n = \@@_set_independent: ,
4051 rl .code:n = \@@_set_independent: ,
4052 lr .code:n = \@@_set_independent: ,
4053 i .code:n = \@@_set_independent: ,
4054 rr .default:n = NoValue ,
4055 ll .default:n = NoValue ,
4056 rl .default:n = NoValue ,
4057 lr .default:n = NoValue ,
4058 i .default:n = NoValue ,
4059 new-group .value_forbidden:n = true ,
4060 new-group .code:n =
4061 \int_compare:nTF { \l_@@_pos_arrow_int = 6 }
4062 { \str_set:Nn \l_@@_status_arrow_str { new-group } }
4063 { \@@_error:n { new-group~without~groups } } ,
4064 o .code:n =
4065 \str_if_empty:NTF \l_@@_previous_key_str
4066 {
4067 \int_compare:nNnTF \l_@@_pos_arrow_int < 6
4068 { \@@_error:n { invalid~key~o } }
4069 {
4070 \str_set:Nn \l_@@_status_arrow_str { over }
4071 \str_set_eq:NN \l_@@_previous_key_str \l_keys_key_str
4072 }
4073 }
4074 { \@@_error:n { Incompatible~options~in~Arrow } } ,
4075 % \end{macrocode}
4076 %
4077 % \medskip
4078 % The other keys don't give any information necessary during the scan of the
4079 % arrows. However, you try to detect errors and that's why all the keys are
4080 % listed in this keys set. An unknown key will be detected at the point of the
4081 % command |\Arrow| and not at the end of the environment.
4082 % \begin{macrocode}
4083 tikz-code .code:n = \prg_do_nothing: ,
4084 tikz-code .value_required:n = true ,
4085 tikz .code:n = \prg_do_nothing: ,
4086 tikz .value_required:n = true ,
4087 start-adjust .code:n = \prg_do_nothing: ,
4088 start-adjust .value_required:n = true ,
4089 end-adjust .code:n = \prg_do_nothing: ,
4090 end-adjust .value_required:n = true ,
4091 adjust .code:n = \prg_do_nothing: ,
4092 adjust .value_required:n = true ,
4093 xoffset .code:n = ,
4094 unknown .code:n =
4095 \@@_sort_seq:N \l_@@_options_Arrow_seq
4096 \seq_if_in:NoTF \l_@@_options_WithArrows_seq \l_keys_key_str
4097 {
4098 \str_set:Nn \l_tmpa_str
4099 { ~However,~this~key~can~be~used~in~the~options~of~{WithArrows}. }
4100 }
4101 { \str_clear:N \l_tmpa_str }
4102 \@@_error:n { Unknown~option~in~Arrow }
4103 }
4104 % \end{macrocode}
4105 %
4106 %
4107 % \bigskip
4108 % A sequence of the options available in |\Arrow|. This sequence will be used in
4109 % the error messages and can be modified dynamically.
4110 % \begin{macrocode}
4111 \seq_new:N \l_@@_options_Arrow_seq
4112 \@@_set_seq_of_str_from_clist:Nn \l_@@_options_Arrow_seq
4113 {
4114 adjust, end-adjust, i, jump, ll, lr, o , rl, rr, start-adjust, tikz,
4115 tikz-code, xoffset
4116 }
4117 % \end{macrocode}
4118 %
4119 % \bigskip
4120 % \begin{macrocode}
4121 \cs_new_protected:Npn \@@_fix_pos_arrow:n #1
4122 {
4123 \str_if_empty:NT \l_@@_previous_key_str
4124 {
4125 \str_set_eq:NN \l_@@_previous_key_str \l_keys_key_str
4126 \int_set:Nn \l_@@_pos_arrow_int { #1 }
4127 }
4128 }
4129 % \end{macrocode}
4130 %
4131 % \bigskip
4132 % The options of the individual commands |\Arrows| are scanned twice. The second
4133 % pass is just before the drawing of the arrow. In this set of keys, we don't
4134 % put an item for the unknown keys because an unknown key would have been
4135 % already detected during the first pass.
4136 %
4137 % \begin{macrocode}
4138 \keys_define:nn {WithArrows / Arrow / SecondPass }
4139 {
4140 tikz-code .tl_set:N = \l_@@_tikz_code_tl ,
4141 tikz-code .initial:n = \draw~(#1)~to~node{#3}~(#2)~; ,
4142 tikz .code:n = \tikzset { WithArrows / arrow / .append~style = { #1 } } ,
4143 rr .code:n = \@@_fix_pos_arrow:n 3 ,
4144 ll .code:n = \@@_fix_pos_arrow:n 1 ,
4145 rl .code:n = \@@_fix_pos_arrow:n 2 ,
4146 lr .code:n = \@@_fix_pos_arrow:n 0 ,
4147 i .code:n = \@@_fix_pos_arrow:n 5 ,
4148 o .code:n = \str_set:Nn \l_@@_previous_key_str { o } ,
4149 % \end{macrocode}
4150 %
4151 % \medskip
4152 % The option |xoffset| is not allowed when the option |group| or the option
4153 % |groups| is used except, if the arrow is independent or if there is only one
4154 % arrow.
4155 % \begin{macrocode}
4156 xoffset .code:n =
4157 \bool_lazy_all:nTF
4158 {
4159 { \int_compare_p:nNn \g_@@_arrow_int > 1 }
4160 { \int_compare_p:nNn \l_@@_pos_arrow_int > 5 }
4161 { ! \str_if_eq_p:on \l_@@_status_arrow_str { independent } }
4162 }
4163 { \@@_error:n { Option~xoffset~forbidden } }
4164 { \dim_set:Nn \l_@@_xoffset_dim { #1 } } ,
4165 xoffset .value_required:n = true ,
4166 start-adjust .dim_set:N = \l_@@_start_adjust_dim,
4167 end-adjust .dim_set:N = \l_@@_end_adjust_dim,
4168 adjust .code:n =
4169 \dim_set:Nn \l_@@_start_adjust_dim { #1 }
4170 \dim_set:Nn \l_@@_end_adjust_dim { #1 } ,
4171 }
4172 % \end{macrocode}
4173 %
4174 % \bigskip
4175 % |\WithArrowsOptions| is the command of the \pkg{witharrows} package to fix
4176 % options at the document level. It's possible to fix in |\WithArrowsOptions|
4177 % some options specific to |{WithArrows}| (in contrast with |{DispWithArrows}|)
4178 % or specific to |{DispWithArrows}| (in contrast with |{WithArrows}|). That's
4179 % why we have constructed a set of keys specific to |\WithArrowsOptions|.
4180 % \begin{macrocode}
4181 %<*LaTeX>
4182 \NewDocumentCommand \WithArrowsOptions { m }
4183 %</LaTeX>
4184 %<*plain-TeX>
4185 \cs_set_protected:Npn \WithArrowsOptions #1
4186 %</plain-TeX>
4187 {
4188 \str_clear_new:N \l_@@_previous_key_str
4189 \keys_set:nn { WithArrows / WithArrowsOptions } { #1 }
4190 }
4191 % \end{macrocode}
4192 %
4193 %
4194 % \bigskip
4195 % \subsection{The command \textbackslash Arrow}
4196 %
4197 % In fact, the internal command is not named |\Arrow| but |\@@_Arrow|. Usually,
4198 % at the beginning of an environment |{WithArrows}|, |\Arrow| is set to be
4199 % equivalent to |\@@_Arrow|. However, the user can change the name with the
4200 % option |command-name| and the user command for |\@@_Arrow| will be different.
4201 % This mechanism can be useful when the user already has a command named
4202 % |\Arrow| that he still wants to use in the environments |{WithArrows}| or
4203 % |{DispWithArrows}|.
4204 %
4205 % \medskip
4206 % \begin{macrocode}
4207 %<*LaTeX>
4208 \cs_new_protected:Npn \@@_Arrow
4209 { \@@_collect_options:n { \@@_Arrow_iii } }
4210 \bool_if:NTF \g_@@_beamer_bool
4211 {
4212 \NewDocumentCommand \@@_Arrow_iii { m d < > m ! O { } }
4213 {
4214 \tl_if_novalue:nTF { #2 }
4215 { \@@_Arrow_ii { #1 } { #3 } [ #4 ] }
4216 { \only <#2> { \@@_Arrow_ii { #1 } { #3 } [ #4 ] } }
4217 }
4218 }
4219 {
4220 \NewDocumentCommand \@@_Arrow_iii { m m ! O { } }
4221 { \@@_Arrow_ii { #1 } { #2 } [ #3 ] }
4222 }
4223 \NewDocumentCommand \@@_Arrow_ii { m m ! O { } }
4224 %</LaTeX>
4225 %<*plain-TeX>
4226 \cs_new_protected:Npn \@@_Arrow
4227 {
4228 \peek_meaning:NTF [
4229 { \@@_Arrow_i }
4230 { \@@_Arrow_i [ ] }
4231 }
4232 \cs_new_protected:Npn \@@_Arrow_i [ #1 ] #2
4233 {
4234 \peek_meaning:NTF [
4235 { \@@_Arrow_ii [ #1 ] { #2 } }
4236 { \@@_Arrow_ii [ #1 ] { #2 } [ ] }
4237 }
4238 \cs_new_protected:Npn \@@_Arrow_ii [ #1 ] #2 [ #3 ]
4239 %</plain-TeX>
4240 {
4241 % \end{macrocode}
4242 %
4243 % The counter |\g_@@_arrow_int| counts the arrows in the environment. The
4244 % incrementation must be global (|gincr|) because the command |\Arrow| will be
4245 % used in the cell of a |\halign|. It's recalled that we manage a stack for this
4246 % counter.
4247 % \begin{macrocode}
4248 \int_gincr:N \g_@@_arrow_int
4249 % \end{macrocode}
4250 %
4251 % \medskip
4252 % We will construct a global property list to store the informations of the
4253 % considered arrow. The six fields of this property list are ``initial'',
4254 % ``final'', ``status'', ``options'', ``label'' and ``input-line''. In order to
4255 % compute the value of ``final'' (the destination row of the arrow), we have to
4256 % take into account a potential option |jump|. In order to compute the value of
4257 % the field ``status'', we have to take into account options |ll|, |rl|,
4258 % |rr|, |lr|, etc. or |new-group|.
4259 %
4260 % We will do that job with a first analyze of the options of the command
4261 % |\Arrow| with a dedicated set of keys called |WithArrows/Arrow/FirstPass|.
4262 %
4263 % \begin{macrocode}
4264 \str_clear_new:N \l_@@_previous_key_str
4265 \keys_set:nn { WithArrows / Arrow / FirstPass } { #1 , #3 }
4266 % \end{macrocode}
4267 %
4268 % \medskip
4269 % We construct now a global property list to store the informations of the
4270 % considered arrow with the six fields ``initial'', ``final'', ``status'',
4271 % ``options'', ``label'' and ``input-line''.
4272 %
4273 % \smallskip
4274 % \begin{enumerate}
4275 % \item First, the row from which the arrow starts:
4276 % \begin{macrocode}
4277 \prop_put:NnV \l_tmpa_prop { initial } \g_@@_line_int
4278 % \end{macrocode}
4279 %
4280 % \item The row where the arrow ends (that's why it was necessary to analyze the
4281 % key |jump|):
4282 % \begin{macrocode}
4283 \int_set:Nn \l_tmpa_int { \g_@@_line_int + \l_@@_jump_int }
4284 \prop_put:NnV \l_tmpa_prop { final } \l_tmpa_int
4285 % \end{macrocode}
4286 %
4287 % \item The ``status'' of the arrow, with 4 possible values: empty,
4288 % |independent|, |new-group| or |over|.
4289 % \begin{macrocode}
4290 \prop_put:Nno \l_tmpa_prop { status } \l_@@_status_arrow_str
4291 % \end{macrocode}
4292 %
4293 % \item The options of the arrow (it's a token list):
4294 % \begin{macrocode}
4295 \prop_put:Nnn \l_tmpa_prop { options } { #1 , #3 }
4296 % \end{macrocode}
4297 %
4298 % \item The label of the arrow (it's also a token list):
4299 % \begin{macrocode}
4300 \prop_put:Nnn \l_tmpa_prop { label } { #2 }
4301 % \end{macrocode}
4302 %
4303 % \item The number of the line where the command |\Arrow| is issued in the TeX
4304 % source (as of now, this is only useful for some error messages).
4305 % \begin{macrocode}
4306 \prop_put:Nne \l_tmpa_prop { input-line } \msg_line_number:
4307 % \end{macrocode}
4308 %
4309 % \item The total width of the arrow (with the label)... but we don't know it
4310 % now and that's why we put |0 pt|. There are used for the arrows of type~|o|.
4311 % \begin{macrocode}
4312 \prop_put:Nnn \l_tmpa_prop { width } { 0 pt }
4313 % \end{macrocode}
4314 %
4315 % \end{enumerate}
4316 %
4317 % The property list has been created in a local variable for convenience. Now,
4318 % it will be stored in a global variable indicating both the
4319 % position-in-the-tree and the number of the arrow.
4320 %
4321 % \begin{macrocode}
4322 \prop_gclear_new:c
4323 { g_@@_arrow _ \l_@@_prefix_str _ \int_use:N \g_@@_arrow_int _ prop }
4324 \prop_gset_eq:cN
4325 { g_@@_arrow _ \l_@@_prefix_str _ \int_use:N \g_@@_arrow_int _ prop }
4326 \l_tmpa_prop
4327 }
4328 % \end{macrocode}
4329 %
4330 % \medskip
4331 % The command |\Arrow| (or the corresponding command with a name given by the
4332 % user with the option |command-name|) will be available only in the last column of
4333 % the environments |{WithArrows}| and |{DispWithArrows}|. In the other columns,
4334 % the command will be linked to the following command |\@@_Arrow_first_columns:|
4335 % which will raise an error.
4336 % \begin{macrocode}
4337 \cs_new_protected:Npn \@@_Arrow_first_columns:
4338 { \@@_error:n { Arrow~not~in~last~column } \@@_Arrow }
4339 % \end{macrocode}
4340 %
4341 %
4342 % \bigskip
4343 % \subsection{The environments \{WithArrows\} and \{DispWithArrows\}}
4344 %
4345 % \subsubsection{Code before the \textbackslash halign}
4346 %
4347 % The command |\@@_pre_halign:n| is a code common to the environments
4348 % |{WithArrows}| and |{DispWithArrows}|. The argument is the list of options
4349 % given to the environment.
4350 % \begin{macrocode}
4351 \cs_new_protected:Npn \@@_pre_halign:n #1
4352 % \end{macrocode}
4353 %
4354 % First, the initialization of |\l_@@_type_env_str| which is the name of the
4355 % encompassing environment. In fact, this token list is used only in the error
4356 % messages.
4357 % \begin{macrocode}
4358 {
4359 %<*LaTeX>
4360 \str_clear_new:N \l_@@_type_env_str
4361 \str_set:NV \l_@@_type_env_str \@currenvir
4362 %</LaTeX>
4363 % \end{macrocode}
4364 %
4365 % \bigskip
4366 % We deactivate the potential externalization of Tikz. The Tikz elements created
4367 % by \pkg{witharrows} can't be externalized since they are created in Tikz
4368 % pictures with |overlay| and |remember picture|.
4369 % \begin{macrocode}
4370 \cs_if_exist:NT \tikz@library@external@loaded
4371 { \tikzset { external / export = false } }
4372 % \end{macrocode}
4373 %
4374 % \bigskip
4375 % \begin{macrocode}
4376 \tikzset { arrows = [ flex ] } % https://texnique.fr/osqa/questions/12199
4377 % \end{macrocode}
4378 %
4379 % \bigskip
4380 % The token list |\l_@@_name_str| will contain the potential name of the
4381 % environment (given with the option |name|). This name will be used to create
4382 % aliases for the names of the nodes.
4383 % \begin{macrocode}
4384 \str_clear_new:N \l_@@_name_str
4385 % \end{macrocode}
4386 %
4387 % \bigskip
4388 % The parameter |\l_@@_status_arrow_str| will be used to store the ``status'' of
4389 % an individual arrow. It will be used to fill the field ``status'' in the
4390 % property list describing an arrow.
4391 % \begin{macrocode}
4392 \str_clear_new:N \l_@@_status_arrow_str
4393 % \end{macrocode}
4394 %
4395 % \bigskip
4396 % The dimension |\l_@@_x_dim| will be used to compute the $x$-value for some
4397 % vertical arrows when one of the options |i|, |group| and |groups| (values 5, 6
4398 % and 7 of |\l_@@_pos_arrow_int|) is used.
4399 % \begin{macrocode}
4400 \dim_zero_new:N \l_@@_x_dim
4401 % \end{macrocode}
4402 %
4403 % \medskip
4404 % The variable |\l_@@_input_line_str| will be used only to store, for each
4405 % command |\Arrow| the line (in the TeX file) where the command is issued. This
4406 % information will be stored in the field ``input-line'' of the arrow. As of
4407 % now, this information is used only in some error messages.
4408 % \begin{macrocode}
4409 \str_clear_new:N \l_@@_input_line_str
4410 % \end{macrocode}
4411 %
4412 %
4413 % Initialization of |\g_@@_arrow_int|, |\g_@@_line_int|,
4414 % |\g_@@_col_int| and |\g_@@_static_col_int|. However, we have to save their
4415 % previous values with the stacks created for this end.
4416 % \begin{macrocode}
4417 \seq_gput_right:NV \g_@@_arrow_int_seq \g_@@_arrow_int
4418 \int_gzero:N \g_@@_arrow_int
4419 \seq_gput_right:NV \g_@@_line_int_seq \g_@@_line_int
4420 \int_gzero:N \g_@@_line_int
4421 \seq_gput_right:NV \g_@@_col_int_seq \g_@@_col_int
4422 \int_gzero:N \g_@@_col_int
4423 \seq_gput_right:NV \g_@@_static_col_int_seq \g_@@_static_col_int
4424 \int_gzero:N \g_@@_static_col_int
4425 % \end{macrocode}
4426 %
4427 % In the preamble of the |\halign|, there will be \emph{two} counters of the
4428 % columns. The aim of this programmation is to detect the use of a
4429 % command |\omit| in a cell of the |\halign| (it should be forbidden).
4430 % For example, in the part of the preamble concerning the third column (if there
4431 % is a third column in the environment), we will have the following instructions :
4432 % \begin{Code}
4433 % \int_gincr:N \g_@@_col_int
4434 % \int_set:Nn \g_@@_static_col_int 3
4435 % \end{Code}
4436 % The counter |\g_@@_col_int| is incremented dynamically and the second is
4437 % static. If the user has used a command |\omit|, the dynamic incrementation is
4438 % not done in the cell and, at the end of the row, the difference between the
4439 % counters may infer the presence of |\omit| at least once.
4440 %
4441 % \bigskip
4442 % We also have to update the position on the nesting tree.
4443 % \begin{macrocode}
4444 \seq_gput_right:Nn \g_@@_position_in_the_tree_seq 1
4445 % \end{macrocode}
4446 %
4447 % The nesting tree is used to create a prefix which will be used in the names of
4448 % the Tikz nodes and in the names of the arrows (each arrow is a property list
4449 % of six fields). If we are in the second environment |{WithArrows}| nested in
4450 % the third environment |{WithArrows}| of the document, the prefix will be |3-2|
4451 % (although the position in the tree is $[3,2,1]$ since such a position always
4452 % ends with a~$1$). First, we do a copy of the position-in-the-tree and then we
4453 % pop the last element of this copy (in order to drop the last~$1$).
4454 % \begin{macrocode}
4455 \seq_set_eq:NN \l_tmpa_seq \g_@@_position_in_the_tree_seq
4456 \seq_pop_right:NN \l_tmpa_seq \l_tmpa_tl
4457 \str_clear_new:N \l_@@_prefix_str
4458 \str_set:Ne \l_@@_prefix_str { \seq_use:Nnnn \l_tmpa_seq - - - }
4459 % \end{macrocode}
4460 %
4461 % \bigskip
4462 % We define the command |\\| to be the command |\@@_cr:| (defined below).
4463 % \begin{macrocode}
4464 \cs_set_eq:NN \\ \@@_cr:
4465 \dim_zero:N \mathsurround
4466 % \end{macrocode}
4467 %
4468 % \bigskip
4469 % These counters will be used later as variables.
4470 % \begin{macrocode}
4471 \int_zero_new:N \l_@@_initial_int
4472 \int_zero_new:N \l_@@_final_int
4473 \int_zero_new:N \l_@@_arrow_int
4474 \int_zero_new:N \l_@@_pos_of_arrow_int
4475 \int_zero_new:N \l_@@_jump_int
4476 % \end{macrocode}
4477 %
4478 % \medskip
4479 % The counter |\l_@@_jump_int| corresponds to the option |jump|. Now, we set the
4480 % initial value for this option.
4481 % \begin{macrocode}
4482 \int_set:Nn \l_@@_jump_int 1
4483 % \end{macrocode}
4484 %
4485 % \medskip
4486 % The string |\l_@@_format_str| corresponds to the option |format|. Now, we set
4487 % the initial value for this option.
4488 % \begin{macrocode}
4489 \str_set:Nn \l_@@_format_str { rL }
4490 % \end{macrocode}
4491 %
4492 %
4493 % \bigskip
4494 % In (the last column of) |{DispWithArrows}|, it's possible to put several
4495 % labels (for the same number of equation). That's why these labels will be
4496 % stored in a sequence |\l_@@_labels_seq|.
4497 % \begin{macrocode}
4498 %<*LaTeX>
4499 \seq_clear_new:N \l_@@_labels_seq
4500 % \end{macrocode}
4501 %
4502 % \begin{macrocode}
4503 \bool_set_false:N \l_@@_tag_next_line_bool
4504 %</LaTeX>
4505 % \end{macrocode}
4506 %
4507 % \bigskip
4508 % The value corresponding to the key |interline| is put to zero before the
4509 % treatment of the options of the environment.\footnote{It's recalled that, by
4510 % design, the option |interline| of an environment doesn't apply in the nested
4511 % environments.}
4512 % \begin{macrocode}
4513 \skip_zero:N \l_@@_interline_skip
4514 % \end{macrocode}
4515 %
4516 % \bigskip
4517 % The value corresponding to the key |code-before| is put to nil before the
4518 % treatment of the options of the environment, because, of course, we don't want
4519 % the code executed at the beginning of all the nested
4520 % environments~|{WithArrows}|. Idem for |code-after|.
4521 % \begin{macrocode}
4522 \tl_clear_new:N \l_@@_code_before_tl
4523 \tl_clear_new:N \l_@@_code_after_tl
4524 % \end{macrocode}
4525 %
4526 % \bigskip
4527 % We process the options given to the environment |{WithArrows}| or
4528 % |{DispWithArrows}|.
4529 % \begin{macrocode}
4530 \str_clear_new:N \l_@@_previous_key_str
4531 \bool_if:NT \l_@@_in_WithArrows_bool
4532 { \keys_set:nn { WithArrows / WithArrows } { #1 } }
4533 \bool_if:NT \l_@@_in_DispWithArrows_bool
4534 { \keys_set:nn { WithArrows / DispWithArrows } { #1 } }
4535 % \end{macrocode}
4536 %
4537 % \medskip
4538 % The dimension |\g_@@_overlap_x_dim| will be the maximal overlap on the right
4539 % of the arrows (and their labels) drawn in the environment |{WithArrows}|. The
4540 % dimension |\l_@@_delta_x_dim| will be the difference of abscissa between the
4541 % right side of the alignment (|\halign|) and the left side of the arrow.
4542 % \begin{macrocode}
4543 \bool_if:NF \l_@@_right_overlap_bool
4544 {
4545 \bool_if:NT \l_@@_in_WithArrows_bool
4546 {
4547 \dim_gzero_new:N \g_@@_overlap_x_dim
4548 \dim_zero_new:N \l_@@_delta_x_dim
4549 }
4550 }
4551 % \end{macrocode}
4552 %
4553 % \medskip
4554 % Now we link the command |\Arrow| (or the corresponding command with a name
4555 % given by the user with the option |command-name|: that's why the following line
4556 % must be after the loading of the options) to the command
4557 % |\@@_Arrow_first_columns:| which will raise an error.
4558 % \begin{macrocode}
4559 \cs_set_eq:cN \l_@@_command_name_str \@@_Arrow_first_columns:
4560 % \end{macrocode}
4561 % It's only in the last column of the environment that it will be linked to the
4562 % command |\@@_Arrow:|.
4563 %
4564 % \medskip
4565 % The counter |\l_@@_nb_cols_int| is the number of columns in the
4566 % |\halign| (excepted the column for the labels of equations in
4567 % |{DispWithArrows}| and excepted eventuals other columns in |{WithArrows}| allowed
4568 % by the option |more-columns|).
4569 % \begin{macrocode}
4570 \int_set:Nn \l_@@_nb_cols_int { \str_count:N \l_@@_format_str }
4571 % \end{macrocode}
4572 %
4573 % \medskip
4574 % Be careful! The following counter |\g_@@_col_int| will be used for two usages:
4575 % \begin{itemize}[beginpenalty=10000]
4576 % \item during, the construction of the preamble of the |\halign|, it will be
4577 % used as counter for the number of the column under construction in the
4578 % preamble (since the preamble is constructed backwards, |\g_@@_col_int| will go
4579 % decreasing from |\l_@@_nb_cols_int| to $1$) ;
4580 % \item once the preamble constructed, the primitive |\halign| is executed, and,
4581 % in each row of the |\halign|, the counter |\g_@@_col_int| will be increased
4582 % from column to column.
4583 % \end{itemize}
4584 %
4585 % \begin{macrocode}
4586 \int_gset_eq:NN \g_@@_col_int \l_@@_nb_cols_int
4587 % \end{macrocode}
4588 %
4589 % \medskip
4590 % We convert the format in a sequence because we use it as a stack (with the top
4591 % of the stack at the end of the sequence) in the construction of the preamble.
4592 % \begin{macrocode}
4593 \seq_clear_new:N \l_@@_format_seq
4594 \seq_set_split:NnV \l_@@_format_seq { } \l_@@_format_str
4595 % \end{macrocode}
4596 %
4597 % \bigskip
4598 % If the option |footnote| or the option |footnotehyper| is used, then we
4599 % extract the footnotes with an environment |{savenotes}| (of the package
4600 % \pkg{footnote} or the package \pkg{footnotehyper}).
4601 % \begin{macrocode}
4602 %<*LaTeX>
4603 \bool_if:NT \c_@@_footnote_bool { \begin { savenotes } }
4604 %</LaTeX>
4605 % \end{macrocode}
4606 %
4607 % \bigskip
4608 % We execute the code |\l_@@_code_before_tl| of the option |code-before| of the
4609 % environment after the potential |\begin{savenotes}| and, symetrically, we will
4610 % execute the |\l_@@_code_after_tl| before the potential |\end{savenotes}| (we
4611 % have a good reason for the last point: we want to extract the footnotes of the
4612 % arrows executed in the |code-after|).
4613 % \begin{macrocode}
4614 \l_@@_code_before_tl
4615 % \end{macrocode}
4616 %
4617 %
4618 %
4619 % \begin{macrocode}
4620 %<*LaTeX>
4621 \cs_set_eq:NN \notag \@@_notag:
4622 \cs_set_eq:NN \nonumber \@@_nonumber:
4623 \cs_set_eq:NN \tag \@@_tag
4624 \cs_set_eq:NN \@@_old_label \label
4625 \cs_set_eq:NN \label \@@_label:n
4626 \cs_set_eq:NN \tagnextline \@@_tagnextline:
4627 %</LaTeX>
4628 }
4629 % \end{macrocode}
4630 % This is the end of |\@@_pre_halign:n|.
4631 %
4632 % \bigskip
4633 % \subsubsection{The construction of the preamble of the \textbackslash halign}
4634 %
4635 % The control sequence |\@@_construct_halign:| will ``start'' the |\halign| and
4636 % the preamble. In fact, it constructs all the preamble excepted the end of
4637 % the last column (more precisely: except the part concerning the construction
4638 % of the left node and the right node).
4639 %
4640 % The same function |\@@_construct_halign:| will be used both for the
4641 % environment |{WithArrows}| and the environment |{DispWithArrows}|.
4642 %
4643 % Several important points must be noted concerning that construction of the
4644 % preamble.
4645 % \begin{itemize}[beginpenalty=10000]
4646 % \item The construction of the preamble is done by reading backwards the
4647 % format |\l_@@_format_str| and adding the corresponding tokens in the input
4648 % stream of TeX. That means that the part of the preamble concerning the last
4649 % cell will be constructed first.
4650 % \item The function |\@@_construct_halign:| is recursive in order to treat
4651 % successively all the letters of the preamble.
4652 % \item Each part of the preamble is created with a |\use:e| function. This
4653 % expansion of the preamble gives the ability of controlling which parts of the
4654 % code will be expanded during the construction of the preamble (other parts
4655 % will be expanded and executed only during the execution of the |\halign|).
4656 % \item The counter |\g_@@_col_int| is used during the loop of the construction
4657 % of the preamble but, it will also appears in the preamble (we could have
4658 % chosen two differents counters but this way saves a counter).
4659 % \end{itemize}
4660 %
4661 % \begin{macrocode}
4662 \cs_new_protected:Npn \@@_construct_halign:
4663 {
4664 \seq_pop_right:NNTF \l_@@_format_seq \l_@@_type_col_str
4665 {
4666 % \end{macrocode}
4667 % Here is the |\use:e| which is fundamental: it will really construct the part
4668 % of the preamble corresponding to a column by expanding only some parts of the
4669 % following code.
4670 % \begin{macrocode}
4671 \use:e
4672 {
4673 % \end{macrocode}
4674 % Before the recursive call of |\@@_construct_halign:|, we decrease the integer
4675 % |\g_@@_col_bool|. But, during the construction of the column which is
4676 % constructed first (that is to say which is the last column of the |\halign|),
4677 % it is \emph{not} lowered because |\int_decr:N|, which is protected, won't be
4678 % expanded by the |\use:e|.
4679 %
4680 % We begin the construction of a generic column.
4681 % \begin{macrocode}
4682 \int_gdecr:N \g_@@_col_int
4683 \@@_construct_halign:
4684 \int_compare:nNnT \g_@@_col_int = \l_@@_nb_cols_int
4685 {
4686 % \end{macrocode}
4687 % We redefine the command |\Arrow| (or the name given to the corresponding
4688 % command by the option |command-name|) in each cell of the last column.
4689 % The braces around |\l_@@_command_name_str| are mandatory because
4690 % |\l_@@_command_name_str| will be expanded by the |\use:e| and the command
4691 % |\cs_set_eq:cN| must still be efficient during the execution of the |\halign|.
4692 % \begin{macrocode}
4693 \cs_set_eq:cN { \l_@@_command_name_str } \@@_Arrow
4694 %<*LaTeX>
4695 \bool_if:NT \l_@@_in_DispWithArrows_bool
4696 {
4697 % \end{macrocode}
4698 % The command |\@@_test_if_to_tag:| (which is protected and, thus, will not be
4699 % expanded during the construction of the preamble) will test, at each row,
4700 % whether the current row must be tagged (and the tag will be put in the very
4701 % last column).
4702 % \begin{macrocode}
4703 \@@_test_if_to_tag:
4704 % \end{macrocode}
4705 % The command |\@@_set_qedhere:| will do a redefinition of |\qedhere| in each
4706 % cell of the last column.
4707 % \begin{macrocode}
4708 \IfPackageLoadedT { amsmath } { \@@_set_qedhere: }
4709 }
4710 %</LaTeX>
4711 }
4712 \str_if_eq:onT \l_@@_type_col_str { c } \hfil
4713 \str_if_eq:onT \l_@@_type_col_str { C } \hfil
4714 \str_if_eq:onT \l_@@_type_col_str { r } \hfill
4715 \str_if_eq:onT \l_@@_type_col_str { R } \hfill
4716 \int_gincr:N \g_@@_col_int
4717 \int_gset:Nn \g_@@_static_col_int { \int_use:N \g_@@_col_int }
4718 \c_math_toggle_token
4719 \str_if_eq:onT \l_@@_type_col_str { C } { { } }
4720 \str_if_eq:onT \l_@@_type_col_str { L } { { } }
4721 \bool_if:NT \l_@@_displaystyle_bool \displaystyle
4722 ##
4723 \str_if_eq:onT \l_@@_type_col_str { C } { { } }
4724 \str_if_eq:onT \l_@@_type_col_str { R } { { } }
4725 \c_math_toggle_token
4726 \int_compare:nNnTF \g_@@_col_int = \l_@@_nb_cols_int
4727 \@@_construct_nodes:
4728 {
4729 % \end{macrocode}
4730 % The following glue (|\hfil|) will be added only if we are not in the last cell
4731 % because, in the last cell, a glue (=skip) is added between the nodes (in
4732 % |\@@_construct_nodes:|).
4733 % \begin{macrocode}
4734 \str_if_eq:onT \l_@@_type_col_str { l } \hfil
4735 \str_if_eq:onT \l_@@_type_col_str { L } \hfil
4736 \str_if_eq:onT \l_@@_type_col_str { c } \hfil
4737 \str_if_eq:onT \l_@@_type_col_str { C } \hfil
4738 \bool_if:NT \l_@@_in_DispWithArrows_bool { \tabskip = \c_zero_skip }
4739 &
4740 }
4741 }
4742 }
4743 % \end{macrocode}
4744 % Now the tokens that will be inserted after the analyze of all the tokens of
4745 % the format: here is the token |\halign|.
4746 % \begin{macrocode}
4747 {
4748 \bool_if:NTF \l_@@_in_WithArrows_bool
4749 {
4750 \ialign
4751 \bgroup
4752 }
4753 {
4754 \halign to \l_@@_linewidth_dim
4755 \bgroup
4756 \bool_if:NT \l_@@_fleqn_bool
4757 { \skip_horizontal:N \l_@@_mathindent_skip }
4758 }
4759 \int_gincr:N \g_@@_line_int
4760 \int_gzero:N \g_@@_col_int
4761 \tl_if_eq:NNF \l_@@_left_brace_tl \c_novalue_tl
4762 {
4763 \skip_horizontal:n
4764 { \box_wd:N \l_@@_left_brace_box + \l_@@_delim_wd_dim }
4765 }
4766 \strut
4767 }
4768 }
4769 % \end{macrocode}
4770 %
4771 %
4772 % \bigskip
4773 % The command |\@@_construct_nodes:| is only for the lisibility of the code
4774 % because, in fact, it is used only once. It constructs the ``left node'' and
4775 % the ``right node'' at the end of each row of the arrow.
4776 % \begin{macrocode}
4777 \cs_new_protected:Npn \@@_construct_nodes:
4778 {
4779 % \end{macrocode}
4780 % We create the ``left node'' of the line (when using macros in Tikz node names,
4781 % the macros have to be fully expandable: here, |\int_use:N| is fully
4782 % expandable).
4783 % \begin{macrocode}
4784 \tikz [ remember~picture , overlay ]
4785 \node
4786 [
4787 node~contents = { } ,
4788 @@_node_style ,
4789 name = wa - \l_@@_prefix_str - \int_use:N \g_@@_line_int - l ,
4790 ]
4791 ;
4792 \hfil
4793 % \end{macrocode}
4794 %
4795 % \bigskip
4796 % Now, after the |\hfil|, we create the ``right node'' and, if the option
4797 % |show-node-names| is raised, the name of the node is written in the document
4798 % (useful for debugging).
4799 % \begin{macrocode}
4800 \tikz [ remember~picture , overlay ]
4801 \node
4802 [
4803 node~contents = { } ,
4804 @@_node_style ,
4805 name = wa - \l_@@_prefix_str - \int_use:N \g_@@_line_int - r ,
4806 ]
4807 ;
4808 \str_if_empty:NF \l_@@_name_str
4809 {
4810 \pgfpicture
4811 \pgfnodealias
4812 { \l_@@_name_str - \int_use:N \g_@@_line_int - l }
4813 { wa - \l_@@_prefix_str - \int_use:N \g_@@_line_int - l }
4814 \pgfnodealias
4815 { \l_@@_name_str - \int_use:N \g_@@_line_int - r }
4816 { wa - \l_@@_prefix_str - \int_use:N \g_@@_line_int - r }
4817 \endpgfpicture
4818 }
4819 \bool_if:NT \l_@@_show_node_names_bool
4820 {
4821 \hbox_overlap_right:n
4822 { \small wa - \l_@@_prefix_str - \int_use:N \g_@@_line_int - r }
4823 }
4824 }
4825 % \end{macrocode}
4826 %
4827 %
4828 %
4829 % \bigskip
4830 % \subsubsection{The environment \{WithArrows\}}
4831 %
4832 %
4833 % \begin{macrocode}
4834 %<*LaTeX>
4835 \NewDocumentEnvironment { WithArrows } { ! O { } }
4836 %</LaTeX>
4837 %<*plain-TeX>
4838 \cs_new_protected:Npn \WithArrows
4839 {
4840 \group_begin:
4841 \peek_meaning:NTF [
4842 { \WithArrows_i }
4843 { \WithArrows_i [ ] }
4844 }
4845 \cs_new_protected:Npn \WithArrows_i [ #1 ]
4846 %</plain-TeX>
4847 {
4848 \bool_set_true:N \l_@@_in_WithArrows_bool
4849 \bool_set_false:N \l_@@_in_DispWithArrows_bool
4850 %<*plain-TeX>
4851 \str_clear_new:N \l_@@_type_env_str
4852 \str_set:Nn \l_@@_type_env_str { WithArrows }
4853 %</plain-TeX>
4854 \@@_pre_halign:n { #1 }
4855 \if_mode_math: \else:
4856 \@@_error:n { WithArrows~outside~math~mode }
4857 \fi:
4858 % \end{macrocode}
4859 %
4860 % \begin{macrocode}
4861 \box_clear_new:N \l_@@_env_box
4862 \hbox_set:Nw \l_@@_env_box
4863 % \end{macrocode}
4864 %
4865 % \bigskip
4866 % The environment begins with a |\vtop|, a |\vcenter| or a
4867 % |\vbox|\footnote{Notice that the use of |\vtop| seems color-safe here...}
4868 % depending of the value of |\l_@@_pos_env_int| (fixed by the options |t|, |c|
4869 % or |b|). The environment |{WithArrows}| must be used in math mode\footnote{An
4870 % error is raised if the environment is used outside math mode.} and therefore,
4871 % we can use |\vcenter|.
4872 % \begin{macrocode}
4873 \int_compare:nNnT \l_@@_pos_env_int = 1 \c_math_toggle_token
4874 \int_case:nn \l_@@_pos_env_int { 0 \vtop 1 \vcenter 2 \vbox }
4875 \bgroup
4876 % \end{macrocode}
4877 %
4878 %
4879 % \bigskip
4880 % The command |\spread@equation| is the command used by \pkg{amsmath} in the
4881 % beginning of an alignment to fix the interline. When used, it becomes no-op.
4882 % However, it's possible to use \pkg{witharrows} without \pkg{amsmath} since we
4883 % have redefined |\spread@equation| (if it is not defined yet).
4884 % \begin{macrocode}
4885 \spread@equation
4886 % \end{macrocode}
4887 %
4888 % \bigskip
4889 % We begin the |\halign| and the preamble. During the construction of the
4890 % preamble, |\l_tmpa_int| will be incremented during each column constructed.
4891 % \begin{macrocode}
4892 \@@_construct_halign:
4893 % \end{macrocode}
4894 %
4895 %
4896 % \medskip
4897 % In fact, the construction of the preamble is not finished. We add a little more.
4898 %
4899 % \medskip
4900 % An environmemnt |{WithArrows}| should have a number of columns equal to the
4901 % length of its format (by default, 2 since the default format is |rl|).
4902 % Nevertheless, if the user wants to use more columns (without arrows)
4903 % it's possible with the option |more-columns|.
4904 % \begin{macrocode}
4905 &&
4906 \@@_error:n { Too~much~columns~in~WithArrows }
4907 \c_math_toggle_token
4908 \bool_if:NT \l_@@_displaystyle_bool \displaystyle
4909 { ## }
4910 \c_math_toggle_token
4911 \cr
4912 }
4913 % \end{macrocode}
4914 %
4915 %
4916 % \bigskip
4917 % We begin the second part of the environment |{WithArrows}|. We have three
4918 % |\egroup|\,: one for the |\halign|, one for the |\vtop| (or |\vcenter| or
4919 % |\vbox|) and one for the |\hbox_set:Nn \l_@@_env_box|.
4920 % \begin{macrocode}
4921 %<*plain-TeX>
4922 \cs_new_protected:Npn \endWithArrows
4923 %</plain-TeX>
4924 {
4925 \\
4926 \egroup
4927 \egroup
4928 \int_compare:nNnT \l_@@_pos_env_int = 1 \c_math_toggle_token
4929 \hbox_set_end:
4930 \@@_post_halign:
4931 % \end{macrocode}
4932 % We want to add white space on the right side of the box in order to take into
4933 % account the arrows and their labels.
4934 % \begin{macrocode}
4935 \bool_if:NF \l_@@_right_overlap_bool
4936 {
4937 \box_set_wd:Nn \l_@@_env_box
4938 { \g_@@_overlap_x_dim + \box_wd:N \l_@@_env_box }
4939 }
4940 \box_use_drop:N \l_@@_env_box
4941 % \end{macrocode}
4942 %
4943 % \bigskip
4944 % If the option |footnote| or the option |footnotehyper| is used, then we
4945 % extract the footnotes with an environment |{footnote}| (of the package
4946 % \pkg{footnote} or the package \pkg{footnotehyper}).
4947 % \begin{macrocode}
4948 %<*LaTeX>
4949 \bool_if:NT \c_@@_footnote_bool { \end { savenotes } }
4950 %</LaTeX>
4951 %<*plain-TeX>
4952 \group_end:
4953 %</plain-TeX>
4954 }
4955 % \end{macrocode}
4956 % This is the end of the environment |{WithArrows}|.
4957 %
4958 %
4959 % \bigskip
4960 % \subsubsection{After the construction of the \textbackslash halign}
4961 %
4962 % The command |\@@_post_halign:| is a code common to the second part of the
4963 % environment |{WithArrows}| and the environment |{DispWithArrows}|.
4964 % \begin{macrocode}
4965 \cs_new_protected:Npn \@@_post_halign:
4966 % \end{macrocode}
4967 %
4968 % \bigskip
4969 % The command |\WithArrowsRightX| is not used by \pkg{witharrows}. It's only a
4970 % convenience given to the user.
4971 % \begin{macrocode}
4972 {
4973 \cs_set:Npn \WithArrowsRightX { \g_@@_right_x_dim }
4974 % \end{macrocode}
4975 %
4976 % \bigskip
4977 % We use |\normalbaselines| of plain-TeX because we have used
4978 % |\spread@equation| (of \pkg{amsmath} or defined directly if \pkg{amsmath} is
4979 % not loaded) and you don't want |\spread@equation| to have effects in the
4980 % labels of the arrows.
4981 % \begin{macrocode}
4982 \normalbaselines
4983 % \end{macrocode}
4984 %
4985 % \bigskip
4986 % If there is really arrows in the environment, we draw the arrows.
4987 % \begin{macrocode}
4988 \int_if_zero:nF \g_@@_arrow_int
4989 {
4990 % \end{macrocode}
4991 % If there is only one arrow, the options |group| and |groups| do not really
4992 % make sense and it will be quicker to act as if we were in option |i| (moreover,
4993 % it allows the option |xoffset| for the unique arrow).
4994 % \begin{macrocode}
4995 \int_compare:nNnT \g_@@_arrow_int = 1
4996 {
4997 \int_compare:nNnT \l_@@_pos_arrow_int > 5
4998 { \int_set:Nn \l_@@_pos_arrow_int 5 }
4999 }
5000 \@@_scan_arrows:
5001 }
5002 % \end{macrocode}
5003 %
5004 % \bigskip
5005 % We will execute the code specified in the option |code-after|, after some
5006 % settings.
5007 % \begin{macrocode}
5008 \group_begin:
5009 \tikzset { every~picture / .style = @@_standard }
5010 % \end{macrocode}
5011 % The command |\WithArrowsNbLines| is not used by \pkg{witharrows}. It's only a
5012 % convenience given to the user.
5013 % \begin{macrocode}
5014 \cs_set:Npn \WithArrowsNbLines { \int_use:N \g_@@_line_int }
5015 % \end{macrocode}
5016 % The command |\MultiArrow| is available in |code-after|, and we have a special
5017 % version of |\Arrow|, called ``|\Arrow| in |code-after|'' in the
5018 % documentation.\footnote{As of now, |\MultiArrow| has no option, and that's
5019 % why its internal name is a name of L3 with the signature |:nn|
5020 % whereas |\Arrow| in |code-after| provides options and has the name of a
5021 % function defined with |\NewDocumentCommand|.}
5022 % \begin{macrocode}
5023 \cs_set_eq:NN \MultiArrow \@@_MultiArrow:nn
5024 \cs_set_eq:cN \l_@@_command_name_str \@@_Arrow_code_after
5025 \bool_set_true:N \l_@@_in_code_after_bool
5026 \l_@@_code_after_tl
5027 \group_end:
5028 % \end{macrocode}
5029 %
5030 % \bigskip
5031 % We update the position-in-the-tree. First, we drop the last component and then
5032 % we increment the last element.
5033 % \begin{macrocode}
5034 \seq_gpop_right:NN \g_@@_position_in_the_tree_seq \l_tmpa_tl
5035 \seq_gpop_right:NN \g_@@_position_in_the_tree_seq \l_tmpa_tl
5036 \seq_gput_right:Ne \g_@@_position_in_the_tree_seq
5037 { \int_eval:n { \l_tmpa_tl + 1 } }
5038 % \end{macrocode}
5039 %
5040 % \bigskip
5041 % We update the value of the counter |\g_@@_last_env_int|. This counter is used
5042 % only by the user function |\WithArrowsLastEnv|.
5043 % \begin{macrocode}
5044 \int_compare:nNnT { \seq_count:N \g_@@_position_in_the_tree_seq } = 1
5045 { \int_gincr:N \g_@@_last_env_int }
5046 % \end{macrocode}
5047 %
5048 % \bigskip
5049 % Finally, we restore the previous values of the counters |\g_@@_arrow_int|,
5050 % |\g_@@_col_int| and |\g_@@_static_col_int|. It is recalled that we manage four
5051 % stacks in order to be able to do such a restoration.
5052 % \begin{macrocode}
5053 \seq_gpop_right:NN \g_@@_arrow_int_seq \l_tmpa_tl
5054 \int_gset:Nn \g_@@_arrow_int \l_tmpa_tl
5055 \seq_gpop_right:NN \g_@@_line_int_seq \l_tmpa_tl
5056 \int_gset:Nn \g_@@_line_int \l_tmpa_tl
5057 \seq_gpop_right:NN \g_@@_col_int_seq \l_tmpa_tl
5058 \int_gset:Nn \g_@@_col_int \l_tmpa_tl
5059 \seq_gpop_right:NN \g_@@_static_col_int_seq \l_tmpa_tl
5060 \int_gset:Nn \g_@@_static_col_int \l_tmpa_tl
5061 }
5062 % \end{macrocode}
5063 % That's the end of the command |\@@_post_halign:|.
5064 %
5065 % \bigskip
5066 % \subsubsection{The command of end of row}
5067 %
5068 % We give now the definition of |\@@_cr:| which is the definition of |\\| in an
5069 % environment |{WithArrows}|. The two commands |\group_align_safe_begin:| and
5070 % |\group_align_safe_end:| are specifically designed for this purpose: test the
5071 % token that follows in an |\halign| structure.
5072 %
5073 % First, we remove an eventual token |*| (just after the |\\|: there should not
5074 % be space between the two) since the commands |\\| and |\\*| are equivalent in
5075 % an environment |{WithArrows}| (an environment |{WithArrows}|, like an
5076 % environment |{aligned}| of \pkg{amsmath}, is always unbreakable).
5077 % \begin{macrocode}
5078 \cs_new_protected:Npn \@@_cr:
5079 {
5080 \scan_stop:
5081 % \end{macrocode}
5082 % We try to detect some |\omit| (as of now, an |\omit| in the last column is
5083 % not detected).
5084 % \begin{macrocode}
5085 \int_compare:nNnF \g_@@_col_int = \g_@@_static_col_int
5086 { \@@_error:n { omit~probably~used } }
5087 \prg_replicate:nn { \l_@@_nb_cols_int - \g_@@_static_col_int } { & { } }
5088 \group_align_safe_begin:
5089 \peek_meaning_remove:NTF * \@@_cr_i: \@@_cr_i:
5090 }
5091 % \end{macrocode}
5092 %
5093 % \medskip
5094 % Then, we peek the next token to see if it's a |[|. In this case, the command
5095 % |\\| has an optional argument which is the vertical skip (=glue) to put.
5096 % \begin{macrocode}
5097 \cs_new_protected:Npn \@@_cr_i:
5098 { \peek_meaning:NTF [ \@@_cr_ii: { \@@_cr_ii: [ \c_zero_dim ] } }
5099 % \end{macrocode}
5100 %
5101 % \bigskip
5102 % Now, we test if the next token is the token |\end|. Indeed, we want to test if
5103 % the following tokens are |\end{WithArrows}| (or |\end{Code}|, etc).
5104 % In this case, we raise an error because the user must not put "\\" at the end
5105 % of its alignment.
5106 % \begin{macrocode}
5107 %<*LaTeX>
5108 \cs_new_protected:Npn \@@_cr_ii: [ #1 ]
5109 {
5110 \peek_remove_spaces:n
5111 {
5112 \peek_meaning:NTF \end
5113 {
5114 \@@_cr_iii:n { #1 }
5115 % \end{macrocode}
5116 % The analyse of the argument of the token |\end| must be after the
5117 % |\group_align_safe_end:| which is the beginning of |\@@_cr_iii:n|.
5118 % \begin{macrocode}
5119 \@@_analyze_end:Nn
5120 }
5121 { \@@_cr_iii:n { #1 } }
5122 }
5123 }
5124 % \end{macrocode}
5125 %
5126 % \begin{macrocode}
5127 \cs_new_protected:Npn \@@_cr_iii:n #1
5128 %</LaTeX>
5129 %<*plain-TeX>
5130 \cs_new_protected:Npn \@@_cr_ii: [ #1 ]
5131 %</plain-TeX>
5132 {
5133 \group_align_safe_end:
5134 % \end{macrocode}
5135 % For the environment |{DispWithArrows}|, the behaviour of |\\| is different
5136 % because we add the last column which is the column for the tag (number of the
5137 % equation). Even if there is no tag, this column is used for the
5138 % |v|-nodes.\footnote{The |v|-nodes are used to compute the abscissa of the
5139 % right margin, used by the option |wrap-lines|.}
5140 % \begin{macrocode}
5141 \bool_if:NT \l_@@_in_DispWithArrows_bool
5142 % \end{macrocode}
5143 % At this stage, we know that we have a tag to put if (and only if) the value of
5144 % |\l_@@_tags_clist| is the comma list |all| (only one element). Maybe,
5145 % previously, the value of |\l_@@_tags_clist| was, for example, |1,last| (which
5146 % means that only the first line and the last line must be tagged). However, in
5147 % this case, the comparison with the number of line has be done before and, now,
5148 % if we are in a line to tag, the value of |\l_@@_tags_clist| is |all|.
5149 % \begin{macrocode}
5150 {
5151 %<*LaTeX>
5152 \clist_if_in:NnTF \l_@@_tags_clist { all }
5153 {
5154 % \end{macrocode}
5155 % Here, we can't use |\refstepcounter{equation}| because if the user has issued
5156 % a |\tag| command, we have to use |\l_@@_tag_tl| and not |\theequation|. That's
5157 % why we have to do the job done by |\refstepcounter| manually.
5158 %
5159 % First, the incrementation of the counter (potentially).
5160 % \begin{macrocode}
5161 \tl_if_empty:NT \l_@@_tag_tl { \int_gincr:N \c@equation }
5162 % \end{macrocode}
5163 %
5164 % We store in |\g_tmpa_tl| the tag we will have to compose at the end of the
5165 % line. We use a global variable because we will use it in the \emph{next} cell
5166 % (after the |&|).
5167 % \begin{macrocode}
5168 \cs_gset:Npe \g_tmpa_tl
5169 { \tl_if_empty:NTF \l_@@_tag_tl \theequation \l_@@_tag_tl }
5170 % \end{macrocode}
5171 % It's possible to put several labels for the same line (it's not possible in
5172 % the environments of \pkg{amsmath}). That's why the differents labels of a same
5173 % line are stored in a sequence |\l_@@_labels_seq|.
5174 % \begin{macrocode}
5175 \seq_if_empty:NF \l_@@_labels_seq
5176 {
5177 % \end{macrocode}
5178 % Now, we do the job done by |\refstepcounter| and by the redefinitions of
5179 % |\refstepcounter| done by some packages (the incrementation of the counter has
5180 % been done yet).
5181 %
5182 % First an action which is in the definition of |\refstepcounter|.
5183 % \begin{macrocode}
5184 \cs_set:Npe \@currentlabel { \p@equation \g_tmpa_tl }
5185 % \end{macrocode}
5186 % Then, an action done by \pkg{hyperref} in its redefinition of
5187 % |\refstepcounter|.
5188 % \begin{macrocode}
5189 \IfPackageLoadedT { hyperref }
5190 {
5191 % the following line is probably pointless (2022/05/16)
5192 % \str_set:Nn \This@name { equation }
5193 \hyper@refstepcounter { equation }
5194 }
5195 % \end{macrocode}
5196 % Then, an action done by \pkg{cleveref} in its redefinition of
5197 % |\refstepcounter|. The package \pkg{cleveref} creates in the |aux| file a
5198 % command |\cref@currentlabel| similar to |\@currentlabel| but with more
5199 % informations.
5200 % \begin{macrocode}
5201 \IfPackageLoadedT { cleveref }
5202 {
5203 \cref@constructprefix { equation } \cref@result
5204 \protected@edef \cref@currentlabel
5205 {
5206 [
5207 \cs_if_exist:NTF \cref@equation@alias
5208 \cref@equation@alias
5209 { equation }
5210 ]
5211 [ \arabic { equation } ] [ \cref@result ]
5212 \p@equation \g_tmpa_tl
5213 }
5214 }
5215 % \end{macrocode}
5216 % Now, we can issue the command |\label| (some packages may have redefined
5217 % |\label|, for example \pkg{typedref}) for each item in the sequence of the
5218 % labels (it's possible with \pkg{witharrows} to put several labels to the same
5219 % line and that's why the labels are in the sequence |\l_@@_labels_seq|).
5220 % \begin{macrocode}
5221 \seq_map_function:NN \l_@@_labels_seq \@@_old_label
5222 }
5223 % \end{macrocode}
5224 % We save the booleans |\l_@@_tag_star_bool| and |\l_@@_qedhere_bool| because
5225 % they will be used in the \emph{next} cell (after the |&|). We recall that the
5226 % cells of a |\halign| are TeX groups.
5227 % \begin{macrocode}
5228 \@@_save:N \l_@@_tag_star_bool
5229 \@@_save:N \l_@@_qedhere_bool
5230 \bool_if:NT \l_@@_tag_next_line_bool
5231 {
5232 \openup -\jot
5233 \bool_set_false:N \l_@@_tag_next_line_bool
5234 \notag \\ &
5235 }
5236 &
5237 \@@_restore:N \l_@@_tag_star_bool
5238 \@@_restore:N \l_@@_qedhere_bool
5239 \bool_if:NT \l_@@_qedhere_bool
5240 { \hbox_overlap_left:n \@@_qedhere_i: }
5241 \cs_set_eq:NN \theequation \g_tmpa_tl
5242 \bool_if:NT \l_@@_tag_star_bool
5243 { \cs_set_eq:NN \tagform@ \prg_do_nothing: }
5244 % \end{macrocode}
5245 % We use |\@eqnnum| (we recall that there are two definitions of |\@eqnnum|, a
5246 % standard definition and another, loaded if the class option |leqno| is used).
5247 % However, of course, the position of the |v|-node is not the same whether the
5248 % option |leqno| is used or not. That's here that we use the flag
5249 % |\c_@@_leqno_bool|.
5250 % \begin{macrocode}
5251 \hbox_overlap_left:n
5252 {
5253 \bool_if:NF \c_@@_leqno_bool
5254 {
5255 \pgfpicture
5256 \pgfrememberpicturepositiononpagetrue
5257 \pgfcoordinate
5258 { wa - \l_@@_prefix_str - \int_use:N \g_@@_line_int - v }
5259 \pgfpointorigin
5260 \endpgfpicture
5261 }
5262 \quad
5263 \@eqnnum
5264 }
5265 \bool_if:NT \c_@@_leqno_bool
5266 {
5267 \pgfpicture
5268 \pgfrememberpicturepositiononpagetrue
5269 \pgfcoordinate
5270 { wa - \l_@@_prefix_str - \int_use:N \g_@@_line_int - v }
5271 \pgfpointorigin
5272 \endpgfpicture
5273 }
5274 }
5275 {
5276 \@@_save:N \l_@@_qedhere_bool
5277 %</LaTeX>
5278 &
5279 %<*LaTeX>
5280 \@@_restore:N \l_@@_qedhere_bool
5281 \bool_if:NT \l_@@_qedhere_bool
5282 { \hbox_overlap_left:n \@@_qedhere_i: }
5283 %</LaTeX>
5284 \pgfpicture
5285 \pgfrememberpicturepositiononpagetrue
5286 \pgfcoordinate
5287 { wa - \l_@@_prefix_str - \int_use:N \g_@@_line_int - v }
5288 \pgfpointorigin
5289 \endpgfpicture
5290 %<*LaTeX>
5291 }
5292 %</LaTeX>
5293 }
5294 \dim_compare:nNnT { #1 } < \c_zero_dim
5295 { \@@_error:n { option~of~cr~negative } }
5296
5297 \cr
5298 \noalign
5299 {
5300 \dim_set:Nn \l_tmpa_dim { \dim_max:nn { #1 } \c_zero_dim }
5301 \skip_vertical:N \l_tmpa_dim
5302 \skip_vertical:N \l_@@_interline_skip
5303 \scan_stop:
5304 }
5305 }
5306 % \end{macrocode}
5307 % According to the documentation of L3, the previous addition in
5308 % ``|#1 + \l_@@_interline_skip|'' is really an addition of skips (=glues).
5309 %
5310 %
5311 % The following command will be used when, after a |\\| (and its optional
5312 % arguments) there is a |\end|. You want to known if this is the end of the
5313 % environment |{WithArrows}| (or |{DispWithArrows}|, etc.) because, in this
5314 % case, we will explain that the environment must not be ended by |\\|. If it is
5315 % not the case, that means it's a classical situation of LaTeX environments not
5316 % correctly imbricated and there will be a LaTeX error.
5317 % \begin{macrocode}
5318 %<*LaTeX>
5319 \cs_new_protected:Npn \@@_analyze_end:Nn #1 #2
5320 {
5321 \str_if_eq:onT \l_@@_type_env_str { #2 }
5322 {
5323 \@@_error:n { newline~at~the~end~of~env }
5324 \group_begin:
5325 \globaldefs = 1
5326 \@@_msg_redirect_name:nn { newline~at~the~end~of~env } { none }
5327 \group_end:
5328 }
5329 % \end{macrocode}
5330 % We reput in the stream the |\end{...}| we have extracted.
5331 % \begin{macrocode}
5332 \end { #2 }
5333 }
5334 %</LaTeX>
5335 % \end{macrocode}
5336 %
5337 % \bigskip
5338 % \subsubsection{The environment \{DispWithArrows\}}
5339 %
5340 % For the environment |{DispWithArrows}|, the general form of the construction
5341 % is of the type:
5342 %
5343 % |\[\vtop{\halign to \displaywidth {...}}\]|
5344 %
5345 % The purpose of the |\vtop| is to have an environment unbreakable.
5346 %
5347 % However, if we are juste after an item of a LaTeX list or at the beginning of
5348 % a |{minipage}|, the construction is slightly different:
5349 %
5350 % |\[\vtop{\halign to \linewidth {...}}\]|
5351 %
5352 %
5353 % \bigskip
5354 % The boolean |\l_@@_in_label_or_minipage_bool| will be raised if we are just
5355 % after a |\item| of a list of LaTeX or at the beginning of a |{minipage}|.
5356 % \begin{macrocode}
5357 %<*LaTeX>
5358 \bool_new:N \l_@@_in_label_or_minipage_bool
5359 %</LaTeX>
5360 % \end{macrocode}
5361 %
5362 %
5363 % \begin{macrocode}
5364 %<*LaTeX>
5365 \NewDocumentEnvironment { DispWithArrows } { ! d < > ! O { } }
5366 %</LaTeX>
5367 %<*plain-TeX>
5368 \cs_new_protected:Npn \DispWithArrows
5369 {
5370 \group_begin:
5371 \peek_meaning:NTF <
5372 { \DispWithArrows_i }
5373 { \DispWithArrows_i < \c_novalue_tl > }
5374 }
5375 \cs_new_protected:Npn \DispWithArrows_i < #1 >
5376 {
5377 \peek_meaning:NTF [
5378 { \DispWithArrows_ii < #1 > }
5379 { \DispWithArrows_ii < #1 > [ ] }
5380 }
5381 \cs_new_protected:Npn \DispWithArrows_ii < #1 > [ #2 ]
5382 %</plain-TeX>
5383 {
5384 \bool_set_true:N \l_@@_in_DispWithArrows_bool
5385 %<*plain-TeX>
5386 \str_clear_new:N \l_@@_type_env_str
5387 \str_set:Nn \l_@@_type_env_str { DispWithArrows }
5388 %</plain-TeX>
5389 % \end{macrocode}
5390 %
5391 % \medskip
5392 % Since the version 1.16 of \pkg{witharrows}, no space is added between an
5393 % |\item| of a LaTeX list and an environment |{DispWithArrows}| except with the
5394 % option |standard-behaviour-with-items| stored in the boolean
5395 % |\l_@@_sbwi_bool|. We have to know if we are just after an |\item| and this
5396 % information will be stored in |\l_@@_in_label_or_minipage_bool|. We have to do
5397 % this test quicky after the beginning of the environment (in particular,
5398 % because it must be done before the execution of the
5399 % |code-before|\footnote{The |code-before| is not meant to contains typesetting
5400 % material. However, it may contain, for example, a |{tikzpicture}| with options
5401 % |overlay| and |remember picture| in order to draw nodes \emph{under} some
5402 % elements of the environment |{DispWithArrows}|.}).
5403 % \begin{macrocode}
5404 %<*LaTeX>
5405 \bool_if:NF \l_@@_sbwi_bool
5406 {
5407 \legacy_if:nT { @inlabel }
5408 { \bool_set_true:N \l_@@_in_label_or_minipage_bool }
5409 \legacy_if:nT { @minipage }
5410 { \bool_set_true:N \l_@@_in_label_or_minipage_bool }
5411 }
5412 %</LaTeX>
5413 % \end{macrocode}
5414 %
5415 % \medskip
5416 % If \pkg{mathtools} has been loaded with the option |showonlyrefs|, we disable
5417 % the code of \pkg{mathtools} for the option |showonlyrefs| with the command
5418 % |\MT_showonlyrefs_false:| (it will be reactivated at the end of the
5419 % environment).
5420 % \begin{macrocode}
5421 %<*LaTeX>
5422 \IfPackageLoadedT { mathtools }
5423 {
5424 \MH_if_boolean:nT { show_only_refs }
5425 {
5426 \MT_showonlyrefs_false:
5427 % \end{macrocode}
5428 % However, we have to re-raise the flag |{show_only_refs}| of \pkg{mhsetup}
5429 % because it has been switched off by |\MT_showonlyrefs_false:| and we will use
5430 % it in the code of the new version of |\label|.
5431 % \begin{macrocode}
5432 \MH_set_boolean_T:n { show_only_refs }
5433 }
5434 }
5435 % \end{macrocode}
5436 %
5437 % An action done by \pkg{typedref} in its redefinition of |\refstepcounter|. The
5438 % command |\sr@name| is a prefix added to the name of the label by the
5439 % redefinition of |\label| done by \pkg{typedref}.
5440 % \begin{macrocode}
5441 \IfPackageLoadedT { typedref }
5442 { \str_set:Nn \sr@name { equation } }
5443 % \end{macrocode}
5444 %
5445 % The command |\intertext@| is a command of \pkg{amsmath} which loads the
5446 % definition of |\intertext|.
5447 % \begin{macrocode}
5448 \IfPackageLoadedT { amsmath } { \intertext@ }
5449 %</LaTeX>
5450 \tl_if_novalue:oF { #1 }
5451 { \cs_set_nopar:Npn \l_@@_left_brace_tl { #1 } }
5452 \@@_pre_halign:n { #2 }
5453 % \end{macrocode}
5454 %
5455 % If |subequations| is used, we encapsulate the environment in an
5456 % environment |{subequations}| of \pkg{amsmath}.
5457 % \begin{macrocode}
5458 %<*LaTeX>
5459 \bool_if:NT \l_@@_subequations_bool { \begin { subequations } }
5460 %</LaTeX>
5461 % \end{macrocode}
5462 %
5463 % \begin{macrocode}
5464 \tl_if_eq:NNF \l_@@_left_brace_tl \c_novalue_tl
5465 {
5466 % \end{macrocode}
5467 % We compute the value of the width of the left delimiter.
5468 % \begin{macrocode}
5469 \hbox_set:Nn \l_tmpa_box
5470 {
5471 % \end{macrocode}
5472 % Even if the default value of |\nulldelimiterspace| is 1.2~pt, we take it into
5473 % account.
5474 % \begin{macrocode}
5475 \group_begin:
5476 \dim_zero:N \nulldelimiterspace
5477 \c_math_toggle_token
5478 \left \l_@@_replace_left_brace_by_tl \vcenter to 1 cm { } \right.
5479 \c_math_toggle_token
5480 \group_end:
5481 }
5482 \dim_zero_new:N \l_@@_delim_wd_dim
5483 \dim_set:Nn \l_@@_delim_wd_dim { \box_wd:N \l_tmpa_box }
5484 \box_clear_new:N \l_@@_left_brace_box
5485 \hbox_set:Nn \l_@@_left_brace_box
5486 {
5487 \group_begin:
5488 \cs_set_eq:NN \label \@@_old_label
5489 \c_math_toggle_token
5490 \bool_if:NT \l_@@_displaystyle_bool \displaystyle
5491 \l_@@_left_brace_tl
5492 { }
5493 \c_math_toggle_token
5494 \group_end:
5495 }
5496 }
5497 % \end{macrocode}
5498 %
5499 % \bigskip
5500 % The token list |\l_@@_tag_tl| will contain the argument of the command |\tag|.
5501 % \begin{macrocode}
5502 %<*LaTeX>
5503 \tl_clear_new:N \l_@@_tag_tl
5504 % \end{macrocode}
5505 %
5506 % \bigskip
5507 % \begin{macrocode}
5508 \bool_set_false:N \l_@@_qedhere_bool
5509 % \end{macrocode}
5510 %
5511 % \bigskip
5512 % The boolean |\l_@@_tag_star_bool| will be raised if the user uses the command
5513 % |\tag| with a star.
5514 % \begin{macrocode}
5515 \bool_set_false:N \l_@@_tag_star_bool
5516 %</LaTeX>
5517 % \end{macrocode}
5518 %
5519 % \begin{macrocode}
5520 \if_mode_math:
5521 \@@_fatal:n { DispWithArrows~in~math~mode }
5522 \fi:
5523 % \end{macrocode}
5524 %
5525 % \bigskip
5526 % The construction is not exactly the same whether we are just after an |\item|
5527 % of a LaTeX list or not. We know if we are after an |\item| thanks to the
5528 % boolean |\l_@@_in_label_or_minipage_bool|.
5529 % \begin{macrocode}
5530 %<*plain-TeX>
5531 \dim_zero_new:N \linewidth
5532 \dim_set_eq:NN \linewidth \displaywidth
5533 %</plain-TeX>
5534 %<*LaTeX>
5535 \bool_if:NTF \l_@@_in_label_or_minipage_bool
5536 {
5537 \noindent
5538 \c_math_toggle_token
5539 }
5540 {
5541 %</LaTeX>
5542 % \end{macrocode}
5543 % We don't use |\[| of LaTeX because some extensions, like \pkg{autonum}, do a
5544 % redefinition of |\[|. However, we put the following lines which are in the
5545 % definition of |\[| even though they are in case of misuse.
5546 % \begin{macrocode}
5547 \if_mode_vertical:
5548 \nointerlineskip
5549 \hbox_to_wd:nn { .6 \linewidth } { }
5550 \fi:
5551 \c_math_toggle_token \c_math_toggle_token
5552 %<*LaTeX>
5553 }
5554 %</LaTeX>
5555 % \end{macrocode}
5556 %
5557 % \begin{macrocode}
5558 \dim_zero_new:N \l_@@_linewidth_dim
5559 %<*LaTeX>
5560 \bool_if:NTF \l_@@_in_label_or_minipage_bool
5561 { \dim_set_eq:NN \l_@@_linewidth_dim \linewidth }
5562 { \dim_set_eq:NN \l_@@_linewidth_dim \displaywidth }
5563 %</LaTeX>
5564 %<*plain-TeX>
5565 \dim_set_eq:NN \l_@@_linewidth_dim \displaywidth
5566 %</plain-TeX>
5567 % \end{macrocode}
5568 %
5569 %
5570 % \begin{macrocode}
5571 \box_clear_new:N \l_@@_halign_box
5572 \setbox \l_@@_halign_box \vtop \bgroup
5573 \tabskip =
5574 \bool_if:NTF \l_@@_fleqn_bool
5575 \c_zero_skip
5576 { 0 pt plus 1000 pt minus 1000 pt }
5577 % \end{macrocode}
5578 %
5579 %
5580 % \bigskip
5581 % The command |\spread@equation| is the command used by \pkg{amsmath} in the
5582 % beginning of an alignment to fix the interline. When used, it becomes no-op.
5583 % However, it's possible to use \pkg{witharrows} without \pkg{amsmath} since we
5584 % have redefined |\spread@equation| (if it is not defined yet).
5585 % \begin{macrocode}
5586 \spread@equation
5587 \@@_construct_halign:
5588 \tabskip = 0 pt plus 1000 pt minus 1000 pt
5589 &
5590 % \end{macrocode}
5591 %
5592 % If the user tries to use more columns than the length of the format, we have to
5593 % raise an error. However, the error won't be in the next column which is the
5594 % columns for the labels of the equations. The error will be after... and it
5595 % must be after. That means that we must not have an error in the next column
5596 % simply because we are not in math mode. That's why this column, even if it is
5597 % for the labels, is in math mode.
5598 % \begin{macrocode}
5599 $ ## $
5600 \tabskip = \c_zero_skip
5601 &&
5602 \@@_fatal:n { Too~much~columns~in~DispWithArrows }
5603 \bool_if:nT \c_false_bool { ## }
5604 \cr
5605 }
5606 % \end{macrocode}
5607 %
5608 % \bigskip
5609 % We begin the second part of the environment |{DispWithArrows}|.
5610 % \begin{macrocode}
5611 %<*plain-TeX>
5612 \cs_new_protected:Npn \endDispWithArrows
5613 %</plain-TeX>
5614 {
5615 %<*LaTeX>
5616 \clist_if_in:NnT \l_@@_tags_clist { last }
5617 { \clist_set:Nn \l_@@_tags_clist { all } }
5618 %</LaTeX>
5619 \\
5620 % \end{macrocode}
5621 % The following |\egroup| is for the |\halign|.
5622 % \begin{macrocode}
5623 \egroup
5624 \unskip \unpenalty \unskip \unpenalty
5625 \box_set_to_last:N \l_tmpa_box
5626 \nointerlineskip
5627 \box_use:N \l_tmpa_box
5628 \dim_gzero_new:N \g_@@_alignment_dim
5629 \dim_gset:Nn \g_@@_alignment_dim { \box_wd:N \l_tmpa_box }
5630 \box_clear_new:N \l_@@_new_box
5631 \hbox_set:Nn \l_@@_new_box { \hbox_unpack_drop:N \l_tmpa_box }
5632 \dim_compare:nNnT
5633 { \box_wd:N \l_@@_new_box } < \g_@@_alignment_dim
5634 { \dim_gset:Nn \g_@@_alignment_dim { \box_wd:N \l_@@_new_box } }
5635 % \end{macrocode}
5636 % The |\egroup| is for the box |\l_@@_halign_box|.
5637 % \begin{macrocode}
5638 \egroup
5639 % \end{macrocode}
5640 %
5641 % \begin{macrocode}
5642 \tl_if_eq:NNTF \l_@@_left_brace_tl \c_novalue_tl
5643 { \box_use_drop:N \l_@@_halign_box }
5644 {
5645 \hbox_to_wd:nn \l_@@_linewidth_dim
5646 {
5647 \bool_if:NTF \l_@@_fleqn_bool
5648 { \skip_horizontal:N \l_@@_mathindent_skip }
5649 \hfil
5650 \hbox_to_wd:nn \g_@@_alignment_dim
5651 {
5652 \box_use_drop:N \l_@@_left_brace_box
5653 % \end{macrocode}
5654 % Here, you should use |\box_ht_plus_dp:N| when TeXLive 2021 will be available
5655 % on Overleaf.
5656 % \begin{macrocode}
5657 \dim_set:Nn \l_tmpa_dim
5658 {
5659 \box_ht:N \l_@@_halign_box
5660 + \box_dp:N \l_@@_halign_box
5661 }
5662 \group_begin:
5663 \dim_zero:N \nulldelimiterspace
5664 \c_math_toggle_token
5665 \left \l_@@_replace_left_brace_by_tl
5666 \vcenter to \l_tmpa_dim { \vfil }
5667 \right.
5668 \c_math_toggle_token
5669 \group_end:
5670 \hfil
5671 }
5672 \hfil
5673 }
5674 \skip_horizontal:N -\l_@@_linewidth_dim
5675 \vcenter { \box_use_drop:N \l_@@_halign_box }
5676 }
5677 % \end{macrocode}
5678 %
5679 % We compute the dimension |\g_@@_right_x_dim|. As a first approximation,
5680 % |\g_@@_right_x_dim| is the $x$-value of the right side of the current
5681 % composition box. In fact, we must take into account the potential labels of
5682 % the equations. That's why we compute |\g_@@_right_x_dim| with the |v|-nodes of
5683 % each row specifically built in this goal. |\g_@@_right_x_dim| is the minimal
5684 % value of the $x$-value of these nodes.
5685 % \begin{macrocode}
5686 \dim_gzero_new:N \g_@@_right_x_dim
5687 \dim_gset_eq:NN \g_@@_right_x_dim \c_max_dim
5688 \pgfpicture
5689 \pgfrememberpicturepositiononpagetrue
5690 \int_step_variable:nNn \g_@@_line_int \l_tmpa_int
5691 {
5692 \cs_if_free:cTF
5693 { pgf @ sh @ ns @ wa - \l_@@_prefix_str - \l_tmpa_int - v }
5694 { \@@_fatal:n { Inexistent~v-node } }
5695 {
5696 \pgfpointanchor
5697 { wa - \l_@@_prefix_str - \l_tmpa_int - v }
5698 { center }
5699 \dim_compare:nNnT \pgf@x < \g_@@_right_x_dim
5700 { \dim_gset_eq:NN \g_@@_right_x_dim \pgf@x }
5701 }
5702 }
5703 \endpgfpicture
5704 % \end{macrocode}
5705 %
5706 %
5707 % \bigskip
5708 % The code in |\@@_post_halign:| is common to |{WithArrows}| and
5709 % |{DispWithArrows}|.
5710 % \begin{macrocode}
5711 \@@_post_halign:
5712 % \end{macrocode}
5713 % If \pkg{mathtools} has been loaded with the option |showonlyrefs|, we
5714 % reactivate the code of \pkg{mathtools} for the option |showonlyrefs| with the
5715 % command |\MT_showonlyrefs_true:| (it has been deactivated in the beginning of
5716 % the environment).
5717 % \begin{macrocode}
5718 %<*LaTeX>
5719 \IfPackageLoadedT { mathtools }
5720 { \MH_if_boolean:nT { show_only_refs } \MT_showonlyrefs_true: }
5721 \bool_if:NTF \l_@@_in_label_or_minipage_bool
5722 {
5723 \c_math_toggle_token
5724 \skip_vertical:N \belowdisplayskip
5725 }
5726 { \c_math_toggle_token \c_math_toggle_token }
5727 %</LaTeX>
5728 %<*plain-TeX>
5729 \c_math_toggle_token \c_math_toggle_token
5730 %</plain-TeX>
5731 % \end{macrocode}
5732 %
5733 % \begin{macrocode}
5734 %<*LaTeX>
5735 \bool_if:NT \l_@@_subequations_bool { \end { subequations } }
5736 % \end{macrocode}
5737 %
5738 % \bigskip
5739 % If the option |footnote| or the option |footnotehyper| is used, then we
5740 % extract the footnotes with an environment |{savenotes}| (of the package
5741 % \pkg{footnote} or the package \pkg{footnotehyper}).
5742 % \begin{macrocode}
5743 \bool_if:NT \c_@@_footnote_bool { \end { savenotes } }
5744 %</LaTeX>
5745 %<*plain-TeX>
5746 \group_end:
5747 %</plain-TeX>
5748 %<*LaTeX>
5749 \ignorespacesafterend
5750 %</LaTeX>
5751 }
5752 % \end{macrocode}
5753 %
5754 % \bigskip
5755 % With the environment |{DispWithArrows*}|, the equations are not numbered. We
5756 % don't put |\begin{DispWithArrows}| and |\end{DispWithArrows}| because there is
5757 % a |\@currenvir| in some error messages.
5758 % \begin{macrocode}
5759 %<*LaTeX>
5760 \NewDocumentEnvironment { DispWithArrows* } { }
5761 {
5762 \WithArrowsOptions { notag }
5763 \DispWithArrows
5764 }
5765 \endDispWithArrows
5766 %</LaTeX>
5767 % \end{macrocode}
5768 %
5769 %
5770 % \bigskip
5771 % \subsection{The commands \textbackslash tag, \textbackslash notag,
5772 % \textbackslash label, \textbackslash tagnextline and \textbackslash qedhere for
5773 % \{DispWithArrows\}}
5774 %
5775 % Some commands are allowed only in the last column of the environment
5776 % |{DispWithArrows}|. We write a command |\@@_if_in_last_col_of_disp:Nn| to
5777 % execute this command only if we are in the last column. If we are in
5778 % another column, an error is raised. The first argument of
5779 % |\@@_if_in_last_col_of_disp:Nn| is the name of the command used in the error
5780 % message and the second is the code to execute.
5781 % \begin{macrocode}
5782 \cs_new_protected:Npn \@@_if_in_last_col_of_disp:Nn #1 #2
5783 {
5784 \bool_if:NTF \l_@@_in_WithArrows_bool
5785 { \@@_error:nn { Not~allowed~in~WithArrows } { #1 } }
5786 {
5787 \int_compare:nNnTF \g_@@_col_int < \l_@@_nb_cols_int
5788 { \@@_error:nn { Not~allowed~in~DispWithArrows } { #1 } }
5789 { #2 }
5790 }
5791 }
5792 % \end{macrocode}
5793 %
5794 % \bigskip
5795 % The command |\@@_notag:| will be linked to the command |\notag| in
5796 % the environments |{WithArrows}| and |{DispWithArrows}|.
5797 % \begin{macrocode}
5798 %<*LaTeX>
5799 \cs_new_protected:Npn \@@_notag:
5800 { \@@_if_in_last_col_of_disp:Nn \notag { \clist_clear:N \l_@@_tags_clist } }
5801 % \end{macrocode}
5802 %
5803 % \bigskip
5804 % The command |\@@_nonumber:| will be linked to the command |\nonumber|
5805 % in the environments |{WithArrows}| and |{DispWithArrows}|.
5806 % \begin{macrocode}
5807 \cs_new_protected:Npn \@@_nonumber:
5808 { \@@_if_in_last_col_of_disp:Nn \nonumber { \clist_clear:N \l_@@_tags_clist } }
5809 % \end{macrocode}
5810 %
5811 % \bigskip
5812 % The command |\@@_tag| will be linked to |\tag| in |{WithArrows}| and
5813 % |{DispWithArrows}|. We do the definition with |\NewDocumentCommand| because
5814 % this command has a starred version.
5815 % \begin{macrocode}
5816 \NewDocumentCommand \@@_tag { s m }
5817 {
5818 \@@_if_in_last_col_of_disp:Nn \tag
5819 {
5820 \tl_if_empty:NF \l_@@_tag_tl
5821 { \@@_error:nn { Multiple~tags } { #2 } }
5822 \clist_set:Nn \l_@@_tags_clist { all }
5823 \IfPackageLoadedT { mathtools }
5824 {
5825 \MH_if_boolean:nT { show_only_refs }
5826 {
5827 \MH_if_boolean:nF { show_manual_tags }
5828 { \clist_clear:N \l_@@_tags_clist }
5829 }
5830 }
5831 \tl_set:Nn \l_@@_tag_tl { #2 }
5832 \bool_set:Nn \l_@@_tag_star_bool { #1 }
5833 % \end{macrocode}
5834 % The starred version |\tag*| can't be used if \pkg{amsmath} has not been loaded
5835 % because this version does the job by deactivating the command |\tagform@|
5836 % inserted by \pkg{amsmath} in the (two versions of the) command
5837 % |\@eqnnum|.\footnote{There are two versions of |@eqnnum|, a standard version
5838 % and a version for the option |leqno|.}
5839 % \begin{macrocode}
5840 \bool_if:nT { #1 }
5841 {
5842 \IfPackageLoadedF { amsmath }
5843 { \@@_error:n { tag*~without~amsmath } }
5844 }
5845 }
5846 }
5847 % \end{macrocode}
5848 %
5849 % \bigskip
5850 % The command |\@@_label:n| will be linked to |\label| in the environments
5851 % |{WithArrows}| and |{DispWithArrows}|. In these environments, it's possible to
5852 % put several labels for the same line (it's not possible in the environments of
5853 % \pkg{amsmath}). That's why we store the differents labels of a same line in a
5854 % sequence |\l_@@_labels_seq|.
5855 % \begin{macrocode}
5856 \cs_new_protected:Npn \@@_label:n #1
5857 {
5858 \@@_if_in_last_col_of_disp:Nn \label
5859 {
5860 \seq_if_empty:NF \l_@@_labels_seq
5861 {
5862 \IfPackageLoadedTF { cleveref }
5863 { \@@_error:n { Multiple~labels~with~cleveref } }
5864 { \@@_error:n { Multiple~labels } }
5865 }
5866 \seq_put_right:Nn \l_@@_labels_seq { #1 }
5867 \IfPackageLoadedT { mathtools }
5868 {
5869 \MH_if_boolean:nT { show_only_refs }
5870 {
5871 \cs_if_exist:cTF { MT_r_#1 }
5872 { \clist_set:Nn \l_@@_tags_clist { all } }
5873 { \clist_clear:N \l_@@_tags_clist }
5874 }
5875 }
5876 \IfPackageLoadedT { autonum }
5877 {
5878 \cs_if_exist:cTF { autonum@#1Referenced }
5879 { \clist_set:Nn \l_@@_tags_clist { all } }
5880 { \clist_clear:N \l_@@_tags_clist }
5881 }
5882 }
5883 }
5884 % \end{macrocode}
5885 %
5886 % \bigskip
5887 % The command |\@@_tagnextline:| will be linked to |\tagnextline| in
5888 % |{DispWithArrows}|.
5889 % \begin{macrocode}
5890 \cs_new_protected:Npn \@@_tagnextline:
5891 {
5892 \@@_if_in_last_col_of_disp:Nn \tagnextline
5893 { \bool_set_true:N \l_@@_tag_next_line_bool }
5894 }
5895 % \end{macrocode}
5896 %
5897 %
5898 % \bigskip
5899 % The environments |{DispWithArrows}| and |{DispWithArrows*}| are compliant with
5900 % the command |\qedhere| of \pkg{amsthm}. However, this compatibility requires a
5901 % special version of |\qedhere|.
5902 %
5903 % This special version is called |\@@_qedhere:| and will be linked with
5904 % |\qedhere| in the last column of the environment |{DispWithArrows}| (only if
5905 % the package \pkg{amsthm} has been loaded). |\@@_qedhere:| raises the boolean
5906 % |\l_@@_qedhere_bool|.
5907 % \begin{macrocode}
5908 \cs_new_protected:Npn \@@_qedhere: { \bool_set_true:N \l_@@_qedhere_bool }
5909 \cs_new_protected:Npn \@@_set_qedhere: { \cs_set_eq:NN \qedhere \@@_qedhere: }
5910 % \end{macrocode}
5911 %
5912 % In the last column of the |\halign| of |{DispWithArrows}| (column of the
5913 % labels, that is to say the numbers of the equations), a command
5914 % |\@@_qedhere_i:| will be issued if the flag |\l_@@_qedhere_bool| has been
5915 % raised. The code of this command is an adaptation of the code of |\qedhere| in
5916 % \pkg{amsthm}.
5917 % \begin{macrocode}
5918 \cs_new_protected:Npn \@@_qedhere_i:
5919 {
5920 \group_begin:
5921 \cs_set_eq:NN \qed \qedsymbol
5922 % \end{macrocode}
5923 % The line |\cs_set_eq:NN \qed@elt \setQED@elt| is a preparation for an action
5924 % on the \textsc{qed} stack. Despite its form, the instruction |\QED@stack|
5925 % executes an operation on the stack. This operation prints the \textsc{qed}
5926 % symbol and nullify the top of the stack.
5927 % \begin{macrocode}
5928 \cs_set_eq:NN \qed@elt \setQED@elt
5929 \QED@stack \relax \relax
5930 \group_end:
5931 }
5932 %</LaTeX>
5933 % \end{macrocode}
5934 %
5935 %
5936 %
5937 %
5938 % \subsection{We draw the arrows}
5939 %
5940 % \bigskip
5941 % The arrows are divided in groups. There is two reasons for this division.
5942 % \begin{itemize}[beginpenalty=10000]
5943 % \item If the option |group| or the option |groups| is used, all the arrows of
5944 % a group are drawn on a same vertical at an abscissa of |\l_@@_x_dim|.
5945 % \item For aesthetic reasons, the starting point of all the starting arrows of
5946 % a group is raised upwards by the value |\l_@@_start_adjust_dim|. Idem for the
5947 % ending arrows.
5948 % \end{itemize}
5949 %
5950 % \medskip
5951 % If the option |group| is used (|\l_@@_pos_arrow_int| = 7), we scan the arrows
5952 % twice: in the first step we only compute the value of |\l_@@_x_dim| for the
5953 % whole group, and, in the second step (|\l_@@_pos_arrow_int| is set to 8), we
5954 % divide the arrows in groups (for the vertical adjustement) and we actually
5955 % draw the arrows.
5956 % \begin{macrocode}
5957 \cs_new_protected:Npn \@@_scan_arrows:
5958 {
5959 \group_begin:
5960 \int_compare:nNnT \l_@@_pos_arrow_int = 7
5961 {
5962 \@@_scan_arrows_i:
5963 \int_set:Nn \l_@@_pos_arrow_int 8
5964 }
5965 \@@_scan_arrows_i:
5966 \group_end:
5967 }
5968 % \end{macrocode}
5969 %
5970 % \bigskip
5971 % \begin{macrocode}
5972 \cs_new_protected:Npn \@@_scan_arrows_i:
5973 {
5974 % \end{macrocode}
5975 %
5976 % \bigskip
5977 % |\l_@@_first_arrow_of_group_int| will be the first arrow of the current group.
5978 %
5979 % |\l_@@_first_line_of_group_int| will be the first line involved in the group
5980 % of arrows (equal to the initial line of the first arrow of the group because
5981 % the option |jump| is always positive).
5982 %
5983 % |\l_@@_first_arrows_seq| will be the list of the arrows of the group starting
5984 % at the first line of the group (we may have several arrows starting from the
5985 % same line). We have to know all these arrows because of the adjustement by
5986 % |\l_@@_start_adjust_dim|.
5987 %
5988 % |\l_@@_last_line_of_group_int| will be the last line involved in the group
5989 % (impossible to guess in advance).
5990 %
5991 % |\l_@@_last_arrows_seq| will be the list of all the arrows of the group
5992 % ending at the last line of the group (impossible to guess in advance).
5993 % \begin{macrocode}
5994 \int_zero_new:N \l_@@_first_arrow_of_group_int
5995 \int_zero_new:N \l_@@_first_line_of_group_int
5996 \int_zero_new:N \l_@@_last_line_of_group_int
5997 \seq_clear_new:N \l_@@_first_arrows_seq
5998 \seq_clear_new:N \l_@@_last_arrows_seq
5999 % \end{macrocode}
6000 %
6001 % \medskip
6002 % The boolean |\l_@@_new_group_bool| is a switch that we will use to indicate
6003 % that a group is finished (and the lines of that group have to be drawn). This
6004 % boolean is not directly connected to the option |new-group| of an individual
6005 % arrow.
6006 % \begin{macrocode}
6007 \bool_set_true:N \l_@@_new_group_bool
6008 % \end{macrocode}
6009 %
6010 % \bigskip
6011 % We begin a loop over all the arrows of the environment. Inside this loop, if a
6012 % group is finished, we will draw the arrows of that group.
6013 % \begin{macrocode}
6014 \int_set:Nn \l_@@_arrow_int 1
6015 \int_until_do:nNnn \l_@@_arrow_int > \g_@@_arrow_int
6016 {
6017 % \end{macrocode}
6018 %
6019 % \bigskip
6020 % We extract from the property list of the current arrow the fields ``initial'',
6021 % ``final'', ``status'' and ``input-line''. For the two former, we have to do
6022 % conversions to integers.
6023 % \begin{macrocode}
6024 \prop_get:cnN
6025 { g_@@_arrow _ \l_@@_prefix_str _ \int_use:N \l_@@_arrow_int _ prop }
6026 { initial } \l_tmpa_tl
6027 \int_set:Nn \l_@@_initial_int \l_tmpa_tl
6028 \prop_get:cnN
6029 { g_@@_arrow _ \l_@@_prefix_str _ \int_use:N \l_@@_arrow_int _ prop }
6030 { final } \l_tmpa_tl
6031 \int_set:Nn \l_@@_final_int \l_tmpa_tl
6032 \prop_get:cnN
6033 { g_@@_arrow _ \l_@@_prefix_str _ \int_use:N \l_@@_arrow_int _ prop }
6034 { status } \l_@@_status_arrow_str
6035 \prop_get:cnN
6036 { g_@@_arrow _ \l_@@_prefix_str _ \int_use:N \l_@@_arrow_int _ prop }
6037 { input-line } \l_@@_input_line_str
6038 % \end{macrocode}
6039 %
6040 %
6041 % \bigskip
6042 % We recall that, after the construction of the |\halign|, |\g_@@_line_int| is
6043 % the total number of lines of the environment. Therefore, the conditionnal
6044 % |\l_@@_final_int > \g_@@_line_int| tests whether an arrow arrives after the
6045 % last line of the environment. In this case, we raise an error (except in the
6046 % second step of treatment for the option |group|). The arrow will be completely
6047 % ignored, even for the computation of |\l_@@_x_dim|.
6048 % \begin{macrocode}
6049 \int_compare:nNnTF \l_@@_final_int > \g_@@_line_int
6050 {
6051 \int_compare:nNnF \l_@@_pos_arrow_int = 8
6052 { \@@_error:n { Too~few~lines~for~an~arrow } }
6053 }
6054 \@@_treat_an_arrow_in_scan:
6055 % \end{macrocode}
6056 %
6057 % \bigskip
6058 % Incrementation of the index of the loop (and end of the loop).
6059 % \begin{macrocode}
6060 \int_incr:N \l_@@_arrow_int
6061 }
6062 % \end{macrocode}
6063 %
6064 % \bigskip
6065 % After the last arrow of the environment, we have to draw the last group of
6066 % arrows. If we are in option |group| and in the first step of treatment
6067 % (|\l_@@_pos_arrow_int| = 7), we don't draw because, in the first step, we
6068 % don't draw anything. If there is no arrow in the group, we don't draw (this
6069 % situation occurs when all the arrows of the potential group arrive after the
6070 % last line of the environment).
6071 % \begin{macrocode}
6072 \bool_lazy_and:nnT
6073 { ! \int_compare_p:nNn \l_@@_pos_arrow_int = 7 }
6074 { \int_compare_p:nNn \l_@@_first_arrow_of_group_int > \c_zero_int }
6075 { \@@_draw_arrows:nn \l_@@_first_arrow_of_group_int \g_@@_arrow_int }
6076 }
6077 % \end{macrocode}
6078 %
6079 % \bigskip
6080 % The following command is only for the lisibility of the code. It's used only
6081 % once. Its name may be misleading. Indeed, it treats an arrow in the scan but
6082 % it \emph{may} trigger the construction of all arrows of a group if it detects
6083 % that a group has just been completed (with |\@@_draw_arrows:nn|)
6084 % \begin{macrocode}
6085 \cs_new_protected:Npn \@@_treat_an_arrow_in_scan:
6086 {
6087 % \end{macrocode}
6088 % We test whether the previous arrow was in fact the last arrow of a group. In
6089 % this case, we have to draw all the arrows of that group, except if we are with
6090 % the option |group| and in the first step of treatment (|\l_@@_pos_arrow_int| =
6091 % 7).
6092 % \begin{macrocode}
6093 \bool_lazy_and:nnT
6094 { \int_compare_p:nNn \l_@@_arrow_int > 1 }
6095 {
6096 \bool_lazy_or_p:nn
6097 {
6098 \bool_lazy_and_p:nn
6099 {
6100 \int_compare_p:nNn
6101 \l_@@_initial_int > \l_@@_last_line_of_group_int
6102 }
6103 { \bool_not_p:n { \int_compare_p:nNn \l_@@_pos_arrow_int = 7 } }
6104 }
6105 { \str_if_eq_p:on \l_@@_status_arrow_str { new-group } }
6106 }
6107 {
6108 \int_if_zero:nF \l_@@_first_arrow_of_group_int
6109 {
6110 \@@_draw_arrows:nn
6111 \l_@@_first_arrow_of_group_int
6112 { \l_@@_arrow_int - 1 }
6113 }
6114 \bool_set_true:N \l_@@_new_group_bool
6115 }
6116 % \end{macrocode}
6117 %
6118 % \bigskip
6119 % The flag |\l_@@_new_group_bool| indicates if we have to begin a new group of
6120 % arrows. In fact, we have to begin a new group in three circonstancies: if we
6121 % are at the first arrow of the environment (that's why the flag is raised
6122 % before the beginning of the loop), if we have just finished a group (that's
6123 % why the flag is raised in the previous conditionnal, for topological reasons
6124 % or if the previous arrows had the status ``new-group''). At the beginning of a
6125 % group, we have to initialize the following variables: |\l_@@_first_arrow_int|,
6126 % |\l_@@_first_line_of_group_int|, |\l_@@_last_line_of_group|,
6127 % |\l_@@_first_arrows_seq|, |\l_@@_last_arrows_seq|.
6128 %
6129 % \begin{macrocode}
6130 \bool_if:nTF \l_@@_new_group_bool
6131 {
6132 \bool_set_false:N \l_@@_new_group_bool
6133 \int_set_eq:NN \l_@@_first_arrow_of_group_int \l_@@_arrow_int
6134 \int_set_eq:NN \l_@@_first_line_of_group_int \l_@@_initial_int
6135 \int_set_eq:NN \l_@@_last_line_of_group_int \l_@@_final_int
6136 \seq_clear:N \l_@@_first_arrows_seq
6137 \seq_put_left:NV \l_@@_first_arrows_seq \l_@@_arrow_int
6138 \seq_clear:N \l_@@_last_arrows_seq
6139 \seq_put_left:NV \l_@@_last_arrows_seq \l_@@_arrow_int
6140 % \end{macrocode}
6141 %
6142 % If we are in option |group| and in the second step of treatment
6143 % (|\l_@@_pos_arrow_int| = 8), we don't initialize |\l_@@_x_dim| because we want
6144 % to use the same value of |\l_@@_x_dim| (computed during the first step) for
6145 % all the groups.
6146 % \begin{macrocode}
6147 \int_compare:nNnF \l_@@_pos_arrow_int = 8
6148 { \dim_set:Nn \l_@@_x_dim { - \c_max_dim } }
6149 }
6150 % \end{macrocode}
6151 %
6152 % \bigskip
6153 % If we are not at the beginning of a new group.
6154 % \begin{macrocode}
6155 {
6156 % \end{macrocode}
6157 %
6158 % If the arrow is independent, we don't take into account that arrow for the
6159 % detection of the end of the group.
6160 % \begin{macrocode}
6161 \str_if_eq:onF \l_@@_status_arrow_str { independent }
6162 {
6163 % \end{macrocode}
6164 % If the arrow is not independent, the arrow belongs to the current group and we
6165 % have to take it into account in some variables.
6166 % \begin{macrocode}
6167 \int_compare:nNnT \l_@@_initial_int = \l_@@_first_line_of_group_int
6168 { \seq_put_left:NV \l_@@_first_arrows_seq \l_@@_arrow_int }
6169 \int_compare:nNnTF \l_@@_final_int > \l_@@_last_line_of_group_int
6170 {
6171 \int_set_eq:NN \l_@@_last_line_of_group_int \l_@@_final_int
6172 \seq_clear:N \l_@@_last_arrows_seq
6173 \seq_put_left:NV \l_@@_last_arrows_seq \l_@@_arrow_int
6174 }
6175 {
6176 \int_compare:nNnT \l_@@_final_int = \l_@@_last_line_of_group_int
6177 { \seq_put_left:NV \l_@@_last_arrows_seq \l_@@_arrow_int }
6178 }
6179 }
6180 }
6181 % \end{macrocode}
6182 %
6183 % \bigskip
6184 % If the arrow is not independent, we update the current $x$-value (in
6185 % |\l_@@_x_dim|) with the dedicated command |\@@_update_x:nn|. If we are
6186 % in option |group| and in the second step of treatment (|\l_@@_pos_arrow_int| =
6187 % 8), we don't initialize |\l_@@_x_dim| because we want to use the same value of
6188 % |\l_@@_x_dim| (computed during the first step) for all the groups.
6189 % \begin{macrocode}
6190 \str_if_eq:onF \l_@@_status_arrow_str { independent }
6191 {
6192 \int_compare:nNnF \l_@@_pos_arrow_int = 8
6193 { \@@_update_x:nn \l_@@_initial_int \l_@@_final_int }
6194 }
6195 }
6196 % \end{macrocode}
6197 %
6198 %
6199 %
6200 % \bigskip
6201 % The macro |\@@_draw_arrows:nn| draws all the arrows whose numbers are between
6202 % |#1| and |#2|. |#1| and |#2| must be expressions that expands to an integer
6203 % (they are expanded in the beginning of the macro). This macro is nullified by
6204 % the option |no-arrows|.
6205 % \begin{macrocode}
6206 \cs_new_protected:Npn \@@_draw_arrows:nn #1 #2
6207 {
6208 \group_begin:
6209 \int_zero_new:N \l_@@_first_arrow_int
6210 \int_set:Nn \l_@@_first_arrow_int { #1 }
6211 \int_zero_new:N \l_@@_last_arrow_int
6212 \int_set:Nn \l_@@_last_arrow_int { #2 }
6213 % \end{macrocode}
6214 %
6215 % \bigskip
6216 % We begin a loop over the arrows we have to draw. The variable
6217 % |\l_@@_arrow_int| (local in the environment |{WithArrows}|) will be used as
6218 % index for the loop.
6219 % \begin{macrocode}
6220 \int_set:Nn \l_@@_arrow_int \l_@@_first_arrow_int
6221 \int_until_do:nNnn \l_@@_arrow_int > \l_@@_last_arrow_int
6222 {
6223 % \end{macrocode}
6224 %
6225 % \bigskip
6226 % We extract from the property list of the current arrow the fields ``initial''
6227 % and ``final'' and we store these values in |\l_@@_initial_int| and
6228 % |\l_@@_final_int|. However, we have to do a conversion because the components
6229 % of a property list are token lists.
6230 % \begin{macrocode}
6231 \prop_get:cnN
6232 { g_@@_arrow _ \l_@@_prefix_str _ \int_use:N \l_@@_arrow_int _ prop }
6233 { initial } \l_tmpa_tl
6234 \int_set:Nn \l_@@_initial_int \l_tmpa_tl
6235 \prop_get:cnN
6236 { g_@@_arrow _ \l_@@_prefix_str _ \int_use:N \l_@@_arrow_int _ prop }
6237 { final } \l_tmpa_tl
6238 \int_set:Nn \l_@@_final_int \l_tmpa_tl
6239 \prop_get:cnN
6240 { g_@@_arrow _ \l_@@_prefix_str _ \int_use:N \l_@@_arrow_int _ prop }
6241 { status } \l_@@_status_arrow_str
6242 % \end{macrocode}
6243 %
6244 % \bigskip
6245 % If the arrow ends after the last line of the environment, we don't draw the
6246 % arrow (an error has already been raised in |\@@_scan_arrows:|). We recall
6247 % that, after the construction of the |\halign|, |\g_@@_line_int| is the total
6248 % number of lines of the environment).
6249 % \begin{macrocode}
6250 \int_compare:nNnF \l_@@_final_int > \g_@@_line_int
6251 % \end{macrocode}
6252 %
6253 % \bigskip
6254 % If the arrow is of type |over| (key |o|), we don't draw that arrow now (those
6255 % arrows will be drawn after all the other arrows).
6256 % \begin{macrocode}
6257 {
6258 \str_if_eq:onTF \l_@@_status_arrow_str { over }
6259 { \seq_put_right:NV \l_@@_o_arrows_seq \l_@@_arrow_int }
6260 \@@_draw_arrow:
6261 }
6262 \int_incr:N \l_@@_arrow_int
6263 }
6264 \@@_draw_o_arrows_of_the_group:
6265 \group_end:
6266 }
6267 % \end{macrocode}
6268 %
6269 %
6270 % \bigskip
6271 % The first |\group_begin:| is for the options of the arrows (but we remind that
6272 % the options |ll|, |rr|, |rl|, |lr|, |i| and |jump| have already been extracted
6273 % and are not present in the field |options| of the property list of the arrow).
6274 % \begin{macrocode}
6275 \cs_new_protected:Npn \@@_draw_arrow:
6276 {
6277 \group_begin:
6278 % \end{macrocode}
6279 %
6280 % \bigskip
6281 % We process the options of the current arrow.
6282 % \begin{macrocode}
6283 \prop_get:cnN
6284 { g_@@_arrow _\l_@@_prefix_str _ \int_use:N \l_@@_arrow_int _ prop }
6285 { options }
6286 \l_tmpa_tl
6287 \str_clear_new:N \l_@@_previous_key_str
6288 % \end{macrocode}
6289 %
6290 % We will expand the second argument of |\keys_set_known:nn| exactly three
6291 % times. Maybe that an e-expansion would be possible but, in the past, there
6292 % were problems with fragile commands such as |\bfseries| in the option
6293 % |font| of the option |tikz| (it seems that this no longer the case).
6294 % \begin{macrocode}
6295 \exp_args:NNNno \exp_args:NNno \exp_args:Nno
6296 \keys_set_known:nn
6297 { WithArrows / Arrow / SecondPass }
6298 { \l_tmpa_tl , tikz = { xshift = \l_@@_xoffset_dim } }
6299 % \end{macrocode}
6300 %
6301 % We create two booleans to indicate the position of the initial node and final
6302 % node of the arrow in cases of options |rr|, |rl|, |lr| or |ll|:
6303 % \begin{macrocode}
6304 \bool_set_false:N \l_@@_initial_r_bool
6305 \bool_set_false:N \l_@@_final_r_bool
6306 \int_case:nn \l_@@_pos_arrow_int
6307 {
6308 0 { \bool_set_true:N \l_@@_final_r_bool }
6309 2 { \bool_set_true:N \l_@@_initial_r_bool }
6310 3
6311 {
6312 \bool_set_true:N \l_@@_initial_r_bool
6313 \bool_set_true:N \l_@@_final_r_bool
6314 }
6315 }
6316 % \end{macrocode}
6317 %
6318 % \bigskip
6319 % \begin{center}
6320 % \begin{tabular}{l}
6321 % \begin{tabular}{@{}l*8c@{}}
6322 % \toprule
6323 % option & |lr| & |ll| & |rl| & |rr| & |v| & |i| & |groups| & |group| \\
6324 % \midrule
6325 % |\l_@@_pos_arrow_int| & $0$ & $1$ & $2$ & $3$ & $4$ & $5$ & $6$ & $7$ \\
6326 % \bottomrule
6327 % \end{tabular} \\
6328 % \footnotesize The option |v| can be used only in |\Arrow| in |code-after| (see
6329 % below).
6330 % \end{tabular}
6331 % \end{center}
6332 %
6333 % \bigskip
6334 % In case of option |i| at a local or global level (|\l_@@_pos_arrow_int| = 5),
6335 % we have to compute the $x$-value of the arrow (which is vertical). The
6336 % computed $x$-value is stored in |\l_@@_x_dim| (the same variable used when the
6337 % option |group| or the option |groups| is used).
6338 % \begin{macrocode}
6339 \int_compare:nNnT \l_@@_pos_arrow_int = 5
6340 {
6341 \dim_set:Nn \l_@@_x_dim { - \c_max_dim }
6342 \@@_update_x:nn \l_@@_initial_int \l_@@_final_int
6343 }
6344 % \end{macrocode}
6345 %
6346 % \bigskip
6347 % |\l_@@_initial_tl| contains the name of the Tikz node from which the arrow
6348 % starts (in normal cases... because with the option |i|, |group| and |groups|,
6349 % the point will perhaps have another
6350 % $x$-value --- but always the same $y$-value). Idem for |\l_@@_final_tl|.
6351 % \begin{macrocode}
6352 \tl_set:Ne \l_@@_initial_tl
6353 { \int_use:N \l_@@_initial_int - \bool_if:NTF \l_@@_initial_r_bool rl }
6354 \tl_set:Ne \l_@@_final_tl
6355 { \int_use:N \l_@@_final_int - \bool_if:NTF \l_@@_final_r_bool rl }
6356 % \end{macrocode}
6357 %
6358 % \bigskip
6359 % The label of the arrow will be stored in |\l_tmpa_tl|.
6360 % \begin{macrocode}
6361 \prop_get:cnN
6362 { g_@@_arrow _ \l_@@_prefix_str _ \int_use:N \l_@@_arrow_int _ prop }
6363 { label }
6364 \l_tmpa_tl
6365 % \end{macrocode}
6366 %
6367 % \bigskip
6368 % Now, we have to know if the arrow starts at the first line of the group and/or
6369 % ends at the last line of the group. That's the reason why we have stored in
6370 % |\l_@@_first_arrows_seq| the list of all the arrows starting at the
6371 % first line of the group and in |\l_@@_last_arrows_seq| the list of
6372 % all the arrows ending at the last line of the group. We compute these values
6373 % in the booleans |\l_tmpa_bool| and |\l_tmpb_bool|. These computations can't be
6374 % done in the following |{tikzpicture}| because of the command |\seq_if_in:NnTF|
6375 % which is \emph{not} expandable.
6376 % \begin{macrocode}
6377 \seq_if_in:NeTF \l_@@_first_arrows_seq
6378 { \int_use:N \l_@@_arrow_int }
6379 { \bool_set_true:N \l_tmpa_bool }
6380 { \bool_set_false:N \l_tmpa_bool }
6381 \seq_if_in:NeTF \l_@@_last_arrows_seq
6382 { \int_use:N \l_@@_arrow_int }
6383 { \bool_set_true:N \l_tmpb_bool }
6384 { \bool_set_false:N \l_tmpb_bool }
6385 \int_compare:nNnT \l_@@_pos_arrow_int = 5
6386 {
6387 \bool_set_true:N \l_tmpa_bool
6388 \bool_set_true:N \l_tmpb_bool
6389 }
6390 % \end{macrocode}
6391 %
6392 % \bigskip
6393 % We compute and store in |\g_tmpa_tl| and |\g_tmpb_tl| the exact coordinates of
6394 % the extremities of the arrow.
6395 % \begin{itemize}[beginpenalty=10000]
6396 % \item Concerning the
6397 % $x$-values, the abscissa computed in |\l_@@_x_dim| will be used if the option
6398 % of position is |i|, |group| or |groups|.
6399 % \item Concerning the
6400 % $y$-values, an adjustement is done for each arrow starting at the first line
6401 % of the group and each arrow ending at the last line of the group (with the
6402 % values of |\l_@@_start_adjust_dim| and |\l_@@_end_adjust_dim|).
6403 % \end{itemize}
6404 %
6405 % \begin{macrocode}
6406 \dim_gzero_new:N \g_@@_x_initial_dim
6407 \dim_gzero_new:N \g_@@_x_final_dim
6408 \dim_gzero_new:N \g_@@_y_initial_dim
6409 \dim_gzero_new:N \g_@@_y_final_dim
6410 \pgfpicture
6411 \pgfrememberpicturepositiononpagetrue
6412 \pgfpointanchor { wa - \l_@@_prefix_str - \l_@@_initial_tl } { south }
6413 \dim_gset:Nn \g_@@_x_initial_dim \pgf@x
6414 \dim_gset:Nn \g_@@_y_initial_dim \pgf@y
6415 \pgfpointanchor { wa - \l_@@_prefix_str - \l_@@_final_tl } { north }
6416 \dim_gset:Nn \g_@@_x_final_dim \pgf@x
6417 \dim_gset:Nn \g_@@_y_final_dim \pgf@y
6418 \endpgfpicture
6419 \bool_lazy_and:nnTF
6420 {
6421 \dim_compare_p:nNn { \g_@@_y_initial_dim - \g_@@_y_final_dim }
6422 > \l_@@_max_length_of_arrow_dim
6423 }
6424 { \int_compare_p:nNn { \l_@@_final_int - \l_@@_initial_int } = 1 }
6425 {
6426 \tl_gset:Ne \g_tmpa_tl
6427 {
6428 \int_compare:nNnTF \l_@@_pos_arrow_int < 5
6429 { \dim_use:N \g_@@_x_initial_dim }
6430 { \dim_use:N \l_@@_x_dim } ,
6431 \dim_eval:n
6432 {
6433 ( \g_@@_y_initial_dim + \g_@@_y_final_dim ) / 2
6434 + 0.5 \l_@@_max_length_of_arrow_dim
6435 }
6436 }
6437 \tl_gset:Ne \g_tmpb_tl
6438 {
6439 \int_compare:nNnTF \l_@@_pos_arrow_int < 5
6440 { \dim_use:N \g_@@_x_final_dim }
6441 { \dim_use:N \l_@@_x_dim } ,
6442 \dim_eval:n
6443 {
6444 ( \g_@@_y_initial_dim + \g_@@_y_final_dim ) / 2
6445 - 0.5 \l_@@_max_length_of_arrow_dim
6446 }
6447 }
6448 }
6449 {
6450 \tl_gset:Ne \g_tmpa_tl
6451 {
6452 \int_compare:nNnTF \l_@@_pos_arrow_int < 5
6453 { \dim_use:N \g_@@_x_initial_dim }
6454 { \dim_use:N \l_@@_x_dim } ,
6455 \bool_if:NTF \l_tmpa_bool
6456 { \dim_eval:n { \g_@@_y_initial_dim + \l_@@_start_adjust_dim } }
6457 { \dim_use:N \g_@@_y_initial_dim }
6458 }
6459 \tl_gset:Ne \g_tmpb_tl
6460 {
6461 \int_compare:nNnTF \l_@@_pos_arrow_int < 5
6462 { \dim_use:N \g_@@_x_final_dim }
6463 { \dim_use:N \l_@@_x_dim } ,
6464 \bool_if:NTF \l_tmpb_bool
6465 { \dim_eval:n { \g_@@_y_final_dim - \l_@@_end_adjust_dim } }
6466 { \dim_use:N \g_@@_y_final_dim }
6467 }
6468 }
6469 % \end{macrocode}
6470 % The dimension |\l_@@_delta_x_dim| is the difference of abscissa between the
6471 % right side of the alignment (|\halign|) and the left side of the arrow.
6472 % \begin{macrocode}
6473 \bool_if:NF \l_@@_right_overlap_bool
6474 {
6475 \bool_if:NT \l_@@_in_WithArrows_bool
6476 {
6477 \pgfpicture
6478 \pgfrememberpicturepositiononpagetrue
6479 \pgfpointanchor { wa - \l_@@_prefix_str - 1 - r } { south }
6480 \int_compare:nNnTF \l_@@_pos_arrow_int < 5
6481 {
6482 \dim_set:Nn \l_@@_delta_x_dim
6483 {
6484 \pgf@x -
6485 ( \dim_min:nn \g_@@_x_initial_dim \g_@@_x_final_dim )
6486 }
6487 }
6488 { \dim_set:Nn \l_@@_delta_x_dim { \pgf@x - \l_@@_x_dim } }
6489 \endpgfpicture
6490 }
6491 }
6492 % \end{macrocode}
6493 %
6494 % \bigskip
6495 % Eventually, we can draw the arrow with the code in |\l_@@_tikz_code_tl|. We
6496 % recall that the value by default for this token list is :\enskip
6497 % ``|\draw (#1) to node {#3} (#2) ;|''. This value can be modified with the
6498 % option |tikz-code|. We use the variant |\@@_draw_arrow:nno| of the macro
6499 % |\@@_draw_arrow:nnn| because of the characters \emph{underscore} in the name
6500 % |\l_tmpa_tl|: if the user uses the Tikz library |babel|, the third argument of
6501 % the command |\@@_draw_arrow:nno| will be rescanned because this third argument
6502 % will be in the argument of a command |node| of an instruction |\draw| of
6503 % Tikz... and we will have an error because of the characters
6504 % \emph{underscore}.\footnote{There were other solutions: use another name
6505 % without \emph{underscore} (like |\ltmpatl|) or use the package
6506 % \pkg{underscore} (with this package, the characters \emph{underscore} will be
6507 % rescanned without errors, even in text mode).}
6508 % \begin{macrocode}
6509 \@@_draw_arrow:nno \g_tmpa_tl \g_tmpb_tl \l_tmpa_tl
6510 % \end{macrocode}
6511 %
6512 % \smallskip
6513 % We close the TeX group opened for the options given to |\Arrow[...]| (local
6514 % level of the options).
6515 % \begin{macrocode}
6516 \group_end:
6517 }
6518 % \end{macrocode}
6519 %
6520 %
6521 % \bigskip
6522 % The function |@@_tmpa:nnn| will draw the arrow. It's merely an environment
6523 % |{tikzpicture}|. However, the Tikz instruction in this environment must be
6524 % inserted from |\l_@@_tikz_code_tl| with the markers |#1|, |#2| and |#3|.
6525 % That's why we create a function |\@@_def_function_arrow:n| which will create
6526 % the function |\@@_arrow:nnn|.
6527 % \begin{macrocode}
6528 \cs_generate_variant:Nn \@@_def_function_arrow:n { o }
6529 \cs_new_protected:Npn \@@_def_function_arrow:n #1
6530 {
6531 \cs_set:Npn \@@_arrow:nnn ##1 ##2 ##3
6532 {
6533 %<*LaTeX>
6534 \begin{tikzpicture}
6535 %</LaTeX>
6536 %<*plain-TeX>
6537 \tikzpicture
6538 %</plain-TeX>
6539 [ @@_standard_arrow ]
6540 % \end{macrocode}
6541 % You keep track of the bounding box because we want to compute the total width
6542 % of the arrow (with the label) for the arrows of type |over| and also for the
6543 % actualization of |\g_@@_overlap_x_dim|.
6544 % \begin{macrocode}
6545 \pgf@relevantforpicturesizetrue
6546 #1
6547 \dim_compare:nNnTF \pgf@picminx = { 16000 pt }
6548 { \dim_zero:N \l_tmpa_dim }
6549 { \dim_set:Nn \l_tmpa_dim { \pgf@picmaxx - \pgf@picminx } }
6550 \dim_add:Nn \l_tmpa_dim \l_@@_xoffset_dim
6551 % \end{macrocode}
6552 % |\l_@@_arrow_int = 0| probably means that we have an arrow in the |code-after|.
6553 % \begin{macrocode}
6554 \int_compare:nNnT \l_@@_arrow_int > 0 % added 2024/10/01
6555 {
6556 \prop_gput:cnV
6557 { g_@@_arrow _ \l_@@_prefix_str _ \int_use:N \l_@@_arrow_int _ prop }
6558 { width }
6559 \l_tmpa_dim
6560 }
6561 % \end{macrocode}
6562 % Now, the actualization of |\g_@@_overlap_x_dim|.
6563 % \begin{macrocode}
6564 \bool_if:NF \l_@@_right_overlap_bool
6565 {
6566 \bool_if:NT \l_@@_in_WithArrows_bool
6567 {
6568 \dim_gset:Nn \g_@@_overlap_x_dim
6569 {
6570 \dim_max:nn
6571 \g_@@_overlap_x_dim
6572 { \l_tmpa_dim - \l_@@_delta_x_dim }
6573 }
6574 }
6575 }
6576 \pgfresetboundingbox
6577 %<*LaTeX>
6578 \end{tikzpicture}
6579 %</LaTeX>
6580 %<*plain-TeX>
6581 \endtikzpicture
6582 %</plain-TeX>
6583 }
6584 }
6585 % \end{macrocode}
6586 %
6587 %
6588 % \medskip
6589 % When we draw the arrow (with |\@@_draw_arrow:nnn|), we first create the
6590 % function |\@@_arrow:nnn| and, then, we use the function |\@@_arrow:nnn| :
6591 % \begin{macrocode}
6592 \cs_generate_variant:Nn \@@_draw_arrow:nnn { n n o }
6593 \cs_new_protected:Npn \@@_draw_arrow:nnn #1 #2 #3
6594 {
6595 % \end{macrocode}
6596 %
6597 % \medskip
6598 % If the option |wrap-lines| is used, we have to use a special version of
6599 % |\l_@@_tikz_code_tl| (which corresponds to the option |tikz-code|).
6600 % \begin{macrocode}
6601 \bool_lazy_and:nnT \l_@@_wrap_lines_bool \l_@@_in_DispWithArrows_bool
6602 { \tl_set_eq:NN \l_@@_tikz_code_tl \c_@@_tikz_code_wrap_lines_tl }
6603 % \end{macrocode}
6604 %
6605 % \medskip
6606 % Now, the main lines of this function |\@@_draw_arrow:nnn|.
6607 % \begin{macrocode}
6608 \@@_def_function_arrow:o \l_@@_tikz_code_tl
6609 \@@_arrow:nnn { #1 } { #2 } { #3 }
6610 }
6611 % \end{macrocode}
6612 %
6613 % \bigskip
6614 % If the option |wrap-lines| is used, we have to use a special version of
6615 % |\l_@@_tikz_code_tl| (which corresponds to the option |tikz-code|).
6616 % \begin{macrocode}
6617 \tl_const:Nn \c_@@_tikz_code_wrap_lines_tl
6618 {
6619 \pgfset { inner~sep = 0pt }
6620 % \end{macrocode}
6621 % First, we draw the arrow without the label.
6622 % \begin{macrocode}
6623 \draw ( #1 ) to node ( @@_label ) { } ( #2 ) ;
6624 % \end{macrocode}
6625 % We retrieve in |\pgf@x| the abscissa of the left-side of the label we will
6626 % put.
6627 % \begin{macrocode}
6628 \pgfpointanchor { wa - \l_@@_prefix_str - @@_label } { west }
6629 % \end{macrocode}
6630 % We compute in |\l_tmpa_dim| the maximal width possible for the label.
6631 % Here is the use of |\g_@@_right_x_dim| which has been computed previously with
6632 % the |v|-nodes.
6633 % \begin{macrocode}
6634 \dim_set:Nn \l_tmpa_dim { \g_@@_right_x_dim - \pgf@x - 0.33333 em }
6635 % \end{macrocode}
6636 % We retrieve in |\g_tmpa_tl| the current value of the Tikz parameter
6637 % ``|text width|''.\footnote{In fact, it's not the current value of
6638 % ``|text width|'': it's the value of ``|text width|'' set in the option |tikz|
6639 % provided by \pkg{witharrows}. These options are given to Tikz in a
6640 % ``|every path|''. That's why we have to retrieve it in a path.}
6641 % \begin{macrocode}
6642 \path \pgfextra { \tl_gset:Ne \g_tmpa_tl \tikz@text@width } ;
6643 % \end{macrocode}
6644 % Maybe the current value of the parameter ``|text width|'' is shorter than
6645 % |\l_tmpa_dim|. In this case, we must use ``|text width|'' (we update
6646 % |\l_tmpa_dim|).
6647 % \begin{macrocode}
6648 \tl_if_empty:NF \g_tmpa_tl
6649 {
6650 \dim_set:Nn \l_tmpb_dim \g_tmpa_tl
6651 \dim_compare:nNnT \l_tmpb_dim < \l_tmpa_dim
6652 { \dim_set_eq:NN \l_tmpa_dim \l_tmpb_dim }
6653 }
6654 % \end{macrocode}
6655 % Now, we can put the label with the right value for ``|text width|''.
6656 % \begin{macrocode}
6657 \dim_compare:nNnT \l_tmpa_dim > \c_zero_dim
6658 {
6659 \path ( @@_label.west )
6660 %<*LaTeX>
6661 node [ anchor = west ]
6662 {
6663 \skip_horizontal:n { 0.33333 em }
6664 \begin { minipage } { \l_tmpa_dim }
6665 \tikz@text@action
6666 \pgfkeysgetvalue { / tikz / node~halign~header } \l_tmpa_tl
6667 \tl_if_eq:NnTF \l_tmpa_tl { \tikz@align@left@header }
6668 { \pgfutil@raggedright }
6669 {
6670 \tl_if_eq:NnTF \l_tmpa_tl { \tikz@align@right@header }
6671 { \pgfutil@raggedleft }
6672 {
6673 \tl_if_eq:NnT \l_tmpa_tl { \tikz@align@center@header }
6674 { \centering }
6675 }
6676 }
6677 #3
6678 \end { minipage }
6679 } ;
6680 %</LaTeX>
6681 %<*plain-TeX>
6682 node [ anchor = west , text~width = \dim_use:N \l_tmpa_dim ]
6683 { \skip_horizontal:n { 0.33333 em } #3 } ;
6684 %</plain-TeX>
6685 }
6686 }
6687 % \end{macrocode}
6688 %
6689 % \bigskip
6690 % \subsubsection{The command update_x}
6691 %
6692 % The command |\@@_update_x:nn| will analyze the lines between |#1| and
6693 % |#2| in order to modify |\l_@@_x_dim| in consequence. More precisely,
6694 % |\l_@@_x_dim| is increased if a line longer than the current value of
6695 % |\l_@@_x_dim| is found. |\@@_update_x:nn| is used in |\@@_scan_arrows:|
6696 % (for options |group| and |groups|) and in |\@@_draw_arrows:nn| (for option
6697 % |i|).
6698 % \begin{macrocode}
6699 \cs_new_protected:Npn \@@_update_x:nn #1 #2
6700 {
6701 \dim_gset_eq:NN \g_tmpa_dim \l_@@_x_dim
6702 \pgfpicture
6703 \pgfrememberpicturepositiononpagetrue
6704 \int_step_inline:nnn { #1 } { #2 }
6705 {
6706 \pgfpointanchor { wa - \l_@@_prefix_str - ##1 - l } { center }
6707 \dim_gset:Nn \g_tmpa_dim { \dim_max:nn \g_tmpa_dim \pgf@x }
6708 }
6709 \endpgfpicture
6710 \dim_set_eq:NN \l_@@_x_dim \g_tmpa_dim
6711 }
6712 % \end{macrocode}
6713 %
6714 % \bigskip
6715 % \subsubsection{We draw the arrows of type o}
6716 %
6717 % We recall that the arrows of type~|o| will be drawn \emph{over} (hence the
6718 % letter |o|) the other arrows. The arrows of type~|o| are available only when
6719 % the option |group| or the option |groups| is in force. The arrows of type~|o|
6720 % will be drawn group by group. The command |\@@_draw_o_arrows_of_the_group:| is
6721 % called after the construction of the (other) arrows of the group.
6722 %
6723 % \begin{macrocode}
6724 \cs_new_protected:Npn \@@_draw_o_arrows_of_the_group:
6725 {
6726 % \end{macrocode}
6727 %
6728 % The numbers of the arrows of type |o| we have to draw are in the sequence
6729 % |\l_@@_o_arrows_seq|. We have to sort that sequence because the order in which
6730 % these arrows will be drawn matters.
6731 %
6732 % \begin{itemize}
6733 % \item The arrows which arrive first must be drawn first.
6734 % \item For arrows with the same final line, the arrows with lower initial line
6735 % must be drawn after (because they encompass the previous ones).
6736 % \end{itemize}
6737 %
6738 %
6739 % The second point ensures the expected output in situations such as in the
6740 % following example:
6741 %
6742 % \bigskip
6743 % \begin{BVerbatim}[boxwidth=6cm,baseline=c]
6744 % $\begin{WithArrows}[groups]
6745 % A & = B \Arrow[o,jump=3]{one}\\
6746 % & = C \Arrow[o,jump=2]{two}\\
6747 % & = D \Arrow{three} \\
6748 % & = E + E
6749 % \end{WithArrows}$
6750 % \end{BVerbatim}
6751 % \hspace{2cm}
6752 % $\begin{WithArrows}[groups,c]
6753 % A & = B \Arrow[o,jump=3]{one}\\
6754 % & = C \Arrow[o,jump=2]{two}\\
6755 % & = D \Arrow{three} \\
6756 % & = E + E
6757 % \end{WithArrows}$
6758 %
6759 % \bigskip
6760 % \begin{macrocode}
6761 \seq_sort:Nn \l_@@_o_arrows_seq
6762 {
6763 \prop_get:cnN
6764 { g_@@_arrow _ \l_@@_prefix_str _ ##1 _ prop }
6765 { final } \l_tmpa_tl
6766 % \end{macrocode}
6767 % We recall that |\prop_get:cnN| retrieves token lists (here |\l_tmpa_tl| and
6768 % |\l_tmpb_tl|). We don't need to do an explicit conversion in L3
6769 % integers because such token lists can be used directly in |\int_compare:nNnTF|.
6770 % \begin{macrocode}
6771 \prop_get:cnN
6772 { g_@@_arrow _ \l_@@_prefix_str _ ##2 _ prop }
6773 { final } \l_tmpb_tl
6774 \int_compare:nNnTF \l_tmpa_tl < \l_tmpb_tl
6775 \sort_return_same:
6776 {
6777 \int_compare:nNnTF \l_tmpa_tl > \l_tmpb_tl
6778 \sort_return_swapped:
6779 {
6780 \prop_get:cnN
6781 { g_@@_arrow _ \l_@@_prefix_str _ ##1 _ prop }
6782 { initial } \l_tmpa_tl
6783 \prop_get:cnN
6784 { g_@@_arrow _ \l_@@_prefix_str _ ##2 _ prop }
6785 { initial } \l_tmpb_tl
6786 \int_compare:nNnTF \l_tmpa_tl < \l_tmpb_tl
6787 \sort_return_swapped:
6788 \sort_return_same:
6789 }
6790 }
6791 }
6792 % \end{macrocode}
6793 %
6794 % \bigskip
6795 % Now, we can draw the arrows of type~|o| of the group in the order of the
6796 % sequence.
6797 % \begin{macrocode}
6798 \seq_map_inline:Nn \l_@@_o_arrows_seq
6799 {
6800 % \end{macrocode}
6801 % We retrieve the initial row and the final row of the arrow.
6802 % \begin{macrocode}
6803 \prop_get:cnN
6804 { g_@@_arrow _ \l_@@_prefix_str _ ##1 _ prop }
6805 { initial } \l_tmpa_tl
6806 \int_set:Nn \l_@@_initial_int \l_tmpa_tl
6807 \prop_get:cnN
6808 { g_@@_arrow _ \l_@@_prefix_str _ ##1 _ prop }
6809 { final } \l_tmpa_tl
6810 \int_set:Nn \l_@@_final_int \l_tmpa_tl
6811 % \end{macrocode}
6812 % The string |\l_@@_input_line_str| will be used only in some error messages.
6813 % \begin{macrocode}
6814 \prop_get:cnN
6815 { g_@@_arrow _ \l_@@_prefix_str _ ##1 _ prop }
6816 { input-line } \l_@@_input_line_str
6817 % \end{macrocode}
6818 % We have to compute the maximal width of all the arrows (with their labels)
6819 % which are covered by our arrow. We will compute that dimension in
6820 % |\g_tmpa_dim|. We need a global dimension because we will have to exit a
6821 % |\pgfpicture|.
6822 % \begin{macrocode}
6823 \dim_gzero:N \g_tmpa_dim
6824 % \end{macrocode}
6825 % We will raise the boolean |\g_tmpa_bool| if we find an arrow ``under'' our
6826 % arrow (we should find at least once since you are drawing an arrow of
6827 % type~|o|: if not, we will raise an error\footnote{Maybe we will change that in
6828 % future versions.}).
6829 % \begin{macrocode}
6830 \bool_set_false:N \g_tmpa_bool
6831 \pgfpicture
6832 \pgfrememberpicturepositiononpagetrue
6833 \int_step_inline:nnn \l_@@_first_arrow_int \l_@@_last_arrow_int
6834 {
6835 \prop_get:cnN
6836 { g_@@_arrow _ \l_@@_prefix_str _ ####1 _ prop }
6837 { initial } \l_tmpa_tl
6838 \prop_get:cnN
6839 { g_@@_arrow _ \l_@@_prefix_str _ ####1 _ prop }
6840 { final } \l_tmpb_tl
6841 \prop_get:cnN
6842 { g_@@_arrow _ \l_@@_prefix_str _ ####1 _ prop }
6843 { status } \l_@@_status_arrow_str
6844 \bool_lazy_any:nF
6845 {
6846 { \int_compare_p:n { ##1 = ####1 } }
6847 { \int_compare_p:nNn \l_@@_initial_int > \l_tmpa_tl }
6848 { \int_compare_p:nNn \l_tmpb_tl > \l_@@_final_int }
6849 % \end{macrocode}
6850 % We don't take into account the independent arrows because we have only
6851 % computed the \emph{width} of the arrows and that's why our arrow of type~|o|
6852 % will be positionned only relatively to the current group.
6853 % \begin{macrocode}
6854 { \str_if_eq_p:on \l_@@_status_arrow_str { independent } }
6855 }
6856 {
6857 % \end{macrocode}
6858 % The total width of the arrow (with its label) has been stored in a ``field''
6859 % of the arrow.
6860 % \begin{macrocode}
6861 \bool_gset_true:N \g_tmpa_bool
6862 \prop_get:cnN
6863 { g_@@ _ arrow _ \l_@@_prefix_str _ ####1 _ prop }
6864 { width }
6865 \l_tmpa_tl
6866 % \end{macrocode}
6867 % We have to do a global affectation in order to exit the |pgfpicture|.
6868 % \begin{macrocode}
6869 \dim_gset:Nn \g_tmpa_dim { \dim_max:nn \g_tmpa_dim \l_tmpa_tl }
6870 }
6871 }
6872 \endpgfpicture
6873 % \end{macrocode}
6874 % The boolean |\g_tmpa_bool| is raised if at least one arrow has been found
6875 % ``under'' our arrow (it should be the case since we are drawing an arrow of
6876 % type~|o|).
6877 % \begin{macrocode}
6878 \bool_if:NTF \g_tmpa_bool
6879 {
6880 \int_set:Nn \l_@@_arrow_int { ##1 }
6881 \dim_set_eq:NN \l_@@_xoffset_dim \g_tmpa_dim
6882 \dim_add:Nn \l_@@_xoffset_dim \l_@@_xoffset_for_o_arrows_dim
6883 % \end{macrocode}
6884 % \begin{macrocode}
6885 \@@_draw_arrow:
6886 }
6887 { \@@_error:n { o~arrow~with~no~arrow~under } }
6888 }
6889 }
6890 % \end{macrocode}
6891 %
6892 % \bigskip
6893 % The command |\WithArrowsLastEnv| is not used by the package \pkg{witharrows}.
6894 % It's only a facility given to the final user. It gives the number of the last
6895 % environment |{WithArrows}| at
6896 % level~$0$ (to the sense of the nested environments). This macro is fully
6897 % expandable and, thus, can be used directly in the name of a Tikz node.
6898 % \begin{macrocode}
6899 %<*LaTeX>
6900 \NewExpandableDocumentCommand \WithArrowsLastEnv { }
6901 { \int_use:N \g_@@_last_env_int }
6902 %</LaTeX>
6903 %<*plain-TeX>
6904 \cs_new:Npn \WithArrowsLastEnv { \int_use:N \g_@@_last_env_int }
6905 %</plain-TeX>
6906 % \end{macrocode}
6907 %
6908 % \bigskip
6909 % \subsection{The command \textbackslash Arrow in code-after}
6910 %
6911 % The option |code-after| is an option of the environment |{WithArrows}| (this
6912 % option is only available at the environment level). In the option |code-after|,
6913 % one can use the command |Arrow| but it's a special version of the command
6914 % |Arrow|. For this special version (internally called |\@@_Arrow_code_after|),
6915 % we define a special set of keys called |WithArrows/Arrow/code-after|.
6916 %
6917 % \begin{macrocode}
6918 \keys_define:nn { WithArrows / Arrow / code-after }
6919 {
6920 tikz .code:n =
6921 \tikzset { WithArrows / arrow / .append~style = { #1 } } ,
6922 tikz .value_required:n = true ,
6923 rr .value_forbidden:n = true ,
6924 rr .code:n = \@@_fix_pos_option:n 0 ,
6925 ll .value_forbidden:n = true,
6926 ll .code:n = \@@_fix_pos_option:n 1 ,
6927 rl .value_forbidden:n = true ,
6928 rl .code:n = \@@_fix_pos_option:n 2 ,
6929 lr .value_forbidden:n = true ,
6930 lr .code:n = \@@_fix_pos_option:n 3 ,
6931 v .value_forbidden:n = true ,
6932 v .code:n = \@@_fix_pos_option:n 4 ,
6933 tikz-code .tl_set:N = \l_@@_tikz_code_tl ,
6934 tikz-code .value_required:n = true ,
6935 xoffset .dim_set:N = \l_@@_xoffset_dim ,
6936 xoffset .value_required:n = true ,
6937 unknown .code:n =
6938 \@@_sort_seq:N \l_@@_options_Arrow_code_after_seq
6939 \@@_error:n { Unknown~option~Arrow~in~code-after }
6940 }
6941 % \end{macrocode}
6942 %
6943 % \bigskip
6944 % A sequence of the options available in |\Arrow| in |code-after|. This sequence
6945 % will be used in the error messages and can be modified dynamically.
6946 % \begin{macrocode}
6947 \seq_new:N \l_@@_options_Arrow_code_after_seq
6948 \@@_set_seq_of_str_from_clist:Nn \l_@@_options_Arrow_code_after_seq
6949 { ll, lr, rl, rr, tikz, tikz-code, v, x, offset }
6950 % \end{macrocode}
6951 %
6952 % \bigskip
6953 % \begin{macrocode}
6954 %<*LaTeX>
6955 \NewDocumentCommand \@@_Arrow_code_after { O { } m m m ! O { } }
6956 %</LaTeX>
6957 %<*plain-TeX>
6958 \cs_new_protected:Npn \@@_Arrow_code_after
6959 {
6960 \peek_meaning:NTF [
6961 { \@@_Arrow_code_after_i }
6962 { \@@_Arrow_code_after_i [ ] }
6963 }
6964 \cs_new_protected:Npn \@@_Arrow_code_after_i [ #1 ] #2 #3 #4
6965 {
6966 \peek_meaning:NTF [
6967 { \@@_Arrow_code_after_ii [ #1 ] { #2 } { #3 } { #4 } }
6968 { \@@_Arrow_code_after_ii [ #1 ] { #2 } { #3 } { #4 } [ ] }
6969 }
6970 \cs_new_protected:Npn \@@_Arrow_code_after_ii [ #1 ] #2 #3 #4 [ #5 ]
6971 %</plain-TeX>
6972 {
6973 \int_set_eq:NN \l_@@_pos_arrow_int \c_one_int
6974 \str_clear_new:N \l_@@_previous_key_str
6975 \group_begin:
6976 \keys_set:nn { WithArrows / Arrow / code-after }
6977 { #1, #5, tikz = { xshift = \l_@@_xoffset_dim } }
6978 \bool_set_false:N \l_@@_initial_r_bool
6979 \bool_set_false:N \l_@@_final_r_bool
6980 \int_case:nn \l_@@_pos_arrow_int
6981 {
6982 0
6983 {
6984 \bool_set_true:N \l_@@_initial_r_bool
6985 \bool_set_true:N \l_@@_final_r_bool
6986 }
6987 2 { \bool_set_true:N \l_@@_initial_r_bool }
6988 3 { \bool_set_true:N \l_@@_final_r_bool }
6989 }
6990 % \end{macrocode}
6991 % We prevent drawing an arrow from a line to itself.
6992 % \begin{macrocode}
6993 \tl_if_eq:nnTF { #2 } { #3 }
6994 { \@@_error:nn { Both~lines~are~equal } { #2 } }
6995 % \end{macrocode}
6996 % We test whether the two Tikz nodes |(#2-l)| and |(#3-l)| really exist. If not,
6997 % the arrow won't be drawn.
6998 % \begin{macrocode}
6999 {
7000 \cs_if_free:cTF { pgf@sh@ns@wa - \l_@@_prefix_str - #2 - l }
7001 { \@@_error:ne { Wrong~line~in~Arrow } { #2 } }
7002 {
7003 \cs_if_free:cTF { pgf@sh@ns@wa - \l_@@_prefix_str - #3 - l }
7004 { \@@_error:ne { Wrong~line~in~Arrow } { #3 } }
7005 {
7006 \int_compare:nNnTF \l_@@_pos_arrow_int = 4
7007 {
7008 \pgfpicture
7009 \pgfrememberpicturepositiononpagetrue
7010 \pgfpointanchor { wa - \l_@@_prefix_str - #2 - l }
7011 { south }
7012 \dim_set_eq:NN \l_tmpa_dim \pgf@x
7013 \dim_set_eq:NN \l_tmpb_dim \pgf@y
7014 \pgfpointanchor { wa - \l_@@_prefix_str - #3 - l }
7015 { north }
7016 \dim_set:Nn \l_tmpa_dim
7017 { \dim_max:nn \l_tmpa_dim \pgf@x }
7018 \tl_gset:Ne \g_tmpa_tl
7019 { \dim_use:N \l_tmpa_dim , \dim_use:N \l_tmpb_dim }
7020 \tl_gset:Ne \g_tmpb_tl
7021 { \dim_use:N \l_tmpa_dim , \dim_use:N \pgf@y }
7022 \endpgfpicture
7023 }
7024 {
7025 \pgfpicture
7026 \pgfrememberpicturepositiononpagetrue
7027 \pgfpointanchor
7028 {
7029 wa - \l_@@_prefix_str -
7030 #2 - \bool_if:NTF \l_@@_initial_r_bool r l
7031 }
7032 { south }
7033 \tl_gset:Ne \g_tmpa_tl
7034 { \dim_use:N \pgf@x , \dim_use:N \pgf@y }
7035 \pgfpointanchor
7036 {
7037 wa - \l_@@_prefix_str -
7038 #3 - \bool_if:NTF \l_@@_final_r_bool r l
7039 }
7040 { north }
7041 \tl_gset:Ne \g_tmpb_tl
7042 { \dim_use:N \pgf@x , \dim_use:N \pgf@y }
7043 \endpgfpicture
7044 }
7045 \@@_draw_arrow:nnn \g_tmpa_tl \g_tmpb_tl { #4 }
7046 }
7047 }
7048 }
7049 \group_end:
7050 }
7051 % \end{macrocode}
7052 %
7053 %
7054 % \bigskip
7055 % \subsection{The command \textbackslash MultiArrow in code-after}
7056 % The command |\@@_MultiArrow:nn| will be linked to |\MultiArrow| when the
7057 % |code-after| is executed.
7058 %
7059 % \begin{macrocode}
7060 \cs_new_protected:Npn \@@_MultiArrow:nn #1 #2
7061 {
7062 % \end{macrocode}
7063 % The user of the command |\MultiArrow| (in |code-after|) will be able to specify
7064 % the list of lines with the same syntax as the loop |\foreach| of \pkg{pgffor}.
7065 % First, we test with a regular expression whether the format of the list of
7066 % lines is correct.
7067 % \begin{macrocode}
7068 \exp_args:Nne
7069 \regex_match:nnTF
7070 { \A \d+ (\,\d+)* ( \, \.\.\. (\,\d+)+ )* \Z }
7071 { #1 }
7072 { \@@_MultiArrow_i:nn { #1 } { #2 } }
7073 { \@@_error:ne { Invalid~specification~for~MultiArrow } { #1 } }
7074 }
7075 % \end{macrocode}
7076 %
7077 % \begin{macrocode}
7078 \cs_new_protected:Npn \@@_MultiArrow_i:nn #1 #2
7079 {
7080 % \end{macrocode}
7081 % That's why we construct a ``clist'' of L3 from the specification of
7082 % list given by the user. The construction of the ``clist'' must be global in
7083 % order to exit the |\foreach| and that's why we will construct the list in
7084 % |\g_tmpa_clist|.
7085 % \begin{macrocode}
7086 \foreach \x in { #1 }
7087 {
7088 \cs_if_free:cTF { pgf@sh@ns@wa - \l_@@_prefix_str - \x - l }
7089 { \@@_error:ne { Wrong~line~specification~in~MultiArrow } \x }
7090 { \clist_gput_right:Ne \g_tmpa_clist \x }
7091 }
7092 % \end{macrocode}
7093 % We sort the list |\g_tmpa_clist| because we want to extract the minimum and
7094 % the maximum.
7095 % \begin{macrocode}
7096 \int_compare:nTF { \clist_count:N \g_tmpa_clist < 2 }
7097 { \@@_error:n { Too~small~specification~for~MultiArrow } }
7098 {
7099 \clist_sort:Nn \g_tmpa_clist
7100 {
7101 \int_compare:nNnTF { ##1 } > { ##2 }
7102 \sort_return_swapped:
7103 \sort_return_same:
7104 }
7105 % \end{macrocode}
7106 % We extract the minimum in |\l_tmpa_tl| (it must be an integer but we store it
7107 % in a token list of L3).
7108 % \begin{macrocode}
7109 \clist_pop:NN \g_tmpa_clist \l_tmpa_tl
7110 % \end{macrocode}
7111 %
7112 % We extract the maximum in |\l_tmpb_tl|. The remaining list (in
7113 % |\g_tmpa_clist|) will be sorted in decreasing order but never mind...
7114 % \begin{macrocode}
7115 \clist_reverse:N \g_tmpa_clist
7116 \clist_pop:NN \g_tmpa_clist \l_tmpb_tl
7117 % \end{macrocode}
7118 %
7119 % We draw the teeth of the rak (except the first one and the last one) with the
7120 % auxiliary function |\@@_MultiArrow_i:n|. This auxiliary fonction is necessary
7121 % to expand the specification of the list in the |\foreach| loop. The first and
7122 % the last teeth of the rak can't be drawn the same way as the others (think,
7123 % for example, to the case of the option ``|rounded corners|'' is used).
7124 % \begin{macrocode}
7125 \exp_args:No \@@_MultiArrow_i:n \g_tmpa_clist
7126 % \end{macrocode}
7127 %
7128 % Now, we draw the rest of the structure.
7129 % \begin{macrocode}
7130 %<*LaTeX>
7131 \begin { tikzpicture }
7132 %</LaTeX>
7133 %<*plain-TeX>
7134 \tikzpicture
7135 %</plain-TeX>
7136 [
7137 @@_standard ,
7138 every~path / .style = { WithArrows / arrow }
7139 ]
7140 \draw [<->] ([xshift = \l_@@_xoffset_dim]\l_tmpa_tl-r.south)
7141 -- ++(5mm,0)
7142 -- node (@@_label) {}
7143 ([xshift = \l_@@_xoffset_dim+5mm]\l_tmpb_tl-r.south)
7144 -- ([xshift = \l_@@_xoffset_dim]\l_tmpb_tl-r.south) ;
7145 \pgfpointanchor { wa - \l_@@_prefix_str - @@_label } { west }
7146 \dim_set:Nn \l_tmpa_dim { 20 cm }
7147 \path \pgfextra { \tl_gset:Ne \g_tmpa_tl \tikz@text@width } ;
7148 \tl_if_empty:NF \g_tmpa_tl { \dim_set:Nn \l_tmpa_dim \g_tmpa_tl }
7149 \bool_lazy_and:nnT \l_@@_wrap_lines_bool \l_@@_in_DispWithArrows_bool
7150 {
7151 \dim_set:Nn \l_tmpb_dim
7152 { \g_@@_right_x_dim - \pgf@x - 0.3333 em }
7153 \dim_compare:nNnT \l_tmpb_dim < \l_tmpa_dim
7154 { \dim_set_eq:NN \l_tmpa_dim \l_tmpb_dim }
7155 }
7156 \path (@@_label.west)
7157 node [ anchor = west, text~width = \dim_use:N \l_tmpa_dim ] { #2 } ;
7158 %<*LaTeX>
7159 \end { tikzpicture }
7160 %</LaTeX>
7161 %<*plain-TeX>
7162 \endtikzpicture
7163 %</plain-TeX>
7164 }
7165 }
7166 % \end{macrocode}
7167 %
7168 % \begin{macrocode}
7169 \cs_new_protected:Npn \@@_MultiArrow_i:n #1
7170 {
7171 %<*LaTeX>
7172 \begin { tikzpicture }
7173 %</LaTeX>
7174 %<*plain-TeX>
7175 \tikzpicture
7176 %</plain-TeX>
7177 [
7178 @@_standard ,
7179 every~path / .style = { WithArrows / arrow }
7180 ]
7181 \foreach \k in { #1 }
7182 {
7183 \draw [ <- ]
7184 ( [xshift = \l_@@_xoffset_dim]\k-r.south ) -- ++(5mm,0) ;
7185 } % ;
7186 %<*LaTeX>
7187 \end{tikzpicture}
7188 %</LaTeX>
7189 %<*plain-TeX>
7190 \endtikzpicture
7191 %</plain-TeX>
7192 }
7193 % \end{macrocode}
7194 %
7195 %
7196 % \bigskip
7197 % \subsection{The error messages of the package}
7198 %
7199 % \begin{macrocode}
7200 \bool_if:NTF \c_@@_messages_for_Overleaf_bool
7201 { \str_const:Nn \c_@@_available_keys_str { } }
7202 {
7203 \str_const:Nn \c_@@_available_keys_str
7204 { For~a~list~of~the~available~keys,~type~H~<return>. }
7205 }
7206 % \end{macrocode}
7207 %
7208 % \begin{macrocode}
7209 \str_new:N \l_witharrows_body_str
7210 % \end{macrocode}
7211 %
7212 % The following commands must \emph{not} be protected since they will be used in
7213 % error messages.
7214 % \begin{macrocode}
7215 \cs_new:Npn \@@_potential_body_i:
7216 {
7217 \str_if_empty:NF \l_witharrows_body_str
7218 { \\ If~you~want~to~see~the~body~of~the~environment,~type~H~<return>. }
7219 }
7220 % \end{macrocode}
7221 %
7222 % \begin{macrocode}
7223 \cs_new:Npn \@@_potential_body_ii:
7224 {
7225 \str_if_empty:NTF \l_witharrows_body_str
7226 { No~further~help~available }
7227 {
7228 The~body~of~your~environment~was:\\
7229 \l_witharrows_body_str
7230 }
7231 }
7232 % \end{macrocode}
7233 %
7234 % \begin{macrocode}
7235 \str_const:Nn \c_@@_option_ignored_str
7236 { If~you~go~on,~this~option~will~be~ignored. }
7237 \str_const:Nn \c_@@_command_ignored_str
7238 { If~you~go~on,~this~command~will~be~ignored. }
7239 % \end{macrocode}
7240 %
7241 % \begin{macrocode}
7242 %<*LaTeX>
7243 \@@_msg_new:nn { amsmath~not~loaded }
7244 {
7245 amsmath~not~loaded.\\
7246 You~can't~use~the~option~'\l_keys_key_str'~because~the~
7247 package~'amsmath'~has~not~been~loaded.\\
7248 If~you~go~on,~this~option~will~be~ignored~in~the~rest~
7249 of~the~document.
7250 }
7251 %</LaTeX>
7252 % \end{macrocode}
7253 %
7254 % \begin{macrocode}
7255 \@@_msg_new:nn { Bad~value~for~replace~brace~by }
7256 {
7257 Incorrect~value.\\
7258 Bad~value~for~the~option~'\l_keys_key_str'.~The~value~must~begin~
7259 with~an~extensible~left~delimiter.~The~possible~values~are:~.,
7260 \token_to_str:N \{,~(,~[,~\token_to_str:N \lbrace,~
7261 \token_to_str:N \lbrack,~\token_to_str:N \lgroup,~
7262 \token_to_str:N \langle,~\token_to_str:N \lmoustache,~
7263 \token_to_str:N \lfloor\ and~\token_to_str:N \lceil\
7264 (and~\token_to_str:N \lvert\ and~\token_to_str:N \lVert\
7265 if~amsmath~or~unicode-math~is~loaded~in~LaTeX).\\
7266 \c_@@_option_ignored_str
7267 }
7268 % \end{macrocode}
7269 %
7270 % \begin{macrocode}
7271 \@@_msg_new:nn { option~of~cr~negative }
7272 {
7273 Bad~value.\\
7274 The~argument~of~the~command~\token_to_str:N\\~
7275 should~be~positive~in~the~row~\int_use:N \g_@@_line_int\
7276 of~your~environment~\{\l_@@_type_env_str\}.\\
7277 \c_@@_option_ignored_str
7278 }
7279 % \end{macrocode}
7280 %
7281 % \begin{macrocode}
7282 \@@_msg_new:nn { omit~probably~used }
7283 {
7284 Strange~problem.\\
7285 Maybe~you~have~used~a~command~
7286 \token_to_str:N\omit\ in~the~line~\int_use:N \g_@@_line_int\
7287 (or~another~line)~of~your~environment~\{\l_@@_type_env_str\}.\\
7288 You~can~go~on~but~you~may~have~others~errors.
7289 }
7290 % \end{macrocode}
7291 %
7292 % \begin{macrocode}
7293 %<*LaTeX>
7294 \@@_msg_new:nnn { newline~at~the~end~of~env }
7295 {
7296 Incorrect~end.\\
7297 The~environments~of~witharrows~(\{WithArrows\}~and~
7298 \{DispWithArrows\})~should~not~end~by~\token_to_str:N \\.\\
7299 However,~you~can~go~on~for~this~time.~No~similar~error~will~be~
7300 raised~in~this~document.
7301 \@@_potential_body_i:
7302 }
7303 { \@@_potential_body_ii: }
7304 %</LaTeX>
7305 % \end{macrocode}
7306 %
7307 % \begin{macrocode}
7308 \@@_msg_new:nnn { Invalid~option~format }
7309 {
7310 Invalide~value.\\
7311 The~key~'format'~should~contain~only~letters~r,~c~and~l~and~
7312 must~not~be~empty.\\
7313 \c_@@_option_ignored_str
7314 \@@_potential_body_i:
7315 }
7316 { \@@_potential_body_ii: }
7317 % \end{macrocode}
7318 %
7319 % \begin{macrocode}
7320 \@@_msg_new:nnn { invalid~key~o }
7321 {
7322 Invalid~use~of~a~key.\\
7323 The~key~'o'~for~individual~arrows~can~be~used~only~in~mode~
7324 'group'~or~in~mode~'groups'.\\
7325 \c_@@_option_ignored_str
7326 \@@_potential_body_i:
7327 }
7328 { \@@_potential_body_ii: }
7329 % \end{macrocode}
7330 %
7331 % \begin{macrocode}
7332 \@@_msg_new:nnn { Value~for~a~key }
7333 {
7334 Misuse~of~a~key.\\
7335 The~key~'\l_keys_key_str'~should~be~used~without~value. \\
7336 However,~you~can~go~on~for~this~time.
7337 \@@_potential_body_i:
7338 }
7339 { \@@_potential_body_ii: }
7340 % \end{macrocode}
7341 %
7342 % \begin{macrocode}
7343 \@@_msg_new:nnn { Unknown~option~in~Arrow }
7344 {
7345 Unknown~option.\\
7346 The~key~'\l_keys_key_str'~is~unknown~for~the~command~
7347 \l_@@_string_Arrow_for_msg_str\ in~the~row~
7348 \int_use:N \g_@@_line_int\ of~your~environment~
7349 \{\l_@@_type_env_str\}. \l_tmpa_str \\
7350 \c_@@_option_ignored_str \\
7351 \c_@@_available_keys_str
7352 }
7353 {
7354 The~available~keys~are~(in~alphabetic~order):~
7355 \seq_use:Nnnn \l_@@_options_Arrow_seq {~and~} {,~} {~and~}.
7356 }
7357 % \end{macrocode}
7358 %
7359 %
7360 % \begin{macrocode}
7361 \@@_msg_new:nnn { Unknown~option~WithArrows }
7362 {
7363 Unknown~option.\\
7364 The~key~'\l_keys_key_str'~is~unknown~in~\{\l_@@_type_env_str\}. \\
7365 \c_@@_option_ignored_str \\
7366 \c_@@_available_keys_str
7367 }
7368 {
7369 The~available~keys~are~(in~alphabetic~order):~
7370 \seq_use:Nnnn \l_@@_options_WithArrows_seq {~and~} {,~} {~and~}.
7371 }
7372 % \end{macrocode}
7373 % \begin{macrocode}
7374 \@@_msg_new:nnn { Unknown~option~DispWithArrows }
7375 {
7376 Unknown~option.\\
7377 The~key~'\l_keys_key_str'~is~unknown~in~\{\l_@@_type_env_str\}. \\
7378 \c_@@_option_ignored_str \\
7379 \c_@@_available_keys_str
7380 }
7381 {
7382 The~available~keys~are~(in~alphabetic~order):~
7383 \seq_use:Nnnn \l_@@_options_DispWithArrows_seq {~and~} {,~} {~and~}.
7384 }
7385 % \end{macrocode}
7386 %
7387 % \begin{macrocode}
7388 \@@_msg_new:nnn { Unknown~option~WithArrowsOptions }
7389 {
7390 Unknown~option.\\
7391 The~key~'\l_keys_key_str'~is~unknown~in~
7392 \token_to_str:N \WithArrowsOptions. \\
7393 \c_@@_option_ignored_str \\
7394 \c_@@_available_keys_str
7395 }
7396 {
7397 The~available~keys~are~(in~alphabetic~order):~
7398 \seq_use:Nnnn \l_@@_options_WithArrowsOptions_seq {~and~} {,~} {~and~}.
7399 }
7400 % \end{macrocode}
7401 %
7402 % \begin{macrocode}
7403 \@@_msg_new:nnn { Unknown~option~Arrow~in~code-after }
7404 {
7405 Unknown~option.\\
7406 The~key~'\l_keys_key_str'~is~unknown~in~
7407 \token_to_str:N \Arrow\ in~code-after. \\
7408 \c_@@_option_ignored_str \\
7409 \c_@@_available_keys_str
7410 }
7411 {
7412 The~available~keys~are~(in~alphabetic~order):~
7413 \seq_use:Nnnn \l_@@_options_Arrow_code_after_seq {~and~} {,~} {~and~}.
7414 }
7415 % \end{macrocode}
7416 %
7417 %
7418 % \begin{macrocode}
7419 \@@_msg_new:nnn { Too~much~columns~in~WithArrows }
7420 {
7421 Too~much~columns.\\
7422 Your~environment~\{\l_@@_type_env_str\}~has~\int_use:N
7423 \l_@@_nb_cols_int\ columns~and~you~try~to~use~one~more.~
7424 Maybe~you~have~forgotten~a~\c_backslash_str\c_backslash_str.~
7425 If~you~really~want~to~use~more~columns~(after~the~arrows)~you~should~use~
7426 the~option~'more-columns'~at~a~global~level~or~for~an~environment. \\
7427 However,~you~can~go~one~for~this~time.
7428 \@@_potential_body_i:
7429 }
7430 { \@@_potential_body_ii: }
7431 % \end{macrocode}
7432 %
7433 % \begin{macrocode}
7434 \@@_msg_new:nnn { Too~much~columns~in~DispWithArrows }
7435 {
7436 Too~much~columns.\\
7437 Your~environment~\{\l_@@_type_env_str\}~has~\int_use:N
7438 \l_@@_nb_cols_int\ columns~and~you~try~to~use~one~more.~
7439 Maybe~you~have~forgotten~a~\c_backslash_str\c_backslash_str\
7440 at~the~end~of~row~\int_use:N \g_@@_line_int. \\
7441 This~error~is~fatal.
7442 \@@_potential_body_i:
7443 }
7444 { \@@_potential_body_ii: }
7445 % \end{macrocode}
7446 %
7447 % \begin{macrocode}
7448 \@@_msg_new:nn { Negative~jump }
7449 {
7450 Incorrect~value.\\
7451 You~can't~use~a~negative~value~for~the~option~'jump'~of~command~
7452 \l_@@_string_Arrow_for_msg_str\
7453 in~the~row~\int_use:N \g_@@_line_int\
7454 of~your~environment~\{\l_@@_type_env_str\}.~
7455 You~can~create~an~arrow~going~backwards~with~the~option~'<-'~of~Tikz. \\
7456 \c_@@_option_ignored_str
7457 }
7458 % \end{macrocode}
7459 %
7460 % \begin{macrocode}
7461 \@@_msg_new:nn { new-group~without~groups }
7462 {
7463 Misuse~of~a~key.\\
7464 You~can't~use~the~option~'new-group'~for~the~command~
7465 \l_@@_string_Arrow_for_msg_str\
7466 because~you~are~not~in~'groups'~mode.~Try~to~use~the~option~
7467 'groups'~in~your~environment~\{\l_@@_type_env_str\}. \\
7468 \c_@@_option_ignored_str
7469 }
7470 % \end{macrocode}
7471 %
7472 %
7473 % \begin{macrocode}
7474 \@@_msg_new:nnn
7475 { Too~few~lines~for~an~arrow }
7476 {
7477 Impossible~arrow.\\
7478 Line~\l_@@_input_line_str\
7479 :~an~arrow~specified~in~the~row~\int_use:N \l_@@_initial_int\
7480 of~your~environment~\{\l_@@_type_env_str\}~can't~be~drawn~
7481 because~it~arrives~after~the~last~row~of~the~environment. \\
7482 If~you~go~on,~this~arrow~will~be~ignored.
7483 \@@_potential_body_i:
7484 }
7485 { \@@_potential_body_ii: }
7486 % \end{macrocode}
7487 %
7488 % \begin{macrocode}
7489 \@@_msg_new:nn { o~arrow~with~no~arrow~under }
7490 {
7491 Problem~with~the~key~'o'.\\
7492 Line~\l_@@_input_line_str\
7493 :~there~is~no~arrow~'under'~your~arrow~of~type~'o'.\\
7494 If~you~go~on,~this~arrow~won't~be~drawn.
7495 }
7496 % \end{macrocode}
7497 %
7498 % \begin{macrocode}
7499 \@@_msg_new:nnn { WithArrows~outside~math~mode }
7500 {
7501 You~are~outside~math~mode.\\
7502 The~environment~\{\l_@@_type_env_str\}~should~be~used~only~in~math~mode~
7503 like~the~environment~\{aligned\}~of~amsmath. \\
7504 Nevertheless,~you~can~go~on.
7505 \@@_potential_body_i:
7506 }
7507 { \@@_potential_body_ii: }
7508 % \end{macrocode}
7509 %
7510 % \begin{macrocode}
7511 \@@_msg_new:nnn { DispWithArrows~in~math~mode }
7512 {
7513 You~are~in~math~mode.\\
7514 The~environment~\{\l_@@_type_env_str\}~should~be~used~only~outside~math~
7515 mode~like~the~environments~\{align\}~and~\{align*\}~of~amsmath. \\
7516 This~error~is~fatal.
7517 \@@_potential_body_i:
7518 }
7519 { \@@_potential_body_ii: }
7520 % \end{macrocode}
7521 %
7522 % \begin{macrocode}
7523 \@@_msg_new:nn { Incompatible~options~in~Arrow }
7524 {
7525 Incompatible~options.\\
7526 You~try~to~use~the~option~'\l_keys_key_str'~but~
7527 this~option~is~incompatible~or~redundant~with~the~option~
7528 '\l_@@_previous_key_str'~set~in~the~same~command~
7529 \l_@@_string_Arrow_for_msg_str. \\
7530 \c_@@_option_ignored_str
7531 }
7532 % \end{macrocode}
7533 %
7534 %
7535 % \begin{macrocode}
7536 \@@_msg_new:nn { Incompatible~options a}
7537 {
7538 Incompatible~options.\\
7539 You~try~to~use~the~option~'\l_keys_key_str'~but~
7540 this~option~is~incompatible~or~redundant~with~the~option~
7541 '\l_@@_previous_key_str'~set~in~the~same~command~
7542 \bool_if:NT \l_@@_in_code_after_bool
7543 {
7544 \l_@@_string_Arrow_for_msg_str\
7545 in~the~code-after~of~your~environment~\{\l_@@_type_env_str\}
7546 }. \\
7547 \c_@@_option_ignored_str
7548 }
7549 % \end{macrocode}
7550 %
7551 % \begin{macrocode}
7552 \@@_msg_new:nnn { Arrow~not~in~last~column }
7553 {
7554 Bad~use~of~\l_@@_string_Arrow_for_msg_str.\\
7555 You~should~use~the~command~\l_@@_string_Arrow_for_msg_str\
7556 only~in~the~last~column~(column~\int_use:N\l_@@_nb_cols_int)~
7557 in~the~row~\int_use:N \g_@@_line_int\
7558 of~your~environment~\{\l_@@_type_env_str\}.\\
7559 However~you~can~go~on~for~this~time.
7560 \@@_potential_body_i:
7561 }
7562 { \@@_potential_body_ii: }
7563 % \end{macrocode}
7564 %
7565 % \begin{macrocode}
7566 \@@_msg_new:nn { Wrong~line~in~Arrow }
7567 {
7568 Wrong~line.\\
7569 The~specification~of~line~'#1'~you~use~in~the~command~
7570 \l_@@_string_Arrow_for_msg_str\
7571 in~the~'code-after'~of~\{\l_@@_type_env_str\}~doesn't~exist. \\
7572 \c_@@_option_ignored_str
7573 }
7574 % \end{macrocode}
7575 %
7576 % \begin{macrocode}
7577 \@@_msg_new:nn { Both~lines~are~equal }
7578 {
7579 Both~lines~are~equal.\\
7580 In~the~'code-after'~of~\{\l_@@_type_env_str\}~you~try~to~
7581 draw~an~arrow~going~to~itself~from~the~line~'#1'.~This~is~not~possible. \\
7582 \c_@@_option_ignored_str
7583 }
7584 % \end{macrocode}
7585 %
7586 % \begin{macrocode}
7587 \@@_msg_new:nn { Wrong~line~specification~in~MultiArrow }
7588 {
7589 Wrong~line~specification.\\
7590 The~specification~of~line~'#1'~doesn't~exist. \\
7591 If~you~go~on,~it~will~be~ignored~for~\token_to_str:N \MultiArrow.
7592 }
7593 % \end{macrocode}
7594 %
7595 % \begin{macrocode}
7596 \@@_msg_new:nn { Too~small~specification~for~MultiArrow }
7597 {
7598 Too~small~specification.\\
7599 The~specification~of~lines~you~gave~to~\token_to_str:N \MultiArrow\
7600 is~too~small:~you~need~at~least~two~lines. \\
7601 \c_@@_command_ignored_str
7602 }
7603 % \end{macrocode}
7604 %
7605 %
7606 % \begin{macrocode}
7607 \@@_msg_new:nn { Not~allowed~in~DispWithArrows }
7608 {
7609 Forbidden~command.\\
7610 The~command~\token_to_str:N #1
7611 is~allowed~only~in~the~last~column~
7612 (column~\int_use:N\l_@@_nb_cols_int)~of~\{\l_@@_type_env_str\}. \\
7613 \c_@@_option_ignored_str
7614 }
7615 % \end{macrocode}
7616 %
7617 % \begin{macrocode}
7618 \@@_msg_new:nn { Not~allowed~in~WithArrows }
7619 {
7620 Forbidden~command.\\
7621 The~command~\token_to_str:N #1 is~not~allowed~in~\{\l_@@_type_env_str\}~
7622 (it's~allowed~in~the~last~column~of~\{DispWithArrows\}). \\
7623 \c_@@_option_ignored_str
7624 }
7625 % \end{macrocode}
7626 %
7627 % \begin{macrocode}
7628 %<*LaTeX>
7629 \@@_msg_new:nn { tag*~without~amsmath }
7630 {
7631 amsmath~not~loaded.\\
7632 We~can't~use~\token_to_str:N\tag*~because~you~haven't~loaded~amsmath~
7633 (or~mathtools). \\
7634 If~you~go~on,~the~command~\token_to_str:N\tag\
7635 will~be~used~instead.
7636 }
7637 % \end{macrocode}
7638 %
7639 % \begin{macrocode}
7640 \@@_msg_new:nn { Multiple~tags }
7641 {
7642 Multiple~tags.\\
7643 You~can't~use~twice~the~command~\token_to_str:N\tag\
7644 in~a~line~of~the~environment~\{\l_@@_type_env_str\}. \\
7645 If~you~go~on,~the~tag~'#1'~will~be~used.
7646 }
7647 % \end{macrocode}
7648 %
7649 %
7650 % \begin{macrocode}
7651 \@@_msg_new:nn { Multiple~labels }
7652 {
7653 Multiple~labels.\\
7654 Normally,~we~can't~use~the~command~\token_to_str:N\label\
7655 twice~in~a~line~of~the~environment~\{\l_@@_type_env_str\}. \\
7656 However,~you~can~go~on.~
7657 \IfPackageLoadedT { showlabels }
7658 { However,~only~the~last~label~will~be~shown~by~showlabels.~ }
7659 If~you~don't~want~to~see~this~message~again,~you~can~use~the~option~
7660 'allow-multiple-labels'~at~the~global~or~environment~level.
7661 }
7662 % \end{macrocode}
7663 %
7664 % \begin{macrocode}
7665 \@@_msg_new:nn { Multiple~labels~with~cleveref }
7666 {
7667 Multiple~labels.\\
7668 Since~you~use~cleveref,~you~can't~use~the~command~\token_to_str:N\label\
7669 twice~in~a~line~of~the~environment~\{\l_@@_type_env_str\}. \\
7670 If~you~go~on,~you~may~have~undefined~references.
7671 }
7672 %</LaTeX>
7673 % \end{macrocode}
7674 %
7675 %
7676 % \begin{macrocode}
7677 \@@_msg_new:nn { Inexistent~v-node }
7678 {
7679 There~is~a~problem.\\
7680 Maybe~you~have~put~a~command~\token_to_str:N\cr\
7681 instead~of~a~command~\token_to_str:N\\~at~the~end~of~
7682 the~row~\l_tmpa_int\
7683 of~your~environment~\{\l_@@_type_env_str\}. \\
7684 This~error~is~fatal.
7685 }
7686 % \end{macrocode}
7687 %
7688 % \bigskip
7689 % The following error when the user tries to use the option |xoffset| in mode
7690 % |group| or |groups| (in fact, it's possible to use the option |xoffset| if
7691 % there is only \emph{one} arrow: of course, the option |group| and |groups| do
7692 % not make sense in this case but, maybe, the option was set in a
7693 % |\WithArrowsOptions|).
7694 % \begin{macrocode}
7695 \@@_msg_new:nn { Option~xoffset~forbidden }
7696 {
7697 Incorrect~key.\\
7698 You~can't~use~the~option~'xoffset'~in~the~command~
7699 \l_@@_string_Arrow_for_msg_str\ in~the~row~\int_use:N \g_@@_line_int\
7700 of~your~environment~\{\l_@@_type_env_str\}~
7701 because~you~are~using~the~option~
7702 ' \int_compare:nNnTF \l_@@_pos_arrow_int = 7
7703 { group }
7704 { groups } '.~It's~possible~for~an~independent~arrow~or~if~there~is~
7705 only~one~arrow. \\
7706 \c_@@_option_ignored_str
7707 }
7708 % \end{macrocode}
7709 %
7710 % \begin{macrocode}
7711 \@@_msg_new:nnn { Duplicate~name }
7712 {
7713 Duplicate~name.\\
7714 The~name~'\l_keys_value_tl'~is~already~used~and~you~shouldn't~use~
7715 the~same~environment~name~twice.~You~can~go~on,~but,~
7716 maybe,~you~will~have~incorrect~results. \\
7717 For~a~list~of~the~names~already~used,~type~H~<return>. \\
7718 If~you~don't~want~to~see~this~message~again,~use~the~option~
7719 'allow-duplicate-names'.
7720 }
7721 {
7722 The~names~already~defined~in~this~document~are:~
7723 \seq_use:Nnnn \g_@@_names_seq { ,~ } { ,~ } { ~and~ }.
7724 }
7725 % \end{macrocode}
7726 %
7727 %
7728 % \begin{macrocode}
7729 \@@_msg_new:nn { Invalid~specification~for~MultiArrow }
7730 {
7731 Invalid~specification.\\
7732 The~specification~of~rows~for~\token_to_str:N\MultiArrow\
7733 (i.e.~#1)~is~invalid. \\
7734 \c_@@_command_ignored_str
7735 }
7736 % \end{macrocode}
7737 %
7738 %
7739 % \subsection{The command \textbackslash WithArrowsNewStyle}
7740 %
7741 % A new key defined with |\WithArrowsNewStyle| will not be available at the
7742 % local level.
7743 % \begin{macrocode}
7744 %<*LaTeX>
7745 \NewDocumentCommand \WithArrowsNewStyle { m m }
7746 %</LaTeX>
7747 %<*plain-TeX>
7748 \cs_new_protected:Npn \WithArrowsNewStyle #1 #2
7749 %</plain-TeX>
7750 {
7751 \keys_if_exist:nnTF { WithArrows / Global } { #1 }
7752 { \@@_error:nn { Key~already~defined } { #1 } }
7753 {
7754 % \end{macrocode}
7755 % First, we detect whether there is unknown keys in |#2| by storing in
7756 % |\l_tmpa_seq| the list of the unknown keys.
7757 % \begin{macrocode}
7758 \seq_clear:N \l_tmpa_seq
7759 \keyval_parse:NNn \@@_valid_key:n \@@_valid_key:nn { #2 }
7760 \seq_if_empty:NTF \l_tmpa_seq
7761 {
7762 \seq_put_right:Ne \l_@@_options_WithArrows_seq
7763 { \tl_to_str:n { #1 } }
7764 \seq_put_right:Ne \l_@@_options_DispWithArrows_seq
7765 { \tl_to_str:n { #1 } }
7766 \seq_put_right:Ne \l_@@_options_WithArrowsOptions_seq
7767 { \tl_to_str:N { #1 } }
7768 \keys_precompile:nnc
7769 { WithArrows / WithArrowsOptions }
7770 { #2 }
7771 { @@ _ style _ #1 _ tl }
7772 \keys_define:nn { WithArrows / Global }
7773 { #1 .code:n = \use:c { @@ _ style _ #1 _ tl } }
7774 }
7775 { \@@_error:nn { Impossible~style } { #1 } }
7776 }
7777 }
7778 % \end{macrocode}
7779 %
7780 % \begin{macrocode}
7781 \@@_msg_new:nn { Impossible~style }
7782 {
7783 Impossible~style.\\
7784 It's~impossible~to~define~the~style~'#1'~
7785 because~it~contains~unknown~keys:~'
7786 \seq_use:Nnnn \l_tmpa_seq { '~and~' } { ',~'} { ',~and~}'.
7787 }
7788 % \end{macrocode}
7789 %
7790 % \begin{macrocode}
7791 \cs_new_protected:Npn \@@_valid_key:n #1
7792 {
7793 \keys_if_exist:nnF { WithArrows / Global } { #1 }
7794 { \seq_put_right:Nn \l_tmpa_seq { #1 } }
7795 }
7796 \cs_new_protected:Npn \@@_valid_key:nn #1 #2
7797 {
7798 \keys_if_exist:nnF { WithArrows / Global } { #1 }
7799 { \seq_put_right:Nn \l_tmpa_seq { #1 } }
7800 }
7801 % \end{macrocode}
7802 %
7803 % \begin{macrocode}
7804 \@@_msg_new:nn { Key~already~defined }
7805 {
7806 Key~already~defined.\\
7807 The~key~'#1'~is~already~defined. \\
7808 If~you~go~on,~your~instruction~\token_to_str:N\WithArrowsNewStyle\
7809 will~be~ignored.
7810 }
7811 % \end{macrocode}
7812 %
7813 %
7814 % \subsection{The options up and down}
7815 %
7816 % The options |up| and |down| are available for individual arrows. The
7817 % corresponding code is given here. It is independent of the main code of the
7818 % extension \pkg{witharrows}.
7819 %
7820 % This code is the only part of the code of \pkg{witharrows} which uses the the
7821 % Tikz library |calc|. That's why we have decided not to load by default this
7822 % library. If it is not loaded, the user will have an error only when using the
7823 % option |up| or the option |down|.
7824 %
7825 % \bigskip
7826 % The keys |up| and |down| can be used with a value. This value is a list of
7827 % pairs key-value specific to the options |up| and |down|.
7828 % \begin{itemize}
7829 % \item The key |radius| is the radius of the rounded corner of the arrow.
7830 % \item The key |width| is the width of the horizontal part of the arrow. The
7831 % corresponding dimension is |\l_@@_arrow_width_dim|. By convention, a value of
7832 % $0$~pt for |\l_@@_arrow_width_dim| means that the option |width| has been used
7833 % with the special value |min| and a value of |\c_max_dim| means that it has
7834 % been used with the value |max|.
7835 % \end{itemize}
7836 %
7837 % \begin{macrocode}
7838 \keys_define:nn { WithArrows / up-and-down }
7839 {
7840 radius .dim_set:N = \l_@@_up_and_down_radius_dim ,
7841 radius .value_required:n = true ,
7842 width .code:n =
7843 \str_case:nnF { #1 }
7844 {
7845 { min } { \dim_zero:N \l_@@_arrow_width_dim }
7846 { max } { \dim_set_eq:NN \l_@@_arrow_width_dim \c_max_dim }
7847 }
7848 { \dim_set:Nn \l_@@_arrow_width_dim { #1 } } ,
7849 width .value_required:n = true ,
7850 unknown .code:n = \@@_error:n { Option~unknown~for~up-and-down }
7851 }
7852 % \end{macrocode}
7853 %
7854 %
7855 % \begin{macrocode}
7856 \@@_msg_new:nn { Option~unknown~for~up-and-down }
7857 {
7858 Unknown~option.\\
7859 The~option~'\l_keys_key_str'~is~unknown.~\c_@@_option_ignored_str
7860 }
7861 % \end{macrocode}
7862 %
7863 %
7864 %
7865 % \bigskip
7866 % The token list |\c_@@_tikz_code_up_tl| is the value of |tikz-code| which will
7867 % be used for an option |up|.
7868 %
7869 % \bigskip
7870 % \begin{macrocode}
7871 %<*LaTeX>
7872 \tl_const:Nn \c_@@_tikz_code_up_tl
7873 {
7874 % \end{macrocode}
7875 % First the case when the key |up| is used with |width=max| (that's the default
7876 % behaviour).
7877 % \begin{macrocode}
7878 \dim_compare:nNnTF \l_@@_arrow_width_dim = \c_max_dim
7879 {
7880 \draw [ rounded~corners = \l_@@_up_and_down_radius_dim ]
7881 let \p1 = ( #1 ) , \p2 = ( #2 )
7882 in (\p1) -- node
7883 {
7884 \dim_set:Nn \l_tmpa_dim { \x2 - \x1 }
7885 \begin { varwidth } \l_tmpa_dim
7886 % \end{macrocode}
7887 % |\narrowragged| is a command of the package \pkg{varwidth}.
7888 % \begin{macrocode}
7889 \narrowragged
7890 #3
7891 \end { varwidth }
7892 }
7893 (\x2,\y1) -- (\p2) ;
7894 }
7895 % \end{macrocode}
7896 % Now the case where the key |up| is used with |width=|\textsl{value} with
7897 % \textsl{value} equal to |min| or a numeric value. The instruction |\path|
7898 % doesn't draw anything: its aim is to compute the natural width of the label of
7899 % the arrow. We can't use |\pgfextra| here because of the |\hbox_gset:Nn|.
7900 % \begin{macrocode}
7901 {
7902 \path
7903 let \p1 = ( #1 ) , \p2 = ( #2 )
7904 in node
7905 {
7906 % \end{macrocode}
7907 % The length |\l_tmpa_dim| will be the maximal width of the box composed by the
7908 % environment |{varwidth}|.
7909 % \begin{macrocode}
7910 \dim_set:Nn \l_tmpa_dim
7911 { \x2 - \x1 - \l_@@_up_and_down_radius_dim }
7912 \dim_compare:nNnF \l_@@_arrow_width_dim = \c_zero_dim
7913 {
7914 \dim_set:Nn \l_tmpa_dim
7915 { \dim_min:nn \l_tmpa_dim \l_@@_arrow_width_dim }
7916 }
7917 % \end{macrocode}
7918 % Now, the length |\l_tmpa_dim| is computed. We can compose the label in the box
7919 % |\g_tmpa_box|. We have to do a global affectation to be able to exit the node.
7920 % \begin{macrocode}
7921 \hbox_gset:Nn \g_tmpa_box
7922 {
7923 \begin { varwidth } \l_tmpa_dim
7924 \narrowragged
7925 #3
7926 \end { varwidth }
7927 }
7928 % \end{macrocode}
7929 % The length |\g_tmpa_dim| will be the width of the arrow (+ the radius of the
7930 % corner).
7931 % \begin{macrocode}
7932 \dim_compare:nNnTF \l_@@_arrow_width_dim > \c_zero_dim
7933 { \dim_gset_eq:NN \g_tmpa_dim \l_@@_arrow_width_dim }
7934 { \dim_gset:Nn \g_tmpa_dim { \box_wd:N \g_tmpa_box } }
7935 \dim_gadd:Nn \g_tmpa_dim \l_@@_up_and_down_radius_dim
7936 } ;
7937 \draw
7938 let \p1 = ( #1 ) , \p2 = ( #2 )
7939 in (\x2-\g_tmpa_dim,\y1)
7940 -- node { \box_use:N \g_tmpa_box }
7941 (\x2-\l_@@_up_and_down_radius_dim,\y1)
7942 [ rounded~corners = \l_@@_up_and_down_radius_dim ]
7943 -| (\p2) ;
7944 }
7945 }
7946 %</LaTeX>
7947 %<*plain-TeX>
7948 \tl_const:Nn \c_@@_tikz_code_up_tl
7949 {
7950 \dim_case:nnF \l_@@_arrow_width_dim
7951 {
7952 \c_max_dim
7953 {
7954 \draw [ rounded~corners = \l_@@_up_and_down_radius_dim ]
7955 let \p1 = ( #1 ) , \p2 = ( #2 )
7956 in (\p1) -- node { #3 } (\x2,\y1) -- (\p2) ;
7957 }
7958 \c_zero_dim
7959 {
7960 \path node
7961 {
7962 \hbox_gset:Nn \g_tmpa_box { #3 }
7963 \dim_gset:Nn \g_tmpa_dim
7964 { \box_wd:N \g_tmpa_box + \l_@@_up_and_down_radius_dim }
7965 } ;
7966 \draw
7967 let \p1 = ( #1 ) , \p2 = ( #2 )
7968 in (\x2-\g_tmpa_dim,\y1)
7969 -- node { \box_use:N \g_tmpa_box }
7970 (\x2-\l_@@_up_and_down_radius_dim,\y1)
7971 [ rounded~corners = \l_@@_up_and_down_radius_dim ]
7972 -| (\p2) ;
7973 }
7974 }
7975 {
7976 \draw
7977 let \p1 = ( #1 ) , \p2 = ( #2 )
7978 in (\x2 - \l_@@_arrow_width_dim - \l_@@_up_and_down_radius_dim,\y1)
7979 -- node { #3 } (\x2-\l_@@_up_and_down_radius_dim,\y1)
7980 [ rounded~corners = \l_@@_up_and_down_radius_dim ]
7981 -| (\p2) ;
7982 }
7983 }
7984 %</plain-TeX>
7985 % \end{macrocode}
7986 %
7987 %
7988 % \bigskip
7989 % The code for an arrow of type |down| is similar to the previous code (for an
7990 % arrow of type |up|).
7991 % \begin{macrocode}
7992 %<*LaTeX>
7993 \tl_const:Nn \c_@@_tikz_code_down_tl
7994 {
7995 \dim_compare:nNnTF \l_@@_arrow_width_dim = \c_max_dim
7996 {
7997 \draw [ rounded~corners = \l_@@_up_and_down_radius_dim ]
7998 let \p1 = ( #1 ) , \p2 = ( #2 )
7999 in (\p1) -- (\x1,\y2) -- node
8000 {
8001 \dim_set:Nn \l_tmpa_dim { \x1 - \x2 }
8002 \begin { varwidth } \l_tmpa_dim
8003 \narrowragged
8004 #3
8005 \end { varwidth }
8006 }
8007 (\p2) ;
8008 }
8009 {
8010 \path
8011 let \p1 = ( #1 ) , \p2 = ( #2 )
8012 in node
8013 {
8014 \hbox_gset:Nn \g_tmpa_box
8015 {
8016 \dim_set:Nn \l_tmpa_dim
8017 % \end{macrocode}
8018 % The $2$~mm are for the tip of the arrow. We don't want the label of the arrow
8019 % too close to the tip of arrow (we assume that to the tip of the arrow has its
8020 % standard position, that is at the end of the arrow.).
8021 % \begin{macrocode}
8022 { \x1 - \x2 - \l_@@_up_and_down_radius_dim - 2 mm }
8023 \begin { varwidth } \l_tmpa_dim
8024 \narrowragged
8025 #3
8026 \end { varwidth }
8027 }
8028 \dim_compare:nNnTF \l_@@_arrow_width_dim > \c_zero_dim
8029 { \dim_gset_eq:NN \g_tmpa_dim \l_@@_arrow_width_dim }
8030 { \dim_gset:Nn \g_tmpa_dim { \box_wd:N \g_tmpa_box } }
8031 \dim_gadd:Nn \g_tmpa_dim \l_@@_up_and_down_radius_dim
8032 } ;
8033
8034 \draw
8035 let \p1 = ( #1 ) , \p2 = ( #2 )
8036 in (\p1)
8037 { [ rounded~corners = \l_@@_up_and_down_radius_dim ] -- (\x1,\y2) }
8038 -- (\x1-\l_@@_up_and_down_radius_dim,\y2)
8039 -- node { \box_use:N \g_tmpa_box } (\x1-\g_tmpa_dim,\y2)
8040 -- ++ (-2mm,0) ;
8041 }
8042 }
8043 %</LaTeX>
8044 %
8045 %<*plain-TeX>
8046 \tl_const:Nn \c_@@_tikz_code_down_tl
8047 {
8048 \dim_case:nnF \l_@@_arrow_width_dim
8049 {
8050 \c_max_dim
8051 {
8052 \draw [ rounded~corners = \l_@@_up_and_down_radius_dim ]
8053 let \p1 = ( #1 ) , \p2 = ( #2 )
8054 in (\p1) -- (\x1,\y2) -- node { #3 } (\p2) ;
8055 }
8056 \c_zero_dim
8057 {
8058 \path node
8059 {
8060 \hbox_gset:Nn \g_tmpa_box { #3 }
8061 \dim_gset:Nn \g_tmpa_dim
8062 { \box_wd:N \g_tmpa_box + \l_@@_up_and_down_radius_dim }
8063 } ;
8064 \draw
8065 let \p1 = ( #1 ) , \p2 = ( #2 )
8066 in (\p1)
8067 { [ rounded~corners = \l_@@_up_and_down_radius_dim ] -- (\x1,\y2) }
8068 -- (\x1-\l_@@_up_and_down_radius_dim,\y2)
8069 -- node { \box_use:N \g_tmpa_box } (\x1-\g_tmpa_dim,\y2)
8070 -- ++ (-2mm,0) ;
8071 }
8072 }
8073 {
8074 \draw
8075 let \p1 = ( #1 ) , \p2 = ( #2 )
8076 in (\p1)
8077 { [ rounded~corners = \l_@@_up_and_down_radius_dim ] -- (\x1,\y2) }
8078 -- (\x1-\l_@@_up_and_down_radius_dim,\y2)
8079 -- node { #3 }
8080 (\x1 - \l_@@_arrow_width_dim - \l_@@_up_and_down_radius_dim,\y2)
8081 -- ++ (-2mm,0) ;
8082 }
8083 }
8084 %</plain-TeX>
8085 % \end{macrocode}
8086 %
8087 % \bigskip
8088 % We recall that the options of the individual arrows are scanned twice. First,
8089 % when are scanned when the command |\Arrow| occurs (we try to know whether the
8090 % arrow is ``individual'', etc.). That's the first pass.
8091 % \begin{macrocode}
8092 \keys_define:nn { WithArrows / Arrow / FirstPass }
8093 {
8094 up .code:n = \@@_set_independent_bis: ,
8095 down .code:n = \@@_set_independent_bis: ,
8096 up .default:n = NoValue ,
8097 down .default:n = NoValue
8098 }
8099 % \end{macrocode}
8100 %
8101 % \bigskip
8102 % The options are scanned a second time when the arrow is actually drawn. That's
8103 % the second pass.
8104 % \begin{macrocode}
8105 \keys_define:nn { WithArrows / Arrow / SecondPass }
8106 {
8107 up .code:n =
8108 \str_if_empty:NT \l_@@_previous_key_str
8109 {
8110 \str_set:Nn \l_@@_previous_key_str { up }
8111 \cs_if_exist:NTF \tikz@library@calc@loaded
8112 {
8113 \keys_set:no { WithArrows / up-and-down } \l_keys_value_tl
8114 \int_set:Nn \l_@@_pos_arrow_int 1
8115 % \end{macrocode}
8116 % We have to set |\l_@@_wrap_lines_bool| to |false| because, otherwise, if the
8117 % option |wrap_lines| is used at a higher level (global or environment), we will
8118 % have a special affectation to |tikz-code| that will overwrite our affectation.
8119 % \begin{macrocode}
8120 \bool_set_false:N \l_@@_wrap_lines_bool
8121 % \end{macrocode}
8122 % The main action occurs now. We change the value of the |tikz-code|.
8123 % \begin{macrocode}
8124 \tl_set_eq:NN \l_@@_tikz_code_tl \c_@@_tikz_code_up_tl
8125 }
8126 { \@@_error:n { calc~not~loaded } }
8127 } ,
8128 down .code:n =
8129 \str_if_empty:NT \l_@@_previous_key_str
8130 {
8131 \str_set:Nn \l_@@_previous_key_str { down }
8132 \cs_if_exist:NTF \tikz@library@calc@loaded
8133 {
8134 \keys_set:no { WithArrows / up-and-down } \l_keys_value_tl
8135 \int_set:Nn \l_@@_pos_arrow_int 1
8136 \bool_set_false:N \l_@@_wrap_lines_bool
8137 \tl_set_eq:NN \l_@@_tikz_code_tl \c_@@_tikz_code_down_tl
8138 }
8139 { \@@_error:n { calc~not~loaded } }
8140 }
8141 }
8142 % \end{macrocode}
8143 %
8144 %
8145 % \begin{macrocode}
8146 \seq_put_right:Nn \l_@@_options_Arrow_seq { down }
8147 \seq_put_right:Nn \l_@@_options_Arrow_seq { up }
8148 % \end{macrocode}
8149 %
8150 %
8151 % \begin{macrocode}
8152 \@@_msg_new:nn { calc~not~loaded }
8153 {
8154 calc~not~loaded.\\
8155 You~can't~use~the~option~'\l_keys_key_str'~because~you~don't~have~loaded~the~
8156 Tikz~library~'calc'.You~should~add~'\token_to_str:N\usetikzlibrary{calc}'~
8157 ~in~the~preamble~of~your~document. \\
8158 \c_@@_option_ignored_str
8159 }
8160 % \end{macrocode}
8161 %
8162 %
8163 % \begin{macrocode}
8164 %<*plain-TeX>
8165 \catcode `\@ = 12
8166 \ExplSyntaxOff
8167 %</plain-TeX>
8168 % \end{macrocode}
8169 %
8170 % \section{History}
8171 %
8172 % \subsection*{Changes between 2.8 and 2.9}
8173 %
8174 % Argument |<...>| for the command |\Arrow| in the class Beamer.
8175 %
8176 % \subsection*{Changes between 2.7 and 2.8}
8177 %
8178 % New key |right-overlap|
8179 %
8180 % \subsection*{Changes between 2.6b and 2.7}
8181 %
8182 % Correction of a bug: when the key |wrap-lines| was in force, the content of
8183 % the annotations was not ``flush left'' by default as it should be (but justified).
8184 %
8185 %
8186 % \subsection*{Changes between 2.6 and 2.6a (and 2.6b)}
8187 %
8188 % Replacement of |\hbox_unpack_clear:N| by |\hbox_unpack_drop:N| since
8189 % |\hbox_unpack_clear:N| is now deprecated in L3.
8190 %
8191 % Version 2.6d: correction of a bug (cf. question 628461 on TeX StackExchange).
8192 %
8193 % \subsection*{Changes between 2.5 and 2.5.1}
8194 %
8195 % Correction of the erroneous programmation of the nodes aliases.
8196 %
8197 %
8198 % \subsection*{Changes between 2.4 and 2.5}
8199 %
8200 % Arrows of type |o| which are \emph{over} other arrows.
8201 %
8202 % \pkg{witharrows} now requires and loads \pkg{varwidth}
8203 %
8204 % \subsection*{Changes between 2.3 and 2.4}
8205 %
8206 % Correction of a bug with |{DispWithArrows}| : cf. question 535989 on |TeX StackExchange|.
8207 %
8208 % \subsection*{Changes between 2.2 and 2.3}
8209 %
8210 % Two options for the arrows of type |up| and |down|: |width| and |radius|.
8211 %
8212 % \subsection*{Changes between 2.1 and 2.2}
8213 %
8214 % Addition of |\normalbaselines| at the beginning of |\@@_post_halign:|.
8215 %
8216 % The warning for an environment ending by |\\| has been transformed in |error|.
8217 %
8218 % \subsection*{Changes between 2.0 and 2.1}
8219 %
8220 % Option |max-length-of-arrow|.
8221 %
8222 % Validation with regular expression for the first argument of |\MultiArrow|.
8223 %
8224 % \subsection*{Changes between 1.18 and 2.0}
8225 %
8226 % A version of \pkg{witharrows} is available for plain-TeX.
8227 %
8228 % \subsection*{Changes between 1.17 and 1.18}
8229 %
8230 % New option |<...>| for |{DispWithArrows}|.
8231 %
8232 % Option |subequations|.
8233 %
8234 % Warning when |{WithArrows}| or |{DispWithArrows}| ends by "\\".
8235 %
8236 % No space before an environment |{DispWithArrows}| if we are at the beginning
8237 % of a |{minipage}|.
8238 %
8239 % \subsection*{Changes between 1.16 and 1.17}
8240 %
8241 % Option |format|.
8242 %
8243 % \subsection*{Changes between 1.15 and 1.16}
8244 %
8245 % Option |no-arrows|
8246 %
8247 % The behaviour of |{DispWithArrows}| after an |\item| of a LaTeX list has been
8248 % changed : no vertical is added. The previous behaviour can be restored with
8249 % the option |standard-behaviour-with-items|.
8250 %
8251 % A given name can no longer be used for two distinct environments. However,
8252 % it's possible to deactivate this control with the option
8253 % |allow-duplicate-names|.
8254 %
8255 %
8256 % \subsection*{Changes between 1.14 and 1.15}
8257 %
8258 % Option |new-group| to start a new group of arrows (only available when the
8259 % environment is composed with the option |groups|).
8260 %
8261 % Tikz externalization is now deactivated in the environments of the
8262 % extension \pkg{witharrows}.\footnote{Before this version, there was an error
8263 % when using \pkg{witharrows} with Tikz externalization. In any case, it's not
8264 % possible to externalize the Tikz elements constructed by \pkg{witharrows}
8265 % because they use the options |overlay| and |remember picture|.}
8266 %
8267 %
8268 % \subsection*{Changes between 1.13 and 1.14}
8269 %
8270 % New options |up| and |down| for the arrows.
8271 %
8272 % \smallskip
8273 % Replacement of some options |O { }| in commands and environments defined with
8274 % \pkg{xparse} by |! O { }| (a recent version of \pkg{xparse} introduced
8275 % the specifier |!| and modified the default behaviour of the last optional
8276 % arguments:
8277 % |//www.texdev.net/2018/04/21/xparse-optional-arguments-at-the-end|).
8278 %
8279 % \smallskip
8280 % Modification of the code of |\WithArrowsNewStyle| following a correction of a
8281 % bug in \pkg{l3keys} in the version of \pkg{l3kernel} of 2019/01/28.
8282 %
8283 % New error message |Inexistent~v-node| to avoid a \pkg{pgf} error.
8284 %
8285 % The error |Option incompatible with 'group(s)'| was suppressed in the version
8286 % 1.12 but this was a mistake since this error is used with the option |xoffset|
8287 % at the local level. The error is put back.
8288 %
8289 % \subsection*{Changes between 1.12 and 1.13}
8290 %
8291 % Options |start-adjust|, |end-adjust| and |adjust|.
8292 %
8293 % This version is not stricty compatible with previous ones. To restore the
8294 % behaviour of the previous versions, one has to use the option |adjust| with
8295 % the value $0$~pt:
8296 %
8297 % \begin{Verbatim}
8298 % \WithArrowsOptions{adjust = 0pt}
8299 % \end{Verbatim}
8300 %
8301 % \subsection*{Changes between 1.11 and 1.12}
8302 %
8303 % New command |\tagnextline|.
8304 %
8305 % New option |tagged-lines|.
8306 %
8307 % An option of position (|ll|, |lr|, |rl|, |rr| or |i|) is now allowed at the
8308 % local level even if the option |group| or the option |groups| is used at the
8309 % global or environment level.
8310 %
8311 % Compatibility of |{DispWithArrows}| with |\qedhere| of \pkg{amsthm}.
8312 %
8313 % Compatibility with the packages \pkg{refcheck}, \pkg{showlabels} and
8314 % \pkg{listlbls}.
8315 %
8316 % The option |\AllowLineWithoutAmpersand| is deprecated because lines without
8317 % ampersands are now always allowed.
8318 %
8319 % \subsection*{Changes between 1.10 and 1.11}
8320 %
8321 % New commands |\WithArrowsNewStyle| and |\WithArrowsRightX|.
8322 %
8323 % \subsection*{Changes between 1.9 and 1.10}
8324 %
8325 % If the option |wrap-lines| is used, the option ``|text width|'' of Tikz is
8326 % still active: if the value given to ``|text width|'' is lower than the width
8327 % computed by |wrap-lines|, this value is used to wrap the lines.
8328 %
8329 % The option |wrap-lines| is now fully compatible with the class option |leqno|.
8330 %
8331 % Correction of a bug: |\nointerlineskip| and |\makebox[.6\linewidth]{}| should
8332 % be inserted in |{DispWithArrows}| only in vertical mode.
8333 %
8334 % \subsection*{Changes between 1.8 and 1.9}
8335 %
8336 % New option |wrap-lines| for the environments |{DispWithArrows}| and
8337 % |{DispWithArrows*}|.
8338 %
8339 % \subsection*{Changes between 1.7 and 1.8}
8340 %
8341 % The numbers and tags of the environment |{DispWithArrows}| are now compatible
8342 % with all the major LaTeX packages concerning references (\pkg{autonum},
8343 % \pkg{cleveref}, \pkg{fancyref}, \pkg{hyperref}, \pkg{prettyref},
8344 % \pkg{refstyle}, \pkg{typedref} and \pkg{varioref}) and with the options
8345 % |showonlyrefs| and |showmanualtags| of \pkg{mathtools}.
8346 %
8347 % \subsection*{Changes between 1.6 and 1.7}
8348 %
8349 % New environments |{DispWithArrows}| and |{DispWithArrows*}|.
8350 %
8351 % \subsection*{Changes between versions 1.5 and 1.6}
8352 %
8353 % The code has been improved to be faster and the Tikz library |calc| is no
8354 % longer required.
8355 %
8356 % A new option |name| is available for the environments |{WithArrows}|.
8357 %
8358 % \subsection*{Changes between versions 1.4 and 1.5}
8359 %
8360 % The Tikz code used to draw the arrows can be changed with the option
8361 % |tikz-code|.
8362 %
8363 % Two new options |code-before| and |code-after| have been added at the
8364 % environment level.
8365 %
8366 % A special version of |\Arrow| is available in |code-after| in order to draw
8367 % arrows in nested environments.
8368 %
8369 % A command |\MultiArrow| is available in |code-after| to draw arrows of other
8370 % shapes.
8371 %
8372 % \subsection*{Changes between versions 1.3 and 1.4}
8373 %
8374 % The package \pkg{footnote} is no longer loaded by default. Instead, two
8375 % options |footnote| and |footnotehyper| have been added. In particular,
8376 % \pkg{witharrows} becomes compatible with \cls{beamer}.
8377 %
8378 % \subsection*{Changes between versions 1.2 and 1.3}
8379 %
8380 % New options |ygap| and |ystart| for fine tuning.
8381 %
8382 % \subsection*{Changes between versions 1.1 and 1.2}
8383 %
8384 % The package \pkg{witharrows} can now be loaded without having loaded
8385 % previously \pkg{tikz} and the libraries |arrow.meta| and |bending| (this
8386 % extension and these libraries are loaded silently by \pkg{witharrows}).
8387 %
8388 % New option |groups| (with a \emph{s})
8389 %
8390 % \subsection*{Changes between versions 1.0 and 1.1}
8391 %
8392 % Option for the command |\\| and option |interline|
8393 %
8394 % Compatibility with |\usetikzlibrary{babel}|
8395 %
8396 % Possibility of nested environments |{WithArrows}|
8397 %
8398 %
8399 % \tableofcontents
8400 %
8401 % \endinput
8402 % Local Variables:
8403 % TeX-fold-mode: t
8404 % TeX-fold-preserve-comments: nil
8405 % fill-column: 80
8406 % flyspell-mode: nil
8407 % End: