Thinking about the issue posted in Colors in underbrace and overbrace - strange behaviour I thought that the reboxing which TeX performs for a \mathop with \limits caused the color to leak outside of the current box. However, colour-leaking isn't the only problem, since also the behaviour of \limits is broken by a non-grouped \color
\documentclass{article}
\usepackage{color}
\begin{document}
\hsize=5cm
Fine:
[
\mathop{{\color{red} foo}}^{A}{B}
\quad
\mathop{foo}^{{\color{red} A}}{B}
\quad
\mathop{foo}^{A}_{{\color{red} B}}
]
Not fine (well, the last \emph{is}):
[
\mathop{\color{red} foo}^{A}{B}
\quad
\mathop{foo}^{\color{red} A}{B}
\quad
\mathop{foo}^{A}_{\color{red} B}
]
\end{document}
Of course, grouping is the correct way to go; but I'm curious why the colour \special breaks the correct limit placement.


\sboxadds an extra group\colorinserts a color restore whatsit via\aftergroupand that whatsit comes where it comes... The extra group keeps it in the superscript. – David Carlisle Dec 24 '20 at 17:23