29

What does \usepackage do that is different than \input or \include? Does it simply import the commands in the package file to the current document or is it more complicated?

39

More complicated. \usepackage:

  • can check that the package is newer than a specified version date
  • can have options specified for loading the package
  • can inherit options from the \documentclass line
  • only loads .sty files
  • checks that it is only called after \documentclass and before \begin{document}
  • ensures catcodes are correct for LaTeX package syntax (\makeatletter/\makeatother) even in the presence of expl3 catcode environments
  • performs assorted housekeeping, including adding the package details to the results given by \listfiles
  • doesn't load the definitions of a package more than once
  • checks that if a package is loaded more than once, the same options have been requested

Whereas \input simply starts reading the file requested as if it had literally been pasted at that point in the document. It can be used to input document text and/or preamble code, for example.

\include is only suitable for inserting document text after \begin{document}, and in fact is geared quite specifically around being used for chapters or parts of document. It performs addition actions over \input, such as starting a new page (with \clearpage) and changing the .aux file so that \includeonly produces correct results.

  • 1
    ...also, \usepackage only works on .sty. – Werner Nov 10 '15 at 7:16
  • 3
    also make sure that nothing bad happens if you load the same package twice – daleif Nov 10 '15 at 8:02
  • thx :) had to rush off before being complete… – Will Robertson Nov 10 '15 at 8:02
  • And (in new latex versions) disables active expl3-catcodes and reenables them after the package. So \ExplSyntaxOn \usepackage{whatever} some expl3-code works fine. – Ulrike Fischer Nov 10 '15 at 9:53
  • although i suppose it's possible, it would be very odd to use\include in the preamble. – barbara beeton Nov 10 '15 at 17:38

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.