next up previous contents
Next: Safe file commands Up: Commands for class and Previous: Delaying code   Contents


Option processing


\ProcessOptions

This command executes the <code> for each selected option.

We shall first describe how \ProcessOptions works in a package file, and then how this differs in a class file.

To understand in detail what \ProcessOptions does in a package file, you have to know the difference between local and global options.

For example, suppose that a document begins:
   \documentclass[german,twocolumn]{article}
   \usepackage{gerhardt}
whilst package gerhardt calls package fred with:
   \PassOptionsToPackage{german,dvips,a4paper}{fred}
   \RequirePackage[errorshow]{fred}
then:

When \ProcessOptions is called, the following happen.

Throughout this process, the system ensures that the code declared for an option is executed at most once.

Returning to the example, if fred.sty contains:

   \DeclareOption{dvips}{\typeout{DVIPS}}
   \DeclareOption{german}{\typeout{GERMAN}}
   \DeclareOption{french}{\typeout{FRENCH}}
   \DeclareOption*{\PackageWarning{fred}{Unknown `\CurrentOption'}}
   \ProcessOptions\relax
then the result of processing this document will be:
   DVIPS
   GERMAN
   Package fred Warning: Unknown `a4paper'.
   Package fred Warning: Unknown `errorshow'.
Note the following:

In a class file, \ProcessOptions works in the same way, except that: all options are local; and the default value for \DeclareOption* is \OptionNotUsed rather than an error.

Note that, because \ProcessOptions has a *-form, it is wise to follow the non-star form with \relax, as in the previous examples, since this prevents unnecessary look ahead and possibly misleading error messages being issued.


\ProcessOptions* \@options

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.

The \@options command from LATEX 2.09 has been made equivalent to this in order to ease the task of updating old document styles to LATEX2e class files.


\ExecuteOptions {<options-list>}

For each option in the <options-list>, in order, this command simply executes the command \ds@<option> (if this command is not defined, then that option is silently ignored).

It can be used to provide a `default option list' just before \ProcessOptions. For example, suppose that in a class file you want to set up the default design to be: two-sided printing; 11pt fonts; in two columns. Then it could specify:

   \ExecuteOptions{11pt,twoside,twocolumn}


next up previous contents
Next: Safe file commands Up: Commands for class and Previous: Delaying code   Contents
Johannes L. Braams 2003-05-18