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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
|
% \iffalse meta-comment
%
% Copyright (C) 2009 by Gonzalo Medina
%
% --------------------------------------------------------------------------
%
% This file may be distributed and/or modified under the
% conditions of the LaTeX Project Public License, either version 1.3
% of this license or (at your option) any later version.
% The latest version of this license is in:
%
% http://www.latex-project.org/lppl.txt
%
% and version 1.3 or later is part of all distributions of LaTeX
% version 2003/12/01 or later.
%
% This work has the LPPL maintenance status `maintained'.
%
% The Current Maintainer of this work is Gonzalo Medina.
%
% This work consists of the files background.dtx and background.ins,
% and the derived files background.sty and background.pdf.
%
% \fi
%
% \iffalse
%
%<*driver>
\documentclass{ltxdoc}
\usepackage{booktabs}
\usepackage{xcolor}
\usepackage{ragged2e}
\usepackage{amsthm}
\usepackage{ifpdf}
\ifpdf
\usepackage[top]{background}
\SetBgContents{-\thepage-}
\SetBgAngle{0}
\SetBgColor{black!40}
\SetBgScale{4}
\SetBgHshift{60}
\SetBgVshift{-5}
\usepackage{mathptmx,courier}
\usepackage[scaled=.9]{helvet}
\fi
\usepackage{hypdoc}
\ifpdf
\usepackage{hypdestopt}
\fi
\hypersetup{pdfkeywords={LaTeX, package, background},%
pdfstartpage={},pdfstartview={},breaklinks=true,%
linktocpage}
\newcommand\MarNote[1]{\marginpar{\RaggedLeft\textcolor{blue}{#1}}}
\newcommand*\package[1]{{\upshape\mdseries\sffamily #1}}
\theoremstyle{remark}
\newtheorem{exam}{Example}
\setlength\parindent{0pt}
\pagestyle{empty}
\makeatletter
\let\ps@titlepage\ps@empty
\makeatother
\usepackage{titletoc}
\titlecontents*{section}[0pt]
{\itshape}{}{}
{, \thecontentspage}[\ --\ ][.]
\titlecontents*{subsection}[0pt]
{\upshape\small}{}{}
{, \thecontentspage}[ (][. ][)]
\setcounter{tocdepth}{2}
\EnableCrossrefs
\CodelineIndex
\RecordChanges
\begin{document}
\DocInput{background.dtx}
\end{document}
%</driver>
% \fi
%
% \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 \~}
%
% \CheckSum{127}
%
% \changes{v 1.0}{2009/11/07}{First version}
%
% \GetFileInfo{background.sty}
%
% \title{The \package{background} package\\
% {\footnotesize\fileversion , dated \filedate.}}
% \author{Gonzalo Medina\\%
% Universidad Nacional de Colombia -- Sede Manizales\\%
% Departamento de Matem\'aticas y Estad\'istica\\
% \texttt{gmedinaar@unal.edu.co}}
%
% \maketitle
%
% \begin{abstract}
% \noindent This package allows the placement of background material on the pages of a
% document. The user can control many aspects (i.e., contents, position, color, opacity) of the
% background material that will be displayed.
% \end{abstract}
% \tableofcontents
% \section{Introduction}
% The \package{background} package relies on the \package{TikZ} and \package{everypar}
% packages to provide a simple and flexible mechanism to include background material on all
% (or on some of) the pages of a \LaTeX2e document.
% \par\medskip
% The implementation is quite simple and parallels the one of the \package{draftwatermark}
% package by Sergio Callegari, but adds greater control over the background material attributes.
% \par\medskip
% The author will gladly receive suggestions, comments and bug reports.
%
% \section{User Interface}
%
% Loading this package (without any package options) in the preamble of a document in the
% standard way:
% \begin{center}
% |\usepackage{background}|
% \end{center}
% activates a set of predefined options that will typeset the word "Draft" across every page of
% your document (from the lower left corner to the upper right corner), using
% \textcolor{red!45}{this color} and a huge font size.
% \par\medskip
% Of course, the package can be loaded using some of the options described in the next section;
% for example:
% \begin{center}
% |\usepackage[some,bottom]{background}|
% \end{center}
%
% \subsection{Package Options}
% Table~\ref{tab:options} shows the available package options\MarNote{By
% default, the package loads the options |all| and |center|.} and their meaning. Obviously, the
% options |all| and |some| are mutually exclusive; the same remark applies to the group of options
% |center|, |bottom|, and |top|.
% \par\medskip
% Take into account that using the |some| 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}).
%
% \begin{table}[!ht]
% \centering
% \begin{tabular}{rp{6cm}}\toprule
% Option & Meaning\\\toprule
% |all| & The background material will be displayed in all the pages.\\
% |some| & The background material will be displayed only in the pages for which the
% |\BgThispage| command was used.\\
% |center| & The background material will be displayed diagonally.\\
% |bottom| & The background material will be displayed horizontally at the bottom of the page.\\
% |top| & The background material will be displayed horizontally at the top of the page.
% \\\bottomrule
% \end{tabular}
% \caption{The package options.}
% \label{tab:options}
% \end{table}
%
% \subsection{User Commands}
% Since the commands 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}}.
% \par\medskip
% \DescribeMacro{\SetBgContents}
% This command allows the user to change the material that will be used as background. The usage
% is
% \begin{center}
% |\SetBgContents{|\meta{material}|}|
% \end{center}
% where \meta{material} can be any text or an image (via the |\includegraphics| command
% from the \package{graphicx} package) or even a graphic created, for example, with the
% \package{TikZ} package.
% \par\medskip
% \DescribeMacro{\SetBgColor}
% This command allows the user to change the color that will be used for the background material if % such material is text. The usage is
% \begin{center}
% |\SetBgContents{|\meta{color}|}|
% \end{center}
% where \meta{color} can be any color set by the \package{xcolor} package.
% \par\medskip
% \DescribeMacro{\SetBgAngle}
% This command allows the user to change the angle that will be used for displaying the background % material. The usage is
% \begin{center}
% |\SetBgContents{|\meta{degrees}|}|
% \end{center}
% where \meta{degrees} can be any value between $-360$ and $360$.
% \par\medskip
% \DescribeMacro{\SetBgOpacity}
% This command allows the user to change the transparency level for the background material. The % usage is
% \begin{center}
% |\SetBgOpacity{|\meta{value}|}|
% \end{center}
% where \meta{value} can be any number between $0$ (full transparency) and $1$ (no
% transparency at all).
% \par\medskip
% \DescribeMacro{\SetBgScale}
% This command allows the user to change the scaling factor that will be applied to the background
% material. The usage is
% \begin{center}
% |\SetBgScale{|\meta{factor}|}|
% \end{center}
% where \meta{factor} can be any positive value.
% \par\medskip
% \par\medskip
% \DescribeMacro{\SetBgPosition}
% This command allows the user to define the position of the background
% material. The usage is
% \begin{center}
% |\SetBgPosition{|\meta{position}|}|
% \end{center}
% where \meta{position} can be any valid\MarNote{Do not enclose \meta{position} inside
% parentheses} position accepted by the |at| syntax for nodes placement (see the TikZ
% manual). Some examples of valid positions are
% \begin{center}
% |\SetBgPosition{0,0}|\\
% |\SetBgPosition{current page.north}|\\
% |\SetBgPosition{5cm,7cm}|
% \end{center}
% \par\medskip
% \DescribeMacro{\SetBgAnchor}
% This command allows the user to set the anchor for the node placement. The usage is
% \begin{center}
% |\SetBgAnchor{|\meta{anchor name}|}|
% \end{center}
% Typical examples are:
% \begin{center}
% |\SetBgAnchor{north east}|\\
% |\SetBgAnchor{west}|\\
% \end{center}
% \par\medskip
% \DescribeMacro{\SetBgHshift}
% \DescribeMacro{\SetBgVshift}
% These two commands control the horizontal and vertical shifting of the node position.
% \begin{center}
% |\SetBgHshift{|\meta{value}|}|\\
% |\SetBgVshift{|\meta{value}|}|
% \end{center}
% \par\medskip
% 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.
% \par\medskip
% \DescribeMacro{\BgThispage}
% This command permits to select particular pages in which the background material will
% be displayed (see example \ref{exa:bgthispage}).
%
% \subsubsection{Experimental}
% \DescribeMacro{\NoBgThispage}
% This command will prevent the background material to be displayed in the page where it
% \MarNote{Do not use this command in two column mode.}
% was issued. Its implementation depends on the \package{afterpage} package,
% so the corresponding precautions must be taken into account (see example
% \ref{exa:nobgthispage}) .
%
% \section{Examples}
% In the following examples, the \package{lipsum} package was used only to automatically
% generate text.
% \begin{exam}
% This example shows how to display the background material only on the first two pages of
% the document:
% \end{exam}
% |\documentclass{article}|\\
% |\usepackage{background}|\\
% |\usepackage{lipsum}|\\
%
% |\begin{document}|\\
% |\lipsum[1-10]|\\
% |\newpage\SetBgContents{}|\\
% |\lipsum[1-30]|\\
% |\end{document}|
% \begin{exam}
% This example imitates the page numbering format used in this document:
% \end{exam}
% |\documentclass{article}|\\
% |\usepackage[top]{background}|\\
% |\usepackage{lipsum}|\\
%
% |\SetBgContents{-\thepage-}|\\
% |\SetBgAngle{0}|\\
% |\SetBgColor{black!40}|\\
% |\SetBgScale{4}|\\
% |\SetBgHshift{60}|\\
% |\SetBgVshift{-5}|\\
%
% |\pagestyle{empty}|\\
%
% |\begin{document}|\\
% |\lipsum[1-30]|\\
% |\end{document}|
%
% \begin{exam}\label{exa:bgthispage}
% This example illustrates how to use of the |\BgThispage| command to add background material
% on selected pages.
% \end{exam}
% |\documentclass{article}|\\
% |\usepackage[some,top]{background}|\\
% |\usepackage{lipsum}|\\
%
% |\begin{document}|\\
% |\lipsum[1-5]|\\
% |\newpage|\\
% |\SetBgContents{A}\SetBgColor{yellow}|\\
% |\BgThispage|\\
% |\lipsum[1-5]|\\
% |\newpage|\\
% |\SetBgContents{B}\SetBgColor{blue}|\\
% |\BgThispage|\\
% |\lipsum[1-5]|\\
% |\end{document}|
%
% \begin{exam}
% This example shows how to proceed in order to obtain different background material for the
% odd and even pages of a document.
% \end{exam}
% |\documentclass{article}|\\
% |\usepackage{background}|\\
% |\usepackage{lipsum}|\\
% |\usepackage{ifthen}|\\
%
% |\SetBgContents{}|\\
% |\SetBgOpacity{1}|\\
% |\SetBgScale{1.5}|\\
% |\makeatletter|\\
% |\AddEverypageHook{%|\\
% | \ifthenelse{\isodd{\thepage}}%|\\
% | {\SetBgAngle{90}%|\\
% | \SetBgPosition{0,-.7\textheight}%|\\
% | \SetBgColor{blue!90}%|\\
% | \SetBgContents{The background package}}%|\\
% | {\SetBgAngle{270}%|\\
% | \SetBgPosition{1.35\textwidth,-.7\textheight}%|\\
% | \SetBgContents{First version}}%|\\
% | \bg@material}|\\
% |\makeatother|\\
%
% |\begin{document}|\\
% |\lipsum[1-30]|\\
% |\end{document}|
%
% \begin{exam}\label{exa:nobgthispage}
% This example\MarNote{Adding the |twocolumn| class option will produce compilation errors}
% illustrates the use of the |\NoBgThispage| command, to
% suppress the background material on selected pages (page 2, in this case).
% \end{exam}
% |\documentclass{article}|\\
% |\usepackage{background}|\\
% |\usepackage{lipsum}|\\
%
% |\begin{document}|\\
% |\lipsum[1-5]|\\
% |\newpage\NoBgThispage|\\
% |\lipsum[1-5]|\\
% |\newpage|\\
% |\lipsum[1-20]|\\
% |\end{document}|
%
% \DoNotIndex{\#,\$,\%,\&,\@,\\,\{,\},\^,\_,\~,\ }
% \DoNotIndex{\advance,\begingroup,\begin,\catcode,\closein}
% \DoNotIndex{\closeout,\day,\def,\edef,\else,\end,\empty,\endgroup,\fi}
% \DoNotIndex{\let,\newcommand,\renewcommand}
%
% \StopEventually{\PrintIndex}
%
% \section{Implementation}
%
% Standard identification:
% \begin{macrocode}
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{background}[2009/11/07 v1.0 bg material]
% \end{macrocode}
%
% Now we load the packages that will be used:
%
% \begin{macrocode}
\RequirePackage{everypage}
\RequirePackage{tikz}
\RequirePackage{afterpage}
% \end{macrocode}
%
% \begin{macro}{\bg@some}
% A boolean (initially set to |false|) to control whether the background material will be displayed in
% every page or not.
% \begin{macrocode}
\newif\ifbg@some
\bg@somefalse
% \end{macrocode}
% \end{macro}
%
% \begin{macro}{\bg@contents}
% \begin{macro}{\bg@color}
% \begin{macro}{\bg@angle}
% \begin{macro}{\bg@opacity}
% \begin{macro}{\bg@scale}
% \begin{macro}{\bg@position}
% \begin{macro}{\bg@anchor}
% \begin{macro}{\bg@hshift}
% \begin{macro}{\bg@vshift}
% We define the internal control commands and set their default value:
% \begin{macrocode}
\def\bg@contents{Draft}
\def\bg@color{red!45}
\def\bg@angle{60}
\def\bg@opacity{.5}
\def\bg@scale{15}
\def\bg@position{current page.center}
\def\bg@anchor{}
\def\bg@hshift{0}
\def\bg@vshift{0}
% \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
%
% Now we declare the package options:
% \begin{macrocode}
\DeclareOption{all}{\bg@somefalse}
\DeclareOption{some}{\bg@sometrue}
\DeclareOption{center}{%
\def\bg@position{current page.center}%
\def\bg@anchor{}%
\def\bg@angle{60}}
\DeclareOption{bottom}{%
\def\bg@position{current page.south}%
\def\bg@anchor{above}%
\def\bg@angle{0}%
\def\bg@scale{8}}
\DeclareOption{top}{%
\def\bg@position{current page.north}%
\def\bg@anchor{below}%
\def\bg@angle{0}%
\def\bg@scale{8}}
% \end{macrocode}
%
% We next execute and process options in the standard \LaTeX2e way:
% \begin{macrocode}
\ExecuteOptions{all,center}
\ProcessOptions
% \end{macrocode}
%
% \begin{macro}{\SetBgContents}
% \begin{macro}{\SetBgColor}
% \begin{macro}{\SetBgAngle}
% \begin{macro}{\SetBgOpacity}
% \begin{macro}{\SetBgScale}
% \begin{macro}{\SetBgPosition}
% \begin{macro}{\SetBgAnchor}
% \begin{macro}{\SetBgHshift}
% \begin{macro}{\SetBgVshift}
% Now comes the definition of the user commands:
% \begin{macrocode}
\newcommand*\SetBgContents[1]{%
\def\bg@contents{#1}}
\newcommand*\SetBgColor[1]{%
\def\bg@color{#1}}
\newcommand*\SetBgAngle[1]{%
\def\bg@angle{#1}}
\newcommand*\SetBgOpacity[1]{%
\def\bg@opacity{#1}}
\newcommand*\SetBgScale[1]{%
\def\bg@scale{#1}}
\newcommand*\SetBgPosition[1]{%
\def\bg@position{#1}}
\newcommand*\SetBgAnchor[1]{%
\def\bg@anchor{#1}}
\newcommand*\SetBgHshift[1]{%
\def\bg@hshift{#1}}
\newcommand*\SetBgVshift[1]{%
\def\bg@vshift{#1}}
% \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\bg@material}
% Our main command uses a simple |\node| construct to build the background material.
% \begin{macrocode}
\newcommand\bg@material{%
\begin{tikzpicture}[remember picture,overlay]
\node [rotate=\bg@angle,scale=\bg@scale,opacity=\bg@opacity,%
xshift=\bg@hshift,yshift=\bg@vshift,color=\bg@color]
at (\bg@position) [\bg@anchor] {\bg@contents};
\end{tikzpicture}}%
% \end{macrocode}
% \end{macro}
%
% \begin{macro}{\BgThispage}
% A simple application of the |AddThispageHook| command provided by the \package{everypage}
% package.
% \begin{macrocode}
\newcommand\BgThispage{\AddThispageHook{\bg@material}}
% \end{macrocode}
% \end{macro}
%
% \begin{macro}{\NoBgThispage}
% A hack that perhaps admits improvements. We make a copy of |\bg@material|, and redefine
% it to be empty on the current page. Then we use the |afterpage| command to restore the
% original background material.
% \begin{macrocode}
\newcommand\NoBgThispage{%
\let\oldbg@material\bg@material\renewcommand\bg@material{}%
\afterpage{\AddEverypageHook{\oldbg@material}}}
% \end{macrocode}
% \end{macro}
%
% Finally, we check for the boolean |bg@some|; if it is |true|, then no background material is
% added; otherwise, the material will be added using the |AddEverypageHook| command.
% \begin{macrocode}
\ifbg@some
\AddThispageHook{}
\else
\AddEverypageHook{\bg@material}
\fi
% \end{macrocode}
%
% \Finale
\endinput
|