# Make a .tex file that combines complete .tex documents in subdirectories

I'm using LaTeX for my research journal (similar to WordPress).

There are a number of subdirectories that contain complete (standalone) .tex files along with PDF files that I made from those standalone files.

I'd like to get a .tex file that contains all the .tex files and compiles to a PDF. What would be a good way to do that?

Currently I compile the .tex file in each subdirectory and then merge all the PDFs into a main PDF file. The problem is that each PDF takes a page and if I have a small note, the most of the page is clear. Please keep in mind that I would like to keep the standalone PDF files, too.

The other option is to cut out the body of the document and paste it into the main LaTeX file, but i was wondering if there is a package that does it. Meaning that would keep both main and stand alone files. Kind of like have chapters of the book compile separately

-

Simply use the standalone package in the main file and \input all other files. The package will strip the preambles from these files. There is also the subpreambles option which will copy the preamble content of all subfiles and load it in the main preamble in the next run, so you don't have to do this yourself if the sub-files need extra packages.

You might have issues with the relatives paths. If so I would set the TEXINPUTS environment variable to .:subdir1:subdir2:subdirn: (note the leading . and the trailing empty entry which are important), so that LaTeX also looks in the subdirectories for files.

-
Is it possible to add a MWE, we get a lot of duplicate questions for this. –  Yiannis Lazarides Feb 23 '12 at 18:31
Note that I'm not aware of the standalone features which Martin mentioned (it isn't easily compatible with some other setups I use) so have a look at his answer since that might be easier to do at this point (Martin is a smart guy!).