# includepdf results in undesired headings

\includepdf[pages={34-40},nup=2x2,frame,landscape,scale=0.8,%
pagecommand=\chapter{fracture}\section{Theoretical}]{Dam-Nonlinear.pdf}
\clearpage
\includepdfmerge[nup=1x2,frame,landscape,scale=0.8,%
pagecommand={\section{blablah}}]{ASCE-Cyclic-Joint-Model.pdf,1,%
ASCE-Cyclic-Joint-Test.pdf,1}
\includepdf[scale=0.8,nup=2x2,pages={9-13},frame,landscape,%
pagecommand=\section{Experimental Work}]{Ageing-Shaking-Cracking.pdf}
\includepdfmerge[nup=1x2,frame,landscape,scale=0.8]{cement-concrete-slowik.pdf,1,%
Optical_Fiber-in-FPZ.pdf,1}


results in

1. Correct header of chapter 1 (Fracture), and section 1.1 (Theoretical) and followed by the pdf file to be included (this takes two pages)
2. First problem, on page 3, I get: Chapter 2 Fracture and 2.1 Theoretical again, followed by blank. Clearly wrong
3. Then I correctly get section 2.2 blah blah followed by the pdf to be included (one page).
4. I get correctly 2.4 Experimental work on the first of two pages, but again the same header of the second (of two) page.
-
Have you tried enclosing the argument(s) of each pagecommand= instruction in curly braces? In the code you provide, you only appear to do so for the first \includepdfmerge macro, but not for the two \includepdf macros. –  Mico Apr 23 '12 at 17:36
As mentioned in the pdfpages documentation, the pagecommand key is executed on every page (or sheet of paper). You're interested in something like a pagecommand* key that does not currently exist. As such, you need some other workaround. –  Werner Apr 23 '12 at 17:41
Have you tried putting curly braces around -- or, equivalently, inserting \begingroup and \endgroup statements before and afer -- the \includepdfmerge and \includepdf statements? This should keep the scope of the respective pagecommand directives localized. (By default, the pagecommand statements apply to all pages...) –  Mico Apr 23 '12 at 19:11

The pagecommand option is only meant for "immaterial" things like \thispagestyle. The way you use it a new chapter will start on every included page.

I assume you are using a book-like class where a new chapter always starts on a right page. The empty page inserted by the second \chapter is what really messes things up.

I advise to move \chapter and \section completely outside of \includepdf:

\chapter{fracture}\section{Theoretical}
\includepdf[pages={34-40},nup=2x2,frame,landscape,scale=0.8,%
pagecommand={}]{texbook.pdf}
\clearpage
\section{blablah}
\includepdfmerge[nup=1x2,frame,landscape,scale=0.8,%
pagecommand={}]{texbook.pdf,%
1,texbook.pdf,1}
\section{Experimental Work}
\includepdf[scale=0.8,nup=2x2,pages={9-13},frame,landscape,%
pagecommand={}]{texbook.pdf}
\includepdfmerge[nup=1x2,frame,landscape,scale=0.8]{texbook.pdf,%
1,texbook.pdf,1}


Of course I can't judge whether this is what you want as you've given very little detail on this.

-
Sure, but then I get a nearly empty blank page (with the headers) which is "ugly". Oh well, I will limit myself to one page inclusion. Thanks –  victor Apr 23 '12 at 18:23
@victor Yes, I had assumed as much. Maybe you don't want the sectioning commands themselves but just the page headers? Take a look at the fancyhdr package, it lets you set the headers to anything you want. –  Stephan Lehmke Apr 23 '12 at 18:31