I recently looked up J. van Hoorn's question on How to color delimiters in Math Mode, and so I decided to test my LaTeX knowledge by trying to define a new appropriate command: \leftcolor{color}<delim symbol> and \rightcolor{color}<delim symbol>.
The MWE is as follows:
\documentclass{article}
\usepackage{amsmath}
\usepackage{xcolor}
%
\newcommand*\leftcolor[2]{%
\color{#1}\left#2\normalcolor%
}
\newcommand*\rightcolor[2]{%
\color{#1}\right#2\normalcolor%
}
%
\begin{document}
\begin{equation*}
%
\leftcolor{red}(\frac{a}{b}\rightcolor{red})^n \neq \left(\frac{a}{b}\right)^n
%
\end{equation*}
\end{document}
The problem can be seen in the result shown below:
I clearly see that the exponent positioning is wrong, but I have no clue on how LaTeX puts that symbol in this way, because I followed the only option possible for the correct coloring (even after searching on the xcolor documentation I didn't find anything related to this topic).
My guess is that the effective size of the delimiter is "faked" in such a way that the compiler finds more correct to put the exponent as one normal size delimiter rather than the extended one.
I don't know if there is some plain TeX or LaTeX string to help about this situation, because the most common solution in these cases involves the making new delimiters such as:
\customdelim{\frac{a}{b}}^n % these commands are not present in this case
The fact is that I don't request this kind of macro because I want to be able to switch directly from one color to another as a specific argument.




Undefined Control Sequencefor\yphantom, and after trying\vphantomthe! Missing delimiter (. inserted)appears, I'm sorry but LaTeX doesn't want to end this so easily :) – TheVal Jul 28 '13 at 20:25! Missing delimiter (. inserted). – TheVal Jul 28 '13 at 20:29(in the preamble, gives the same error as before. Maybe I fonud one of DEK allowance valuable bugs :-) – TheVal Jul 28 '13 at 20:41\leftand\rightneed to be in the same group. You can’t put only one of them in a\vphantom. You could put both in it but then they need also the original content (here the fraction) to actually expand to the right size. The problem here seems to be an internal\aftergroup\reset@colorwhich will act as the base for the superscript. But you already use a\normalsizeafter the\right#2which will act as a base for the superscript. See{\frac{a}{b}}^2 = {\frac{a}{b}}\normalcolor^2– Qrrbrbirlbel Jul 28 '13 at 20:48bgroup/egroupvery well). – TheVal Jul 28 '13 at 21:02