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}?
1 Answers
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).
- 60,462
-
note that by design packages may use
\usepackageand\ProvidesPackageis optional, so the intention is that it is easier to use\usepackage(as the catcode of@is managed automatically) – David Carlisle Jul 06 '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 07 '20 at 00:15
-
@user199 no,
\RequirePackagewill also load packages. The difference is that\RequirePackagecan be used before a\documentclass, while\usepackagecan't, else the two do the same, that is again a conceptual difference. – Skillmon Jul 07 '20 at 06:52
\input{tikz.sty}\begin{document}Hello!\end{document}. A lot of funny errors appear. As far as I know,\usepackageor actually\RequirePackagedoes a lot of processing before loading a.styfile and a lot of macro/catcode juggling too. It also cares about versioning, package options...\inputjust load a file and smiles a "Good luck" to you. – Jul 06 '20 at 17:20\inputis really easy to manage, you just do whatever you would've done in your preamble in that file and use\input{foo}. A\usepackageshouldn't use\usepackagebut\RequirePackagefor any other packages it needs, and it should report back who it is with\ProvidesPackage. A\usepackagewill automatically have\makeatletterat its start and\makeatotherat its end. Else the two are roughly the same. – Skillmon Jul 06 '20 at 17:34