12.14.6 \DeclareOption

Synopsis:

\DeclareOption{option}{code}
\DeclareOption*{option}{code}

Define an option a user can include in their \documentclass command. For example, a class smcmemo could have an option logo allowing users to put the institutional logo on the first page. The document would start with \documentclass[logo]{smcmemo}. To enable this, the class file must contain \DeclareOption{logo}{code} (and later, \ProcessOptions).

If you request an option that has not been declared, by default this will produce a warning like Unused global option(s): [badoption]. This can be changed by using \DeclareOption*{code}, which executes code for any unknown option.

For example, many classes extend an existing class, using code such as \LoadClass{article} (see \LoadClass). In this case, it makes sense to pass any otherwise-unknown options to the underlying class, like this:

\DeclareOption*{%
  \PassOptionsToClass{\CurrentOption}{article}%
}

As another example, our class smcmemo might allow users to keep lists of memo recipients in external files, so the user could invoke \documentclass[math]{smcmemo} and it will read the file math.memo. This code inputs the file if it exists, while if it doesn’t, the option is passed to the article class:

\DeclareOption*{\InputIfFileExists{\CurrentOption.memo}
  {}{%
  \PassOptionsToClass{\CurrentOption}{article}}}

Unofficial LaTeX2e reference manual