Aside: drawing a colored square with native LaTeX code |
The preceding example shows how to include an external graphics file into a LaTeX document. The example is intentionally simple, to illustrate the concept. For this very simple example, LaTeX is smart enough to draw the picture without using an external graphics program.
To see how native LaTeX code can produce a red square, copy
the following example with the
mouse, save the file as square.tex,
and run the commands latex square
, dvips square
,
and ghostview square.ps &
to preview the output on the
screen.
\documentclass[12pt]{article} \usepackage{graphics,color} \begin{document} \newsavebox{\mysquare} \savebox{\mysquare}{\textcolor{red}{\rule{1in}{1in}}} This is a red square: \usebox{\mysquare} Here is a rotated and scaled square: \scalebox{0.696}{\rotatebox{69.6}{\usebox{\mysquare}}} Here is a resized square with the aspect ratio distorted: \resizebox{0.69\textwidth}{0.6\textheight}{\usebox{\mysquare}} \end{document}
The example also shows how LaTeX can save and reuse a
picture via the savebox
command.
Aside: drawing a colored square with native LaTeX code |