Recently, I found a question on how to use preamble kind of thing that we can use for storing the name of the style files and personal macros. I generally use \input{preamble.tex}
. What is the pros and cons if I use \usepackage{preamble}
?
The \input
macro essentially is the same as putting the contents of the input file where the macro is used. So to use it is really easy, you can use anything you would use in your preamble in that file and input it.
Creating a file to be input by \usepackage
is a bit more complicated (but not that much). First a file input with \usepackage
should report which file that is using \ProvidesPackage
(optionally with specifying a date, version, and purpose). Also, a package shouldn't include additional packages with \usepackage
, but instead use \RequirePackage
. Inside a package you don't have to use \makeatletter
at the start and \makeatother
at its end.
Other than that, the two are roughly the same and there isn't too much difference (from a technical viewpoint, conceptually there is a difference, see the link Alan Munn provided).
-
note that by design packages may use
\usepackage
and\ProvidesPackage
is optional, so the intention is that it is easier to use\usepackage
(as the catcode of@
is managed automatically) – David Carlisle Jul 6 '20 at 21:49 -
So, it appears that \usepackage ignores the packages that are not required for a certain case, however \input always loads the all packages listed in the preamble.tex. Am I correct? – user199 Jul 7 '20 at 0:15
-
@user199 no,
\RequirePackage
will also load packages. The difference is that\RequirePackage
can be used before a\documentclass
, while\usepackage
can't, else the two do the same, that is again a conceptual difference. – Skillmon Jul 7 '20 at 6:52
\input{tikz.sty}\begin{document}Hello!\end{document}
. A lot of funny errors appear. As far as I know,\usepackage
or actually\RequirePackage
does a lot of processing before loading a.sty
file and a lot of macro/catcode juggling too. It also cares about versioning, package options...\input
just load a file and smiles a "Good luck" to you. – user193767 Jul 6 '20 at 17:20\input
is really easy to manage, you just do whatever you would've done in your preamble in that file and use\input{foo}
. A\usepackage
shouldn't use\usepackage
but\RequirePackage
for any other packages it needs, and it should report back who it is with\ProvidesPackage
. A\usepackage
will automatically have\makeatletter
at its start and\makeatother
at its end. Else the two are roughly the same. – Skillmon Jul 6 '20 at 17:34