It is possible in LaTeX to write expressions like \frac12, which should be equivalent to expressions like \frac{1}{2}. Is there a formal term for the first form of notation?
- 13,411
- 113
2 Answers
No.
This is just part of the normal way TeX absorbs non-delimited macro arguments. If you define
\def\foo#1{Something using #1 (or not).}
or equivalently
\newcommand\foo[1]{Something using #1 (or not).}
when \foo is expanded, it absorbs the next token or balanced group in the input stream as its argument (which is available as #1 in the definition).
Assuming normal category codes
- a token is a single character (except
\,{,},%or a space or newline (since those are ignored)) or a command sequence (something starting with\), - a balanced group starts with
{and ends with the first}that does not belong to a different group (that started later). The braces are stripped from the group upon absorption (that is,#1does not contain them).
This is why \foo x and \foo{x}, \newcommand{\foo} and \newcommand\foo or \frac 12, \frac{1}{2}, \frac{1}2 and \frac1 2 are equivalent.
It is good practice to choose the version that is clearest, which usually means using a group. Personally, I explicitly omit the group in cases where I have to input a single token, like \newcommand\foo.
- 14,892
It might be worth adding that distinguishing between single-token arguments and arguments in braces is more explicit in LaTeX3/expl3. By convention, every expl3 macro name should end in : followed by a sequence of letters, called argument specifiers, each reflecting the type of the corresponding argument.
Beside many others we have
nfor braced-group or single-token arguments, andNfor single-token arguments only, usually macro/function names or variable names.
Those specifiers still don't change the way (La)TeX processes the individual arguments, but it gives a hint to the user about how the arguments are used inside the macro.
For example, the l3tl package provides two functions \tl_if_empty:nTF and \tl_if_empty:NTF. While both functions check if a token list is empty and execute code conditionally, the former is expected to be called with a braced group of tokens, where the latter expects a token list variable that is first expanded before the test is performed on its contents.
- 13,411
\frac12works because the argument to an undelimited TeX macro (like\frac) is either a single token (1is a single token, for example) or, a group of tokens delimited by{...}, in which case the outer braces are removed. That's why both forms are equivalent. However there isn't a special name to one of them... – Phelype Oleinik Aug 01 '19 at 02:12\frac{1}{2}are just "more work to do", because it's unnecessary to group a single token. – siracusa Aug 01 '19 at 03:01${ 1 = 0 }$the braces act essentially like an implicit\hboxand prevent linebreaking and space stretching, but braces used as macro argument delimiters are a different thing entirely. – David Carlisle Aug 01 '19 at 07:00${ 1 = 0 }$delimit what Knuth calls a subformula, and indeed they have consequences I didn't anticipate before reading about them in the TeXbook! – frougon Aug 01 '19 at 07:31\frac12will not prevent linebreaking nor space stretching? – manooooh Aug 01 '19 at 08:18\frac12you have a control word token\fractriggering the processing of two braceless undelimited arguments. With\frac{1}2you have a control word token\fractriggering the processing of an undelimted argument nested in braces and a braceless undelimited argument. With\frac1{2}you have a control word token\fractriggering the processing of a braceless undelimted argument and an undelimited argument nested in braces. With\frac{1}{2}you have a control word token\fractriggering the processing of two undelimited arguments, each of them nested in braces. – Ulrich Diez Aug 01 '19 at 08:48