I'm trying the use the xkeyval package to define a very simple command using keys. However, I'm utterly confused by its behavior, and the package documentation is not exactly helpful either. Here's a MWE with what I wanted to achieve (expected) and what I actually got. Why is this happening and what do I need to do to get the result I'm after? I've also consulted: How to create a command with key values? and: A package template using xkeyval? without any luck
\documentclass{article}
\usepackage{xkeyval}
\makeatletter
\define@key[]{fam}{foo}[XX]{#1}
\newcommand{\mycommand}[1][]{%
\begingroup
\setkeys[]{fam}{#1}
``Using the macro: \fam@foo ''
\endgroup
}
\makeatother
\begin{document}
% Example where I hoped to get the default value (XX)
\mycommand % Expected: "Using the macro XX" - Got: "Using the macro"
% Example where I hoped to override the default value
\mycommand[foo=YY] % Expected: "Using the macro YY" - Got: YY "Using the macro"
\end{document}


xkeyval(Sec 3.1) not working? And what doestokseven mean? Is it just arbitrary? And why do I have to specify even more\def's? I thought that was supposed to be handled by the\define@keycommand? And why do I have to specify default values with an extra call to\setkeyswhen you are supposed to supply that in\define@key? – hakoja Apr 25 '14 at 11:04toksis just arbitrary; use\define@cmdkeyif you want a “uniform” name. The default value is used when the key is called without a value. – egreg Apr 25 '14 at 11:11cmdkeyexample appeared cleaner, how do I specify functions of the input with it? I.e. if I want to take in the value offoo(#1) and make it bold (say). And what do you mean by called? I'm sorry for being so dense, but it seems that there is something really fundamental I'm not getting here... – hakoja Apr 25 '14 at 11:16Using the macro: \textbf{\cmdfam@foo}with\define@cmdkey; or\define@key[]{fam}{foo}{\def\cmdfam@foo{\textbf{#1}}}and thenUsing the macro \cmdfam@foo– egreg Apr 25 '14 at 11:19