I am just putting the code that you gave inside a \newcommand
. Is it what was needed?
\newcommand{\TwoSidedTextArrow}[6]{
\ensuremath{%
\xrightarrow[%
\stackrel{\normalsize\text{}}{%
\shortstack[c]{%
{\textcolor{blue}{\text{\scriptsize{\nameref{#1}}}}}\ %
\textcolor{blue}{\text{\scriptsize{#2 gets #3}}}%
}}]{%
\stackrel{\normalsize\text{}}{%
\shortstack[c]{%
{\textcolor{black}{\text{\scriptsize{\nameref{#4}}}}}\ %
\text{\scriptsize{#5 gets #6 \&}}}%
}}%
}%
}
Your example then becomes
क्रोष्टान् + स् \TwoSidedTextArrow{8.2.7}{नकार}{लोप}{6.1.68}{सकार}{लोप}
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).
Best Answer
The following code defines a user command named
extoverset
, which takes two mandatory arguments and acts like\overset
, except that it stretches the width of the 2nd argument (say,\sim
) to equal the width of the first argument. An optional third argument can be used to fine-tune the resulting widths.Certainly not perfect -- but hopefully it's a (decent?) start.