Comment the 2 lines alternativelly, one works the other doesn't :
\documentclass{beamer}
\begin{document}
\pgfkeys{/Baq/.cd ,
nb/.default = 10,
nb/.store in = \nb,
nb,
contraintes/.default = 5,
contraintes/.store in = \contraintes,
% Comment alternativelly
contraintes/.code={\directlua{contraintes = \contraintes }} ,
contraintes
}
\newcommand{\Contraintes}[1][contraintes = 6]{%
\pgfkeys{/Baq/.cd , #1 }
\directlua{
% Comment alternativelly
% contraintes = \contraintes
nb = \nb
tex. print ( "Coucou :" , \nb , \contraintes )
}
}
\begin{frame}
\Contraintes
\end{frame}
\end{document}
It is possible to make the \directlua command part to work, but hen one can't change the value :
\documentclass{beamer}
\begin{document}
\pgfkeys{/Baq/.cd ,
contraintes/.store in = \contraintes,
contraintes = 5,
contraintes/.code={\directlua{contraintes = \contraintes }} ,
}
\newcommand{\Contraintes}[1][contraintes = 6]{%
\pgfkeys{/Baq/.cd , #1 }
\directlua{
tex. print ( "Coucou :" , \contraintes )
}
}
\begin{frame}
\Contraintes
\end{frame}
\end{document}
/.initialand/.code(or one of its relatives) can be used to bind to a key both a value and some code, respectively. See the doc for/.initial. – muzimuzhi Z Jul 08 '22 at 05:23