# How to clear the background of just the current page?

eso-pic provides \AddToShipoutPictureBG to add content to the background at every page and \AddToShipoutPictureBG* to add it only to the current page. \ClearShipoutPicture clears all the content. But there is no \ClearShipoutPicture* to clear the content only for the current page.

I would like to show some content in every page but chapter pages. Using \AddToShipoutPictureBG{} when the chapter is created doesn't work, since the previous content is not cleared, it is just added. If I use \ClearShipoutPicture I need to know when the page is changed to add the content again. How should I do this?

I also tried background, but \NoBgThispage is not working. I could use

\backgroundsetup{contents={
\begin{tikzpicture}
...
\end{tikzpicture}
,angle=0
}}


instead of \AddToShipoutPictureBG{...} and \backgroundsetup{contents={}} instead of \ClearShipoutPicture. The results is pretty much the same.

MWE:

\documentclass[a4paper,twoside,openright]{report}
\usepackage{lipsum}
\usepackage{filecontents}
\begin{filecontents}{ch1.tex}
\lipsum[1-3]\section{First section ch1}\lipsum[4-10]
\end{filecontents}
\begin{filecontents}{ch2.tex}
\lipsum[11-14]\section{First section ch2}\lipsum[15-25]
\end{filecontents}
\usepackage[usenames,dvipsnames,svgnames,table]{xcolor}
\usepackage{xifthen}
\usepackage{totcount}
\usepackage{eso-pic}
\usepackage{tikz,bm}
\usetikzlibrary{shapes,arrows}
\usetikzlibrary{calc,positioning}

\regtotcounter{sidecnt} \newcounter{sidecnt}

\colorlet{sidecolor}{red!75}
\colorlet{sidelabelcolor}{blue}

\def\vsidemargin{3.5cm}

\begin{tikzpicture}[overlay]
\pgfmathsetmacro{\pheight}{(\paperheight-2*\vsidemargin)/28.453}
\pgfmathsetmacro{\myt}{-(\vsidemargin/28.453)-(\thesidecnt-1)/\totvalue{sidecnt}*\pheight}
\pgfmathsetmacro{\myb}{-(\vsidemargin/28.453)-\thesidecnt/\totvalue{sidecnt}*\pheight}
\ifthenelse{\isodd{\value{page}}}{\def\corner{east}\def\sign{-}}{\def\corner{west}\def\sign{+}}
\fill[sidecolor] ($(current page.north \corner)+(0,\myt)$) rectangle ($(current page.north \corner)+(\sign0.75,\myb)$);
\node[font=\normalfont\sffamily\bfseries] at ($(current page.north \corner)+(\sign0.375,\myt-0.5)$) {\color{sidelabelcolor}\thechapter};
\end{tikzpicture}
}

\newcommand\importchapter[2]{
\chapter{#1}
\stepcounter{sidecnt}
%\ClearShipoutPicture* alike
\input{#2}
}

\begin{document}

\importchapter{First chapter}{ch1.tex}
\importchapter{Second chapter}{ch2.tex}

\end{document}


I don't want the background to be shown in pages 1 and 5.

• Did you try the method explained in Gonzalo Medina's answer? There is a comment from the user there explaining that the method worked for them. If not, please provide a Minimum (non-)Working Example. If Gonzalo Medina is around, I am sure he will then be happy to help you. (And, if not, likely somebody else will be able to. But it is his package, after all.) – cfr Sep 22 '14 at 0:38
• OK. He was last seen almost a month ago. But I'm sure somebody will be able to help once you post some code. – cfr Sep 22 '14 at 0:40
• I checked Gonzalo Medina's answer, and commented there at first. But, since I saw that he has been out for a month I tried with eso-pic and then thought it would be better to open a new question. The difference between that question and this is that I'm actually using \input to get a new chapter, and I don't want to modify its content. I provided a MWE and added some details. – U.Martinez-Corral Sep 22 '14 at 1:06
• In that case, I recommend cheating ;). – cfr Sep 22 '14 at 2:05

You can cheat by adding a white rectangle the size of the page to the background on chapter pages to cover over the background picture rather than actually clearing it. Obviously, if you are printing on any colour of paper other than white, you'd need to match the colour. But hopefully that is not so and this will work:

\documentclass[a4paper,twoside,openright]{report}
\usepackage{lipsum}
\usepackage{filecontents}
\begin{filecontents}{ch1.tex}
\lipsum[1-3]\section{First section ch1}\lipsum[4-10]
\end{filecontents}
\begin{filecontents}{ch2.tex}
\lipsum[11-14]\section{First section ch2}\lipsum[15-25]
\end{filecontents}
\usepackage[usenames,dvipsnames,svgnames,table]{xcolor}
\usepackage{xifthen}
\usepackage{totcount}
\usepackage{eso-pic}
\usepackage{tikz,bm}
\usetikzlibrary{shapes,arrows}
\usetikzlibrary{calc,positioning}

\regtotcounter{sidecnt} \newcounter{sidecnt}

\colorlet{sidecolor}{red!75}
\colorlet{sidelabelcolor}{blue}

\def\vsidemargin{3.5cm}

\begin{tikzpicture}[overlay]
\pgfmathsetmacro{\pheight}{(\paperheight-2*\vsidemargin)/28.453}
\pgfmathsetmacro{\myt}{-(\vsidemargin/28.453)-(\thesidecnt-1)/\totvalue{sidecnt}*\pheight}
\pgfmathsetmacro{\myb}{-(\vsidemargin/28.453)-\thesidecnt/\totvalue{sidecnt}*\pheight}
\ifthenelse{\isodd{\value{page}}}{\def\corner{east}\def\sign{-}}{\def\corner{west}\def\sign{+}}
\fill[sidecolor] ($(current page.north \corner)+(0,\myt)$) rectangle ($(current page.north \corner)+(\sign0.75,\myb)$);
\node[font=\normalfont\sffamily\bfseries] at ($(current page.north \corner)+(\sign0.375,\myt-0.5)$) {\color{sidelabelcolor}\thechapter};
\end{tikzpicture}}

