TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

xkeyval provides \DeclareOptionX which effectively defines a key like \define@key does but that can be used as a package option.

How can I \DeclareOptionXs that behave like \define@choicekey or \define@boolkey would?

I've done the following, but it isn't ideal.


This isn't great since the error doesn't refer to the key it should refer to, that is, to the key that the user sets.

Is there some obvious way of doing this that I am missing?

share|improve this question
up vote 6 down vote accepted

You do not have to use \DeclareOptionX to set up options using xkeyval. As with any other keyval package for LaTeX, anything which is set up as a key will work as an option for the appropriate family. Thus you can use \define@choicekey or \define@boolkey directly:

\define@choicekey*{fam}{key}{val1,Val2,VAL3}{You chose: #1}

makes key available as a choice key when loading the package or class the code is contained in.

share|improve this answer
Huh. I was fairly sure I tried exactly this and it didn't work! It does work now. I wonder what I was doing wrong... [Also, isn't it \DeclareOptionX not \DefineOptionX?] – Seamus Jul 18 '11 at 14:46

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.