I need to be able to check if the value of a pgfkey is empty or not. A solution I have tried (using package etoolbox
):
\edef\temp{\pgfkeysvalueof{/path/key}}%
\expandafter\ifstrequal\expandafter{\temp}{}{key is empty}{key is not empty}%
But this does not work if the value of the key expands to something empty or even worse: the value of the key cannot be expanded! How can I check whether a key is empty or not without expanding it? I just want to check if it's string value is equal to "" or not.
Edit: Added a full example
\documentclass{article}
\usepackage{tikz}
\usepackage{etoolbox}
\usepackage{overpic}
\newcommand{\strcomp}{\expandafter\ifstrequal\expandafter}%
\pgfkeys{
/icon/.cd,
width/.initial,
overlay/.initial,
}
\newcommand{\icon}[2][]{%
{%
\pgfkeys{/icon/.cd,width,overlay,#1}%
\def\options{}%
\edef\temp{\pgfkeysvalueof{/icon/width}}%
\strcomp{\temp}{}{}{\edef\options{width=\pgfkeysvalueof{/icon/width},\options}}%
\edef\temp{\pgfkeysvalueof{/icon/overlay}}%
\strcomp{\temp}{}{%
\edef\graphic{\noexpand\includegraphics[\options]{#2}}%
}{%
\edef\temp{\noexpand\begin{overpic}[\options]{#2}}%
\def\graphic{\temp\put(0,0){\pgfkeysvalueof{/icon/overlay}}\end{overpic}}%
}%
\graphic
}%
}%
\begin{document}
\icon{example-image} % Works!
\icon[width=3cm]{example-image} % Works :)
\icon[width=3cm,overlay=jei]{example-image} % Also works :)
\icon[width=3cm,overlay={\includegraphics{overlay-image}}]{example-image} % Breaks down when trying to expand in \edef\temp{\pgfkeysvalueof{/icon/overlay}}
\end{document}