I'm trying to create a keycommand with optional arguments, but I can't get it to work. I looked at Comparing an argument to a string when argument is a result of a command with etoolbox and although the example there works, I can't get it to work for use with keycommand, nor can I get ifcommandkey
to work as expected. I recently upgraded from Tex Live 2009 to Tex Live 2011 and in 2009, ifcommandkey
was working.
In Tex Live 2011, how do I check whether a key was given or not?
Below is an example where I try different things. None have the desired effect; in the third call, I want the result to be something like "No spam. No eggs. No paper. No Salt", but I get "Has spam" in every run. Why?
\documentclass{minimal}
\usepackage{keycommand}
\usepackage{etoolbox}
\begin{document}
\newcommand\myifstrempty{\expandafter\ifstrempty\expandafter}
\newkeycommand{\testkc}[spam,eggs,paper,salt][][0]{
\ifcommandkey{spam}{Spam: ``\commandkey{spam}''}{No spam}.
\ifcommandkey{eggs}{Eggs: ``\commandkey{eggs}''}{No eggs}.
\ifcommandkey{paper}{Paper: ``\commandkey{paper}''}{No paper}.
\ifcommandkey{salt}{Salt: ``\commandkey{salt}''}{No Salt}.
\ifcommandkey\expandafter{salt}{Salt: ``\commandkey{salt}''}{No Salt}.
\myifstrempty{\commandkey{spam}}{Not has spam}{Has spam}
\expandafter\ifstrempty{\expandafter{\commandkey{spam}}}{Not has spam}{Has spam}
}
\testkc[spam=bad, eggs=good, salt=horrid]
\testkc[paper=gold]
\testkc
\newcommand{\aORb}[1]{%
\expandafter\ifstrequal\expandafter{#1}{a}{"a" was given}{not a}, %
\expandafter\ifstrequal\expandafter{#1}{b}{"b" was given}{not b}%
}
\aORb{a}
\aORb{b}
\end{document}
The result looks like this: