Is there a test for the different styles within maths mode? What I really want is to be able to save the current style to reinvoke it later on, but a \if
along the lines of \ifmmode
would work just as well.
In the specific example, I want to measure how big something will be when displayed in maths mode, so I do:
\settoheight{\mathheight}{some bit of maths}
except that it complains because the some bit of maths
gets put in a box and measured, and the box doesn't know that it's maths. So instead I put:
\settoheight{\mathheight}{\(some bit of maths\)}
except that then I get the wrong answer if this is used in displayed maths. So ideally, I want:
\ifdisplaystyle
\let\currentstyle\displaystyle
\else
\iftextstyle
\let\currentstyle\textstyle
...
\fi
\fi
\settoheight{\mathheight}{\(\currentstyle some bit of maths\)}
and then I'll be happy.
Is there such a test?
Okay, so \mathchoice
is clearly the way to go (thanks Martin!), but its behaviour is a little odd and since I want to use it to define a macro depending on which mode I'm in, this oddity is quite important. Here's the code:
\newcommand{\mathtest}{%
\gdef\name{a}%
\mathchoice{%
\name
\gdef\name{b}%
}{%
\name
\gdef\name{c}%
}{%
\name
\gdef\name{d}%
}{%
\name
\gdef\name{e}%
}%
\name}
\[
\mathtest
\]
If \mathchoice
behaved like \if
, this ought to print ab
. But it prints ae
. All the options to \mathchoice
get processed (which makes me wonder a bit how it works, but that's by-the-by).
So, is there an obvious way to make \mathchoice
behave a little more like \if
?
mathstyle
package doesn't work for\( .. \)
making it not work for what I want (which is closer to the first example than the second - that was to show that\mathchoice
didn't behave how I wanted).\mathchoice
, see TeX by Topic: 'The primitive command\mathchoice{D}{T}{S}{SS}
lets the user specify four variants of a formula for the four styles. TeX constructs all four and inserts the appropriate one.'