You can’t. In order to understand why, you need to know how \over
works.
When TeX finds \over
(or \atop
, \above
, \overwithdelims
, \atopwithdelims
, \abovewithdelims
), it saves the math-list-so-far (the numerator) in a special stack and proceeds to build a new math list with what comes after \over
(the denominator). When the current group ends, which might had been started with $
, $$
, {
or \left
, TeX finally knows what style the (generalized) fraction should be typeset in. At this point TeX can assign the correct math style to every item in the numerator and denominator so to actually append a fraction atom to the current math list.
As a consequence of this, you can do nothing more on the numerator, which has already been transformed in a math list, only awaiting to get style assignment to its items.
You might redefine \over
to do the primitive \over
and issue \color{red}
, which will color the denominator. But beware that you need to read the two arguments in the case of \...withdelims
.
This is similar to the strategy of amsmath
tat saves \over
as \@@over
and redefines it to do \@@over
and issue a warning. However, this warning is only issued once, but it's not difficult to modify the behavior so every use triggers the warning.
This is achieved in \primfrac
:
\DeclareRobustCommand{\primfrac}[1]{%
\PackageWarning{amsmath}{%
Foreign command \@backslashchar#1;\MessageBreak
\protect\frac\space or \protect\genfrac\space should be used instead%
\MessageBreak
}
\global\@xp\let\csname#1\@xp\endcsname\csname @@#1\endcsname
\csname#1\endcsname
}
As you see, the line starting with \global
redefines the command \over
or sibling into the corresponding primitive. Just remove the \global
.
Example.
\documentclass{article}
\usepackage{amsmath}
\makeatletter
\DeclareRobustCommand{\primfrac}[1]{%
\PackageWarning{amsmath}{%
Foreign command \@backslashchar#1;\MessageBreak
\protect\frac\space or \protect\genfrac\space should be used instead%
\MessageBreak
}
\@xp\let\csname#1\@xp\endcsname\csname @@#1\endcsname
\csname#1\endcsname
}
\makeatother
\begin{document}
Here I use a fraction $a\over b$.
Here I use a generalized fraction $a\choose b$.
Another fraction $a\over b$.
\end{document}
This will produce in the log file
Package amsmath Warning: Foreign command \over;
(amsmath) \frac or \genfrac should be used instead
(amsmath) on input line 18.
Package amsmath Warning: Foreign command \atopwithdelims;
(amsmath) \frac or \genfrac should be used instead
(amsmath) on input line 20.
Package amsmath Warning: Foreign command \over;
(amsmath) \frac or \genfrac should be used instead
(amsmath) on input line 22.
Only the first two would appear without removing \global
.
However, you see that \choose
triggers a warning about \atopwithdelims
rather than \choose
. This is because LaTeX adopts plain TeX's definition
\def\choose{\atopwithdelims()}
You may want to add
\let\@@choose\choose
\renewcommand{\choose}{\primfrac{choose}}
so you will also get
Package amsmath Warning: Foreign command \choose;
(amsmath) \frac or \genfrac should be used instead
(amsmath) on input line 23.
in addition to the same warning for the subsequent usage of \atopwithdelims
.
\over
is one of aPlainTeX
tag, it's better to use\frac
, if you ready to change to\frac
some suggestions are there\over
to\frac
and I really don't need to do it.