# witharrows - Problem to use a length given by \settowidth

The following code doesn't use the offset given by \myl. What am I missing ?

\documentclass{article}

\usepackage{witharrows}

\newlength\myl

\newcommand\doublearrow[2]{
\settowidth\myl{#1}%plus 2em
%Good length: \the\myl
\Arrow[tikz = ->]{#1}
\Arrow[xoffset=\myl,
tikz = <-]{#2}
}

\begin{document}

$\begin{WithArrows} A & = B \doublearrow{Explication down to.}% {Explication up to.} \\ & = C \end{WithArrows}$

\end{document}


I have written a new version of witharrows (v. 2.5 2020-06-23) in order to give the ability to define a robust command \DoubleArrow as required by the OP.

In this new version of witharrows, a new type of invidual arrow is introduced: the type o (for over). Such arrow is drawn over the other arrows as illustrated in the following example.

\documentclass{article}
\usepackage{witharrows}

\begin{document}
$\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}$
\end{document}


It's now easy to define a robust command \DoubleArrow with the expected behaviour:

\documentclass{article}
\usepackage{witharrows}
\NewDocumentCommand \DoubleArrow { O {} m m }
{
\Arrow[tikz=->,#1]{#2}%
\Arrow[o,tikz=<-,#1]{#3}
}

\begin{document}
$\begin{WithArrows}[groups] A & = (a+b)^2 \DoubleArrow[tikz={font=\bfseries}]{expansion}{factorization} \\ & = a^2 + 2ab+b^2 \end{WithArrows}$
\end{document}


• Great and so useful for lessons ! – projetmbc Jun 23 at 21:43

For some reason you need to make the length global for this to work. (Probably WithArrows scans for the \Arrow commands and does some nice tricks with them.)

\documentclass{article}

\usepackage{witharrows}

\newlength\myl

\newcommand\doublearrow[2]{%
\settowidth\myl{#1}%
\global\myl=\myl%
\Arrow[tikz = ->]{#1}%
\Arrow[xoffset = \dimexpr\myl+1em,tikz    = <-]{#2}%
}

\begin{document}

$\begin{WithArrows} A & = B \doublearrow{Explication down to.}% {Explication up to} \\ & = C \end{WithArrows}$

\end{document}


I also added a grace distance of 1em but this has nothing to do with the problem.

• Thanks for the trick ! I have also noticed the missing grace distance. – projetmbc Jun 13 at 20:52
• Yes. The command \doublearrow is executed in the cell of an array (an \halign of TeX) and each such cell is a TeX group. However, the arrows are not drawn when TeX is in that cell: they are drawn after the construction of the \halign: that's why a global affectation is required here. – F. Pantigny Jun 13 at 21:26
• Thanks a lot or "Merci beaucoup". – projetmbc Jun 13 at 22:16

If you want a macro \doublearrow which may be used several times in the same environment {WithArrows}, you can't use a global dimension. You have to substitute \mylen by its numerical value in the option [xoffset = \mylen] before the execution of the command \Arrow.

The following code gives a way to do that.

\documentclass{article}

\usepackage{witharrows}

\WithArrowsOptions{tikz={font=}}

\ExplSyntaxOn
\NewDocumentCommand \doublearrow { m m }
{
\hbox_set:Nn \l_tmpa_box { #1 }
\dim_set:Nn \l_tmpa_dim { \box_wd:N \l_tmpa_box + 20 pt }
\Arrow [tikz = ->] { #1 }
\use:x { \Arrow [xoffset=\dim_use:N \l_tmpa_dim , tikz = <-] } { #2 }
}
\ExplSyntaxOff

\begin{document}

$\begin{WithArrows} A & = B \doublearrow{$1+2$}{$3+4$} \\ & = C \\ & = D \doublearrow{up to down}{down to up} \\ & = E \end{WithArrows}$

\end{document}


In fact, this code is not perfect for two reasons.

• The argument of the first \Arrow is composed twice. It's a problem if there is a code with side effects in that argument (for example a \footnote).

• The width of the label of the first \Arrow is computed without applying the potential formatting options (the key tikz={font={...}}). If such options are used, the computed width will be wrong and the position of the second arrow will also be wrong. That's why, for an homogeneous behaviour, I have considered that \WithArrowsOptions{tikz={font=}} is in force.

• Good ! Thanks ! Why I forget this case of use... There is stil a little problem. I have tried to use the following example but the first spacing isn't big enough : $\begin{WithArrows} A & = B \doublearrow{$1+2$}{$3+4$} \\ & = C \doublearrow{Explication down to.}{Explication up to} \\ & = D \end{WithArrows}$ – projetmbc Jun 14 at 12:23
• You are right. I have modified my post. There is a problem with the potential formatting of the argument of the \Arrow. As for now, it's not possible to solve that problem without using internals of witharrows. – F. Pantigny Jun 14 at 13:12
• Thanks for this explanations. Maybe this could be a new feature : I always write like this when I teach to my "secondes de lycée". With my "premières de lycée" I use another syntax coming from formal methods of the computer sciences. – projetmbc Jun 14 at 13:21