4 %% graphics.dtx Copyright (C) 1994 David Carlisle Sebastian Rahtz
5 %% Copyright (C) 1995--2017 David Carlisle, LaTeX3 Project
7 %% This file is part of the Standard LaTeX `Graphics Bundle'.
8 %% It may be distributed under the terms of the LaTeX Project Public
9 %% License, as described in lppl.txt in the base LaTeX distribution.
10 %% Either version 1.3c or, at your option, any later version.
12 %% This file has the LPPL maintenance status "maintained".
15 \ProvidesFile{graphics.dtx}
17 %<package>\NeedsTeXFormat{LaTeX2e}[1995/12/01]
18 %<package>\ProvidesPackage{graphics}
19 %<driver> \ProvidesFile{graphics.drv}
21 % \ProvidesFile{graphics.dtx}
22 [2017/06/25 v1.2c Standard LaTeX Graphics (DPC,SPQR)]
26 \documentclass{ltxdoc}
27 \newenvironment{option}[1]{\expandafter\macro\expandafter{%
28 \csname ds@#1\endcsname}}{\endmacro}
30 \DocInput{graphics.dtx}
35 % \GetFileInfo{graphics.dtx}
37 % \title{The \textsf{graphics} package\thanks{This file
38 % has version number \fileversion, last
39 % revised \filedate.}}
40 % \author{D. P. Carlisle\and S. P. Q. Rahtz}
42 % \MaintainedByLaTeXTeam{graphics}
46 % \changes{v0.3a}{1994/02/24}
47 % {First DPC version (after prototype by SPQR).}
48 % \changes{v0.4e}{1994/05/30}
49 % {Rename egraphics to graphicx}
50 % \changes{v1.0}{1996/05/29}
54 % \def\star{{\ttfamily*}}
56 % \def\Describe@Macro#1{\endgroup
57 % \setbox0=\lastbox\llap{\PrintDescribeMacro{#1}}}%
61 % \section{Introduction}
63 % This package implements various `graphics' functions. The main
64 % features are a) inclusion of `graphics' files. b) Rotation of sections
65 % of the page, c) Scaling of sections of the page.
67 % The design is split into three `levels'.
69 % \item The user interface. This is the collection of commands designed
70 % to appear in a document text. Actually two separate user interface
71 % have been implemented. The `standard' interface, described here, and a
72 % more powerful, and more `user-friendly' interface provided by the
74 % \item The core functions. These functions, which are also implemented
75 % in this file do all the `main work'. The `user-interface functions
76 % just collect together the information from any optional-arguments or
77 % star-forms, and then call one of these functions.
78 % \item The driver files. It is not possible to achieve the
79 % functionality of this package just using \TeX. The |dvi| driver used
80 % must be given additional instructions. (Using the |\special| command
81 % of \TeX.) Unfortunately, the capabilities of various drivers differ,
82 % and the syntax required to pass instructions to the drivers is also
83 % not standardised. So the `core functions' never access |\special|
84 % directly, but rather call a series of commands that must be defined in
85 % a special file customised for each driver. The accompanying file,
86 % |drivers.dtx| has suitable files for a range of popular drivers.
89 % \section{Package Options}
90 % Most of the options, such as |dvips|, |textures| etc., specify the
91 % driver that is to be used to print the document. You may wish to set
92 % up a configuration file so that this option always takes effect, even
93 % if not specified in the document. To do this, produce a file
94 % |graphics.cfg| containing the line:\\
95 % |\ExecuteOptions{dvips}|\\
96 % (or whichever other driver you wish.)
98 % Apart from the driver options there are a few other options to control
99 % the behaviour of the package.
100 % \begin{description}
102 % Do not include graphics files, but instead print a box of the size
103 % the graphic would take up, and the file name. This greatly speeds up
104 % previewing on most systems.
106 % Turns off the |draft| option.
108 % Show a lot of tracing information on the terminal. If you are not me
109 % you probably do not want to use this option.
111 % Do not show rotated text. Sometimes useful if your previewer can not
114 % Do not show scaled text.
116 % Look for Bounding Box lines of the form |%%HiResBoundingBox| instead
117 % of the standard |%%BoundingBox|. These are used by some applications
118 % to get round the restriction that BoundingBox comments should only
119 % have integer values.
120 % \item[setpagesize, nosetpagesize]
121 % The |setpagesize| option requests that the driver option sets the page size.
122 % (Whichever option is used, the page size is not set by this package if |\mag|
123 % has been changed from its default value.)
124 % \item[demo] Instead of including a graphics file, make
125 % |\includegraphics| insert a black rectangle of size 150\,pt by
126 % 100\,pt unless either dimension was already specified by another
130 % \section{Standard Interface}
132 % \subsection{Graphics Inclusion}
135 % \includegraphics\star\oarg{llx,lly}\oarg{urx,ury}\marg{file}\\
136 % Include a graphics file.
138 % If \star\ is present, then the graphic is `clipped' to the size
139 % specified. If \star\ is omitted, then any part of the graphic that is
140 % outside the specified `bounding box' will over-print the surrounding
143 % If the optional arguments are omitted, then the size of the graphic
144 % will be determined by reading an external file as described below.
145 % If \oarg{urx,ury} is present, then it should specify the coordinates
146 % of the top right corner of the image, as a pair of \TeX\ dimensions.
147 % If the units are omitted they default to |bp|. So |[1in,1in]| and
148 % |[72,72]| are equivalent. If only one optional argument appears, the
149 % lower left corner of the image is assumed to be at |[0,0]|. Otherwise
150 % \oarg{llx,lly} may be used to specify the coordinates of this point.
153 % \graphicspath\marg{dir-list}\\
154 % This optional declaration may be used to specify a list of directories
155 % in which to search for graphics files. The format is as for the
156 % \LaTeXe\ primitive |\input@path|, a list of directories, each in a
157 % |{}| group (even if there is only one in the list). For example:
158 % |\graphicspath{{eps/}{tiff/}}|
159 % would cause the system to look in the subdirectories |eps| and |tiff|
160 % of the current directory. The default setting of this path is
161 % |\input@path| that is: graphics files will be found wherever \TeX\
165 % \DeclareGraphicsExtensions\marg{ext-list}\\
166 % This specifies the behaviour of the system when the filename argument to
167 % |\includegraphics| does not have an extension specified.
168 % Here \marg{ext-list} should be a comma-separated list of file
169 % extensions, each with a leading period (\texttt{.}).
170 % A file name is produced by appending \emph{sep} and one extension.
171 % If a file is found, the system acts as if that extension had been
172 % specified. If not, the next extension in \emph{ext-list} is tried.
173 % \changes{v1.0m}{2001/06/07}{Extended documentation (CAR) graphics/3228}
175 % Each use of |\DeclareGraphicsExtensions| overwrites all previous
176 % definitions. It is not possible to add an extension to an
179 % Early versions of this package defined a default argument for this
180 % command. This has been removed.
183 % \DeclareGraphicsRule
184 % \marg{ext}\marg{type}\marg{read-file}\marg{command}\\
185 % Any number of these declarations can be made. They determine how the
186 % system behaves when a file with extension \emph{ext} is specified.
187 % (The extension may be specified explicitly or, if the argument to
188 % |\includegraphics| does not have an extension, it may be a default
189 % extension from the \emph{ext-list} specified with
190 % |\DeclareGraphicsExtensions|.)
192 % \emph{ext} is the \emph{extension} of the file. Any file with this
193 % extension will be processed by this graphics rule. Normally a file
194 % with an extension for which no rule has been declared will generate an
195 % error, however you may use |*| as the extension to define a
196 % \emph{default rule}. For instance the |dvips| driver file declares all
197 % files to be of type |eps| unless a more specific rule is declared.
199 % Since Version v0.6, extensions should be specified including the |.|
200 % that is, |.eps| not |eps|.
202 % \emph{type} is the `type' of file involved. All files of the same type
203 % will be input with the same internal command (which must be defined in
204 % a `driver file'). For example files with extensions |ps|, |eps|,
205 % |ps.gz| may all be classed as type |eps|.
207 % \emph{read-file} determines the extension of the file that should be
208 % read to determine size information. It may be the same as \emph{ext}
209 % but it may be different, for example |.ps.gz| files are not readable
210 % easily by \TeX, so you may want to put the bounding box information in
211 % a separate file with extension |.ps.bb|. If \emph{read-file} is empty,
212 % |{}|, then the system will not try to locate an external file for size
213 % info, and the size must be specified in the arguments of
214 % |\includegraphics|. As a special case |*| may be used to denote the
215 % same extension as the graphic file. This is mainly of use in
216 % conjunction with using |*| as the extension, as in that case the
217 % particular graphic extension is not known. For example
219 % \DeclareGraphicsRule{*}{eps}{*}{}
221 % This would declare a default rule, such that all unknown extensions
222 % would be treated as EPS files, and the graphic file would be read for
223 % a BoundingBox comment.
225 % If the driver file specifies a procedure for
226 % reading size files for \emph{type}, that will be used, otherwise the
227 % procedure for reading |eps| files will be used. Thus the size of
228 % bitmap files may be specified in a file with a PostScript style
229 % |%%BoundingBox| line, if no other specific format is available.
231 % \emph{command} is usually empty, but if non empty it is used in place
232 % of the filename in the |\special|. Within this argument, |#1| may be
233 % used to denote the filename. Thus using the dvips driver, one may
235 % |\DeclareGraphicsRule{.ps.gz}{eps}{.ps.bb}{`zcat #1}|\\
236 % the final argument causes dvips to use the |zcat| command to unzip the
237 % file before inserting it into the PostScript output.
239 % \subsection{Rotation}
242 % \rotatebox\marg{angle}\marg{text}\\
243 % Rotate \emph{text} \emph{angle} degrees anti-clockwise. Normally
244 % the rotation is about the left-hand end of the baseline of
247 % \subsection{Scaling}
250 % \scalebox\marg{h-scale}\oarg{v-scale}\marg{text}\\
251 % Scale \emph{text} by the specified amounts. If \emph{v-scale} is
252 % omitted, the vertical scale factor is the same as the horizontal one.
255 % \resizebox\star\marg{h-length}\marg{v-length}\marg{text}\\
256 % Scale \emph{text} so that the width is \emph{h-length}.
257 % If |!| is used as either length argument, the other argument is used
258 % to determine a scale factor that is used in both directions.
259 % Normally \emph{v-length} refers to the height of the box, but in the
260 % star form, it refers to the `height + depth'.
261 % As normal for \LaTeXe\ box length arguments, |\height|,
262 % |\width|, |\totalheight| and |\depth| may be used to refer to the
263 % original size of the box.
265 % \section{The Key=Value Interface}
266 % As mentioned in the introduction, apart from the above `standard
267 % interface', there is an alternative syntax to the |\includegraphics|
268 % and |\rotatebox| commands that some people may prefer. It is provided
269 % by the accompanying |graphicx| package.
273 % \section{The Graphics Kernel Functions}
275 % \subsection{Graphics Inclusion}
278 % {\Ginclude@graphics}\marg{file}\\
279 % Insert the contents of the file \emph{file} at the current point.
280 % |\Ginclude@graphics| may use the four macros |\Gin@llx|, |\Gin@lly|,
281 % |\Gin@urx|, |\Gin@ury| to determine the `bounding box' of the graphic.
282 % The result will be a \TeX\ box of width $\mathit{urx}-\mathit{llx}$
283 % and height $\mathit{ury}-\mathit{lly}$. If |\Gin@clip| is \meta{true}
284 % then part of the graphic that is outside this box should not be
285 % displayed. (Not all drivers can support this `clipping'.) Normally all
286 % these parameters are set by the `user interface level'.
290 % {\Gread@eps}\marg{file}\\
291 % For each \emph{type} of graphics file supported, the driver file must
292 % define |\Ginclude@|\emph{type} and, optionally |\Gread@|\emph{type}.
293 % The read command is responsible for obtaining size information from
294 % the file specified in the |\DeclareGraphicsRule| command. However the
295 % kernel defines a function, |\Gread@eps|, which can read PostScript
297 % |%%BoundingBox| comment. This function will be used for any type for
298 % which a specific function has not been declared. |\Gread@eps| accepts
299 % a generalised version of the bounding box comment. \TeX\ units may be
300 % used (but there must be no space before the unit). If the unit is
301 % omitted |bp| is assumed. So\\
302 % |%%BoundingBox 0 0 2in 3in|\\
303 % Would be accepted by this function, to produce a 2in wide, by 3in high
306 % \subsection{Rotation}
310 % Rotate the contents of |\box0| through |\Grot@angle| degrees
311 % (anti-clockwise). The user-interface is responsible for setting the
312 % macro |\Grot@angle|, and putting the appropriate text in |\Grot@box|.
314 % \subsection{Scaling}
317 % {\Gscale@box}\marg{xscale}\oarg{yscale}\marg{text}\\
318 % (The second argument is not optional.)
319 % Scale \emph{text} by the appropriate scale factors.
322 % {\Gscale@box@dd}\marg{dima}\marg{dimb}\marg{text}\\
323 % Scale \emph{text} in both directions by a factor
324 % \emph{dima}/\emph{dimb}.
328 % \marg{dima}\marg{dimb}\marg{dimc}\marg{dimd}\marg{text}\\
329 % Scale \emph{text} in horizontally by a factor \emph{dima}/\emph{dimb},
330 % and vertically by a factor of \emph{dimc}/\emph{dimd}.
333 % {\Gscale@div}\marg{cmd}\marg{dima}\marg{dimb}\\
334 % Define the macro \emph{cmd} to be the ratio of the lengths
335 % \emph{dima}/\emph{dimb}.
338 % \section{Interface to the Driver Files}
340 % \subsection{Graphics Inclusion}
342 % Each driver file must declare that its driver can include graphics of
343 % certain \emph{types}. It does this by declaring for each type a
344 % command of the form:\\
345 % |\Ginclude@|\emph{type}\\
346 % The Graphics kernel function will call this driver-defined function
347 % with the filename as argument, and certain additional information will
348 % be provided as follows.:
350 % \noindent\begin{tabular}{p{.4\textwidth}p{.5\textwidth}}
351 % |\Gin@llx|, |\Gin@lly|,\newline
352 % |\Gin@urx|, |\Gin@ury| &Macros storing the `bounding box'\\
353 % |\Gin@nat@width|\newline |\Gin@nat@height| &
354 % Registers storing the natural size.\\
355 % |\Gin@req@width|\newline |\Gin@req@height| &
356 % Registers storing the required size, after scaling.\\
357 % |\Gin@scalex|, |\Gin@scaley| & macros with the scale factors. A value
358 % of |!| means: Scale by the same amount as the other direction.\\
359 % |\ifGin@clip| & |\newif| token, true if the graphic should be
360 % `clipped' to the bounding box.
363 % Optionally the driver may define a command of the form:\\
364 % |\Gread@|\emph{type}\\
365 % This is responsible for reading an external file to find the bounding
366 % box information. If such a command is not declared, but a read-file is
367 % specified the command |\Gread@eps|, which is defined in the Graphics
368 % Kernel will be used.
370 % \subsection{Literal Postscript}
371 % Drivers that are producing PostScript output may want to define
372 % the following macros. They each take one argument which should be
373 % passed to an appropriate special. They are not used directly by this
374 % package but allow other packages to use the standard configuration
375 % file and package options to customise to various drivers:\\
376 % |\Gin@PS@raw|, Literal PostScript special.\\
377 % |\Gin@PS@restored|, Literal PostScript special, the driver will
378 % surround this with a save-restore pair.\\
379 % |\Gin@PS@literal@header|, Postscript to be inserted in the header
380 % section of the PostScript file.\\
381 % |\Gin@PS@file@header|, external file to be inserted in the header
382 % section of the PostScript file.
385 % \subsection{Rotation}
387 % |\Grot@start|, |\Grot@end| These macros must be defined to insert the
388 % appropriate |\special| to rotate the text between them by
389 % |\Grot@angle| degrees. The kernel function will make sure that the
390 % correct \TeX\ spacing is produced, these functions only need insert
393 % \subsection{Scaling}
395 % |\Gscale@start|, |\Gscale@end|, as for rotation, but here scale the
396 % text by |\Gscale@x| and |\Gscale@y|.
399 % \section{Implementation}
405 % \subsection{Initialisation}
407 % \begin{macro}{\Gin@codes}
408 % First we save the catcodes of some characters, and set them to
409 % fixed values whilst this file is being read.
410 % \changes{v0.5a}{1994/07/20}
411 % {Save and restore catcodes}
414 \catcode`\noexpand\^^A\the\catcode`\^^A\relax
415 \catcode`\noexpand\"\the\catcode`\"\relax
416 \catcode`\noexpand\*\the\catcode`\*\relax
417 \catcode`\noexpand\!\the\catcode`\!\relax
418 \catcode`\noexpand\:\the\catcode`\:\relax}
422 \catcode`\^^A=\catcode`\%
430 % We will need to have an implementation of the trigonometric
431 % functions for the rotation feature. May as well load it now.
433 \RequirePackage{trig}
436 % \begin{macro}{\Grot@start}
437 % \begin{macro}{\Grot@end}
438 % Initialise the rotation primitives.
440 \providecommand\Grot@start{\@latex@error{Rotation not supported}\@ehc
441 \global\let\Grot@start\relax}
442 \providecommand\Grot@end{}
447 % \begin{macro}{\Gscale@start}
448 % \begin{macro}{\Gscale@end}
449 % Initialise the scaling primitives.
451 \providecommand\Gscale@start{\@latex@error{Scaling not supported}\@ehc
452 \global\let\Gscale@start\relax}
453 \providecommand\Gscale@end{}
458 % \begin{macro}{\Gread@BBox}
459 % \changes{v1.0b}{1996/10/29}
460 % {Moved to initial section, for hiresbb option}
461 % |%%BoundingBox| as a macro for testing with |\ifx|.
462 % This may be redefined by the hiresbb option.
464 \edef\Gread@BBox{\@percentchar\@percentchar BoundingBox}
468 % \subsection{Options}
470 % \begin{option}{draft}
471 % \begin{option}{final}
472 % \changes{v0.3i}{1994/03/23}
473 % {notdraft option added}
474 % \changes{v0.4a}{1994/04/13}
475 % {Rename option to nodraft}
476 % \changes{v0.4d}{1994/05/06}
477 % {Rename option to final}
479 \DeclareOption{draft}{\Gin@drafttrue}
480 \DeclareOption{final}{\Gin@draftfalse}
485 % \begin{macro}{\ifGin@draft}
486 % True in draft mode.
492 % \begin{option}{hiresbb}
493 % \changes{v1.0b}{1996/10/29}
494 % {hiresbb option added}
495 % If given this option the package will look for bounding box comments
496 % of the form |%%HiResBoundingBox| (which typically have real values)
497 % instead of the standard |%%BoundingBox| (which should have integer
500 \DeclareOption{hiresbb}{%
501 \edef\Gread@BBox{\@percentchar\@percentchar HiResBoundingBox}}
505 % \begin{option}{demo}
506 % \changes{v1.0o}{2006/02/20}{demo option added}
507 % If given this option the package will disregard the actual
508 % graphics file and insert a black box unless width or height are
511 \DeclareOption{demo}{%
513 \def\Ginclude@graphics#1{%
514 \rule{\@ifundefined{Gin@@ewidth}{150pt}{\Gin@@ewidth}}%
515 {\@ifundefined{Gin@@eheight}{100pt}{\Gin@@eheight}}}}}
519 % \begin{option}{setpagesize}
520 % \begin{option}{nosetpagesize}
521 % The |setpagesize| option requests that the driver option sets the page size.
522 % (Whichever option is used, the page size is not set by this package if |\mag|
523 % has been changed from its default value.)
524 % \changes{v1.0s}{2016/06/02}
525 % {(no)setpagesize options added}
527 \newif\ifGin@setpagesize\Gin@setpagesizetrue
528 \DeclareOption{setpagesize}{\Gin@setpagesizetrue}
529 \DeclareOption{nosetpagesize}{\Gin@setpagesizefalse}
534 % \begin{macro}{\Gin@driver}
537 \providecommand\Gin@driver{}
541 % \begin{option}{dvips}
542 % \changes{v0.3g}{1994/03/15}
543 % {Use dvips def file not development version}
544 % \begin{option}{xdvi}
545 % Tomas Rockicki's PostScript driver (unix, MSDOS, VMS\ldots).
546 % The |X11| previewer |xdvi| supports basically the same set of
549 \DeclareOption{dvips}{\def\Gin@driver{dvips.def}}
550 \DeclareOption{xdvi}{\ExecuteOptions{dvips}}
555 % \begin{option}{dvipdf}
556 % \changes{v1.0c}{1996/10/31}
558 % Sergey Lesenko's dvipdf driver.
560 \DeclareOption{dvipdf}{\def\Gin@driver{dvipdf.def}}
564 % \begin{option}{dvipdfm}
565 % \changes{v1.0k}{1999/01/13}
567 % \changes{v1.2a}{2017/06/01}
568 % {make dvipdfm an alias for dvipdfmx}
569 % Mark Wick's dvipdfm driver (now merged with xdvipdfmx).
571 \DeclareOption{dvipdfm}{\def\Gin@driver{dvipdfmx.def}}
575 % \begin{option}{dvipdfmx}
576 % \changes{v1.0m}{2005/11/14}
578 % The driver for the dvipdfmx project (also supports xdvipdfmx).
580 \DeclareOption{dvipdfmx}{\def\Gin@driver{dvipdfmx.def}}
584 % \begin{option}{xetex}
585 % \changes{v1.0m}{2005/11/14}
587 % Jonathan Kew's \TeX\ variant.
589 \DeclareOption{xetex}{\def\Gin@driver{xetex.def}}
593 % \begin{option}{pdftex}
594 % \changes{v1.0d}{1997/06/07}
596 % Han The Thanh's \TeX\ variant.
598 \DeclareOption{pdftex}{\def\Gin@driver{pdftex.def}}
602 % \begin{option}{luatex}
603 % \changes{v1.0q}{2016/01/03}
605 % Lua\TeX\ \TeX\ variant.
607 \DeclareOption{luatex}{\def\Gin@driver{luatex.def}}
611 % \begin{option}{luatex}
612 % \changes{v1.0r}{2016/05/09}
616 \DeclareOption{dvisvgm}{\def\Gin@driver{dvisvgm.def}}
620 % \begin{option}{dvipsone}
621 % \begin{option}{dviwindo}
622 % \changes{v0.3c}{1994/03/04}
623 % {dviwindo support.}
624 % \changes{v0.7c}{1995/09/07}
625 % {Merge dviwindo option with dvipsone}
626 % The drivers for the Y\&Y \TeX\ system.
628 \DeclareOption{dvipsone}{\def\Gin@driver{dvipsone.def}}
629 \DeclareOption{dviwindo}{\ExecuteOptions{dvipsone}}
634 % \begin{option}{emtex}
635 % \begin{option}{dviwin}
636 % Two freely available sets of drivers for MSDOS, OS/2 and Windows.
638 \DeclareOption{emtex}{\def\Gin@driver{emtex.def}}
639 \DeclareOption{dviwin}{\def\Gin@driver{dviwin.def}}
644 % \begin{option}{oztex}
645 % \changes{v1.0f}{1997/09/09}
646 % {Merge dvips and oztex options}
647 % Oz\TeX\ (Macintosh).
648 % Since release 3 of Oz\TeX, merge with dvips back end.
650 \DeclareOption{oztex}{\ExecuteOptions{dvips}}
654 % \begin{option}{textures}
655 % Textures (Macintosh).
657 \DeclareOption{textures}{\def\Gin@driver{textures.def}}
661 % \begin{option}{pctexps}
662 % \begin{option}{pctexwin}
663 % \begin{option}{pctexhp}
664 % \begin{option}{pctex32}
665 % \changes{v1.0b}{1996/10/29}
666 % {pctex32 option added}
667 % PC\TeX\ (MSDOS/Windows) .
669 \DeclareOption{pctexps}{\def\Gin@driver{pctexps.def}}
670 \DeclareOption{pctexwin}{\def\Gin@driver{pctexwin.def}}
671 \DeclareOption{pctexhp}{\def\Gin@driver{pctexhp.def}}
672 \DeclareOption{pctex32}{\def\Gin@driver{pctex32.def}}
679 % \begin{option}{truetex}
680 % \changes{v1.0b}{1996/10/29}
681 % {truetex and tcidef options added}
682 % \begin{option}{tcidvi}
683 % Kinch TrueTeX, and its version with extended special support as
684 % shipped by Scientific Word.
686 \DeclareOption{truetex}{\def\Gin@driver{truetex.def}}
687 \DeclareOption{tcidvi}{\def\Gin@driver{tcidvi.def}}
692 % \begin{option}{vtex}
693 % \changes{v1.0h}{1998/05/27}
694 % {vtex option added}
697 \DeclareOption{vtex}{\def\Gin@driver{vtex.def}}
701 % \begin{option}{dvi2ps}
702 % \begin{option}{dvialw}
703 % \begin{option}{dvilaser}
704 % \begin{option}{dvitops}
705 % \begin{option}{psprint}
706 % \begin{option}{pubps}
708 % \changes{v0.6b}{1994/12/12}
709 % {ln support (untested)}
710 % \changes{v1.0b}{1996/10/29}
711 % {options for historic drivers depreciated}
712 % If \emph{anyone} is using any of these driver options
713 % would they let me know. All these are essentially untried
714 % and untested as far as I know.
716 %\DeclareOption{dvi2ps}{\def\Gin@driver{dvi2ps.def}}
717 %\DeclareOption{dvialw}{\def\Gin@driver{dvialw.def}}
718 %\DeclareOption{dvilaser}{\def\Gin@driver{dvilaser.def}}
719 %\DeclareOption{dvitops}{\def\Gin@driver{dvitops.def}}
720 %\DeclareOption{psprint}{\def\Gin@driver{psprint.def}}
721 %\DeclareOption{pubps}{\def\Gin@driver{pubps.def}}
722 %\DeclareOption{ln}{\def\Gin@driver{ln.def}}
732 % \begin{option}{debugshow}
733 % You probably don't want to use this\ldots
735 \DeclareOption{debugshow}{\catcode`\^^A=9 \let\GDebug\typeout}
739 % A local configuration file may define more options.
740 % It should also make one driver option the default, by calling
741 % |\ExecuteOptions| with the appropriate option.
742 % \changes{v0.4f}{1994/07/27}
743 % {Add missing 3rd argument to \cs{InputIfFileExists}}
745 \InputIfFileExists{graphics.cfg}{}{}
748 % \begin{option}{hiderotate}
749 % \changes{v0.4a}{1994/04/13}
750 % {Rename option to hiderotate}
752 \DeclareOption{hiderotate}{%
753 \def\Grot@start{\begingroup\setbox\z@\hbox\bgroup}
754 \def\Grot@end{\egroup\endgroup}}
758 % \begin{option}{hidescale}
759 % \changes{v0.4a}{1994/04/13}
760 % {Rename option to hidescale}
762 \DeclareOption{hidescale}{%
763 \def\Gscale@start{\begingroup\setbox\z@\hbox\bgroup}
764 \def\Gscale@end{\egroup\endgroup}}
768 % After the options are processed, load the appropriate driver file.
769 % If a site wants a default driver (eg |textures|) it just needs to put
770 % |\ExecuteOptions{textures}| in a |graphics.cfg| file.
775 % Check that a driver has been specified (either as an option, or as a
776 % default option in the configuration file). Then load the `def' file
777 % for that option, if it has not already been loaded by some other
778 % package (for instance the \textsf{color} package).
779 % \changes{v0.5c}{1994/10/03}
780 % {Error if no driver specified}
783 \PackageError{graphics}
784 {No driver specified}
785 {You should make a default driver option in a file \MessageBreak
786 graphics.cfg\MessageBreak
787 eg: \protect\ExecuteOptions{textures}%
790 \PackageInfo{graphics}{Driver file: \Gin@driver}
791 \@ifundefined{ver@\Gin@driver}{\input{\Gin@driver}}{}
796 % \subsection{Graphics Inclusion}
798 % This Graphics package uses a lot of dimension registers. \TeX\ only
799 % has a limited number of registers, so rather than allocate new ones,
800 % re-use some existing \LaTeX\ registers. This is safe as long as all
801 % uses of the registers are \emph{local}, and that you can be sure
802 % that you \emph{never} need to have access to both uses within the
805 % \begin{macro}{\Gin@llx}
806 % \begin{macro}{\Gin@lly}
807 % \begin{macro}{\Gin@urx}
808 % \begin{macro}{\Gin@ury}
809 % In fact these four lengths are now stored as macros not as dimen
810 % registers, mainly so that integer |bp| lengths may be passed exactly.
811 % \changes{v0.7a}{1995/04/11}
812 % {Bounding box coords no longer in registers}
824 % \begin{macro}{\Gin@nat@width}
825 % \begin{macro}{\Gin@nat@height}
826 % The `natural' size of the graphic, before any scaling.
828 \let\Gin@nat@width\leftmarginv
829 \let\Gin@nat@height\leftmarginvi
834 % \begin{macro}{\ifGin@clip}
835 % This switch is \meta{true} if any graphics outside the specified
836 % bounding box (really viewport) should not be printed.
842 % \begin{macro}{\DeclareGraphicsExtensions}
843 % \changes{v0.6a}{1994/11/29}
844 % {Remove optional argument, ignore spaces in main argument.}
845 % Declare a comma separated list of default extensions to be used
846 % if the file is specified with no extension.
848 \newcommand\DeclareGraphicsExtensions[1]{%
849 \edef\Gin@extensions{\zap@space#1 \@empty}}
853 % \begin{macro}{\Gin@extensions}
854 % Initialise the list of possible extensions.
855 % \changes{v0.4b}{1994/04/20}
856 % {Use \cmd{\providecommand} in case a previous def file has
857 % already defined it}
859 \providecommand\Gin@extensions{}
863 % \begin{macro}{\includegraphics}
864 % \changes{v1.1a}{2017/03/17}
865 % {\cs{leavevmode} added before the group in \cs{Gin@iii} so that
866 % settings in \cs{everypar} are cleared}
867 % Top level command for the standard interface, just look for a |*|.
869 \def\includegraphics{%
871 % Clear |\everypar| before starting a group.
878 {\Gin@cliptrue\Gin@i}%
879 {\Gin@clipfalse\Gin@i}}
883 % \begin{macro}{\Gin@i}
884 % If an optional argument is present, call |\Gin@ii| to process it,
885 % otherwise call |\Ginclude@graphics|.
886 % \changes{v0.3e}{1994/03/09}
887 % {Now specify ll before ur coordinate}
892 {\Gin@bboxfalse\Ginclude@graphics}}
896 % \begin{macro}{\Gin@ii}
897 % Look for a second optional argument.
906 % \begin{macro}{\Gin@iii}
907 % Set the coordinates of the {\bfseries l}lower {\bfseries l}eft corner,
908 % and the coordinates of the {\bfseries u}pper {\bfseries r}ight
909 % corner. The coordinates may be any \TeX\ dimension, defaulting to |bp|.
910 % \changes{v0.6c}{1994/12/15}
911 % {(Denis Roegel) Extra group to keep bb settings local}
913 \def\Gin@iii[#1,#2][#3,#4]#5{%
916 \Gin@defaultbp\Gin@llx{#1}%
917 \Gin@defaultbp\Gin@lly{#2}%
918 \Gin@defaultbp\Gin@urx{#3}%
919 \Gin@defaultbp\Gin@ury{#4}%
920 \Ginclude@graphics{#5}%
925 % \begin{macro}{\Gin@defaultbp}
926 % \changes{v0.7a}{1995/04/11}{Macro added}
927 % \begin{macro}{\Gin@def@bp}
928 % \changes{v0.7a}{1995/04/11}{Macro added}
929 % This macro grabs a length, |#2|, which may or may not have a unit,
930 % and if a unit is supplied, converts to `bp' and stores the value in
931 % |#1|. If a unit is not supplied `bp' is assumed, and |#2| is directly
932 % stored in |#1|. Note that supplying `bp' is not quite the same as
933 % supplying no units, as in the former case a conversion via `pt' and
934 % back to `bp' takes place which can introduce rounding error. The error
935 % is invisibly small but files conforming to Adobe DSC should have
936 % \emph{integer} Bounding Box Coordinates, and conceivably some drivers
937 % might demand integer values.
938 % (Although most seem to accept real values (if they accept bounding box
939 % coordinates at all) in the |\special|. This is the reason why the
940 % mechanism uses |\def| and not \TeX\ lengths, as in earlier releases of
943 \def\Gin@defaultbp#1#2{%
944 \afterassignment\Gin@def@bp\dimen@#2bp\relax{#1}{#2}}
948 \def\Gin@def@bp#1\relax#2#3{%
953 \edef#2{\strip@pt\dimen@}%
959 % \begin{macro}{\DeclareGraphicsRule}
960 % Declare what actions should be taken for a particular file
963 % |#1| extension, |#2| type, |#3| read-file, |#4| command,
964 % \changes{v0.5d}{1994/10/24}
965 % {(Arthur Ogawa) Check arg3 is *, not arg2.}
967 \def\DeclareGraphicsRule#1#2#3#4{%
968 \edef\@tempa{\string *}\def\@tempb{#3}%
969 \expandafter\edef\csname Gin@rule@#1\endcsname##1%
971 {\ifx\@tempa\@tempb\noexpand\Gin@ext\else#3\fi}%
972 {\ifx\indent#4\indent##1\else#4\fi}}}
976 % An example rule base.
978 % ext type read command
979 % \DeclareGraphicsRule{.ps} {eps} {.ps} {}
980 % \DeclareGraphicsRule{.eps} {eps} {.eps} {}
981 % \DeclareGraphicsRule{.ps.gz}{eps} {.ps.bb} {`zcat #1}
982 % \DeclareGraphicsRule{.pcx} {bmp} {} {}
985 % \begin{macro}{\graphicspath}
986 % User level command to set the input path for graphics files.
987 % A list of directories, each in a |{}| group.
989 \def\graphicspath#1{\def\Ginput@path{#1}}
993 % \begin{macro}{\Ginput@path}
994 % The default graphic path is |\input@path|.
996 \ifx\Ginput@path\@undefined
997 \let\Ginput@path\input@path
1002 % \begin{macro}{\Gin@getbase}
1003 % \changes{v0.6a}{1994/11/29}
1004 % {remove \cs{Gin@sep}}
1005 % Given a possible extension, |#1|, check whether the file exists. If
1006 % it does set |\Gin@base| and |\Gin@ext| to the filename stripped of
1007 % the extension, and the extension, respectively.
1009 \def\Gin@getbase#1{%
1011 \def\noexpand\@tempa####1#1\space{%
1012 \def\noexpand\Gin@base{####1}}}%
1013 \IfFileExists{\filename@area\filename@base#1}%
1015 \expandafter\@tempa\@filef@und
1016 \edef\Gin@ext{#1}}{}}%
1020 % \begin{macro}{\Gin@ext}
1021 % Initialise the macro to hold the extension.
1027 % \begin{macro}{\Gin@sepdefault}
1028 % \changes{v0.6a}{1994/11/29}
1029 % {remove \cs{Gin@sep}}
1030 % This must match the token used by |\filename@parse| to delimit the
1033 \def\Gin@sepdefault{.}
1037 % \begin{macro}{\Ginclude@graphics}
1038 % The main internal function implementing graphics file inclusion.
1039 % |#1| is the file name.
1040 % \changes{v0.4c}{1994/04/28}
1041 % {Improve the wording of error messages}
1042 % \changes{v0.5a}{1994/07/20}
1043 % {Add default (*) rule possibility}
1044 % \changes{v0.6a}{1994/11/29}
1045 % {remove \cs{Gin@sepdefault}}
1047 \def\Ginclude@graphics#1{%
1049 \let\input@path\Ginput@path
1050 \filename@parse{#1}%
1051 \ifx\filename@ext\relax
1052 \@for\Gin@temp:=\Gin@extensions\do{%
1054 \Gin@getbase\Gin@temp
1057 \Gin@getbase{\Gin@sepdefault\filename@ext}%
1059 % \changes{v0.4d}{1994/05/06}
1060 % {Make file not found a warning not an error}
1061 % \changes{v0.6a}{1994/11/29}
1062 % {remove \cs{Gin@sep}}
1063 % If the user supplied an explicit extension, just give a warning if the
1064 % file does not exist. (It may be created later.)
1067 \@warning{File `#1' not found}%
1068 \def\Gin@base{\filename@area\filename@base}%
1070 % \changes{v0.6c}{1994/12/15}
1071 % {(Piet van Oostrum) include `.' in \cs{Gin@ext}}%
1073 \edef\Gin@ext{\Gin@sepdefault\filename@ext}%
1077 % If no extension is supplied, it is an error if the file does not
1078 % exist, as there is no way for the system to know which extension to
1082 \@latex@error{File `#1' not found}%
1083 {I could not locate the file with any of these extensions:^^J%
1084 \Gin@extensions^^J\@ehc}%
1086 \@ifundefined{Gin@rule@\Gin@ext}%
1088 % \changes{v0.5a}{1994/07/20}
1089 % {Add default (*) rule possibility}
1090 % Handle default rule.
1092 {\ifx\Gin@rule@*\@undefined
1093 \@latex@error{Unknown graphics extension: \Gin@ext}\@ehc
1095 \expandafter\Gin@setfile\Gin@rule@*{\Gin@base\Gin@ext}%
1097 {\expandafter\expandafter\expandafter\Gin@setfile
1098 \csname Gin@rule@\Gin@ext\endcsname{\Gin@base\Gin@ext}}%
1104 % \begin{macro}{\ifGread@}
1105 % True if a file should be read to obtain the natural size.
1107 \newif\ifGread@\Gread@true
1111 % \begin{macro}{\Gin@setfile}
1112 % Set a file to the size specified in arguments, or in a `read file'.
1113 % \changes{v0.5d}{1994/10/24}
1114 % {(Arthur Ogawa) Add missing \cs{expandafter}}
1116 \def\Gin@setfile#1#2#3{%
1117 \ifx\\#2\\\Gread@false\fi
1121 \expandafter\ifx\csname Gread@#1\endcsname\relax
1126 \endcsname{\Gin@base#2}%
1129 % \changes{v0.5a}{1994/07/20}
1130 % {New error trap for missing size arguments}
1131 % \changes{v0.7f}{1995/11/10}
1132 % {Use \cs{Gin@nosize}}
1133 % By now the natural size should be known either from arguments or
1134 % from the file. If not generate an error. (The \textsf{graphicx}
1135 % interface relaxes this condition slightly.)
1141 % \changes{v0.7a}{1995/04/11}{\cs{Gin@viewport@code} added.}
1142 % The following call will modify the `natural size' if the user has
1143 % supplied a viewport or trim specification. (Not available in the
1144 % standard interface.)
1148 % Save the natural size, and then call |\Gin@req@sizes| which (in the
1149 % key-val interface) will calculate the required size from the natural
1150 % size, and any scaling info.
1152 \Gin@nat@height\Gin@ury bp%
1153 \advance\Gin@nat@height-\Gin@lly bp%
1154 \Gin@nat@width\Gin@urx bp%
1155 \advance\Gin@nat@width-\Gin@llx bp%
1159 % Call |\Ginclude@|\emph{type} to include the figure unless
1160 % this is not defined, or draft mode is being used.
1161 % \changes{v0.7h}{1996/02/20}
1162 % {missing \texttt{@} added in \texttt{Gread@} csnames}
1164 \expandafter\ifx\csname Ginclude@#1\endcsname\relax
1166 \expandafter\ifx\csname Gread@#1\endcsname\relax
1167 \@latex@error{Can not include graphics of type: #1}\@ehc
1168 \global\expandafter\let\csname Gread@#1\endcsname\@empty
1173 \hb@xt@\Gin@req@width{%
1175 \vbox to \Gin@req@height{%
1176 \hrule \@width \Gin@req@width
1179 \rlap{ \ttfamily\expandafter\strip@prefix\meaning\@tempa}%
1185 % \changes{v0.3i}{1994/3/23}
1186 % {Add file list info}
1187 % Support |\listfiles| and then set the final box to the required size.
1189 \@addtofilelist{#3}%
1190 \ProvidesFile{#3}[Graphic file (type #1)]%
1191 \setbox\z@\hbox{\csname Ginclude@#1\endcsname{#3}}%
1193 \ht\z@\Gin@req@height
1194 \wd\z@\Gin@req@width
1200 % \begin{macro}{\Gin@decode}
1201 % \changes{v1.2c}{2017/06/25}
1203 % In the standard interface this is a no-op, but needs to be defined
1204 % to allow the caching code to be set up.
1206 \let\Gin@decode\@empty
1210 % \begin{macro}{\Gin@exclamation}
1211 % \changes{v0.7g}{1995/12/06}{Macro added}
1212 % Catcode 12 |!|, in case of French, or other language styles.
1214 \def\Gin@exclamation{!}
1218 % \begin{macro}{\Gin@page}
1219 % \changes{v1.2a}{2017/06/01}
1221 % In the standard interface this is a no-op, but needs to be defined
1222 % to allow the caching code to be set up.
1224 \let\Gin@page\@empty
1228 % \begin{macro}{\Gin@pagebox}
1229 % \changes{v1.2a}{2017/06/01}
1231 % In the standard interface always points to the |cropbox|.
1233 \def\Gin@pagebox{cropbox}
1237 % \begin{macro}{\ifGin@interpolate}
1238 % \changes{v1.2a}{2017/06/01}
1240 % In the standard setting a no-op.
1242 \newif\ifGin@interpolate
1246 % \begin{macro}{\Gin@log}
1247 % \changes{v1.2a}{2017/06/01} {New macro} In the standard interface
1248 % this prints to the log but can be changed via keys in \textsf{graphicx}.
1255 % \begin{macro}{\Gin@req@sizes}
1256 % \begin{macro}{\Gin@scalex}
1257 % \begin{macro}{\Gin@scaley}
1258 % \begin{macro}{\Gin@req@height}
1259 % \begin{macro}{\Gin@req@width}
1260 % In the standard interface there is no scaling, so the required size
1261 % is the same as the natural size. In other interfaces |\Gin@req@sizes|
1262 % will be responsible for setting these parameters. Here we can set them
1264 % \changes{v0.3g}{1994/03/15}
1265 % {Initialise y-scale to !!}
1266 % \changes{v1.0g}{1998/05/14}
1267 % {Fix !! usage in changes entries. graphics/2724}
1269 \let\Gin@req@sizes\relax
1271 \let\Gin@scaley\Gin@exclamation
1272 \let\Gin@req@height\Gin@nat@height
1273 \let\Gin@req@width\Gin@nat@width
1281 % \begin{macro}{\Gin@viewport@code}
1282 % In the standard interface there is no possibility of specifying
1283 % a viewport, so this is a no-op.
1284 % \changes{v0.7a}{1995/04/11}{Macro added}
1286 \let\Gin@viewport@code\relax
1290 % \begin{macro}{\Gin@nosize}
1291 % \changes{v1.0p}{2014/10/14}{Fixed typo in error message}
1292 % \changes{v0.7f}{1995/11/10}
1294 % This command is called in the case that the graphics type
1295 % specifies no `read file' and the user supplied no size arguments.
1296 % In the standard interface can only generate an error.
1300 {Cannot determine size of graphic in #1 (no size specified)}%
1305 % \subsection{Reading the BoundingBox in EPS files}
1307 % \begin{macro}{\ifGin@bbox}
1308 % \changes{v0.7a}{1995/04/11}{Name changed from \cs{ifGin@viewport}}
1309 % This switch should be set \meta{true} once a size has been found,
1310 % either in an argument, or in an external file.
1316 % \begin{macro}{\Gread@generic}
1317 % \changes{v1.2a}{2017/06/01}
1319 % \begin{macro}{\Gread@generic@aux}
1320 % \begin{macro}{\Gread@eps}
1321 % Read an EPS file (|#1|) and search for a line
1322 % starting with |%%BoundingBox| and returns the result
1323 % by setting four dimension registers
1324 % |\Gin@llx|, |\Gin@lly|, |\Gin@urx| and |\Gin@ury|.
1325 % \changes{v0.5e}{1994/1l/02}
1326 % {Fix the catcodes of \cs{endlinechar} and ctrl-D}
1327 % \changes{v0.7a}{1995/04/11}
1328 % {Fix more catcodes, for binary headers of eps files}
1329 % \changes{v1.2a}{2017/06/01}
1330 % {Split to allow code reuse by \cs{Gread@extractbb} in
1331 % \texttt{dvipdfmx.def} driver}
1332 % \begin{macro}{\Gread@eps@aux}
1334 \def\Gread@generic#1#2{%
1335 \edef\Gread@attr@hash{%
1336 \ifx\Gin@pagebox\@empty\else
1339 \ifx\Gin@page\@empty\else
1343 \@ifundefined{#1 bbox\Gread@attr@hash}%
1344 {\Gread@generic@aux{#1}{#2}}
1346 \expandafter\global\expandafter\let\expandafter\@gtempa
1347 \csname #1 bbox\Gread@attr@hash\endcsname
1349 \expandafter\Gread@parse@bb\@gtempa\\%
1351 \def\Gread@generic@aux#1#2{%
1354 % Make it reasonably safe to have binary headers in the EPS file
1355 % before the bounding box line.
1358 \loop\ifnum\@tempcnta<\@xxxii
1359 \catcode\@tempcnta14 %
1360 \advance\@tempcnta\@ne
1366 % Make sure tab and space are accepted as white space.
1367 % \changes{v1.0e}{1997/09/02}
1368 % {Allow TAB in DSC comments graphics/2587}
1369 % \changes{v1.0i}{1999/01/07}
1370 % {Fix catcode of hyphen. graphics/2846}
1374 \catcode\endlinechar5 %
1378 % The first thing we need to do is to open the
1379 % information file, if possible.
1380 % \changes{v0.4d}{1994/05/06}
1381 % {Improve the error message if the info file is not there.}
1382 % \changes{v1.2a}{2017/06/01}
1383 % {Allow for spaces in name of a file}
1385 \immediate\openin\@inputcheck"#1" %
1388 % \changes{v0.3i}{1994/03/23}
1389 % {Wording of error message improved}
1390 % \changes{v1.0}{1996/05/29}
1391 % {Use \cs{@gtempa} not \cs{g@tempa} /2090}
1392 % \changes{v1.2b}{2017/06/13}
1393 % {Stored bounding box data for reuse}
1396 \expandafter\xdef\csname #1 bbox\Gread@attr@hash\endcsname{\@gtempa}%
1399 {Cannot determine size of graphic in #1 (no BoundingBox)}%
1401 \gdef\@gtempa{0 0 72 72 }%
1406 \Gread@generic{#1}\Gread@eps@aux
1408 \def\Gread@eps@aux#1{%
1410 \@latex@error{File `#1' not found}\@ehc
1413 % Now we'll scan lines until we find one that starts with
1415 % We need to reset the catcodes to read the file, and so this
1416 % is done in a group.
1419 \let\@tempb\Gread@false
1421 \read\@inputcheck to\@tempa
1425 \expandafter\Gread@find@bb\@tempa:.\\%
1429 \immediate\closein\@inputcheck
1438 % \begin{macro}{\Gread@find@bb}
1439 % If a line in the EPS file starts with a |%%BoundingBox:|, we
1440 % will examine it more closely. Note using the `extra' argument |#2#3|
1441 % causes any space after the |:| to be gobbled.
1443 \long\def\Gread@find@bb#1:#2#3\\{%
1445 \ifx\@tempa\Gread@BBox
1446 \Gread@test@atend#2#3()\\%
1450 % \begin{macro}{\Gread@test@atend}
1451 % Determine if the stuff following the |%%BoundingBox| is `(atend)',
1452 % which will involve further reading of the file. This is accomplished
1453 % by making |\@tempb| into a no-op, so that finding a |%%BoundingBox|
1454 % does not stop the loop.
1456 \def\Gread@test@atend#1(#2)#3\\{%
1458 \ifx\@tempa\Gread@atend
1468 % \begin{macro}{\Gread@parse@bb}
1469 % We have |%%BoundingBox| and what follows is not `(atend)' so we
1470 % will parse the rest of the line as a BB with four elements.
1471 % PostScript files should never have units specified in the
1472 % BoundingBox comment, but we allow arbitrary \TeX\ units in external
1473 % files, or in other interfaces.
1475 \def\Gread@parse@bb#1 #2 #3 #4 #5\\{%
1476 \Gin@defaultbp\Gin@llx{#1}%
1477 \Gin@defaultbp\Gin@lly{#2}%
1478 \Gin@defaultbp\Gin@urx{#3}%
1479 \Gin@defaultbp\Gin@ury{#4}}%
1483 % \begin{macro}{\Gread@atend}
1484 % |atend| as a macro for testing with |\ifx|.
1486 \def\Gread@atend{atend}
1491 % \subsection{Rotation}
1493 % As above, we will re-use some existing local registers.
1495 % \begin{macro}{\Grot@height}
1496 % \begin{macro}{\Grot@left}
1497 % \begin{macro}{\Grot@right}
1498 % \begin{macro}{\Grot@depth}
1499 % Final Rotated box dimensions
1501 \let\Grot@height\@ovxx
1502 \let\Grot@left\@ovyy
1503 \let\Grot@right\@ovdx
1504 \let\Grot@depth\@ovdy
1511 % \begin{macro}{\Grot@h}
1512 % \begin{macro}{\Grot@l}
1513 % \begin{macro}{\Grot@r}
1514 % \begin{macro}{\Grot@d}
1515 % Original box dimensions
1527 % \begin{macro}{\Grot@x}
1528 % \begin{macro}{\Grot@y}
1529 % Coordinates of centre of rotation.
1531 \let\Grot@x\@linelen
1532 \let\Grot@y\@dashdim
1537 % \begin{macro}{\rotatebox}
1538 % The angle is specified by |#1|. The box to be rotated is |#2|.
1539 % In the standard interface the centre of rotation is $(0,0)$.
1540 % Then finally call |\Grot@box| to rotate the box.
1541 % \changes{v0.3f}{1994/03/11}{Remove star form}
1542 % \changes{v0.3h}{1994/03/17}{Fix Typo}
1543 % \changes{v0.7a}{1995/04/11}{\cs{leavevmode} added graphics/1521}
1544 % \changes{v1.0n}{2001/07/07}
1545 % {Made long (CAR) graphics/2908 and 3345}
1547 \long\def\rotatebox#1#2{%
1550 \setbox\z@\hbox{{#2}}%
1558 % \begin{macro}{\Grot@setangle}
1559 % Set the internal macro used by |\Grot@box|. In the standard
1560 % interface this is trivial, but other interfaces may have more
1561 % interesting definitions. For example:
1563 % \def\Grot@setangle#1{%
1565 % \dimen@-57.2968\dimen@
1566 % \edef\Grot@angle{\strip@pt\dimen@}}
1568 % This would cause the argument of |\rotatebox| to be interpreted as
1569 % an angle specified in \emph{radians}, \emph{clockwise}.
1571 \def\Grot@setangle#1{\edef\Grot@angle{#1}}
1575 % \subsection{Deriving a `bounding box' for rotated object}
1576 % We want to know the size of a `bounding box' enclosing the rotated
1578 % We define two formulae (as \TeX\ macros) to work out the $x$ and $y$
1579 % coordinates of vertices of the rotated box
1580 % in relation to its original coordinates (i.e., its width, height
1581 % and depth). The box we visualize with vertices $B$, $C$,
1582 % $D$ and $E$ is illustrated below. The vertex
1583 % $S$ is the reference point on the baseline. $O$ is the centre of
1584 % rotation, which in the standard interface is always $S$.
1587 % \setlength{\unitlength}{3pt}%
1589 % \begin{picture}(34,36)(12,44)
1591 % \put(20,52){\dashbox{1}(20,21){}}
1592 % \put(20,80){\line(0,-1){36}}
1593 % \put(12,58){\line(1, 0){34}}
1601 % \put(33,65){\circle*{1}}
1605 % The formulae are, for a point $P$ and angle $\alpha$:
1608 % P'_x = P_x - O_x \\
1609 % P'_y = P_y - O_y \\
1610 % P''_x = ( P'_x \times \cos(\alpha)) - ( P'_y \times \sin(\alpha) ) \\
1611 % P''_y = ( P'_x \times \sin(\alpha)) + ( P'_y \times \cos(\alpha) ) \\
1612 % P'''_x = P''_x + O_x + L_x \\
1613 % P'''_y = P''_y + O_y
1616 % The `extra' horizontal translation $L_x$ at the end is calculated so
1617 % that the leftmost point of the resulting box has $x$-coordinate $0$.
1618 % This is desirable as \TeX\ boxes must have the reference point at
1619 % the left edge of the box.
1621 % \begin{macro}{\Grot@Px}
1622 % Work out new $x$ coordinate of point after rotation. The parameters
1623 % |#2| and |#3| are the original $x$ and $y$ coordinates of the point.
1624 % The new $x$ coordinate is stored in |#1|.
1626 \def\Grot@Px#1#2#3{%
1628 \advance#1-\Grot@sin#3}
1631 % \begin{macro}{\Grot@Py}
1632 % Work out new $y$ coordinate of point after rotation. The parameters
1633 % |#2| and |#3| are the original $x$ and $y$ coordinates of the point.
1634 % The new $y$ coordinate is stored in |#1|.
1636 \def\Grot@Py#1#2#3{%
1638 \advance#1\Grot@cos#3}
1642 % \begin{macro}{\Grot@box}
1643 % This is the tricky bit. We can rotate the box, but then need
1644 % to work out how much space to leave for it on the page.
1646 % We simplify matters by working out first which quadrant we are in, and
1647 % then picking just the right values.
1653 % We are going to need to know the sine and cosine
1654 % of the angle; simplest to calculate these now.
1656 \CalculateSin\Grot@angle
1657 \CalculateCos\Grot@angle
1658 \edef\Grot@sin{\UseSin\Grot@angle}%
1659 \edef\Grot@cos{\UseCos\Grot@angle}%
1660 ^^A \GDebug{Rotate: angle \Grot@angle, sine is \Grot@sin,
1661 ^^A cosine is \Grot@cos}%
1663 % Save the four extents of the original box.
1665 \Grot@r\wd\z@ \advance\Grot@r-\Grot@x
1666 \Grot@l\z@ \advance\Grot@l-\Grot@x
1667 \Grot@h\ht\z@ \advance\Grot@h-\Grot@y
1668 \Grot@d-\dp\z@ \advance\Grot@d-\Grot@y
1670 % Now a straightforward test to see which quadrant we are
1673 \ifdim\Grot@sin\p@>\z@
1674 \ifdim\Grot@cos\p@>\z@
1677 % Height=$By$, Right=$Ex$, Left=$Cx$, Depth=$Dy$
1679 \Grot@Py\Grot@height \Grot@r\Grot@h%B
1680 \Grot@Px\Grot@right \Grot@r\Grot@d%E
1681 \Grot@Px\Grot@left \Grot@l\Grot@h%C
1682 \Grot@Py\Grot@depth \Grot@l\Grot@d%D
1686 % Height=$Ey$, Right=$Dx$, Left=$Bx$, Depth=$Cy$
1688 \Grot@Py\Grot@height \Grot@r\Grot@d%E
1689 \Grot@Px\Grot@right \Grot@l\Grot@d%D
1690 \Grot@Px\Grot@left \Grot@r\Grot@h%B
1691 \Grot@Py\Grot@depth \Grot@l\Grot@h%C
1694 \ifdim\Grot@cos\p@<\z@
1697 % Height=$Dy$, Right=$Cx$, Left=$Ex$, Depth=$By$
1699 \Grot@Py\Grot@height \Grot@l\Grot@d%D
1700 \Grot@Px\Grot@right \Grot@l\Grot@h%C
1701 \Grot@Px\Grot@left \Grot@r\Grot@d%E
1702 \Grot@Py\Grot@depth \Grot@r\Grot@h%B
1706 % Height=$Cy$, Right=$Bx$, Left=$Dx$, Depth=$Ey$
1708 \Grot@Py\Grot@height \Grot@l\Grot@h%C
1709 \Grot@Px\Grot@right \Grot@r\Grot@h%B
1710 \Grot@Px\Grot@left \Grot@l\Grot@d%D
1711 \Grot@Py\Grot@depth \Grot@r\Grot@d%E
1715 % Now we should translate back by $(O_x,O_y)$, but \TeX\ can not really
1716 % deal with boxes that do not have the reference point at the left edge.
1717 % (Everything with a $-$ve $x$-coordinate would over-print earlier
1718 % text). So we modify the horizontal translation so that the
1719 % reference point as understood by \TeX\ \emph{is} at the left edge.
1720 % This means that the `centre of rotation' is not fixed by |\rotatebox|,
1721 % but typically moves horizontally. We also need to find the image of
1722 % the original reference point, $S$, as that is where the rotation
1723 % specials must be inserted.
1726 \advance\Grot@height\Grot@y
1727 \advance\Grot@depth\Grot@y
1728 \Grot@Px\dimen@ \Grot@x\Grot@y
1729 \Grot@Py\dimen@ii \Grot@x\Grot@y
1730 \dimen@-\dimen@ \advance\dimen@-\Grot@left
1731 \dimen@ii-\dimen@ii \advance\dimen@ii\Grot@y
1735 ^^A \GDebug{Rotate: (l,r,h,d)^^J%
1736 ^^A Original \the\Grot@l,\the\Grot@r,\the\Grot@h,\the\Grot@d,^^J%
1737 ^^A New..... \the\Grot@left,\the\Grot@right,%
1738 ^^A \the\Grot@height,\the\Grot@depth}%
1744 \raise\dimen@ii\hbox{\Grot@start\box\z@\Grot@end}}%
1747 \advance\Grot@right-\Grot@left\wd\z@\Grot@right
1754 % \subsection{Stretching and Scaling}
1757 % \begin{macro}{\scalebox}
1758 % The top level |\scalebox|. If the vertical scale factor is omitted it
1759 % defaults to the horizontal scale factor, |#1|.
1760 % \changes{v0.3d}{1994/03/06}{Better support for negative arguments.}
1763 \@ifnextchar[{\Gscale@box{#1}}{\Gscale@box{#1}[#1]}}
1767 % \begin{macro}{\Gscale@box}
1768 % Internal version of |\scalebox|.
1769 % \changes{v0.7a}{1995/04/11}
1770 % {\cs{leavevmode} moved earlier. graphics/1521}
1771 % \changes{v1.0j}{1999/01/07}
1772 % {made long. graphics/2908}
1773 % \changes{v1.1b}{2017/04/14}
1774 % {Adjust box resizing for math mode gh issue 6}
1776 \long\def\Gscale@box#1[#2]#3{%
1778 \def\Gscale@x{#1}\def\Gscale@y{#2}%
1779 \setbox\z@\hbox{{#3}}%
1780 \setbox\tw@\hbox{\Gscale@start\rlap{\copy\z@}\Gscale@end}%
1789 \hb@xt@-#1\wd\z@{\kern-#1\wd\z@\box\tw@\hss}%
1791 \hb@xt@#1\wd\z@{\box\tw@\kern#1\wd\z@\hss}%
1797 % \begin{macro}{\reflectbox}
1798 % Just an abbreviation for the appropriate scale to get reflection.
1799 % \changes{v0.3e}{1994/03/09}{Macro added}
1801 \def\reflectbox{\Gscale@box-1[1]}
1806 % \begin{macro}{\resizebox}
1807 % \changes{v0.3b}{1994/03/01}{Recode \cmd\resizebox.}
1808 % \changes{v0.7b}{1995/04/27}
1809 % {Add \cs{leavevmode} for graphics/1512}
1810 % Look for a |*|, which specifies that a final vertical size refers to
1811 % `height + depth' not just `height'.
1815 \@ifstar{\Gscale@@box\totalheight}{\Gscale@@box\height}}
1819 % \begin{macro}{\Gscale@@box}
1820 % Look for the |!| in the arguments.
1821 % \changes{v0.5a}{1994/07/20}
1822 % {Support French active !!}
1823 % \changes{v0.5d}{1994/10/24}
1824 % {Correct the support for !!}
1826 % {1995/12/06}{Use \cs{Gin@exclamation}}
1828 \def\Gscale@@box#1#2#3{%
1829 \let\@tempa\Gin@exclamation
1830 \expandafter\def\expandafter\@tempb\expandafter{\string#2}%
1831 \expandafter\def\expandafter\@tempc\expandafter{\string#3}%
1836 \toks@{\Gscale@box@dd{#3}#1}%
1840 \toks@{\Gscale@box@dd{#2}\width}%
1842 \toks@{\Gscale@box@dddd{#2}\width{#3}#1}%
1849 % \begin{macro}{\Gscale@box@dd}
1850 % Scale the text |#3| in both directions by a factor $|#1|/|#2|$.
1851 % \changes{v0.3i}{1994/03/23}
1852 % {Missing percent added}
1853 % \changes{v1.0i}{1999/01/07}
1854 % {made long. graphics/2908}
1856 \long\def\Gscale@box@dd#1#2#3{%
1857 \@begin@tempboxa\hbox{#3}%
1858 \setlength\@tempdima{#1}%
1859 \setlength\@tempdimb{#2}%
1860 \Gscale@div\@tempa\@tempdima\@tempdimb
1861 \Gscale@box\@tempa[\@tempa]{\box\@tempboxa}%
1866 % \begin{macro}{\Gscale@box@dddd}
1867 % Scale the text |#5| horizontally by a factor $|#1|/|#2|$ and
1868 % vertically by a factor $|#3|/|#4|$.
1869 % \changes{v0.3i}{1994/03/23}
1870 % {Missing percent added}
1871 % \changes{v0.7e}{1995/09/29}
1872 % {Add \cs{ifGin@iso} code added}
1873 % \changes{v1.0i}{1999/01/07}
1874 % {made long. graphics/2908}
1876 \long\def\Gscale@box@dddd#1#2#3#4#5{%
1877 \@begin@tempboxa\hbox{#5}%
1878 \setlength\@tempdima{#1}%
1879 \setlength\@tempdimb{#2}%
1880 \Gscale@div\@tempa\@tempdima\@tempdimb
1881 \setlength\@tempdima{#3}%
1882 \setlength\@tempdimb{#4}%
1883 \Gscale@div\@tempb\@tempdima\@tempdimb
1885 \ifdim\@tempa\p@>\@tempb\p@
1891 \Gscale@box\@tempa[\@tempb]{\box\@tempboxa}%
1896 % \begin{macro}{\ifGin@iso}
1897 % If this flag is true, then specifying two lengths to |\resizebox|
1898 % scales the box by the same factor in either direction, such that
1899 % neither length \emph{exceeds} the stated amount. No user interface
1900 % to this flag in the standard package, but it is used by the
1901 % |keepaspectratio| key to |\includegraphics| in the \textsf{graphicx}
1903 % \changes{v0.7e}{1995/09/29}
1910 % \begin{macro}{\Gscale@div}
1911 % The macro |#1| is set to the ratio of the lengths |#2| and |#3|.
1912 % \changes{v0.7a}{1995/04/11}
1913 % {Add trap for division by 0}
1914 % \changes{v0.7d}{1995/09/27}
1915 % {Use \cs{setlength} to support calc package}
1916 % \changes{v1.0a}{1996/09/16}
1917 % {Stop infinite loop if 2nd arg zero. graphics/2259}
1919 \def\Gscale@div#1#2#3{%
1920 \setlength\dimen@{#3}%
1922 \PackageError{graphics}{Division by 0}\@eha
1925 \edef\@tempd{\the\dimen@}%
1926 \setlength\dimen@{#2}%
1936 % \changes{v1.0u}{2016/10/09}
1937 % {avoid overflow for small lengths eg 5sp divided by 2sp}
1939 \ifdim\ifnum\count@<\tw@\maxdimen\else\dimen@\fi<8192\p@
1943 \dimen@ii\@tempd\relax
1944 \divide\dimen@ii\count@
1945 \divide\dimen@\dimen@ii
1947 \edef#1{\strip@pt\dimen@}}
1954 \let\Gin@codes\relax