\newcommand\importchapter[2]{
\chapter{#1}
\stepcounter{sidecnt}
\begin{tikzpicture}[overlay,color=white]
\fill (current page.north east) rectangle (current page.south west);
\end{tikzpicture}}
\input{#2}}

\begin{document}

\importchapter{First chapter}{ch1.tex}
\importchapter{Second chapter}{ch2.tex}

\end{document}


• I was going mad trying to cheat with \newtoggles seen here to get to the same point :S. Thanks for that easier way. I won't tell anyone you recommended cheating ;). Hope Gonzalo will find how to fix it in future versions. – U.Martinez-Corral Sep 22 '14 at 2:16

This is the solution I came to, using a \newtoggle provided by the etoolbox package. The one provided by @cfr is straightforward and uses the commands provided by the eso-pic package, which is already used. However, this solution covers only the desired part, maintaining any other content which may be in the background. I though it would be good to have both answers published.

\documentclass[a4paper,twoside,openright]{report}
\usepackage{lipsum}
\usepackage{filecontents}
\begin{filecontents}{ch1.tex}
\lipsum[1-3]\section{First section ch1}\lipsum[4-10]
\end{filecontents}
\begin{filecontents}{ch2.tex}
\lipsum[11-14]\section{First section ch2}\lipsum[15-25]
\end{filecontents}
\usepackage[usenames,dvipsnames,svgnames,table]{xcolor}
\usepackage{xifthen}
\usepackage{totcount}
\usepackage{eso-pic}
\usepackage{tikz,bm}
\usetikzlibrary{shapes,arrows}
\usetikzlibrary{calc,positioning}

\regtotcounter{sidecnt} \newcounter{sidecnt}

\colorlet{sidecolor}{red!75}
\colorlet{sidelabelcolor}{blue}

\def\vsidemargin{3.5cm}

\begin{tikzpicture}[overlay]
\pgfmathsetmacro{\pheight}{(\paperheight-2*\vsidemargin)/28.453}
\pgfmathsetmacro{\myt}{-(\vsidemargin/28.453)-(\thesidecnt-1)/\totvalue{sidecnt}*\pheight}
\pgfmathsetmacro{\myb}{-(\vsidemargin/28.453)-\thesidecnt/\totvalue{sidecnt}*\pheight}
\ifthenelse{\isodd{\value{page}}}{\def\corner{east}\def\sign{-}}{\def\corner{west}\def\sign{+}}
\fill[sidecolor] ($(current page.north \corner)+(0,\myt)$) rectangle ($(current page.north \corner)+(\sign0.75,\myb)$);
\node[font=\normalfont\sffamily\bfseries] at ($(current page.north \corner)+(\sign0.375,\myt-0.5)$) {\color{sidelabelcolor}\thechapter};
\iftoggle{noSide}{ \fill[white] ($(current page.north \corner)+(0,\myt)$) rectangle ($(current page.north \corner)+(\sign0.75,\myb)$); }{} %added
\end{tikzpicture}
}

\newcommand\importchapter[2]{
\chapter{#1}