# Watermarking selected content

I would like to add watermarks on any pages containing content between two markers or within some environment (or similar), ideally including any figures which might float onto later pages. Something similar to the below:

% Starting confidential marker
\section{Something confidential}
\lipsum % several pages, including floating figures or similar
% Ending confidential marker


Currently I am already using the draftwatermark package for watermarking the rest of my document, and would like to keep this, and overlay something identically over this too (perhaps on a different diagonal) but saying confidential and in capital red letters.

I've looked at the major watermarking packages (xwatermark, draftwatermark, etc.), but can't seem to find something capable of this. I suspect it might be achievable by noting the page numbers and using a solution similar to (adapted from this answer)

\newwatermark[pages=\firstpagemarker-\secondpagemarker,color=red!25,scale=3,xpos=0,ypos=0]{Confidential}


The issue with this is that it requires me to know the page ranges in advance, which I think can be hacked using a solution similar to this using table of content markers.

# Desirable features

I would like whatever watermarking solution proposed to not issue a \clearpage or similar. The effect of the watermarking should not disturb the format of the document.

Dealing with figures is a little more tricky. The first thing is that only pages with any content within the indicated confidential region have a watermark. If a page does not contain any of the content, then no watermark (blank pages within a confidential region can be marked). This implies that if a confidential figure floats several pages to after the last confidential content then the intermediate pages are not water marked.

A similar scenario is if a non-confidential figure spills into the confidential page range, and consumes the entire page without showing anything in the confidential content, then I would prefer such a page not to be marked confidential. I don't expect this to happen often, and don't regard this as needing to be satisfied as strictly as the previous requirements. (False positives are acceptable, false negatives are not).

Lastly, any referencing content created inside of the confidential range, like items in the index, table of contents, nomenclature, or similar should not be effected.

It should be safe to assume there will be no nested confidential material.

# Current attempt

\documentclass[english,a4paper,11pt,twoside,openright]{book}
\usepackage[]{draftwatermark}
\SetWatermarkScale{1}
\SetWatermarkLightness{0.8}
\usepackage{lipsum}
\usepackage{fancyhdr}
\usepackage{xwatermark}
\usepackage{xcolor}
\begin{document}
\section{Non-confidential stuff}
\lipsum
% Starting confidential marker
%% There won't be a clear page here <-- %%
\newwatermark[pages=\firstpagemarker-\secondpagemarker,color=red!25,angle=-45,scale=2.5,xpos=0,ypos=0]{CONFIDENTIAL}
\newcommand{\firstpagemarker}{\thepage}
\section{Something confidential}
\lipsum
\begin{figure}[htb] % making a big figure which I know will be pushed back a few pages.
\noindent\fbox{\begin{minipage}[t][0.8\textheight][c]{\dimexpr\textwidth-2\fboxsep-2\fboxrule\relax}
\centering Some floating figure which is also confidential
\end{figure}
% Ending confidential marker
\newcommand{\secondpagemarker}{\thepage}
\section{Normal stuff again}
\lipsum
\end{document}


In this example only pages 2,3,4 and 6 should have the confidential watermark.

Using background and an confidential environment

\documentclass[english,a4paper,11pt,twoside,openright]{book}

\usepackage{lipsum}
\usepackage{fancyhdr}
\usepackage[contents={}]{background}
\usepackage{xcolor}

\newenvironment{envconfidential}{
\newpage\backgroundsetup{contents={confidential}}
}
{\newpage\backgroundsetup{contents={}}}

\begin{document}

\section{Non-confidential stuff}
\lipsum[1-5]

\begin{envconfidential}
\section{Something confidential}
\lipsum[1-10]

\end{envconfidential}

\section{Normal stuff again}
\lipsum[1-5]

\end{document}


I added the newpage, so that you "catch" every confidential part with a background image.

• This was close to what I was after, but I don't want to issue a \newpage at the start or end of the environment, but I would like to have the document read as it normally would, but just with an overlay. Also, yours misses the spill over text on the top of page 4. I'll update my question shortly to make this feature more prominent. Jan 31, 2020 at 14:54
• Then just take out the newpage :) thats no problem. Jan 31, 2020 at 15:01
• Taking out the \newpage is closer to what I'm after, but it is still missing a few bits. Notably in the MWE the spill over lines on page 4 and the figure on page 6. I've updated the question to detail the requirements. Jan 31, 2020 at 15:10