31

There are a few questions regarding the speed of loading packages together, but this question isn't necessarily about that. I'm more interested in any tangible, persistent differences, such as package clashes and the like.


Is there any difference between loading packages one by one,

\usepackage{x}
\usepackage{y}
\usepackage{z}

as opposed to loading them 'all at the same time'?

\usepackage{x,y,z}

I know that some packages behave differently depending on the order in which they are loaded (xcolor is a prime example), but I suspect that as long as the order remains the same (x,y,z, not z,x,y, say), everything should work exactly the same.

7
  • 12
    It's easier to uncomment a package (e.g. for tests) if you load them one-by-one. Many packages have options which can differ: You can't combine \usepackage[utf8]{inputenc} with \usepackage[T1]{fontenc}. Beside this there is no difference. I'm using lists when I'm lazy and want to add a package fast, but one-by-one is in the long run easier to handle. Mar 26, 2013 at 8:50
  • 2
    I second Ulrike. When testing, commenting out a single use package is definitely easier, and the options need to match, but I often load a bunch of packages with no options in a single line, and never noticed a difference. I'd be surprised if there was one.
    – Ingmar
    Mar 26, 2013 at 9:02
  • @UlrikeFischer you raise a very good point with the commenting. Packages with options will always of course need to be loaded separately (save any possibly user-created macro, but that would end badly for debugging), but leaving them one-by-one would be somewhat easier to handle. It should be noted, however, that each package can be on its own line: (\usepackage{x,\ny,\nz}), allowing commenting and (marginally) saving space (which is a bad reason to do anything on this level). Mar 26, 2013 at 11:09
  • 1
    @SeanAllred: With \usepackage{x,\ny,\nz} you can't comment out packgae z easily, you will have to put the last brace on a line on its own. So you will use 4 lines instead of three. I have another reason why I avoid lists: In my editor when I doubleclick on \usepackage it opens the sty. This doesn't work with lists. Mar 26, 2013 at 11:14
  • 1
    @SeanAllred Both answers here work also with lists :-)
    – giordano
    Feb 20, 2014 at 19:50

1 Answer 1

31

The heart of \usepackage (and \documentclass and \RequirePackage and \LoadClass) is \@onefilewithoptions which as its name suggests loads one package or class file and passes it a list of options. \usepackage is a very thin wrapper around that which splits up the comma separated list of package names and calls \@onefilewithoptions on each one. So to TeX there is virtually no difference between the forms. The differences are just to do with ease of editing, whether you want to control groups of packages or control them individually.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .