The syntax rules of TeX allow for certain primitives to have an “argument” delimited by \bgroup
or \egroup
. The main examples are
\hbox
, \vbox
, \vtop
, \vcenter
, \halign
and \noalign
.
This is the basis where, for instance, \halign
LaTeX builds tabular
on: with \begin{tabular}{<arg>}
the argument is transformed into a suitable preamble for \halign
and then, besides other things irrelevant for this discussion, TeX executes
\leavevmode$\vcenter\bgroup\halign\bgroup<built preamble>\cr
and, when \end{tabular}
is found,
\crcr\egroup\egroup$
is performed. The \vcenter
can be \vbox
or \vtop
depending on the option given to tabular
. Of course, this possibility is exploited also in lrbox
.
Other primitive commands accept an argument in the form of a <general text>
and the TeXbook describes this as
<filler>{<balanced text><right brace>
where <filler>
is an arbitrary sequence of \relax
and space tokens, {
means an implicit or explicit token with category code 1 (so either {
or \bgroup
) and <right brace>
means an explicit character token of category code 1.
Examples of primitives with this are \uppercase
, \message
, \write
and \mark
, besides assignments to token registers:
<token variable><equals><general text>
So you can't define a macro based on \uppercase
whose argument is delimited by \egroup
, but you can do it with \hbox
.
Worse, for your plan, is the fact that the replacement text in a macro definition must be delimited by explicit character tokens of categories 1 and 2 respectively.
Note that there is a rule of thumb for knowing which primitives accept \egroup
as final delimiter: those where the argument is enclosed in an implicit group (with a quirk about \halign
because \tabskip
assignments will be performed outside this implicit group). This is the case also for the primitive actions of _
and ^
, by the way.
It's impossible to define a general macro whose argument can be delimited by }
or \egroup
. An apparent argument can, provided the replacement text ends with a primitive accepting \egroup
in the first place; \aftergroup
trickery can then be used for completing the task. Just to make a silly example, here's an implementation of \vfbox
that takes a named color as optional argument:
\documentclass{article}
\usepackage{color}
\makeatletter
\newcommand{\vfbox}[1][black]{%
\def\vfbox@color{#1}%
\setbox\vfbox@box=\hbox\bgroup
\aftergroup\vfbox@do
\let\next=
}
\newcommand{\vfbox@do}{%
\begingroup
\color{\vfbox@color}%
\fbox{\box\vfbox@box}%
\endgroup
}
\newbox\vfbox@box
\makeatother
\begin{document}
\vfbox\bgroup abc\egroup
\vfbox{abc\egroup
\vfbox[blue]\bgroup abc}
\end{document}

But you can't do it with \uppercase
(besides its limitation).
<general text>
must end with an explicit brace, not\egroup
. For font changing or box making commands it is actually easy, but delimiting an argument of a general macro either by\egroup
or}
₁ is difficult, if ever possible. And I'm really dubious about its usefulness.{]
than\bgroup\egroup
and much easier and more robust to define commands using that form why would you want to do this? your question gives no indication of any possible reason or potential benefit.\def
, or similar defining commands, behave in a very different way from native commands; the latter accept the balanced braces as well as the balanced\bgroup
and\egroup
pairs, even if these implicit braces are used inside different macros, for example the opening and the closing macros of an environment. Parsing macros for finding their arguments is not the same as processing their arguments by native commands.{<balanced text>}
as argument accept\bgroup
or\egroup
in place of{
or}
(\hbox
, for instance). Primitives that have<general text>
as argument, only accept\bgroup
as a replacement of{
, but require}
at the end (\uppercase
, for instance). Some primitives (the\def
family) have an argument that must be delimited by explicit braces.\hbox
).