# Is there a source function/capability in LaTeX [duplicate]

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?

-

## marked as duplicate by egreg, Harish Kumar, percusse, Kurt, Tyler RinkerNov 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 Nov 4 '12 at 23:52
@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

## 1 Answer

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!
\begin{document}
…


where preamble.tex consists of the usual:

\documentclass[<options>]{class}
\usepackage[…]{…}
\usepackage[…]{…}
\usepackage[…]{…}
% own settings, stuff, etc.

2. Custom class (.cls) or package (.sty) file. Usage:

\documentclass[<options>]{myclass}
\usepackage[<options>]{mypackage}
\usepackage{other packages, only for this document}
\begin{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
-
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