\documentclass[11pt,twoside]{article}
\usepackage{asp2004}
\usepackage{graphicx}
\markboth{Mahoney}{Using {\ttfamily graphicx}}
\pagestyle{myheadings}

\begin{document}
\title{How to Use the {\ttfamily graphicx} Package}
 \author{T. J. Mahoney}
\affil{Instituto de Astrof\'\i sica de Canarias, E-38205 La Laguna, Tenerife,
Spain}


\begin{abstract}
This guide explains how to import and manipulate
graphics into your article for inclusion in a volume of proceedings
in the ASP Conference Series. 
\end{abstract}

\section{Introduction}
Given the widely varying degrees
of familiarity with \LaTeX\ of our authors, we feel that the \verb"\plotone",
\verb"\plottwo", and \verb"\plotfiddle" commands will serve most purposes. However,
those who are more {\itshape au fait} with \LaTeX\ might wish to use the {\ttfamily
graphicx} package. This package enables the user to wield far greater control
over the importation of graphics into a {\ttfamily.tex} file and, apart from
the usual sizing and rotational facilities, also enables the user to crop or trim an
image as desired (e.g., to get rid of surrounding blank margins). The {\ttfamily
graphicx} package is useful if you need to use only a part of a complete image.
This guide will take you through the various parameter (``keys'') of the package
and applying them to the sample figure {\ttfamily demo.eps} (copied from Kopka \&
Daly 1999).

\section{Invoking {\ttfamily graphicx}}
The first step to take is to ensure that you have the command\\

\verb"\usepackage{graphicx}"\\

\noindent in the preamble of your article. Importing a graphic is then done by
usingthe command\\

\verb"\includegraphics["{\itshape key1 = \ldots, 
key2 = \ldots, etc.}\verb"]{"{\itshape filename}\verb"}"

\noindent Optional parameters---called ``keys''---enable the figure to be resized,
rotated, cropped, trimmed, etc. These keys and their functions are listed below.

