Debian Codegraph @

texmf-dist/tex/generic/texdraw/texdraw.tex

raw
1 % TeXdraw macros
2
3 % $Id: texdraw.tex 2.7 2019/04/18 TeXdraw-v2r3 $
4
5 % Copyright (C) 1991-2019 Peter Kabal
6
7 % This work is licensed under the Creative Commons Attribution (CC-BY)
8 % License, any version. To view the licenses, visit
9 % creativecommons.org/licenses/by or send a letter to
10 % Creative Commons, PO Box 1866, Mountain View, CA 94042, USA.
11
12 % Peter Kabal
13 % Department of Electrical & Computer Engineering
14 % McGill University
15
16 % peter dot kabal at mcgill dot ca
17 % http://www-mmsp.ece.mcgill.ca/MMSP/Documents/Software/
18
19 \def\setRevDate $#1 #2 #3${#2}
20 \def\TeXdrawId{\setRevDate $Date: 2019/04/18 14:10:45 $ TeXdraw V2R3}
21
22 % ===============================================================
23
24 % The TeXdraw macros allow PostScript line drawings and such to be
25 % generated from within TeX and LaTeX.
26 % (1) TeXdraw allows TeX text (either horizontal or rotated) to be
27 % superimposed on the figure.
28 % (2) TeXdraw implements a \bsegment-\esegment environment which allows
29 % parameter changes and coordinate changes to be kept local. In
30 % effect these segments are self-contained relocatable procedures.
31 % (3) TeX's macro facility can be used to modularize drawing units and
32 % produce more complex entities from simple elements.
33 % (4) The drawing can be positioned on the page like any other TeX box.
34
35 % TeXdraw coordinate units have positive X to the right and positive Y up.
36 % The drawing units can be selected (initially inches). In addition, two
37 % scaling parameters - unit scale and segment scale - are available. Their
38 % effects are multiplicative.
39
40 % Segments allow for relocatable drawing units. Inside each segment the
41 % coordinates are relative to the initial point, which becomes (0 0).
42 % Scaling is local to segments. Each segment inherits the unit scale
43 % scaling from outside the segment, but any changes apply to that segment
44 % and inferior segments. The segment scale factor is reset to unity on
45 % entry to each segment.
46
47 % The coordinates given as command arguments are used to determine
48 % the size of the drawing. The width of the plot line, sizes of
49 % arrowheads, arcs or text do not affect the size of the drawing.
50
51 % TeXdraw writes PostScript commands to an intermediate file. After the
52 % drawing is finished, the PostScript file is included in the document as a
53 % PostSript include file.
54
55 % This file is divided into 4 parts,
56 % - TeXdraw user interface
57 % - Utility definitions
58 % - Low level definitions
59 % - PostScript file macros
60
61
62 \chardef\catamp=\the\catcode`\@
63 \catcode`\@=11
64
65 % ===============================================================
66 % ===== TeXdraw user interface ==================================
67 \long % \centertexdraw needs to be very \long
68 \def\centertexdraw #1{\hbox to \hsize{\hss
69 \btexdraw #1\etexdraw
70 \hss}}
71
72 % ====== Begin TeXdraw
73 % Inside the texdraw box:
74 % The \vbox should be of zero size; none of the TeXdraw drawing commands
75 % generate text, the TeXdraw text commands generate zero size boxes.
76
77 \def\btexdraw {\x@pix=0 \y@pix=0
78 \x@segoffpix=\x@pix \y@segoffpix=\y@pix
79 \let\p@sfile=\p@sundef
80 % Set the default values (define outside of the group so that \etexdraw can
81 % see the scaling parameters)
82 \t@exdrawdef
83 \setbox\t@xdbox=\vbox\bgroup\offinterlineskip
84 \global\d@bs=0 % pending segments
85 \global\p@osinitfalse
86 \s@avemove \x@pix \y@pix % capture the initial position
87 \m@pendingfalse
88 \global\p@osinitfalse % capture the next move
89 \p@athfalse
90 \the\everytexdraw}
91
92 % ====== End TeXdraw
93 % Write out a trailer, close the file, bring in the PostScript code as
94 % a \special include file. The \special is offset on the page to be at
95 % (llx,ury) in PostScript coordinates.
96
97 % The drawing is placed in a \vbox of appropriate size (zero depth). The
98 % temporary PostScript file is superimposed with offsets such that the
99 % lower lefthand corner of the drawing is aligned with the lower lefthand of
100 % the box.
101 \def\etexdraw {\p@sclose % close the PostScript file
102 \egroup % ends the \vbox \bgroup
103 \vbox {\offinterlineskip
104 \pixtobp \xminpix \l@lxbp \pixtobp \yminpix \l@lybp
105 \pixtobp \xmaxpix \u@rxbp \pixtobp \ymaxpix \u@rybp
106 \ifx\p@sfile\p@sundef
107 \hbox{\t@xdempty
108 [{\l@lxbp},{\l@lybp}][{\u@rxbp},{\u@rybp}]}%
109 \else
110 \hbox{\t@xdinclude
111 [{\l@lxbp},{\l@lybp}][{\u@rxbp},{\u@rybp}]{\p@sfile}}%
112 \fi
113 \t@xdtext}%
114 }
115 % Superimpose TeX text. The position is temporarily offset to a position
116 % corresponding to (0 0) to place the TeX text.
117 \def\t@xdtext {
118 \ifdim \wd\t@xdbox>0pt
119 \t@xderror {TeXdraw box non-zero size, possible extraneous text}%
120 \fi
121 \pixtodim \xminpix \t@xpos \pixtodim \yminpix \t@ypos
122 \kern \t@ypos
123 \hbox {\kern -\t@xpos
124 \box\t@xdbox % TeX text
125 \kern \t@xpos}%
126 \kern -\t@ypos\relax
127 }
128
129 % ===== Drawing scaling
130 % The units in any segment may be scaled arbitrarily. A unit scale is
131 % local to a segment but affects enclosed segments unless specifically
132 % overridden in that segment. In addition there is a segment scale. The
133 % overall scale is the product of the two scaling factors.
134 %
135 % Scaling is handled entirely on the TeX side, the PostScript side gets
136 % absolute pixel coordinates.
137
138 % Drawing units, e.g. "in" or "cm"
139 \def\drawdim #1 {\def\d@dim{#1\relax}}
140
141 % \u@nitsc - unit scale
142 % \s@egsc - segment scale
143 % \d@sc - drawing scale, product of the unit scale and segment scale
144
145 % Note that successive application of relative scale factors can lead
146 % to poor accuracy of the final scale factor. Each scale factor is
147 % represented to about 5 decimal digits after the decimal point.
148 \def\setunitscale #1 {\edef\u@nitsc{#1}%
149 \realmult \u@nitsc \s@egsc \d@sc}
150 \def\relunitscale #1 {\realmult {#1}\u@nitsc \u@nitsc
151 \realmult \u@nitsc \s@egsc \d@sc}
152 \def\setsegscale #1 {\edef\s@egsc {#1}%
153 \realmult \u@nitsc \s@egsc \d@sc}
154 \def\relsegscale #1 {\realmult {#1}\s@egsc \s@egsc
155 \realmult \u@nitsc \s@egsc \d@sc}
156
157 % ===== Drawing segments
158 % The position is restored after a segment.
159 % Segments use TeX grouping on the TeX side and gsave/grestore on the
160 % PostScript side to keep changes local. On the TeX side segments have
161 % (0 0) as the initial point, while the PostScript side sees no scale
162 % changes or translations.
163 \def\bsegment {\ifp@ath
164 \f@lushbs
165 \f@lushmove
166 \fi
167 \begingroup
168 \x@segoffpix=\x@pix
169 \y@segoffpix=\y@pix
170 \setsegscale 1
171 \global\advance \d@bs by 1\relax}
172 \def\esegment {\endgroup
173 \ifnum \d@bs=0
174 \writetx {es}%
175 \else
176 \global\advance \d@bs by -1
177 \fi}
178
179 % Save a position
180 % Save each coordinate as the macro "*name". The macro is defined to
181 % be the pixel coordinate value.
182 \def\savecurrpos (#1 #2){\getsympos (#1 #2)\a@rgx\a@rgy
183 \s@etcsn \a@rgx {\the\x@pix}%
184 \s@etcsn \a@rgy {\the\y@pix}}
185 \def\savepos (#1 #2)(#3 #4){\getpos (#1 #2)\a@rgx\a@rgy
186 \coordtopix \a@rgx \t@pixa
187 \advance \t@pixa by \x@segoffpix
188 \coordtopix \a@rgy \t@pixb
189 \advance \t@pixb by \y@segoffpix
190 \getsympos (#3 #4)\a@rgx\a@rgy
191 \s@etcsn \a@rgx {\the\t@pixa}%
192 \s@etcsn \a@rgy {\the\t@pixb}}
193
194 % ===== Line parameters
195 % The following parameters apply to subsequent lines. Each of these
196 % commands invokes a stroke to draw the previous line segments,
197 % establishes the current point and then changes the line parameter.
198 % The parameters are kept local by the PostScript gsave/grestore
199 % mechanism. We use \writetx here, instead of \writeps, since we
200 % do not want to flush any moves.
201 \def\linewd #1 {\coordtopix {#1}\t@pixa
202 \f@lushbs
203 \writetx {\the\t@pixa\space sl}}
204 \def\setgray #1 {\f@lushbs
205 \writetx {#1 sg}}
206 \def\lpatt (#1){\listtopix (#1)\p@ixlist
207 \f@lushbs
208 \writetx {[\p@ixlist] sd}}
209
210 % ===== Line drawing
211 % PostScript uses the concept of a path consisting of line segments.
212 % In this interface to PostScript, paths are continuous across the
213 % beginning of segments. Paths terminate at the end of a segment with
214 % an implicit move. In addition, paths are both terminated and started
215 % with a move. There is a current point at all times, starting with
216 % initial position (0,0).
217 \def\lvec (#1 #2){\getpos (#1 #2)\a@rgx\a@rgy
218 \s@etpospix \a@rgx \a@rgy
219 \writeps {\the\x@pix\space \the\y@pix\space lv}}
220 \def\rlvec (#1 #2){\getpos (#1 #2)\a@rgx\a@rgy
221 \r@elpospix \a@rgx \a@rgy
222 \writeps {\the\x@pix\space \the\y@pix\space lv}}
223 \def\move (#1 #2){\getpos (#1 #2)\a@rgx\a@rgy
224 \s@etpospix \a@rgx \a@rgy
225 \s@avemove \x@pix \y@pix}
226 \def\rmove (#1 #2){\getpos (#1 #2)\a@rgx\a@rgy
227 \r@elpospix \a@rgx \a@rgy
228 \s@avemove \x@pix \y@pix}
229
230 % ===== Circles, ellipses and arcs
231 % Note that arcs do not update the size of the drawing.
232 % \lcir, stroked circle
233 % r:#1 - radius
234 % \fcir, filled circle
235 % f:#1 - fill gray level, 0 is black, 1 is white
236 % r:#2 - radius
237 % \ellip, stroked ellipse
238 % rx:#1 - x radius
239 % ry:#2 - y radius
240 % \fellip, filled ellipse
241 % f:#1 - fill gray level, 0 is black, 1 is white
242 % rx:#1 - x radius
243 % ry:#2 - y radius
244 % \larc, stroked counterclockwise arc, with the present position being
245 % the center of the arc. Only the arc is drawn (not the line
246 % joining the center to the beginning of the arc)
247 % r:#1 - radius
248 % sd:#2 - start angle (degrees)
249 % ed:#3 - end angle (degrees)
250 \def\lcir r:#1 {\coordtopix {#1}\t@pixa
251 \writeps {\the\t@pixa\space cr}%
252 \r@elupd \t@pixa \t@pixa
253 \r@elupd {-\t@pixa}{-\t@pixa}}
254 \def\fcir f:#1 r:#2 {\coordtopix {#2}\t@pixa
255 \writeps {\the\t@pixa\space #1 fc}%
256 \r@elupd \t@pixa \t@pixa
257 \r@elupd {-\t@pixa}{-\t@pixa}}
258 \def\lellip rx:#1 ry:#2 {\coordtopix {#1}\t@pixa
259 \coordtopix {#2}\t@pixb
260 \writeps {\the\t@pixa\space \the\t@pixb\space el}%
261 \r@elupd \t@pixa \t@pixb
262 \r@elupd {-\t@pixa}{-\t@pixb}}
263 \def\fellip f:#1 rx:#2 ry:#3 {\coordtopix {#2}\t@pixa
264 \coordtopix {#3}\t@pixb
265 \writeps {\the\t@pixa\space \the\t@pixb\space #1 fe}%
266 \r@elupd \t@pixa \t@pixb
267 \r@elupd {-\t@pixa}{-\t@pixb}}
268 \def\larc r:#1 sd:#2 ed:#3 {\coordtopix {#1}\t@pixa
269 \writeps {\the\t@pixa\space #2 #3 ar}}
270
271 % ===== Fill commands
272 % The form here completes a path with a closepath, applies the fill,
273 % starts a newpath and moves to the current point. The gray level has
274 % 0 as black and 1 as white. The current path is terminated.
275
276 \def\ifill f:#1 {\writeps {#1 fl}} % Fill only
277 \def\lfill f:#1 {\writeps {#1 fp}} % Stroke and fill
278
279 % ===== Text
280 % TeX text superimposed on the drawing
281 % \htext (x y){text} or \htext {text}
282 % \vtext (x y){text} or \vtext {text}
283 % \rtext td:angle (x y){text} or \rtext td:angle {text}
284 % \textref h:#1 v:#2
285
286 % The TeX text (or whatever) is placed in an \hbox. The box is rotated
287 % for vertical text. The text is placed on the drawing at the specified
288 % location (coordinates specified) or the current location (coordinates
289 % not specified). The text reference point is placed at that location.
290 % For the purposes of determining the drawing size, the text box is of
291 % zero size.
292
293 % Horizontal text
294 % Check if the argument starts with a left parenthesis
295 \def\htext #1{\def\testit {#1}%
296 \ifx \testit\l@paren
297 \let\t@cmd=\h@move
298 \else
299 \let\t@cmd=\h@text
300 \fi
301 \t@cmd {#1}}
302
303 % Rotated text
304 \def\rtext td:#1 #2{\def\testit {#2}%
305 \ifx \testit\l@paren
306 \let\t@cmd=\r@move
307 \else
308 \let\t@cmd=\r@text
309 \fi
310 \t@cmd td:#1 {#2}}
311
312 % Vertical text
313 \def\vtext {\rtext td:90 }
314
315 % Text reference point
316 % h:#1 text horizontal reference point - L, C or R
317 % v:#2 text vertical reference point - T, C or B
318 \def\textref h:#1 v:#2 {\ifx #1R%
319 \edef\l@stuff {\hss}\edef\r@stuff {}%
320 \else
321 \ifx #1C%
322 \edef\l@stuff {\hss}\edef\r@stuff {\hss}%
323 \else % default L
324 \edef\l@stuff {}\edef\r@stuff {\hss}%
325 \fi
326 \fi
327 \ifx #2T%
328 \edef\t@stuff {}\edef\b@stuff {\vss}%
329 \else
330 \ifx #2C%
331 \edef\t@stuff {\vss}\edef\b@stuff {\vss}%
332 \else % default B
333 \edef\t@stuff {\vss}\edef\b@stuff {}%
334 \fi
335 \fi}
336
337 % ===== Arrow vectors
338 \def\avec (#1 #2){\getpos (#1 #2)\a@rgx\a@rgy
339 \s@etpospix \a@rgx \a@rgy
340 \writeps {\the\x@pix\space \the\y@pix\space (\a@type) %
341 \the\a@lenpix\space \the\a@widpix\space av}}
342
343 \def\ravec (#1 #2){\getpos (#1 #2)\a@rgx\a@rgy
344 \r@elpospix \a@rgx \a@rgy
345 \writeps {\the\x@pix\space \the\y@pix\space (\a@type) %
346 \the\a@lenpix\space \the\a@widpix\space av}}
347
348 % Arrowhead size
349 % l:#1 - length of the arrowhead
350 % w:#2 - width of the base of the arrowhead
351 \def\arrowheadsize l:#1 w:#2 {\coordtopix{#1}\a@lenpix
352 \coordtopix{#2}\a@widpix}
353 % Arrowhead type
354 % t:#1 - arrowhead type, F filled triangle (using current gray level)
355 % T empty closed triangle
356 % W white filled triangle
357 % V Vee shape, at the end of the vector
358 % H (or other character) Vee shape, vector stops
359 % short of the Vee
360 \def\arrowheadtype t:#1 {\edef\a@type{#1}}
361
362 % ===== Bezier curve
363 % The initial point is assumed to be the current point. Only the last
364 % coordinate affects the size of the plot.
365 \def\clvec (#1 #2)(#3 #4)(#5 #6)%
366 {\getpos (#1 #2)\a@rgx\a@rgy
367 \coordtopix \a@rgx\t@pixa
368 \advance \t@pixa by \x@segoffpix
369 \coordtopix \a@rgy\t@pixb
370 \advance \t@pixb by \y@segoffpix
371 \getpos (#3 #4)\a@rgx\a@rgy
372 \coordtopix \a@rgx\t@pixc
373 \advance \t@pixc by \x@segoffpix
374 \coordtopix \a@rgy\t@pixd
375 \advance \t@pixd by \y@segoffpix
376 \getpos (#5 #6)\a@rgx\a@rgy
377 \s@etpospix \a@rgx \a@rgy
378 \writeps {\the\t@pixa\space \the\t@pixb\space
379 \the\t@pixc\space \the\t@pixd\space
380 \the\x@pix\space \the\y@pix\space cv}}
381
382 % ===== Draw the bounding box
383 \def\drawbb {\bsegment
384 \drawdim bp
385 \linewd 0.24 % line width 1/300 inch = 0.24 bp
386 \setunitscale {\p@sfactor}
387 \writeps {\the\xminpix\space \the\yminpix\space mv}%
388 \writeps {\the\xminpix\space \the\ymaxpix\space lv}%
389 \writeps {\the\xmaxpix\space \the\ymaxpix\space lv}%
390 \writeps {\the\xmaxpix\space \the\yminpix\space lv}%
391 \writeps {\the\xminpix\space \the\yminpix\space lv}%
392 \esegment}
393
394
395 % ===============================================================
396 % ===== Utility macros used by TeXdraw ==========================
397
398 % ===== Decode coordinates
399 % Get coordinates
400 % This macro is used to get two arguments separated by a blank, with
401 % possible leading and trailing blanks. Symbolic coordinates are
402 % converted to user coordinates.
403 % (#1 #2) - coordinates
404 % #3 - macro name to receive the x-coordinate value
405 % #4 - macro name to receive the y-coordinate value
406 \def\getpos (#1 #2)#3#4{\g@etargxy #1 #2 {} \\#3#4%
407 \c@heckast #3%
408 \ifa@st
409 \g@etsympix #3\t@pixa
410 \advance \t@pixa by -\x@segoffpix
411 \pixtocoord \t@pixa #3%
412 \fi
413 \c@heckast #4%
414 \ifa@st
415 \g@etsympix #4\t@pixa
416 \advance \t@pixa by -\y@segoffpix
417 \pixtocoord \t@pixa #4%
418 \fi}
419
420 % Get symbolic coordinate names
421 % (#1 #2) - symbolic coordinates
422 % #3 - macro name to receive the symbolic x coordinate name
423 % #4 - macro name to receive the symbolic y coordinate name
424 \def\getsympos (#1 #2)#3#4{\g@etargxy #1 #2 {} \\#3#4%
425 \c@heckast #3%
426 \ifa@st \else
427 \t@xderror {TeXdraw: invalid symbolic coordinate}%
428 \fi
429 \c@heckast #4%
430 \ifa@st \else
431 \t@xderror {TeXdraw: invalid symbolic coordinate}%
432 \fi}
433
434 % ===== Convert a list of values to pixel values
435 % (#1) - blank separated list of values in user coordinates
436 % #2 - macro name to receive the blank separated list of pixel values
437 \def\listtopix (#1)#2{\def #2{}%
438 \edef\l@ist {#1 }% % append a blank to the string
439 \m@oretrue
440 \loop
441 \expandafter\g@etitem \l@ist \\\a@rgx\l@ist
442 \a@pppix \a@rgx #2%
443 \ifx \l@ist\empty
444 \m@orefalse
445 \fi
446 \ifm@ore
447 \repeat}
448
449 % ===== Real multiplication
450 % This function uses the property that a box dimension may be scaled by
451 % a real value. The values are converted to dimensions in units of pt.
452 % This choice gives us a reasonable dynamic range. The final step is to
453 % clean off the "pt" on the resulting dimension. Note that these are fixed
454 % point operations with each operand represented to an accuracy of about 5
455 % decimal places.
456
457 % Note we must use magnified points not "true" points, since the answer is
458 % expressed in magnified points. The result will be calculated in the same
459 % manner no matter what the magnification is.
460 % #1 and #2 are multiplicands
461 % #3 macro name to capture the real result
462 \def\realmult #1#2#3{\dimen0=#1pt
463 \dimen2=#2\dimen0
464 \edef #3{\expandafter\c@lean\the\dimen2}}
465
466 % ===== Divide integers, real result
467 % #1 integer numerator value
468 % #2 integer denominator (divisor) value
469 % #3 macro name to capture the real result
470 \def\intdiv #1#2#3{\t@counta=#1
471 \t@countb=#2
472 % Limitations: #1 must be negatable, i.e. it must not be the largest
473 % magnitude negative number
474 % #2 must be able to be multiplied by 2 without overflow
475 % Calculate a*65536/b where the factor 65536 converts from pt to sp.
476 % This operation can also be interpretated as an extended precision
477 % numerator divided by the denominator. The scheme used is basically a
478 % long division, except that it is bootstrapped by an integer divide.
479 % The computations are carried out with positive numerator and
480 % denominator, with the appropriate restoration of sign at the end.
481 % \t@counta == remainder, r, initially set to a
482 % \t@countb == denominator, b
483 % \t@countc == quotient, q
484 % \t@countd == +1, a and b have the same sign
485 % -1, a and b have opposite signs
486 % \t@counte == temporary register
487 \ifnum \t@countb<0
488 \t@counta=-\t@counta
489 \t@countb=-\t@countb
490 \fi
491 \t@countd=1 % record the sign
492 \ifnum \t@counta<0
493 \t@counta=-\t@counta
494 \t@countd=-1
495 \fi
496 % % q=a/b, r=a-q*b
497 \t@countc=\t@counta \divide \t@countc by \t@countb
498 \t@counte=\t@countc \multiply \t@counte by \t@countb
499 \advance \t@counta by -\t@counte
500 \t@counte=-1
501 \loop
502 \advance \t@counte by 1
503 \ifnum \t@counte<16 % loop 16 times
504 \multiply \t@countc by 2 % q=2q
505 \multiply \t@counta by 2 % r=2r
506 \ifnum \t@counta<\t@countb \else % if ( r >= b )
507 \advance \t@countc by 1 % q=q+1
508 \advance \t@counta by -\t@countb % r=r-b
509 \fi
510 \repeat
511 \divide \t@countb by 2 % rounding
512 \ifnum \t@counta<\t@countb % if ( r >= b/2 ) q=q+1
513 \advance \t@countc by 1
514 \fi
515 \ifnum \t@countd<0 % restore the sign
516 \t@countc=-\t@countc
517 \fi
518 \dimen0=\t@countc sp % express as a dimension
519 \edef #3{\expandafter\c@lean\the\dimen0}}
520
521 % ===============================================================
522 % ===== Internal TeXdraw macros =================================
523
524 % ===== Macros for converting between dimensions and units
525 % Convert drawing units (coordinate value, scaled by the unit scale and
526 % segment scale) to pixels. We use rounding to get more accurate results.
527 % #1 dimension in drawing units
528 % #2 count in pixels (returned into a count)
529 \def\coordtopix #1#2{\dimen0=#1\d@dim
530 \dimen2=\d@sc\dimen0
531 \t@counta=\dimen2 % scaled dimension in sp
532 \t@countb=\s@ppix
533 \divide \t@countb by 2
534 \ifnum \t@counta<0 % rounding
535 \advance \t@counta by -\t@countb
536 \else
537 \advance \t@counta by \t@countb
538 \fi
539 \divide \t@counta by \s@ppix
540 #2=\t@counta}
541
542 % Convert from absolute pixels to relative scaled coordinates
543 % #1 - input integer pixel value
544 % #2 - macro name to receive the character string corresponding to the
545 % floating point coordinate value
546 \def\pixtocoord #1#2{\t@counta=#1%
547 \multiply \t@counta by \s@ppix
548 \dimen0=\d@sc\d@dim
549 \t@countb=\dimen0
550 \intdiv \t@counta \t@countb #2}
551
552 % Convert pixels to TeX dimensions.
553 % #1 - input integer pixel value
554 % #2 - returned dimension (returned into a dimension register)
555 \def\pixtodim #1#2{\t@countb=#1%
556 \multiply \t@countb by \s@ppix
557 #2=\t@countb sp\relax}
558
559 % Convert pixels to (integer) bp units
560 % #1 - input pixel value
561 % #2 - integer value, returned as a macro definition
562 \def\pixtobp #1#2{\dimen0=\p@sfactor pt
563 \t@counta=\dimen0
564 \multiply \t@counta by #1%
565 \ifnum \t@counta < 0 % rounding
566 \advance \t@counta by -32768
567 \else
568 \advance \t@counta by 32768
569 \fi
570 \divide \t@counta by 65536
571 \edef #2{\the\t@counta}}
572
573 % ===== Allocations for registers and counts
574 % == Temporary count registers
575 \newcount\t@counta \newcount\t@countb % Use at lowest levels
576 \newcount\t@countc \newcount\t@countd
577 \newcount\t@counte
578 \newcount\t@pixa \newcount\t@pixb % Use for pixel values
579 \newcount\t@pixc \newcount\t@pixd
580
581 % == Temporary dimension registers
582 \newdimen\t@xpos \newdimen\t@ypos
583
584 % == Position and parameter registers
585 % The minimum and maximum extent in the X and Y direction in pixel units
586 % (updated globally to reach outside segments)
587 \newcount\xminpix \newcount\xmaxpix
588 \newcount\yminpix \newcount\ymaxpix
589
590 % == Arrowhead parameters
591 \newcount\a@lenpix \newcount\a@widpix
592
593 % == Absolute pixel positions
594 \newcount\x@pix \newcount\y@pix
595 \newcount\x@segoffpix \newcount\y@segoffpix
596 \newcount\x@savepix \newcount\y@savepix
597
598 % == Conversion factor
599 \newcount\s@ppix % sp/pixel
600
601 % == Pending segments count
602 \newcount\d@bs
603
604 % == Counter to form unique file names
605 \newcount\t@xdnum
606 \global\t@xdnum=0
607
608 % == TeXdraw box
609 \newbox\t@xdbox
610
611 % == Output stream number for the PostScript file
612 \newwrite\drawfile
613
614 % == \newif
615 \newif\ifm@pending
616 \newif\ifp@ath
617 \newif\ifa@st
618 \newif\ifm@ore
619 \newif \ift@extonly
620 \newif\ifp@osinit
621
622 % == \newtoks
623 \newtoks\everytexdraw
624
625 % ===== Character definitions
626 \def\l@paren{(}
627 \def\a@st{*}
628
629 % ===== Special character macros
630 % Need to be able to insert "%", "{" and "}" characters into the
631 % PostScript file.
632 % Define macros which have these characters with category "other".
633 % We will assume that these characters have the standard meanings -
634 % after all, we use comments and braces in this code.
635 \catcode`\%=12
636 \def\p@b {%!} \def\p@p {%%}
637 \catcode`\%=14
638 \catcode`\{=12 \catcode`\}=12 \catcode`\u=1 \catcode`\v=2
639 \def\l@br u{v \def\r@br u}v
640 \catcode `\{=1 \catcode`\}=2 \catcode`\u=11 \catcode`\v=11
641
642 % ===== Pixel conversion factors
643 % The position is kept as an integer value (count). It is set to a
644 % resolution corresponding to 300 units/inch. We refer to them as pixels,
645 % but in fact the resolution is just that: movements are quantized to lie
646 % on a grid with that resolution.
647
648 % Using pixel units which correspond to the actual resolution of the device
649 % has advantages in that all horizontal and vertical lines then will be
650 % drawn with the same line thickness. In addition the coordinates are
651 % then integer values (no decimal point or leading zeros) which leads
652 % to a more compact PostScript file.
653
654 % The following macro sets the conversion from PostScript units (bp) to the
655 % integer units (pixels). The file inclusion \special environment in the
656 % PostScript driver restores the context to default PostScript values
657 % (bp or 72/in and origin in the lower lefthand corner). A scaling value
658 % of 0.24 converts to 300/inch. Note that the PostScript commands written
659 % to the temporary PostScript file do not depend on the TeX magnification
660 % in effect. Magnification should be handled by the dvi to PostScript
661 % driver at the time that the file is included in the output.
662
663 % Calculate the conversion factors
664 % Let s@ppix = sp/pixel = u / p, where u = sp/unit and p = pix/unit (both
665 % integer values).
666 % We calculate s@ppix as
667 % s@ppix = [ (u+0.5p)/p ]
668 % We also calculate the PostScript scale factor bp/pixel
669 % Let b = sp/bp. We want p@sfactor = s@ppix/b. For 300 pixels/inch, this
670 % gives p@sfactor=0.24. Using rounding
671 % p@sfactor = [ (s@ppix+0.5b)/b ] .
672 % To carry out the arithmetic, we will operate in sp units (integers) and
673 % generate the answer in pt units (multiplying by sp/pt). This result will
674 % expressed as a character string representing a real number after the "pt"
675 % designator is stripped off.
676
677 {\catcode`\p=12 \catcode`\t=12
678 \gdef\c@lean #1pt{#1}}
679
680 \def\sppix#1/#2 {\dimen0=1#2 \s@ppix=\dimen0
681 \t@counta=#1%
682 \divide \t@counta by 2
683 \advance \s@ppix by \t@counta
684 \divide \s@ppix by #1% % \s@ppix available
685 \t@counta=\s@ppix
686 \multiply \t@counta by 65536 % 1 pt = 65536 sp
687 \advance \t@counta by 32891 % 0.5 bp = 32890.88 sp
688 \divide \t@counta by 65782 % 1 bp = 65781.76 sp
689 \dimen0=\t@counta sp
690 \edef\p@sfactor {\expandafter\c@lean\the\dimen0}}
691
692 % ===== Low level coordinate decoding macros
693 % Get two values, separated by a blank
694 % Invoke as \g@etargxy <stuff> {} \\\ma\mb
695 \def\g@etargxy #1 #2 #3 #4\\#5#6{\def #5{#1}%
696 \ifx #5\empty
697 \g@etargxy #2 #3 #4 \\#5#6% leading blank
698 \else
699 \def #6{#2}%
700 \def\a@rg {#3}%
701 \ifx \a@rg\empty \else
702 \t@xderror {TeXdraw: invalid coordinate}%
703 \fi
704 \fi}
705
706 % Check for a leading asterisk
707 % Sets \a@stfalse or \a@sttrue, test with \ifa@st
708 \def\c@heckast #1{\expandafter
709 \c@heckastll #1\\}
710 \def\c@heckastll #1#2\\{\def\testit {#1}%
711 \ifx \testit\a@st
712 \a@sttrue
713 \else
714 \a@stfalse
715 \fi}
716
717 % Decode a symbolic coordinate
718 % Pixel value returned to a count
719 \def\g@etsympix #1#2{\expandafter
720 \ifx \csname #1\endcsname \relax
721 \t@xderror {TeXdraw: undefined symbolic coordinate}%
722 \fi
723 #2=\csname #1\endcsname}
724
725 % Set a macro named #1 to have value #2
726 \def\s@etcsn #1#2{\expandafter
727 \xdef\csname#1\endcsname {#2}}
728
729 % ===== Low level list decoding macros
730 % Pick off the first item -> #3, rest of string -> #4
731 \def\g@etitem #1 #2\\#3#4{\edef #4{#2}\edef #3{#1}}
732 \def\a@pppix #1#2{\edef\a@rg {#1}%
733 \ifx \a@rg\empty \else
734 \coordtopix {#1}\t@pixa
735 \ifx #2\empty
736 \edef #2{\the\t@pixa}%
737 \else
738 \edef #2{#2 \the\t@pixa}%
739 \fi
740 \fi}
741
742 % ===== Macros for updating the position
743 % Calculate the position in pixels and update the maximum excursions
744 \def\s@etpospix #1#2{\coordtopix {#1}\x@pix
745 \advance \x@pix by \x@segoffpix
746 \coordtopix {#2}\y@pix
747 \advance \y@pix by \y@segoffpix
748 \u@pdateminmax \x@pix \y@pix}
749
750 \def\r@elpospix #1#2{\coordtopix {#1}\t@pixa
751 \advance \x@pix by \t@pixa
752 \coordtopix {#2}\t@pixa
753 \advance \y@pix by \t@pixa
754 \u@pdateminmax \x@pix \y@pix}
755
756 \def\r@elupd #1#2{\t@counta=\x@pix
757 \advance\t@counta by #1%
758 \t@countb=\y@pix
759 \advance\t@countb by #2%
760 \u@pdateminmax \t@counta \t@countb}
761
762 \def\u@pdateminmax #1#2{\ifnum #1>\xmaxpix
763 \global\xmaxpix=#1%
764 \fi
765 \ifnum #1<\xminpix
766 \global\xminpix=#1%
767 \fi
768 \ifnum #2>\ymaxpix
769 \global\ymaxpix=#2%
770 \fi
771 \ifnum #2<\yminpix
772 \global\yminpix=#2%
773 \fi}
774
775 % ===== Save moves / flush moves
776 % A TeXdraw segment which generates only TeX text uses only move, begin
777 % segment and end segment commands. The goal is to avoid writing out
778 % empty segments for such cases. To this end, moves are held back and
779 % only written out if necessary to set the position or terminate a path.
780 % Also in this way, a TeXdraw drawing which generates only TeX text will
781 % not generate a PostScript file.
782
783 % Two flags are used. Both flags are local to a segment.
784 % - move pending: Set when a move has been invoked but the move command
785 % has not been written out to the PostScript file.
786 % - path in progress: Set when a PostScript path has been started but the
787 % path has not been terminated and stroked.
788 % (1) Moves are kept back. Using TeX's groups, a local flag and local
789 % position registers are used to keep track of whether the latest
790 % move applicable to a given segment has been written out or not. In
791 % effect there is a stack of pending moves, one for each level of
792 % segment nesting.
793 % (2) At the beginning of a segment, if a PS path is in progress and a
794 % a move is pending, the move is written out, terminating the path
795 % and stroking the path. This is done to ensure that the path is
796 % stroked before lines and/or fills are executed in the segment.
797 % (3) At the beginning of a segment, if a PS path is not in progress,
798 % any pending moves are kept back. Effectively, the move will be
799 % transferred into the segment. It will be written out only when
800 % the position needs to be updated for some other command. Such
801 % moves which are transferred into segments may have to be repeated
802 % outside the segment. The move pending flag will be restored to
803 % the value outside the segment on exit from the segment.
804 % (4) A begin segment command is not written out, but instead a global
805 % segment backlog counter is incremented. The backlog of begin
806 % segment commands is written out when a drawing command is
807 % encountered.
808 % The effect of the above on the TeXdraw commands is as follows.
809 % (a) move:
810 % - set the current position
811 % - record the position of the saved move
812 % - set the move pending flag
813 % (b) begin segment:
814 % - if a path is in progress
815 % - if a move is pending
816 % - if there is a backlog of segments
817 % - write out enough begin segments to clear the backlog
818 % - write out the pending move
819 % - reset the move pending flag (local to the containing segment,
820 % but affects inferior segments)
821 % - reset the path in progress flag
822 % - increment the segment backlog counter
823 % - begin a group
824 % (c) end segment:
825 % - end a group
826 % - if there is no backlog of segments
827 % - write an end segment command
828 % - if there is a backlog of segments
829 % - decrement the backlog counter, thereby omitting an empty
830 % empty segment.
831 % - the move pending flag and path in progress flag are automatically
832 % restored on leaving the TeX group
833 % (d) text:
834 % - create a text box
835 % (e) line parameters:
836 % - if there is a backlog of segments
837 % - write out enough begin segments to clear the backlog
838 % - clear the path in progress flag
839 % - write the PS command changing the line parameter
840 % (f) other drawing commands:
841 % - update the current position
842 % - if there is a backlog of segments
843 % - write out enough begin segments to clear the backlog
844 % - if there is a pending move
845 % - write out the pending move
846 % - reset the move pending flag (local to this segment, but affects
847 % inferior segments)
848 % - set the path in progress flag
849 % - write the drawing command
850 % Notes:
851 % (1) The es PS command strokes the path at the end of a segment to
852 % ensure that the correct line parameters are used for the segment.
853 % The path before the corresponding bs command is restored and
854 % continued.
855 % (2) The \f@lushbs and \f@lushmove commands must be invoked before each
856 % drawing command written to the PS file. The macro \writeps includes
857 % these operations.
858
859 % Another awkward business has to do with initialization. We want a
860 % default (0 0) initial position so that the user can draw vectors
861 % immediately. However, if the user specifies another move before
862 % beginning to draw, that position should be the initial position. The
863 % importance of this initial position is that the determination of the
864 % maximum excursion must take this value into account. We handle the
865 % initialization in the \s@avemove and \f@lushmove macros. The macro
866 % \ifp@osinit indicates whether the next move should be captured as the
867 % initial values for \xminpix, \yminpix, \xmaxpix, and \ymaxpix. However,
868 % if a \f@lushmove is invoked, then we assume that the appropriate initial
869 % values have already been set. The "mv" command in PostScript is defined
870 % to stroke the current path (if any) and move to the pixel coordinates
871 % specified.
872
873 % Note that \m@pendingtrue and \m@pendingfalse define the flag locally.
874 % In addition, \x@savepix and \y@savepix are local variables. We make
875 % use of the fact that the values of the flag and positions propagate
876 % down to inferior segments but not up to superior segments. This
877 % behaviour Is consistent with the gsave/grestore operation on the
878 % PostScript side.
879 \def\s@avemove #1#2{\x@savepix=#1\y@savepix=#2%
880 \m@pendingtrue
881 \ifp@osinit \else
882 \global\p@osinittrue
883 \global\xminpix=\x@savepix \global\yminpix=\y@savepix
884 \global\xmaxpix=\x@savepix \global\ymaxpix=\y@savepix
885 \fi}
886
887 \def\f@lushmove {\global\p@osinittrue
888 \ifm@pending
889 \writetx {\the\x@savepix\space \the\y@savepix\space mv}%
890 \m@pendingfalse
891 \p@athfalse
892 \fi}
893
894 % ===== Flush begin segment
895 % \f@lushbs flushes any saved up \bsegments. Some of these may be
896 % redundant, but we cannot know without looking ahead beyond the
897 % \esegment.
898 \def\f@lushbs {\loop
899 \ifnum \d@bs>0
900 \writetx {bs}%
901 \global\advance \d@bs by -1
902 \repeat}
903
904 % ===== Internal text macros
905 % Horizontal text, use only 3 levels of box nesting here
906 \def\h@move #1#2 #3)#4{\move (#2 #3)%
907 \h@text {#4}}
908 \def\h@text #1{\pixtodim \x@pix \t@xpos
909 \pixtodim \y@pix \t@ypos
910 \vbox to 0pt{\normalbaselines
911 \t@stuff
912 \kern -\t@ypos
913 \hbox to 0pt{\l@stuff
914 \kern \t@xpos
915 \hbox {#1}%
916 \kern -\t@xpos
917 \r@stuff}%
918 \kern \t@ypos
919 \b@stuff\relax}}
920
921 % Rotated text
922 % Uses 5 levels of box nesting here (so that the text reference point
923 % is that <before> rotation). This was done so that the reference point
924 % definition makes sense with arbitrary angle rotation. The text is
925 % rotated with respect to the text reference point. The result is zero
926 % sized. These macros generate in-line PostScript.
927 % #1 - rotation angle in degrees
928 % #2 - text to be rotated
929 \def\r@move td:#1 #2#3 #4)#5{\move (#3 #4)%
930 \r@text td:#1 {#5}}
931 \def\r@text td:#1 #2{\vbox to 0pt{\pixtodim \x@pix \t@xpos
932 \pixtodim \y@pix \t@ypos
933 \kern -\t@ypos
934 \hbox to 0pt{\kern \t@xpos
935 \rottxt {#1}{\z@sb {#2}}%
936 \hss}%
937 \vss}}
938 \def\z@sb #1{\vbox to 0pt{\normalbaselines
939 \t@stuff
940 \hbox to 0pt{\l@stuff \hbox {#1}\r@stuff}%
941 \b@stuff}}
942
943 % ===== Rotate text, in-line PostScript code
944 \ifx \rotatebox\@undefined
945 \def\rottxt #1#2{\bgroup
946 \special {ps: gsave currentpoint currentpoint translate
947 #1\space neg rotate
948 neg exch neg exch translate}%
949 #2%
950 \special {ps: currentpoint grestore moveto}%
951 \egroup}
952 \else
953 \let\rottxt=\rotatebox
954 \fi
955
956 % ===== Error message
957 % If not defined, use the plain TeX errmessage macro
958 \ifx \t@xderror\@undefined
959 \let\t@xderror=\errmessage
960 \fi
961
962 % ===== Default values
963 % These are reset each time TeXdraw is invoked
964 \def\t@exdrawdef {\sppix 300/in % 300 pixels/inch
965 \drawdim in % drawing units are inches
966 \edef\u@nitsc {1}% % unit scale 1 (has to be set
967 % before invoking \setsegscale)
968 \setsegscale 1 % segment scale 1
969 \arrowheadsize l:0.16 w:0.08
970 \arrowheadtype t:T
971 \textref h:L v:B }
972
973
974 % ===============================================================
975 % ===== PostScript file macros ==================================
976
977 % ===== Include the TeXdraw graphics
978 % The drawing in a box of appropriate size will be placed such that its
979 % lower left hand corner will be at the current TeX position.
980 \ifx \includegraphics\@undefined
981 \def\t@xdinclude [#1,#2][#3,#4]#5{%
982 \begingroup % keep definitions local
983 \message {<#5>}%
984 \leavevmode
985 \t@counta=-#1% % integer bounding box coordinates
986 \t@countb=-#2%
987 \setbox0=\hbox{%
988 \special {PSfile="#5"\space
989 hoffset=\the\t@counta\space voffset=\the\t@countb}}%
990 \t@ypos=#4 bp%
991 \advance \t@ypos by -#2 bp%
992 \t@xpos=#3 bp%
993 \advance \t@xpos by -#1 bp%
994 \dp0=0pt \ht0=\t@ypos \wd0=\t@xpos
995 \box0%
996 \endgroup}
997 \else
998 \let\t@xdinclude=\includegraphics
999 \fi
1000
1001 % Leave space without including a PS file
1002 \def\t@xdempty [#1,#2][#3,#4]{%
1003 \begingroup
1004 \leavevmode
1005 \setbox0=\hbox{}%
1006 \t@ypos=#4 bp%
1007 \advance \t@ypos by -#2 bp%
1008 \t@xpos=#3 bp%
1009 \advance \t@xpos by -#1 bp%
1010 \dp0=0pt \ht0=\t@ypos \wd0=\t@xpos
1011 \box0%
1012 \endgroup}
1013
1014 % ===== Write to the PostScript file
1015 % Macro to write PostScript commands to the temporary PostScript file
1016 % To decrease the size of the PostScript file, moves are kept back to
1017 % allow redundant multiple moves to be removed. In addition empty gsave/
1018 % grestore pairs are not written. The PostScript file is not opened if
1019 % TeXdraw has not generated any PostScript commands, i.e. it has produced
1020 % only TeX text.
1021 % \writeps : flushes the pending move to make sure things are positioned
1022 % correctly and flushes pending begin segments before calling
1023 % \writetx to write to the PostScript file
1024 % \writetx : writes directly to the PostScript file. This version is used
1025 % only for those commands which just change line parameters
1026 % without drawing. This routine opens the file and writes the
1027 % PS file header the first time it is called.
1028 % \p@swr : lowest level direct write to the PostScript file
1029 \def\writeps #1{\f@lushbs
1030 \f@lushmove
1031 \p@athtrue
1032 \writetx {#1}}
1033 \def\writetx #1{\p@sopen
1034 \ifx\p@sfile\p@sundef \else
1035 \p@swr {#1}%
1036 \fi}
1037 \def\p@swr #1{\immediate\write\drawfile {#1}}
1038
1039 % ===== Open/Close a PostScript file
1040 % Open a PostScript file, write the definitions used by TeXdraw.
1041 \xdef\p@sundef{UnDeFiNeD}
1042 \def\p@sopen {%
1043 \ifx\p@sfile\p@sundef
1044 \p@sopenI
1045 \fi
1046 }
1047 % The code has a hook to avoid generating the PS file under certain
1048 % circumstances. The amsmath package sometimes sets an expression twice,
1049 % once to measure it and again to actually typeset it. In the first case,
1050 % \ifmeasuring@ is set to true. For that setting, the PS file is not
1051 % generated.
1052 \def\p@sopenI {%
1053 \ifx\ifmeasuring@\iftrue \else % \ifmeasuring@ undefined or false
1054 \global\advance \t@xdnum by 1
1055 \ifnum \t@xdnum<10
1056 \xdef \p@sfile{\jobname.ps\the\t@xdnum}%
1057 \else
1058 \xdef \p@sfile{\jobname.p\the\t@xdnum}%
1059 \fi
1060 \t@xdopen \p@sfile
1061 \fi
1062 }
1063
1064 \def\p@sclose {
1065 \ifx\p@sfile\p@sundef \else
1066 \t@xdclose
1067 \fi
1068 }
1069 \def\t@xdopen #1{%
1070 \immediate\openout\drawfile=#1%
1071 \p@swr {\p@b PS-Adobe-3.0 EPSF-3.0}%
1072 \p@swr {\p@p BoundingBox: (atend)}%
1073 \p@swr {\p@p Title: TeXdraw drawing: #1}%
1074 \p@swr {\p@p Pages: 1}%
1075 \p@swr {\p@p Creator: \TeXdrawId}%
1076 \p@swr {\p@p CreationDate: \the\year/\the\month/\the\day}%
1077 \p@swr {50 dict begin}%
1078 \p@swr {/mv {stroke moveto} def}%
1079 \p@swr {/lv {lineto} def}%
1080 \p@swr {/st {currentpoint stroke moveto} def}%
1081 \p@swr {/sl {st setlinewidth} def}%
1082 \p@swr {/sd {st 0 setdash} def}%
1083 \p@swr {/sg {st setgray} def}%
1084 \p@swr {/bs {gsave} def /es {stroke grestore} def}%
1085 \p@swr {/fl \l@br gsave setgray fill grestore}%
1086 \p@swr { currentpoint newpath moveto\r@br\space def}%
1087 \p@swr {/fp {gsave setgray fill grestore st} def}%
1088 \p@swr {/cv {curveto} def}%
1089 \p@swr {/cr \l@br gsave currentpoint newpath 3 -1 roll 0 360 arc}%
1090 \p@swr { stroke grestore\r@br\space def}%
1091 \p@swr {/fc \l@br gsave setgray currentpoint newpath}%
1092 \p@swr { 3 -1 roll 0 360 arc fill grestore\r@br\space def}%
1093 \p@swr {/ar {gsave currentpoint newpath 5 2 roll arc stroke grestore} def}%
1094 \p@swr {/el \l@br gsave /svm matrix currentmatrix def}%
1095 \p@swr { currentpoint translate scale newpath 0 0 1 0 360 arc}%
1096 \p@swr { svm setmatrix stroke grestore\r@br\space def}%
1097 \p@swr {/fe \l@br gsave setgray currentpoint translate scale newpath}%
1098 \p@swr { 0 0 1 0 360 arc fill grestore\r@br\space def}%
1099 \p@swr {/av \l@br /hhwid exch 2 div def /hlen exch def}%
1100 \p@swr { /ah exch def /tipy exch def /tipx exch def}%
1101 \p@swr { currentpoint /taily exch def /tailx exch def}%
1102 \p@swr { /dx tipx tailx sub def /dy tipy taily sub def}%
1103 \p@swr { /alen dx dx mul dy dy mul add sqrt def}%
1104 \p@swr { /blen alen hlen sub def}%
1105 \p@swr { gsave tailx taily translate dy dx atan rotate}%
1106 \p@swr { (V) ah ne {blen 0 gt {blen 0 lineto} if} {alen 0 lineto} ifelse}%
1107 \p@swr { stroke blen hhwid neg moveto alen 0 lineto blen hhwid lineto}%
1108 \p@swr { (T) ah eq {closepath} if}%
1109 \p@swr { (W) ah eq {gsave 1 setgray fill grestore closepath} if}%
1110 \p@swr { (F) ah eq {fill} {stroke} ifelse}%
1111 \p@swr { grestore tipx tipy moveto\r@br\space def}%
1112 \p@swr {\p@sfactor\space \p@sfactor\space scale}%
1113 \p@swr {1 setlinecap 1 setlinejoin}%
1114 \p@swr {3 setlinewidth [] 0 setdash}%
1115 \p@swr {0 0 moveto}%
1116 }
1117
1118 % Notes:
1119 % - mv (move to) This command includes a stroke before the moveto. The
1120 % stroke terminates a path and the move begins another path.
1121 % - bs (begin segment) encloses a segment in a gsave/grestore to keep
1122 % changes to line parameters local.
1123 % - es (end segment) does a "stroke grestore" to make sure lines inside
1124 % the segment use the line parameters local to that segment
1125 % - ar (arc) The path is generated and stroked inside a gsave/grestore,
1126 % leaving the current path intact.
1127 % - cr (circle) The path is generated and stroked inside a gsave/grestore,
1128 % leaving the current path intact.
1129 % - fc (filled circle) The path is generated and filled inside a gsave/
1130 % grestore, keeping the fill level local to the circle. The current
1131 % path is left intact.
1132 % - el (ellipse) The path is generated and stroked inside a gsave/grestore,
1133 % leaving the current path intact. The elliptical path is defined
1134 % with different x and y scaling, then stroked with default scaling
1135 % to give a constant line thickness.
1136 % - fe (filled ellipse) The path is generated and filled inside a gsave/
1137 % grestore, leaving the current path intact.
1138 % - fl (fill) The current path is closed and filled inside a gsave/restore,
1139 % keeping the fill level local. A newpath terminates the path.
1140 % - fp (fill path) The current path is closed and then filled inside a
1141 % gsave/grestore. Finally the closed path is stroked, implicitly
1142 % terminating the path.
1143 % - av (arrow vector) The arrow vector is drawn inside a gsave/grestore.
1144 % The line width and type are those currently in effect. After the
1145 % grestore, the current path is continued with a move to the tip of
1146 % the vector.
1147
1148 % ===== Close the PostScript file
1149 % Write a trailer with the BoundingBox, close the file. Note that the
1150 % BoundingBox may be larger than the commands in the PostScript file
1151 % indicate. This is due to the fact that multiple move commands in
1152 % a row are collapsed into a single move. The BoundingBox information
1153 % includes the effect of the moves which were expunged.
1154 \def\t@xdclose {%
1155 \bgroup
1156 \p@swr {stroke end showpage}%
1157 \p@swr {\p@p Trailer:}%
1158 \pixtobp \xminpix \l@lxbp \pixtobp \yminpix \l@lybp
1159 \pixtobp \xmaxpix \u@rxbp \pixtobp \ymaxpix \u@rybp
1160 \p@swr {\p@p BoundingBox: \l@lxbp\space \l@lybp\space
1161 \u@rxbp\space \u@rybp}%
1162 \p@swr {\p@p EOF}%
1163 \egroup
1164 \immediate\closeout\drawfile
1165 }
1166
1167 % ===============================================================
1168 \catcode`\@=\catamp