I redefined `^` to give different colors depending on whether it is a superscript, supersuperscript, etc using the following:

```
\catcode`^\active
\def^#1{%
    \mathchoice{%
        \sp{\color{red}#1}%
    }{%
        \sp{\color{blue}#1}%
    }{
        \sp{\color{green}#1}%
    }{
        \sp{\color{orange}#1}%
    }%
}

```

This yields
[![enter image description here](https://i.stack.imgur.com/r0pIW.png)](https://i.stack.imgur.com/r0pIW.png)

which is what I wanted. However, when I have a big operator like `\sum`, the code

```
\sum_{n=1}^\infty \frac{1}{n}

```

yields
[![enter image description here](https://i.stack.imgur.com/xkK7U.png)](https://i.stack.imgur.com/xkK7U.png)
instead of putting the `\infty` correctly in the limit. If I don't use `\mathchoice`, this doesn't happen. Is there a way to fix this?

Side note: I'm not sure why blue is skipped in the colors. Shouldn't the `k` and `+1` be blue, not green?