4

Many packages are loaded as prerequisites by other packages that internally use some of this package’s features.

If I need to use a specific package, and this packages is already loaded by another package (or the document class), should I still load that package via loadpackage in the preamble? Or should I simply use its commands without explicitly loading, because it works?

  • 3
    It's better if you do, because if that dependency changes eventually, your document will still compile. And "loading a package again" doesn't load it again. The wrappers around \input executed by \usepackage assure that the package is loaded only once. – Phelype Oleinik Aug 15 '18 at 15:16
  • 2
    I do not think this is a duplicate. The other question only answer the technical part: "Is there a problem with loading the package twice?" While this is the subsequent question: "If it does not make a technical difference, should we do it?" – Marcel Krüger Aug 15 '18 at 20:26
  • Just to be sure, you mean \usepackage and not loadpackage, right? – moewe Aug 16 '18 at 7:22
  • 1
    For packages that you explicitly need in the code you write I think it can make sense to load them even if they are loaded by other packages already. Of course you need to make sure to avoid an option clash. I have a few exceptions to that rule: mathtools always loads amsmath, so if I use the former I do not load the latter. amssymb loads amsfonts, I normally load amssymb and then do not load amsfonts explicitly. So I guess if it is an established and integral part of package X to load another package Y and I'm unlikely to ever use Y alone I do not load Y explicitly. – moewe Aug 16 '18 at 7:29
3

This will create a problem if the same package gets loaded both automatically and manually, with conflicting options. However, you will also have a problem if you do not, and the package later changes so as not to include the other automatically.

In many cases, a package that includes another will be able to pass options through to it. For example, \usepackage[leqno]{mathtools} passes the leqno option to amsmath. You should use that interface if available. If there’s a special option to load a package from another class or package, such as hyperref has for several other packages, there’s probably a reason for that.

Otherwise, if you need particular options for the class another is built on top of, your best bet is to load the base package yourself first. Usually, the second package will not load it again.

If the base package has a command to switch on options after it’s loaded, a well-written package that needs that option set should use that command, and you can do the same. This ought to avoid clashes from loading the package twice with different options.

If you don’t care about the options to the base package, I usually, but not always, still include it. Consider whether it’s a stable part of the interface that one package is built on top of the other or an implementation detail that might change.

For example, mathtools is designed to extend amsmath and unicode-math is designed to extend fontspec, so I would include only the top-level package. On the other hand, if a publisher’s class or stylesheet included a font package, or twocolumn, I’d figure that’s liable to change if the paper is ever reprinted.

  • 3
    \RequirePackage and \usepackage are synonyms when used after \documentclass. – egreg Aug 16 '18 at 9:39
  • @egreg Good thing I never bothered to be consistent about it, then! I guess that means there’s no way around updating the source if the package changes how it loads another package you use. – Davislor Aug 16 '18 at 20:56

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.