# How to write the preamble into a file

Can one define a bunch of macros, include them in a LaTeX source file main.tex and after issuing

}
\end{document}

-
I am not fully understanding your requirements. But I believe that the \documentclass needs to be set in the main file that you are compiling -- perhaps you should post a separate question for that to confirm. My understanding of preamble is that it is everything after \documentclass and before \begin{document},and that is what this solution achieves. Perhaps this is best done via a script outside of LaTeX, as per @AndrewStacey's comment. – Peter Grill Oct 25 '12 at 1:40

Something like this?

\documentclass{article}
\usepackage{filecontents}
\begin{filecontents}{\jobname.hed}

\usepackage{lipsum}
\usepackage{amsmath}
\def\WWW{World}