Skip to content
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

Fix foreach not remembering nodes between iterations #1304

Closed
wants to merge 58 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
ad03942
fix: incorrectly placed matrix delimiters
muzimuzhi Jun 9, 2022
937b354
docs: ensure `doc` v2 is loaded
muzimuzhi Jul 2, 2022
5d98602
docs: ensure active `^^M` is non-expandable
muzimuzhi Jul 4, 2022
de96d67
docs: fix typo (close #1185)
muzimuzhi Aug 29, 2022
4240ad6
fix: additional braces in description of key handler `.append code`
EagleoutIce Sep 7, 2022
4f0b709
fix: guard against LuaMetaTeX's changed \meaning
hmenke Sep 23, 2022
f39dd0d
docs: use handler `/.append`
muzimuzhi Oct 13, 2022
1f85761
chore: add dependabot to keep actions up-to-date
muzimuzhi Oct 20, 2022
1c843a9
chore: Update GitHub Actions
hmenke Nov 12, 2022
bd9613b
fix(ci): disable git safe.directory
hmenke Jan 13, 2023
f49f0c9
fix(doc): replace uses of \cs{...} with |\...|
hmenke Jan 13, 2023
a85413f
fix(build): license is a multi field
hmenke Jan 13, 2023
27ad7c4
fix(ci): automate CTAN validation and uploading
muzimuzhi Jan 15, 2023
9e0d878
Release 3.1.10
hmenke Jan 13, 2023
f6c7d00
Typo
quark67 Mar 15, 2023
aee5b41
Fixing typos
deining Apr 4, 2023
a78e964
docs: fix typos (#1257)
muzimuzhi Apr 27, 2023
b184f93
Update pgfmanual-en-pgfkeys.tex (#1261)
hetzenmat May 25, 2023
e09607f
docs: update contributors
muzimuzhi May 25, 2023
f2399b3
fix: use corresponding line cap cmd #808
muzimuzhi May 26, 2023
2580e30
chore(git): ignore .synctex.gz files
muzimuzhi Jul 26, 2023
467766f
fix: typo in animations #1273
hmenke Sep 3, 2023
b6734d9
test: update testfile
muzimuzhi Sep 3, 2023
d2b1d22
docs: update CI badge [ci skip]
muzimuzhi Sep 3, 2023
0963b67
docs: add changelog entry for #1273 [ci skip]
muzimuzhi Sep 3, 2023
12a38a9
chore(deps): bump actions/checkout from 3 to 4
dependabot[bot] Sep 11, 2023
e988e66
docs: simplify the stripe-pattern matrix example
muzimuzhi Sep 22, 2023
8b6ee86
fix conflicting bbox setting between pgfsys-dvisvgm and dvisvgm command;
agrahn Sep 12, 2023
1d3535f
Update tex/generic/pgf/systemlayer/pgfsys-dvisvgm.def
agrahn Sep 20, 2023
7371bd4
docs: simplify short verb `|...|` (#1267)
muzimuzhi Jul 26, 2023
742ce71
docs: add codeexample preambles for short verb
muzimuzhi Jul 26, 2023
987e851
Fix shadings on LuaMetaTeX
zauguin Nov 5, 2022
6ce8705
Harden pgfmathparser against active chars
josephwright Nov 30, 2022
ece59e9
Update ChangeLog
josephwright Nov 30, 2022
d436492
On additional conditional updated
josephwright Nov 30, 2022
ae9d592
docs: tidy ChangeLog for #1214 [ci skip]
muzimuzhi Oct 23, 2023
a1a947c
docs: tidy ChangeLog for #1221 [ci skip]
muzimuzhi Oct 23, 2023
73ea508
chore(deps): bump actions/github-script from 6 to 7
dependabot[bot] Nov 20, 2023
67d9326
Update pgfmanual-en-tikz-coordinates.tex
maxchendt Nov 29, 2023
810f682
docs: fix default for isosceles triangle stretches
Flupp Dec 13, 2023
41c0cea
chore(deps): bump actions/upload-artifact from 3 to 4 (#1299)
dependabot[bot] Dec 18, 2023
07a5d00
build: drop unneeded `maxprintline` setting
muzimuzhi Dec 21, 2023
37d73a2
docs: cleanup pgfmanual preamble (#1300)
muzimuzhi Dec 21, 2023
134da12
ci: analyse and show overfull hbox(es)
muzimuzhi Oct 20, 2022
503dc63
docs: resolve overfull hboxes >=20pt
muzimuzhi Jan 15, 2021
3100454
build(fix): respect directory structure when copying `docfiles`
muzimuzhi Feb 11, 2023
5c26f95
refactor(doc): adapt `\graphicspath` for flattened doc tree
muzimuzhi Feb 11, 2023
292fa1d
refactor: promote warning "Plot data file `...' not found" to error
muzimuzhi Feb 11, 2023
bb712ea
Fix for nodes in foreach
loopspace Jan 8, 2024
eff182f
Changelog for foreach fix
loopspace Jan 8, 2024
bf8d893
More robust fix for foreach
loopspace Jan 9, 2024
3d03d02
docs: \makeatletter and \makeatother should match (#1305)
rockyzhz Jan 10, 2024
61ba843
chore(docs): add new contributor
muzimuzhi Jan 10, 2024
f35286d
build: drop deprecated l3build target `revisionfile`
muzimuzhi Jan 14, 2024
c46ed90
docs: fix typo in intro: "questions" => "question" (#1309)
salewski Mar 6, 2024
7eb346a
docs: fix typo in pgfmanual: "which where" => "which were" (#1310)
salewski Mar 8, 2024
5fb6ca9
Keys for remembering macros/dimensions in foreach interations
loopspace Apr 2, 2024
f2fa2e4
Merge branch 'master' into fixforeach
loopspace Apr 2, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/generic/pgf/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).

### Fixed

- Foreach in path remembers nodes between iterates #1303
- Typo in animations `end on` key #1273
- Output bounding box adjustment in pgfsys-dvisvgm.def #1275
- Fix shadings under LuaMetaTeX
Expand Down
79 changes: 62 additions & 17 deletions tex/generic/pgf/frontendlayer/tikz/tikz.code.tex
Original file line number Diff line number Diff line change
Expand Up @@ -2580,28 +2580,77 @@

\def\tikz@fchar oreach{\tikz@foreach}%


%
% These are to allow \foreach to remember macros and dimensions between iterations
%

\def\tikzforeach@smugglers@cove{}
\let\tikztostart=\relax
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe move this to tex/generic/pgf/frontendlayer/tikz/libraries/tikzlibrarytopaths.code.tex where \tikztostart (and \tikztotarget) originally come from.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had a look at tikzlibrarytopaths.code.tex and while that is where \tikztostart is used, it is never defined there. The definitions are contained in the core TikZ parser in that whenever TikZ encounters a coordinate then it sets \tikztostart to something sensible so that if the next command is a to path then the start is set up correctly. Similarly with \tikz@tangent (which is mainly used in the calc library).

So I'm happy to move it, but just want to double-check first.


\def\tikzforeach@smuggle@macro#1{%
\pgfutil@ifx#1\relax{}{%
\expandafter
\pgfutil@g@addto@macro
\expandafter
\tikzforeach@smugglers@cove
\expandafter
{%
\expandafter\def\expandafter#1\expandafter{#1}%
}%
}%
}

\def\tikzforeach@smuggle@dimen#1{%
\pgfutil@ifx#1\relax{}{%
\expandafter
\pgfutil@g@addto@macro
\expandafter
\tikzforeach@smugglers@cove
\expandafter
{%
\expandafter#1\expandafter=\the#1\relax%
}%
}%
}

\def\tikzforeach@smugglers@loot{%
%
\tikzforeach@smuggle@macro\tikz@moveto@waiting%
\tikzforeach@smuggle@macro\tikztostart%
\tikzforeach@smuggle@macro\tikz@tangent%
%
\tikzforeach@smuggle@dimen\tikz@lastx%
\tikzforeach@smuggle@dimen\tikz@lasty%
\tikzforeach@smuggle@dimen\tikz@lastxsaved%
\tikzforeach@smuggle@dimen\tikz@lastysaved%
%
}
Comment on lines +2591 to +2628
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like this approach (and the naming scheme 😁), but I think it would be even better if we could make this more general using pgfkeys, so that a user can register their own loot.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you happy with just remember macro and remember dimension for the keys? I've not found any other keys in the tikz namespace with those names.


\tikzset{
remember macro/.code={
\tikzforeach@smuggle@macro#1
},
remember dimension/.code={
\tikzforeach@smuggle@dimen#1
}
}

\def\tikz@foreach{%
\def\pgffor@beginhook{%
\tikz@lastx=\tikz@foreach@save@lastx%
\tikz@lasty=\tikz@foreach@save@lasty%
\tikz@lastxsaved=\tikz@foreach@save@lastxsaved%
\tikz@lastysaved=\tikz@foreach@save@lastysaved%
\tikzforeach@smugglers@cove%
\gdef\tikzforeach@smugglers@cove{}%
\setbox\tikz@figbox=\box\tikz@tempbox%
\setbox\tikz@figbox@bg=\box\tikz@tempbox@bg%
\expandafter\tikz@scan@next@command\pgfutil@firstofone}%
\def\pgffor@endhook{\pgfextra{%
\xdef\tikz@foreach@save@lastx{\the\tikz@lastx}%
\xdef\tikz@foreach@save@lasty{\the\tikz@lasty}%
\xdef\tikz@foreach@save@lastxsaved{\the\tikz@lastxsaved}%
\xdef\tikz@foreach@save@lastysaved{\the\tikz@lastysaved}%
\tikzforeach@smugglers@loot%
\global\setbox\tikz@tempbox=\box\tikz@figbox%
\global\setbox\tikz@tempbox@bg=\box\tikz@figbox@bg%
\pgfutil@gobble}}%
\def\pgffor@afterhook{%
\tikz@lastx=\tikz@foreach@save@lastx%
\tikz@lasty=\tikz@foreach@save@lasty%
\tikz@lastxsaved=\tikz@foreach@save@lastxsaved%
\tikz@lastysaved=\tikz@foreach@save@lastysaved%
\tikzforeach@smugglers@cove
\gdef\tikzforeach@smugglers@cove{}%
\let\pgffor@beginhook\relax%
\let\pgffor@endhook\relax%
\let\pgffor@afterhook\relax%
Expand All @@ -2610,13 +2659,9 @@
\tikz@scan@next@command}%
\global\setbox\tikz@tempbox=\box\tikz@figbox%
\global\setbox\tikz@tempbox@bg=\box\tikz@figbox@bg%
\xdef\tikz@foreach@save@lastx{\the\tikz@lastx}%
\xdef\tikz@foreach@save@lasty{\the\tikz@lasty}%
\xdef\tikz@foreach@save@lastxsaved{\the\tikz@lastxsaved}%
\xdef\tikz@foreach@save@lastysaved{\the\tikz@lastysaved}%
\tikzforeach@smugglers@loot%
\foreach}%


% Syntax for againpath:
% \againpath \somepathname

Expand Down
Loading