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

Vivi
  • 26,953
  • 31
  • 77
  • 79

1 Answers1

7

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