| 1 |
% \iffalse |
| 2 |
%% |
| 3 |
%% File: watermark.dtx Copyright (C) 2002--2004 by Alexander I. Rozhenko |
| 4 |
%% |
| 5 |
%<package>\NeedsTeXFormat{LaTeX2e} |
| 6 |
%<package>\ProvidesPackage{watermark} |
| 7 |
%<package> [2004/12/09 v1.1 Watermarks (NCC)] |
| 8 |
% |
| 9 |
% \changes{v1.00}{2002/01/29}{This version is uploaded to CTAN} |
| 10 |
% \changes{v1.01}{2002/02/13}{Hbox underfull removed in empty |\thispageheading|} |
| 11 |
% \changes{v1.02}{2003/04/04}{Hbox underfull removed in plain and empty styles} |
| 12 |
% \changes{v1.1}{2004/12/09}{Simplify the implementation of |\thispageheading|} |
| 13 |
% \changes{v1.1}{2004/12/09}{Documentation was prepared} |
| 14 |
% |
| 15 |
%<*driver> |
| 16 |
\let\makeindex\relax |
| 17 |
\documentclass{ltxdoc} |
| 18 |
\usepackage{watermark,nccboxes} |
| 19 |
\GetFileInfo{watermark.sty} |
| 20 |
\begin{document} |
| 21 |
\title{The \textsf{watermark} package\thanks{This file |
| 22 |
has version number \fileversion, last |
| 23 |
revised \filedate.}} |
| 24 |
\author{Alexander I. Rozhenko\\[email protected]} |
| 25 |
\date{\filedate} |
| 26 |
\maketitle |
| 27 |
\DocInput{watermark.dtx} |
| 28 |
\end{document} |
| 29 |
%</driver> |
| 30 |
% \fi |
| 31 |
% |
| 32 |
% \thispageheading{This heading was prepared with the |
| 33 |
% {\tt\string\thispageheading} command.\\ |
| 34 |
% It allows long multi-line headings!} |
| 35 |
% |
| 36 |
% \section{User Interface} |
| 37 |
% |
| 38 |
% \DescribeMacro\watermark |
| 39 |
% \DescribeMacro\leftwatermark |
| 40 |
% \DescribeMacro\rightwatermark |
| 41 |
% \DescribeMacro\thiswatermark |
| 42 |
% The package provides watermarks on output pages. A watermark is |
| 43 |
% some text or picture printed at the background of paper. |
| 44 |
% A watermark is prepared in a picture box stored at the |
| 45 |
% beginning of header. So, you should place |
| 46 |
% the watermark material with LaTeX's |\put| and |\multiput| commands. |
| 47 |
% Allowed watermark commands are shown in the table: |
| 48 |
% \begin{center}\catcode`|=12 |
| 49 |
% \small |
| 50 |
% \renewcommand\cboxstyle{\footnotesize} |
| 51 |
% \begin{tabular}{|l|l|}\hline |
| 52 |
% \hfill\cbox{Command}\hfill\mbox{} & |
| 53 |
% \hfill\cbox{Meaning}\hfill\mbox{}\\\hline |
| 54 |
% \Strut/.8/ |
| 55 |
% \verb+\watermark+\marg{body} & |
| 56 |
% Set the same watermark for all pages\\ |
| 57 |
% \verb+\leftwatermark+\marg{body} & |
| 58 |
% Set the even-page watermark\\ |
| 59 |
% \verb+\rightwatermark+\marg{body} & |
| 60 |
% Set the odd-page watermark\\ |
| 61 |
% \verb+\thiswatermark+\marg{body} & |
| 62 |
% Set a watermark for the current page only \\ |
| 63 |
% \hline |
| 64 |
% \end{tabular} |
| 65 |
% \end{center} |
| 66 |
% In one-side mode, the |\leftwatermark| is ignored and the |
| 67 |
% |\rightwatermark| is applied to all pages. |
| 68 |
% |
| 69 |
% \DescribeMacro\thispageheading |
| 70 |
% The package also provides the command |
| 71 |
% |\thispageheading|\marg{heading} |
| 72 |
% which replaces a heading for the current page to the specified |
| 73 |
% multi-line heading. The heading is prepared in the parbox |
| 74 |
% of the |\textwidth| width aligned on the top line. This |
| 75 |
% command does not suppress watermarks. |
| 76 |
% |
| 77 |
% Examples of using watermarks are shown in the |ncccropmark| |
| 78 |
% package. |
| 79 |
% \StopEventually{} |
| 80 |
% |
| 81 |
% \section{The Implementation} |
| 82 |
% |
| 83 |
% \begin{macro}{\@begindvi} |
| 84 |
% To support watermarks, we use the |\@begindvi| hook from the output |
| 85 |
% routine. This hook works only once at the beginning of dvi, |
| 86 |
% but some packages (e.g. |hyperref|) also use it for their own needs. |
| 87 |
% So, we redefine it at the beginning of document in such a way to |
| 88 |
% accurately save its behaviour after the first call when it can be |
| 89 |
% redefined by other packages. All the we need from this hook~--- |
| 90 |
% to call the |\WMK@insert| command every time when the output |
| 91 |
% routine composes a new page. |
| 92 |
% \begin{macrocode} |
| 93 |
%<*package> |
| 94 |
\AtBeginDocument{ |
| 95 |
\let\WMK@begindvi\@begindvi |
| 96 |
\def\@begindvi{% |
| 97 |
% \end{macrocode} |
| 98 |
% Apply saved |\@begindvi| hook and then call the |
| 99 |
% |\WMK@insert| command: |
| 100 |
% \begin{macrocode} |
| 101 |
\WMK@begindvi |
| 102 |
\WMK@insert |
| 103 |
% \end{macrocode} |
| 104 |
% After that we must redefine the |\@begindvi| hook, |
| 105 |
% because it is already redefined here to the |\@empty| value |
| 106 |
% (or to something else if another package using this hook is loaded). |
| 107 |
% We save its new meaning in the |\WMK@begindvi| command |
| 108 |
% and redefine the |\@begindvi|: |
| 109 |
% \begin{macrocode} |
| 110 |
\global\let\WMK@begindvi\@begindvi |
| 111 |
\gdef\@begindvi{\WMK@begindvi\WMK@insert}% |
| 112 |
}% |
| 113 |
} |
| 114 |
% \end{macrocode} |
| 115 |
% \end{macro} |
| 116 |
% |
| 117 |
% \begin{macro}{\WMK@insert} |
| 118 |
% The command redefines the current header and inserts the |
| 119 |
% |\WMK@hook| at the beginning of header. |
| 120 |
% A box produced by this hook has zero natural sizes. |
| 121 |
% \begin{macrocode} |
| 122 |
\def\WMK@insert{% |
| 123 |
\let\WMK@head\@thehead |
| 124 |
\def\@thehead{\WMK@hook\WMK@head}% |
| 125 |
} |
| 126 |
% \end{macrocode} |
| 127 |
% \end{macro} |
| 128 |
% |
| 129 |
% \begin{macro}{\WMK@hook} |
| 130 |
% The command applies |
| 131 |
% this watermark (|\WMK@this|), odd watermark (|\WMK@odd|), |
| 132 |
% or even watermark (|\WMK@even|). The watermarks are prepared |
| 133 |
% within the picture environment: |
| 134 |
% \begin{macrocode} |
| 135 |
\def\WMK@hook{% |
| 136 |
\begin{picture}(0,0)\relax |
| 137 |
\ifx\WMK@this\relax |
| 138 |
\if@twoside |
| 139 |
\ifodd\c@page\WMK@odd\else\WMK@even\fi |
| 140 |
\else |
| 141 |
\WMK@odd |
| 142 |
\fi |
| 143 |
\else |
| 144 |
\WMK@this \global\let\WMK@this\relax |
| 145 |
\fi |
| 146 |
\end{picture}% |
| 147 |
% \end{macrocode} |
| 148 |
% After that we test the header. At the first, we test the |
| 149 |
% |\WMK@thishead| command. If it is specified, we let |
| 150 |
% |\WMK@head| to |\WMK@thishead|. |
| 151 |
% \begin{macrocode} |
| 152 |
\ifx\WMK@thishead\relax \else |
| 153 |
\let\WMK@head\WMK@thishead |
| 154 |
\global\let\WMK@thishead\relax |
| 155 |
\fi |
| 156 |
% \end{macrocode} |
| 157 |
% The original |\@thehead| command |
| 158 |
% saved in |\WMK@head| can be defined with |\@oddhead| content |
| 159 |
% or can be let to |\@oddhead| or |\@evenhead|. |
| 160 |
% We test all these cases to recognize when the head is really empty. |
| 161 |
% A head prepared with |\thispageheading| can be also empty. |
| 162 |
% If the empty case is recognized, we insert the |\hfil| command |
| 163 |
% to avoid underfull. |
| 164 |
% \begin{macrocode} |
| 165 |
\ifx\WMK@head\@empty \hfil |
| 166 |
\else |
| 167 |
\def\@tempa{\@oddhead}% |
| 168 |
\ifx\WMK@head\@tempa |
| 169 |
\ifx\@oddhead\@empty \hfil \fi |
| 170 |
\fi |
| 171 |
\fi |
| 172 |
} |
| 173 |
% \end{macrocode} |
| 174 |
% \end{macro} |
| 175 |
% |
| 176 |
% Set defaults for this heading and watermarks. |
| 177 |
% \begin{macrocode} |
| 178 |
\let\WMK@thishead\relax |
| 179 |
\let\WMK@this\relax |
| 180 |
\let\WMK@odd\@empty |
| 181 |
\let\WMK@even\@empty |
| 182 |
% \end{macrocode} |
| 183 |
% |
| 184 |
% \begin{macro}{\watermark} |
| 185 |
% \begin{macro}{\leftwatermark} |
| 186 |
% \begin{macro}{\rightwatermark} |
| 187 |
% \begin{macro}{\thiswatermark} |
| 188 |
% Define watermark producing commands: |
| 189 |
% \begin{macrocode} |
| 190 |
\newcommand{\watermark}[1]{\leftwatermark{#1}\rightwatermark{#1}} |
| 191 |
\newcommand{\leftwatermark}[1]{\gdef\WMK@even{#1}} |
| 192 |
\newcommand{\rightwatermark}[1]{\gdef\WMK@odd{#1}} |
| 193 |
\newcommand{\thiswatermark}[1]{\gdef\WMK@this{#1}} |
| 194 |
% \end{macrocode} |
| 195 |
% \end{macro} |
| 196 |
% \end{macro} |
| 197 |
% \end{macro} |
| 198 |
% \end{macro} |
| 199 |
% |
| 200 |
% \begin{macro}{\thispageheading} |
| 201 |
% Finally, define the |\thispageheading|\marg{heading} command. |
| 202 |
% We especially test the case of empty heading and |
| 203 |
% set |\WMK@thishead| to the |\@empty| value in this case. |
| 204 |
% This allows avoiding underfull in the |\WMK@hook|. |
| 205 |
% \begin{macrocode} |
| 206 |
\newcommand{\thispageheading}[1]{% |
| 207 |
\def\@tempa{#1}% |
| 208 |
\ifx\@tempa\@empty |
| 209 |
\global\let\WMK@thishead\@empty |
| 210 |
\else |
| 211 |
\gdef\WMK@thishead{\parbox[t]\textwidth{#1}}% |
| 212 |
\fi |
| 213 |
} |
| 214 |
%</package> |
| 215 |
% \end{macrocode} |
| 216 |
% \end{macro} |
| 217 |
\endinput |