This document describes various ways to get figures into LaTeX documents.
There are two possibilities for directly producing a PostScript version of an Splus graphic:
postscript(file="foo.ps", horiz=F, onefile=F, print.it=F) plot... dev.off()
The output will be written to the specified file.
It may be useful to process the PostScript file with the ps2epsi program (supplied with ghostscript) before including it into latex, since Splus tends to leave large margins:
ps2epsi foo.ps foo.eps
This also adds a bitmap version of the image, which is apparently used by certain Macintosh software to display it on the screen.
A method is described here for including Encapsulated PostScript figures into LaTeX 2e documents using the "graphics" macro package.
The declaration for dvips is:
\documentclass{article}
\usepackage[dvips]{graphics}
\begin{document}
or for a Macintosh with Textures:
\documentclass{article}
\usepackage[textures]{graphics}
\begin{document}
To include an image in a document, use something like:
\includegraphics{foo.eps}
The included file should have a name ending with ".ps" or ".eps".
TeX interprets the image as a single "box", as though it was simply a large character. So A\includegraphics{foo.eps}B will include the image in the middle of a line between the A and B.
The usual practice is to include the image in a figure environment:
\begin{figure}
\begin{center}
\includegraphics{xfig.eps}
\end{center}
\caption{this is a figure}
\end{figure}
If the figure is the wrong size for the document, it can be scaled:
\scalebox{0.5}{\includegraphics{xfig.eps}}
The scaling in the horizontal and vertical directions can be specified independently:
\scalebox{0.5}[0.8]{\includegraphics{xfig.eps}}
The graphic can also be rotated, with a rotation specified in degrees anti-clockwise:
\rotatebox{180}{\includegraphics{xfig.eps}}
To combine rotation and scaling, the macros can be nested:
\scalebox{0.5}[0.8]{\rotatebox{180}{\includegraphics{xfig.eps}}}
It's possible to embed formulae inside an Splus figure or xfig diagram, but this requires a more complicated procedure.
Firstly, in the case of an Splus figure, it must first be produced with the Fig device driver active:
fig("fig1.fig")
plot...
dev.off()
Now from outside S do: xfig fig1.fig.
Inside xfig, add the LaTeX expressions to the figure, using
$...$ to switch to math-mode where necessary. Use
the normal method in xfig for adding text, but set the "special text"
mode using the "Text flags" menu at the bottom of the screen.
Export the figure from xfig twice: firstly using the format "Combined PS/LaTeX (PS part)" to a file such as fig1.pstex, secondly using "Combined PS/LaTeX (LaTeX part)" to a file such as fig1.pstex_t.
Create a driver file (e.g., fig1.tex) containing something like:
\documentclass{article}
\usepackage{epsfig}
\setlength{\textwidth}{100cm}
\setlength{\textheight}{100cm}
\begin{document}
\pagestyle{empty}
\input{fig1.pstex_t}
\end{document}
Run the commands:
latex fig1.tex dvips -E fig1.dvi -o fig1.eps
You should now have a file named "fig1.eps" which can be included (with scaling and rotation if desired) in other LaTeX documents.
Note that there is a problem in old versions of dvips (pre 1997) in that the BoundingBox in the "fig1.eps" file only takes account of latex output, not the included figure.
It's possible to create colour PostScript output by setting options on the PostScript device:
motif() device, changing the colour scheme
if necessary.
ps.options(colors=xgetrgb(), background=xgetrgb("background"))
postscript() procedure
described above.
Note that if the background colour is changed in this way, the
ps2epsi program will no longer work. To leave the background white
instead, omit the background argument from the ps.options
procedure call.
For more technical details of the LaTeX 2e graphics package see "Packages in the Graphics Bundle" by D. Carlisle (in DVI or PostScript format).
Another detailed document is "Using EPS Graphics in LaTeX-2e Documents" by Keith Reckdahl (in PostScript format).
For information about producing PostScript files from Splus see the help pages for the postscript, xgetrgb, ps.options and ps.options.send procedures and the Splus Users Manual.
PostScript is a language for describing how images should be drawn on a page. PostScript data can sent directly to a laser printer which supports PostScript, or can be displayed on a computer screen using a program such as ghostscript. A PostScript file should begin with the characters "%!". Here's an example:
%!PS-Adobe-3.0
150 dict begin gsave
/bd{bind def}def
/PVer 3200 def
% drawing commands
/I{Coord SetPage 1 setlinecap 1 setlinejoin
LineTypes{RastersPerPoint ScaleArray}forall
/Helvetica findfont
PointSize RastersPerPoint mul Cex mul scalefont setfont
/Colors GColors def
}bd
...
A PostScript file is "encapsulated" for the purposes of this document if:
it meets some extra restrictions which allow it to be embedded in other documents.
it has a "bounding box" comment which specifies the rectangle within which the PostScript will place its output on the page. e.g.,
%%BoundingBox: 15 13 575 829
This gives the coordinates of the lower-left and upper-right corners of the box in points (with 72 points per inch).
usually it will have additional text in the comment at the beginning of the file:
%!PS-Adobe-3.0 EPSF-2.0
When ghostview displays an encapsulated file, it will reduce the size of the window on the screen to the bounding box limits.