What is the best practice for separating the preamble to a dedicated file?
I've seen two variants:
- A package: preamble.sty and
\usepackage{preamble} - A .tex file: preamble.tex and
\input{preamble}
Which one is to be preferred?
What is the best practice for separating the preamble to a dedicated file?
I've seen two variants:
\usepackage{preamble}\input{preamble}Which one is to be preferred?
My opinion mostly:
Preamble commands that add functionality to the document (e.g., defining macros) belong in a package (.sty file).
Preamble commands that define the look of the document (paper geometry, page headers, font selections), belong in a custom document class (.cls file). You can use high-level LaTeX commands to derive a custom class from a standard-issue class, and pass options to it.
See Style/class tutorials for examples of both.
Update 2022-03-27 User @tush asked for a reference. The closest I could find is LaTex2e for class and package writers by the LaTeX project team. They write:
2.3 Is it a class or a package?
The first thing to do when you want to put some new LaTeX commands in a file is to decide whether it should be a document class or a package. The rule of thumb is:
If the commands could be used with any document class, then make them a package; and if not, then make them a class.
There are two major types of class: those like
article,reportorletter, which are free-standing; and those which are extensions or variations of other classes—for example, theprocdocument class, which is built on thearticledocument class. Thus, a company might have a localownletclass for printing letters with their own headed note-paper. Such a class would build on top of the existingletterclass but it cannot be used with any other document class, so we haveownlet.clsrather thanownlet.sty.The
graphicspackage, in contrast, provides commands for including images into a LaTeX document. Since these commands can be used with any document class, we havegraphics.styrather thangraphics.cls.
Commands that set the document's look like paper geometry, page headers, font selections, seem closer to the ownlet case than to the graphics case. That's why I think they belong in a class rather than a package.
.cls file?
– tush
Mar 24 '22 at 12:45
\usepackageis more or less\input{#1.sty}so it doesn't make any difference in practice. – David Carlisle Sep 02 '14 at 20:12\usepackagestatement, the@("at") character is immediately of category "letter", which makes all those\makeatletterand\makeatotherstatements unnecessary. – Mico Sep 02 '14 at 20:21