summaryrefslogtreecommitdiff
path: root/graphics/texdraw/manual/texdraw.texi
blob: 9cacbc735005113fcc27b04a9dd7a0de97dfc081 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
% -*-texinfo-*-

%  $Id: texdraw.texi 2.11 2019/04/18 TeXdraw-v2r3 $

% To produce a TeX version of this manual, you must have the following
% files accessible to TeX.
%   texdraw.texi  - this file, the TeXdraw manual, part of the TeXdraw
%                   distribution
%   texdraw.tex   - the TeXdraw macros, part of the TeXdraw distribution
%   txdtools.tex  - extra macros for TeXdraw, part of the TeXdraw
%                   distribution
%   texinfo.tex   - texinfo manual macros (distributed by FSF, for instance
%                   with the GNUemacs editor).  This version of the manual has
%                   been tested with version 2.145 of texinfo.tex.  The file
%                   texinfo.tex is available by anonymous ftp as
%                   pub/gnu/texinfo-3.6.tar.Z on prep.ai.mit.edu.
%
\input texdraw    % bring in TeXdraw before texinfo changes "\" to "@"
\input txdtools

\input texinfo    @c -*-texinfo-*-
@comment %**start of header
@setfilename texdraw.info
@settitle @TeX{}draw
@comment %**end of header

@copying
This manual (edition 2.3) documents @TeX{}draw, a system for
producing PostScript drawings from @TeX{}.

Copyright @copyright{} 1993--2019 Peter Kabal

This work is licensed under the Creative Commons Attribution (CC-BY)
License, any version. To view the licenses, visit
@w{@url{creativecommons.org/licenses/by}} or send a letter to
Creative Commons, PO Box 1866, Mountain View, CA 94042, USA.
@end copying

@dircategory TeX
@direntry
* TeXdraw: (texdraw).           Drawing PostScript diagrams within TeX.
@end direntry


@titlepage
@title @TeX{}draw
@subtitle PostScript Drawings from @TeX{}
@subtitle Edition 2.3
@subtitle April 2019
@author Peter Kabal

@page
@vskip 0pt plus 1filll
@insertcopying

Peter Kabal @*
Department of Electrical @& Computer Engineering @*
McGill University @*

