[Tex/LaTex] reduce vertical space for \xrightarrow

amsmath

I find the vertical spacing of amsmath's \xrightarrow too large for the underset. Is there an easy way to reduce it (i.e. put "below" close to the arrow, in the example)?

\documentclass{minimal}
\usepackage{amsmath}
\begin{document}
\fbox{$\xrightarrow[\fbox{below}]{\fbox{above}}$}
\end{document}

I looked at the arrow definition (ext@arrow, e.g. discussed in Understanding ext@arrows) and there, \limits^{}_{} is used.

PS. I am interested in a short and simple solution. I know how to built a new extensible arrow from scratch, but wanted to know if there is an easier solution.

Best Answer

Remedied the valid comment of mh256, creating macro \xxrightarrow[]{} that reduces the space of the underset, but allows for the length of the underset.

EDITED to make it \mathrel and also to use temp \box2 instead of \box0, which appears to be also used by \xrightarrow.

\documentclass{minimal}
\usepackage{amsmath,stackengine}
\stackMath
\newcommand\xxrightarrow[2][]{\mathrel{%
  \setbox2=\hbox{\stackon{\scriptstyle#1}{\scriptstyle#2}}%
  \stackunder[0pt]{%
    \xrightarrow{\makebox[\dimexpr\wd2\relax]{$\scriptstyle#2$}}%
  }{%
   \scriptstyle#1\,%
  }%
}}
\parskip 3pt
\begin{document}
\fbox{$\xxrightarrow[\fbox{below}]{\fbox{above}}$}

\fbox{$\xxrightarrow[\fbox{below is a long text}]{\fbox{above}}$}

$ x \xxrightarrow[bottom]{top} y$

$x \xxrightarrow[a]{a} y$

$x \xrightarrow[a]{a} y$

\end{document}

enter image description here