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?
Asked
Active
Viewed 2,450 times
35
jak123
- 4,252
- 5
- 26
- 49
1 Answers
42
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
\documentclassline - only loads
.styfiles - checks that it is only called after
\documentclassand before\begin{document} - ensures catcodes are correct for LaTeX package syntax (
\makeatletter/\makeatother) even in the presence ofexpl3catcode 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.
Will Robertson
- 73,872
\usepackageonly works on.sty. – Werner Nov 10 '15 at 07:16\ExplSyntaxOn \usepackage{whatever} some expl3-codeworks fine. – Ulrike Fischer Nov 10 '15 at 09:53\includein the preamble. – barbara beeton Nov 10 '15 at 17:38