# Disabling the draft option in a package

Within a package I'm making, I want ignore the default draft behavior and write my own. I have tried:

\DeclareOption{draft}{
MYCOMMANDS
...
\OptionNotUsed
}
\ProcessOptions


If draft is used, my commands are run, but all other features of the draft option (e.g. disabling images and hyperlinks) are still enabled.

I want to disable the draft option from the document class level from my package and prevent it from being passed to any packages. Is this possible to do from my package?

-
So you want to patch the code of other packages? –  Martin Schröder Oct 31 '11 at 18:26
I would like to disable the draft option at the document class level and prevent it from being passed to any other packages. –  Scribblemacher Oct 31 '11 at 18:29
You can't: if the draft option is specified with \documentclass it will be passed to all packages that know such option. Conversely, if it's specified only to your package, it will not be passed to other packages. –  egreg Oct 31 '11 at 18:34
@David: This would only be possible (if it's possible at all) at class level. But you probably need to patch the option handling of LaTeX to make it work. –  Martin Schröder Oct 31 '11 at 21:54
Is there any reason why you want to specify the draft option at the class level and not for your package only? I think this would be the easiest option without any fiddling around with LaTeX internals. –  Elmar Zander Nov 1 '11 at 22:19

If the draft option is specified with \documentclass it will be passed to all packages that know such option. Conversely, if it's specified only along your package, it will not be passed to other packages.

\documentclass[<global options>]{<class>}
\usepackage[<local options>]{<package>}


The options in the <global options> list will be tried by the class and any package loaded in the preamble, but won't show errors or warnings if not known by a package.

The options in the <local options> list will be passed to <package> (which might pass them to other packages loaded after it, via \PassOptionsToPackage).

So with

\documentclass[draft,...]{article}


all packages will try to honor the draft option, and nothing can be done about this with code in some package.

However, if your package is loaded immediately after the class and you know how to modify the global options list, then it's possible to do what you wish. Here's the "secret" code:

\def\@clearglobaloption#1{%
\def\@tempa{#1}%
\def\@tempb{\@gobble}%
\@for\next:=\@classoptionslist\do
{\ifx\next\@tempa
\message{Cleared  option \next\space from global list}%
\else
\edef\@tempb{\@tempb,\next}%
\fi}%
\let\@classoptionslist\@tempb
\expandafter\ifx\@tempb\@gobble
\let\@classoptionslist\@empty
\fi}

\@clearglobaloption{draft}


I've made it generic: any option can be cleared in this way. Beware that some classes such as beamer do different things with the option list and so the trick might not work with them.

-