%
% \iffalse
%
%% graphics.dtx Copyright (C) 1994 David Carlisle Sebastian Rahtz
%
%<package>\NeedsTeXFormat{LaTeX2e}
%<package>\ProvidesPackage{graphics}
%<package>         [1994/05/30 v0.4e Standard LaTeX Graphics (DPC,SPQR)]
%
%<*driver>
\documentclass{ltxdoc}
\usepackage{graphics}
\GetFileInfo{graphics.sty}
\begin{document}
 \title{The \textsf{graphics} package\thanks{This file
        has version number \fileversion, last
        revised \filedate.}}
 \author{D. P. Carlisle\and S. P. Q. Rahtz}
 \date{\filedate}
 \maketitle
 \DocInput{graphics.dtx}
\end{document}
%</driver>
% \fi
%
% \CheckSum{960}
%
% \changes{v0.3a}{1994/02/24}
%     {First DPC version (after prototype by SPQR).}
% \changes{v0.4e}{1994/05/30}
%     {Rename egraphics to graphicx}
%
%
% \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
%
% \section{Introduction}
%
% This package implements various `graphics' functions. The main
% features are a) inclusion of `graphics' files. b) Rotation of sections
% of the page, c) Scaling of sections of the page.
%
% The design is split into three `levels'.
% \begin{itemize}
% \item The user interface. This is the collection of commands designed
% to appear in a document text. Actually two separate user interface
% have been implemented. The `standard' interface, described here, and a
% more powerful, and more `user-friendly' interface provided by the
% |graphicx| package. 
% \item The core functions. These functions, which are also implemented
% in this file do all the `main work'. the `user-interface functions
% just collect together the information from any optional-arguments or
% star-forms, and then call one of these functions.
% \item The driver files. All the functionns provided by this package
% are not possible to achieve just using \TeX. The |dvi| driver used
% must be given additional instructions. (Using the |\special| command
% of \TeX.) Unfortunately, the capabilities of various drivers differ,
% and the syntax required to pass instructions to the derivers is also
% not standardised. So the `core functions' never acces |\special|
% directly, but rather call a series of commands that must be defined in
% a special file customised for each driver. The accompanying file,
% |drivers.dtx| has suitable files for a range of popular drivers.
% \end{itemize}
% \section{Standard Interface}
%
% \subsection{Graphics Inclusion}
%
% \DescribeMacro
%     \includegraphics\star\oarg{llx,lly}\oarg{urx,ury}\arg{file}\\
% Include a graphics file.
%
% If \star\ is present, then the graphic is `clipped' to the size
% specified. If \star\ is omitted, then any part  of the graphic that is
% outside the specified `bounding box' will  over-print the surrounding
% text.
%
% If the optional arguments are omitted, then the size of the graphic
% will be determined by reading an external file as described below.
% If \oarg{urx,ury} is present, then it should specify the coordinates
% of the top right corner of the image, as a pair of \TeX\ dimensions.
% If the units are ommited they default to |bp|. So |[1in,1in]| and
% |[72,72]| are equivalent. If only one optional argument appears, the
% lower left corner of the image is assumed to be at |[0,0]|. Otherwise
% \oarg{llx,lly} may be used to specify the cordinates of this point.
%
% \DescribeMacro
%    \graphicspath\arg{dir-list}\\
% This optional declaration may be used to specify a list of directories
% in which to search for graphics files. The format is as for the
% \LaTeXe\ primitive |\input@path|, a list of directories, each in a
% |{}| group (even if there is only one in the list). For example:
%  |\graphicspath{{eps/}{tiff/}}|
% would cause the system to look in the subdirectories |eps| and |tiff|
% of the current directory. The default setting of this path is
% |\input@path| that is: graphics files will be found wherever \TeX\
% files are found.
%
% \DescribeMacro
%   \DeclareGraphicsExtensions\oarg{sep}\arg{ext-list}\\
% This specifies the behaviour of the system when argument to
% |\includegraphics| does not have an extension specified.
% \arg{ext-list} should be a comma separated list of file extensions.
% A file name is produced by appending \emph{sep} and one extension.
% If a file is found, the system acts as if that extension had been
% specified. If not, the next extension in \emph{ext-list} is tried.
% The default value for \emph{sep} is the dot |.|.
%
% \DescribeMacro
% \DeclareGraphicsRule\arg{ext}\arg{type}\arg{read-file}\arg{command}\\
% Any number of these declarations can be made. they determine how the
% system behaves when a file with extension \emph{ext} is specified.
% (The extension may be specified explicitly or, if the argument to
% |\includegraphics| does not have an extension, it may be a default
% extension from the \emph{ext-list} specified with 
% |\DeclareGraphicsExtensions|.)
% 
% \emph{type} is the `type' of file involved. All files of the same type
% will be input with the same internal command (which must be defined in
% a `driver file'). For example files with extensions |ps|, |eps|,
% |ps.gz| may all be classed as type |eps|.
%
% \emph{read-file} determines the extension of the file that should be
% read to determine size information. It may be the same as \emph{ext}
% but it may be different, for example |ps.gz| files are not readable
% easily by \TeX, so you may want to put the bounding box information in
% a separate file with extension  |ps.bb|. If \emph{read-file} is empty,
% |{}|, then the system will not try to locate an external file for size
% info, and the size must be specified in the arguments of
% |\includegraphics|. If the driver file specifies a procedure for
% reading size files for \emph{type}, that will be used, otherwise the 
% procedure for reading |eps| files will be used. Thus the size of
% bitmap files may be specified in a file with a PostScript style
% |%%BoundingBox| line, if no other specific format is available.
%
% \emph{command} is usually empty, but if non empty it is used in place
% of the filename in the |\special|. Within this argument, |#1| may be
% used to denote the filename. Thus using the dvips driver, one may
% use\\
% |\DeclareGrahicsRule{ps.gz}{eps}{ps.bb}{`zcat #1}|\\
% the final argument causes dvips to use the |zcat| command to unzip the
% file before inserting it into the PostScript output.
%
% \subsection{Rotation}
% 
% \DescribeMacro
%   \rotatebox\arg{angle}\arg{text}\\
% Rotate \emph{text} \emph{angle} degrees anti-clockwise. Normally 
% the rotation is about the left-hand end of the baseline of
% \emph{text}.
%
% \subsection{Scaling}
%
% \DescribeMacro
%   \scalebox\arg{h-scale}\oarg{v-scale}\arg{text}\\
% Scale \emph{text} by the specified ammounts. If \emph{v-scale} is
% omitted, the vertical scale factor is the same as the horizontal one.
%
% \DescribeMacro
%   \resizebox\star\arg{h-length}\arg{v-length}\arg{text}\\
% Scale \emph{text} so that the width is \emph{h-length}.
% If |!| is used as either length argument, the other argument is used
% to determine a scale factor that is used in both directions.
% Normally \emph{v-length} refers to the height of the box, but in the
% star form, it refers to the `height +  depth'. 
% As normal for \LaTeXe\ box length arguments, |\height|,
% |\width|, |\totalheight|, |\depth| may be used to refer to the
% original size of the box.
%
% \StopEventually{}
%
% \section{The Graphics Kernel Functions}
%
% \subsection{Graphics Inclusion}
% 
% \DescribeMacro
%   {\Ginclude@graphics}\arg{file}\\
% Insert the contents of the file \emph{file} at the current point.
% |\Ginclude@macro| may use the four registers |\Gin@llx|, |\Gin@lly|,
% |\Gin@urx|, |\Gin@ury| to determine the `bounding box' of the graphic.
% The result will be a \TeX\ box of width $\mathit{urx}-\mathit{llx}$
% and height $\mathit{ury}-\mathit{lly}$. If |\Gin@clip| is \meta{true}
% then part of the graphic that is outside this box should not be
% displayed. (Not all drivers can support this `clipping'.) Normally all
% these parameters are set by the `user interface level'.
%
%
% \DescribeMacro
%   {\Gread@eps}\arg{file}
% For each \emph{type} of graphics file supported The driver file must
% define |\Ginclude@|\emph{type} and, optionally |\Gread@|\emph{type}.
% The read command is responsible for obtaining size information from
% the file specified in the |\DeclareGraphicsRule| command. However the
% kernel define a function which can read PoostScript files to find the
% |%%BoundingBox| comment. This function will be used for any type for
% which a specific function has not been declared. |\Gread@eps| accepts
% a generalised version of the bounding box comment. \TeX\ units may be
% used (but there must be no space before the unit). If the unit is
% omitted |bp| is assumed. So\\ 
% |%%BoundingBox 0 0 2in 3in|\\
% Would be accepted by this function, to produce a 2in wide, by 3in high
% graphic. 
%
% \subsection{Rotation}
%
% \DescribeMacro
%   {\Grot@box}\\
% Rotate the contents of |\box0| through |\Grot@angle| degrees
% (anti-clockwise). The user-interface is responsible for setting the
% macro |\Grot@angle|, and putting the appropriate text in |\Grot@box|.
%
% \subsection{Scaling}
%
% \DescribeMacro
%   {\Gscale@box}\arg{xscale}\oarg{yscale}\arg{text}\\
% (The second argument is not optional.)
% Scale \emph{text} by the appropriate scale factors.
%
% \DescribeMacro
%  {\Gscale@box@dd}\arg{dima}\arg{dimb}\arg{text}\\
% Scale \emph{text} in both directions by a factor
% \emph{dima}/\emph{dimb}. 
%
% \DescribeMacro
% {\Gscale@box@dddd}\arg{dima}\arg{dimb}\arg{dimc}\arg{dimd}\arg{text}\\
% Scale \emph{text} in horizontally by a factor \emph{dima}/\emph{dimb},
% and vertically by a factor of  \emph{dimc}/\emph{dimd}.
%
% \DescribeMacro
% {\Gscale@div}\arg{cmd}\arg{dima}\arg{dimb}\\
% Define the macro \emph{cmd} to be the ratio of the lengths
% \emph{dima}/\emph{dimb}. 
%
%
% \section{Interface to the Driver Files}
%
% \subsection{Graphics Inclusion}
%
% Each driver file must declare that its driver can include graphics of
% certain \emph{types}. It does this by declaring for each type a
% command of the form:\\
% |\Ginclude@|\emph{type}\\
% The Graphics kernel function will call this driver-defined function
% with the filename as argument, and certain additional information will
% be provided as follows.:
%
% \noindent\begin{tabular}{p{.4\textwidth}p{.4\textwidth}}
% |\Gin@llx|, |\Gin@lly|, |\Gin@urx|, |\Gin@ury| &Registers soring the
%      `bounding box'\\
% |\Gin@nat@width| |\Gin@nat@height| &
%               Registers storing the natural size.\\
% |\Gin@req@width| |\Gin@req@height| &
%               Registers storing the required size, after scaling.\\
% |\Gin@scalex|, |\Gin@scaley| & macros with the scale factors. A value
% of |!| means, scale by the same amount as the other direction.\\
% |\ifGin@clip| & |\newif| token, true if the graphic should be
%                 `clipped' to  the bounding box.
% \end{tabular}
%
% Optionally the driver may define a command of the form:\\
% |\Gread@|\emph{type}\\
% This is responsible for reading an external file to find the bounding
% box information. If such a command is not declared, but a read-file is
% specified the command |\Gread@eps|, which is defined in the Graphics
% Kernel will be used. 
%
% \subsection{Rotation}
%
% |\Grot@start|, |\Grot@end| These macros must be defined to insert the
% appropriate |\special| to rotate the text between them by
% |\Grot@angle| degrees. The kernel function will make sure that the
% correct \TeX\ spacing is produced, these functions only need insert
% the |\special|.
%
% \subsection{Scaling}
%
% |\Gscale@start|, |\Gscale@end|, as for rotation, but here scale the
% text by |\Gscale@x| and |\Gscale@y|.
%
%
% \section{Implementation}
%
% \changes{v0.4a}{1994/04/13}
%     {TEMP KLUDGE for Feb 94 release of 2e: 
%      define \cmd{\@addtofilelist}}
%    \begin{macrocode}
%<*package>
\def\@addtofilelist#1{%
  \xdef\@filelist{\@filelist,#1}}
%    \end{macrocode}
%
% \subsection{Initialisation}
%
% We will need to have an implementation of the trigonometric
% functions for the rotation feature. May as well load it now.
%    \begin{macrocode}
\RequirePackage{trig}
%    \end{macrocode}
%
%  \begin{macro}{\Grot@start}
%  \begin{macro}{\Grot@end}
% Initialise the rotation primitives.
%    \begin{macrocode}
\providecommand\Grot@start{\@latexerr{Rotation not supported}\@ehc
            \global\let\Grot@start\relax}
\providecommand\Grot@end{}
%    \end{macrocode}
%  \end{macro}
%  \end{macro}
%
%  \begin{macro}{\Grot@start}
%  \begin{macro}{\Grot@end}
% Initialise the scaling primitives.
%    \begin{macrocode}
\providecommand\Gscale@start{\@latexerr{Scaling not supported}\@ehc
            \global\let\Gscale@start\relax}
\providecommand\Gscale@end{}
%    \end{macrocode}
%  \end{macro}
%  \end{macro}
%
% \subsection{Options}
%
% \changes{v0.3c}{1994/03/04}
%     {dviwindo support.}
% \changes{v0.3g}{1994/03/15}
%     {Use dvips def file not development version}
%    \begin{macrocode}
\DeclareOption{dvips}{\input{dvips.def}}
%    \end{macrocode}
%
% \changes{v0.3i}{1994/3/23}
%     {notdraft option added}
% \changes{v0.4a}{1994/04/13}
%     {Rename option to nodraft}
% \changes{v0.4d}{1994/05/06}
%     {Rename option to final}
%    \begin{macrocode}
\newif\ifGin@draft
\DeclareOption{draft}{\Gin@drafttrue}
\DeclareOption{final}{\Gin@draftfalse}
%    \end{macrocode}
%    
%    \begin{macrocode}
\DeclareOption{dvgt}{\input{dvgt.def}}
\DeclareOption{dvi2ps}{\input{dvi2ps.def}}
\DeclareOption{dvialw}{\input{dvialw.def}}
\DeclareOption{dvilaser}{\input{dvilaser.def}}
\DeclareOption{dvipsone}{\input{dvipsone.def}}
\DeclareOption{dvitops}{\input{dvitops.def}}
\DeclareOption{dviwindo}{\input{dviwindo.def}}
\DeclareOption{dvitps}{\input{dvitps.def}}
\DeclareOption{emtex}{\input{emtex.def}}
\DeclareOption{dviwin}{\input{dviwin.def}}
\DeclareOption{oztex}{\input{oztex.def}}
\DeclareOption{psprint}{\input{psprint.def}}
\DeclareOption{pubps}{\input{pubps.def}}
\DeclareOption{textures}{\input{textures.def}}
%    \end{macrocode}
%
%    \begin{macrocode}
\DeclareOption{debug}{\catcode`\^^A=9 \let\GDebug\typeout}
\edef\GctrlA{\catcode`\noexpand\^^A\the\catcode`\^^A\relax}
\catcode`\^^A=\catcode`\%
%    \end{macrocode}
%
% A local configuration file may define more options.
%    \begin{macrocode}
\InputIfFileExists{graphics.cfg}{}
%    \end{macrocode}
%
% \changes{v0.4a}{1994/04/13}
%     {Rename option to hiderotate}
%    \begin{macrocode}
\DeclareOption{hiderotate}{%
  \def\Grot@start{\begingroup\setbox\z@\hbox\bgroup}
  \def\Grot@end{\egroup\endgroup}}
%    \end{macrocode}
%
% \changes{v0.4a}{1994/04/13}
%     {Rename option to hidescale}
%    \begin{macrocode}
\DeclareOption{hidescale}{%
  \def\Gscale@start{\begingroup\setbox\z@\hbox\bgroup}
  \def\Gscale@end{\egroup\endgroup}}
%    \end{macrocode}
%
%    \begin{macrocode}
\ProcessOptions
%    \end{macrocode}
%
%
% \subsection{Graphics Inclusion}
%
% This Graphics package uses a lot of dimension registers. \TeX\ only
% has a limited number of registers, so rather than allocate new ones,
% re-use some existing \LaTeX\ registers. This is safe as long as all
% uses of the registers are \emph{local}, and that you can be sure
% that you \emph{never} need to have access to both uses within the
% same scope.
%    \begin{macrocode}
\let\Gin@llx\leftmargini
\let\Gin@lly\leftmarginii
\let\Gin@urx\leftmarginiii
\let\Gin@ury\leftmarginiv
\let\Gin@nat@width\leftmarginv
\let\Gin@nat@height\leftmarginvi
%    \end{macrocode}
%
%  \begin{macro}{\ifGin@clip}
% This switch is \meta{true} if any graphics outside the specified
% bounding box (viewport) should not be printed.
%    \begin{macrocode}
\newif\ifGin@clip
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\DeclareGraphicsExtensions}
% Declare a comma separated list of default extensions to be used
% If the file is specified with no extension. The default argument
% allows an alternative to |.| to be used as the separator before the
%    extension.
%    \begin{macrocode}
\newcommand\DeclareGraphicsExtensions[2][.]{%
  \def\Gin@sepdefault{#1}%
  \def\Gin@extensions{#2}}
%    \end{macrocode}
% \end{macro}
%
%  \begin{macro}{\Gin@extensions}
% Initialise the list of possible extensions.
% \changes{v0.4b}{1994/04/20}
%     {Use \cmd{\providecommand} in case a previous def file has
%     already defined it}
%    \begin{macrocode}
\providecommand\Gin@extensions{}
%    \end{macrocode}
%  \end{macro}
%
% \begin{macro}{\includegraphics}
% Top level command for the standard interface, just look for a |*|.
%    \begin{macrocode}
\def\includegraphics{%
  \@ifstar
    {\Gin@cliptrue\Gin@i}%
    {\Gin@clipfalse\Gin@i}}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\Gin@i}
%  If an optional argument is present, call |\Gin@ii| to process it,
%    otherwise call |\Ginclude@graphics|.
% \changes{v0.3e}{1994/03/09}
%     {Now specify ll before ur coordinate}
%    \begin{macrocode}
\def\Gin@i{%
  \@ifnextchar[%]
    {\Gin@viewporttrue\Gin@ii}
    {\Gin@viewportfalse\Ginclude@graphics}}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\Gin@ii}
% Look for a second optional argument.
%    \begin{macrocode}
\def\Gin@ii[#1,#2]{%
  \@ifnextchar[%]
    {\Gin@iii[#1,#2]}
    {\Gin@iii[\z@,\z@][#1,#2]}}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\Gin@iii}
% Set the cordinates of the {\bfseries l}lower {\bfseries l}eft corner,
% and the cordinates of the {\bfseries u}pper {\bfseries r}ight
% corner. The cordinates may be any \TeX\ dimension, defaulting to |bp|.
%    \begin{macrocode}
\def\Gin@iii[#1,#2][#3,#4]{%
  \@defaultunits\Gin@llx#1bp\relax\@nnil
  \@defaultunits\Gin@lly#2bp\relax\@nnil
  \@defaultunits\Gin@urx#3bp\relax\@nnil
  \@defaultunits\Gin@ury#4bp\relax\@nnil
  \Ginclude@graphics}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\DeclareGraphicsRule}
% Declare what actions should be taken for a particular file
% extension.
%
%  |#1| extension, |#2| type, |#3| read-file, |#4| command,
%    \begin{macrocode}
\def\DeclareGraphicsRule#1#2#3#4{%
  \expandafter\edef\csname Gin@rule@#1\endcsname##1%
       {{#2}{#3}{\ifx\indent#4\indent##1\else#4\fi}}}
%    \end{macrocode}
% \end{macro}
%
% An example rule base.
%\begin{verbatim}
%                    ext    type  read  command
% \DeclareGrahicsRule{ps}   {eps} {ps}    {}
% \DeclareGrahicsRule{eps}  {eps} {eps}   {}
% \DeclareGrahicsRule{ps.gz}{eps} {ps.bb} {`zcat #1}
% \DeclareGrahicsRule{pcx}  {bmp} {}      {}
%\end{verbatim}
%
% \begin{macro}{\graphicspath}
% User level command to set the input path for graphics files.
% A list of directories, each in a |{}| group.
%    \begin{macrocode}
\def\graphicspath#1{\def\Ginput@path{ #1}}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\Ginput@path}
% The default graphic path is |\input@path|.
%    \begin{macrocode}
\ifx\Ginput@path\@undefined
  \let\Ginput@path\input@path
\fi
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\Gin@getbase}
% Given a possible extension, |#1|, check whether the file exists. If
% it does set |\Gin@base| and |\Gin@ext| to the filename stripped of
% the extension, and the extension, respectively.
%    \begin{macrocode}
\def\Gin@getbase#1{%
  \edef\Gin@tempa{%
    \def\noexpand\@tempa####1#1\space{%
      \def\noexpand\Gin@base{####1}}}%
  \IfFileExists{\filename@area\filename@base\Gin@sep#1}%
    {\Gin@tempa
     \expandafter\@tempa\@filef@und
     \edef\Gin@ext{#1}}{}}%
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\Gin@ext}
% Initialise the macro to hold the extension.
%    \begin{macrocode}
\let\Gin@ext\relax
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\Gin@sep}
% Initialise the macro to hold the separator.
%    \begin{macrocode}
\def\Gin@sep{.}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\Ginclude@grapics}
%  The main internal function implementing graphics file inclusion.
%  |#1| is the file name.
% \changes{v0.4c}{1994/04/28}
%     {Improve the wording of error messages}
%    \begin{macrocode}
\def\Ginclude@graphics#1{%
  \begingroup
  \let\input@path\Ginput@path
  \filename@parse{#1}%
  \ifx\filename@ext\relax
    \let\Gin@sep\Gin@sepdefault
    \@for\Gin@temp:=\Gin@extensions\do{%
      \ifx\Gin@ext\relax
        \Gin@getbase\Gin@temp
      \fi}%
  \else
    \Gin@getbase\filename@ext
%    \end{macrocode}
% \changes{v0.4d}{1994/05/06}
%     {Make file not found a warning not an error}
% If the user supplied an explicit extension, just give a warning if the
% file does not exist. (It may be created later.)
%    \begin{macrocode}
    \ifx\Gin@ext\relax
       \@warning{File `#1' not found}%
       \def\Gin@base{\filename@area\filename@base\Gin@sep}%
       \let\Gin@ext\filename@ext
    \fi
  \fi
%    \end{macrocode}
% If no extension is supplied, it is an error if the file does not
% exist, as there is no way for the system to know which extension to
% supply.
%    \begin{macrocode}
    \ifx\Gin@ext\relax
         \@latexerr{File `#1' not found}%
         {I could not locate the file with any of these extensions:^^J%
          \Gin@extensions^^J\@ehc}%
    \else
       \@ifundefined{Gin@rule@\Gin@ext}%
         {\@latexerr{Unknown graphics extension: \Gin@ext}\@ehc}%
         {\expandafter\expandafter\expandafter\Gin@setfile
              \csname Gin@rule@\Gin@ext\endcsname{\Gin@base\Gin@ext}}%
    \fi
  \endgroup}
%    \end{macrocode}
% \end{macro}
%
%    \begin{macrocode}
\newif\ifGread@\Gread@true
%    \end{macrocode}
%
% \begin{macro}{\Gin@setfile}
% Set a file to the size specified in arguments, or in a `read file'.
%    \begin{macrocode}
\def\Gin@setfile#1#2#3{%
  \ifx\\#2\\\Gread@false\fi
  \ifGin@viewport\else\ifGread@
    \csname Gread@%
       \ifx\csname Gread@#1\endcsname\relax
         eps%
       \else
         #1%
       \fi
    \endcsname{\Gin@base#2}%
  \fi\fi
  \Gin@nat@height\Gin@ury\advance\Gin@nat@height-\Gin@lly
  \Gin@nat@width\Gin@urx\advance\Gin@nat@width-\Gin@llx
  \Gin@req@sizes
  \expandafter\ifx\csname Ginclude@#1\endcsname\relax
    \Gin@drafttrue
    \expandafter\ifx\csname Gread#1\endcsname\relax
      \@latexerr{Can not include graphics of type: #1}\@ehc
      \global\expandafter\let\csname Gread#1\endcsname\@empty
    \fi
  \fi
  \leavevmode
  \ifGin@draft
      \hbox to \Gin@req@width{%
        \vrule\hss
        \vbox to \Gin@req@height{%
           \hrule \@width \Gin@req@width
           \vss
           \edef\@tempa{#3}%
           \rlap{ \ttfamily\expandafter\strip@prefix\meaning\@tempa}%
           \vss
           \hrule}%
        \hss\vrule}%
  \else
%    \end{macrocode}
% \changes{v0.3i}{1994/3/23}
%     {Add file list info}
%    \begin{macrocode}
    \@addtofilelist{#3}%
    \ProvidesFile{#3}[Graphic file (type #1)]%
    \setbox\z@\hbox{\csname Ginclude@#1\endcsname{#3}}%
    \dp\z@\z@
    \ht\z@\Gin@req@height
    \wd\z@\Gin@req@width
  \box\z@
  \fi}
%    \end{macrocode}
% \end{macro}
%
%
%  \begin{macro}{\Gin@req@sizes}
% In the standard interface there is no scaling, so the required size
% is the same as the natural size. In other interfaces |\Gin@req@sizes|
% will be responsible for setting these parameters. Here we can set them
% globally.
% \changes{v0.3g}{1994/03/15}
%     {Initialise y-scale to !}
%    \begin{macrocode}
\let\Gin@req@sizes\relax
\def\Gin@scalex{1}%
\def\Gin@scaley{!}%
\let\Gin@req@height\Gin@nat@height
\let\Gin@req@width\Gin@nat@width
%    \end{macrocode}
%  \end{macro}
%
% \subsection{Reading the BoundingBox in EPS files}
%
% \begin{macro}{\ifGin@viewport}
% This switch should be set \meta{true} once a size has been found,
% either in an argument, or in an external file.
%    \begin{macrocode}
\newif\ifGin@viewport
%    \end{macrocode}
%  \end{macro}
%
% \begin{macro}{\Gread@eps}
% Read an EPS file (|#1|) and search for a line
% starting with |%%BoundingBox| and returns the result
% by setting four dimension registers
% |\Gin@llx|, |\Gin@lly|, |\Gin@urx| and |\Gin@ury|.
%    \begin{macrocode}
\def\Gread@eps#1{%
  \begingroup
  \let\do\@makeother\dospecials\catcode`\ 10 %
%    \end{macrocode}
% The first thing we need to do is to open the
% information file, if possible.
% \changes{v0.4d}{1994/05/06}
%     {Improve the error message if the info file is not there.}
%    \begin{macrocode}
  \immediate\openin\@inputcheck#1 %
  \ifeof\@inputcheck
    \@latexerr{File `#1' not found}\@ehc
  \else
%    \end{macrocode}
% Now we'll scan lines until we find one that starts with
% |%%BoundingBox:|
% We need to reset the catcodes to read the file, and so this
% is done in a group.
%    \begin{macrocode}
     \Gread@true
     \let\@tempb\Gread@false
     \loop
       \read\@inputcheck to\@tempa
       \ifeof\@inputcheck
         \Gread@false
       \else
         \expandafter\Gread@find@bb\@tempa:.\\%
       \fi
     \ifGread@
     \repeat
    \immediate\closein\@inputcheck
  \fi
%    \end{macrocode}
% \changes{v0.3i}{1994/03/23}
%     {Wording of error message improved}
%    \begin{macrocode}
  \ifGin@viewport\else
    \@latexerr
      {Cannot determine size of graphic in #1 (no BoundingBox).}%
      \@ehc
    \gdef\g@tempa{0 0 72 72 }%
  \fi
  \endgroup
  \expandafter\Gread@parse@bb\g@tempa\\}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\Gread@find@bb}
% If a line in the EPS file starts with a |%%BoundingBox:|, we
% will examine it more closely. Note using the `extra' argument |#2#3|
% causes any space after the |:| to be gobbled.
%    \begin{macrocode}
\long\def\Gread@find@bb#1:#2#3\\{%
  \def\@tempa{#1}%
  \ifx\@tempa\Gread@BBox
    \Gread@test@atend#2#3()\\%
  \fi}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\Gread@test@atend}
% Determine if the stuff following the |%%BoundingBox| is `(atend)',
% which will involve further reading of the file. This is accomplished
% by making |\@tempb| into a no-op, so that finding a |%%BoundingBox|
% does not stop the loop.
%    \begin{macrocode}
\def\Gread@test@atend#1(#2)#3\\{%
  \def\@tempa{#2}%
  \ifx\@tempa\Gread@atend
    \Gread@true
    \let\@tempb\relax
  \else
    \gdef\g@tempa{#1}%
    \@tempb
    \Gin@viewporttrue
  \fi}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\Gread@parse@bb}
% We have |%%BoundingBox| and what follows is not `(atend)' so we
% will parse the rest of the line as a BB with four elements.
% PostScript files should never have units specified in the
% BoundingBox comment, but we allow arbitrary \TeX\ units in external
% files, or in other interfaces.
%    \begin{macrocode}
\def\Gread@parse@bb#1 #2 #3 #4 #5\\{%
  \@defaultunits\Gin@llx#1bp\relax\@nnil
  \@defaultunits\Gin@lly#2bp\relax\@nnil
  \@defaultunits\Gin@urx#3bp\relax\@nnil
  \@defaultunits\Gin@ury#4bp\relax\@nnil}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\Gread@atend}
% |atend| as a macro for testing with |\ifx|.
%    \begin{macrocode}
\def\Gread@atend{atend}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\Gread@BBox}
% |%%BoundingBox| as a macro for testing with |\ifx|.
%    \begin{macrocode}
\edef\Gread@BBox{\@percentchar\@percentchar BoundingBox}
%    \end{macrocode}
% \end{macro}
%
%
% \subsection{Rotation}
%
% As above, we will re-use some existing local registers.
%    \begin{macrocode}
\let\Grot@height\@ovxx
\let\Grot@left\@ovyy
\let\Grot@right\@ovdx
\let\Grot@depth\@ovdy
\let\Grot@l\@ovro
\let\Grot@r\@ovri
\let\Grot@h\@xdim
\let\Grot@d\@ydim
\let\Grot@x\@linelen
\let\Grot@y\@dashdim
%    \end{macrocode}
%
% \begin{macro}{\rotatebox}
% The angle is specified by |#1|. The box to be rotated is |#2|.
% In the standard interface the centre of rotation is $(0,0)$.
% Then finally call |\Grot@box| to rotate the box.
% \changes{v0.3f}{1994/03/11}{Remove star form}
% \changes{v0.3h}{1994/03/17}{Fix Typo}
%    \begin{macrocode}
\def\rotatebox#1#2{%
  \Grot@setangle{#1}%
  \setbox\z@\hbox{{#2}}%
  \Grot@x\z@
  \Grot@y\z@
  \Grot@box}
%    \end{macrocode}
% \end{macro}
%
%
% \begin{macro}{\Grot@setangle}
% Set the internal macro used by |\Grot@box|. In the standard
% interface this is trivial, but other interfaces may have more
% interesting definitions. For example:
%\begin{verbatim}
% \def\Grot@setangle#1{%
%   \dimen@#1\p@
%   \dimen@-57.2968\dimen@
%   \edef\Grot@angle{\strip@pt\dimen@}}
%\end{verbatim}
% This would cause the argument of |\rotatebox| to be interpreted as
% an angle specified in \emph{radians}, \emph{clockwise}.
%    \begin{macrocode}
\def\Grot@setangle#1{\edef\Grot@angle{#1}}
%    \end{macrocode}
% \end{macro}
%
% \subsection{Deriving a `bounding box' for rotated object}
% We want to know the size of a `bounding box' enclosing the rotated
% box.
% We define two formulae (as \TeX\ macros) to work out the $x$ and $y$
% coordinates of vertices of the rotated box
% in relation to its original coordinates (ie its width, height
% and depth). The box we visualize with vertices $B$, $C$,
% $D$ and $E$ is illustrated below. The vertex
% $S$ is the reference point on the baseline. $O$ is the centre of
% rotation, which in the standard interface is always either $S$ or $A$.
%
% \begin{center}
% \setlength{\unitlength}{3pt}%
%
% \begin{picture}(34,36)(12,44)
% \thicklines
% \put(20,52){\dashbox{1}(20,21){}}
% \put(20,80){\line(0,-1){36}}
% \put(12,58){\line(1, 0){34}}
% \put(41,59){A}
% \put(40,74){B}
% \put(21,74){C}
% \put(21,49){D}
% \put(40,49){E}
% \put(21,59){S}
% \put(33,65){O}
% \put(33,65){\circle*{1}}
% \end{picture}
% \end{center}
%
% The formulae are, for a point $P$ and angle $\alpha$:
%\[
% \begin{array}{l}
% P'_x = P_x - O_x \\
% P'_y = P_y - O_y \\
% P''_x =  ( P'_x \times \cos(\alpha)) - ( P'_y \times \sin(\alpha) ) \\
% P''_y =  ( P'_x \times \sin(\alpha)) + ( P'_y \times \cos(\alpha) ) \\
% P'''_x = P''_x + O_x + L_x \\
% P'''_y = P''_y + O_y
% \end{array}
% \]
% The `extra' horizontal translation $L_x$ at the end is calculated so
% that the leftmost point of the resulting box has $x$-coordinate $0$.
% This is desirable as \TeX\ boxes must have the reference point at
% the left edge of the box.
%
% \begin{macro}{\Grot@Px}
% Work out new $x$ coordinate of point after rotation. The parameters
% |#2| and |#3| are the original $x$ and $y$ coordinates of the point.
% The new $x$ coordinate is stored in |#1|.
%    \begin{macrocode}
\def\Grot@Px#1#2#3{%
        #1\Grot@cos#2%
        \advance#1-\Grot@sin#3}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\Grot@Py}
% Work out new $y$ coordinate of point after rotation. The parameters
% |#2| and |#3| are the original $x$ and $y$ coordinates of the point.
% The new $y$ coordinate is stored in |#1|.
%    \begin{macrocode}
\def\Grot@Py#1#2#3{%
        #1\Grot@sin#2%
        \advance#1\Grot@cos#3}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\Grot@findenclose}
% This is the tricky bit. We can rotate the box, but then need
% to work out how much space to leave for it on the page.
%
% We simplify matters by working out first which quadrant we are in, and
% then picking just the right values.
%
%    \begin{macrocode}
\def\Grot@box{%
  \begingroup
%    \end{macrocode}
% We are going to need to know the sine and cosine
% of  the angle; simplest to calculate these now.
%    \begin{macrocode}
  \CalculateSin\Grot@angle
  \CalculateCos\Grot@angle
  \edef\Grot@sin{\UseSin\Grot@angle}%
  \edef\Grot@cos{\UseCos\Grot@angle}%
^^A   \GDebug{Rotate: angle \Grot@angle, sine is \Grot@sin,
^^A             cosine is \Grot@cos}%
%    \end{macrocode}
% Save the four extents of the original box.
%    \begin{macrocode}
  \Grot@r\wd\z@  \advance\Grot@r-\Grot@x
  \Grot@l\z@     \advance\Grot@l-\Grot@x
  \Grot@h\ht\z@  \advance\Grot@h-\Grot@y
  \Grot@d-\dp\z@ \advance\Grot@d-\Grot@y
%    \end{macrocode}
% Now a straightforward test to see which quadrant we are
% operating in;
%    \begin{macrocode}
  \ifdim\Grot@sin\p@>\z@
    \ifdim\Grot@cos\p@>\z@
%    \end{macrocode}
% First quadrant:
% Height=$By$, Right=$Ex$, Left=$Cx$, Depth=$Dy$
%    \begin{macrocode}
      \Grot@Py\Grot@height \Grot@r\Grot@h%B
      \Grot@Px\Grot@right  \Grot@r\Grot@d%E
      \Grot@Px\Grot@left   \Grot@l\Grot@h%C
      \Grot@Py\Grot@depth  \Grot@l\Grot@d%D
    \else
%    \end{macrocode}
% Second quadrant:
% Height=$Ey$, Right=$Dx$, Left=$Bx$, Depth=$Cy$
%    \begin{macrocode}
      \Grot@Py\Grot@height \Grot@r\Grot@d%E
      \Grot@Px\Grot@right  \Grot@l\Grot@d%D
      \Grot@Px\Grot@left   \Grot@r\Grot@h%B
      \Grot@Py\Grot@depth  \Grot@l\Grot@h%C
    \fi
  \else
    \ifdim\Grot@cos\p@<\z@
%    \end{macrocode}
% Third quadrant:
% Height=$Dy$, Right=$Cx$, Left=$Ex$, Depth=$By$
%    \begin{macrocode}
      \Grot@Py\Grot@height \Grot@l\Grot@d%D
      \Grot@Px\Grot@right  \Grot@l\Grot@h%C
      \Grot@Px\Grot@left   \Grot@r\Grot@d%E
      \Grot@Py\Grot@depth  \Grot@r\Grot@h%B
    \else
%    \end{macrocode}
% Fourth quadrant:
% Height=$Cy$, Right=$Bx$, Left=$Dx$, Depth=$Ey$
%    \begin{macrocode}
      \Grot@Py\Grot@height \Grot@l\Grot@h%C
      \Grot@Px\Grot@right  \Grot@r\Grot@h%B
      \Grot@Px\Grot@left   \Grot@l\Grot@d%D
      \Grot@Py\Grot@depth  \Grot@r\Grot@d%E
    \fi
  \fi
%    \end{macrocode}
% Now we should translate back by $(O_x,O_y)$, but \TeX\ can not really
% deal with boxes that do not have the reference point at the left edge.
% (Everything with a $-$ve $x$-coordinate would over-print earlier
% text). So we modify the horizontal translation so that the 
% reference point as understood by \TeX\ \emph{is} at the left edge.
% This means that the `centre of rotation' is not fixed by |\rotatebox|,
% but typically moves horizontally. We also need to find the image of
% the original reference point, $S$, as that is where the rotation
% specials must be inserted.
%
%    \begin{macrocode}
  \advance\Grot@height\Grot@y
  \advance\Grot@depth\Grot@y
  \Grot@Px\dimen@  \Grot@x\Grot@y
  \Grot@Py\dimen@ii \Grot@x\Grot@y
  \dimen@-\dimen@     \advance\dimen@-\Grot@left
  \dimen@ii-\dimen@ii \advance\dimen@ii\Grot@y
%    \end{macrocode}
%
%    \begin{macrocode}
^^A   \GDebug{Rotate: (l,r,h,d)^^J%
^^A Original \the\Grot@l,\the\Grot@r,\the\Grot@h,\the\Grot@d,^^J%
^^A New..... \the\Grot@left,\the\Grot@right,%
^^A          \the\Grot@height,\the\Grot@depth}%
%    \end{macrocode}
%
%    \begin{macrocode}
  \setbox\z@\hbox{%
    \kern\dimen@
    \raise\dimen@ii\hbox{\Grot@start\box\z@\Grot@end}}%
  \ht\z@\Grot@height
  \dp\z@-\Grot@depth
  \advance\Grot@right-\Grot@left\wd\z@\Grot@right
  \leavevmode\box\z@
  \endgroup}
%    \end{macrocode}
% \end{macro}
%
%
% \subsection{Stretching and Scaling}
%
%
%  \begin{macro}{\scalebox}
% The top level |\scalebox|. If the vertical scale factor is omitted it
% defaults to the horizontal scale factor, |#1|.
% \changes{v0.3d}{1994/03/06}{Better support for negative arguments.}
%    \begin{macrocode}
\def\scalebox#1{%
  \@ifnextchar[{\Gscale@box{#1}}{\Gscale@box{#1}[#1]}}
%    \end{macrocode}
%  \end{macro}
%
%  \begin{macro}{\Gscale@box}
% Internal version of |\scalebox|.
%    \begin{macrocode}
\def\Gscale@box#1[#2]#3{%
  \def\Gscale@x{#1}\def\Gscale@y{#2}%
  \setbox\z@\hbox{{#3}}%
  \setbox\tw@\hbox{\Gscale@start\rlap{\copy\z@}\Gscale@end}%
  \leavevmode
  \ifdim#2\p@<\z@
    \ht\tw@-#2\dp\z@
    \dp\tw@-#2\ht\z@
  \else
    \ht\tw@#2\ht\z@
    \dp\tw@#2\dp\z@
  \fi
  \ifdim#1\p@<\z@
    \hbox to -#1\wd\z@{\kern-#1\wd\z@\box\tw@\hss}%
  \else
    \wd\tw@#1\wd\z@
    \box\tw@
  \fi}
%    \end{macrocode}
%  \end{macro}
%
%
%  \begin{macro}{\reflectbox}
% Just an abbreviation for the appropriate scale to get relection.
% \changes{v0.3e}{1994/03/09}{Macro added}
%    \begin{macrocode}
\def\reflectbox{\Gscale@box-1[1]}
%    \end{macrocode}
%  \end{macro}
%
%
%  \begin{macro}{\resizebox}
% \changes{v0.3b}{1994/03/01}{Recode \cmd\resizebox.}
% Look for a |*|, which specifies that a final vertical size refers to
% `height + depth' not just `height'.
%    \begin{macrocode}
\def\resizebox{%
  \@ifstar{\Gscale@@box\totalheight}{\Gscale@@box\height}}
%    \end{macrocode}
%  \end{macro}
%
%  \begin{macro}{\Gscale@@box}
% Look for the |!| in the arguments.
%    \begin{macrocode}
\def\Gscale@@box#1#2#3{%
  \def\@tempa{!}%
  \def\@tempb{#2}%
  \def\@tempc{#3}%
  \ifx\@tempb\@tempa
    \ifx\@tempc\@tempa
      \toks@{\mbox}%
    \else
      \toks@{\Gscale@box@dd{#3}#1}%
    \fi
  \else
    \ifx\@tempc\@tempa
      \toks@{\Gscale@box@dd{#2}\width}%
    \else
      \toks@{\Gscale@box@dddd{#2}\width{#3}#1}%
    \fi
  \fi
  \the\toks@}
%    \end{macrocode}
%  \end{macro}
%
%  \begin{macro}{\Gscale@box@dd}
% Scale the text |#3| in both directions by a factor $|#1|/|#2|$.
% \changes{v0.3i}{1994/03/23}
%     {Missing percent added}
%    \begin{macrocode}
\def\Gscale@box@dd#1#2#3{%
  \@begin@tempboxa\hbox{#3}%
    \setlength\@tempdima{#1}%
    \setlength\@tempdimb{#2}%
    \Gscale@div\@tempa\@tempdima\@tempdimb
    \Gscale@box\@tempa[\@tempa]{\box\@tempboxa}%
  \@end@tempboxa}
%    \end{macrocode}
%  \end{macro}
%
%  \begin{macro}{\Gscale@box@dddd}
% Scale the text |#5| horizontally by a factor $|#1|/|#2|$ and
% vertically by a factor $|#3|/|#4|$.
% \changes{v0.3i}{1994/03/23}
%     {Missing percent added}
%    \begin{macrocode}
\def\Gscale@box@dddd#1#2#3#4#5{%
  \@begin@tempboxa\hbox{#5}%
    \setlength\@tempdima{#1}%
    \setlength\@tempdimb{#2}%
    \Gscale@div\@tempa\@tempdima\@tempdimb
    \setlength\@tempdima{#3}%
    \setlength\@tempdimb{#4}%
    \Gscale@div\@tempb\@tempdima\@tempdimb
    \Gscale@box\@tempa[\@tempb]{\box\@tempboxa}%
  \@end@tempboxa}
%    \end{macrocode}
%  \end{macro}
%
%  \begin{macro}{\Gscale@div}
% The macro |#1| is set to the ratio of the lengths |#2| and |#3|.
%    \begin{macrocode}
\def\Gscale@div#1#2#3{%
 \dimen@#3\edef\@tempd{\the\dimen@}%
 \dimen@#2\relax
 \count@65536\relax
 \ifdim\dimen@<\z@
  \dimen@-\dimen@
  \count@-\count@
 \fi
 \loop
 \ifdim\dimen@<8192\p@
   \dimen@\tw@\dimen@
   \divide\count@\tw@
 \repeat
 \dimen@ii=\@tempd\relax
 \divide\dimen@ii\count@
 \divide\dimen@\dimen@ii
 \edef#1{\strip@pt\dimen@}}
%    \end{macrocode}
%  \end{macro}
%
% Restore |^^A|.
%    \begin{macrocode}
\GctrlA
%</package>
%    \end{macrocode}
%
% \Finale
%
