Unlike in Java, Python, and other programming languages, in TeX the fundamental programming construct that is affected by grouping is not variable, but assignment, of which there are many kinds. Some assignments assign a value to a variable, i.e. to a control sequence, but others assign a value to an internal quantity. Not all assignments respect TeX's grouping. I will dedicate this answer to a complete description of TeX assignments. The descriptions have been compiled from The TeXbook (20th printing, Addison-Wesley 1991), to which the page numbers refer.
All TeX assignments have the same effect in all modes. Assignment commands often include an =
sign, but in all such cases this sign is optional. (p. 275)
A given assignment is either global or local. An assignment is global if it is prefixed by \global
or if it is one of the assignments on the list of global assignments below. Otherwise, the assignment is local.
Local assignments obey TeX’s grouping structure; i.e., the changed quantities will be restored to their former values when the current group ends. On the other hand, the effects of global assignments persist across grouping boundaries. (p. 277)
Every assignment can be prefixed by \global
(p. 275), but the presence or absence of \global
as a prefix has no effect on the assignments listed in the Global Assignments list below. (p. 277) A \gdef
command is equivalent to \global\def
, and \xdef
is equivalent to \global\edef
. (p. 276)
If the \globaldefs
parameter is positive at the time of an assignment, a prefix of \global
is automatically implied; but if \globaldefs
is negative at the time of the assignment, a prefix of \global is ignored. If \globaldefs
is zero (which it usually is), the appearance or nonappearance of \global
determines whether or not a global assignment is made. (p. 275)
A noteworthy quirk of assignments that is unrelated to grouping, is that TeX takes precautions to ensure that constructions like ‘\chardef\cs=10\cs
’ and ‘\font\cs=name\cs
’, i.e. assignments in which the control sequence is used immediately after it is defined, won’t expand the second \cs
until the assignments are done. (p. 278) This is contrary to TeX's normal rules of expansion, which guarantee, for instance, that the control sequence \after
in
\def\after{0}%
\chardef\cs=1\after
will expand during \cs
's definition, so that the ultimate effect will be the same as
\def\after{0}%
\chardef\cs=10
Global Assignments
The following is an exhaustive list of all of TeX's inherently global assignments. (pp. 277-278 & 271) The effects of these assignments transcend groupings.
- font assignment
\fontdimen ... = ...
\hyphenchar ... = ...
\skewchar ... = ...
- hyphenation assignment
\hyphenation ...
\patterns ...
- box size assignment
\ht<8-bit number> = ...
\wd<8-bit number> = ...
\dp<8-bit number> = ...
- interaction mode assignment
\errorstopmode
\scrollmode
\nonstopmode
\batchmode
- intimate assignment
- special integer assignment
* \spacefactor = ...
* \prevgraf = ...
* \deadcycles = ...
* \insertpenalties = ...
- special dimen assignment
* \prevdepth = ...
* \pagegoal = ...
* \pagetotal = ...
* \pagestretch = ...
* \pagefilstretch = ...
* \pagefillstretch = ...
* \pagefilllstretch = ...
* \pageshrink = ...
* \pagedepth = ...
Local Assignments
The following is an exhaustive list of all of TeX's local assignments. (pp. 275-277 & 271) Unless preceded by \global
, the effects of these assignments are confined to the current (most inner) grouping.
Macro assignments
Non-macro assignments
- variable assignment
- integer assignment
* <integer parameter> = ...
(see below for a complete list of int. parameters)
* <countdef token> = ...
(<countdef token>
= a c-seq. defined by \countdef
)
* \count<8-bit number> = ...
- dimen assignment
* <dimen parameter> = ...
(see below for a complete list of dimen parameters)
* <dimendef token> = ...
(<dimendef token>
= a c-seq. defined by \dimendef
)
* \dimen<8-bit number> = ...
- glue assignment
* <glue parameter> = ...
(see below for a complete list of glue parameters)
* <skipdef token> = ...
(<skipdef token>
= a c-seq. defined by \skipdef
)
* \skip<8-bit number> = ...
- muglue assignment
* <muglue parameter> = ...
(see below for a complete list of muglue parameters)
* <muskipdef token> = ...
(<muskipdef token>
= a c-seq. def. by \muskipdef
)
* \muskip<8-bit number> = ...
- token assignment
* <token parameter> = ...
(see below for a complete list of token parameters)
* <toksdef token> = ...
(<toksdef token>
= a c-seq. defined by \toksdef
)
* \toks<8-bit number> = ...
- arithmetic
\advance ... (by) ...
\multiply ... (by) ...
\divide ... (by) ...
- code assignment
\catcode<8-bit number> = ...
\mathcode<8-bit number> = ...
\lccode<8-bit number> = ...
\uccode<8-bit number> = ...
\sfcode<8-bit number> = ...
\delcode<8-bit number> = ...
- let assignment
\futurelet ...
\let ... = ...
- shorthand definition
\chardef ... = ...
\mathchardef ... = ...
\countdef ... = ...
\dimendef ... = ...
\skipdef ... = ...
\muskipdef ... = ...
\toksdef ... = ...
- fontdef token assignment
<fontdef token>
(<fontdef token>
= a control-sequence defined by \font
)
\nullfont
- family assignment
\textfont<4-bit number> = ...
\scriptfont<4-bit number> = ...
\scriptscriptfont<4-bit number> = ...
\parshape = ...
\read ... to ...
\font ... = ... (at/scaled ...)
\setbox<8-bit number> = ...
TeX's 103 Parameters
The following is an exhaustive list of all of TeX's parameters.
Integer parameters (55)
\adjdemerits
\binoppenalty
\brokenpenalty
\clubpenalty
\day
\defaulthyphenchar
\defaultskewchar
\delimiterfactor
\displaywidowpenalty
\doublehyphendemerits
\endlinechar
\errorcontextlines
\escapechar
\exhyphenpenalty
\fam
\finalhyphendemerits
\floatingpenalty
\globaldefs
\hangafter
\hbadness
\holdinginserts
\hyphenpenalty
\interlinepenalty
\language
\lefthyphenmin
\linepenalty
\looseness
\mag
\maxdeadcycles
\month
\newlinechar
\outputpenalty
\pausing
\postdisplaypenalty
\predisplaypenalty
\pretolerance
\relpenalty
\righthyphenmin
\showboxbreadth
\showboxdepth
\time
\tolerance
\tracingcommands
\tracinglostchars
\tracingmacros
\tracingonline
\tracingoutput
\tracingpages
\tracingparagraphs
\tracingrestores
\tracingstats
\uchyph
\vbadness
\widowpenalty
\year
(pp. 272-273)
Dimen parameters (21)
\boxmaxdepth
\delimitershortfall
\displayindent
\displaywidth
\emergencystretch
\hangindent
\hfuzz
\hoffset
\hsize
\lineskiplimit
\mathsurround
\maxdepth
\nulldelimiterspace
\overfullrule
\parindent
\predisplaysize
\scriptspace
\splitmaxdepth
\vfuzz
\voffset
\vsize
(p. 274)
Glue parameters (15)
\abovedisplayshortskip
\abovedisplayskip
\baselineskip
\belowdisplayshortskip
\belowdisplayskip
\leftskip
\lineskip
\parfillskip
\parskip
\rightskip
\spaceskip
\splittopskip
\tabskip
\topskip
\xspaceskip
(p. 274)
Muglue parameters (3)
\medmuskip
\thickmuskip
\thinmuskip
(p. 274)
Token parameters (9)
\errhelp
\everycr
\everydisplay
\everyhbox
\everyjob
\everymath
\everypar
\everyvbox
\output
(p. 275)
* TeX automatically inserts a begin-group symbol ‘{
’ at the beginning and an end-group symbol ‘}
’ at the end of the argument assigned to the \output
parameter. (p. 253)
The Primitive Grouping Environments
In the following '{
' stands for either a character token with catcode 1 or a control-sequence \let
to such a character token. Similarly, '}
' stands for either a character token with catcode 2 or a control-sequence/active character \let
to such a character token.
The following is a comprehensive list of all primitive grouping environments besides the obvious \begingroup ... \endgroup
and unadulterated {...}
.
\halign<box specification>{<alignment material>}
\valign<box specification>{<alignment material>}
\noalign<filler>{<vertical mode material>}
With \halign
, respectively \valign
, TeX enters a new level of grouping, represented by the '{
' and '}
', within which changes to \tabskip
will be confined. The alignment material can also contain optional occurrences of '\noalign<filler>{<vertical mode material>}
' between lines; this adds another level of grouping. TeX also enters an additional level of grouping when it works on each individual entry of the alignment. (p. 282, 285-286)
\insert<8-bit number><filler>{<vertical mode material>}
\vadjust<filler>{<vertical mode material>}
The '{
' causes TEX to enter a new level of grouping ended by the matching '}
'. (pp. 280-281)
\hbox<box specification>{<box material>}
\vbox<box specification>{<box material>}
\vtop<box specification>{<box material>}
\vcenter<box specification>{<box material>}
The '{
' initiates a new level of grouping ended by the the matching '}
'. (pp. 278, 290)
$<math mode material>$
$$<math mode material>$$
Upon encountering '$
' or '$$
' in horizontal mode, TeX enters a new level of grouping, and stays there until the matching '$
', respectively '$$
'. (pp. 287, 293)
A {...}
pair encountered in math mode (as in the other modes) signals a new level of grouping. (pp. 290, 291)
\eqno<math mode material>$
\leqno<math mode material>$
Upon reading \eqno
, respectively \leqno
, TeX enters a new level of grouping until the end of the math list (signaled by the closing '$
'). (p. 293)
\left<delim><math mode material>\right<delim>
With '\left
' TeX begins a new group, which is terminated by '\right
'. (p. 292)