3

I want to create a command that can change the default value of my pgfkeys. I think the problem is that the value set as default is not expanded. Therefore the icondefaultsa below doesn't work. Therefore I made icondefaultsb, which works. The drawback is that the global variables \width and \overlay are created, and changing them also changes the default values of the pgfkeys.

\pgfkeys{
    /icon/.cd,
    width/.initial = ,
    width/.default = ,
    overlay/.initial = ,
    overlay/.default = ,
    width,overlay,
}
\newcommand\icondefaultsa[1]{%
    \pgfkeys{/icon/.cd,#1}%
    \pgfkeys{
        /icon/.cd,
        width/.default = \pgfkeysvalueof{/icon/width},
        overlay/.default = \pgfkeysvalueof{/icon/overlay},
        width,overlay,
    }%
}
\newcommand\icondefaultsb[1]{%
    \pgfkeys{/icon/.cd,#1}%
    \pgfkeysgetvalue{/icon/width}{\width}%
    \pgfkeysgetvalue{/icon/overlay}{\overlay}%
    \pgfkeys{
        /icon/.cd,
        width/.default = \width,
        overlay/.default = \overlay,
        width,overlay,
    }%
}

1 Answer 1

3

Not sure if this quite what you want, but you could try the following and see if it works:

\documentclass[border=5]{standalone}
\usepackage{pgfkeys}

\begin{document}

\pgfkeys{%
    /icon/.cd,
    width/.initial=,
    width/.default=,
    overlay/.initial=,
    overlay/.default=,
    %
    set defaults/.cd,
    .unknown/.code={%
      \pgfkeys{/icon/\pgfkeyscurrentname/.default=#1}%
    }
}
\def\icondefaultsa#1{%
    \pgfkeys{/icon/set defaults/.cd, #1}%
}
\tt
\begin{tabular}{l}
\pgfkeys{/icon/width}
width: (\pgfkeysvalueof{/icon/width})
\\
\icondefaultsa{width=5pt}%
\pgfkeys{/icon/width}
width: (\pgfkeysvalueof{/icon/width})
\\
\icondefaultsa{width=23pt}%
\pgfkeys{/icon/width}
width: (\pgfkeysvalueof{/icon/width})

\end{tabular}
\end{document}

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .