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 defined this macro:


Later on, I noticed that when it's used inside a subscript, it looks a little bit hard to tell whether it's $\sim f$ or $\sim_f$. ($\sim f$ is not meaningful, but that's beside the point.) So I added an additional macro, for use in subscripts (and in principle superscripts, though that also would not be meaningful):

\newcommand{\scriptfoldeq}[1]{\foldeq{\raisebox{-0.25mm}{$\scriptscriptstyle #1$}}}

But then it occurred to me that it would be quite convenient if there is a way to detect whether a macro is being called inside a subscript or superscript, and react accordingly. Is there?


Using David's answer, here is what my original macro looks like now:

    \sim_{\mathchoice{}{}{#1}{\raisebox{-0.25mm}{$\scriptscriptstyle #1$}}}
    % {\sim_f} looks similar to {\sim f} in subscript/superscript.
share|improve this question
up vote 10 down vote accepted

You can use \mathchoice or its wrapper \mathpalette . These don't really detect where the macro is being used, they simply set the content four times in four different styles and TeX uses the appropriate box when laying out the mathematics.

enter image description here


$$\test {\test \over \test} \test^{\test^\test} $$

\centerline{$\test {\test \over \test} \test^{\test^\test} $}

share|improve this answer

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.