What is the best way to alias a key using PGF Keys

The approach I usually employ is to use a .code handler that just executes \pgfkeysalso on the alias target:

\pgfkeys{other path/somecolor/.code={\pgfkeysalso{path/color=#1}}

However, as I have learned from Christian Feuersänger, this is exactly how the .style handler is defined in pgfkeys. So an even cleaner solution is:

\pgfkeys{/other path/somecolor/.style={path/color=#1}}

I have expanded on Daniel's idea and used handlers to define a handler called .alias. The code is shown below:

\documentclass{article}
\usepackage{pgfkeys}
\begin{document}
\makeatletter
% alias key
\pgfkeys{%
   /handlers/.alias/.code=
      \pgfkeysedef\pgfkeyscurrentpath{%
                  \noexpand\pgfkeysalso{\pgfkeysdefaultpath#1={##1}}},%
      /handlers/.alias/.value required,%
      /handlers/.blank/.code=\pgfkeyssetvalue{\pgfkeyscurrentpath/.@blank}{#1},%
      /handlers/.blank/.default=\pgfkeysnovalue,%
}

\pgfkeys{test/.store in=\storethis,
         tes/.alias=test,}

\pgfkeys{tes=123}
\storethis 

\pgfkeys{test=this is a test}
\storethis
\end{document}

Came across the .forward to handler in the pgf manual on page 891.

\documentclass{article}
\usepackage{pgfkeys}
\begin{document}
    \makeatletter
    \pgfkeys{
        path/color/.store in=\color@cx,
        path/somecolor/.forward to=/path/color
    }
    \pgfkeys{path/somecolor=red}
    \color@cx
\end{document}

Which produces "red".

Tags:

Pgfkeys