%
% \iffalse
%
%% graphicx.dtx Copyright (C) 1994 David Carlisle Sebastian Rahtz
%
%<package>\NeedsTeXFormat{LaTeX2e}
%<package>\ProvidesPackage{graphicx}
%<package>         [1994/05/30 v0.4b Enhanced LaTeX Graphics (DPC,SPQR)]
%
%<*driver>
\documentclass{ltxdoc}
\usepackage{graphicx}
\GetFileInfo{graphicx.sty}
\begin{document}
 \title{The \textsf{graphicx} package\thanks{This file
        has version number \fileversion, last
        revised \filedate.}}
 \author{D. P. Carlisle\and S. P. Q. Rahtz}
 \date{\filedate}
 \maketitle
 \DocInput{graphicx.dtx}
\end{document}
%</driver>
% \fi
%
% \CheckSum{376}
%
% \changes{v0.3}{1994/03/01}
%     {First DPC version (after prototype by SPQR).}
% \changes{v0.4b}{1994/05/30}
%     {Rename from egraphics. 8+3 name for CDROM}
%
% \def\oarg#1{{\ttfamily[}{\em#1\/}{\ttfamily]}}
% \def\arg#1{{\ttfamily\char`\{}{\em#1\/}{\ttfamily\char`\}}}
% \def\star{{\ttfamily*}}
% \makeatletter
% \def\Describe@Macro#1{\endgroup
%              \setbox0=\lastbox\llap{\PrintDescribeMacro{#1}}}%
% \makeatother
% \marginparsep0pt
%
% \maketitle
%
% \section{Introduction}
%
% This package provides an alternative interface to the \LaTeXe\
% graphics functions. The command names provided are the same as in the
% standard package, and they use the same internal functions. However
% the meaning of the optional arguments is different. Note \emph{only}
% the optional arguments have changed any document which only uses the
% graphics commands with the mandatory arguments and/or the star-forms
% will work identically (with essentially identical implementation) with
% the two packages.
%
% \section{KV Interface}
% something about key=value and why it isn't standard now, and should
% not be viewed as a prototype for \LaTeX3, which will almost certainly
% have a different concept of named arguments. It is a more robust
% implementation of a syntax long used by \LaTeX2.09 packages such as
% psfig and pstricks.
%
% \section{The User Interface}
%
% \DescribeMacro
%     \includegraphics\star\oarg{key-val list}\arg{file}\\
% Include a graphics file.
% 
% The possible keys are described below. The star form is just for
% compatibility with the standard interface, and essentially just adds
% |clip| to the keys specified.
%
% \DescribeMacro
%      \rotatebox\oarg{key-val list}\arg{text}\\
% Rotate \emph{text}.
%
% The possible keys are described below.
%
% \StopEventually{}
%
% \section{Implementation}
%
%    \begin{macrocode}
%<*package>
%    \end{macrocode}
%
%    \begin{macrocode}
\DeclareOption*{\PassOptionsToPackage\CurrentOption{graphics}}
%    \end{macrocode}
%
%    \begin{macrocode}
\ProcessOptions
%    \end{macrocode}
%
%    \begin{macrocode}
\RequirePackage{keyval,graphics}
%    \end{macrocode}
%
%
% \subsection{Graphics Inclusion}
%
% Various `keys' or named arguments are supported.
% \begin{description}
% \item[bb] The argument should be four dimensions, separated by spaces.
% If the units are omitted, |bp| are assumed.
% \item[angle] Rotation angle.
% \item[width] required width, a dimension (default units |bp|).
% \item[height] required height. a dimension (default units |bp|).
% \item[scale] scale factor.
% \item[clip] either `true' or `false' (or no value, which is equivalent
% to `true'). Clip the graphic to the bounding box.
% \item[draft] a boolean valued key, like `clip'. locally switches to
% draft mode.
% \end{description}
%
% Currently Only scaling by the same factor in both directions is
% supported. Surround the |\includegraphics| command in a |\resizebox|
% if you wish to change the aspect ratio.
%
% The arguments are interpreted left to right. |clip|, |draft|, |bb|,,
% and |llx| etc have the same effect wherever they appear. but the
% scaling and rotation keys interact.
%
% Any scaling that is specified \emph{before} rotation, is handled by
% the internal graphics inclusion function. rotation, or any later
% scaling is handled by implicitly calling |\rotatebox| or |\scalebox|.
% So |[height=1in,angle=90]| scales the graphic to 1in, then rotates it,
% so it is one inch wide. |[angle=90,height=1in]|  first rotates, then
% scales the result so that it is 1in high. A driver that can scale
% included graphics, but not arbitrary text will not be able to support
% the second form, as it will require a call to |\scalebox|, but the
% first form should work as there the scaling is handled by
% |\Ginclude@graphics|.
% \changes{v0.3b}{1994/03/11}{use bbllx not llx}
% \changes{v0.3b}{1994/03/11}{add natheight and natwidth}
%    \begin{macrocode}
\define@key{Gin}{bb}
           {\Gin@viewporttrue\Gread@parse@bb#1 \\}
\define@key{Gin}{bbllx}
           {\Gin@viewporttrue\@defaultunits\Gin@llx#1bp\relax\@nnil}
\define@key{Gin}{bblly}
           {\Gin@viewporttrue\@defaultunits\Gin@lly#1bp\relax\@nnil}
\define@key{Gin}{bburx}
           {\Gin@viewporttrue\@defaultunits\Gin@urx#1bp\relax\@nnil}
\define@key{Gin}{bbury}
           {\Gin@viewporttrue\@defaultunits\Gin@ury#1bp\relax\@nnil}
\define@key{Gin}{natwidth}
           {\Gin@viewporttrue\@defaultunits\Gin@urx#1bp\relax\@nnil
            \advance\Gin@urx\Gin@llx}
\define@key{Gin}{natheight}
           {\Gin@viewporttrue\@defaultunits\Gin@ury#1bp\relax\@nnil
            \advance\Gin@ury\Gin@lly}
%    \end{macrocode}
%
%    \begin{macrocode}
\define@key{Gin}{angle}
           {\Gin@esetsize
            \@tempswatrue
            \edef\@tempa{\toks@{\noexpand\rotatebox{#1}{\the\toks@}}}%
            \@tempa}
%    \end{macrocode}
%
%    \begin{macrocode}
\define@key{Gin}{width}{\def\Gin@ewidth{#1}}
\define@key{Gin}{height}{\def\Gin@eheight{#1}}
%    \end{macrocode}
%
%    \begin{macrocode}
\define@key{Gin}{scale}{%
  \if@tempswa
    \edef\@tempa{\toks@{\noexpand\Gscale@box{#1}[#1]{\the\toks@}}}%
    \@tempa
  \else
    \def\Gin@req@sizes{%
      \def\Gin@scalex{#1}\def\Gin@scaley{!}%
      \Gin@req@height\Gin@scalex\Gin@nat@height
      \Gin@req@width\Gin@scalex\Gin@nat@width}%
  \fi
  \@tempswatrue}
%    \end{macrocode}
%
%    \begin{macrocode}
\define@key{Gin}{draft}[true]{%
  \lowercase{\Gin@boolkey{#1}}{draft}}
%    \end{macrocode}
%
%    \begin{macrocode}
\define@key{Gin}{clip}[true]{%
  \lowercase{\Gin@boolkey{#1}}{clip}}
%    \end{macrocode}
%
% If you use `type' you must use no extension in the main argument
% and you must use `ext'. You can also use `read' and `command'.
%    \begin{macrocode}
\define@key{Gin}{type}{%
  \def\Ginclude@graphics##1{%
    \begingroup
    \def\Gin@base{##1\Gin@sep}%
    \edef\@tempa{{#1}{\Gin@eread}{\Gin@ecom{##1\Gin@sep\Gin@eext}}}%
    \expandafter\Gin@setfile\@tempa
    \endgroup}}
%    \end{macrocode}
%
% specify an extension, for use with the `type' key.
%    \begin{macrocode}
\define@key{Gin}{ext}{\def\Gin@eext{#1}}
%    \end{macrocode}
%
% specify a read file, for use with the `type' key.
%    \begin{macrocode}
\define@key{Gin}{read}{\def\Gin@eread{#1}}
\let\Gin@eread\@empty
%    \end{macrocode}
%
% specify a command, for use with the `type' key.
%    \begin{macrocode}
\define@key{Gin}{command}{\def\Gin@ecom##1{#1}}
\let\Gin@ecom\@firstofone
%    \end{macrocode}
%
%
% \begin{macro}{\Gin@boolkey}
% Helper function for defining boolean valued functions. The order of
% arguments allows |\lowercase| to only act on the user-supplied
% argument.
% \changes{v0.4a}{1994/04/14}{Make `empty'=true so clip= works}
%    \begin{macrocode}
\def\Gin@boolkey#1#2{%
  \csname Gin@#2\ifx\relax#1\relax true\else#1\fi\endcsname}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\Gin@esetsize}
%    \begin{macrocode}
\def\Gin@esetsize{%
  \def\@tempa{!}%
  \if@tempswa
%    \end{macrocode}
%  external 
%    \begin{macrocode}
    \edef\@tempa{\toks@{\noexpand
             \resizebox{\Gin@ewidth}{\Gin@eheight}{\the\toks@}}}%
    \@tempa   
  \else
%    \end{macrocode}
% internal
%    \begin{macrocode}
    \ifx\Gin@ewidth\@tempa
      \ifx\Gin@eheight\@tempa
%    \end{macrocode}
% no resizing
%    \begin{macrocode}
      \else
%    \end{macrocode}
% height set
%    \begin{macrocode}
         \let\Gin@@eheight\Gin@eheight
         \def\Gin@req@sizes{%
           \Gscale@div\Gin@scaley\Gin@@eheight\Gin@nat@height
           \def\Gin@scalex{!}%
           \Gin@req@height\Gin@@eheight
           \Gin@req@width\Gin@scaley\Gin@nat@width}%
      \fi
    \else
      \ifx\Gin@eheight\@tempa
%    \end{macrocode}
% width set
%    \begin{macrocode}
         \let\Gin@@ewidth\Gin@ewidth
         \def\Gin@req@sizes{%
           \Gscale@div\Gin@scalex\Gin@@ewidth\Gin@nat@width
           \def\Gin@scaley{!}%
           \Gin@req@width\Gin@@ewidth
           \Gin@req@height\Gin@scalex\Gin@nat@height}%
      \else
%    \end{macrocode}
% both set
%    \begin{macrocode}
         \let\Gin@@ewidth\Gin@ewidth
         \let\Gin@@eheight\Gin@eheight
         \def\Gin@req@sizes{%
           \Gscale@div\Gin@scalex\Gin@@ewidth\Gin@nat@width
           \Gscale@div\Gin@scaley\Gin@@eheight\Gin@nat@height
           \Gin@req@width\Gin@scalex\Gin@nat@width
           \Gin@req@height\Gin@scaley\Gin@nat@height}%
       \fi
     \fi
  \fi
  \def\Gin@ewidth{!}\let\Gin@eheight\Gin@ewidth}
%    \end{macrocode}
% \end{macro}
%
%    \begin{macrocode}
\newdimen\Gin@req@height
\newdimen\Gin@req@width
\let\Gin@outer@scalex\relax
\let\Gin@outer@scaley\relax
\let\Gin@angle\relax
\def\Gin@ewidth{!}\let\Gin@eheight\Gin@ewidth
\def\Gin@scalex{1}\def\Gin@scaley{!}%
%    \end{macrocode}
%
% \begin{macro}{\Gin@i}
% Use the same top level |\includegraphics| command as the standard
% interface. This will set the clipping switch, and then call |\Gin@i|.
% \changes{v0.3c}{1994/03/15}{Dont localy initialise width/height}
% \changes{v0.3c}{1994/03/15}{Always call \cmd{\Gin@ii}}
%    \begin{macrocode}
\def\Gin@i{%
 \def\Gin@req@sizes{%
   \Gin@req@height\Gin@nat@height
   \Gin@req@width\Gin@nat@width}%
 \@ifnextchar[\Gin@ii{\Gin@ii[]}}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\Gin@ii}
%  If an optional argument is present, call |\setkeys| to process it,
%    \begin{macrocode}
\def\Gin@ii[#1]#2{%
  \begingroup
    \@tempswafalse
    \toks@{\Ginclude@graphics{#2}}%
    \setkeys{Gin}{#1}%
    \Gin@esetsize
    \the\toks@
  \endgroup}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\Gin@iii}
% Not needed for the KV interface.
%    \begin{macrocode}
\let\Gin@iii\relax
%    \end{macrocode}
% \end{macro}
%
% \changes{v0.4b}{1994/05/06}
%     {Remove incorrect initialisation of \cs{Gin@scalex}}
%
% \section{Rotation}
%
% \begin{macro}{\rotatebox}
% Look for an optional argument.
% \changes{v0.3b}{1994/03/11}{Remove star form}
%    \begin{macrocode}
\def\rotatebox{%
  \@ifnextchar[\Grot@box@kv\Grot@box@std}
%    \end{macrocode}
% \end{macro}
%    
% \begin{macro}{\Grot@box@std}
% If no KV argument, just repeat the standard definition.
%    \begin{macrocode}
\def\Grot@box@std#1#2{%
  \Grot@setangle{#1}%
  \setbox\z@\hbox{{#2}}%
  \Grot@x\z@
  \Grot@y\z@
  \Grot@box}
%    \end{macrocode}
% \end{macro}
%    
% \begin{macro}{\Grot@box@kv}
%    \begin{macrocode}
\def\Grot@box@kv[#1]#2#3{%
  \@begin@tempboxa\hbox{#3}%
    \Grot@x\width \divide\Grot@x\tw@
    \Grot@y\height \advance\Grot@y-\depth \divide\Grot@y\tw@
    \setkeys{Grot}{#1}%
    \setbox\z@\box\@tempboxa
    \Grot@setangle{#2}%
    \Grot@box
  \@end@tempboxa}
%    \end{macrocode}
% \end{macro}
%    
%
% There are two ways of specifying the centre of rotation.
%
% |origin=|\meta{label}, where the labels are up to two of |lrctbB| 
% (|B| denotes the baseline, as for PSTricks).
%
% |x=|\meta{dimen}|,y=|\meta{dimen} The $x,y$ coordinate of the centre
% of rotation. As usual |\height| etc may be used.
%    \begin{macrocode}
\define@key{Grot}{origin}[c]{%
 \@tfor\@tempa:=#1\do{%
    \if l\@tempa \Grot@x\z@\else
    \if r\@tempa \Grot@x\width\else
    \if t\@tempa \Grot@y\height\else
    \if b\@tempa \Grot@y-\depth\else
    \if B\@tempa \Grot@y\z@\fi\fi\fi\fi\fi}}
\define@key{Grot}{x}{\setlength\Grot@x{#1}}
\define@key{Grot}{y}{\setlength\Grot@y{#1}}
%    \end{macrocode}
%
% `units' specifies the number or units in one anti-clockwise circle.
%  so the default is $360$. $-360$ gives clockwise rotation, $6.283185$
%  gives radians etc.
%    \begin{macrocode}
\define@key{Grot}{units}{%
  \def\Grot@setangle##1{%
  \dimen@##1\p@
  \dimen@ii#1\p@
  \divide\dimen@ii360\relax
  \divide\dimen@\dimen@ii
  \edef\Grot@angle{\number\dimen@}}}
%    \end{macrocode}
%
%    \begin{macrocode}
%</package>
%    \end{macrocode}
%
% \Finale
%
