# How to define a style of undefined key choice? [duplicate]

I would like to implement something like default in a switch statement, but for .is choice pgf key. I know that there is an error key handler /errors/unknown choice value but I don't know how to use it. Or may be there is a solution without implementing this handler ?

What I want is when I define for example test/.is choice, to be able to define something like test/.else style={...} that is executed for any test=<unknown choice> with #1 set to <unknown choice> (like if test was not a choice).

\documentclass[tikz,border=7pt]{standalone}
\tikzset{
test/.is choice,
test/1/.style={red},
test/2/.style={blue},
% test/.else style={yellow} <-- how to implement this ?
}
\begin{document}
\begin{tikzpicture}
\fill[test=1] circle(3);
\fill[test=2] circle(2);
\fill[yellow] circle(1); % I would like [test=007]
\end{tikzpicture}
\end{document}


Note: I asked myself this question when I was writing this answer.

EDIT After the answer of @TeXnician I want to specify that I would like to be able to declare something like test/.else style={#1} and then use it like this test=yellow (the parameter is important for me).

You do not search for .else, but for .unknown (see section 82.3.6 in the TikZ manual).

\documentclass[tikz,border=7pt]{standalone}
\tikzset{
test/.is choice,
test/1/.style={red},
test/2/.style={blue},
test/.unknown/.style={yellow}
}
\begin{document}
\begin{tikzpicture}
\fill[test=1] circle(3);
\fill[test=2] circle(2);
\fill[test=007] circle(1); % I would like [test=007]
\end{tikzpicture}
\end{document}


As for requirement two: using the key given you can use it as \pgfkeyscurrentname, e.g.:

\documentclass[tikz,border=7pt]{standalone}
\tikzset{
test/.is choice,
test/1/.style={red},
test/2/.style={blue},
test/.unknown/.style={\pgfkeyscurrentname}
}
\begin{document}
\begin{tikzpicture}
\fill[test=1] circle(3);
\fill[test=2] circle(2);
\fill[test=yellow] circle(1); % I would like [test=007]
\end{tikzpicture}
\end{document}

• Thanks for your answer that ask one part of my question, because the #1 is not set to 007 like this. Sorry, my example was not clear :( – Kpym Apr 14 '18 at 8:39
• This is what I was searching for, thanks ! I tried \pgfkeyscurrentvalue but it was not defined ;) – Kpym Apr 14 '18 at 8:58
• The bad news for me is that .list={1,...,\pgfkeyscurrentname} is not working, where .list={1,...,#1} is working :( – Kpym Apr 14 '18 at 9:08
• @Kpym That's probably, because it does not expand properly. Maybe you should ask this as new question. – TeXnician Apr 14 '18 at 9:10
• I have my expansion (not very nice) solution with .unknown/.prefix code={\edef\pgfkeyscurrentchoice{\pgfkeyscurrentname}} and then use \pgfkeyscurrentchoice in place of \pgfkeyscurrentname in .list={1,...,\pgfkeyscurrentchoice}. – Kpym Apr 14 '18 at 9:29