Al Draw Te X
Al Draw Te X
Al Draw Te X
(Al)DraTEX
A package for doing (portable) graphics in TEX
Jos Winnink
jos.winnink@cpb.nl
1 Introduction rectangles
Arent there enough graphic systems that you can use in circles and ovals
combination with (LA)TEX? You may ask. It depends on bezier curves
what you need and prefer. Some systems use picture for-
Then there are add-on features like:
mats (e.g. different type of bitmap formats) that are gen-
painting
erated outside of TEX1 . This mechanism is inherent not
clipping
portable2. The same argument can be given to the use of
putting text into pictures
PostScript. That leaves two ways to implement graphics in
dimensions
TEX in a portable way.
backtracking features
One solution is to implement the graphic system in TEX the placement of figures
(like PICTEX3, and (Al)DraTEX). The other route that can
be taken is to use MET A F O N T in combination with TEX. In DraTEX offers different coordinate systems:
this article I will concentrate on the (Al)DraTEX-package. two dimensional
This package is a representative of the TEX approach. three dimensional
polar coordinates
Because (Al)DraTEX only depends on TEX, it can be used
on any system on which you want to process your TEX doc- The axes can be rotated during the drawing process.
uments. It is possible to use (Al)DraTEX in a non portable Furthermore DraTEX has knowledge of intersection points
fashion. Gurari describes in his book how to use PostScript, of lines and circles. You can do repetitons on simple vari-
but that is not the subject of this article. ables (Do-loops), on paths and with data. It is possible
In the rest of this article I will give a rough overview of the and usefull to define your own objects and commands. It
system and present some examples with the corresponding speaks for itself that doing calculations is also possible.
the source code. The examples are taken from Guraris
book. 2.2 The high-level facilities (AlDraTEX)
Based on the low-level facilities offered by DraTEX, charts
and diagrams are implemented in AlDraTEX.
2 Structure of (Al)DraTEX
Gurari used a two level design when creating (Al)DraTEX. Chart types
There is a lower level which consists off so called low-level
The following types of charts are offered.
drawing facilities. The file dratex.sty implements
pie charts
this level.
The file aldratex.sty implements the high-level facil-
ities, which are modular designed. This means that it is
possible to only load the module(s) you need.
45
The (Al)DraTEX package can be used without modifica-
tions with plain TEX, LATEX2" and LATEX. 10
15 30
2.1 The low-level facilities (DraTEX)
Of course there are the basic drawing facilities:
lines
moving from one location to another
marked locations
Eitan M. Gurari,T X & LAT X, Drawing & Literate Programming, McGraw Hill, 1994.
E E
1
TEX means any system like LATEX, LATEX2" and plain-TEX.
2
Portable to me means in this case only depending on standard TEX tools.
3
Michael J. Wichura, The PICTEX manual.
Dutch TEX Users Group (NTG), P.O. Box 394, 1740 AJ Schagen, The Netherlands Reprint MAPS#13 (94.2); Nov 1994
150 (Al)DraTEX, Portable Graphics in TEX Bijlage E
sentence
Su Mo Tu We Th Fr Sa
bar charts
the noun
girl
a b c
bb
tree diagrams
is done by executing:
sentence
\Draw
\RotateTo(90)
\Do(1,50) {
\Do(1,4){
the noun \LineF(22)
\Rotate(90)
}
\MoveF(22)\Rotate(-30)
\Scale(0.9,0.9)
}
girl \EndDraw
Reprint MAPS#13 (94.2); Nov 1994 Dutch TEX Users Group (NTG), P.O. Box 394, 1740 AJ Schagen, The Netherlands
Bijlage E (Al)DraTEX, Portable Graphics in TEX 151
Example 3 Example 5
To illustrate your own weather forecast column in the news- Drawing a fully connected network with 10 nodes
paper you could use the following program fragment.
\Draw(0.05in,1mm) 4 3
\DrawRectAt(-1,7,1,16)
\PaintRectAt(-1,3,1,7)
5 2
\PaintCircle(3) \Move(-0.04,5)
\Text(--32$o$F- - -0$o$C --) 6 1
\EndDraw
7 10
8 9
40 Example 6
An example tree
0
0 60 120
Is created bij the following piece of code
\Draw
\MarkLoc(a) \MoveTo(120,80) \MarkLoc(b)
\Axis(a,b)(S-1,0&60&120)
\Axis(a,b)(W-1,0&40&80)
\Define\Sin(1){
\SaveUnits
\Units(1pt,1pt) \MarkLoc(t)
\MoveTo(0,0) \MarkLoc(o)
\RotateTo(#1) \MoveF(1) is produced by
\MarkLoc(p) \CSeg\Y(o,p) \Draw
\MoveToLoc(t) \RecallUnits \PictNode(1){
} \Do(1,#1) {
\Define\Y(2){\Q=#2;} {\Line(3,10) {\Line(3,-10)}
\MoveTo(0,40) {\Move(0,9){\Line(-3,-9)} {\Line(3,-9)}}
\Do(0,120){ \Line(0,13)
\I=\DoReg; \I*20; \Text(--$\bullet$--)
\Sin(\Val\I) \Q*\DoReg; }
\Q/3; \Q+40; \Move(9,0)
\LineTo(\DoReg,\Val\Q) }
} }
\EndDraw \Tree()( 2,5 //
0,2 & 2,3 //
0,1 & 0,2 //
)
\EndDraw
Dutch TEX Users Group (NTG), P.O. Box 394, 1740 AJ Schagen, The Netherlands Reprint MAPS#13 (94.2); Nov 1994
152 (Al)DraTEX, Portable Graphics in TEX Bijlage E
Example 7 4 Conclusions
A transition diagram describing a finite state automata is In my opinion Gurari succeeded in implementing a pow-
quite easy generated using the following program. erfull graphics facility for TEX with TEX. The drawback
\Draw
of his approach is the time it takes to process the graphics.
\NewCIRCNode(\StateNode,106,)
\NewCIRCNode(\AStateNode,106,103) An advantage is that you get a system that has a one-pass
\Define\StateAt(3)% approach and can be used on any platform for which there
{\MoveTo(#2,#3) \StateNode(#1)(--$q_{#1}$--)} exists a TEX implementation.
\Define\AStateAt(3)%
{\MoveTo(#2,#3) \AStateNode(#1)(--$q_{#1}$--)} The system itself is much more versatile than e.g. the pic-
\DiagramSpec(\StateAt & \AStateAt & \TransEdge) ture environment that comes with LATEX2" .
\ArrowHeads(1)
\Diagram (0,0,0 & 1,50,50 & 3,90,-50 & 4,20,- I myself experienced a problem with the software that was
50)%
included in the book. This was version 1.0 that gave some
(2,75,0)%
(0,1,a,b & 1,2,a, & 0,2, ,b & 2,2,0,b & 0,4,a, problems with LATEX. On the FTP-site4 mentioned in the
& 4,3,a,b) book I found version 1.1 and this version has not shown
\CurvedEdgeAt(3,1,0,1,1,0)(20,0.3,0,0.5) any problems up to now.
j
\EdgeLabel[+](--a--)
\EndDraw I like to suggest to the people involved in the LATEX3 project
to look at this package before implemting a graphics sub-
q1 system.
j gj
a a
b
q0 q2
a
b
b
j j
a
a
q4 q3
b
4
ftp-address: ftp.cis.ohio-state.edu in /pub/tex/osu/gurari.
Reprint MAPS#13 (94.2); Nov 1994 Dutch TEX Users Group (NTG), P.O. Box 394, 1740 AJ Schagen, The Netherlands