3

I was thinking about doing something crazy, namely, I want to define a "newcommand" by

\renewcommand{\alpha}{\ensuremath{\alpha}}

so that later in text mode I can just do \alpha instead of $\alpha$ (The actual macro will have \xspace in it, but let's ignore that.).

The question is, how do I let the system know, when it replace \alpha by \ensuremath{\alpha} to use the "built-in" macro \alpha, instead of the renewed one, and thus not stuck in an infinite loop?

Or, is there a way to make sure the macro only "expand" once?

Werner
  • 603,163
h__
  • 821
  • Don't moan when you find that the result of \alpha-\beta is different from what you'd expected. There's no reason why math symbold should be used in text without proper markup. – egreg Feb 20 '13 at 07:36
  • Well, that's what I expected, so I will take care. You see lots of the time people want to write \alpha-male or \epsilon-neighborhood, \delta-ball etc. And there is no easy solution for that. – h__ Feb 20 '13 at 08:13
  • For alpha-male, you can always write it in full text. For \epsilon-neighborhood, you really should write it with dollars : see for example the difference between $\epsilon$'-neighborhood (expansion of your macro) and $\epsilon'$-neighborhood (what you probably want to write). The point is : if it is always the same math symbol with the same text, you can encapsulate all in a macro. But if it may vary, you should stick with math markup. You can also see http://tex.stackexchange.com/questions/34830/when-not-to-use-ensuremath-for-math-macro. – T. Verron Feb 20 '13 at 08:21
  • @T.Verron I understand that primes are funny and will take care of that. I will put it in math mode whenever it is not a single letter. – h__ Feb 20 '13 at 08:27
  • 1
    @hyh Yes, there is an easy solution for that: $\alpha$-male. But, since it's a technical term in a non mathematical field, probably \alphamale with a proper definition would be preferable. – egreg Feb 20 '13 at 08:46

1 Answers1

5

I'm not sure why you would want to do this, but here's how anyway

\let\oldalpha\alpha
\renewcommand{\alpha}{\ensuremath{\oldalpha}}

Your queried approach would result in an infinite loop. The \let essentially makes an alias for the former meaning of \alpha which will allow you to redefine it later.

A.Ellett
  • 50,533