# create a self-contained source?

Is there a simple way to export a self-contained source for a large LaTeX document? I would like it to export all of the class files, etc as well as the sources that I have written in order to create a self-contained source.

LaTeX offers the environment filecontents and filecontents* which allow you to add external files to your .tex file. The environments have to be used before the \documentclass declaration. If you process the .tex file the files are then written to the local directory (but only if there isn't already a file with that name) and thus can be used as part of the document.

Example:

\begin{filecontents}{myarticle.cls}

The filecontents environment writes a short header (behind % signs at the top of the generated file, the star form suppresses that header. The latter is useful if you want to generate a file that needs to be kept unchanged. What is not possible is to add real binary files to your document in that way (e.g., a .jpg graphic).
• LaTeX has \listfiles that gives you at least the list of all files used (I think there also a few scripts around to then collect them from the file system and put them into a zip or the like) – Frank Mittelbach Mar 13 '12 at 20:47
• If you include \usepackage{filecontents} then the files will be overwritten. This is very useful when composing test cases so that the file on disk is always the latest version. – Peter Grill Mar 15 '12 at 20:15