8

It seems that the commands \xrightarrow, etc. in mathtools package don't allow me to put text above or below two arrows (\rightrightarrows). Is there any way to do this with extensible arrows? A crude way would be

\overset{b}{\underset{a}{\rightrightarrows}}

but the arrows are not extensible. For that matter, it also doesn't support \twoheadrightarrow, etc.

5
  • 1
    For example you might want to explain where \rightrightarrow comes from? It is not a standard command, so of course mathtools does not support it.
    – daleif
    Commented May 14, 2013 at 14:45
  • \rightrightarrow is an AMS arrow, two right arrows one above the other.
    – ashpool
    Commented May 14, 2013 at 14:54
  • @daleif -- \rightrightarrows (note plural) and \twoheadrightarrow are both defined in amssymb. the latter is potentially extensible in the same manner as \xrightarrow; the former isn't, since the equal sign can't be used as an extender (as it can for \Rightarrow). Commented May 14, 2013 at 14:58
  • @barbarabeeton-- you are right. I corrected to the plural form. Thanks.
    – ashpool
    Commented May 14, 2013 at 15:21
  • That would explain why I couldn't make it compile
    – daleif
    Commented May 14, 2013 at 20:18

3 Answers 3

15

The following example defines \xtwoheadrightarrow and \xtwoheadleftarrow similar to the definitions of \xrightarrow and \xleftarrow:

\documentclass{article}
\usepackage{amssymb}
\usepackage{amsmath}

\makeatletter
\providecommand*{\twoheadrightarrowfill@}{%
  \arrowfill@\relbar\relbar\twoheadrightarrow
}
\providecommand*{\twoheadleftarrowfill@}{%
  \arrowfill@\twoheadleftarrow\relbar\relbar
}
\providecommand*{\xtwoheadrightarrow}[2][]{%
  \ext@arrow 0579\twoheadrightarrowfill@{#1}{#2}%
}
\providecommand*{\xtwoheadleftarrow}[2][]{%
  \ext@arrow 5097\twoheadleftarrowfill@{#1}{#2}%
}
\makeatother

\begin{document}
\[
  A \xrightarrow[under]{over} B
  \xtwoheadrightarrow[under]{over} C
  \xtwoheadleftarrow[under]{over} D
\]
\end{document}

Result

The case \rightrightarrows/\leftleftarrows is much more complicate. Before there is a symbol \relbar that is used for the extensible part of the arrow. But there is no symbol for the double line case. Thus the vertical positions of the lines and their thickness is not known. The following example defines \relrelbar for this purpose that is composed of \relbar lowered and raised by the amount given in macro \relrelbarsep. Therefore this macro needs to be redefined for a different font. The example uses the AMS fonts:

\documentclass{article}
\usepackage{amssymb}
\usepackage{amsmath}

\makeatletter
\newcommand*{\relrelbarsep}{.386ex}
\newcommand*{\relrelbar}{%
  \mathrel{%
    \mathpalette\@relrelbar\relrelbarsep
  }%
}
\newcommand*{\@relrelbar}[2]{%
  \raise#2\hbox to 0pt{$\m@th#1\relbar$\hss}%
  \lower#2\hbox{$\m@th#1\relbar$}%
}
\providecommand*{\rightrightarrowsfill@}{%
  \arrowfill@\relrelbar\relrelbar\rightrightarrows
}
\providecommand*{\leftleftarrowsfill@}{%
  \arrowfill@\leftleftarrows\relrelbar\relrelbar
}
\providecommand*{\xrightrightarrows}[2][]{%
  \ext@arrow 0359\rightrightarrowsfill@{#1}{#2}%
}
\providecommand*{\xleftleftarrows}[2][]{%
  \ext@arrow 3095\leftleftarrowsfill@{#1}{#2}%
}
\makeatother

\begin{document}
\[
  A \xrightrightarrows[under]{over} B
  \xleftleftarrows[under]{over} C
\]
\end{document}

Result

The numbers 0579, ... are four arguments for \ext@arrow that is defined by package amsmath:

\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}}}%
}

Some remarks:

  • The width of box \tw@ contains the maximal width of the text below. above and the symbol without text.
  • The latter two numbers specify the margins for the texts in the measurement phase.
  • The first two numbers specify the margins for the texts that is finally set and allows to insert some asymmetry of the horizontal placement because of the arrows.
