I have some commands whose named arguments are processed by pgfkeys
\dog[breed=Labrador, name=Fido]
\human[name=John, car owned=Porsche]
How can I arrange that
\dog[breed=Labrador, car owned=Rover]
gives the error message Invalid key 'car owned', and
\dog[name=Fido]
gives the error message Missing required key 'breed'?
Here is a MWE to use as a starting point.
\documentclass{article}
\usepackage{pgfkeys}
\makeatletter
\pgfkeys{/wickerson/.cd,
breed/.store in = {\wickerson@breed},
name/.store in = {\wickerson@name},
car owned/.store in = {\wickerson@carowned}
}
\newcommand*\dog[1][]{%
\pgfkeys{/wickerson/.cd, name=noName, breed=noBreed, #1}
Dog is a {\wickerson@breed} and is called {\wickerson@name}.\par
}
\newcommand*\human[1][]{%
\pgfkeys{/wickerson/.cd, name=noName, car owned=noCar, #1}
Human is called {\wickerson@name} and owns a {\wickerson@carowned}.\par
}
\makeatother
\begin{document}
\dog[breed=Labrador, name=Fido] % GOOD
\human[name=John, car owned=Porsche] % GOOD
\dog[breed=Labrador, car owned=Rover] % BAD (irrelevant key given)
\dog[name=Fido] % BAD (required key missing)
\end{document}
.store in, you can simply initialize/wickerson/breed/.initial = {}, and then every use of/wickerson/breed = whateverwill set the value of this key towhatever, which can be retrieved (expandably) with\pgfkeysvalueof{/wickerson/breed}. This way you don't reinvent the namespace wheel thatpgfkeysprovides. – Ryan Reich May 31 '13 at 17:34pgfkeysbut need to learn so am using this to start. While there might be "official"pgfkeysways to do this, it seems that if you declare separatedogkeysandhumankeys, then this handles the first case:\dog[breed=Labrador, car owned=Rover]results in an error. For the second problem you could just test ifbreedis empty. – Peter Grill May 31 '13 at 22:37