# \xrightarrow: position of text over an arrow should be lower

The following example of LaTeX code

\documentclass[b4paper,oneside, final, 10pt]{article}
\usepackage[english]{babel}
\usepackage{charter}
\usepackage{amsfonts}
\usepackage{mathtools}
\usepackage[top=1.5cm, bottom=2.9cm, left=2.1cm, right=2.1cm]{geometry}

\begin{document}
\noindent\textbf{\large Algebraic Morse Theory:} Let $R$ be any ring. A
\emph{based $R$-complex}, is a chain $R$-complex $(A_\star,\partial_\star)$,
together with a chosen decomposition $A_n\!=\bigoplus_{i\in I_n}\!\!\!A_{n,i}$
for every $n$. Then $\partial_{n,i,j}\!=\!\partial_{i,j}$ denotes the $R$-module
homomorphism $A_{n,i} \smash{\overset{\iota}{\longrightarrow}} A_n \smash{\overset{\partial_n}{\longrightarrow}}A_{n-1} \smash{\overset{\pi}{\longrightarrow}}A_{n-1,j}$, where $\iota$ is the coordinate inclusion and
$\pi$ is the coordinate projection. The associated digraph of $A_\star$,
$\Gamma_{\!A_\star}\!=\!\Gamma$, is a directed simple graph whose vertices are
the indices from all $I_n$, and directed edges correspond to nonzero maps
$\partial_{i,j}$. Each edge $(i,j)$ will be denoted by $i\!\to\!j$.\\[2mm]

\noindent\textbf{Conclusion:} Given a based $R$-complex $(A_\star,\partial_\star,I_\star)$,
any Morse matching $\mathcal{M}$ on $\Gamma_{\!A_\star}$ induces a homotopy
equivalence between complexes $(A_\star,\partial_\star)$ and
$(\mathring{A}_\star,\mathring{\partial}_\star)$, more precisely $A_\star \xrightarrow{\pi\text{ s.d.r. }}\pi(A_\star) = \pi(\mathring{A}_\star) \xleftarrow{\pi=p^{-1}\,\cong}\mathring{A}_\star$, and therefore isomorphisms
$H_n(A_\star,\partial_\star) \cong H_n(\mathring{A}_\star,\mathring{\partial}_\star)$
for all $n\!\in\!\mathbb{Z}$. In particular, if $\mathcal{M}^0_{n-1}\!= \emptyset =\!\mathcal{M}^0_{n+1}$ then there holds $H_n(A_\star,\partial_\star) \cong \mathring{A}_n$.
\end{document}


produces (\iota, \partial, \pi are too high) instead of . Furthermore, it produces instead of (lowered text)

or even better (lowered text and better overlay with p) .

Is there a way to create a better command \xrightarrow (and if possible, also \xleftarrow, \xRightarrow, \xLeftarrow, etc.), that positions the text better, like in the pictures above? The style in the second and fifth pics is most desirable. Also, I would be most happy if this command had an optional argument [...] that specified offset from the line of the arrow (including negative space).

P.S. By the way, is there a way to make the + and - sign in sub and superscripts appear with less space left and right of it? For example, -1 in the above picture is too far away from p.

-
When making an example it helps if you make a Minimal example that demonstrates the problem, your posted example loads dozens of unrelated packages –  David Carlisle Jan 20 '13 at 12:55
i beg to differ with the very low positioning of the embellishment \pi=p... in the last two examples -- the arrow should never cut through the descender of the text above. any good math editor (person) would immediately mark that for correction! and "interrupting" the arrow as in the last example is entirely wrong. while i might agree that this text is higher than desirable, it's definitely desirable that text over all arrows be aligned on the same baseline, which the \delta_n is definitely not. you're treading here on hundreds of years of practice. –  barbara beeton Jan 20 '13 at 13:04
You are using many obsolete,duplicating, and/or conflicting packages: mathtools loads amsmath, tikz and possibly others load xcolor in the background which is better than color. tocloft has a subfigure option which is meant to be used with subfigure package but that's obsolote and subfig superseded it .... But as @DavidCarlisle mentions, to be able to help you I need to install all of these packages just to see that arrow placement which is just pointless. –  percusse Jan 20 '13 at 13:36
I agree that the text might sit a bit lower on the arrow (such that \xrightarrow{x_p^q} is still just above the arrow). However, if your issue is increased lineskip and you use a lot of inline math, I suggest adding \linespread{1.08} into your preamble, which will make all the line a bit looser. This way you'd get a more pleasant result I think. –  tohecz Jan 20 '13 at 15:02
Although I do agree that Leon's wishes are not "typesetting canon" I like the way it looks and thus +1'ed this question. Furthermore I'd like to add that at the moment the xrightarrow (xleftarrow) command does not really align its (actual) text on the same baseline. If you look closely at the to \pis ontop of the arrows in his third image you will notice that they have a different vertical distance from their respective arrow. His proposed style contains less whitespace than the standard LaTeX result (and the \pis have the same vertical offset) and thus is more appeasing (for me). –  elemakil Jan 20 '13 at 15:50

