I've been doing some experiments with the xkeyval package and I've encountered two problems I haven't been able to solve (yet); in the following example code I define and set two families of keys: box and text and use those to build two simple commands.
1) How do I keep local the values set for the keys in the optional argument of \mybox? (if you compile my example code you'll have a better idea of my problem).
Code: Select all
\documentclass{article}
\usepackage{xkeyval}
\usepackage{xcolor}
\makeatletter
\define@key{box}{fcolor}{\def\FrameColor{#1}}
\define@key{box}{bgcolor}{\def\BgColor{#1}}
\setkeys{box}{fcolor=blue,bgcolor=red}
\define@key{text}{family}{\def\FontFamily{#1}}
\define@key{text}{series}{\def\FontSeries{#1}}
\setkeys{text}{family=\sffamily,series=\bfseries}
\makeatother
\newcommand\mybox[2][]{%
\setkeys{box}{#1}
\fcolorbox{\FrameColor}{\BgColor}{#2}
}
\newcommand\mytext[2][]{%
\setkeys{text}{#1}
{\FontFamily\FontSeries#2}
}
\begin{document}
This box has (as it should) the values that were set for the keys in the definition
\mybox{text}
This box has (as it should) the values set in the optional argument of \verb+\mybox+
\mybox[fcolor=blue,bgcolor=yellow]{text}
This box should have the value that was set for the keys in the definition
instead, it has the same values that were set in the previous call of \verb+\mybox+
\mybox{text}
\end{document}
Edit: I suppressed a superfluous optional argument from my example code (a remanent of the real code I am writing).