# Better transitive closure of labelled arrow

I think the answer will be easy, but I haven't found it yet:

I use labelled arrows like \xrightarrow\tau a lot. Sometimes, I need the transitive closure of such relations, which I write \xrightarrow\tau^* but then, the star is way to high, quite above the \tau.

How can I put the star at the same height as if I had written \rightarrow^*, even when I have a label?

Figures:

-
While code snippets are useful for explaining, it is best to compose a MWE that illustrates the problem including the \documentclass and the appropriate packages so that those trying to help don't have to recreate it. –  Peter Grill Nov 22 '11 at 10:59
@PeterGrill: my bad. With the tag amsmath, I thought that appropriate packages were obvious, and my question is (I think/thought) orthogonal to the document class. –  Axioplase Nov 22 '11 at 11:15
Yes it is obvious (in this case), but still takes time to type (and fix typos in my case :-)). It would just be helpful to also included the code you used to produce the image. –  Peter Grill Nov 22 '11 at 11:24

\documentclass{article}
\usepackage{amsmath}
\def\Xrightarrow#1#2{\xrightarrow#1{}\negthickspace^#2}
\begin{document}

$\rightarrow^*$

$\xrightarrow\tau{}\!\!^*$

$\Xrightarrow\tau*$
\end{document}


\!\! is the same as \negthickspace

-

You can use \raisebox to adjust the height of the *. Here is the original and one with \raisebox:

I have also define a macro \myxrightarrow that you can use as \myxrightarrow{\tau} to get the same effect.

\documentclass[border=2pt]{standalone}
\usepackage{amsmath}
\newcommand*{\myxrightarrow}[1]{{\xrightarrow{#1}}\raisebox{0.4ex}{\scriptsize*}}%
\begin{document}
$\xrightarrow\tau^*$

${\xrightarrow\tau}\raisebox{0.4ex}{\scriptsize *}$

$\myxrightarrow{\tau}$
\end{document}

-
I had something similar, but I put the \tau in the \raisebox to make it have zero height. That way, one doesn't have to guess the vertical offset (but the resulting shape might be smaller than it really is). –  Andrew Stacey Nov 22 '11 at 11:05
use another font size and it will be funny ... –  Herbert Nov 22 '11 at 14:29

Here's another version which defines a new arrow, \xrighttransarrow (maybe there's a better name ...). This is an extensible arrow modelled on the definition of \xrightarrow which makes the * a part of the arrow, rather than a decoration to be added on afterwards. There's a bit of jiggery-pokery to get the spacing right: the * has to be ignored as far as the placement of the \tau is concerned, but then it has to be taken into account when positioning the arrow with its surrounding text. I may well have messed up those bits as I'm no expert on lengths. It's also possible that it would go wrong in different maths styles.

Here's the code:

\documentclass{article}
\usepackage{amsmath}

\makeatletter
\newdimen\arrow@ht
\setbox\@tempboxa\hbox{$$\rightarrow$$}
\arrow@ht\ht\@tempboxa
\newdimen\star@wd
\setbox\@tempboxa\hbox{$$\scriptstyle *$$}
\star@wd\wd\@tempboxa
\def\righttransarrowfill@{\arrowfill@\relbar\relbar{\raisebox{0pt}[\arrow@ht][0pt]{$$\rightarrow^*\hskip-\star@wd$$}}}
\setbox\@tempboxa\hbox{$$\rightarrow$$}
\arrow@ht\ht\@tempboxa
\newcommand{\xrighttransarrow}[2][]{\ext@arrow 0359\righttransarrowfill@{#1}{#2}\hskip\star@wd}
\makeatother

\begin{document}
$$a\rightarrow^* b a\xrightarrow\tau^* b a\xrightarrow{\raisebox{0pt}[0pt][0pt]{\(\scriptstyle\tau$$}}^* b
a \xrighttransarrow\tau b
\)
\end{document}


Here's the result (note that there's also another \raisebox solution in the middle there):

-

Here is a simpler definition

\newcommand{\tto}[1][]{\mathrel{
\vphantom{\xrightarrow{#1}}
\smash{\xrightarrow{#1}}
\vphantom{\to}^*}
}

$\tto$
$\tto[\tau]$


-