@code{peter dot kabal at mcgill dot ca} @*
@code{http://www-mmsp.ece.mcgill.ca/MMSP/Documents/Software/}
@end titlepage

@contents

@ifnottex
@node Top, Introduction, (dir), (dir)
@top TeXdraw

@TeX{}draw is a collection of macros that allow drawings to be created
from @emph{within} @TeX{}.

This is edition 2.3 of the @TeX{}draw documentation.
@end ifnottex

@menu
* Introduction::
* TeXdraw Commands::
* Drawing Segments and Scaling::
* Using TeXdraw with LaTeX::
* More Details::
* PostScript Commands::
* TeXdraw Toolbox::
* Examples::
* Command Listing::

Indices
* Concept Index::
* Command Index::

 --- The Detailed Node Listing ---

Introduction

* Distribution::

TeXdraw Commands

* Accessing TeXdraw::
* Command syntax::
* TeXdraw coordinates::
* Coordinate specification::
* Line vectors::
* TeX text::
* Circles and arcs::
* Bezier curves::
* Fill commands::

Drawing Segments and Scaling

* Drawing segments::
* Drawing paths::
* Saving positions::
* Scaling coordinates::
* Drawing size::
* Initial current position::

Using TeXdraw with LaTeX

* PostScript printer drivers::

More Details

* Errors while using TeXdraw::
* Extending TeXdraw::
* How TeXdraw merges graphics and text::

Extending TeXdraw

* Scaling::
* Resolution::
* Text placement::
* Intermediate PostScript file::

PostScript Commands

TeXdraw Toolbox

* Coordinate parsing::
* Real arithmetic::
* Arrow curve::

Examples

* Block diagram::
* Filter response graph::
* Geometric construction::

Command Listing

Command Index

Concept Index
@end menu


@node Introduction, TeXdraw Commands, Top, Top
@chapter Introduction

@TeX{} is a powerful typesetting program which allows for complex text
layouts but by itself lacks a general graphics capability.  However,
when coupled with an appropriate printer driver program, external
graphics files can be inserted into the printed document.  In this mode,
@TeX{} is instructed to leave space for a drawing.  The drawing is
inserted by the printer driver program.  The @TeX{}draw macros described
here generate the external graphics file from within @TeX{} and generate
the instructions to the the print driver program to position the
graphics at the appropriate position on the page.

@TeX{}draw consists of a set of @TeX{} macros that create line drawings
and other figures.  The drawing primitives include solid lines,
patterned lines, Bezier curves, circles and arrows.  Other commands
allow for the filling of a region with a gray level.  The drawing
commands generate PostScript code.  This limits @TeX{}draw to systems
which use PostScript printers.  @TeX{}draw also provides commands to
position @TeX{} text, including mathematics, on the drawing.  The final
drawing, with text and graphics, can be positioned on the page like any
other @TeX{} box.

@cindex @code{dvips} printer driver
@cindex La@TeX{}
@cindex @code{graphics} package
The basic @TeX{}draw macros for @TeX{} use the @code{\special} syntax
recognized by the printer driver program @code{dvips}.  However, when
invoked as a La@TeX{}2e package, the @TeX{}draw macros can be used with
any of the PostScript printer driver programs supported by the standard
@code{graphics} package for La@TeX{}2e.

The basic @TeX{}draw macros provide only simple drawing commands.
However, @TeX{}draw provides a drawing segment environment which allows
parameter changes and coordinate scaling changes to be kept local to the
drawing segment.  This facility, together with @TeX{}'s macro
capabilities allows one to modularize drawing units and extend
@TeX{}draw by building more complex graphics entities from simpler
elements.

@menu
* Distribution::
@end menu

@node Distribution, , , Introduction
@section Distribution information
@cindex distribution

The entire @TeX{}draw package, both code and documentation, is
released under Creative Commons Attribution (CC-BY) license, any
version.


@node TeXdraw Commands, Drawing Segments and Scaling, Introduction, Top
@chapter Using the @TeX{}draw Commands

The main @TeX{}draw macros (commands) are defined in the file
@file{texdraw.tex}.  These macros may be used directly in @TeX{}.  The
file @file{texdraw.sty} provides an interface for use with La@TeX{}2e.
The following sections describe the basic commands for @TeX{}draw.

@menu
* Accessing TeXdraw::
* Command syntax::
* TeXdraw coordinates::
* Coordinate specification::
* Line vectors::
* TeX text::
* Circles and arcs::
* Bezier curves::
* Fill commands::
@end menu

@node Accessing TeXdraw, Command syntax, , TeXdraw Commands
@section Accessing @TeX{}draw
@cindex accessing @TeX{}draw
@cindex invoking @TeX{}draw

@cindex plain @TeX{}
@cindex La@TeX{}
The form of the user command to run the @TeX{} program depends on which
version of @TeX{} is being used, and which other macro packages are
preloaded as format files.  Typically, installations have at least two
versions of @TeX{} --- plain @TeX{} which includes basic typesetting
macros (usually invoked as @file{tex}) and La@TeX{}2e which includes the
La@TeX{}2e typesetting macros (usually invoked as @file{latex}).  An
older version of La@TeX{}, version 2.09, may also be available.  The
@TeX{}draw macros can be used with plain @TeX{} and with either version
of La@TeX{}.

For use with plain @TeX{}, the user must read in the @TeX{}draw macros
from the file @file{texdraw.tex}.
@example
@group
\input texdraw            % Read in the TeXdraw macros
 ...
\btexdraw
  ...                     % TeXdraw commands to generate a drawing
\etexdraw
@end group
@end example

For use with La@TeX{} version 2.09, the user reads in the @TeX{}draw
macros from the file @file{texdraw.tex} and optionally defines the
@code{\begin@{texdraw@}} / @code{\end@{texdraw@}} environment.
@example
@group
\documentstyle[11pt]@{article@}  % Article style at 11pt size
...
\input texdraw            % Read in the TeXdraw macros
\newenvironment@{texdraw@}@{\leavevmode\btexdraw@}@{\etexdraw@}
 ...
\begin@{texdraw@}
  ...                     % TeXdraw commands to generate a drawing
\end@{texdraw@}
...
\end@{document@}
@end group
@end example

@cindex @code{texdraw} package
@cindex @code{graphics} package
For use with La@TeX{}2e, the user must load the @code{texdraw} package
(file @file{texdraw.sty}).  This package file defines the
@code{\begin@{texdraw@}} / @code{\end@{texdraw@}} environment, brings in
the standard @code{graphics} package and reads in the file
@file{texdraw.tex} containing the definitions of the @TeX{}draw macros.
@example
@group
\documentclass[11pt]@{article@}  % Article class at 11pt size
\usepackage@{texdraw@}           % TeXdraw commands

\begin@{document@}
 ...
\begin@{texdraw@}
  ...                     % TeXdraw commands to generate a drawing
\end@{texdraw@}
 ...
\end@{document@}
@end group
@end example

As the @TeX{}draw commands are processed by @TeX{}, an intermediate
PostScript file is generated.  The intermediate PostScript has a name of
the form @file{@var{name}.ps1}.  The name part is derived from the name
of the main @TeX{} file being processed.  If more than one drawing is
produced, the digit in the file name extension is
incremented.@footnote{After the ninth PostScript file, the name of the
intermediate PostScript file takes the form @file{@var{name}.p10}, with
the number increasing from 10 with each file.}

The @TeX{}draw commands to produce a drawing are inserted between
@code{\btexdraw} and @code{\etexdraw} commands, or for La@TeX{}, between
@code{\begin@{texdraw@}} and @code{\end@{texdraw@}} commands.  This
results in a @TeX{} box of appropriate size containing the drawing
generated by the @TeX{}draw commands.  The @TeX{}draw box can be
positioned in a document like any other @TeX{} box.

The @code{\centertexdraw@{...@}} macro centers the box generated by
@TeX{}draw.  The vertical space taken up is equal to the vertical size
of the drawing.  The @code{\centertexdraw} macro is normally used in
vertical mode (between paragraphs).  A @code{\par} command (a blank line
will do also) before a @code{\centertexdraw} command will terminate
horizontal mode and return to vertical mode.  For La@TeX{}, a structured
equivalent to the @code{\centertexdraw@{...@}} command is shown below.
@example
@group
\begin@{center@}
\begin@{texdraw@}
  ...
\end@{texdraw@}
\end@{center@}
@end group
@end example

The @code{\everytexdraw} command can be used to define a set of
@TeX{}draw commands that will be executed at the beginning of every
@TeX{}draw drawing.  It is invoked as @code{\everytexdraw@{ ...@}},
with the desired @TeX{}draw commands as arguments.

@table @code
@findex \btexdraw
@item \btexdraw
Start a @TeX{}draw drawing.  The drawing is terminated with an
@code{\etexdraw} command.
@findex \etexdraw
@item \etexdraw
End a @TeX{}draw drawing started with a @code{\btexdraw} command.  The
resulting @TeX{}draw drawing is placed in a box with height equal to the
height of the drawing and width equal to the width of the drawing.  The
depth of the box is zero.
@findex \begin@{texdraw@}
@item \begin@{texdraw@}
Start a @TeX{}draw drawing.  The drawing is terminated with an
@code{\end@{texdraw@}} command.  This command is for use with La@TeX{}.
@findex \end@{texdraw@}
@item \end@{texdraw@}
End a @TeX{}draw drawing started with a @code{\begin@{texdraw@}}
command.  The resulting @TeX{}draw drawing is placed in a box with
height equal to the height of the drawing and width equal to the width
of the drawing.  The depth of the box is zero.  This command is for use
with La@TeX{}.
@findex \centertexdraw
@item \centertexdraw@{ ... @}
Center a @TeX{}draw box horizontally.  The argument contains @TeX{}draw
commands.  The resulting box has the horizontal size @code{\hsize} and
height equal to the height of the drawing.
@findex \everytexdraw
@item \everytexdraw@{ ... @}
Specify @TeX{}draw commands to be executed at the beginning of every
@TeX{}draw drawing.
@end table

@node Command syntax, TeXdraw coordinates, Accessing TeXdraw, TeXdraw Commands
@section Command syntax
@cindex command syntax
@cindex syntax of commands

Generally @TeX{}draw commands that take a single argument need a
terminating blank or newline after the argument.  Arguments that are
self-delimiting, such as coordinates within parentheses and text within
braces, do not need the terminating blank.  However, even when not
needed by the defining syntax of the command, blanks following command
arguments are allowed and ignored within the @TeX{}draw environment.

On entering the @TeX{}draw environment, @TeX{} is in internal vertical
mode (vertical mode inside a @code{\vbox}).  In this mode, spaces can be
placed freely between commands.  However, any other extraneous input
that generates output that is not part of the @TeX{}draw environment is
disallowed.

Blank lines are interpreted as paragraph breaks, equivalent to a
@code{\par} command.  The @TeX{}draw macro @code{\centertexdraw} is
defined with the @code{\long} attribute to allow @code{\par} commands
and blank lines to be interspersed between @TeX{}draw commands.  The
@code{\btexdraw} and @code{\etexdraw} commands also allow @code{\par}
command and blank lines to be included.

@node TeXdraw coordinates, Coordinate specification, Command syntax, TeXdraw Commands
@section @TeX{}draw coordinates
@cindex coordinates

The @TeX{}draw coordinate system has increasing @var{x} to the right and
increasing @var{y} upward.  The coordinates (without the unit) are
floating point numbers.  Integer values can be written without a decimal
point.  The size of the drawing is determined by the maximum excursions
of the coordinates specified in @TeX{}draw commands.
@tex
\bigskip
\centertexdraw{
  \avec (0 0.8) \textref h:C v:B \htext (0 0.9){\sl y}
  \move (0 0) \avec (0.8 0) \textref h:L v:C \htext(0.9 0){\sl x}
  \move (0 1.0)}
@end tex

Consider the following example of @TeX{}draw commands to draw a simple
figure.
@example
@group
\centertexdraw@{
  \drawdim cm  \linewd 0.02
  \move(2 2) \lvec(3 3) \lvec(2 4) \lvec(1 3) \lvec(2 2)
  \textref h:C v:C \htext(2 3)@{$\sum \rho_n$@}
@}
@end group
@end example
@tex
\bigskip
\centertexdraw{
  \drawdim{cm} \linewd 0.02
  \move(2 2) \lvec(3 3) \lvec(2 4) \lvec(1 3) \lvec(2 2)
  \textref h:C v:C \htext(2 3){$\sum \rho_n$}
}
@end tex
This drawing uses units of centimetres, with a line width of 0.02 cm.
The @var{x} coordinate ranges between 1 and 3 while the @var{y}
coordinate ranges between 2 and 4.  When included into a document, the
size of the drawing is 2 cm by 2 cm.  The drawing is placed in a @TeX{}
box, with the lower lefthand corner of the box corresponding to
@TeX{}draw coordinate @code{(1 2)} and the upper righthand corner at
@code{(3 4)}.  The @code{\centertexdraw} command centers the drawing
horizontally.  The @code{\textref} command controls the centering of the
text.  The text in this drawing is centered (both horizontally and
vertically) at the coordinate @code{(2 3)}.

@node Coordinate specification, Line vectors, TeXdraw coordinates, TeXdraw Commands
@section Coordinate specification
@cindex coordinate specification
@cindex position specification

Coordinates are specified within parentheses, with blanks (but no comma)
between the values.  Leading blanks and trailing blanks are permitted
within the parentheses.  The coordinates refer to units, which are
specified by the @code{\drawdim} command.  The default is inches, but
any valid @TeX{} dimension unit can be specified.  Symbolic
specification of saved coordinate values will be discused later
(@pxref{Saving positions}).

@table @code
@findex \drawdim
@item \drawdim @var{dim}
Set the units to @var{dim}.  The argument @var{dim} can be any valid
@TeX{} dimension unit.  The units are used to interpret coordinate
values.  Examples of valid units: @code{cm}, @code{mm}, @code{in},
@code{pt}, and @code{bp}.
@end table

Examples of coordinate and scaling specifications:
@table @code
@item \drawdim @{cm@} \move(2 2)
Set the units to centimetres, move to a position 2 cm to the right and 2
cm up from the origin of the drawing coordinate system.
@item \drawdim bp
Set the units to big points.
@item \lvec ( 2.2 +5.5) \lvec(2.3 -2) \lvec(2.2 5.4 )
Examples of acceptable coordinate specifications.
@end table

@node Line vectors, TeX text, Coordinate specification, TeXdraw Commands
@section Line vectors
@cindex lines
@cindex vectors
@cindex arrows
@cindex moves
@cindex current position

@TeX{}draw implements moves, line vectors and arrow vectors.  There are
both absolute and relative motion versions of these vector commands.
@TeX{}draw maintains a current position.  Lines are drawn from the
current position to a new coordinate, with the new coordinate becoming
the new current position.  An explicit move can be used to establish a
new current position.  The position @code{(0 0)} is used if there is no
move to an initial current position.

The @code{\move} and @code{\rmove} commands establish a new current
position without drawing a line.  The @code{\lvec} and @code{\rlvec}
commands draw a line from the current position to a new position, which
then becomes the new current position.  The @code{\avec} and
@code{\ravec} commands draw a line with an arrowhead from the current
position to a new coordinate, which then becomes the new current
position.  The tip of the arrow is at the new current position.  The
direction of the arrow follows the direction of the line.  Since this
direction is undefined for zero length vectors, these are not allowed
for @code{\avec} or @code{\ravec}.  Zero length arrow vectors will
generate a PostScript print error: @code{undefinedresult}.  For any
non-zero length vector, the full size arrowhead is drawn, even if that
arrowhead is longer than the line length.

The absolute motion versions of these commands specify the coordinate of
the final position.

@table @code
@findex \move
@item \move (@var{x} @var{y})
Move to coordinate @code{(@var{x} @var{y})}.  The new current position
is @code{(@var{x} @var{y})}.
@findex \lvec
@item \lvec (@var{x} @var{y})
Draw a line from the current position to coordinate @code{(@var{x}
@var{y})}.  The new current position is @code{(@var{x} @var{y})}.
@findex \avec
@item \avec (@var{x} @var{y})
Draw a line with an arrowhead from the current position to
@code{(@var{x} @var{y})}.  The new current position is @code{(@var{x}
@var{y})}.  The arrowhead is aligned with the line, with the tip at
@code{(@var{x} @var{y})}.
@end table

@cindex relative positioning
The relative motion versions of these commands interpret the coordinates
as displacements relative to the current position.  Given the
displacements @code{(@var{dx} @var{dy})} as a parameter, each of the
relative motion commands moves @var{dx} units in the @var{x} direction
and @var{dy} units in the @var{y} direction.

@table @code
@findex \rmove
@item \rmove (@var{dx} @var{dy})
Move from the current position, @var{dx} units in the @var{x} direction
and @var{dy} units in the @var{y} direction.  The final position becomes
the new current position.
@findex \rlvec
@item \rlvec (@var{dx} @var{dy})
Draw a line from the current position, @var{dx} units in the @var{x}
direction and @var{dy} units in the @var{y} direction.  The final
position becomes the new current position.
@findex \ravec
@item \ravec (@var{dx} @var{dy})
Draw a line with an arrowhead from the current position, @var{dx} units
in the @var{x} direction and @var{y} units in the @var{y} direction.
The final position becomes the new current position.  The arrowhead is
aligned with the line, with the tip at the new current position.
@end table

Lines can be customized with commands to change the line width, line
pattern and line gray level rendition.  In addition, commands for
changing the type and size of the arrowhead are available.

@cindex line width
@cindex width of lines
@cindex dashed lines
@cindex dotted lines
@cindex gray levels for lines
@cindex arrowhead parameters
@table @code
@findex \linewd
@item \linewd @var{width}
Set the line width to @var{width} units.  Initially @var{width} is 0.01
inches (corresponding to 3 pixels at 300 pixels to the inch).
@item \lpatt (@var{pattern})
Set lines to have the pattern @code{(@var{pattern})}.  A pattern is a
sequence of on/off lengths separated by blanks and enclosed in parentheses.
The lengths alternately specify the length of a dash and the length of a
gap between dashes.  Each length is interpreted using the current
scaling and drawing units.  The pattern is used cyclically.  The empty
pattern signifies a solid line.  The initial line pattern is a solid
line, corresponding to the empty pattern @code{\lpatt ()}.
@findex \setgray
@item \setgray @var{level}
Set the gray level of lines.  Gray levels are real values from 0 (black)
through intermediate values (gray) to 1 (white).  The initial gray level
is 0 corresponding to black.
@findex \arrowheadtype
@item \arrowheadtype t:@var{type}
Set the arrowhead type to @var{type}, where @var{type} is one of
@code{F}, @code{T}, @code{W}, @code{V}, or @code{H}.  There are two
kinds of arrowheads.  The first kind is a triangle.  There are 3
variants: type @code{T} is an empty triangle, type @code{F} is a filled
triangle (using the current gray level for lines), type @code{W} is a
triangle filled with white.  The second kind of arrowhead is an open
ended Vee.  There are 2 variants: type @code{V} has the stem continue to
the tip, type @code{H} has the stem stop at the base of the arrowhead.
The initial arrowhead type is @code{T}.
@findex \arrowheadsize
@item \arrowheadsize l:@var{length} w:@var{width}
Set the arrowhead size to be @var{length} units long and @var{width}
units wide.  The width is measured across the ``base'' of the arrowhead.
The initial arrowhead size has a @var{length} of 0.16 inches and a
@var{width} of 0.08 inches.
@end table

Note that the lines which outline the arrowhead will be drawn with the
same line pattern used for the stem.  Normally, arrow vectors are drawn
with the line pattern set for a solid line.  Note that the fill level
used for the @code{F} variant of the arrowhead uses the same gray level
as used for lines.  The difference between the @code{T} variant and the
@code{W} variant only shows up if the arrowhead is placed over non-white
areas of the drawing.  The @code{W} variant obliterates the area under
the arrowhead.

Examples of line parameter and arrowhead settings are shown in the
following code.
@example
@group
\centertexdraw@{
  \drawdim in
  \linewd 0.03 \setgray 0.6 \arrowheadtype t:F \avec(0 0.5)
  \linewd 0.01 \setgray 0   \arrowheadtype t:V \avec(0.5 0.5)
  \linewd 0.015 \lpatt(0.067 0.1) \lvec (1 0)
  \linewd 0.02 \lpatt() \arrowheadtype t:T \avec(1.5 0.5)
  \arrowheadtype t:H \avec(2.0 0.5)
  \setgray 0.4 \arrowheadtype t:W \avec(3.0 0)
@}
@end group
@end example
@tex
\bigskip
\centertexdraw{
  \drawdim in
  \linewd 0.03 \setgray 0.6 \arrowheadtype t:F \avec(0.5 0.5)
  \linewd 0.01 \setgray 0   \arrowheadtype t:V \avec(1.0 0.5)
  \linewd 0.015 \lpatt(0.067 0.1) \lvec (1.5 0)
  \linewd 0.02 \lpatt() \arrowheadtype t:T \avec(2.0 0.5)
  \arrowheadtype t:H \avec(2.5 0.5)
  \setgray 0.4 \arrowheadtype t:W \avec(3.0 0)
  \textref h:R v:T \htext (0.35 0.50){\tt t:F}
  \textref h:R v:T \htext (1.0 0.43){\tt t:V}
  \textref h:R v:T \htext (1.82 0.50){\tt t:T}
  \textref h:R v:T \htext (2.5 0.43){\tt t:H}
  \textref h:R v:B \htext (2.8 0){\tt t:W}
}
@end tex

@node TeX text, Circles and arcs, Line vectors, TeXdraw Commands
@section @TeX{} text
@cindex text commands

Text may be superimposed on the drawing.  The text argument of the
@code{\htext} command is in horizontal mode.  This text can be ordinary
text, math mode expressions, or even more complicated boxes consisting
of tables and the like.  The resulting @TeX{} text is placed in a box.
The reference point of the box can be chosen to be one of nine
locations: horizontally left, center or right; vertically top, center or
bottom.  The @code{\htext} command takes one of two forms.

@table @code
@findex \htext
@item \htext (@var{x} @var{y})@{@var{text}@}
@itemx \htext @{@var{text}@}
The first form of this command places the @TeX{} text @var{text}
horizontally with the text reference point at the coordinate
@code{(@var{x} @var{y})}.  The new current position is @code{(@var{x}
@var{y})}.  The second form of this command places the @TeX{} text
@var{text} horizontally with the text reference point at the current
position.  The text reference point is set with the @code{\textref}
command.
@end table

@cindex vertical text
@cindex rotated text
@cindex text rotation
Text can be placed vertically using the @code{\vtext} command.  The text
argument is in horizontal mode.  The @TeX{} text is placed in a box and
then rotated counterclockwise.  The reference point is the point in the
box, @emph{before} rotation of the text.  Not all PostScript printer
drivers support vertical text.

@table @code
@findex \vtext
@item \vtext (x y)@{@var{text}@}
@itemx \vtext @{@var{text}@}
The first form of this command places the @TeX{} text @var{text}
vertically with the text reference point at the coordinate
@code{(@var{x} @var{y})}.  The new current position is @code{(@var{x}
@var{y})}.  The second form of this command places the @TeX{} text
@var{text} vertically with the text reference point at the current
position.  In both cases, the @TeX{} text is placed in a box and the box
is rotated counterclockwise by 90 degrees about the text reference
point.  The text reference point is set with the @code{\textref}
command.
@end table

@cindex rotated text
@cindex text rotation
Text can be placed at an arbitrary angle using the @code{\rtext}
command.  The text argument is in horizontal mode.  The @TeX{} text is
placed in a box and then rotated counterclockwise.  The reference point
is the point in the box, @emph{before} rotation of the text.  Not all
PostScript printer drivers support rotated text.

@table @code
@findex \rtext
@item \rtext td:@var{angle} (x y)@{@var{text}@}
@itemx \rtext td:@var{angle} @{@var{text}@}
The first form of this command places the @TeX{} text @var{text} at an
angle with the text reference point at the coordinate @code{(@var{x}
@var{y})}.  The new current position is @code{(@var{x} @var{y})}.  The
second form of this command places the @TeX{} text @var{text} at an
angle with the text reference point at the current position.  In both
cases, the @TeX{} text is placed in a box and the box is rotated
counterclockwise by @var{angle} degrees about the text reference point.
The text reference point is set with the @code{\textref} command.
@end table

The reference point for subsequent @TeX{} text in a @code{\htext},
@code{\vtext} or @code{\rtext} command is set with the @code{\textref}
command.

@table @code
@findex \textref
@item \textref h:@var{h-ref} v:@var{v-ref}
Set the text reference point for subsequent text commands.  The
horizontal reference point @var{h-ref} is one of @code{L}, @code{C} or
@code{R} (left, center or right).  The vertical reference point
@var{v-ref} is one of @code{T}, @code{C} or @code{B} (top, center or
bottom).  For rotated text, the reference point is determined before
rotation.  The initial text reference point corresponds to
@code{\textref h:L v:B}.
@end table
@noindent

@tex
\centertexdraw{
  \def\bdot {\bsegment
               \fcir f:0 r:0.02
             \esegment}
  \def\Ttext #1{\bsegment
                  \textref h:C v:B \htext (0 +0.06){#1}
                \esegment}
  \def\Btext #1{\bsegment
                  \textref h:C v:T \htext (0 -0.06){#1}
                \esegment}
  \def\Ltext #1{\bsegment
                  \textref h:R v:C \htext (-0.08 0){#1}
                \esegment}
  \def\Rtext #1{\bsegment
                  \textref h:L v:C \htext (+0.08 0){#1}
                \esegment}
  \move (-1.5 0)
  \bsegment
    \move (+1.55 +0.45) \move (-1.55 -0.45) \move (0 0)
    \Ttext{Horizontal Text}
    \bdot                   \Btext{\tt h:C v:C}
    \move (-0.9 0)    \bdot \Ltext{\tt h:L v:C}
    \move (+0.9 0)    \bdot \Rtext{\tt h:R v:C}
    \move (0 +0.3)    \bdot \Ttext{\tt h:C v:T}
    \move (0 -0.3)    \bdot \Btext{\tt h:C v:B}
    \move (-0.9 -0.3) \bdot \Ltext{\tt h:L v:B}
    \lvec (-0.9 +0.3) \bdot \Ltext{\tt h:L v:T}
    \lvec (+0.9 +0.3) \bdot \Rtext{\tt h:R v:T}
    \lvec (+0.9 -0.3) \bdot \Rtext{\tt h:R v:B}
    \lvec (-0.9 -0.3)
  \esegment
  \def\atext {\rtext td:45 }
  \def\ATtext #1{\bsegment
                   \setsegscale 0.707
                   \textref h:C v:B \atext (-0.06 +0.06){#1}
                 \esegment}
  \def\ABtext #1{\bsegment
                   \setsegscale 0.707
                   \textref h:C v:T \atext (+0.060 -0.06){#1}
                 \esegment}
  \def\ALtext #1{\bsegment
                   \setsegscale 0.707
                   \textref h:R v:C \atext (-0.08 -0.08){#1}
                 \esegment}
  \def\ARtext #1{\bsegment
                   \setsegscale 0.707
                   \textref h:L v:C \atext (+0.08 +0.08){#1}
                 \esegment}
  \move (+1.5 0)
  \bsegment
    \move (+1.33 +1.33) \move (-1.33 -1.33) \move (0 0)
    \setsegscale 0.707
    \ATtext{Rotated Text}
    \bdot                   \ABtext{\tt h:C v:C}
    \move (-0.9 -0.9) \bdot \ALtext{\tt h:L v:C}
    \move (+0.9 +0.9) \bdot \ARtext{\tt h:R v:C}
    \move (-0.3 +0.3) \bdot \ATtext{\tt h:C v:T}
    \move (+0.3 -0.3) \bdot \ABtext{\tt h:C v:B}
    \move (-0.6 -1.2) \bdot \ALtext{\tt h:L v:B}
    \lvec (-1.2 -0.6) \bdot \ALtext{\tt h:L v:T}
    \lvec (+0.6 +1.2) \bdot \ARtext{\tt h:R v:T}
    \lvec (+1.2 +0.6) \bdot \ARtext{\tt h:R v:B}
    \lvec (-0.6 -1.2)
  \esegment
}
@end tex

The font used to render the text is determined as for any other @TeX{}
text.  Normally the font used outside of @TeX{}draw is in effect.  If
desired, other fonts can be specified as part of the text.  Any font
changes within a @TeX{}draw text command remain local to that command.

Only the coordinate of the text reference point in a @code{\htext},
@code{\vtext} or @code{\rtext} command is used in calculating the size
of the drawing.  This means that text itself can spill outside of the
drawing area determined by @TeX{}draw.  The area of the drawing can be
increased to include the text by issuing additional @code{\move}
commands.

@example
@group
\centertexdraw@{
             \avec(-0.75 -0.25) \textref h:R v:C \htext@{H-text@}
  \move(0 0) \avec(-0.75 +0.25) \textref h:R v:B \htext@{H-text@}
  \move(0 0) \avec(0 +0.5)      \textref h:L v:T \vtext@{V-text@}
  \move(0 0) \avec(+0.75 +0.25) \textref h:L v:B \htext@{H-text@}
  \move(0 0) \avec(+0.75 -0.25) \textref h:L v:C \htext@{H-text@}
@}
@end group
@end example
@iftex
Superimposed on this example is a shaded region showing the limits of
the @TeX{}draw box as determined by the coordinates specified.
@tex
\bigskip
\centertexdraw{
  \move(-0.75 -0.25) \lvec (-0.75 +0.5) \lvec (+0.75 +0.5)
  \lvec(+0.75 -0.25) \ifill f:0.9         % fill the region
  \move(0 0)
             \avec(-0.75 -0.25) \textref h:R v:C \htext{H-text}
  \move(0 0) \avec(-0.75 +0.25) \textref h:R v:B \htext{H-text}
  \move(0 0) \avec(0 +0.5)      \textref h:L v:T \vtext{V-text}
  \move(0 0) \avec(+0.75 +0.25) \textref h:L v:B \htext{H-text}
  \move(0 0) \avec(+0.75 -0.25) \textref h:L v:C \htext{H-text}
  \move (-1.15 -0.3) \move (+1.15 +0.92)  % increase the size of the drawing
}
@end tex
@end iftex

@node Circles and arcs, Bezier curves, TeX text, TeXdraw Commands
@section Circles, ellipses and arcs
@cindex circles
@cindex filled circles
@cindex ellipses
@cindex arcs

@TeX{}draw supplies commands to generate circles, ellipses and arcs.
There are two forms of the circle command.  The @code{\lcir} command
draws a circle of given radius.  The @code{\fcir} command draws a filled
circle.  In the latter case, the circle is filled by a specified gray
level.  For the filled circle, the line defining the circumference of
the circle is not drawn.  Note that the gray level area filled in by the
@code{\fcir} command is opaque, even if the fill is chosen to be white.
For either form of the circle command, the drawing size is increased if
necessary to contain the circle.

The @code{\lellip} command generates an ellipse specified by the radius
of the ellipse in the @var{x} direction and the radius of the ellipse in
the @var{y} direction.  The ellipse is symmetrical about horizontal and
vertical lines drawn through the current point.  The @code{\fellip}
command draws a filled ellipse.  In the latter case, the ellipse is
filled by a specified gray level.  For the filled ellipse, the line
defining the boundary of the ellipse is not drawn.  For either form of
the ellipse command, the drawing size is increased if necessary to
contain the ellipse.


The @code{\larc} command generates a counterclockwise arc specified by a
start angle in degrees and an end angle in degrees.  The center of the
arc is the current position.  Only the arc is drawn, not the line
joining the center to the beginning of the arc.  Note that the
@code{\larc} command does not affect the size of the drawing.

@table @code
@findex \lcir
@item \lcir r:@var{radius}
Draw a circle with center at the current position.  The radius is
specified by @var{radius}.  This command draws a line along the
circumference of the circle.  The drawing size is increased if necessary
to contain the circle.
@findex \fcir
@item \fcir f:@var{level} r:@var{radius}
Draw a filled circle with center at the current position.  The radius is
specified by @var{radius}.  The circle is painted with the gray level
specified by @var{level}.  A gray level of 1 corresponds to white, with
decreasing values getting darker.  The level 0 is full black.  This
command does not draw a line along the circumference.  The drawing size
is increased if necessary to contain the circle.
@findex \lellip
@item \lellip rx:@var{x-radius} ry:@var{y-radius}
Draw an ellipse with center at the current position.  The radius in the
@var{x} direction is specified by @var{x-radius}.  The radius in the
@var{y} direction is specified by @var{y-radius}.  The drawing size is
increased if necessary to contain the ellipse.
@findex \fellip
@item \fellip f:@var{level} rx:@var{x-radius} ry:@var{y-radius}
Draw a filled ellipse with center at the current position.  The radius
in the @var{x} direction is specified by @var{x-radius}.  The radius in
the @var{y} direction is specified by @var{y-radius}.  The ellipse is
painted with the gray level specified by @var{level}.  A gray level of 1
corresponds to white, with decreasing values getting darker.  The level
0 is full black.  This command does not draw a line along the boundary
of the ellipse.  The drawing size is increased if necessary to contain
the ellipse.
@findex \arc
@item \larc r:@var{radius} sd:@var{start-angle} ed:@var{end-angle}
Draw a counterclockwise arc.  The center of the arc is at the current
position.  The radius is specified by @var{radius}.  The start and end
angles (in degrees) are specified by @var{start-angle} and
@var{end-angle}.  This command does not affect the limits (size) of the
drawing.
@end table

As an example, the following commands draw a filled circle, and
superimpose an arc.
@example
@group
\centertexdraw@{
  \linewd 0.02
  \fcir f:0.7 r:1
  \larc r:1 sd:45 ed:135
  \lvec (+0.707 +0.707) \move (0 0) \lvec (-0.707 +0.707)
@}
@end group
@end example
@tex
\bigskip
\centertexdraw{
  \linewd 0.02
  \fcir f:0.7 r:1
  \larc r:1 sd:45 ed:135
  \lvec ( 0.707  0.707) \move (0 0) \lvec (-0.707 +0.707)
}
@end tex

Note that for the arc command, the resulting figure can spill outside of
the @TeX{}draw box as determined by the maximum excursions of the
coordinates.  Extra moves can be used to compensate for the size of the
arc.

@node Bezier curves, Fill commands, Circles and arcs, TeXdraw Commands
@section Bezier curves
@cindex Bezier curves
@cindex curves

Bezier curves in @TeX{}draw use 4 reference coordinates, two as the end
points and two others to control the shape of the curve.  Let the 4
points be @code{(@var{x0} @var{y0})}, @code{(@var{x1} @var{y1})},
@code{(@var{x2} @var{y2})} and @code{(@var{x3} @var{y3})}.  The curve
starts out tangent to the line joining the first two points and ends up
tangent to the line joining the second two points.  The control points
``pull'' at the curve to control the curvature.  The amount of pull
increases with the distance of the control point from the endpoint.

@tex
As the parameter $\mu$ varies from 0 to 1, the coordinates of the Bezier
curve are given by a pair of parametric cubic equations,
$$
\def\x #1{\hbox{\sl x#1}}
\def\y #1{\hbox{\sl y#1}}
\eqalign{
 \x{}(\mu) &= (1-\mu)^3 \x0 + 3\mu(1-\mu)^2 \x1 + 3\mu^2(1-\mu) \x2 + \mu^3 \x3 \cr
 \y{}(\mu) &= (1-\mu)^3 \y0 + 3\mu(1-\mu)^2 \y1 + 3\mu^2(1-\mu) \y2 + \mu^3 \y3\ . \cr}
$$
@end tex
@ifinfo
As the parameter u varies from 0 to 1, the coordinates of the Bezier
curve are given by a pair of parametric cubic equations,

@noindent
x(u) = (1-u)^3 x0  + 3u (1-u)^2 x1  + 3u^2 (1-u) x2  + u^3 x3
@noindent
y(u) = (1-u)^3 y0  + 3u (1-u)^2 y1  + 3u^2 (1-u) y2  + u^3 y3 .

@end ifinfo


@table @code
@findex \clvec
@item \clvec (@var{x1} @var{y1})(@var{x2} @var{y2})(@var{x3} @var{y3})
Draw a Bezier curve from the current position to the coordinate
@code{(@var{x3} @var{y3})} which becomes the new current position.  The
coordinates @code{(@var{x1} @var{y1})} and @code{(@var{x2} @var{y2})}
serve as control points for the curve.  Only the last coordinate given
is used to update the size of the drawing.
@end table
@noindent
Note that only 3 coordinate pairs are specified.  The other point is the
current position before the @code{\clvec} command is executed.  Only the
last coordinate specified in the @code{\clvec} command is used to
determine the extent of the drawing.  While the Bezier curve passes
through the old current position and the new current position, in
general the curve will not reach the intermediate control points.  The
curve is always entirely enclosed by the convex quadrilateral defined by
the two end points and the two control points.  Note that the curve may
pass outside the limits of the drawing as determined by the end point of
the curve.

A simple Bezier curve is produced by the following example.
@example
@group
\btexdraw
  \move (0 0)
  \clvec (0 1)(1 0)(1 1)
\etexdraw
@end group
@end example

@iftex
This example is the rightmost of the following Bezier curves.  The
drawings also show the end points and the control points for each curve.
@tex
\bigskip
\centertexdraw{
  \def\Ltext #1{\bsegment
                  \textref h:R v:C \htext (-0.08 0){#1}
                \esegment}
  \def\Rtext #1{\bsegment
                  \textref h:L v:C \htext (+0.08 0){#1}
                \esegment}
  \def\bdot {\fcir f:0 r:0.02 }
  \def\Ldot #1{\bdot \Ltext{#1}}
  \def\Rdot #1{\bdot \Rtext{#1}}
  \move (-2 0)
  \bsegment
    \lpatt (0.033)
    \move (0 0) \Ldot{0} \lvec (0 1) \Ldot{1}
    \lvec (1 1) \Rdot{2} \lvec (1 0) \Rdot{3}
    \lpatt ()
    \move (0 0) \clvec (0 1)(1 1)(1 0)
  \esegment
  \move (0 0)
  \bsegment
    \lpatt (0.033)
    \move (0 0) \Ldot{0}  \lvec (0.5 0.8) \Ldot{1}
    \lvec (1.5 0.8) \Rdot{2} \lvec (1 0) \Rdot{3}
    \lpatt ()
    \move (0 0) \clvec (0.5 1)(1.5 1)(1 0)
  \esegment
  \move ( 2 0)
  \bsegment
    \lpatt (0.033)
    \move (0 0) \Ldot{0} \lvec (0 1) \Ldot{1}
    \lvec (1 0) \Rdot{2} \lvec (1 1) \Rdot{3}
    \lpatt ()
    \move (0 0) \clvec (0 1)(1 0)(1 1)
  \esegment
}
@end tex
@end iftex

@node Fill commands, , Bezier curves, TeXdraw Commands
@section Fill commands
@cindex filling regions
@cindex painting regions
@cindex paths

PostScript deals with paths consisting of line segments.  The paths can
be closed and the interior of the closed region filled.  From
@TeX{}draw, paths start with a @code{\move} or @code{\rmove} command and
continue with @code{\lvec}, @code{\rlvec} or @code{\clvec} commands.
The @TeX{}draw fill commands close the path and fill the interior of the
closed region.  Closing the path means that effectively another
@code{\lvec} line is drawn from the last point specified to the initial
point.  @TeX{}draw provides two forms of the fill command.  The
@code{\ifill} fills the interior of the region with the given gray
level.  The lines defining the path are not drawn.  The @code{\lfill}
command fills the region defined by the closed path and draws a line
along the enclosing path.  Note for both forms of the fill command, the
gray level used for filling is opaque, even if the gray level is chosen
to be white.

@table @code
@findex \lfill
@item \lfill f:@var{level}
Close the current path, draw the line around the path using the current
grey level for lines and paint the interior of the region with specified
gray level @var{level}.  Gray levels are real values from 0 (black)
through intermediate values (grays) to 1 (white).
@findex \ifill
@item \ifill f:@var{level}
Close the current path and paint the interior of the region with gray
level @var{level}.  The line around the path is not drawn.  Gray levels
are real values from 0 (black) through intermediate values (grays) to 1
(white).
@end table

The following example draws a ``flag'' with the interior filled in.  The
path around the boundary is given in a clockwise order to define a
closed path.  We could take advantage of the fact that the fill command
will close an open path to eliminate one of the @code{\lvec} commands.
@example
@group
\centertexdraw@{
\move (0.5 0)
\lvec (0 0.5) \clvec (0.5 0.85)(1 0.65)(1.5 1)
\lvec (2 0.5) \clvec (1.5 0.15)(1 0.35)(0.5 0)
\lfill f:0.8
@}
@end group
@end example
@tex
\bigskip
\centertexdraw{
\move (0.5 0)
\lvec (0 0.5) \clvec (0.5 0.85)(1 0.65)(1.5 1)
\lvec (2 0.5) \clvec (1.5 0.15)(1 0.35)(0.5 0)
\lfill f:0.8
}
@end tex

In @TeX{}draw, the @code{\move} command always terminates any previous
paths and starts a new path.  Commands that change line parameters
(e.g@.  @code{\setgray} or @code{\lpatt}) also terminate paths and start
new paths.  The circle, ellipse and arc commands do not affect the
definition of the current path.  The @code{\avec} command is not
appropriate for defining a path to be filled.  It ends a subpath at its
tail and begins a new subpath at its tip.  Filling a region defined by a
path with subpaths is more complicated in that each subpath is closed
before filling.


@node Drawing Segments and Scaling, Using TeXdraw with LaTeX, TeXdraw Commands, Top
@chapter Drawing Segments and Scaling

@TeX{}draw provides individually scaled segments which can be used to
create relocatable drawing modules.

@menu
* Drawing segments::
* Drawing paths::
* Saving positions::
* Scaling coordinates::
* Drawing size::
* Initial current position::
@end menu

@node Drawing segments, Drawing paths, , Drawing Segments and Scaling
@section Drawing segments
@cindex segments
@cindex drawing segments

A @TeX{}draw drawing segment allows for local modifications of
parameters and relative positioning.  A @TeX{}draw segment is delimited
by a @code{\bsegment} command and an @code{\esegment} command.  Inside
the segment, the initial current position is @code{(0 0)}.  Any changes
to parameters such as the gray level and the line width, remain local to
the segment.  Segments are implemented in @TeX{} using a
@code{\begingroup} and @code{\endgroup}.  Segments can be nested.

@table @code
@findex \bsegment
@item \bsegment
Start a drawing segment.  The coordinate system is shifted such that the
current position corresponds to the coordinate @code{(0 0)}.  Changes to
scaling, position and line parameters stay local to the drawing segment.
@findex \esegment
@item \esegment
End a drawing segment.  The current position in effect before the
corresponding @code{\bsegment} command is restored.  The scaling and
line parameter values revert to those in effect before the corresponding
@code{\bsegment} command was invoked.
@end table

@node Drawing paths, Saving positions, Drawing segments, Drawing Segments and Scaling
@section Drawing paths
@cindex fill operations, interaction with drawing segments
@cindex paths
@cindex stroking lines
Certain subtle interactions occur between drawing segments and fill
operations.  In PostScript, lines are drawn by first defining a path,
then later stroking the path to draw the line.  In @TeX{}draw, this
stroking occurs when the line is terminated, say by a @code{\move}
command.  PostScript paths are interrupted by, but continue after a
drawing segment.  This means that a path started before a segment may
not be stroked (drawn) until after the segment ends.  Consider the
following example.
@example
@group
\move (0 0)
\lvec (1 1)
\bsegment
  \move (-0.25 -0.25)
  \fcir f:0.8 r:0.5
\esegment
\move (0 0)
@end group
@end example
A PostScript path is started at @code{(0 0)} and continues with a line
to @code{(1 1)}.  This path is interrupted by the segment.  The filled
circle is drawn next.  After the segment, the path continues and is not
stroked until the @code{\move (0 0)} command after the end of the
segment.  This means that the line appears on top of the filled region.

If the fill operation is to cover the line, the path must be stroked
before the fill operation.  From @TeX{}draw, the move commands
@code{\move} and @code{\rmove}, and the end @TeX{}draw command
@code{\etexdraw} terminate a path and cause it to be stroked.  Within a
segment, the end segment command @code{\esegment} also terminates and
strokes a path.  In the example above, the line can be stroked by
inserting a move command (such as a @code{\rmove (0 0)} which does not
affect the position), before the start of the segment.

@node Saving positions, Scaling coordinates, Drawing paths, Drawing Segments and Scaling
@section Saving positions
@cindex saving positions
@cindex positions, saving
@cindex coordinate, symbolic
@cindex symbolic coordinate

The @code{\savecurrpos} command saves the current position.  The saved
position is an absolute position, not one relative to a segment.  The
position saving mechanism is global; the position can be saved within a
nested segment and then used outside of the segment.  The @var{x} and
@var{y} coordinates of the position are saved separately as named
coordinates.  The names are of the form @code{*@var{name}}, with the
leading @code{*} being obligatory.  A companion command,
@code{\savepos}, saves a given coordinate (relative to the current
segment) as an absolute symbolic position.

@table @code
@findex \savecurrpos
@item \savecurrpos (*@var{px} *@var{py})
Save the current position as the absolute position referenced by
@code{(*@var{px} *@var{py})}.
@findex \savepos
@item \savepos (@var{x} @var{y})(*@var{px} *@var{py})
Save the coordinate position @code{(@var{x} @var{y})} as the absolute
position referenced by @code{(*@var{px} *@var{py})}.  The coordinate
@code{(@var{x} @var{y})} is interpreted in the normal fashion as a
coordinate relative to the current segment, using the current scaling
factors and drawing unit.
@end table

The symbolic names used to specify a saved position can consist of any
characters that are not special to @TeX{}, but must start with a
@code{*} character.  The symbolic names can be used as the @var{x}
and/or @var{y} coordinate in any command that needs a coordinate.
Symbolic coordinates are not normally used with relative motion commands
such as @code{\rlvec} or @code{\rmove}.  If used with relative motion,
the corresponding displacement is equal to the symbolic coordinate
value.

On exit from a segment, the position and graphics state on entry is
restored.  Any changes to line types, scaling and position are
discarded.  However, it is sometimes useful alter the position on exit
from a segment.  The @code{\savepos} command allows for the saving of a
position within the segment.  This position can be restored after the
@code{\esegment} with a @code{\move} command using the saved symbolic
position.  This approach can be used to build modules which operate in a
manner analogous to the basic relative motion line vector commands.

The following example defines a macro which draws a box 0.75 inches wide
by 0.5 inches high containing centered text.  On leaving the macro the
position will be set at a point on the righthand side of the box.
@example
@group
\def\tbox #1@{\bsegment
               \lvec (0 +0.25)    \lvec (0.75 +0.25)
               \lvec (0.75 -0.25) \lvec (0 -0.25) \lvec (0 0)
               \textref h:C v:C \htext (0.375 0)@{#1@}
               \savepos (0.75 0)(*ex *ey)
             \esegment
             \move (*ex *ey)@}
@end group
@end example
With this definition, we can treat @code{\tbox} in the same way as the
basic vector commands, stringing them together to form a block diagram
as in this example.
@example
@group
\centertexdraw@{
  \ravec (1 0) \tbox@{$H(z)$@} \ravec (1 0)
@}
@end group
@end example
@tex
\def\tbox #1{\bsegment
               \lvec (0 +0.25)    \lvec (0.75 +0.25)
               \lvec (0.75 -0.25) \lvec (0 -0.25) \lvec (0 0)
               \textref h:C v:C \htext (0.375 0){#1}
               \savepos (0.75 0)(*ex *ey)
             \esegment
             \move (*ex *ey)}
\bigskip
\centertexdraw{
  \ravec (1 0) \tbox{$H(z)$} \ravec (1 0)
}
@end tex

@node Scaling coordinates, Drawing size, Saving positions, Drawing Segments and Scaling
@section Scaling coordinates
@cindex scaling coordinates
@cindex relative scaling
@cindex segment scale
@cindex unit scale

There are two scale factors available, the unit scale factor and the
segment scale factor.  The overall scale factor is the product of these
two.  There are absolute and relative versions of commands to change
these scale factors.

The unit scale factor is normally used to affect global scale changes.
Changes to the unit scale factor remains local to a segment, but
propagate to inferior segments.  The default value is unity.

The segment scale factor is used for local scale changes.  It remains
local to a segment.  The segment scale factor is reset to unity on entry
into each segment.  This means that changes to the segment scale factor
do not propagate to inferior segments.

@table @code
@findex \setunitscale
@item \setunitscale @var{scale}
Set the unit scaling to @var{scale}.  The argument @var{scale} is a real
number which is used to scale coordinate values.  The overall scaling
factor is the product of the unit scale factor and the segment scale
factor.
@findex \relunitscale
@item \relunitscale @var{value}
Adjust the unit scale factor by multiplying by @var{value}.  This has
the effect of multiplying the overall scale factor by the same factor.
The overall scaling factor is the product of the unit scale factor and
the segment scale factor.
@findex \setsegscale
@item \setsegscale @var{scale}
Set the segment scale factor.  The argument @var{scale} is a real number
which is used to scale coordinate values.  The overall scale factor is
the product of the unit scale factor and the segment scale factor.
@findex \relsegscale
@item \relsegscale @var{value}
Adjust the segment scale factor by multiplying by @var{value}.  This has
the effect of multiplying the current overall scale factor by the same
factor.  The overall scaling factor is the product of the unit scale
factor and the segment scale factor.
@end table

In addition to the unit scale factor and the segment scale factor, the
scaling can be controlled by the choice of drawing units with the
command @code{\drawdim} (@pxref{Coordinate specification}).

@table @code
@item \drawdim cm \setunitscale 2.54
Set the units to centimetres scaled by 2.54.  Together these commands
are effectively the same as @code{\drawdim in}.
@end table

The segment scale can be used to allow scale changes in segments so that
values are in more convenient units.  For example suppose dimensions in
a segment are multiples of one third of an inch.  The segment scale can
be set once to make 1 drawing unit equal 0.3333 inches.  From that point
on, coordinates can be specified with integer values.

The following example defines a macro to draw a rectangular box which is
twice as wide as it is high.  The width is specified as an argument.
@example
@group
\def\mybox #1@{\bsegment
                \setsegscale #1
                \lvec (0 +0.25) \lvec (1 +0.25) \lvec (1 -0.25)
                \lvec (0 -0.25) \lvec (0 0)
              \esegment@}
