Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

This TeX.SE thread is a good resource for how to make your usual preamble into a package or document class. I would like to know why I should do that. What are the pros and cons of doing so, as compared with just leaving the preamble in every document you write?

Here's how I see it:

Pros of leaving the preamble in every document

  • Easy to edit it if necessary
  • If I forget how I defined something, I can just scroll up and look
  • Only one file to keep track of per document
  • If I send my document to someone else, they can compile it immediately, without any fussing over where to put my package/class file
  • Progressive changes to my preamble don't cause an accumulation of files that can never be moved lest all old documents break

Cons of leaving the preamble in every document

  • Takes up more room on the computer
  • You have to scroll down a bit more before getting to start writing in your document

(the pros and cons of making a package or class being exactly dual)

To me, this comes down heavily against making a package or class. Am I missing considerations that would tip the balance the other way? Perhaps for certain documents, one choice is better than the other?

share|improve this question
6  
You're forgetting an argument against having a "universal preamble" in a personal package: it will grow larger with packages and macros that may have nothing to do with a particular document. Maintaining it becomes difficult with time. In a paper I had to put in shape for publication, I found 250 preamble lines (taken probably from a "universal preamble"); after reviewing them, less than 30 lines survived, with the packages and macros actually used in the document. –  egreg May 26 '13 at 22:40
5  
I do a mixture of both. For fonts, e.g., I have a custom fonts file where I load, thanks to the ifluatex package, a basic font setup for pdfTeX and one for LuaTeX. I do custom packages for things like law citation definitions (which are used across several articles/projects I'm working on). However, I like to load things like hyperref in each file separately; things like multicol might be in one document, but not in others, so I load those packages individually on a case-by-case basis. Having everything in only one package is too inflexible for my tastes. –  jon May 26 '13 at 22:44
    
A few points (on both lists) are not really valid. You can always out-source the preamble or parts of it in a separate .tex file that is then \inputted. The simplest package is just this file with a .sty extension and \usepackage instead of \input. It really boils down to how often you can use this out-sourced file (package or not), how often you will add new features to it (for new documents), how hard it will be to maintain compatibility for older documents. The main file of my documents usually start with \input{preamble}. –  Qrrbrbirlbel May 27 '13 at 0:36
1  
“If I send my document to someone else, they can compile it immediately, without any fussing over where to put my package/class file.” A package file (.sty) or a class file (.cls) can simply be copied along with the document and will be used then. There is no need to “install” your custom package or class first. –  Qrrbrbirlbel May 27 '13 at 0:40
add comment

2 Answers

up vote 12 down vote accepted

As egreg points out in his comment, maintaining a universal preamble is a bit of a fool's errand, because different types of documents require different needs. For instance, the preamble of a report may require very different settings from those a beamer presentation would require. That said, I find that creating my own style file for certain types of documents makes my life much, much easier.

Ask yourself whether you're likely to reuse the same preamble for multiple documents of a given type (e.g. a series of lecture slides).

If the answer is yes, creating a custom class/package is the way to go. Obvious benefits include:

  • reusability: no need to copy and paste the same preamble for each new document.
  • consistency of the output, from one document to the next.
  • refinement: you can add new features to your style file as you identify new needs.
  • maintainability: you only need to change your style file to effect changes in all the documents that use it.
  • readability: the preamble of your input files will be much shorter.

If the answer is no, if you're going to use those particular settings in your preamble only once, don't bother creating your own style file.

share|improve this answer
5  
+1 Depending on your editor it may also be possible to set up template-type files which can include a preamble and save yourself from typing a lot. I prefer this to any kind of universal preamble for most of my documents. –  Alan Munn May 26 '13 at 23:47
add comment

As others have pointed out, trying to make a universal preamble is likely to lead to bloat as you wind up defining lots of macros that are irrelevant, or possibly even damaging (in terms of name conflicts etc.), for the current document; but it's pretty clear that there's something wrong with cut-and-pasting identical code, or large swathes of identical code, document by document. However, considering the question this way seems to be like asking "Should I include every CTAN package I have installed, or cut-and-paste all relevant macros each time?"; it seems to me that grouping your commonly used macros according to functionality and / or intent, and including only those that you need, is a perfectly reasonable (and preferable) middle ground.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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