4

I want to process my class options so as to create a (potentially long) options list for package(s) I'm loading, e.g.

% set default package options here somehow
\DeclareOption{myvariant}{
    % set a bunch of alternative options overriding the default
}

\RequirePackage[some kind of magic should go here]{mypackage}

Specifically, I thought maybe I should be using PassOptionsToClass, but then - how do I prevent the default action?

Right now I'm doing something else, and kind of ugly, which relies on my specific package of interest (geometry) allowing doing everything with a command rather than a package option:

\newcommand{\iitcs@geometry{\geometry{key=val,key2=val2}}
\DeclareOption{myopt}{
 \renewcommand{\iitcs@geometry{\geometry{key=val3,key3=val4}}
}
%...
\RequirePackage{geometry}
\iitcs@geometry

(edit) I'll emphasize that I'd like a solution for the case I have no choice but to provide the right package options, with no flexibility like with `geometry'.

2

You can use \geometry and options therein multiple times. So for this application I suggest something like

\DeclareOption{myopt}{%
  \AtEndOfPackage{\geometry{paperwidth=3cm,paperheight=9cm}}}

\ProcessOptions\relax
\RequirePackage{geometry}
\geometry{paperwidth=12cm,paperheight=12cm} % default

In more general cases it may be more difficult, because options are executed in the order they are listed in the package, when it calls \ProcessOptions.

So if packageB.sty declares x and nox in this order (later using \ProcessOptions, not \ProcessOptions*) and you say in packageA.sty

\DeclareOption{x}{\PassOptionsToPackage{x}{packageB}}
\DeclareOption{nox}{\PassOptionsToPackage{nox}{packageB}}

\ExecuteOptions{nox}
\ProcessOptions\relax
\RequirePackage{packageB}

then nox will be executed last by packageB no matter if you call packageA with the x option.

So a more precise answer depends on "real world" situations.

  • Umm, won't the \AtEndOfPackage be executed before the \geometry command below? Or maybe I'm missing its semantics. Also, and more importantly, I'm interested in a general approach, so let's assume I have to load the package with the proper options rather than a command later on. Have edited my question to clarify that. – einpoklum Oct 7 '11 at 16:20
  • 1
    No, \AtEndOfPackage code is executed when LaTeX ends reading the .sty file, just prior returning to read the calling file. \ProcessOptions will simply set the token list for \AtEndOfPackage. – egreg Oct 7 '11 at 16:25
  • How will it know which sty to exacute after? Also, in your second example, won't nox be executed first rather than last, due to the \ExecuteOption{nox}? Finally, I'm more interested in one-option-to-many rather than one-option-to-one. – einpoklum Oct 7 '11 at 19:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.