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:


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)



    \message{The message is: \myvalue}%
    \def\myvalue{^^J^^JBye!!!!!^^J^^J}% I don't want to call updateValueShouldBeCalledOnce here as it might be called several times
    \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={
  \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


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.

  • 1
    Generally speaking, I don't think you can. You will have to compromise somewhere. What are you trying to achieve on the TikZ-CD level? Here, I suggest defining your own command: \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. Commented Feb 22, 2023 at 0:28
  • @Qrrbrbirlbel ok thanks, I guess I'll do that then (basically, I want to put all edges on a special layer by default, but the styles I got to change the layers are not really resilient to being changed multiple times).
    – tobiasBora
    Commented Feb 22, 2023 at 1:12
  • Layers as in PGF Layers, i.e. foreground/background stuff? An inflexible version of this consists in \bgarrow where an arrow will be put onto the background layer. Which would be just a specialized version of \arrowOnLayer{layername}[<normal options>]. Though, with filtered PGFkeys we could process the options to \arrow twice, once to figure out which layer should be used and then for the normal TikZ path. Commented Mar 2, 2023 at 13:01


You must log in to answer this question.

Browse other questions tagged .