I'm using this solution provided here to clear the pagestyle when blank pages are introduced due to the usage of the openright option in the report class and the \cleardoublepage command:
\let\origdoublepage\cleardoublepage
\newcommand{\clearemptydoublepage}{\clearpage{\pagestyle{empty}\origdoublepage}}
\let\cleardoublepage\clearemptydoublepage
However, besides clearing the pagestyle, I'd like to display a note in the middle of the page. I've tried with eso-pic and tikz (to get it centered, taking the left and right margins into account):
\let\origdoublepage\cleardoublepage
\newcommand{\clearemptydoublepage}{
\clearpage{\pagestyle{empty}\AddToShipoutPictureBG*{
\begin{tikzpicture}[overlay]
\pgfmathsetmacro{\correct}{((\rmargin-\lmargin)/(2*28.453)}
\node[font=\normalfont] at ($(current page.center)+(\correct,0)$) {\blanknote};
\end{tikzpicture}
}
\origdoublepage}}
\let\cleardoublepage\clearemptydoublepage
Since \AddToShipoutPictureBG* gets executed before \origdoublepage, which is in fact \cleardoublepage, the note is added to the blank page, if inserted, or to the first page of the next chapter. I'd like to avoid the latter behaviour, i.e. not to execute \AddToShipoutPictureBG* if \origdoublepage does nothing.
I'm using eso-pic instead of background because \NoBgThispage is not working at the moment, and I use it to create other backgrounds, as exposed in this question. But I'm open to other approaches.
MWE (the incorrect behaviour is shown in page 5):
\documentclass[a4paper,titlepage,11pt,twoside,openright]{report}
\usepackage{lipsum}
\usepackage{eso-pic}
\def\lmargin{3.5cm}
\def\rmargin{1.5cm}
\def\blanknote{This page intentionally left blank}
\usepackage[left=\lmargin, right=\rmargin]{geometry}
\usepackage{tikz}
\usetikzlibrary{calc,positioning}
\let\origdoublepage\cleardoublepage
\newcommand{\clearemptydoublepage}{
\clearpage{\pagestyle{empty}\AddToShipoutPictureBG*{
\begin{tikzpicture}[overlay]
\pgfmathsetmacro{\correct}{((\rmargin-\lmargin)/(2*28.453)}
\node[font=\normalfont] at ($(current page.center)+(\correct,0)$) {\blanknote};
\end{tikzpicture}
}
\origdoublepage}}
\let\cleardoublepage\clearemptydoublepage
\begin{document}
Introduction text...
\chapter{First} \lipsum[1-9]
\chapter{Second} \lipsum[10-12]
\chapter{Third} \lipsum[15]
\end{document}