Is it wrong to use \frac1{}?

When typing math in (La)TeX, I often omit the braces surrounding the first argument to the \frac macro, at least when it's 1, writing things like \frac1{1+x^2}. I initially came by that use while reading a document written by someone else, and thought it was a different macro (which one might define as \newcommand{\frac1}[1]{\frac{1}{#1}}.

Although I now understand the way \frac1 works, I still wonder : is this an acceptable use, or is it generally frowned upon?

• although you won't find it in the ams documentation, \frac12 is often used, and works perfectly well, to produce "one half". not purist, but not generally misunderstood by readers of the input either. (do be kind, though, and leave a space after the 2.) – barbara beeton Jan 13 '12 at 20:17
• Since it works it can't be wrong, or can it? I'd consider it a matter of style. In a similar vain, one could use \newcommand\foo{FOO} and in fact, I sometimes do. – Christian Lindig Jan 13 '12 at 20:23
• How do you type 23/45 with that notation? – percusse Jan 13 '12 at 22:16

Longer answer: Here's the actual definition of the LaTeX command \frac:

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


What this shows is that LaTeX's \frac command is a (very well-designed) wrapper around TeX's \over command. By the syntax rules of TeX, if the "arguments" of the \frac command are not enclosed in curly braces, TeX will happily treat the first nonblank item/character it encounters after \frac as #1 and the second item as #2. Hence, \frac12 is (to TeX's parser) the same as \frac{1}{2}, and \frac xy -- note the space between the c and the x -- is the same as \frac{x}{y}.

That said, I suspect that if you get into a habit of leaving off the braces whenever the numerator and denominator both consist of a single letter or digit, you'll soon have forgotten that you're employing a shorthand method. Sooner or later, then, you'll write something like \frac 1 12 and start wondering why it's not being rendered as \frac{1}{12}...

Addendum: You mention toying with the idea of creating the one-argument macro

\newcommand{\frac1}[1]{\frac{1}{#1}}


Unfortunately, this isn't going to fly because TeX doesn't let you mix letters and digits in the name of a macro (unless you resort to a \cs... \endcs detour). However, why even bother creating such a one-argument version of the \frac macro? Note that \frac1{<denominator>} is a perfectly valid LaTeX expression: the 1 that follows \frac in \frac1 will be interpreted by TeX as the #1 part of the two-argument macro -- which is exactly what you want, correct?

• "you'll write something like \frac 1 12 and start wondering why it's not being rendered as \frac{1}{12}..." true, however you'll also quickly stop doing this again, after you've run into the problem a few times. I now add braces quite automatically when needed, but leave them out if not. – leftaroundabout Jan 14 '12 at 3:05
• You write No, at least not in principle, but I don't understand your reasoning. Why is it not valid to write \frac12 or \frac 12 (at least in principle)? I'd argue that answering Yes, at least in principle would make more sense. Personally, I'd never write it because I always pass arguments to macros using braced groups (unless the macro is a TeX delimited macro) because (I find) this is clearer. – user10274 Jan 14 '12 at 9:15
• Why does the LaTeX definition enclose the first argument in \begingroup..\endgroup but not the second? – Christian Lindig Jan 14 '12 at 9:27
• @ChristianLindig source2e says that it's done in order to prevent, for example, font changes in the numerator to affect the denominator. – egreg Jan 14 '12 at 9:53
• @MarcvanDongen - I meant to say that it wasn't wrong because no syntax rule is violated and the output is (presumably) what the writer intends it to be. That said, there are of course additional considerations, beyond mere adherence to syntax rules, one can apply to judging the quality of code. I fully agree with you, by the way, that it's a good idea to (nearly) always use braces when using LaTeX macros. – Mico Jan 14 '12 at 12:27

Don't know if this should be an answer or a comment...

Leaving off the curly braces is perfectly acceptable for the TeX compilers but may give you trouble if you will ever use Latexdiff. Or, in general, everything that tries to parse LaTeX code without being LaTeX itself, such as the syntax highlighters of many editors.

Not a big problem in itself, but I personally find Latexdiff very useful and would suggest you to integrate it in your normal workflow, especially if you write TeX documents in collaboration with other people.

There is no such thing as bad grammar in TeX, as long as it works. On a predominantly Plain TeX file, writing it this way it would be common. If you using LaTeX it would be preferable to have them enclosed in curly brackets as a matter of consistency and good style not to mention courtesy to any reviewer that might not be as conversant with TeX/LaTeX as you are.

In the LaTeX kernel source, the Team did not use brackets (possibly to save tokens), as for example:

\DeclareTextCommandDefault{\textonequarter}{\ensuremath {\frac14}}


My own preference is to use braces in all instances.

• Hmmm, I'd say that even if something works, it may still be possible to judge the grammar as being good or bad... – Mico Jan 13 '12 at 21:00
• @Mico Not sure if I agree with you, bad = incorrect which does apply here, since TeX translated it into the right sequence of 0s and 1s. Grammatically poor, maybe:) – Yiannis Lazarides Jan 13 '12 at 21:20
• What's your distinction between "poor" and "bad" (grammar)? :-) – Mico Jan 13 '12 at 21:23
• Heyeyey, sorry to be grumpy, but "it works" is definitely not necessarily the same as "it is correct"! – Brent.Longborough Jan 13 '12 at 21:48
• I see it as really two separate issues: (1) Is it good grammar or bad grammar? (2) Is it good style or bad style? If it works in all cases, then it's good grammar by definition. If it's simple and clear and maintainable, then it's probably not bad style. – Todd Lehman Jan 14 '12 at 7:40