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

name prefix and name suffix vs. edge: starting point of edge paths are incorrect #846

Closed
ghost opened this issue Apr 13, 2020 · 3 comments
Closed
Milestone

Comments

@ghost
Copy link

ghost commented Apr 13, 2020

It seems that there is some problem using nodes with name prefix (or name suffix for that matter) and the edge path construction. When one switches on either of them, the edge will connect to the node center of the starting node.

\documentclass[tikz,border=3mm]{standalone}
\begin{document}
\begin{tikzpicture}[nodes={circle,draw},>=stealth]
 \begin{scope}[name prefix=L-]
  \path node (A) {A} (2,0) node (B){B};
  \path (A) edge (B);
 \end{scope}
 \begin{scope}[xshift=4cm]
  \path node (A) {A} (2,0) node(B){B};
  \path (A) edge (B);
 \end{scope}
\end{tikzpicture}
\end{document}

Screen Shot 2020-04-13 at 6 10 59 AM

Left is a scope with a name prefix, and the edge extends to the center of the A node, where as in the right scope, where there is no node prefix, the result is as expected. If we use a name suffix, the same problem arises.

@hmenke hmenke added this to the 3.1.6 milestone Apr 14, 2020
@QJLc
Copy link

QJLc commented Apr 18, 2020

I may get the point of this issue.

See tikz.code.tex.

After line 5427, I add lines:

    \def\tikz@parse@node@temp{#2}%
    \ifx\tikz@parse@node@temp\tikztostart%
      \tikz@shapebordertrue%
    \fi%

this will set the (\tikztostart) on shape border. But I do not know whether this will cause errors.

I guess, the key point about this issue is , command \tikz@scan@one@point sets \tikz@shapeborderfalse, the full name L-A is saved in \tikztostart, so, \tikz@shapeborderfalse is always valid, and then, command \tikz@@movetowill set

\let\tikz@moveto@waiting=\relax

@hmenke
Copy link
Member

hmenke commented Apr 18, 2020

Hm, I'm not sure whether this is the right way to approach this. It seems like a very symptomatic treatment. This patch also solves the problem and is maybe a bit more idiomatic. I'm not sure which way to go.

--- a/tex/generic/pgf/frontendlayer/tikz/tikz.code.tex
+++ b/tex/generic/pgf/frontendlayer/tikz/tikz.code.tex
@@ -5431,7 +5431,13 @@
         \tikz@shapebordertrue%
         \def\tikz@shapeborder@name{\tikz@pp@name{#2}}%
       \fi%
-    \fi
+    \else\ifcsname pgf@sh@ns@#2\endcsname
+      \expandafter\ifx\csname pgf@sh@ns@#2\endcsname\tikz@coordinate@text%
+      \else
+        \tikz@shapebordertrue%
+        \def\tikz@shapeborder@name{#2}%
+      \fi%
+    \fi\fi
   \fi%
   \edef\tikz@marshal{\noexpand#1{\noexpand\pgfqpoint{\the\pgf@x}{\the\pgf@y}}}%
   \tikz@marshal%

@QJLc
Copy link

QJLc commented Apr 18, 2020

Yes, I have learned it, your patch is very reasonable.
The command
\tikz@scan@one@point{\tikz@@moveto}(A)
will define
\def\tikz@shapeborder@name{L-A}
so, the added line
+ \def\tikz@shapeborder@name{#2}%
could repeat the defination, is this repetition needed?

hmenke added a commit to hmenke/pgf that referenced this issue May 18, 2020
We had similar things already.  Usually, when a prefixed name does not
exist TikZ either bails or just does nothing.  Here we have the latter
kind.  If the prefixed node has no anchor, TikZ just does nothing and
leaves \tikz@shapeborder@name unset.  This has adverse effects when
drawing edges, because they store the node name and restore it later.
When the node name is restored, another name prefix is added to the
already prefixed node that was stored.  To remedy this, we now try the
unprefixed node, when the prefixed node does not exist.  This is
probably not 100% compatible but whoever was relying on this behavior
was on thin ice anyway.  The new behavior is more of the kind of “do
what I mean”.
@hmenke hmenke closed this as completed May 18, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

2 participants