{grouping} is about the grouping mechanism in TeX, and about local and global assignments.

learn more… | top users | synonyms (2)

19
votes
1answer
520 views

] inside an optional argument

I accidentally discovered (here) that a closing square bracket within an optional argument delimited by [ ] can cause problems. Here is example code illustrating the issue: \documentclass{article} ...
12
votes
2answers
556 views

Is there a way to set a *global* key value using `pgfkeys`?

The simple answer to this question appears to be "No"; quoting from the pgf manual: The setting of a key is always local to the current TeX group. However, this is very annoying because it means ...
10
votes
3answers
1k views

Drawing a proper shadow for overlapping objects

I draw images that are composed of several overlapping nodes. If I add a drop shadow to each node, the shadow of the second node is drawn over the first node, as seen in the picture below (which ...
55
votes
1answer
8k 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 ...
18
votes
4answers
481 views

How do I get a value out of a group?

I've just recovered from my first real foray into LaTeX3 programming. It was ... an experience. Not a completely unpleasant one and once I'd gotten used to the syntax then I found it a lot easier ...
12
votes
2answers
9k views

Temporarily increase line spacing

How do I temporarily increase line spacing? I have some text on my title page: \begin{center} { \Large \textbf{The Great Thesis About Some Very Great Things Indeed With a Pretty Long Title That Will ...
10
votes
1answer
195 views

Global scope or permanent length or savebox

I am trying to save a minipage width and height in one environment, and use these dimensions in a subsequent environment of mine, to make a picture environment. The idea is to create a picture on the ...
6
votes
2answers
639 views

Tikz: How to move a footnote in a node out of that group?

Apologies for the slightly strange title, I struggled to come up with something else. I have defined my own quote environment with brackets around the quote. In order to do that I use tikz and the ...
8
votes
2answers
528 views

\newtoks token seems to have local scope

I want to collect the first line of a quotation to use later. I have used \newtoks for a similar purpose so tried it here, this way: \documentclass[12pt] {article} \newtoks{\qfirstlineinternal} ...
17
votes
2answers
2k views

What does \begingroup\expandafter…\endgroup do?

I often see code of the following form in package implementations (this example is from the LaTeX3 sources): \begingroup\expandafter\expandafter\expandafter\endgroup \expandafter\ifx\csname ...
14
votes
3answers
299 views

What is the difference between local and global in a TeX meaning?

In tikz declare function and babel french option it came to the question about the difference between local and global in a TeX meaning. In the liked question the babel shorthand ; should be ...
12
votes
3answers
1k views

\global\renewcommand equivalent of \global\def

The following MWE works just fine, but I had to resort to using \global\def (not that there's anything wrong with it). The intent of the MWE is to provide access to the value of macro as set in an ...
7
votes
3answers
505 views

Using execute at begin node with \phantom and \pgfuseimage in TikZ?

Problem I would like to create several nodes whose text is a placeholder for an image, i.e., \phantom{\pgfuseimage{mypicture}}. This is easily done as, for example: \matrix { \node ...
5
votes
1answer
310 views

Splitting a command syntax across a \newenvironment definition

This question is a direct follow-up to the question Can a \newcommand Definition Contain Braces as Substitution Text? I asked yesterday. The following example is once again a counter-intuitive one, ...
12
votes
2answers
286 views

Is there a way to limit the scope of \usepackage?

When I tried to use the breqn package suggested by an answer to the question How do I break a long equation over lines It managed to break a whole bunch of unrelated equations (equations that did ...
12
votes
2answers
247 views

necessity of braces for accent commands

Many resources on LaTeX teach that "é" and "ä" are typeset with (respectively) \'{e} and \"{a}; and it is similar for other accent symbols. Are the braces really needed? Aren't \'e and \"a shorter but ...
10
votes
1answer
736 views

Why do \setcounter and \addtocounter commands have global effect, while \setlength and \addtolength commands obey the normal scoping rules?

The \setcounter and \addtocounter commands have global effect, while the \setlength and \addtolength commands obey the normal scoping rules. Why were they designed like this? Why are ...
9
votes
2answers
526 views

Beamer: content in box register does not survive \end{frame}

Consider the following example (I edited the example to include LaTeX lrbox environment): \documentclass{beamer} \newsavebox\mybox \newsavebox\myboxb \begin{document} \frame{ \sbox\mybox{Hello ...
2
votes
1answer
210 views

Paragraph and subparagraph titles inherit color settings from TeX group *after* them

I'm getting some strange behaviour when using the color package at paragraph and subparagraph level. See the code snippet below: \usepackage[usenames,dvips]{color} \section{A} {\color{Green} ...
24
votes
3answers
6k views

When to use @ in an \if statement

I am new to LaTeX and so this question might come across as rather basic. It might also reflect my biases/assumptions from my C/C++ programming days. I was seeing the code of the 'exam' class and ...
24
votes
4answers
876 views

Kerning between bold and non-bold text

I'd like to write a word in bold followed by a comma and a non-bold word, like this: \textbf{why}, blah If I just write why, TeX inserts a kern to shift the comma a little closer to the "y". But ...
15
votes
1answer
178 views

First occurrence of a command

I'm writing some macros that need to behave differently after first occurrence. I decided to use the etoolbox package's toggle. My MWE is as follows: \documentclass{article} \usepackage{etoolbox} ...
11
votes
1answer
289 views

What is the scope of elements of TikZ pictures?

I understand that named elements of a tikzpicture cannot be referenced before they are defined; but I'm confused about how "long" a named element persists. It appears that once named, an element ...
11
votes
2answers
176 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 ...
18
votes
3answers
326 views

What are the effects of an empty group, {}?

In order to have a syntactic space after a no-argument command, one is taught to delimit the command token with an empty group ({}), like this: \somecommand{} more LaTeX material. However an empty ...
12
votes
2answers
312 views

How to create *local* labels/refs in LaTeX?

Concise question: Is there any way to limit the scope in which a \label is visible to a \ref? Motivation: My current goal is to create a rather large document, containing many exercises and their ...
16
votes
2answers
327 views

Why do I have to put the center environment in a group for \@afterindentfalse\@afterheading to suppress indentation?

Consider the following two macros, the only difference being that one has the environment inside a group: \documentclass{article} \makeatletter \newcommand\thisworks{% {\begin{center} $\ast$ ...
5
votes
1answer
1k views

How to globally tikzset styles

I would like to set a tikzstyle from within a tabular environment, and use it after the table. Adding the usual \global seems to have no effect. The MWE below produces: but I want the last line ...
3
votes
0answers
766 views

Attempts to manually change \linewidth ignored by LaTeX [closed]

I was going to try to answer the question: How can I change the geometry of a page on the chapter header page only, and return to normal on the next page? It didn't seem like it should be too ...
18
votes
3answers
592 views

Should LaTeX counters always be modified globally?

In this answer, egreg states that "LaTeX counters should always be modified globally". However, the etoolbox package provides the \defcounter macro which will assign a value to a previously ...
10
votes
2answers
456 views

How can I change the text color in such a way that the effect transcends groups?

I'd like to have a command \globalred that makes all subsequent text red, even if the command is issued inside a group. For example, the output of the TeX file \documentclass{article} ...
9
votes
3answers
373 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 ...
8
votes
1answer
136 views

Why does the `&` reset grouping?

In this answer, I used \tikzmark to mark the extent of a typeset piece of text, so I could draw changebars next to it. But it initially seemed that the changebars "disappear" with math-mode content. ...
7
votes
3answers
1k views

LaTeX3: how to define a variable locally

I am trying to learn the LaTeX3 syntax. One of the questions I have come up with is how to define a variable, i. e. a macro without arguments in TeX parlance, with local scope within a group. In TeX ...
6
votes
2answers
368 views

Is there a way to control scope of fontspec font change?

I would like to limit the scope of \fontspec to just one or a couple of words in my paragraph, for example: Vivamus gravida lacus a sapien \fontspec{The Font Name}{interdum} eget interdum mi ...
5
votes
1answer
161 views

Can a \newcommand Definition Contain Braces as Substitution Text?

The following example is completely counter-intuitive, but I need this in a bigger definition I'm not including here. \newcommand{\openbrace}{{} I need this to start a nested scope. Is this ...
4
votes
1answer
201 views

Measure and retain lengths between tabular rows

I need elements in a tabular environment to set some lengths and be able to access these lengths in another row of this same table. But it appears that adding \global in front of \settoheight and ...
4
votes
2answers
1k views

\bgroup and \egroup?

So I've been looking to expand on the following bit of code (a hack to not screw up the margins when using oversized figures): \noindent\makebox[\textwidth]{% \begin{tabularx}{1.5\textwidth}{XX} ...
2
votes
2answers
253 views

Macro behaviour different inside tabular environment

I have a lot of problems lately with macros expanding (or not expanding) at unexpected times, so thought I was having a related problem here. But, in this case, things are working as I want outside of ...