TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|improve this question
up vote 5 down vote accepted

edit: improved answer based on comments.

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.

share|improve this answer
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
@MartinScharrer Might that problem be resolved by having a dummy \newcommand in the first preamble loaded and \renewcommands everywhere else? – Ethan Bolker May 14 '12 at 17:19
@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

Don't know this answers your question correctly.

If we have a huge latex file, we can simply break it down into different files as per our convenience and and include those files in the main file using the following tag:


titlepage.txt is the latex file in the same directory.

share|improve this answer
I don't think this will work for inputting files that are complete documents. – JohnReed May 14 '12 at 16:18
yea, correct. It will help when the main file is the complete document and the other included files are just a snippets that can be cut-copied from the mail file. – mtk May 15 '12 at 6:18

Your Answer


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.