Transcription

The package witharrows for plain-TeX and LaTeX F. [email protected] 4, 2021AbstractThe LaTeX package witharrows provides environments {WithArrows} and {DispWithArrows}similar to the environments {aligned} and {align} of amsmath but with the possibility to drawarrows on the right side of the alignment. These arrows are usually used to give explanationsconcerning the mathematical calculus presented.In this document, we describe the LaTeX extension witharrows (however, witharrows can also be usedwith plain-TeX: see p. 23). This package can be used with xelatex, lualatex, pdflatex but alsoby the classical workflow latex-dvips-ps2pdf (or Adobe Distiller). This package loads the packagesl3keys2e, varwidth, tikz and the Tikz libraries arrows.meta and bending. The arrows are drawn withTikz and that’s why several compilations may be necessary.This package provides an environment {WithArrows} to construct alignments of equations witharrows for the explanations on the right side: \begin{WithArrows}A & (a 1) 2 \Arrow{we expand} \\& a 2 2a 1 % ------- don't put \\ here\end{WithArrows} A (a 1)2 a2 2a 1we expandThe arrow has been drawn with the command \Arrow on the row from which it starts. The command\Arrow must be used in the second column (the best way is to put it at the end of the second cell ofthe row as in the previous example).The environment {WithArrows} bears similarities with the environment {aligned} of amsmath (andmathtools). The extension witharrows also provides an environment {DispWithArrows} which issimilar to the environment {align} of amsmath: cf. p. 17.1Options for the shape of the arrowsThe command \Arrow has several options. These options can be put between square brackets, before,or after the mandatory argument.The option jump gives the number1 of rows the arrow must jump (the default value is, of course, 1). \begin{WithArrows}A & \bigl((a b) 1\bigr) 2 \Arrow[jump 2]{we expand} \\& (a b) 2 2(a b) 1 \\& a 2 2ab b 2 2a 2b 1\end{WithArrows} Thisdocument corresponds to the version 2.6c of witharrows, at the date of 2021/03/04.not possible to give a non-positive value to jump. See below (p. 2) the way to draw an arrow which goesbackwards.1 It’s1

A (a b) 1 2 (a b)2 2(a b) 12we expand2 a 2ab b 2a 2b 1It’s possible to put several arrows starting from the same row. \begin{WithArrows}A & \bigl((a b) 1\bigr) 2 \Arrow{}\Arrow{}[jump 2] \\& (a b) 2 2(a b) 1 \\& a 2 2ab b 2 2a 2b 1\end{WithArrows} 2A (a b) 1 (a b)2 2(a b) 1 a2 2ab b2 2a 2b 1The option xoffset shifts the arrow to the right (we usually don’t want the arrows to be stucked onthe text). The initial value of xoffset is 3 mm. \begin{WithArrows}A & \bigl((a b) 1\bigr) 2\Arrow[xoffset 1cm]{with \texttt{xoffset 1cm}} \\& (a b) 2 2(a b) 1\end{WithArrows} 2A (a b) 1 (a b)2 2(a b) 1with xoffset 1cmThe arrows are drawn with Tikz. That’s why the command \Arrow has an option tikz which canbe used to give to the arrow (in fact, the command \path of Tikz) the options proposed by Tikz forsuch an arrow. The following example gives an thick arrow. \begin{WithArrows}A & (a 1) 2 \Arrow[tikz thick]{we expand} \\& a 2 2a 1\end{WithArrows} A (a 1)2 a2 2a 1we expandIt’s also possible to change the arrowheads. For example, we can draw an arrow which goes backwardswith the Tikz option -. \begin{WithArrows}A & (a 1) 2 \Arrow[tikz -]{we factorize} \\& a 2 2a 1\end{WithArrows} A (a 1)2 a2 2a 1we factorizeIt’s also possible to suppress both tips of the arrow with the Tikz option “-”. \begin{WithArrows}A & (a 1) 2 \Arrow[tikz -]{very classical} \\& a 2 2a 1\end{WithArrows} 2

