21

Is it possible to load some package from a .sty file only if some option is selected?

(Naive approach \DeclareOption{something}{\RequirePackage{something}} doesn't work.)

lockstep
  • 250,273
Grigory M
  • 4,984
  • 4
  • 39
  • 37

1 Answers1

24

Use \if... switches, I do something like

\newif\if@loadsomething\@loadsomethingfalse
\DeclareOption{something}{\@loadsomethingtrue}
...
\ProcessOptions\relax

\if@loadsomething
  \RequirePackage{something}
\fi

I haven't myself completely figured out how the "options" mechanism works, or why your example doesn't, but I guess it has to do with the precise moment when the options are being executed and the state of TeX's context when that happens.

Juan A. Navarro
  • 62,139
  • 32
  • 140
  • 169