@end group
@end example

@node Drawing size, Initial current position, Scaling coordinates, Drawing Segments and Scaling
@section Drawing size
@cindex size of the drawing

The effective size of the drawing is determined by the maximum
excursions of the coordinates supplied to @TeX{}draw commands.  The
minimum and maximum scaled @var{x} and @var{y} coordinates are tallied.
Note that @code{\move} commands contribute to the determination of the
calculated size of the drawing, even though they do not generate visible
lines.  The circle and ellipse commands add a compensation for the radii
of circles and ellipses.  The final @TeX{}draw drawing is placed in a
@TeX{} box with lower lefthand corner corresponding to
@code{(}@var{x}-min @var{y}-min@code{)} and upper righthand corner at
@code{(}@var{x}-max @var{y}-max@code{)}.

Text generated by @code{\htext}, @code{\vtext} or @code{\rtext} can
spill outside the box as determined above.  Only the text reference
point is guaranteed to be in the drawing box.  Arcs can also spill
outside the drawing box.  Note also that the widths of lines, and the
sizes of arrowheads do not affect the size of the drawing.  The
calculated size of the drawing will never be larger than the actual size
of the drawing.  In extreme cases in which text or lines extend far
outside the drawing, extra @code{\move} commands should be used to
establish the size of the drawing so that the @TeX{}draw box includes
all of the drawing.

@TeX{}draw provides the @code{\drawbb} command to draw a box which
indicates the effective size of the drawing.  Whenever @code{\drawbb} is
invoked, a ruled box is drawn around the drawing as it has been sized up
to that point.  Normally @code{\drawbb} is invoked just before the end
of a drawing to indicate the effective size of the final drawing.

@table @code
@findex \drawbb
@item \drawbb
Draw a ruled box around the effective size of a drawing produced by
@TeX{}draw commands.
@end table

@node Initial current position, , Drawing size, Drawing Segments and Scaling
@section Initial current position
@cindex current position
@cindex initial current position

The first operation in a drawing should be a move to establish the
current position.  The current position can be established explicitly
through a @code{\move} command or a text positioning command such as
@code{\htext} with a coordinate.  However, if an attempt is made to use
a drawing command which needs a current position and none has been
established, @TeX{}draw implicitly sets the initial current position to
@code{(0 0)}.  The size of the @TeX{}draw figure is normally determined
from the sequence of coordinates specified, but will include the
implicit initial position in case another initial position has not been
explicitly specified.

@node Using TeXdraw with LaTeX, More Details, Drawing Segments and Scaling, Top
@chapter Using @TeX{}draw with La@TeX{}
@cindex accessing @TeX{}draw
@cindex invoking @TeX{}draw
@cindex La@TeX{}
@cindex @code{texdraw} package

The La@TeX{} typesetting system uses a structured approach to declaring
typesetting environments.  For La@TeX{}2e, the @code{texdraw} package
defines the @code{texdraw} environment.  The @TeX{}draw environment is
started with a @code{\begin@{texdraw@}} command and terminated with an
@code{\end@{texdraw@}} command.  All of the basic @TeX{}draw commands
can be used within the @code{texdraw} environment.

As an example, a La@TeX{}2e variant of an earlier example can be
constructed as follows.
@example
@group
\documentclass@{article@}
\usepackage@{texdraw@}
 ...
\begin@{document@}
 ...
