In my copy-editing work I need to fix the layout of equations in the submitted papers.

To make it easier and faster it would be helpful to have the all fractions generated by the \over command displayed in red in the .pdf document.

Is there a way to achieve this? (Maybe redefining the \over command or adding something else in the preamble?)

  • \over is one of a PlainTeX tag, it's better to use \frac, if you ready to change to \frac some suggestions are there
    – MadyYuvi
    Jan 31 at 5:03
  • I know, but I always found to complicate to change \over to \frac and I really don't need to do it. Jan 31 at 5:17
  • 1
    if you use ansmath then frac is already redefined and over is defined to make a warning Jan 31 at 8:09

2 Answers 2


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:

Foreign command \@backslashchar#1;\MessageBreak
\protect\frac\space or \protect\genfrac\space should be used instead%
  \global\@xp\let\csname#1\@xp\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.



Foreign command \@backslashchar#1;\MessageBreak
\protect\frac\space or \protect\genfrac\space should be used instead%
  \@xp\let\csname#1\@xp\endcsname\csname @@#1\endcsname


Here I use a fraction $a\over b$.

Here I use a generalized fraction $a\choose b$.

Another fraction $a\over b$.


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


You may want to add


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.


I show that colorizing fractions declared by \over is possible. My experimental code is designed for OpTeX:

   {\def\mlist{}\checkover {#2}\_ea}\_ea\addto\_ea\mlist\_ea{\_ea{\mlist}}%
   \_ea \scanmath\_fi}
\def\checkover #1{\def\tmp{#1}\isinlist\tmp{\over}\iftrue
   \addto\mlist{\Red #1}\else \scanmath #1{\_fin}\fi}
\def\checkmath #1${\def\mlist{}\checkover{#1}\mlist$}
\def\checkdisplay #1$${\def\mlist{}\checkover{#1}\mlist$$}

     a &= {1\over2} b + {4\over 5} \cr
     b &= {7\over {8\over 9}} }

The text $a\over b$ and $c={d\over e}$.


The \everydisplay runs \checkdisplay and \everymath runs \checkmath. The whole math formula is read to the #1 parameter and then it is checked if there is \over at "outer group level". If it is true then \Red is appended. Else we check if there is something like ...{...}...{...}.... Each such partial group is scanned separately and if there is \over then \Red is appended.

This experimental macro isn't universal. It doesn't check correctly the patterns like \left(...\over...\right), you must to write \left({...\over...}\right) instead it.

  • The approach is somewhat similar to math mode - Can I redefine the dollar - TeX - LaTeX Stack Exchange but it uses everydisplay/everymath. If you have some command/environment that enters math mode (e.g. \begin{align*} in LaTeX) it doesn't work though.
    – user202729
    Jan 31 at 15:24
  • // of course this answer also assumes the \over appears in "top-level" instead of hidden in some command, and there's no catcode-changing commands inside the math mode.
    – user202729
    Jan 31 at 15:29
  • 3
    OpTeX doesn't use nothing like \begin{align}, so there is no problem. Catcode changing is not typical inside math mode. OP asks to colorize fractions created directly by \over, no by macros which "hide" the \over primitive.
    – wipet
    Jan 31 at 16:17
  • OpTeX is not going to improve LaTeX.
    – user206750
    Feb 1 at 2:01
  • 3
    OP doesn't mention LaTeX. OK, if my macro prototype should be used as starting point for LaTeX, more work have to be done.
    – wipet
    Feb 1 at 6:38

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .