summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/source/latex/eso-pic/eso-pic.dtx
blob: 497bc1b7f2b52b9107f8930b7d2e0e3564133d34 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
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
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
% \iffalse meta-comment
%
% Copyright (C) 1998-2010 by Rolf Niepraschk <Rolf.Niepraschk@gmx.de>
% -------------------------------------------------------------------
% 
% This file may be distributed and/or modified under the
% conditions of the LaTeX Project Public License, either version 1.2
% 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.2 or later is part of all distributions of LaTeX 
% version 1999/12/01 or later.
% 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 "author-maintained".
%
% Please send error reports and suggestions for improvements to
%   Rolf Niepraschk <Rolf.Niepraschk@gmx.de>.
%
% \fi
%
% \iffalse
%<package>\NeedsTeXFormat{LaTeX2e}[1999/12/01]
%<package>\ProvidesPackage{eso-pic}
%<package>   [2013/10/06 v2.0d eso-pic (RN)]
%
%<*driver>
\documentclass[a4paper]{ltxdoc}
\usepackage{eso-pic,array}
\EnableCrossrefs\CodelineIndex\RecordChanges
\begin{document}
  \DocInput{eso-pic.dtx}
\end{document}
%</driver>
% \fi
%
% \CheckSum{751}
%
% \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         \~}
%
% \iffalse meta-comment
% ===================================================================
%  @LaTeX-package-file{
%    author         = {Rolf Niepraschk},
%    version        = "v2.0a",
%    date           = "08 Jun 2010",
%    filename       = "eso-pic.sty",
%    address        = "",
%    telephone      = "",
%    email          = "Rolf.Niepraschk@gmx.de",
%    codetable      = "ISO/ASCII",
%    keywords       = "LaTeX2e, \shipout, picture",
%    dependences    = "atbegshi",
%    supported      = "yes",
%    docstring      = "LaTeX package which makes it easy to add some  
%                       picture commands to every page." 
%  }
% ===================================================================
% \fi
%
% \providecommand\env[1]{\textsf{#1}}
% \providecommand\clsname[1]{\textsf{#1}}
% \providecommand\pkgname[1]{\textsf{#1}}
% \providecommand\optname[1]{\textsf{#1}}
% \providecommand\progname[1]{\textsf{#1}}
%
% \setlength\emergencystretch{3em}
%
%  \changes{v0.4}{1998/06/02}{Initial version}
%  \changes{v0.5}{1998/07/11}{Some bug corrections}
%  \changes{v0.6}{2000/05/13}{Some corrections for compatibility with
%     the \pkgname{html} package suggested by Ross Moore and a licence note}
%  \changes{v0.7}{2001/07/20}{New command \cmd{\AddToShipoutPicture*}}
%  \changes{v1.0}{2002/07/03}{New commands \cmd{\LenToUnit},%
%    \cmd{\AtPageUpperLeft}, \cmd{\AtPageCenter}, \cmd{\AtTextUpperLeft}, 
%    and \cmd{\AtTextCenter}.}
% \changes{v1.0c}{2002/10/30}{New command \cmd{\AtTextLowerLeft} and 
%    corrections to \cmd{\AtTextUpperLeft}.}
%  \changes{v1.1}{2002/11/07}{New commands and package options for 
%    background grids.}
%  \changes{v1.1b}{2002/11/16}{New package options "texcoord" and "pscoord"}
%  \changes{v1.1b}{2002/11/16}{New command \cmd{\AtPageLowerLeft}}
%
% \GetFileInfo{eso-pic.sty}
%
% \DoNotIndex{\newcommand,\newenvironment}
%
% \title{The \pkgname{eso-pic} package\thanks{This document
%   corresponds to \pkgname{eso-pic}~\fileversion, dated \filedate.}}
% \author{Rolf Niepraschk \\ \texttt{Rolf.Niepraschk@gmx.de}}
%
% \date{}
%
% \maketitle
%
% \section{Introduction}
%
%  This package makes it easy to add some picture commands to every page 
%  at absolute positions.
% \section{Usage}
%   See also the example \LaTeX\ documents (|eso-*.tex|).
%
%  \subsection{Basic commands for adding \LaTeX{} stuff to the page background}
%  \DescribeMacro{\AddToShipoutPictureBG} All the picture commands which are
%  parameters of an \cs{AddToShipoutPictureBG} command will be added to the 
%  internal macro \cs{ESO@HookIBG}. This macro is part of a 
%  zero-length \texttt{picture} environment with basepoint at the lower left 
%  corner of the page (default) or at the upper left corner 
%  (package option "texcoord"). The \texttt{picture} environment will be 
%  shipped out at every new page.
%  
%  \DescribeMacro{\AddToShipoutPictureBG*} \cs{AddToShipoutPictureBG*} works like 
%  \cs{AddToShipoutPictureBG} but only for the current page. It used the internal
%  macro \cs{ESO@HookIIBG} which contents will be removed 
%  automatically.
%  
%  For compatibility the macros \cs{AddToShipoutPicture} and 
%  \cs{AddToShipoutPicture*} are aliases for \cs{AddToShipoutPictureBG} 
%  and \cs{AddToShipoutPictureBG*}.
%  
%  \DescribeMacro{\AddToShipoutPictureFG}
%  \DescribeMacro{\AddToShipoutPictureFG*} Works like 
%  \cs{AddToShipoutPictureBG} but the picture commands are on the top 
%  oft the normal document content.
%
%  \DescribeMacro{\ClearShipoutPictureBG} A call of 
%  \cs{ClearShipoutPictureBG} 
%  clears the contents of \cs{ESO@HookIBG}. 
%
%  For compatibility the macro \cs{ClearShipoutPicture} 
%  is an alias for \cs{ClearShipoutPictureBG}.
%  
%  \DescribeMacro{\ClearShipoutPictureFG} A call of 
%  \cs{ClearShipoutPictureFG} 
%  clears the contents of \cs{ESO@HookIFG}. 
%
%   \DescribeMacro{\LenToUnit} Allows a length as parameter to a picture
%    command. Note that this macro is no more necessary when using 
%      |\usepackage{picture}|.
%
%  \DescribeMacro{\gridSetup} 
%   \cmd{\gridSetup}\oarg{gridunitname}\marg{gridunit}\marg{labelfactor}^^A
%     \marg{griddelta} \marg{gridDelta}\marg{gap}. For details see the 
%     implementation section.\par\clearpage
%  \DescribeMacro{\AtPageUpperLeft}
%  \DescribeMacro{\AtPageLowerLeft}
%  \DescribeMacro{\AtPageCenter} 
%  \DescribeMacro{\AtTextUpperLeft}
%  \DescribeMacro{\AtTextLowerLeft}
%  \DescribeMacro{\AtTextCenter}
%  \DescribeMacro{\AtStockUpperLeft}
%  \DescribeMacro{\AtStockLowerLeft}
%  \DescribeMacro{\AtStockCenter} 
%    Helper macros for easier positioning on the page. 
%
%  \subsection{Package options}
%  \begin{center}
%  \begin{tabular}{@{}>{\ttfamily}llp{.5\textwidth}@{}}
%    \textnormal{Option} & Value & Comments \\ \hline
%    pscoord & empty or \textit{true}, \textit{false} & The zero point of
%      the coordinate system is the lower left corner of the page
%      (the default). \\
%    texcoord & empty or \textit{true}, \textit{false} & The zero point of
%      the coordinate system is the upper left corner of the page. \\
%    grid & empty or \textit{true}, \textit{false} & A grid is drawing; 
%      default: false. \\
%    gridunit & \textit{mm}, \textit{in}, \textit{bp}, \textit{pt} & Distance 
%      between gridlines are multiples of \texttt{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 & \textit{solid} or \textit{dotted} & `dotted' is very slow! 
%      default: solid. \\
%    colorgrid & empty or \textit{true}, \textit{false} & Shortcut for 
%          `grid=true', `gridcolor=red' and `subgridcolor=green'; 
%          default: false.\\
%    dvips        & empty or \textit{true}, \textit{false} & Is also true 
%      if the package option \texttt{dvips} is 
%      used by \pkgname{color} or \pkgname{graphics}. If true package 
%      \pkgname{eepic} is loaded for better performance of dotted lines.   
%    
%  \end{tabular}
%  \end{center}
%
% \StopEventually{\PrintChanges\PrintIndex}
%
% \section{Implementation}
%
% \subsection{The main functionality}
%
%    \begin{macrocode}
\RequirePackage{atbegshi}
%    \end{macrocode}
% \begin{macro}{\LenToUnit}
%  \changes{v1.0d}{2006/07/14}{Using \cmd{\providecommand} instead of
%   \cmd{\newcommand} for \cmd{\LenToUnit}}
%    \begin{macrocode}
\providecommand*\LenToUnit[1]{#1\@gobble}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\ESO@isMEMOIR}
%    Support for the \clsname{memoir} class.
%    \begin{macrocode}
\newcommand\ESO@isMEMOIR[2]{#2}
\@ifclassloaded{memoir}{\renewcommand\ESO@isMEMOIR[2]{#1}}{}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\AtPageUpperLeft}
%    \begin{macrocode}
\newcommand\AtPageUpperLeft[1]{%
  \put(0,\LenToUnit{-\ESO@yoffsetI}){#1}%
}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\AtPageLowerLeft}
%    \begin{macrocode}
\newcommand\AtPageLowerLeft[1]{\AtPageUpperLeft{%
  \put(0,\LenToUnit{-\paperheight}){#1}}}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\AtPageCenter}
%    \begin{macrocode}
\newcommand\AtPageCenter[1]{\AtPageUpperLeft{%
  \put(\LenToUnit{.5\paperwidth},\LenToUnit{-.5\paperheight}){#1}}%
}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\AtStockLowerLeft}
%  \changes{v2.0a}{2009/10/07}{New}
%    \begin{macrocode}
\newcommand\AtStockLowerLeft{}
\ESO@isMEMOIR{%
  \renewcommand\AtStockLowerLeft[1]{%
    \begingroup
      \@tempdima=-\stockwidth
      \advance\@tempdima\trimedge
      \advance\@tempdima\paperwidth
      \if@twoside\ifodd\c@page\else
        \@tempdima=-\trimedge
      \fi\fi
      \@tempdimb=-\stockheight
      \advance\@tempdimb\paperheight
      \advance\@tempdimb\trimtop
      \AtPageLowerLeft{%
        \put(\LenToUnit{\@tempdima},\LenToUnit{\@tempdimb}){#1}%
      }%
    \endgroup
  }
}{%
  \let\AtStockLowerLeft=\AtPageLowerLeft
}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\AtStockUpperLeft}
%  \changes{v2.0a}{2009/10/07}{New}
%    \begin{macrocode}
\newcommand\AtStockUpperLeft{}
\ESO@isMEMOIR{%
  \renewcommand\AtStockUpperLeft[1]{%
    \AtStockLowerLeft{%
      \put(0,\LenToUnit{\stockheight}){#1}%
    }%
  }%
}{%
  \let\AtStockUpperLeft=\AtPageUpperLeft
}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\AtStockCenter}
%  \changes{v2.0a}{2009/10/07}{New}
%    \begin{macrocode}
\newcommand\AtStockCenter{}
\ESO@isMEMOIR{%
  \renewcommand\AtStockCenter[1]{%
    \AtStockLowerLeft{%
      \put(\LenToUnit{.5\stockwidth},\LenToUnit{.5\stockheight}){#1}%
    }%
  }%
}{%
  \let\AtStockCenter=\AtPageCenter
}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\AtTextUpperLeft}
%  \changes{v2.0a}{2009/10/07}{Works now for class \clsname{memoir}}
%    \begin{macrocode}
\ESO@isMEMOIR{%
  \newcommand\AtTextUpperLeft[1]{%
    \begingroup
      \ifodd\c@page
        \@tempdima=\spinemargin
      \else
        \@tempdima=\paperwidth
        \advance\@tempdima-\textwidth
        \advance\@tempdima-\spinemargin
      \fi
      \@tempdimb=-\uppermargin
      \AtPageUpperLeft{%
        \put(\LenToUnit{\@tempdima},\LenToUnit{\@tempdimb}){#1}%
      }%
    \endgroup
  }
}{%
  \newcommand\AtTextUpperLeft[1]{%
    \begingroup
      \@tempdima=1in\relax
      \ifodd\c@page
        \advance\@tempdima\oddsidemargin
      \else
        \advance\@tempdima\evensidemargin
      \fi
      \@tempdimb=-1in\relax
      \advance\@tempdimb-\topmargin
      \advance\@tempdimb-\headheight
      \advance\@tempdimb-\headsep
      \AtPageUpperLeft{%
        \put(\LenToUnit{\@tempdima},\LenToUnit{\@tempdimb}){#1}%
      }%    
    \endgroup
  }
}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\AtTextLowerLeft}
%    \begin{macrocode}
\newcommand\AtTextLowerLeft[1]{\AtTextUpperLeft{%
  \put(0,\LenToUnit{-\textheight}){#1}}}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\AtTextCenter}
%    \begin{macrocode}
\newcommand\AtTextCenter[1]{\AtTextUpperLeft{%
  \put(\LenToUnit{.5\textwidth},\LenToUnit{-.5\textheight}){#1}}}
%    \end{macrocode}
% \end{macro}
% \DescribeMacro{\ESO@HookIBG}\DescribeMacro{\ESO@HookIIBG}
% \DescribeMacro{\ESO@HookIIIBG}\DescribeMacro{\ESO@HookIFG}
% \DescribeMacro{\ESO@HookIIFG}
%    \begin{macrocode}
\newcommand{\ESO@HookIBG}{}
\newcommand{\ESO@HookIIBG}{}
\newcommand{\ESO@HookIIIBG}{}
\newcommand{\ESO@HookIFG}{}
\newcommand{\ESO@HookIIFG}{}
\newcommand{\ESO@HookI}{}
\newcommand{\ESO@HookII}{}
\newcommand{\ESO@HookIII}{}
\let\ESO@HookI=\ESO@HookIBG
\let\ESO@HookII=\ESO@HookIIBG
\let\ESO@HookIII=\ESO@HookIIIBG
%    \end{macrocode}
% \begin{macro}{\AddToShipoutPictureBG}
% \begin{macro}{\AddToShipoutPictureFG}
% \changes{v2.0b}{2010/06/08}{New command \cmd{\AddToShipoutPictureFG}}
%    \begin{macrocode}
\newcommand{\AddToShipoutPictureBG}{%
  \@ifstar{\g@addto@macro\ESO@HookIIBG}{\g@addto@macro\ESO@HookIBG}}
\newcommand{\AddToShipoutPicture}{}
\let\AddToShipoutPicture=\AddToShipoutPictureBG
%    \end{macrocode}  
% \end{macro}
% \end{macro}
% \begin{macro}{\AddToShipoutPictureFG}
%    \begin{macrocode}
\newcommand{\AddToShipoutPictureFG}{%
  \@ifstar{\g@addto@macro\ESO@HookIIFG}{\g@addto@macro\ESO@HookIFG}}
%    \end{macrocode}  
% \end{macro}  
% \begin{macro}{\ClearShipoutPictureBG}
% \begin{macro}{\ClearShipoutPicture}
% \begin{macro}{\ClearShipoutPictureFG}
% \changes{v1.0a}{2002/10/07}{Changed \cmd{\let} to 
%   \cmd{\global}\cmd{\let} (suggested by Alberto Lusiani).}
%    \begin{macrocode}
\newcommand{\ClearShipoutPictureBG}{\global\let\ESO@HookIBG\@empty}
\newcommand{\ClearShipoutPicture}{}
\let\ClearShipoutPicture=\ClearShipoutPictureBG
\newcommand{\ClearShipoutPictureFG}{\global\let\ESO@HookIFG\@empty}
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
% \begin{macro}{\AtBeginShipout}
% \begin{macro}{\AtBeginShipoutUpperLeft}
% \begin{macro}{\AtBeginShipoutUpperLeftForeground}
% (see package \pkgname{atbegshi})
% \changes{v2.0c}{2010/10/06}{bugfix for memoir class
%   (reported by YI Hoze)}
%    \begin{macrocode}
\ESO@isMEMOIR{%
  \AtBeginShipout{%
    \@tempdima=-\trimedge
    \advance\@tempdima-\paperwidth
    \advance\@tempdima\stockwidth
    \if@twoside\ifodd\c@page\else
      \advance\@tempdima2\trimedge
      \advance\@tempdima\paperwidth
      \advance\@tempdima-\stockwidth
    \fi\fi
    \@tempdimb=\ESO@yoffsetI
    \advance\@tempdimb-\trimtop
    \nointerlineskip
    \AtBeginShipoutUpperLeft{%
      \put(\LenToUnit{\@tempdima},\LenToUnit{\@tempdimb}){%
        \ESO@HookIIIBG\ESO@HookIBG\ESO@HookIIBG
        \global\let\ESO@HookIIBG\@empty
      }%
    }%
    \AtBeginShipoutUpperLeftForeground{%
      \put(\LenToUnit{\@tempdima},\LenToUnit{\@tempdimb}){%
        \ESO@HookIFG\ESO@HookIIFG
        \global\let\ESO@HookIIFG\@empty
      }%
    }%
  }
}{%
  \AtBeginShipout{%
    \nointerlineskip
    \AtBeginShipoutUpperLeft{%
      \put(0,\LenToUnit{\ESO@yoffsetI}){%
        \ESO@HookIIIBG\ESO@HookIBG\ESO@HookIIBG
        \global\let\ESO@HookIIBG\@empty
      }%
    }%
    \AtBeginShipoutUpperLeftForeground{%
      \put(0,\LenToUnit{\ESO@yoffsetI}){%
        \ESO@HookIFG\ESO@HookIIFG
        \global\let\ESO@HookIIFG\@empty
      }%
    }%
  }
}
%    \end{macrocode}  
% \end{macro}
% \end{macro}
% \end{macro}
% \subsection{The background grid}
%    \begin{macrocode}
\RequirePackage{keyval}
%    \end{macrocode}
%  Initialising some macros
%    \begin{macrocode}
\newif\ifESO@dvips\ESO@dvipsfalse \newif\ifESO@grid\ESO@gridfalse
\newif\ifESO@texcoord\ESO@texcoordfalse
\newcommand*\ESO@gridunitname{}
\newcommand*\ESO@gridunit{}
\newcommand*\ESO@labelfactor{}
\newcommand*\ESO@griddelta{}\newcommand*\ESO@griddeltaY{}
\newcommand*\ESO@gridDelta{}\newcommand*\ESO@gridDeltaY{}
\newcommand*\ESO@gridcolor{}
\newcommand*\ESO@subgridcolor{}
\newcommand*\ESO@subgridstyle{dotted}% ???
\newcommand*\ESO@gap{}
\newcommand*\ESO@yoffsetI{}\newcommand*\ESO@yoffsetII{}
\newcommand*\ESO@gridlines{\thinlines}
\newcommand*\ESO@subgridlines{\thinlines}
\newcommand*\ESO@hline[1]{\ESO@subgridlines\line(1,0){#1}}
\newcommand*\ESO@vline[1]{\ESO@subgridlines\line(0,1){#1}}
\newcommand*\ESO@Hline[1]{\ESO@gridlines\line(1,0){#1}}
\newcommand*\ESO@Vline[1]{\ESO@gridlines\line(0,1){#1}}    
\newcommand\ESO@fcolorbox[3]{\fbox{#3}}
\newcommand\ESO@color[1]{}
\newcommand\ESO@colorbox[2]{%
  \begingroup
    \fboxrule=\z@\fbox{#2}%
  \endgroup
}
%    \end{macrocode}
% \begin{macro}{\gridSetup}
%    \begin{macrocode}
\newcommand\gridSetup[6][]{%
  \edef\ESO@gridunitname{#1}\edef\ESO@gridunit{#2}
  \edef\ESO@labelfactor{#3}\edef\ESO@griddelta{#4}
  \edef\ESO@gridDelta{#5}\edef\ESO@gap{#6}}
%    \end{macrocode}
% \end{macro}
%  All the key-value options 
%    \begin{macrocode}
\define@key{ESO}{texcoord}[true]{\csname ESO@texcoord#1\endcsname}
\define@key{ESO}{pscoord}[true]{\csname @tempswa#1\endcsname
  \if@tempswa\ESO@texcoordfalse\else\ESO@texcoordtrue\fi}
\define@key{ESO}{dvips}[true]{\csname ESO@dvips#1\endcsname}
\define@key{ESO}{grid}[true]{\csname ESO@grid#1\endcsname
  \setkeys{ESO}{gridcolor=black,subgridcolor=black}}
\define@key{ESO}{colorgrid}[true]{\csname ESO@grid#1\endcsname
  \setkeys{ESO}{gridcolor=red,subgridcolor=green}}
\define@key{ESO}{gridcolor}{\def\ESO@gridcolor{#1}}
\define@key{ESO}{subgridcolor}{\def\ESO@subgridcolor{#1}}
\define@key{ESO}{subgridstyle}{\def\ESO@subgridstyle{#1}}%
\define@key{ESO}{gridunit}{%
  \def\@tempa{#1}
  \def\@tempb{bp}
  \ifx\@tempa\@tempb
    \gridSetup[\@tempa]{1bp}{1}{10}{50}{2}
  \else
    \def\@tempb{pt}
    \ifx\@tempa\@tempb
      \gridSetup[\@tempa]{\p@}{1}{10}{50}{2}
    \else     
      \def\@tempb{in}
      \ifx\@tempa\@tempb
        \gridSetup[\@tempa]{.1in}{.1}{2}{10}{.5}
      \else 
        \gridSetup[mm]{1mm}{1}{5}{20}{1}
      \fi
    \fi
  \fi      
}
\setkeys{ESO}{subgridstyle=solid,pscoord=true,gridunit=mm}
%    \end{macrocode}
%    \begin{macro}{\ProcessOptionsWithKV}
%    This macro can process package options using `key=value' syntax. 
%    \begin{macrocode}
\def\ProcessOptionsWithKV#1{%
  \let\@tempc\@empty
  \@for\CurrentOption:=\@classoptionslist\do{%
    \@ifundefined{KV@#1@\CurrentOption}%
    {}{\edef\@tempc{\@tempc,\CurrentOption,}}}%
  \edef\@tempc{%
    \noexpand\setkeys{#1}{\@tempc\@ptionlist{\@currname.\@currext}}}%
  \@tempc
  \AtEndOfPackage{\let\@unprocessedoptions\relax}}%
%    \end{macrocode}
%    \end{macro}
%    \begin{macrocode}  
\ProcessOptionsWithKV{ESO}%
%    \end{macrocode} 
%    \begin{macro}{\ESO@div}
%  Divides length |#1| by |#2| \(\times\) \cmd{\ESO@gridunit} and adds one. 
%  Result is in \cmd{\@tempcnta}.
%    \begin{macrocode}
\newcommand\ESO@div[2]{%
  \@tempdima=#1\relax\@tempdimb=\ESO@gridunit\relax
  \@tempdimb=#2\@tempdimb\divide\@tempdima by \@tempdimb
  \@tempcnta\@tempdima\advance\@tempcnta\@ne}  
%    \end{macrocode}
%    \end{macro}
%  \changes{v1.1c}{2005/12/24}{Remove the disadvantageous check of 
%    `pdfTeX'. Now using with Xe\LaTeX\ should be possible.}
%  \changes{v2.0a}{2009/10/07}{Better test of color/xcolor}
%  \changes{v2.0d}{2013/10/06}{Improved color commands}
%    \begin{macrocode} 
\@ifundefined{colorbox}{%
  \IfFileExists{xcolor.sty}{\RequirePackage{xcolor}}%
    {\RequirePackage{color}}%
}{}%
\let\ESO@color=\color
\renewcommand\ESO@colorbox[2]{%
  \begingroup
    \fboxsep=.4ex %
    \colorbox{#1}{#2}%
  \endgroup
}
\renewcommand\ESO@fcolorbox[3]{%
  \begingroup
    \fboxsep=.5ex %
    \fcolorbox{#1}{#2}{#3}%
  \endgroup
}
\AtBeginDocument{%
  \ESO@dvipsfalse
  \@ifundefined{Gin@driver}{}%
  {%
    \ifx\Gin@driver\@empty\else%
      \filename@parse{\Gin@driver}\def\reserved@a{dvips}%
      \ifx\filename@base\reserved@a\ESO@dvipstrue\fi
    \fi
  }% 
  \ifESO@dvips\def\@tempb{eepic}\else\def\@tempb{epic}\fi
  \def\@tempa{dotted}%\def\ESO@gap{\LenToUnit{6\@wholewidth}}%
  \ifx\@tempa\ESO@subgridstyle
    \IfFileExists{\@tempb.sty}%
    {%
      \RequirePackage{\@tempb}
      \renewcommand*\ESO@hline[1]{\ESO@subgridlines\dottedline{\ESO@gap}%
        (0,0)(##1,0)}
      \renewcommand*\ESO@vline[1]{\ESO@subgridlines\dottedline{\ESO@gap}%
        (0,0)(0,##1)} 
    }{}
  \else
    \ifx\ESO@gridcolor\ESO@subgridcolor
      \renewcommand*\ESO@gridlines{\thicklines}
    \fi       
  \fi
} 
\ifESO@texcoord
  \def\ESO@yoffsetI{\z@}\def\ESO@yoffsetII{-\paperheight}
  \edef\ESO@griddeltaY{-\ESO@griddelta}\edef\ESO@gridDeltaY{-\ESO@gridDelta}
\else
  \def\ESO@yoffsetI{-\paperheight}\def\ESO@yoffsetII{\z@}
  \edef\ESO@griddeltaY{\ESO@griddelta}\edef\ESO@gridDeltaY{\ESO@gridDelta}
\fi
%    \end{macrocode}  
%    \begin{macro}{\ESO@gridpicture}
%    \begin{macrocode} 
\newcommand\ESO@gridpicture{%
  \begingroup
    \setlength\unitlength{\ESO@gridunit}%
    \ESO@color{\ESO@subgridcolor}%
%    \end{macrocode}     
%    --- horizontal subgrid lines ---
%    \begin{macrocode}    
    \ESO@div{\paperheight}{\ESO@griddelta}%
    \multiput(0,0)(0,\ESO@griddeltaY){\@tempcnta}%
      {\ESO@hline{\LenToUnit{\paperwidth}}}%
%    \end{macrocode}     
%    --- vertical subgrid lines ---
%    \begin{macrocode}  
    \ESO@div{\paperwidth}{\ESO@griddelta}%
    \multiput(0,\LenToUnit{\ESO@yoffsetII})(\ESO@griddelta,0){\@tempcnta}%
      {\ESO@vline{\LenToUnit{\paperheight}}}%
    \ESO@color{\ESO@gridcolor}%
%    \end{macrocode}     
%    --- horizontal grid lines ---
%    \begin{macrocode}     
    \ESO@div{\paperheight}{\ESO@gridDelta}%
    \multiput(0,0)(0,\ESO@gridDeltaY){\@tempcnta}%
      {\ESO@Hline{\LenToUnit{\paperwidth}}}%
%    \end{macrocode}     
%    --- vertical grid lines ---
%    \begin{macrocode}        
    \ESO@div{\paperwidth}{\ESO@gridDelta}%
    \multiput(0,\LenToUnit{\ESO@yoffsetII})(\ESO@gridDelta,0){\@tempcnta}%
      {\ESO@Vline{\LenToUnit{\paperheight}}}%
%    \end{macrocode}         
%    --- horizontal numbers ---
%  \changes{v1.1a}{2002/11/09}{Font setting added.}
%    \begin{macrocode}   
    \fontsize{10}{12}\normalfont%   
    \ESO@div{\paperwidth}{\ESO@gridDelta}%
    \multiput(0,\ESO@gridDeltaY)(\ESO@gridDelta,0){\@tempcnta}{%
      \@tempcntb=\@tempcnta\advance\@tempcntb-\@multicnt
      \ifnum\@tempcntb>1\relax
        \multiply\@tempcntb by \ESO@gridDelta\relax
        \@tempdima=\@tempcntb sp\@tempdima=\ESO@labelfactor\@tempdima
        \@tempcntb=\@tempdima%
        \makebox(0,0)[c]{\ESO@colorbox{white}{\the\@tempcntb}}%
      \fi}%
%    \end{macrocode}        
%    --- vertical numbers ---
%    \begin{macrocode} 
    \ifx\ESO@gridunitname\@empty\def\@tempa{0}\else\def\@tempa{1}\fi
    \ESO@div{\paperheight}{\ESO@gridDelta}%
    \multiput(\ESO@gridDelta,0)(0,\ESO@gridDeltaY){\@tempcnta}{%
      \@tempcntb=\@tempcnta\advance\@tempcntb-\@multicnt%
      \ifnum\@tempcntb>\@tempa\relax
        \multiply\@tempcntb by \ESO@gridDelta\relax%
        \@tempdima=\@tempcntb sp\@tempdima=\ESO@labelfactor\@tempdima
        \@tempcntb=\@tempdima
        \makebox(0,0)[c]{\ESO@colorbox{white}{\the\@tempcntb}}%
      \fi      
    }%     
%    \end{macrocode}     
%    --- the unit label ---
%    \begin{macrocode}
    \ifx\ESO@gridunitname\@empty\else
      \thicklines\fboxrule=\@wholewidth
      \put(\ESO@gridDelta,\ESO@gridDeltaY){\makebox(0,0)[c]{%
        \ESO@fcolorbox{\ESO@gridcolor}{white}{%
          \textbf{\ESO@gridunitname}}}}%
    \fi          
    \normalcolor%
  \endgroup
}
%    \end{macrocode}  
%    \end{macro}    
%  Add the grid to the shipout picture (\cmd{\ESO@HookIIIBG} is independed 
%  from the user commands 
%  \cmd{\AddToShipoutPictureBG} and \cmd{\AddToShipoutPictureBG*}).
%  \changes{v2.0d}{2013/10/06}{grid should be in foreground}
%    \begin{macrocode}   
\ifESO@grid\g@addto@macro\ESO@HookIFG{\ESO@gridpicture}\fi
%    \end{macrocode} 
%
% \Finale
\endinput