I'm having trouble implementing this solution inside eso-pic: If pagestyle equal to... -- How should I ask it? It looks like \thepagestyle is coming out equal to "fancy" on every page, including obviously and explicitly "plain" pages.
\documentclass[12pt,twoside]{book}
\usepackage[paperwidth=4in,paperheight=2in,left=0.5in,top=0.25in,%
right=0.25in,bottom=0.25in]{geometry}
\usepackage{fancyhdr}
\usepackage{etoolbox}
\usepackage{eso-pic}
\makeatletter
\pretocmd{\pagestyle}{%
\gdef\@regularpagestyle{#1}%
\gdef\thepagestyle{\if@specialpage\@specialstyle\else\@regularpagestyle\fi}
}
{\message{(patching of \string\pagestyle\ succeeded)}}
{\message{(patching of \string\pagestyle\ failed)}}
\makeatother
\pagestyle{fancy}
\begin{document}
\AddToShipoutPicture{%
\fontsize{24.88pt}{24.88pt}\selectfont%
\ifdef{\thepagestyle}{%
The page style is `\thepagestyle'.%
}{%
There is no page style declared.%
}}
\thispagestyle{plain}
\ifdef{\thepagestyle}{
The page style is `\thepagestyle'.%
}{%
There is no page style declared.
}
\end{document}
My goal is to set different background images for each page style. I can either set a continuing default (using \AddToShipoutPicture), or a single page (using \AddToShipoutPicture*), but not both.
Using them concurrently gives terrible results. Clearing the default for a single page leaves no way to set the default again, unless I know exact page boundaries.
The solution here would be a terrible cop-out imho: How to clear the background of just the current page? It would result in a bloated filesize and low quality internal data.
Right now I'm trying to put all the logic in a single call to \AddToShipoutPicture (in my custom command \PageDecor):
\documentclass[10pt,twoside]{book}
\usepackage[paperwidth=6in,paperheight=9in,left=1in,top=1in,right=0.75in,bottom=1in]{geometry}
\usepackage{fancyhdr}
\renewcommand{\headrulewidth}{0pt}
\usepackage{graphicx}
\usepackage{etoolbox}
\usepackage{ifthen}
\makeatletter
\pretocmd{\pagestyle}{
\gdef\@regularpagestyle{#1}
\gdef\thepagestyle{\if@specialpage\@specialstyle\else\@regularpagestyle\fi}
}
{\message{(patching of \string\pagestyle\ succeeded)}}
{\message{(patching of \string\pagestyle\ failed)}}
\makeatother
\usepackage{eso-pic}
\newcommand{\PageDecor}{\AddToShipoutPicture{%
\ifodd\value{page}%
\ifthenelse{\equal{\thepagestyle}{fancy}}{%
\includegraphics[width=6in]{decor-6x9-right-fancy.pdf}%
}{%
\includegraphics[width=6in]{decor-6x9-right-plain.pdf}%
}%
\else%
\ifthenelse{\equal{\thepagestyle}{fancy}}{%
\includegraphics[width=6in]{decor-6x9-left-fancy.pdf}%
}{%
\includegraphics[width=6in]{decor-6x9-left-plain.pdf}%
}%
\fi%
}}
\newcommand{\PageDecorFancyOnce}{\AddToShipoutPicture*{%
\ifodd\value{page}%
\includegraphics[width=6in]{decor-6x9-right-fancy.pdf}%
\else%
\includegraphics[width=6in]{decor-6x9-left-fancy.pdf}%
\fi%
}}
\newcommand{\PageDecorPlainOnce}{\AddToShipoutPicture*{%
\ifodd\value{page}%
\includegraphics[width=6in]{decor-6x9-right-plain.pdf}%
\else%
\includegraphics[width=6in]{decor-6x9-left-plain.pdf}%
\fi%
}}
\begin{document}
\pagestyle{fancy}
\pagenumbering{arabic}
\setcounter{page}{1}
\fancypagestyle{plain}{\fancyhf{} \cfoot[\thepage]{\thepage}}
\fancyhf{}
\lhead[{\makebox[0.25in][l]{\hfill\thepage\hfill}}]{}
\rhead[]{{\makebox[0.25in][r]{\hfill\thepage\hfill}}}
\PageDecor
\thispagestyle{plain}
Testing testing 0123456789
\clearpage
\thispagestyle{plain}
Testing testing 0123456789
\clearpage
Testing testing 0123456789
\clearpage
Testing testing 0123456789
\end{document}
I can simulate my desired output here only because I know every page boundary:
%\PageDecor
\thispagestyle{plain}
\PageDecorPlainOnce
Testing testing 0123456789
\clearpage
\thispagestyle{plain}
\PageDecorPlainOnce
Testing testing 0123456789
\clearpage
\PageDecorFancyOnce
Testing testing 0123456789
\clearpage
\PageDecorFancyOnce
Testing testing 0123456789
I'm afraid I just don't understand Matthew Leingang's modifications well enough to troubleshoot them myself. I've searched for definitions to these symbols \if@specialpage, etc. to no avail. It remains entirely a black box for me.
Any help or insight would be appreciated.




\thispagestylenever actually calls\pagestyle, so you don't really pick up on page styles set by something other than\pagestyle. – Werner May 04 '16 at 20:30\thispagestylejust fine when used outside\AddToShipoutPicture– Quartz May 04 '16 at 20:51