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

I want to add an option that sets a flag to a document class. That is, I want to be able to type


and get one type of behavior, and type


to get a different type of behavior. I'm thinking I should do it like this in the class file:


Will this work? Could this cause a problem if a package I use in the document also has a \newif\if@foo in it?

share|improve this question
up vote 5 down vote accepted

The LaTeX2e for class and package writers contains some examples of this within section 3.3 Declaring options (p 12). It pertains to the declaration of package and class options. The following snippets are taken from there:

An option is declared as follows:


For example, the dvips option (slightly simplied) to the graphics package is implemented as:


This means that when an author writes \usepackage[dvips]{graphics}, the file dvips.def is loaded. As another example, the a4paper option is declared in the article class to set the \paperheight and \paperwidth lengths:


Sometimes a user will request an option which the class or package has not explicitly declared. By default this will produce a warning (for classes) or error (for packages); this behaviour can be altered as follows:


For example, to make the package fred produce a warning rather than an error for unknown options, you could specify:

  \PackageWarning{fred}{Unknown option `\CurrentOption'}%

Then, if an author writes \usepackage[foo]{fred}, they will get a warning

Package fred Warning: Unknown option `foo'.

Subsequent sections contain some examples of classes constructed from others, which would be good to review.

Using options that are common to other packages could be problematic. However, since you have a choice over the boolean (or macros) associated with the option, choose it to be unique to your class. Authors typically include some form of package reference in the macros. For example, the tufte-latex bundle prepends most commands and booleans with @tufte to avoid possible clashes.

share|improve this answer

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.