I am not a TeX/LaTeX specialist, recently I wrote a package concerning 'problems' and 'solutions' which is intended to be displayed at the end of the document, however it is not restricted to that purposes. In order to achieve that behaviour, amongst other features, I used the xkeyval package, with a lot of key macros and boolean keys also.
I want to provide a better version and get rid of dozens of key macro definition lines and boolean key definitions basically looking alike but just setting some flags, replacing the tedious entering of LaTeX code by some short commands like
\GenerateBoolKey[true]{SomeKeys}{DummyBoolKey}
This should define the boolean key DummyBoolKey belonging to family SomeKeys as if one would have written
\define@boolkey{SomeKeys}{DummyBoolKey}[true]{%
\ifKV@SomeKeys@DummyBoolKey%
%Do something if true%
\else%
%Do something different if false%
\fi%
}%
The xkeyval documentation (version 2.6b) says on page 7 that there is defined a macro \ifKV@fam@key as \newif
Well, I failed in writing the above command and using the \ifKV macro, here is a minimal (non) working example, which fails during compiling with error message
! Too many }'s.
Here's a minimal example
\documentclass{minimal}
\usepackage{xkeyval}
\makeatletter
\providecommand{\GenerateBoolKey}[3][false]{%
\define@boolkey{#2}{#3}[#1]{%
\csname ifKV@#2@#3 \endcsname%
\typeout{true}% % Do something if true
\else%
\typeout{false}% % Do something different if false
\fi%
}% End of \define@boolkey
}% End of \providecommand
\makeatother
% Key Family is called SomeKeys
% Use a fake command for testing purposes
\providecommand{\DummyCommand}[1][false]{%
\setkeys{SomeKeys}{#1}%
% Do something useful inside this command...
}%
\begin{document}
\GenerateBoolKey{SomeKeys}{DummyBoolKey}%
\DummyCommand[DummyBoolKey=true]%
\end{document}
How can I provide the \newif command on the fly with my 'wrapper' code in order to provide the \ifKV boolean test?
\csnameline, which should be\csname ifKV@#2@#3\endcsname(or\@nameuse{ifKV@#2@#3}). Does altering that fix your issue? – Joseph Wright Jan 01 '14 at 11:52