MetaFun - Pragma ADE
MetaFun - Pragma ADE MetaFun - Pragma ADE
234 Does it wor k ok? D o e s i t wor k o k ? A B C D o e s i t wor k o k ? The previous macro is not really an example of generalization, but we used it for demonstrating how to build graphics in a stepwise way. If you put the steps in buffers, you can even combine steps and replace them at will. This is how we made the previous step by step examples: We put each sub--graphic in a buffer and then called the ones we wanted. We now present a more general approach to typesetting along a given path. This method is not only more robust and general, it is also a more compact definition, especially if we omit the tracing and testing code. We use a familiar auxiliary definition. The \setstrut and \strut commands ensure that the lines have the proper depth and height. \def\processfollowingtoken#1% {\appendtoks#1\to\MPtoks \setbox\MPbox=\hbox{\RotFont\setstrut\strut\the\MPtoks}% \startMPdrawing n := n + 1 ; len[n] := \the\wd\MPbox ; \stopMPdrawing \startMPdrawing[-] pic[n] := btex \RotFont\setstrut\strut#1 etex ; pic[n] := pic[n] shifted -llcorner pic[n] ; \stopMPdrawing} The definition of \followtokens is as follows. Keep in mind that \RotFont is defined in the META POST environment. You may notice that we have added a directive to include the METAPOST graphic called followtokens. Storing the path in a graphic container instead of using \startMPdrawing is less sensitive for interference with other drawing processes. \def\followtokens#1% {\vbox\bgroup \MPtoks\emptytoks \resetMPdrawing \startMPdrawing \includeMPgraphic{followtokens} picture pic[] ; numeric len[], n ; n := 0 ; \stopMPdrawing \handletokens#1\with\processfollowingtoken \startMPdrawing numeric al, pl, at, wid, pos ; pair ap, ad ; al := arclength RotPath ; pl := (al-len[n])/(n-1) ; for i=1 upto n : wid := abs(xpart lrcorner pic[i] - xpart llcorner pic[i]) ; pos := len[i]-wid/2 + (i-1)*pl ; at := arctime pos of RotPath ; Typesetting in METAPOST TEX text
ap := point at of RotPath ; ad := direction at of RotPath ; draw pic[i] shifted (-wid/2,0) rotated (angle(ad)) shifted ap ; endfor ; \stopMPdrawing \MPdrawingdonetrue \getMPdrawing \resetMPdrawing \egroup} So, how does this compare to earlier results? The original, full text as typeset by TEX, looks like: We now follow some arbitrary path ... In the examples, the text is typeset along the path with: \followtokens{We now follow some arbitrary path ...} We now follow some arbitrary path ... Since we did not set a path, a dummy path is used. We can provide a path by (re)defining the graphic followtokens. \startuseMPgraphic{followtokens} path RotPath ; RotPath := fullcircle ; \stopuseMPgraphic We now follow some arbitrary path ... We now follow some arbitrary path ... \startuseMPgraphic{followtokens} path RotPath ; RotPath := reverse fullcircle ; \stopuseMPgraphic We now follow some arbitrary path ... \startuseMPgraphic{followtokens} path RotPath ; RotPath := (-3cm,-1cm)--(0,1cm)--(3cm,-1cm) ; \stopuseMPgraphic We now follow some arbitrary path ... TEX text Typesetting in METAPOST 235
- Page 187 and 188: Since we have collected some nice b
- Page 189 and 190: 8 Special effects Sometimes we want
- Page 191 and 192: Because of this implementation, sha
- Page 193 and 194: test_shade(origin shifted (.25cm,0)
- Page 195 and 196: fill p shifted (3cm,0) withcolor .5
- Page 197 and 198: \definecolor [tred] [r=1,t=.5,a=exc
- Page 199 and 200: Figure 8.4 Another clipped cow. \pl
- Page 201 and 202: withpen pencircle scaled 4mm withco
- Page 203 and 204: Because this graphic is the result
- Page 205 and 206: The resulting PDF file can be inclu
- Page 207 and 208: Including another METAPOST graphic,
- Page 209 and 210: After these examples your are proba
- Page 211 and 212: In this graphic, we have two text f
- Page 213 and 214: } {}} Here we feed some MATHML int
- Page 215 and 216: 9 Functions METAPOST provides a wid
- Page 217 and 218: 9.2 Grids Some day you may want to
- Page 219 and 220: 13 13 13 13 Figure 9.1 Quick and di
- Page 221 and 222: 2 − ×10 1 − 1 0×100 Figure 9.
- Page 223 and 224: Figure 9.3 By using transparent col
- Page 225 and 226: There are enough applications out t
- Page 227 and 228: Of course we could extend this LUA
- Page 229 and 230: 10 Typesetting in METAPOST It is sa
- Page 231 and 232: Meta is a female lion! Figure 10.2
- Page 233 and 234: We use the low level CONTEXT macro
- Page 235 and 236: So, now we have: M etaPostisFun! Wh
- Page 237: n := n + 1 ; len[n] := \the\wd\MPbo
- Page 241 and 242: \startoverlay {\startuseMPgraphic{f
- Page 243 and 244: \startuseMPgraphic{text draw} draw
- Page 245 and 246: vsize := ypart urcorner p - ypart l
- Page 247 and 248: We are now ready for an attempt to
- Page 249 and 250: We can manipulate the heigth and de
- Page 251 and 252: \strutheight) ; % height of first l
- Page 253 and 254: w := h := 6cm ; o := 6pt ; path p ;
- Page 255 and 256: Donald Knuth has spent the past sev
- Page 257 and 258: Donald Knuth has spent the past sev
- Page 259 and 260: 11 Debugging Those familiar with CO
- Page 261 and 262: 4 3 5 2 6 1 0 7 8 You can pass opti
- Page 263 and 264: 3 4 0 2 1 Of course you may want to
- Page 265 and 266: 12 Defining styles Since the integr
- Page 267 and 268: color=gray, contrastcolor=gray, sty
- Page 269 and 270: def right_menu_button (expr nn, rr,
- Page 271 and 272: \Topic {Edward R. Tufte} \input tuf
- Page 273 and 274: A Few Nice Quotes A Simple Style De
- Page 275 and 276: 13 A few applications For those who
- Page 277 and 278: vardef spring (expr a, b, w, h, n)
- Page 279 and 280: There is a numeric constant labelof
- Page 281 and 282: text text text text text text text
- Page 283 and 284: p := fullcircle scaled (2*length(lo
- Page 285 and 286: These definitions of anglebetween a
- Page 287 and 288: Because in most cases we want the l
234<br />
Does it wor k ok?<br />
D o e s i t wor k o k ?<br />
A B C<br />
D o e s i t wor k o k ?<br />
The previous macro is not really an example of generalization, but we used it for demonstrating<br />
how to build graphics in a stepwise way. If you put the steps in buffers, you can even combine<br />
steps and replace them at will. This is how we made the previous step by step examples: We put<br />
each sub--graphic in a buffer and then called the ones we wanted.<br />
We now present a more general approach to typesetting along a given path. This method is not<br />
only more robust and general, it is also a more compact definition, especially if we omit the tracing<br />
and testing code. We use a familiar auxiliary definition. The \setstrut and \strut commands<br />
ensure that the lines have the proper depth and height.<br />
\def\processfollowingtoken#1%<br />
{\appendtoks#1\to\MPtoks<br />
\setbox\MPbox=\hbox{\RotFont\setstrut\strut\the\MPtoks}%<br />
\startMPdrawing<br />
n := n + 1 ; len[n] := \the\wd\MPbox ;<br />
\stopMPdrawing<br />
\startMPdrawing[-]<br />
pic[n] := btex \RotFont\setstrut\strut#1 etex ;<br />
pic[n] := pic[n] shifted -llcorner pic[n] ;<br />
\stopMPdrawing}<br />
The definition of \followtokens is as follows. Keep in mind that \RotFont is defined in the META<br />
POST environment. You may notice that we have added a directive to include the METAPOST graphic<br />
called followtokens. Storing the path in a graphic container instead of using \startMPdrawing<br />
is less sensitive for interference with other drawing processes.<br />
\def\followtokens#1%<br />
{\vbox\bgroup<br />
\MPtoks\emptytoks<br />
\resetMPdrawing<br />
\startMPdrawing<br />
\includeMPgraphic{followtokens}<br />
picture pic[] ; numeric len[], n ; n := 0 ;<br />
\stopMPdrawing<br />
\handletokens#1\with\processfollowingtoken<br />
\startMPdrawing<br />
numeric al, pl, at, wid, pos ; pair ap, ad ;<br />
al := arclength RotPath ;<br />
pl := (al-len[n])/(n-1) ;<br />
for i=1 upto n :<br />
wid := abs(xpart lrcorner pic[i] - xpart llcorner pic[i]) ;<br />
pos := len[i]-wid/2 + (i-1)*pl ;<br />
at := arctime pos of RotPath ;<br />
Typesetting in METAPOST TEX text