TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Possible Duplicate:
How to make a standard preamble into a package

I often have the same preamble stuff in my documents that kind of clutter the work space a bit. Some are custom commands I've stolen from here or there and some are calls to packages.

In R I can use a function called source that allows me to create an external file of these commands and then I can just call source to read this external file and it's magically in the working memory (LINK to source info). It would be nice to do the same with LaTeX. Does LaTeX have this kind of capability?

share|improve this question

marked as duplicate by egreg, Harish Kumar, percusse, Kurt, Tyler Rinker Nov 5 '12 at 1:18

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

@hpesoj626 I think you're right. It's actually a duplicate and this thread should probably be closed. – Tyler Rinker Nov 4 '12 at 23:55
up vote 5 down vote accepted

There are three ways to outsource your preamble:

  1. (The easiest one) Separate .tex file, say preamble.tex. Usage:

    \input{preamble} % NOT \include and NO file ending!

    where preamble.tex consists of the usual:

    % own settings, stuff, etc.
  2. Custom class (.cls) or package (.sty) file. Usage:

    \usepackage{other packages, only for this document}

    Your custom package can be simply just the same as the aforementioned preamble.tex (but with .sty), but you can also write a package that is quite dynamic, see for example: Reference guide to begin writing a class and/or a package

  3. Pre-compiled preamble
share|improve this answer
I will add some resourceful links in a minute … – Qrrbrbirlbel Nov 4 '12 at 23:47
In case you are looking for links for 3: ultrafast pdflatex with precompiling Custom format file: How to automate the generation of the “precompiled preamble” whenever one of the files that are used there are changed. I am working on a problem I am having with this so had the link open. – Peter Grill Nov 4 '12 at 23:49
Thank you that's pretty easy. +1 – Tyler Rinker Nov 4 '12 at 23:56
@TylerRinker Yes, the first one is quite the easiest way as it is just a literally way of out-sourcing your code. No much experience needed. For the other ways I refer to the full knowledge of TeX.SE, all is already covered. (The third way is a very experienced one and is only if at all needed for very big documents (or slow machines).) – Qrrbrbirlbel Nov 5 '12 at 0:00

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