7

I've found the question Default value for a key defined with pgfkeys which works fine. But I would like to define an .is choice key with a default value, and I can't seem to get things to work.

I've tried something along the following lines

\makeatletter
\def\ae@subcolumn@width{\columnwidth/2}
\def\ae@subcolumn@height{\textheight}
\def\ae@par@style{CIAO MOON}
\pgfkeys{/ae/sub/column/.cd,
  width/.store in=\ae@subcolumn@width,
  height/.store in=\ae@subcolumn@height,
  par style/.code/.default={\def\ae@par@style{HELLO WORLD}},
  par style/.is choice,
  par style/raggedright/.code={\let\ae@par@style\raggedright},
  }

\newenvironment{aesubcol}[1]
  {%%
    \pgfkeys{/ae/sub/column/.cd,#1}%%
    \begin{minipage}[t][\ae@subcolumn@height]{\ae@subcolumn@width}%%
    \ae@par@style
  }{%%
    \end{minipage}}
\makeatother

I've also tried setting the default value using

  par style/.default={\def\ae@par@style{HELLO WORLD}},

or

  par style/.default/.code={\def\ae@par@style{HELLO WORLD}},

But none of these have the desired effect.

How can I set a default value for a choice key?

9

Default for an is choice is one of the choices, so simply do this:

\pgfkeys{/tmp/.is choice}
\pgfkeys{/tmp/list/.code={...}}
\pgfkeys{/tmp/.default=list}

This small example shows the expected behaviour:

\documentclass{article}
\usepackage{pgfkeys}
\begin{document}
\def\tmp{No-choice}
\pgfkeys{/test/my choice/.is choice,
    /test/my choice/list/.code={\def\tmp{list}},
    /test/my choice/array/.code={\def\tmp{array}},
}

\tmp

\pgfkeys{/test/my choice=array}
\tmp

\pgfkeys{/test/my choice=list}
\tmp

\pgfkeys{/test/my choice/.default=list}
\tmp

\pgfkeys{/test/my choice=array}
\tmp

\pgfkeys{/test/my choice}
\tmp

\end{document}
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.