summaryrefslogtreecommitdiff
path: root/vu-cs-standard-thesis/Latex/StyleFiles/watermark.sty
blob: 497130798c813c0f279cd3361d3df23a81e41881 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{watermark}
         [2002/01/29 v1.00 Watermarks (NCC)]
%
% The package provides watermarks on output pages. A watermark is
% some text or picture printed at the background of paper. A watermark
% is prepared in picture box stored at the beginning of running head.
% So, the watermark material must be put on the page with LaTeX's \put and
% \multiput commands.
%
% \watermark{BODY}      sets a watermark to be printed on all pages
% \leftwatermark{BODY}  sets a watermark to be printed on every even page
%                       if twoside mode is turned on. Otherwise, this
%                       watermark is ignored. Odd-page watermark
%                       leaves unchanged.
% \rightwatermark{BODY} sets a watermark to be printed on every odd page
%                       if twoside mode is turned on. Otherwise, this
%                       watermark is printed on all pages. Even-page
%                       watermark leaves unchanged.
% \thiswatermark{BODY}  sets a watermark for the current page only.
%
% Additionally, the package provides the command \thispageheading{HEADING}
% which replaces a heading for the current page to specified heading.
% Watermarks are also printed when a heading is replaced.
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% We use the \@begindvi hook from the output routine.
% This hook works only once at the beginning of dvi, but some packages
% (e.g. hyperref) also use it for their own needs.
% So, we redefine it at the beginning of document in such a way to 
% accurately save its behaviour after the first call when it can be
% redefined by other packages.
%
\AtBeginDocument{
  \let\WMK@begindvi\@begindvi
  \def\@begindvi{\WMK@begindvi \WMK@insert
    \global\let\WMK@begindvi\@begindvi       % Save redefined behaviour and
    \gdef\@begindvi{\WMK@begindvi\WMK@insert}% redefine \@begindvi once more
  }%
}
%
% The \WMK@insert command redefines current header and inserts the
% \WMK@hook at the beginning of header. A box produced by this hook
% has zero natural sizes.
%
\def\WMK@insert{\let\WMK@head\@thehead \def\@thehead{\WMK@hook\WMK@head}}
\def\WMK@hook{%
  \begin{picture}(0,0)\relax
    \ifx\WMK@this\relax
      \if@twoside
        \ifodd\c@page\WMK@odd\else\WMK@even\fi
      \else
        \WMK@odd
      \fi
    \else
      \WMK@this \global\let\WMK@this\relax
    \fi
  \end{picture}%
}
%
% Define watermark producing commands
%
\newcommand{\watermark}[1]{\leftwatermark{#1}\rightwatermark{#1}}
\newcommand{\leftwatermark}[1]{\long\gdef\WMK@even{#1}}
\newcommand{\rightwatermark}[1]{\long\gdef\WMK@odd{#1}}
\newcommand{\thiswatermark}[1]{\long\gdef\WMK@this{#1}}
\watermark{}
\let\WMK@this\relax
%
% Now we define \thispageheading{heading} command.
% It replaces a heading on the current page to the
% specified one and prepares it in \parbox. Watermarks are leaved unchanged.
% The \ifWMK@savehead is needed to protect from multiple use of this command
% on the same page.
%
\newif\ifWMK@savehead \WMK@saveheadfalse
\newcommand{\thispageheading}[1]{%
  \ifWMK@savehead \else
    \global\WMK@saveheadtrue \global\let\WMK@savehook\WMK@hook
  \fi
  \long\gdef\WMK@hook{\WMK@savehook
    \parbox[t]\textwidth{#1}\let\WMK@head\@empty
    \global\WMK@saveheadfalse \global\let\WMK@hook\WMK@savehook
  }%
}
\endinput