4

What is the best practice for separating the preamble to a dedicated file?

I've seen two variants:

  1. A package: preamble.sty and \usepackage{preamble}
  2. A .tex file: preamble.tex and \input{preamble}

Which one is to be preferred?

  • To be honest, the one that you like best :-) Either way is ok and good practice, though i prefer to write my own packages (with options and stuff). Having said that, if you want to implement any options, write a package :-) – Johannes_B Sep 2 '14 at 20:06
  • I think the package version is logically more consistent, although in the absence of options the definition of \usepackage is more or less \input{#1.sty} so it doesn't make any difference in practice. – David Carlisle Sep 2 '14 at 20:12
  • Definitely the separate .sty file option: In a style file that's loaded with a \usepackage statement, the @ ("at") character is immediately of category "letter", which makes all those \makeatletter and \makeatother statements unnecessary. – Mico Sep 2 '14 at 20:21
5

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.

  • Is it ok to place .sty files in the local folder next to the .tex document (if it contains really document-specific code) or should .sty files always be in the appropriate TEXMFHOME subfolder? – Tim Hoffmann Sep 17 '14 at 20:30
  • @TimHoffmann: either are perfectly acceptable. But if you are putting auxiliary code in a package you will probably want to use it more than once. That suggests a central location. – Matthew Leingang Sep 18 '14 at 0:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.