# Optional math symbols as arguments to custom command

I have a custom command defined as

\newcommand{\transition}[1]{$\stackrel{\texttt{#1}}{-->}$}


The argument that I pass to the command can sometimes be normal text and thus is formatted using \texttt{text} and sometimes I want to pass a math symbol such as \tau or \alpha or a combination of these.

Is there a way how I can reason on the argument being passed, such as introduce an if then else depending on the type of the parameter?

-

Use \mathtt instead.

\documentclass{article}
\usepackage{amsmath}
\newcommand{\transition}[1]{\ensuremath{\xrightarrow{\mathtt{#1}}}}
\begin{document}
\transition{foo}
\transition{\alpha}
\end{document}


You can use \textstyle before #1 if you want lager text.

-
Maybe you should explain, that you've used \ensuremath instead of $$ to make \transition work not only in text but also inside of math. – Schweinebacke Dec 9 '11 at 8:41
works great! thanks – aseychell Dec 9 '11 at 9:54