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.

Sean Allred
  • 27,421
  • 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. – Ulrike Fischer Mar 26 '13 at 08: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 '13 at 09: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). – Sean Allred Mar 26 '13 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. – Ulrike Fischer Mar 26 '13 at 11:14
  • @UlrikeFischer now that is a nice editor feature. Could I ask which you are using? I'll have to write something for Emacs if it doesn't exist already. I'd agree that hanging braces are ugly, so it may be best to just include them manually as you said. With a good editor, the difference in effort is nominal. – Sean Allred Mar 26 '13 at 11:22
  • @SeanAllred I'm using winedt. Its default behaviour is to open the documentation on a doubleclick, but I changed it (I need to open style files frequently). Now it runs the (miktex) command findtexmf -start xxx.sty – Ulrike Fischer Mar 26 '13 at 11:49
  • 1
    @SeanAllred Both answers here work also with lists :-) – giordano Feb 20 '14 at 19:50

1 Answers1

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.

David Carlisle
  • 757,742