Skip to content

Commit

Permalink
More robust fix for foreach
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
loopspace committed Jan 9, 2024
1 parent 4641086 commit a898ad3
Showing 1 changed file with 50 additions and 22 deletions.
72 changes: 50 additions & 22 deletions tex/generic/pgf/frontendlayer/tikz/tikz.code.tex
Original file line number Diff line number Diff line change
Expand Up @@ -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%
Expand All @@ -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

Expand Down

0 comments on commit a898ad3

Please sign in to comment.