3

This question already has an answer here:

I'd like to include some pages from the pdf file produced by a tex document into the document itself. Is it possible to do it? The use case is that I would like to produce an 'outline of the talk' slide at the end of a beamer presentation, like this one

enter image description here

Minimal non-working example:

\documentclass{beamer}
\usepackage{graphicx}
\begin{document}
\begin{frame}
  \begin{block}{Frame}
    First frame
  \end{block}
\end{frame}
\begin{frame}
  \includegraphics[page=1, width=0.5\textwidth]{\jobname.pdf}
\end{frame}
\end{document}

I have tried pdfpages and \includegraphics from graphicx, but they both fail with the same error

pdfTeX error: pdflatex (file XXX.pdf): xpdf: reading PDF image failed

I am fine if the included version is not the one currently being compiled, but the result of a previous compilation of the same file. If I rename the pdf file and then include the copy it works (that's how I produced the image above); it would be OK to have a solution that simply automates this. I'd like to avoid turning on unrestricted \write18 just for this, though.

marked as duplicate by Federico Poloni, user36296 beamer Feb 9 '17 at 16:58

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • 2
    you will need to move the file, so use shell-escape (or simpler really) just include the moving of the file into your build command for the document. – David Carlisle Feb 9 '17 at 16:09
  • 1
    Maybe helpful: tex.stackexchange.com/questions/69991/… – user36296 Feb 9 '17 at 16:36
  • @samcarter Thanks, that sounds like the exact same question. I voted to close my own question as a duplicate (I didn't know it was even possible...) – Federico Poloni Feb 9 '17 at 16:55
1

When compiling a .tex iput file, usually the name of the resulting .pdf output file is the same as the name of the .tex iput file.

Usually an existing .pdf output file that came into being during a previous (La)TeX run gets destroyed at the start of the current (La)TeX run. Therefore it usually is not available for including/importing pages during the current (La)TeX run.

That destruction can be worked around:

E.g., you can write some shell-script or batch-script for renaming the .pdf file in question before starting compilation.

With many TeX platforms it also is possible when calling (La)TeX from the command-line to pass some option for changing/setting the name of all those files where the name is derived/deriveable from the expansion of the \jobname-primitive. This also affects the name of the .pdf output file.

E.g., in the current (February 9, 2017) documentation for the TeX platform MiKTeX 2.9 you can read:

Setting the Name of the Output File

You can change the name of all output files by using the option --job-name=name. 
This switch actually sets the name of the TeX job and has an effect of the 
output file names, because these names are derived from the job name.
Look at the following example:

C:\> latex -job-name=foo sample2e
This is TeX, Version 3.14159 (MiKTeX 2.2)
(D:\texmf\tex\latex\base\sample2e.tex
LaTeX2e <2001/06/01>
Babel <v3.7h> and hyphenation patterns for english, german, ngerman, loaded.
(D:\texmf\tex\latex\base\article.cls
Document Class: article 2001/04/21 v1.4e Standard LaTeX document class
(D:\texmf\tex\latex\base\size10.clo))
No file foo.aux.
(D:\texmf\tex\latex\base\omscmr.fd) [1] [2] [3] (foo.aux) )
Output written on foo.dvi (3 pages, 7256 bytes).
Transcript written on foo.log.
C:\>

Note the altered output file names: foo.aux, foo.dvi and foo.log.

For producing your presentation you can probably write a script for creating two .pdf output files from the same set of .tex input files, using different job-names.

E.g., in the process of producing the first .pdf output file, use a job-name which containes the phrase "draft".

E.g., in the process of producing the second .pdf output file, use a job-name which containes the phrase "final".

The "draft" .pdf output file and the "final" .pdf output file should be very similar.

But:

When producing the first .pdf file, the "draft" .pdf output file, you can have TeX insert some dummy pages in those places where you actually wish to have included copies of some of the document's own pages.

When producing the second .pdf file, the "final" .pdf output file, you can apply graphics/graphicx-package's \includegraphics or pdfpages-package's \includepdf in those places where you actually wish to have included copies of some of the document's own pages for importing/including pages from the "draft" .pdf output file.

This way same page-breaking and page-numbering of the "draft" .pdf output file and the "final" .pdf output file is ensured.

As the "draft" .pdf output file and the "final" .pdf output file are based on the same set of .tex input files, you need to implement a mechanism for finding out whether it is the "draft" .pdf output file or the "final" .pdf output file that currently gets produced.

It the "draft" .pdf output file is in production, have TeX insert some dummy pages.

It the "final" .pdf output file is in production, have TeX import the pages from the "draft" .pdf output file.

Such a mechanism could be based on the kernel-macro \ifFileExists, which can be used for checking whether the "draft" .pdf output file already exists, and, if so, having TeX include pages from the "draft" .pdf output file, and, if not so, having TeX include/produce some "dummy pages".

It could also be based on checking whether the expansion of the \jobname-primitive yields the name of the "draft" .pdf output file or the name of the "final" .pdf output file.

Be aware that currently in any case importing via graphics/graphicx-package's \includegraphics or via pdfpages-package's \includepdf implies that hyperlinks contained within original pages are disabled within copied pages.

Also be aware that copied pages actually stem from a (La)TeX run where the expansion of \jobname was different. Therefore pages that are to be copied not containing textual phrases derived from the expansion of the \jobname-primitive might be a good idea.

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