summaryrefslogtreecommitdiff
path: root/macros/latex/contrib/xwatermark
diff options
context:
space:
mode:
authorNorbert Preining <norbert@preining.info>2019-09-02 13:46:59 +0900
committerNorbert Preining <norbert@preining.info>2019-09-02 13:46:59 +0900
commite0c6872cf40896c7be36b11dcc744620f10adf1d (patch)
tree60335e10d2f4354b0674ec22d7b53f0f8abee672 /macros/latex/contrib/xwatermark
Initial commit
Diffstat (limited to 'macros/latex/contrib/xwatermark')
-rw-r--r--macros/latex/contrib/xwatermark/README51
-rw-r--r--macros/latex/contrib/xwatermark/doc/xwatermark-examples1.tex75
-rw-r--r--macros/latex/contrib/xwatermark/doc/xwatermark-examples2.pdfbin0 -> 179188 bytes
-rw-r--r--macros/latex/contrib/xwatermark/doc/xwatermark-examples2.tex201
-rw-r--r--macros/latex/contrib/xwatermark/doc/xwatermark-guide.pdfbin0 -> 512645 bytes
-rw-r--r--macros/latex/contrib/xwatermark/doc/xwatermark-guide.tex697
-rw-r--r--macros/latex/contrib/xwatermark/tex/xwatermark.sty2474
7 files changed, 3498 insertions, 0 deletions
diff --git a/macros/latex/contrib/xwatermark/README b/macros/latex/contrib/xwatermark/README
new file mode 100644
index 0000000000..f1361cf49e
--- /dev/null
+++ b/macros/latex/contrib/xwatermark/README
@@ -0,0 +1,51 @@
+This is the README file for the 'xwatermark' package.
+
+VERSION
+
+Version 1.5.2d, 23 October 2012
+
+LOCATION ON CTAN
+
+macros/latex/contrib/xwatermark
+
+SUMMARY
+
+This package puts user-specified watermarks (graphics and arbitrary
+texts) on select pages of documents. It is more general than the
+packages 'draftwatermark', 'watermark', 'draftmark', 'wallpaper' and
+similar packages. The advantages of xwatermark over these packages
+include: the user can specify the watermark and color, the watermark
+position and orientation, the page(s) (all pages, odd pages, even pages,
+a particular page number, and a range of pages) on which the watermark
+should appear, and all the options are passed directly to package instead
+of being defined by macros. Also, multiple text and/or picture watermarks
+(or wallpapers) can be put on the same page or range of pages with
+little effort.
+
+Among other macros, there are the macros \newwatermark and
+\newwallpaper, both of which can be used to dynamically specify
+watermark properties for each page or range of pages. With the
+'xcolor' package (not loaded by this package), all colors and
+those defined within the user document can be passed to this package.
+
+
+LICENSE
+
+Copyright (c) 2009-2012 Ahmed Musa (amusa22@gmail.com)
+
+This work (ie, all the files in the xwatermark manifest) may be
+distributed and/or modified under the conditions of the LaTeX
+Project Public License (LPPL), either version 1.3 of this license or
+any later version. The latest version of this license is in
+http://www.latex-project.org/lppl.txt and version 1.3 or later
+is part of all distributions of LaTeX version 2005/12/01 or later.
+
+The LPPL maintenance status of this software is 'author-maintained'.
+
+This software is provided 'as it is', without warranty of any
+kind, either expressed or implied, including, but not limited to,
+the implied warranties of merchantability and fitness for a
+particular purpose.
+
+
+
diff --git a/macros/latex/contrib/xwatermark/doc/xwatermark-examples1.tex b/macros/latex/contrib/xwatermark/doc/xwatermark-examples1.tex
new file mode 100644
index 0000000000..206b5bfdbc
--- /dev/null
+++ b/macros/latex/contrib/xwatermark/doc/xwatermark-examples1.tex
@@ -0,0 +1,75 @@
+%++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++%
+% This is file 'xwatermark-examples1.tex', version 1.5.2d. %
+% % % This work (ie, all the files in the xwatermark manifest) may be %
+% distributed and/or modified under the conditions of the LaTeX %
+% Project Public License, either version 1.3 of this license or any %
+% later version. The latest version of this license is at %
+% http://www.latex-project.org/lppl.txt and version 1.3 or later %
+% is part of all distributions of LaTeX version 2005/12/01 or later. %
+% %
+% The LPPL maintenance status of this software is 'author-maintained'. %
+% %
+% This software is provided 'as it is', without warranty of any kind, %
+% either expressed or implied, including, but not limited to, the %
+% implied warranties of merchantability and fitness for a particular %
+% purpose. %
+% %
+% Copyright (c) 2009-2012 Ahmed Musa (amusa22@gmail.com). %
+%++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++%
+
+\documentclass[a4paper,10pt,final,showpagenos]{article}
+\makeatletter
+\InputIfFileExists{xwatermark-examples.cfg}{}{%
+ \errmessage{No file xwatermark-examples.cfg or wrong path}}
+\xnewwatermark[pages={\lastdocpage-1}-\lastdocpage,fontfamily=phv,fontsize=11pt,
+ fontseries=m,align=center,height=\paperheight,width=\paperheight,
+ angle=90,scale=1,xpos=1.15,ypos=0]{\usecsn{watermark-4}}
+\xnewwatermark*[pagex={3,5,7},fontfamily=phv,fontsize=11pt,
+ fontseries=m,align=center,height=\paperheight,width=\paperheight,
+ angle=0,scale=1,xpos=0,ypos=40]{\usecsn{watermark-7}}
+\xnewwatermark[page=1,fontfamily=phv,fontsize=11pt,
+ fontseries=m,align=center,height=\paperwidth,width=\paperheight,
+ angle=90,scale=1,xpos=1.15,ypos=0]{\usecsn{watermark-2}}
+\xnewwatermark[page=3,fontfamily=phv,fontsize=11pt,fontseries=m,align=center,
+ height=\paperheight,width=.7\paperheight,angle=45,scale=1,xpos=0,
+ ypos=0]{\usecsn{watermark-5}}
+\xnewwatermark[evenpages,fontfamily=phv,fontsize=11pt,fontseries=m,align=center,
+ height=\paperheight,width=\paperheight,angle=45,scale=1,xpos=1,
+ ypos=0]{\usecsn{watermark-3}}
+
+\begin{document}
+
+\title{%
+ {\setbox\z@\vbox to.25\paperheight{}\box0}%
+ \bfseries The \texttt{\ttcl{blue}{xwatermark}} Package
+ \xcopyright{red}\\[1ex]
+ \large Version 1.5.2d\\[2ex]
+ \Large EXAMPLES (File 1)%
+}
+\author{%
+ \textbf{Ahmed Musa}\\Preston, United Kingdom\\
+ \email{amusa22@gmail.com}
+}
+\maketitle
+
+\thispagestyle{empty}
+
+\newpage
+\noindent
+\ltslipsum[1-3]
+
+\newpage
+\ltslipsum[1-4]
+
+\newpage
+\ltslipsum[1-4]
+
+\newpage
+\ltslipsum[1-4]
+
+\newpage
+\ltslipsum[1-4]
+
+\newpage
+\ltslipsum[1-4]
+\end{document}
diff --git a/macros/latex/contrib/xwatermark/doc/xwatermark-examples2.pdf b/macros/latex/contrib/xwatermark/doc/xwatermark-examples2.pdf
new file mode 100644
index 0000000000..c90e563f25
--- /dev/null
+++ b/macros/latex/contrib/xwatermark/doc/xwatermark-examples2.pdf
Binary files differ
diff --git a/macros/latex/contrib/xwatermark/doc/xwatermark-examples2.tex b/macros/latex/contrib/xwatermark/doc/xwatermark-examples2.tex
new file mode 100644
index 0000000000..169904b799
--- /dev/null
+++ b/macros/latex/contrib/xwatermark/doc/xwatermark-examples2.tex
@@ -0,0 +1,201 @@
+%++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++%
+% This is file 'xwatermark-examples2.tex', version 1.5.2d. %
+% %
+% This work (ie, all the files in the xwatermark manifest) may be %
+% distributed and/or modified under the conditions of the LaTeX %
+% Project Public License, either version 1.3 of this license or any %
+% later version. The latest version of this license is at %
+% http://www.latex-project.org/lppl.txt and version 1.3 or later %
+% is part of all distributions of LaTeX version 2005/12/01 or later. %
+% %
+% The LPPL maintenance status of this software is 'author-maintained'. %
+% %
+% This software is provided 'as it is', without warranty of any kind, %
+% either expressed or implied, including, but not limited to, the %
+% implied warranties of merchantability and fitness for a particular %
+% purpose. %
+% %
+% Copyright (c) 2009-2012 Ahmed Musa (amusa22@gmail.com). %
+%++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++%
+
+\documentclass[final,showpagenos]{article}
+\makeatletter
+
+\InputIfFileExists{xwatermark-examples.cfg}{}{%
+ \errmessage{No file xwatermark-examples.cfg or wrong path}}
+
+\thispagestyle{empty}
+
+%\watermarkpaths*[.](/){{},/Graphics}
+\watermarkpaths[.](/){{}{/Graphics}}
+
+\newwatermark*[%
+ page=2,fontfamily=put,textcolor=BurntOrange,fontsize=1cm,
+ textscale=1,textalign=center,textangle=45,picangle=90,
+ picontoptext=false,boxalign=center,picxpos=50,
+ picypos=.25\paperheight,textxpos=-70,textypos=-50,
+ picbb=116 428 477 718,picscale=1,picfile=tabu-test1,
+ picfileext=eps
+]{\ttcl{Green}{\texttt{xwatermark\\package}}}
+
+\newwallpaper[%
+ page=2,fontfamily=put,textcolor=BurntOrange,fontsize=1cm,
+ textscale=2,textalign=center,textangle=45,picangle=45,
+ tilexoffset=0pt,squaretiles,tileyoffset=0pt,picontoptext=true,
+ boxalign=center,picbb=54 54 483 242,picscale=2,picfile=fant,
+ tileno=4,picfileext=epsx,graphicsoptions={keepaspectratio,hiresbb}
+]{\texttt{fant}}
+
+
+% * (star) means 'put on foreground';
+% ' (prime) means 'ignore this mark':
+\newwallpaper*[%
+ page=3,fontfamily=put,textcolor=BurntOrange,fontsize=1cm,textscale=2,
+ textalign=center,textangle=45,picangle=45,tilexoffset=0pt,%squaretiles,
+ tileyoffset=0pt,picontoptext=false,boxalign=center,
+ picbb=116 428 477 718,picscale=2,picfile=tabu-test1,tileno=4,
+ % The package will look for the right file extension in each mode,
+ % ignoring the following 'epsx':
+ picfileext=epsx
+]{\texttt{test}}
+
+\newwallpaper[%
+ page=5,fontfamily=put,textcolor=BurntOrange,fontsize=1cm,textscale=2,
+ textalign=center,textangle=0,picangle=0,tilexoffset=0pt,squaretiles,
+ tileyoffset=0pt,picontoptext=false,boxalign=center,showpagecenter,
+ picbb=116 428 477 718,picscale=2,picfile=tabu-test1,tileno=4,
+ picfileext=eps
+]{\texttt{test}}
+
+\newwallpaper*[%
+ page=4,fontfamily=put,textcolor=violet!70,fontsize=1cm,textscale=1,
+ textalign=center,textangle=45,picangle=0,tilexoffset=0pt,squaretiles,
+ tileyoffset=0pt,picontoptext=false,boxalign=center,%top-left,
+ picbb=20 21 590 400,picscale=1,picfile=comet1,%tileno=8,
+ picfileext=epsx
+]{Comet}
+
+\dummywallpaper[%
+ page=5,fontfamily=put,textcolor=BurntOrange,fontsize=1cm,textscale=2,
+ textalign=center,textangle=45,picangle=45,squaretiles,tilexoffset=0pt,
+ tileyoffset=0pt,picontoptext=false,%boxalign=l-t,
+ picbb=115 623 238 747,picscale=2,picfile=xwatermarkpic1,
+ picfileext=eps
+]{YES}
+
+\newwatermark[%
+ pages=4,fontfamily=put,textcolor=blue,fontsize=1.2cm,textscale=1,
+ width=.8\paperheight,textalign=center,textangle=90,textxpos=0,textypos=0
+]{%
+ \xwmcolorbox[framesep=4pt,framerule=4pt,fillcolor=brown!70!yellow!55,
+ innerframecolor=white,outerframecolor=blue,height=1.5cm,
+ depth=1cm,textalign=center,width=.8\paperheight]%
+ {\tt\string\advance\ttcl{red}{\string\knowledge}%
+ \string\by\ttcl{red}{\string\inquiry}}%
+}
+
+\newwatermark[%
+ page=6,fontfamily=put,textcolor=BurntOrange!70,fontsize=1cm,textscale=2,
+ picbb=78 563 304 788,picscale=2,picfile=xwatermarkpic3,
+ picfileext=epsx,width=\paperwidth,textalign=center,textangle=0,
+ textxpos=0,textypos=0,picontoptext=false
+]{\ttcl{black}{Yes}}
+
+\newwatermark*[%
+ page=6,fontfamily=put,textcolor=violet!70,fontsize=2cm,textscale=1,
+ width=\paperwidth,textalign=center,textangle=0,textxpos=0,textypos=0
+]{\fbox{Brought to front}}
+
+\newwatermark[%
+ page=7,fontfamily=put,textcolor=MidnightBlue!80,fontsize=2cm,textscale=1,
+ width=\paperwidth,textalign=center,textangle=-50,textxpos=-30,textypos=80
+]{\fbox{Taken to back}}
+
+\csndef*{watermark-2a}#1#2{%
+ \newwatermark[%
+ pages=6-7,fontfamily=pbk,textcolor=gray!35,fontsize=12pt,fontseries=n,
+ textalign=center,textangle=#2,textscale=1,textxpos=#1,textypos=0,
+ width=\paperheight
+ ]{%
+ \xwmcolorbox[framesep=5pt,framerule=2pt,fillcolor=teal,
+ innerframecolor=magenta,outerframecolor=green,
+ textalign=center,width=.98\paperheight]%
+ {%
+ \color{white}\framebox[2cm][t]{\phantom{Hello}}\hspace{1cm}%
+ \color{orange!85!red!55}\ttcl{red}{$\blacktriangleright$}%
+ \hspace{2.1cm}Page \thepage~of~\pageref{xwmlastpage}%
+ \hspace{2.1cm}\ttcl{red}{$\blacktriangleleft$}\hspace{1cm}%
+ \color{white}\framebox[2cm][t]{\phantom{Hello}}%
+ \xwmstrut{9mm}{6mm}%
+ }%
+ }%
+}
+
+\begin{ltscomment}
+The same watermark is placed twice on the same page.
+Compare this with one of the examples in xwatermark-examples1.tex:
+\end{ltscomment}
+
+\usecsn{watermark-2a}{-.428\paperwidth}{90}
+\usecsn{watermark-2a}{.428\paperwidth}{-90}
+
+\begin{ltscomment}
+Here is an inefficient example. \scalebox and \rotatebox
+could have been more efficiently achieved in the following
+example:
+\end{ltscomment}
+\newwatermark[page=\lastdocpage,width=\paperheight]{%
+ \setbox\xwm@boxb=\hb@xt@.9\paperheight{%
+ \hfuzz\maxdimen\hss
+ \xwmcolorbox[framesep=4pt,framerule=4pt,fillcolor=brown!70,
+ innerframecolor=white,outerframecolor=MidnightBlue,height=1cm,
+ depth=.8cm,textalign=center,width=.8\paperheight]%
+ {\scalebox{1.2}{\bf\tt\ttcl{white}{\char`\\advance}%
+ \ttcl{red}{\string\knowledge}%
+ \string\by\ttcl{blue}{\char`\\inquiry}}}\hss}%
+ \begin{center}\rotatebox{45}{\box\xwm@boxb}\end{center}%
+}
+
+\begin{document}
+
+\title{%
+ {\setbox\z@\vbox to.25\paperheight{}\box0}%
+ \bfseries The \texttt{\ttcl{blue}{xwatermark}} Package
+ \xcopyright{red}\\[1ex]
+ \large Version 1.5.2d\\[2ex]
+ \Large EXAMPLES (File 2)%
+}
+\author{%
+ \textbf{Ahmed Musa}\\Preston, United Kingdom\\
+ \email{amusa22@gmail.com}
+}
+\maketitle
+\thispagestyle{empty}
+
+\newpage
+
+\ltslipsum[1-4]
+
+\ltslipsum
+
+\newpage
+
+\ltslipsum[1-4]
+
+\newpage
+
+\ltslipsum[1-4]
+
+\newpage
+
+\ltslipsum[1-4]
+
+\newpage
+
+\ltslipsum[1-4]
+
+\newpage
+
+\ltslipsum[1-4]
+
+\end{document}
diff --git a/macros/latex/contrib/xwatermark/doc/xwatermark-guide.pdf b/macros/latex/contrib/xwatermark/doc/xwatermark-guide.pdf
new file mode 100644
index 0000000000..adc639a2f7
--- /dev/null
+++ b/macros/latex/contrib/xwatermark/doc/xwatermark-guide.pdf
Binary files differ
diff --git a/macros/latex/contrib/xwatermark/doc/xwatermark-guide.tex b/macros/latex/contrib/xwatermark/doc/xwatermark-guide.tex
new file mode 100644
index 0000000000..8c4ad0556e
--- /dev/null
+++ b/macros/latex/contrib/xwatermark/doc/xwatermark-guide.tex
@@ -0,0 +1,697 @@
+\makeatletter
+\documentclass[
+ use-a4-paper,
+ use-10pt-font,
+ final-version,
+ use-UK-English,
+ fancy-section-headings,
+ frame-section-numbers,
+ para-abstract-style,
+ input-config-file,
+ no-hyperref-messages,
+ option-stack-limit=4,
+ inputfile=true,
+]{amltxdoc}
+
+\makeindex
+\ifdefTF\newgeometry{}{%
+ \let\newgeometry\@gobble
+ \let\restoregeometry\relax
+}
+
+
+\begin{document}
+
+\begin{frontmatter}
+\title{The \texttt{\color{blue}xwatermark} Package\titleref{t1}}
+\subtitle{\textsf{A dynamic watermarking scheme for \latex}}
+\titlenote[t1]{The package is available at \url{\titleurltext}.}
+\version{1.5.2d}
+\titleurl{http://mirror.ctan.org/macros/latex/contrib/xwatermark/}
+\author{Ahmed Musa\Email{amusa22@gmail.com}\\
+ {\small The University of Central Lancashire, Preston, UK}}
+
+\let\abstractname\relax
+\begin{abstract}
+\makecolorbox[framesep=4pt, framerule=1pt, innerframecolor=red!55,
+ outerframecolor=ForestGreen, align=justified, fillcolor=white,
+ width=\textwidth, boxalign=center, height=.25cm, depth=0cm,framebox]{%
+ \centering\xwmcolorbox[align=center, fillcolor=white, innerframecolor=blue, outerframecolor=orange, width=.5\hsize, height=2.5mm]{\textbf{Abstract}} \\[\baselineskip]
+ The \pkg{xwatermark} package puts user-supplied watermarks (graphics and/or arbitrary texts) on select pages of documents using user-friendly key-value interfaces. It has more functionality and dynamism than, for example, the packages \pkg{draftcopy, draftwatermark, watermark, draftmark, wallpaper}. More than one (graphics and/or text) watermark can be placed jointly or independently on the same document page or on select pages. Watermarks can be placed in the page background or foreground, and watermarks can conveniently be placed on select pages as rectangular or square tiles, depending on the user's choice. Some utility macros, namely, \ffx'{\xwmminipage, \xwmcolorbox, \makecolobox, \fancypagenos} are also provided by the package for handy use in creating watermarks and for other uses. Watermarks (especially wallpapers) take their toll on computer resources, especially speed and save stack size. The packages in the \pkg{xwatermark} bundle (and beyond) have been optimized as much as currently possible. In many instances more than one run of the document will be needed to get the watermarks on the desired pages, especially if the user calls \fx{\lastdocpage} to get the last page of the document.
+}
+\end{abstract}
+\end{frontmatter}
+
+\noindent
+
+\xwmcolorbox[framesep=5pt,framerule=2pt,fillcolor=white,
+ outerframecolor=purple,innerframecolor=brown,textalign=justified,
+ width=.97\textwidth]{%
+ \normalfont\small\color{black}\vspace*{-1ex}%
+ \begin{center}\colorbullet{red}\hspace{1cm}\licensename\hspace{1cm}%
+ \colorbullet{red}\end{center}\vspace*{1ex}%
+ This work (\ie, all the files in the \pkg{xwatermark} manifest) may be distributed and/or
+ modified under the conditions of the \lppl, either version~1.3 of this license or any later
+ version. The \lppl maintenance status of this software is \quoted{author-maintained}. This
+ software is provided \quoted{as it is}, without warranty of any kind, either expressed or
+ implied, including, but not limited to, the implied warranties of merchantability and
+ fitness for a particular purpose. \CopyrightYear
+}
+
+\xwmcolorbox[framesep=5pt,framerule=2pt,fillcolor=white,
+ outerframecolor=purple,innerframecolor=brown,textalign=justified,
+ width=.97\textwidth]{%
+ \begingroup
+ \hypersetup{linkcolor=blue}\tableofcontents
+ \endgroup
+}
+
+
+\docsection(sec:newfeatures){New features}
+
+Enter \ffx'{\xwmwatermarkon,\xwmwatermarkoff} for suspending and resuming watermark placement on pages.
+
+
+
+\docsection(sec:intro){Introduction}
+
+\lletter{T}{he \pkg'{xwatermark}} puts user-specified watermarks (graphics and/or arbitrary texts) on select pages of documents. It has more functionality and dynamism than, for example, the packages \pkg'{draftcopy, draftwatermark, watermark, draftmark,wallpaper}. The advantages of \pkg'{xwatermark} over these earlier packages include:
+
+\begin{enum}
+\item Both text and graphics watermarks are admissible within any watermark item or instance.
+\item The user can dynamically customize the attributes (color, position, orientation, scale, the page(s)---first page, last page, all pages, odd pages, even pages, a particular page, and a range of pages---on which the watermark should appear) of each watermark.
+\item Watermarks can be placed in the background and in the foreground of document pages by simple instructions.
+\item Rectangular and square wallpapers can be produced from watermarks to suit user needs without effort.
+\item All the command options/keys are passed directly via user-friendly key-value interfaces, instead of being defined in the source file by several macros. There are only two main user commands: \ffx'{\newwatermark, \newwallpaper}. The user is relieved of the need to remember and deploy several different macros, except, of course, that function keys are used. The list of keys and their default values for these functions are given in \sref{sec:packageoptions}.
+\end{enum}
+
+With the \pkg'{xcolor} (not loaded automatically by the \pkg'{xwatermark}), all colors (including \hx{white}, shades like \hx{-red!75!green!50}, and those defined within the user document) can be passed to this package. And, as mentioned above, both texts and pictures can be submitted and printed as watermarks on the same page, and on different positions.
+
+There are global and local package options. These are listed and explained in
+\sref{sec:packageoptions}.
+
+Users who have since complained of not being able to conveniently place more than one watermark on the same page can now heave a sigh relieve: the current version of the package has enabled this functionality. You can now mix text and graphics watermarks and wallpapers and place as many of them as you like on the same page. This version of the package comes with optimized looping macros and a key management system (the \pkg'{ltxkeys}) to enable several watermarks and wallpapers to be placed efficiently on the same document pages. The \pkg'{ltxkeys} can be used for general key parsing.
+
+
+\docsection(sec:user-interface){User interfaces}
+
+\docsubsection{Loading the package}
+
+In style files the package may be loaded with \hx{\RequirePackage} and in document files with \hx{\usepackage} together with the package keys that can be passed as options.
+
+\ltsnote Some of the keys are \quoted{option keys}, \ie, they can appear only in \hx{\documentclass} or \hx{\usepackage} and not as, or in, arguments of other functions or macros. The \quoted{non-option keys} are those that can't appear in \hx{\documentclass} or \hx{\usepackage} but in the arguments of other macros. If a key is a non-option key and the user submits it to \hx{\documentclass} or \hx{\usepackage}, the package will alert the user. The same thing can be expected when a key is an option key and is submitted outside of \hx{\documentclass} or \hx{\usepackage}. The \quoted{need value} keys are keys that can't be called without a user-supplied value.
+
+The package keys \ffx'{printwatermark, disablegeometry} are option keys, and hence can be called as follows:
+
+\start'{example}[Package loading]
+\RequirePackage[printwatermark,disablegeometry]{xwatermark}|label(mac:pkgload)
+\usepackage[printwatermark,disablegeometry]{xwatermark}
+\finish{example}
+
+The other options may be submitted via user commands like \ffx'{\newwatermark, \newwallpaper}. Please see \srefrange[tab:]{globaloptions,localoptions} for a full listing of all the available package and command options. By design, the boolean option \fx{printwatermark} should not appear in the macros \ffx'{\newwatermark, \newwallpaper} but as a package or \hx{\documentclass} option. It is disabled just before \hx{\begin{document}} and any attempt to pass it via \fx{\newwatermark} or \fx{\newwallpaper} thereafter will trigger an error.
+
+When boolean options (\eg, \ffx'{printwatermark,allpages}) are passed without values, they are assumed implicitly \hx{true} by the package.
+
+\ltsnote When your watermark is not printed, first check that the option \fx{printwatermark} is \texttt{true}. This is one of the means to control the printing of watermarks. The others are through the following commands (more details are available in \sref{sec:dummywatermarks}):
+
+\start+'{newmacro}[\dummywatermark, \DiscardAllWatermarks, etc]
+\dummywatermark, \DiscardAllWatermarks, \UseDummyWatermarks,
+\DiscardDummyWatermarks
+\finish{newmacro}
+\fxi*{\dummywatermark, \DiscardAllWatermarks,
+ \UseDummyWatermarks, \DiscardDummyWatermarks}
+
+The option \fx{textmark} implies text watermarks, for which all the font properties can be selected. It does not apply to graphics watermarks. For graphics watermarks you need the keys: \fx{picfile} (the graphics/picture filename, with its full path but without its extension), and \fx{picfileext} (the file extension). Admissible file extensions are \hhx'{ps,eps,pdf,png,mps,jpeg}; they should be submitted without the dot. The extensions \hhx'{ps,eps} are for \hx{dvi} files, while the rest are for \hx{pdf} runs. Additional information is needed (see \sref{sec:pic-watermark})\footnote{When the options \ffx'{align ,height, width, angle, scale, xpos, ypos, color} appear without prefixes such as \fx{pic} or \fx{text}, they refer to the text watermark and not the graphics watermark. The user can thus use these options in place of \ffx'{textalign,textheight,textwidth, textangle, textscale, textxpos, textypos, textcolor}, respectively. However, options referring to graphics watermarks must always be prefixed with \fx{pic} (\eg, picfile).}.
+
+The following points should be noted about the values of the \fx{textmark}:
+
+\begin{enum}
+\item The value of the \fx{textmark} may be any arbitrary multi-line text, such as
+
+\start{example}[textmark]
+textmark=Hello world,\\[.25\baselineskip] We're here.
+\finish{example}
+
+\item The value of \fx{textmark} may be arbitrary (blocks of) texts or even kernel or package commands, but not filenames on their own (except when submitted as values of graphics keys). The package has a user-friendly interface for inserting graphics watermarks and wallpapers, which does not require the user to directly employ \hx{\includegraphics}.
+\item The \ffx'{textwidth, picwidth} should be properly selected to match user's taste and the length of the \fx{textmark}. It may be set to \hx{\paperwidth} or \hx{\paperheight}, or any arbitrary length. Its default value is preset to \hx{\paperheight}. Sometimes it might also be necessary to suitably select the \fx{height}, whose default value is \hx{\paperwidth}.
+\item If the longest line of a \fx{textmark} is longer than \hx{\paperwidth} and/or \hx{\paperheight} (depending on the orientation of the \fx{textmark}), then the \fx{fontsize} and the \fx{textscale} (or \fx{picscale}) options will have to be suitably chosen.
+\end{enum}
+
+The boolean options \ffx'{firstpage,lastpage,allpages, firstpage, oddpages, evenpages},
+which specify the pages that should receive watermarks, may be replaced by any of the options \ffx{page=x, pages=x-y, pagex={x,y,z}}, where \quoted{\fx{x}}, \etcc, stand for any page number. If you enter, for example, \fx{pages=0-10}, all pages from 1~to 10 will receive the watermark. On the other hand, an entry like \fx{pages=10-0} will print watermark on page 10 only. If no page-specifying option is given and \fx{printwatermark} is true, watermark will appear only on the first page and a warning message will be entered in the transcript file. When passing \fx{page=x} or \fx{pages=x-y} as option to package, don't forget to include the equality sign (\fx{=}), otherwise the option will trigger an \quoted{unknown option/key} error. The key \fx{pages} expects a page range with the pages separated by a hyphen, while \fx{pagex} expects a comma-separated list of pages. For obvious reasons, the value of the key \fx{pagex} must always be given in balanced curly braces.
+
+When specifying package options either in \hx{\usepackage} or \hx{\documentclass} (or indeed in the macros \ffx'{\newwatermark, \newwallpaper, \xwmminipage,\xwmcolorbox, \fancypagenos}), the following points should be noted:
+
+\begin{enum}
+\item Multiple lines are permitted but not blank lines.
+\item Extra paces between options and words are ignored.
+\item Active characters (those of catcode~13) may be allowed (but see \sref{sec:activechar} for further comments).
+\item Options are mostly order-agnostic, except \fxi{graphicsoptions}, whose values take precedence over those supplied via other keys (see \sref{sec:graphicsoptions}).
+\end{enum}
+
+
+The global boolean option \fx{printwatermark}=\hx{true} (or \hx{=false}) should ideally be set when loading the package, \eg,
+
+\start'{example}[Package option: printwatermark]
+\usepackage[printwatermark]{xwatermark}
+\finish{example}
+
+or in the \hx{\documentclass} options list:
+
+\start'{example}[Package option: printwatermark]
+\documentclass[a4paper,12pt,printwatermark]{article}
+\usepackage{xwatermark}.
+\finish{example}
+
+The remaining options should ideally be set dynamically using the macro \fx{\newwatermark} or \fx{\newwallpaper}. These other options can be set for each page, as on the pages of the accompanying example files.
+
+
+\docsection(sec:newwatermarks){The \headfx{\newwatermark} macro}
+
+The use syntax for the command \fx{\newwatermark} is as follows
+
+\start{newmacro}[\newwatermark]
+\newwatermark[|A(keyval)]{|A(mark)}
+\newwatermark|R(*')[|A(keyval)]{|A(mark)}
+\finish{newmacro}
+\fxi*{\newwatermark}
+
+where \ang{keyval} is the list of keys and their values (called the watermark attributes) and \ang{mark} is the text watermark. Graphics watermarks are to be specified with their file name, file extension, \etcc. The full lists of the available keys for the macro \fx{\newwatermark} and others are available in \sref{sec:packageoptions}.
+
+The \stform of \fx{\newwatermark} puts the watermark in the foreground instead of the background, and the \pmform is ignored, \ie, no watermark is produced (see \sref{sec:dummywatermarks}).
+
+The macro \fx{\newwatermark} can be used as in
+
+\start{example}[\newwatermark]
+\newwatermark[|R(pagex)={2,5,7},fontfamily=bch,color=gray!25,angle=45,scale=3,
+ xpos=0,ypos=0]{DRAFT},
+\finish{example}
+
+where the \fx{textmark} has been enclosed in curly braces as the last argument of the macro. The options (called the watermark attributes) are expected in square brackets. The \fx{textmark} (which is \quoted{DRAFT} in the above example) can also be given within square brackets, in which case the curly braces will be empty:
+
+\start{example}[\newwatermark]
+\newwatermark|R(*)[page=10,fontfamily=bch,color=gray!25,angle=45,scale=3,xpos=0,
+ ypos=0,textmark=DRAFT]{}.
+\finish{example}
+
+The option \fx{printwatermark} may appear in only \fx{\usepackage} or \hx{\documentclass} options list, since it is disabled at \hx{\begin{document}}. However, the options \ffx'{firstpage, lastpage, allpages, oddpages, evenpages}, \etcc, which specify watermark pages, can and should appear in the command \fx{\newwatermark}. This implies that the instructions that specify watermark pages may be issued and superseded dynamically (page by page or chapter by chapter). For small documents, this feature may be unnecessary, but it will be useful in large documents (such as a report or book), in which the watermark may change from chapter to chapter.
+
+When you want the watermark on only one page of the document, you can conveniently use the \fx{\newwatermark} macro with the page option \mbox{\fx{page}=\ang{no}} in the preamble of your document after issuing
+
+\start+{example}[\usepackage,printwatermark]
+\usepackage[printwatermark]{xwatermark}
+\finish{example}
+
+In this way, you don't have to bother with locating in the source file the spot that corresponds to the page on which you want the watermark to appear. In fact, you can collect all the watermarks in the document preamble or in a configuration file with the command \fx{\newwatermark}.
+
+\ltsnote Each call to \fx{\newwatermark} must contain the page(s) that will receive the watermark(s), otherwise the user will be alerted. The page specifiers are:
+
+\start'{syntax}[page specifiers]
+page=x pages=x-y pagex={x,y,z} firstpage
+lastpage allpages oddpages evenpages
+\finish{syntax}
+
+
+\docsubsection{Options without values}
+
+If you follow an option key with an equality sign but without a value, as in, \eg,
+
+\start{example}[\newwatermark]
+\newwatermark[firstpage,fontfamily=,color=gray!25,angle=45,scale=0.8,
+ xpos=0,ypos=0,textmark=]{},
+\finish{example}
+
+then there will be no problem but the outcome may be unpredictable, depending on the key that has no value. In the above example, no watermark will be printed (not even the default mark, which is \fx{DRAFT}) because empty textmark is valid and implies that no watermark should be printed. The absence of \texttt{fontfamily} in \quoted{\fx{fontfamily=}} will compel \texorlatex to use an arbitrary \texttt{fontfamily} that isn't the default (the default \texttt{fontfamily} is \fx{phv} if the key \fx{fontfamily} is not passed, and \fx{cmr} otherwise).
+
+
+\docsubsection{Emptying the watermarks of some pages or objects}
+
+If you issue any of the statements
+
+\start{syntax}[page specifiers]
+page=x pages=x-y pagex={x,y,z} firstpage
+lastpage allpages evenpages oddpages
+allpages=true evenpages=true oddpages=true
+\finish{syntax}
+
+together with \fx{printwatermark}=\hx{true} but you don't want the mark on any particular page, you can simply set \fx{\newwatermark[other keys,textmark=]{}} or, to the same effect, you may set \fx{\newwatermark[other keys]{}}, where \quoted{other keys} may include the page specifiers\footnote{In the case of graphics watermarks, setting \ftfx{\newwatermark[other keys,picfile=]{}} will prompt a \quoted{no file} error.}. These both imply that the text watermark for the given page is empty. This can be useful when transiting from one watermark type to another. Moreover, since both picture and text marks can be submitted via one and the same command \fx{\newwatermark} (see \sref{sec:pic-text-mark}), this technique may be used to empty the text watermark for the given page or range of pages. For example,
+
+\start{example}[\newwatermark]
+\newwatermark[allpages,fontfamily=put,color=white,fontsize=3cm,scale=1,
+ picbb=112 619 242 751,picscale=3,picfile=./graphics/myfig,picfileext=eps,
+ width=\paperheight,align=center,angle=0,xpos=0,ypos=0]{}
+\finish{example}
+
+will print only the picture watermark, since the \fx{textmark} is empty here.
+
+
+\docsubsection(sec:pic-text-mark){Printing both picture and text watermarks on same page}
+
+Both picture and text marks can be submitted and printed on the same page via one and the same \fx{\newwatermark}. For example,
+
+\start{example}[\newwatermark]
+\newwatermark[pages=1-2,fontfamily=put,color=white,fontsize=3cm,scale=1,
+ picbb=112 619 242 751,picscale=3,picfile={./graphics/myfig},
+ picfileext=eps,width=\paperheight,align=center,angle=0,xpos=0,
+ ypos=0]{Hello World}
+\finish{example}
+
+However, both the picture and text marks will then share the same subset of the attributes (position, angle, align, \etcc). When text and graphics watermarks appear on the same page, the recommended approach is to submit the two types of watermark by two separate calls to \fx{\newwatermark}.
+
+
+\docsubsection{The usefulness of the \headhx{white} color}
+
+You can deploy the white color to great effect in designing text watermarks. Also, if you set \fx{allpages}=\hx{true} or \fx{evenpages}=\hx{true} or \fx{oddpages=true} together with \fx{printwatermark}=\hx{true} but you don't want the mark on any particular page, you can simply enter \fx{color=white} in the \fx{\newwatermark} on that page. This applies only to text watermarks, as such a declaration has no effect on picture watermarks. This may be convenient in circumstances where you may change your mind as to whether to place a watermark on a particular page or not. In this way you don't have to set \fx{\newwatermark[other keys,textmark=]{}} or remove (or comment out) the \fx{\newwatermark} command for that (or indeed any) page. See also \sref{sec:dummywatermarks}.
+
+
+\docsubsection(sec:dummywatermarks){Dummy watermarks}
+
+When you don't need a watermark printed, you can simply replace its \fx{\newwatermark} with \fx{\dummywatermark}, instead of commenting out the entire watermark or using \fx{color=white}. Both the macros \fx{\newwatermark} and \fx{\dummywatermark} have the same syntax and expect the same number and types of arguments:
+
+\start{newmacro}[\dummywatermark]
+\dummywatermark[pages=12-13,fontfamily=phv,fontsize=11pt,fontseries=m,
+ align=center,height=\paperheight,width=\paperwidth,angle=90,scale=1,
+ xpos=0,ypos=-1
+]{Example}
+\finish{newmacro}
+\fxi*{\dummywatermark}
+
+And when you don't want any of your watermarks printed, you could simply issue the option \fx{printwatermark}=\hx{false} or call the command \fxi{\DiscardAllWatermarks}. These will simply turn all instances of \fx{\newwatermark} command into \fx{\dummywatermark}. In any run, you may decide to use some or all of the dummy watermarks. To use all dummy watermarks, you issue the command \fxi{\UseDummyWatermarks} before the instances of \fx{\dummywatermark}. To again disregard all subsequent dummy watermarks, which is the default state, simply call the command \fxi{\DiscardDummyWatermarks}. These commands provide a convenient scheme for deciding the watermarks to be printed with minimal typing. For wallpapers, there is the corresponding command \fxi{\dummywallpaper}. Also, putting a prime sign (\Redprime) on \fx{\newwatermark} or \fx{\newwallpaper} turns the command into a dummy mark, but only for that single instance. Subsequent \fx{\newwatermark} and \fx{\newwallpaper} without primes will produce watermarks and wallpapers, respectively.
+
+
+\docsection(sec:wallpapers){Wallpapers}
+
+\docsubsection{The \headfx{\newwallpaper} macro}
+
+The command \fx{\newwallpaper} can be used to produce rectangular and square tiles on document pages. The use syntax for the command \fx{\newwallpaper} is
+
+\start{newmacro}[\newwallpaper]
+\newwallpaper[|A(keyval)]{|A(mark)}
+\newwallpaper|R(*')[|A(keyval)]{|A(mark)}
+\finish{newmacro}
+\fxi*{\newwallpaper}
+
+where \ang{keyval} is the list of keys and their values (called the attributes) and \ang{mark} is the text (and not graphics) watermark. Graphics watermarks are again to be specified with their file name, file extension, \etcc. The full lists of the available keys for the macro \fx{\newwallpaper} are available in \sref{tab:localoptions}.
+
+The \stform of \fx{\newwallpaper} puts the watermark in the foreground instead of the background, and the \pmform is ignored, \ie, no wallpaper is produced (see \sref{sec:dummywatermarks}).
+
+When you get unexpected tiles, you first should consider enabling or disabling the keys \fx{squaretiles} (default \texttt{true}) and/or \fx{boxalign} (default \texttt{center}). The key \fx{boxalign} may assume one of the values in the set \ffx{t-l,t-r,b-l,b-r,s} or \ffx{top-left, top-right, bottom-left, bottom-right, center, justified}.
+
+
+\docsection(sec:pic-watermark){Graphics watermarks}
+
+For graphics/picture watermarks, you need the \fx{picfile} (the graphics filename, with its full path but without its extension), \fx{picfileext} (the picture filename extension without the dot), \fx{picbb} (the picture bounding box), and \fx{picscale} (the picture scale)\footnote{These options have longer, easier to remember, names; see \sref{tab:localoptions}.}. Admissible file extensions are \fx{eps}, \fx{pdf}, \fx{png} and \fx{jpeg}; the latter three, but not the first, may be used in the case of \pdftex. The file extension should be passed without the dot. If the file extension is not passed to package, the package selects it automatically based on whether \pdftex mode is running or not (normal extensions are \fx{eps} for dvi mode and \fx{pdf} for \pdftex mode). In fact, the package does search hard on the given paths for other admissible file types with the base filename the user has specified. If you have the graphics file in both \fx{eps} and \pdf-compatible formats, then you don't have to bother about submitting the file extension to the package: it will automatically select the appropriate file extension, depending on the mode (\pdf or \texttt{dvi}) in which it is running.
+
+
+\docsubsection(sec:graphicsoptions)
+ [Passing key values to \headhx{\includegraphics} directly]
+ {Passing key values to \headhx{\includegraphics} directly}
+\fxim*{graphicsoptions}
+
+The \pkg'{xwatermark} uses \pkg'{graphicx}'s \hxi{\includegraphics} to insert graphics watermarks.
+Users can pass valid key values to the command \hx{\includegraphics} directly via the macros \ffx'{\newwatermark,\newwallpaper}. The key to use for this purpose is \fx{graphicsoptions}. The following points should be noted in respect of the key \fx{graphicsoptions}:
+
+\begin{enum}
+\item Values of the key \fx{graphicsoptions} must always be enclosed in curly braces, since they are expected to be more than one.
+\item Only keys and values valid for the command \hx{\includegraphics} may appear in the command \fx{graphicsoptions}. Valid keys for \hx{\includegraphics} are
+
+\start'{example}[\includegraphics keys]
+bb, bbllx, bblly, hiresbb, viewport, trim, height, width, natheight,
+natwidth, totalheight, angle, origin, keepaspectratio, scale, clip,
+draft, type, ext, read, command
+\finish{example}
+
+\item Key values submitted via \fx{graphicsoptions} supersede those submitted outside it, even if those outside \fx{graphicsoptions} appear earlier than \fx{graphicsoptions} in the command \fx{\newwatermark} or \fx{\newwallpaper}.
+\item Values submitted via \fx{graphicsoptions} have only local effect, in the sense that they become null and void outside of \fx{\newwatermark} or \fx{\newwallpaper}. If the user wants the key values submitted via \fx{graphicsoptions} to prevail for all subsequent watermarks and wallpapers, then he should use the command \fx{\GraphicsOptions}. Values passed via \fx{\GraphicsOptions} don't only have global effect, but they always override those submitted via \fx{graphicsoptions}.
+\end{enum}
+
+It should be noted that \fx{\GraphicsOptions} isn't a key but a stand-alone command with the following syntax:
+
+\start{newmacro}[\GraphicsOptions]
+\GraphicsOptions{|A(keyval)}
+\finish{newmacro}
+\fxi*{\GraphicsOptions}
+
+where \ang{keyval} are admissible keys for the command \hx{\includegraphics} and their user-supplied values. The values so suggested by \fx{\GraphicsOptions} override those given via the keys of the \pkg{xwatermark}, including \fx{graphicsoptions}. Such values remain in force until they are changed later by another call to \fx{\GraphicsOptions}.
+
+An example follows:
+
+\start{example}[graphicsoptions]
+\newwallpaper[%
+ page=10,picangle=45,tilexoffset=0pt,tileyoffset=0pt,picontoptext=false,
+ boxalign=top-left,picbb=116 428 477 718,picscale=2,picfile=tabu-test1,
+ tileno=4,picfileext=pdf,|R(graphicsoptions)={clip,keepaspectratio,hiresbb}
+]{mypicture}
+
+|com(or globally as)
+\GraphicsOptions{clip=true,keepaspectratio,hiresbb}
+\finish{example}
+\fxi*{\GraphicsOptions}
+
+The commands \hhx'{\DeclareGraphicsExtensions, \DeclareGraphicsRule} of the \pkg'{graphics} can still be invoked before setting graphics watermarks.
+
+
+\docsubsection{The graphics input paths}
+
+Users can suggest the possible locations of the graphics watermarks to the package by using the command \fx{\watermarkpaths}, whose syntaxes are
+
+\start{newmacro}[\watermarkpaths]
+\watermarkpaths[|A(pre)]|(|A(post)|){{path-1}{path-2}...{path-n}}
+\watermarkpaths|*[|A(pre)]|(|A(post)|){path-1,path-2,...,path-n}
+\finish{newmacro}
+\fxi*{\watermarkpaths}
+
+Here, \ang{pre} and \ang{post} are optional arguments that apply to all the given paths. Caution should be exercised when using these optional arguments, since when used incorrectly they can yield the wrong path (see the example below). In the \unstform all the paths must be provided in surrounding curly braces and must have no commas, otherwise the package will raise an error. The \stform expects paths to be separated by commas. The package works hard to find your watermark on the suggested path.
+
+\start+{example}[\watermarkpaths]
+\watermarkpaths{{./}{./graphics/}{./graphics/recentfiles/}}
+\watermarkpaths|*{./,./graphics/,./graphics/recentfiles/}
+\watermarkpaths|(/|){{.}{./graphics}{./graphics/recentfiles}}
+\watermarkpaths|*|(/|){.,./graphics,./graphics/recentfiles}
+|com(Note the empty balanced braces below. Without them, the first entry)
+|com(|(which is supposed to be {./}|) will be wrong:)
+\watermarkpaths[.]|(/|){{}{/graphics}{/graphics/recentfiles}}
+\watermarkpaths|*[.]|(/|){{},/graphics,/graphics/recentfiles}
+\finish{example}
+
+By default, the packages works hard to preserve outer curly braces, unless and until they are required to be removed.
+
+The command \fx{\watermarkpaths} inherits the current contents of \latex's \hx{\input@path} command and \pkg'{graphics}'s \hx{\Ginput@path} (the latter takes argument from \hx{\graphicspath}).
+
+
+\docsection{Other aspects of package architecture and use}
+
+\docsubsection{\headhx{\documentclass} options}
+
+The package is set to inherit the \hx{\documentclass} options, if the options apply to the package. Therefore, some of the package options can be passed to the package via the \hx{\documentclass} options list. This is perhaps most appropriate in the case of the option \fx{printwatermark}. However, package options supersede those passed via the \hx{\documentclass}. For example, the option \fx{printwatermark}=\hx{true} in the \hx{\documentclass} options list can normally be superseded by the option \fx{printwatermark}=\hx{false} in loading the \pkg'{xwatermark}, \eg, as in
+
+\start{example}[package loading]
+\usepackage[printwatermark=false]{xwatermark},
+\finish{example}
+
+and vice versa. It should, however, be noted that some package options and keys are restricted either to the \hhx'{\documentclass,\usepackage} (this applies to the so-called \quoted{option keys}) or to the various user macros (in the case of \quoted{non-option keys}). Normally, the package will alert the user to the wrong call of any of the options and keys.
+
+If you don't need the watermark on any page of your document, simply replace the option \fx{printwatermark} (=\hx{true}) with \fx{printwatermark}=\hx{false} in \hx{\usepackage} or \hx{\documentclass}. If you have specified \fx{printwatermark} (=\hx{true}) in the \hx{\documentclass} options list but you still don't need the watermark on any page of your document, then you would have to use the tools of \sref{sec:dummywatermarks}.
+
+
+\docsubsection<Size of the watermark>{The size of the watermark}
+
+In the case of text watermarks, the size of the watermark is controlled by three parameters, namely, \fx{fontsize}, \fx{fontseries} and \fx{scale}. All can be set dynamically. Their default values are \fx{5cm}, \fx{b} and \fx{1}, respectively. For picture watermarks, the size is determined by \fx{picscale}.
+
+
+\docsubsection{The coordinates of the watermark}
+
+The watermark coordinates (specified by \fx{xpos} and \fx{ypos}) have their origin at the center of the page and are with respect to the geometric center of the watermark. The default unit is \hx{millimeter}, but this can be changed on any page by changing the value of \fx{coordunit}. For example,
+
+\start+{example}[\newwatermark,coordunit]
+\newwatermark[other attributes,coordunit=|R(unit of length)]{}.
+\finish{example}
+
+Acceptable units of length include \hx{mm} (millimeter), \hx{cm} (centimeter), \hx{in} (inch), \hx{pt}~(point), \hx{bp} (big point), \hx{dd} (didot), \hx{ex} (height of small \hx{x}), \hx{pc} (pica), \hx{cc}~(cicero), and \hx{em}~(width of capital \hx{M}).
+
+
+\docsubsection{Wrong location of the watermark}
+
+If you discover that the watermark is wrongly positioned on the page(s) of your document, as some users have had course to complain, the chances are that you have submitted wrong coordinates (values of \fx{xpos} and \fx{ypos}) to the package or the watermark's width (\fx{textwidth} or \fx{picwidth}) is not optimal or both reasons. The package does not take responsibility for this and will normally not warn you in this respect. Since the output file provides a direct and simple indication of the occurrence of the anomaly, no attempt has been made in the package to warn users in this regard. If you do not specify the keys \fx{xpos} and/or \fx{ypos} at all in the call to \fx{\newwatermark}, their default values will be used by the package. Also, if you list these keys without their values in the call to \fx{\newwatermark}, their default values (\fx{xpos=0} and \fx{ypos=0}, which yield the center of paper) will be assumed by the package. The default value of the watermark's width is \hx{\paperheight}, and not \hx{\paperwidth} as might be expected.
+
+When the \pkg'{geometry} is loaded together with the \pkg'{xwatermark}, page layout scale changes by the \pkg'{geometry} may result in the watermarks being positioned slightly away from the intended position. See \sref{sec:geometry} for further details.
+
+
+\docsubsection{Wrong size of the watermark}
+
+When you discover that your text or graphics watermark is not of the size you expect, then you should check the global and local scale and width of the watermark. It is most likely that the chosen combination is wrong or inconsistent. Global and local package options are described in \sref{sec:packageoptions}. For example, choosing \fx{scale=0.7} and \fx{width=\paperwidth} may yield something unexpected. So will mixing inconsistent global and local scales or width, or both.
+
+
+\docsubsection{Breaking the watermark into lines}
+
+It is possible to break text watermarks into lines, as in the following examples:
+
+\start{example}
+\newwatermark[evenpages,fontfamily=ptm,angle=45,scale=.7,
+ align=center,color=green,xpos=0,ypos=0]{Directorate\\[.25ex]Only}
+
+\newwatermark[allpages,fontfamily=ptm,angle=45,scale=.8,align=left,
+ color=green,xpos=0,ypos=0]{Control\\[.25ex]Version}.
+\finish{example}
+
+More complex examples are available in the example source and \pdf files that shipped with this package.
+
+
+\docsubsection{The alignment of the watermark}
+
+The alignment of the watermark is controlled by the keys \ffx'{align, textalign, boxalign}. The first two are equivalent and may be set to \fx{center}, \fx{left}, \fx{right} or \fx{justified}. The default is \fx{center}. This is particularly useful for putting arbitrary texts (that are not necessarily watermarks) on pages of documents. The admissible values for the key \fx{boxalign} are given in \sref{tab:localoptions}.
+
+
+\docsubsection{Locating the page center}
+
+In case you need to locate the paper/page center for placing the watermark or some other material at any position on the page, a two-line grid can be placed on the page background with the key \fx{showpagecenter}, which may be issued (dynamically for each page) with the \fx{\newwatermark} macro as follows:
+
+\start{example}[showpagecenter]
+\newwatermark[allpages,showpagecenter]{}
+\newwatermark[page=1,showpagecenter=true]{}
+
+\newwatermark[allpages,showpagecenter,fontfamily=ptm,angle=60,scale=.7,
+ color=brown!25!yellow!75,coordunit=cc,xpos=0,ypos=0]{Confidential!}.
+\finish{example}
+
+If after issuing this command to get a centered grid on a page, you no longer require the grid on the following pages, you simply issue another
+
+\start{example}
+\newwatermark[pages=1-2,showpagecenter=false]{}
+
+\newwatermark[page=10-\lastdocpage,showpagecenter=false,fontfamily=panr,
+ angle=60,scale=.7,color=brown!25!yellow!75,coordunit=cc,xpos=0,ypos=0]
+ {Confidential!}
+\finish{example}
+
+
+\docsubsection{The last page of the document}
+
+You can easily obtain the last page of the document with the label \fx{xwmlastpage}, which is automatically provided by the package: the user doesn't have to insert it himself. In general, you can use the command \fx{\xwmgetpagenumber} to extract page numbers from \latex labels (even in expansion contexts). More than one run may be necessary in extracting page numbers from this command. The following example inserts the watermark from second to the last page to the last page. Note that in this example the starting page is necessarily enclosed in curly braces so as to distinguish the two hyphens that serve different purposes.
+
+\start{example}[\xwmgetpagenumber,\lastdocpage]
+\newwatermark[pages={\lastdocpage-2}-\lastdocpage,angle=90,
+ scale=1,xpos=0,ypos=-1]{This is page \thepage~of~\pageref*{xwmlastpage}}
+\finish{example}
+\fxi*{\xwmgetpagenumber,\lastdocpage}
+
+The command \fx{\lastdocpage} is equivalent to \fx{\xwmgetpagenumber{xwmlastpage}}.
+
+
+\docsubsection(sec:activechar){Active characters}
+
+Active characters (\ie, those of category 13) and expandable commands can normally be used as values of the \fx{textmark} key in the \fx{\newwatermark} macro. However, such values cannot be passed via the \hx{\documentclass} or the \hx{\usepackage{xwatermark}} command without first loading one of the packages: \pkg'{xkvltxp,kvoptions-patch,catoptions}. That is, the following should work:
+
+\start{example}
+\RequirePackage{catoptions}
+\documentclass[myoption={My watermark,\\[2ex]
+ designed~by \textsc{Mr.~J\"ohnson}}]{class-file}
+
+\begin{document}
+Blackberry lily ...
+\end{document}
+\finish{example}
+
+In plain \tex the only active character is the tie character (\ie, \hx{\nobreakspace}). However, some packages do make some other characters active. For example, after issuing the command \hx{\MakeShortVerb{\x}}, the packages \pkg{doc} and \pkg{shortvrb} make the character \fx{x} active\footnote{The \pkg'{fancyvrb} has, \eg, \ftfx{\DefineShortVerb[key=value pairs]{\x}}.}. The user can use such active characters in values of the \fx{textmark} key without locally changing their catcode to~11 or~12. In the case of \hx{\MakeShortVerb{\x}}, you can issue \hx{\DeleteShortVerb{\x}} to revert to normal use of character \fx{x}. As another example, the option \hx{turkish} of the \pkg'{babel} uses the equal sign (\hx{=}) as active shorthand character.
+
+
+\docsection(sec:making-boxes){Macros for creating boxes}
+
+To make it easier for users to create paragraph boxes and color boxes of texts and watermarks, the \pkg'{xwatermark} provides the macros \fx{\xwmcolorbox} and \fx{\xwmminipage}. The macro \fx{\xwmcolorbox} calls the macro \fx{\xwmminipage}.
+
+
+\docsubsection(sec:minipage){The \headfx{\xwmminipage} macro}
+
+The \fx{\xwmminipage} macro is a \hx{minipage} environment that may be used for framing watermarks. It accepts verbatim material. Like the \fx{\newwatermark} macro, this macro is called with key-value pairs as follows (see \sref{tab:localoptions} for a full listing of the available keys):
+
+\start{newmacro}[\xwmminipage]
+\xwmminipage[key=value list]{balanced text}
+\xwmcolorbox[key=value list]{balanced text}.
+\finish{newmacro}
+\fxi*{\xwmminipage}
+
+The \fx{textcolor} key in \fx{\xwmminipage} is the color of the text. In the case of \fx{\xwmcolorbox}, four color values are expected: \ffx'{textcolor, fillcolor, outerframecolor, innerframecolor}. Texts with commas need to be enclosed in braces when submitted to these macros. The default values of the keys of these macros are described in \sref{sec:localoptions}.
+
+The macros \ffx'{\xwmminipage,\xwmcolorbox} can be nested within and among themselves, \eg,
+
+\start{example}[\xwmminipage]
+\newwatermark[pagex={1,3,10},fontfamily=txtt,fontseries=m,color=red,
+ align=center,scale=0.7,angle=0,xpos=0,ypos=0]{%
+ \xwmminipage[width=\paperwidth]{%
+ \xwmminipage[width=\paperwidth,align=left,textcolor=magenta]
+ {\TeX\\[.1ex] \LaTeX}\\[1ex]
+ \xwmminipage[width=\paperwidth,align=center,textcolor=green]
+ {\TeX\\[.1ex] \LaTeX}\\[1ex]
+ \xwmminipage[width=\paperwidth,align=right,textcolor=orange]
+ {\TeX\\[.1ex] \LaTeX}%
+ }%
+}
+\finish{example}
+
+More complicated examples can be found in the example files. But some of the complications found in the example files are unnecessary since several simple watermarks can be placed on the same document page by specifying the same page number for those simple watermarks.
+
+
+\docsubsection(sec:colorbox){The \headfx{\xwmcolorbox} macro}
+
+The macro \fx{\xwmcolorbox} provides a key-value interface to \pkg'{xcolor}'s \hx{\fcolorbox}\footnote{The \pkg'{xwatermark} also comes with the macro \fx{\xwmshade} which is similar to \fx{\xwmcolorbox}, but which, unlike \fx{\xwmcolorbox}, can break neatly across pages (in the manner of the \pkg'{framed}). But since no watermark is expected to break across pages, the macro \fx{\xwmshade} isn't described in this guide. Power users should still be able to use it.}.
+
+\start{newmacro}[\xwmcolorbox]
+\xwmcolorbox[key=value list]{balanced text}.
+\finish{newmacro}
+\fxi*{\xwmcolorbox}
+
+
+\docsubsection(sec:makecolorbox){The \headfx{\makecolorbox} macro}
+
+This macro has the same syntax and options as the \fx{\xwmcolorbox} macro except that the resulting \hx{colorbox} is centered by using the \hx{center} environment and the markup box \hx{\makebox[0pt][c]{}}. It is intended for producing \hx{colorbox}\unskip es such as the one for article abstracts. The user may experiment with the following settings, from which the abstract of this guide was produced:
+
+\start{newmacro}[\makecolorbox]
+\makecolorbox[framesep=4pt,framerule=1pt,innerframecolor=red!55,
+ outerframecolor=ForestGreen,align=justified,
+ fillcolor=gray!25,width=.95\hsize,boxalign=center,
+ height=2.5mm,depth=0mm,framebox]{%
+ \centering\xwmcolorbox[align=center,fillcolor=white,
+ innerframecolor=blue,outerframecolor=orange,width=.5\hsize,
+ height=2mm]{\textbf{Abstract}}\\[\baselineskip]
+ The \pkg'{xwatermark} provides facilities for \ldots
+}
+\finish{newmacro}
+\fxi*{\makecolorbox}
+
+Notice here that the macro \fx{\makecolorbox} calls the macro \fx{\xwmcolorbox}.
+
+
+\docsection(sec:fancypagenos){The \headfx{\fancypagenos} macro}
+
+The macro \fx{\fancypagenos}, which has the following syntax, can be used to position and format page numbers in the desired fashion. Its keys and their default values are described in \sref{tab:localoptions}. Page numbers produced by \fx{\fancypagenos} will, by default, appear in the foreground, so that they can be seen on top of watermarks. If you want the page numbers to appear in the background, then set \fx{sendtoback}=\hx{true} as one of the key-value pairs in the call to \fx{\fancypagenos}.
+
+\start{newmacro}[\fancypagenos]
+\fancypagenos[key=value pairs]
+\finish{newmacro}
+\fxi*{\fancypagenos}
+
+Even after issuing the command \fx{\fancypagenos}, you can still decide not to print the fancy page numbers by calling the command \fxi{\NoFancyPageNumbers}. The complement of the command \fxi{\NoFancyPageNumbers} is \fxi{\FancyPageNumbers}.
+
+
+\docsection(sec:geometry)[\headpkg{xwatermark} and \headpkg{geometry} package]
+ {Using \headpkg{xwatermark} with \headpkg{geometry} package}
+
+Because the \pkg'{geometry} changes the scale, ratio, magnification, and other native dimensions of the paper to get the needed layout right all the time, the \pkg'{geometry} may interfere with the \pkg'{xwatermark}. The only layout parameter that the \pkg'{geometry} may retain is the paper center, which, unfortunately, does not always coincide with the text center. In fact, even the \hx{\paperwidth} and \hx{\paperheight} can be changed by the user of the \pkg'{geometry}.
+
+Feasible solutions to this problem include setting the watermarks before loading the \pkg'{geometry}; using the \pkg'{geometry} with the option \fx{pass} in the preliminary runs, when setting the watermarks (see further details below); using \hx{true} dimensions (\eg, \fx{coordunit}=\hx{truept}); and using relative, rather than absolute, dimension units (\ie, \hhx'{em,ex}). The power-user can also experiment with the primitives \hhx'{\magnification, \mag, \magstep}.
+
+The \hx{pass} option of the \pkg'{geometry} has been available from version~4.2 of the \pkg'{geometry} onwards. It disables auto-layout and all of the \pkg'{geometry} settings except \hx{verbose} and \hx{showframe}. It can be used to determine the page layout of the \hx{\documentclass} and layouts created by other packages and manual settings. The user can also employ the option \hx{showframe} of the \pkg'{geometry} to view how the scaling factors used by the \pkg'{geometry} might change native layout dimensions. The option \hx{reset} of the \pkg'{geometry} is also useful in this regard.
+
+The \pkg'{geometry} saves native \texorlatex dimensions and switches in the macro \hx{\Gm@dorg} before processing \pkg'{geometry} options. This macro is called by \pkg{geometry} when the options \hx{pass} and \hx{reset} are passed to it. Reconciling the two packages (\pkg{xwatermark,geometry}) at a \quoted{high level} will involve simply calling this macro within the \pkg'{xwatermark} whenever \pkg{xwatermark} detects that the \pkg'{geometry} has been loaded by the user. This is what has been done in the \pkg'{xwatermark}: the package has a boolean option called \fx{disablegeometry}, which, if true, invokes the command \hx{\Gm@dorg} of the \pkg'{geometry} to disable \pkg'{geometry} settings and enforce native paper layout dimensions. First the \pkg'{xwatermark} detects at the very last moment of the document preamble (just before \hx{\begin{document}}) if the \pkg'{geometry} has been loaded by the user. If yes, and if the user has suggested \fx{disablegeometry}=\hx{true} in the call to \pkg{xwatermark}, then \pkg{xwatermark} issues the command \hx{\geometry{pass}}, which, as mentioned earlier, calls \hx{\Gm@dorg}.
+
+After the effects of the \pkg'{geometry} are re-introduced (\ie, after setting the \pkg'{xwatermark} option \fx{disablegeometry}=\hx{false}), it might still be necessary, depending on the user need, to fine-tune the positions of the watermarks.
+
+Because the \pkg'{geometry} stipulates that the command \hx{\Gm@dorg} can be issued only in the document preamble, the switch \fx{disablegeometry} can appear as option only in \hx{\documentclass} or \hx{\usepackage{xwatermark}}. But it matters not which of the two packages (\pkg{geometry, xwatermark}) is loaded first. To call \hx{\Gm@dorg}, the \pkg'{xwatermark} uses the hook \hx{\BeforeStartOfDocument} from the \pkg'{catoptions}. \hx{\AtBeginDocument}, a native \latex hook, is inapplicable in this case.
+
+
+\docsection{Support for \ltsneverexpand{\acro{UNICODE}} and
+ \ltsneverexpand{\acro{UTF}} encodings}
+
+The \pkg'{xwatermark} can be used with any font encoding, provided the \fx{fontfamily} is properly declared before use. For example, with the following declarations on \XeTeX, Rembrandt Wolpert (\url{wolpert@uark.edu}) obtained some \fx{.pdf} outputs that he is willing to share with other users:
+
+\start{example}[\newfontfamily]
+\newfontfamily{\chinese}{STFangsong} % SinoType FangSong
+
+\newcommand{\chtext}[1]{{\chinese \XeTeXlinebreaklocale "jp"
+ \XeTeXlinebreakskip=0pt plus 1pt #1}%
+}
+
+\newwatermark[allpages,fontsize=5cm,align=center,
+ color=red!75!blue!25,angle=90,xpos=-65,ypos=-38,scale=.49]
+ {=\fbox{\color{red!65}\chtext{|color(red)watermark in Chinese or Japanese script|color(blue)}}=}
+
+\newfontfamily{\Gara}{Garamond Premier Pro}
+
+\newwatermark[allpages,fontsize=5cm,scale=.46,align=center,
+ angle=90,color=red!75!blue!25,xpos=-72,ypos=-38]
+ {=\fbox{\color{red!65}\Gara The different ligature}=\\[.35ex]}.
+\finish{example}
+\hxi*{\newfontfamily}
+
+It doesn't matter what the user declares as a \fx{fontfamily} provided he/she declares it before using it and provided the declaration is valid. It is thus possible to mix scripts in one watermark (\eg, Latin, Chinese, Korean, Japanese, Arabic, Russian scripts, you name it).
+
+\docsection{Repeated graphics in a document}
+
+For graphics watermarks, the watermark image, or any other image that is repeated in the document, has the potential to make the processed version of the document surprisingly large. The problem is that the default mechanisms of graphics usage add the image at every point it is to be used, and when processed, the image appears in the output file at each such point.
+
+See the \acro{UKTUG FAG}, version~3.20 (2010), entry number~146, page~95, for the available solutions to this problem. As described by this reference, if the \texttt{PostScript} version of the file is destined for conversion to \pdf, either by a ghostscript-based mechanism such as \hx{ps2pdf} or by, for example, Acrobat Distiller, the issue is not as important, since the distillation mechanism will amalgamate graphics objects whether or not the \texttt{PostScript} has them amalgamated. \pdftex does the same job with graphics, automatically converting multiple insertions into pointers to graphics objects. See also the \hx{\pdfxform} command and instructions about \hx{XObject}s in \pdftex user manual.
+
+
+\docsection{Further examples of use of \headpkg{xwatermark} package}
+
+The files \files'{xwatermark-examples1,xwatermark-examples2}, source files of examples of use of the \pkg'{xwatermark} together with their \pdf versions, are provided with this guide in the \pkg{xwatermark} bundle.
+
+
+\docsection(sec:packageoptions){Package options and macro keys}
+
+We categorize the package options and keys into global and local. Global options are those set either in \hx{\documentclass} or in \hx{\usepackage}, while local options are those set with the macros \ffx'{\newwatermark,\newwallpaper,\xwmminipage,\xwmcolorbox,\makecolorbox}.
+
+
+\docsubsection(sec:globaloptions){Global options}
+
+The global package options are listed and described in the following \sref{tab:globaloptions}.
+
+\begingroup
+\small
+\ifboolTF{amd@inputfile}{%
+ \InputDocument{tab-globaloptions}
+}{}
+\endgroup
+
+
+\docsubsection(sec:localoptions){Local options}
+
+Local package options are those associated with the commands \ffx'{\newwatermark, \newwallpaper, \xwmminipage, \xwmcolorbox, \makecolorbox, \fancypagenos}. They are described in the following \sref{tab:localoptions}.
+
+\begingroup
+\small
+\ifboolTF{amd@inputfile}{%
+ \InputDocument{tab-localoptions}
+}{}
+\endgroup
+
+
+\docsection(sec:version-hist){Version history}
+
+The following change history highlights significant changes that affect user utilities and interfaces; changes of technical nature are not documented in this section. The \stsign on the right-hand side of the following lists means the subject features in the package but is not reflected anywhere in this user guide.
+
+\begin{versionhist}
+ \begin{version}{1.5.2d}{2012/10/23}
+ \item Bug fix in writing section numbers and pages to the auxiliary file \vsecref*
+ \end{version}
+ \begin{version}{1.5.2c}{2012/10/14}
+ \item The commands \ffx'{\xwmwatermarkon,\xwmwatermarkoff} introduced \vsecref*
+ \end{version}
+ \begin{version}{1.5.2b}{2012/08/01}
+ \item Persistent interaction mode inherited from \pkg'{catoptions} removed \vsecref*
+ \end{version}
+ \begin{version}{1.5.2a}{2012/02/01}
+ \item New command \fx{\xwm@stripallouterbraces} introduced \vsecref*
+ \end{version}
+ \begin{version}{1.5.2}{2011/10/20}
+ \item To match changes in \pkg'{ltxkeys} \vsecref*
+ \end{version}
+ \begin{version}{1.5.1}{2011/07/20}
+ \item Following user request, two new keys were introduced for the macro \fx{\fancypagenos} \vsecref{sec:fancypagenos}
+ \end{version}
+ \begin{version}{1.5.0}{2011/07/10}
+ \item Introduced the \pkg'{ltxkeys}, a highly robust and optimized module for general creation and management of keys \vsecref*
+ \item Provisions for placing more than one watermark on the same page. \vsecref{sec:newwatermarks}
+ \item Introduced wallpaper functionalities \vsecref{sec:wallpapers}
+ \item Adaptable and flexible fancy page numbers \vsecref{sec:fancypagenos}
+ \end{version}
+\end{versionhist}
+
+\newpage
+\ltsindexpreamble{Index numbers refer to page numbers.}
+\ltsindexpreambleformat{\centering}
+\ltsindexcolumns\tw@
+\printindex
+
+\end{document}
+
diff --git a/macros/latex/contrib/xwatermark/tex/xwatermark.sty b/macros/latex/contrib/xwatermark/tex/xwatermark.sty
new file mode 100644
index 0000000000..9ead5f270e
--- /dev/null
+++ b/macros/latex/contrib/xwatermark/tex/xwatermark.sty
@@ -0,0 +1,2474 @@
+%++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++%
+% This is file 'xwatermark.sty', version 1.5.2d, October 23, 2012. %
+% %
+% This package puts user-specified watermarks (graphics and arbitrary %
+% texts) on select pages of documents. See package documentation %
+% for further details. %
+% %
+% This work (ie, all the files in the xwatermark manifest) may be %
+% distributed and/or modified under the conditions of the LaTeX %
+% Project Public License, either version 1.3 of this license or any %
+% later version. The latest version of this license is in %
+% http://www.latex-project.org/lppl.txt and version 1.3 or later %
+% is part of all distributions of LaTeX version 2005/12/01 or later. %
+% %
+% The LPPL maintenance status of this software is 'author-maintained'. %
+% %
+% This software is provided 'as it is', without warranty of any kind, %
+% either expressed or implied, including, but not limited to, the %
+% implied warranties of merchantability and fitness for a particular %
+% purpose. %
+% %
+% Copyright (c) 2009-2012 Ahmed Musa (amusa22@gmail.com). %
+%++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++%
+
+\@ifpackageloaded{catoptions}{%
+ \@ifpackagelater{catoptions}{2012/10/14}{}{%
+ \@latex@error{Loaded version of 'catoptions' package is
+ not current}\@ehd
+ }%
+}{%
+ \RequirePackage{catoptions}[2012/10/14]%
+}
+\UseNormalCatcodes
+\StyleFilePurpose{A dynamic watermarking scheme}
+\StyleFileRCSInfo
+$Id: xwatermark.sty,v 1.5.2d 2012/10/23 09:00:00 Ahmed Musa Exp $
+\ProvidesPackage{xwatermark}[\StyleFileInfo]
+\NeedsTeXFormat{LaTeX2e}[2011/06/27]
+\SetStyleFileMessages[xwm@]{info}{warn}{err}
+\robust@def*\xwm@@err#1#2#3{\xwm@err{#1}{#2}\@gobble}
+\cptloadpackages{%
+ fix-cm||2006/03/24;
+ picture||2008/11/26;
+ graphicx||1999/02/16;
+ atbegshi||2008/07/31;
+ fancyhdr;
+ atveryend||2010/03/24;
+ ltxkeys;
+ framed||2007/10/04
+}
+\AtEndOfPackage{\BeforeStartOfDocument{%
+ \ifcsndefTF{ver@hyperref.sty}{}{\usepackage{hyperref}}%
+}}
+
+\newletcs\xwm@nil\relax
+\new@def*\xwm@nnil{\xwm@nil}
+\AtBeginShipoutInit
+\cptnewvariables{box}[xwm@box]{a,b}\relax
+\cptnewvariables{count}[xwm@]{cnta}[\z@pt]
+\cptnewvariables{if}[xwm@]{pdf,swa,swb,foregrd,wall,putmark}[false]
+\newletcs\xwm@catch@nil\relax
+\new@def*\xwm@catchtonil#1\xwm@catch@nil{\def\stuff{#1}}
+\xwm@putmarktrue
+\cptnewvariables{write}[xwm@]{wrt}\relax
+\robust@def*\AtShipoutAlwaysUpperLeft#1{%
+ \AtBeginShipout{\AtBeginShipoutUpperLeft{#1}}%
+}
+\robust@def*\xwm@secstopagerange#1{%
+ % To do: what of if a chapter, instead of another section,
+ % comes after section.
+ \begingroup
+ \ifblankTF{#1}{}{%
+ \def\@do##1##2,##3\@nil##4{%
+ \ifstrcmpTF\do{##1}{}{%
+ \csn@xdef{xwm@sec@page@end@\detokenize{##4}}{##2}%
+ \do{##1}{##2},##3\@nil
+ }%
+ }%
+ \def\do##1##2,##3\@nil{%
+ \ifstrcmpTF\do{##1}{}{%
+ \csn@xdef{xwm@sec@page@start@\detokenize{##1}}{##2}%
+ \@do##3\@nil{##1}%
+ }%
+ }%
+ \do#1,\do\do,\@nil
+ }%
+ \endgroup
+}
+\new@def*\xwm@seclist{}
+\AtEndDocument{%
+ \immediate\write\@auxout{%
+ \string\xwm@secstopagerange{%
+ \xwm@seclist\ifx\xwm@seclist\@empty\else,\fi
+ {10000}{\lastdocpage}%
+ }%
+ }%
+}
+\robust@def*\xwm@recordsecno{%
+ \xdef\xwm@seclist{%
+ \xwm@seclist\ifx\xwm@seclist\@empty\else,\fi
+ {\thesection}{\thepage}%
+ }%
+}
+\edef\reserved@a{%
+ % To do: do the same for chapter.
+ \def\noexpand\@seccntformat##1{%
+ \unexpanded\expandafter{\@seccntformat{#1}}%
+ \unexpanded{\protect\xwm@recordsecno}%
+ }%
+}
+\reserved@a
+\new@def*\xwm@boxframestack{}
+\robust@def*\xwm@pushboxframe{%
+ \xdef\xwm@boxframestack{%
+ \fboxrule=\the\fboxrule\relax
+ \fboxsep=\the\fboxsep\relax
+ \xwm@nil{\expandcsonce\xwm@boxframestack}%
+ }%
+}
+\robust@def*\xwm@popboxframe{%
+ \begingroup
+ \def\reserved@a##1\xwm@nil{\endgroup
+ ##1\gdef\xwm@boxframestack
+ }%
+ \expandafter\reserved@a\xwm@boxframestack
+}
+\robust@def\xwm@stripallouterbraces#1#2{%
+ \edef#2{\unexpanded\cptthreexp{\xwm@str@pallouterbraces#1\strip@nil}}%
+}
+\robust@def\xwm@str@pallouterbraces#1\strip@nil{%
+ \romannumeral\ifbracedTF{#1}{%
+ \expandafter\ifnullTF\expandafter{\@gobble#1}{%
+ \expandafter\@gobble\xwm@str@pallouterbraces#1\strip@nil
+ }{0 #1}%
+ }{0 #1}%
+}
+\robust@def\xwm@stripallouterbracesincs#1{%
+ \expandafter\xwm@stripallouterbraces\expandafter{#1}#1%
+}
+\new@def*\xwmremoveleadparsers#1#2{%
+ \s@expandarg\ifbracedTF{#2}{%
+ \unexpanded\expandafter{#2}%
+ }{%
+ \unexpanded\expandafter{\romannumeral
+ \expandafter\xwm@removeleadparsers#2\noboundary{#1}}%
+ }%
+}
+\new@def*\xwm@removeleadparsers#1#2\noboundary#3{%
+ \ifcondTF\if\string#1\string#3\fi{%
+ \xwm@removeleadparsers#2\noboundary{#3}%
+ }{%
+ 0 #1#2%
+ }%
+}
+\robust@def*\xwm@ifxcolorloaded{%
+ \ifcsndefTF{ver@xcolor.sty}\@iden{%
+ \xwm@err{'xcolor' package not loaded}\@ehd
+ }%
+}
+\robust@def*\xwmdefinecolor{%
+ \xwm@ifxcolorloaded{%
+ \let\reserved@e\definecolor
+ \cpt@testopt\xwm@definecolor{}%
+ }%
+}
+\robust@def*\xwmcolorlet{%
+ \xwm@ifxcolorloaded{%
+ \let\reserved@e\colorlet
+ \cpt@testopt\xwm@definecolor{}%
+ }%
+}
+\robust@def*\xwm@definecolor[#1]#2{%
+ \@ifundefinedcolor{#2}{%
+ \reserved@e[#1]{#2}%
+ }{%
+ \xwm@err{Color name '#2' already defined}\@ehd
+ }%
+}
+\robust@def*\xwmdefinecolorset{\cpt@testopt\xwm@definecolorset{x}}
+\robust@def*\xwm@definecolorset[#1]{%
+ \cpt@testpnopt{\xwm@d@finecolorset{#1}}{1}%
+}
+\robust@def*\xwm@d@finecolorset#1(#2)#3{%
+ \xwm@ifxcolorloaded{%
+ \begingroup
+ \cptemptifycsset{\xwm@tempb,\xwm@tempc,\xwm@tempd,\xwm@tempe}%
+ \def\xwm@tempa##1,##2,##3,##4,##5\@nil{%
+ \ifblankTF{##4}{%
+ \xwm@err{Incomplete color format in
+ \string\xwmdefinecolorset}\@ehd
+ }{%
+ \def\xwm@tempf{##1}%
+ }%
+ }%
+ \cpt@stfalse\cpt@csvnormalize[;]{#3}%
+ \def\do##1;{%
+ \ifnot@nil{##1}{%
+ \xwm@tempa##1,,,,\@nil
+ \xifinsetTF{,\xwm@tempf,}{,\xwm@tempd,}{%
+ \edef\xwm@tempe{\csliststack,\xwm@tempe\xwm@tempf}%
+ }{%
+ \edef\xwm@tempd{\csliststack,\xwm@tempd\xwm@tempf}%
+ \@ifundefinedcolor{#1\xwm@tempf#2}{%
+ \edef\xwm@tempb{\csliststack;\xwm@tempb##1}%
+ }{%
+ \edef\xwm@tempc{\csliststack;\xwm@tempc#1\xwm@tempf#2}%
+ }%
+ }%
+ \do
+ }%
+ }%
+ \expandafter\do\normalized@list;\@nil;%
+ \ifcsemptyTF\xwm@tempe{}{%
+ \xwm@err{Color names '\expandcsonce\xwm@tempe' multiply
+ \MsgBrk submitted to \string\xwmdefinecolorset}\@ehd
+ }%
+ \ifcsemptyTF\xwm@tempc{}{%
+ \xwm@err{Color names '\expandcsonce\xwm@tempc' already in use}\@ehd
+ }%
+ \ifcsemptyTF\xwm@tempb{}{%
+ \cptexpandarg{\xglobal\definecolorset{rgb}{#1}{#2}}
+ {\expandcsonce\xwm@tempb}%
+ }%
+ \endgroup
+ }%
+}
+\DefSuffixChecker\xwm@suffixcheck{*}{+}{'}
+\robust@def*\xwmifitemsinTF{%
+ \begingroup\xwm@swatrue\cpt@testopt\xwm@itemsin\@ne
+}
+\robust@def*\xxwmifitemsinTF{%
+ \begingroup\xwm@swatrue\cpt@testopt\xwm@xitemsin\@ne
+}
+\robust@def*\xwmifitemsinFT{%
+ \begingroup\xwm@swafalse\cpt@testopt\xwm@itemsin\@ne
+}
+\robust@def\xwm@xitemsin[#1]#2#3{%
+ \cptexpandtwoargs{\xwm@itemsin[#1]}{#2}{#3}%
+}
+\robust@def\xwm@itemsin[#1]#2#3{%
+ \begingroup
+ \afterassignment\xwm@catchtonil\@tempcnta=#1\xwm@catch@nil
+ \if\relax\cptoxdetok\stuff\relax
+ \ifnum\numexpr#1<\@ne
+ \xwm@err{Invalid number '\the#1'\relax
+ \MsgBrk for command \string\xwmifitemsinTF}\@ehd
+ \fi
+ \else
+ \xwm@err{Token '\detokenize{#1}' not an integer}\@ehd
+ \fi
+ \endgroup
+ \lowercase{%
+ \edef\xwm@tempa{\unexpanded{#2}}%
+ \edef\xwm@tempb{\unexpanded{#3}}%
+ }%
+ \cpt@sttrue\cpt@csvnormalize[,]\xwm@tempb
+ \def\xwm@nritems{0}%
+ \def\xwm@items{}%
+ \def\csv@do##1{%
+ \xifinsetFT{,\detokenize{##1}}{,\cptoxdetok\xwm@tempb}{}{%
+ \edef\xwm@items{%
+ \expandcsonce\xwm@items\ifx\xwm@items\@empty\else,\fi
+ \unexpanded{##1}%
+ }%
+ \edef\xwm@nritems{\the\numexpr\xwm@nritems+1}%
+ \ifnum\xwm@nritems>\numexpr#1-1\relax\loopbreak\fi
+ }%
+ }%
+ \csv@@parse*[,]\xwm@tempa
+ \expandafter\endgroup
+ \csname
+ @\ifnum\xwm@nritems>\numexpr#1-1\relax
+ \ifxwm@swa first\else second\fi
+ \else
+ \ifxwm@swa second\else first\fi
+ \fi
+ oftwo\endcsname
+}
+\robust@def*\xwm@hyphenpagerange#1#2#3{%
+ \xifinsetTF{\detokenize{\xwmgetpagenumber}}{\cptoxdetok{#1}}{%
+ \xwm@swbtrue
+ }{%
+ \xifinsetTF{\detokenize{\lastdocpage}}{\cptoxdetok{#1}}{%
+ \xwm@swbtrue
+ }{%
+ \xwm@swbfalse
+ }%
+ }%
+ \protected@edef#2{#1}\def#3{}%
+ \begingroup
+ \catcode`\-=12\relax
+ \cptscantokens#2%
+ \postgroupdef#2\endgroup
+ \oifinsetTF{-}{#2}{%
+ \expandafter\xwm@splitpagerange#2\xwm@nil{#2}{#3}%
+ }{%
+ \ifblankTF{#1}{%
+ \xwm@err{Empty page range for watermark:
+ ^^J||\expandcsonce\xwm@currwatermark||.^^J}\@ehd
+ }{%
+ \protected@edef#3{#1}%
+ }%
+ }%
+}
+\robust@def*\xwm@splitpagerange#1-#2\xwm@nil#3#4{%
+ \def#3{#1}\def#4{#2}%
+ \ifinsetTF{-}{#2}{%
+ \xwm@err{Too many hyphens in page range '#1-#2'
+ \MsgBrk of watermark:^^J||\expandcsonce\xwm@currwatermark||}\@ehd
+ }{%
+ \ifblankTF{#1}{%
+ \xwm@warn{No start-page in page-range of watermark:
+ ^^J||\expandcsonce\xwm@currwatermark||.^^JI have used the
+ default start-page '\xwm@defaultfirstpage'
+ instead}%
+ \def#3{\xwm@defaultfirstpage}%
+ \xwm@swafalse
+ }{%
+ \xwm@swatrue
+ }%
+ \ifblankTF{#2}{%
+ \xwm@warn{No end-page for page-range
+ of watermark:^^J||\expandcsonce\xwm@currwatermark||
+ ^^JI have used the default end-page
+ '\xwm@defaultlastpage' instead}%
+ \def#4{\xwm@defaultlastpage}%
+ \xwm@swafalse
+ }{%
+ \xwm@swatrue
+ }%
+ \ifxwm@swa
+ \ifnum\numexpr#1=\numexpr#2\relax\else
+ \ifnum\numexpr#1<\numexpr#2\relax\else
+ \ifxwm@swb\else
+ \xwm@err{Watermark start-page '#1' is greater
+ than end-page '#2'}\@ehd
+ \fi
+ \fi
+ \fi
+ \fi
+ }%
+}
+\let\xwm@papercenter\relax
+\ifdefTF\pdfoutput{%
+ \ifnum\pdfoutput<\@ne\xwm@pdffalse\else\xwm@pdftrue\fi
+}{%
+ \xwm@pdffalse
+}
+\new@def*\xwm@allowedcoordunits{%
+ em,ex,in,pt,pc,cm,mm,dd,cc,nd,nc,bp,sp,\paperwidth,%
+ \paperheight,\textwidth,\textheight,\hsize,\vsize,%
+ \columnwidth,\linewidth
+}
+\robust@def*\xwm@checkcoordunit#1{%
+ \oifinset@sp@TF,{#1}{\xwm@allowedcoordunits}{}{%
+ \xwm@err{Invalid coordinate unit '#1'}{%
+ Allowed coordinate units are:
+ ^^J||\xwm@allowedcoordunits||^^J}%
+ }%
+}
+\robust@def*\xwm@defaultunits#1#2{%
+ \begingroup
+ \@defaultunits\@tempdima\dimexpr#1\p@\relax\@nnil
+ \edefpass#2{\endgroup\def\noexpand#2{\the\@tempdima}}%
+}
+\robust@def*\xwm@getposition#1#2#3{%
+ \begingroup
+ \@defaultunits\@tempdima\dimexpr#1#3\p@\relax\@nnil
+ \edef\xwm@tempa{\the\dimexpr0.5\paperwidth+\@tempdima\relax}%
+ \@defaultunits\@tempdima\dimexpr#2#3\p@\relax\@nnil
+ \edef\xwm@tempb{\the\dimexpr-0.5\paperheight+\@tempdima\relax}%
+ \cptexpanded{\endgroup
+ \csn@def{\cptremovescape#1@a}{\xwm@tempa}%
+ \csn@def{\cptremovescape#2@a}{\xwm@tempb}%
+ }%
+}
+\cptrobustify{%
+ \fbox,\framebox,\makebox,\rotatebox,\scalebox,\raisebox
+}
+\new@def*\xwm@relax{\relax}
+\robust@def*\xwm@settextalign#1{%
+ \ifmacroTF{#1}{}{\cpt@notcserr{#1}}%
+ \begingroup
+ \cptexpandmacro{#1}\xwm@tempa
+ \cptexpandargonce{\endgroup\xwm@stripallouterbraces}\xwm@tempa#1%
+ \ltxkeys@trimspacesincs{#1}%
+ \cptexpandsecond{\def\reserved@a##1}{#1}##2##3\xwm@nil{%
+ \def\reserved@a{##2}%
+ \ifxTF\reserved@a\xwm@nnil{%
+ \cpt@err{Invalid value '#1' for textalign}\@ehd
+ \def#1{xwm@relax}%
+ }{%
+ \def#1{##2}%
+ }%
+ }%
+ \cptexpandsecond{\reserved@a
+ center{center},\centering{center},right{flushright},
+ \flushright{flushright},\raggedleft{flushright},
+ left{flushleft},\flushleft{flushleft},\raggedright{flushleft},
+ justified{xwm@relax},\relax{xwm@relax},xwm@relax{xwm@relax}%
+ }{#1}{\xwm@nil}\xwm@nil
+}
+\robust@def*\xwm@getalign#1{%
+ \ifmacroTF{#1}{%
+ \csn@edef{xwm@\expandafter\@gobblethree\string#1}{%
+ \xifstrcmpTF{#1}{\relax}{relax}{#1}%
+ }%
+ }{%
+ \cpt@notcserr{#1}%
+ }%
+}
+% 'boxalign' may be in the format 't-l, t-r, b-l, b-r, c, s'
+% or 'top-left, top-right, etc':
+\robust@def*\xwm@setboxalign#1{%
+ \ifmacroTF{#1}{}{\cpt@notcserr{#1}}%
+ \begingroup
+ \toks@{}%
+ \cptexpandarg\lowercase{\def\noexpand\reserved@a{#1}}%
+ % We don't want the format 't-l' mixed with 'top-left':
+ \def\xwm@tempa{}\def\xwm@tempb{}%
+ \def\xwm@resa##1-{%
+ \ifstrcmpTF{##1}{\xwm@nil}{}{%
+ \ifinsetTF{,##1,}{,top,left,right,bottom,center,justified,}{%
+ \edef\xwm@tempa{\csliststack,\xwm@tempa##1}%
+ }{%
+ \ifinsetTF{,##1,}{,l,r,b,t,c,s,}{%
+ \edef\xwm@tempb{\xwm@tempb##1}%
+ }{%
+ \toks@\expandafter{\the\toks@##1}%
+ }%
+ }%
+ \xwm@resa
+ }%
+ }%
+ \expandafter\xwm@resa\reserved@a-\xwm@nil-%
+ \s@expandarg\ifnullTF{\the\toks@}{}{%
+ \xwm@err{'boxalign' has invalid or inconsistent
+ \MsgBrk values '#1'}\@ehd
+ }%
+ \ifcsnullTF\xwm@tempa{}{%
+ \ifcsnullTF\xwm@tempb{}{%
+ \xwm@err{Invalid values '#1' for 'boxalign':
+ \MsgBrk possibly a mixture of styles}\@ehd
+ }%
+ }%
+ \def\xwm@tempc{}%
+ \ifcsnullTF\xwm@tempa{}{%
+ \def\xwm@resa##1##2##3\xwm@nil##4{%
+ \ifblankTF{##3}{}{%
+ \ifinsetFT{,##1,}{,##4,}{}{%
+ \xifinsetTF{##2}{\xwm@tempc}{}{%
+ \edef\xwm@tempc{\xwm@tempc##2}%
+ }%
+ }%
+ \xwm@resa##3\xwm@nil{##4}%
+ }%
+ }%
+ \cptexpandarg
+ {\xwm@resa{center}{c}{justified}{s}{left}{l}{right}{r}%
+ {top}{t}{bottom}{b}\xwm@mil\xwm@mil\xwm@nil}\xwm@tempa
+ }%
+ \ifcsnullTF\xwm@tempb{}{%
+ \def\siso@do##1{%
+ \ifinsetFT{,##1,}{,l,r,b,t,c,s,}{}{%
+ \xifinsetTF{##1}{\xwm@tempc}{}{%
+ \edef\xwm@tempc{\xwm@tempc##1}%
+ }%
+ }%
+ }%
+ \simpleexpandarg\siso@@loop\xwm@tempb
+ }%
+ \ifcsnullTF\xwm@tempc{%
+ \xifblankTF{#1}{%
+ \def\xwm@tempc{s}%
+ }{%
+ \xwm@err{Invalid entries '#1' for 'boxalign'}\@ehd
+ }%
+ }{%
+ \begingroup
+ \cpt@cnta\z@pt
+ \def\siso@do##1{\advance\cpt@cnta\@ne}%
+ \s@expandarg\siso@@loop\xwm@tempc
+ \ifnum\cpt@cnta>2\relax
+ \xwm@err{More than two entries '#1' for 'boxalign'}\@ehd
+ \fi
+ \endgroup
+ }%
+ \let#1=\xwm@tempc
+ \postgroupdef#1\endgroup
+}
+\robust@def*\xwm@notenddocerr{%
+ \xwm@err{Wrong location of end-of-document command}\@ehd
+}
+\robust@def*\AfterEndOfDocument{\grightaddtocs\xwm@afterenddoc}
+\new@def*\xwm@afterenddoc{}
+\robust@def*\AfterLastPageOfDocument{%
+ \grightaddtocs\xwm@afterlastpage
+}
+\new@def*\xwm@afterlastpage{}
+\AtEndDocument{%
+ \let\xwm@aft@renddoc\AtVeryEnd@AtVeryEndDocumentHook
+ \def\AtVeryEnd@AtVeryEndDocumentHook{%
+ \let\AfterEndOfDocument\@firstofone
+ \xwm@afterenddoc\xwm@aft@renddoc
+ \let\AfterEndOfDocument\xwm@notenddocerr
+ \undefcs\xwm@afterenddoc
+ \undefcs\xwm@aft@renddoc
+ }%
+ \let\xwm@afterl@stpage\AtVeryEnd@AfterLastShipoutHook
+ \def\AtVeryEnd@AfterLastShipoutHook{%
+ \let\AfterLastPageOfDocument\@firstofone
+ \xwm@afterlastpage\xwm@afterl@stpage
+ \let\AfterLastPageOfDocument\xwm@notenddocerr
+ \undefcs\xwm@afterlastpage
+ \undefcs\xwm@afterl@stpage
+ }%
+}
+\robust@def*\xwmnewlabel{\xwm@newlabel{xwmr}}
+\robust@def*\xwm@newlabel#1#2#3{%
+ \begingroup
+ \ifcsndefFT{#1@#2}{}{%
+ \gdef\xwm@multiplelabels{%
+ \ltxmsg@warn{There were multiply-defined labels}%
+ }%
+ \ltxmsg@warn{Label '#2' multiply defined}%
+ }%
+ \csn@gdef{#1@#2}{#3}%
+ \endgroup
+}
+\let\xwm@multiplelabels\relax
+\BeforeStartOfDocument{%
+ \global\let\xwm@multiplelabels\relax
+}
+\robust@def*\xwm@lbtestdef#1#2#3{%
+ \begingroup
+ \def\xwm@tempa{#3}%
+ \expandafter\ifx\csname#1@#2\endcsname\xwm@tempa\else
+ \gdef\xwm@lbtestsw{00}\fi
+ \endgroup
+}
+\begingroup
+\makeatletter
+\InputIfFileExists{\jobname.xwm}{}{}
+\endgroup
+\if@filesw
+ \immediate\openout\xwm@wrt=\jobname.xwm
+ \immediate\write\xwm@wrt{\relax}
+\fi
+\AfterLastPageOfDocument{%
+ \if@filesw
+ \begingroup
+ \advance\c@page\m@one
+ \xwmlabel{xwmlastpage}%
+ \endgroup
+ \fi
+ \immediate\closeout\xwm@wrt
+ \let\xwm@newlabel\xwm@lbtestdef
+ \gdef\xwm@lbtestsw{01}%
+ \begingroup
+ \makeatletter
+ \InputIfFileExists{\jobname.xwm}{}{}%
+ \endgroup
+ \if@filesw
+ \ifx\xwm@multiplelabels\relax
+ \if\xwm@lbtestsw
+ \ltxmsg@warn{Label(s) may have changed.
+ Rerun to get cross-references right}%
+ \fi
+ \else
+ \xwm@multiplelabels
+ \fi
+ \fi
+}
+\new@def*\xwm@labelcarr#1#2#3\xwm@nil{\ifblankTF{#3}{}{#2}}
+\new@def*\xwmgetpagenumber#1{%
+ \ifcsndefTF{xwmr@#1}{%
+ \cptsevenxp\xwm@labelcarr
+ \usename{xwmr@#1}\xwm@defaultfirstpage\xwm@nil
+ }{%
+ \xwm@defaultfirstpage
+ }%
+}
+\new@def*\lastdocpage{\xwmgetpagenumber{xwmlastpage}}
+\robust@def*\xwmlabel#1{%
+ \@bsphack
+ \begingroup
+ \@onelevel@sanitize\@currentlabelname
+ \edef\@currentlabelname{%
+ \expandafter\strip@period\@currentlabelname\relax.\relax\@@@
+ }%
+ \immediate\write\@auxout{%
+ \string\newlabel{#1}{{\@currentlabel}{\thepage}%
+ {\@currentlabelname}{\@currentHref}{}}%
+ }%
+ \immediate\write\xwm@wrt{%
+ \string\xwmnewlabel{#1}{{\@currentlabel}{\thepage}%
+ {\@currentlabelname}{\@currentHref}{}}%
+ }%
+ \endgroup
+ \@esphack
+}
+\robust@def*\DeclareWatermarkParser#1{%
+ \begingroup
+ \xwm@stripallouterbraces{#1}\xwm@tempa
+ \xdef\xwm@watermarkparser{\cptoxdetok\xwm@tempa}%
+ \endgroup
+}
+\DeclareWatermarkParser{;}
+\robust@def*\xwm@put{\leavevmode\put}
+\new@edef*\xwm@defaultfileext{\ifxwm@pdf pdf\else eps\fi}
+\new@def*\xwm@picfilesread{}
+\robust@def*\xwm@fileextfn#1#2{%
+ \ifcsndefFT{#2picfile}{}{%
+ \def\xwm@tempb##1##2{%
+ \xwm@warn{Default file extension '##1'\MsgBrk
+ substituted for invalid '#1' in\MsgBrk
+ ##2 mode. I'll later confirm the\MsgBrk
+ existence of \usename{#2picfile}.##1%
+ }%
+ }%
+ \ifcsnnullTF{#2picfile}{%
+ \csn@edef{#2picfileext}{}%
+ }{%
+ \xifinsetTF{,\usename{#2picfile},}{,\xwm@picfilesread,}{%
+ \xwm@swbfalse
+ }{%
+ \xwm@swbtrue
+ \cptgxaddtolist*\xwm@picfilesread{\usename{#2picfile}}%
+ }%
+ \aftercsname\xwm@stripallouterbracesincs{#2picfileext}%
+ \ifdefboolTF{xwm@pdf}{%
+ \xifinsetTF{,\usename{#2picfileext},}{,pdf,png,jpeg,jpg,mps,}{}{%
+ \csn@def{#2picfileext}{pdf}%
+ \ifxwm@swb\xwm@tempb{pdf}{pdf}\fi
+ }%
+ }{%
+ \xifinsetTF{,\usename{#2picfileext},}{,eps,ps,}{}{%
+ \csn@def{#2picfileext}{eps}%
+ \ifxwm@swb\xwm@tempb{eps}{dvi}\fi
+ }%
+ }%
+ }%
+ }%
+}
+\ltxkeys@boolkey[XWM]{main}[xwm@]{disablegeometry}[true]{%
+ \BeforeStartOfDocument{%
+ \ifxwm@disablegeometry
+ \ifdefFT\geometry{}{%
+ \geometry{pass}%
+ \xwm@info{On your request (ie, 'disablegeometry=true')
+ \MsgBrk I have disabled the features of the
+ \MsgBrk 'geometry' package}%
+ }%
+ \fi
+ }%
+}
+\new@def*\xwm@gr@phicsoptions{}
+\robust@def*\GraphicsOptions#1{\gdef\xwm@gr@phicsoptions{#1}}
+\ltxkeys@definekeys*[XWM]{main}[xwm@]{%
+ disable-geometry=true/\setaliaskey{disablegeometry};
+ printwatermark=true;
+ print-watermark=true/\setaliaskey{printwatermark};
+ allownesting=true;
+ showpagecenter=true/\ifdefboolTF{xwm@showpagecenter}
+ {\wmk@showpagecentertrue\wlp@showpagecentertrue}{};
+ show-page-center=true/\setaliaskey{showpagecenter};
+ showpapercenter=true/\setaliaskey{showpagecenter};
+ usedummymarks=true;
+ use-dummy-marks=true/\setaliaskey{usedummymarks};
+ defaultfirstpage=1;
+ default-first-page=1/\setaliaskey{defaultfirstpage};
+ defaultlastpage=\xwmgetpagenumber{xwmlastpage};
+ default-last-page=\xwmgetpagenumber{xwmlastpage}/
+ \setaliaskey{defaultlastpage};
+ frontpagestyle=empty;
+ front-page-style=empty/\setaliaskey{frontpagestyle};
+ watermarkparser={;}/\DeclareWatermarkParser{#1};
+ watermark-parser={;}/\setaliaskey{watermarkparser};
+ resetpaperorigin=true/\ifxwm@resetpaperorigin\pdfhorigin\z@pt
+ \pdfvorigin\z@pt\hoffset\z@pt\voffset\z@pt\fi;
+ reset-paper-origin=true/\setaliaskey{resetpaperorigin};
+}
+\ltxkeys@biboolkeys+[XWM]{main}[xwm@]{draft,final}[true]
+ {}{}{\ltxkeys@keyvalerr}
+\ltxkeys@makeoptionkeys[XWM]{main}
+\BeforeStartOfDocument{%
+ \ifxwm@printwatermark
+ \cptreplaceoneelement\XWM@main@initialkeyvals
+ {printwatermark=false}{printwatermark=true}%
+ \fi
+}
+\robust@def*\xwm@defcommonkeys#1{%
+ \begingroup
+ \endlinechar\m@one
+ \expandafter\endgroup\xwm@defc@mmonkeys{#1}%
+}
+\robust@def*\xwm@defc@mmonkeys#1#2{%
+ \csn@def{#1@commonkeys}##1{#2}%
+ \AtEndOfPackage{\letcsntocs{#1@commonkeys}\relax}%
+}
+\xwm@defcommonkeys{xwm-1}{%
+ minmark=true;
+ onepageonly=true;
+ prange=true;
+ tmark=true;
+ pmark=true;
+ graphicsoptions={}/
+ \ifbracedTF{##1}{%
+ \aftercsname{\xwm@stripallouterbraces{##1}}{#1graphicsoptions}
+ }{%
+ \cpt@err{Values of key 'graphicsoptions' not braced}\@ehd
+ };
+ GraphicsOptions=/
+ \ifdocstartedTF{%
+ \xwm@err{\noexpand\GraphicsOptions
+ is a command, not a key.\MsgBrk
+ Maybe you meant 'graphicsoptions'}\@ehd
+ }{};
+ picontoptext=true;
+ picture-on-top-text=true/\setaliaskey{picontoptext};
+ pic-on-top-text=true/\setaliaskey{picontoptext};
+ textontoppic=true/\setaliaskey{picontoptext}[false];
+ text-on-top-picture=true/\setaliaskey{picontoptext}[false];
+ text-on-top-pic=true/\setaliaskey{picontoptext}[false];
+ draftboxcolor=blue;
+ draft-box-color=blue/\setaliaskey{draftboxcolor};
+ textcolor=gray!25;
+ text-color=gray!25/\setaliaskey{textcolor};
+ color=gray!25/\setaliaskey{textcolor};
+ textangle=0;
+ text-angle=0/\setaliaskey{textangle};
+ angle=0/\setaliaskey{textangle};
+ textscale=1;
+ text-scale=1/\setaliaskey{textscale};
+ scale=1/\setaliaskey{textscale};
+ textalign=center/\aftercsname\xwm@settextalign{#1textalign};
+ text-align=center/\setaliaskey{textalign};
+ align=center/\setaliaskey{textalign};
+ showpagecenter=true/\ifdefboolTF{#1showpagecenter}{%
+ \usename{#1showpagecentertrue}}{\usename{#1showpagecenterfalse}};
+ show-page-center=true/\setaliaskey{showpagecenter};
+ showpapercenter=true/\setaliaskey{showpagecenter};
+ fontsize=1cm/\aftercsname{\xwm@defaultunits{##1}}{#1fontsize};
+ fontseries=b;
+ fontfamily=bch;
+ \needvalue{picfile}=/\aftercsname\xwm@stripallouterbracesincs{#1picfile}
+ \ifcsnnullTF{#1picfile}{\usename{#1pmarkfalse}}{\usename{#1pmarktrue}
+ \usename{#1minmarktrue}};
+ \needvalue{picture-file}=/\setaliaskey{picfile};
+ picfileext=\xwm@defaultfileext/\xwm@fileextfn{##1}{#1};
+ pic-file-ext=\xwm@defaultfileext/\setaliaskey{picfileext};
+ picangle=0;
+ picture-angle=0/\setaliaskey{picangle};
+ picscale=1;
+ picture-scale=1/\setaliaskey{picscale};
+ picbb=0 0 100 100;
+ picture-bb=0 0 100 100/\setaliaskey{picbb};
+ pic-bounding-box=0 0 100 100/\setaliaskey{picbb};
+ picxpos=\z@pt;
+ picture-xpos=0/\setaliaskey{picxpos};
+ picture-x-position=0/\setaliaskey{picxpos};
+ picypos=\z@pt;
+ picture-ypos=0/\setaliaskey{picypos};
+ picture-y-position=0/\setaliaskey{picypos};
+ mark=DRAFT/\setaliaskey{textmark};
+ textmark=DRAFT/
+ \aftercsname\xwm@stripallouterbracesincs{#1textmark}
+ \ifcsnnullTF{#1textmark}{%
+ \usename{#1tmarkfalse}
+ }{%
+ \usename{#1tmarktrue}
+ };
+ text-mark=DRAFT/\setaliaskey{textmark};
+ firstpage=true/\ifdefboolFT{#1firstpage}{}{\usename{#1minmarktrue}};
+ first-page=true/\setaliaskey{firstpage};
+ allpages=true/\ifdefboolFT{#1allpages}{}{\usename{#1minmarktrue}};
+ oddpages=true/\ifdefboolFT{#1oddpages}{}{\usename{#1minmarktrue}};
+ evenpages=true/\ifdefboolFT{#1evenpages}{}{\usename{#1minmarktrue}};
+ page=1/
+ \ifinsetTF{-}{##1}{%
+ \xwm@err{I found '-' in '##1' for key 'page',
+ \MsgBrk but 'page' doesn't take page-range}\@ehd
+ }{%
+ \ifnum\numexpr##1=\z@pt\else\usename{#1onepageonlytrue}
+ \usename{#1minmarktrue}\fi
+ };
+ pages=1-1/
+ \aftercsname\xwm@stripallouterbracesincs{#1pages}
+ \aftercsname\xifstrcmpTF{#1pages}{0-0}{}{%
+ \usename{#1prangetrue}\usename{#1minmarktrue}
+ }
+ \cptexpandsecond\xwm@hyphenpagerange{\cptmakecs{#1pages}
+ \cptmakecs{#1pagestart}\cptmakecs{#1pageend}};
+ pagex={1}/
+ \ifbracedTF{##1}{}{%
+ \xwm@err{Value of key 'pagex' must be braced}\@ehd
+ };
+ boxalign=/\ifblankTF{##1}{}
+ {\aftercsname\xwm@setboxalign{#1boxalign}};
+ box-align=/\setaliaskey{boxalign};
+}
+\robust@def*\xwm@adddefkeys{%
+ \begingroup
+ \endlinechar\m@one
+ \cpt@testopt\xwm@addd@fkeys{}%
+}
+\robust@def\xwm@addd@fkeys[#1]#2#3#4#5{%
+ \def\xwm@tempa{\endgroup#4}%
+ \expandafter\expandafter\expandafter\xwm@tempa
+ \expandafter\expandafter\expandafter
+ {\csname#2@commonkeys\endcsname{#3}#1#5}%
+}
+\xwm@adddefkeys[;]{xwm-1}{wmk@}
+ {\ltxkeys@definekeys*[XWM]{watermark}[wmk@]}{%
+ textwidth=\paperheight;
+ text-width=\paperheight/\setaliaskey{textwidth};
+ width=\paperheight/\setaliaskey{textwidth};
+ textheight=\paperwidth;
+ text-height=\paperwidth/\setaliaskey{textheight};
+ height=\paperwidth/\setaliaskey{textheight};
+ \needvalue{picheight}=;
+ pic-height=/\setaliaskey{picheight};
+ picture-height=/\setaliaskey{picheight};
+ \needvalue{picwidth}=;
+ picture-width=/\setaliaskey{picwidth};
+ textxpos=0;
+ text-xpos=0/\setaliaskey{textxpos};
+ text-x-position=0/\setaliaskey{textxpos};
+ xpos=0/\setaliaskey{textxpos};
+ textypos=0;
+ text-ypos=0/\setaliaskey{textypos};
+ text-y-position=0/\setaliaskey{textypos};
+ ypos=0/\setaliaskey{textypos};
+ coordunit=mm/\xwm@checkcoordunit{#1};
+ coord-unit=mm/\setaliaskey{coordunit};
+ position-unit=mm/\setaliaskey{coordunit};
+}
+\ltxkeys@makeoptionkeys*[XWM]{watermark}
+\xwm@adddefkeys[;]{xwm-1}{wlp@}
+ {\ltxkeys@definekeys*[XWM]{wallpaper}[wlp@]}{%
+ textheight=\wlp@tileysize;
+ text-height=\wlp@tileysize/\setaliaskey{textheight};
+ textwidth=\wlp@tilexsize;
+ text-width=\wlp@tilexsize/\setaliaskey{textwidth};
+ picheight=\wlp@tileysize;
+ picture-height=\wlp@tileysize/\setaliaskey{picheight};
+ picwidth=\wlp@tilexsize;
+ picture-width=\wlp@tilexsize/\setaliaskey{picwidth};
+ tilexsize=.25\paperwidth;
+ tile-xsize=.25/\setaliaskey{tilexsize};
+ tileysize=.25\paperheight;
+ tile-ysize=.25/\setaliaskey{tileysize};
+ wpxoffset=\z@pt;
+ wallpaper-xoffset=\z@pt/\setaliaskey{wpxoffset};
+ wpyoffset=\z@pt;
+ wallpaper-yoffset=\z@pt/\setaliaskey{wpyoffset};
+ tilexoffset=\z@pt;
+ tile-xoffset=\z@pt/\setaliaskey{tilexoffset};
+ tileyoffset=\z@pt;
+ tile-yoffset=\z@pt/\setaliaskey{tileyoffset};
+ tileno=4;
+ tilenumber=4/\setaliaskey{tileno};
+ tile-number=4/\setaliaskey{tileno};
+ number-of-tiles=4/\setaliaskey{tileno};
+ squaretiles=true;
+ square-tiles=true/\setaliaskey{squaretiles};
+}
+\ltxkeys@makeoptionkeys*[XWM]{wallpaper}
+\ltxkeys@definekeys*[XWM]{fancypagenos}[pgn@]{%
+ textalign=center/\xwm@settextalign\pgn@textalign;
+ text-align=center/\setaliaskey{textalign};
+ align=center/\setaliaskey{textalign};
+ boxalign=/\ifblankTF{#1}{}{\xwm@setboxalign\pgn@boxalign};
+ box-align=center/\setaliaskey{boxalign};
+ textangle=0;
+ text-angle=0/\setaliaskey{textangle};
+ angle=0/\setaliaskey{textangle};
+ picangle=0;
+ picture-angle=0/\setaliaskey{picangle};
+ textwidth=.25\textwidth;
+ text-width=.25/\setaliaskey{textwidth};
+ width=.25\hsize/\setaliaskey{textwidth};
+ textheight=.25\textheight;
+ text-height=.25/\setaliaskey{textheight};
+ height=.25\vsize/\setaliaskey{textheight};
+ textxpos=\z@pt;
+ x-position=0/\setaliaskey{textxpos};
+ xposition=0/\setaliaskey{textxpos};
+ xpos=\z@pt/\setaliaskey{textxpos};
+ textypos=\z@pt;
+ y-position=0/\setaliaskey{textypos};
+ yposition=0/\setaliaskey{textypos};
+ ypos=\z@pt/\setaliaskey{textypos};
+ textcolor=blue;
+ text-color=blue/\setaliaskey{textcolor};
+ color=blue/\setaliaskey{textcolor};
+ textscale=2.5;
+ text-scale=2.5/\setaliaskey{textscale};
+ scale=2.5/\setaliaskey{textscale};
+ coordunit=mm/\xwm@checkcoordunit{#1};
+ coord-unit=mm/\setaliaskey{coordunit};
+ position-unit=mm/\setaliaskey{coordunit};
+ fontfamily=bch;
+ fontseries=m;
+ format=\fbox;
+ framerule=.4\p@;
+ framesep=3\p@;
+ fontsize=12\p@/\xwm@defaultunits{#1}\pgn@fontsize;
+ cfoot;
+ center-footer=/\setaliaskey{cfoot};
+ footer-center=/\setaliaskey{cfoot};
+ rfoot;
+ right-footer=/\setaliaskey{rfoot};
+ footer-right=/\setaliaskey{rfoot};
+ lfoot;
+ left-footer=/\setaliaskey{lfoot};
+ footer-left=/\setaliaskey{lfoot};
+ chead;
+ center-header=/\setaliaskey{chead};
+ header-center=/\setaliaskey{chead};
+ rhead;
+ right-header=/\setaliaskey{rhead};
+ header-right=/\setaliaskey{rhead};
+ lhead;
+ left-header=/\setaliaskey{lhead};
+ header-left=/\setaliaskey{lhead};
+ headruleheight=.4\p@;
+ headrule-height=.4\p@/\setaliaskey{headruleheight};
+ headruledepth=.4\p@;
+ headrule-depth=.4\p@/\setaliaskey{headruledepth};
+ headrulewidth=\headwidth;
+ headrule-width=\headwidth/\setaliaskey{headrulewidth};
+ headrulesep=2\p@;
+ headrule-sep=2\p@/\setaliaskey{headrulesep};
+ headrule-separation=2\p@/\setaliaskey{headrulesep};
+ headrulecolor=blue;
+ headrule-color=blue/\setaliaskey{headrulecolor};
+ footruleheight=.4\p@;
+ footrule-height=.4\p@/\setaliaskey{footruleheight};
+ footruledepth=.4\p@;
+ footrule-depth=.4\p@/\setaliaskey{footruledepth};
+ footrulewidth=\headwidth;
+ footrule-width=\headwidth/\setaliaskey{footrulewidth};
+ footrulesep=2\p@;
+ footrule-sep=2\p@/\setaliaskey{footrulesep};
+ footrule-separation=2\p@/\setaliaskey{footrulesep};
+ footrulecolor=cyan;
+ footrule-color=blue/\setaliaskey{footrulecolor};
+ hfoffsetleft=.5;
+ hfoffset-left=.5/\setaliaskey{hfoffsetleft};
+ hfoffsetright=.5;
+ hfoffset-right=.5/\setaliaskey{hfoffsetright};
+ style=\thepage;
+ printstyle=\thepage/\setaliaskey{style};
+ sendtoback=true;
+}
+\ltxkeys@makeoptionkeys*[XWM]{fancypagenos}
+\ltxkeys@definekeys*[XWM]{fancypagenos}[pgn@]{%
+ showpagenos=true/\ifpgn@showpagenos\global\pgn@showpagenostrue\fi;
+ showpagenumbers=true/\setaliaskey{showpagenos};
+ show-page-numbers=true/\setaliaskey{showpagenos};
+ show-pagenos=true/\setaliaskey{showpagenos};
+ show-pageno=true/\setaliaskey{showpagenos};
+ showonpageone=true;
+ show-on-page-one=true/\setaliaskey{showonpageone};
+ showheadrule=true;
+ show-headrule=true/\setaliaskey{showheadrule};
+ showfootrule=true;
+ show-footrule=true/\setaliaskey{showfootrule};
+}
+\BeforeStartOfDocument{%
+ \ifpgn@showpagenos
+ \cptreplaceoneelement\XWM@fancypagenos@initialkeyvals
+ {showpagenos=false}{showpagenos=true}%
+ \fi
+}
+\robust@def*\PrintWatermark{\global\xwm@printwatermarktrue}
+\ltxkeys@declareoption*{%
+ \ltxkeys@getpvalnopad
+ \xwm@warn{Unknown option '\CurrentKey' with
+ value '\InnocentVal' ignored}%
+}
+\ltxkeys@executeoptions[XWM]<main>{%
+ printwatermark=true,disablegeometry=false
+}\relax
+\ltxkeys@processoptions*[XWM]<main,watermark,wallpaper,%
+ fancypagenos>\relax
+\new@def*\xwm@samplemarkkeys{%
+ firstpage,lastpage,allpages,oddpages,evenpages,
+ picscale,picture-scale,
+ picfile,picture-file,
+ picfileext,pic-file-ext,
+ picangle,picture-angle,
+ picbb,picture-bb,pic-bounding-box,
+ picxpos,picture-xpos,picture-x-position,
+ picypos,picture-ypos,picture-y-position,
+ showpagecenter,show-page-center,
+ picontoptext,picture-on-top-text,pic-on-top-text,
+ textontoppic,text-on-top-picture,text-on-top-pic=true,
+ pic-height,picture-height,
+ picwidth,picture-width,
+ squaretiles,square-tiles,
+ tilexsize,tile-xsize,
+ tileysize,tile-ysize,
+ wpxoffset,wallpaper-xoffset,
+ wpyoffset,wallpaper-yoffset,
+ tilexoffset,tile-xoffset,
+ tileyoffset,tile-yoffset,
+ tileno,tilenumber,tile-number,number-of-tiles
+}
+\new@def*\xwm@pagespecifiers{%
+ % '=' is needed here to create uniqueness; eg, to avoid confusing
+ % ',page' with ',pages'.
+ page=,pages=,pagex=,firstpage,lastpage,allpages,oddpages,evenpages,%
+ section=,sections=,sectionx=%
+}
+\robust@def*\xwm@decidedetok#1{%
+ \ifntypeTF{#1}{%
+ \ifmacroTF{#1}{%
+ \let\xwm@detoktype\cptoxdetok
+ }{%
+ \let\xwm@detoktype\detokenize
+ }%
+ }{%
+ \let\xwm@detoktype\detokenize
+ }%
+}
+\robust@def*\xwm@decidexp#1{%
+ \ifntypeTF{#1}{%
+ \ifmacroTF{#1}{%
+ \let\xwm@exptype\expandcsonce
+ }{%
+ \let\xwm@exptype\unexpanded
+ }%
+ }{%
+ \let\xwm@exptype\unexpanded
+ }%
+}
+\robust@def*\newwatermark#1{%
+ \xwm@wallfalse
+ \ifstrcmpTF{#1}\dummywatermark{%
+ \xwm@err{'\string\dummywatermark' in front of
+ \string\newwatermark}{First comment out or
+ remove '\string\dummywatermark'.}%
+ }{%
+ \def\xwm@forelist{\xwm@forewmklist}%
+ \def\xwm@backlist{\xwm@backwmklist}%
+ \xwm@suffixcheck\xwm@newwatermark{#1}%
+ }%
+}
+\robust@def*\xnewwatermark{%
+ \xwm@suffixcheck{\cpt@teststpm{\cpt@testopt\cpt@xnewwatermark{}}}%
+}
+\robust@def*\xwm@ltxcmds{%
+ \centering,\flushright,\flushleft,\raggedright,%
+ \raggedleft,\fbox,\framebox,\makebox,\rotatebox,%
+ \scalebox,\raisebox,\color,\textcolor,\usecsn,%
+ \newcommand,\lastdocpage
+}
+\robust@def*\xwm@relaxltxcmds{%
+ \def\ltxkeys@do##1{\let##1=\relax}%
+ \ltxkeys@parse*1\xwm@ltxcmds
+}
+\robust@def*\cpt@xnewwatermark[#1]#2{%
+ \begingroup
+ \xwm@relaxltxcmds
+ \cptexpanded{%
+ \endgroup
+ \newwatermark\ifcpt@st*\fi\ifcpt@pm'\fi
+ [\expandcstwice{#1}]{\expandcstwice{#2}}%
+ }%
+}
+\robust@def*\newwallpaper#1{%
+ \xwm@walltrue
+ \ifstrcmpTF{#1}\dummywallpaper{%
+ \xwm@err
+ {'\string\dummywallpaper' in front of \string\newwallpaper}%
+ {First comment out or remove '\string\dummywallpaper'.}%
+ }{%
+ \def\xwm@forelist{\xwm@forewalllist}%
+ \def\xwm@backlist{\xwm@backwalllist}%
+ \xwm@suffixcheck\xwm@newwatermark{#1}%
+ }%
+}
+\robust@def*\xnewwallpaper{%
+ \cpt@teststpm{\cpt@testopt\cpt@xnewwallpaper{}}%
+}
+\robust@def*\cpt@xnewwallpaper[#1]#2{%
+ \begingroup
+ \xwm@relaxltxcmds
+ \cptexpanded{%
+ \endgroup
+ \newwallpaper\ifcpt@st*\fi\ifcpt@pm'\fi
+ [\expandcstwice{#1}]{\expandcstwice{#2}}%
+ }%
+}
+\robust@def*\xwm@newwatermark{%
+ \def\siso@do##1{\catcode`##1\string=12}%
+ \cpt@teststpm{%
+ \let\ifxwm@foregrd\ifcpt@st
+ \cpt@testopt{%
+ \begingroup
+ \expandafter\siso@@loop\expandafter
+ {\xwm@watermarkparser,;|-=!'"*}%
+ \expandafter\endgroup\xwm@n@wwatermark
+ }{}%
+ }%
+}
+\robust@def\xwm@n@wwatermark[#1]#2{%
+ \ifdefboolTF{cpt@pm}{}{\xwm@n@ww@termark{#1}{#2}}%
+}
+\robust@def\xwm@n@ww@termark#1#2{%
+ \xwm@decidexp{#1}%
+ \edef\xwm@currattrib{\xwm@exptype{#1}}%
+ \cpt@sttrue\cpt@kvnormalize[,]\xwm@currattrib
+ \xwm@decidexp{#2}%
+ \edef\xwm@currmark{\xwm@exptype{#2}}%
+ \xwm@decidedetok{#2}%
+ \xwm@swafalse
+ \xifinsetTF{\detokenize{\newwatermark}}{\xwm@detoktype{#2}}{%
+ \xwm@swatrue
+ }{%
+ \xifinsetTF{\detokenize{\newwallpaper}}{\xwm@detoktype{#2}}{%
+ \xwm@swatrue
+ }{}%
+ }%
+ \ifxwm@swa
+ \ifxwm@allownesting\else
+ \xwm@err{Nested '\string\newwatermark' or
+ '\string\newwallpaper'\MsgBrk
+ while option 'allownesting' is false}\@ehd
+ \fi
+ \fi
+ \ifdefboolTF{xwm@wall}{}{%
+ \xwmifitemsinFT[1]{%
+ squaretiles,square-tiles,tilexsize,tile-xsize,%
+ tileysize,tile-ysize,wpxoffset,wallpaper-xoffset,%
+ wpyoffset,wallpaper-yoffset,tilexoffset,tile-xoffset,%
+ tileyoffset,tile-yoffset,tileno,tilenumber,%
+ tile-number,number-of-tiles%
+ }{#1}{}{%
+ \xwm@@err{'\xwm@items' not admissible for
+ \MsgBrk non-wallpaper watermarks}\@ehd
+ }%
+ }%
+ \ifdefboolTF{xwm@allownesting}{}{%
+ \cpt@choicefdfalse
+ \def\csv@do##1{%
+ \xifinsetFT{,\detokenize{##1}}{,\xwm@detoktype{#2}}{}{%
+ \def\xwm@tempa{##1}%
+ \cpt@choicefdtrue\loopbreak
+ }%
+ }%
+ \csv@@parse*[,]\xwm@samplemarkkeys
+ \ifcpt@choicefd
+ \xwm@err{Illegal location of '\xwm@tempa'.
+ \MsgBrk The following keys are not allowed in
+ \MsgBrk mandatory/second argument of
+ \MsgBrk '\string\newwatermark' or '\string\newwallpaper':
+ ^^J||\xwm@samplemarkkeys||}\@ehd
+ \fi
+ }%
+ \xifinsetFT\xwm@watermarkparser{\xwm@detoktype{#2}}{}{%
+ \xwm@err{Watermark parser '\xwm@watermarkparser' appears in
+ the following watermark.\MsgBrk Enclose your token
+ '\xwm@watermarkparser' in braces:^^J||\unexpanded{#2}||}\@ehd
+ }%
+ \xxwmifitemsinTF[1]\xwm@pagespecifiers{\expandcsonce\xwm@currattrib}{%
+ \xxwmifitemsinTF[2]\xwm@pagespecifiers{\expandcsonce\xwm@currattrib}{%
+ \xwm@err{Too many page specifiers '\xwm@items' for watermark:
+ ^^J||\expandcsonce\xwm@currattrib||}{%
+ Only one page specifier is allowed in watermark.}%
+ }{}%
+ }{%
+ \xwm@err{No page specifier for watermark:
+ ^^J||\expandcsonce\xwm@currmark||}\@ehd
+ }%
+ \ifcsnullTF\xwm@currattrib{%
+ \ifcsnullTF\xwm@currmark{}{%
+ \xwm@@err{No attributes for watermark:
+ ^^J||\expandcsonce\xwm@currmark||}\@ehd
+ }%
+ }{%
+ \xwm@makecurrmark
+ }%
+ \edef\reserved@a{%
+ \ifxwm@foregrd\expandcsonce\xwm@forelist\else
+ \expandcsonce\xwm@backlist\fi
+ }%
+ \expandafter\edef\reserved@a{%
+ \expandafter\ifdefined\reserved@a\expandcstwice\reserved@a\fi
+ \expandcsonce\xwm@currwatermark
+ }%
+}
+\robust@def*\xwm@avoidtwopagespecs{%
+ \if\xwm@pagespecfd
+ \xwm@err{Two page specifiers in watermark attributes:
+ ^^J||\cptoxdetok\xwm@currattrib||}\@ehd
+ \else
+ \def\xwm@pagespecfd{00}%
+ \fi
+}
+\robust@def*\xwm@addcurrmark#1{%
+ % Local group is in effect.
+ % If the current mark is already on current page, ignore it. This, eg,
+ % avoids 'pagex={1,1,2},textmark=X' making two entries for 'X' on page 1.
+ \letcstocsn\reserved@a{xwm@mark@@\romannumeral#1}%
+ \ifx\reserved@a\xwm@currattrib\else
+ \xifinsetTF{\detokenize{textmark=}}{\cptoxdetok\xwm@currattrib}{%
+ \@tempswafalse
+ \ifx\xwm@currmark\@empty\else
+ \xwm@err{Duplicate textmark in ||\cptoxdetok\xwm@currmark||}
+ {I found textmark earlier in the mandotory argument of
+ \noexpand\newwatermark, and now I find textmark key in the
+ attribute list.}%
+ \fi
+ }{%
+ \@tempswatrue
+ }%
+ \edef\xwm@tempb{%
+ page=\number#1,\expandcsonce\xwm@currattrib,%
+ \if@tempswa textmark={\expandcsonce\xwm@currmark}\fi
+ }%
+ \edef\xwm@currwatermark{%
+ % {<page.no>}{<curr.mark>}
+ \expandcsonce\xwm@currwatermark{\number#1}{\expandcsonce\xwm@tempb}%
+ }%
+ \gletcsntocs{xwm@mark@@\romannumeral#1}\xwm@currattrib
+ \fi
+}
+\robust@def*\xwm@getpagespec#1{%
+ \ifinsetTF{,#1,}{,page,pages,pagex,section,sections,sectionx,}{%
+ % \xwm@ifpagespec has shown that #1 is in \xwm@currattrib. We
+ % need to confirm that '#1=' is in \xwm@currattrib.
+ \xifinsetTF{,\detokenize{#1=}}{,\cptoxdetok\xwm@currattrib}{%
+ \def\xwm@tempa##1#1=##2,##3\xwm@nil{%
+ \ifblankTF{##2}{%
+ \xwm@warn{Key '#1' has an empty value; '1' assumed}\@ehd
+ \def\xwm@currpages{1}%
+ }{%
+ \ifinsetTF{,#1,}{,pages,sections,}{%
+ \ifinsetTF{,}{##2}{%
+ \xwm@err{Key '#1' doesn't accept comma-separated
+ \MsgBrk page numbers: use a hyphen}\@ehd
+ }{}%
+ }{%
+ \ifinsetTF{,#1,}{,pagex,sectionx,}{%
+ \ifinsetTF{-}{##2}{%
+ \xwm@err{Key '#1' doesn't accept hyphen-separated
+ \MsgBrk page numbers: use commas}\@ehd
+ }{}%
+ }{}%
+ }%
+ \def\xwm@currpages{##2}%
+ }%
+ \edef\xwm@currattrib{\unexpanded{##1,##3}}%
+ }%
+ \expandafter\xwm@tempa\xwm@currattrib,\xwm@nil
+ }{%
+ \xwm@err{Key '#1' doesn't have '=' and a value}\@ehd
+ }%
+ }{%
+ \xwm@getpagespec@a{#1}%
+ }%
+ \kv@@normalize*\xwm@currattrib
+}
+\robust@def*\xwm@getpagespec@a#1{%
+ \xifinsetTF{,\detokenize{#1=true},}{,\cptoxdetok\xwm@currattrib,}{%
+ \def\xwm@tempa##1#1=true,##2\xwm@nil{%
+ \edef\xwm@currattrib{\unexpanded{##1,##2}}%
+ }%
+ \expandafter\xwm@tempa\xwm@currattrib,\xwm@nil
+ }{%
+ \xifinsetTF{,\detokenize{#1=false},}{,\cptoxdetok\xwm@currattrib,}{%
+ \def\xwm@tempa##1#1=false,##2\xwm@nil{%
+ \edef\xwm@currattrib{\unexpanded{##1,##2}}%
+ }%
+ \expandafter\xwm@tempa\xwm@currattrib,\xwm@nil
+ }{%
+ \def\xwm@tempa##1#1,##2\xwm@nil{%
+ \edef\xwm@currattrib{\unexpanded{##1,##2}}%
+ }%
+ \expandafter\xwm@tempa\xwm@currattrib,\xwm@nil
+ }%
+ }%
+}
+\robust@def*\xwm@ifpagespec#1{%
+ \@expandtwoargs\cpt@in{,\detokenize{#1}}{,\cptoxdetok\xwm@currattrib}%
+ \ifdefboolTF{cpt@in}\@iden\@gobble
+}
+\robust@def*\xwm@normalizedoublecomma#1{%
+ \def\xwm@tempa##1,,##2\normal@nil{%
+ \ifblankTF{##2}{%
+ \edef#1{\unexpanded{##1}}%
+ }{%
+ \xwm@tempa##1,##2\normal@nil
+ }%
+ }%
+ \expandafter\xwm@tempa#1,,\normal@nil
+}
+\robust@def*\xwm@makecurrmark{%
+ \begingroup
+ \edef\xwm@lastpage{\lastdocpage}%
+ \def\xwm@currwatermark{}%
+ \def\xwm@pagespecfd{01}%
+ \xwm@ifpagespec{page=}{%
+ \xwm@avoidtwopagespecs
+ \xwm@getpagespec{page}%
+ \xwm@addcurrmark\xwm@currpages
+ }%
+ \xwm@ifpagespec{pages=}{%
+ \xwm@avoidtwopagespecs
+ \xwm@getpagespec{pages}%
+ \xwm@hyphenpagerange\xwm@currpages\xwm@pagestart\xwm@pageend
+ \xwm@cnta\numexpr\xwm@pagestart\relax
+ \cptloop
+ \xwm@addcurrmark\xwm@cnta
+ \advance\xwm@cnta\@ne
+ \ifnum\xwm@cnta<\numexpr\xwm@pageend+1\relax
+ \cptrepeat
+ }%
+ \xwm@ifpagespec{pagex=}{%
+ \xwm@avoidtwopagespecs
+ \xwm@getpagespec{pagex}%
+ \expandafter\cptfor\xwm@currpages\dofor{%
+ \xwm@addcurrmark{##1}%
+ }%
+ }%
+ \xwm@ifpagespec{firstpage}{%
+ \xwm@avoidtwopagespecs
+ \xwm@getpagespec{firstpage}%
+ \xwm@addcurrmark{1}%
+ }%
+ \xwm@ifpagespec{lastpage}{%
+ \xwm@avoidtwopagespecs
+ \xwm@getpagespec{lastpage}%
+ \xwm@addcurrmark\xwm@lastpage
+ }%
+ \xwm@ifpagespec{allpages}{%
+ \xwm@avoidtwopagespecs
+ \xwm@getpagespec{allpages}%
+ \xwm@cnta\@ne
+ \cptloop
+ \xwm@addcurrmark\xwm@cnta
+ \advance\xwm@cnta\@ne
+ \ifnum\xwm@cnta<\numexpr\xwm@lastpage+1\relax
+ \cptrepeat
+ }%
+ \xwm@ifpagespec{evenpages}{%
+ \xwm@avoidtwopagespecs
+ \xwm@getpagespec{evenpages}%
+ \xwm@cnta\@ne
+ \cptloop
+ \ifodd\xwm@cnta\else
+ \xwm@addcurrmark\xwm@cnta
+ \fi
+ \advance\xwm@cnta\@ne
+ \ifnum\xwm@cnta<\numexpr\xwm@lastpage+1\relax
+ \cptrepeat
+ }%
+ \xwm@ifpagespec{oddpages}{%
+ \xwm@avoidtwopagespecs
+ \xwm@getpagespec{oddpages}%
+ \xwm@cnta\z@pt
+ \cptloop
+ \ifodd\xwm@cnta
+ \xwm@addcurrmark\xwm@cnta
+ \fi
+ \advance\xwm@cnta\@ne
+ \ifnum\xwm@cnta<\numexpr\xwm@lastpage+1\relax
+ \cptrepeat
+ }%
+ % Incomplete concept. To be refined later. Basically, I want to get page
+ % range from section numbers. The work to be done next is actually in
+ % formatting \xwm@seclist and completing \xwm@convertsecstopagerange and
+ % \xwm@convertsecstopagerange@hyphen.
+ \xwm@ifpagespec{section=}{%
+ \xwm@avoidtwopagespecs
+ \xwm@getpagespec{section}%
+ \xwm@convertsecstopagerange\xwm@currpages
+ \xwm@addcurrmark\xwm@currpages
+ }%
+ \xwm@ifpagespec{sections=}{%
+ \xwm@avoidtwopagespecs
+ \xwm@getpagespec{sections}%
+ \xwm@convertsecstopagerange@hyphen\xwm@currpages
+ \xwm@hyphenpagerange\xwm@currpages\xwm@pagestart\xwm@pageend
+ \xwm@cnta\numexpr\xwm@pagestart\relax
+ \cptloop
+ \xwm@addcurrmark\xwm@cnta
+ \advance\xwm@cnta\@ne
+ \ifnum\xwm@cnta<\numexpr\xwm@pageend+1\relax
+ \cptrepeat
+ }%
+ \xwm@ifpagespec{sectionx=}{%
+ \xwm@avoidtwopagespecs
+ \xwm@getpagespec{sectionx}%
+ \xwm@convertsecstopagerange\xwm@currpages
+ \expandafter\cptfor\xwm@currpages\dofor{%
+ \xwm@addcurrmark{##1}%
+ }%
+ }%
+ \if\xwm@pagespecfd\else
+ \xwm@err{No page specifier in watermark attributes:
+ ^^J||\cptoxdetok\xwm@currattrib||}\@ehd
+ \fi
+ \postgroupdef\xwm@currwatermark\endgroup
+}
+% \xwm@convertsecstopagerange{<section.range>}
+\robust@def*\xwm@convertsecstopagerange#1{%
+ \begingroup
+ \def\xwm@tempa{}%
+ \expandafter\cptfor#1\dofor{%
+ \letcstocsn\reserved@a{xwm@sec@page@start@\detokenize{##1}}%
+ \letcstocsn\reserved@b{xwm@sec@page@end@\detokenize{##1}}%
+ \ifx\reserved@a\undefined
+ \def\reserved@a{1}%
+ \fi
+ \ifx\reserved@b\undefined
+ \def\reserved@b{1}%
+ \fi
+ % To do:
+ % To build the page range for each section, loop from section start
+ % (page start) to section end (page end).
+ \xifinsetTF{,\reserved@a,}{,\xwm@tempa,}{}{%
+ \edef\xwm@tempa{%
+ \xwm@tempa\ifx\xwm@tempa\@empty\else,\fi\reserved@a
+ }%
+ }%
+ }%
+ \let#1\xwm@tempa
+ \postgroupdef#1\endgroup
+}
+% \xwm@convertsecstopagerange@hyphen{<section.range>}
+\robust@def*\xwm@convertsecstopagerange@hyphen#1{%
+ \begingroup
+ \def\xwm@tempa{}%
+ \def\csv@do##1{%
+ \letcstocsn\reserved@a{xwm@sec@page@start@\detokenize{##1}}%
+ \ifx\reserved@a\undefined
+ \def\reserved@a{1}%
+ \fi
+ \xifinsetTF{-\reserved@a-}{-\xwm@tempa-}{}{%
+ \edef\xwm@tempa{%
+ \xwm@tempa\ifx\xwm@tempa\@empty\else-\fi\reserved@a
+ }%
+ }%
+ }%
+ \csv@@parse*[-]#1%
+ \let#1\xwm@tempa
+ \postgroupdef#1\endgroup
+}
+\robust@def*\dummywatermark#1{%
+ \ifstrcmpTF{#1}\newwatermark{%
+ \xwm@err
+ {'\string\newwatermark' in front of \string\dummywatermark}%
+ {First comment out or remove '\string\newwatermark'.}%
+ }{%
+ \ifdefboolTF{xwm@usedummymarks}\newwatermark\xwm@dummywatermark
+ #1%
+ }%
+}
+\robust@def*\dummywallpaper#1{%
+ \ifstrcmpTF{#1}\newwallpaper{%
+ \xwm@err
+ {'\string\newwallpaper' in front of \string\dummywallpaper}%
+ {First comment out or remove '\string\newwallpaper'.}%
+ }{%
+ \ifdefboolTF{xwm@usedummymarks}\newwallpaper\xwm@dummywatermark
+ #1%
+ }%
+}
+\robust@def*\xwm@dummywatermark{%
+ \cpt@teststpm{\cpt@testopt\xwm@d@mmywatermark{}}%
+}
+\robust@def*\xwm@d@mmywatermark[#1]#2{}
+\robust@def*\UseDummyWatermarks{\global\xwm@usedummymarkstrue}
+\robust@def*\DiscardDummyWatermarks{\global\xwm@usedummymarksfalse}
+\DiscardDummyWatermarks
+\robust@def*\DiscardAllWatermarks{%
+ \global\let\newwatermark\dummywatermark
+ \global\xwm@usedummymarksfalse
+}
+\robust@def*\xwmsuspendwatermark{\xwm@putmarkfalse}
+\robust@def*\xwmresumewatermark{\xwm@putmarktrue}
+\newletcs\xwmwatermarkoff\xwmsuspendwatermark
+\newletcs\xwmwatermarkon\xwmresumewatermark
+
+\robust@def*\xwm@putbothmarks{%
+ \ifdefboolFT{xwm@putmark}{}{%
+ \ifdefFT\xwm@watermarklist{}\xwm@textpicmark@a
+ \ifdefFT\xwm@wallpaperlist{}\xwm@wallpaper@a
+ }%
+}
+\chardef\xwm@nowatermarksignal\z@pt
+\AtBeginShipout{%
+ \endlinechar13 \catcode13=5\relax
+ \catcode`\ =10\relax
+ \catcode`\\\z@pt
+ \catcode`\{\@ne
+ \catcode`\}\tw@
+ \ifdefboolTF{xwm@printwatermark}{%
+ \let\xwm@watermarklist\xwm@backwmklist
+ \let\xwm@wallpaperlist\xwm@backwalllist
+ \AtBeginShipoutUpperLeft{%
+ \xwm@foregrdfalse
+ \xwm@putbothmarks
+ }%
+ \let\xwm@watermarklist\xwm@forewmklist
+ \let\xwm@wallpaperlist\xwm@forewalllist
+ \AtBeginShipoutUpperLeftForeground{%
+ \xwm@foregrdtrue
+ \xwm@putbothmarks
+ }%
+ }{%
+ \ifnum\xwm@nowatermarksignal<\@ne
+ \edef\xwm@nowatermarksignal{\the\numexpr\xwm@nowatermarksignal+1}%
+ \xwm@info{'printwatermark=false': no watermark printed}%
+ \fi
+ }%
+}
+\robust@def*\xwm@perpagestate{%
+ page=0,
+ pagex={0},
+ pages=0-0,
+ minmark=false,
+ onepageonly=false,
+ prange=false,
+ tmark=false,
+ pmark=false,
+ firstpage=false,
+ allpages=false,
+ oddpages=false,
+ evenpages=false,
+ showpagecenter=false,
+ textmark=DRAFT,
+ textalign=center,
+ boxalign=,
+ textcolor=gray!55,
+ fontfamily=bch,
+ textangle=0,
+ picangle=0,
+ fontsize=1cm,
+ fontseries=b,
+ textscale=1,
+ picscale=1,
+ picheight=,
+ picwidth=,
+ picbb=0 0 100 100,
+ picfileext,
+ picontoptext=false,
+ graphicsoptions={},
+}
+\robust@edef*\xwm@perpagewmkstate{%
+ \expandcsonce\xwm@perpagestate,
+ \unexpanded{%
+ height=\paperwidth,
+ width=\paperheight,
+ textxpos=0,
+ textypos=0,
+ picxpos=\z@pt,
+ picypos=\z@pt,
+ coordunit=mm
+ }%
+}
+\robust@edef*\xwm@perpagewallstate{%
+ \expandcsonce\xwm@perpagestate,
+ \unexpanded{%
+ tilexsize=.5\paperwidth,
+ tileysize=.5\paperheight,
+ wpxoffset=\z@pt,
+ wpyoffset=\z@pt,
+ textmark=,
+ picfile=,
+ tilexoffset=\z@pt,
+ tileyoffset=\z@pt,
+ tileno=4,
+ squaretiles=false
+ }%
+}
+\robust@def*\xwm@textpicmark@a{%
+ \ifcsnullTF\xwm@watermarklist{%
+ \ifdefboolTF{xwm@foregrd}{}{%
+ \ifdefboolFT{xwm@printwatermark}{}{%
+ \ifdefboolTF{xwm@draft}{%
+ \ifdefboolTF{wmk@showpagecenter}{}{%
+ \ifnumcmpFT\c@page=\@ne{}{%
+ \cptexpandargonce{\ltxkeys@setkeys[XWM]{watermark}}%
+ \xwm@perpagewmkstate
+ \wmk@tmarktrue\wmk@pmarkfalse
+ \cptdimdef\wmk@textxpos@a{0.5\paperwidth}%
+ \cptdimdef\wmk@textypos@a{-0.5\paperheight}%
+ \xwm@textpicmark@c
+ \xwm@info{'printwatermark' and 'draft' are 'true'
+ \MsgBrk but no watermark(s): watermark
+ \MsgBrk printed on page 1 only}%
+ }%
+ }%
+ }{%
+ \ifnum\c@page=\@ne
+ \xwm@info{'printwatermark=true' and 'draft=false'
+ \MsgBrk but no watermark(s)}%
+ \fi
+ }%
+ }%
+ }%
+ }{%
+ \xwm@processmarks\xwm@watermarklist{%
+ \xwm@setwatermarkkeys{watermark}{wmk}{##2}%
+ \ifdefboolFT{wmk@minmark}{}\xwm@textpicmark@c
+ }%
+ }%
+}
+\robust@def*\xwm@wallpaper@a{%
+ \ifcsnullTF\xwm@wallpaperlist{}{%
+ \xwm@processmarks\xwm@wallpaperlist{%
+ \xwm@setwatermarkkeys{wallpaper}{wall}{##2}%
+ \ifdefboolFT{wlp@minmark}{}\xwm@wallpaper@c
+ }%
+ }%
+}
+\robust@def*\xwm@setwatermarkkeys#1#2#3{%
+ \ltxkeys@getkeynames{#3}%
+ \cptexpandsecond{%
+ \ltxkeys@setkeys[XWM]{#1}%
+ }{%
+ [\ltxkeys@keynames]{\expandcsnonce{xwm@perpage#2state}}%
+ }%
+ \edef\xwm@currwatermark{\unexpanded{#3}}%
+ \ifblankTF{#3}{}{\ltxkeys@setkeys[XWM]{#1}{#3}}%
+}
+\robust@def*\xwm@processmarks#1#2{%
+ \def\xwm@pr@cessmarks##1##2{%
+ \ifstrcmpTF{##1}{\@nil}{}{%
+ \ifnumcmpTF##1=\c@page{#2}{%
+ \edef#1{\expandcsonce#1\unexpanded{{##1}{##2}}}%
+ }%
+ \xwm@pr@cessmarks
+ }%
+ }%
+ \cptexpandsecondonce{\def#1{}\xwm@pr@cessmarks}{#1}{\@nil}{}%
+}
+\ltxkeys@disablekeys*[XWM]{main}{printwatermark,disablegeometry}
+\BeforeStartOfDocument{%
+ \unless\ifxwm@printwatermark
+ \xwm@info{*** printwatermark=false: no watermark printed}%
+ \fi
+}
+\newcommand\xwm@papercenter{%
+ \color{red}\noindent
+ \xwm@put(0,-0.5\paperheight){\line(1,0){\paperwidth}}%
+ \xwm@put(0.5\paperwidth,0){\line(0,-1){\paperheight}}%
+ \xwm@put(0.5\paperwidth,-0.5\paperheight){\circle{10}}%
+ \normalcolor
+}
+\robust@def*\xwm@textbox#1{%
+ \begingroup
+ \let\nxp\noexpand
+ \let\mcs\cptmakecs
+ \edef\xwm@curralign{\expandcsnonce{#1@textalign}}%
+ \cptexpanded{\endgroup
+ \xwm@put(\mcs{#1@textxpos@a},\mcs{#1@textypos@a}){%
+ \nxp\leavevmode\nxp\@killglue\noindent
+ \nxp\makebox(0,0)[\expandcsnonce{#1@boxalign}]{%
+ \nxp\rotatebox[origin=c]{\mcs{#1@textangle}}{%
+ \nxp\scalebox{\mcs{#1@textscale}}{%
+ \nxp\parbox[c][\mcs{#1@textheight}]%
+ [c]\mcs{#1@textwidth}{%
+ \nxp\color{\mcs{#1@textcolor}}%
+ \cptdimdef\mcs{#1@fontsize@a}{\mcs{#1@fontsize}}%
+ \cptdimdef\mcs{#1@fontsize@a}%
+ {1.5\p@*\mcs{#1@fontsize@a}}%
+ \nxp\fontfamily\mcs{#1@fontfamily}%
+ \nxp\fontseries\mcs{#1@fontseries}%
+ \nxp\fontsize\mcs{#1@fontsize}\mcs{#1@fontsize@a}%
+ \nxp\selectfont
+ \nxp\leavevmode
+ \nxp\begin{\xwm@curralign}%
+ \mcs{#1@textmark}%
+ \nxp\end{\xwm@curralign}%
+ }%
+ }%
+ }%
+ }%
+ }%
+ }%
+ \@killglue\normalcolor
+}
+% See also \xwmgetpicturesize.
+\robust@def*\xwm@getgrafsize#1{%
+ \ifcsnnullTF{#1@picwidth}{%
+ \ifcsnnullTF{#1@picheight}{%
+ \edef\pic@size{scale=\cptmakecs{#1@picscale}}%
+ }{%
+ \xwm@err{You have supplied picture height
+ but not width}\@ehd
+ }%
+ }{%
+ \ifcsnnullTF{#1@picheight}{%
+ \xwm@err{You have supplied picture width
+ but not height}\@ehd
+ }{%
+ \edef\pic@size{width=\cptmakecs{#1@picwidth},%
+ height=\cptmakecs{#1@picheight}}%
+ }%
+ }%
+}
+\robust@def*\xwm@picmark{%
+ \xwm@findpicfile\wmk@picfile\wmk@picfileext
+ \xwm@getgrafsize{wmk}%
+ \cptpassexpanded{%
+ \setbox\xwm@boxa=\hbox{%
+ \noexpand\includegraphics[\ifxwm@pdf viewport\else
+ bb\fi=\wmk@picbb,\pic@size,clip,\wmk@graphicsoptions,%
+ \xwm@gr@phicsoptions]{\xwm@filefound}%
+ }%
+ }%
+ \cptdimdef\widthofcurrpic{\wd\xwm@boxa}%
+ \cptdimdef\heightofcurrpic{\ht\xwm@boxa}%
+ \cptdimdef\depthofcurrpic{\dp\xwm@boxa}%
+ \xwm@makedraftbox
+ \xwm@put(\wmk@picxpos@a,\wmk@picypos@a){%
+ \rotatebox[origin=c]\wmk@picangle{%
+ \cptexpandsecond{\makebox(0,0)}{[\wmk@boxalign]{%
+ \ifdefboolTF{xwm@draft}{\xwm@draftbox{wmk}}{\copy\xwm@boxa}%
+ }%
+ }%
+ }}%
+}
+\robust@def*\xwm@makedraftbox{%
+ \fboxsep\p@\fboxrule.4\p@
+ \cptdimdef\xwm@tempa{(\ht\xwm@boxa+\dp\xwm@boxa
+ -2\fboxsep-2\fboxrule)/2}%
+ \cptdimdef\xwm@tempb{\wd\xwm@boxa-2\fboxsep-2\fboxrule}%
+ \setbox\@tempboxa\hbox{\color@begingroup
+ \ttfamily\color{red}\Large (draft mode)\color@endgroup}%
+ \setbox\xwm@boxb=\hb@xt@\xwm@tempb{%
+ \xwmstrut\xwm@tempa\z@pt
+ \hb@xt@\xwm@tempb{\hss\unhbox\@tempboxa\hss}%
+ \xwmstrut\z@pt\xwm@tempa
+ }%
+}
+\robust@def*\xwm@draftbox#1{%
+ \begingroup
+ \color{\usename{#1@draftboxcolor}}\fbox{\copy\xwm@boxb}%
+ \endgroup
+}
+\newcommand*\xwm@textpicmark@c{%
+ \xwm@getposition\wmk@textxpos\wmk@textypos\wmk@coordunit
+ \xwm@getposition\wmk@picxpos\wmk@picypos\wmk@coordunit
+ \ifdefboolTF{wmk@picontoptext}{%
+ \ifdefboolFT{wmk@tmark}{}{\xwm@textbox{wmk}}%
+ \ifdefboolFT{wmk@pmark}{}\xwm@picmark
+ }{%
+ \ifdefboolFT{wmk@pmark}{}\xwm@picmark
+ \ifdefboolFT{wmk@tmark}{}{\xwm@textbox{wmk}}%
+ }%
+ \ifdefboolFT{wmk@showpagecenter}{}\xwm@papercenter
+}
+\AtBeginDocument{%
+ \ifdefTF\Ginput@path{%
+ \xdef\xwm@inputpath{\Ginput@path\xwm@inputpath}%
+ \ifxTF\Ginput@path\input@path{}{%
+ \ifdefFT\input@path{}{%
+ \xdef\xwm@inputpath{\input@path\xwm@inputpath}%
+ }%
+ }%
+ }{%
+ \ifdefFT\input@path{}{%
+ \xdef\xwm@inputpath{\input@path\xwm@inputpath}%
+ }%
+ }%
+}
+\new@def*\xwm@inputpath{}
+\robust@def*\watermarkpaths{%
+ \cpt@testst{\cpt@testopt\xwm@w@termarkpaths{}}%
+}
+\robust@def*\xwm@w@termarkpaths[#1]{%
+ \cpt@testpnopt{\xwm@w@term@rkpaths#1}{}
+}
+\robust@def*\xwm@w@term@rkpaths#1(#2)#3{%
+ \cpt@useemptytrue
+ \def\xwm@tempa{#3}%
+ \ifdefboolTF{cpt@st}{%
+ \ifbracedTF{#3}{\xwm@stripallouterbraces{#3}\xwm@tempa}{}%
+ \def\csv@do##1{%
+ \ifbracedTF{##1}{%
+ \xwm@stripallouterbraces{##1}\xwm@tempa
+ }{%
+ \def\xwm@tempa{##1}%
+ }%
+ \cptexpandarg{\grightaddtocs\xwm@inputpath}{{#1\xwm@tempa#2}}%
+ }%
+ \csv@@parse*[,]\xwm@tempa
+ }{%
+ \xifinsetFT{,}{\cptoxdetok\xwm@tempa}{}{%
+ \xwm@err{Input path '#3' contains comma:
+ \MsgBrk Commas can appear only in the argument
+ \MsgBrk of star (*) variant of \string\watermarkpaths}\@ehd
+ }%
+ \def\tsv@do##1{%
+ \ifbracedTF{##1}{%
+ \cptexpandarg{\grightaddtocs\xwm@inputpath}{{#1\@iden##1#2}}%
+ }{%
+ \xwm@err{Input path '##1' needs outer braces}\@ehd
+ }%
+ }%
+ \tsv@@parse*\xwm@tempa
+ }%
+}
+\newletcs\watermarkpath=\watermarkpaths
+\new@def*\xwmifeofTF#1{\ifcondTF\ifeof#1\fi}
+\robust@def*\pdfiffileexistsTF#1{%
+ \ifcondFT\if\pdffilesize{#1}\relax\fi
+}
+\robust@def*\xwmiffileexistsTF#1{%
+ \openin\@inputcheck#1\@space
+ \xwmifeofTF\@inputcheck{%
+ \ifcsnullTF\xwm@inputpath{%
+ \@secondoftwo
+ }{%
+ \xwm@iffileonpath{#1}%
+ }%
+ }{%
+ \closein\@inputcheck
+ \edef\xwm@filefound{#1}%
+ \@firstoftwo
+ }%
+}
+\robust@def*\xwmiffileexistsFT#1{%
+ \xwmiffileexistsTF{#1}\@secondoftwo\@firstoftwo
+}
+\robust@def*\xwm@iffileonpath#1{%
+ \let\xwm@pathfound\@empty
+ \cpt@choicefdfalse
+ \def\tsv@do##1{%
+ \xwm@stripallouterbraces{##1}\xwm@tempa
+ \openin\@inputcheck\xwm@tempa#1\@space
+ \xwmifeofTF\@inputcheck{}{%
+ \let\xwm@pathfound\xwm@tempa
+ \edef\xwm@filefound{\xwm@tempa#1}%
+ \closein\@inputcheck
+ \cpt@choicefdtrue\loopbreak
+ }%
+ }%
+ \tsv@@loop*\xwm@inputpath
+ \ifdefboolTF{cpt@choicefd}%
+}
+\robust@def*\xwm@nofileerr#1#2{%
+ \message{%
+ ^^J! Package xwatermark Error: File '#1.#2' not found.
+ ^^J^^JType x to quit, or <RETURN> to proceed,
+ ^^Jor enter new name (default extension: #2):^^J
+ }%
+ \begingroup
+ \endlinechar-1\global\read-1 to\@gtempa
+ \endgroup
+ \ifcsnullTF\@gtempa{}{%
+ \oifstrcmpTF\@gtempa{x}{%
+ \stop
+ }{%
+ \oifstrcmpTF\@gtempa{X}{%
+ \stop
+ }{%
+ \filename@parse\@gtempa
+ \edef#1{\filename@area\filename@base}%
+ \edef#2{\ifxTF\filename@ext\relax{#2}{\filename@ext}}%
+ \xwm@findpicfile{#1}{#2}%
+ }%
+ }%
+ }%
+}
+\robust@def*\xwm@findpicfile#1#2{%
+ \let\xwm@filefound\@empty
+ \edef\xwm@filegiven{#1.#2}%
+ \ifdefboolTF{xwm@pdf}{%
+ \xwm@f@ndpicfile{#1}{#2}{pdf,png,jpeg,mps}%
+ }{%
+ \xwm@f@ndpicfile{#1}{#2}{eps,ps}%
+ }%
+ \ifcsnullFT\xwm@filefound{}{\xwm@nofileerr{#1}{#2}}%
+}
+\robust@def*\xwm@f@ndpicfile#1#2#3{%
+ \xwm@swafalse
+ \xwmiffileexistsTF{#1.#2}{%
+ \xwm@swbtrue
+ }{%
+ \xwm@swbfalse
+ \def\csv@do##1{%
+ \xwmiffileexistsFT{#1.##1}{}{%
+ \xwm@swatrue\loopbreak
+ }%
+ }%
+ \csv@@loop[,]{#3}%
+ }%
+ \ifdefboolTF{xwm@swb}{}{%
+ \ifdefboolTF{xwm@swa}{%
+ \xwm@warn{File '\xwm@filegiven' doesn't exist
+ \MsgBrk on given path(s) '\xwm@inputpath',
+ \MsgBrk but I have found \xwm@filefound'}%
+ }{%
+ \let\xwm@filefound\@empty
+ \let\xwm@pathfound\@empty
+ }%
+ }%
+}
+\robust@def*\xwm@wallpaper@c{%
+ \ifdefboolTF{wlp@picontoptext}{%
+ \xwm@textwallpaper
+ \xwm@picwallpaper
+ }{%
+ \xwm@picwallpaper
+ \xwm@textwallpaper
+ }%
+ \ifdefboolFT{wlp@showpagecenter}{}\xwm@papercenter
+}
+\robust@def*\xwm@textwallpaper{%
+ \ifdefboolFT{wlp@tmark}{}{%
+ \ifdefboolTF{wlp@squaretiles}\xwm@sqtexttiles\xwm@texttiles
+ }%
+}
+\robust@def*\xwm@picwallpaper{%
+ \ifdefboolFT{wlp@pmark}{}{%
+ \ifdefboolTF{wlp@squaretiles}\xwm@sqpictiles\xwm@pictiles
+ }%
+}
+\robust@def*\xwm@dotiling{\xwm@makedraftbox\xwm@dotiling@a}
+\robust@def*\xwm@dotiling@a{%
+ \let\tiley\wlp@wpyoffset
+ \cptwhiledim\tiley<\paperheight-\wlp@wpyoffset\do{%
+ \cptdimdef\xwm@tempa{-\paperheight+\tiley}%
+ \let\tilex\wlp@wpxoffset
+ \cptwhiledim\tilex<\paperwidth-\wlp@wpxoffset\do{%
+ \leavevmode\@killglue
+ \xwm@put(\tilex,\xwm@tempa){\rotatebox[origin=c]
+ \xwm@currangle{%
+ \cptexpandsecond{\makebox(0,0)}{[\wlp@boxalign]}{%
+ \ifdefboolTF{xwm@draft}{\xwm@draftbox{wlp}}{\copy\xwm@boxa}%
+ }%
+ }}%
+ \cptdimadd\tilex{\wlp@tilexsize+\wlp@tilexoffset}%
+ }%
+ \cptdimadd\tiley{\wlp@tileysize+\wlp@tileyoffset}%
+ }%
+}
+\robust@def*\xwm@toofewtiles#1{%
+ \ifnum\numexpr#1<4\relax
+ \xwm@err{Too few square wallpapers '#1';
+ \MsgBrk minimum expected: 4}\@ehd
+ \fi
+}
+\robust@def*\xwm@texttiles{%
+ \setbox\xwm@boxa=\hbox{%
+ \resizebox\wlp@tilexsize\wlp@tileysize
+ {\color{\wlp@textcolor}\wlp@textmark}%
+ }%
+ \let\xwm@currangle\wlp@textangle
+ \xwm@dotiling
+}
+\robust@def*\xwm@sqtexttiles{%
+ \xwm@toofewtiles\wlp@tileno
+ \cptdimdef\wlp@tilexsize{\paperwidth/\wlp@tileno}%
+ \let\wlp@tileysize\wlp@tilexsize
+ \setbox\xwm@boxa=\hbox{%
+ \resizebox\wlp@tilexsize\wlp@tileysize
+ {\color{\wlp@textcolor}\wlp@textmark}%
+ }%
+ \let\xwm@currangle\wlp@textangle
+ \xwm@dotiling
+}
+\robust@def*\xwm@tilepicbox{%
+ \xwm@findpicfile\wlp@picfile\wlp@picfileext
+ \setbox\xwm@boxa=\hbox{%
+ \cptexpandsecond\includegraphics{%
+ [\ifxwm@pdf viewport\else bb\fi=\wlp@picbb,
+ width=\the\dimexpr\wlp@tilexsize,height=
+ \the\dimexpr\wlp@tileysize,clip,
+ \wlp@graphicsoptions,\xwm@gr@phicsoptions]%
+ }{\xwm@filefound}%
+ }%
+}
+\robust@def*\xwm@pictiles{%
+ \xwm@tilepicbox
+ \let\xwm@currangle\wlp@picangle
+ \xwm@dotiling
+}
+\robust@def*\xwm@sqpictiles{%
+ \xwm@toofewtiles\wlp@tileno
+ \cptdimdef\wlp@tilexsize{\paperwidth/\wlp@tileno}%
+ \let\wlp@tileysize\wlp@tilexsize
+ \xwm@tilepicbox
+ \let\xwm@currangle\wlp@picangle
+ \xwm@dotiling
+}
+\robust@def*\xwmsetbox#1#2#3#4{%
+ \begingroup
+ \setbox1\hbox{\color@begingroup#4\color@endgroup}%
+ \setbox\@tempboxa\hbox to#1\textwidth{%
+ \setbox0\vtop{%
+ \ignorespaces#4\vskip\dimexpr#3\textheight/2\relax
+ }%
+ \cptdimdef\x{(#1\textwidth-\wd1)/2\relax}%
+ \hskip\x\box0\hskip-\x
+ }%
+ \ht\@tempboxa=\dimexpr#2\textheight/2\relax
+ \noindent\box\@tempboxa
+ \endgroup
+}
+\robust@def*\xwmstrut#1#2{%
+ \relax\unskip
+ \ifhmode\nobreak\fi
+ \begingroup
+ \setbox\@tempboxa=\hbox{\vrule\@height#1\@depth#2\@width\z@pt}%
+ \ifmmode\copy\@tempboxa\else\unhcopy\@tempboxa\fi
+ \endgroup
+}
+\robust@def*\xwmgetpicturesize{\cpt@testopt\xwm@getpicsize{}}
+\robust@def*\xwm@getpicsize[#1]#2{%
+ \begingroup
+ \edef\Ginput@path{%
+ \usecsifdef\Ginput@path\usecsifdef\xwm@inputpath
+ \usecsifdef\input@path
+ }%
+ \setbox\xwm@boxa=\hbox{\includegraphics[#1]{#2}}%
+ % See also \widthofcurrpic.
+ \cptdimdef\widthofpic{\wd\xwm@boxa}%
+ \cptdimdef\heightofpic{\ht\xwm@boxa}%
+ \cptdimdef\depthofpic{\dp\xwm@boxa}%
+ \cptdimdef\totalheightofpic{\ht\xwm@boxa+\dp\xwm@boxa}%
+ \let\\\cpt@csexit
+ \cptexpanded{\endgroup
+ \\\widthofpic\\\heightofpic\\\depthofpic\\\totalheightofpic
+ }%
+}
+% #1=optional text to be printed as watermark
+% #2=sundry fixed keys
+% #3=variable keys, separated by semicolon (set-1;...;set-n)
+% Each set-i has the syntax <key1=val1,...,keyn=valn>
+\robust@def*\repeatwatermarks{%
+ \cpt@teststpm{\cpt@testopt\xwm@repeatwatermarks{}}%
+}
+\robust@def\xwm@repeatwatermarks[#1]#2#3{%
+ \edef\cpt@tempa{\csv@@loop\ifcpt@st*\fi}%
+ \def\csv@do##1{%
+ \ifblankTF{##1}{}{\newwatermark[#2,##1]{#1}}%
+ }%
+ \ifdefboolTF{cpt@pm}{}{\cpt@tempa[;]{#3}}%
+}
+\ltxkeys@definekeys*[XWM]{boxedminipage}[xwmbmp@]{%
+ width=\textwidth;
+ textcolor=black;
+ framecolor=black;
+ framesep=3\p@;
+ framerule=0.4\p@;
+ height=\z@pt;
+ depth=\z@pt;
+ textalign=justified/\xwm@settextalign\xwmbmp@textalign;
+ innerpos=c;
+}
+\robust@def*\xwmboxedminipage{\cpt@testopt\xwm@boxedminipage{}}
+\begingroup
+\catcode`\|=\catcode`\%
+\robust@gdef*\xwm@boxedminipage[#1]{%
+ \ltxkeys@launchkeys[XWM]{boxedminipage}{#1}%
+ \xwm@stripallouterbracesincs\xwmbmp@width
+ \xwm@stripallouterbracesincs\xwmbmp@textcolor
+ \leavevmode\@pboxswfalse
+ \begingroup
+ \color{\xwmbmp@framecolor}%
+ \xifstrcmpTF\xwmbmp@innerpos{b}{%
+ \vbox
+ }{%
+ \xifstrcmpTF\xwmbmp@innerpos{t}{%
+ \vtop
+ }{%
+ \ifdefboolTF{mmode}{%
+ \vcenter
+ }{%
+ \@pboxswtrue $\vcenter |$
+ }%
+ }%
+ }%
+ {\ifnum`}=0\fi
+ \hsize\xwmbmp@width\relax
+ \hrule\@height\xwmbmp@framerule
+ \hbox{\ifnum`}=0\fi
+ \vrule\@width\xwmbmp@framerule
+ \kern\xwmbmp@framesep\relax
+ \vbox{\ifnum`}=0\fi
+ \vskip\xwmbmp@framesep\relax
+ \cptdimdef\reserved@a{\hsize-(\xwmbmp@framerule+\xwmbmp@framesep)*2}%
+ \hsize\reserved@a\relax
+ \textwidth\reserved@a\relax
+ \columnwidth\reserved@a\relax
+ \@parboxrestore
+ \c@mpfootnote\z@pt
+ \let\@footnotetext\@mpfootnotetext
+ \let\@listdepth\@mplistdepth\@mplistdepth\z@pt
+ \@minipagerestore\@minipagetrue
+ \everypar{\global\@minipagefalse\everypar{}}%
+ \leavevmode\@killglue
+ \xwmstrut\xwmbmp@height\z@pt
+ \noindent\color{\xwmbmp@textcolor}%
+ \begin\xwmbmp@textalign
+ \ignorespaces
+}
+\robust@gdef*\endxwmboxedminipage{%
+ \end\xwmbmp@textalign
+ \xwmstrut\z@pt\xwmbmp@depth
+ \ifvoid\@mpfootins\else
+ \vskip\skip\@mpfootins\footnoterule\unvbox\@mpfootins
+ \fi
+ \vskip\xwmbmp@framesep\relax
+ \ifnum`{=0\fi}%
+ \kern\xwmbmp@framesep\relax
+ \vrule\@width\xwmbmp@framerule
+ \ifnum`{=0\fi}%
+ \hrule\@height\xwmbmp@framerule
+ \ifnum`{=0\fi}%
+ \if@pboxsw\m@th$\fi |$
+ \leavevmode\@killglue
+ \endgroup
+ \@ignoretrue
+}
+\endgroup
+
+\ltxkeys@definekeys*[XWM]{minipage}[xwmmp@]{%
+ width=\paperwidth;
+ textcolor=black;
+ framecolor=black;
+ framesep=3\p@;
+ framerule=0.4\p@;
+ height=\z@pt;
+ depth=\z@pt;
+ textalign=center/\xwm@settextalign\xwmmp@textalign;
+ text-align=center/\setaliaskey{textalign};
+ framebox=true;
+ insertframe=true/\setaliaskey{framebox};
+ insert-frame=true/\setaliaskey{framebox};
+}
+\robust@def*\xwmminipage{\cpt@testopt\xwm@minipage{}}
+\robust@def\xwm@minipage[#1]#2{%
+ \ltxkeys@launchkeys[XWM]{minipage}{#1}%
+ \xwm@stripallouterbracesincs\xwmmp@width
+ \xwm@stripallouterbracesincs\xwmmp@textcolor
+ \xwm@pushboxframe
+ \fboxsep\xwmmp@framesep\fboxrule\xwmmp@framerule\relax
+ \cptdimdef\xwmmp@boxwidth{\xwmmp@width-2\fboxsep-2\fboxrule}%
+ \def\xwm@printbox{%
+ \color{\xwmmp@framecolor}%
+ \ifxwmmp@framebox\fbox{\fi
+ \usebox\xwm@boxa
+ \ifxwmmp@framebox}\fi
+ \xwm@popboxframe
+ }%
+ \@killglue\noindent
+ \begin{lrbox}\xwm@boxa
+ \@killglue\noindent
+ \begin{minipage}[c][\height][s]\xwmmp@boxwidth
+ \@killglue\noindent
+ \xwmstrut\xwmmp@height\z@pt
+ \begin\xwmmp@textalign
+ \textcolor{\xwmmp@textcolor}{#2}\relax
+ \end\xwmmp@textalign
+ \xwmstrut\z@pt\xwmmp@depth
+ \end{minipage}%
+ \@ignoretrue\@killglue
+ \end{lrbox}%
+ \@ignoretrue\@killglue\noindent
+ \xwm@printbox
+ \normalcolor
+ \@ignoretrue
+}
+\ltxkeys@definekeys*[XWM]{colorbox}[xwmcbx@]{%
+ width=\textwidth;
+ height=\z@pt;
+ depth=\z@pt;
+ framebox=true;
+ insertframe=true/\setaliaskey{framebox};
+ insert-frame=true/\setaliaskey{framebox};
+ textcolor=black;
+ fillcolor=white;
+ outerframecolor=black;
+ outer-frame-color=black/\setaliaskey{outerframecolor};
+ innerframecolor=black;
+ inner-frame-color=black/\setaliaskey{innerframecolor};
+ framesep=3\p@;
+ framerule=0.4\p@;
+ textalign=center/\xwm@settextalign\xwmcbx@textalign;
+ align=center/\setaliaskey{textalign};
+ text-align=center/\setaliaskey{textalign};
+}
+\robust@def*\xwmcolorbox{\cpt@testopt\xwm@colorbox{}}
+\robust@def\xwm@colorbox[#1]#2{%
+ \ltxkeys@launchkeys[XWM]{colorbox}{#1}%
+ \xwm@pushboxframe
+ \fboxsep\xwmcbx@framesep\fboxrule\xwmcbx@framerule\relax
+ \removelastskip\noindent
+ \fcolorbox{\xwmcbx@outerframecolor}{\xwmcbx@fillcolor}{%
+ \cptexpandsecond\xwmminipage{[textalign=\xwmcbx@textalign,
+ framesep=\xwmcbx@framesep,framerule=\xwmcbx@framerule,
+ framecolor=\xwmcbx@innerframecolor,width=\xwmcbx@width,
+ height=\xwmcbx@height,depth=\xwmcbx@depth,
+ textcolor=\xwmcbx@textcolor,framebox=true]}{#2}%
+ }%
+ \xwm@popboxframe
+ \removelastskip
+ \normalcolor
+}
+\ltxkeys@definekeys*[XWM]{makecolorbox}[xwmmbx@]{%
+ width=\textwidth;
+ height=\z@pt;
+ depth=\z@pt;
+ framebox=true;
+ textcolor=black;
+ fillcolor=white;
+ outerframecolor=black;
+ outer-frame-color=black/\setaliaskey{outerframecolor};
+ innerframecolor=black;
+ inner-frame-color=black/\setaliaskey{innerframecolor};
+ framesep=3\p@;
+ framerule=0.4\p@;
+ textalign=center/\xwm@settextalign\xwmmbx@textalign;
+ align=center/\setaliaskey{textalign};
+ text-align=center/\setaliaskey{textalign};
+ boxalign=center/\xwm@settextalign\xwmmbx@boxalign;
+}
+\robust@def*\makecolorbox{\cpt@testopt\xwm@makecolorbox{}}
+\robust@def*\xwm@makecolorbox[#1]#2{%
+ \ltxkeys@launchkeys[XWM]{makecolorbox}{#1}%
+ \begin{\xwmmbx@boxalign}%
+ \makebox[\z@pt][c]{%
+ \xwmstrut\xwmmbx@height\z@pt
+ \xwm@pushboxframe
+ \fboxsep\xwmmbx@framesep\fboxrule\xwmmbx@framerule\relax
+ \fcolorbox{\xwmmbx@outerframecolor}{\xwmmbx@fillcolor}{%
+ \cptexpandsecond\xwmminipage{[textalign=\xwmmbx@textalign,
+ framesep=\xwmmbx@framesep,framerule=\xwmmbx@framerule,
+ framecolor=\xwmmbx@innerframecolor,width=\xwmmbx@width,
+ height=\xwmmbx@height,depth=\xwmmbx@depth,
+ textcolor=\xwmmbx@textcolor,framebox=
+ \thebool@normal{xwmmbx@framebox}]}{#2}%
+ }%
+ \xwm@popboxframe
+ \xwmstrut\z@pt\xwmmbx@depth
+ }%
+ \end{\xwmmbx@boxalign}%
+ \removelastskip
+ \normalcolor
+}
+\ltxkeys@definekeys*[XWM]{shade}[xwmshd@]{%
+ width=\hsize;
+ leftadjust=\z@pt;
+ indent=\z@pt;
+ fillcolor=gray!75;
+ framecolor=black;
+ framesep=3\p@;
+ framerule=0.4\p@;
+ height=\z@pt;
+ depth=\z@pt;
+ textalign=justified/\xwm@settextalign\xwmshd@textalign;
+ textcolor=black
+}
+\robust@def*\xwm@frameshade{%
+ \def\FrameCommand{%
+ \clubpenalty\@m\widowpenalty\@m
+ \noindent\kern\xwmshd@leftadjust
+ \fboxrule\xwmshd@framerule\fboxsep\xwmshd@framesep\relax
+ \fcolorbox{\xwmshd@framecolor}{\xwmshd@fillcolor}%
+ }%
+ \parindent\z@pt\finalhyphendemerits\z@pt
+ \cptdimdef\xwm@tempa{\xwmshd@width-(\xwmshd@framesep
+ +\xwmshd@framerule+\xwmshd@indent)}%
+ \color{\xwmshd@textcolor}%
+ \MakeFramed{%
+ \hsize\xwm@tempa\FrameRestore\@setminipage
+ }%
+ \xwmstrut\xwmshd@height\z@pt
+ \begin\xwmshd@textalign
+}
+\robust@def*\xwmshade{\cpt@testopt\xwm@shade{}}
+\robust@def*\xwm@shade[#1]{%
+ \ltxkeys@launchkeys[XWM]{shade}{#1}%
+ \xwm@frameshade
+}
+\robust@def*\endxwmshade{%
+ \end\xwmshd@textalign
+ \xwmstrut\z@pt\xwmshd@depth
+ \par\unskip\endMakeFramed\@ignoretrue
+}
+\ltxkeys@definekeys*[XWM]{fadingtext}[fad@]{%
+ textcolor=white;
+ boxcolor=black;
+ scale=1;
+ letterwidth=5mm;
+ barcolor=yellow;
+ height=\z@pt;
+ depth=\z@pt
+}
+\newcommand*\xwmfadingtext[2][]{%
+ \ltxkeys@launchkeys[XWM]{fadingtext}{#1}%
+ \begingroup
+ \@tempcnta\z@pt
+ \def\siso@do##1{%
+ \advance\@tempcnta\@ne
+ \csn@xdef{fade@\romannumeral\@tempcnta}{\cpttrimspace{##1}}%
+ }%
+ \siso@@loop{#2}%
+ \def\colbox##1{%
+ \color{.!80}%
+ \colorbox{.}{{%
+ \color{\fad@textcolor!\the\numexpr100-\@tempcnta/\icol*10\relax}%
+ \ifnum\icol=\@ne
+ \kern\dimexpr\fad@letterwidth/50\relax
+ \fi
+ \makebox[\fad@letterwidth]{##1}%
+ \ifnum\icol<\@tempcnta
+ \scalebox\fad@scale{\textcolor{\fad@barcolor}{$|$}}%
+ \else
+ \scalebox\fad@scale{\phantom{$|$}}%
+ \kern\dimexpr-\fad@letterwidth/10\relax
+ \fi
+ }}%
+ }%
+ \color{\fad@boxcolor}%
+ \chardef\icol\z@pt
+ \cptdotimes\@tempcnta{%
+ \cptpushnumber\icol
+ \colbox{\scalebox\fad@scale
+ {\xwmstrut\fad@height\fad@depth
+ \usename{fade@\romannumeral\icol}}}%
+ }%
+ \endgroup
+}
+\cptonlypreamble{%
+ \dummypagenos,\fancypagenos,
+ \FancyPageNumbers,\NoFancyPageNumbers
+}
+\newcommand*\dummypagenos[1][]{}
+\newcommand*\fancypagenos[1][]{%
+ \ifblankTF{#1}{}{\AtBeginDocument{\xwm@fancypagenos{#1}}}%
+}
+\robust@def*\NoFancyPageNumbers{%
+ \AfterStartOfDocument{\global\pgn@showpagenosfalse}%
+}
+\robust@def*\FancyPageNumbers{%
+ \AfterStartOfDocument{\global\pgn@showpagenostrue}%
+}
+\robust@def*\xwm@fancypagenos#1{%
+ \ltxkeys@launchkeys[XWM]{fancypagenos}{#1}%
+ \xwm@getposition\pgn@textxpos\pgn@textypos\pgn@coordunit
+ \ifnumcmpFT\c@page=\@ne{}{%
+ \AfterStartOfDocument{\thispagestyle{\xwm@frontpagestyle}}%
+ }%
+ \pagestyle{fancyplain}%
+ \fancyhf{}%
+ \cfoot{\pgn@cfoot}\rfoot{\pgn@rfoot}%
+ \lfoot{\pgn@lfoot}\chead{\pgn@chead}%
+ \rhead{\pgn@rhead}\lhead{\pgn@lhead}%
+ \ifpgn@showheadrule
+ \def\headrule{{%
+ \color{\pgn@headrulecolor}%
+ \hrule\@height\pgn@headruleheight\@depth\pgn@headruledepth
+ \@width\headwidth\vspace{\pgn@headrulesep}%
+ \hrule\@height\pgn@headruleheight\@depth\pgn@headruledepth
+ \@width\headwidth\vspace{-\pgn@headrulesep}%
+ }}%
+ \else
+ \let\headrule\relax
+ \fi
+ \ifpgn@showfootrule
+ \def\footrule{{%
+ \color{\pgn@footrulecolor}%
+ \hrule\@height\pgn@footruleheight\@depth\pgn@footruledepth
+ \@width\headwidth\vspace{\pgn@footrulesep}%
+ \hrule\@height\pgn@footruleheight\@depth\pgn@footruledepth
+ \@width\headwidth\vspace{\pgn@footrulesep}%
+ }}%
+ \else
+ \let\footrule\relax
+ \fi
+ \xwm@gethfoffset\pgn@hfoffsetleft\pgn@hfoffsetright
+ \fancyhfoffset[R,L]\xwm@hfoffset
+ \AtBeginShipout{%
+ \ifdefboolTF{pgn@sendtoback}{%
+ \AtBeginShipoutUpperLeft{%
+ \xwm@f@ncyp@genos
+ }%
+ }{%
+ \AtBeginShipoutUpperLeftForeground{%
+ \xwm@f@ncyp@genos
+ }%
+ }%
+ }%
+}
+\cptnewswitch{xwm@fancy}
+\robust@def*\xwm@f@ncypagenos{%
+ \def\pgn@textmark{%
+ \begingroup
+ \fboxrule\pgn@framerule\fboxsep\pgn@framesep\relax
+ \pgn@format{\normalfont\pgn@style}%
+ \endgroup
+ }%
+ \cptswitchtrue{xwm@fancy}%
+ \xwm@textbox{pgn}%
+ \cptswitchfalse{xwm@fancy}%
+}
+\robust@def*\xwm@f@ncyp@genos{%
+ \ifboolFT{pgn@showpagenos}{}{%
+ \ifnumcmpTF\c@page=\@ne{%
+ \ifdefboolTF{pgn@showonpageone}\xwm@f@ncypagenos\relax
+ }{%
+ \xwm@f@ncypagenos
+ }%
+ }%
+}
+\robust@def*\xwm@gethfoffset#1#2{%
+ \begingroup
+ \def\temp@err{%
+ \xwm@err{Only digits (without units) are allowed\MsgBrk
+ in the values of 'hfoffsetleft' and 'hfoffsetright'}\@ehd
+ }%
+ \xifblankTF{#1}{}{%
+ \xxwmifitemsinTF\xwm@allowedcoordunits{#1}\temp@err{}%
+ }%
+ \xifblankTF{#2}{}{%
+ \xxwmifitemsinTF\xwm@allowedcoordunits{#2}\temp@err{}%
+ }%
+ \def\xwm@tempc##1##2{%
+ \xifblankTF{##1}{\def##2{1}}{\def##2{##1}}%
+ \ifdim##2\p@>\p@\def##2{1}\fi
+ }%
+ \xwm@tempc{#1}\xwm@tempa\xwm@tempc{#2}\xwm@tempb
+ \def\xwm@tempc##1{%
+ \xifinsetFT{.}{##1}{}{%
+ \def\xwm@tempd####1.####2\xwm@nil{\def##1{.####2}}%
+ \cptexpandsecond\xwm@tempd{##1}\xwm@nil
+ }%
+ }%
+ \xwm@tempc\xwm@tempa\xwm@tempc\xwm@tempb
+ \cptpassexpanded{%
+ \endgroup\def\noexpand\xwm@hfoffset{%
+ \the\dimexpr\xwm@tempa\marginparsep+%
+ \xwm@tempb\marginparwidth\relax
+ }%
+ }%
+}
+\robust@redef*\Gin@ii[#1]#2{%
+ \ifstrcmpTF{[}{#2}{%
+ \Gin@iii[#1][%
+ }{%
+ \begingroup
+ \@tempswafalse
+ \toks@{\Ginclude@graphics{#2}}%
+ \ltxkeys@setkeys{Gin}{#1}%
+ \Gin@esetsize
+ \the\toks@
+ \endgroup
+ }%
+}
+\robust@redef*\Grot@box@kv[#1]#2#3{%
+ \@begin@tempboxa\hbox{#3}%
+ \Grot@x\dimexpr\width/2\relax
+ \Grot@y\dimexpr(\height-\depth)/2\relax
+ \ltxkeys@setkeys{Grot}{#1}%
+ \setbox\z@pt\box\@tempboxa
+ \Grot@setangle{#2}%
+ \Grot@box
+ \@end@tempboxa
+}
+
+\endinput
+
+%%% End of file xwatermark.sty %%%