[Tex/LaTex] Text both above and below double arrows

arrowsmath-mode

I would like to use a command like

\xleftrightarrows[#1]{#2}

namely extendable arrows for double arrows with an optional superscript and subscript
Mathtools package provides

\xleftrightarrow[#1]{#2}

namely extending arrows for a double arrow, but I want want two arrows in both direction.
Any clue?

Best Answer

REVISED SOLUTION (AUTOMATED EXTENSIBILITY):

There are two arguments: the overset and underset text (set in \scriptstyle). You can play with the value 1.7 in my MWE, which will change the arrow length relative to the text length (smaller value will lengthen the arrow).

\documentclass{article} 
\usepackage{stackengine}
\usepackage{scalerel}
\usepackage{fp}
\def\clipeq{\!\mathrm{=}\!}
\def\Lla{\Longleftarrow\!\!\!\!\!\!}
\def\Lra{\!\!\!\!\!\!\Longrightarrow}
\newcount\argwidth
\newcount\clipeqwidth
\savestack\tempstack{\stackon{$\clipeq$}{}}%
\clipeqwidth=\wd\tempstackcontent\relax
\newcommand\xleftrightarrows[2]{%
  \savestack\tempstack{\stackon{$\scriptstyle#1$}{$\scriptstyle#2$}}%
  \argwidth=\wd\tempstackcontent\relax%
  \FPdiv\scalefactor{\the\argwidth}{\the\clipeqwidth}%
  \FPsub\scalefactor{\scalefactor}{1.7}% <---CAN PLAY WITH THIS VALUE
  \FPmax\scalefactor{\scalefactor}{.05}%
  \mathrel{%
  \stackunder[2pt]{\stackon[3pt]{$\Lla\hstretch{\scalefactor}{\clipeq}\Lra$}%
     {$\scriptstyle#1$}}{$\scriptstyle#2$}%
  }%
}
\parskip 1ex
\begin{document} 
$Z \xleftrightarrows{ABC}{defghi} R$

$\xleftrightarrows{}{}$

$\xleftrightarrows{a}{}$

$\xleftrightarrows{ab}{}$

$\xleftrightarrows{abc}{}$

$\xleftrightarrows{abcd}{}$

$\xleftrightarrows{abcde}{}$
\end{document}

enter image description here

ORIGINAL SOLUTION (MANUAL EXTENSIBILITY):

I create the macro you asked for with two mandatory arguments and one optional argument. The mandatory args are the overset and underset text (set in \scriptstyle). The optional argument is a real number which is indicative of the length scale of the arrow (roughly equal to how many characters longer you would like to make the default arrow).

Note: I wrapped a \mathrel{} about the stacking commands, assuming that's the way you wanted to use it. Also, the width of the stack will conform to the width of the longest element of the stack. If you wanted the width of the stack to conform to the arrow width, regardless of the length of the over- and underset text, you could add \def\useanchorwidth{T} to the beginning of the \xleftrightarrows definition. You can also tweak the overset and underset separation distances (currently set to 3pt and 2pt, respectively.

\documentclass{article} 
\usepackage{stackengine}
\usepackage{scalerel}
\def\clipeq{\!\mathrm{=}\!}
\def\Lla{\Longleftarrow\!\!\!\!}
\def\Lra{\!\!\!\!\Longrightarrow}
\newcommand\xleftrightarrows[3][0]{%
  \mathrel{%
  \ifthenelse{\equal{#1}{0}}%
  {\stackunder[2pt]{\stackon[3pt]{$\Lla\Lra$}%
     {$\scriptstyle#2$}}{$\scriptstyle#3$}}%
  {\stackunder[2pt]{\stackon[3pt]{$\Lla\hstretch{#1}{\clipeq}\Lra$}%
     {$\scriptstyle#2$}}{$\scriptstyle#3$}}%
  }%
}
\begin{document} 
$Q \xleftrightarrows{ABC}{defghi} Z \xleftrightarrows[3]{ABC}{defghi} R$
\end{document}

enter image description here