# How to include a latex document as layout example?

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?

-
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

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.

-

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

\documentclass{article}

\usepackage{filecontents}
\begin{filecontents*}{layout.tex}
\documentclass[preview,border=12pt,12pt]{standalone}
\usepackage[a6paper,margin=1cm,showframe]{geometry}
\usepackage{lipsum}
\begin{document}
\section*{Minipage}
\noindent
\fbox{%
\begin{minipage}{.45\linewidth}
Left Minipage
\end{minipage}}
\hfill
\fbox{
\begin{minipage}{.45\linewidth}
Right Minipage
\end{minipage}}

\section*{Hello World}
{\tiny\lipsum[1]}
\end{document}
\end{filecontents*}

\immediate\write18{pdflatex layout.tex}

\usepackage[a5paper,vmargin=1.5cm,hmargin=1cm,landscape]{geometry}
\usepackage{xcolor,showexpl,lipsum}
\lstset
{
language={[LaTeX]TeX},
basicstyle=\scriptsize\tt,
backgroundcolor=\color{yellow!50},
numbers=none,
frame=single,
breaklines,
explpreset={},
pos=r,
varwidth,
}

\begin{document}
\section*{How to write a report with \LaTeX}
\LTXinputExample[graphic=layout.pdf,width=.5\textwidth]{layout.tex}
\lipsum[1-2]
\begin{figure}
\centering
\includegraphics[width=.5\linewidth]{layout}
\caption{The layout of our project report.}
\label{fig:layout}
\end{figure}
\end{document}


-