\begin{itemize}
\item \verb"scale =" {\itshape number} --- a magnification factor
\item \verb"width =" {\itshape length} --- the width to which the figure should be
scaled\footnote{If the height is not given, it too is scaled by the same amount.}
\item \verb"height =" {\itshape length} --- the height to which the figure should be
scaled\footnote{If the width is not given, it too is scaled by the same amount.}
\item \verb"totalheight =" {\itshape length} --- height plus depth of figure (to be
used if figure is rotated)
\item \verb"keepaspectratio = true/false" --- maintains the height/width ratio
\item \verb"angle =" {\itshape number} --- angle (in degrees)
by which the figure is to be rotated counterclockwise
\item \verb"origin =" {\itshape location}\footnote{%
{\ttfamily bl} = bottom left, {\ttfamily c} = center, {\ttfamily t} = top,
 {\ttfamily r} = right, {\ttfamily B} = baseline, or any meaningful combination
thereof.} --- the point about which rotation is to occur
\item \verb"draft = true/false" --- prevents figure from being imported, but created
a named box with the dimensions of the figure (this option is used to speed up
processing)
\item \verb"clip = true/false" --- excludes whatever is outside the bounding box
\item \verb"bb =" {\itshape llx lly urx ury} --- enters the bounding box coordinates,
which are given by default in points (1/72 inch),
manually (the bounding box might be missing or you might want to alter it)
\item \verb"viewport =" {\itshape llx lly urx ury} --- specifies bounding box 
w.r.t.\ bottom left of existing bounding box; used with {\ttfamily clip} to select
a part of the image (or to clear unwanted margins.
\item \verb"trim =" {\itshape dllx dlly durx dury} --- reduces the bounding box by
the amount specified
\item \verb"hiresbb = true/false" --- reads the bounding box information from
the line
\verb"%%HiResBoundingBox" in figure file
\end{itemize}

\section{Experimenting with {\ttfamily graphicx}}
Figure~\ref{fig1} shows the default image produced by the graphics file {\ttfamily
demo.eps}, called using the command\\

\verb"\includegraphics{demo}"\\

\noindent (note that none of the keys is used).

\begin{figure}[!ht]
\begin{center}
\includegraphics{demo}
\end{center}
\caption{Here is a {\ttfamily demo.eps} to play with.}\label{fig1}
\end{figure}

Figure~\ref{fig2} shows
 the same figure scaled by a factor of three and rotated by 60 degrees
anticlockwise and using the command\\

\verb"\includegraphics[scale = 3, angle = 60]{demo}"\\


\begin{figure}[!ht]
\begin{center}
\includegraphics[scale = 3, angle = 60]{demo}
\end{center}
\caption{Here is {\ttfamily demo.eps} again rescaled to three times its
original size and rotated counterclockwise through 60 degrees.}\label{fig2}
\end{figure}

Figure~\ref{fig3} shows the default image with a different aspect ratio, created by
varying the height and width with the command\\

\verb"\includegraphics[width = 400pt, height = 200pt]{demo}"\\

\begin{figure}[!ht]
\begin{center}
\includegraphics[width = 400pt, height = 200pt]{demo}
\end{center}
\caption{Here is {\ttfamily demo.eps} with a different aspect ratio.}\label{fig3}
\end{figure}

In Figure~\ref{fig4} we plot
the file {\tt family demo2.eps}, which has a larger bounding box but
using the default keys (\verb"\includegraphics{demo2}"). We see that the 
relevant part of the figure has
been forced down to the lower left of the figure in spite of our efforts to center it.
There are three ways of rectifying this situation. We can:
\begin{enumerate}
\item Force a new bounding
box manually with the {\ttfamily bb} key (keying in the original coordinates)
\item Use the {\ttfamily viewport} key
\item Use the {\ttfamily trim} key
\end{enumerate}

We can force a new bounding box by using:\\

\verb"\includegraphics[bb = 169 158 233 242]{demo2}"\\

We have used the bounding box values for {\ttfamily demo.eps} for 
{\ttfamily demo.eps2}. The result is shown in Figure~\ref{fig5}. We chose these
values for the new bounding box because we already knew them from {\ttfamily
demo.eps}; in practice we would need to experiment with various values in order
to find something that works.

\begin{figure}[!ht]
\begin{center}
\includegraphics{demo2}
\end{center}
\caption{Here is {\ttfamily demo2.eps}, which is {\ttfamily demo.eps} 
with a different bounding box; this
creates wide margins at the top and to the right of the original figure and
causing the relevant part of the figure into the bottom left corner.}\label{fig4}
\end{figure}

\begin{figure}[!ht]
\begin{center}
\includegraphics[bb = 169 158 233 242]{demo2}
\end{center}
\caption{We set a new bounding box manually with the key {\ttfamily bb}
to eliminate the unwanted margins and restore the figure to its central
position.}\label{fig5}
\end{figure}

We get identical results if we use the command\\

\verb"\includegraphics[viewport = 0 0 64 84]{demo2.eps}"\\

\noindent (see Figure~\ref{fig6}) or \\

\verb"\includegraphics[trim = 0 0 300 300]{demo2.eps}"

\noindent (see Figure~\ref{fig7}). (Note that the {\ttfamily} key takes the
bottom left corner of the existing bounding box as its origin.)

\begin{figure}[!ht]
\begin{center}
\includegraphics[viewport = 0 0 64 84]{demo2}
\end{center}
\caption{Elimination of unwanted margins using the
  {\ttfamily viewport} key (note that the origin, (0,0), is now the bottom
  left corner of the original bounding box.}\label{fig6}
\end{figure}

\begin{figure}[!ht]
\begin{center}
\includegraphics[trim = 0 0 300 300]{demo2}
\end{center}
\caption{Elimination of unwanted margins using {\ttfamily trim} key.}\label{fig7}
\end{figure}

\end{document}
