15

\ProcessOptions and \ProcessKeyvalOptions

Which comes first? Does it matter?

\ProcessOptions\relax or \ProcessOptions*

What's the difference? Apparently for keyval there is only the starred version. Which should I use? I looked at the docs and they were not extremely helpful.


I'm creating my own class based on article. I'm using kvoptions for the easy creation of boolean options (\DeclareBoolOption and \DeclareComplementaryOption).

2 Answers 2

17

Without package kvoptions

An option is defined by

\DeclareOption{<option>}{<code>}

The star form defines the behavior for unknown options:

\DeclareOption*{<code>}

Options are processed by

\ProcessOptions\relax

that processes the options in the order of declaration in the package file (seldom useful) or

\ProcessOptions*

that process the options in calling order (usually recommended).

With package kvoptions

With package kvoptions the replacement for \ProcessOptions* is \ProcessKeyvalOptions. Neither \ProcessOptions nor \ProcessOptions* should be used together with \ProcessKeyvalOptions.

Package options are now interpreted as key value options. They can be defined with \define@key of package keyval. But package kvoptions provides some shortcuts: \DeclareBoolOption, \DeclareStringOption, ...

\DeclareOption is replaced by \DeclareVoidOption and \DeclareOption* is replaced by \DeclareDefaultOption.

For a more complete example, see section "3 Example" of package kvoptions.

2
  • I'd still be curious why almost all examples add \relax after \ProcessOptions, even though this is supposed to be a no-op? Jul 3, 2015 at 18:26
  • 2
    @FlorianEchtler The syntax of \ProcessOptions knows an optional star. The \relax acts as stopper that the command is finished and no optional star is following. Jul 3, 2015 at 18:32
5

Testing this on examples, the order of \ProcessOptions and \ProcessKeyvalOptions does not seem to matter, unless of course the code of one set options directly affects that of the other.

For \ProcessOptions\relax vs. \ProcessOptions*, clsguide explains that the order the options is processed in is different:

\ProcessOptions*: This is like \ProcessOptions but it executes the options in the order specified in the calling commands, rather than in the order of declaration in the class or package. For a package this means that the global options are processed first.

As to which you should use, if you are writing the class completely from scratch, I would advise that you use just one style; either use kvoptions for all of your own options or use exclusively the classical style. If your are building your class on top of an existing one, then it depends on the details: if you are only adding new options then \LoadClassWithOptions may well be sufficient to deal with the old options of that class and you can stick to the kvoptions style for your own additions.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .