%
% \iffalse
%
%% graphics.dtx Copyright (C) 1994 David Carlisle Sebastian Rahtz
%%
%% This file is part of the Standard LaTeX `Graphics Bundle'.
%%
%% It should be distributed *unchanged* and together with all other
%% files in the graphics bundle. The file 00readme.txt contains a list
%% of all of these files.
%%
%% A modified version of this file may be distributed, but it should
%% be distributed with a *different* name. Changed files must be
%% distributed *together with a complete and unchanged* distribution
%% of these files.
%%
%<*dtx>
          \ProvidesFile{graphics.dtx}
%</dtx>
%<package>\NeedsTeXFormat{LaTeX2e}[1994/12/01]
%<package>\ProvidesPackage{graphics}
%<driver> \ProvidesFile{graphics.drv}
% \fi
%         \ProvidesFile{graphics.dtx}
          [1994/12/15 v0.6c Standard LaTeX Graphics (DPC,SPQR)]
%
% \iffalse
%<*driver>
\documentclass{ltxdoc}
\begin{document}
 \DocInput{graphics.dtx}
\end{document}
%</driver>
% \fi
%
% \GetFileInfo{graphics.dtx}
%
% \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
%
% \CheckSum{1071}
%
% \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{Package Options}
% Most of the options, such as |dvips|, |textures| etc., specify the
% driver that is to be used to print the document. You may wish to set
% up a configuration file so that this option always takes effect, even
% if not specified in the document. To do this, produce a file
% |graphics.cfg| containing the line:\\
% |\ExecuteOptions{dvips}|\\
% (or whichever other driver you wish.)
%
% Apart from the driver options there are a few other options to control
% the behaviour of the package.
% \begin{description}
% \item[draft]
% \item[final]
% \item[debugshow]
% \item[hiderotate]
% \item[hidescale]
% \end{description}
%
% \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\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.
%
% Earlier versions of this package defined a default argument for this
% command. This has been removed.
%
% \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{ext} is the \emph{extension} of the file. Any file with this
% extension will be processed by this graphics rule. Normally a file
% with an extension for which no rule has been declared will generate an
% error, however you may use |*| as the extension to define a
% \emph{default rule}, for instance the |dvips| driver file declares all
% files to be of type |eps| unless a more specific rule is declared.
%
% Since Version v0.6, extensions should be specified including the |.|
% that is, |.eps| not |eps|.
%
% \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|. As a special case |*| may be used to denote the
% same extension as the graphic file. This is mainly of use in
% conjuction with using |*| as the extension, as in that case the
% particular graphic extension is not known. For example
%\begin{verbatim}
% \DeclareGraphicsRule{*}{eps}{*}{}
%\end{verbatim}
% This would decalare a default rule, such that all unknown extensions
% would be treated as EPS files, and the graphic file would be read for
% a BoundingBox comment.
%
% 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.
%
% \section{The Key=Value Interface}
% As mentioned in the introcuction, apart from the above `standard
% interface' there is an alternative synatx to the |\includegraphics|and
% |\rotatebox| commands that some people may prefer. It is provided by
% the accompanying |graphicx| package.
%
% \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 defines a function, |\Gread@eps|,  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{.5\textwidth}}
% |\Gin@llx|, |\Gin@lly|,\newline
% |\Gin@urx|, |\Gin@ury| &Registers storing the `bounding box'\\
% |\Gin@nat@width|\newline |\Gin@nat@height| &
%               Registers storing the natural size.\\
% |\Gin@req@width|\newline |\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}
%
%    \begin{macrocode}
%<*package>
%    \end{macrocode}
%
% \subsection{Initialisation}
%
% First we save the catcodes of some characters, and set them to
% fixed values whilst this file is being read.
% \changes{v0.5a}{1994/07/20}
%     {Save and restore catcodes}
%    \begin{macrocode}
\edef\Gin@codes{%
 \catcode`\noexpand\^^A\the\catcode`\^^A\relax
 \catcode`\noexpand\"\the\catcode`\"\relax
 \catcode`\noexpand\*\the\catcode`\*\relax
 \catcode`\noexpand\!\the\catcode`\!\relax
 \catcode`\noexpand\:\the\catcode`\:\relax}
