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

I would like to be able to alias a PGF key to another name, is this possible and if it is, how do I do this?

For example if I have defined a key as:

 \pgfkeys{path/
color/.store in=\color@cx
}


I would like have the ability to let "color" to "somecolor" would it also be possible to alias keys that have been defined using .style?

-
In this particular example, whenever you refer to it with color=somecolor it would be stored in \color@cx. Which one do you want to access later with alias? There is /.link key but I don't know if that's what you are after. –  percusse Apr 9 '12 at 10:27
@percusse I would like both to point to the same macro color->color@cx and somecolor->color@cx. –  Yiannis Lazarides Apr 9 '12 at 10:42
They can both be appointed to execute the same /.code. For example, \pgfkeys{setmycolor/.code={\color@cx=#1}}\/pgfkeys{color/.style={setmycolor=blu‌​e}}\pgfkeys{somecolor/.style={setmycolor=red}}. –  percusse Apr 9 '12 at 10:51

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}}

-
Note that this is 100% equivalent to other path/somecolor/.style={path/color=#1}. This is because /.style is defined by means of \pgfkeysalso (just as you did). An "alias" in this sense is a style. –  Christian Feuersänger May 11 '12 at 20:30
@ChristianFeuersänger:Thanks for the info; I have edited this into the answer. –  Daniel May 11 '12 at 21:10
I added a missing closing brace to Daniel's second solution. –  Ahmed Musa May 11 '12 at 23:58
@Daniel I would appreciate your comments on the code I posted --still finding my way around pgf:) . –  Yiannis Lazarides Jun 6 '12 at 13:48

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}

-
I don't know pgfkeys well, but what is the name/macro \pgfkeyscurrentpath/.@blank supposed to do? –  Ahmed Musa Jun 6 '12 at 16:03
Good idea, way more PGFish :-) I probably would reverse the syntax and make .alias a handler that is executed on the key to link to (test/.alias=tes) instead of the alias, as this seems more natural to me (reflects the order of parameters to ln -s on UNIX) –  Daniel Jun 6 '12 at 20:47
@AhmedMusa It creates a handler to provide a value for the empty case i.e, test/.default=default, test/.blank=this is blank, will print for test default and for test= will give this is blank. Not related to the question, but thought could be useful to leave it in. –  Yiannis Lazarides Jun 6 '12 at 23:06
@Daniel Thanks, agreed on the reverse. –  Yiannis Lazarides Jun 6 '12 at 23:06