Home

endgroup

Endgroup is a TeX primitive used to end a group that was started by begingroup (or by an opening brace). Grouping creates a local scope for assignments and definitions, and endgroup marks the point at which that local scope ends. When a group ends, most changes made inside it are discarded unless they were made global.

In TeX, many operations are scoped by groups. Within a group, changes to registers such as counts,

Syntax and related terms: The primitive end of a group is \endgroup. Its synonym is \egroup, and

Typical uses: Endgroup is used in macro and package development to confine temporary changes to a small,

Example (conceptual): A count is set inside a group, and without global, its new value does not

dimen
registers,
and
token
definitions
are
local
to
the
group.
If
you
want
a
change
to
affect
the
outside
world,
you
must
use
the
global
modifier
(for
example,
\global\advance\count0
by
1).
Endgroup
itself
does
not
automatically
make
changes
global;
it
simply
closes
the
current
local
scope.
its
opening
partner
is
\begingroup
(with
synonyms
\bgroup).
Closing
a
group
with
endgroup
is
equivalent
in
effect
to
closing
a
brace-delimited
block,
but
endgroup
is
a
dedicated
TeX
primitive
that
can
be
used
in
macro
programming
and
lower-level
code
where
explicit
scoping
matters.
well-defined
region.
It
helps
prevent
side
effects
from
leaking
into
the
surrounding
document.
In
LaTeX,
grouping
with
braces
is
common,
but
endgroup
provides
a
precise,
explicit
way
to
terminate
a
group
when
writing
low-level
code
or
complex
macro
definitions.
affect
the
outside.
With
a
global
assignment
inside
the
group,
the
value
persists
after
endgroup.
This
illustrates
how
endgroup
controls
local
versus
global
effects
within
TeX’s
scoping
model.