I need to be able to refer to the same identifier when a node is being created and when a path is drawn. For now I tried to use \tikz@fig@name during the node creation, and \tikztostart (or \tikztoend) during the path creation... While it works for tikz-cd matrices, it fails on regular nodes (\tikz@fig@name is empty). Ideally, I'd like this common identifier to work for tikz-cd matrices, named nodes, and not named nodes... but since I don't think it's possible to draw a link when a node has no name, it's less important if it fails for no-named nodes.
The goal is to solve this issue: Compute intersection between a node's boundary and a path (Or, how to generalize pgfpointshapeborder)
MWE (see log to see the name of the nodes)
\documentclass[]{article}
\usepackage{tikz-cd}
\usetikzlibrary{calc}
\usetikzlibrary{shapes.misc, positioning,intersections}
\begin{document}
\makeatletter
\tikzset{
defaultNodeStyle/.code={
\tikz@fig@mustbenamed %% <- this forces a name, but when the node already has a name, this name will change... (see logs) Not very useful.
\message{The node name is: \tikz@fig@name}
},
mypath/.style={
to path={
\pgfextra{
\message{The starting point name is: \tikztostart}
\message{The ending point name is: \tikztotarget}
}
(\tikztostart) -- (\tikztotarget) \tikztonodes
},
}
}
\makeatother
\begin{tikzcd}
|[defaultNodeStyle]| A \ar[r,mypath] & |[defaultNodeStyle]| B
\end{tikzcd}
\message{========= Tikzpicture myNodeName(2) ========}
\message{Observe that node names does not match starting points:}
\begin{tikzpicture}
\node[defaultNodeStyle] (myNodeName) {Named};
\node[defaultNodeStyle] (myNodeName2) at (1,1) {Named};
\draw (myNodeName) to[mypath] (myNodeName2);
\end{tikzpicture}
\message{========= Tikzpicture no name ========}
\begin{tikzpicture}
\node[defaultNodeStyle] {No name};
\end{tikzpicture}
\end{document}
\tikz@fig@mustbenamedwhich forces a node to have a name. – Andrew Stacey Oct 20 '21 at 15:07\tikz@fig@mustbenamedin thedefaultNodeStyle/.codedoes force a name (which is cool for empty names), but unfortunately for nodes named manually like\node[defaultNodeStyle] (myNodeName2) {}the name is changed afterwards, so the starting point ismyNodeNamewhile the value after\tikz@fig@mustbenamedistikz@f@3... – tobiasBora Oct 21 '21 at 14:36name path=function@of@the@name... so I guess I can do it quite late. But I also discovered another issue: if I use an alias for my node, then\tikztostartwill be the name of the alias, and \emph{not} the name of the node... So I basically have 3 versions of the name for a same node that coexists: the temporary name, the real name given by the user, and the alias when used later to draw wires... (I need alias because I'm playing also with matrices) – tobiasBora Oct 21 '21 at 17:54