I am trying to use pgfkeys to define an API for some macros, and I am having trouble detecting when a key is "empty". Based on this answer, I have come up with the following code:
\documentclass[12pt]{article}
\usepackage{tikz}
\usepackage{etoolbox}
\newcommand{\specialsave}[1]{
\pgfkeys{
/specialstore/place/.cd,
a/.initial,
c/.initial,#1, % there cannot be a newline before #1
c/.get=\cvalA, % this must come after #1, otherwise it won't get the values that are set
}
\edef\cvalB{\pgfkeysvalueof{/specialstore/place/c}}
\def\compareval{\pgfkeysnovalue}
\ifdefequal{\cvalA}{\compareval}{c is empty by comparison A}{c is non-empty by comparison A}
\ifdefequal{\cvalB}{\compareval}{c is empty by comparison B}{c is non-empty by comparison B}
}
\begin{document}
\specialsave{
a=the values of a,
}
\\
\specialsave{
a=the values of a,
c
}
\\
\specialsave{
a=the values of a,
c=
}
\\
\specialsave{
a=the values of a,
c={}
}
\end{document}
which produces:
c is empty by comparison A
c is non-empty by comparison B
c is empty by comparison A
c is non-empty by comparison B
c is non-empty by comparison A
c is non-empty by comparison B
c is non-empty by comparison A
c is non-empty by comparison B
My question is
- How can I detect empty values in
\cvalB, and - How can I detect that the values in cases
c=andc={}are "empty"?


\cvalA, though... Can you explain why it works? – Jason Siefken May 26 '19 at 15:50\edef\cvalB{\pgfkeysvalueof{/specialstore/place/c}}and\edef\compareval{\pgfkeysnovalue}, and compare the expanded values. In your code, only the first one is expanded, so you compare an expanded value with an unexpanded one. – May 26 '19 at 17:32\edef\cmpareval{\pgfkeysnovalue}version,\ifdefequal{\cvalA}{\compareval}{c is empty}{c is non-empty}reportsc is non-emptyin the first two cases. – Jason Siefken May 26 '19 at 18:18.getcode" I was under the impression that you only want the B check to work. (I just realized that the above code really did not work because I again lost again the editor of this site. I fixed this. The lower code does not use.getand works.) – May 26 '19 at 18:23