2

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}

tobiasBora
  • 8,684
  • Are you okay browsing the tikz source code? If so, there's a command something like \tikz@fig@mustbenamed which forces a node to have a name. – Andrew Stacey Oct 20 '21 at 15:07
  • @AndrewStacey putting \tikz@fig@mustbenamed in the defaultNodeStyle/.code does 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 is myNodeName while the value after \tikz@fig@mustbenamed is tikz@f@3... – tobiasBora Oct 21 '21 at 14:36
  • When do you need to know the name? Can you delay needing to know it until after a name would have been given, if it is given? – Andrew Stacey Oct 21 '21 at 17:50
  • For the nodes, I just need that name to choose a name 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 \tikztostart will 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
  • (for now I redefined a command to add the alias, and to create another name path for me, but it's not super efficient) – tobiasBora Oct 21 '21 at 18:07

0 Answers0