Example of including external graphics in LaTeX documents |
At present, the only graphics format that is convenient to
include in LaTeX documents is Encapsulated
PostScript.
You can convert other graphics formats into PostScript by
using various graphics programs (xv
,
for example)
or by using the TOM Conversion Service on the World-Wide Web. Plots that you
create in Maple can be saved automatically in PostScript
format.
Here is an extremely simple example, for demonstration purposes, of an Encapsulated PostScript file. Copy the following code with the mouse and save it in a file named redsquare.ps. (Normally, you would not code PostScript by hand: some external program would create the PostScript file.)
%!PS %%BoundingBox: 0 0 100 100 1.000 0.000 0.000 setrgbcolor newpath 0 0 moveto 100 0 rlineto 0 100 rlineto -100 0 rlineto closepath fill
Use your text editor to open the file test.tex that you
created in the preceding example, and add the command
"\includegraphics{redsquare.ps}
" just before the
"\end{document}
" statement. Save your file, run "latex
test", "dvips test", and "ghostview test.ps &" to
preview the result on the screen. You should see a red square on
a color monitor.
Next try modifying the \includegraphics
statement to read
\scalebox{2.718}{\rotatebox{-27.18}{\includegraphics{redsquare.ps}}}
Save your file and again run the commands "latex test", "dvips test", and "ghostview test.ps &" to preview the result on the screen. What happens? Next try
\resizebox{0.75\textwidth}{!}{\includegraphics{redsquare.ps}}
Can you figure out what these LaTeX commands are doing?
Incidentally, LaTeX can draw a colored square all by itself, without using PostScript. See the example.
Often illustrations are put inside a LaTeX "figure" environment so that they can "float" to various positions on the page to help LaTeX break pages at convenient points. Here is an example of how the corresponding LaTeX code looks.
\begin{figure} \begin{center} \resizebox{3cm}{!}{\includegraphics{redsquare.ps}} \end{center} \caption{My red square} \end{figure}
It is possible to flow text around graphics as in the example. One way to do this is to use the floatflt package, which is included in most standard LaTeX installations. Documentation is available on Mats Dahlgren's web page. Another possibility is to use wrapfig.sty.
Example of including external graphics in LaTeX documents |