% \iffalse meta-comment
%
% Copyright 2006-2020
% Sergio Callegari <sergio.callegari@gmail.com>
%
% ---------------------------------------------
% This file is part of the draftwatermark package,
% a contribution to the LaTeX2e system.
% ---------------------------------------------
%
% This work may be distributed and/or modified under the
% conditions of the LaTeX Project Public License, version 1.3c.
% This license is in
%   https://www.latex-project.org/lppl/lppl-1-3c/
% and is part of all distributions of LaTeX later than
% 2008-05-04.
%
% This work has the LPPL maintenance status "maintained".
%
% This program consists of the files listed in the README.md file
% included in the package.
%
%<*driver>
\documentclass[a4paper]{ltxdoc}
\usepackage{newtxtext}
\usepackage{hologo}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{textcomp}
\usepackage{url}
\EnableCrossrefs
\CodelineIndex
\RecordChanges
\CodelineIndex
%\RecordChanges
\begin{document}
  \DocInput{draftwatermark.dtx}
\end{document}
%</driver>
%
% \fi
%
% \CheckSum{577}
%
% \def\filename{draftwatermark.dtx}
% \def\fileversion{3.3}
% \def\filedate{2024/03/04}
% \def\docdate{2024/03/03}
%
% \DoNotIndex{\\}
% \DoNotIndex{\begin, \end, \begingroup, \endgroup}
% \DoNotIndex{\csname, \endcsname}
% \DoNotIndex{\if, \else, \fi}
% \DoNotIndex{\ifx, \fi}
% \DoNotIndex{\ifodd, \fi}
% \DoNotIndex{\@car, \@empty, \@ifnextchar, \@ifundefined, \@nil,
%   \@onelevel@sanitize, \@tempboxa, \@tempdima, \@tempdimb, \@tfor}
% \DoNotIndex{\AddEverypageHook, \AddThispageHook, \AddToHook, \AddToHookNext,
%   \addtolength, \author}
% \DoNotIndex{\bfseries, \box}
% \DoNotIndex{\color}
% \DoNotIndex{\DeclareBoolOption, \DeclareComplementaryOption,
%   \DeclareStringOption, \def, \define@key, \depth, \dimexpr,
%   \DisableKeyvalOption, \do, \documentclass, \dp}
% \DoNotIndex{\edef, \endinput, \expandafter}
% \DoNotIndex{\fbox, \fontsize}
% \DoNotIndex{\hbox, \hspace, \hss, \ht}
% \DoNotIndex{\let, \lipsum}
% \DoNotIndex{\maketitle, \MyWM, \MessageBreak}
% \DoNotIndex{\newcommand, \newsavebox, \NeedsTeXFormat}
% \DoNotIndex{\PackageError, \PackageWarningNoLine, \paperheight,
%   \paperwidth, \ProcessKeyvalOptions, \ProvidesPackage, \put}
% \DoNotIndex{\raisebox, \relax, \RequirePackage, \RequirePackageWithOptions,
%   \rotatebox}
% \DoNotIndex{\savebox, \sbox, \scalebox, \section, \selectfont, \setkeys,
%   \SetupKeyvalOptions, \setlength, \sffamily, \shortstack}
% \DoNotIndex{\thepage, \title}
% \DoNotIndex{\usebox, \usepackage}
% \DoNotIndex{\vbox, \vspace, \vss}
% \DoNotIndex{\wd, \wmbox}
%
% \setcounter{IndexColumns}{2}
% \setlength{\IndexMin}{3cm}
%
% \newcommand*{\Lpack}[1]{\textsf {#1}}           ^^A typeset a package
% \newcommand*{\Lopt}[1]{\texttt {#1}}            ^^A typeset an option
% \newcommand*{\file}[1]{\texttt {#1}}            ^^A typeset a file
% \newcommand*{\Lcount}[1]{\textsl {\small#1}}    ^^A typeset a counter
% \newcommand*{\pstyle}[1]{\textsl {#1}}          ^^A typeset a pagestyle
% \newcommand*{\Lenv}[1]{\texttt {#1}}            ^^A typeset an environment
%
% \title{The \Lpack{draftwatermark} package\thanks{This file
%     (\texttt{\filename}) has version number \fileversion, last
%     revised \filedate.}}
%
% \author{%
%   Sergio Callegari\thanks{Sergio Callegari can be reached at
%       \texttt{sergio.callegari at gmail dot com}}}
%
% \date{\docdate}
%
% \maketitle
%
% \begin{abstract}
%   The \Lpack{draftwatermark} package extends \hologo{LaTeX} providing a
%   means to add a watermark (typically textual and light gray, but
%   possibly more sophisticated) on the pages of a document (either on
%   every page, on the first page, or on selected pages). Typical usage
%   may consist in writing words such as ``DRAFT'' or ``CONFIDENTIAL''
%   across the pages. The package may remind in some sense
%   \Lpack{draftcopy} by Dr.~Juergen Vollmer, but its implementation is
%   lighter (as the reduced code footprint shows) and does not rely on
%   postscript specials, making the package fully compatible with
%   \hologo{pdfLaTeX}, \hologo{XeLaTeX} and \hologo{LuaLaTeX}. Its feature
%   set is somehow restricted because the emphasis is on the simplicity of
%   the interface. For complex layouts, consider \Lpack{scrlayer.sty} from
%   the \emph{KOMA script} bundle or directly using the new \hologo{LaTeX}
%   shipout hooks.
% \end{abstract}
%
% \section{Introduction}
%
% \changes{R1.0}{2006/06/30}{Initial release.}%
% \changes{R1.1}{2012/01/06}{Many small fixes in the documentation.}
% This package extends \hologo{LaTeX} providing a means to add a textual,
% usually light gray (but possibly colored) watermark on every page, the
% first page, or selected pages of a document. Typical usage may consist
% in writing words such as ``DRAFT'' or ``CONFIDENTIAL'' across document
% pages.
%
% The package may remind in some sense \Lpack{draftcopy} by Dr.~Juergen
% Vollmer, but its implementation differs in a few points:
% \begin{enumerate}
% \item Code footprint is smaller, although this does not mean much on
%   modern computers.
% \item There is no use of Postscript specials or other driver-dependent
%   tricks, so the package should be compatible with any output driver and
%   with \hologo{pdfLaTeX}, \hologo{XeLaTeX}, and \hologo{LuaLaTeX}\ in
%   particular. Recently, compatibility with PDF generating engines is
%   quite important and its lack in \Lpack{draftcopy} and was the first
%   motivation for writing \Lpack{draftwatermark}.
% \item Reduced code footprint comes at some price. Many features of
%   \Lpack{draftcopy} are not supported here, most notably
%   \Lpack{draftwatermark} has:
%   \begin{itemize}
%   \item No automatic selection of the watermark text to use, based on
%     the language, relying on pre-stored translations of the word
%     ``DRAFT''. This may be no big loss, since one is free to choose
%     whatever text he/she happens to prefer.
%   \item No automatic possibility to watermark only the first \emph{two}
%     pages of a document. However, it is possible to automatically
%     watermark only the first or to \emph{manually} stop the watermarking
%     after the second page.
%   \end{itemize}
%   Note that some features available as options in \Lpack{draftcopy}
%   (e.g., the possibility of time-stamping the watermark text) can be
%   obtained working on the watermark text itself.
% \end{enumerate}
%
% The emphasis of \Lpack{draftwatermark} is on the simplicity of its
% interface. In many cases the package will do the right thing by just
% loading it, without any further configuration. Such simplicity pairs
% with some limitations. As an example, \Lpack{draftwatermark} is capable
% of putting some text or an image on the background of the page, below
% the document text, but not of \emph{stamping}, that is putting it in the
% foreground, above the document text. Similarly, it is not well suited
% for complex watermark layouts. As a further note, there may be
% unexpected behaviors when \Lpack{draftwatermark} is used together with
% other packages affecting the page building, e.g., with respect to the
% stacking order of the objects on the page. For any complex layout, or
% when the Z-ordering is important, the recommendation is to look at the
% \Lpack{scrlayer} package in the \emph{KOMA script} bundle or to rely
% directly on the new shipout hook mechanism provided by \hologo{LaTeX}.
%
%
% \section{User interface}
% When loaded, \Lpack{draftwatermark} sets up a number of defaults
% (detailed later and modifiable by specific commands) and immediately
% becomes active.
%
% \subsection{Package options and configuration}
% If loaded as
% \begin{quote}
%   |\usepackage{draftwatermark}|
% \end{quote}
% the package sets up itself to put the a large, grayed background text
% saying ``DRAFT'' at the center every page.
%
% This behavior can be modified by passing options to the package as in
% \begin{quote}
%   |\usepackage[<options>]{draftwatermark}|
% \end{quote}
%
% \DescribeMacro{\DraftwatermarkOptions}
% \changes{R2.0}{2020/03/08}{Introduction of a keyval option mechanism.}
% The package behavior can also be dynamically changed \emph{after the
% package is loaded} by the command |\DraftwatermarkOptions{<options>}|
% that can be used anywhere in the document source. In either case,
% |<options>| is a comma separated list of options, each given as a
% |<key>| or as a |<key>=<value>| pair. Unless otherwise indicated, all
% options that can be used at the loading of the package can also be given
% via the |\DraftwatermarkOptions{<options>}| mechanism. In fact, the two
% things are almost equivalent, with some cautionary
% details. Specifically, the parsing of options by the |\usepackage|
% command is a bit quirky, hence when specifying options with the
% |<key>=<value>| syntax, some values that are accepted by
% |\DraftwatermarkOptions| may cause issues when specifying options with
% |\usepackage|.  \medskip
%
% The available options are:
% \begin{itemize}
%   \changes{R1.1}{2012/01/06}{Introduce the ``stamp'', ``nostamp'' and
%     ``final'' options to control whether the watermark should actually
%     be printed.}^^A
% \item \verb!firstpageonly=true|false!\\
%   If no value is provided, |true| is assumed. Default is |false|.\\
%   Instructs \Lpack{draftwatermark} to only apply the watermark on the
%   first page.\\
%   This option cannot be used with |\DraftwatermarkOptions{<options>}|.
% \item |firstpage| legacy alias of |firstpageonly|.
% \item \verb!stamp=true|false!\\
%   If no value is provided, |true| is assumed. Default is |true|.\\
%   Instructs \Lpack{draftwatermark} to print the watermark.
% \item |nostamp| legacy alias of |stamp=false|.
% \item |final| legacy alias of |stamp=false|.
% \item |angle=<real>|\\
%   Default is |45|.\\
%   Defines the angle, in degrees, at which the watermark text should be
%   printed.
% \item |scale=<real>|\\
%   Default is |1|.\\
%   Defines the scale at which the watermark text should be printed.
% \item |fontsize=<length>|\\
%   Default is |0.25\paperwidth|.\\
%   Defines the font size for the watermark text. See
%   Section~\ref{ssec:fontsize}.
% \item |text=<token list>|\\
%   Default is |DRAFT|.
%   Defines the watermark text. See notes in Section~\ref{ssec:text}.
% \item |hpos=<length>|\\
%   Default is |0.5\paperwidth|.\\
%   Defines the horizontal position of the watermark, based on its anchor
%   point. See also the |pos| option.
% \item |vpos=<length>|\\
%   Default is |0.5\paperheight|.\\
%   Defines the horizontal position of the watermark, based on its anchor
%   point. See also the |pos| option.
% \item |pos={<length>, <length>}|\\
%   Defines at once the horizontal (first length) and vertical (second
%   length) position of the watermark, based on its anchor point. See also
%   the options |hpos| and |vpos|.
% \item \verb!hanchor=l|c|r!\\
%   Default is |c|.\\
%   Defines the horizontal position of the watermark anchor
%   point. Specifically, |l| stands for \emph{left}, |c| for \emph{center}
%   and |r| for \emph{right}. See also the |anchor| option.
% \item \verb!vanchor=t|m|b!\\
%   Default is |m|.\\
%   Defines the vertical position of the watermark anchor
%   point. Specifically, |t| stands for \emph{top}, |m| for \emph{middle}
%   and |b| for \emph{bottom}. See also the |anchor| option.
% \item |anchor=<string>|\\
%   Defines the anchor point for the watermark. The anchor point is placed
%   at the page coordinates specified by the |hpos| and |vpos|
%   options. The string used for the specification is made of the |l|,
%   |c|, |r|, |t|, |m|, and |b| characters, whose meaning is as described
%   for the |hanchor| and |vanchor| options. For instance, if the anchor
%   specification is |lt|, then the top left corner of the watermark is
%   placed at the position specified by the |hpos| and |vpos| options.
% \item \verb!alignment=l|c|r!\\
%   Default is |c|.\\
%   Defines the alignment for the watermark text in case it contains line
%   breaks. Specifically, |l| aligns left, |c| aligns at the center and
%   |r| aligns right.
% \item |colormodel=<color model>|\\
%   Defaults to |gray|.\\
%   Defines the color model for the specification of the color of the
%   watermark text. Can be any color model supported by the \Lpack{color}
%   package. Leaving it empty allows named colors to be specified. See
%   also the |color| option.
% \item |colorspec=<color specification>|\\
%   Defaults to |0.8|.\\
%   Defines a color specification for the watermark text. The
%   specification is interpreted according to the color model. For
%   instance if the model is |rgb|, then the specification can be a color
%   triple. See also the |color| option.
% \item |color=<full color specification>|\\
%   Defines the color of the watermark text. The color specification may
%   include an optional color model and must include a color
%   specification, following the standard set by the \Lpack{color}
%   package. For instance, some examples of valid specifications are
%   |red|, or |{[rgb]{1, 0, 1}}|, or |{[gray]{0.5}}|.
% \item |markcmd=<macro>|\\
%   Default is |\DraftwatermarkStdMark|.\\
%   Defines the command used to draw the actual watermark. See also
%   Sect.~\ref{sec:markcmd}.
% \end{itemize}
%
% \section{Some notes on the configuration options}
%
% \subsection{The \Lopt{stamp} option and its companion configuration
% directives}
%
% The |stamp|, |nostamp| and |final| options let one control whether the
% watermark should actually be printed or not. They can be handy for
% quickly removing the ``draft'' status from a document, without having to
% alter the actual watermark setup. Option \Lopt{final} is a synonym for
% \Lopt{nostamp}. Note that \Lopt{final} is a commonly used global
% (class-level) option that can be simultaneously obeyed by multiple
% packages. The option \Lopt{stamp} can be used to override a global
% \Lopt{final} option and to recover the watermarking.
%
% Via the |\DraftwatermarkOptions| command, the |stamp| option can be
% given at arbitrary points in the document to suspend or resume
% watermarking. In this way one can \emph{manually} apply the watermark
% only on selected pages of a document.
%
% \subsection{The watermark text size}
% \label{ssec:fontsize}
%
% The package lets one control the watermark size in two different
% ways. One is by picking a font size via the |fontsize| option; the other
% one is by scaling the watermark with the |scale| option.
%
% In principle, using a large font to produce a large textual watermark is
% the preferred choice. In fact, a font with a large point size is not
% just a scaled up version of the same font with a small point
% size. Conversely, it is a font where all the traits are adjusted to
% actually look well at a large size. This is why \Lpack{draftwatermark}
% defaults to setting |scale=1| and to a large point size for the font (in
% fact, sufficiently large to get the word ``DRAFT'', rotated at
% 45\textdegree, take about half of the page width.
%
% Nonetheless asking for a large font may not work, if \hologo{LaTeX} has
% not been set up to use \emph{scalable} fonts. For this reason, the
% recommendation is to always use \Lpack{draftwatermark} on \hologo{LaTeX}
% or \hologo{pdfLaTeX} together with other packages that trigger the usage
% of fully scalable fonts (practical examples may be \Lpack{newtx} or
% \Lpack{mathptmx}, etc.). An even better alternative is to use modern
% \TeX\ engines, as in \hologo{XeLaTeX} or \hologo{LuaLaTeX} with
% \Lpack{fontspec}. In any case, recall that even with scalable fonts,
% \hologo{LaTeX} may be unable to deal with extremely large font sizes
% (e.g., $\gg 5\,\mathrm{cm}$). If really large letters are required for
% the watermark, a suitable combination of |fontsize| and |scale| may be
% needed.
%
% One can immediately realize when \hologo{LaTeX} is unable to deal with
% the package default or selected |fontsize| from two things: (i) a font
% warning from \LaTeX; and (ii) a tiny watermark text whose size seems not
% to react to the |fontsize| option. In this case, either switch to
% scalable fonts or select a small |fontsize| (e.g., |12pt|) together with
% a |scale| significantly larger than |1|.
%
% \subsection{The watermark text}
% \label{ssec:text}
%
% As previously noticed, the watermark text can be specified with the
% |text| option. The value passed to the |text| option does not need to be
% a plain string. Conversely, it may include formatting marks, such as
% line break commands (e.g., |\\|) or commands to select font variants
% (e.g., |\bfseries|). In fact, it is also possible to use a command to
% include an image as the text. In case line breaks are present, the text
% is left, right, center aligned according to the |alignment| option. A
% word of caution is necessary, though. To use \hologo{LaTeX} commands in
% the watermark text, please configure the latter via the
% |\DraftwatermarkOptions| command. Trying to do so by passing options to
% the \Lpack{draftwatermark} package via the |\usepackage| mechanism may
% fail due to how \hologo{LaTeX} parses option strings. Also note that the
% text may need to be surrounded by braces.
%
% If the watermark text includes line breaks, \Lpack{draftwatermark} will
% use a very thin interline space, according to the fact that the
% multi-line text is managed by surrounding the it with a \hologo{LaTeX}
% |shortstack| command.
%
% Also, note that the watermark typesetting happens inside a \TeX\ group,
% to make sure that any parameter setting you do in the |text| token list
% can stay local.
%
% As a further remark, observe that in order to only put a watermark on
% selected pages, an alternative to changing the |stamp| configuration
% option at arbitrary points in the document can be to use conditional
% expressions in the watermark text itself.
%
% \subsection{The watermark positioning}
%
% The watermark position is controlled via the |hpos| and |vpos|
% configuration options (or alternatively, by the |pos| configuration
% option). It is worth underlining that these configuration parameters
% require \emph{lengths} not plain numbers.
%
% The coordinates used by the positioning parameters are measured from the
% top left corner of the page. They work in conjunction with the anchoring
% parameters (|hanchor|, |vanchor| and |anchor|). Specifically, the anchor
% point of the watermark is placed at the specified position. The default
% is to center the watermark on the page, but it is possible to choose
% other positions by a smart choice of the positioning and anchoring
% parameters. For instance, one may want to put the watermark on the top
% right corner of each page, which can be easily done with an |rt|
% anchoring.
%
% As a final remark, observe that the specification of the positioning
% coordinates can be based on \hologo{LaTeX} macros. For instance, one can
% set the horizontal position |hpos| at |0.5\paperwidth| (for centering)
% or at |\dimexpr\paperwidth-5mm| (for placement at the right hand side of
% the page). Interestingly, \Lpack{draftwatermark} re-evaluates the
% positioning coordinates on every page. This means that positions based
% on |\paperwidth| or |\paperheight| should dynamically adjust if the page
% size is changed through the document.
% \changes{R2.1}{2020/05/11}{Let anchor directives be re-evaluated on
%   every page.}^^A
% To some extent, this is also true
% of the anchor options. For instance, one may set the horizontal anchor
% |hanchor| at |\ifodd\thepage r\else l\fi| causing the anchor point to
% alternate between |r| and |l| at every new page. In conjunction with a
% similarly conditional |hpos| setting, for instance
% |\ifodd\thepage \dimexpr\paperwidth-5mm \else 5mm\fi|, this enables
% interesting effects, like placing the watermark close to the right side
% of the page on odd pages and to the left side of the page on even
% pages. Obviously, this kind of setting is only applicable with the
% |hanchor| and |vanchor| options, and not with the |anchor| shorthand.
%
% \section{The standard watermark and ways of overriding it}
% \label{sec:markcmd}
%
% In order to simplify its usage as much as possible, the
% \Lpack{draftwatermark} package is designed under the assumption that,
% most of the time, the user will need just a \emph{textual} watermark and
% some basic way to tune its visual aspect, such as choosing the text
% font, font size, scale, rotation angle, etc.
%
% \DescribeMacro{\DraftwatermarkStdMark} To this aim, the macro
% |\DraftwatermarkStdMark| is provided to do the standard job of
% typesetting the watermark text according to the configuration-defined
% font, color, angle, and so on. Then the package arranges so that this
% macro is called whenever watermarking is needed.
%
% In case the facilities provided by |\DraftwatermarkStdMark| are
% insufficient, the package user can set up his/her own macro to do the
% watermark typesetting and instruct \Lpack{draftwatermark} to use it in
% place of |\DraftwatermarkStdMark|. This is done by using the
% configuration option |markcmd| that takes the new macro name as its
% parameter. The advice is to always write a new macro rather than
% redefining or patching |\DraftwatermarkStdMark|. Note that because
% |markcmd| can be reconfigured multiple times, one may actually define
% multiple macros to get different watermark layouts on different
% pages of the same document.
%
% \begin{sloppy} It is worth recalling that when |markcmd| is set to
%   something different from |\DraftwatermarkStdMark|, the angle, font,
%   scale, color parameters will be ignored. In this case, the package
%   user is on his/her own if he/she wants to parametrize the watermark
%   appearance.
%
% \end{sloppy}
%
% \section{Compatibility notes}
%
% \subsection{Compatibility notes for package version 3.0 and later}
%
% \changes{R3.0}{2020/12/08}{Remove dependency on package
% \Lpack{everypage}.}^^A
% Version 3.0 of the package takes advantage of the new functionalities
% introduced in \hologo{LaTeX} with the Fall 2020 release and gets rid of
% its dependency on \Lpack{everypage}. In principle, this could result in
% behavioral differences in corner cases.
%
% \changes{R3.0}{2020/12/08}{Automatically load legacy code for older
% \hologo{LaTeX} formats.}^^A
% For users of versions of \hologo{LaTeX} before Fall 2020,
% \Lpack{draftwatermarks} falls back to its own legacy code base, now
% packaged as \Lpack{draftwatermark-2x}.
%
% It is worth remarking that there is no advantage in trying to explicitly
% load \Lpack{draftwatermark-2x} on a modern \hologo{LaTeX} to try to get
% the past behavior. In fact, even if the old code base uses
% \Lpack{everypage}, on modern \hologo{LaTeX} formats, the latter tries
% itself to rely on the new \hologo{LaTeX} functionalities rather than its
% own legacy mechanisms.
%
% \subsection{Compatibility notes for package version 2.0 and later}
%
% \changes{R2.0}{2020/03/08}{Complete package overhaul.}
% Version 2.0 of the package is an almost complete rewrite with respect to
% version 1.2. Specifically, all the configuration mechanism has been
% overhauled, by moving to an interface based on configuration keys and
% associated values.
%
% In principle, compatibility to the 1.x series should be fully preserved
% by the provision of a \emph{legacy interface}. In case old documents are
% broken by the 2.x series, please report it as a bug.
%
% The advice is not to use the legacy interface in new documents, unless
% you know that they will need to be processed in environments lacking a
% recent \Lpack{draftwatermark}.
%
% \subsection{The legacy interface}
%
% The legacy interface is composed by the following commands:
% \begin{itemize}
% \item \DescribeMacro{\SetWatermarkAngle}^^A
%   Command |\SetWatermarkAngle{<real>}| is the same as\\
%   |\DraftwatermarkOptions{angle=<real>}|.
% \item \DescribeMacro{\SetWatermarkColor}^^A
%   \changes{R1.1}{2012/01/06}{Add support for specifying color
%     of textual watermark.}^^A
%   Command |\SetWatermarkColor[<model>]{<color spec>}| is the same as\\
%   |\DraftwatermarkOptions{color={[<model>]{<color spec>}}}|.
% \item \DescribeMacro{\SetWatermarkLightness}^^A
%   Command |\SetWatermarkLightness{<real>}| is the same as\\
%   |\DraftwatermarkOptions{color={[<gray>]{<real>}}}|. The real value
%   should be in between 0 (for black) and 1 (for white).
% \item \DescribeMacro{\SetWatermarkFontSize}^^A
%   Command |\SetWatermarkFontSize{<length>}| is the same as\\
%   |\DraftwatermarkOptions{fontsize=<length>}|.
% \item \DescribeMacro{\SetWatermarkScale}^^A
%   Command |\SetWatermarkScale{<real>}| is the same as\\
%   |\DraftwatermarkOptions{scale=<real>}|.
% \item \DescribeMacro{\SetWatermarkHorCenter}^^A
%   \changes{R1.2}{2015/02/19}{Add support for specifying the watermark
%     horizontal position.}^^A
%   Command |\SetWatermarkHorCenter{<length>}| is the same as\\
%   |\DraftwatermarkOptions{hpos=<length>, hanchor=c}|.
% \item \DescribeMacro{\SetWatermarkVerCenter}^^A
%   \changes{R1.2}{2015/02/19}{Add support for specifying the watermark
%     vertical position.}^^A
%   Command |\SetWatermarkVerCenter{<length>}| is the same as\\
%   |\DraftwatermarkOptions{vpos=<length>, vanchor=m}|.
% \item \DescribeMacro{\SetWatermarkText}^^A
%   Command |\SetWatermarkText{<text>}| is the same as\\
%   |\DraftwatermarkOptions{text={<text>}}|.
% \end{itemize}
%
% Note that the legacy interface supports only a subset of what is
% possible with the modern interface.
%
% \section{Examples}
% \label{sec:examples}
%
% \subsection{Plain case, using  the modern package interface}
%
% As an example, consider this first document source:
%
% \iffalse
%<*samplecode-modern>
% \fi
%    \begin{macrocode}
\documentclass{article}
\usepackage[svgnames]{xcolor}
\usepackage[T1]{fontenc}
\usepackage[firstpageonly, color={[gray]{0.5}},
  text=DRAFT\\COPY]{draftwatermark}
\usepackage{mathptmx}
\usepackage{lipsum}
\title{Sample document for the draftwatermark package}
\author{}

\begin{document}
\maketitle

\section{One}
\lipsum[1-3]

\section{Two}
\lipsum[4-6]

\end{document}
%    \end{macrocode}
% \iffalse
%</samplecode-modern>
% \fi
%
% This produces a two pages document with placeholder content, putting a
% page-centered watermark on the first page only. The watermark is made a
% slightly darker toneof gray than the default.
%
% \subsection{Plain case, using the legacy interface}
%
% Using the legacy interface, the source for the same sample document as
% above would look like:
% \iffalse
%<*samplecode-legacy>
% \fi
%    \begin{macrocode}
\documentclass{article}
\usepackage[svgnames]{xcolor}
\usepackage[T1]{fontenc}
\usepackage[firstpage]{draftwatermark}
\usepackage{mathptmx}
\usepackage{lipsum}

\SetWatermarkLightness{0.5}
\SetWatermarkText{DRAFT\\COPY}

\title{Sample document for the draftwatermark package}
\author{}

\begin{document}
\maketitle

\section{One}
\lipsum[1-3]

\section{Two}
\lipsum[4-6]

\end{document}
%    \end{macrocode}
% \iffalse
%</samplecode-legacy>
% \fi
%
% \subsection{Things that cannot be done with the legacy interface}
%
% A major limitation of the legacy interface that has been removed with
% the modern interface is the inability to control the watermark
% anchoring. For instance, one may want the watermark to appear in the
% right top angle of every page. With the modern interface, such a result
% can be easily obtained as in the following sample code:
% \iffalse
%<*samplecode-anchor>
% \fi
%    \begin{macrocode}
\documentclass{article}
\usepackage[svgnames]{xcolor}
\usepackage[T1]{fontenc}
\usepackage[firstpage, anchor=tr, color=red,
  pos={\dimexpr\paperwidth-5mm, 5mm},
  angle=-45, fontsize=32pt]{draftwatermark}
\usepackage{mathptmx}
\usepackage{lipsum}
\title{Sample document for the draftwatermark package}
\author{}

\DraftwatermarkOptions{text=\bfseries DRAFT}
\begin{document}
\maketitle

\section{One}
\lipsum[1-3]

\section{Two}
\lipsum[4-6]

\end{document}
%    \end{macrocode}
% \iffalse
%</samplecode-anchor>
% \fi
%
% Another interesting possibility of the modern interface derives from the
% fact that the positioning and anchoring options are re-evaluated for
% every page. This allows the positioning to dynamically change following
% other parameters (for instance the |\paperwidth|) or to take advantage
% of conditionals to achieve effects such as differentiating the watermark
% for odd and even pages, as shown in the following code:
% \iffalse
%<*samplecode-dynamic>
% \fi
%    \begin{macrocode}
\documentclass{article}
\usepackage[svgnames]{xcolor}
\usepackage[T1]{fontenc}
\usepackage[color=red, fontsize=32pt]{draftwatermark}
\usepackage{mathptmx}
\usepackage{lipsum}
\title{Sample document for the draftwatermark package}
\author{}

\DraftwatermarkOptions{%
  angle=0,
  text={\ifodd\thepage ODD\else EVEN\fi},
  hpos={\ifodd\thepage \dimexpr\paperwidth-5mm\else 5mm\fi},
  vpos=5mm,
  vanchor=t,
  hanchor={\ifodd\thepage r\else l\fi}
}

\begin{document}
\maketitle

\section{One}
\lipsum[1-3]

\section{Two}
\lipsum[4-6]

\end{document}
%    \end{macrocode}
% \iffalse
%</samplecode-dynamic>
% \fi
%
% \subsection{Maximum freedom with a custom watermarking command}
%
% Maximum freedom can be obtained with a custom watermarking command. The
% following example shows how it can be used, once again differentiating
% the watermark for odd and even pages.
%\iffalse
%<*samplecode-custom>
% \fi
%    \begin{macrocode}
\documentclass{article}
\usepackage[svgnames]{xcolor}
\usepackage[T1]{fontenc}
\usepackage{draftwatermark}
\usepackage{mathptmx}
\usepackage[scaled]{helvet}
\usepackage{lipsum}
\title{Sample document for the draftwatermark package}
\author{}

\newsavebox\wmbox
\savebox\wmbox{%
  {\color[rgb]{1,0.8,0.8}\sffamily \fbox{DRAFT}}}
\newcommand\MyWM{%
  \ifodd\thepage
    \hspace*{\dimexpr \paperwidth -\wd\wmbox-10mm}%
    \usebox{\wmbox}%
  \else
    \usebox{\wmbox}%
  \fi}

\DraftwatermarkOptions{anchor=lt, pos={5mm, 5mm}, markcmd=\MyWM}
\begin{document}
\maketitle

\section{One}
\lipsum[1-3]

\section{Two}
\lipsum[4-6]

\end{document}
%    \end{macrocode}
% \iffalse
%</samplecode-custom>
% \fi
%
%
% \section{Development and support}
%
% The package is developed on \emph{github}:
% \begin{quote}
%   \url{https://github.com/callegar/LaTeX-draftwatermark}
% \end{quote}
% Please, refer to that site for any bug report or development
% information.  Be so kind to refrain from opening bugs for enhancement
% requests that, from the present document, would evidently require moving
% against some fundamental design decisions.
%
% \StopEventually {}
%
% \section{Implementation}
% \subsection{Implementation of \Lpack{draftwatermark}}
%
% Announce the name and version of the package, which requires
% \LaTeXe.
% \changes{R3.2}{2024/03/03}{Fix version number of main package.}^^A
% \iffalse
%<*draftwatermark>
% \fi
%    \begin{macrocode}
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{draftwatermark}%
  [2024/03/04 3.3 Put a gray textual watermark on document pages]
%    \end{macrocode}
% \changes{R3.0}{2020/12/08}{Automatically load legacy code for older
% \hologo{LaTeX} formats.}^^A
% Depending on the actual functionalities provided by \hologo{LaTeX}
% consider loading \Lpack{draftwatermark-2x}. If so doing, warn about this,
% and hand over the operation to that package.
%    \begin{macrocode}
\@ifundefined{AddToHook}{%
  \PackageWarningNoLine{draftwatermark}{%
    You appear to be running a version of LaTeX\MessageBreak
    unsupported by current draftwatermark.\MessageBreak
    Forcing fallback to `draftwatermark-2x` that\MessageBreak
    uses an older code base}%
  \RequirePackageWithOptions{draftwatermark-2x}%
  \endinput}{}
%    \end{macrocode}
%
% Require the needed packages.
% \changes{R3.1}{2024/01/22}{Require `xcolor` instead of `color`.}%
%    \begin{macrocode}
\RequirePackage{kvoptions}
\RequirePackage{graphicx}
\RequirePackage{xcolor}
%    \end{macrocode}
%
% Define the configuration options and default values.
%    \begin{macrocode}
\DeclareBoolOption[false]{firstpageonly}
\define@key{draftwatermark}{firstpage}[true]{%
  \csname draftwatermark@firstpageonly#1\endcsname}
\DeclareBoolOption[true]{stamp}
\DeclareComplementaryOption{nostamp}{stamp}
\DeclareComplementaryOption{final}{stamp}
\DeclareStringOption[45]{angle}
\DeclareStringOption[1]{scale}
\DeclareStringOption[DRAFT]{text}
\DeclareStringOption[0.5\paperwidth]{hpos}
\DeclareStringOption[0.5\paperheight]{vpos}
\DeclareStringOption[0.25\paperwidth]{fontsize}
\DeclareStringOption[gray]{colormodel}
\DeclareStringOption[0.8]{colorspec}
\DeclareStringOption[c]{hanchor}
\DeclareStringOption[m]{vanchor}
\DeclareStringOption[c]{alignment}
\DeclareStringOption[\DraftwatermarkStdMark]{markcmd}
\define@key{draftwatermark}{pos}{%
  \draftwatermark@processpos #1\@nil}
\define@key{draftwatermark}{anchor}{%
  \draftwatermark@processanchor{#1}}
\define@key{draftwatermark}{color}{%
  \draftwatermark@processcolor #1\@nil}
%    \end{macrocode}
%
% Set up some helper marcros to process the options. These should be
% rather self-explanatory.
%    \begin{macrocode}
\def\draftwatermark@processpos#1,#2\@nil{%
  \def\draftwatermark@hpos{#1}%
  \def\draftwatermark@vpos{#2}}

\def\draftwatermark@processanchor#1{%
  \def\draftwatermark@tempa{#1}
  \@onelevel@sanitize \draftwatermark@tempa
  \expandafter \@tfor \expandafter \draftwatermark@tempb
    \expandafter :\expandafter =\draftwatermark@tempa
    \do
    {%
      \if \draftwatermark@tempb l%
        \def \draftwatermark@hanchor{l}%
      \else \if \draftwatermark@tempb c%
        \def \draftwatermark@hanchor{c}%
      \else \if \draftwatermark@tempb r%
        \def \draftwatermark@hanchor{r}%
      \else \if \draftwatermark@tempb t%
        \def \draftwatermark@vanchor{t}%
      \else \if \draftwatermark@tempb m%
        \def \draftwatermark@vanchor{m}%
      \else \if \draftwatermark@tempb b%
        \def \draftwatermark@vanchor{b}
      \else
        \PackageError{draftwatermark}{%
          Illegal anchor directive `\draftwatermark@tempb'}%
          {Directive has been ingnored.}%
      \fi\fi\fi\fi\fi\fi
    }}

\def\draftwatermark@processcolor{%
  \@ifnextchar[
    \draftwatermark@processcolor@ii\draftwatermark@processcolor@i}

\def\draftwatermark@processcolor@i#1\@nil{%
  \def\draftwatermark@colormodel{}%
  \def\draftwatermark@colorspec{#1}}

\def\draftwatermark@processcolor@ii[#1]#2\@nil{%
  \def\draftwatermark@colormodel{#1}%
  \def\draftwatermark@colorspec{#2}}

%    \end{macrocode}
%
% Process the package options\dots
%    \begin{macrocode}
\ProcessKeyvalOptions*
%    \end{macrocode}
%
% \dots\, and then disable the |firstpageonly| and |firstpage| options,
% that can only be used at the package loading time.
%    \begin{macrocode}
\DisableKeyvalOption{draftwatermark}{firstpageonly}
\DisableKeyvalOption{draftwatermark}{firstpage}

%    \end{macrocode}
%
% \begin{macro}{\DraftwatermarkOptions}
%   Set up a command to modify the configuration as needed.
%    \begin{macrocode}
\newcommand\DraftwatermarkOptions[1]{\setkeys{draftwatermark}{#1}}

%    \end{macrocode}
% \end{macro}
%
% Introduce the legacy interface.
% \begin{macro}{\SetWatermarkAngle}
%   Legacy command to set the rotation angle for the standard watermark
%    \begin{macrocode}
\newcommand\SetWatermarkAngle[1]{\DraftwatermarkOptions{angle=#1}}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\SetWatermarkFontSize}
%   Legacy command to set the font size for the standard watermark
%    \begin{macrocode}
\newcommand\SetWatermarkFontSize[1]{\DraftwatermarkOptions{fontsize=#1}}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\SetWatermarkScale}
%   Legacy command to set the scale for the standard watermark
%    \begin{macrocode}
\newcommand\SetWatermarkScale[1]{\DraftwatermarkOptions{scale=#1}}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\SetWatermarkHorCenter}
% \begin{macro}{\SetWatermarkVerCenter}
% Legacy commands to set the horizontal and vertical position for the
% standard watermark, also forcing it to be centered there.
%    \begin{macrocode}
\newcommand\SetWatermarkHorCenter[1]{%
  \DraftwatermarkOptions{hpos=#1, hanchor=c}}
\newcommand\SetWatermarkVerCenter[1]{%
  \DraftwatermarkOptions{vpos=#1, vanchor=m}}
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \begin{macro}{\SetWatermarkText}
%   \changes{R2.3}{2020/12/06}{Fix legacy interface to accept
%     text including commas.}^^A
%   Legacy command to set the text of the standard watermark
%    \begin{macrocode}
\newcommand\SetWatermarkText[1]{\DraftwatermarkOptions{text={#1}}}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\SetWatermarColor}
% \begin{macro}{\SetWatermarkLightness}
% Legacy commands to set the color for the
% standard watermark.
%    \begin{macrocode}
\newcommand\SetWatermarkColor[2][]{%
  \DraftwatermarkOptions{colormodel=#1, colorspec=#2}}
\newcommand\SetWatermarkLightness[1]{%
  \DraftwatermarkOptions{colormodel=gray, colorspec=#1}}

%    \end{macrocode}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\DraftwatermarkStdMark}
% The command to generate the standard watermark
% \changes{R2.2}{2020/06/29}{Wrap watermark text in a shortstack to make
%   line breaks possible.}
%    \begin{macrocode}
\newcommand\DraftwatermarkStdMark{%
  \rotatebox{\draftwatermark@angle}{%
    \scalebox{\draftwatermark@scale}{%
      \begingroup
      \ifx\draftwatermark@colormodel\@empty
        \color{\draftwatermark@colorspec}%
      \else
        \color[\draftwatermark@colormodel]{\draftwatermark@colorspec}%
      \fi
      \setlength{\@tempdima}{\draftwatermark@fontsize}%
      \fontsize{\@tempdima}{1.2\@tempdima}\selectfont
      \shortstack[\draftwatermark@alignment]{\draftwatermark@text}%
      \endgroup}}}

%    \end{macrocode}
% \end{macro}
%
% The code to actually print the watermark
%    \begin{macrocode}
\newcommand\draftwatermark@printwm[1]{%
  \sbox\@tempboxa{\raisebox{\depth}{#1}}%
  \setlength{\@tempdima}{\draftwatermark@hpos}%
  \setlength{\@tempdimb}{-\draftwatermark@vpos}%
  \edef \draftwatermark@tempa{\draftwatermark@hanchor}%
  \@onelevel@sanitize \draftwatermark@tempa
  \expandafter\def\expandafter\draftwatermark@tempb
    \expandafter{\expandafter\@car \draftwatermark@tempa\@nil}%
  \if \draftwatermark@tempb r%
    \addtolength\@tempdima{-\wd\@tempboxa}%
  \else\if \draftwatermark@tempb c%
    \addtolength\@tempdima{-0.5\wd\@tempboxa}%
  \else\if \draftwatermark@tempb l%
    \relax
  \else
    \PackageError{draftwatermark}{%
      Illegal anchor directive `\draftwatermark@tempb'}%
        {Anchoring to left side.}%
  \fi\fi\fi
  \edef \draftwatermark@tempa{\draftwatermark@vanchor}%
  \@onelevel@sanitize \draftwatermark@tempa
  \expandafter\def\expandafter\draftwatermark@tempb
    \expandafter{\expandafter\@car \draftwatermark@tempa\@nil}%
  \if \draftwatermark@tempb b%
    \relax
  \else\if \draftwatermark@tempb m%
    \addtolength\@tempdimb{-0.5\ht\@tempboxa}%
  \else\if \draftwatermark@tempb t%
    \addtolength\@tempdimb{-\ht\@tempboxa}%
  \else
    \PackageError{draftwatermark}{%
      Illegal anchor directive `\draftwatermark@tempb'}%
        {Anchoring to top side.}%
  \fi\fi\fi
  \put(\@tempdima,\@tempdimb){\usebox\@tempboxa}%
}

%    \end{macrocode}
%
% A wrapper to make the watermark printing conditional
%    \begin{macrocode}
\newcommand\draftwatermark@print[1]{%
  \ifdraftwatermark@stamp
    \draftwatermark@printwm{#1}%
  \fi}
%    \end{macrocode}
%
% \dots\, now, the code to set up the \Lpack{everypage} hooks to
% assure that the watermark printing commands are called when needed
%    \begin{macrocode}
\ifdraftwatermark@firstpageonly
  \AddToHookNext{shipout/background}{%
    \draftwatermark@print{\draftwatermark@markcmd}}%
\else
  \AddToHook{shipout/background}{%
    \draftwatermark@print{\draftwatermark@markcmd}}%
\fi
%    \end{macrocode}
% Finally, declare precedence rules with respect to shipout/background
% hooks that may be set up by other packages. These are important
% because they end up controlling the stacking of background
% artifacts. Specifically, the draft watermark should go below
% anything else. A notable package that must be considered is
% \Lpack{eso-pic}, particularly because it gets used by
% \Lpack{pdfpages}
% \changes{R3.3}{2024/03/04}{Declare precedence rules with respect to
%   other users of the shipout/background hook. This fixes the
%   background stacking order when using \Lpack{pdfpages}.}%
%    \begin{macrocode}
\DeclareHookRule{shipout/background}{draftwatermark}{<}{eso-pic}
%    \end{macrocode}
% \iffalse
%</draftwatermark>
% \fi
%
% \subsection{Implementation of \Lpack{draftwatermark-2x}}
%
% Announce the name and version of the package, which requires
% \LaTeXe.
% \changes{R3.2}{2024/03/03}{Fix name of legacy package.}
% \iffalse
%<*draftwatermark-2x>
% \fi
%    \begin{macrocode}
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{draftwatermark-2x}%
  [2020/12/06 2.3 Put a gray textual watermark on document pages]

%    \end{macrocode}
%
% Require the needed packages.
%    \begin{macrocode}
\RequirePackage{kvoptions}
\RequirePackage{everypage}[2007/06/20]
\RequirePackage{graphicx}
\RequirePackage{color}

%    \end{macrocode}
% Set up options and assumptions for the \Lpack{kvoptions} package
%    \begin{macrocode}
\SetupKeyvalOptions{family=draftwatermark, prefix=draftwatermark@}

%    \end{macrocode}
%
% Define the configuration options and default values.
%    \begin{macrocode}
\DeclareBoolOption[false]{firstpageonly}
\define@key{draftwatermark}{firstpage}[true]{%
  \csname draftwatermark@firstpageonly#1\endcsname}
\DeclareBoolOption[true]{stamp}
\DeclareComplementaryOption{nostamp}{stamp}
\DeclareComplementaryOption{final}{stamp}
\DeclareStringOption[45]{angle}
\DeclareStringOption[1]{scale}
\DeclareStringOption[DRAFT]{text}
\DeclareStringOption[0.5\paperwidth]{hpos}
\DeclareStringOption[0.5\paperheight]{vpos}
\DeclareStringOption[0.25\paperwidth]{fontsize}
\DeclareStringOption[gray]{colormodel}
\DeclareStringOption[0.8]{colorspec}
\DeclareStringOption[c]{hanchor}
\DeclareStringOption[m]{vanchor}
\DeclareStringOption[c]{alignment}
\DeclareStringOption[\DraftwatermarkStdMark]{markcmd}
\define@key{draftwatermark}{pos}{%
  \draftwatermark@processpos #1\@nil}
\define@key{draftwatermark}{anchor}{%
  \draftwatermark@processanchor{#1}}
\define@key{draftwatermark}{color}{%
  \draftwatermark@processcolor #1\@nil}

%    \end{macrocode}
%
% Set up some helper marcros to process the options. These should be
% rather self-explanatory.
%    \begin{macrocode}
\def\draftwatermark@processpos#1,#2\@nil{%
  \def\draftwatermark@hpos{#1}%
  \def\draftwatermark@vpos{#2}}

\def\draftwatermark@processanchor#1{%
  \def\draftwatermark@tempa{#1}
  \@onelevel@sanitize \draftwatermark@tempa
  \expandafter \@tfor \expandafter \draftwatermark@tempb
    \expandafter :\expandafter =\draftwatermark@tempa
    \do
    {%
      \if \draftwatermark@tempb l%
        \def \draftwatermark@hanchor{l}%
      \else \if \draftwatermark@tempb c%
        \def \draftwatermark@hanchor{c}%
      \else \if \draftwatermark@tempb r%
        \def \draftwatermark@hanchor{r}%
      \else \if \draftwatermark@tempb t%
        \def \draftwatermark@vanchor{t}%
      \else \if \draftwatermark@tempb m%
        \def \draftwatermark@vanchor{m}%
      \else \if \draftwatermark@tempb b%
        \def \draftwatermark@vanchor{b}
      \else
        \PackageError{draftwatermark}{%
          Illegal anchor directive `\draftwatermark@tempb'}%
          {Directive has been ingnored.}%
      \fi\fi\fi\fi\fi\fi
    }}

\def\draftwatermark@processcolor{%
  \@ifnextchar[
    \draftwatermark@processcolor@ii\draftwatermark@processcolor@i}

\def\draftwatermark@processcolor@i#1\@nil{%
  \def\draftwatermark@colormodel{}%
  \def\draftwatermark@colorspec{#1}}

\def\draftwatermark@processcolor@ii[#1]#2\@nil{%
  \def\draftwatermark@colormodel{#1}%
  \def\draftwatermark@colorspec{#2}}

%    \end{macrocode}
%
% Process the package options\dots
%    \begin{macrocode}
\ProcessKeyvalOptions*
%    \end{macrocode}
%
% \dots\, and then disable the |firstpageonly| and |firstpage| options,
% that can only be used at the package loading time.
%    \begin{macrocode}
\DisableKeyvalOption{draftwatermark}{firstpageonly}
\DisableKeyvalOption{draftwatermark}{firstpage}

%    \end{macrocode}
%
% \begin{macro}{\DraftwatermarkOptions}
%   Set up a command to modify the configuration as needed.
%    \begin{macrocode}
\newcommand\DraftwatermarkOptions[1]{\setkeys{draftwatermark}{#1}}

%    \end{macrocode}
% \end{macro}
%
% Introduce the legacy interface.
% \begin{macro}{\SetWatermarkAngle}
%   Legacy command to set the rotation angle for the standard watermark
%    \begin{macrocode}
\newcommand\SetWatermarkAngle[1]{\DraftwatermarkOptions{angle=#1}}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\SetWatermarkFontSize}
%   Legacy command to set the font size for the standard watermark
%    \begin{macrocode}
\newcommand\SetWatermarkFontSize[1]{\DraftwatermarkOptions{fontsize=#1}}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\SetWatermarkScale}
%   Legacy command to set the scale for the standard watermark
%    \begin{macrocode}
\newcommand\SetWatermarkScale[1]{\DraftwatermarkOptions{scale=#1}}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\SetWatermarkHorCenter}
% \begin{macro}{\SetWatermarkVerCenter}
% Legacy commands to set the horizontal and vertical position for the
% standard watermark, also forcing it to be centered there.
%    \begin{macrocode}
\newcommand\SetWatermarkHorCenter[1]{%
  \DraftwatermarkOptions{hpos=#1, hanchor=c}}
\newcommand\SetWatermarkVerCenter[1]{%
  \DraftwatermarkOptions{vpos=#1, vanchor=m}}
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \begin{macro}{\SetWatermarkText}
%   \changes{R2.3}{2020/12/06}{Fix legacy interface to accept
%     text including commas.}^^A
%   Legacy command to set the text of the standard watermark
%    \begin{macrocode}
\newcommand\SetWatermarkText[1]{\DraftwatermarkOptions{text={#1}}}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\SetWatermarColor}
% \begin{macro}{\SetWatermarkLightness}
% Legacy commands to set the color for the
% standard watermark.
%    \begin{macrocode}
\newcommand\SetWatermarkColor[2][]{%
  \DraftwatermarkOptions{colormodel=#1, colorspec=#2}}
\newcommand\SetWatermarkLightness[1]{%
  \DraftwatermarkOptions{colormodel=gray, colorspec=#1}}

%    \end{macrocode}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\DraftwatermarkStdMark}
% The command to generate the standard watermark
%    \begin{macrocode}
\newcommand\DraftwatermarkStdMark{%
  \rotatebox{\draftwatermark@angle}{%
    \scalebox{\draftwatermark@scale}{%
      \begingroup
      \ifx\draftwatermark@colormodel\@empty
        \color{\draftwatermark@colorspec}%
      \else
        \color[\draftwatermark@colormodel]{\draftwatermark@colorspec}%
      \fi
      \setlength{\@tempdima}{\draftwatermark@fontsize}%
      \fontsize{\@tempdima}{1.2\@tempdima}\selectfont
      \shortstack[\draftwatermark@alignment]{\draftwatermark@text}%
      \endgroup}}}

%    \end{macrocode}
% \end{macro}
%
% The code to actually print the watermark
%    \begin{macrocode}
\newcommand\draftwatermark@printwm[1]{%
  \sbox\@tempboxa{#1}%
  \setlength{\@tempdima}{\draftwatermark@hpos}%
  \setlength{\@tempdimb}{\draftwatermark@vpos}%
  \edef \draftwatermark@tempa{\draftwatermark@hanchor}%
  \@onelevel@sanitize \draftwatermark@tempa
  \expandafter\def\expandafter\draftwatermark@tempb
    \expandafter{\expandafter\@car \draftwatermark@tempa\@nil}%
  \if \draftwatermark@tempb r%
    \addtolength\@tempdima{-\wd\@tempboxa}%
  \else\if \draftwatermark@tempb c%
    \addtolength\@tempdima{-0.5\wd\@tempboxa}%
  \else\if \draftwatermark@tempb l%
    \relax
  \else
    \PackageError{draftwatermark}{%
      Illegal anchor directive `\draftwatermark@tempb'}%
        {Anchoring to left side.}%
  \fi\fi\fi
  \edef \draftwatermark@tempa{\draftwatermark@vanchor}%
  \@onelevel@sanitize \draftwatermark@tempa
  \expandafter\def\expandafter\draftwatermark@tempb
    \expandafter{\expandafter\@car \draftwatermark@tempa\@nil}%
  \if \draftwatermark@tempb b%
    \addtolength\@tempdimb{-\ht\@tempboxa}%
    \addtolength\@tempdimb{-\dp\@tempboxa}%
  \else\if \draftwatermark@tempb m%
    \addtolength\@tempdimb{-0.5\ht\@tempboxa}%
    \addtolength\@tempdimb{-0.5\dp\@tempboxa}%
  \else\if \draftwatermark@tempb t%
    \relax
  \else
    \PackageError{draftwatermark}{%
      Illegal anchor directive `\draftwatermark@tempb'}%
        {Anchoring to top side.}%
  \fi\fi\fi
  \vbox to 0pt {%
      \vspace*{-1in}%
      \vspace*{\@tempdimb}%
      \hbox to 0pt {%
        \hspace*{-1in}%
        \hspace*{\@tempdima}%
        \usebox\@tempboxa
        \hss}%
      \vss}}

%    \end{macrocode}
%
% A wrapper to make the watermark printing conditional
%    \begin{macrocode}
\newcommand\draftwatermark@print[1]{%
  \ifdraftwatermark@stamp
    \draftwatermark@printwm{#1}%
  \fi}
%    \end{macrocode}
%
% \dots\, and finally the code to set up the \Lpack{everypage} hooks to
% assure that the watermark printing commands are called when needed
%    \begin{macrocode}
\ifdraftwatermark@firstpageonly
  \AddThispageHook{\draftwatermark@print{\draftwatermark@markcmd}}
\else
  \AddEverypageHook{\draftwatermark@print{\draftwatermark@markcmd}}
\fi
%    \end{macrocode}
% \iffalse
%</draftwatermark-2x>
% \fi
%
%
% \Finale
% \PrintChanges
% \pagebreak[1]
% \PrintIndex
%
% \CharacterTable
%  {Upper-case    \A\B\C\D\E\F\G\H\I\J\K\L\M\N\O\P\Q\R\S\T\U\V\W\X\Y\Z
%   Lower-case    \a\b\c\d\e\f\g\h\i\j\k\l\m\n\o\p\q\r\s\t\u\v\w\x\y\z
%   Digits        \0\1\2\3\4\5\6\7\8\9
%   Exclamation   \!     Double quote  \"     Hash (number) \#
%   Dollar        \$     Percent       \%     Ampersand     \&
%   Acute accent  \'     Left paren    \(     Right paren   \)
%   Asterisk      \*     Plus          \+     Comma         \,
%   Minus         \-     Point         \.     Solidus       \/
%   Colon         \:     Semicolon     \;     Less than     \<
%   Equals        \=     Greater than  \>     Question mark \?
%   Commercial at \@     Left bracket  \[     Backslash     \\
%   Right bracket \]     Circumflex    \^     Underscore    \_
%   Grave accent  \`     Left brace    \{     Vertical bar  \|
%   Right brace   \}     Tilde         \~}
\endinput

%%% Local Variables:
%%% mode: doctex
%%% TeX-master: t
%%% End:
