Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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
add comment

2 Answers

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
1  
Oh, wow, that's very cool. Thanks! –  Matt B. Feb 10 '11 at 22:26
add comment

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
1  
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
add comment

Your Answer

 
discard

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.