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 would like to include a latex document in an other latex document as figure to give an example for an layout, that means, the result of a latex document should be shown as, so to say a mini page in an other document:

This is a Title of my Main Document

This is some text in the document that talks about a layout and so on an   
refers to a figure that should illustrate this talking (fig. 1). 
    |                         |
    |   This is a latex       |
    |   document, embedded    |
    |   to the main document  |
    |                         |
    |                         |
    |                         |
    |                         |
    |                         |
    |                         |
    |                         |
     fig. 1

Is this possible?

share|improve this question
do you want to show the source or the result? (both are possible) – David Carlisle Jul 16 '14 at 15:31
Do you want to include the output (for example, a single page) or the code? If you compile the example code in a separate file you can insert the pdf page as figure. – Sigur Jul 16 '14 at 15:32
@DavidCarlisle The result should be shown. – user5950 Jul 16 '14 at 15:34
@Sigur I updated my question. Is it possible to directly insert a latex file without compile the example code in a separate file? – user5950 Jul 16 '14 at 15:44
@user5950 Either you display the LaTeX code or you insert the result of compiling the LaTeX code, the result is (usually, nowadays) a PDF. So what -- PDF or *.tex file? – Keks Dose Jul 16 '14 at 15:58
up vote 11 down vote accepted

You ask in comments if a separate file can be avoided, but it is much more accurate to just typeset the document to a separate file and include the resulting page with \includegraphics from graphicx package.

Obviously for small sections such as a single \textbf{hello} or even an enumerate environment it is possible just to put the code being demonstrated in a minipage, but in general it's very hard to isolate the style settings for the outer document from affecting the example.

For the LaTeX companion book which has dozens of these kinds of examples, the source code of the example document is in the main file, and is written verbatim to a separate file, a makefile controlling the process ensures that these generate files are run through latex to produce the result images to re-include back into the original document.

share|improve this answer

Simulating the more general case (just for fun). You can adapt it to suit your need.


Left Minipage
Right Minipage

\section*{Hello World}

\immediate\write18{pdflatex layout.tex}


\section*{How to write a report with \LaTeX}
\caption{The layout of our project report.}

enter image description here

enter image description here

share|improve this answer

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.