pgf macros add tag
user 3.14159
I try to summarize the question in the following mini-article (the TeX code is below):
![Screen Shot 2021-03-23 at 9.59.00 PM.png](/image?hash=673bb6e3d5315b51a7a687ccb6213770f950fe084d1c07c36b2b51a2bc1ad970)
\subsection*{Standard \LaTeX}
In standard \LaTeX\ (or just \TeX) one define macros, e.g.\def\mycode#1{(#1!)}
One can then use the macro ``as is'', e.g.
\verb|\mycode{pft}| yields \texttt{\mycode{pft}}.
If the result of such operations is expandable, one can store it in a new macro,
\verb|\edef\myresult{\mycode{pft}}\myresult| yields \myresult.


In \texttt{pgf} one can also define macros/codes, e.g.\pgfkeys{/my stuff/my code/.code={(#1!)}}
 \verb|\pgfkeys{/my stuff/my code/.code={(#1!)}}|.
One can then use the code ``as is'', e.g.
\verb|\pgfkeys{/my stuff/my code=pft}| yields \texttt{\pgfkeys{/my stuff/my code=pft}}.
However, storing the result in a new macro is not easy. For instance, naive
attempts of the sort
 \verb|\edef\myresult{\pgfkeys{/my stuff/my code=pft}}|
fail miserably. One \emph{can} make it work, of course,
\verb|\pgfkeysgetvalue{/my stuff/my code/.@cmd}{\mytemporarymacro}%|\\
\pgfkeysgetvalue{/my stuff/my code/.@cmd}{\mytemporarymacro}%
But this is far from elegant.


Is it possible to get the result of a \texttt{pgf} code more easily? 

P.S.\ The \verb|\edef| is not essential, the analogous question arises for
ordinary \verb|\def|s.
Top Answer
Anonymous 2081


%%% stolen from ConTeXt's syst-ext.mkii







% #1 \def method
% #2 PGF key
% #3 macro
    % Retrieve args and body
    % Assemble macro
    \to \pgfkeys@temptoks
    \to \pgfkeys@temptoks

%\def\pgfkeysgetgdef{\pgfkeysgetdef@\gdef} % if desired


% Works for code with single argument
\pgfkeys{/my stuff/my code/.code={(#1!)}}
\pgfkeysgetdef{/my stuff/my code}{\mymacro}

% Works for code with n arguments (here only 2)
\pgfkeys{/my stuff/my code/.code 2 args={(#1+#2!)}}
\pgfkeysgetdef{/my stuff/my code}{\mymacro}

% Works for code with delimited arguments
\pgfkeys{/my stuff/my code/.code args={[#1/#2]}{(#1--#2!)}}
\pgfkeysgetdef{/my stuff/my code}{\mymacro}


This room is for discussion about this question.

Once logged in you can direct comments to any contributor here.

Enter question or answer id or url (and optionally further answer ids/urls from the same question) from

Separate each id/url with a space. No need to list your own answers; they will be imported automatically.