10

This question explains the difference between \over and \frac and it seems as though the most experienced members unanimously agree that \over is inferior (if not something to be outright regretted); however, egreg's example, while illustrative of a potential issue, isn't quite enough to deter me from the practicality of \over.

I just discovered this command and have not yet implemented it anywhere, but find substantial allure in the practicality of not having to use delimiters everywhere (especially as I do extensive colour-coding of expressions, which also multiplies delimiters).

I trust the experience in this community, but would like, if possible, to understand what kind of practical issues I run the risk of encountering with the occasional use of \over when dealing with simple expressions?

Because practical is subjective, I will attempt to illustrate the intended measure with egreg's example: he illustrated the difference in rendering between:

\[
  \fam0 a \over b
\]

and

\[
 \frac{\fam0 a}{b}
\]

For my purposes, should such an issue arise, it is easily resolved by using \frac and so, while this example illustrates a shortcoming of \over and the need for something more robust, it does not illustrate to me any reason to eschew \over when it does yield the desired output.

10
  • 1
    By "simple expressions" do you mean 1 \over 2? In general, if there's any surrounding math, you'd still need bracing (in the form {1 \over 2}. Have you tried using \frac a b? The output might just be what you're after.
    – Werner
    Apr 18, 2017 at 16:15
  • \frac{a}{b} is seven tokens, eleven characters; {a\over b} is five tokens, ten characters. You have a real gain only in simple formulas such as $a\over b$ (three tokens, eight characters, not counting $) whereas $\frac{a}{b}$ is seven and eleven as before, but I guess these will be a little minority in your document.
    – egreg
    Apr 18, 2017 at 16:42
  • 3
    @RaxAdaam: It's best to stick to one thing, since it provides consistency. It also means you can tap into the macro constructions for later modification, if needed. See Consistent typography.
    – Werner
    Apr 18, 2017 at 16:51
  • 2
    @RaxAdaam While \frac ab works, I cannot recommend it. Typing \frac{a}{b} is just as quick and clearer. You'll never find something such as \frac12 in my answers on Math.SE.
    – egreg
    Apr 18, 2017 at 16:51
  • 2
    @RaxAdaam There's an interview of Knuth where he's asked about this (naturally, he prefers typing \over). If I can dig it up, I'll post an answer. Apr 19, 2017 at 0:02

2 Answers 2

9

In The TeX tuneup of 2014 (TUGboat, Volume 35 (2014), No. 1), which discusses all changes made to TeX based on comments received in the years 2008–2013 (all changes = a single change: see this question), Donald Knuth answers a question about \over versus \frac and similar:

Questions and Answers Barbara [Beeton] also asked me to answer three questions, which she said “keep coming up in various forums,” so that she could point people to the answers if those questions come up again.

[…]

(2) If you were designing TeX today, would you still use \over and friends, rather than something like \frac{...}{...}, when the latter would avoid the necessity of \mathchoice and \mathpalette?

This question, from tex.stackexchange.com, also quoted from page 151 of [The TeXbook]:

\mathchoice is somewhat expensive in terms of time and space, and you should use it only when you’re willing to pay the price.

And well, I guess that quote implies my answer. For I was clearly willing to pay the price in 1982, so I’m certainly willing to pay zero today!

I suppose there are some people in the world who prefer expressions like ‘sum(2, 3)’ to ‘2 + 3’; but I’m certainly not among them. Ever since TeX was born, I’ve been enormously pleased by the ability to write ‘2\over3’ or ‘n\choose k’ or ‘p\atop q’ or ···, instead of being forced to write something like ‘frac{2}{3}’ that would have distracted my attention from the task at hand.

The questioner seems to want to place burdens on all users, rather than on the backs of a few macro-developers.

If you look at LaTeX’s definition of \frac (you can invoke texdoc source2e to read it), you'll see that it is:

defininion of <code>\frac</code>

(You can also find this definition

\def\frac#1#2{{\begingroup#1\endgroup\over#2}}

in texmf-dist/source/latex/base/ltmath.dtx, or with \show, or whatever.)

So whenever you type \frac{a}{b} in a document, it is exactly as if you had typed:

{\begingroup a \endgroup\over b}

There is nothing more, or magical, about using \frac. And if in a given (typical) context the \begingroup and \endgroup are not needed (i.e., the same output is produced without them), you can drop them, and similarly for the outer braces, so that it would be equivalent to writing a \over b in that case.

So as far as your question goes:

For my purposes, should such an issue arise, it is easily resolved by using \frac and so, while this example illustrates a shortcoming of \over and the need for something more robust, it does not illustrate to me any reason to eschew \over when it does yield the desired output.

there is simply no practical difference of the kind you're looking for: when \over yields the desired output, they are equivalent; the only point of using \frac is that sometimes they are not equivalent and \over may give you undesired output.

So for a summary: your choice boils down into two options:

  1. You like the \frac syntax. Then use it, and congratulate yourself that you don't have to worry about accidentally getting the wrong output, and on being "consistent" with verbose LaTeX syntax conventions.

  2. You like the \over syntax. Then use it, and congratulate yourself on the simpler syntax (preferred by Knuth too), and if you ever accidentally get the wrong output, just notice it and fix it, telling yourself it's not a big deal.

When you ask for “practical consequences” and say you

can't imagine a context where using \over would cause a problem that couldn't be solved by just using \frac for that instance

I don't know what sort of answer you're looking for, because there does not exist any such context, by definition (of \frac): if in some context \over gives the wrong output, you can always fix it by adding braces or groups, and indeed by using \frac. That's what it's for.

1
  • This is really outstanding for the completeness of answer, context and definitions etc, thank you! I can't tell if you're intentionally misreading my statement, at the end, or just interpreting it loosely to really drive home your point about the definition, but when I said "_I can't imagine a context where using \over ... _," I meant using just \over (or { #1 \over #2}), without additions. My point was that \frac{#1}{#2}, from a results perspective (not knowing the definition, previously) did simply seem to be a dressed-up \over for some ambiguous case. Thank you for clarifying!
    – Rax Adaam
    Feb 13, 2018 at 16:32
17

There are no advantages to using \over in a LaTeX document.

A major aim of LaTeX is to give a consistent syntax for a tex based markup, with mandatory arguments in {} optional ones in [] etc. so \rule{2pt}{3pt} not \hrule width 2pt height 3pt. Using \over breaks that completely.

If you use \over with amsmath loaded you get the warning

Package amsmath Warning: Foreign command \over;
(amsmath)                \frac or \genfrac should be used instead
(amsmath)                 on input line 6.

In many ways it's a shame that is only a warning not an error, we and the AMS were just not quite brave enough at the time:-)

Practically speaking of course within TeX \over will work in most cases, unless some package does get braver and undefined it, however the fact that it does not obey the same syntax rules does have a cost, notably on TeX to html and other convertors. Without using a full TeX execution engine it is quite hard to know what are the arguments of \over and so it complicates the job of convertors which may not support it at all, or only support simple cases.

If you think the \over syntax is simpler, answer the following question before running the example.

What is the fraction in each of these cases?

\documentclass{article}



\begin{document}
$  1 + \begingroup a \over b \endgroup + 2$

$  1 + \bgroup a \over b \egroup + 2$

$  1 + { a \over b \egroup + 2$


$  1 + \bgroup a \over b } + 2$

\end{document}
9
  • 1
    Bravo! Bravo, maestro! Apr 18, 2017 at 16:33
  • 3
    Thank you for the reply. This still seems to be a theoretical argument rather than a practical one (& I agree, the given reasons make sense, but given that we have \over I'm trying to understand why I shouldn't make use of it, when advantageous). While I appreciate the illustration, I would personally avoid the issue by a) using a convention for my begin / end group: I like { a \over b } more than the \frac alternative (both more readable and less annoying) and b) using \frac only for complicated expressions where over wouldn't work (an example of which I cannot yet imagine).
    – Rax Adaam
    Apr 18, 2017 at 16:38
  • 1
    David. Thanks. You just greatly improved my answer at tex.stackexchange.com/questions/332012/… Apr 18, 2017 at 17:11
  • 2
    @RaxAdaam it has no advantages and you may wish to convert your tex to html and not have it fail or use amsmath and not have it scream at you, they seem practical rather than theoretical issues. Apr 18, 2017 at 18:51
  • 1
    @DavidCarlisle true - conversion to html is a practical point (albeit quite easily dealt with assuming one did use a consistent begin/endgroup convention); the point was lost on me between the other examples, which are not. I do not consider automated complaints from from a compiler to be a practical issue - I'm just not that sensitive :) If this is really the extent of the issue, I don't see any reason not to use it when convenient... &nd I do believe it has one clear advantage: fewer curly braces. I also find it reads quite naturally and leaves the code less busy.
    – Rax Adaam
    Apr 18, 2017 at 23:27

You must log in to answer this question.

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