% \iffalse meta-comment
%
% Copyright (C) 1998-2002 by Rolf Niepraschk <niepraschk@ptb.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.
%
% Please send error reports and suggestions for improvements to
%   Rolf Niepraschk <niepraschk@ptb.de>.
%
% \fi
%
% \iffalse
%<package>\NeedsTeXFormat{LaTeX2e}[1999/12/01]
%<package>\ProvidesPackage{eso-pic}
%<package>   [2002/10/30 v1.0c eso-pic (RN)] 
%
%<*driver>
\documentclass{ltxdoc}
\usepackage{eso-pic}
\EnableCrossrefs         
\CodelineIndex
\RecordChanges
\begin{document}
  \DocInput{eso-pic.dtx}
\end{document}
%</driver>
% \fi
%
% \CheckSum{190}
%
% \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	    = "1.0b",
%    date	    = "23 October 2002",
%    filename	    = "eso-pic.sty",
%    address	    = "",
%    telephone      = "",
%    email	    = "niepraschk@ptb.de",
%    codetable      = "ISO/ASCII",
%    keywords	    = "LaTeX2e, \shipout, picture",
%    dependences    = "everyshi",
%    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}}
%
%  \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}.}
%
% \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{niepraschk@ptb.de}}
%
% \date{}
%
% \maketitle
%
% \begin{abstract}
%    This package makes it easy to add some picture commands to every page.
% \end{abstract}
%
% \section{Introduction}
%
%  This package is an extension to Martin Schr\"oder's \pkgname{everyshi} 
%  package. Using \pkgname{every\-shi}'s \cs{EveryShipout} command 
%  \pkgname{eso-pic} adds one or more userdefined \texttt{picture} commands to 
%  \LaTeX's shipout routine. 
%
% \section{Usage}
%
%  \DescribeMacro{\AddToShipoutPicture} All the picture commands which are
%  parameters of an \cs{AddToShipoutPicture} command will be added to the 
%  internal macro \cs{ESO@HookI}. This macro is part of a 
%  zero-length \texttt{picture} environment with basepoint at the lower left 
%  corner of the page (similar to postscript). The \texttt{picture} 
%  environment will be shipped out at every new page.
%
%  \DescribeMacro{\ClearShipoutPicture} A call of \cs{ClearShipoutPicture} 
%  clears the contents of \cs{ESO@HookI}. 
%  
%  \DescribeMacro{\AddToShipoutPicture*} \cs{AddToShipoutPicture*} works like 
%  \cs{AddToShipoutPicture} but only for the current page. It used the internal
%  macro \cs{ESO@HookII} which contents will be removed automatically.
%
%  \DescribeMacro{\LenToUnit} Allows a length as parameter to a picture
%    command.
%
%  \DescribeMacro{\AtPageUpperLeft} Some helper macros for easier 
%    positioning to importend points on the page. 
%  \DescribeMacro{\AtPageCenter}
%  \DescribeMacro{\AtTextUpperLeft}
%  \DescribeMacro{\AtTextLowerLeft}
%  \DescribeMacro{\AtTextCenter}
%
% \StopEventually{\PrintChanges\PrintIndex}
%
% \section{Implementation}
%
%    \begin{macrocode}
\RequirePackage{everyshi}
%    \end{macrocode}
% \begin{macro}{\LenToUnit}
%    \begin{macrocode}
\newcommand\LenToUnit[1]{#1\@gobble}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\AtPageUpperLeft}
%    \begin{macrocode}
\newcommand\AtPageUpperLeft[1]{%
  \begingroup
    \@tempdima=0pt\relax\@tempdimb=\paperheight\relax              
    \put(\LenToUnit{\@tempdima},\LenToUnit{\@tempdimb}){#1}%   
  \endgroup   
}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\AtPageCenter}
%    \begin{macrocode}
\newcommand\AtPageCenter[1]{%
  \begingroup
    \@tempdima=.5\paperwidth\@tempdimb=.5\paperheight%
    \put(\LenToUnit{\@tempdima},\LenToUnit{\@tempdimb}){#1}% 
  \endgroup  
}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\AtTextUpperLeft}
%    \begin{macrocode}
\newcommand\AtTextUpperLeft[1]{%
  \begingroup
    \setlength\@tempdima{1in}%
    \ifodd\c@page%
      \advance\@tempdima\oddsidemargin%
    \else%
      \advance\@tempdima\evensidemargin%
    \fi%
    \@tempdimb=\paperheight\advance\@tempdimb-1in\relax%
    \advance\@tempdimb-\topmargin%
    \advance\@tempdimb-\headheight\advance\@tempdimb-\headsep%
    \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}
%    \begin{macrocode}
\newcommand{\ESO@HookI}{} \newcommand{\ESO@HookII}{}
\newcommand{\ESO@HookIII}{}
%    \end{macrocode}
% \begin{macro}{\AddToShipoutPicture}
%    \begin{macrocode}
\newcommand{\AddToShipoutPicture}{%
  \@ifstar{\g@addto@macro\ESO@HookII}{\g@addto@macro\ESO@HookI}}
%    \end{macrocode}  
% \end{macro}  
% \begin{macro}{\ClearShipoutPicture}
% \changes{v1.0a}{2002/10/07}{Changed \cmd{\let} to 
%   \cmd{\global}\cmd{\let} (suggested by Alberto Lusiani).}
%    \begin{macrocode}
\newcommand{\ClearShipoutPicture}{\global\let\ESO@HookI\@empty}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\ESO@isMEMOIR}
%    \begin{macrocode}
\newcommand\ESO@isMEMOIR[1]{}
\@ifclassloaded{memoir}{\renewcommand\ESO@isMEMOIR[1]{#1}}{}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\@ShipoutPicture}
% \changes{v0.8}{2002/01/21}{Compatibility with the \clsname{memoir} class 
%    (suggested by Andreas Matthias).}
% \changes{v0.9}{2002/07/27}{Compatibility with the \pkgname{crop} package 
%   (better test of \clsname{memoir}).}
% \changes{v0.9}{2002/07/27}{\cmd{\nointerlineskip} prevents a small vertical 
%  misplacement (suggested by Stephan Lehmke)}
% \changes{v1.0b}{2002/10/23}{A new hook \cmd\ESO@HookIII for special 
%    purpose (suggested by D. P. Story).}
%    \begin{macrocode}
\newcommand{\@ShipoutPicture}{%
  \bgroup
    \@tempswafalse%
    \ifx\ESO@HookI\@empty\else\@tempswatrue\fi%
    \ifx\ESO@HookII\@empty\else\@tempswatrue\fi%
    \ifx\ESO@HookIII\@empty\else\@tempswatrue\fi%
    \if@tempswa%
      \@tempdima=1in\@tempdimb=-\@tempdima%
      \advance\@tempdimb\paperheight%     
      \ESO@isMEMOIR{%
        \advance\@tempdima\trimedge%
        \advance\@tempdima\paperwidth%
        \advance\@tempdima-\stockwidth%
        \if@twoside\ifodd\c@page\else%
          \advance\@tempdima-2\trimedge%
          \advance\@tempdima-\paperwidth%
          \advance\@tempdima\stockwidth%
        \fi\fi%
        \advance\@tempdimb\trimtop}%
      \unitlength=1pt%
      \global\setbox\@cclv\vbox{%
        \vbox{%
          \let\protect\relax
          \pictur@(0,0)(\strip@pt\@tempdima,\strip@pt\@tempdimb)%  
            \ESO@HookIII\ESO@HookI\ESO@HookII%
            \global\let\ESO@HookII\@empty%
          \endpicture}%         
          \nointerlineskip%
        \box\@cclv%
      }%
    \fi
  \egroup
}
%    \end{macrocode}
% \end{macro}
%    \begin{macrocode}
\EveryShipout{\@ShipoutPicture}
%    \end{macrocode}
%
% \Finale
\endinput
