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.

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.

share|improve this question
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 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 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 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 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 at 18:39

1 Answer 1

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
\documentclass{article}
\usepackage{graphicx}
\usepackage{stackengine}% Used for testing; not needed for \math(v)rule's
\parindent=0pt
\makeatletter

\newcommand\mathrule[3][0pt]{%
  \ifdim#2>#3\math@hrule[#1]{#2}{#3}\else\math@vrule[#1]{#2}{#3}\fi}

\newcommand\math@hrule[3][0pt]{%
  \gdef\mystery@factor{0.07}%
 \@tempdima=#3%
  \rule[#1]{0pt}{#3}% Needed to account for .5\@tempdima vertical offset of rounded rule
  \raisebox{.5\@tempdima+#1}{%
    \makebox[#2][l]{\kern-.5\@tempdima\@@mathrule{#2}{#3}}}%
}

\newcommand\math@vrule[3][0pt]{%
  \gdef\mystery@factor{0.0}%
 \@tempdima=#2%
  \rule[#1]{0pt}{#3}% Needed to account for .5\@tempdima vertical offset of rounded rule
  \raisebox{-.0\@tempdima+#1}{%
    \kern0.5\@tempdima%
    \rotatebox{90}{\kern-0.5\@tempdima\makebox[#3][l]{\@@mathrule{#3}{#2}}}%
    \kern0.5\@tempdima}%
}

\def\@@mathrule#1#2{%
  \@tempdimb=#2%
  \@tempdima=\dimexpr#1-\mystery@factor\@tempdimb%Why 0.07 for \math@hrule?
  \pdfliteral{%
    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 }}
\makeatother
\begin{document}
\mathrule{60bp}{1bp}\par
\rule{60bp}{1bp}\par
x\mathrule[-1pt]{20bp}{1bp}x\mathrule{20bp}{1bp}x\par
x\rule[-1pt]{20bp}{1bp}x\rule{20bp}{1bp}x\par
\stackunder[2pt]{\rule{60bp}{3bp}}{\mathrule{60bp}{3bp}}\par
\fbox{\mathrule[-1ex]{4ex}{.5ex}}\fbox{\rule[-1ex]{4ex}{.5ex}}\par
\fbox{\mathrule[+1ex]{4ex}{.5ex}}\fbox{\rule[+1ex]{4ex}{.5ex}}\par
\clearpage
\mathrule{1bp}{60bp} \rule{1bp}{60bp}\par
x\mathrule[-1pt]{1bp}{20bp}x\mathrule{1bp}{20bp}x%
  \rule[-1pt]{1bp}{20bp}x\rule{1bp}{20bp}x\par
x\rule[-1pt]{1bp}{20bp}x\rule{1bp}{20bp}x\par
\stackunder[2pt]{\rule{3bp}{10bp}\mathrule{3bp}{10bp}}%
  {\mathrule{3bp}{10bp}\rule{3bp}{10bp}}\par
\fbox{\mathrule[-1ex]{.5ex}{4ex}}\fbox{\rule[-1ex]{.5ex}{4ex}}\par
\fbox{\mathrule[+1ex]{.5ex}{4ex}}\fbox{\rule[+1ex]{.5ex}{4ex}}\par
\end{document}

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:

\documentclass{article}
\usepackage[margin=1in]{geometry}
\usepackage{graphicx}
\usepackage{ifthen}
\newcounter{fnum}\newcounter{countindex}

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

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?

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

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.