4
  • very nice! you say that \relrelbar needs to be redefined for fonts other than computer modern. but it's true in any case that the definitions for extensible arrows, and especially for double-stem arrows, need to be examined carefully for any other fonts since cm arrows were fine-tuned so that the minus and equals signs could be used as extenders, and this is decidedly not true for most other fonts, even for some that were allegedly created with the intention of being used for math. Commented May 14, 2013 at 15:50
  • @barbarabeeton Even worse, the thickness and vertical positions might even depend on the font/design size of the same font. Commented May 14, 2013 at 15:59
  • @HeikoOberdiek Thanks! Could you explain what the numbers 0579, 0395, etc. do exactly? For example, if I want to adopt your code to \rightarrowtail, should I change those numbers? I looked at their definitions, but I'm totally lost.
    – ashpool
    Commented May 14, 2013 at 16:31
  • Thanks a lot for explaining what ` 0579` does. Is there any way to lower the upper text a bit? I could not figure it out by myself…
    – Clément
    Commented Sep 22, 2022 at 19:54
4

Adapting an answer from How do I put text over a squiggly arrow?. See that answer for a full description of the created macros, though, in the end, the commands to use are \rextlinearrow{string}{integer} for a right arrow and \lextlinearrow{string}{integer} for a left arrow. The integer is the arrow-shaft length defined in terms of multiples of a minus sign. The string is the text to be written over the arrow.

\documentclass[12pt]{article}
\parskip 1ex
\usepackage{amssymb}
\usepackage{ifthen}
\textwidth 2in
\begin{document}
Here are the commands to make extensible arrows, with no text above
them:

\newcommand{\extline}{$\scriptsize$-$\normalsize$\!}
\newcommand{\lextlineend}{$\scriptsize$\lhd\!$\normalsize$}
\newcommand{\rextlineend}{$\scriptsize\rule{.1ex}{0ex}$\rhd$\normalsize$}
\noindent
$2H_2 + O_2 ~\extline\extline\extline\rextlineend~ 2H_2O $\\
$2H_2 + O_2 ~\lextlineend\extline\extline\extline~ 2H_2O $

Now I will create commands to place text over them

\newcounter{index}

\newcommand\extlines[1]{%
  \setcounter{index}{0}%
  \whiledo {\value{index}< #1}
  {\addtocounter{index}{1}\extline}
}

\newcommand\rextlinearrow[2]{$
  \setbox0\hbox{$\extlines{#2}\rextlineend$}%
  \tiny$%
  \!\!\!\!\begin{array}{c}%
  \mathrm{#1}\\%
  \usebox0%
  \end{array}%
  $\normalsize$\!\!%
}

\newcommand\lextlinearrow[2]{$
  \setbox0\hbox{$\lextlineend\extlines{#2}$}%
  \tiny$%
  \!\!\!\!\begin{array}{c}%
  \mathrm{#1}\\%
  \usebox0%
  \end{array}%
  $\normalsize$\!\!%
}

\noindent
$2H_2 + O_2 \rextlinearrow{exothermic}{7} 2H_2O $\\
$2H_2 + O_2 \lextlinearrow{heat}{3} ~ 2H_2O $

\end{document}

enter image description here

1

Here's a shorter, yet more precise solution based on \xleftrightharpoons from mathtools code.

\documentclass{article}
\usepackage{amssymb}
\usepackage{amsmath}

\makeatletter

\def\rightarrowfill@script{%
    \arrowfill@{\scriptstyle\relbar}{\scriptstyle\relbar}{\scriptstyle\rightarrow}}

\newcommand*\xrightrightarrows[2][]{\mathrel{%
  \raise.6ex\hbox{%
    $\ext@arrow 0359\rightarrowfill@script{\phantom{#1}}{#2}$}%
  \setbox0=\hbox{%
    $\ext@arrow 0359\rightarrowfill@script{#1}{\phantom{#2}}$}%
  \kern-\wd0 \lower.2ex\box0}}

\makeatother

\begin{document}

$$
f\rightrightarrows g, f\xrightrightarrows{X} g
$$

\end{document}

It also works with other fonts like mathabx, keeping the ling aligned with an arrow.

demo

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .