Debian Codegraph @

texmf-dist/tex/latex/pictex2/pictex2.sty

raw
1 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2 % pictex2.sty -- extension to PiCTeX
3 %
4 % William Park <[email protected]>
5 % Dec 1997, Aug 1998, May 1999
6 %
7 %
8 % Introduction:
9 % -------------
10 %
11 % PiCTeX's \putrule requires you to calculate the absolute coordinates,
12 % and connects between only 2 points at a time. I found this very
13 % inconvenient to calculate the coordinates repeatedly for something
14 % like
15 % \putrule from x0 y0 to x1 y1
16 % \putrule from x1 y1 to x2 y2
17 % ...
18 % \putrule from .. .. to xn yn
19 % but I didn't want to use
20 % \setlinear
21 % \plot x0 y0 x1 y1 x2 y2 ... xn yn /
22 % because it consumes too much memory, using dots where rules can be
23 % used. Also, I wanted to draw boxes, circles, and other LaTeX and
24 % PiCTeX figures at the current position whose coordinate can be pain to
25 % calculate manually.
26 %
27 % This file defines 2 user commands:
28 % \putanyline, \setanyline
29 % Everything else is internal macros.
30 %
31 %
32 % Extension 1: \putanyline
33 % -------------------------
34 %
35 % Therefore, I wrote \putanyline which connects points using \putrule
36 % (rules) or \plot (dots) depending whether the line segment is
37 % horizontal, vertical, or sloped. It automatically calculates the
38 % current position, so that you can use relative coordinate when
39 % specifying the next point to go to. Furthermore, you can insert
40 % boxes, circles, and vectors at the current position. In effect,
41 % \putanyline allows you to draw without "lifting pen from paper".
42 %
43 % Its usage is
44 % \putanyline from x y <command> <arguments> <command> <arguments> ... /
45 % where command/arguments are any permutation of
46 % from x y -- starting point
47 % to x y -- draw line to (x,y), using \plot if necessary
48 % slope dx dy -- draw line to (dx,dy), using \plot if necessary
49 % jump dx dy -- jump by <dx,dy> without drawing
50 % right s -- draw horizontal rule to right by s unit
51 % left s -- draw horizontal rule to left by s unit
52 % up s -- draw vertical rule up by s unit
53 % down s -- draw vertical rule down by s unit
54 % x a -- draw horizontal rule to x=a
55 % y b -- draw vertical rule to y=b
56 % RIGHT s -- draw horizontal LaTeX vector to right by s unit
57 % LEFT s -- draw horizontal LaTeX vector to left by s unit
58 % UP s -- draw vertical LaTeX vector up by s unit
59 % DOWN s -- draw vertical LaTeX vector down by s unit
60 % X a -- draw horizontal LaTeX vector to x=a
61 % Y b -- draw vertical LaTeX vector to y=b
62 % box width height -- put corner of box at current point
63 % circle dia -- put center of circle at current point
64 % arc dx dy deg -- draw arc from (dx,dy) about current point
65 % BOX (x,y) [Blrbt] -- put LaTeX \framebox(x,y){} with [] orientation
66 % CIRCLE dia -- put LaTeX \circle{d} at current point
67 % VECTOR (x,y) s -- put LaTeX \vector(x,y){s} at current point
68 % SLOPE (x,y) s -- put LaTeX \line(x,y){s} at current point
69 %
70 % For example, the repeated \putrule above can be replaced by
71 % \putanyline from x0 y0 to x1 y1 to x2 y2 ... to xn yn /
72 % But, if it will be using horizontal or vertical rules anyway, it is
73 % more convenient to use relative coordinate and write
74 % \putanyline from x0 y0 right a up b left c down d ... /
75 % where each direction implies starting from current position which is
76 % calculated and updated automatically. However, the following commands
77 % box, circle, arc, BOX, CIRCLE
78 % do not update the current position, since there is no clear "end"
79 % point to go to.
80 %
81 % When using LaTeX objects, PiCTeX's horizontal and vertical scales
82 % should be same as LaTeX's \unitlength. I usually do something like
83 % \usepackage{pictex2}
84 % ...
85 % $$\beginpicture \unitlength=1cm
86 % \setcoordinatesystem units <\unitlength,\unitlength>
87 % ...
88 % \endpicture$$
89 %
90 %
91 % Extension 2: \setanyline
92 % -------------------------
93 %
94 % I also wrote \setanyline mode for \plot to use rules if a line segment
95 % is horizontal or vertical. Its usage is similar to \setlinear,
96 % \setanyline
97 % \plot x0 y0 x1 y1 x2 y2 ... xn yn /
98 % With this command, the points must be specified using absolute
99 % coordinate as usual; you cannot use relative coordinates.
100 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
101
102
103 \NeedsTeXFormat{LaTeX2e}
104 \ProvidesPackage{pictex2} % this package
105 \RequirePackage{pictex} % standard part of teTeX
106
107 \catcode`!=11
108 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
109 % \putanyline from x y to x y slope dx dy jump dx dy
110 % right s left s up s down s x a y a
111 % RIGHT s LEFT s UP s DOWN s X a Y b
112 % box w h circle d arc dx dy deg
113 % BOX (x,y) [Blrtb] CIRCLE d VECTOR (x,y) s SLOPE (x,y) s
114 % /
115 %
116 \def\putanyline{\!putanyline}% changed from \multiput
117 \def\!putanyline{\futurelet\!nextchar\!!putanyline}
118 \def\!!putanyline{%
119 \if f\!nextchar \def\!!!putanyline{\!putanylinefrom}%
120 \else \if t\!nextchar \def\!!!putanyline{\!putanylineto}%
121 \else \if s\!nextchar \def\!!!putanyline{\!putanylineslope}%
122 \else \if j\!nextchar \def\!!!putanyline{\!putanylinejump}%
123 %
124 \else \if r\!nextchar \def\!!!putanyline{\!putanylineright}%
125 \else \if l\!nextchar \def\!!!putanyline{\!putanylineleft}%
126 \else \if u\!nextchar \def\!!!putanyline{\!putanylineup}%
127 \else \if d\!nextchar \def\!!!putanyline{\!putanylinedown}%
128 \else \if x\!nextchar \def\!!!putanyline{\!putanylinex}%
129 \else \if y\!nextchar \def\!!!putanyline{\!putanyliney}%
130 %
131 \else \if R\!nextchar \def\!!!putanyline{\!putanylineRIGHT}%
132 \else \if L\!nextchar \def\!!!putanyline{\!putanylineLEFT}%
133 \else \if U\!nextchar \def\!!!putanyline{\!putanylineUP}%
134 \else \if D\!nextchar \def\!!!putanyline{\!putanylineDOWN}%
135 \else \if X\!nextchar \def\!!!putanyline{\!putanylineX}%
136 \else \if Y\!nextchar \def\!!!putanyline{\!putanylineY}%
137 %
138 \else \if b\!nextchar \def\!!!putanyline{\!putanylinebox}%
139 \else \if c\!nextchar \def\!!!putanyline{\!putanylinecircle}%
140 \else \if a\!nextchar \def\!!!putanyline{\!putanylinearc}%
141 %
142 \else \if B\!nextchar \def\!!!putanyline{\!putanylineBOX}%
143 \else \if C\!nextchar \def\!!!putanyline{\!putanylineCIRCLE}%
144 \else \if V\!nextchar \def\!!!putanyline{\!putanylineVECTOR}%
145 \else \if S\!nextchar \def\!!!putanyline{\!putanylineSLOPE}%
146 %
147 \fi \fi \fi \fi
148 \fi \fi \fi \fi \fi \fi
149 \fi \fi \fi \fi \fi \fi
150 \fi \fi \fi
151 \fi \fi \fi \fi
152 \!!!putanyline}
153
154 % from x y -- starting point
155 % to x y -- draw line to (x,y), using \plot if necessary
156 % slope dx dy -- draw line to (dx,dy), using \plot if necessary
157 % jump dx dy -- jump by <dx,dy> without drawing
158 %
159 \def\!putanylinefrom from #1 #2 {%
160 \!xS=\!M{#1}\!xunit
161 \!yS=\!M{#2}\!yunit
162 \!ifnextchar/{\!finish}{\!putanyline}}
163 \def\!putanylineto to #1 #2 {%
164 \!xE=\!M{#1}\!xunit
165 \!yE=\!M{#2}\!yunit
166 \!drawputanyline}
167 \def\!putanylineslope slope #1 #2 {%
168 \!xE=\!xS \!xdiff=\!M{#1}\!xunit \advance\!xE by \!xdiff
169 \!yE=\!yS \!ydiff=\!M{#2}\!yunit \advance\!yE by \!ydiff
170 \!drawputanyline}
171 \def\!putanylinejump jump #1 #2 {%
172 \!xdiff=\!M{#1}\!xunit \advance\!xS by \!xdiff
173 \!ydiff=\!M{#2}\!yunit \advance\!yS by \!ydiff
174 \!ifnextchar/{\!finish}{\!putanyline}}
175
176 \def\!drawputanyline{%
177 \!xM=\!xE
178 \!yM=\!yE
179 \!xdiff=\!xE \advance\!xdiff by -\!xS
180 \!ydiff=\!yE \advance\!ydiff by -\!yS
181 \ifdim \!xdiff=\!zpt% vertical rule
182 \ifdim \!ydiff<\!zpt% adjusted for line thickness
183 \!ydiff=-0.5\linethickness
184 \else
185 \!ydiff=0.5\linethickness
186 \fi
187 \advance\!yE by \!ydiff
188 \advance\!yS by -\!ydiff
189 \setdimensionmode
190 \putrule from {\!xS} {\!yS} to {\!xE} {\!yE}
191 \setcoordinatemode
192 \else \ifdim \!ydiff=\!zpt% horizontal rule
193 \ifdim \!xdiff<\!zpt% adjusted for line thickness
194 \!xdiff=-0.5\linethickness
195 \else
196 \!xdiff=0.5\linethickness
197 \fi
198 \advance\!xE by \!xdiff
199 \advance\!xS by -\!xdiff
200 \setdimensionmode
201 \putrule from {\!xS} {\!yS} to {\!xE} {\!yE}
202 \setcoordinatemode
203 \else% line using \plot
204 {\setdimensionmode
205 \setlinear
206 \plot {\!xS} {\!yS} {\!xE} {\!yE} /
207 \setcoordinatemode}%
208 \fi \fi
209 \!xS=\!xM
210 \!yS=\!yM
211 \!ifnextchar/{\!finish}{\!putanyline}}
212
213 % right s -- draw horizontal rule to right by s unit
214 % left s -- draw horizontal rule to left by s unit
215 % up s -- draw vertical rule up by s unit
216 % down s -- draw vertical rule down by s unit
217 % x a -- draw horizontal rule to x=a
218 % y b -- draw vertical rule to y=b
219 %
220 \def\!putanylineright right #1 {%
221 \!xE=\!xS \!xdiff=\!M{#1}\!xunit \advance\!xE by \!xdiff
222 \!yE=\!yS
223 \!drawputanyline}
224 \def\!putanylineleft left #1 {%
225 \!xE=\!xS \!xdiff=\!M{#1}\!xunit \advance\!xE by -\!xdiff
226 \!yE=\!yS
227 \!drawputanyline}
228 \def\!putanylineup up #1 {%
229 \!xE=\!xS
230 \!yE=\!yS \!ydiff=\!M{#1}\!yunit \advance\!yE by \!ydiff
231 \!drawputanyline}
232 \def\!putanylinedown down #1 {%
233 \!xE=\!xS
234 \!yE=\!yS \!ydiff=\!M{#1}\!yunit \advance\!yE by -\!ydiff
235 \!drawputanyline}
236 \def\!putanylinex x #1 {%
237 \!xE=\!M{#1}\!xunit
238 \!yE=\!yS
239 \!drawputanyline}
240 \def\!putanyliney y #1 {%
241 \!xE=\!xS
242 \!yE=\!M{#1}\!yunit
243 \!drawputanyline}
244
245 % RIGHT s -- draw horizontal LaTeX vector to right by s unit
246 % LEFT s -- draw horizontal LaTeX vector to left by s unit
247 % UP s -- draw vertical LaTeX vector up by s unit
248 % DOWN s -- draw vertical LaTeX vector down by s unit
249 % X a -- draw horizontal LaTeX vector to x=a
250 % Y b -- draw vertical LaTeX vector to y=b
251 %
252 \def\!putanylineRIGHT RIGHT #1 {%
253 \setdimensionmode
254 \put {\vector(1,0){#1}} [Bl] at {\!xS} {\!yS}
255 \setcoordinatemode
256 \!xdiff=\!M{#1}\!xunit \advance\!xS by \!xdiff
257 \!ifnextchar/{\!finish}{\!putanyline}}
258 \def\!putanylineLEFT LEFT #1 {%
259 \setdimensionmode
260 \put {\vector(-1,0){#1}} [Bl] at {\!xS} {\!yS}
261 \setcoordinatemode
262 \!xdiff=\!M{#1}\!xunit \advance\!xS by -\!xdiff
263 \!ifnextchar/{\!finish}{\!putanyline}}
264 \def\!putanylineUP UP #1 {%
265 \setdimensionmode
266 \put {\vector(0,1){#1}} [Bl] at {\!xS} {\!yS}
267 \setcoordinatemode
268 \!ydiff=\!M{#1}\!yunit \advance\!yS by \!ydiff
269 \!ifnextchar/{\!finish}{\!putanyline}}
270 \def\!putanylineDOWN DOWN #1 {%
271 \setdimensionmode
272 \put {\vector(0,-1){#1}} [Bl] at {\!xS} {\!yS}
273 \setcoordinatemode
274 \!ydiff=\!M{#1}\!yunit \advance\!yS by -\!ydiff
275 \!ifnextchar/{\!finish}{\!putanyline}}
276 \def\!putanylineX X #1 {%
277 \!xdiff=\!M{#1}\!xunit
278 \advance\!xdiff by -\!xS
279 \Divide <\!xdiff> by <\unitlength> forming <\!xE>
280 \placevalueinpts of <\!xE> in {\!putanylinescale}
281 \setdimensionmode
282 \ifdim \!xdiff<\!zpt
283 \put {\vector(-1,0){-\!putanylinescale}} [Bl] at {\!xS} {\!yS}
284 \else
285 \put {\vector(1,0){\!putanylinescale}} [Bl] at {\!xS} {\!yS}
286 \fi
287 \setcoordinatemode
288 \advance\!xS by \!xdiff
289 \!ifnextchar/{\!finish}{\!putanyline}}
290 \def\!putanylineY Y #1 {%
291 \!ydiff=\!M{#1}\!yunit
292 \advance\!ydiff by -\!yS
293 \Divide <\!ydiff> by <\unitlength> forming <\!yE>
294 \placevalueinpts of <\!yE> in {\!putanylinescale}
295 \setdimensionmode
296 \ifdim \!ydiff<\!zpt
297 \put {\vector(0,-1){-\!putanylinescale}} [Bl] at {\!xS} {\!yS}
298 \else
299 \put {\vector(0,1){\!putanylinescale}} [Bl] at {\!xS} {\!yS}
300 \fi
301 \setcoordinatemode
302 \advance\!yS by \!ydiff
303 \!ifnextchar/{\!finish}{\!putanyline}}
304
305 % box width height -- put corner of box at current point
306 % circle dia -- put center of circle at current point
307 % arc dx dy deg -- draw arc from <dx,dy> about current point
308 %
309 \def\!putanylinebox box #1 #2 {%
310 \!xE=\!xS \!xdiff=\!M{#1}\!xunit \advance\!xE by \!xdiff
311 \!yE=\!yS \!ydiff=\!M{#2}\!yunit \advance\!yE by \!ydiff
312 \setdimensionmode
313 \putrectangle corners at {\!xS} {\!yS} and {\!xE} {\!yE}
314 \setcoordinatemode
315 \!ifnextchar/{\!finish}{\!putanyline}}
316 \def\!putanylinecircle circle #1 {%
317 \!xE=\!xS \!xdiff=\!M{#1}\!xunit \advance\!xE by 0.5\!xdiff
318 \!yE=\!yS
319 {\setdimensionmode
320 \circulararc 360 degrees from {\!xE} {\!yE} center at {\!xS} {\!yS}
321 \setcoordinatemode}%
322 \!ifnextchar/{\!finish}{\!putanyline}}
323 \def\!putanylinearc arc #1 #2 #3 {%
324 \!xE=\!xS \!xdiff=\!M{#1}\!xunit \advance\!xE by \!xdiff
325 \!yE=\!yS \!ydiff=\!M{#2}\!yunit \advance\!yE by \!ydiff
326 {\setdimensionmode
327 \circulararc {#3} degrees from {\!xE} {\!yE} center at {\!xS} {\!yS}
328 \setcoordinatemode}%
329 \!ifnextchar/{\!finish}{\!putanyline}}
330
331 % BOX (x,y) [Blrbt] -- put LaTeX \framebox(x,y){} with [] orientation
332 % CIRCLE dia -- put LaTeX \circle{d} at current point
333 % VECTOR (x,y) s -- put LaTeX \vector(x,y){s} at current point
334 % SLOPE (x,y) s -- put LaTeX \line(x,y){s} at current point
335 %
336 \def\!putanylineBOX BOX (#1,#2) [#3] {%
337 \setdimensionmode
338 \put {\begin{picture}(#1,#2)
339 \put(0,0){\framebox(#1,#2){}}
340 \end{picture}} [#3] at {\!xS} {\!yS}
341 \setcoordinatemode
342 \!ifnextchar/{\!finish}{\!plotrule}}
343 \def\!putanylineCIRCLE CIRCLE #1 {%
344 \setdimensionmode
345 \put {\circle{#1}} [Bl] at {\!xS} {\!yS}
346 \setcoordinatemode
347 \!ifnextchar/{\!finish}{\!putanyline}}
348 \def\!putanylineVECTOR VECTOR (#1,#2) #3 {%
349 \setdimensionmode
350 \put {\vector(#1,#2){#3}} [Bl] at {\!xS} {\!yS}
351 \setcoordinatemode
352 \!xE=#1\unitlength
353 \!yE=#2\unitlength
354 \ifdim \!xE=\!zpt% vertical
355 \!xdiff=\!zpt
356 \!ydiff=#3\unitlength
357 \ifdim \!yE<\!zpt
358 \!ydiff=-\!ydiff
359 \fi
360 \else
361 \!xdiff=#3\unitlength
362 \ifdim \!xE<\!zpt
363 \!xdiff=-\!xdiff
364 \fi
365 \Divide <\!yE> by <\!xE> forming <\!ydiff>
366 \placevalueinpts of <\!ydiff> in {\!putanylinescale}
367 \!ydiff=\!putanylinescale\!xdiff
368 \fi
369 \advance\!xS by \!xdiff
370 \advance\!yS by \!ydiff
371 \!ifnextchar/{\!finish}{\!putanyline}}
372 \def\!putanylineSLOPE SLOPE (#1,#2) #3 {%
373 \setdimensionmode
374 \put {\line(#1,#2){#3}} [Bl] at {\!xS} {\!yS}
375 \setcoordinatemode
376 \!xE=#1\unitlength
377 \!yE=#2\unitlength
378 \ifdim \!xE=\!zpt% vertical
379 \!xdiff=\!zpt
380 \!ydiff=#3\unitlength
381 \ifdim \!yE<\!zpt
382 \!ydiff=-\!ydiff
383 \fi
384 \else
385 \!xdiff=#3\unitlength
386 \ifdim \!xE<\!zpt
387 \!xdiff=-\!xdiff
388 \fi
389 \Divide <\!yE> by <\!xE> forming <\!ydiff>
390 \placevalueinpts of <\!ydiff> in {\!putanylinescale}
391 \!ydiff=\!putanylinescale\!xdiff
392 \fi
393 \advance\!xS by \!xdiff
394 \advance\!yS by \!ydiff
395 \!ifnextchar/{\!finish}{\!putanyline}}
396
397
398 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
399 % \setanyline
400 % \plot x0 y0 x1 y1 x2 y2 ... /
401 %
402 \def\setanyline{% changed from \setlinear
403 \let\!drawcurve=\!lcurverule
404 \let\!!Shade=\!!lShade
405 \let\!!!Shade=\!!!lShade}
406
407 \def\!lcurverule #1 #2 {% changed from \!lcurve
408 \!start (#1,#2)
409 \!Ljoinrule}
410
411 \def\!Ljoinrule #1 #2 {% changed from \!Ljoin
412 \!ljoinrule (#1,#2)
413 \!ifnextchar/{\!finish}{\!Ljoinrule}}
414
415 \def\!ljoinrule (#1,#2){% changed from \!ljoin
416 \advance\!intervalno by 1
417 \!xE=\!M{#1}\!xunit
418 \!yE=\!M{#2}\!yunit
419 \!rotateaboutpivot\!xE\!yE
420 \!xdiff=\!xE \advance \!xdiff by -\!xS
421 \!ydiff=\!yE \advance \!ydiff by -\!yS
422 \!Pythag\!xdiff\!ydiff\!arclength% ** arclength = sqrt(xdiff**2+ydiff**2)
423 \global\advance \totalarclength by \!arclength%
424 \ifdim \!xdiff=\!zpt% vertical rule
425 \!xM=\!xE
426 \!yM=\!yE
427 \ifdim \!ydiff<\!zpt% adjusted for line thickness
428 \!ydiff=-0.5\linethickness
429 \else
430 \!ydiff=0.5\linethickness
431 \fi
432 \advance\!yE by \!ydiff
433 \advance\!yS by -\!ydiff
434 \setdimensionmode
435 \putrule from {\!xS} {\!yS} to {\!xE} {\!yE}
436 \setcoordinatemode
437 \!xS=\!xM
438 \!yS=\!yM
439 \else \ifdim \!ydiff=\!zpt% horizontal rule
440 \!xM=\!xE
441 \!yM=\!yE
442 \ifdim \!xdiff<\!zpt% adjusted for line thickness
443 \!xdiff=-0.5\linethickness
444 \else
445 \!xdiff=0.5\linethickness
446 \fi
447 \advance\!xE by \!xdiff
448 \advance\!xS by -\!xdiff
449 \setdimensionmode
450 \putrule from {\!xS} {\!yS} to {\!xE} {\!yE}
451 \setcoordinatemode
452 \!xS=\!xM
453 \!yS=\!yM
454 \else
455 \!drawlinearsegment% set by dashpat to \!linearsolid or \!lineardashed
456 \!xS=\!xE
457 \!yS=\!yE
458 \fi \fi
459 \ignorespaces}
460
461 \catcode`!=12
462
463 % End of pictex2.sty