I am trying to use the xkeyval
package to include key arguments in a new environment. It seems to work except for default values. Here's my best try so far:
\documentclass{article}
\usepackage{xkeyval}
\makeatletter
\define@key{Mystuff}{foo}[what]{\def\foo{#1}}
\define@key{Mystuff}{bar}[whatever]{\def\bar{#1}}
\savekeys{Mystuff}{foo,bar}
\makeatother
\newenvironment{myenv}[1][]%
{\setkeys{Mystuff}{#1}BEGIN \foo}
{END \bar}
\begin{document}
\begin{myenv}[bar=BAAAR]
Uh?
\end{myenv}
\end{document}
But this will cause LaTeX to complain about
\foo
being undefined:
! Undefined control sequence.
\\myenv [#1]->\setkeys {Mystuff}{#1}BEGIN \foo
l.18 \begin{myenv}[bar=BAAAR]
And the output will be something like "BEGIN Uh? END BAAAR
" (without the default "what" value to \foo
).
What am I doing wrong there, and how can I change this example so the default value for \foo
will be used?