8

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?

1 Answer 1

10

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}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .