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

In the listings package, they note that "a global \documentclass-option draft is recognized, so you don’t need to repeat it as a package option"

I tried looking into its source to see how it accomplishes this, but I wasn't able to find the magic bit. How does one detect the global \documentclass options from within an independent style/package?

share|improve this question
up vote 12 down vote accepted

This is done automatically for all packages by LaTeX's \ProcessOptions. It checks if any of the global class options are defined by the package and executes the ones which are. You do not need to do anything special in your package.

This is explained in clsguide, page 18. The source code which implements it can be seen in source2e, page 370.

share|improve this answer
Oh, wow, that's very cool. Thanks! – Matt B. Feb 10 '11 at 22:26

I think the story is more subtle than Martin has had the time to explain. It is the starred form of \ProcessOptions, when issued in packages, that copies and processes global options (submitted via \documentclass) in the order in which they were submitted via \documentclass. The unstarred variant of \ProcessOptions doesn’t copy global options from \documentclass (except when issued in a class file – where, in the LaTeX2e kernel approach, \@curroptions come from \@classoptionslist) and processes the options in the order in which they were declared.

share|improve this answer
Thanks Ahmed for explaining it further. I didn't do it in that detail on purpose, but pointed him to the clsguide where this details are explained. IMO he has to read that document anyway. – Martin Scharrer Feb 15 '11 at 18:11

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.