In the intersections
library, the macro \tikz@intersect@namedpaths
is used to ensure that the path-saving is done right at the end. It is globally defined, but is only locally reset to empty when it has been processed. This means that, for example, it can persist outside scopes meaning that paths named inside a scope can become available outside it, causing potential issues with conflicting names.
The fix would seem to be to make the reset global by prefixing the \let
inside \tikz@intersect@finish
by \global
.
Here's a MWE. See also this question on TeX-SX.
\documentclass{article} %\url{http://tex.stackexchange.com/q/150598/86} \usepackage{tikz} \usetikzlibrary{intersections} \begin{document} \begin{tikzpicture} \draw[name path=abc] (-3,-3) -- (3,3); \draw[name path=def] (3,-3) -- (-3,3); \draw[green, ultra thick, name intersections={of=abc and def}] (intersection-1) circle[radius=6pt]; \begin{scope} \draw[name path=abc] (-3,-2) -- (2,3); \draw[green, ultra thick, name intersections={of=abc and def}] (intersection-1) circle[radius=6pt]; \end{scope} \path (0,0); % needed to invoke \tikz@intersect@namedpath from inside the scope \draw[blue, ultra thick, name intersections={of=abc and def}] (intersection-1) circle[radius=10pt]; \end{tikzpicture} \makeatletter \def\tikz@intersect@finish{% \ifx\tikz@intersect@namedpaths\pgfutil@empty% \else% \tikz@intersect@namedpaths% \global\let\tikz@intersect@namedpaths=\pgfutil@empty% \fi% } \makeatother \begin{tikzpicture} \draw[name path=abc] (-3,-3) -- (3,3); \draw[name path=def] (3,-3) -- (-3,3); \draw[green, ultra thick, name intersections={of=abc and def}] (intersection-1) circle[radius=6pt]; \begin{scope} \draw[name path=abc] (-3,-2) -- (2,3); \draw[green, ultra thick, name intersections={of=abc and def}] (intersection-1) circle[radius=6pt]; \end{scope} \path (0,0); % needed to invoke \tikz@intersect@namedpath from inside the scope \draw[blue, ultra thick, name intersections={of=abc and def}] (intersection-1) circle[radius=10pt]; \end{tikzpicture} \end{document}
Fixed in CVS as suggested.
The bugfix broke the manual, in particular, the euclid example
It fails with
Reverting the patch makes this work again.
I would suggest to move the clearing instruction either to
\end{scope}
or to\end{tikzpicture}
, whatever fits best... does that make sense?I will reopen the ticket.
@Till if you do not mind, I will revert the fix for now such that the manual compiles
Last edit: Stefan Pinnow 2018-12-21
Not easily fixable, see note in the code in
\tikz@intersect@finish
.I was thinking to reset
\tikz@intersect@namedpaths
using\aftergroup
. In the folowing example it worksthe same code without the fix produce
and it do not breake the code from the manual given by Christian Feuersänger earlier.
But it is not working if we have multiple groups like this
So this is not a good fix, but it is clear that
\tikz@intersect@namedpaths
should not be available outside the current group.One more : I think that
\global\let\tikz@intersect@namedpaths=\pgfutil@empty
(with\gloabl
!) should be executed rally "after" the;
if this is possible. The\tikz@finish
is executed more than once for some "complex" paths, end this is why\gloabl
breaks some examples.For example the following code, where I aded manually
\clear@namedpaths
after each;
, works fine.And this manual cleaning looks to be backward compatible. But I don't know if there is a possibility in tikz to run something really after the
;
(something likeexecute after path end
key).I think I have found a solution (or an idea of solution): instead of resetting globally
\tikz@intersect@namedpaths
after the;
we can do it at the beginning of every\path
command. Here is the code :And if this code is used we don't need to clear
\tikz@intersect@namedpaths
in\tikz@intersect@finish
or we can simply remove
\tikz@intersect@finish
and replace it with\tikz@intersect@namedpaths
inside\tikz@finish
.This works with the examples I have tested.
Last edit: Kpym 2019-01-07
Does it also work in low-level PGF or does the problem not exist there?
This is a problem at TikZ level only, conserning
name path
key (vsname path global
key).Last edit: Kpym 2019-01-10
Could you please submit a merge request with the required changes?
Done.