Multiple AddToShipoutPicture

Asif just a moment. 1 answers, 0 views
backgrounds eso-pic

\myTileWallPaper is defined in the classfile like this

\makeatletter
\newcommand{\myTileWallPaper}[4]{%
\begingroup
\setlength{\tileYoffset}{\wpYoffset}
\setlength{\tilewidth}{#1}%
\setlength{\tileheight}{#2}%
\setlength{\tileY}{0pt}%
\whiledo{\lengthtest{\tileY < \paperheight}}{% 
  \setlength{\tileX}{0pt}%
  \setlength{\tileXoffset}{\wpXoffset}%
  \whiledo{\lengthtest{\tileX < \paperwidth}}{% 
    \put(\LenToUnit{\tileXoffset},\LenToUnit{\tileYoffset}){%
      \includegraphics[height=\tileheight,width=\tilewidth]{#3}}%
    \addtolength{\tileX}{\tilewidth}
    \addtolength{\tileXoffset}{\tilewidth}
  }%
  \addtolength{\tileY}{\tileheight}
  \addtolength{\tileYoffset}{\tileheight}
}%
\endgroup
}
\makeatother

When I use two \AddToShipoutPictures, LaTeX throws an error.

\AddToShipoutPicture{%
\ifthenelse{\isodd{\thepage}}% Wenn ungerade Seitenzahl, dann Bild 1, sonst Bild 2.
    {\myTileWallPaper{\paperwidth}{\paperheight}{wallpaper1}}% ungerade Seite
    {\myTileWallPaper{\paperwidth}{\paperheight}{wallpaper2}}% gerade Seite
}
    \AddToShipoutPicture{\setlength{\unitlength{0.1mm}}\put(500,2522){\includegraphics[width=1.5cm]{Logoimg}}}

The error is as follows :

! Missing number, treated as zero.
<to be read again>
{
l.73 \end{document}
A number should have been here; I inserted `0'.
(If you can't figure out why I needed to see a number,
look up `weird error' in the index to The TeXbook.)

If I remove the 2nd \AddToShipoutPicture, everything seems to work fine. If I remove the 2nd \AddToShipoutPicture and put it ahead of the first one, everything seems to work fine -- although it doesn't work since the wall-paper then covers the logo.

1 Answers


Ahmed Musa 12/19/2011.

The following tiling isn't exactly correct, but it is precisely what you would have had if your code compiled. Use, eg, xwatermark package instead.

\usepackage{graphicx}
\usepackage{catoptions}
\usepackage{eso-pic}

\makeatletter
\cptnewdimens{tileXoffset,tileYoffset,wpXoffset,wpYoffset,
  tilewidth,tileheight,tileX,tileY}
\wpXoffset.25cm\wpYoffset.25cm
\robust@def*\myTileWallPaper#1#2#3{%
  \begingroup
  \tileYoffset\wpYoffset
  \tilewidth=\dimexpr#1\relax
  \tileheight=\dimexpr#2\relax
  \tileY=0pt
  \cptwhiledim\tileY<\paperheight\do{%
    \tileX=0pt \tileXoffset\wpXoffset
    \cptwhiledim\tileX<\paperwidth\do{%
      \put(\LenToUnit{\tileXoffset},\LenToUnit{\tileYoffset}){%
        \includegraphics[height=\tileheight,width=\tilewidth]{#3}%
      }%
      \addtolength{\tileX}{\tilewidth}%
      \addtolength{\tileXoffset}{\tilewidth}%
    }%
    \addtolength{\tileY}{\tileheight}%
    \addtolength{\tileYoffset}{\tileheight}%
  }%
  \endgroup
}
\makeatother

\begin{document}
\AddToShipoutPicture{%
  \ifnumoddTF\thepage
    {\myTileWallPaper{.25\paperwidth}{.25\paperheight}{diag1.eps}}%
    {\myTileWallPaper{.25\paperwidth}{.25\paperheight}{diag2.eps}}%
}

Here is the correct solution. Now you use keys in place of parameters.

\documentclass{article}
\usepackage{atbegshi,picture,graphicx,ifpdf}
\usepackage{pathkeys}
\makeatletter
\pathkeys{wallpaper/asif/define*(cmd):
  viewport/00 00 100 100;
  xtilenr/2;
  ytilenr/2;
  wpxoffset/0pt;
  wpyoffset/0pt;
  inputpath//;
}
\newcommand*\mytilewallpaper[2][]{%
  \begingroup
  \pathkeys@currentpath{wallpaper/asif}%
  \pathkeys{set:#1}%
  \pathkeys@useshortcmds
  \edef\ffileext{\ifpdf pdf\else eps\fi}%
  \edef\reserved@a{\pkv{inputpath}}%
  \edef\reserved@a{\expandafter\ltxkeys@stripallouterbraces
    \expandafter{\reserved@a}}%
  \edef\Ginput@path{\ifcsnullTF\reserved@a{}{{\reserved@a/}}}%
  \cptdimdef\tilewidth{(\paperwidth-\pkv{wpxoffset}*2)/\pkv{xtilenr}}%
  \cptdimdef\tileheight{(\paperheight-\pkv{wpyoffset}*2)/\pkv{ytilenr}}%
  \cptdimdef\tileY{-\paperheight+\pkv{wpyoffset}}%
  \@tempcntb\z@
  \cptwhilenum\@tempcntb<\pkv{ytilenr}\do{%
    \edef\tileX{\pkv{wpxoffset}}%
    \@tempcnta\z@
    \cptwhilenum\@tempcnta<\pkv{xtilenr}\do{%
      \leavevmode\@killglue
      \cptexpanded{\noexpand\put(\tileX,\tileY){\noexpand\includegraphics
      [viewport=\pkv{viewport},height=\tileheight,
      width=\tilewidth,clip]{#2.\ffileext}}}%
      \advance\@tempcnta\@ne
      \cptdimadd\tileX{\tilewidth}%
    }%
    \advance\@tempcntb\@ne
    \cptdimadd\tileY{\tileheight}%
  }%
  \endgroup
}
\makeatother

\begin{document}
\def\wpspec{[viewport=20 21 590 400,xtilenr=4,ytilenr=4,
  wpxoffset=2cm,wpyoffset=2cm,inputpath={./graphics}]{comet1}}
\AtBeginShipout{%
  \AtBeginShipoutUpperLeft{%
  \ifnumoddTF\thepage
    {}%
    {\expandafter\mytilewallpaper\wpspec}%
}}
x
\newpage
x
\end{document} 

enter image description here


HighResolutionMusic.com - Download Hi-Res Songs

1 BLACKPINK

Kiss And Make Up flac

BLACKPINK. 2018. Writer: Soke;Kny Factory;Billboard;Chelcee Grimes;Teddy Park;Marc Vincent;Dua Lipa.
2 Martin Garrix

Waiting For Tomorrow flac

Martin Garrix. 2018. Writer: Pierce Fulton;Mike Shinoda;Martijn Garritsen;Brad Delson.
3 John Legend

Written In The Stars flac

John Legend. 2018. Writer: Kiana Brown;Santoy;Kevin White;Mike Woods;MZMC;The Heavy Group;Rice N' Peas.
4 Martin Garrix

Access flac

Martin Garrix. 2018. Writer: Martin Garrix.
5 Martin Garrix

Yottabyte flac

Martin Garrix. 2018. Writer: Martin Garrix.
6 Alan Walker

Diamond Heart flac

Alan Walker. 2018. Writer: Alan Walker;Sophia Somajo;Mood Melodies;James Njie;Thomas Troelsen;Kristoffer Haugan;Edvard Normann;Anders Froen;Gunnar Greve;Yann Bargain;Victor Verpillat;Fredrik Borch Olsen.
7 Cardi B

Taki Taki flac

Cardi B. 2018. Writer: Bava;Juan Vasquez;Vicente Saavedra;Jordan Thorpe;DJ Snake;Ozuna;Cardi B;Selena Gomez.
8 Bradley Cooper

Shallow flac

Bradley Cooper. 2018. Writer: Andrew Wyatt;Anthony Rossomando;Mark Ronson;Lady Gaga.
9 Post Malone

Sunflower flac

Post Malone. 2018. Writer: Louis Bell;Billy Walsh;Carter Lang;Swae Lee;Post Malone.
10 Dyro

Latency flac

Dyro. 2018. Writer: Martin Garrix;Dyro.
11 Lady Gaga

I'll Never Love Again flac

Lady Gaga. 2018. Writer: Benjamin Rice;Lady Gaga.
12 Rita Ora

Let You Love Me flac

Rita Ora. 2018. Writer: Rita Ora.
13 Zara Larsson

Ruin My Life flac

Zara Larsson. 2018. Writer: Delacey;Michael Pollack;Stefan Johnson;Jordan Johnson;Sermstyle;Jackson Foote.
14 Halsey

Without Me flac

Halsey. 2018. Writer: Halsey;Delacey;Louis Bell;Amy Allen;Justin Timberlake;Timbaland;Scott Storch.
15 ZAYN

Fingers flac

ZAYN. 2018. Writer: Zayn Malik;Alex Oriet;David Phelan.
16 Dewain Whitmore

Burn Out flac

Dewain Whitmore. 2018. Writer: Dewain Whitmore;Ilsey Juber;Emilio Behr;Martijn Garritsen.
17 Mako

Rise flac

Mako. 2018. Writer: Riot Music Team;Mako;Justin Tranter.
18 Bradley Cooper

Always Remember Us This Way flac

Bradley Cooper. 2018. Writer: Lady Gaga;Dave Cobb.
19 Blinders

Breach (Walk Alone) flac

Blinders. 2018. Writer: Dewain Whitmore;Ilsey Juber;Blinders;Martin Garrix.
20 Julia Michaels

There's No Way flac

Julia Michaels. 2018. Writer: Ian Kirkpatrick;Justin Tranter;Julia Michaels;Lauv.

Language

Popular Tags