7

I have a source code named source.tex which produces a PDF file consisting of more than one page. The source code will be displayed by LTXinputExample as a formatted text and the corresponding output is provided by the existing PDF file via graphic option.

The problem is that graphic only shows the first page, the remaining pages are ignored. I want all pages to be shown in matrix form.

\documentclass{article}
\usepackage{filecontents}
\begin{filecontents*}{source.tex}
\documentclass[tikz]{standalone}
\begin{document}
\tikz \draw[blue] (0,0) circle (1);
\newpage
\tikz \draw[red] (0,0) circle (1);
\end{document}
\end{filecontents*}

\immediate\write18{pdflatex source}

\usepackage{showexpl}
\lstset
{
    frame=single,
}

\begin{document}
\LTXinputExample[graphic=source,pos=b,width=4cm,justification=\centering]{source.tex}
\end{document}

Can you make the graphic option of LTXinputExample able to render all pages of a multi-page PDF file?

Edit:

Could you merge the Doctor Herbert's solution with the following to get the better layout?

\documentclass{book}
\usepackage[a4paper,margin=25mm,showframe=false]{geometry}
\usepackage{graphicx}
\usepackage{listings}

\newcount\x
\newcommand\IncludeOutput[1]{% #1: filename without extension 
    \lstinputlisting[frame=single]{"#1.tex"}
  \pdfximage{"#1.pdf"}%
    \loop
        \ifnum\x<\pdflastximagepages
            \advance\x by 1
            \noindent\hfill
            \fbox{\includegraphics[width=0.5\dimexpr\linewidth-4\fboxrule-1cm,page=\x]{"#1"}}%                      
        \ifnum\x<\pdflastximagepages
            \advance\x by 1
            \hfill
            \fbox{\includegraphics[width=0.5\dimexpr\linewidth-4\fboxrule-1cm,page=\x]{"#1"}}%
        \fi
        \hfill\null\par
    \repeat
}

\begin{document}
    \IncludeOutput{DummyText}
    And more text follows\dots
\end{document}

enter image description here

2
  • No, not by default. You would have to patch \SX@resultInput and insert a loop. – Ulrike Fischer Nov 3 '12 at 18:35
  • @UlrikeFischer: It is beyond my ability. :-) – kiss my armpit Nov 3 '12 at 18:39
7
+1500

put the following into a file showexpl.cfg and save it in a directory where TeX will find it with kpsewhich (running texhash maybe needed). At least put it into the document directory. The file is automatically read by showexpl and redefines the output routine.

\RequirePackage{multido}
\newsavebox\SX@tempbox
\renewcommand*\SX@resultInput{%
  \ifx\SX@graphicname\@empty
    \begingroup
      \MakePercentComment\makeatother\catcode`\^^M=5\relax
      \SX@@preset\SX@preset
      \if@SX@rangeaccept
       \let\SX@tempa=\SX@input
      \else
       \let\SX@tempa=\input
      \fi
      \SX@tempa{\SX@codefile}\par%
    \endgroup
  \else
  \sbox\SX@tempbox{\includegraphics{\SX@graphicname}}
    \multido{\iP=1+1}{\pdflastximagepages}{%
      \expandafter\includegraphics\expandafter[\SX@graphicparam,page=\iP]{\SX@graphicname}}
  \fi
}
%% End of file `showexpl.cfg'.

If you want to frame also the result then it needs a lot of other code changes. However, it doesn't really make sense ...

\documentclass{article}
\usepackage{filecontents}
\begin{filecontents*}{source.tex}
\documentclass[tikz]{standalone}
\begin{document}
\tikz \draw[blue] (0,0) circle (1);
\newpage
\tikz \draw[red] (0,0) circle (1);
\end{document}
\end{filecontents*}

\immediate\write18{pdflatex source}

\usepackage{showexpl}
\lstset{frame=single,rframe=}

\begin{document}
\LTXinputExample[graphic=source,pos=b,width=4cm,justification=\raggedright]{source.tex}
\end{document}

enter image description here

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.