Yesterday, I provided an (incorrect) answer to this question, and would like to check my understanding of why it was wrong.
The answer I provided produced (almost) the correct result in the output document, but for very wrong reasons, and I would like a deeper understanding of what my answer is actually doing (as opposed to what I thought it was doing).
\documentclass{article}
\usepackage{tikz}
\begin{document}
\pgfkeys{/a/.code=(a)}
\pgfkeys{/a}
\def\b{\pgfkeys{/a}}
\b
\expandafter\def\c{\pgfkeys{/a}}
\c
\end{document}
seems to produce the correct output of (a) (a) (a)
(with an additional space between the first and second (a)
). I didn't use \show
to see what each of \a
, \b
, and \c
were, though, so didn't actually answer the question as asked.
I assumed that \expandafter\def\c{\pgfkeys{/a}}
would expand the pgfkeys
part, and assign it to \c
, and so do what the original questioner wanted.
From @DavidCarlisle's comment, this only works because \c
is already defined, and so this re-defines the expansion of \c
(in the comment \T1-cmd
, in my case \OT1-cmd
) to be \pgfkeys{/a}
(not expanded), and so is the same as \b
. The use of \c
then expands, and produces the same as the expansion of \b
(additionally, breaking any use of accents at any point further in the document).
Is my understanding of what went wrong correct? If not, what does this actually do? Bonus question: is there a number of \expandafter
here that would make this actually work the way I thought?
\expandafter\def\expandafter\c\expandafter{\pgfkeys{/a}}
. But it only expand once, it doesn't expand fully. So \c would then have the definition\expandafter \pgfkeys@@set \expandafter {\pgfkeysdefaultpath }{/a}
{
and}
as "mere group delimiters that don't really count", but TeX sees each one of them as one token (unless the standard plain/LaTeX catcodes have been changed), so they do count for\expandafter