I have several compilable LaTeX input files and their corresponding PDF files. Each PDF file contains any number of pages. I want to import each LaTeX input file with \lstinputlisting
followed by its PDF pages as images. I have to consider
- the number of pages for each PDF file on the fly,
- the available spaces for the images
to avoid getting trimmed/cropped output.
The following is my MWE. Determining the number of PDF pages per file on the fly has been solved. The remaining task is to automatically arrange the imported PDF pages.
\documentclass[12pt]{book}
\usepackage[a4paper,margin=25mm,showframe=false]{geometry}
\usepackage{graphicx}
\usepackage{multido}
\usepackage{etoolbox,ifpdf,ifxetex}
\ifxetex
\newcount\pdflastximagepages
\def\pdfximage#1{\pdflastximagepages=\XeTeXpdfpagecount"#1"\relax}
\fi
\newcommand\Directory{}
\newcommand{\InsertOutput}[1]{%
\IfFileExists{\Directory/#1.pdf}{%
\pdfximage{\Directory/#1.pdf}%
\multido{\i=1+1}{\the\pdflastximagepages}
{\includegraphics[page=\i]{\Directory/#1}}
}{The corresponding PDF file does not exist.}%
}
\begin{document}
\renewcommand\Directory{Contents}
\InsertOutput{Article}
\end{document}
Pages in a single PDF file have the same dimension. I might need scaling factor to arrange the images. Each PDF file might need different scaling factor but the same factor will be used for the pages in a single PDF file. I prefer no more than 2 images in one row.
I skipped the usage of \lstinputlisting
code for the sake of simplicity.
Using pdfpages
package is not my option because I need the images floats and fill the available space.
The real scenario
I want to write a tutorial on LaTeX showing the code followed its output.
As LTXexample
from showexpl
does not work well for a compilable LaTeX input file, I have to use \lstinputlisting
and \includegraphics
.
The problem is to arrange the images following the imported code.
I want to produce a tutorial like below. FOR EXAMPLE, the page n
contains a source code and 2m
images, the page n+1
may contain the remaining images and some sentences as the corresponding comments, with m
and n
are integers.
pdfpages
package and its layout options.