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

Gabriele
  • 1,815

2 Answers2

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.

campa
  • 31,130
egreg
  • 1,121,712
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.

wipet
  • 74,238