I am getting some colleagues to migrate from Word to LaTeX for technical documents, but old habits die hard.

I am looking for a way to compile each LaTeX document partially without document tags, so that each document can be previewed easily, while still being capable of inclusion in a larger document which will in fact have a document tag.

Is it possible to have document tags in all documents (read .tex files) to allow fragment compilation, then suppress them once an inclusion is performed?

  • 1
    can you clarify what you mean by "document tag"? environments? preamble? --- You might want to take a look at standalone. Mar 20 '11 at 23:31
  • I mean the preamble + document environment.
    – whatnick
    Mar 21 '11 at 1:46

I assume you mean the document environment (\begin{document} ... \end{document}) and the preamble with "document tags".

Technically you need them in any compilable LaTeX document. There are some packages which allow you to ignore the preamble (incl. {document}) of included sub-files. A simple one is the docmute package. Extended features (like coping the sub-preambles to the main one) are provided by the standalone package and class, which however targets more the inclusion of diagrams which should be also compilable standalone, but is also suitable for sub-documents.

Simple create the other documents as normal including a \documentclass and document environment, and then load the docmute or standalone package in the main document. These redefine \documentclass etc. so that they are ignored.

There is also the combine class and accompanied packages, which might be also useful for you.

  • I chose the standalone package, does what I want for now.
    – whatnick
    Mar 21 '11 at 2:01
  • As much for future reference as anything else, the subfiles package does a very similar thing to standalone by allowing you to build all of your *.tex files using the preamble and document class/parameters from the main *.tex file, and so may be considered by future viewers of this question if they don't want the document class of subfiles to default to article, which I think standalone does.
    – Edd
    Apr 4 '11 at 9:03
  • @Edd: Thanks for also mentioning subfiles. With the standalone class the sub-files include their own preamble so that they can be compiled standalone. The used class default to article, but this can be easily changed using the class=<class> option. The standalone package allows you then to copy the sub-preamble to the main preamble. Quit the opposite direction like for subfiles. Apr 4 '11 at 9:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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