1

Pretty much what the title says. Simplest description, I have two backgrounds, one that is for the odd pages (pageBGRight.png) and one that is for even pages (pageBGLeft.png). My intuition is that it needs some form of If statement, but I seem to be goofing up the syntax in a way I can't quite figure out. If someone could take a look I would appreciate it.

OH, I am using the older "AddEverypageHook" because I am using a system that does not yet have the most up to date version of Latex, and I do not have authority to update it myself. Thanks!


\AddEverypageHook{\ifodd\value{page}\relax{shipout/background}{%
    \put (0in,-\paperheight){\includegraphics[width=\paperwidth,height=\paperheight]{pageBGRight}}%
}
\else
  {shipout/background}{%
    \put (0in,-\paperheight){\includegraphics[width=\paperwidth,height=\paperheight]{pageBGLeft}}%
}
\fi}

2 Answers 2

2

texdoc source2e is 1,110 pages of stuff you might not know otherwise. In particular, there's this gem:

However, most use cases for everyshi are attempts to put some picture or text into the background or foreground of the page and that can be done today simply by using the shipout/background and shipout/foreground hooks without any need to coding.

You're kind of using the hooks, but not really in that there's nothing magical about the string shipout/background and just putting it there is telling LaTeX to typeset that string.

Instead you should be able to write:

\AddToHook{shipout/background}{
   \put(0in,-\paperheight){%
      \ifodd\value{page}\relax
         \includegraphics[width=\paperwidth,height=\paperheight]{pageBGRight}%
      \else
         \includegraphics[width=\paperwidth,height=\paperheight]{pageBGLeft}%
      \fi
   }
}

Note also, that I simplified the code a bit by moving the \ifodd as deeply into the code as possible.

Ah, but I see that you think you are forced to use \AddEveryPageHook. Assuming that the above doesn't work, the source2e document says:

\AddEverypageHook{code}\AddToHook{shipout/background}{\put(1in,-1in){code}}

So with that knowledge, we can replace \AddToHook{shipout/background} with AddEveryPageHook and then we might need to adjust the values in the \put command above to fix positioning.¹


  1. Would it really be an answer from me without at least one footnote? Very well then: given that I haven't tried your code, I think that you might have to adjust the values even in the canonical LaTeX hooks version.
1

Nevermind, I solved it. I had to start from scratch and use a slightly different methodology, but I got it working. For those interested, this is what I did:

\backgroundsetup{
scale=1,
opacity=1,
angle=0,
color=black,
contents={%
 \ifodd\value{page}
   \includegraphics[width=\paperwidth]{pageBGRight.png}
  \else
   \includegraphics[width=\paperwidth]{pageBGLeft.png}
  \fi}}

I had to use the background package, but that got the job done.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .