当所有选项都处理完毕后,如何自动执行 tikz/pgf 选项中的代码?我想执行一次命令,比如说updateValueShouldBeCalledOnce
(读取前面选项设置的一些变量(sayBye
/ sayHello
,可能出现多次)),因为如果运行两次就会失败,所以现在我需要写\rar[sayBye,updateValueShouldBeCalledOnce]
,但我宁愿写:
\rar[sayBye]
我怎能这样做?
平均能量损失(要检查该函数是否被调用一次或两次,请检查日志,每次调用该函数时它都会显示一条消息)
\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}
请注意,我知道保存选择并稍后在 pgfkeys 中执行?但它实际上想要一些不同的东西,因为我想在读取所有选项后自动运行不同的操作。