How can I automatically execute a code in a tikz/pgf option when all options are processed? I want to execute a command a single time, say updateValueShouldBeCalledOnce (that reads some variable sets by previous options (sayBye/sayHello, potentially present multiple times)) as it fails if it's run twice, so for now I need to write \rar[sayBye,updateValueShouldBeCalledOnce], but I'd rather write:
\rar[sayBye]
How could I do that?
MWE (to check if the function is called once or twice, check at the log, it displays a message everytime the function is called)
\documentclass{article}
\usepackage{amsmath}
\usepackage{tikz-cd}
\begin{document}
\def\myvalue{}
\noindent\begin{tikzcd}[
updateValueShouldBeCalledOnce/.code={%
\message{The message is: \myvalue}%
},
sayBye/.code={%
\def\myvalue{^^J^^JBye!!!!!^^J^^J}% I don't want to call updateValueShouldBeCalledOnce here as it might be called several times
},
sayHello/.code={%
\def\myvalue{^^J^^JHello!!!!!^^J^^J}% I don't want to call updateValueShouldBeCalledOnce here as it might be called several times
},
nodes in empty cells=true,
every arrow/.style={
->,
draw,
sayHello
},
]
\text{I want to do this} & \
A \rar[updateValueShouldBeCalledOnce] & B \rar[sayBye,updateValueShouldBeCalledOnce] & C\
\text{But with this syntax} & \
A \rar & B \rar[sayBye] & C
\end{tikzcd}
\end{document}
Note that I'm aware of Save choice and execute later in pgfkeys? but it actually wants something different, as I'd like the differed action to be automatically run after reading all options.
\newcommand\myarrow[1][]{\arrow[#1,updateValueShouldBeCalledOnce]}. With a bit patch work, we can hide this from the user (so that the normal commands can be used) if necessary. – Qrrbrbirlbel Feb 22 '23 at 00:28\bgarrowwhere an arrow will be put onto thebackgroundlayer. Which would be just a specialized version of\arrowOnLayer{layername}[<normal options>]. Though, with filtered PGFkeys we could process the options to\arrowtwice, once to figure out which layer should be used and then for the normal TikZ path. – Qrrbrbirlbel Mar 02 '23 at 13:01