A (a 1)2very classical a2 2a 1In order to have straight arrows instead of curved ones, we must use the Tikz option “bend left 0”. \begin{WithArrows}A & (a 1) 2 \Arrow[tikz {bend left 0}]{we expand} \\& a 2 2a 1\end{WithArrows} A (a 1)2we expand a2 2a 1In fact, it’s possible to change more drastically the shape or the arrows with the option tikz-code(presented p. 23).It’s possible to use the Tikz option “text width” to control the width of the text associated to thearrow.2 \begin{WithArrows}A & \bigl((a b) 1\bigr) 2\Arrow[jump 2,tikz {text width 5.3cm}]{We have done.} \\& (a b) 2 2(a b) 1 \\& a 2 2ab b 2 2a 2b 1\end{WithArrows} 2A (a b) 1We have done a two-stages expansion (a b)2 2(a b) 122 a 2ab b 2a 2b 1but it would have been clever to expand with the multinomial theorem.In the environments {DispWithArrows} and {DispWithArrows*}, there is an option wrap-lines.With this option, the lines of the labels are automatically wrapped on the right: see p. 20.If we want to change the font of the text associated to the arrow, we can, of course, put a commandlike \bfseries, \large or \sffamily at the beginning of the text. But, by default, the texts arecomposed with a combination of \small and \itshape. When adding \bfseries at the beginningof the text, we won’t suppress the \small and the \itshape and we will consequently have a text ina bold, italic and small font. \begin{WithArrows}A & (a 1) 2 \Arrow{\bfseries we expand} \\& a 2 2a 1\end{WithArrows} A (a 1)2 a2 2a 1we expandIt’s possible to put commands \\ in the text to force new lines3 . However, if we put a \\ , a commandof font placed in the beginning of the text will have effect only until the first command \\ (like in anenvironment {tabular}). That’s why Tikz gives an option font to modify the font of the whole text.Nevertheless, if we use the option tikz {font {\bfseries}}, the default specification of \smalland \itshape will be overwritten.2 It’s possible to avoid the hyphenations of the words: use the Tikz option “align flush left” in LaTeX and“align {flushleft,nothyphenated}” in ConTeXt.3 By default, this is not possible in a Tikz node. However, in witharrows, the nodes are created with the optionalign left, and, thus, it becomes possible.3

