# Script to remove curly brackets around a single token. How legitimate would that be?

I work on a script that tries to bring LaTeX input into a more canonical form. One of the things I would like to do is remove curly brackets around single tokens, which could be either a single character or a control sequence.

This could be done, e.g., in commands such as \newcommand, \begin{wrapfigure}, etc. As far as I could check, this is safe to do in "normal" input, i.e., article text, using more or less common packages.

Is this true?

• Note that the canonical form as documented in the latex manual always uses the braced form. – David Carlisle Dec 15 '15 at 7:56
• Almost... I believe that Lamport says somewhere that you can, in some cases, remove the curlies, but advises the reader to consult an expert, which is precisely what I do here. – Yossi Gil Dec 15 '15 at 9:24
• The latex companion says that (and has examples of for example \newcommand\foo{...} with no {} around \foo but I think you'll find the latex book always uses braces. – David Carlisle Dec 15 '15 at 9:58

Note that the canonical form as documented in the latex manual always uses the braced form.

While it is true that you can omit braces from single token macro arguments it is not in general true that you can always omit them around single characters (which may be more than one token) or after all command sequences (which may not be macros).

Omiting the {} from either of the following generates an error.

\documentclass{article}

\usepackage[utf8]{inputenc}

\begin{document}

\fbox{é}

\uppercase{e}

\end{document}

• These examples are kind of cheating, because in pdfTeX é is not a single token (in Xe/LuaTeX it is) and \uppercase is a primitive which requires balanced text. Your advice to refrain from stripping braces around all single tokens remains valid, though. – Henri Menke Dec 15 '15 at 8:37
• Also the \uppercase scenario holds for any primitive expecting balanced text, such as \message, \special, or \everymath. – Henri Menke Dec 15 '15 at 8:40
• @HenriMenke I think you meant "illustrative" not "cheating" :-) The OP's question suggests that the script to canonicalise the input is not written in tex, so the point is that "token" and "single character" need to be interpreted with care (and in particular in the context sensitive way in which TeX interprets them) which can be tricky if using sed or python or some such, which may take a different view on the input. – David Carlisle Dec 15 '15 at 9:04
• Indeed, tokenization should be done with care: strip comments, and deal with creatures such as "^^", "\\", and even more challenging, deal with verbatim and the listings environment. Still, I cannot think of a case where a user, a client of LaTeX, would use \uppercase, \special, or \everymath. Also, I see no harm in requiring lualatex/xelatex. So, the answer as I read it is: "Yes, you can remove curlies around a single token, but warn your client that this should not be applied on style files, and if non-plain-ascii characters are used, be sure to compile your input with lualatex – Yossi Gil Dec 15 '15 at 9:34
• @YossiGil same thing – David Carlisle Dec 15 '15 at 10:41