Eso Pic
Eso Pic
Rolf Niepraschk
[email protected]
1 Introduction
This package makes it easy to add some picture commands to every page at ab-
solute positions.
2 Usage
See also the example LATEX documents (eso-*.tex).
1
\AtPageUpperLeft Helper macros for easier positioning on the page.
\AtPageLowerLeft
\AtPageCenter 2.2 Package options
\AtTextUpperLeft
\AtTextLowerLeft Option Value Comments
\AtTextCenter pscoord empty or true, false The zero point of the coordinate system
\AtStockUpperLeft is the lower left corner of the page (the
\AtStockLowerLeft default).
\AtStockCenter texcoord empty or true, false The zero point of the coordinate system
is the upper left corner of the page.
grid empty or true, false A grid is drawing; default: false.
gridunit mm, in, bp, pt Distance between gridlines are multiples
of gridunit. default: mm.
gridcolor a valid color name Color of the main gridlines; default:
black
subgridcolor a valid color name Color of the subgridlines; default: black.
subgridstyle solid or dotted ‘dotted’ is very slow! default: solid.
colorgrid empty or true, false Shortcut for ‘grid=true’, ‘gridcolor=red’
and ‘subgridcolor=green’; default: false.
dvips empty or true, false Is also true if the package option dvips is
used by color or graphics. If true package
eepic is loaded for better performance of
dotted lines.
3 Implementation
3.1 The main functionality
1 \RequirePackage{atbegshi}
\LenToUnit
2 \providecommand*\LenToUnit[1]{#1\@gobble}
\AtPageUpperLeft
5\newcommand\AtPageUpperLeft[1]{%
6 \put(0,\LenToUnit{-\ESO@yoffsetI}){#1}%
7}
\AtPageLowerLeft
8 \newcommand\AtPageLowerLeft[1]{\AtPageUpperLeft{%
9 \put(0,\LenToUnit{-\paperheight}){#1}}}
\AtPageCenter
10 \newcommand\AtPageCenter[1]{\AtPageUpperLeft{%
11 \put(\LenToUnit{.5\paperwidth},\LenToUnit{-.5\paperheight}){#1}}%
12 }
2
\AtStockLowerLeft
13 \newcommand\AtStockLowerLeft{}
14 \ESO@isMEMOIR{%
15 \renewcommand\AtStockLowerLeft[1]{%
16 \begingroup
17 \@tempdima=-\stockwidth
18 \advance\@tempdima\trimedge
19 \advance\@tempdima\paperwidth
20 \if@twoside\ifodd\c@page\else
21 \@tempdima=-\trimedge
22 \fi\fi
23 \@tempdimb=-\stockheight
24 \advance\@tempdimb\paperheight
25 \advance\@tempdimb\trimtop
26 \AtPageLowerLeft{%
27 \put(\LenToUnit{\@tempdima},\LenToUnit{\@tempdimb}){#1}%
28 }%
29 \endgroup
30 }
31 }{%
32 \let\AtStockLowerLeft=\AtPageLowerLeft
33 }
\AtStockUpperLeft
34 \newcommand\AtStockUpperLeft{}
35 \ESO@isMEMOIR{%
36 \renewcommand\AtStockUpperLeft[1]{%
37 \AtStockLowerLeft{%
38 \put(0,\LenToUnit{\stockheight}){#1}%
39 }%
40 }%
41 }{%
42 \let\AtStockUpperLeft=\AtPageUpperLeft
43 }
\AtStockCenter
44 \newcommand\AtStockCenter{}
45 \ESO@isMEMOIR{%
46 \renewcommand\AtStockCenter[1]{%
47 \AtStockLowerLeft{%
48 \put(\LenToUnit{.5\stockwidth},\LenToUnit{.5\stockheight}){#1}%
49 }%
50 }%
51 }{%
52 \let\AtStockCenter=\AtPageCenter
53 }
\AtTextUpperLeft
54 \ESO@isMEMOIR{%
55 \newcommand\AtTextUpperLeft[1]{%
56 \begingroup
57 \ifodd\c@page
58 \@tempdima=\spinemargin
59 \else
3
60 \@tempdima=\paperwidth
61 \advance\@tempdima-\textwidth
62 \advance\@tempdima-\spinemargin
63 \fi
64 \@tempdimb=-\uppermargin
65 \AtPageUpperLeft{%
66 \put(\LenToUnit{\@tempdima},\LenToUnit{\@tempdimb}){#1}%
67 }%
68 \endgroup
69 }
70 }{%
71 \newcommand\AtTextUpperLeft[1]{%
72 \begingroup
73 \@tempdima=1in\relax
74 \ifodd\c@page
75 \advance\@tempdima\oddsidemargin
76 \else
77 \advance\@tempdima\evensidemargin
78 \fi
79 \@tempdimb=-1in\relax
80 \advance\@tempdimb-\topmargin
81 \advance\@tempdimb-\headheight
82 \advance\@tempdimb-\headsep
83 \AtPageUpperLeft{%
84 \put(\LenToUnit{\@tempdima},\LenToUnit{\@tempdimb}){#1}%
85 }%
86 \endgroup
87 }
88 }
\AtTextLowerLeft
89 \newcommand\AtTextLowerLeft[1]{\AtTextUpperLeft{%
90 \put(0,\LenToUnit{-\textheight}){#1}}}
\AtTextCenter
91 \newcommand\AtTextCenter[1]{\AtTextUpperLeft{%
92 \put(\LenToUnit{.5\textwidth},\LenToUnit{-.5\textheight}){#1}}}
\ESO@HookIBG
\ESO@HookIIBG 93 \newcommand{\ESO@HookIBG}{}
\ESO@HookIIIBG 94 \newcommand{\ESO@HookIIBG}{}
\ESO@HookIFG 95 \newcommand{\ESO@HookIIIBG}{}
\ESO@HookIIFG 96 \newcommand{\ESO@HookIFG}{}
97 \newcommand{\ESO@HookIIFG}{}
98 \newcommand{\ESO@HookI}{}
99 \newcommand{\ESO@HookII}{}
100 \newcommand{\ESO@HookIII}{}
101 \let\ESO@HookI=\ESO@HookIBG
102 \let\ESO@HookII=\ESO@HookIIBG
103 \let\ESO@HookIII=\ESO@HookIIIBG
\AddToShipoutPictureBG
\AddToShipoutPictureFG 104 \newcommand{\AddToShipoutPictureBG}{%
105 \@ifstar{\g@addto@macro\ESO@HookIIBG}{\g@addto@macro\ESO@HookIBG}}
4
106 \newcommand{\AddToShipoutPicture}{}
107 \let\AddToShipoutPicture=\AddToShipoutPictureBG
\AddToShipoutPictureFG
108 \newcommand{\AddToShipoutPictureFG}{%
109 \@ifstar{\g@addto@macro\ESO@HookIIFG}{\g@addto@macro\ESO@HookIFG}}
\ClearShipoutPictureBG
\ClearShipoutPicture 110 \newcommand{\ClearShipoutPictureBG}{\global\let\ESO@HookIBG\@empty}
\ClearShipoutPictureFG 111 \newcommand{\ClearShipoutPicture}{}
112 \let\ClearShipoutPicture=\ClearShipoutPictureBG
113 \newcommand{\ClearShipoutPictureFG}{\global\let\ESO@HookIFG\@empty}
5
154 }%
155 }
156 }
\gridSetup
183 \newcommand\gridSetup[6][]{%
184 \edef\ESO@gridunitname{#1}\edef\ESO@gridunit{#2}
185 \edef\ESO@labelfactor{#3}\edef\ESO@griddelta{#4}
186 \edef\ESO@gridDelta{#5}\edef\ESO@gap{#6}}
6
200 \def\@tempb{bp}
201 \ifx\@tempa\@tempb
202 \gridSetup[\@tempa]{1bp}{1}{10}{50}{2}
203 \else
204 \def\@tempb{pt}
205 \ifx\@tempa\@tempb
206 \gridSetup[\@tempa]{\p@}{1}{10}{50}{2}
207 \else
208 \def\@tempb{in}
209 \ifx\@tempa\@tempb
210 \gridSetup[\@tempa]{.1in}{.1}{2}{10}{.5}
211 \else
212 \gridSetup[mm]{1mm}{1}{5}{20}{1}
213 \fi
214 \fi
215 \fi
216 }
217 \setkeys{ESO}{subgridstyle=solid,pscoord=true,gridunit=mm}
\ProcessOptionsWithKV This macro can process package options using ‘key=value’ syntax.
218 \def\ProcessOptionsWithKV#1{%
219 \let\@tempc\@empty
220 \@for\CurrentOption:=\@classoptionslist\do{%
221 \@ifundefined{KV@#1@\CurrentOption}%
222 {}{\edef\@tempc{\@tempc,\CurrentOption,}}}%
223 \edef\@tempc{%
224 \noexpand\setkeys{#1}{\@tempc\@ptionlist{\@currname.\@currext}}}%
225 \@tempc
226 \AtEndOfPackage{\let\@unprocessedoptions\relax}}%
227 \ProcessOptionsWithKV{ESO}%
232 \@ifundefined{colorbox}{%
233 \IfFileExists{xcolor.sty}{\RequirePackage{xcolor}}%
234 {\RequirePackage{color}}%
235 }{}%
236 \let\ESO@color=\color
237 \let\ESO@colorbox=\colorbox
238 \let\ESO@fcolorbox=\fcolorbox
239 \AtBeginDocument{%
240 \ESO@dvipsfalse
241 \@ifundefined{Gin@driver}{}%
242 {%
243 \ifx\Gin@driver\@empty\else%
244 \filename@parse{\Gin@driver}\def\reserved@a{dvips}%
245 \ifx\filename@base\reserved@a\ESO@dvipstrue\fi
246 \fi
247 }%
7
248 \ifESO@dvips\def\@tempb{eepic}\else\def\@tempb{epic}\fi
249 \def\@tempa{dotted}%\def\ESO@gap{\LenToUnit{6\@wholewidth}}%
250 \ifx\@tempa\ESO@subgridstyle
251 \IfFileExists{\@tempb.sty}%
252 {%
253 \RequirePackage{\@tempb}
254 \renewcommand*\ESO@hline[1]{\ESO@subgridlines\dottedline{\ESO@gap}%
255 (0,0)(##1,0)}
256 \renewcommand*\ESO@vline[1]{\ESO@subgridlines\dottedline{\ESO@gap}%
257 (0,0)(0,##1)}
258 }{}
259 \else
260 \ifx\ESO@gridcolor\ESO@subgridcolor
261 \renewcommand*\ESO@gridlines{\thicklines}
262 \fi
263 \fi
264 }
265 \ifESO@texcoord
266 \def\ESO@yoffsetI{\z@}\def\ESO@yoffsetII{-\paperheight}
267 \edef\ESO@griddeltaY{-\ESO@griddelta}\edef\ESO@gridDeltaY{-\ESO@gridDelta}
268 \else
269 \def\ESO@yoffsetI{-\paperheight}\def\ESO@yoffsetII{\z@}
270 \edef\ESO@griddeltaY{\ESO@griddelta}\edef\ESO@gridDeltaY{\ESO@gridDelta}
271 \fi
\ESO@gridpicture
272 \newcommand\ESO@gridpicture{%
273 \begingroup
274 \setlength\unitlength{\ESO@gridunit}%
275 \ESO@color{\ESO@subgridcolor}%
— horizontal subgrid lines —
276 \ESO@div{\paperheight}{\ESO@griddelta}%
277 \multiput(0,0)(0,\ESO@griddeltaY){\@tempcnta}%
278 {\ESO@hline{\LenToUnit{\paperwidth}}}%
— vertical subgrid lines —
279 \ESO@div{\paperwidth}{\ESO@griddelta}%
280 \multiput(0,\LenToUnit{\ESO@yoffsetII})(\ESO@griddelta,0){\@tempcnta}%
281 {\ESO@vline{\LenToUnit{\paperheight}}}%
282 \ESO@color{\ESO@gridcolor}%
— horizontal grid lines —
283 \ESO@div{\paperheight}{\ESO@gridDelta}%
284 \multiput(0,0)(0,\ESO@gridDeltaY){\@tempcnta}%
285 {\ESO@Hline{\LenToUnit{\paperwidth}}}%
— vertical grid lines —
286 \ESO@div{\paperwidth}{\ESO@gridDelta}%
287 \multiput(0,\LenToUnit{\ESO@yoffsetII})(\ESO@gridDelta,0){\@tempcnta}%
288 {\ESO@Vline{\LenToUnit{\paperheight}}}%
— horizontal numbers —
289 \fontsize{10}{12}\normalfont%
290 \ESO@div{\paperwidth}{\ESO@gridDelta}%
291 \multiput(0,\ESO@gridDeltaY)(\ESO@gridDelta,0){\@tempcnta}{%
8
292 \@tempcntb=\@tempcnta\advance\@tempcntb-\@multicnt
293 \ifnum\@tempcntb>1\relax
294 \multiply\@tempcntb by \ESO@gridDelta\relax
295 \@tempdima=\@tempcntb sp\@tempdima=\ESO@labelfactor\@tempdima
296 \@tempcntb=\@tempdima%
297 \makebox(0,0)[c]{\ESO@colorbox{white}{\the\@tempcntb}}%
298 \fi}%
— vertical numbers —
299 \ifx\ESO@gridunitname\@empty\def\@tempa{0}\else\def\@tempa{1}\fi
300 \ESO@div{\paperheight}{\ESO@gridDelta}%
301 \multiput(\ESO@gridDelta,0)(0,\ESO@gridDeltaY){\@tempcnta}{%
302 \@tempcntb=\@tempcnta\advance\@tempcntb-\@multicnt%
303 \ifnum\@tempcntb>\@tempa\relax
304 \multiply\@tempcntb by \ESO@gridDelta\relax%
305 \@tempdima=\@tempcntb sp\@tempdima=\ESO@labelfactor\@tempdima
306 \@tempcntb=\@tempdima
307 \makebox(0,0)[c]{\ESO@colorbox{white}{\the\@tempcntb}}%
308 \fi
309 }%
— the unit label —
310 \ifx\ESO@gridunitname\@empty\else
311 \thicklines\fboxrule=\@wholewidth
312 \put(\ESO@gridDelta,\ESO@gridDeltaY){\makebox(0,0)[c]{%
313 \ESO@fcolorbox{\ESO@gridcolor}{white}{%
314 \textbf{\ESO@gridunitname}}}}%
315 \fi
316 \normalcolor%
317 \endgroup
318 }
Add the grid to the shipout picture (\ESO@HookIIIBG is independed from the user
commands \AddToShipoutPictureBG and \AddToShipoutPictureBG*).
319 \ifESO@grid\g@addto@macro\ESO@HookIIIBG{\ESO@gridpicture}\fi
Change History
9
\LenToUnit . . . . . . . . . . . . . . 2 using with XeLATEX should be
v1.1 possible. . . . . . . . . . . . . . . . . . 7
General: New commands and pack- v2.0a
age options for background General: Better test of color/xcolor 7
grids. . . . . . . . . . . . . . . . . . . . 1 \AtStockCenter: New . . . . . . . . . 3
v1.1a \AtStockLowerLeft: New . . . . . . . 3
\AtStockUpperLeft: New . . . . . . . 3
\ESO@gridpicture: Font setting
\AtTextUpperLeft: Works now for
added. . . . . . . . . . . . . . . . . . . 8
class memoir . . . . . . . . . . . . . . 3
v1.1b
v2.0b
General: New command \AddToShipoutPictureFG: New
\AtPageLowerLeft . . . . . . . . . 1 command \AddToShipoutPictureFG
New package options ”texcoord” ........................ 4
and ”pscoord” . . . . . . . . . . . . 1 v2.0c
v1.1c \AtBeginShipoutUpperLeftForeground:
General: Remove the disadvanta- bugfix for memoir class (re-
geous check of ‘pdfTeX’. Now ported by YI Hoze) . . . . . . . . . 5
10