In Plain TeX, when I try to create an array of control sequences (\word0
, \word1
, etc.) and print it out using a loop, TeX stumbles over the accented-i control sequence \'{\i}
. I get this error:
! Missing number, treated as zero.
<to be read again>
}
\word1 ->r\'{\i }
os
\body ->\csname word\the \i \endcsname
\^^M\advance \i by 1 \ifnum \i < \word
\next ->\body
\let \next \iterate \else \let \next \relax \fi \next
l.40 Automatic array and printing: \printlist
This makes me think I have not understood something correctly about expansion, perhaps. Why does this error occur?
The image shows the output that results from ignoring the error during compilation.
% This accent macro works.
Spelled out: r\'{\i}os
% It also works inside another macro.
\def\rios{r\'{\i}os}
Macro: \rios
% When I make a quasi-array by hand it works.
\expandafter\def\csname word0\endcsname{river}
\expandafter\def\csname word1\endcsname{r\'{\i}os}
Array by hand:
\csname word0\endcsname\
\csname word1\endcsname
% When I make the array automatically and print the results manually, it works.
\newcount\word
\word=0
\def\addtolist #1{
\expandafter\def\csname word\the\word\endcsname{#1}
\advance\word by 1
}
\addtolist{river}
\addtolist{r\'{\i}os}
Automatic array, print by hand:
\csname word0\endcsname\
\csname word1\endcsname
% But when I try to print the list automatically, TeX stumbles over the accented i.
\newcount\i
\def\printlist{
\i=0
\loop
\csname word\the\i\endcsname\
\advance\i by 1
\ifnum\i < \word
\repeat
}
Automatic array and printing: \printlist
\bye