next up previous contents
Next: Delaying code Up: Commands for class and Previous: Commands within option code

   
Moving options around

These two commands are also very useful within the <code> argument of \DeclareOption or \DeclareOption*:


\PassOptionsToPackage {<options-list>} {<package-name>}
\PassOptionsToClass {<options-list>} {<class-name>}

The command \PassOptionsToPackage passes the option names in <options-list> to package <package-name>. This means that it adds the <option-list> to the list of options used by any future \RequirePackage or \usepackage command for package <package-name>. Example:

   \PassOptionsToPackage{foo,bar}{fred}
   \RequirePackage[baz]{fred}
is the same as:
   \RequirePackage[foo,bar,baz]{fred}

Similarly, \PassOptionsToClass may be used in a class file to pass options to another class to be loaded with \LoadClass. The effects and use of these two commands should be contrasted with those of the following two (documented above, in 4.2):

   \LoadClassWithOptions
   \RequirePackageWithOptions
The command\RequirePackageWithOptions is similar to \RequirePackage, but it always loads the required package with exactly the same option list as that being used by the current class or package, rather than with any option explicitly supplied or passed on by \PassOptionsToPackage.

The main purpose of \LoadClassWithOptions is to allow one class to simply build on another, for example:

  \LoadClassWithOptions{article}
This should be compared with the slightly different construction
  \DeclareOption*{\PassOptionsToClass{\CurrentOption}{article}}
  \ProcessOptions\relax
  \LoadClass{article}
As used above, the effects are more or less the same, but the first is a lot less to type; also the \LoadClassWithOptions method runs slightly quicker.

If, however, the class declares options of its own then the two constructions are different. Compare, for example:

  \DeclareOption{landscape}{\@landscapetrue}
  \ProcessOptions\relax
  \LoadClassWithOptions{article}
with:
  \DeclareOption{landscape}{\@landscapetrue}
  \DeclareOption*{\PassOptionsToClass{\CurrentOption}{article}}
  \ProcessOptions\relax
  \LoadClass{article}
In the first example, the article class will be loaded with option landscape precisely when the current class is called with this option. By contrast, in the second example it will never be called with option landscape as in that case article is passed options only by the default option handler, but this handler is not used for landscape because that option is explicitly declared.


next up previous contents
Next: Delaying code Up: Commands for class and Previous: Commands within option code
LaTeX3 Mail Server
1999-07-12