4

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?)

3
  • \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

4

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.

4

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

\def\scanmath#1#{\scanmathA{#1}}
\def\scanmathA#1#2{\addto\mlist{#1}\ifx\_fin#2\else
   {\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$$}

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

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

\bye

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.

5
  • 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 .