\newcommand@{\tbox@}[1]@{%
   \bsegment
     \lvec (0 +0.25)    \lvec (0.75 +0.25)
     \lvec (0.75 -0.25) \lvec (0 -0.25) \lvec (0 0)
     \textref h:C v:C \htext (0.375 0)@{#1@}
     \savepos (0.75 0)(*ex *ey)
   \esegment
   \move (*ex *ey)@}
\begin@{center@}
\begin@{texdraw@}
  \ravec (1 0) \tbox@{$H(z)$@} \ravec (1 0)
\end@{texdraw@}
\end@{center@}
 ...
\end@{document@}
@end group
@end example

This example illustrates the use of the La@TeX{} command
@code{\newcommand} as an alternative to the plain @TeX{} command
@code{\def}.  Instead of the basic @TeX{}draw command
@code{\centertexdraw}, a nested combination of the La@TeX{} centering
environment and the @TeX{}draw environment is used.

@menu
* PostScript printer drivers::
@end menu

@node PostScript printer drivers, , , Using TeXdraw with LaTeX
@section PostScript printer drivers
@cindex printer drivers
@cindex PostScript printer drivers

@cindex @code{graphics} package
The @code{texdraw} package uses the printer driver interface provided by
the standard La@TeX{}2e @code{graphics} package.  Any options to the
@code{texdraw} package are passed to the @code{graphics} package.
Specifically, the name of the PostScript driver to be used can be
specified as an option to the @code{texdraw} package.  With no explicit
printer driver option, the default printer driver associated with the
@code{graphics} package is used.

@cindex @code{dvips} printer driver
@cindex @code{xdvi} driver
@cindex @code{dvi2ps} printer driver
@cindex @code{dvialw} printer driver
@cindex @code{dvilaser} printer driver
@cindex @code{dvipsone} printer driver
@cindex @code{dviwindo} printer driver
@cindex @code{dvitops} printer driver
@cindex @code{oztex} printer driver
@cindex @code{psprint} driver
@cindex @code{textures} printer driver
@cindex @code{pctexps} printer driver
@cindex @code{pctexwin} printer driver
@cindex rotated text
@cindex text rotation
The @code{texdraw} package can be used with any of the printer drivers
supported by the @code{graphics} package that allow for the importation
of PostScript graphics files, viz., @code{dvips}, @code{xdvi},
@code{dvi2ps}, @code{dvialw}, @code{dvilaser}, @code{dvipsone},
@code{dviwindo}, @code{dvitops}, @code{oztex}, @code{psprint},
@code{textures}, @code{pctexps}, and @code{pctexwin}.  Not all of these
drivers support the text rotation needed for the @TeX{}draw commands
@code{\vtext} and @code{\rtext}.  Of the drivers listed above, only the
following support support text rotation: @code{dvips}, @code{xdvi},
@code{dvi2ps}, @code{dvitops}, @code{textures}, and @code{pctexps}.


@node More Details, PostScript Commands, Using TeXdraw with LaTeX, Top
@chapter More Details

The first part of this chapter offers some suggestions for strategies to
isolate errors in @TeX{} and @TeX{}draw input.  The second part of this
chapter discusses implementational issues.  An awareness of these issues
is useful if @TeX{}draw is to be extended.

@menu
* Errors while using TeXdraw::
* Extending TeXdraw::
* How TeXdraw merges graphics and text::
@end menu

@node Errors while using TeXdraw, Extending TeXdraw, , More Details
@section Errors while using @TeX{}draw
@cindex problems while using @TeX{}draw
@cindex errors while using @TeX{}draw

@TeX{} input is notoriously difficult to debug.  If @TeX{} reports
errors, so much the better.  If the cause is not immediately obvious,
consider using a binary search strategy, removing sections of code with
the premature insertion of the @code{\bye} (or @code{\end@{document@}}
for La@TeX{}) command (with the appropriate closing of any open groups
and the like).  Other strategies include the insertion of
@code{\message@{I am here@}} at appropriate places.  Try using
@code{\tracingmacros=1}.  Many problems turn out to be due to an
incorrect number of macro arguments or incorrectly delimited macro
arguments.  The @code{\tracingmacros=1} option writes the macro
arguments and macro expansions to the @TeX{} log file.

Certain errors may not manifest themselves until well after the
offending command.  For instance, if a closing parenthesis is missing
from a @TeX{}draw coordinate, @TeX{} continues searching for the
parenthesis.  If one is found, perhaps many lines later, the @TeX{}draw
error message @code{invalid coordinate} will be printed at this later
point.

All input in the @TeX{}draw environment should be intended for
interpretation by @TeX{}draw commands.  @TeX{}draw places text inside a
zero size box (the text itself extends outside the box).  Extraneous
input manifests itself as a non-zero size @TeX{}draw text box. This
causes the @TeX{}draw text and the PostScript graphics to be displaced
from one another.  An error message is issued if a non-zero width
@TeX{}draw text box is detected.  If this error message appears, look
for unintended character sequences amongst the commands to @TeX{}draw.

Several @TeX{}draw commands pass their arguments ``raw'' to the
PostScript file.  That means that invalid arguments can generate
PostScript errors when the document is printed.  For instance the
argument of the @code{\setgray} command is passed straight through to
the PostScript file.  If this argument is non-numeric, a PostScript
error results.  Not all PostScript printers report errors back to the
user.  The print may just stop prematurely.  One approach to debugging
is to use a PostScript previewer on a workstation. That way, one can
determine at which point in the drawing the PostScript error occurs.

@node Extending TeXdraw, How TeXdraw merges graphics and text, Errors while using TeXdraw, More Details
@section Extending @TeX{}draw
@cindex implementation

@TeX{}draw is implemented using a combination of @TeX{} commands and
PostScript code.  This section discusses some of the implementational
issues as they relate to extending @TeX{}draw.

@TeX{}draw as implemented, offers a basic set of drawing features.
These are adequate for certain tasks such as producing block diagrams.
There are different approaches to extending @TeX{}draw to include other
functions.  In some cases, the desired functionality can be achieved by
writing a @TeX{} macro which builds on top of the existing @TeX{}draw
commands.  As these extensions become more complex, the limitations of
@TeX{} for computations become increasingly evident.  In other cases,
access to different features of PostScript is desired.  The appropriate
approach would be to write new PostScript procedures which can be
accessed by @TeX{} macros.

Included with @TeX{}draw is a set of macros for directly accessing
PostScript functions.  These are described in an appendix
(@pxref{PostScript Commands}).

@TeX{}draw also comes with a toolbox of routines for handling much of
the user interface, converting between different coordinate
representations and the like.  The macros for coordinate decoding and
for computations involving coordinates are described in an appendix
(@pxref{TeXdraw Toolbox, , @TeX{}draw Toolbox}).

@menu
* Scaling::
* Resolution::
* Text placement::
* Intermediate PostScript file::
@end menu

@node Scaling, Resolution, , Extending TeXdraw
@subsection Scaling
@cindex scaling

The scaling commands provided in @TeX{}draw are designed to affect only
the coordinate values specified in commands.  For instance, changing the
@code{\setunitscale} value changes the interpretation of the coordinate
in an @code{\avec (@var{x} @var{y})} command, but does not change the
line width or arrowhead sizes in effect.  None of the @TeX{}draw scaling
commands affect the size of @TeX{} text produced by, for instance, the
@code{\htext} command.  Scale changes will however affect the
positioning of text for subsequent commands.

The line parameters are changed only if the corresponding commands to
change them are issued.  If the @code{\linewd} command is given, the
current coordinate scaling is used to determine the line width.  To
achieve a behaviour more like a global scaling, whenever the scale
factor is changed, the line parameters should be set again.

@node Resolution, Text placement, Scaling, Extending TeXdraw
@subsection Resolution
@cindex resolution

@TeX{}draw scales coordinates before passing them to PostScript.
Keeping track of the coordinate scaling is necessary, in any event, to
allow @TeX{}draw to compute the maximum excursions of the coordinates.
@TeX{}draw uses pixel units in its PostScript code.  One pixel unit is
equal to 1/300 of an inch.  @TeX{}draw issues PostScript commands with
integer valued pixel coordinates.  This sets the positioning resolution
for @TeX{}draw.  The passing of integer valued coordinates which
correspond to the device resolution keeps lines aligned with the device
grid; parallel lines of the same width will be rendered with the same
width.

The position saving mechanism in @TeX{}draw (@pxref{Saving positions})
associates the pixel coordinates of a position with the specified name.

@TeX{}draw uses the limited real number representation provided by
@TeX{}.  These operations are based on the representation of dimensions
as real-valued numbers of points.  Internally in @TeX{}, dimensions are
stored 32-bit values, normalized so that 1 pt corresponds to the scaled
point (sp) value of 65536.  Dimensions with magnitudes between 0.000015
pt and 32767 pt can be represented.  This is also the dynamic range of
the @TeX{}draw pixel coordinates passed to PostScript.  @TeX{}draw must
convert from user supplied coordinates using the scaling factor (which
itself consists of two components, the unit scale and the segment scale)
and a pixel conversion factor.  The use of limited precision real
numbers in these computations can cause accumulation of error when
relative scaling is used repeatedly.

@node Text placement, Intermediate PostScript file, Resolution, Extending TeXdraw
@subsection Text placement

While in the @TeX{}draw environment, @TeX{} text is placed in a @TeX{}
box while PostScript code is written to the intermediate file.  At the
end of the @TeX{}draw environment, the size of the drawing is
determined.  A @TeX{} box of this size is created.  The @TeX{}
@code{\special} mechanism is used to instruct the PostScript driver
program to position the PostScript drawing from the intermediate file in
this area.  Next, the text generated by @TeX{}draw is positioned and
placed in the box.  Note that when the document is printed, the
PostScript drawing is placed on the page before the @TeX{} text; @TeX{}
text will appear on top of graphics.

@cindex rotated text
@cindex text rotation
The rotation of text is carried out with in-line PostScript code which
does not appear in the intermediate PostScript file.  This code is sent
to the PostScript driver with a @code{\special} command.  This
PostScript code is embedded in the dvi (device independent) file that
@TeX{} produces.

@node Intermediate PostScript file, , Text placement, Extending TeXdraw
@subsection The intermediate PostScript file
@cindex Encapsulated PostScript File

The intermediate PostScript file consists of a header, a body and a
trailer following Encapsulated PostScript File (EPSF) standards.  The
header sets up PostScript definitions and default parameter values.  The
trailer includes the @code{BoundingBox} information which gives the
coordinates in default PostScript units (72 per inch) for the lower
lefthand corner and the upper righthand corner of the drawing.  The body
of the intermediate PostScript file contains the PostScript commands
generated by @TeX{}draw.

Many moves in @TeX{}draw serve only to position text or to reset saved
positions.  @TeX{}draw buffers move commands in order to be able to
collapse runs of moves.  Only the last move of a run of moves is
actually written to the PostScript file.  However the intermediate moves
still affect the size of the drawing.  The expunging of moves means that
the PostScript file @code{BoundingBox} information may indicate a drawing size
larger than the PostScript commands themselves would warrant.

Drawing segments in @TeX{}draw show up in the PostScript file as saves
and restores of the PostScript graphics state.  Segment starts are
buffered and only written out if necessary.  This way ``empty'' segments
do not generate output to the PostScript file.  These empty segments
arise if a segment contains only moves and text commands.  The moves
inside the segment are not needed since they are local to the segment,
and the text commands do not generate output to the PostScript file.

If @TeX{}draw is used only for moves and text, no intermediate
PostScript file will be created.

@node How TeXdraw merges graphics and text, , Extending TeXdraw, More Details
@section How @TeX{}draw merges graphics and text
@cindex graphics placement
@cindex text placement
@cindex placement of graphics and text

@TeX{}draw creates a box which is the same size as the graphic.  The
printer driver will place the PostScript graphic into this space.  Any
@TeX{} text generated by the @TeX{}draw commands will be superimposed on
this graphic.

@cindex @code{texdraw} package
@cindex @code{graphics} package
The La@TeX{}2e front-end for @TeX{}draw is enabled by including the
@code{texdraw} package.  The @code{texdraw} package automatically
invokes the standard @code{graphics} package distributed with
La@TeX{}2e.  The @code{graphics} package has support for a number of
different printer drivers, including a number for PostScript printers.
Any options to the @code{texdraw} package are passed on to the
@code{graphics} package.  Such an option can be used to select a driver
other than the default one.

@cindex PostScript printer drivers
@cindex printer drivers
@cindex @code{dvips} printer driver
@cindex rotated text
@cindex text rotation
Within the @code{graphics} package, the driver option is used to select
definitions for the low-level macros which generate the @code{\special}
commands needed to request insertion of a graphics file and to rotate
text.@footnote{Not all PostScript drivers support text rotation.}
@TeX{}draw uses the user-level macros defined by the @code{graphics}
package (@pxref{PostScript printer drivers}).  When not used with the
La@TeX{}2e front-end, @TeX{}draw defines versions of these macros that
are suitable for use with the @code{dvips} printer driver.

@node PostScript Commands, TeXdraw Toolbox, More Details, Top
@appendix PostScript Commands
@cindex PostScript commands

This appendix describes a set of macros for accessing some of the
PostScript builtin functions.  Each of these macros issues a single
PostScript command.  The extra services provided by @TeX{}draw are the
interpretation of coordinates in user units relative to the current
drawing segment and the writing of a pending @TeX{}draw move to the
PostScript file.  This last operation establishes the current point in
PostScript.  The user of these commands should be familiar with the
concepts of path construction and filling in PostScript.  Further
details on the PostScript functions used can found in the
@cite{PostScript Language Reference Manual, Second Edition}, Adobe
Systems, Addison-Wesley, 1990.

These macros are distributed in file @file{txdps.tex}.

The @code{\PSsetlinecap} and @code{\PSsetlinejoin} commands control the
way line ends and line joins are rendered.  The default values set by
@TeX{}draw (round caps and round join) are appropriate for most
drawings.  Changes to these parameters apply to the current and
subsequent paths.

@cindex line cap
@cindex line join
@table @code
@findex setlinecap
@findex \PSsetlinecap
@item \PSsetlinecap @var{type}
Set the line cap parameter.  The value @code{0} gives a butt cap;
@code{1} gives a round cap; and @code{2} gives a projecting square cap.
The initial value is corresponds to a round cap.
@findex setlinejoin
@findex \PSsetlinejoin
@item \PSsetlinejoin @var{type}
Set the line join parameter.  The value @code{0} gives a miter join;
@code{1} gives a round join; and @code{2} gives a bevel join.  The
initial value corresponds to a round join.
@end table

@cindex stroking lines
@cindex filling regions
@cindex paths
@cindex current position in PostScript
PostScript paths and fill operations can be controlled by a number of
functions.  By design, @TeX{}draw always maintains a defined PostScript
current point.  Some of the following macros cause the PostScript
current point to become undefined.  The PostScript current point must be
set again (say with a @code{\PSmoveto} command) before invoking basic
@TeX{}draw commands.
@table @code
@findex stroke
@findex \PSstroke
@item \PSstroke
Stroke a PostScript path.  The current path is stroked with the current
gray level (set with @code{\setgray}) and the current line pattern (set
with @code{\lpatt}).  The PostScript current point becomes undefined.
@findex newpath
@findex \PSnewpath
@item \PSnewpath
Establish a new path.  The PostScript current point becomes undefined.
@findex closepath
@findex \PSclosepath
@item \PSclosepath
Close a subpath.  A new subpath is started.
@findex fill
@findex \PSfill
@item \PSfill
Fill a region defined by a path.  Each subpath is closed and the
enclosed regions painted with the current gray level.  The PostScript
current point becomes undefined.  The gray level can be set with the
@TeX{}draw command @code{\setgray}.
@end table

The following line commands interpret coordinates relative to the
current @TeX{}draw scaling and drawing segment.  The specified
coordinate affects the drawing size as determined by @TeX{}draw.
@cindex lines
@cindex moves
@table @code
@findex lineto
@findex \PSlineto
@item \PSlineto (@var{x} @var{y})
Add a line segment to the current path.  This command is identical to
the @TeX{}draw command @code{\lvec}.  The PostScript current point must
be defined before this command is issued.
@findex moveto
@findex \PSmoveto
@item \PSmoveto (@var{x} @var{y})
Move to the coordinate specified by @code{(@var{x} @var{y})}.  The
PostScript current point becomes defined.
@end table

The following macros provide access to the general arc commands in
PostScript.  The coordinates are interpreted relative to the current
@TeX{}draw scaling and drawing segment.  The specified coordinate
affects the drawing size as determined by @TeX{}draw.
@cindex arcs
@table @code
@findex arc
@findex \PSarc
@item \PSarc r:@var{radius} sd:@var{start-angle} ed:@var{end-angle} (@var{x} @var{y})
Draw a counterclockwise arc.  The center of the arc is at the given
position.  The radius is specified by @var{radius}.  The start and end
angles (in degrees) are specified by @var{start-angle} and
@var{end-angle}.  If the PostScript current point is defined, this
command also draws the line from the current point to the beginning of
the arc.  The line and arc become part of the current path. The current
point becomes defined.
@findex arcn
@findex \PSarcn
@item \PSarcn r:@var{radius} sd:@var{start-angle} ed:@var{end-angle} (@var{x} @var{y})
Draw a clockwise arc.  The center of the arc is at the given position.
The radius is specified by @var{radius}.  The start and end angles (in
degrees) are specified by @var{start-angle} and @var{end-angle}.  If the
PostScript current point is defined, this command also draws the line
from the current point to the beginning of the arc.  The line and arc
become part of the current path.  The current point becomes defined.
@end table

The macro @code{\writeps} provides the general facility to write
arbitrary PostScript commands to the PostScript file.  This macro is
used by the preceding commands and by the @TeX{}draw commands
themselves.  This facility has to be used with care since changes in
position or scaling resulting from the PostScript commands are not known
to @TeX{}draw.
@table @code
@findex \writeps
@item \writeps @{@var{<ps-commands>}@}
Write PostScript commands to the intermediate PostScript file.  Before
the commands are inserted, any pending @TeX{}draw move is written to the
PostScript file.  The PostScript scaling gives 300 units/inch.
@end table


@node TeXdraw Toolbox, Examples, PostScript Commands, Top
@appendix @TeX{}draw Toolbox

This appendix describes some of the macros supplied with @TeX{}draw
which can be used to define additional commands for creating drawings.
The macros described here work in the user specified coordinate system.
Some of these toolbox macros are used by the @TeX{}draw commands
themselves, others are supplied in an auxiliary file
@file{txdtools.tex}.

@menu
* Coordinate parsing::
* Real arithmetic::
* Arrow curve::
@end menu

@node Coordinate parsing, Real arithmetic, , TeXdraw Toolbox
@appendixsec Coordinate parsing

The coordinate parsing macro @code{\getpos} is useful for creating new
commands.  This macro takes care of stripping leading and trailing
blanks from coordinates specified between parentheses.  In addition,
symbolic coordinates are translated to the corresponding relative
coordinate using the segment offset and scaling in effect.

The macro @code{\currentpos} returns the relative coordinates of the
current position.  The returned values are relative to the current
segment and the current scaling.  The macro @code{\cossin} returns the
real-valued cosine and sine of the direction of the line joining two
points.  The macro @code{\vectlen} returns the length of a vector.  The
results appear as the value of user supplied macro names.

@cindex coordinate parsing
@cindex current position
@cindex angle of a vector
@cindex direction of a line
@cindex cosine of a vector direction
@cindex sine of a vector direction
@cindex length of a vector
@table @code
@findex \getpos
@item \getpos (@var{x} @var{y})\@var{mx}\@var{my}
Decode coordinate values. The coordinates specified by @code{(@var{x}
@var{y})} are decoded. Symbolic coordinates are translated to the
corresponding relative coordinate using the current segment offset and
scaling.  The resulting character strings representing the real-valued
coordinates are assigned to the macros specified by @code{\@var{mx}} and
@code{\@var{my}}.
@findex \currentpos
@item \currentpos \@var{mx}\@var{my}
Return the coordinates of the current position.  The coordinates are
relative to the current segment offset and scaling.  The resulting
character strings representing the real-valued coordinates are assigned
to the macros specified by @code{\@var{mx}} and @code{\@var{my}}.
@findex \cossin
@item \cossin (@var{x1} @var{y1})(@var{x2} @var{y2})\@var{cosa}\@var{sina}
Return the cosine and sine of the direction of a vector joining two
points.  The cosine and sine of the angle of the vector which goes from
@code{(@var{x1} @var{y1})} to @code{(@var{x2} @var{y2})}.  The character
strings representing these real-valued quantities are assigned to the
macros specified by @code{\@var{cosa}} and @code{\@var{sina}}.
@findex \vectlen
@item \vectlen (@var{x1} @var{y1})(@var{x2} @var{y2})\@var{len}
Return the length of a vector joining two points.  The length of the
vector is relative to the current scaling.  The character string
representing the real-valued length is assigned to the macro specified
by @code{\@var{len}}.
@end table

@node Real arithmetic, Arrow curve, Coordinate parsing, TeXdraw Toolbox
@appendixsec Real arithmetic

The @TeX{}draw toolbox supplies macros to perform real arithmetic on
coordinate values.  The result appears as the value of a user supplied
macro name.
@table @code
@findex \realadd
@item \realadd @{@var{value1}@} @{@var{value2}@} \@var{sum}
Add two real quantities, assigning the resultant character string
representing the sum to the macro @code{\@var{sum}}.
@findex \realmult
@item \realmult @{@var{value1}@} @{@var{value2}@} \@var{prod}
Multiply two real quantities, assigning the resultant character string
representing the product to the macro @code{\@var{prod}}.
@findex \realdiv
@item \realdiv @{@var{value1}@} @{@var{value2}@} \@var{result}
Divide two real quantities, assigning the resultant character string
representing the result of @var{value1}/@var{value2} to the macro
@code{\@var{result}}.
@end table

@node Arrow curve, , Real arithmetic, TeXdraw Toolbox
@appendixsec Arrow curve
@cindex example, arrow curve

This example illustrates the use of the @TeX{}draw toolbox routines to
do computations with the coordinates.  The problem will be tackled in
two parts.  First, we will produce a macro to place an arrowhead on a
Bezier curve.  Then given this macro, we will produce a macro which can
draw a ``wiggly'' line from the current position to a given coordinate.

@tex
\bigskip
\def\cavec (#1 #2)(#3 #4)(#5 #6){
  \clvec (#1 #2)(#3 #4)(#5 #6)
  \cossin (#3 #4)(#5 #6)\cosa\sina
  \rmove (0 0) % stroke the Bezier curve
  \bsegment
    \drawdim in \setsegscale 0.05
    \move ({-\cosa} -\sina)  \avec (0 0)
  \esegment}

\def\caw (#1 #2){
  \currentpos \xa\ya
  \cossin ({\xa} \ya)(#1 #2)\cosa\sina

% The nominal wiggly curve is (0 0) (1+dx dy) (-dx -dy) (1 0)
% Find the rotated offset (dx dy) -> (du dv)
  \rotatecoord (0.4 0.1)\cosa\sina \du\dv

% calculate the length of the vector
  \vectlen ({\xa} \ya)(#1 #2)\len

% draw the curve in normalized units
  \bsegment
    \setsegscale {\len}
    \realadd \cosa \du \tmpa  \realadd \sina \dv \tmpb
    \cavec ({\tmpa} \tmpb)({-\du} -\dv)({\cosa} \sina)
  \esegment

  \move (#1 #2)}

% rotate a coordinate (x y)
% arguments: (x y) cosa sina x' y'
%  x' = cosa * x - sina * y;  y' = sina * x + cosa * y
\def\rotatecoord (#1 #2)#3#4#5#6{
  \getpos (#1 #2)\xarg\yarg
  \realmult \xarg {#3} \tmpa  \realmult \yarg {#4} \tmpb
  \realadd \tmpa {-\tmpb} #5
  \realmult \xarg {#4} \tmpa  \realmult \yarg {#3} \tmpb
  \realadd \tmpa \tmpb #6}

\centertexdraw{
  \arrowheadtype t:W
  \move (0 0)
  \cavec (1.4 0.1)(-0.4 -0.1)(1 0)
  \move (1 0) \caw (1 1) \htext{tip at \tt (1 1)}
  \move (1 0) \caw (2 1) \htext{tip at \tt (2 1)}
  \move (1 0) \caw (2 0) \htext{tip at \tt (2 0)}
  \move (0 1.13) \move (0 -0.04)
}
@end tex

The first macro, @code{\cavec}, uses the @code{\cossin} command to
determine the the cosine and sine of the angle of the line joining the
second control point to the end point of the Bezier curve.  Recall that
the Bezier curve is tangent to this line at the end point.  After
drawing the Bezier curve, the scaling is set locally to absolute units
of 0.05 inches.  We go back down the line from the end point by 0.05
inches and draw an arrow vector to the end point from there.  This arrow
vector is mostly arrowhead, with little or no tail.

@example
@group
\def\cavec (#1 #2)(#3 #4)(#5 #6)@{
  \clvec (#1 #2)(#3 #4)(#5 #6)
  \cossin (#3 #4)(#5 #6)\cosa\sina
  \rmove (0 0)
  \bsegment
    \drawdim in \setsegscale 0.05
    \move (@{-\cosa@} -\sina)  \avec (0 0)
  \esegment@}
@end group
@end example

Note the use of macros as arguments to a @code{\move} command.  Minus
signs are put in front of the macros.  However, the value of the macro
@code{\cosa} or @code{\sina} could be negative.  Fortunately, @TeX{}
accepts two minus signs in a row and interprets the result as positive.
Note that the @code{\rmove (0 0)} command before the beginning of the
segment ensures that the Bezier curve is stroked before the arrowhead is
drawn.

The second macro @code{\caw} builds on @code{\cavec}.  The goal is to
produce a wiggly vector that can be used as a pointer in a drawing.
Consider the following symmetrical normalized Bezier curve.
@example
\centertexdraw@{ \move (0 0) \cavec (1.4 0.1)(-0.4 -0.1)(1 0) @}
@end example

This curve has the appropriate wiggle.  Now we want to be able to draw
this curve, appropriately scaled and rotated.  The macro @code{\caw}
needs to do computations on the coordinates.  First, @code{\caw} uses
the macros @code{\getpos} and @code{\currentpos} to get the positions of
the end and start of the curve.  Next, the length of the vector is
calculated using the macro @code{\vectlen}.  A local macro
@code{\rotatecoord} is used to rotate a coordinate pair about the
origin, using the cosine and sine of the rotation angle.  The vector
length is used to scale the normalized curve.  The remaining code draws
the rotated, normalized curve.

@example
\def\caw (#1 #2)@{
  \currentpos \xa\ya
  \cossin (@{\xa@} \ya)(#1 #2)\cosa\sina

% The nominal wiggly curve is (0 0) (1+dx dy) (-dx -dy) (1 0)
% Find the rotated offset (dx dy) -> (du dv)
  \rotatecoord (0.4 0.1)\cosa\sina \du\dv

% calculate the length of the vector
  \vectlen (@{\xa@} \ya)(#1 #2)\len

% draw the curve in normalized units
  \bsegment
    \setsegscale @{\len@}
    \realadd \cosa \du \tmpa  \realadd \sina \dv \tmpb
    \cavec (@{\tmpa@} \tmpb)(@{-\du@} -\dv)(@{\cosa@} \sina)
  \esegment
  \move (#1 #2)@}

% rotate a coordinate (x y)
% arguments: (x y) cosa sina x' y'
%  x' = cosa * x - sina * y;  y' = sina * x + cosa * y
\def\rotatecoord (#1 #2)#3#4#5#6@{
  \getpos (#1 #2)\xarg\yarg
  \realmult \xarg @{#3@} \tmpa  \realmult \yarg @{#4@} \tmpb
  \realadd \tmpa @{-\tmpb@} #5
  \realmult \xarg @{#4@} \tmpa  \realmult \yarg @{#3@} \tmpb
  \realadd \tmpa \tmpb #6@}
@end example

Finally, the new macro can be used as follows.
@example
\centertexdraw@{
  \arrowheadtype t:W
  \move (0 0)
  \cavec (1.4 0.1)(-0.4 -0.1)(1 0)
  \move (1 0) \caw (1 1) \htext@{tip at \tt (1 1)@}
  \move (1 0) \caw (2 1) \htext@{tip at \tt (2 1)@}
  \move (1 0) \caw (2 0) \htext@{tip at \tt (2 0)@}

@}
@end example

Note that the Bezier curve in the macro @code{\cavec} lies below the
arrowhead.  The example then draws an arrowhead of type @code{W} to
erase the part of the line below the arrowhead.

@node Examples, Command Listing, TeXdraw Toolbox, Top
@appendix Examples
@cindex example, block diagram

This appendix shows examples of the use of @TeX{}draw.

@menu
* Block diagram::
* Filter response graph::
* Geometric construction::
@end menu

@node Block diagram, Filter response graph, , Examples
@appendixsec Block diagram of a lattice filter

The block diagram of a lattice filter uses a library of extended
commands built from the basic @TeX{}draw commands.

@tex
\bigskip
\bigskip
\def\delay {\bsegment
              \setsegscale 0.3
              \lvec (0 +0.5) \lvec (1 +0.5) \lvec (1 -0.5)
              \lvec (0 -0.5) \lvec (0 0)
              \textref h:C v:C  \htext (0.5 0){$z^{-1}$}
              \savepos (1 0)(*ex *ey)
            \esegment
            \move (*ex *ey)}
\def\bdot {\fcir f:0 r:0.02 }
\def\Ttext #1{\bsegment
                \textref h:C v:B  \htext (0 +0.06){#1}
              \esegment}
\def\Btext #1{\bsegment
                \textref h:C v:T  \htext (0 -0.06){#1}
              \esegment}
\def\Ltext #1{\bsegment
                \textref h:R v:C  \htext (-0.06 0){#1}
              \esegment}
\def\Rtext #1{\bsegment
                \textref h:L v:C  \htext (+0.06 0){#1}
              \esegment}
\def\cradius {0.08}
\def\pluss {\bsegment
              \setsegscale {\cradius}
              \move (-0.5 0) \lvec (+0.5 0)
              \move (0 -0.5) \lvec (0 +0.5)
            \esegment}
\def\pcir {\lcir r:{\cradius} \pluss}
\def\puttext (#1 #2)#3{\bsegment
                         \setsegscale {\cradius}
                         \textref h:C v:C \htext (#1 #2){#3}
                       \esegment}
\def\putwnw #1{\puttext (-1.7 +1.2){#1}}
\def\putwsw #1{\puttext (-1.7 -1.2){#1}}
\def\putn   #1{\puttext ( 0   +2  ){#1}}
\def\puts   #1{\puttext ( 0   -2  ){#1}}
\def\avectoc (#1 #2){\currentpos \xa\ya
                     \cossin ({\xa} \ya)(#1 #2)\cosa\sina
                     \savepos (#1 #2)(*tx *ty)
                     \bsegment
                       \move (*tx *ty)
                       \setsegscale {\cradius}
                       \rmove ({-\cosa} -\sina)
                       \savecurrpos (*ex *ey)
                     \esegment
                     \avec (*ex *ey)
                     \move (#1 #2)}
\def\avecfrc (#1 #2){\currentpos \xa\ya
                     \cossin ({\xa} \ya)(#1 #2)\cosa\sina
                     \bsegment
                       \setsegscale {\cradius}
                       \move ({\cosa} \sina)
                       \savecurrpos (*ex *ey)
                     \esegment
                     \move (*ex *ey)
                     \avec (#1 #2)}

\centertexdraw{
\drawdim in
\arrowheadtype t:F  \arrowheadsize l:0.08 w:0.04
\def\pl {$\scriptscriptstyle +$} \def\mn {$\scriptscriptstyle -$}

\move (0 +0.63) \move (0 -0.60) % compensate for the text size
\move (0 0)

% Input to the first stage
\bsegment
  \Ltext{$x(n)$}
  \lvec (0.3 0) \bdot \lvec (0.3 +0.4)
  \move (0.3 0) \lvec (0.3 -0.4)
  \savepos (0.3 0)(*ex *ey)
\esegment
\move (*ex *ey)

% first lattice stage
\bsegment
  \move (0 +0.4)  \avectoc (1.7 +0.4)
  \pcir \putwnw{\pl} \puts{\mn}
  \avecfrc (2.1 +0.4)
  \move (0 -0.4)  \avec (0.4 -0.4) \delay \avectoc (1.7 -0.4)
  \pcir \putwsw{\pl} \putn{\mn}
  \avecfrc (2.1 -0.4)
  \move (0.9 +0.4)  \bdot  \avectoc (1.7 -0.4)
  \move (0.9 -0.4)  \bdot  \avectoc (1.7 +0.4)
  \move (0.1 +0.42) \Ttext {$f_0(n)$}
  \move (2.0 +0.42) \Ttext {$f_1(n)$}
  \move (0.1 -0.4)  \Btext {$b_0(n)$}
  \move (2.0 -0.4)  \Btext {$b_1(n)$}
  \textref h:L v:B  \htext (1.15 +0.2){$K_1$}
  \textref h:L v:T  \htext (1.15 -0.2){$K_1$}
  \savepos (2.1 0)(*ex *ey)
\esegment
\move (*ex *ey)

% center section
\bsegment
  \textref h:C v:C
  \htext (0.3 +0.4){$\cdots$}
  \htext (0.3 -0.4){$\cdots$}
  \savepos (0.6 0)(*ex *ey)
\esegment
\move (*ex *ey)

% last lattice stage
\bsegment
  \move (0 +0.4)  \avectoc (1.7 +0.4)
  \pcir \putwnw{\pl} \puts{\mn}
  \avecfrc (2.3 +0.4) \Rtext{$e(n)$}
  \move (0 -0.4)  \avec (0.4 -0.4) \delay \avectoc (1.7 -0.4)
  \pcir \putwsw{\pl} \putn{\mn}
  \avecfrc (2.1 -0.4)
  \move (0.9 +0.4)  \bdot  \avectoc (1.7 -0.4)
  \move (0.9 -0.4)  \bdot  \avectoc (1.7 +0.4)
  \move (0.1 +0.42) \Ttext {$f_{P-1}(n)$}
  \move (2.0 +0.42) \Ttext {$f_P(n)$}
  \move (0.1 -0.4)  \Btext {$b_{P-1}(n)$}
  \move (2.0 -0.4)  \Btext {$b_P(n)$}
  \textref h:L v:B  \htext (1.15 +0.2){$K_P$}
  \textref h:L v:T  \htext (1.15 -0.2){$K_P$}
\esegment
}
\bigskip
@end tex

The block diagram uses a ``delay'' block.  This is defined as a segment
which leaves the current position at the end of this block.  A second
macro, @code{\bdot}, draws a ``big'' dot which is used to mark junctions
of lines.  The @code{\Ttext} command centers text above a given point.
The offset to position the text is local to a segment, resulting in no
change to the current point.  Similar macros to position text below a
point (@code{\Btext}), to the left of a point (@code{\Ltext}) and to the
right of a point (@code{\Rtext}) are used in the final drawing.
@example
\def\delay @{\bsegment
              \setsegscale 0.3
              \lvec (0 +0.5) \lvec (1 +0.5) \lvec (1 -0.5)
              \lvec (0 -0.5) \lvec (0 0)
              \textref h:C v:C  \htext (0.5 0)@{$z^@{-1@}$@}
              \savepos (1 0)(*ex *ey)
            \esegment
            \move (*ex *ey)@}
\def\bdot @{\fcir f:0 r:0.02 @}
\def\Ttext #1@{\bsegment
                \textref h:C v:B  \htext (0 +0.06)@{#1@}
              \esegment@}
@end example

Several of the block diagram elements scale with the size of the summing
nodes.  The radius of the circles for the summing nodes is defined as
the macro @code{\cradius}.  The summing nodes will have enclosed plus
signs, appropriately scaled.  The plus sign is drawn by the macro
@code{\pluss}.  The macro @code{\pcir} draws both the circle and the
plus sign.  The incoming lines to a summing node will be labelled with
plus or minus signs (characters this time), placed at the appropriate
position with respect to the center of the summing node.  These
positions are given in terms of compass directions.  The macro
@code{\putwnw} places text west by north-west relative to the center of
the summing node.
@example
\def\cradius @{0.08@}
\def\pluss @{\bsegment
               \setsegscale @{\cradius@}
               \move (-0.5 0) \lvec (+0.5 0)
               \move (0 -0.5) \lvec (0 +0.5)
             \esegment@}
\def\pcir @{\lcir r:@{\cradius@} \pluss@}
\def\puttext (#1 #2)#3@{\bsegment
                         \setsegscale @{\cradius@}
                         \textref h:C v:C \htext (#1 #2)@{#3@}
                       \esegment@}
\def\putwnw #1@{\puttext (-1.7 +1.2)@{#1@}@}
@end example

The block diagram has vectors arriving and departing from the summing
nodes (circles).  One could calculate the points of intersection of the
lines with the circles, and then enter the values into the @TeX{}draw
code.  However, in this example, we implement an automated procedure.
Two macros are needed, an arrow vector to a circle (@code{\avectoc}) and
an arrow vector leaving from a circle (@code{\avecfrc}).  The macros
will calculate the point of intersection with the circle and start or
end the vector at the intersection point.

The arrow macros use scaling and relative positioning inside of a
drawing segment.  In the case of the macro @code{\avectoc}, a move is
made to the final point (center of the circle), then within a drawing
segment, a scaled move is made back towards the initial point to
determine the intersection point with the circle.

@example
\def\avectoc (#1 #2)@{\currentpos \xa\ya
                     \cossin (@{\xa@} \ya)(#1 #2)\cosa\sina
                     \savepos (#1 #2)(*tx *ty)
                     \bsegment
                       \move (*tx *ty)
                       \setsegscale @{\cradius@}
                       \rmove (@{-\cosa@} -\sina)
                       \savecurrpos (*ex *ey)
                     \esegment
                     \avec (*ex *ey)
                     \move (#1 #2)@}
\def\avecfrc (#1 #2)@{\currentpos \xa\ya
                     \cossin (@{\xa@} \ya)(#1 #2)\cosa\sina
                     \bsegment
                       \setsegscale @{\cradius@}
                       \move (@{\cosa@} \sina)
                       \savecurrpos (*ex *ey)
                     \esegment
                     \move (*ex *ey)
                     \avec (#1 #2)@}
@end example

Having defined these macros, we are ready to draw the block diagram.
The first and last sections of the lattice filter are very similar,
differing mainly in the text labels.  With more effort, code could be
shared between the commands used to draw these blocks.
@example
\centertexdraw@{
\drawdim in
\arrowheadtype t:F  \arrowheadsize l:0.08 w:0.04
\def\pl @{$\scriptscriptstyle +$@} \def\mn @{$\scriptscriptstyle -$@}

\move (0 +0.63) \move (0 -0.60) % compensate for the text size
\move (0 0)

% Input to the first stage
\bsegment
  \Ltext@{$x(n)$@}
  \lvec (0.3 0) \bdot \lvec (0.3 +0.4) \move (0.3 0) \lvec (0.3 -0.4)
  \savepos (0.3 0)(*ex *ey)
\esegment
\move (*ex *ey)

% first lattice stage
\bsegment
  \move (0 +0.4)  \avectoc (1.7 +0.4)
  \pcir \putwnw@{\pl@} \puts@{\mn@}
  \avecfrc (2.1 +0.4)
  \move (0 -0.4)  \avec (0.4 -0.4) \delay \avectoc (1.7 -0.4)
  \pcir \putwsw@{\pl@} \putn@{\mn@}
  \avecfrc (2.1 -0.4)
  \move (0.9 +0.4)  \bdot  \avectoc (1.7 -0.4)
  \move (0.9 -0.4)  \bdot  \avectoc (1.7 +0.4)
  \move (0.1 +0.42) \Ttext @{$f_0(n)$@}
  \move (2.0 +0.42) \Ttext @{$f_1(n)$@}
  \move (0.1 -0.4)  \Btext @{$b_0(n)$@}
  \move (2.0 -0.4)  \Btext @{$b_1(n)$@}
  \textref h:L v:B  \htext (1.15 +0.2)@{$K_1$@}
  \textref h:L v:T  \htext (1.15 -0.2)@{$K_1$@}
  \savepos (2.1 0)(*ex *ey)
\esegment
\move (*ex *ey)

% center section
\bsegment
  \textref h:C v:C \htext (0.3 +0.4)@{$\cdots$@}
  \htext (0.3 -0.4)@{$\cdots$@}
  \savepos (0.6 0)(*ex *ey)
\esegment
\move (*ex *ey)

% last lattice stage
\bsegment
  \move (0 +0.4)  \avectoc (1.7 +0.4)
  \pcir \putwnw@{\pl@} \puts@{\mn@}
  \avecfrc (2.3 +0.4) \Rtext@{$e(n)$@}
  \move (0 -0.4)  \avec (0.4 -0.4) \delay \avectoc (1.7 -0.4)
  \pcir \putwsw@{\pl@} \putn@{\mn@}
  \avecfrc (2.1 -0.4)
  \move (0.9 +0.4)  \bdot  \avectoc (1.7 -0.4)
  \move (0.9 -0.4)  \bdot  \avectoc (1.7 +0.4)
  \move (0.1 +0.42) \Ttext @{$f_@{P-1@}(n)$@}
  \move (2.0 +0.42) \Ttext @{$f_P(n)$@}
  \move (0.1 -0.4)  \Btext @{$b_@{P-1@}(n)$@}
  \move (2.0 -0.4)  \Btext @{$b_P(n)$@}
  \textref h:L v:B  \htext (1.15 +0.2)@{$K_P$@}
  \textref h:L v:T  \htext (1.15 -0.2)@{$K_P$@}
\esegment
@}
@end example

The macros used in this example are similar to the block diagram macros
defined in the file @file{blockdiagram.tex}.

@node Filter response graph, Geometric construction, Block diagram, Examples
@appendixsec Filter response graph
@cindex example, graph

This example shows the response of a canonical filter.  @TeX{}draw is
not well suited for general purpose graphing --- it has no coordinate
translation facility nor does it have separate @var{x} and @var{y}
scaling.  Nonetheless, for certain simple graphs, @TeX{}draw is
adequate.

@tex
\bigskip
\centertexdraw{
\arrowheadtype t:F  \arrowheadsize l:0.08 w:0.04
\def\ds {\displaystyle}
\def\ticklab (#1 #2)#3{\move(#1 #2)
                       \bsegment
                         \lvec (0 0.05)
                         \textref h:C v:T \htext (0 -0.05){#3}
                       \esegment}
\def\Rtext #1{\bsegment
                \textref h:L v:C \htext ( 0.08 0){#1}
              \esegment}

\move (2.4 -0.32)    % move to set the size

\move (0 0)
% Axes
\avec (0  1.4)
\move (0 0) \avec (2.2 0) \Rtext{$\omega$}
\ticklab (0 0)   {0}
\ticklab (0.8 0) {$\ds {\pi \over  2N} $}
\ticklab (1.2 0) {$\omega_s$}
\ticklab (1.6 0) {$\ds {\pi \over N} $}

\linewd 0.025
\move (0 1)
\lvec (0.4 1)
\lvec (0.44 0.998)
\lvec (0.48 0.988)
\lvec (0.52 0.973)
\lvec (0.56 0.951)
\lvec (0.60 0.923)
\lvec (0.64 0.891)
\lvec (0.68 0.852)
\lvec (0.72 0.809)
\lvec (0.76 0.760)
\lvec (0.80 0.707)
\lvec (0.84 0.649)
\lvec (0.88 0.587)
\lvec (0.92 0.522)
\lvec (0.96 0.454)
\lvec (1.00 0.382)
\lvec (1.04 0.309)
\lvec (1.08 0.233)
\lvec (1.12 0.156)
\lvec (1.16 0.078)
\lvec (1.20 0)
\lvec (1.9 0)
}
\bigskip
@end tex

In this example, macro @code{\ticklab} places a labelled axis tick at a
given position.  The data is specified in a straightforward manner,
having been scaled beforehand to give the desired aspect ratio for the
graph.

@example
\centertexdraw@{
\arrowheadtype t:F  \arrowheadsize l:0.08 w:0.04
\def\ds @{\displaystyle@}
\def\ticklab (#1 #2)#3@{\move(#1 #2)
                       \bsegment
                         \lvec (0 0.05)
                         \textref h:C v:T \htext (0 -0.05)@{#3@}
                       \esegment@}
\def\Rtext #1@{\bsegment
                \textref h:L v:C \htext (+0.08 0)@{#1@}
              \esegment@}

\move (2.4 -0.3)    % move to set the size

\move (0 0)
% Axes
\avec (0 +1.4)
\move (0 0) \avec (2.2 0) \Rtext@{$\omega$@}
\ticklab (0 0)   @{0@}
\ticklab (0.8 0) @{$\ds @{\pi \over 2N@} $@}
\ticklab (1.2 0) @{$\omega_s$@}
\ticklab (1.6 0) @{$\ds @{\pi \over N@} $@}

\linewd 0.025
\move (0 1)
\lvec (0.4 1)
\lvec (0.44 0.998)
\lvec (0.48 0.988)
\lvec (0.52 0.973)
\lvec (0.56 0.951)
 ...
\lvec (1.08 0.233)
\lvec (1.12 0.156)
\lvec (1.16 0.078)
\lvec (1.20 0)
\lvec (1.9 0)
@}
@end example

@node Geometric construction, , Filter response graph, Examples
@appendixsec Geometric construction
@cindex example, circle and ellipse

This example shows a geometric construction which places an ellipse
tangent to an enclosing circle.  The size of the ellipse is determined
from geometric considerations.  Macros are used to modularize the code.
The example alters the unit scale factor.  This allows the drawing to be
carried out in units normalized to the radius of the circle.

@tex
\bigskip
\centertexdraw{
\arrowheadtype t:V \arrowheadsize l:0.08 w:0.04
\linewd 0.01
\setunitscale 1.5            % circle will have radius 1.5 inches

\def\Btext #1{\bsegment
                \textref h:C v:T \htext (0 -0.04){#1}
              \esegment}
\def\Ttext #1{\bsegment
                \textref h:C v:B \htext (0  0.04){#1}
              \esegment}
\def\Ltext #1{\bsegment
                \textref h:R v:C \htext (-0.04 0){#1}
              \esegment}
\def\bdot {\fcir f:0 r:0.0133 }
\def\vtick {\bsegment
              \move (0 -0.05) \lvec (0  0.05)
            \esegment}
\def\htick {\bsegment
              \move (-0.05 0) \lvec ( 0.05 0)
            \esegment}
\def\Hlen #1#2{\bsegment
                 \vtick \avec ({#1} 0) \vtick \avec (0 0)
                 \relsegscale 0.5
                 \move ({#1} 0) \Ttext {#2}
               \esegment}
\def\Vlen #1#2{\bsegment
                 \htick \avec (0 {#1}) \htick \avec (0 0)
                 \relsegscale 0.5
                 \move (0 {#1}) \Ltext {#2}
               \esegment}

\lcir r:1                         % circle
\move (-1.05 0) \lvec ( 1.05 0)   % axes
\move (0 -1.05) \lvec (0  1.05)

\move (0 0) \lvec (0.707 0.707) \bdot
\rmove (0.02 0.02) \textref h:L v:B \htext {X}
\move (0.707 -0.707) \bdot
\textref h:R v:T \htext(-0.02 -0.02){O}

\move (0.5 0)                     % center of ellipse
\bsegment
  \lellip rx:0.435 ry:0.804
  \bdot \Btext {$\beta_2$}
  \move (0 0.15) \Hlen {0.435}{$|\beta_1{+}\beta_3|$}
  \move (-0.7 0) \Vlen {0.804}{$|\beta_1{-}\beta_3|$}
\esegment
}
\bigskip
@end tex
@example
\centertexdraw@{
\arrowheadtype t:V \arrowheadsize l:0.08 w:0.04
\linewd 0.01
\setunitscale 1.5            % circle will have radius 1.5 inches

\def\Btext #1@{\bsegment
                \textref h:C v:T \htext (0 -0.04)@{#1@}
              \esegment@}
\def\Ttext #1@{\bsegment
                \textref h:C v:B \htext (0 +0.04)@{#1@}
              \esegment@}
\def\Ltext #1@{\bsegment
                \textref h:R v:C \htext (-0.04 0)@{#1@}
              \esegment@}
\def\bdot @{\fcir f:0 r:0.0133 @}
\def\vtick @{\bsegment
              \move (0 -0.05) \lvec (0 +0.05)
            \esegment@}
\def\htick @{\bsegment
              \move (-0.05 0) \lvec (+0.05 0)
            \esegment@}
\def\Hlen #1#2@{\bsegment
                 \vtick \avec (@{#1@} 0) \vtick \avec (0 0)
                 \relsegscale 0.5
                 \move (@{#1@} 0) \Ttext @{#2@}
               \esegment@}
\def\Vlen #1#2@{\bsegment
                 \htick \avec (0 @{#1@}) \htick \avec (0 0)
                 \relsegscale 0.5
                 \move (0 @{#1@}) \Ltext @{#2@}
               \esegment@}

\lcir r:1                         % circle
\move (-1.05 0) \lvec ( 1.05 0)   % axes
\move (0 -1.05) \lvec (0  1.05)

\move (0 0) \lvec (0.707 0.707) \bdot
\rmove (0.02 0.02) \textref h:L v:B \htext @{X@}
\move (0.707 -0.707) \bdot
\textref h:R v:T \htext(-0.02 -0.02)@{O@}

\move (0.5 0)                     % center of ellipse
\bsegment
  \lellip rx:0.435 ry:0.804
  \bdot \Btext @{$\beta_2$@}
  \move (0 0.15) \Hlen @{0.435@}@{$|\beta_1@{+@}\beta_3|$@}
  \move (-0.7 0) \Vlen @{0.804@}@{$|\beta_1@{-@}\beta_3|$@}
\esegment
@}
@end example


@node Command Listing, Command Index, Examples, Top
@appendix Alphabetic listing of commands
@cindex listing of commands

@table @code

@item \arrowheadsize l:@var{length} w:@var{width}
Set the arrowhead size to be @var{length} units long and @var{width}
units wide.  The width is measured across the ``base'' of the arrowhead.
The initial arrowhead size has a @var{length} of 0.16 inches and a
@var{width} of 0.08 inches.

@item \arrowheadtype t:@var{type}
Set the arrowhead type to @var{type}, where @var{type} is one of
@code{F}, @code{T}, @code{W}, @code{V}, or @code{H}.  There are two
kinds of arrowheads.  The first kind is a triangle.  There are 3
variants: type @code{T} is an empty triangle, type @code{F} is a filled
triangle (using the current gray level for lines), type @code{W} is a
triangle filled with white.  The second kind of arrowhead is an open
ended Vee.  There are 2 variants: type @code{V} has the stem continue to
the tip, type @code{H} has the stem stop at the base of the arrowhead.
The initial arrowhead type is @code{T}.

@item \avec (@var{x} @var{y})
Draw a line with an arrowhead from the current position to
@code{(@var{x} @var{y})}.  The new current position is @code{(@var{x}
@var{y})}.  The arrowhead is aligned with the line, with the tip at
@code{(@var{x} @var{y})}.

@item \begin@{texdraw@}
Start a @TeX{}draw drawing.  The drawing is terminated with an
@code{\end@{texdraw@}} command.  This command is for use with La@TeX{}.

@item \bsegment
Start a drawing segment.  The coordinate system is shifted such that the
current position corresponds to the coordinate @code{(0 0)}.  Changes to
scaling, position and line parameters stay local to the drawing segment.

@item \btexdraw
Start a @TeX{}draw drawing.  The drawing is terminated with an
@code{\etexdraw} command.

@item \centertexdraw @{ ... @}
Center a @TeX{}draw box.  The argument contains @TeX{}draw commands.
The resulting box has the horizontal size @code{\hsize} and height equal
to the height of the drawing.

@item \clvec (@var{x1} @var{y1})(@var{x2} @var{y2})(@var{x3} @var{y3})
Draw a Bezier curve from the current position to the coordinate
@code{(@var{x3} @var{y3})} which becomes the new current position.  The
coordinates @code{(@var{x1} @var{y1})} and @code{(@var{x2} @var{y2})}
serve as control points for the curve.  Only the last coordinate given
is used to update the size of the drawing.

@item \drawbb
Draw a ruled box around the effective size of a drawing produced by
@TeX{}draw commands.

@item \drawdim @var{dim}
Set the units to @var{dim}.  The argument @var{dim} can be any valid
@TeX{} dimension unit.  The units are used to interpret coordinate
values.  Examples of valid units: @code{cm}, @code{mm}, @code{in},
@code{pt}, and @code{bp}.

@item \end@{texdraw@}
End a @TeX{}draw drawing started with a @code{\begin@{texdraw@}}
command.  The resulting @TeX{}draw drawing is placed in a box with
height equal to the height of the drawing and width equal to the width
of the drawing.  The depth of the box is zero.  This command is for use
with La@TeX{}.

@item \esegment
End a drawing segment.  The current position in effect before the
corresponding @code{\bsegment} command is restored.  The scaling and
line parameter values revert to those in effect before the corresponding
@code{\bsegment} was invoked.

@item \etexdraw
End a @TeX{}draw drawing started with a @code{\btexdraw} command.  The
resulting @TeX{}draw drawing is placed in a box with height equal to the
height of the drawing and width equal to the width of the drawing.  The
depth of the box is zero.

@item \everytexdraw @{ ... @}
Specify @TeX{}draw commands to be executed at the beginning of every
@TeX{}draw drawing.

@item \fcir f:@var{level} r:@var{radius}
Draw a filled circle with center at the current position.  The radius is
specified by @var{radius}.  The circle is painted with the gray level
specified by @var{level}.  A gray level of 1 corresponds to white, with
decreasing values getting darker.  The level 0 is full black.  This
command does not draw a line along the circumference.  The drawing size
is increased if necessary to contain the circle.

@item \fellip f:@var{level} rx:@var{x-radius} ry:@var{y-radius}
Draw a filled ellipse with center at the current position.  The radius
in the @var{x} direction is specified by @var{x-radius}.  The radius in
the @var{y} direction is specified by @var{y-radius}.  The ellipse is
painted with the gray level specified by @var{level}.  A gray level of 1
corresponds to white, with decreasing values getting darker.  The level
0 is full black.  This command does not draw a line along the boundary
of the ellipse.  The drawing size is increased if necessary to contain
the ellipse.

@item \htext (@var{x} @var{y})@{@var{text}@}
@itemx \htext @{@var{text}@}
The first form of this command places the @TeX{} text @var{text}
horizontally with the text reference point at the coordinate
@code{(@var{x} @var{y})}.  The new current position is @code{(@var{x}
@var{y})}.  The second form of this command places the @TeX{} text
@var{text} horizontally with the text reference point at the current
position.  The text reference point is set with the @code{\textref}
command.

@item \ifill f:@var{level}
Close the current path and paint the interior of the region with gray
level @var{level}.  The line around the path is not drawn.  Gray levels
are real values from 0 (black) through intermediate values (grays) to 1
(white).

@item \larc r:@var{radius} sd:@var{start-angle} ed:@var{end-angle}
Draw a counterclockwise arc.  The center of the arc is at the current
position.  The radius is specified by @var{radius}.  The start and end
angles (in degrees) are specified by @var{start-angle} and
@var{end-angle}.  This command does not affect the limits (size) of the
drawing.

@item \lcir r:@var{radius}
Draw a circle with center at the current position.  The radius is
specified by @var{radius}.  This command draws a line along the
circumference of the circle.  The drawing size is increased if necessary
to contain the circle.

@item \lellip rx:@var{x-radius} ry:@var{y-radius}
Draw an ellipse with center at the current position.  The radius in the
@var{x} direction is specified by @var{x-radius}.  The radius in the
@var{y} direction is specified by @var{y-radius}.  The drawing size is
increased if necessary to contain the ellipse.

@item \lfill f:@var{level}

Close the current path, draw the line around the path using the current
grey level for lines and paint the interior of the region with specified
gray level @var{level}.  Gray levels are real values from 0 (black)
through intermediate values (grays) to 1 (white).

@item \linewd @var{width}
Set the line width to @var{width} units.  Initially @var{width} is 0.01
inches (corresponding to 3 pixels at 300 pixels to the inch).

@item \lpatt (@var{pattern})
Set lines to have the pattern @code{(@var{pattern})}.  A pattern is a
sequence of on/off lengths separated by blanks and enclosed in parentheses.
The lengths alternately specify the length of a dash and the length of a
gap between dashes.  Each length is interpreted using the current
scaling and drawing units.  The pattern is used cyclically.  The empty
pattern signifies a solid line.  The initial line pattern is a solid
line, corresponding to the empty pattern @code{\lpatt ()}.

@item \lvec (@var{x} @var{y})
Draw a line from the current position to coordinate @code{(@var{x}
@var{y})}.  The new current position is @code{(@var{x} @var{y})}.

@item \move (@var{x} @var{y})
Move to coordinate @code{(@var{x} @var{y})}.  The new current position
is @code{(@var{x} @var{y})}.

@item \ravec (@var{dx} @var{dy})
Draw a line with an arrowhead from the current position, @var{dx} units
in the @var{x} direction and @var{y} units in the @var{y} direction.
The final position becomes the new current position.  The arrowhead is
aligned with the line, with the tip at the new current position.

@item \relsegscale @var{value}
Adjust the segment scale factor by multiplying by @var{value}.  This has
the effect of multiplying the current overall scale factor by the same
factor.  The overall scaling factor is the product of the unit scale
factor and the segment scale factor.

@item \relunitscale @var{value}
Adjust the unit scale factor by multiplying by @var{value}.  This has
the effect of multiplying the overall scale factor by the same factor.
The overall scaling factor is the product of the unit scale factor and
the segment scale factor.

@item \rlvec (@var{dx} @var{dy})
Draw a line from the current position, @var{dx} units in the @var{x}
direction and @var{dy} units in the @var{y} direction.  The final
position becomes the new current position.

@item \rmove (@var{dx} @var{dy})
Move from the current position, @var{dx} units in the @var{x} direction
and @var{dy} units in the @var{y} direction.  The final position becomes
the new current position.

@item \rtext td:@var{angle} (x y)@{@var{text}@}
@itemx \rtext td:@var{angle} @{@var{text}@}
The first form of this command places the @TeX{} text @var{text} at an
angle with the text reference point at the coordinate @code{(@var{x}
@var{y})}.  The new current position is @code{(@var{x} @var{y})}.  The
second form of this command places the @TeX{} text @var{text} at an
angle with the text reference point at the current position.  In both
cases, the @TeX{} text is placed in a box and the box is rotated
counterclockwise by @var{angle} degrees about the text reference point.
The text reference point is set with the @code{\textref} command.

@item \savecurrpos (*@var{px} *@var{py})
Save the current position as the absolute position referenced by
@code{(*@var{px} *@var{py})}.

@item \savepos (@var{x} @var{y})(*@var{px} *@var{py})
Save the coordinate position @code{(@var{x} @var{y})} as the absolute
position referenced by @code{(*@var{px} *@var{py})}.  The coordinate
@code{(@var{x} @var{y})} is interpreted in the normal fashion as a
coordinate relative to the current segment, using the current scaling
factors and drawing unit.

@item \setgray @var{level}
Set the gray level of lines.  Gray levels are real values from 0 (black)
through intermediate values (gray) to 1 (white).  The initial gray level
is 0 corresponding to black.

@item \setsegscale @var{scale}
Set the segment scale factor.  The argument @var{scale} is a real number
which is used to scale coordinate values.  The overall scale factor is
the product of the unit scale factor and the segment scale factor.

@item \setunitscale @var{scale}
Set the unit scaling to @var{scale}.  The argument @var{scale} is a real
number which is used to scale coordinate values.  The overall scaling
factor is the product of the unit scale factor and the segment scale
factor.

@item \textref h:@var{h-ref} v:@var{v-ref}
Set the text reference point for subsequent text commands.  The
horizontal reference point @var{h-ref} is one of @code{L}, @code{C} or
@code{R} (left, center or right).  The vertical reference point
@var{v-ref} is one of @code{T}, @code{C} or @code{B} (top, center or
bottom).  For rotated text, the reference point is determined before
rotation.  The initial text reference point corresponds to
@code{\textref h:L v:B}.

@item \vtext (x y)@{@var{text}@}
@itemx \vtext @{@var{text}@}
The first form of this command places the @TeX{} text @var{text}
vertically with the text reference point at the coordinate
@code{(@var{x} @var{y})}.  The new current position is @code{(@var{x}
@var{y})}.  The second form of this command places the @TeX{} text
@var{text} vertically with the text reference point at the current
position.  In both cases, the @TeX{} text is placed in a box and the box
is rotated counterclockwise by 90 degrees about the text reference
point.  The text reference point is set with the @code{\textref}
command.

@end table

@node Command Index, Concept Index, Command Listing, Top
@unnumbered Command Index
@printindex fn

@node Concept Index, , Command Index, Top
@unnumbered Concept Index
@printindex cp

@bye