[Tex/LaTex] Pass package options at loading time or later

package-options

(This isn't really about a LaTeX issue but more about personal taste and arguments herefore.)

Do you prefer to pass package options at loading time with, say,

\usepackage[something]{geoemtry}
\usepackage[something]{siunitx}

or later in the preamble with

\geometry{something}
\sisetup{something}

? I'm asking because I can't make a decision about what to do.

An argument for doing it at loading time is than not all packages have other ways of selecting package options than at loading time (see, e.g., Options for “footmisc'' package) and then the first choice makes the preamble more consistent.

Best Answer

This mostly depends on what the options do. Let's look at some cases.

Package babel

The options are basically the languages used. The main language is the last specified option (or the one given with main=<language> from babel 3.9). While the language list could in principle be specified later in the preamble, there no point in being able to say \babelsetup{<languages>}, because this must necessarily go in the preamble, since they act “globally” on the document.

Package geometry

One can use \usepackage[<options>]{geometry} and zero or more \geometry{<options>} commands. This is useful because one can add options when they become necessary; if an option is specified more than once, the last specification wins. However, I don't recommend using more than one \geometry command, because this makes the preamble difficult to manage. The most recent versions of geometry have a \newgeometry command that's similar to \geometry, which is not really necessary.

Package footmisc

The options redefine internal commands. The redefinitions are based on the specified options and are performed when the package code is processed. It would be almost impossible to have a \footmiscsetup command.

Package hyperref

One can specify package options or give one or more \hypersetup commands. This works because the relative code is executed at begin document; some of them can also be changed mid document.

Package caption

All options can be changed mid document, so a \captionsetup command is welcome in order to locally customize the captions. One can give "global” options as package options and then use \captionsetup at the relevant spots.

Package siunitx

The same considerations as for caption hold.

Package imakeidx

One can specify global options (say texindy for using Xindy as the sorting engine), but one can override the global options for a specific index, by giving options to \makeindex. An \imakeidxsetup command might make sense, to give options that are implicitly used by the subsequently defined indices. But cases where more than three or four indices are rare and defining a complex infrastructure for a few use cases would only make the code more difficult to maintain.

Final words

If options to a package are inherently global, there's no point in providing a \...setup command. Options that process different package code can only be given as package options, or code maintenance becomes really difficult and conflict prone, because the only way to manage the \...setup code is to overload \AtBeginDocument, which only slows starting up document processing.

If options can be set locally in the document, a \...setup command is what's needed.