What would be the best way to include sample LaTeX output, in the form of (reduced) whole pages, into another document that discusses its typesetting?

I am thinking of creating one ("example") document with all the examples, and tagging each one with \label; in the main document, I would fetch the labels with the help of the xr package and include the appropriate page range with pdfpages. A first problem: I can expect to know the number of pages to include for each example, but how can I tell pdfpages to include from \pageref{exampleA} to \pageref{exampleA}+1? (Presumably there's some package that can calculate \pageref{exampleA}+1 in a form that I can pass to pdfpages. But which one?)

So far so good. This has the advantage that it's easy for the example document to use a different style than the documentation; but I need to manually ensure that the examples are generated with the same code that I describe in the main document. This is not essential, but could be handy. Perhaps I could also include latex code from the example document into the main document by somehow retrieving and line ranges (how?) and passing them to \lstinputlisting of the listings package), but I'd expect that to be more trouble than it's worth.

Can anyone recommend a better workflow? Are there better-suited packages that I am unaware of?

To summarize: I'm interested in the best way to show whole pages as sample output in a document that discusses its typesetting. Including PDF pages from another document, and including source lines from another TeX file, are possible approaches but not necessarily the best ones: I'm open to alternatives.

  • 1
    In part 2 of my answer at tex.stackexchange.com/questions/166418/…, I show how to include a series of whole pages from one document as a series of slightly reduced (and clipped) figures in another document. – Steven B. Segletes Apr 21 '14 at 12:55
  • Thanks! I've seen this question+answers before but certainly didn't connect it to my problem. Did you have to use \includegraphics (and a ton of pdf files) instead of pdfpages? The latter is clearly designed for managing all of the generated pages, whether one-up or n-up, so maybe I won't be able to use it for this? (I could try to get it to work, I know, but I don't want to waste a lot of time barking up the wrong tree.) – alexis Apr 21 '14 at 13:08
  • I did work with many PDF files, though in my case it was easy because Acrobat (installed on my system) will break a document into many files xxx_1, xxx_2, etc., at the click of a button. One commenter to my answer, Raphael, noted that "On GNU/Linux, splitting a document into single pages is easily achieved by pdftk in.pdf burst output out_%04d.pdf (pick suitably many digits for enumeration)." If you have a preferable way, by all means use it. I was just trying to get you started in one form or another. – Steven B. Segletes Apr 21 '14 at 13:13
  • I'm certainly not set on one approach. I'd prefer to avoid breaking up my file into single pages, but I'm flexible; and indeed I am asking for alternatives! – alexis Apr 21 '14 at 18:13
  • 1
    I've discovered that \includegraphics[page=2]{filename} is a valid syntax, which will alleviate the need for you to split the target file into subfiles. – Steven B. Segletes Apr 21 '14 at 18:39

Ok, first I need a multipage document that I want to insert. So, that others can compile it, I grabbed my MWE from Is there such a thing as a `\mathrule`? (rounded endcaps), which creates a 2-page output (name this source as useroundrule.tex):

\pdfcompresslevel=0 %%% to see how it works in the pdf code
\usepackage{stackengine}% Used for testing; not needed for \math(v)rule's


  \rule[#1]{0pt}{#3}% Needed to account for .5\@tempdima vertical offset of rounded rule

  \rule[#1]{0pt}{#3}% Needed to account for .5\@tempdima vertical offset of rounded rule

  \@tempdima=\dimexpr#1-\mystery@factor\@tempdimb%Why 0.07 for \math@hrule?
    q []0 d %
    1 J %  set line cap to rounded ends
    \strip@pt\@tempdimb\space w \strip@pt\@tempdimb\space 0 m %
    \strip@pt\@tempdima\space 0 l S Q }}
\mathrule{1bp}{60bp} \rule{1bp}{60bp}\par

So compile that to make a two page document (useroundrule.pdf) with some roundrule figures drawn on it. Now run this program that grabs the two pages from useroundrule.pdf and inserts them as whole-page (captioned) figures:


\def\blahblah{, from my other document}
\setcounter{fnum}{\thefigure}\addtocounter{fnum}{0}% can use as offset
\whiledo{\value{countindex} < 2}{
  \fbox{\includegraphics[scale=0.89,trim=48 36 46 60,page=\thefnum]{useroundrule.pdf}}
  \caption{Page \thefnum\blahblah}

Here is an image of the 2nd inserted page:

enter image description here

IN the above MWE, I scaled and clipped so as to occupy the whole textwidth/textheight. However, there is no reason one cannot scale and clip to smaller sized images, use [ht] figures, rather than [p] figures, etc.

This approach was based on part 2 of my answer at Put entire thesis on one A0 poster?

| improve this answer | |
  • Thanks! I'll need some time to get back to this and digest your answer... – alexis Apr 23 '14 at 18:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.