Debian Codegraph @

texmf-dist/source/latex/background/background.dtx

raw
1 % \iffalse meta-comment
2 %
3 % Copyright (C) 2009, 2012, 2014 by Gonzalo Medina
4 %
5 % --------------------------------------------------------------------------
6 %
7 % This file may be distributed and/or modified under the
8 % conditions of the LaTeX Project Public License, either version 1.3
9 % of this license or (at your option) any later version.
10 % The latest version of this license is in:
11 %
12 % http://www.latex-project.org/lppl.txt
13 %
14 % and version 1.3 or later is part of all distributions of LaTeX
15 % version 2003/12/01 or later.
16 %
17 % This work has the LPPL maintenance status `maintained'.
18 %
19 % The Current Maintainer of this work is Gonzalo Medina.
20 %
21 % This work consists of the files background.dtx and background.ins,
22 % and the derived files background.sty and background.pdf.
23 %
24 % \fi
25 %
26 % \iffalse
27 %
28 %<*driver>
29 \documentclass{ltxdoc}
30 \usepackage{booktabs}
31 \usepackage[T1]{fontenc}
32 \usepackage[svgnames,x11names]{xcolor}
33 \usepackage{tikz}
34 \usepackage{ragged2e}
35 \usepackage{ntheorem}
36 \usepackage{framed}
37 \usepackage{fourier}
38 \usepackage{beramono}
39 \usepackage{ifpdf}
40 \ifpdf
41 \usepackage[placement=top]{background}
42 \SetBgContents{-\thepage-}
43 \SetBgAngle{0}
44 \SetBgColor{black!40}
45 \SetBgScale{4}
46 \SetBgHshift{60}
47 \SetBgVshift{-5}
48 \fi
49 \usepackage{hypdoc}
50 \ifpdf
51 \usepackage{hypdestopt}
52 \fi
53 \hypersetup{%
54 pdftitle={Background material},
55 pdfauthor={Gonzalo Medina},
56 pdfkeywords={LaTeX, package, background},%
57 pdfstartpage={1},%
58 pdfstartview={},%
59 breaklinks=true,%
60 linktocpage}
61
62 \makeatletter
63 \global\let\tikz@ensure@dollar@catcode=\relax
64 \makeatother
65
66
67 \newcommand\MarNote[1]{\marginpar{\RaggedLeft\textcolor{blue}{#1}}}
68 \newcommand*\package[1]{{\upshape\mdseries\sffamily #1}}
69
70 \makeatletter
71 \renewtheoremstyle{margin}%
72 {\item[\theorem@headerfont \llap{\fbox{\rule{0pt}{9pt}##1\ ##2}\quad }]}
73 {\item[\theorem@headerfont \llap{\fbox{\rule{0pt}{9pt}##1\ ##2}\quad }]}
74 \makeatother
75
76 \theoremstyle{margin}
77 \newtheorem{exam}{Example}
78
79 \setlength\parindent{0pt}
80
81 \pagestyle{empty}
82 \makeatletter
83 \let\ps@titlepage\ps@empty
84 \makeatother
85
86 \usepackage{titletoc}
87 \titlecontents*{section}[0pt]
88 {\itshape}{}{}
89 {, \thecontentspage}[\ --\ ][.]
90 \titlecontents*{subsection}[0pt]
91 {\upshape\small}{}{}
92 {, \thecontentspage}[ (][. ][)]
93 \setcounter{tocdepth}{2}
94
95 \newenvironment{mycode}
96 {\begin{shaded}\ttfamily}
97 {\end{shaded}}
98
99 \renewenvironment{shaded}{%
100 \def\FrameCommand{\FrameRestore\fboxsep=\FrameSep\colorbox{Honeydew2}}%
101 \MakeFramed {\FrameRestore}}%
102 {\endMakeFramed}
103
104 \newcommand\impo{%
105 \tikz{%
106 \node[draw=Maroon, very thick , fill=Honeydew2,%xshift=2cm,%
107 text width=0.8cm , text height=.8cm , text depth=0cm , text badly centered]
108 {\textcolor{Maroon}{\fontsize{30}{72}\selectfont\bfseries !}};
109 }
110 }
111
112 \newenvironment{Alerta}
113 {\par}%
114 {\marginpar{\hfill\impo}\par}
115
116 \newcommand\colorsample[1]{%
117 \raisebox{1.5pt}{\colorbox{#1}{\hphantom{e}\vphantom{e}}}%
118 }
119
120 \EnableCrossrefs
121 \CodelineIndex
122 \RecordChanges
123
124 \begin{document}
125 \DocInput{background.dtx}
126 \end{document}
127 %</driver>
128 % \fi
129 %
130 % \CharacterTable
131 % {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
132 % 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
133 % Digits \0\1\2\3\4\5\6\7\8\9
134 % Exclamation \! Double quote \" Hash (number) \#
135 % Dollar \$ Percent \% Ampersand \&
136 % Acute accent \' Left paren \( Right paren \)
137 % Asterisk \* Plus \+ Comma \,
138 % Minus \- Point \. Solidus \/
139 % Colon \: Semicolon \; Less than \<
140 % Equals \= Greater than \> Question mark \?
141 % Commercial at \@ Left bracket \[ Backslash \\
142 % Right bracket \] Circumflex \^ Underscore \_
143 % Grave accent \` Left brace \{ Vertical bar \|
144 % Right brace \} Tilde \~}
145 %
146 % \CheckSum{208}
147 %
148 % \changes{v 1.0}{2009/11/07}{First version}
149 % \changes{v 2.0}{2012/08/06}{Second version}
150 %
151 % \GetFileInfo{background.sty}
152 % \hfuzz=90pt
153 %
154 % \title{The \package{background} package\\
155 % {\footnotesize\fileversion , dated \filedate.}}
156 % \author{Gonzalo Medina\\%
157 % Universidad Nacional de Colombia -- Sede Manizales\\%
158 % Departamento de Matem\'aticas y Estad\'istica\\
159 % \texttt{[email protected]}}
160 %
161 % \maketitle
162 %
163 % \begin{abstract}
164 % \noindent This package allows the placement of quite arbitrary background material on the pages of a
165 % document. The user can control many aspects (i.e., contents, position, color, opacity) of the
166 % background material that will be displayed. The background material can be modified as many times as required and it can be displayed in all the pages or in some specifically chosen ones.
167 % \end{abstract}
168 % \tableofcontents
169 % \section{Introduction}
170 % The \package{background} package relies on the \package{TikZ} and \package{everypar}
171 % packages to provide a simple and flexible mechanism to include background material on all
172 % (or on some of) the pages of a \LaTeX2e document.
173 % \par\medskip
174 % The author will gladly receive suggestions, comments and bug reports.
175 %
176 % \section{User Interface}
177 %
178 % Loading this package (without any package options) in the preamble of a document in the
179 % standard way:
180 % \begin{mycode}
181 % |\usepackage{background}|
182 % \end{mycode}
183 % activates a set of predefined options that will typeset the word "Draft" across every page of
184 % your document (from the lower left corner to the upper right corner), using
185 % \textcolor{red!45}{this color} and a huge font size.
186 % \par\medskip
187 % Of course, the package can be loaded using some of the options described in the next section;
188 % for example:
189 % \begin{mycode}
190 % |\usepackage[pages=some,placement=bottom]{background}|
191 % \end{mycode}
192 % For a later change of options, this package provides the command
193 % \begin{mycode}
194 %|\backgroundsetup{|\meta{options}|}|
195 % \end{mycode}
196 % So, for example,
197 % \begin{mycode}
198 %|\usepackage[contents=Confidential,color=blue]{background}|
199 % \end{mycode}
200 % and
201 % \begin{mycode}
202 %|\usepackage{background}|\\
203 %|\backgroundsetup{contents=Confidential,color=blue}|
204 % \end{mycode}
205 % produce the same result. The advantage of |\backgroundsetup| is that it can be used not only in the preamble but on the body of the document, as many times as required.\medskip
206 % \begin{Alerta}
207 % The document needs to be processed twice to get the background material in the right position.
208 % \end{Alerta}
209 %
210 % \subsection{Options}
211 % The options described in this section can be used as package options or in the argument of the |\backgroundsetup| command. The table~\ref{tab:options} contains a summary of all the available options and their default values. Since the options used to modify attributes of the background material depend on the |\node| construct offered by the \package{TikZ} package, we strongly encourage the reading of Till Tantau's \href{http://mirror.ctan.org/graphics/pgf/base/doc/generic/pgf/pgfmanual.pdf}{\emph{PGF/TikZ package manual}}.
212
213 %\par\medskip
214 %\DescribeMacro{pages=}
215 % This option controls wether the background material should appear in all or in some of the pages of the document. The predefined values for this option are |all| (default) and |some|. Take into account that using the value |some| for this option will cause no background material to be displayed at all and the user will have to issue the command |\BgThispage| for each page in which he/she desires the background material to appear (see example \ref{exa:bgthispage}).
216 %\par\medskip
217 %\DescribeMacro{firstpage=}
218 % This boolean option allows the user to specify, setting the value |true|, that the background material must be displayed only in the first page of the document. The deafulat value is |false|.
219 % \par\medskip
220 %\DescribeMacro{placement=}
221 % This option allows the user to choose three predefined positions for the background material; the predefined values for this option are |center| (default), |top| and |bottom|. Using |center| will cause the background material to be displayed diagonally across the page, from the bottom left corner to the upper right corner of the page(s); the |top| value will cause the background material to be displayed horizontally at the top of the page(s), and the |bottom|value will cause the background material to be displayed horizontally at the top of the page(s).
222 %\par\medskip
223 %
224 %\DescribeMacro{contents=}
225 % This options allows the user to specify the material that will be used in the document. This material can be quite arbitrary: text of arbitrary length, images included via the standard |\includegraphics| command from the \package{graphicx} package, or graphics created with the \package{PGF/TikZ} package, for example.
226 % \par\medskip
227 % \begin{Alerta}
228 % If the material that will be used as background contains \LaTeX\ commands or if it is not plain text, then the |\backgroundsetup| command \emph{must} be used to declare the contents instead of using the key |contents| as one of the package options.
229 %\end{Alerta}
230 %\par\medskip
231 %\DescribeMacro{color=}
232 % This option allows the user to specify the color for the background material that will be used in the document. The whole range of colors provided by the \package{xcolor} package can be used.
233 %\par\medskip
234 %\DescribeMacro{angle=}
235 % This option allows the user to specify the angle for the background material that will be used in the document. Angles are measred counterclockwise; any value between -360 and 360 can be used.
236 %\par\medskip
237
238
239 %\DescribeMacro{opacity=}
240 % This option allows the user to change the transparency level for the background material. Any number between 0 (full transparency) and 1 (no transparency at all) can be used as a valid value for this option.
241 %\par\medskip
242
243 %\DescribeMacro{scale=}
244 % This option allows the user to change the scaling factor that will be applied to the background material. Any (sensible) positive value can be used.
245 % \par\medskip
246
247 %\DescribeMacro{position=}
248 % This option allows the user to define the position of the background material. Any valid position accepted by the at syntax for nodes placement can be used (see the TikZ manual). When using coordinates, do \emph{not} enclose them inside parentheses. Some examples of valid positions are
249 % \begin{mycode}
250 %|position={0,0}|\\
251 %|position=current page.north|\\
252 %|position={5cm,7cm}|
253 % \end{mycode}
254
255 %\DescribeMacro{nodeanchor=}
256 %This option allows the user to set the anchor for the node containing the background material. Typical values for this key are:
257 % \begin{mycode}
258 %|nodeanchor=south east|\\
259 %|nodeanchor=north|
260 % \end{mycode}
261 % \par\medskip
262
263 %\DescribeMacro{anchor=}
264 %This option allows the user to set the simplified anchor for the node containing the background material. Typical values for this key are:
265 % \begin{mycode}
266 %|anchor=left|\\
267 %|anchor={below=30pt}|
268 % \end{mycode}
269 % \par\medskip
270
271 %
272 %\DescribeMacro{hshift=}
273 %\DescribeMacro{vshift=}
274 % These two options control the horizontal and vertical shifting, respectively, of the node position.
275 % \begin{table}[!ht]
276 % \centering
277 % \caption{Available options.}
278 % \renewcommand\arraystretch{1.3}
279 % \makebox[\textwidth]{
280 % \begin{tabular}{rll}\toprule
281 % Key & Possible Values & Default\\\midrule
282 % |pages| & |<all|$\mid$|some>| & |all| \\
283 % |firstpage| & |<true|$\mid$|false>| & |false| \\
284 % |placement| & |<center|$\mid$|top|$\mid$|bottom>| & |center| \\
285 % |contents| & Text, images, etc. & |Draft|\\
286 % |color| & Any valid color & |red!45|\ \ \colorsample{red!45}\\
287 % |angle| & Any value between -360 and 360 & |60|, for |center| \\
288 % & & |0|, for |top| and |bottom|\\
289 % |opacity| & Any value between 0 and 1 & |0.5| \\
290 % |scale| & Any positive value & |15| for |center| \\
291 % & & |8| for |top| and |bottom| \\
292 % |position| & Any value for node placement & |current page.center| for |center| \\
293 % & & |current page.north| for |top| \\
294 % & & |current page.south| for |bottom| \\
295 % |anchor| & Any simplified value for node anchor & |empty| for |center| \\
296 % & & |below| for |top| \\
297 % & & |above| for |bottom| \\
298 % |nodeanchor| & Any value for node anchor & |center| \\
299 % |hshift| & Any length. & 0pt \\
300 % |vshift| & Any length. & 0pt \\
301 % \\\bottomrule
302 % \end{tabular}
303 % }
304 % \label{tab:options}
305 % \end{table}
306 %
307 % \subsection{User Commands}
308 % The following two commands are designed to give the user control on whether the background material should or should not appear on specific pages of the document.
309 % \par\medskip
310 % \DescribeMacro{\BgThispage}
311 % This command permits to select particular pages in which the background material will
312 % be displayed (see example \ref{exa:bgthispage}).
313 % \par\medskip
314 %
315 % \DescribeMacro{\NoBgThispage}
316 % This command will prevent the background material to be displayed in the page where it
317 % was issued.
318 % \par\medskip
319 % \begin{Alerta}
320 % Do not use this command in two column documents since its implementation depends on the \package{afterpage} package, and this package doesn't cooperate with two-column mode (see example~\ref{exa:nobgthispage}) .
321 % \end{Alerta}
322
323 %
324
325 % \section{Examples}
326 % In the following examples, the \package{lipsum} package was used only to automatically
327 % generate text.
328 % \begin{exam}
329 % This example shows how to display the background material only on the first two pages of
330 % the document:
331 % \end{exam}
332 % \begin{mycode}
333 % |\documentclass{article}|\\
334 % |\usepackage{background}|\\
335 % |\usepackage{lipsum}|\\
336 %
337 % |\begin{document}|\\
338 % |\lipsum[1-10]|\\
339 % |\newpage\backgroundsetup{contents={}}|\\
340 % |\lipsum[1-30]|\\
341 % |\end{document}|
342 % \end{mycode}
343 %
344 % \begin{exam}
345 % This example imitates the page numbering format used in this document:
346 % \end{exam}
347 % \begin{mycode}
348 % |\documentclass{article}|\\
349 % |\usepackage[|\\
350 % | placement=top,|\\
351 % | angle=0, |\\
352 % | color=black!40, |\\
353 % | scale=4, |\\
354 % | hshift=60, |\\
355 % | vshift=-5 |\\
356 % | ]{background}| \\
357 % |\backgroundsetup{contents={-\thepage-}}|\\
358 % |\usepackage{lipsum}|\\
359 %
360 % |\pagestyle{empty}|\\
361 %
362 % |\begin{document}|\\
363 % |\lipsum[1-30]|\\
364 % |\end{document}|
365 % \end{mycode}
366 %
367 % \begin{exam}\label{exa:bgthispage}
368 % This example illustrates how to use of the {\normalfont |\BgThispage|} command to add background material on selected pages and how to use {\normalfont |\backgroundsetup|}.
369 % \end{exam}
370 % \begin{mycode}
371 % |\documentclass{article}|\\
372 % |\usepackage[pages=some,placement=top]{background}|\\
373 % |\usepackage{lipsum}|\\
374 %
375 % |\begin{document}|\\
376 % |\lipsum[1-5]|\\
377 % |\newpage|\\
378 % |\backgroundsetup{contents=A,color=yellow}|\\
379 % |\BgThispage|\\
380 % |\lipsum[1-5]|\\
381 % |\newpage|\\
382 % |\backgroundsetup{contents=B,color=blue}|\\
383 % |\BgThispage|\\
384 % |\lipsum[1-5]|\\
385 % |\end{document}|
386 % \end{mycode}
387 %
388 % \begin{exam}
389 % This example shows how to proceed in order to obtain different background material for the
390 % odd and even pages of a document.
391 % \end{exam}
392 % \begin{mycode}
393 % |\documentclass{article}|\\
394 % |\usepackage[ |\\
395 % | contents={}, |\\
396 % | opacity=1, |\\
397 % | scale=1.5, |\\
398 % | color=blue!90 |\\
399 % | ]{background} |\\
400 % |\usepackage{lipsum}|\\
401 % |\usepackage{ifthen}|\\
402 %
403 % |\AddEverypageHook{%|\\
404 % | \ifthenelse{\isodd{\value{page}}}%|\\
405 % | {\backgroundsetup{ |\\
406 % | angle=90, |\\
407 % | position={0,-0.65\textheight}, |\\
408 % | contents={The background package} |\\
409 % | }% |\\
410 % | }% |\\
411 % | {\backgroundsetup{|\\
412 % | angle=270,|\\
413 % | position={0.9\textwidth,-.7\textheight},%|\\
414 % | contents={Version 2.1}|\\
415 % | }% |\\
416 % | }% |\\
417 % | \BgMaterial}|\\
418 %
419 % |\begin{document}|\\
420 % |\lipsum[1-30]|\\
421 % |\end{document}|
422 % \end{mycode}
423 %
424 % \begin{exam}\label{exa:nobgthispage}
425 % This example
426 % illustrates the use of the {\normalfont |\NoBgThispage|} command, to
427 % suppress the background material on selected pages (page 2, in this case).
428 % Adding the {\normalfont |twocolumn|} class option will produce compilation errors
429 % \end{exam}
430 % \begin{mycode}
431 % |\documentclass{article}|\\
432 % |\usepackage{background}|\\
433 % |\usepackage{lipsum}|\\
434 %
435 % |\begin{document}|\\
436 % |\lipsum[1-5]|\\
437 % |\newpage\NoBgThispage|\\
438 % |\lipsum[1-5]|\\
439 % |\newpage|\\
440 % |\lipsum[1-20]|\\
441 % |\end{document}|
442 % \end{mycode}
443 %
444 %\section{Compatibility with version 1.0}
445 % \par\medskip
446 % The macros used in version 1.0 to control the attributes of the background material are still available for backwards compatibility. However, users of version 2.0 are encouraged to use the newly implemented |key=value| mechanism instead. The old macros are listed below:
447 %
448 % \begin{mycode}
449 % |\SetBgContents| \\
450 % |\SetBgColor|\\
451 % |\SetBgAngle|\\
452 % |\SetBgOpacity|\\
453 % |\SetBgScale|\\
454 % |\SetBgPosition|\\
455 % |\SetBgAnchor|\\
456 % |\SetBgHshift|\\
457 % |\SetBgVshift|\\
458 % \end{mycode}
459 %
460 % \begin{Alerta}
461 % In version 1.0 there were five package options: |all|, |some|, |center|, |top|, and |bottom|; these options are still available, but the user is encouraged to use the |pages| and |placement| keys; so, for example,
462 % \end{Alerta}
463 % \begin{mycode}
464 % |\usepackage[some,top]{background}|
465 % \end{mycode}
466 % from version 1.0, could be replaced, from version 2.0 on, with
467 % \begin{mycode}
468 % |\usepackage[pages=some,placement=top]{background}|
469 % \end{mycode}
470 %
471 % \section*{Hystory}
472 %
473 % \textbf{Version 1.0 (2009/11/07)}: first implementation, quite simple and paralleling the one of the \texttt{draftwatermark} package by Sergio Callegari, but adding greater control over the background material attributes.\bigskip
474
475 % \textbf{Version 2.0 (2012/08/06)}:
476 % \begin{itemize}
477 % \item Complete reimplementation, now using the \texttt{xkeyval} package to handle attributes and options in an unified way through the \texttt{key=value} mechanism.
478 % \item A bug in version 1.0 with |\SetBgAnchor| was reported by \texttt{eudoxos} at \url{http://tex.stackexchange.com/q/47875/3954}; the bug has been fixed.
479 % \item A user command |\BgMaterial| has been added.
480 % \end{itemize}
481 %
482 % \textbf{Version 2.1 (2014/03/04)}:
483 % \begin{itemize}
484 % \item Added the |nodeanchor| key..
485 % \item The containing node has now |inner sep=0pt|.
486 % \item Improved documentation.
487 % \end{itemize}
488 %
489 % \DoNotIndex{\#,\$,\%,\&,\@,\\,\{,\},\^,\_,\~,\ }
490 % \DoNotIndex{\@ifpackageloaded }
491 % \DoNotIndex{\advance,\AtEndDocument,\begingroup,\begin,\catcode,\clearpage}
492 % \DoNotIndex{\closein,\closeout,\CurrentOption,\day,\DeclareOptionX}
493 % \DoNotIndex{\def,\DeclareRobustCommand,\define@choycekey}
494 % \DoNotIndex{\edef,\else,\end,\empty,\endgroup,\ExecuteOptions,\ExecuteOptionsX,\fi}
495 % \DoNotIndex{\ifcase,\NeedsTeXFormat,\newif,\node,\nr,\or,\PackageWarning}
496 % \DoNotIndex{\let,\newcommand,\renewcommand}
497 % \DoNotIndex{\ProcessOptionsX,\ProvidesPackage,\relax,\RequirePackage,\val}
498 %
499 % \StopEventually{\PrintIndex}
500 %
501 % \section{Implementation}
502 %
503 % Standard identification:
504 % \begin{macrocode}
505 \NeedsTeXFormat{LaTeX2e}
506 \ProvidesPackage{background}[2014/03/04 v2.1 background material]
507 % \end{macrocode}
508 %
509 % Next, we check if the needed packages have been already loaded; if not, we load them:
510 %
511 % \begin{macrocode}
512 \@ifpackageloaded{xkeyval}{}{\RequirePackage{xkeyval}}
513 \@ifpackageloaded{tikz}{}{\RequirePackage{tikz}}
514 \@ifpackageloaded{everypage}{}{\RequirePackage{everypage}}
515 \@ifpackageloaded{afterpage}{}{\RequirePackage{afterpage}}
516 % \end{macrocode}
517 %
518 % \begin{macro}{contents=}
519 % \begin{macro}{color=}
520 % \begin{macro}{angle=}
521 % \begin{macro}{opacity=}
522 % \begin{macro}{scale=}
523 % \begin{macro}{position=}
524 % \begin{macro}{anchor=}
525 % \begin{macro}{nodeanchor=}
526 % \begin{macro}{hshift=}
527 % \begin{macro}{vshift=}
528 % Now we declare the options that will control the background material
529 % \begin{macrocode}
530 \DeclareOptionX[BG]<background>{contents}{%
531 \def\Background@Contents{#1}}
532 \DeclareOptionX[BG]<background>{color}{%
533 \def\Background@Color{#1}}
534 \DeclareOptionX[BG]<background>{angle}{%
535 \def\Background@Angle{#1}}
536 \DeclareOptionX[BG]<background>{opacity}{%
537 \def\Background@Opacity{#1}}
538 \DeclareOptionX[BG]<background>{scale}{%
539 \def\Background@Scale{#1}}
540 \DeclareOptionX[BG]<background>{position}{%
541 \def\Background@Position{#1}}
542 \DeclareOptionX[BG]<background>{anchor}{%
543 \def\Background@Anchor{#1}}
544 \DeclareOptionX[BG]<background>{nodeanchor}{%
545 \def\Background@NodeAnchor{#1}}
546 \DeclareOptionX[BG]<background>{hshift}{%
547 \def\Background@HShift{#1}}
548 \DeclareOptionX[BG]<background>{vshift}{%
549 \def\Background@VShift{#1}}
550 % \end{macrocode}
551 % \end{macro}
552 % \end{macro}
553 % \end{macro}
554 % \end{macro}
555 % \end{macro}
556 % \end{macro}
557 % \end{macro}
558 % \end{macro}
559 % \end{macro}
560 % \end{macro}
561 %
562 % \begin{macro}{\bg@some}
563 % A boolean (initially set to |false|) to control whether the background material will be displayed in
564 % every page or not.
565 % \begin{macrocode}
566
567 \newif\ifbg@some
568 \bg@somefalse
569 % \end{macrocode}
570 % \end{macro}
571 %
572 % \begin{macro}{pages=}
573 % \begin{macro}{position=}
574 % We define the two choice keys \texttt{pages} and \texttt{position} and set the default for their options:
575 % \begin{macrocode}
576
577 \define@choicekey+[BG]{background}{pages}[\val\nr]{all,some}{%
578 \ifcase\nr\relax
579 \bg@somefalse
580 \or
581 \bg@sometrue
582 \fi
583 }{%
584 \PackageWarning{background}{erroneous input ignored}%
585 }
586
587 \define@choicekey+[BG]{background}{placement}[\val\nr]{center,bottom,top}{%
588 \ifcase\nr\relax
589 \renewcommand\Background@Position{current page.center}%
590 \renewcommand\Background@Anchor{}%
591 \renewcommand\Background@Angle{60}
592 \or
593 \renewcommand\Background@Position{current page.south}%
594 \renewcommand\Background@Anchor{above}%
595 \renewcommand\Background@Angle{0}%
596 \or
597 \renewcommand\Background@Position{current page.north}%
598 \renewcommand\Background@Anchor{below}%
599 \renewcommand\Background@Angle{0}%
600 \fi
601 }{%
602 \PackageWarning{background}{erroneous input ignored}%
603 }
604 % \end{macrocode}
605 % \end{macro}
606 % \end{macro}
607 %
608 %
609 % \begin{macro}{firstpage}
610 % This boolean key makes the background material to be displayed only in the first page of the document; dafault value=false.
611 % \begin{macrocode}
612 \define@boolkey+[BG]{background}{firstpage}{%
613 \ifBG@background@firstpage
614 \bg@sometrue%
615 \AtBeginDocument{\BgThispage}%
616 \else
617 \bg@somefalse%
618 \fi
619 }{%
620 \PackageWarning{background}{erroneous input ignored}%
621 }
622 % \end{macrocode}
623 % \end{macro}
624 %
625 % For compatibility with previous version we also provide the package options \texttt{some}, \texttt{all}, \texttt{center}, \texttt{top}, and, \texttt{bottom}:
626 % \begin{macrocode}
627
628 \DeclareOptionX[BG]<background>{all}{\bg@somefalse}
629 \DeclareOptionX[BG]<background>{some}{\bg@sometrue}
630 \DeclareOptionX[BG]<background>{center}{%
631 \renewcommand\Background@Position{current page.center}%
632 \renewcommand\Background@Anchor{}%
633 \renewcommand\Background@Angle{60}}
634 \DeclareOptionX[BG]<background>{bottom}{%
635 \renewcommand\Background@Position{current page.south}%
636 \renewcommand\Background@Anchor{above}%
637 \renewcommand\Background@Angle{0}%
638 \renewcommand\Background@Scale{8}}
639 \DeclareOptionX[BG]<background>{top}{%
640 \renewcommand\Background@Position{current page.north}%
641 \renewcommand\Background@Anchor{below}%
642 \renewcommand\Background@Angle{0}%
643 \renewcommand\Background@Scale{8}}
644 % \end{macrocode}
645
646 % And we execute the options \texttt{all} and \texttt{center}.
647 % \begin{macrocode}
648
649 \ExecuteOptions{all,center}
650 % \begin{macrocode}
651
652 % Now we process any unknown inputs. A warning will be produced when the
653 % user issues an option that has not been declared.
654 % \begin{macrocode}
655
656 \DeclareOptionX*{\PackageWarningNoLine{background}{Option '\CurrentOption' ignored}}
657 % \end{macrocode}
658 %
659 % We next execute and process the options:
660 % \begin{macrocode}
661
662 \ExecuteOptionsX[BG]<background>{%
663 firstpage=false,
664 contents=Draft,%
665 color=red!45,%
666 angle=60,%
667 opacity=0.5,%
668 scale=10,%
669 position=current page.center,%
670 anchor={},%
671 nodeanchor={center},%
672 hshift=0pt,%
673 vshift=0pt%
674 }
675
676 \ProcessOptionsX[BG]<background>
677 % \end{macrocode}
678 %
679 % \begin{macro}{\backgroundsetup}
680 % We define \verb+\backgroundsetup+; our command for changing default values ay any point of the document:
681 % \begin{macrocode}
682 \DeclareRobustCommand*\backgroundsetup[1]{%
683 \setkeys[BG]{background}{#1}
684 }
685 % \end{macrocode}
686 % \end{macro}
687 %
688 %
689 % \begin{macro}{\bg@material}
690 % Our main command uses a simple |\node| construct to build the background material.
691 % \begin{macrocode}
692
693 \newcommand\bg@material{%
694 \begin{tikzpicture}[remember picture,overlay,scale=\Background@Scale]
695 \node[
696 rotate=\Background@Angle,
697 scale=\Background@Scale,
698 opacity=\Background@Opacity,
699 anchor=\Background@NodeAnchor,
700 xshift=\Background@HShift,
701 yshift=\Background@VShift,
702 color=\Background@Color,
703 inner sep=0pt
704 ]
705 at (\Background@Position) [\Background@Anchor]
706 {\Background@Contents};
707 \end{tikzpicture}}%
708 % \end{macrocode}
709 % \end{macro}
710 %
711 % \begin{macro}{\BgThispage}
712 % A simple application of the |AddThispageHook| command provided by the \package{everypage}
713 % package.
714 % \begin{macrocode}
715 \newcommand\BgThispage{\AddThispageHook{\bg@material}}
716 % \end{macrocode}
717 % \end{macro}
718 %
719 % \begin{macro}{\NoBgThispage}
720 % A hack that perhaps admits improvements. We make a copy of |\bg@material|, and redefine
721 % it to be empty on the current page. Then we use the |afterpage| command to restore the
722 % original background material.
723 % \begin{macrocode}
724
725 \newcommand\NoBgThispage{%
726 \let\oldbg@material\bg@material\renewcommand\bg@material{}%
727 \afterpage{\AddEverypageHook{\oldbg@material}}}
728 % \end{macrocode}
729 % \end{macro}
730 %
731 % Finally, we check for the boolean |bg@some|; if it is |true|, then no background material is
732 % added; otherwise, the material will be added using the |AddEverypageHook| command.
733 % \begin{macrocode}
734
735 \ifbg@some
736 \AddThispageHook{}
737 \else
738 \AddEverypageHook{\bg@material}
739 \fi
740 % \end{macrocode}
741 %
742 % \begin{macro}{\SetBgContents}
743 % \begin{macro}{\SetBgColor}
744 % \begin{macro}{\SetBgAngle}
745 % \begin{macro}{\SetBgOpacity}
746 % \begin{macro}{\SetBgScale}
747 % \begin{macro}{\SetBgPosition}
748 % \begin{macro}{\SetBgAnchor}
749 % \begin{macro}{\SetBgHshift}
750 % \begin{macro}{\SetBgVshift}
751 % Now we take care of backwards compatibility; we create the old commands and use them as
752 % aliases for the new ones:
753 % \begin{macrocode}
754
755 \newcommand\SetBgContents[1]{%
756 \def\Background@Contents{#1}}
757 \newcommand\SetBgAngle[1]{%
758 \def\Background@Angle{#1}}
759 \newcommand\SetBgColor[1]{%
760 \def\Background@Color{#1}}
761 \newcommand\SetBgScale[1]{%
762 \def\Background@Scale{#1}}
763 \newcommand\SetBgVshift[1]{%
764 \def\Background@VShift{#1}}
765 \newcommand\SetBgHshift[1]{%
766 \def\Background@HShift{#1}}
767 \newcommand\SetBgPosition[1]{%
768 \def\Background@Position{#1}}
769 \newcommand\SetBgAnchor[1]{%
770 \def\Background@Anchor{#1}}
771 \newcommand\SetBgOpacity[1]{%
772 \def\Background@Opacity{#1}}
773 % \end{macrocode}
774 % \end{macro}
775 % \end{macro}
776 % \end{macro}
777 % \end{macro}
778 % \end{macro}
779 % \end{macro}
780 % \end{macro}
781 % \end{macro}
782 % \end{macro}
783 %
784 % \begin{macro}{\BgMaterial}
785 % We create a copy of \verb+\bg@material+ to be used directly in documents
786 % \begin{macrocode}
787
788 \let\BgMaterial\bg@material
789 % \end{macrocode}
790 % \end{macro}
791 %
792 % Finally, we invoke \verb+\clearpage+ at the end of the document to be sure that the background material in the last page will be processed appropriately:
793 % \begin{macrocode}
794
795 \AtEndDocument{\clearpage}
796 % \end{macrocode}
797 % \Finale
798 \endinput