Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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 at 15:31
1  
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 at 15:32
    
@DavidCarlisle The result should be shown. –  user5950 Jul 16 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 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 at 15:58

2 Answers 2

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.

\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}

enter image description here

enter image description here

share|improve this answer

Your Answer

 
discard

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.