# Article example inside beamer frame

Let us assume that we have the following example code for an article

\documentclass{article}
\title{Sample title}
\author{Sample author}
\date{}
\begin{document}
\maketitle
\section{Sample section}
\end{document}


I wish to include the output of the above code as a minipage in my beamer frame. How can I do that? I would prefer a vector output rather than a PNG / JPG screenshot.

• Compile to PDF. \usepackage{pdfpages} and \includepdf{filename}?
– cfr
Jan 10, 2015 at 2:36

The easiest would be to create a separate document that contains the article content and include it as an image. Here's an example:

\documentclass{beamer}
\let\Tiny\tiny% http://tex.stackexchange.com/a/94159/5764
\usepackage{fancyvrb}
\usetheme{Warsaw}
\begin{document}

\begin{SaveVerbatim}{CodeBox}
\documentclass{article}
\title{Sample title}
\author{Sample author}
\date{}
\begin{document}
\maketitle
\section{Sample section}
\end{document}
\end{SaveVerbatim}

\begin{frame}[fragile]
\frametitle{\LaTeX{} code}

\begin{columns}
\begin{column}{.5\linewidth}
\UseVerbatim{CodeBox}
\end{column}

\begin{column}{.5\linewidth}
\includegraphics[width=\linewidth]{article}%
\end{column}
\end{columns}
\end{frame}

\end{document}


If you want to include a specific page from article.pdf, use the key-value page=<num> to include page <num> from article.pdf. You could also frame the page by using instead

\fbox{\includegraphics[width=\dimexpr\linewidth-2\fboxsep-2\fboxrule]{article}}


Note that code is stored in a box using fancyvrb and recalled inside the frame. Since you're dealing with beamer containing verbatim-like content, set the frame properties to [fragile].

Creating a separate document for the article is the easiest way. It has to be compiled only once and output plus source code can be included in the beamer frame.

But if you prefer to have only one source document which starts the compilation of the article, you can use the following (based on tcolorbox):

\documentclass{beamer}
\usepackage[skins,listings,raster]{tcolorbox}
\usetheme{Warsaw}
\begin{document}

\begin{frame}[fragile]
\frametitle{\LaTeX{} code}

\begin{tcblisting}{
enhanced,oversize,lower separated=false,
colframe=red!50!black,colback=yellow!10!white,
interior style={top color=yellow!5!white,bottom color=yellow!20!white},
listing side comment,
listing options={style=tcblatex,texcsstyle=*\color{red!70!black}},
pdf comment,
compilable listing,
run pdflatex,
raster columns=1}
\documentclass{article}
\usepackage{lipsum}
\title{Sample title}
\author{Sample author}
\date{}
\begin{document}
\maketitle
\section{Sample section}
\lipsum[1-3]
\end{document}
\end{tcblisting}

\end{frame}

\end{document}


Since the compilation of the article has to be started during compilation of the beamer frames, you have to use the -shell-escape option.

pdflatex -shell-escape mybeamerfile.tex


The example contains just one page. To select e.g. a possible page 3, you could use

comment style={drop lifted shadow,graphics pages={3}}


You can also show more than one page of output, but the size of each will shrink:

\documentclass{beamer}
\usepackage[skins,listings,raster]{tcolorbox}
\usetheme{Warsaw}
\begin{document}

\begin{frame}[fragile]
\frametitle{\LaTeX{} code}

\begin{tcblisting}{
enhanced,oversize,lower separated=false,
colframe=red!50!black,colback=yellow!10!white,
interior style={top color=yellow!5!white,bottom color=yellow!20!white},
listing side comment,sidebyside gap=5mm,
listing options={style=tcblatex,texcsstyle=*\color{red!70!black}},
pdf comment,
compilable listing,
run pdflatex}
\documentclass{article}
\usepackage{lipsum,tikz}
\title{Sample title}
\author{Sample author}
\date{}
\begin{document}
\maketitle
\section{Sample section}
\lipsum[1-12]
\begin{center}