# mathchoice and spacing

I am using \mathchoice to define a command \norm that acts differently when in displaystyle or not but I have problem with spacing.

My problem is well illustrated in the following example:

\documentclass{minimal}

\newcommand\myBig{\mathchoice{\bigg|}{}{}{}}
\begin{document}
$$\Bigg|_a$$
$$\myBig_a$$
\end{document}


which gives me The first line is what I want. The second one is not correct because the "_a" is too high.

It seems that using mathchoice acts as if there was a {} after the command. Is it possible to avoid this behaviour?

Do you mean like this?

\documentclass{article}

\newcommand\myBig{{\mathchoice{\bigg|}{}{}{}}}

\begin{document}

$\Bigg|_a \quad \myBig_a$

\end{document}


## Explanation

\mathchoice doesn't make a math atom that can take subscripts and superscripts. Well, this is not the complete truth and even the TeXbook is not very explicit on this point, but it is sufficient for describing the particular issue. With the braces, you make an ordinary math atom around the \mathchoice, so the subscript is appended to this atom.

## Caveat

Never use the minimal class for examples. See Why should the minimal class be avoided?

Never use $$ in LaTeX. See Why is $...$ preferable to$$ ... ?

• Related to the title of the question, could you add something explaining why \mathchoice{\times}{\sin}{=}{(} spaces correctly? Not tried that now, but I know I questioned why did \mathchoice space correctly things that were “inside”, because I believed it first made a box then put the correct box there. Mar 28 '17 at 15:33
• @Manuel Define “space correctly”; if you add ^2 after the mathchoice construction, it doesn't seem to be placed as if the construction was an atom. Mar 28 '17 at 15:38
• I meant it behaves as if it was a \mathbin in \displaystyle, a \mathop in \textstyle, a \mathrel in \scriptstyle, and a \mathopen in \scriptscriptstyle. I haven't tested it right now, but I remember it behaved weirdly in that sense; and if that's the case (and I'm not mistaken), you can add that info to the answer, I believe it's the perfect excuse. Mar 28 '17 at 15:40
• @Manuel I've changed the description Mar 28 '17 at 15:49
• Okey, I guess it needs a new question. I was curious about why did \mathchoice behave that way, while the official explanation has always been “it makes four boxes and then chooses the correct one”. Mar 28 '17 at 16:19