18

I understand that these two commands do the same thing:

\usepackage[letterpaper, landscape, margin=2in]{geometry}

and

\usepackage{geometry}
\geometry{legalpaper, landscape, margin=2in}

Is there any reason why one would be preferable over the other? I mean to ask this question not just with reference to the geometry package, but in general if possible.

  • 11
    If a class you're using already loads geometry the second way is mandatory, otherwise there's no difference. – egreg Jan 21 '16 at 20:37
  • 10
    Sometimes people load multiple packages in one call, e.g. \usepackage{geometry, fancyhdr}; in this case, the second way would also be mandatory. – Arun Debray Jan 21 '16 at 20:38
  • 1
    Please post that as an answer. Both really. And thank you, this was driving me nuts not knowing. – A Feldman Jan 21 '16 at 20:38
  • 2
    Sometimes it matters. Some packages are such that certain options can only be given in particular ways e.g. at load time \usepackage[<option>]{<package>} or they don't provide an equivalent of \geometry{}. Also, in some cases, you might want to set certain options after \begin{document} when you can no longer use \usepackage. (Other times, options can only be set in the preamble, of course.) I guess: 'It depends. Oh, and it is complicated.' is probably closest to the truth. – cfr Jan 22 '16 at 2:38
  • 2
    Related: Loading Packages Together versus Separately – Sean Allred Jan 23 '16 at 23:00
4

This is possible for some packages, but not necessarily all options can be set in either way.

Notable packages that allow for separate commands are

  • geometry and \geometry
  • hyperref and \hypersetup
  • microtype and \microtypesetup
  • siunitx and \sisetup
  • caption and captionsetup

(the list is not exhaustive).

There are some differences; \geometry can only be given in the preamble, whereas the setup commands for the other packages can go essentially anywhere and respect grouping.

Consult the documentation for each package to see what options (maybe none) doesn't make sense in \usepackage or in the setup command.

Some peculiarity: if you want different settings for figure and table captions, you must use \captionsetup. For caption I actually would recommend using the command form anyway, rather than a long list of package options.

There is another relevant aspect. Suppose you want to set the text width using a macro that you want to set in a separate place, maybe for doing experiments. An input such as

\usepackage[textwidth=\mytextwidth]{geometry}

\newcommand{\mytextwidth}{13cm}

\begin{document}

wouldn't work even if we know that geometry does its settings at begin document, because the optional argument to \usepackage is fully expanded at calling time. To the contrary,

\usepackage{geometry}

\geometry{textwidth=\mytextwidth}

\newcommand{\mytextwidth}{13cm}

\begin{document}

would work, because options in that case are not fully expanded at calling time but only when the setting is actually performed

Such behavior will probably change in LaTeX3, which will use newer option processing functions also in \documentclass and \usepackage).

So what method you use is mostly a personal choice. However there are cases where the command way is mandatory. If the document class you use already loads, say, geometry, you can't call \usepackage[<options>]{geometry} with a different set of options; the command form is free of this problem . The same for the other packages, but note that some options to hyperref cannot be undone with \hypersetup once they have been set in the package options.

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.