-
Notifications
You must be signed in to change notification settings - Fork 109
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[pgffor] "remember=\x as \lastx" without "(initially ...)" reports \lastx undefined #855
Comments
Possible patch (needs testing) --- a/tex/generic/pgf/utilities/pgffor.code.tex
+++ b/tex/generic/pgf/utilities/pgffor.code.tex
@@ -737,6 +737,7 @@
\pgfutil@append@tomacro{\pgffor@remember@code}{\noexpand\def\noexpand#2{#2}}%
\def\pgffor@test{#4}%
\ifx\pgffor@test\pgfutil@empty%
+ \pgfutil@append@tomacro{\pgffor@assign@once@code}{\def#2{0}}%
\else%
\pgfutil@append@tomacro{\pgffor@assign@once@code}{\def#2{#4}}%
\fi% |
I think this was broken by this commit e22a1aa which means it has been broken for 10 years. |
Interesting, I discovered an undocumented syntax in there: \documentclass{article}
\usepackage{pgffor}
\begin{document}
\def\lastx{A}
\foreach \x/\y [remember={\lastx=\x}] in {B,...,H}
{$\overrightarrow{\lastx\x}$, }
\end{document} But that really doesn't work so well. The following behaves a little bit funky: \documentclass{article}
\usepackage{pgffor}
\begin{document}
\def\lastx{A}
\def\lasty{0}
\foreach \x/\y [remember={\lastx=\x;\lasty=\y;}] in {B/1,...,H/6}
{$\overrightarrow{\lastx\x\lasty\y}$, }
\end{document} In fact, if I write
|
The current fix 08041e4 (additionally) allows input with empty \documentclass{article}
\usepackage{pgffor}
\begin{document}
% \lastx is initialized to zero as well
\foreach \x [remember=\x as \lastx (initially )] in {B,...,H}
{$\overrightarrow{\lastx\x}$, }
\end{document} That might not be the expected effect and will make the logic too complex to be fully documented. The following attempt avoids that: --- a/tex/generic/pgf/utilities/pgffor.code.tex
+++ b/tex/generic/pgf/utilities/pgffor.code.tex
@@ -727,7 +727,7 @@
}
\def\pgffor@remember@parse@old#1#2\pgffor@stop{%
- \pgffor@remember@@parse@old#1#2\pgffor@stop as#1(initially )\pgffor@@stop}
+ \pgffor@remember@@parse@old#1#2\pgffor@stop as#1(initially 0)\pgffor@@stop}
\def\pgffor@remember@@parse@old#1#2as#3#4\pgffor@@stop{%
\pgffor@remember@@@parse@old{#1}{#3}#2#4\pgffor@stop\pgffor@@stop} |
Your proposed patch is much better. I have queued it for inclusion. |
Many thanks. :) |
A follow-up question: Do we need to allow
If --- a/tex/generic/pgf/utilities/pgffor.code.tex
+++ b/tex/generic/pgf/utilities/pgffor.code.tex
@@ -735,11 +735,7 @@
\def\pgffor@remember@@@parse@old#1#2#3(initially #4)#5\pgffor@stop#6\pgffor@@stop{%
\pgfutil@append@tomacro{\pgffor@assign@after@code}{\edef#2{#1}}%
\pgfutil@append@tomacro{\pgffor@remember@code}{\noexpand\def\noexpand#2{#2}}%
- \def\pgffor@test{#4}%
- \ifx\pgffor@test\pgfutil@empty%
- \else%
- \pgfutil@append@tomacro{\pgffor@assign@once@code}{\def#2{#4}}%
- \fi%
+ \pgfutil@append@tomacro{\pgffor@assign@once@code}{\def#2{#4}}%
} This changes the logic to (in pseudo-code)
Full example \documentclass{article}
\usepackage{pgffor}
\begin{document}
% this prints "<>, <1>, <2>, <3>, <>,"
\foreach \x in {,1,2,3,} { <\x>, }
% currently, this raises an error "\lasti is undefined"
% if the attempt applied, \lastx is initialized to empty
% and this prints "<1>, <12>, <23>,",
\foreach \x[remember=\x as \lastx (initially )] in {1,2,3} { <\lastx\x>, }
\end{document} |
If you are posting a patch, please always paste the full diff. The one that you posted is corrupt because there are three more lines missing, so I couldn't directly apply it and had to fix it by hand. In fact, you don't have to patches at all, you can just file a pull request here on GitHub or you can use |
Thanks again. I'll take care of it. Also, I'm not confident enough to directly open a pr. |
@muzimuzhi, just give it a try. That will be a good chance to learn something. |
Brief outline of the bug
The pgf manual (3.1.5b, sec. 89, p. 1004) says
In my understanding, if
(initially <value>)
is missing,<macro>
is initially defined as0
. But<macro>
is reported to be undefined.Minimal working example (MWE)
The above example reports
The text was updated successfully, but these errors were encountered: