Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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

share|improve this question
add comment

2 Answers 2

up vote 8 down vote accepted

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.

share|improve this answer
    
Is it possible to add a MWE, we get a lot of duplicate questions for this. –  Yiannis Lazarides Feb 23 '12 at 18:31
add comment

Take a look at my answer to this question, in there I describe how I split up big files. I don't know if this is something you are able to do still, but it might be something to keep in mind for future projects.

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!).

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.