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.

I have to put some academic papers at the end of a document, but only include a subset of their pages (due to the page limitations in our project). Now, I would like to mark each included page with the original page number of the PDF paper I'm including.

Here is my MWE to illustrate the question.

\documentclass{article}
\usepackage{pdfpages}

\begin{document}

\includepdf[pages={1-2,4},picturecommand={\put(30,30){\makebox{Lorem Ipsum p. XX}}}]{lorem.pdf}

\end{document}

I created a second PDF called lorem.pdf by just typesetting:

\documentclass{article}
\usepackage{lipsum}

\begin{document}
\lipsum[1-25]
\end{document}

which creates a 4-page document lorem.pdf. Now, when I include only parts of the paper, namely pages 1, 2, and 4, I would like to fill in these numbers in the 'picturecommand' text instead of XX. Is there a way to reference that number there?

share|improve this question
3  
Just in general: I recommend to use article instead of the minimal class, even for minimal documents. minimal is more a code example than a real class and has no real benefit, but can cause some issues because not all normal things are set. –  Martin Scharrer Apr 13 '12 at 18:29
    
Why not do pagecommand={\thispagestyle{plain}} and let the included pdf show its own page number? (instead of picturecommand) –  Ariel Apr 13 '12 at 18:54
add comment

1 Answer

up vote 6 down vote accepted

Assuming that your input document (lorem.pdf) has no pages numbers and that the page numbers specified by the key-value pages={1-2,4} are the actual page numbers in the source document, the macro \AM@page contains the value you're after:

\documentclass{article}
\usepackage{pdfpages}% http://ctan.org/pkg/pdfpages
\begin{document}
\makeatletter
\includepdf[
   pages={1-2,4},
   picturecommand={\put(30,30){\makebox{Lorem Ipsum p.\ \AM@page}}}]
  {lorem.pdf}
\makeatother
\end{document}

The above MWE prints

Lorem Ipsum p. 1
Lorem Ipsum p. 2
Lorem Ipsum p. 4

in the lower-left corner.

If the above conditions are not met, then it would be possible to temporarily modify \AM@page to be a certain shift from the given values.

share|improve this answer
    
hmph that's simpler than mine, I'll delete –  David Carlisle Apr 13 '12 at 19:19
    
yes, the conditions were exactly as you stated. Thanks! –  Linda Apr 13 '12 at 19:23
add comment

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.