
% overpic.sty -- Rolf Niepraschk, niepraschk@ptb.de

\def\fileversion{v0.5}
\def\filedate{1997/11/22}

\ProvidesPackage{overpic}
    [\filedate\space\fileversion\space\space Overwriting eps pictures]  
                  
\NeedsTeXFormat{LaTeX2e}

\typeout{Package: overpic \fileversion\space <\filedate> (RN)}

\newcommand\OVP@scale{}

\DeclareOption{percent}{\renewcommand\OVP@scale{100}}
\DeclareOption{permil}{\renewcommand\OVP@scale{\@m}}
\DeclareOption{abs}{\renewcommand\OVP@scale{\z@}}

\DeclareOption*{\PassOptionsToPackage{\CurrentOption}{graphicx}}

\ExecuteOptions{percent}

\ProcessOptions

\RequirePackage{graphicx,epic}

\newif\ifGin@grid 

\define@key{Gin}{grid}[true]{\lowercase{\Gin@boolkey{#1}}{grid}}
\define@key{Gin}{tics}{\count@=#1}
\define@key{Gin}{unit}{\setlength\@tempdima{#1}}

\ifnum\OVP@scale>\z@%
  \ifnum\OVP@scale=\@m
    \typeout{overpic: relative positioning in permil}% 
  \else
    \typeout{overpic: relative positioning in percent}% 
  \fi  
  \newcommand\OVP@calc{%  
    \ifnum\@tempcnta>\@tempcntb%
      \divide\@tempcnta by \OVP@scale%
      \setlength\unitlength{\@tempcnta sp}% 
      \@tempcnta=\OVP@scale%
      \divide\@tempcntb by \unitlength%
    \else
      \divide\@tempcntb by \OVP@scale%
      \setlength\unitlength{\@tempcntb sp}%  
      \@tempcntb=\OVP@scale%
      \divide\@tempcnta by \unitlength%
    \fi%
    \ifnum\count@=\z@ 
      \count@=\OVP@scale\divide\count@ by 10%
    \fi%
  }%  
\else%           
  \typeout{overpic: absolute positioning in \unitlength}%
  \newcommand\OVP@calc{%
    \setlength\unitlength{\@tempdima}%
    \divide\@tempcnta by \unitlength%
    \divide\@tempcntb by \unitlength% 
    \ifnum\count@=\z@\count@=10\fi%  
  }%  
\fi  
 
\newenvironment{overpic}[2][]{%
  \sbox\z@{\includegraphics[#1]{#2}}%
  \settowidth \@tempcnta{\usebox\z@}%
  \settoheight\@tempcntb{\usebox\z@}%
  \setlength\@tempdima{\unitlength}%
  \count@=\z@\Gin@gridfalse\setkeys{Gin}{#1}% 
%
  \OVP@calc%
%  
  \begin{picture}(\@tempcnta,\@tempcntb)%
    \put(0,0){\usebox\z@}%
    \ifGin@grid%
      \put(0,0){\normalfont\fontsize\@viipt\@viiipt\selectfont%
        \grid(\@tempcnta,\@tempcntb)(\count@,\count@)[0,0]}%
    \fi%  
}{% 
  \end{picture}%
}

\endinput
