Sep. 2003 Lenko Grigorov, Queen's University
1
Graphics for DES
…circles and arrows in the sand
Sep. 2003 Lenko Grigorov, Queen's University
2
Goal
• Create graphics (graphs) which can be (re)used in papers.– vector description (vs. bitmaps)
• scalability• size
– application independent data format• can be used with Word/LaTeX/etc.• can be edited
– easy to create (we are lazy)– cheap!
Sep. 2003 Lenko Grigorov, Queen's University
3
Paths
• CorelDRAW (or Visio)– best tool– Windows-only– expensive (or pirated)
• xfig– discouraging user interface– UN*X-only (a very limited Windows-version exists)
• free software (Mayura Draw, Sketch, Sodipodi, jPicEdt, etc…)– platform/format dependability
Sep. 2003 Lenko Grigorov, Queen's University
4
Choice
• Encapsulated PostScript (EPS)– vector format– standard– works with PS printers only– convertible to PDF– good integration with LaTeX– importable to Word
Sep. 2003 Lenko Grigorov, Queen's University
5
Tools• User (geek)• LaTeX (MiKTeX)
– http://www.miktex.org/
• pstricks (LaTeX add-on)– http://www.pstricks.de/
• Java– http://java.sun.com/
• Ghostscript– http://www.cs.wisc.edu/~ghost/
• epsBoxFix (that’s mine!!… and it’s buggy)– http://www.a-ideas.com/epsBoxFix/
Sep. 2003 Lenko Grigorov, Queen's University
6
• Describe graph– create .tex file\documentclass{article}\usepackage{pst-tree} %for trees\usepackage{pst-node} %for other graphs\pagestyle{empty}\begin{document}. . . %here be graphics\end{document}
– use PST commands to describe graph• more on this later• unfortunately, no lazy graphical tool
– well, there is jPicEdt for the brave
Process (1 of 3)
Sep. 2003 Lenko Grigorov, Queen's University
7
Process (2 of 3)
• Compile graph– two runs of LaTeX (PST calculates distances)
• latex graph.tex
• latex graph.tex
– DivX… I mean DVIPS (-E is for EPS)• dvips -o graph.eps -E graph.dvi
– epsBoxFix to fix the output of DVIPSjava -jar epsBoxFix.jar "C:\gs\gs8.00\bin\gswin32c.exe" graph.eps
• CAUSION: Do NOT trust your only copy of an EPS file to epsBoxFix!
Sep. 2003 Lenko Grigorov, Queen's University
8
Process (3 of 3)
• Use graph in paper– Word:
• menu Insert/Picture/From file
• print to PDF or to PS printer only
– LaTeX:\begin{figure}
\begin{center}
\includegraphics[scale=.67]{graph.eps}
\caption{\label{fig:1}Cindy Crawford on the beach}
\end{center}
\end{figure}
Sep. 2003 Lenko Grigorov, Queen's University
9
Why epsBoxFix?(or a small advertisement)
• EPS files contain a BoundingBox comment, which specifies which part of the whole page actually contains the graphic
• DVIPS does not handle PST output correctly and the BoundingBox comment is incorrect
• I couldn’t find a freely available tool, which can convert PS to EPS reasonably, or which can fix the BoundingBox comment– GhostScript can be used for PS2EPS conversion, but Type1
fonts are rendered to bitmaps (which is no good)
Sep. 2003 Lenko Grigorov, Queen's University
10
EPS vs. embedding
• embedding– simpler– no problems with fonts– smaller file
• EPS– environment-independent– reusable!– standard
Sep. 2003 Lenko Grigorov, Queen's University
11
PSTricks
• Documentation:– http://www.maths.lth.se/help/latex/pstricks/
• User Manual
• untitled – PST for graphs
• Use:– \usepackage{pst-tree} %for trees– \usepackage{pst-node} %for other graphs
Sep. 2003 Lenko Grigorov, Queen's University
12
PST nodes
• empty node (no visual output)– \pnode(x,y){name}
• circular node, empty– \Cnode*[par](x,y){name}
• circular node, with text– \circlenode*[par]{name}{stuff}
• name is used to create connections• stuff is the stuff you want in the node
Sep. 2003 Lenko Grigorov, Queen's University
13
PST connections
• Syntax:– \ctype[par]{arrows}{node1}{node2}
• “ctype” can be:– ncline (straight line)– ncarc (an arc). [arcangle=deg] can be used to
control the curve (30° works well)– nccircle[par]{arrows}{node}{radius} (can be
used for self-loops)
Sep. 2003 Lenko Grigorov, Queen's University
14
PST connection labeling• label commands have to come right after connection
commands• commands are:
– \naput*[par]{stuff} (above connection)– \ncput*[par]{stuff} (on connection)– \nbput*[par]{stuff} (below connection)
• the star causes the label to mask the underlying connection• use [npos=number] to position the label along the
connection (0=starting node, 1=end node)• use [nrot=:angle] to rotate label, [nrot=:U] makes it
parallel to the connection
Sep. 2003 Lenko Grigorov, Queen's University
15
PST node labeling
• \nput*[par]{refangle}{name}{stuff}
• refangle tells at what angle around the node the label should be placed
• [labelsep=number] tells how far from the node the label should be placed
Sep. 2003 Lenko Grigorov, Queen's University
16
PST parameters
• Parameters can be set globally using:– \psset{key=value}
• Could be:– radius– arrows (-> ; <- ; <->)– arcangle– linecolor– etc…
Sep. 2003 Lenko Grigorov, Queen's University
17
Labeling example\cnode(0,0){.5cm}{root}\cnode*(3,1.5){4pt}{A}\cnode*(3,0){4pt}{B}\cnode*(3,-1.5){4pt}{C}\psset{nodesep=3pt} %or\psset{nodesep=3pt\psset{nodesep=3pt,,nrot=:U}nrot=:U}\ncline{root}{A}\naput{above}\ncline{root}{B}\ncput*{on}\ncline{root}{C}\nbput{below}
Sep. 2003 Lenko Grigorov, Queen's University
18
PST matrix
• The coolest stuff for the manual creation of aligned graphs
• \psmatrix[par] … \endpsmatrix
• \begin{psmatrix}[par] … \end{psmatrix}
• columns separated by ‘&’, rows by ‘\\’
• par: colsep=number, rowsep=number, etc…
• mnode=p|c|circle|… (the prefixes of node names)
• nodes referred by name or coordinates (e.g., {1,2})
Sep. 2003 Lenko Grigorov, Queen's University
19
Matrix example 1
$
\psmatrix[colsep=1cm]
& [mnode=circle] X \\
Y & Z
\endpsmatrix
\psset{nodesep=3pt,arrows=->}
\ncline{1,2}{2,1}
\ncline{1,2}{2,2}
\ncline[linestyle=dotted]{2,1}{2,2}
$
Sep. 2003 Lenko Grigorov, Queen's University
20
Matrix example 2
\psset{arrows=->}
\begin{psmatrix}[rowsep=1cm,mnode=circle]
[name=A, mnode=p] &
[name=B,colsep=.5cm,doubleline=true,doublesep=.1mm] {\makebox[1ex]{}} &
[name=C] {\makebox[1ex]{}}
\end{psmatrix}
\ncarc[arcangle=30]{->}{B}{C}
\naput{$\textup{goS}_i$, $\textup{goB}_i$}
\ncarc[arcangle=30]{->}{C}{B}
\naput{$\textup{fetch10}_i$, $\textup{fetch20}_i$}
\ncline{->}{A}{B}
Sep. 2003 Lenko Grigorov, Queen's University
21
PST trees
\pstree{(root)node}{(sub)trees and (terminal)nodes}
\pstree{\Toval{root}}{\TC* \TC* \TC* \TC*}
\pstree{\Tp}{
\TC*
\pstree{\Tc{3pt}}{\TC* \TC*}
\TC*}
Sep. 2003 Lenko Grigorov, Queen's University
22
PST trees
• Brackets are important!• Nodes are: Tp, Tc, Tcircle, … (T with node type)• Set parameters using \pstree[key=value]
– treemode=L|R|U|D (left, right, up, down)– treefit=tight|loose– treesep (separation between nodes in same level)– levelsep=*number (separation between levels; no star:
use centers of nodes, star: use edges of nodes and 2 LaTeX runs needed)
– thistreefit / thistreesep / thislevelsep
Sep. 2003 Lenko Grigorov, Queen's University
23
PST tree edges
• Names of nodes– name=id– \pssucc, \pspred (this and predecessor)
• Edges are drawn automatically– override with edge=none|connection command
• Edge labels– use \naput, \ncput etc. after the node or– ^{label} = \naput; _{label} = \nbput (\ncput: no shortcut)– ~{label} labels the node (use \nput to change position)– if you use \nput, you cannot use ‘^’ and ‘_’
Sep. 2003 Lenko Grigorov, Queen's University
24
Tree example\psset{arrows=->}
\pstree[treemode=R,linecolor=history]
{\Tcircle[linecolor=history]{\makebox[1em]{0}}}
{\pstree[linecolor=black]
{\Tcircle[linecolor=black]{\makebox[1em]{1}}
^{$\textup{goS}_{1}$}}
{\Tcircle{\makebox[1em]{3}}~{$v=-400$}
^{$\textup{fetch10}_{1}$}
\Tcircle{\makebox[1em]{4}}~{$v=\infty$}
_{$\textup{goS}_{2}$}
}}
Sep. 2003 Lenko Grigorov, Queen's University
25
Summary
• The solution is:– versatile (PST can make all kinds of graphics)– applicable (vector EPS output)– cheap (free)
• Is it fun?– yes, assuming we have the geek user
• Tools still missing…– GIDDES 2 PST?
• Conclusion:– we are still in the dark ages of circles and arrows
Sep. 2003 Lenko Grigorov, Queen's University
26
Service Pack 1
• This information was obtained recently:– Karbon14 (part of KOffice)
and– Draw (part of OpenOffice)
seem to be capable of exporting to EPS.• KOffice runs on UN*X, Linux, Windows+Cygwin.
• OpenOffice runs on UN*X, Linux, Windows.
Sep. 2003 Lenko Grigorov, Queen's University
27
…
• Lenko recommends the use of:
TeXnicCenterhttp://www.toolscenter.org/products/texniccenter/
(I get $5 for each eye that sees this slide)