\catcode`\^^A=\catcode`\%
\catcode`\"=12
\catcode`\*=11
\catcode`\!=12
\catcode`\:=12
%    \end{macrocode}
%
% 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{\@latex@error{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{\@latex@error{Scaling not supported}\@ehc
            \global\let\Gscale@start\relax}
\providecommand\Gscale@end{}
%    \end{macrocode}
%  \end{macro}
%  \end{macro}
%
% \subsection{Options}
%
% \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{macro}{\Gin@driver}
% Driver in use.
%    \begin{macrocode}
\providecommand\Gin@driver{}
%    \end{macrocode}
%  \end{macro}
%
% \changes{v0.3c}{1994/03/04}
%     {dviwindo support.}
% \changes{v0.3g}{1994/03/15}
%     {Use dvips def file not development version}
% \changes{v0.6b}{1994/12/12}
%     {ln support (untested)}
%    \begin{macrocode}
\DeclareOption{dvips}{\def\Gin@driver{dvips.def}}
\DeclareOption{xdvi}{\ExecuteOptions{dvips}}
\DeclareOption{dvi2ps}{\def\Gin@driver{dvi2ps.def}}
\DeclareOption{dvialw}{\def\Gin@driver{dvialw.def}}
\DeclareOption{dvilaser}{\def\Gin@driver{dvilaser.def}}
\DeclareOption{dvipsone}{\def\Gin@driver{dvipsone.def}}
\DeclareOption{dvitops}{\def\Gin@driver{dvitops.def}}
\DeclareOption{dviwindo}{\def\Gin@driver{dviwindo.def}}
\DeclareOption{emtex}{\def\Gin@driver{emtex.def}}
\DeclareOption{dviwin}{\def\Gin@driver{dviwin.def}}
\DeclareOption{oztex}{\def\Gin@driver{oztex.def}}
\DeclareOption{psprint}{\def\Gin@driver{psprint.def}}
\DeclareOption{pubps}{\def\Gin@driver{pubps.def}}
\DeclareOption{textures}{\def\Gin@driver{textures.def}}
\DeclareOption{pctexps}{\def\Gin@driver{pctexps.def}}
\DeclareOption{pctexwin}{\def\Gin@driver{pctexwin.def}}
\DeclareOption{pctexhp}{\def\Gin@driver{pctexhp.def}}
\DeclareOption{ln}{\def\Gin@driver{ln.def}}
%    \end{macrocode}
%
%    \begin{macrocode}
\DeclareOption{debugshow}{\catcode`\^^A=9 \let\GDebug\typeout}
%    \end{macrocode}
%
% A local configuration file may define more options. 
% It should also make one driver option the default, by calling
% |\ExecuteOptions| with the appropriate option.
% \changes{v0.4f}{1994/07/27}
%      {Add missing 3rd argument to \cs{InputIfFileExists}}
%    \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}
%
% After the options are processed, load the appropriate driver file.
% If a site wants a default driver (eg |textures|) it just needs to put
% |\ExecuteOptions{textures}| in a |graphics.cfg| file.
%    \begin{macrocode}
\ProcessOptions
%    \end{macrocode}
%
% \changes{v0.5c}{1994/10/03}
%     {Error if no driver specified}
%    \begin{macrocode}
\if!\Gin@driver!
  \PackageError{graphics}
    {No driver specified}
    {You should make a default driver option in a file \MessageBreak
     graphics.cfg\MessageBreak
     eg: \protect\ExecuteOptions{textures}%
     }
\else
  \PackageInfo{graphics}{Driver file: \Gin@driver}
  \@ifundefined{ver@\Gin@driver}{\input{\Gin@driver}}{}
\fi
%    \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}
% \changes{v0.6a}{1994/11/29}
%     {Remove optional argument, ignore spaces in main argument.}
% Declare a comma separated list of default extensions to be used
% If the file is specified with no extension.
%    \begin{macrocode}
\newcommand\DeclareGraphicsExtensions[1]{%
  \edef\Gin@extensions{\zap@space#1 \@empty}}
%    \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@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]{%
  \@ifnextchar[%]
    {\Gin@iii[#1]}
    {\Gin@iii[\z@,\z@][#1]}}
%    \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|.
% \changes{v0.6c}{1994/12/15}
%     {(Denis Roegel) Extra group to keep bb settings local}
%    \begin{macrocode}
\def\Gin@iii[#1,#2][#3,#4]#5{%
  \begingroup
  \Gin@viewporttrue
  \@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{#5}%
  \endgroup}
%    \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,
% \changes{v0.5d}{1994/10/24}
%     {(Arthur Ogawa) Check arg3 is |*|, not arg2.}
%    \begin{macrocode}
\def\DeclareGraphicsRule#1#2#3#4{%
  \edef\@tempa{\string *}\def\@tempb{#3}%
  \expandafter\edef\csname Gin@rule@#1\endcsname##1%
       {{#2}%
        {\ifx\@tempa\@tempb\noexpand\Gin@ext\else#3\fi}%
        {\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}
% \changes{v0.6a}{1994/11/29}
%     {remove \cs{Gin@sep}}
% 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#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@sepdefault}
% \changes{v0.6a}{1994/11/29}
%     {remove \cs{Gin@sep}}
% This must match the token used by |\filename@parse| to delimit the
% extension.
%    \begin{macrocode}
\def\Gin@sepdefault{.}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\Ginclude@graphics}
%  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}
% \changes{v0.5a}{1994/07/20}
%     {Add default (*) rule possibility}
% \changes{v0.6a}{1994/11/29}
%     {remove \cs{Gin@sepdefault}}
%    \begin{macrocode}
\def\Ginclude@graphics#1{%
  \begingroup
  \let\input@path\Ginput@path
  \filename@parse{#1}%
  \ifx\filename@ext\relax
    \@for\Gin@temp:=\Gin@extensions\do{%
      \ifx\Gin@ext\relax
        \Gin@getbase\Gin@temp
      \fi}%
  \else
    \Gin@getbase{\Gin@sepdefault\filename@ext}%
%    \end{macrocode}
% \changes{v0.4d}{1994/05/06}
%     {Make file not found a warning not an error}
% \changes{v0.6a}{1994/11/29}
%     {remove \cs{Gin@sep}}
% 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}%
%    \end{macrocode}
% \changes{v0.6c}{1994/12/15}
%     {(Piet van Oostrum) include `.' in \cs{Gin@ext}}%    
%    \begin{macrocode}
       \edef\Gin@ext{\Gin@sepdefault\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
         \@latex@error{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}%
%    \end{macrocode}
% \changes{v0.5a}{1994/07/20}
%     {Add default (*) rule possibility}
% Handle default rule.
%    \begin{macrocode}
         {\ifx\Gin@rule@*\@undefined
            \@latex@error{Unknown graphics extension: \Gin@ext}\@ehc
          \else
            \expandafter\Gin@setfile\Gin@rule@*{\Gin@base\Gin@ext}%
           \fi}%
         {\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'.
% \changes{v0.5d}{1994/10/24}
%     {(Arthur Ogawa) Add missing \cs{expandafter}}
%    \begin{macrocode}
\def\Gin@setfile#1#2#3{%
  \ifx\\#2\\\Gread@false\fi
  \ifGin@viewport\else
    \ifGread@
      \csname Gread@%
         \expandafter\ifx\csname Gread@#1\endcsname\relax
           eps%
         \else
           #1%
         \fi
      \endcsname{\Gin@base#2}%
    \else
%    \end{macrocode}
% \changes{v0.5a}{1994/07/20}
%     {New error trap for missing size arguments}
%    \begin{macrocode}
    \@latex@error
      {Cannot determine size of graphic in #3 (no size specifed)}%
      \@ehc
    \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
      \@latex@error{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|.
% \changes{v0.5e}{1994/1l/02}
%     {Fix the catcodes of \cs{endlinechar} and ctrl-D}
%    \begin{macrocode}
\def\Gread@eps#1{%
  \begingroup
  \let\do\@makeother\dospecials\catcode`\ 10 %
  \@makeother\^^D%
  \catcode\endlinechar5 %
%    \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
    \@latex@error{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
    \@latex@error
      {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.
% \changes{v0.5a}{1994/07/20}
%     {Support French active !}
% \changes{v0.5d}{1994/10/24}
%     {Correct the support for !}
%    \begin{macrocode}
\def\Gscale@@box#1#2#3{%
  \def\@tempa{!}%
  \expandafter\def\expandafter\@tempb\expandafter{\string#2}%
  \expandafter\def\expandafter\@tempc\expandafter{\string#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 Catcodes
%    \begin{macrocode}
\Gin@codes
\let\Gin@codes\relax
%    \end{macrocode}
%
%    \begin{macrocode}
%</package>
%    \end{macrocode}
%
% \Finale
%
