4

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.

2 Answers 2

5

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.

4
  • 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. Commented May 14, 2012 at 17:09
  • @MartinScharrer Might that problem be resolved by having a dummy \newcommand in the first preamble loaded and \renewcommands everywhere else? Commented May 14, 2012 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. Commented May 14, 2012 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
    Commented May 14, 2012 at 18:29
1

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:

\input{titlepage.tex}

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

2
  • 1
    I don't think this will work for inputting files that are complete documents.
    – JohnReed
    Commented May 14, 2012 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
    Commented May 15, 2012 at 6:18

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .