# Combining Independent Latex Files

I have loads of latex files in a directory, each having (basically the same) preamble. That is, they use the same packages, the same documentclass, and they each define the same newcommands; there might be slight differences.

Is there some package out there that allows me to import all the files into one file without too much fuss?

What I'm essentially after is that some of the files are very short and only take up about a quarter of a page. When I print all this out, I'd rather it format such that it makes the most of every page -- that is, immediately start the next latex file on the same page.

-

This sounds like a job for the `standalone` package. After loading the package, you can use the `\input` command to load the documents.

The full preamble line would be `\usepackage[print,sort]{standalone}`; the `print,sort` options need to be set in order to combine all of the preambles into a `.stp` file. You can then copy the combined preamble from the `.stp` file into your main document. Perhaps there is a way to automate the process of copying the `.stp` file contents into the preamble, but I don't know of one.

-
I'm not sure if `subpreambles` is a wise choice here. If the same macros are defined with `\newcommand` you will get errors. Manually creating a common preamble might be the necessary. –  Martin Scharrer May 14 '12 at 17:09
@EthanBolker: I wouldn't do that with the automated `subpreambles`. Instead a common preamble can be produced using the `print,sort` options which create a `.stp` file. This can then be copied to the main preamble and modified. –  Martin Scharrer May 14 '12 at 17:35
@MartinScharrer I have updated the answer based on your input. I based my previous answer on a simple test case that only involved the use of the `amsmath` package in the sub file. –  JohnReed May 14 '12 at 18:29

`\input{titlepage.tex}`