1

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}

enter image description here

Of course, grouping is the correct way to go; but I'm curious why the colour \special breaks the correct limit placement.

campa
  • 31,130
  • 1
    this is basically the whole "color safe" boxing introduced in latex2e, why \sbox adds an extra group \color inserts a color restore whatsit via \aftergroup and that whatsit comes where it comes... The extra group keeps it in the superscript. – David Carlisle Dec 24 '20 at 17:23

1 Answers1

3
\documentclass{article}
\usepackage{color}\showoutput
\begin{document}
\hsize=5cm
\[
\max^{{\color{red} A}}
\]
\[
\max^{\color{red} A}
\]

\end{document}

This is the same issue as the "colour safe groups" introduced for \sbox etc.

\color introduces a color restore via \aftergroup and without the extra group this drops out of the superscript.

the log shows.

...\hbox(12.08887+0.0)x18.61118, shifted 61.82631, display
....\vbox(12.08887+0.0)x18.61118
.....\kern1.0
.....\hbox(4.78334+0.0)x18.61118, glue set 6.29863fil
......\glue 0.0 plus 1.0fil minus 1.0fil
......\hbox(4.78334+0.0)x6.01392
.......\pdfcolorstack 0 push {1 0 0 rg 1 0 0 RG}
.......\OML/cmm/m/it/7 A
......\pdfcolorstack 0 pop

with the grouped case the color pop comes after A

but with the ungrouped case

.....\hbox(4.78334+0.0)x18.61118, glue set 6.29863fil
......\glue 0.0 plus 1.0fil minus 1.0fil
......\pdfcolorstack 0 push {1 0 0 rg 1 0 0 RG}
......\OML/cmm/m/it/7 A
......\glue 0.0 plus 1.0fil minus 1.0fil
.....\kern1.99998
.....\hbox(4.30554+0.0)x18.61118
......\OT1/cmr/m/n/10 m
......\OT1/cmr/m/n/10 a
......\OT1/cmr/m/n/10 x
....\pdfcolorstack 0 pop

the color pop comes after max

enter image description here


In the cases that you show with a B not under max the color restore whatsit has been placed before the _B so it is subscripting that node, not the mathop.

David Carlisle
  • 757,742