I got stuck with the following piece of TeX:
\def\foo{A}
\def\bar{\foo}
\let\baz\bar
1: \baz
\def\foo{B}
\\
2: \baz
\\
\begin{array}[t]{r}
\def\foo{C}
3: \baz
\\
\def\foo{D}
4: \baz
\\
5: \baz
\end{array}
\begin{enumerate}
\def\foo{E}
\item[6:] \baz
\item[7:]
\def\foo{F}
\baz
\item[8:] \baz
\end{enumerate}
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.
array
is group scoped. You need\gdef
instead of\def
to communicate outside of the group.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.