4
votes
1answer
43 views

How do you define a command to select nested groups?

Assuming a pair structure (2-tuple) is defined using groups {{<tokens1>}{<tokens2>}} is it possible to define a command \first#1{...} (and \last#1{...}) taking the surrounding group as ...
7
votes
3answers
210 views

When to use or avoid grouping?

For writing my own TeX code, grouping (\begingroup, \endgroup) helps on automatically saving and restoring TeX "variables". (La)TeX "variables" are either macros or registers. The registers can ...
13
votes
1answer
121 views

Difference between “hbox group” and “adjusted hbox group”?

eTeX's \currentgrouptype distinguishes two types of \hbox group types \hbox{\showthe\currentgrouptype} % 3 "adjusted hbox group" \noindent \hbox{\showthe\currentgrouptype} % 2 "hbox group" Looking ...
19
votes
2answers
245 views

global confusion

Simply put, when should I care if something is global or not? What does this really mean? If my package, for example, provides \newcommand*{\setfooter}[1]{\def\mypackage@footer{#1}} And I later ...
1
vote
1answer
196 views

Unexpected scoping issue using \XeTeXinterchartoks

Minimal example (compile with xetex): \XeTeXinterchartokenstate = 1 \newXeTeXintercharclass \classa \XeTeXcharclass `\a \classa \XeTeXinterchartoks 255 \classa = {\begingroup} \XeTeXinterchartoks ...
11
votes
2answers
467 views

\expandafter within a \begingroup … \endgroup [duplicate]

Possible Duplicate: What does \begingroup\expandafter…\endgroup do? In many of Heiko Oberdiek's packages one sees this type of construction: ...
10
votes
1answer
133 views

Emulate TeX's grouping

In TeX, various kinds of groups must match properly, for instance, the following is wrong: $ \begingroup $ \endgroup I would like macros which allow such mismatched grouping. They would keep ...
11
votes
2answers
181 views

What combinations of mode and \currentgrouptype exist?

I am trying to predict in any given situation what TeX does if a closing brace reaches its stomach (apart from reverting local assignments). For instance, \vbox{\tracingall H} shows that if it is in ...
9
votes
3answers
382 views

Making register declarations local, Undefining a register (count, toks, etc.)

Is it possible to make \newcount, \newtoks, etc. respect grouping, so that, e.g., \newcount\temp\temp=2{\newcount\temp\temp=1}\showthe\temp gives 2 (instead of 0)? Relatedly, is it possible to ...
60
votes
2answers
9k views

When should one use \begingroup instead of \bgroup?

Is there ever a case when the use of \begingroup is preferred to \bgroup? Obviously, \bgroup is necessary in cases where you need to have balanced braces and thus cannot use {, but when is it ...