0

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}?

cgnieder
  • 66,645
user199
  • 37
  • 1
  • 5
  • Try \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. –  Jul 06 '20 at 17:20
  • 3
    \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 06 '20 at 17:34
  • 1
    @Skillmonlikestopanswers.xyz Can you turn your comment into a response? – AndréC Jul 06 '20 at 18:14
  • 2
  • it should be noted that MikTeX maintains its own database of sty files and will not recognize a sty tile until it is added to the FNDB. – John Kormylo Jul 07 '20 at 12:30

1 Answers1

1

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).

Skillmon
  • 60,462
  • 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 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, \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 07 '20 at 06:52