text:
# xwatermark-guide.

x
w
a
t
e
r
m
a
r
k
x
w
a
t
e
r
m
a
r
k
x
w
a
t
e
r
m
a
r
k
x
w
a
t
e
r
m
a
r
k
x
w
a
t
e
r
m
a
r
k
The xwatermark PackageI
Version 1.5.2a
A dynamic watermarking scheme for LATEX
Ahmed Musa The University of Central Lancashire, Preston, UK
29th January 2012
Abstract
The xwatermark package puts user-supplied watermarks (graphics and/or arbitrary texts) on select pages of documents using user-friendly key-value interfaces. It has more functionality and dynamism than, for example, the packages draftcopy, draftwatermark, watermark, draftmark,
wallpaper. More than one (graphics and/or text) watermark can be placed jointly or independently on the same document page or on select pages. Watermarks can be placed in the page
background or foreground, and watermarks can conveniently be placed on select pages as rectangular or square tiles, depending on the user’s choice. Some utility macros, namely, \xwmminipage,
\xwmcolorbox, \makecolobox and \fancypagenos are also provided by the package for handy
use in creating watermarks and for other uses. Watermarks (especially wallpapers) take their toll
on computer resources, especially speed and save stack size. The packages in the xwatermark
bundle (and beyond) have been optimized as much as currently possible. In many instances
more than one run of the document will be needed to get the watermarks on the desired pages,
especially if the user calls \lastdocpage to get the last page of the document.
I
The package is available at http://mirror.ctan.org/macros/latex/contrib/xwatermark/.
The xwatermark package
29th January 2012
•
•
This work (i. e., all the files in the xwatermark manifest) may be distributed and/or modified under
the conditions of the LATEX Project Public License (LPPL), either version 1.3 of this license or any
later version. The LPPL maintenance status of this software is ‘author-maintained’. This software
is provided ‘as it is’, without warranty of any kind, either expressed or implied, including, but not
c MMXII
limited to, the implied warranties of merchantability and fitness for a particular purpose. Contents
1 Introduction
2
2 User interfaces
2.1 Loading the package . . . . . . . .
3
3
3 The \newwatermark macro
3.1 Options without values . . . . . .
3.2 Emptying the watermarks of some
pages or objects . . . . . . . . . .
3.3 Printing both picture and text watermarks on same page . . . . . .
3.4 The usefulness of the white color
3.5 Dummy watermarks . . . . . . .
.
5
6
.
6
.
.
.
7
7
7
4 Wallpapers
4.1 The \newwallpaper macro . . . . .
8
8
5 Graphics watermarks
8
5.1 Passing
key
values
to
\includegraphics directly . . . . 9
5.2 The graphics input paths . . . . . 10
6 Other aspects of package architecture and use
6.1 \documentclass options . . . . . .
6.2 The size of the watermark . . . . .
6.3 The coordinates of the watermark
6.4 Wrong location of the watermark .
6.5 Wrong size of the watermark . . .
1
10
10
11
11
11
11
6.6
6.7
6.8
6.9
6.10
Breaking the watermark into lines
The alignment of the watermark .
Locating the page center . . . . . .
The last page of the document . .
Active characters . . . . . . . . . .
12
12
12
13
13
7 Macros for creating boxes
13
7.1 The \xwmminipage macro . . . . . 14
7.2 The \xwmcolorbox macro . . . . . 14
7.3 The \makecolorbox macro . . . . . 14
8 The \fancypagenos macro
15
9 xwatermark and geometry package
15
10 Support for unicode and utf encodings
16
11 Repeated graphics in a document
12 Further
examples
xwatermark package
of
use
16
of
17
13 Package options and macro keys
17
13.1 Global options . . . . . . . . . . . 17
13.2 Local options . . . . . . . . . . . . 18
14 Version history
23
Index
25
Introduction
puts user-specified watermarks (graphics and/or arbitrary texts) on
T selectxwatermark
pages of documents. It has more functionality and dynamism than, for example, the
HE
PACKAGE
packages draftcopy, draftwatermark, watermark, draftmark and wallpaper packages. The
advantages of xwatermark package over these earlier packages include:
a) Both text and graphics watermarks are admissible within any watermark item or instance.
b) The user can dynamically customize the attributes (color, position, orientation, scale, the
page(s)—first page, last page, all pages, odd pages, even pages, a particular page, and a
Page 2 of 25
The xwatermark package
29th January 2012
range of pages—on which the watermark should appear) of each watermark.
c) Watermarks can be placed in the background and in the foreground of document pages by
simple instructions.
d) Rectangular and square wallpapers can be produced from watermarks to suit user needs
without effort.
e) All the command options/keys are passed directly via user-friendly key-value interfaces, instead of being defined in the source file by several macros. There are only two main user
commands: \newwatermark and \newwallpaper. The user is relieved of the need to remember and deploy several different macros, except, of course, that function keys are used. The
list of keys and their default values for these functions are given in section 13.
With the xcolor package (not loaded automatically by the xwatermark package), all colors (including white, shades like -red!75!green!50, and those defined within the user document) can
be passed to this package. And, as mentioned above, both texts and pictures can be submitted
and printed as watermarks on the same page, and on different positions.
There are global and local package options. These are listed and explained in section 13.
Users who have since complained of not being able to conveniently place more than one watermark
on the same page can now heave a sigh relieve: the current version of the package has enabled this
functionality. You can now mix text and graphics watermarks and wallpapers and place as many
of them as you like on the same page. This version of the package comes with optimized looping
macros and a key management system (the ltxkeys package) to enable several watermarks and
wallpapers to be placed efficiently on the same document pages. The ltxkeys package can be used
for general key parsing.
2
User interfaces
In style files the package may be loaded with \RequirePackage and in document files with
\usepackage together with the package keys that can be passed as options.
Note 2.1 Some of the keys are ‘option keys’, i. e., they can appear only in \documentclass or
\usepackage and not as, or in, arguments of other functions or macros. The ‘non-option keys’
are those that can’t appear in \documentclass or \usepackage but in the arguments of other
macros. If a key is a non-option key and the user submits it to \documentclass or \usepackage,
the package will alert the user. The same thing can be expected when a key is an option key and is
submitted outside of \documentclass or \usepackage. The ‘need value’ keys are keys that can’t
be called without a user-supplied value.
The package keys printwatermark and disablegeometry are option keys, and hence can be called
as follows:
1
2
\RequirePackage[printwatermark,disablegeometry]{xwatermark}
\usepackage[printwatermark,disablegeometry]{xwatermark}
The other options may be submitted via user commands like \newwatermark and \newwallpaper.
Please see Tables 1 and 2 for a full listing of all the available package and command options. By
design, the boolean option printwatermark should not appear in the macros \newwatermark
and \newwallpaper but as a package or \documentclass option. It is disabled just before
\begin{document} and any attempt to pass it via \newwatermark or \newwallpaper thereafter
will trigger an error.
Page 3 of 25
The xwatermark package
29th January 2012
When boolean options (e. g., printwatermark and allpages) are passed without values, they are
assumed implicitly true by the package.
Note 2.2 When your watermark is not printed, first check that the option printwatermark is
true. This is one of the means to control the printing of watermarks. The others are through the
following commands (more details are available in subsection 3.5):
3
4
The option textmark implies text watermarks, for which all the font properties can be selected.
It does not apply to graphics watermarks. For graphics watermarks you need the keys: picfile
(the graphics/picture filename, with its full path but without its extension), and picfileext (the
file extension). Admissible file extensions are ps, eps, pdf, png, mps and jpeg; they should be
submitted without the dot. The extensions ps and eps are for dvi files, while the rest are for pdf
runs. Additional information is needed (see section 5)H1 .
The following points should be noted about the values of the textmark:
a) The value of the textmark may be any arbitrary multi-line text, such as
Example: textmark
5
textmark=Hello world,\\[.25\baselineskip] We’re here.
b) The value of textmark may be arbitrary (blocks of) texts or even kernel or package commands, but not filenames on their own (except when submitted as values of graphics keys).
The package has a user-friendly interface for inserting graphics watermarks and wallpapers,
which does not require the user to directly employ \includegraphics.
c) The textwidth and picwidth should be properly selected to match user’s taste and the
length of the textmark. It may be set to \paperwidth or \paperheight, or any arbitrary
length. Its default value is preset to \paperheight. Sometimes it might also be necessary
to suitably select the height, whose default value is \paperwidth.
d) If the longest line of a textmark is longer than \paperwidth and/or \paperheight (depending on the orientation of the textmark), then the fontsize and the textscale (or picscale)
options will have to be suitably chosen.
The boolean options firstpage, lastpage, allpages, firstpage, oddpages and evenpages,
which specify the pages that should receive watermarks, may be replaced by any of the options
page=x, pages=x-y, pagex={x,y,z}, where ‘x’, etc., stand for any page number. If you enter,
for example, pages=0-10, all pages from 1 to 10 will receive the watermark. On the other hand,
an entry like pages=10-0 will print watermark on page 10 only. If no page-specifying option is
given and printwatermark is true, watermark will appear only on the first page and a warning
message will be entered in the transcript file. When passing page=x or pages=x-y as option to
package, don’t forget to include the equality sign (=), otherwise the option will trigger an ‘unknown
option/key’ error. The key pages expects a page range with the pages separated by a hyphen,
while pagex expects a comma-separated list of pages. For obvious reasons, the value of the key
pagex must always be given in balanced curly braces.
H1 When the options align, height, width, angle, scale, xpos, ypos and color appear without prefixes such as
pic or text, they refer to the text watermark and not the graphics watermark. The user can thus use these
options in place of textalign, textheight, textwidth, textangle, textscale, textxpos, textypos and textcolor,
respectively. However, options referring to graphics watermarks must always be prefixed with pic (e. g., picfile).
Page 4 of 25
The xwatermark package
29th January 2012
When specifying package options either in \usepackage or \documentclass (or indeed in the
macros \newwatermark, \newwallpaper, \xwmminipage, \xwmcolorbox and \fancypagenos), the
following points should be noted:
a) Multiple lines are permitted but not blank lines.
b) Extra paces between options and words are ignored.
c) Active characters (those of catcode 13) may be allowed (but see subsection 6.10 for further
d) Options are mostly order-agnostic, except graphicsoptions, whose values take precedence
over those supplied via other keys (see subsection 5.1).
The global boolean option printwatermark=true (or =false) should ideally be set when loading
the package, e. g.,
Package option: printwatermark
6
\usepackage[printwatermark]{xwatermark}
or in the \documentclass options list:
Package option: printwatermark
7
8
\documentclass[a4paper,12pt,printwatermark]{article}
\usepackage{xwatermark}.
The remaining options should ideally be set dynamically using the macro \newwatermark or
\newwallpaper. These other options can be set for each page, as on the pages of the accompanying example files.
3
The \newwatermark macro
The use syntax for the command \newwatermark is as follows
New macro: \newwatermark
9
10
\newwatermark[hkeyvali]{hmarki}
\newwatermark*’[hkeyvali]{hmarki}
where hkeyvali is the list of keys and their values (called the watermark attributes) and hmarki is
the text watermark. Graphics watermarks are to be specified with their file name, file extension,
etc. The full lists of the available keys for the macro \newwatermark and others are available in
section 13.
The starred (?) variant of \newwatermark puts the watermark in the foreground instead of the
background, and the prime (’) variant is ignored, i. e., no watermark is produced (see subsection 3.5).
The macro \newwatermark can be used as in
Example: \newwatermark
11
12
\newwatermark[pagex={2,5,7},fontfamily=bch,color=gray!25,angle=45,scale=3,
xpos=0,ypos=0]{DRAFT},
where the textmark has been enclosed in curly braces as the last argument of the macro. The
options (called the watermark attributes) are expected in square brackets. The textmark (which
Page 5 of 25
The xwatermark package
29th January 2012
is ‘DRAFT’ in the above example) can also be given within square brackets, in which case the
curly braces will be empty:
Example: \newwatermark
13
14
\newwatermark*[page=10,fontfamily=bch,color=gray!25,angle=45,scale=3,xpos=0,
ypos=0,textmark=DRAFT]{}.
The option printwatermark may appear in only \usepackage or \documentclass options list,
since it is disabled at \begin{document}. However, the options firstpage, lastpage, allpages,
oddpages and evenpages, etc., which specify watermark pages, can and should appear in the
command \newwatermark. This implies that the instructions that specify watermark pages may
be issued and superseded dynamically (page by page or chapter by chapter). For small documents,
this feature may be unnecessary, but it will be useful in large documents (such as a report or book),
in which the watermark may change from chapter to chapter.
When you want the watermark on only one page of the document, you can conveniently use the
\newwatermark macro with the page option page=hnoi in the preamble of your document after
issuing
Examples: \usepackage, printwatermark
15
\usepackage[printwatermark]{xwatermark}
In this way, you don’t have to bother with locating in the source file the spot that corresponds to
the page on which you want the watermark to appear. In fact, you can collect all the watermarks
in the document preamble or in a configuration file with the command \newwatermark.
Note 3.1 Each call to \newwatermark must contain the page(s) that will receive the watermark(s),
otherwise the user will be alerted. The page specifiers are:
16
17
page=x
lastpage
pages=x-y
allpages
pagex={x,y,z}
oddpages
firstpage
evenpages
3.1 Options without values
If you follow an option key with an equality sign but without a value, as in, e. g.,
Example: \newwatermark
18
19
\newwatermark[firstpage,fontfamily=,color=gray!25,angle=45,scale=0.8,
xpos=0,ypos=0,textmark=]{},
then there will be no problem but the outcome may be unpredictable, depending on the key that
has no value. In the above example, no watermark will be printed (not even the default mark,
which is DRAFT) because empty textmark is valid and implies that no watermark should be printed.
The absence of fontfamily in ‘fontfamily=’ will compel (LA)TEX to use an arbitrary fontfamily
that isn’t the default (the default fontfamily is phv if the key fontfamily is not passed, and cmr
otherwise).
3.2 Emptying the watermarks of some pages or objects
If you issue any of the statements
Page 6 of 25
The xwatermark package
20
21
page=x
lastpage
29th January 2012
pages=x-y
allpages=true
pagex={x,y,z}
evenpages=true
firstpage
oddpages=true
together with printwatermark=true but you don’t want the mark on any particular page, we
can simply set \newwatermark[other keys,textmark=]{} or, to the same effect, we may set
\newwatermark[other keys]{}, where ‘other keys’ may include the page specifiersH2 . These both
imply that the text watermark for the given page is empty. This can be useful when transiting from
one watermark type to another. Moreover, since both picture and text marks can be submitted
via one and the same command \newwatermark (see subsection 3.3), this technique may be used
to empty the text watermark for the given page or range of pages. For example,
Example: \newwatermark
22
23
24
\newwatermark[allpages,fontfamily=put,color=white,fontsize=3cm,scale=1,
picbb=112 619 242 751,picscale=3,picfile=./graphics/myfig,picfileext=eps,
width=\paperheight,align=center,angle=0,xpos=0,ypos=0]{}
will print only the picture watermark, since the textmark is empty here.
3.3 Printing both picture and text watermarks on same page
Both picture and text marks can be submitted and printed on the same page via one and the same
\newwatermark. For example,
Example: \newwatermark
25
26
27
28
\newwatermark[pages=1-2,fontfamily=put,color=white,fontsize=3cm,scale=1,
picbb=112 619 242 751,picscale=3,picfile={./graphics/myfig},
picfileext=eps,width=\paperheight,align=center,angle=0,xpos=0,
ypos=0]{Hello World}
However, both the picture and text marks will then share the same subset of the attributes (position, angle, align, etc.). When text and graphics watermarks appear on the same page, the recommended approach is to submit the two types of watermark by two separate calls to \newwatermark.
3.4 The usefulness of the white color
You can deploy the white color to great effect in designing text watermarks. Also, if you set
allpages=true or evenpages=true or oddpages=true together with printwatermark=true
but you don’t want the mark on any particular page, you can simply enter color=white in the
\newwatermark on that page. This applies only to text watermarks, as such a declaration has no
effect on picture watermarks. This may be convenient in circumstances where you may change your
mind as to whether to place a watermark on a particular page or not. In this way you don’t have to
set \newwatermark[other keys,textmark=]{} or remove (or comment out) the \newwatermark
3.5 Dummy watermarks
When you don’t need a watermark printed, you can simply replace its \newwatermark with
\dummywatermark, instead of commenting out the entire watermark or using color=white. Both
H2
In the case of graphics watermarks, setting \newwatermark[other keys,picfile=]{} will prompt a ‘no file’ error.
Page 7 of 25
The xwatermark package
29th January 2012
the macros \newwatermark and \dummywatermark have the same syntax and expect the same
number and types of arguments:
New macro: \dummywatermark
29
30
31
32
\dummywatermark[pages=12-13,fontfamily=phv,fontsize=11pt,fontseries=m,
align=center,height=\paperheight,width=\paperwidth,angle=90,scale=1,
xpos=0,ypos=-1
]{Example}
And when you don’t want any of your watermarks printed, you could simply issue the option
printwatermark=false or call the command \DiscardAllWatermarks. These will simply turn
all instances of \newwatermark command into \dummywatermark. In any run, you may decide to use some or all of the dummy watermarks. To use all dummy watermarks, you issue
the command \UseDummyWatermarks before the instances of \dummywatermark. To again disregard all subsequent dummy watermarks, which is the default state, simply call the command
\DiscardDummyWatermarks. These commands provide a convenient scheme for deciding the watermarks to be printed with minimal typing. For wallpapers, there is the corresponding command
\dummywallpaper. Also, putting a prime sign (’) on \newwatermark or \newwallpaper turns the
command into a dummy mark, but only for that single instance. Subsequent \newwatermark and
\newwallpaper without primes will produce watermarks and wallpapers, respectively.
4
Wallpapers
4.1 The \newwallpaper macro
The command \newwallpaper can be used to produce rectangular and square tiles on document
pages. The use syntax for the command \newwallpaper is
New macro: \newwallpaper
33
34
\newwallpaper[hkeyvali]{hmarki}
\newwallpaper*’[hkeyvali]{hmarki}
where hkeyvali is the list of keys and their values (called the attributes) and hmarki is the text
(and not graphics) watermark. Graphics watermarks are again to be specified with their file name,
file extension, etc. The full lists of the available keys for the macro \newwallpaper are available
in Table 2.
The starred (?) variant of \newwallpaper puts the watermark in the foreground instead of the
background, and the prime (’) variant is ignored, i. e., no wallpaper is produced (see subsection 3.5).
When you get unexpected tiles, you first should consider enabling or disabling the keys squaretiles
(default true) and/or boxalign (default center). The key boxalign may assume one of the values
in the set t-l, t-r, b-l, b-r, s or top-left, top-right, bottom-left, bottom-right, center,
justified.
5
Graphics watermarks
For graphics/picture watermarks, you need the picfile (the graphics filename, with its full path
but without its extension), picfileext (the picture filename extension without the dot), picbb
(the picture bounding box), and picscale (the picture scale)H3 . Admissible file extensions are
H3
These options have longer, easier to remember, names; see Table 2.
Page 8 of 25
The xwatermark package
29th January 2012
eps, pdf, png and jpeg; the latter three, but not the first, may be used in the case of pdfTEX.
The file extension should be passed without the dot. If the file extension is not passed to package,
the package selects it automatically based on whether pdfTEX mode is running or not (normal
extensions are eps for dvi mode and pdf for pdfTEX mode). In fact, the package does search hard
on the given paths for other admissible file types with the base filename the user has specified. If
you have the graphics file in both eps and pdf-compatible formats, then you don’t have to bother
about submitting the file extension to the package: it will automatically select the appropriate file
extension, depending on the mode (pdf or dvi) in which it is running.
5.1 Passing key values to \includegraphics directly
The xwatermark package uses graphicx package’s \includegraphics to insert graphics watermarks. Users can pass valid key values to the command \includegraphics directly via the macros
\newwatermark and \newwallpaper. The key to use for this purpose is graphicsoptions. The
following points should be noted in respect of the key graphicsoptions:
a) Values of the key graphicsoptions must always be enclosed in curly braces, since they are
expected to be more than one.
b) Only keys and values valid for the command \includegraphics may appear in the command
graphicsoptions. Valid keys for \includegraphics are
\includegraphics keys
35
36
37
bb, bbllx, bblly, hiresbb, viewport, trim, height, width, natheight,
natwidth, totalheight, angle, origin, keepaspectratio, scale, clip,
c) Key values submitted via graphicsoptions supersede those submitted outside it, even
if those outside graphicsoptions appear earlier than graphicsoptions in the command
\newwatermark or \newwallpaper.
d) Values submitted via graphicsoptions have only local effect, in the sense that they become
null and void outside of \newwatermark or \newwallpaper. If the user wants the key values
submitted via graphicsoptions to prevail for all subsequent watermarks and wallpapers,
then he should use the command \GraphicsOptions. Values passed via \GraphicsOptions
don’t only have global effect, but they always override those submitted via graphicsoptions.
It should be noted that \GraphicsOptions isn’t a key but a stand-alone command with the
following syntax:
New macro: \GraphicsOptions
38
\GraphicsOptions{hkeyvali}
where hkeyvali are admissible keys for the command \includegraphics and their user-supplied
values. The values so suggested by \GraphicsOptions override those given via the keys of the
xwatermark, including graphicsoptions. Such values remain in force until they are changed later
by another call to \GraphicsOptions.
An example follows:
Example: graphicsoptions
39
40
41
42
43
\newwallpaper[%
page=10,picangle=45,tilexoffset=0pt,tileyoffset=0pt,picontoptext=false,
boxalign=top-left,picbb=116 428 477 718,picscale=2,picfile=tabu-test1,
tileno=4,picfileext=pdf,graphicsoptions={clip,keepaspectratio,hiresbb}
]{mypicture}
Page 9 of 25
The xwatermark package
44
45
29th January 2012
% or globally as
\GraphicsOptions{clip=true,keepaspectratio,hiresbb}
The commands \DeclareGraphicsExtensions and \DeclareGraphicsRule of the graphics package can still be invoked before setting graphics watermarks.
5.2 The graphics input paths
Users can suggest the possible locations of the graphics watermarks to the package by using the
command \watermarkpaths, whose syntaxes are
New macro: \watermarkpaths
46
47
\watermarkpaths[hprei](hposti){{path-1}{path-2}...{path-n}}
\watermarkpaths?[hprei](hposti){path-1,path-2,...,path-n}
Here, hprei and hposti are optional arguments that apply to all the given paths. Caution should
be exercised when using these optional arguments, since when used incorrectly they can yield the
wrong path (see the example below). In the unstarred variant all the paths must be provided in
surrounding curly braces and must have no commas, otherwise the package will raise an error. The
starred (?) variant expects paths to be separated by commas. The package works hard to find your
watermark on the suggested path.
Examples: \watermarkpaths
48
49
50
51
52
53
54
55
\watermarkpaths{{./}{./graphics/}{./graphics/recentfiles/}}
\watermarkpaths?{./,./graphics/,./graphics/recentfiles/}
\watermarkpaths(/){{.}{./graphics}{./graphics/recentfiles}}
\watermarkpaths?(/){.,./graphics,./graphics/recentfiles}
% Note the empty balanced braces below. Without them, the first entry
% (which is supposed to be {./}) will be wrong:
\watermarkpaths[.](/){{}{/graphics}{/graphics/recentfiles}}
\watermarkpaths?[.](/){{},/graphics,/graphics/recentfiles}
By default, the packages works hard to preserve outer curly braces, unless and until they are
required to be removed.
The command \watermarkpaths inherits the current contents of LATEX’s \[email protected] command
and graphics package’s \[email protected] (the latter takes argument from \graphicspath).
6
Other aspects of package architecture and use
6.1 \documentclass options
The package is set to inherit the \documentclass options, if the options apply to the package.
Therefore, some of the package options can be passed to the package via the \documentclass
options list. This is perhaps most appropriate in the case of the option printwatermark. However, package options supersede those passed via the \documentclass. For example, the option
printwatermark=true in the \documentclass options list can normally be superseded by the
Page 10 of 25
The xwatermark package
29th January 2012
56
\usepackage[printwatermark=false]{xwatermark},
and vice versa. It should, however, be noted that some package options and keys are restricted
either to the \documentclass and \usepackage (this applies to the so-called ‘option keys’) or to
the various user macros (in the case of ‘non-option keys’). Normally, the package will alert the
user to the wrong call of any of the options and keys.
If you don’t need the watermark on any page of your document, simply replace the option
printwatermark (=true) with printwatermark=false in \usepackage or \documentclass. If
you have specified printwatermark (=true) in the \documentclass options list but you still
don’t need the watermark on any page of your document, then you would have to use the tools of
subsection 3.5.
6.2 The size of the watermark
In the case of text watermarks, the size of the watermark is controlled by three parameters, namely,
fontsize, fontseries and scale. All can be set dynamically. Their default values are 5cm, b
and 1, respectively. For picture watermarks, the size is determined by picscale.
6.3 The coordinates of the watermark
The watermark coordinates (specified by xpos and ypos) have their origin at the center of the page
and are with respect to the geometric center of the watermark. The default unit is millimeter,
but this can be changed on any page by changing the value of coordunit. For example,
Examples: \newwatermark, coordunit
57
\newwatermark[other attributes,coordunit=unit of length]{}.
Acceptable units of length include mm (millimeter), cm (centimeter), in (inch), pt (point), bp (big
point), dd (didot), ex (height of small x), pc (pica), cc (cicero), and em (width of capital M).
6.4 Wrong location of the watermark
If you discover that the watermark is wrongly positioned on the page(s) of your document, as some
users have had course to complain, the chances are that you have submitted wrong coordinates
(values of xpos and ypos) to the package or the watermark’s width (textwidth or picwidth) is
not optimal or both reasons. The package does not take responsibility for this and will normally
not warn you in this respect. Since the output file provides a direct and simple indication of the
occurrence of the anomaly, no attempt has been made in the package to warn users in this regard.
If you do not specify the keys xpos and/or ypos at all in the call to \newwatermark, their default
values will be used by the package. Also, if you list these keys without their values in the call to
\newwatermark, their default values (xpos=0 and ypos=0, which yield the center of paper) will be
assumed by the package. The default value of the watermark’s width is \paperheight, and not
\paperwidth as might be expected.
When the geometry package is loaded together with the xwatermark package, page layout scale
changes by the geometry package may result in the watermarks being positioned slightly away
from the intended position. See section 9 for further details.
6.5 Wrong size of the watermark
When you discover that your text or graphics watermark is not of the size you expect, then you
Page 11 of 25
The xwatermark package
29th January 2012
should check the global and local scale and width of the watermark. It is most likely that the chosen
combination is wrong or inconsistent. Global and local package options are described in section 13.
For example, choosing scale=0.7 and width=\paperwidth may yield something unexpected. So
will mixing inconsistent global and local scales or width, or both.
6.6 Breaking the watermark into lines
It is possible to break text watermarks into lines, as in the following examples:
Example
58
59
60
61
\newwatermark[evenpages,fontfamily=ptm,angle=45,scale=.7,
align=center,color=green,xpos=0,ypos=0]{Directorate\\[.25ex]Only}
\newwatermark[allpages,fontfamily=ptm,angle=45,scale=.8,align=left,
color=green,xpos=0,ypos=0]{Control\\[.25ex]Version}.
More complex examples are available in the example source and pdf files that shipped with this
package.
6.7 The alignment of the watermark
The alignment of the watermark is controlled by the keys align, textalign and boxalign. The
first two are equivalent and may be set to center, left, right or justified. The default is
center. This is particularly useful for putting arbitrary texts (that are not necessarily watermarks)
on pages of documents. The admissible values for the key boxalign are given in Table 2.
6.8 Locating the page center
In case you need to locate the paper/page center for placing the watermark or some other material
at any position on the page, a two-line grid can be placed on the page background with the key
showpagecenter, which may be issued (dynamically for each page) with the \newwatermark macro
as follows:
Example: showpagecenter
62
63
64
65
\newwatermark[allpages,showpagecenter]{}
\newwatermark[page=1,showpagecenter=true]{}
\newwatermark[allpages,showpagecenter,fontfamily=ptm,angle=60,scale=.7,
color=brown!25!yellow!75,coordunit=cc,xpos=0,ypos=0]{Confidential!}.
If after issuing this command to get a centered grid on a page, you no longer require the grid on
the following pages, you simply issue another
Example
66
67
68
69
\newwatermark[pages=1-2,showpagecenter=false]{}
\newwatermark[page=10-\lastdocpage,showpagecenter=false,fontfamily=panr,
angle=60,scale=.7,color=brown!25!yellow!75,coordunit=cc,xpos=0,ypos=0]
{Confidential!}
Page 12 of 25
The xwatermark package
29th January 2012
6.9 The last page of the document
You can easily obtain the last page of the document with the label xwmlastpage, which is automatically provided by the package: the user doesn’t have to insert it himself. In general, you can use
the command \xwmgetpagenumber to extract page numbers from LATEX labels (even in expansion
contexts). More than one run may be necessary in extracting page numbers from this command.
The following example inserts the watermark from second to the last page to the last page. Note
that in this example the starting page is necessarily enclosed in curly braces so as to distinguish
the two hyphens that serve different purposes.
Example: \xwmgetpagenumber ,\lastdocpage
70
71
\newwatermark[pages={\lastdocpage-2}-\lastdocpage,angle=90,
scale=1,xpos=0,ypos=-1]{This is page \thepage~of~\pageref*{xwmlastpage}}
The command \lastdocpage is equivalent to \xwmgetpagenumber{xwmlastpage}.
6.10 Active characters
Active characters (i. e., those of category 13) and expandable commands can normally be used as
values of the textmark key in the \newwatermark macro. However, such values cannot be passed
via the \documentclass or the \usepackage{xwatermark} command without first loading one of
the packages: xkvltxp, kvoptions-patch and catoptions packages. That is, the following should
work:
Example
72
73
74
75
76
77
\RequirePackage{catoptions}
\documentclass[myoption={My watermark,\\[2ex]
designed~by \textsc{Mr.~J\"ohnson}}]{class-file}
\begin{document}
Blackberry lily ...
\end{document}
In plain TEX the only active character is the tie character (i. e., \nobreakspace). However,
some packages do make some other characters active. For example, after issuing the command
\MakeShortVerb{\x}, the packages doc and shortvrb make the character x activeH4 . The user
can use such active characters in values of the textmark key without locally changing their catcode
to 11 or 12. In the case of \MakeShortVerb{\x}, you can issue \DeleteShortVerb{\x} to revert
to normal use of character x. As another example, the option turkish of the babel package uses
the equal sign (=) as active shorthand character.
7
Macros for creating boxes
To make it easier for users to create paragraph boxes and color boxes of texts and watermarks,
the xwatermark package provides the macros \xwmcolorbox and \xwmminipage. The macro
\xwmcolorbox calls the macro \xwmminipage.
H4
The fancyvrb package has, e. g., \DefineShortVerb[key=value pairs]{\x}.
Page 13 of 25
The xwatermark package
29th January 2012
7.1 The \xwmminipage macro
The \xwmminipage macro is a minipage environment that may be used for framing watermarks.
It accepts verbatim material. Like the \newwatermark macro, this macro is called with key-value
pairs as follows (see Table 2 for a full listing of the available keys):
New macro: \xwmminipage
78
79
\xwmminipage[key=value list]{balanced text}
\xwmcolorbox[key=value list]{balanced text}.
The textcolor key in \xwmminipage is the color of the text. In the case of \xwmcolorbox,
four color values are expected: textcolor, fillcolor, outerframecolor and innerframecolor.
Texts with commas need to be enclosed in braces when submitted to these macros. The default
values of the keys of these macros are described in subsection 13.2.
The macros \xwmminipage and \xwmcolorbox can be nested within and among themselves, e. g.,
Example: \xwmminipage
80
81
82
83
84
85
86
87
88
89
90
\newwatermark[pagex={1,3,10},fontfamily=txtt,fontseries=m,color=red,
align=center,scale=0.7,angle=0,xpos=0,ypos=0]{%
\xwmminipage[width=\paperwidth]{%
\xwmminipage[width=\paperwidth,align=left,textcolor=magenta]
{\TeX\\[.1ex] \LaTeX}\\[1ex]
\xwmminipage[width=\paperwidth,align=center,textcolor=green]
{\TeX\\[.1ex] \LaTeX}\\[1ex]
\xwmminipage[width=\paperwidth,align=right,textcolor=orange]
{\TeX\\[.1ex] \LaTeX}%
}%
}
More complicated examples can be found in the example files. But some of the complications
found in the example files are unnecessary since several simple watermarks can be placed on the
same document page by specifying the same page number for those simple watermarks.
7.2 The \xwmcolorbox macro
The macro \xwmcolorbox provides a key-value interface to xcolor package’s \fcolorboxH5 .
New macro: \xwmcolorbox
91
\xwmcolorbox[key=value list]{balanced text}.
7.3 The \makecolorbox macro
This macro has the same syntax and options as the \xwmcolorbox macro except that the resulting
colorbox is centered by using the center environment and the markup box \makebox[0pt][c]{}.
It is intended for producing colorboxes such as the one for article abstracts. The user may
experiment with the following settings, from which the abstract of this guide was produced:
H5
The xwatermark package also comes with the macro \xwmshade which is similar to \xwmcolorbox, but which,
unlike \xwmcolorbox, can break neatly across pages (in the manner of the framed package). But since no watermark
is expected to break across pages, the macro \xwmshade isn’t described in this guide. Power users should still be
able to use it.
Page 14 of 25
The xwatermark package
29th January 2012
New macro: \makecolorbox
92
93
94
95
96
97
98
99
100
\makecolorbox[framesep=4pt,framerule=1pt,innerframecolor=red!55,
outerframecolor=ForestGreen,align=justified,
fillcolor=gray!25,width=.95\hsize,boxalign=center,
height=2.5mm,depth=0mm,framebox]{%
\centering\xwmcolorbox[align=center,fillcolor=white,
innerframecolor=blue,outerframecolor=orange,width=.5\hsize,
height=2mm]{\textbf{Abstract}}\\[\baselineskip]
The \pkg’{xwatermark} provides facilities for \ldots
}
Notice here that the macro \makecolorbox calls the macro \xwmcolorbox.
8
The \fancypagenos macro
The macro \fancypagenos, which has the following syntax, can be used to position and format
page numbers in the desired fashion. Its keys and their default values are described in Table 2.
Page numbers produced by \fancypagenos will, by default, appear in the foreground, so that they
can be seen on top of watermarks. If you want the page numbers to appear in the background,
then set sendtoback=true as one of the key-value pairs in the call to \fancypagenos.
New macro: \fancypagenos
101
\fancypagenos[key=value pairs]
Even after issuing the command \fancypagenos, you can still decide not to print the fancy
page numbers by calling the command \NoFancyPageNumbers. The complement of the command
\NoFancyPageNumbers is \FancyPageNumbers.
9
Using xwatermark with geometry package
Because the geometry package changes the scale, ratio, magnification, and other native dimensions
of the paper to get the needed layout right all the time, the geometry package may interfere with
the xwatermark package. The only layout parameter that the geometry package may retain is the
paper center, which, unfortunately, does not always coincide with the text center. In fact, even
the \paperwidth and \paperheight can be changed by the user of the geometry package.
Feasible solutions to this problem include setting the watermarks before loading the geometry
package; using the geometry package with the option pass in the preliminary runs, when setting
the watermarks (see further details below); using true dimensions (e. g., coordunit=truept); and
using relative, rather than absolute, dimension units (i. e., em and ex). The power-user can also
experiment with the primitives \magnification, \mag and \magstep.
The pass option of the geometry package has been available from version 4.2 of the geometry
package onwards. It disables auto-layout and all of the geometry package settings except verbose
and showframe. It can be used to determine the page layout of the \documentclass and layouts
created by other packages and manual settings. The user can also employ the option showframe of
the geometry package to view how the scaling factors used by the geometry package might change
native layout dimensions. The option reset of the geometry package is also useful in this regard.
The geometry package saves native (LA)TEX dimensions and switches in the macro \[email protected] before
processing geometry package options. This macro is called by geometry when the options pass
and reset are passed to it. Reconciling the two packages (xwatermark, geometry) at a ‘high
Page 15 of 25
The xwatermark package
29th January 2012
level’ will involve simply calling this macro within the xwatermark package whenever xwatermark
detects that the geometry package has been loaded by the user. This is what has been done in the
xwatermark package: the package has a boolean option called disablegeometry, which, if true,
invokes the command \[email protected] of the geometry package to disable geometry package settings
and enforce native paper layout dimensions. First the xwatermark package detects at the very
last moment of the document preamble (just before \begin{document}) if the geometry package
has been loaded by the user. If yes, and if the user has suggested disablegeometry=true in the
call to xwatermark, then xwatermark issues the command \geometry{pass}, which, as mentioned
earlier, calls \[email protected]
After the effects of the geometry package are re-introduced (i. e., after setting the xwatermark
package option disablegeometry=false), it might still be necessary, depending on the user need,
to fine-tune the positions of the watermarks.
Because the geometry package stipulates that the command \[email protected] can be issued only in the
document preamble, the switch disablegeometry can appear as option only in \documentclass or
\usepackage{xwatermark}. But it matters not which of the two packages (geometry, xwatermark)
is loaded first. To call \[email protected], the xwatermark package uses the hook \BeforeStartOfDocument
from the catoptions package. \AtBeginDocument, a native LATEX hook, is inapplicable in this
case.
10
Support for unicode and utf encodings
The xwatermark package can be used with any font encoding, provided the fontfamily is properly
declared before use. For example, with the following declarations on XETEX, Rembrandt Wolpert
([email protected]) obtained some .pdf outputs that he is willing to share with other users:
Example: \newfontfamily
102
103
104
105
\newfontfamily{\chinese}{STFangsong} % SinoType FangSong
\newcommand{\chtext}[1]{{\chinese \XeTeXlinebreaklocale "jp"
\XeTeXlinebreakskip=0pt plus 1pt #1}%
}
108
\newwatermark[allpages,fontsize=5cm,align=center,
color=red!75!blue!25,angle=90,xpos=-65,ypos=-38,scale=.49]
{=\fbox{\color{red!65}\chtext{watermark in Chinese or Japanese script}}=}
109
\newfontfamily{\Gara}{Garamond Premier Pro}
106
107
110
111
112
\newwatermark[allpages,fontsize=5cm,scale=.46,align=center,
angle=90,color=red!75!blue!25,xpos=-72,ypos=-38]
{=\fbox{\color{red!65}\Gara The different ligature}=\\[.35ex]}.
It doesn’t matter what the user declares as a fontfamily provided he/she declares it before using
it and provided the declaration is valid. It is thus possible to mix scripts in one watermark (e. g.,
Latin, Chinese, Korean, Japanese, Arabic, Russian scripts, you name it).
11
Repeated graphics in a document
For graphics watermarks, the watermark image, or any other image that is repeated in the document, has the potential to make the processed version of the document surprisingly large. The
Page 16 of 25
The xwatermark package
29th January 2012
problem is that the default mechanisms of graphics usage add the image at every point it is to be
used, and when processed, the image appears in the output file at each such point.
See the uktug fag, version 3.20 (2010), entry number 146, page 95, for the available solutions to
this problem. As described by this reference, if the PostScript version of the file is destined for
conversion to pdf, either by a ghostscript-based mechanism such as ps2pdf or by, for example,
Acrobat Distiller, the issue is not as important, since the distillation mechanism will amalgamate
graphics objects whether or not the PostScript has them amalgamated. pdfTEX does the same
job with graphics, automatically converting multiple insertions into pointers to graphics objects.
12
Further examples of use of xwatermark package
The files xwatermark-examples1.tex and xwatermark-examples2.tex, source files of examples
of use of the xwatermark package together with their pdf versions, are provided with this guide
in the xwatermark bundle.
13
Package options and macro keys
We categorize the package options and keys into global and local. Global options are those set
either in \documentclass or in \usepackage, while local options are those set with the macros
\newwatermark, \newwallpaper, \xwmminipage, \xwmcolorbox and \makecolorbox.
13.1 Global options
The global package options are listed and described in the following Table 1.
Table 1: Global options of the package
All the keys in this table are ‘option keys’, i. e., they can appear only in \documentclass or
\usepackage. If a key is an option key and it is issued in functions other than \documentclass
or \usepackage, the package will alert the user to that effect.
Option
defaultfirstpage,
default-first-page
defaultlastpage,
default-last-page
Default
1
1
Meaning
The default first page of document, when the first
page hasn’t been known yet.
The default last page of document, when the last
page has’t been shipped out yet.
draft
false
The document is in draft mode.See note 1.1
final
true
disablegeometry,
disable-geometry
false
The document is in final mode.
This option determines whether the page layout
settings by the geometry package should be disabled so that the watermarks can be set more
The style of the front page, in the sense of the
fancyhdr package.
The boolean that determines if picture watermark
is placed on top of text watermark or otherwise,
when they occur at the same location on a page.
The global boolean switch that determines
whether watermarks should be printed or not.1.3
Continued on next page
frontpagestyle,
front-page-style
picontoptext,
pic-on-top-text,
picture-on-top-text
printwatermark,
print-watermark
empty
true
true
Page 17 of 25
The xwatermark package
29th January 2012
Continued from last page
Option
Default
resetpaperorigin,
reset-paper-origin
false
showpagecenter,
show-page-center
textontoppic,
text-on-top-pic,
text-on-top-picture
Meaning
The boolean to call to reset the paper origin (\pdfhorigin, \pdfvorigin, \hoffset and
\voffset) to zero unit.
Boolean that indicates if the center of the paper
should be shown with a cross (and circle).1.4
false
The reverse of picontoptext.
false
usedummymarks,
use-dummy-marks
true
watermarkparser,
watermark-parser
; (semicolon)
The boolean that instructs xwatermark to print
watermarks that have been defined by the
\dummywatermark or \dummywallpaper in addition to those defined by \newwatermark and/or
\newwallpaper.
The option determines the watermark parser, a
quantity that is used internally to build watermarks into lists.1.5
Table 1 notes
1.1 draft and final are complementary (biboolean) options, i. e., when one is true, the other is automatically set to false.
1.2 Version 5.6 and higher of the geometry package make this option less likely to be needed, unlike the
earlier versions of geometry.
1.3
This option can be passed to package as either true or false and can appear in the \documentclass
options list or \usepackage. If for any reason you don’t want the watermark printed in any run,
you can enter printwatermark=false. If the option draft or final appears in the \documentclass
or \usepackage, it won’t affect the printing or otherwise of the watermark, apart from determining if
graphics watermarks are actually inserted instead of framed empty boxes. The printing of the watermark
is determined by the option printwatermark.
1.4
The xwmgrid package, which provides a full gridding functionality consistent with the xwatermark
package, will be released shortly.
1.5
If you do have the watermarkparser in your watermark, it must be enclosed in curly braces, otherwise
the package will flag a fatal error. You can change the watermarkparser to say ‘|’ (vertical bar), in case
you have too many ‘;’ (semicolons) in your watermarks and you are fed up with enclosing them in braces.
13.2 Local options
Local package options are those associated with the commands \newwatermark, \newwallpaper,
\xwmminipage, \xwmcolorbox, \makecolorbox and \fancypagenos. They are described in the
following Table 2.
Table 2: Local (function-dependent) options of the package
Most of the keys in this table are ‘non-option keys’, i. e., they can’t appear in \documentclass or
\usepackage but in the arguments of the given functions. If a key is a non-option key and the user
submits it to \documentclass or \usepackage, the package will alert the user.
Option
Default
Meaning
\newwatermark macro
angle, textangle,
text-angle
0◦
The orientation of text watermark.
Continued on next page
Page 18 of 25
The xwatermark package
29th January 2012
Continued from last page
Option
align, textalign,
text-align
page, pages, pagex,
firstpage, lastpage,
allpages, evenpages,
oddpages
boxalign, box-align
coordunit, coord-unit,
position-unit
color, textcolor,
text-color
Default
Meaning
The internal horizontal alignment of the watermark within a watermark box.See note 2.1
center
These determine the pages on which the watermarks are to be printed.2.2
center/s
The alignment of the watermark box.2.3
mm
The unit for x- and y-coordinates of watermark.
gray!25
The color of the text watermark.
This option will insert framed empty boxes in
place of graphics watermarks.
The color of the box that is printed in place of
graphics watermarks in draft document mode.
This option actually does nothing for now. It is
included for possible future application.
draft
false
draftboxcolor,
draft-box-color
blue
final
false
fontfamily
bch
The fontfamily of the text watermark.
fontsize
1cm
The fontsize of the text watermark.2.4
fontseries
b
The font series of the text watermark.2.5
the command \includegraphics.2.6
\paperwidth
The height of text watermarks.
graphicsoptions
height, textheight,
text-height
mark, textmark, text-mark
DRAFT
The default text watermark.
picscale, picture-scale
picbb, picture-bb,
pic-bounding-box
1
Scale of picture watermark.
The bounding box (dvi mode) or viewport (pdf
mode) of the picture watermark.
0 0 100 100
picfile, picture-file
picfileext, pic-file-ext
eps/pdf
picheight, pic-height,
picture-height
picangle, picture-angle
The height of picture watermarks.
0◦
picwidth, picture-width
picontoptext,
picture-on-top-text
picxpos, picture-xpos,
picture-x-position
picypos, picture-ypos,
picture-y-position
scale, textscale,
text-scale
showpagecenter,
show-page-center,
showpapercenter
The filename of picture watermark.2.7
The filename extension of the picture watermark.2.8
true
0
0
1
false
The orientation of picture watermarks.
The width of picture watermarks.
Pictures should be placed on top of text watermarks if the two types of watermark occur on
the same spot on a page.
The horizontal coordinate of the picture watermarks.
The horizontal coordinate of the picture watermarks.
The scale of the text watermark.
Boolean for requesting the indication of the center of the paper. See xwmgrids package for additional information.
Continued on next page
Page 19 of 25
The xwatermark package
29th January 2012
Continued from last page
Option
Default
textontoppic,
text-on-top-pic,
text-on-top-picture
false
width, textwidth,
text-width
\paperheight
xpos, textxpos, text-xpos,
text-x-position
0
ypos, textypos, text-ypos,
text-y-position
0
align, textalign,
text-align
\newwallpaper macro2.11
The internal horizontal alignment of the watercenter
mark within a watermark box.2.12
The horizontal and vertical alignments of the
center (s)
watermark box.2.13
boxalign, box-align
Meaning
Text watermarks should be placed on top of
graphics watermarks if the two types of watermark occur on the same spot on a page. This
reverses the boolean picontoptext.
The width of text watermarks; doesn’t apply to
graphics watermarks.2.9
These specify the horizontal coordinate of watermark (with reference to the center of paper,
and not the text center).2.10
The vertical coordinate of the watermark.
picheight,
picture-height
.25\paperheight
The height of each cell of picture wallpaper.
picwidth, picture-width
.25\paperwidth
The width of each cell of picture wallpaper.
tilexsize, tile-xsize
.25\paperwidth
The width of each cell of tiled wallpaper.
tileysize, tile-ysize
.25\paperheight
The height of each cell of tiled wallpaper.
textheight, text-height
.25\paperheight
The height of each cell of text wallpaper.
textwidth, text-width
tilexoffset,
tile-xoffset
tileyoffset,
tile-yoffset
.25\paperwidth
The width of each cell of text wallpaper.
The horizontal shift between the tiles of wallpaper.
tileno, tilenumber,
tile-number,
number-of-tiles
squaretiles,
square-tiles
wpxoffset,
wallpaper-xoffset
wpyoffset,
wallpaper-yoffset
0pt
0pt
The vertical shift between the tiles of wallpaper.
The maximum number of cells for tiled
wallpapers if the parameters tilexsize and
4
tileysize aren’t specified or if the boolean
squaretiles is true.2.14
The boolean that determines if the tiles should
true
be rectangular or square.2.15
The horizontal offset of wallpaper from the mar0pt
gin or edge of paper.
The vertical offset of wallpaper from the margin
0pt
or edge of paper.
\xwmminipage macro2.16
depth
0ex
Additional depth of the boxed minipage.
height
framebox, insertframe,
insert-frame
.5\textheight
Additional height of the boxed minipage.
The boolean that determines whether the box
is framed or not.
true
framesep
3pt
\fboxsep of the boxed minipage.
framerule
0.4pt
\fboxrule of the boxed minipage.
textwidth
\paperwidth
Width of the boxed minipage.
textcolor
black
Color of text inside boxed minipage.
Continued on next page
Page 20 of 25
The xwatermark package
29th January 2012
Continued from last page
Option
Default
framecolor
white
textalign, text-align
Meaning
Color of frame of boxed minipage.
Alignment of the text inside the boxed minipage
center
of the command \xwmminipage (expected values
are center, left, right and justified).
\xwmcolorbox macro
depth
framebox, insertframe,
insert-frame
0ex
The boolean that determines whether the box
is framed or not.
framesep
3pt
\fboxsep of the colorbox.
framerule
0.4pt
\fboxrule of the colorbox.
height
innerframecolor,
inner-frame-color
outerframecolor,
outer-frame-color
0ex
white
Color of the inner frame of colorbox.
white
Color of the outer frame of colorbox.
textcolor
black
textalign, text-align
center
Color of text inside colorbox.
Alignment of the text inside the colorbox of
\xwmcolorbox (expected values are center,
left, right and justified).
true
\paperwidth
Width of the colorbox.
\makecolorbox macro
The options of the macro \makecolorbox are the same as those of the related macro \xwmcolorbox.
Please refer to subsection 7.3 for the syntaxes of these macros.
\fancypagenos macro
cfoot, center-footer,
Center footer.2.17
footer-center
width
\fbox
The desired format of the fancy-page numbers.
mm
The units of the position/coordinates x and y.
fontfamily
cmss
The fontfamily of the fancy-page numbers.
fontsize
5cm
The fontsize of the fancy-page numbers.
fontseries
b
The font series of the fancy-page numbers.
footrule-height
.4pt
Foot rule height.
footrule-depth
.4pt
Foot rule depth.
footrule-width
footrule-sep,
footrule-separation
Foot rule width.
Foot rule vertical separation (i. e., the vertical
separation between the two lines.
format
coordunit, coord-unit,
position-unit
2pt
footrule-color
cyan
Foot rule color.
Left \hfoffset (see fancyhdr for the meaning
of \hfoffset).
hfoffset-left
.5
hfoffset-right
.5
Right \hfoffset (see fancyhdr).
.4pt
.4pt
Continued on next page
Page 21 of 25
The xwatermark package
29th January 2012
Continued from last page
Option
Default
Meaning
Head rule separation (i. e., the vertical separation between the two lines.
2pt
lfoot, left-footer,
footer-left
blue
style, printstyle
\thepage
rfoot, right-footer,
footer-right
showpagenos, show-pageno,
show-pagenos,
show-page-numbers
showonpageone,
show-on-page-one
showfootrule,
show-footrule
Left footer.
The presentation style of the fancy-page numbers.
Right footer.
true
false
true
true
sendtoback
true
align, textalign,
text-align
center
boxalign, box-align
center
color, textcolor,
text-color
scale, textscale,
text-scale
angle, textangle,
text-angle
width, textwidth,
text-width
height, textheight,
text-height
xpos, textxpos,
x-position
ypos, textypos,
y-position
Boolean that determines if fancy-page numbers
should be shown.
Boolean that determines if fancy-page numbers
should be shown on the first page of the document.
Boolean that determines if the headrule should
be shown.
Boolean that determines if the footrule should
be shown.
Boolean that determines if the fancy-page numbers should be placed in the background or foreground.
The alignment of the text in the fancy-page
number box (if it is boxed).
The alignment of the fancy-page number box (if
it is boxed).
blue
The color of the fancy-page numbers.
2.5
The scale of the fancy-page numbers.
0
The orientation of the fancy-page numbers.
0ex
Width of the fancy-page numbers.
0ex
Height of the fancy-page numbers.
0
0
The horizontal coordinates of the fancy-page
numbers (from page center).
The vertical coordinates of the fancy-page numbers (from page center).
Table 2 notes
2.1 The key can assume only one of the values center, left, right and justified. Any other text
alignment value is inadmissible and thus rejected by the package with a fatal error.
Page 22 of 25
The xwatermark package
29th January 2012
2.2 The options allpages, evenpages, oddpages are boolean keys, while page, pages and pagex require
values, e. g., page=x, pages=x-y and pagex={x,y,z}. If the package is loaded and none of these options is
passed to it, but the option printwatermark is true, the default watermark (DRAFT) will be printed on
the first page of the document (but only in draft mode) and a warning message logged in the transcript
file. The key pages expects a page range with the pages separated by a hyphen, while pagex expects a
list of pages that will receive the watermarks.
2.3
Both text and picture watermarks are normally put in boxes for manipulation before being typeset.
This key refers to the horizontal and vertical alignments of the box. The key can assume one of the
values t-l, t-r, b-l, b-r, s, or top-left, top-right, bottom-left, bottom-right, center, justified.
Elements of these two sets can’t be combined. When submitted as key values, the elements of both sets
are not to be separated by commas or spaces but by hyphens (e. g., one of t-l, t-r, b-l, b-r, s, or one
of top-left, top-right, bottom-left, bottom-right, center, justified).
2.4
If for some reason you need other fontsizes (e. g., 10pt, 11pt or 12pt for printing text watermarks in
\normalfont), you will need to submit them as values of fontsize.
2.5
If you need normal document text, put fontseries=m, which implies medium weight and width.
2.6
The command \includegraphics is used for all graphics inclusion tasks. Users can directly pass
values to admissible options of the command \includegraphics. See subsection 5.1.
2.7
This, with its full path, must be submitted when including picture watermark.
2.8 Valid extensions are eps, pdf, png, jpeg, mps; the latter four may be used in the case of pdfT X.
E
The file extension should be passed without the dot. If the option is not passed to package, xwatermark
selects eps (in dvi mode) or pdf (in pdfTEX mode).
2.9
For some design reasons we set \paperheight as the default value of mark’s width instead of mark’s
height.
2.10 There
is no need to attach a unit to xpos or ypos; if the user does, the unit will be used in place of
coordunit.
2.11 Some
of the \newwatermark keys can also be called when inserting wallpapers. If you aren’t sure if a
key is applicable, don’t worry: just try it. The package collects all inadmissible keys together and prints
them in the transcript file on each run. Normally, the user is alerted by an error message. Indeed if you
receive any failed compilation, you should first suspect that the failure is due to the use of an invalid key.
The next keys apply specifically to wallpaper watermarks.
2.12 The
key can assume only one of the values center, left, right and justified.
2.13 The
key can assume one of the values t-l, t-r, b-l, b-r, s, or top-left, top-right, bottom-left,
bottom-right, center, justified. When submitted as key values, the elements are not to be separated
by commas or spaces but by hyphens (e. g., one of t-l, t-r, b-l, b-r, s, or one of top-left, top-right,
bottom-left, bottom-right, center, justified).
2.14 If
tilexsize and tileysize are given and squaretiles is false, tileno is ignored.
2.15 Sometimes
choosing squaretiles (i. e., setting it true) can yield an undesired outcome if textalign
and boxalign haven’t been properly selected. In such a situation, the user is advised to first experiment
with setting squaretiles to false and/or textalign and boxalign to center.
2.16 The
\xwmminipage command can take verbatim material and provides a hkeyi=hvaluei alternative
to the \boxedminipage command of the boxedminipage package.
2.17 All
headers and footers are as in fancyhdr package.
14
Version history
The following change history highlights significant changes that affect user utilities and interfaces;
changes of technical nature are not documented in this section. The star sign (?) on the right-hand
side of the following lists means the subject features in the package but is not reflected anywhere
in this user guide.
Version 1.5.2a[2012/02/01]
New command \[email protected] introduced . . . . . . . . . . . . . . . . . . . .
Page 23 of 25
?
The xwatermark package
29th January 2012
Version 1.5.2[2011/10/20]
To match changes in ltxkeys package
. . . . . . . . . . . . . . . . . . . . . . . . . . . . .
?
Version 1.5.1[2011/07/20]
Following user request, two new keys were introduced for the macro \fancypagenos .
section 8
Version 1.5.0[2011/07/10]
Introduced the ltxkeys package, a highly robust and optimized module for general creation and
management of keys . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
?
Provisions for placing more than one watermark on the same page.
. . . . . . . . . .
section 3
Introduced wallpaper functionalities . . . . . . . . . . . . . . . . . . . . . . . . . . . .
section 4
Adaptable and flexible fancy page numbers . . . . . . . . . . . . . . . . . . . . . . . .
section 8
Page 24 of 25
The xwatermark package
29th January 2012
Index
Index numbers refer to page numbers.
D
\DiscardAllWatermarks . . . . . . . . . . . . . . . . . . . . . . . 4, 8
\DiscardDummyWatermarks . . . . . . . . . . . . . . . . . . . . 4, 8
\dummywallpaper . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
\dummywatermark . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4, 8
F
\fancypagenos . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
\FancyPageNumbers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
xwatermark-examples1.tex . . . . . . . . . . . . . . . . 17
xwatermark-examples2.tex . . . . . . . . . . . . . . . . 17
G
\GraphicsOptions . . . . . . . . . . . . . . . . . . . . . . . . . . . 9, 10
graphicsoptions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5, 9
I
\includegraphics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
L
\lastdocpage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
M
\makecolorbox . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
N
\newfontfamily . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
\newwallpaper . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
\newwatermark . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
\NoFancyPageNumbers . . . . . . . . . . . . . . . . . . . . . . . . . . 15
P
Packages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
babel . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
boxedminipage . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
catoptions . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13, 16
doc . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
draftcopy . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1, 2
draftmark . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1, 2
draftwatermark . . . . . . . . . . . . . . . . . . . . . . . . . . 1, 2
fancyhdr . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
fancyvrb . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
framed. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .14
geometry . . . . . . . . . . . . . . . . . . . . . . . . . 2, 11, 15–18
graphics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
graphicx . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
kvoptions-patch . . . . . . . . . . . . . . . . . . . . . . . . . . 13
ltxkeys . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3, 24
shortvrb . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
wallpaper . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1, 2
watermark . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1, 2
xcolor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3, 14
xkvltxp . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
xwatermark . . . . . . . . . . . . . . 1–3, 9–11, 13–18, 23
xwmgrid . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
S
Size of the watermark . . . . . . . . . . . . . . . . . . . . . . . . 11
U
\UseDummyWatermarks . . . . . . . . . . . . . . . . . . . . . . . . . 4, 8
W
\watermarkpaths . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
X
\xwmcolorbox . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
\xwmgetpagenumber . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
\xwmminipage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
Page 25 of 25


text:
# TPS2113A Power Multiplexer Carrier with USB Micro-B Connector

 Pololu item #: 2596 156 in stock

Price break Unit price (US\$)
1 4.95
5 4.25
25 3.75
100 3.49

 Quantity: backorders allowed

This breakout board for Texas Instruments’s TPS2113A autoswitching power multiplexer allows you to select which of two power sources is connected to a load while blocking reverse current into either of the sources. It has an adjustable current limit that can be set as high as 2 A and an adjustable switching threshold. Each input power rail on the multiplexer can be supplied with 2.8 V to 5.5 V, and the board also breaks out a USB Micro-B connector that can be used to supply one of the rails.

## Overview

The Texas Instruments TPS2113A autoswitching power multiplexer allows you to switch seamlessly between two power sources of 2.8 V to 5.5 V while blocking reverse current into either source. The power multiplexer (or mux) has an adjustable current limit that can be set as high as 2 A and an adjustable switching threshold that helps reduce output voltage droop when switching. Each input channel is controlled by an internal MOSFET switch, so the mux avoids the voltage drop that occurs when diodes are used to OR multiple power supplies together.

The TPS2113A makes a great addition to any project that needs to be able to transition between two sources like USB and external power, but its small size makes it difficult for a student or hobbyist to use. This carrier breaks out all of the chip’s features to 0.1″-spaced pins, making it easy to use with standard solderless breadboards. In addition, the board serves as a breakout for a USB Micro-B connector that can be used to supply one of the input power rails.

By default, the TPS2113A operates in autoswitching mode, which means that it will automatically select the source that has a higher voltage, but the VSNS pin can be used to maintain IN1 as the selected source until it falls below a configurable switching threshold, making IN1 the primary or preferred source. The board ships with USB power connected to IN1, which enables the common application of having a device that can be powered by USB or an external power supply, automatically choosing the appropriate source based on what is connected. USB power can be switched from IN1 to IN2 by cutting a trace and configuring a surface-mount jumper.

Since this board is a carrier for the TPS2113A, we recommend careful reading of the TPS2113A datasheet (1MB pdf).

We carry a similar power multiplexer based on the FPF1320 that is smaller, lower-cost, and works at lower voltages, but it has some limitations that make it not as well suited for automatic USB power-switching applications (e.g. the output voltage can drop to 1 V before the FPF1320 switches to the secondary source).

## Using the power multiplexer

### Pinout

Pin Description
IN1 Primary power switch input. Can be connected to a 2.8 V to 5.5 V power source. Connected to VBUS by default through surface-mount jumper. The multiplexer will function with IN1 as low as 1.5V as long as IN2 is above 2.8 V.
IN2 Secondary power switch input. Can be connected to a 2.8 V to 5.5 V power source.
VBUS USB 5 V supply. Connected to IN1 by default through surface-mount jumper.
OUT Multiplexed power output.
GND Common ground for power supplies, load, and USB. (All of the board’s GND pins are internally connected with each other and with GND from the USB connector.)
VSNS Switching control input. An internal power FET connects OUT to IN1 if the VSNS voltage is greater than 0.8 V. Otherwise, the FET connects OUT to the higher of IN1 and IN2. This pin is pulled low through an on-board 20 kΩ pull-down resistor, setting the board to autoswitching mode by default. See the Control inputs section below for more details on using this pin to set a switching threshold.
EN Enable input. When driven high, OUT is disconnected from both IN1 and IN2. This pin is pulled low through an on-board 100 kΩ pull-down resistor so the IC is enabled by default.
ILIM Current limit input. An on-board 1 kΩ resistor from ILIM to GND sets the default current limit to 0.5 A nominally, but an external resistor can be added in parallel with it to increase the limit to a maximum of 2 A.
STAT Status output that indicates which input is currently connected to the output. This pin drives low when IN1 is selected and is pulled up to OUT through an on-board 100 kΩ pull-up resistor when IN2 is selected.
D−
D+
ID
Signals broken out from USB connector.

### Control inputs

The TPS2113A has three control inputs that can optionally be used to override the default behavior of the device: VSNS (switching operation control), EN (enable), and ILIM (current limit control).

The VSNS pin determines the switching behavior of the device. It is pulled low by default, which results in autoswitching mode (the higher of the two input sources is automatically selected). However, when the voltage on this pin exceeds 0.8 V, the primary input source, IN1, is connected to OUT regardless of the voltages on IN1 and IN2. The precise nature of this 0.8 V threshold in turn makes it possible to use an external resistor to set a desired switching threshold for IN1. By connecting this external resistor between VSNS and IN1, a voltage divider is created with the existing 20 kΩ VSNS pull-down resistor, and the board will select IN1 as long as the output of this voltage divider is greater than 0.8 V. (If it drops below the 0.8 V threshold, the multiplexer reverts to selecting the higher of the two sources.) The value of the added resistor determines the voltage at which the behavior of the multiplexer changes, as defined by the following equation:

V_text(threshold) = (R/(20\ text(kΩ)) + 1) * 0.8\ text(V)

The board has a second IN1 pin so that there is a convenient place to connect this switching threshold resistor. For 5 V applications, adding a 100 kΩ resistor works well, since that sets the threshold to 4.8 V. The VSNS input has built-in hysteresis which helps prevent repeated switching from one source to the other.

The EN pin can be driven high to turn off the output and put the TPS2113A in a low-power state. The board is enabled by default.

The ILIM pin is used to set the multiplexer’s current limit by comparing the voltage across a resistor with an internal 0.5V reference. The board includes a 1 kΩ resistor that sets the default current limit to a nominal 0.5 A, but an external resistor can be connected between the ILIM pin and GND to increase the limit to a maximum of 2 A. Such a resistor can conveniently be connected between the ILIM pin and the neighboring GND pin. The following equation shows how the value of the external resistor determines the current limit:

I_text(limit) = ((1\ text(kΩ))/R + 1) * 0.5\ text(A)

We can see from this that the 2 A maximum current limit can be achieved by adding a 330 Ω resistor. (Note that the actual current limiting threshold can vary by up to about 0.3 A from the nominal limit; see the datasheet for details.)

### Power connections without USB

If you want to select from between two general power supplies, you can connect one power source across IN1 and GND and the other across IN2 and GND. The voltages on these power inputs can be up to 5.5 V, and the multiplexer will function with IN1 as low as 1.5V as long as IN2 is above 2.8 V. The load should be connected across OUT and GND and should draw no more than 2 A. In this configuration, the power supply connected to IN1 is the primary power source if VSNS is high.

### Power connections with USB

The Micro-B USB connector makes it easy to use USB as one of the two power sources. By default, the VBUS line from the USB connector is tied to IN1. This allows you to power your circuit from either USB or an external power source connected to IN2, with USB as the primary power source if VSNS is high.

If you want the external source to be the primary source instead of USB, you can use a hobby knife to cut the trace in the board’s surface-mount jumper that connects the IN1 and VBUS pads, then bridge the VBUS and IN2 pads to connect those two lines together. You can then connect your external source to IN1, making it the preferred supply if VSNS is high.

Warning: It is important to be aware that while this board has three power inputs, two of those three are typically tied together (there are only two independent power inputs to the TPS2113A). As such, you must take care to avoid creating a short circuit between USB power and an external power supply. For example, when the board is in its default configuration (i.e. with VBUS tied to IN1), any external power supply must be connected to IN2; connecting it to IN1 will create a short between this power supply and USB power when USB is connected.

The remaining lines from the USB connector (D−, D+, ID, and GND) are broken out to a set of pins adjacent to OUT, allowing this module to also function as a basic USB Micro-B connector breakout board.

### Included hardware

The included 1×15 strip of 0.1″ header pins can be broken into smaller pieces and soldered in to use the board with perfboards, breadboards, or 0.1″ female connectors. The board has two mounting holes that work with #2 and M2 screws (not included).

### Schematic diagram

This schematic is also available as a downloadable PDF (171k pdf).

### People often buy this product together with:

(702) 262-6648
Same-day shipping, worldwide
My account Comments or questions? About Pololu Contact Ordering information Distributors

format: plain


text:
# Mathematical Conundrum!

This topic is 2975 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hey all,

I am trying to code collision with a tile map.

The problem I have is that the tile map is by array location, but player movement is by pixel.

I need a way to make this calculation to determine whether a tile is passable (array location value 0).

bool tilePassable(){  if(map[guyPosX / 32][guyPosY / 32] == 0)   {     return true;   }  else   {     return false;   }}

The problem I have is that naturally the precise pixel the character is sitting on will not necessarily be a multiple of 32, so I will end up with a decimal resule when I divide its location by 32.

Is there a way to make this calculation to the nearest whole number, ie ignoring any remainder, so that, for example 100 / 32 = 3 (ignoring the remaining 4).

Is there a way to make this calculation in code?

Thanks

[Edited by - Zahlman on August 31, 2010 4:08:40 PM]

##### Share on other sites
If guyPosX and guyPosY are integers, chances are what you have will work fine.

##### Share on other sites
Yes, they are integers.

Wont I get an error saying I'm converting from an integer to a double if I do it though?

##### Share on other sites
No, what you are doing is called integer division. Your operands guyPosX and 32 are both integers.

##### Share on other sites
Ok thanks!

Tried it and it works ok :)

##### Share on other sites
Quote:
 Original post by kutuupIs there a way to make this calculation to the nearest whole number, ie ignoring any remainder, so that, for example 100 / 32 = 3 (ignoring the remaining 4).

Though in this case it isn't needed since you're using integers, you could use the floor function.

##### Share on other sites
While we're at it, let's simplify.

"If it is raining outside, I will take my umbrella with me; otherwise, I will not take my umbrella with me."

Ugh. Wordy, and not actually making things clearer.

"I will take my umbrella with me if (and only if) it is raining".

Much better.

Thus:

bool tilePassable(){  return map[guyPosX / 32][guyPosY / 32] == 0;}

##### Share on other sites
The problem with this approach, as I learned a few days ago coding my tile engine, is that if the player's sprite isn't the same dimensions as the tiles, then you'll collide with a lot of "air". If the pos of your sprite is based on the top left pixel, then checking collision on the top and left will be perfect but on the right and bottom will not.

I'm sure there are a million ways around this, however I just include 3 small arrays (mine are vectors but you could use what ever you want). One for the xpos for collidable tiles, one for the ypos of collidable tiles, and one for the type of collidable tile (==1 for collidable on all sides, ==2 if it damages you, etc etc.) Then you can make a more precise collision check based off of x/y coord instead of tile spots. This also stops you from cycling through a large map and only cycle through known collidable spots. The array is filled when the level is made by deciding what tiles are collidable, multiplying their index by the tile size, and adding that number to the array.

1. 1
Rutin
46
2. 2
3. 3
4. 4
5. 5
JoeJ
19

• 11
• 15
• 9
• 10
• 13
• ### Forum Statistics

• Total Topics
633004
• Total Posts
3009840
• ### Who's Online (See full list)

There are no registered users currently online

×