\begin{WithArrows}A & (a 1) 2 \Arrow[tikz {font {\bfseries}}]{we expand} \\& a 2 2a 1\end{WithArrows} A (a 1)2we expand a2 2a 1If we want exactly the same result as previously, we have to give to the option font the value\itshape\small\bfseries.The options can be given directly between square brackets to the environment {WithArrows}. Theremust be no space between the \begin{WithArrows} and the opening bracket ([) of the options ofthe environment. Such options apply to all the arrows of the environment.4 \begin{WithArrows}[tikz blue]A & \bigl((a b) 1\bigr) 2 \Arrow{first expansion.} \\& (a b) 2 2(a b) 1 \Arrow{second expansion.} \\& a 2 2ab b 2 2a 2b 1\end{WithArrows} 2A (a b) 1first expansion. (a b)2 2(a b) 1second expansion. a2 2ab b2 2a 2b 1The environment {WithArrows} has an option displaystyle. With this option, all the elements arecomposed in \displaystyle (like in an environment {aligned} of amsmath).Without the option displaystyle: \begin{WithArrows}\int 0 1 (x 1) 2 dx& \int 0 1 (x 2 2x 1) dx\Arrow{linearity of integration}\\& \int 0 1 x 2 dx 2 \int 0 1 x dx \int 0 1 dx \\& \frac13 2\frac12 1 \\& \frac73\end{WithArrows} R1R1(x 1)2 dx 0 (x2 2x 1)dx0linearity of integrationR1R1R1 0 x2 dx 2 0 xdx 0 dx 1373 2 12 1The same example with the option displaystyle:Z 1Z 1(x2 2x 1)dx(x 1)2 dx 00ZZ1x2 dx 2 0Z1xdx 0linearity of integration1dx011 2 1327 34 They also apply to the nested environments {WithArrows} (with the logical exceptions of interline, code-beforeand code-after).4

Almost all the options can also be set at the document level with the command \WithArrowsOptions.In this case, the scope of the declarations is the current TeX group (these declarations are “semiglobal”). For example, if we want all the environments {WithArrows} composed in \displaystylewith blue arrows, we can write \WithArrowsOptions{displaystyle,tikz blue}.5\WithArrowsOptions{displaystyle,tikz blue} \begin{WithArrows}\sum {i 1} n (x i 1) 2& \sum {i 1} n (x i 2 2x i 1) \Arrow{by linearity}\\& \sum {i 1} n x i 2 2\sum {i 1} nx i n\end{WithArrows} nX(xi 1)2 i 1nX(x2i 2xi 1)i 1 nXi 1x2i 2nXby linearityxi ni 1The command \Arrow is recognized only in the environments {WithArrows}. If we have a command\Arrow previously defined, it’s possible to go on using it outside the environments {WithArrows}.However, a previouly defined command \Arrow may still be useful in an environment {WithArrows}.If we want to use it in such an environment, it’s possible to change the name of the command \Arrowof the package witharrows: there is an option command-name for this purpose. The new name of thecommand must be given to the option without the leading backslash.\NewDocumentCommand {\Arrow} {} {\longmapsto} \begin{WithArrows}[command-name Explanation]f & \bigl(x \Arrow (x 1) 2\bigr)\Explanation{we work directly on fonctions}\\& \bigl(x \Arrow x 2 2x 1\bigr)\end{WithArrows} f x 7 (x 1)2we work directly on fonctions x 7 x2 2x 1The environment {WithArrows} provides also two options code-before and code-after for LaTeXcode that will be executed at the beginning and at the end of the environment. These options arenot designed to be hooks (they are available only at the environment level and they do not apply tothe nested environments). \begin{WithArrows}[code-before \color{blue}]A & (a b) 2 \Arrow{we expand} \\& a 2 2ab b 2\end{WithArrows} A (a b)2 a2 2ab b2we expandSpecial commands are available in code-after: a command \WithArrowsNbLines which gives thenumber of lines ( rows) of the current environment (this is a command and not a counter), a specialform of the command \Arrow and the command \MultiArrow: these commands are described in thesection concerning the nested environments, p. 14.5 It’s also possible to configure witharrows by modifying the Tikz style WithArrows/arrow which is the style used bywitharrows when drawing an arrow. For example, to have the labels in blue with roman (upright) types, one can usethe following instruction: \tikzset{WithArrows/arrow/.append style {blue,font {}}}.5

2Numbers of columnsSo far, we have used the environment {WithArrows} with two columns. However, it’s possible to usethe environment with an arbitrary number of columns with the option format. The value given tothis option is like the preamble of an environment {array}, that is to say a sequence of letters r, cand l, but also R, C and L.New 2.6 The letters R, C and L add empty groups {} which provide correct spaces when thesecolumns contain symbols with the type \mathrel (such as , , etc.) or \mathbin (such as , ,etc.). This system is inspired by the environment {IEEEeqnarray} of the package IEEEtrantools.The initial value of the parameter format is, in fact, rL.For exemple, if we want only one column left-aligned, we use the option format l. \begin{WithArrows}[format l]f(x) \ge g(x) \Arrow{by squaring both sides} \\f(x) 2 \ge g(x) 2 \Arrow{by moving to left side} \\f(x) 2 - g(x) 2 \ge 0\end{WithArrows} f (x) g(x)f (x)2 g(x)2f (x)2 g(x)2 0by squaring both sidesby moving to left sideIn the following example, we use five columns all centered (the environment {DispWithArrows*} ispresented p. 17).\begin{DispWithArrows*}[format cCcCc,wrap-lines,tikz {align flush left},interline 1mm]k & \;\le\; & t & \;\le\; & k 1 \\\frac{1}{k 1} & \le & \frac{1}{t} & \le & \frac{1}{k}\Arrow{we can integrate the inequalities since k \leq k 1 } \\\int\limits k {k 1} \frac{d t}{k 1}& \le & \int\limits k {k 1} \frac{dt}{t}& \le & \int\limits k {k 1} \frac{dt}{k} \\\frac{1}{k 1} & \le & \ln(k 1)-\ln(k) & \le & \frac{1}{k}\end{DispWithArrows*}k t k 11k 1 1t k 1Rkdtk 11k 13 k 1Rkdtt ln(k 1) ln(k) 1kk 1Rkdtkwe can integrate the inequalities since k k 11kPrecise positioning of the arrowsThe environment {WithArrows} defines, during the composition of the array, two series of nodesmaterialized in red in the following example.66 The option show-nodes can be used to materialize the nodes. The nodes are in fact Tikz nodes of shape “rectangle”,but with zero width. An arrow between two nodes starts at the south anchor of the first node and arrives at the northanchor of the second node.6

Z0I Zπ4π4 0Zπ4 0Zπ4 0Zπ4 0Z π4 ln 1 tanπ4 u ( du) ln 1 tan π4 u du 1 tan uln 1 du1 tan u 1 tan u 1 tan uduln1 tan u 2lndu1 tan u ln 2 ln(1 tan u) du0Z π4π ln 2 ln(1 tan u) du40π ln 2 I4The nodes of the left are at the end of each line of text. These nodes will be called left nodes. Thenodes of the right side are aligned vertically on the right side of the array. These nodes will be calledright nodes.By default, the arrows use the right nodes. We will say that they are in rr mode (r for right). Thesearrows are vertical (we will say that an arrow is vertical when its two ends have the same abscissa).However, it’s possible to use the left nodes, or a combination of left and right nodes, with one of theoptions lr, rl and ll (l for left). Those arrows are, usually, not vertical.Z 0 Therefore I ln 1 tan π4 u ( du)This arrow uses the lr option.Zπ4π4 0Zπ4 0Zπ4 0Zπ4 0Z π4 ln 1 tan π4 u du 1 tan uln 1 du1 tan u 1 tan u 1 tan uduln1 tan u 2lndu1 tan u ln 2 ln(1 tan u) duThis arrow uses a ll option and ajump equal to 20Z π4π ln 2 ln(1 tan u) du40π ln 2 I4There is also an option called i (i for intermediate). With this option, the arrow is vertical and atthe leftmost position. \begin{WithArrows}(a b)(a ib)(a-b)(a-ib)& (a b)(a-b)\cdot(a ib)(a-ib) \\& (a 2-b 2)(a 2 b 2) \Arrow[i]{because (x-y)(x y) x 2-y 2 }\\& a 4-b 4\end{WithArrows} 7

(a b)(a ib)(a b)(a ib) (a b)(a b) · (a ib)(a ib) (a2 b2 )(a2 b2 )because (x y)(x y) x2 y 2 a 4 b4The environment {WithArrows} gives also a group option. With this option, all the arrows of theenvironment are grouped on a same vertical line and at a leftmost position. \begin{WithArrows}[displaystyle,group]2xy'-3y \sqrt x& \Longleftrightarrow 2x(K'y 0 Ky 0')-3Ky 0 \sqrt x \\& \Longleftrightarrow 2xK'y 0 K(2xy 0'-3y 0) \sqrt x \\& \Longleftrightarrow 2x K'y 0 \sqrt x \Arrow{.}\\.\end{WithArrows} 2xy 0 3y x 2x(K 0 y0 Ky00 ) 3Ky0 0 2xK y0 2xK 0 y0 K(2xy00 x 2xK 0 x x 232 K 0 K 12x21 2x1 x 3y0 ) xwe replace y0 by its valuesimplification of the xantiderivationThe environment {WithArrows} gives also a groups option (with a s in the name). With this option,the arrows are divided into several “groups”. Each group is a set of connected7 arrows. All the arrowsof a given group are grouped on a same vertical line and at a leftmost position.A B C D D0onetwo E F G H I K L M N OthreefourIn an environment which uses the option group or the option groups, it’s still possible to give anoption of position (ll, lr, rl, rr or i) to an individual arrow8 . Such arrow will be drawn irrespectiveof the groups. It’s also possible to start a new group by applying the option new-group to an givenarrow.If desired, the option group or the option groups can be given to the command \WithArrowsOptionsso that it will become the default value. In this case, it’s still possible to come back to the defaultbehaviour for a given environment {WithArrows} with the option rr: \begin{WithArrows}[rr]In the following example, we have used the option groups for the environment and the optionnew-group for the last arrow (that’s why the last arrow is not aligned with the others).7 More precisely: for each arrow a, we note i(a) the number of its initial row and f (a) the number of its final row;for two arrows a and b, we say that a b when Ji(a), f (a)K Ji(b), f (b)K 6 ; the groups are the equivalence classes ofthe transitive closure of .8 Such an arrow will be called independent in the technical documentation8

nPk 0cos kxcosk x nP (eikx )(cos x)kk 0 nP k 0 ikxe(cos x)kn Pk 01 4(cos x)k is real ix k !ecos xn 1eixcos xeix1 cosxi(n 1)x1 ecosn 1 x (z z 0 ) (z) (z 0 )sum of terms of a geometric progressionalgebraic calculation ixe1 cosx cosn 1 x ei(n 1)x cosn 1 xcos x eixcos x 1cosn x 1cosn x 1cosn x 1cosn x· cosn 1 x ei(n 1)xcos x eixreduction to common denominator (kz) k · (z) if k is realcosn 1 x (cos(n 1)x i sin(n 1)x)cos x (cos x i sin x)(cosn 1 x cos(n 1)x) i sin(n 1)x i sin x algebraic form of the complexes sin(n 1)xsin xThe option “o” for individual arrowsLet’s consider, in a given environment, two arrows called a and b. We will note ia and ib the numbersof the initial lines of a et b dans fa and fb the numbers of the final lines. Of course, we have ia faand ib fbWe will say that the arrow a covers the arrow b when ia ib fb fa . We will also say that thearrow a is over the arrow b.A B CIn the exemple on the right, the red arrow covers theblue one. D EOn the local level, there exists a key o. This key is available only when the option group or theoption groups is in force (cf. p. 8).An arrow of type o is drawn with an horizontal shift (such as those set by xoffset) automaticallycomputed by taking into account the arrows covered by our arrow.9 \begin{WithArrows}[groups]A & B\Arrow{one}\Arrow[o,jump 3]{direct} \\& C C \Arrow{two} \\& D D D \Arrow{three} \\& E E \\& F F\end{WithArrows} A B C C D D D E Eonetwodirectthree F F9 Among the covered arrows, the independent ones (that is to say with an explicit key rr, ll, lr, rl, i, up or down)are not taken into account in the computation of the value of xoffset.9

Arrows of type o may themselves be covered by other arrows of type o. \begin{WithArrows}[groups]A & B \Arrow{one}\Arrow[o,jump 2]{two}\Arrow[o,jump 3]{three}\\& C \\& D \\& E E E E E E E\end{WithArrows} A Bone C Dtwothree E E E E E E EThe horizontal space between an arrow of type o and the arrows immediately covered is fixed bythe dimension xoffset-for-o-arrows which can be set which the command \WithArrowsOptions(initial value: 2 mm).5The options “up” and “down” for individual arrowsAt the local level, there are also two options for individual arrows, called “up” and “down”. Thefollowing example illustrates these types of arrows:\(\begin{WithArrows}A & B\Arrow[up]{an arrow of type \texttt{up}} \\& C C C C C C C C \\& C C C C C C C C\Arrow[down]{an arrow of type \texttt{down}} \\& E E\end{WithArrows}\)an arrow of type upA B C C C C C C C C C C C C C C C C E Ean arrow of type downThe options up and down require the Tikz library calc. It it has not been previously loaded by theuser, an error will be raised.In fact, the options up and down may be used with a value which is a list of couples key-value. The key radius is the radius of the rounded corner of the arrow.10 The key width is the width of the (horizontal part of) the arrow:– with the value max, the width of the arrow is ajusted with respect of the position of thenodes (that’s the behaviour by default of the arrows up and down as shown in the previousexample);10 Theinitial value of this parameter is 4 pt, which is the default value of the “rounded corners” of Tikz.10

– with a numerical value, the width of the arrow is directly fixed to that numerical value;– with the value min, the width of the arrow is adjusted with respect to the contents of thelabel of the arrow. \begin{WithArrows}A & B\Arrow[up {radius 0pt,width 2cm}]{we try} \\& C C C C C C C C\end{WithArrows} we tryA B C C C C C C C C \begin{WithArrows}A & B\Arrow[up {width min}]{we try} \\& C C C C C C C C\end{WithArrows} we tryA B C C C C C C C CThe options relative to the arrows up and down can be fixed at the global or environment level withthe key up-and-down. Th