0

Keys can be set a default value by the handler /.default in pgfkeys. However, when this is used, the name of the key has to be in the list of \pgfkeys(e.g. \pgfkeys{mykey}). My question is: how to make a key get a default value when this key is not in the list of \pgfkeys. Here is my code example for illustration.

\documentclass{article} 
\usepackage{pgfkeys}

\begin{document}

\pgfkeys{mykey/.code=#1} 
\pgfkeys{} % I want to get a typeset of "3" for example

\end{document}
lyl
  • 2,727
  • This is only an example. There maybe many options in terms of "key=value" in a macro, but user need not specify every option when calling this macro. For those option arguments that do not appear in the list of \pgfkeys, I want to give them default values. – lyl May 19 '18 at 02:08
  • That is to say, not all options argument have to appear in the macro calling which has more than one optional arguments in terms of "key=value". – lyl May 19 '18 at 02:20
  • Thank you marmot for your good info. I think my example is poor which do not explain my real purpose. Yet I just find a solution to my question at https://tex.stackexchange.com/questions/85754/default-value-for-a-key-defined-with-pgfkeys . – lyl May 19 '18 at 02:40
  • To be honest I do not really understand the point of your question. Could you please clarify what you mean with "is not in the list of pgfkeys"? Undefined keys which should have a default? – TeXnician May 19 '18 at 07:56
  • @TeXnician There is a macro, for example, \mycmd, it should be call like this: \mycmd[key1=val1,key2=val2,key3=val3,...]{...}. However in many cased, it's unnessessory to specify all these keys. May be \mycmd[key2=val2]{...} is enough in which key1, key3,...keyn have their default values. – lyl May 19 '18 at 09:28
  • And where's the problem if you have defined the keys with an initial value? (Note: initial not default) – TeXnician May 19 '18 at 09:58
  • @TeXnician \pgfkeys{ aa/.code=#1, aa/.default=aa, aa/.initial=aa, bb/.code=#1, } \pgfkeys{bb=bb} you see, aa will not be typeset even if "/.initial" is used – lyl May 20 '18 at 01:14
  • And that's obviously correct, because \pgfkeys does set the keys, but not invoke them/gets the value. You should read the manual. – TeXnician May 20 '18 at 07:01

0 Answers0