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}{सकार}{लोप}
The algorithm for placing sub- and superscripts is "hard-wired" in the TeX engine, and it's not as simple as you might think. First of all, there's a special treatment for sub- and superscripts of "simple characters" like a
, \alpha
or \mathcal{A}
. In this case you also have some horizontal displacement of the subscript that is determined by the italic correction of the character: for example, the subscript should be shifted to the left for an F
, but not for an A
.
The default values for raising and lowering are as follows in the case of "simple characters". The superscript is (tentatively!) raised by the maximum of (depth of superscript) + (1/4 of the x-height)
and σk
, where the x-height is the \fontdimen
parameter number 5, and σk
is \fontdimen
parameter number k (of \textfont2
unless the whole formula is in a sub- or superscript itself). Now it depends on the current style (which, unfortunately, the TeX user can only access via \mathpalette
or \mathchoice
): In \displaystyle
k=13 is used, in "cramped style" k=15, and k=14 otherwise.
How much the subscript is lowered depends on the presence of a superscript. If there's a superscript, then the subscript is (tentatively!) lowered by σ17
, otherwise by the maximum of (height of subscript) - (80% of the x-height)
and σ16
. In the case of a sub- and superscript combination there's an additional adjustment (with some unpleasant side effects), see e.g. this answer of mine.
If the sub- or superscript is not attached to a "simple character" but to some other nucleus, then additional minimum shift values are used: the superscript is raised by at least (height of nucleus) - σ18
, the subscript is lowered by at least (depth of nucleus) + σ19
, where σ18
and σ19
are to be taken from \scriptfont2
unless the whole formula is in a sub- or superscript itself (in which case \scriptscriptfont2
should be used).
I'm not sure if you really want to implement this ... if you do, have a look at Rule 18 of Appendix G in the TeXbook for details.
Best Answer
If your problem is that the argument to the extendible arrow (e.g.
add
) is raising the asterisk too high, you can always\smash
your argument so that it takes no vertical space (e.g. using code such as$\xrightarrow{\smash{add}}^*$
).Edit. As implied by
egreg
in the comments, a better solution would be to use\xrightarrow{\text{add}}\mathrel{\vphantom{\to}^*}
, so that the text above the arrow contributes to the height of the line without contributing to the height of the superscript. (See this duplicate question for reference.)