Consider the following code:
\documentclass[border=2mm]{standalone}
\usepackage{tikz}
\usepackage{xcolor}
\makeatletter
\tikzset { myVSplitPlainVrtxStyle/.style args={#1,#2}{%
circle,
minimum size= 5mm,
draw= #1!55!black!90,
fill = #1,
alias=tmp@name,
postaction={%
insert path={
\pgfextra{%
\pgfpointdiff{\pgfpointanchor{\pgf@node@name}{center}}%
{\pgfpointanchor{\pgf@node@name}{east}}%
\pgfmathsetmacro\insiderad{\pgf@x}
% } %The alternative bracket closing
\fill[#2] (\pgf@node@name.base) ([yshift=\pgflinewidth]\pgf@node@name.south) arc (-90:90:\insiderad-\pgflinewidth)--cycle;
\draw[#2!55!black!90] (\pgf@node@name.base) ([yshift=\pgflinewidth/2]\pgf@node@name.south) arc (-90:90:\insiderad-\pgflinewidth/2);
}
}
}
}
}
\makeatother
\begin{document}
\begin{tikzpicture}
\node[ myVSplitPlainVrtxStyle = {blue, lime} ] {};
\end{tikzpicture}
\end{document}
I have copy-pasted this code and modified it to my needs; however, there are parts that I do not understand. I would appreciate it you helping me understand what is going on. Also any improvements or seperate ideas are welcomed.
alias = tmp@name- I have no idea why this is needed. I believed it is related to the fact that the style gets two input arguments. What does it do? Why is it necessary?
postaction- I do not see the need for postaction. There is no need to say "do it later", and yet, when I remove it the code no longer function. What is happening?
insert path- The manual says it is used to add something to the current path. I believe the only reason for its existence is to allow the use of
\pgfextra. However, what is the current path in this context? Any other way to do this?
- The manual says it is used to add something to the current path. I believe the only reason for its existence is to allow the use of
\pgfextra- Why use this option? The manual says this command is used in path construction and temporary suspends that to have some TeX code executed first. More importantly, I am confused by the place the closing bracket
}is placed. I have marked the more natural place for me, but that produces error. Why my intuition of the position of}is incorrect?
- Why use this option? The manual says this command is used in path construction and temporary suspends that to have some TeX code executed first. More importantly, I am confused by the place the closing bracket
(\pgf@node@name.base)- The original author have put this in the code. I don't understant the need of it. It works fine without it. Why was it done?




\pgfextrahas the following usage\draw (0,0)--(1,1) \pgfextra{LaTeX code such as \pgfmathsetmacro} (2,2)--(3,3). That is, it escapes back to the normal LaTeX context and lets you do arithmetics. – Symbol 1 Jun 22 '21 at 06:02(\pgf@node@name.base)will move the "cursor"/"pen" to that point. Base is a rather bizarre anchor; it has something to do with the position of the text but there is no text here. You may delete it if that does not cause harm. – Symbol 1 Jun 22 '21 at 06:07\node ... ;is a shorthand of\draw node ... ;. The current path in this context is an empty path. So you need to add something (in your case, hemicircles) to have it drawn and filled. – Symbol 1 Jun 22 '21 at 06:11alias=tmp@nameis (probably) giving the concerned node a dummy name so that\pgf@node@nameis nonempty. It cannot bename=tmp@namebecause that will override the name you gave. – Symbol 1 Jun 22 '21 at 06:13postactionis to postpone the drawing until the node name is defined. – Symbol 1 Jun 22 '21 at 06:15
– Aria Jun 23 '21 at 01:05It is curious that pgf@node@name does not use "name" and will use the alias name (at least I think that is what is happening.) Just out of curiosity you know of any reason why?
As it the case in your example and manual you put
}after the computations like\pgfmathsetmacrois done. The placement of}is still curious for me, as it does not run properly in my placement.In this case it is logical (based on the objective) to have
postaction; however, (again out of curiosity) why doesn't it run if you remove it.\pgf@node@nameis probably accessed by bothnameandaliasso either of them will make it nonempty. It doesn't matter ifpgf@node@nameends up with being the alias because it still points to the name. For 2, the closing brace}is part of the\pgfextra{ ... }syntax. The correct syntax of the math macro is\pgfmathsetmacro\twenty{10+5*2}. (cont) – Symbol 1 Jun 23 '21 at 01:34circleand to access its anchors at the same moment. – Symbol 1 Jun 23 '21 at 01:35