# Understanding ext@arrows

I don't quite understand how \ext@arrow of amsmath is working. When I look at the code, its functionality seems straight forward to me at the first glance.

\def\ext@arrow#1#2#3#4#5#6#7{%
\mathrel{\mathop{%
\setbox\z@\hbox{#5\displaystyle}%
\setbox\tw@\vbox{\m@th
\hbox{$\scriptstyle\mkern#3mu{#6}\mkern#4mu$}%
\hbox{$\scriptstyle\mkern#3mu{#7}\mkern#4mu$}%
\copy\z@
}%
\hbox to\wd\tw@{\unhbox\z@}}%
\limits
\@ifnotempty{#7}{^{\if0#1\else\mkern#1mu\fi
#7\if0#2\else\mkern#2mu\fi}}%
\@ifnotempty{#6}{_{\if0#1\else\mkern#1mu\fi
#6\if0#2\else\mkern#2mu\fi}}}%
}


The first part uses #3 and #4 to determine how long the arrow should be (I call that length A). The second part does then set the text above or below the arrow and uses #1 and #2 as left and right margin (I call that length B).

First of all, I think that the separate declaration of #3 and #4 is not necessary, the sum of both would suffice (as text is always set centered on an arrow enlarged by use of #3 and #4).

While playing around with different values, I realized that the arrow does not always have length A. If the text is longer (B > A), then the arrow is longer as well. The following two examples read to the same results.

\documentclass{minimal}
\usepackage{amsmath}
\begin{document}
\makeatletter\noindent
$\ext@arrow 00{20}{20}\rightarrowfill@{a}{b}$\\
$\ext@arrow {20}{20}00\rightarrowfill@{a}{b}$
\end{document}


So, in that case, one does not need #3 and #4 at all. #1 and #2 would suffice.

The only reason for #3 and #4, I can see, is to specify a minimum length of the arrow in case there is no text (and #1 and #2 are never used in that case). However, I do not quite understand while the calculation of value A is so complicated then (incorporating the text, that is empty in that case).

Is this historic ballast? Or did I understand something wrong?

-
 The choice of differing #3 and #4 arguments allow you to generate extended arrows that are horizontally offset (either left or right) from the centre. – Werner May 24 '12 at 7:32 I doubt that (as I wrote above). #3 and #4 are only used for the width measurement, not for typesetting. A test confirms that. $\ext@arrow 00{40}0\rightarrowfill@{a}{b}$ produces centered text. – Martin May 24 '12 at 8:24 Try and give different values to #1 and #2. – egreg May 24 '12 at 9:32 Try to read my initial post first. – Martin May 24 '12 at 14:21

The arguments #3 and #4 could be joined to one argument since they only set some horizontal size (\wd\tw@). But they cannot be omitted if you want to have the arrow be long even if there is no text at all, as you can see in the following commented example:

\documentclass{article}
\usepackage{amsmath}
\begin{document}

\makeatletter
\noindent
without text:
\\
$f\ext@arrow 00{15}{15}\rightarrowfill@{}{}g$
\\
$f\ext@arrow 00{30}0\rightarrowfill@{}{}g$ \qquad same result as above
\\
$f\ext@arrow {15}{15}00\rightarrowfill@{}{}g$ \qquad different result

\bigskip
\noindent
with some text you really do not need $\#3$ and $\#4$:
\\
$f\ext@arrow 00{15}{15}\rightarrowfill@{111}{22}g$
\\
$f\ext@arrow 00{30}0\rightarrowfill@{111}{22}g$
\\
$f\ext@arrow {15}{15}00\rightarrowfill@{111}{22}g$ \qquad these three gave the same result
\\
$f\ext@arrow 0{12}{30}0\rightarrowfill@{111}{22}g$
\\
$f\ext@arrow {9}{21}00\rightarrowfill@{111}{22}g$ \qquad these two do the same and move the numbers a bit left. But computing $\#1$ and $\#2$ such that $\#2-\#1=12$ and $\#2+\#1=30$ is necessary.

\end{document}

-
 Thanks. This is exactly what I found (and tried to describe in my initial post). I was confused about the useless calculations. Firstly, there is no need to have #3 and #4 as separate arguments. Secondly, instead of \hbox{$\scriptstyle\mkern#3mu{#6}\mkern#4mu$} one could simply add #3 and #4 (because #3 and #4 are only needed when #6 and #7 [the texts] are empty). I simply was not expecting such an cumbersome macro in a high-quality package like amsmath and had doubts about my reasoning. – Martin May 24 '12 at 14:17 @Martin It is possible that in some alpha-version of the package the definition was different, and removal of one argument would make a lot of complications... Such things happen all the time. – tohecz May 24 '12 at 14:45