summaryrefslogtreecommitdiff
path: root/macros/latex/contrib/draftwatermark/draftwatermark.dtx
diff options
context:
space:
mode:
Diffstat (limited to 'macros/latex/contrib/draftwatermark/draftwatermark.dtx')
-rw-r--r--macros/latex/contrib/draftwatermark/draftwatermark.dtx105
1 files changed, 79 insertions, 26 deletions
diff --git a/macros/latex/contrib/draftwatermark/draftwatermark.dtx b/macros/latex/contrib/draftwatermark/draftwatermark.dtx
index 2cd35a1bbd..ab5cb3b948 100644
--- a/macros/latex/contrib/draftwatermark/draftwatermark.dtx
+++ b/macros/latex/contrib/draftwatermark/draftwatermark.dtx
@@ -9,10 +9,9 @@
% ---------------------------------------------
%
% It may be distributed and/or modified under the conditions of the
-% LaTeX Project Public License, either version 1.3 of this licence, or
-% any later version. The latest version of this license is at
-% http://www.latex-project.org/lppl.txt and version 1.3 is part
-% of all distributions of LaTeX version 2003/06/01 or later.
+% LaTeX Project Public License, version 1.3. This license is at
+% https://www.latex-project.org/lppl/ and is part
+% of all distributions of LaTeX version 2005/12/01 or later.
%
% This work has the LPPL maintenance status "author-maintained".
%
@@ -45,7 +44,7 @@
\DoNotIndex{\DeclareBoolOption, \DeclareComplementaryOption,
\DeclareStringOption, \def, \define@key, \dimexpr, \DisableKeyvalOption,
\do, \documentclass, \dp}
-\DoNotIndex{\expandafter}
+\DoNotIndex{\edef, \expandafter}
\DoNotIndex{\fbox, \fontsize}
\DoNotIndex{\hbox, \hspace, \hss, \ht}
\DoNotIndex{\let, \lipsum}
@@ -73,9 +72,9 @@
% \CheckSum{288}
%
% \def\filename{draftwatermark.dtx}
-% \def\fileversion{2.0}
-% \def\filedate{2020/03/14}
-% \def\docdate{2020/03/14}
+% \def\fileversion{2.1}
+% \def\filedate{2020/05/11}
+% \def\docdate{2020/05/11}
%
% \newcommand*{\Lpack}[1]{\textsf {#1}} ^^A typeset a package
% \newcommand*{\Lopt}[1]{\texttt {#1}} ^^A typeset an option
@@ -245,8 +244,8 @@
% 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!hanchor=t|m|b!\\
-% Default is |c|.\\
+% \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.
@@ -385,13 +384,22 @@
%
% As a final remark, observe that the specification of the positioning
% coordinates can be based on \LaTeX\ macros. For instance, one can set
-% the horizontal position at |0.5\paperwidth| (for centering) or at
+% 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.
-%
+% size is changed through the document. 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}
%
@@ -426,8 +434,7 @@
%
% \end{sloppy}
%
-% \section{Compatibility notes for version 2.0 of the package and later
-% versions}
+% \section{Compatibility notes for package version 2.0 and later}
%
% Version 2.0 of the package is an almost complete rewrite with respect to
% version 1.2. Specifically, all the configuration mechanism has been
@@ -477,6 +484,7 @@
% possible with the modern interface.
%
% \section{Examples}
+% \label{sec:examples}
%
% \subsection{Plain case, using the modern package interface}
%
@@ -590,13 +598,56 @@
% \fi
% \makeatletter \c@CodelineNo\z@ \makeatother
%
+% 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[named]{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
+% \makeatletter \c@CodelineNo\z@ \makeatother
+%
% \subsection{Maximum freedom with a custom watermarking command}
%
-% As a final example, see how maximum freedom can be obtained with a
-% custom watermarking command. The following document source lets one have
-% a watermark on the top right corner of odd pages and on the top left
-% corner of even pages.
-% \iffalse
+% 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}
@@ -659,6 +710,8 @@
% \item[1.2 - 2015/02/19] Add support for watermark position.
% \item[2.0 - 2020/03/08] Configuration management overhaul; introduction
% of a legacy interface for compatibility.
+% \item[2.1 - 2020/05/11] Allow anchor information to be re-evaluated on
+% every page
% \end{description}
%
% \StopEventually {}
@@ -673,7 +726,7 @@
% \begin{macrocode}
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{draftwatermark}%
- [2020/03/14 2.0 Put a gray textual watermark on document pages]
+ [2020/05/11 2.1 Put a gray textual watermark on document pages]
% \end{macrocode}
%
@@ -859,10 +912,10 @@
\sbox\@tempboxa{#1}%
\setlength{\@tempdima}{\draftwatermark@hpos}%
\setlength{\@tempdimb}{\draftwatermark@vpos}%
- \let \draftwatermark@tempa \draftwatermark@hanchor
+ \edef \draftwatermark@tempa{\draftwatermark@hanchor}%
\@onelevel@sanitize \draftwatermark@tempa
\expandafter\def\expandafter\draftwatermark@tempb
- \expandafter{\expandafter\@car \draftwatermark@tempa\@nil}
+ \expandafter{\expandafter\@car \draftwatermark@tempa\@nil}%
\if \draftwatermark@tempb r%
\addtolength\@tempdima{-\wd\@tempboxa}%
\else\if \draftwatermark@tempb c%
@@ -874,10 +927,10 @@
Illegal anchor directive `\draftwatermark@tempb'}%
{Anchoring to left side.}%
\fi\fi\fi
- \let \draftwatermark@tempa \draftwatermark@vanchor
+ \edef \draftwatermark@tempa{\draftwatermark@vanchor}%
\@onelevel@sanitize \draftwatermark@tempa
\expandafter\def\expandafter\draftwatermark@tempb
- \expandafter{\expandafter\@car \draftwatermark@tempa\@nil}
+ \expandafter{\expandafter\@car \draftwatermark@tempa\@nil}%
\if \draftwatermark@tempb b%
\addtolength\@tempdimb{-\ht\@tempboxa}%
\addtolength\@tempdimb{-\dp\@tempboxa}%
@@ -891,7 +944,7 @@
Illegal anchor directive `\draftwatermark@tempb'}%
{Anchoring to top side.}%
\fi\fi\fi
- \vbox to 0pt {
+ \vbox to 0pt {%
\vspace*{-1in}%
\vspace*{\@tempdimb}%
\hbox to 0pt {%