I wrote some functions that allow to lower/raise the text under/above xrightarrow arrows. It seams that the text typeset using these macros is a little wider but it doesn't look too bad ;)

The code required is:

\usepackage{ifthen}
\usepackage{xargs}

\newcommandx{\yaHelper}[2][1=\empty]{%
\ifthenelse{\equal{#1}{\empty}}%
{ \ensuremath{ \scriptstyle{ #2 } } } % no offset
{ \raisebox{ #1 }[0pt][0pt]{ \ensuremath{ \scriptstyle{ #2 } } } }  % with offset
}

\newcommandx{\yrightarrow}[4][1=\empty, 2=\empty, 4=\empty, usedefault=@]{%
\ifthenelse{\equal{#2}{\empty}}
{ \xrightarrow{ \protect{ \yaHelper[ #4 ]{ #3 } } } } % there's no text below
{ \xrightarrow[ \protect{ \yaHelper[ #2 ]{ #1 } } ]{ \protect{ \yaHelper[ #4 ]{ #3 } } } } % there's text below
}

\newcommandx{\yleftarrow}[4][1=\empty, 2=\empty, 4=\empty, usedefault=@]{%
\ifthenelse{\equal{#2}{\empty}}
{ \xleftarrow{ \protect{ \yaHelper[ #4 ]{ #3 } } } } % there's no text below
{ \xleftarrow[ \protect{ \yaHelper[ #2 ]{ #1 } } ]{ \protect{ \yaHelper[ #4 ]{ #3 } } } } % there's text below
}

\newcommandx{\yRightarrow}[4][1=\empty, 2=\empty, 4=\empty, usedefault=@]{%
\ifthenelse{\equal{#2}{\empty}}
{ \xRightarrow{ \protect{ \yaHelper[ #4 ]{ #3 } } } } % there's no text below
{ \xRightarrow[ \protect{ \yaHelper[ #2 ]{ #1 } } ]{ \protect{ \yaHelper[ #4 ]{ #3 } } } } % there's text below
}

\newcommandx{\yLeftarrow}[4][1=\empty, 2=\empty, 4=\empty, usedefault=@]{%
\ifthenelse{\equal{#2}{\empty}}
{ \xLeftarrow{ \protect{ \yaHelper[ #4 ]{ #3 } } } } % there's no text below
{ \xLeftarrow[ \protect{ \yaHelper[ #2 ]{ #1 } } ]{ \protect{ \yaHelper[ #4 ]{ #3 } } } } % there's text below
}


Usage is: yrightarrow[<TEXT-BELOW>][<OFFSET-BELOW>]{<TEXT-ABOVE>}[<OFFSET-ABOVE>} and similarly for the others.
A working minimal example looks like this:

\documentclass{minimal}
\usepackage{amsmath}
\usepackage{ifthen}
\usepackage{xargs}

\newcommandx{\yaHelper}[2][1=\empty]{%
\ifthenelse{\equal{#1}{\empty}}%
{ \ensuremath{ \scriptstyle{ #2 } } } % no offset
{ \raisebox{ #1 }[0pt][0pt]{ \ensuremath{ \scriptstyle{ #2 } } } }  % with offset
}

\newcommandx{\yrightarrow}[4][1=\empty, 2=\empty, 4=\empty, usedefault=@]{%
\ifthenelse{\equal{#2}{\empty}}
{ \xrightarrow{ \protect{ \yaHelper[ #4 ]{ #3 } } } } % there's no text below
{ \xrightarrow[ \protect{ \yaHelper[ #2 ]{ #1 } } ]{ \protect{ \yaHelper[ #4 ]{ #3 } } } } % there's text below
}

\begin{document}
\begin{align*}
A \yrightarrow{\pi \, \text{s.d.r.}}[-2pt] B \, , \: C \yrightarrow[\pi \, \text{s.d.r.}][4pt]{\pi \, \text{s.d.r.}}[-2pt] D
\end{align*}
\end{document}


However, this seems to be a brute force approach and I don't know whether there may be any side-effects (also I'm not doing any math-size checks, the stuff above and below the arrow will be always set in scriptstyle). And of course it is a "dumb" solution because one has to determine the offset manually. And finally there's no support for the feature suggested by the fifth image.

I'd advise you to accept this answer not (yet) because I hope that somebody can provide a better solution (hopefully including the feature suggested by the fifth image, which possibly could be achieved by printing first the content with a slightly larger font and white colour and then overprint the actual content in black).

-
What's \protect{ for? –  egreg Jan 20 '13 at 22:41
Without the protect the code yields the error ERROR: Argument of \\yaHelper has an extra }. Some google'ing showed that this is the result of putting a fragile command in a moving argument, which can be resolved be enclosing the whole thing in protect. –  elemakil Jan 21 '13 at 10:09