I got stuck with the following piece of TeX:

1: \baz
2: \baz

3: \baz
4: \baz
5: \baz

\item[6:] \baz


\item[8:] \baz

This piece of TeX is rendered as follows:

1: A
2: B

3: C
4: D
5: B

6: E
7: F
8: F

Now, lines 1 and 2 behave as expected, after redefining \foo, the new value is printed. However, when wrapped in an array, line 5 prints B where I would expect D. The macros work as expected when inside enumerate (lines 6-8).

How is it that line 5 prints as B instead of D and how to fix the definition of the macros? I presume there is something weird going on with the expansion inside array. I tried to change array for align but that manifests the same problem.

  • 1
    Each element of the array is group scoped. You need \gdef instead of \def to communicate outside of the group. Nov 6, 2020 at 11:31
  • Blah, you are right, gdef works. Can you perhaps make this into a full answer and add some appropriate tex phrases? I seriously spent ages to try to figure this myself but it is very hard to google this.
    – fari
    Nov 6, 2020 at 11:45

1 Answer 1


This is completely expected

\def\foo{A}     % now \foo expands to A
\def\bar{\foo}  % now \bar expands to \foo
\let\baz\bar    % now \baz expands to \foo
1: \baz         % we get \foo, then A
\def\foo{B}     % now \foo expands to B
2: \baz         % we get \foo, then B

\def\foo{C}     % now \foo expands to C
3: \baz         % we get \foo, then C
\\              % end of cell, \foo reverts to B
\def\foo{D}     % now \foo expands to D
4: \baz         % we get \foo, then D
\\              % end of cell, \foo reverts to B
5: \baz         % we get \foo, then B

\def\foo{E}     % now \foo expands to E
\item[6:] \baz  % we get \foo, then E

\def\foo{F}     % now \foo expands to F
\baz            % we get \foo, then F

\item[8:] \baz  % we get \foo, then F

Cells in array form groups. It's not clear what you want to achieve, but if you want that the definition of \foo transcends groups, you need \gdef rather than \def.

In particular, what's the role of \bar? You never use it, except when defining \baz as an alias to it.

  • You are right, it the groups. I had no idea cells form groups neither did it pop to me in any related question when I was trying to find a fix. I was writing a macro that issues a newline and prepends some text to it,whcih I want to change mid-array. After Steven's previous comment above I ended up with: \def\baz{\gdef\foo{D}}, \def\qux{\gdef\foo{E}} and \def\NL{\newline\foo}
    – fari
    Nov 6, 2020 at 12:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.