[Tex/LaTex] \AddEverypageHook just checks the first page

backgroundshookspage-breaking

I am totally new to LaTeX and right now I'm trying to find out how everything works. For the following code I get a background picture only on the first page although I want to have it on all odd pages. Additionally I get an error stating:

Undefined control sequence: \AddEverypageHook

This is my code:

\documentclass[a4paper]{report}
\usepackage[english]{babel} 
\usepackage{lipsum}
\usepackage{ifthen}
\usepackage{blindtext}
\usepackage{graphicx}
\usepackage{eso-pic}

\newcommand\BackgroundPic{
\put(-4,0){
\parbox[b][\paperheight]{\paperwidth}{%
\vfill
\centering
\includegraphics[width=\paperwidth,height=\paperheight,
keepaspectratio]{background.jpg}%
\vfill
}}}

\makeatletter
\AddEverypageHook{%
\ifthenelse{\isodd{\value{page}}}%
  {}%
  {\AddToShipoutPicture*{\BackgroundPic}}%
  }
\makeatother

\begin{document}


\title{The Triangulation of Titling Data in
       Non-Linear Gaussian Fashion via $\rho$ Series}
\date{October 31, 475}
\author{John Doe\\ Magic Department, Richard Miles University
        \and Richard Row, \LaTeX\ Academy}
\maketitle
\blinddocument
\end{document}

It would be nice if you could help me with this and explain what is going wrong here.
Thanks in advance.

Best Answer

The eso-pic package does not provide \AddEverypageHook, hence the "Undefined control sequence" error. The latter is provided by the everypage package. However, since eso-pic loads atbegshi by default, you can use the functionality provided by it to tap into the page output routine.

It seems like you're after printing some background image on every odd/even page of your document. The following does that:

enter image description here

\documentclass[a4paper]{report}
\usepackage[english]{babel}% http://ctan.org/pkg/babel
%\usepackage{lipsum}% http://ctan.org/pkg/lipsum
\usepackage{ifthen}% http://ctan.org/pkg/ifthen
\usepackage{blindtext}% http://ctan.org/pkg/blindtext
\usepackage{graphicx}% http://ctan.org/pkg/graphicx
\usepackage{eso-pic}% http://ctan.org/pkg/eso-pic

\newcommand\BackgroundPic{%
  \put(-4,0){%
    \parbox[b][\paperheight]{\paperwidth}{%
      \vfill
      \centering
      \includegraphics[width=\paperwidth,height=\paperheight,keepaspectratio]{tiger}%
      \vfill
  }}}

%\makeatletter
\AtBeginShipout{%
  \ifthenelse{\isodd{\value{page}}}%
    {}%
    {\AddToShipoutPictureBG*{\BackgroundPic}}%
}
%\makeatother

\begin{document}


\title{The Triangulation of Titling Data in
       Non-Linear Gaussian Fashion via $\rho$ Series}
\date{October 31, 475}
\author{John Doe\\ Magic Department, Richard Miles University
        \and Richard Row, \LaTeX\ Academy}
\maketitle
\blinddocument
\end{document}

Here are some further considerations:

  • To place an image in the "background layer", eso-pic offers \AddToShipoutPictureBG while \AddToShipoutPictureFG prints it in the "foreground layer". Each have a starred variant pertaining to only that page it's called on. There is no \AddToShipoutPicture (without BG or FG).

  • The picture addition is based on \value{page}, so any command that influences page numbering has an effect on the placement (like your title).

Related Question