[Tex/LaTex] \xrightarrow: position of text over an arrow should be lower

arrowsmath-modeoverlayspositioning

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 enter image description here (\iota, \partial, \pi are too high) instead of enter image description here. Furthermore, it produces enter image description here instead of (lowered text) enter image description here

or even better (lowered text and better overlay with p) enter image description here.

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.

Best Answer

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}  

Example Result (Cutout)

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).