From a898ad3933b53735dd8f3d3fdceda6756ad7e5bf Mon Sep 17 00:00:00 2001 From: Andrew Stacey Date: Tue, 9 Jan 2024 21:41:20 +0000 Subject: [PATCH] More robust fix for foreach This adds in the saving code for `\tikztostart` and `\tikz@tangent`, plus provides a more robust and maintainable method of saving the various macros and dimensions by creating a single (global) token list that will restore them to their given values upon invocation. Signed-off-by: Andrew Stacey --- .../pgf/frontendlayer/tikz/tikz.code.tex | 72 +++++++++++++------ 1 file changed, 50 insertions(+), 22 deletions(-) diff --git a/tex/generic/pgf/frontendlayer/tikz/tikz.code.tex b/tex/generic/pgf/frontendlayer/tikz/tikz.code.tex index 1415fdd3c..31202cddb 100644 --- a/tex/generic/pgf/frontendlayer/tikz/tikz.code.tex +++ b/tex/generic/pgf/frontendlayer/tikz/tikz.code.tex @@ -2580,31 +2580,64 @@ \def\tikz@fchar oreach{\tikz@foreach}% -\def\tikz@foreach{% +\def\tikzforeach@smugglers@cove{} +\let\tikztostart=\relax + +\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% + % +} + + +\def\tikz@patched@foreach{% \def\pgffor@beginhook{% - \global\let\tikz@moveto@waiting\tikz@foreach@moveto@waiting% - \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{% - \global\let\tikz@foreach@moveto@waiting\tikz@moveto@waiting% - \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{% - \let\tikz@moveto@waiting\tikz@foreach@moveto@waiting% - \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% @@ -2613,14 +2646,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}% - \global\let\tikz@foreach@moveto@waiting\tikz@moveto@waiting% + \tikzforeach@smugglers@loot% \foreach}% - % Syntax for againpath: % \againpath \somepathname