How to create a squiggle arrow with some text on it in TikZ?

I need to define a new command to create a squiggle arrow with some text on it. Something similar to what \xrightarrow command produces but with wiggly arrows as in \rightsquigarrow. The length of the arrow should automatically be adjusted to fit the text above it and I do not know how to handle this part in TikZ. Any ideas would be much appreciated.

-
You can put your node and decorate a regular arrow going from (nodename.south west) to (nodename.south east) with a little extra adjustment (Check the manual page 49) but why do you need TikZ for this? Is there any disadvantage of the ones you mentioned? – percusse Jun 18 '12 at 1:17
@percusse: I guess there is no \xrightsquigarrow. – Caramdir Jun 18 '12 at 1:59
@Caramdir Aha, that explains it :) – percusse Jun 18 '12 at 2:02
Related: Squiggly arrows in tikz – Jake Jun 18 '12 at 4:34

As percusse mentions in his comment, you can use a node and a decorated arrow; something like this:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{decorations.pathmorphing,shapes}

\newcounter{sarrow}
\newcommand\xrsquigarrow[1]{%
\stepcounter{sarrow}%
\begin{tikzpicture}[decoration=snake]
\node (\thesarrow) {\strut#1};
\draw[->,decorate] (\thesarrow.south west) -- (\thesarrow.south east);
\end{tikzpicture}%
}

\begin{document}

\end{document}


The following code contains a new version of \xrsquigarrow using the zigzag decoration and \mathrel to be used in math-mode; it shows a comparison between \xrightarrow, \rightsquigarrow and \xrsquigarrow (some fine-tuning is still required, but I leave that to you):

\documentclass{article}
\usepackage{amsmath,amssymb}
\usepackage{tikz}
\usetikzlibrary{calc,decorations.pathmorphing,shapes}

\newcounter{sarrow}
\newcommand\xrsquigarrow[1]{%
\stepcounter{sarrow}%
\mathrel{\begin{tikzpicture}[baseline= {( $(current bounding box.south) + (0,-0.5ex)$ )}]
\node[inner sep=.5ex] (\thesarrow) {$\scriptstyle #1$};
\path[draw,<-,decorate,
decoration={zigzag,amplitude=0.7pt,segment length=1.2mm,pre=lineto,pre length=4pt}]
(\thesarrow.south east) -- (\thesarrow.south west);
\end{tikzpicture}}%
}

\begin{document}

$A\xrightarrow{f} B\quad A\rightsquigarrow B\quad A\xrsquigarrow{f}B\quad A\xrsquigarrow{(f\circ g)\circ h}B$

\end{document}


This definition does not cover the case in which the arrow is to be used in super/sub-scripts.

-
Thanks, Gonzalo! This is very similar to what I had in mind. The only difference is the shape of the arrow that does not exactly look like \rightsquigarrow. This is important since I want to use the command in math mode and thus, it has to have a clean look. For example, $s \xsquigarrow{OR} t$ means a special operation between $s$ and $t$. The way you have defined the command does not produce a neat output in this setting. I am under impression that the wiggle type must have something to do with the "segment amplitude" and "segment length" of the arrow. Do you have any idea for fixing this? – Ali Jun 18 '12 at 2:35
@Ali in this case, use the zigzag decoration and appropriate values for amplitude and segment length; I'll give an example in some minutes. – Gonzalo Medina Jun 18 '12 at 2:50
I customized your command as follows: \newcounter{sarrow} \newcommand\xrsquigarrow[1]{% \stepcounter{sarrow}% \begin{tikzpicture} \node[scale=0.5] (\thesarrow) {\mathstrut#1}; \draw[->,snake=zigzag,segment amplitude=.3mm,segment length=1.3mm,line after snake=.9mm] (\thesarrow.south west) -- (\thesarrow.south east); \end{tikzpicture}% } This almost produces the right output in math mode, e.g., $s \xrsquigarrow{OR} t$. I am just wondering how I can add some free space between the math symbols and the arrow? Thanks again. – Ali Jun 18 '12 at 3:19
@Ali please see my updated answer. – Gonzalo Medina Jun 18 '12 at 3:23
Great! Thanks a lot, Gonzalo! – Ali Jun 18 '12 at 3:29