# The difference between \pgfkeysvalueof and /.store in [duplicate]

I thought using \pgfkeysvalueof on a key that does not have a /.store in and the variable of a key that does have a /.store in would give the same result. This seems not to be the case.

This example, using /.store in for the key overlay works like a charm:

\documentclass{article}
\usepackage{tikz}
\usepackage{etoolbox}
\usepackage{overpic}

\pgfkeys{
/icon/.cd,
width/.initial,
overlay/.initial,
overlay/.store in=\iconoverlay,
set defaults/.unknown/.code={\pgfkeys{/icon/\pgfkeyscurrentname/.default=#1}}
}
\newcommand\icondefaults[1]{%
\pgfkeys{/icon/set defaults/.cd, #1}%
}
\newcommand\ifkeyempty[3]{%
\pgfkeysgetvalue{#1}{\keyvalue}%
\ifempty{\keyvalue}{#2}{#3}%
}
\newcommand\ifempty[3]{%
\def\novalue{\pgfkeysnovalue}%
\def\empty{}%
\ifboolexpr{test {\ifdefequal{#1}{\empty}} or test {\ifdefequal{#1}{\novalue}}}{#2}{#3}%
}
\newcommand{\icon}[2][]{%
{%
\pgfkeys{/icon/.cd,width,overlay,#1}% Reset to default values
\def\options{}%
\ifkeyempty{/icon/width}{}{\edef\options{width=\pgfkeysvalueof{/icon/width},\options}}%
\ifempty{\iconoverlay}{%
\edef\graphic{\noexpand\includegraphics[\options]{#2}}%
}{%
\edef\overlay{\noexpand\begin{overpic}[\options]{#2}}%
\def\graphic{\overlay\put(0,0){\iconoverlay}\end{overpic}}%
}%
\graphic%
}%
}%

\begin{document}

\icondefaults{width=6cm}
\icon{example-image} % Image gets default width 6cm
\icon[width=2cm,overlay={\icon{example-image-overlay}}]{example-image} % Image gets width 2cm, while the overlaid image gets default width 6cm
\icon{example-image} % Image gets default width 6cm

\end{document}


While this example does not work. The only difference is that /.store in is not used for the key overlay, and hence \pgfkeysvalueof is used to access the value of the key. It results in an error TeX capacity exceeded.

\documentclass{article}
\usepackage{tikz}
\usepackage{etoolbox}
\usepackage{overpic}

\pgfkeys{
/icon/.cd,
width/.initial,
overlay/.initial,
set defaults/.unknown/.code={\pgfkeys{/icon/\pgfkeyscurrentname/.default=#1}}
}
\newcommand\icondefaults[1]{%
\pgfkeys{/icon/set defaults/.cd, #1}%
}
\newcommand\ifkeyempty[3]{%
\pgfkeysgetvalue{#1}{\keyvalue}%
\ifempty{\keyvalue}{#2}{#3}%
}
\newcommand\ifempty[3]{%
\def\novalue{\pgfkeysnovalue}%
\def\empty{}%
\ifboolexpr{test {\ifdefequal{#1}{\empty}} or test {\ifdefequal{#1}{\novalue}}}{#2}{#3}%
}
\newcommand{\icon}[2][]{%
{%
\pgfkeys{/icon/.cd,width,overlay,#1}% Reset to default values
\def\options{}%
\ifkeyempty{/icon/width}{}{\edef\options{width=\pgfkeysvalueof{/icon/width},\options}}%
\ifkeyempty{/icon/overlay}{%
\edef\graphic{\noexpand\includegraphics[\options]{#2}}%
}{%
\edef\overlay{\noexpand\begin{overpic}[\options]{#2}}%
\def\graphic{\overlay\put(0,0){\pgfkeysvalueof{/icon/overlay}}\end{overpic}}%
}%
\graphic%
}%
}%

\begin{document}

\icondefaults{width=6cm}
\icon{example-image} % Image gets default width 6cm
\icon[width=2cm,overlay={\icon{example-image-overlay}}]{example-image} % Image gets width 2cm, while the overlaid image gets default width 6cm
\icon{example-image} % Image gets default width 6cm

\end{document}


Does anyone know what is the difference between accessing a key's value through \pgfkeysvalueof and through it's /.store in variable?