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

Latex newbie here. Let's say I create a page with some Latex code, and I want to have the following beamer slide contain the output of that code. how can I do that?

\begin{frame}[fragile]{How does \mbox{\LaTeX} work?}
\title{My R Poem}


R is my favoritest.


I assume there's a package for this, but I'm not aware of it and can't find it via google.

share|improve this question
Do you want to show code and result side-by-side or just the output? – Martin Scharrer Jul 2 '11 at 18:06
I'd have the code on one slide, which is done with the verbatim package (see code above), and another slide for the output. – ATMathew Jul 2 '11 at 18:07
up vote 5 down vote accepted

To include the output of a different, full document with own preamble you would have to include the output as PDF (or PS if you insist using non-PDF latex). I would recommend you to store the code in an external file and use the standalone class to produce a tightly cut PDF (the preview package is internally used to do this). Then simply include the PDF as graphic using \includegraphics[width=...]{filename}. You can also include the source using the listings package and \lstinputlisting. It also allows you to remove the first or last code lines if you want to remove the \documentclass[class=<realclass>]{standalone} part.

The v1.0 of the standalone package allows to automatically compile sub-files as standalone documents and include them as images to the main document.

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.