TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I wish to write a macro which will be able to tell whether the machine is currently in mathmode or not. The pseudo-code is:

%other commands

Is such a thing possible? And if so, how?

share|improve this question
up vote 14 down vote accepted

You may want to declare it with \DeclareRobustCommand as you need to protect this from expanding at the wrong time.

share|improve this answer
That seems to work. Thanks! – Ron Feb 17 '12 at 20:12
@David I would add a \relax at the start here, just to be on the safe side. – Joseph Wright Feb 17 '12 at 20:35

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.