%Started May 1996, C.G. van der laan, cgl@rc.service.rug.nl %Version June 1996 \newif\ifdraft\drafttrue \draftfalse \ifdraft\else\input psfig \fi %Watch out for double ! in verbatim, especially with %!!PS \input blue.tex \loadtocmacros\tolerance500\hbadness=499\hfuzz=5pt \parindent=1pc\everyverbatim{\unmc} %Needed EPS files: baker.eps, barnwindowii.eps, bentley.eps, % eschera.eps, escherb.eps, escherknotmf.eps, % escherknotiii.epsabr, flower.eps, % gurariabc.eps, gurarisq.eps % jvr.eps, linebundle.eps, malbork.eps, % polygon.eps, polygonii.eps, prpie.eps, % sine.eps, sinedisks.eps, seal.eps, % textalongarc.eps, textalongspiral.eps. \bluetitle Paradigms: Just a little bit of PostScript \blueissue \maps{96}2 \bluepictures\metapostpic\pstexpic \blueabstract It is all about creating EPS\Dash with graphics\Dash to be merged with \AllTeX{} scripts. The emphasis is on creating raw PostScript for simple symmetrical pictures. Asides, like incorporating accurate graphs of math functions, typesetting text along curved paths, or tables set sideways have been addressed. A poor man's mftoeps approach is touched upon: (declarative) METAFONT into (imperative) PostScript. \bluekeywords Declarative program, education, EPS, Escher, graphics, imperative code, \AllTeX, math graphs, METAFONT, merging EPS and \AllTeX, MetaPost, mftoeps, PostScript, sideways tables, text along curved paths. \beginscript \bluehead BLUe's Design X Hi folks. The user's guide which comes with BLUe's format system\Dash Publishing with \TeX, PWT for short\Dash is processed {\em completely\/} by \TeX, {\em no\/} other tools such as \PS{} are needed.\ftn{Nobody knows what the future has in store, but for the moment I consider it a good thing that the PWT guide can be processed just by \TeX, well \dots with BLUe's format.} However, of late I exercised \MF \Dash well, eventually MetaPost with the help of Jos Winnink\Dash for graphics to be included in \TeX{} documents, and finally embarked PostScript straightaway to create EPS pictures. $$\metapostpic$$ \PS{} is involuntary needed to (electronically) paste up the graphics, and as resulting file format.\ftn{For exchange the {\tt.tex} and (hand-coded) {\tt.eps} files are much better suited because of their conciseness. This can't be beaten, not even by Adobe's PDF\Dash Portable Document Format.} If we come to think of graphics as $$\vbox{\hbox{just doing the `right' strokes or fills}}$$ then \PS{} provides the means for this: lines, splines and circular arcs, to be drawn or filled.\ftn{PostScript II also provides for colors and processing in a network.} I use the sidestep $$\vbox{\hbox{\MF{} $\rightarrow $MetaPost $\rightarrow$ EPS}}$$ for general pictures but also for obtaining the right (control) points explicitly from a decalarative specification in \MF, as shown by Escher's knot at the end.\ftn{Another way for arriving at the EPS code is to use Jackowski's |mftoeps| package or to use MetaPost.} $$\pstexpic$$ With respect to graphics \PS{} can be seen as a {\em little\/} language in the UNIX tradition.\ftn{See Bentley's Little languages in `More programming pearls\Dash\-Confes\-sions from a coder.' Addison-Wesley.} A little bit of \PS{} adheres the 80\%--20\% adage: 80\% of the effects (or more) with 20\% of the energy (or less). One can with a little knowledge of \PS{} code graphics immediately and {\em completely\/} in \PS. The more so because of the ubiquitous public domain GhostScript previewers to verify the result, next to of course the \PS{} laser printers. Furthermore, text is just a special case of graphics, and merging just a little bit of text\Dash malenki Russians would say\Dash with the graphics goes equally simple at first glance. And to end the lovesong the inclusion of accurate graphs of mathematical functions goes well via coding these in \PS{} and including these as figures. (Of course Hobby's graph extension could be used as well, or other advanced graphics packages.) This is illustrated by a graph of the sine function to convey the idea. PStricks is about {\em interfacing}. Not assuming knowledge of \PS. This note discusses mainly {\em merging}. Is about extending your \TeX pertise with just a little\Dash tsjut-tsjut Russians would say\Dash knowledge of \PS{} rewarded by high returns. Below I'll summarize what is needed from \PS, and illustrate the use of it with a few examples, introducing en route the operators we need given the example. \bluehead PostScript \bluesubhead Processing \PS{} comes with a user's guide (cookbook) and reference manual, the so-called blue and red books in the Adobe \PS{} series. For processing \PS{} an interpreter is needed, such as a \PS{} laser printer or a GhostScript previewer. For inclusion in \AllTeX{} I use the psfig macros.\ftn{Courtesy Trevor J. Darrell.} Goossens in his PostScript and \AllTeX, \maps{92}1, nicely details about inclusion of PostScript.\ftn{See also the \LaTeX{} Companion.} As with PDF I consider the post-processing capability {\em independently\/} from the tool which created the \PS{} source, very powerful and flexible. \bluesubhead Subset 0 from the language \PS{} is stack-oriented. This means that operations are prescribed in polish-reverse notation, also known as prefix notation, similar to the HP pocket calculators. Addition\Dash use of operator |add|\Dash for example is notated as follows. \beginverbatim 2 3 add%yields 5 on the stack, 2 3 consumed !endverbatim \PS{} is artificially structured via structure information in comments, double \%-ed comments. Programs which obey the Adobe structure are called conforming and this is usually needed for inclusion within \AllTeX, especially the BoundingBox line is required. \blueexample Conforming EPS structure \beginverbatim %!!PS EPS %%Title: <name> %%Creator: <name> %%CreationData: <date> %%BoundingBox: <llx> <lly> <urx> <ury> %%DocumentFonts: (atend) %%EndComments <prolog> %%EndProlog %%Page: 0 1 <page 1> %%Page: 1 2 <page 2> %%Trailer <...> %%DocumentFonts: Times-Roman ... %%Pages: 3 %%EOF !endverbatim Creating and drawing paths is done by separate operators. For creating paths operations like |moveto| are provided while drawing goes via |stroke|. \beginverbatim 0 0 moveto 0 10 lineto%create path stroke%draw a v-line of 10pt height !endverbatim Variables\Dash names to be associated with their values\Dash are handled via the so-called dictionaries. The functionality can also be obtained via procedures. \beginverbatim /size {10} def !endverbatim The so-called literal name is preceded by a slash to distinguish the declaration from its invoke. The invoke is done by just the name, also called executable name. The procedure text is surrounded by curly braces. Parameters are absent too. The (operand) stack is used. For graphics we have a CurrentTransformMatrix\Dash CTM\Dash which maps the user space on the device space, the printer or screen. Equally powerful is the concept of encapsulating graphics via |gsave| and |grestore|, that is the graphics state is local\Dash encapsulated\Dash after |gsave| until |grestore|. Next to the CTM \PS{} maintains the currentpoint and currentpath. Batagelj, \maps{95}1\Dash Combining \TeX{} and \PS\Dash provides an in a nutshell overview.\ftn {Nice are the hints to remove repeated parts from files which are generated by CorelDRAW and Mathematica, in order to reduce the size of the automatically generated and to be included files. (The idea is to remove duplicate `dictionaries' which are included with each result.) The example of how to include graphs of math functions in a document is {\em very\/} useful. However, with respect to his first picture I would prefer to use the inherent symmetry in the data as opposed to providing all the data.} Another introduction is in Fokker en van Oostrum's `Plaatjes in een tekst,' \maps{94}2, next to a survey of drawing software. \bluesubhead Summary of (graphics) commands The following snapshot is borrowed from Gurari, well \dots a little modified.\ftn{% Gurari E.M (1994): \TeX{} \& \LaTeX\Dash Drawing \& Literate Programming. McGraw Hill. ISBN 0-07-025208-4.} Its main purpose is to show that the number of relevant graphics primitives is low. The functionalities will be dealt with along the way in the examples. For the details of the commands or the list of operators see the red book.\ftn{A complete list with functional summaries is in the red book section 6.2 Operator summary.} $$\everyverbatim{\emc} \vbox{\halign{\hfil#\cr \bf Arithmetic and math operators\hfill\cr |<num>| |<num>| mul $num$ \cr |<num>| sine $num$ \cr % \bf Path construction operators\hfill\cr currentpoint $x$ $y$ \cr |<x>| |<y>| moveto \cr |<dx>| |<dy>| rmoveto \cr |<x>| |<y>|lineto \cr |<dx>| |<dy>| rlineto \cr $\langle q_{1x}\rangle$ $\langle q_{1y}\rangle$ $\langle q_{2x}\rangle$ $\langle q_{2y}\rangle$ $\langle p_{2x}\rangle$ $\langle p_{2y}\rangle$ curveto \cr $\langle c_x\rangle$ $\langle c_y\rangle$ $\langle r\rangle$ $\langle ang_1\rangle$ $\langle ang_2\rangle$ arc \cr % \bf String operators\hfill\cr |<string>| |<num>| |<num>| getinterval \cr % \bf Character and font operators\hfill\cr {\tt\char92}|<fontname>| findfont \cr \ |<fontsize>| scalefont setfont \cr |<string>| show \cr |{<body>}| |<string>| kshow \cr % \bf Graphics state operators\hfill\cr |<num>| setgray \cr |<num>| setlinewidth \cr % \bf Dictionary operators\hfill\cr /|<defname> {<body>}| def \cr % \bf Coordinate system and matrix operators\hfill\cr |<num>| |<num>| translate \cr |<num>| |<num>| scale \cr |<num>| rotate \cr % \bf Relational, boolean, and bitwise operators\hfill\cr |<num>|\||<string>| |<num>|\||<string>| le $bool$\cr % \bf Control operators\hfill\cr |<bool> {<truepart>} {<falsepart>}| ifelse \cr |<num> {<body>}| repeat \cr |<from> <step> <to>{<body>}| for \cr } }$$ With prefix $\langle in\rangle\> \langle operator\rangle\>\langle result\rangle$ is elegant. \bluesubhead What is not allowed as EPS? I'm not knowledgeable enough to answer that question, nor do I know of a full-blown definition of EPS. For the moment it is some subset which works with all interpretors, with my subset 0 in there. When one restricts oneself to the basics of graphics, arithmetic and similar operations then the boundary area between EPS and full \PS\Dash or its various implementations\Dash is not in sight. \bluesubhead Documentation The red book\Dash the reference manual\Dash is generally recommended, though the blue book\Dash the tutorial and cookbook\Dash is also nice.\ftn{I used the \PS I red book and this is well-suited to get the flavour. For \TeX{} and METAFONT %\MF{} %font not available this is similar. To grasp the basic ideas Knuth's first book is a more concise survey of the main lines of thought than \TB{} and {\sl The METAFONTbook}.} \blueexample Pie chart from the blue book $$\ifdraft\vbox to3in{\vss\hbox{Pie chart}\vss} \else\psfig{file=prpie.eps,height=3in} \fi$$ The invoke is essentially as follows and shows that the codes can be used straightforwardly.\ftn{It is not standard \PS. We have to construct some kind of library to use the PostScript programs from. Maybe the CTAN as global network library? Copied on the various CD-ROMS?} It is no longer necessary to mesh around with the picture environment or so, to achieve the effect. \beginverbatim %preliminary matter (January Pie Sales) 24 12 %... array size [ [(Blueberry) .12 ] [(Cherry) .30 ] [(Apple) .26 ] [(Boston Cream) .16 ] [(Other) .04 ] [(Vanilla Cream) .12 ] ] 306 396%translate center to 140 %size DrawPieChart showpage !endverbatim There is also a \PS-FAQ, consult |ftp wilma.cs.brown.edu:|\\ \null\qquad \qquad |pub/comp.lang.postscript|. It contains an annotated bibliography as well. The examples from Adobe's blue book are available on the net. \bluesubhead Proofing For previewing or printing, {\em as such\/} I have to include a shift to move the picture away from the lower left corner, say \beginverbatim 300 500 translate !endverbatim \bluesubhead Inclusion I usually build a figure symmetrically around the origin and then include it via \beginverbatim $$\psfig{file=<name>,height=<number><unit>}$$ !endverbatim A unit can be |in|(ch), |cm|, and ilks. \cs{psfig} is very vulnerable to spaces because of \TeX's parsing. So no spaces in there. Now and then I forget to inactivate the |translate| needed while previewing. No real problem. \bluesubsubhead BoundingBox Providing the right BoundingBox coordinates has all to do with proper placement within context, the look-and-feel. Default \PS{} assumes the origin\Dash in user space\Dash at the lower left corner of the paper\Dash in device space. Surround the picture by as-if lines and supply the coordinates, in points as units in user space coordinates, of the lower left corner and the upper right corner in the BoundingBox specification. Simple is to build a picture around its symmetry point\Dash and let this coincide with the origin\Dash with as pleasing result that the horizontal positioning comes out centered, when used within math display. Vertically, I add a 10 or so extra on either side in the BoundingBox specification, but that depends on the character of the picture. Some preview systems can measure the BoundingBox and allow adjustment interactively.\ftn{For a summary of tools to assist finding the BoundingBox coordinates see, Reckdahl K (1995): Using EPS graphics in \LaTeX{} documents. reckdahl@leland.stanford.edu.} \bluesubhead Writing PostScript A line bundle and a variant of it are introduced to show how to create simple EPS. \bluesubsubhead A line bundle $$\ifdraft\vbox to1in{\vss\hbox{Line bundle}\vss} \else\psfig{file=linebundle.eps,height=1in} \fi$$ How to do this in \PS? A line as such is simple. First a |moveto| and then a |lineto|. So a way is to create a loop and repeatedly draw from the origin to the end of the various lines. This can be done elegantly by using appropriately the CTM. \beginverbatim %!!PS EPS %%Title: Line bundle %%Creator: cgl %%CreationDate: June 4 1996 %%BoundingBox: -40 -45 40 45 %%Pages: 1 %%EndProlog %%Page: 1 1 /r 36 def 10{0 0 moveto r 0 lineto 36 rotate }repeat stroke showpage !endverbatim Explanation. The idea is that first a simple line is draw, for example along the x-axes. What happens if after that we rotate? Right, the mapping is changed. And what happens if we supply the {\em same\/} line after this? Indeed, it will show up rotated. Because \PS{} is an interpretive language we can realize this specification after the rotate via a loop, which for this simple case reads |10{...}repeat|.\ftn{Do you see the variant for drawing a polygon? This duality linebundle and polygon has been used by Gabo and is about what he called stereometry versus perimetry, the structure versus the surface} \beginquote Appropriately maintaining the CTM for symmetrical pictures can yield simple looking \PS{} programs. \endquote \bluesubsubhead A flower $$\ifdraft\vbox to1in{\vss\hbox{Flower}\vss} \else\psfig{file=flower.eps,height=1in} \fi$$ This exercises the use of |arc|. \beginverbatim %!!PS EPS %%Title: Flower %%Creator: cgl (Courtesy Papert) %%CreationDate: June 4 1996 %%BoundingBox: -40 -45 40 45 %%Pages: 1 %%EndProlog %%Page: 1 1 /r 36 def 10{r r moveto%begin drawing point r 0 r 90 180 arc currentpoint%origin 0 r r 270 360 arc 36 rotate }repeat stroke showpage !endverbatim Explanation. We have the same structure as the previous program but the `line' is now a little more elaborated: two arcs of a circle. \PS{} provides an operator for drawing circular arcs, called arc. The arc has $(x,y)$ as centre, r as radius, $ang_1$ the angle of a vector from $(x,y)$ of length $r$ to the first endpoint of the arc, and $ang_2$ the angle of a vector from $(x,y)$ of length $r$ to the second endpoint of the arc.\ftn{The arc is drawn counter clockwise. |arcn| draws clockwise.} These arguments are expected to be on the stack. \beginverbatim x y r ang1 ang2 !bf arc !endverbatim Important is to realize that arc {\em counts\/} its angle from (x, 0) and that the {\em drawing\/} starts from the point on the stack The specification of the flower in \MF/\MP{} reads essentially as follows. \beginverbatim for k:= 1 upto 10: draw(origin{up}..{right}(up+right){down}.. {left}origin) rotated 36k; endfor !endverbatim Explanantion. \MF{} allows for specification of the directions\ftn{There is also a quartercircle which apart from orientation is drawn similarly.} $up =(0,1), right=(1,0)$. IMHO, with all respect the \MF{} and \PS{} programs are similar modulo some syntactic sugar. However, the extra possibility of specifying the directions is more convenient than using control points. But perhaps that is a matter of taste, although the handling of control points is powerful as B\'ezier himself has shown in the past. From this I conclude that for these simple kinds of pictures we can as well use \PS{} straightaway. \bluehead Some more Graphics \blueexample Malbork window This is all about using |curveto|, especially choosing suitable control points. $$\ifdraft\vbox to1in{\vss\hbox{Malbork window}\vss} \else\psfig{file=malbork.eps,height=1in} \fi$$ \beginverbatim %!!PS EPS %%Title: Malbork Window %%Creator: cgl %%CreationDate: May 21 1996 %%BoundingBox: -40 -40 40 40 %%Pages: 1 %%EndProlog %%Page: 1 1 45 rotate 10 0 moveto 4{20 0 37.5 12.5 25 25 curveto 12.5 37.5 0 20 0 10 curveto 90 rotate }repeat%inside lops next 5 0 moveto 4{5 35 35 5 0 5 curveto 90 rotate }repeat%enclosing circle next 36 0 moveto 0 0 36 0 360 arc stroke showpage !endverbatim Explanation. |translate| changes the CTM, with the effect that the device coordinates are shifted. (Useful for use of \PS{} alone out of context.) |rotate| changes the CTM, and because of being an interpretive language the various loop traversals map the {\em same\/} user coordinates on the rotated device coordinates. $\langle number\rangle \{\dots\}$ |repeat| is a loop to be traversed $\langle number\rangle$ of times. |curveto| adds a spline to the current path from the currentpoint to the last point on the stack. The first two points are the so-called control points of the spline.\ftn{Much similar as in METAFONT. Choosing for the inner lop the control points in this way is borrowed from Haralambous Y (1995): Some METAFONT techniques. \tubissue{16}(1), 46\dash53. It is also supplied in the description of |curveto| in the red book.} |arc| adds a circular arc to the current path from the currentpoint. The details of the arguments for the operators are nicely documented in the red book. \blueexample Escher's impossible triangle This is all about {\em wrong\/} projections. However, these kinds of pictures are intriguing and fun. I consider them well-suited to illustrate \PS's drawing capabilities. $$\ifdraft\vbox to1in{\vss\hbox{Escher's impossible triangle}\vss} \else\psfig{file=eschera.eps,height=1in} \fi$$ \beginverbatim %!!PS EPS %%Title: Escher's impossible triangle %%Creator: cgl (inspired by Guy Shaw) %%CreationDate: May 23 1996 %%BoundingBox: -40 -40 40 40 %%Pages: 1 %%EndProlog %%Page: 1 1 3{25 34 moveto 25 -34 lineto 17 -38.2 lineto 17 20 lineto -17.6 0 lineto 120 rotate }repeat stroke showpage !endverbatim \on5{} points, the right stroke and a rotation or two, that's it. End of story. However, it is all about finding those \on5{} points. $$\ifdraft\vbox to1in{\vss\hbox{the 5 points}\vss} \else\psfig{file=escherb.eps,height=1in} \fi$$ \beginverbatim %!!PS EPS %%Title: Essential stroke %%Creator: cgl (inspired by Guy Shaw) %%CreationDate: May 23 1996 %%BoundingBox: -40 -40 40 40 %%Pages: 1 %%EndProlog %%Page: 0 1 25 34 moveto currentpoint 0 -68 rlineto currentpoint%down -120 rotate 25 34 lineto%preserve symmetry 120 rotate currentpoint 17 20 lineto currentpoint -17.6 0 lineto currentpoint %labels /Courier findfont 8 scalefont setfont moveto -5 -3 rmoveto (5) show moveto 1 1 rmoveto (4) show moveto 2 -5 rmoveto (3) show moveto 2 0 rmoveto (2) show moveto 2 0 rmoveto (1) show stroke showpage !endverbatim Explanation. The essential stroke figure also illustrates the integration of text in this case digits. |currentpoint| pushes the point on the stack. The last |moveto|-s pop these coordinates up. |rmoveto| moves {\em relatively.} \smallbreak And what about their relationships, and what about the minimal information to be prescribed? Looking more closely it turns out that {\em only\/} the first point is all that is needed. The rest is implicit to the nature of the figure.\ftn{Of course one can also think of other equivalent parameters like size and thickness.} \beginverbatim %!!PS EPS %%Title: Escher's Impossible triangle II %%Creator: cgl %%CreationDate: May 23 1996 %%BoundingBox: -40 -40 40 40 %%Pages: 1 %%EndProlog %%Page: 1 1 %Parameterized over p1 /point {25 34} def%note x<y % 3{point moveto currentpoint neg lineto%down -120 rotate point lineto%preserve symmetry 120 rotate currentpoint 2 div neg lineto currentpoint 3 sqrt mul sub 0 lineto 120 rotate }repeat stroke showpage !endverbatim Explanation. |currentpoint| yields the coordinates of the current point of the path on the stack. The other operations do what their names suggest. The temporarily change of the CTM within the loop expresses the rotation symmetry relation between points \on1{} and \on3. \blueexample Bentley's polygon This code is all about a double loop and using the loop variable from the stack, next to using the |gsave| and |grestore| advantageously. $$\ifdraft\vbox to1in{\vss\hbox{Bentley's polygon}\vss} \else\psfig{file=bentley.eps,height=1in} \fi$$ \beginverbatim %!!PS EPS %%Title: Bentley's double loop %%Creator: cgl %%CreationDate: May 30 1996 %%BoundingBox: -100 -105 100 105 %%EndProlog 10{1 1 9{100 0 moveto gsave 36 mul rotate%loopcount*36 100 0 lineto stroke grestore } for 36 rotate }repeat showpage !endverbatim Explanantion. |gsave| and |grestore| are needed to draw locally, that is at the end the graphics state\Dash currentpoint, currentpath and CTM\Dash is restored with the values at the beginning. \on1{} \on1{} \on9{} stand for beginvalue step and endvalue of the |for| counter. \blueexample Another double loop A set of nested polygons provide also a double loop situation. $$\ifdraft\vbox to1in{\vss\hbox{Polygons}\vss} \else\psfig{file=polygon.eps,height=1in} \fi$$ \beginverbatim %!!PS EPS Nested pentagons %%Title: Pentagons %%Creator: cgl %%CreationDate: June 17 1996 %%BoundingBox: -100 -100 100 100 %%Pages: 1 %%EndProlog %%Page: 1 1 10 10 100{dup 0 moveto 5{72 rotate dup 0 lineto }repeat }for stroke showpage !endverbatim \blueexample Polygons with splines as sides This generalization of polygons was introduced by Jackowski at Euro\TeX{} \on95. A special case of \MF's interpath functionality is shown en-passant. $$\ifdraft\vbox to1in{\vss\hbox{flexess}\vss} \else\psfig{file=polygonii.eps,height=1in} \fi$$ \beginverbatim %!!PS EPS Nested `squares' %%Title: polygon.eps II %%Creator: cgl %%CreationDate: June 17 1996 %%BoundingBox: -100 -100 100 100 %%Pages: 1 %%EndProlog %%Page: 1 1 /r 100 def /r1 {r .25 mul} def /r3 {r .75 mul} def 25{r 0 moveto 4{r3 r3 r1 r1 0 r curveto 90 rotate }repeat .9 .9 scale }repeat stroke showpage !endverbatim \blueexample Barn window This is all about playing with circles and circular arcs.\ftn{The first example in the blue book collection provides a similar picture with gradually changing scales of grey.} $$\ifdraft\vbox to1in{\vss\hbox{Barn window}\vss} \else\psfig{file=barnwindowii.eps,height=1in} \fi$$ \beginverbatim %!!PS EPS %%Title: Barn Window II %%Creator: cgl %%CreationDate: May 29 1996 %%BoundingBox: -45 -45 45 45 %%Pages: 1 %%EndProlog %%Page: 1 1 /l 36 def /r {l 22.5 sin mul} def /m {l 22.5 cos mul} def 8{r .5 mul 0 moveto l 0 lineto currentpoint %begin circular arc 22.5 rotate m 0%center r %radius -90 90 arc 22.5 rotate }repeat %inner circle /rin {r .5 mul} def rin 0 moveto 0 0 rin 0 360 arc %outer circle /rout {r m add} def rout 0 moveto 0 0 rout 0 360 arc %extra circles /rin {r .25 mul} def 22.5 rotate 8{m rin add 0 moveto m 0 rin 0 360 arc 45 rotate }repeat stroke showpage !endverbatim I'm sure I'll come back some day and look again through this window, but then pastel colored. \blueexample Baker's inspiration $$\ifdraft\vbox to1in{\vss\hbox{Woody Baker's picture}\vss} \else\psfig{file=baker.eps,height=1in} \fi$$ This example is similar to Escher's impossible triangle. Find the essential stroke and rotate. \beginverbatim %!!PS EPS %%Creator: cgl (inspired by Woody Baker) %%CreationDate: May 1996 %%BoundingBox: -80 -80 80 80 %%Pages: 1 %%EndProlog %%Page: 1 1 4{-15 25 moveto 0 -10 rlineto 60 0 rlineto 0 -30 rlineto 10 0 rlineto 0 40 rlineto -70 0 rlineto 0 10 rlineto 80 0 rlineto 0 -60 rlineto -30 0 rlineto 0 10 rlineto 10 0 rlineto % 35 -25 moveto 0 -10 rlineto 20 0 rlineto 10 10 rlineto % 45 15 moveto 10 10 rlineto 90 rotate }repeat stroke % /Courier findfont 10 scalefont setfont -55 -75 moveto (Courtesy Woody Baker)show showpage !endverbatim \blueexample Romanovsky's real Escher $$\ifdraft\vbox to1in{\vss\hbox{JVR's picture}\vss} \else\psfig{file=jvr.eps,height=1in} \fi$$ Grey scales can be obtained simply via $\langle number\rangle$ |setgray|, with $\langle number\rangle \in [0, 1]$. 0 denotes black and 1 is white. The idea is to construct the essential path\Dash the stroke denoted by a grey scale\Dash and to use this \on3{} times. \bluehead Math graphs In \AllTeX{} documents it is a problem\ftn{Communicated by Nico Temme. He solved the problem by doing the calculations in PASCAL. For advanced manipulations Mathematica or Mapple are generally used where the resulting EPS is pasted up in the \AllTeX{} script as usual.} how to include accurate graphs of mathematical functions. Because of \PS's arithmetic and graphics capabilities it is handy to use \PS. \blueexample Sine function $$\ifdraft\vbox to1in{\vss\hbox{sine function}\vss} \else\psfig{file=sine.eps,height=1in} \fi$$ \beginverbatim %!!PS EPS %%Title: Sine function %%Creator: cgl (inspired by Batagelj) %%CreationDate: May 27 1996 %%BoundingBox: -200 -110 200 110 %%EndProlog /Courier findfont 15 scalefont setfont %figure scaled by 100 %x-axes and label -200 0 moveto 200 0 lineto -15 -15 rmoveto (x) show %y-axes and label 0 -110 moveto 0 110 lineto -35 -10 rmoveto (sin) show %function -180 0 moveto -180 10 180{%from step to dup sin 100 mul%(x, 100sin x) lineto }for stroke showpage !endverbatim The invoke might read as follows. \beginverbatim $$\psfig{file=sine.eps,height=1in}$$ !endverbatim \bluehead Text set along curved paths A teaser. With the advent of scalable and rotationable outline fonts this is possible too. \blueexample Along a circle $$\ifdraft \vbox to 1in{\vss\hbox{text along an arc}\vss} \else \psfig{file=textalongarc.eps,height=1in} \fi$$ \beginverbatim %!!PS EPS %%Title: Typesetting along arcs %%Creator: cgl %%CreationDate: June 4 1996 %%BoundingBox: -100 50 100 125 %%Pages: 1 %%EndProlog %%Page: 1 1 /Courier findfont 10 scalefont setfont /text (happybirthday) def 50 rotate 0 1 12{0 100 moveto text exch 1 getinterval show -10 rotate }for stroke showpage !endverbatim Joseph Romanovsky communicated that |kshow|\Dash kerning (and more general positioning) under user control\Dash is available which allows a general def to be executed between two characters of a string. \blueexample Along a spiral The blue book provides an example of typesetting along a path\Dash a quotation of Woody Allen\Dash where the path accentuates his filmmaker profession. The example below shows a nice effect with little knowledge of \PS, essentially the use of |kshow|. $$\ifdraft \vbox to 2in{\vss\hbox{text along spiral}\vss} \else \psfig{file=textalongspiral.eps} \fi$$ \beginverbatim %!!PS EPS %%Title: Text along spiral %%Creator: J.V. Romanovsky %%BoundingBox: -100 -90 60 70 %%EndProlog /Courier findfont 20 scalefont setfont -100 0 moveto 50 rotate {-10 rotate 3 0 rmoveto .98 .98 scale} (Olga Grineva my charming St Peterburg hostess)kshow showpage !endverbatim \blueexample Seals The problem has been discussed by Hoenig at Euro\TeX{} \on92, and Zlatu\v{s}ka at Euro\TeX{} \on95, both biased by \MF. \PS{} alone is suited too with an overall simpler process. Combining two earlier supplied examples yields Zlatu\v{s}ka's seal in principle.\ftn{The blue book also provides a seal\Dash Symphony No.\on9\Dash but that is more complex and ipso facto requires more knowledge of \PS{} to understand what is going on, IMHO, with all respect. To set this poster from the blue book is no more difficult than the use of |arc|, however. My example gives you the feeling that you understand what is going on, I hope.} \beginverbatim %!!PS EPS %%Title: Seal, in principle %%Creator: cgl %%CreationDate: June 6 1996 %%BoundingBox: -110 -45 110 100 %%Pages: 1 %%EndProlog %%Page: 1 1 %150 650 translate /Courier findfont 10 scalefont setfont /text (happy postscripting to you) def /r 100 def gsave 90 rotate %begin orientation 0 r moveto%begin point {-7.04 rotate 0 r moveto} text kshow grestore%next the central Escher 3{25 34 moveto 25 -34 lineto 17 -38.2 lineto 17 20 lineto -17.6 0 lineto 120 rotate }repeat stroke showpage !endverbatim $$\ifdraft \vbox to 1.5in{\vss\hbox{seal}\vss} \else \psfig{file=seal.eps,height=1.5in} \fi$$ Remark. The difference of fonts in the main text and that used by \PS{} is no longer there when \PS{} fonts are used throughout, be it the \PS{} version of the CM family. \blueexample Gurari's squares $$\ifdraft \vbox to 1in{\vss\hbox{Gurari's squares}\vss} \else \psfig{file=gurarisq.eps,height=1in} \fi$$ \beginverbatim %!!PS Gurari squares %%BoundingBox: -200 -110 200 110 %%Creator: cgl %%CreationDate: June 20 1996 %%EndProlog /r 22 def /square {1 1 4{0 r rlineto 90 rotate}for} def 0 0 moveto 90 rotate 50{r 0 rmoveto square -30 rotate .9 .9 scale }repeat stroke showpage !endverbatim \blueexample Gurari's ABC Very nice this suggestion of motion. $$\ifdraft \vbox to 1.5in{\vss\hbox{Gurari's speedy ABC}\vss} \else \psfig{file=gurariabc.eps,height=1.5in} \fi$$ \beginverbatim %!PS EPS %%Title: Guarai's ABC %%BoundingBox: 0 -45 100 75 %%Creator: Gurari %%CreationDate: copied June 17 1996 %%Pages: 1 %%EndComments %%EndProlog %%Page: 1 1 /Times-Bold findfont 45 scalefont setfont -40 rotate 1 -.03 0{setgray 0 0 moveto (ABC) show 3 rotate } for 0 0 moveto -4 rotate 1 setgray (ABC) show showpage !endverbatim \blueexample Walking along the S-curve In {\sl The METAFONTbook\/} ex\on13.\on10{} is about drawing overlapping disks along a path, the S-figure. How to do this in \PS{} straightaway? There is no `point of' a path operator so the best we can attain is to walk along a math function. $$\ifdraft \vbox to 1in{\vss\hbox{S-figure}\vss} \else \psfig{file=sinedisks.eps,height=1in} \fi$$ \beginverbatim %!PS Sine with overlapping disks %%BoundingBox: -200 -110 200 110 %%Creator: cgl (METAFONTbook ex13.10) %%CreationDate: June 17 1996 %%EndProlog newpath -180 10 180{dup sin 100 mul%(x, 100sin x) 12.5 0 360 arc gsave 1 setgray fill grestore stroke }for showpage !endverbatim Explanation. |1 setgray fill| is the erase functionality, encapsulated to yield what we want. \bluehead Tables set sideways Another teaser is to set tables rotated. Rokicki provided rotate macros along with his |dvips|, among others. I have borrowed the essence from his rotate macros and recast into the following. \beginverbatim \def\rotate#1%stuff #2%degrees in PS direction {\setbox\abox=\hbox{#1}% \adim\ht\abox\advance\adim by\dp\abox \hbox to\adim{\vbox to\wd\abox {\vskip\wd\abox \special{ps: gsave currentpoint currentpoint translate #2 neg rotate neg exch neg exch translate}% \box\abox\vss}\hss}% \special{ps: currentpoint grestore moveto}% }%end rotate !endverbatim The point is that it is not much. The |ps:| is dependent on the system still, alas. \blueexample Rotated table The example works under UNIX with Rokicky's |dvips|. %under UNIX \newdimen\adim \newbox\abox % \def\rotate#1%stuff #2%degrees in PS direction {\setbox\abox=\hbox{#1}% \adim\ht\abox\advance\adim by\dp\abox \hbox to\adim{\vbox to\wd\abox{\vskip\wd\abox \special{ps: gsave currentpoint currentpoint translate #2 neg rotate neg exch neg exch translate}% \box\abox\vss}\hss}% \special{ps: currentpoint grestore moveto}% }%end rotate \begindemo \def\data{1\cs2\rs 3\cs4 } pre \rotate{\framed \btable\data} {90} post !yields \def\data{1\cs2\rs 3\cs4 } pre \rotate{\framed\btable\data}{90} post \enddemo Remark. Gurari (1994) has provided some more examples of \PS$\leftrightarrow$(Al)Dra\TeX{} interaction. Real interfacing. Apart from portability problems it gets quite complicated. For the moment I refrain and code the `pictures' in raw \PS{} assisted by \MF{} for prompting control points of those curves which can be specified elegantly in a declarative way. \bluehead METAFONT/MetaPost user interface Sometimes it is more natural to specify points and {\em directions}. It is true that specifying a control point along the direction can yield the same effect but the distance between the point and its control point influences the shape. \blueexample Escher's knot This example is all about specifying directions. $$\ifdraft\vbox to1in{\vss\hbox{Escher knot II}\vss} \else\psfig{file=escherknotmf.eps,height=1in} \fi$$ In \MF{} the coding would read as follows. \beginverbatim %Escher's Knot. June 96. cgl@rc.service.rug.nl def openit = openwindow currentwindow from origin to (screen_rows,screen_cols) at (-2r,3r)enddef; pickup pencircle scaled 1; tracingstats:=proofing:=1; screenstrokes; pair p[]; %parameters r:=100; alfa=90; % p2:=(0,.85r); %independent from p1,3,4 p4:=(0,-.5r); %dependent points because of symmetry p1:=p4 rotated -120; p3:=p4 rotated 120; path q; q=p1{dir alfa}..{(1,0)}p2.. {dir(-alfa)}p3..{dir(alfa-240)}p4; draw q; draw q rotated 120; draw q rotated-120; showit; end !endverbatim By the nature of the figure not only points are related but also their directions. How to cope with this in \PS? It can be done but is not so elegant, honestly speaking cumbersome. But \dots there is a solution or two, hang on. \beginverbatim %!!PS EPS %%Title: Escher knot II %%Creator: cgl (inspired by Knotplot) %%CreationDate: June 1996 %%BoundingBox: -95 -95 95 95 %%Pages: 1 %%EndProlog %%Page: 1 1 % /angle 90 def /r 100 def /point {0 -.5 r mul}def /p1 {-.25 r mul 3 sqrt mul .25 r mul moveto currentpoint angle sin 2 mul add exch angle cos 2 mul add exch -20 .85 r mul 0 .85 r mul curveto stroke} def /p3 { .25 r mul 3 sqrt mul .25 r mul moveto %Control point currentpoint angle sin -15 mul add exch angle cos 15 mul add exch %Control point: % 58.62 -.5 r mul 5 add%angle 90 0 angle -240 add cos -15 mul add -.5 r mul angle -240 add sin -15 mul add 0 -.5 r mul curveto stroke} def 3{p1 gsave -1 1 scale p1 grestore%reflect p3 120 rotate }repeat showpage !endverbatim Explanation. The essential curve is split into \on3{} pieces: p$_1$,\dots p$_3$. The first two are related by reflection. The third must properly match. In the Columbus's egg paragraph the straight |.eps| code is given, biased by the knowledge of the (control) points. \bluesubhead A teaser More complicated is when the line is changed into a tube, and when we have to deal with hidden lines. In \MF{} the code could read as follows, where use is made of |intersectiontimes| and of subpaths.\ftn{This code works as such on my Mac with Bluesky's PD METAFONT. For other environments build a character from it, or adapt it for use in MetaPost, or even simpler copy the bread-and-butter EPS code which is appended at the end.} \blueexample Escher's knot III This example is all about getting from a {\em declarative\/} specification in \MF{} to a {\em imperative\/} EPS code. $$\ifdraft\vbox to1in{\vss\hbox{Escher knot III}\vss} \else\psfig{file=escherknotiii.epsabr,height=1in} \fi$$ First the declarative \MF{} code. \beginverbatim %Escher Knot III. June 96. cgl@rc.service.rug.nl def openit = openwindow currentwindow from origin to (screen_rows,screen_cols) at (-2r,3r)enddef; pickup pencircle scaled 1; tracingstats:=proofing:=1; screenstrokes; numeric t, u, v, w; pair p[]; path q[]; def assignpoints= p2:=(0,.85r); %independent from p1,3,4 p4:=(0,-.5r); %dependent points because of symmetry p1:=p4 rotated -120; p3:=p4 rotated 120; enddef; % alfa=90;r:=100; assignpoints; q1:=p1{dir alfa}..{(1,0)}p2.. {dir(-alfa)}p3..{dir(alfa-240)}p4; %inside r:=.75r; assignpoints; q2:=p1{dir alfa}..{(1,0)}p2.. {dir(-alfa)}p3..{dir(alfa-240)}p4; (t,u)= subpath (2.5,3) of q1 intersectiontimes (q2 rotated -120); (v,w)= q2 intersectiontimes (q1 rotated 120); %showvariable t,u; draw subpath (0,2.5 + t/2) of q1; draw subpath (0,2.5 + t/2) of q1 rotated 120; draw subpath (0,2.5 + t/2) of q1 rotated-120; %showvariable v,w; draw subpath (v,3) of q2; draw subpath (v,3) of q2 rotated 120; draw subpath (v,3) of q2 rotated-120; showit; end !endverbatim To give the reader an impression of what \MP{} will yield |escherknotIII.eps|, the imperative code, is included.\ftn{A white lie. I have edited the file and reduced the data\Dash and deleted |dtransform|, |idtransform| and the various |set...|\Dash for the \on6{} strokes into only \on2{} and rotated these. METAFONT allowed me to declaratively specify the picture while MetaPost provided me with the essential path data. Well\dots even METAFONT can be asked to provide those (control) points.} \beginverbatim %!!PS EPS %%BoundingBox: -40 -31 40 43 %%Creator: MetaPost and JJW, CGL %%CreationDate: June 17 1996 %%Pages: 1 %%EndProlog %%Page: 1 1 3{-21.6507 12.5 moveto -21.6507 27.74551 -13.78212 42.5003 0 42.5003 curveto 13.78212 42.5003 21.6507 27.74551 21.6507 12.5 curveto 21.6507 -0.24506 16.04897 -12.19249 6.58395 -20.3313 curveto % -14.3152 15.86746 moveto -12.43301 23.58928 -7.45113 29.75021 0 29.75021 curveto 9.64748 29.75021 15.15549 19.42186 15.15549 8.75 curveto 15.15549 -2.07904 9.37823 -12.08548 0 -17.5 curveto 120 rotate }repeat stroke showpage !endverbatim As can be seen from the last code it is all about finding the right (control) points and draw the strokes, as remarked at the beginning of this note. The difference between the declarative \MF{} specification and the resulting (unedited) \MP{} code is striking. When the last code is shown first one would say, ah\dots \PS{} is easy just data and some strokes. The resulting code is equivalent to Woody Baker's code: just the right stroke and a rotation or two. KnotPlot on the net provides a more complicated version where the light reflection is emulated by shades of grey. The gzipped file is \on64KB, however. A world of difference. \bluesubhead Columbus' egg Why not use \MF{} to create `the (control) points' from the descriptive picture and use these in raw \PS{} straightaway? After assigning |precontrol|-s and |postcontrol|-s to pairs and inserting |show|-s, \MF{} yielded for the simple Escher knot the data in the transcript file. A little editing of this log file resulted in the following imperative EPS code. \beginverbatim %!!PS EPS %%Title: Escher knot (mf prompted) %%Creator: cgl %%CreationDate: June 1996 %%BoundingBox: -80 -80 80 80 %%Pages: 1 %%EndProlog %%Page: 1 1 3{-43.30139 25 moveto -43.30139 55.49103 -27.56424 85.00061 0 85.00061 curveto 27.56424 85.00061 43.30139 55.49103 43.30139 25 curveto 43.30139 -5.94014 26.79497 -34.5299 0 -50 curveto 120 rotate }repeat stroke showpage !endverbatim I presume the functionality is similar to Jackowski's |mftoeps|. The above method is my Poor Man's \MF2EPS, with concise, very concise and intelligible EPS as result. \bluehead Acknowledgements First of all Don Knuth and John Hobby thank you. Thank you Joseph Romanovsky for showing by example the power of \PS, and for your cooperation on the \MF$\leftrightarrow$\PS{} duality. Thank you Bogus\l{}aw Jackowski for your `\PS{} for \TeX ies' at Bacho\TeX{} \on96, suggesting that \PS{} as such is beneficial for \TeX ies, next to your mftoeps. Thank you Eitan Gurari and anonymous \TeX ies of which I borrowed material, not in the least Adobe for providing \PS{} to start with. Piet Tutelaers provided me with a copy of the PSFAQ, and Erik Frambach traced the file with examples from the blue book, next to KnotPlot. As usual Jos Winnink proofed the paper and lend a helping hand in procrusting towards MAPS inclusion if not for processing |escherknot.mf| into |escherknot.eps| via \MP. \bluehead Conclusion To code symmetrical and simple curves in raw \PS{} is fun and yields elegant scripts and concise files. To merge text with graphics is fun too, and the teaser to set along curved paths can be done by \PS{} elegantly. Another teaser of drawing math curves accurately along with \AllTeX{} is solved also by means of \PS. Powerful too is to {\em extend\/} the inclusion of .eps files at the dvi level by a little more interaction between \AllTeX{} and \PS. Rotating a box, with as applications for example typesetting tables in landcape, is possible in \PS, at the expense of system dependency because of the \cs{special}-s. {\em Merging\/} a little knowledge of \PS{} with \TeX pertise is powerful. PStricks concentrates on {\em interfacing\/} \AllTeX{} with \PS{} at the expense of burdening \AllTeX{} too much, IMHO, with all respect. For \cs{rotate} I interfaced too. However, for typesetting along curved paths I would not think of interfacing via rotated boxes or so. Of course, people who do need advanced features or have special wishes might better use Adobe Illustrator, CorelDRAW, Mathematica, or Adobe Photoshop, and not to forget the pleasing MetaPost. To understand and learn \TeX{} did take me a couple of years. To acqaint myself with \MF{} did cost me a few months. Learning just a little bit of \PS{} was a matter of weeks, and when concentrating on paths and (control) points the |moveto|, |arc| and |curveto| can be grasped in a late afternoon. Although the blue book contains also examples of typesetting text, I consider \TeX{} unsurpassed for this. The best of both worlds is to combine \AllTeX{} and \PS. Maybe we should follow Adobe and extend the use of \PS{} by PDF\Dash or use the alternative HTML\Dash to facilitate WWW surfing. \bluehead What more? For pictures I use a \TeX{} controlled database with the beneficial side-effect that I don't have to worry about file systems when using pictures (tools, references and ilks) on different machines. I would welcome a similar functionality for my collection of \PS{} pictures to be used with \cs{psfig}. A next step is the manipulation of colors either via \MP{} or \PS{} directly. Jackowski uses Adobe Illustrator for example to enrich interactively the systematic EPS pictures created by \MF. Indeed interesting, very interesting, but beyond my possibilities for some time to come. Neither do I have access to color \PS{} printers as yet, alas. My case rests. Have fun, and all the best. \makesignature \pasteuptoc \endscript