Copyright © 2005 Gene Michael Stover. All rights reserved. Permission to copy, store, & view this document unmodified & in its entirety is granted.
Herein are some experiments with LATEX's portable graphics. In most cases, I used a Lisp program to write the LATEX source code for each picture.
Here's a simple figure that I've borrowed from Web (& Print) Log 2005.
Here is the Lisp program which created that figure:
(defun draw-simple (strm)
(format strm "~&\\setlength{\\unitlength}{1mm}")
(format strm "~&\\begin{picture}(50,50)")
(loop for i from 1 to 5 do
(format strm "~&\\put(~D,0){~D}" (* 10 i) i)
(format strm "~&\\put(0,~D){~D}" (* 10 i) i))
(do ((i 0.0 (+ i 0.1)))
((>= i 5.0))
(format strm "~&\\put(~,2F,~,2F){ \\circle*{1} }"
(* 10 i) (* 10 (/ (* i i) 5))))
(format strm "~&\\end{picture}")
(format strm "~&")
strm)
Before graphing functions, let's figure out how to draw the x- & y-axese & label them.
Let's make a picture that is 120 milimeters wide by 90 milimeters high. Location (0, 0) in the graph is its lower left-hand corner. We'll label each axis with tick marks every milimeter. Every ten milimeters, we'll draw the number of milimeters (For example 10, 20, 30, ...)
Awesome! That wasn't too tough to do. I created a file called fig-axes00.tex, created a picture environment in it, then edited & compiled until I got what I wanted. It took about ten tries to get the horizonal axis the way I wanted, but the vertical axis was trivial because I used the horizontal axis as a model.
Here is the LATEX code which created that figure:
\setlength{\unitlength}{1mm}
\begin{picture}(130,100)(-10,-10)
% The horizontal axis
\put(0,0){\line(1,0){120}}
% On the horizontal axis, a tick mark every 10 milimeters
\multiput(0,0)(10,0){12}{\line(0,-1){1}}
% On the horizontal axis, label each tick mark
\put(0,-4){0}
\put(10,-4){10}
\put(20,-4){20}
\put(30,-4){30}
\put(40,-4){40}
\put(50,-4){50}
\put(60,-4){60}
\put(70,-4){70}
\put(80,-4){80}
\put(90,-4){90}
\put(100,-4){100}
\put(110,-4){110}
\put(120,-4){120}
% The vertical axis
\put(0,0){\line(0,1){90}}
% On the vertical axis, a tick mark every 10 milimeters
\multiput(0,0)(0,10){9}{\line(-1,0){1}}
% On the vertical axis, label each tick mark
\put(-5,0){0}
\put(-5,10){10}
\put(-5,20){20}
\put(-5,30){30}
\put(-5,40){40}
\put(-5,50){50}
\put(-5,60){60}
\put(-5,70){70}
\put(-5,80){80}
\put(-5,90){90}
\end{picture}
Let's plot
with individual,
filled dots.
Here is the Lisp program which created that file:
(defun draw-fig10 ()
(with-open-file (strm "fig10.tex" :direction :output
:element-type 'character
:if-exists :supersede
:if-does-not-exist :create)
(format strm "~&\\setlength{\\unitlength}{1mm}")
(format strm "~&\\begin{picture}(130,100)(-10,-10)")
(format strm "~& % The horizontal axis")
(format strm "~& \\put(0,0){\\line(1,0){120}}")
(format strm "~& % On the horizontal axis, a tick mark every 10 mm")
(format strm "~& \\multiput(0,0)(10,0){12}{\\line(0,-1){1}}")
(format strm "~& % On the horizontal axis, label each tick mark")
(format strm "~& \\put(0,-4){0}")
(format strm "~& \\put(10,-4){10}")
(format strm "~& \\put(20,-4){20}")
(format strm "~& \\put(30,-4){30}")
(format strm "~& \\put(40,-4){40}")
(format strm "~& \\put(50,-4){50}")
(format strm "~& \\put(60,-4){60}")
(format strm "~& \\put(70,-4){70}")
(format strm "~& \\put(80,-4){80}")
(format strm "~& \\put(90,-4){90}")
(format strm "~& \\put(100,-4){100}")
(format strm "~& \\put(110,-4){110}")
(format strm "~& \\put(120,-4){120}")
(format strm "~& % The vertical axis")
(format strm "~& \\put(0,0){\\line(0,1){90}}")
(format strm "~& % On the vertical axis, a tick mark every 10 milimeters")
(format strm "~& \\multiput(0,0)(0,10){9}{\\line(-1,0){1}}")
(format strm "~& % On the vertical axis, label each tick mark")
(format strm "~& \\put(-5,0){0}")
(format strm "~& \\put(-5,10){10}")
(format strm "~& \\put(-5,20){20}")
(format strm "~& \\put(-5,30){30}")
(format strm "~& \\put(-5,40){40}")
(format strm "~& \\put(-5,50){50}")
(format strm "~& \\put(-5,60){60}")
(format strm "~& \\put(-5,70){70}")
(format strm "~& \\put(-5,80){80}")
(format strm "~& \\put(-5,90){90}")
(format strm "~& % plot Y = 89 * sin (X/10)")
(format strm "~& % Individual points")
(loop for x from 0 to 120 do
(format strm "~& \\put(~A,~A){\\circle*{0.5}}" x
(+ (* 44 (sin (/ x 10))) 45)))
(format strm"~&\\put(90,70){$Y = 44 sin \\frac{X}{10} + 45$}")
(format strm "~&\\end{picture}")))
That Lisp program first outputs a copy of the picture
code for the previous example, the one with the labeld axes
but nothing else. Then the Lisp program figures the values
for a bunch of (x, y) pairs & uses them for a bunch of
\put \circle commands. Oh yeah,
& it also puts the equation onto the picture itself.
That's it.
Gene Michael Stover 2008-04-20