4

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?

1 Answer 1

5

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.

1
  • 3
    Maybe you should explain, that you've used \ensuremath instead of $$ to make \transition work not only in text but also inside of math. Dec 9, 2011 at 8:41

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .