I'm trying to write a macro that returns different things depending on it if is used in a displayed equation or if it is used in an inline equation. Something like this, I assume:

        This equation is displayed!
        This equation is inline!

I assume there's a way to do this, as $\sum$ and $$\sum$$ look different. How is it done?

  • 3
    Possible duplicate: What is \mathchoice?
    – Werner
    Sep 11, 2018 at 18:24
  • 1
    I think the questions are certainly similar. If your answer had simply been "go read this question", that would have been enough. I'm not very familiar with StackExchange's opinion on how similar things should be to be marked as duplicate, so maybe it's correct to do so. I think my question has the advantage of being asked in a way that someone might be able to find it without knowing the solution (figure out how \mathchoice works and then use it).
    – Pi Fisher
    Sep 11, 2018 at 19:28

1 Answer 1


You can use \mathchoice in the following way to condition:

  {<display style>}
  {<text style>}
  {<script style>}
  {<script-script style>}

to discern between what is displayed within the respective styles. Here's an example:

enter image description here


    {D} % \displaystyle
    {T} % \textstyle
    {S} % \scriptstyle
    {s} % \scriptscriptstyle


See $\foo^{\foo^{\foo}}$. Also see
  \quad \mbox{and} \quad
  \textstyle \foo_{\foo_{\foo}}


You must log in to answer this question.

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