summaryrefslogtreecommitdiff
path: root/graphics/asymptote/doc/FAQ/asy-faq.info
blob: 66de54d920d99cefdac87d5aeadceb8d2b63488b (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
Info file: asy-faq.info,    -*-Text-*-
produced by bfnnconv.pl from the Bizarre Format With No Name.

INFO-DIR-SECTION Languages
START-INFO-DIR-ENTRY
* asymptote FAQ: (asy-faq).    Asymptote Frequently Asked Questions.
END-INFO-DIR-ENTRY


File: asy-faq.info, Node: Top, Next: Question 1.1, Up: (dir)

            ASYMPTOTE FREQUENTLY ASKED QUESTIONS
                            2022-09-17
                          
This is the list of Frequently Asked Questions about Asymptote (asy).

Index

* Menu:
* Section 1::       About Asymptote
* Section 2::       Questions about installation and setup
* Section 3::       Questions about paths
* Section 4::       Questions about labels
* Section 5::       Questions about arrows
* Section 6::       Questions about 2D graphs
* Section 7::       Questions about programming
* Section 8::       Questions about differences between Asymptote and
                    MetaPost
* Section 9::       Questions about output

Section 1, About Asymptote
* Question 1.1::    What is Asymptote?
* Question 1.2::    How do I obtain Asymptote?
* Question 1.3::    Where can I ask questions about Asymptote?
* Question 1.4::    Why was the name Asymptote chosen?
* Question 1.5::    In the internal Asymptote source code, what does the
                    name camp refer to?

Section 2, Questions about installation and setup
* Question 2.1::    Is it possible to install Asymptote on Mac OS X?
* Question 2.2::    Why do I get the error Bad CPU type in executable on
                    installing Asymptote from the MAC OS binary?
* Question 2.3::    What do I do if I get the error: Error: pdfetex (file
                    pdftex.cfg): cannot open config file...texinfo.tex
                    appears to be broken?
* Question 2.4::    What do I do if I get the error: ! Undefined control
                    sequence. l.6 @copying?
* Question 2.5::    Is it possible to integrate Asymptote into LaTeX?
* Question 2.6::    Is it possible to integrate Asymptote into latex or
                    pdflatex?
* Question 2.7::    Do I need the tkinter package to install an Asymptote
                    rpm binary?
* Question 2.8::    What does the path %USERPROFILE%\.asy\config.asy mean?
* Question 2.9::    Why do I get the error "string not terminated" when I
                    try to set settings.dir="C:\asymptote\";?
* Question 2.10::   How do I change environment variables in Microsoft
                    Windows, for example, in order to change the default
                    PostScript viewer?
* Question 2.11::   Under Microsoft Windows XP, why do I get an error like
                    "Invalid Parameter - 432x432"?
* Question 2.12::   Why does Asymptote freeze upon trying to draw a label
                    with my MikTex installation under Microsoft Windows?

Section 3, Questions about paths
* Question 3.1::    Why do I get a syntax error message when I specify an
                    integer value for the path tension?
* Question 3.2::    Shouldn't dots always be the same size?

Section 4, Questions about labels
* Question 4.1::    How do I get Greek letters like omega to show up in my
                    labels?
* Question 4.2::    Can Asymptote use matrices as labels?
* Question 4.3::    How do I tell Asymptote to load a particular LaTeX
                    package, like mathptmx?
* Question 4.4::    How can I use international fonts in Asymptote labels?
* Question 4.5::    How can I use Fourier fonts?
* Question 4.6::    Is there any way to change the default appearance of
                    the decimal separator, using a comma instead of a dot?
* Question 4.7::    How can I get a rotated label with the filled box
                    rotated as well so that it fits the text?
* Question 4.8::    How can I rotate labels in a 3D figure?
* Question 4.9::    How can I draw some squares and circles of a fixed
                    size and put a label in the middle of them?
* Question 4.10::   The binary operator * can be used to scale the color
                    of a pen by a real number. Does this scaling factor
                    have to be less than 1?
* Question 4.11::   Why is the space after the comma decimal separator in
                    my locale so large?
* Question 4.12::   How can I prevent
                    texpreamble("\usepackage[pdftex]{hyperref}") from
                    changing the page size?

Section 5, Questions about arrows
* Question 5.1::    How do I draw two arrows at arbitrary positions along
                    a path?
* Question 5.2::    How do I reverse the direction of an arrowhead?
* Question 5.3::    How do I change the size of all arrows?
* Question 5.4::    Can I create other arrowhead styles?

Section 6, Questions about 2D graphs
* Question 6.1::    How can I draw x axis ticks on the right side, with
                    the tick labels on the left side (relative to the axis
                    path)?
* Question 6.2::    How can I reposition the x axis label to
                    three-quarters along the axis length?
* Question 6.3::    How can I move the x axis label down 10bp?
* Question 6.4::    Can I use different pens for the axis, the axis label,
                    and the tick labels?
* Question 6.5::    How can I change the font type of the axes label?
* Question 6.6::    How can I change the font type of the tick labels on
                    an axis?
* Question 6.7::    How can I prevent axes tick labels from rendering on
                    top of each other?
* Question 6.8::    How do I make the plot region of a graph, ignoring
                    labels and legends, have a fixed size?
* Question 6.9::    How can I plot a function f(x) within [0,1]x[0,2]
                    without explicitly calculating the x values for which
                    f(x) hits the boundary?
* Question 6.10::   Is it possible to define customized palettes?
* Question 6.11::   Is there an easy way to graph factorial functions
                    nicely?
* Question 6.12::   How do I indicate that a certain length should be
                    exactly the size I prescribe with no rescaling, within
                    a picture which has its own size?
* Question 6.13::   How can I make the y axis display base-2 logarithmic
                    values?
* Question 6.14::   How can I align the x axes of two graphs on the same
                    figure?
* Question 6.15::   How can I change the direction of the y-axis, such
                    that negatives values are on the upper y-axis?
* Question 6.16::   How can I fill a path with a function that defines the
                    color of each location?
* Question 6.17::   Is there a way to draw a function that is not
                    explicitly given, such as (y - 2)^2 = x - 1 ?
* Question 6.18::   Is it possible to reverse or stretch an axis?
* Question 6.19::   Why can't I use the UnFill option to draw graphs with
                    empty markers?
* Question 6.20::   How can I force several images to use the same palette
                    range (e.g. the entire 0-255 grayscale range)?

Section 7, Questions about programming
* Question 7.1::    Is Asymptote an interpreter or a compiler?
* Question 7.2::    What is the difference between a frame and a picture?
* Question 7.3::    What is the difference between a path and a guide?
* Question 7.4::    What is a convenient way to declare and initialize an
                    array of pictures?
* Question 7.5::    Is there a way to define functions that act on arrays
                    in general (i.e. work for arrays of any type)?
* Question 7.6::    Is there any way to declare structures ahead of their
                    definition, e.g. where struct A performs some
                    operation on struct B, but B contains an A member?
* Question 7.7::    Where are static variables in for loops allocated?
* Question 7.8::    Is there a debugger for asy?
* Question 7.9::    Do you accept patches for Asymptote?

Section 8, Questions about differences between Asymptote and
                    MetaPost
* Question 8.1::    What is the equivalent of the MetaPost c[a,b]
                    interpolation operator?
* Question 8.2::    How does picture scaling differ in Asymptote and
                    MetaPost?
* Question 8.3::    How can I avoid automatic scaling of a picture?
* Question 8.4::    What is the equivalent of MetaPost ... command?
* Question 8.5::    What is the equivalent of the MetaPost pickup command?
* Question 8.6::    What is the equivalent of the MetaPost whatever
                    command?
* Question 8.7::    What is the equivalent for the MetaPost command for
                    lray - horiz*v - verti*u = whatever*(LightSource - R),
                    a system of three linear equations for three unknowns:
                    horiz, verti, whatever?
* Question 8.8::    In MetaPost, it is possible to have a drawing remain
                    the same size in different pictures by defining a unit
                    u and explicitly multiply all the coordinates by u. Is
                    there a better way to do this in Asymptote?
* Question 8.9::    In MetaPost, one could produce tiling pictures by
                    generating a picture, and then clipping the picture to
                    a rectangle of fixed dimensions around the center of
                    the picture. How is that done in Asymptote?

Section 9, Questions about output
* Question 9.1::    How can I disable automatic invocation of the PS
                    viewer after an asy file is done processing?
* Question 9.2::    How do I output jpeg images?
* Question 9.3::    Can I embed bitmaps (photos) into my drawings and
                    position and scale them?
* Question 9.4::    Does Asymptote support direct PDF output?
* Question 9.5::    How to I produce large pictures of high quality in
                    raster format (e.g. png, giff etc).
* Question 9.6::    Is it possible to produce multi-page documents with
                    asymptote?



File: asy-faq.info, Node: Section 1, Next: Section 2, Previous: Top, Up: Top

About Asymptote

* Menu:
* Question 1.1::    What is Asymptote?
* Question 1.2::    How do I obtain Asymptote?
* Question 1.3::    Where can I ask questions about Asymptote?
* Question 1.4::    Why was the name Asymptote chosen?
* Question 1.5::    In the internal Asymptote source code, what does the
                    name camp refer to?



File: asy-faq.info, Node: Question 1.1, Next: Question 1.2, Previous: Top, Up: Section 1

Question 1.1.  What is Asymptote?

Asymptote is a vector graphics language designed for technical graphics,
inspired by MetaPost but with IEEE floating-point numerics, native
three-dimensional graphics, Grayscale/RGB/CMYK colourspaces, and a
C++-like syntax. Unlike MetaPost, it natively supports multiple-segment
paths (and hence regions other than simply connected ones), tiling
patterns, Gouraud  shading, tensor patch shading, and PostScript images.


File: asy-faq.info, Node: Question 1.2, Next: Question 1.3, Previous: Question 1.1, Up: Section 1

Question 1.2.  How do I obtain Asymptote?

Binary releases are available for Linux, MacOS X, and Microsoft Windows
platforms, in addition to full source code, from the website
https://asymptote.sourceforge.io/.  Many Linux distributions (such as
RedHat and Debian) now include an Asymptote package (check your
distribution's documentation for further information about this).


File: asy-faq.info, Node: Question 1.3, Next: Question 1.4, Previous: Question 1.2, Up: Section 1

Question 1.3.  Where can I ask questions about Asymptote?

If you have a question, please try to find an answer in this FAQ, in the
extensive Asymptote documentation at
https://asymptote.sourceforge.io/doc/, or search the forum:
http://sourceforge.net/forum/forum.php?forum_id=409349.


File: asy-faq.info, Node: Question 1.4, Next: Question 1.5, Previous: Question 1.3, Up: Section 1

Question 1.4.  Why was the name Asymptote chosen?

Well, it isn't the perfect graphics package, but we do think it is getting
there asymptotically...


File: asy-faq.info, Node: Question 1.5, Next: Question 2.1, Previous: Question 1.4, Up: Section 1

Question 1.5.  In the internal Asymptote source code, what does the name camp refer to?

That was our original tentative name for this project, which stood for
"C's Answer to MetaPost" (the language that inspired Asymptote).  However,
we eventually decided that the name Asymptote better emphasizes the
mathematical and graphical nature of this language.


File: asy-faq.info, Node: Section 2, Next: Section 3, Previous: Section 1, Up: Top

Questions about installation and setup

* Menu:
* Question 2.1::    Is it possible to install Asymptote on Mac OS X?
* Question 2.2::    Why do I get the error Bad CPU type in executable on
                    installing Asymptote from the MAC OS binary?
* Question 2.3::    What do I do if I get the error: Error: pdfetex (file
                    pdftex.cfg): cannot open config file...texinfo.tex
                    appears to be broken?
* Question 2.4::    What do I do if I get the error: ! Undefined control
                    sequence. l.6 @copying?
* Question 2.5::    Is it possible to integrate Asymptote into LaTeX?
* Question 2.6::    Is it possible to integrate Asymptote into latex or
                    pdflatex?
* Question 2.7::    Do I need the tkinter package to install an Asymptote
                    rpm binary?
* Question 2.8::    What does the path %USERPROFILE%\.asy\config.asy mean?
* Question 2.9::    Why do I get the error "string not terminated" when I
                    try to set settings.dir="C:\asymptote\";?
* Question 2.10::   How do I change environment variables in Microsoft
                    Windows, for example, in order to change the default
                    PostScript viewer?
* Question 2.11::   Under Microsoft Windows XP, why do I get an error like
                    "Invalid Parameter - 432x432"?
* Question 2.12::   Why does Asymptote freeze upon trying to draw a label
                    with my MikTex installation under Microsoft Windows?



File: asy-faq.info, Node: Question 2.1, Next: Question 2.2, Previous: Question 1.5, Up: Section 2

Question 2.1.  Is it possible to install Asymptote on Mac OS X?

It is easy to compile Asymptote directly from the source code at
http://sourceforge.net/project/showfiles.php?group_id=120000 We recommend
first upgrading to the latest GNU readline library, unless you don't care
about interactive readline support (in which case configure will
automatically detect and disable obsolete versions of the readline
library).  Marius Schamschula also maintains a binary package for various
MacOS X platforms
http://www.hmug.org/pub/MacOS_X/X/Applications/Publishing/asymptote.


File: asy-faq.info, Node: Question 2.2, Next: Question 2.3, Previous: Question 2.1, Up: Section 2

Question 2.2.  Why do I get the error Bad CPU type in executable on installing Asymptote from the MAC OS binary?

This means either that you have a binary distribution for another MAC
architecture, or (according to Marius Schamschula) that you may have a
missing library. The simplest solution is to compile Asymptote directly
from the official source:
http://sourceforge.net/project/showfiles.php?group_id=120000.


File: asy-faq.info, Node: Question 2.3, Next: Question 2.4, Previous: Question 2.2, Up: Section 2

Question 2.3.  What do I do if I get the error: Error: pdfetex (file pdftex.cfg): cannot open config file...texinfo.tex appears to be broken?

Simply put https://asymptote.sourceforge.io/asymptote.pdf in the directory
doc and repeat the command make all.  Or, if you don't want to build a
local copy of the documentation, simply proceed with make install-asy.


File: asy-faq.info, Node: Question 2.4, Next: Question 2.5, Previous: Question 2.3, Up: Section 2

Question 2.4.  What do I do if I get the error: ! Undefined control sequence. l.6 @copying?

Either upgrade your texinfo package or follow one of the easy work arounds
in *Note Question 2.3:: `What do I do if I get the error: Error: pdfetex
(file pdftex.cfg): cannot open config file...texinfo.tex appears to be
broken?'.


File: asy-faq.info, Node: Question 2.5, Next: Question 2.6, Previous: Question 2.4, Up: Section 2

Question 2.5.  Is it possible to integrate Asymptote into LaTeX?

Yes, see the example latexusage.tex. Dario Teixeira has also written a
detailed guide on the topic. You can download it from
http://dario.dse.nl/projects/asylatex/.

Philippe Ivaldi has contributed an Asymptote mode for Emacs users
https://asymptote.sourceforge.io/doc/Editing-modes.html, which includes a
lasy-mode that allows one to compile and view the output of one
\begin{asy}...\end{asy} section at a time.


File: asy-faq.info, Node: Question 2.6, Next: Question 2.7, Previous: Question 2.5, Up: Section 2

Question 2.6.  Is it possible to integrate Asymptote into latex or pdflatex?

Yes, as of version 1.14, Asymptote supports latex and pdflatex (both in
EPS/PDF and inline mode), as illustrated by the example latexusage.tex:

pdflatex latexusage
asy latexusage
pdflatex latexusage

File: asy-faq.info, Node: Question 2.7, Next: Question 2.8, Previous: Question 2.6, Up: Section 2

Question 2.7.  Do I need the tkinter package to install an Asymptote rpm binary?

No, you don't need tkinter unless you want to try out the GUI xasy. Try

rpm -Uvh --nodeps asymptote-x.xx-1.i386.rpm
where x.xx represents the version number.


File: asy-faq.info, Node: Question 2.8, Next: Question 2.9, Previous: Question 2.7, Up: Section 2

Question 2.8.  What does the path %USERPROFILE%\.asy\config.asy mean?

That is the way that Microsoft Windows refers to the user profile
directory.  There's nothing really to understand here, just put your
configuration commands in the file config.asy in a new folder
%USERPROFILE%\.asy.


File: asy-faq.info, Node: Question 2.9, Next: Question 2.10, Previous: Question 2.8, Up: Section 2

Question 2.9.  Why do I get the error "string not terminated" when I try to set settings.dir="C:\asymptote\";?

The backslash is an escape character here, so \" is interpreted as a
verbatim quotation mark, leaving the string without a terminating
quotation mark. Fortunately, this is the only escaped character in
double-quoted strings. A final backslash isn't needed here anyway, but
should you really want one somewhere, you can say:
settings.dir="C:\asymptote"+'\\';.


File: asy-faq.info, Node: Question 2.10, Next: Question 2.11, Previous: Question 2.9, Up: Section 2

Question 2.10.  How do I change environment variables in Microsoft Windows, for example, in order to change the default PostScript viewer?

While it is easier to set the corresponding Asymptote configuration
variable in your config.asy file, here is the procedure for changing
Microsoft Windows environment variables:

Click on the [Start] button

* RIGHT-click on 'My Computer'

* Choose 'Properties' from the popup menu

* Click the 'Advanced' tab

* Click the 'Environment Variables' button.


File: asy-faq.info, Node: Question 2.11, Next: Question 2.12, Previous: Question 2.10, Up: Section 2

Question 2.11.  Under Microsoft Windows XP, why do I get an error like "Invalid Parameter - 432x432"?

This means that ImageMagick wasn't properly installed and you are using
the MSDOS convert program rather than the ImageMagick one. Or you may have
installed ImageMagick but ran Asymptote from an existing MSDOS window.  In
that case, simply open a new window and try again. If that doesn't work,
check that

convert --version 
returns something like

Version: ImageMagick 6.2.8 06/27/06 Q16 http://www.imagemagick.org

File: asy-faq.info, Node: Question 2.12, Next: Question 3.1, Previous: Question 2.11, Up: Section 2

Question 2.12.  Why does Asymptote freeze upon trying to draw a label with my MikTex installation under Microsoft Windows?

Likely, this means that latex and dvips are not in your default path.  Try
adding the appropriate paths in your config.asy file,  for example:

import settings;
latex="C:\Program Files\MiKTeX 2.7\miktex\bin\latex.exe";
dvips="C:\Program Files\MiKTeX 2.7\miktex\bin\dvips.exe";

File: asy-faq.info, Node: Section 3, Next: Section 4, Previous: Section 2, Up: Top

Questions about paths

* Menu:
* Question 3.1::    Why do I get a syntax error message when I specify an
                    integer value for the path tension?
* Question 3.2::    Shouldn't dots always be the same size?



File: asy-faq.info, Node: Question 3.1, Next: Question 3.2, Previous: Question 2.12, Up: Section 3

Question 3.1.  Why do I get a syntax error message when I specify an integer value for the path tension?

What is happening here is that

draw((0,0)..tension 2..(0,50)..(100,100));
is read as

draw((0,0)..tension 2. .(0,50)..(100,100));
So the first . after the two is treated as a decimal point.  Just put a
space after the integer tension value:

draw((0,0)..tension 2 ..(0,50)..(100,100));

File: asy-faq.info, Node: Question 3.2, Next: Question 4.1, Previous: Question 3.1, Up: Section 3

Question 3.2.  Shouldn't dots always be the same size?

From the documentation:

"The dot command defined in the module plain draws a dot having a diameter
equal to an explicit pen linewidth or the default linewidth magnified by
dotfactor (6 by default)."

Thus, when you use the default pen, the dot will have size 6*linewidth,
but when you give a pen with an explicit width specified, you will  have a
dot of size linewidth. If you want the first case to behave like the
second, you may set dotfactor=1.


File: asy-faq.info, Node: Section 4, Next: Section 5, Previous: Section 3, Up: Top

Questions about labels

* Menu:
* Question 4.1::    How do I get Greek letters like omega to show up in my
                    labels?
* Question 4.2::    Can Asymptote use matrices as labels?
* Question 4.3::    How do I tell Asymptote to load a particular LaTeX
                    package, like mathptmx?
* Question 4.4::    How can I use international fonts in Asymptote labels?
* Question 4.5::    How can I use Fourier fonts?
* Question 4.6::    Is there any way to change the default appearance of
                    the decimal separator, using a comma instead of a dot?
* Question 4.7::    How can I get a rotated label with the filled box
                    rotated as well so that it fits the text?
* Question 4.8::    How can I rotate labels in a 3D figure?
* Question 4.9::    How can I draw some squares and circles of a fixed
                    size and put a label in the middle of them?
* Question 4.10::   The binary operator * can be used to scale the color
                    of a pen by a real number. Does this scaling factor
                    have to be less than 1?
* Question 4.11::   Why is the space after the comma decimal separator in
                    my locale so large?
* Question 4.12::   How can I prevent
                    texpreamble("\usepackage[pdftex]{hyperref}") from
                    changing the page size?



File: asy-faq.info, Node: Question 4.1, Next: Question 4.2, Previous: Question 3.2, Up: Section 4

Question 4.1.  How do I get Greek letters like omega to show up in my labels?

In (La)TeX, Greek letters can be obtained in math mode by prepending a
backslash to the letter name. So for a omega symbol, use "$\omega$".
Everything between the dollar signs is considered to be a math formula.
Uppercase Greek letters can be used by capitalizing the first letter of
the name:

label("$\omega$",(0,0));
label("$\Omega$",(20,0));

File: asy-faq.info, Node: Question 4.2, Next: Question 4.3, Previous: Question 4.1, Up: Section 4

Question 4.2.  Can Asymptote use matrices as labels?

Yes:
usepackage("amsmath");
label("$\begin{matrix} 1 & 2 \\\ 1 & 1 \end{matrix}$",(0,0));

File: asy-faq.info, Node: Question 4.3, Next: Question 4.4, Previous: Question 4.2, Up: Section 4

Question 4.3.  How do I tell Asymptote to load a particular LaTeX package, like mathptmx?

Put

usepackage("mathptmx");
at the beginning of your file. Note: to enable the Adobe Times Roman font
for text, you will also need to say:
defaultpen(TimesRoman());

File: asy-faq.info, Node: Question 4.4, Next: Question 4.5, Previous: Question 4.3, Up: Section 4

Question 4.4.  How can I use international fonts in Asymptote labels?

See https://asymptote.sourceforge.io/doc/Pens.html.


File: asy-faq.info, Node: Question 4.5, Next: Question 4.6, Previous: Question 4.4, Up: Section 4

Question 4.5.  How can I use Fourier fonts?

usepackage("fourier");
defaultpen(font("T1","fut\textfamilyextension","m","n"));

File: asy-faq.info, Node: Question 4.6, Next: Question 4.7, Previous: Question 4.5, Up: Section 4

Question 4.6.  Is there any way to change the default appearance of the decimal separator, using a comma instead of a dot?

Just set your locale appropriately:

locale("it_IT");
usepackage("icomma");
label(format(0.5));

File: asy-faq.info, Node: Question 4.7, Next: Question 4.8, Previous: Question 4.6, Up: Section 4

Question 4.7.  How can I get a rotated label with the filled box rotated as well so that it fits the text?

frame f;
label(f,"This is some text",white,Fill(blue));
add(rotate(65)*f);

File: asy-faq.info, Node: Question 4.8, Next: Question 4.9, Previous: Question 4.7, Up: Section 4

Question 4.8.  How can I rotate labels in a 3D figure?

You need to first project the triple to a pair like this:

import three;
size(100,100);

draw(rotate(90,project(Z))*"A",O--X);

File: asy-faq.info, Node: Question 4.9, Next: Question 4.10, Previous: Question 4.8, Up: Section 4

Question 4.9.  How can I draw some squares and circles of a fixed size and put a label in the middle of them?

Fixed-size objects should be drawn on a separate picture and then added to
currentpicture. Here is one way (see also
https://asymptote.sourceforge.io/gallery/subpictures.asy and
https://asymptote.sourceforge.io/gallery/mosquito.asy):

real u=2cm;
 
picture square;
draw(square,scale(u)*shift(-0.5,-0.5)*unitsquare);
 
picture circle;
draw(circle,scale(0.5u)*unitcircle);
 
void add(picture pic=currentpicture, Label L, picture object, pair z) { 
add(pic,object,z);
label(pic,L,z);
} 
 
add("square",square,(0,0));
add("circle",circle,(5cm,0));

File: asy-faq.info, Node: Question 4.10, Next: Question 4.11, Previous: Question 4.9, Up: Section 4

Question 4.10.  The binary operator * can be used to scale the color of a pen by a real number. Does this scaling factor have to be less than 1?

The scaling factor can be greater than 1. But keep in mind that the rgb
color  components saturate at 1.

Try
write(cyan); write(0.8*cyan); write(1.5*cyan);
and you will quickly see what is going on.

To get a lighter cyan you can say white+cyan,  which yields rgb(0.5,1,1).
If you want something even lighter specify the  rgb colors directly,  for
example, rgb(0.9,1,1).

Alternatively, work in cmyk colour space, which is nicer in that it
handles  saturation separately from hue:

0.1*Cyan is light and 0.9*Cyan is dark.  You can also say 0.1*cmyk(red).


File: asy-faq.info, Node: Question 4.11, Next: Question 4.12, Previous: Question 4.10, Up: Section 4

Question 4.11.  Why is the space after the comma decimal separator in my locale so large?

LaTeX is treating the comma as punctuation and not as a decimal separator.
The solution is to load the icomma package near the beginning of your
file:
usepackage("icomma");

File: asy-faq.info, Node: Question 4.12, Next: Question 5.1, Previous: Question 4.11, Up: Section 4

Question 4.12.  How can I prevent texpreamble("\usepackage[pdftex]{hyperref}") from changing the page size?

texpreamble("\usepackage[pdftex,setpagesize=false]{hyperref}");

File: asy-faq.info, Node: Section 5, Next: Section 6, Previous: Section 4, Up: Top

Questions about arrows

* Menu:
* Question 5.1::    How do I draw two arrows at arbitrary positions along
                    a path?
* Question 5.2::    How do I reverse the direction of an arrowhead?
* Question 5.3::    How do I change the size of all arrows?
* Question 5.4::    Can I create other arrowhead styles?



File: asy-faq.info, Node: Question 5.1, Next: Question 5.2, Previous: Question 4.12, Up: Section 5

Question 5.1.  How do I draw two arrows at arbitrary positions along a path?

Assuming that at least one of the arrowheads is to be filled, you can do
this:

size(200); 
path g = (0,0)..(1,3)..(3,0); 
draw(g,Arrow(Relative(0.9))); 
add(arrow(g,invisible,FillDraw(black),Relative(0.5))); 
add(arrow(reverse(g),invisible,FillDraw(white,black),Relative(0.9))); 
If both of the arrowheads are to be drawn with filltype NoFill, one will
need to create a specialized version of the arrow routine in
plain_arrows.asy:

void arrow(frame f, arrowhead arrowhead=DefaultHead,
           path g, pen p=currentpen, real size=0,
           real angle=arrowangle, filltype filltype=arrowhead.defaultfilltype,
           position position=EndPoint, bool forwards=true,
           margin margin=NoMargin, bool center=false);

File: asy-faq.info, Node: Question 5.2, Next: Question 5.3, Previous: Question 5.1, Up: Section 5

Question 5.2.  How do I reverse the direction of an arrowhead?

Simply reverse the direction of the path.

path g=((0,0)--(5cm,0));
draw(reverse(g),Arrow(Relative(0.55)));

File: asy-faq.info, Node: Question 5.3, Next: Question 5.4, Previous: Question 5.2, Up: Section 5

Question 5.3.  How do I change the size of all arrows?

To override the arrowsize you can give every Arrow drawing attribute a
real size argument. If you want to do this globally, you can override the
pen-dependent arrowsize function like this:

DefaultHead.size=new real(pen p=currentpen) {return 2mm;};

File: asy-faq.info, Node: Question 5.4, Next: Question 6.1, Previous: Question 5.3, Up: Section 5

Question 5.4.  Can I create other arrowhead styles?

Yes, you can build custom arrowheads like this (see the predefined
arrowhead styles in plain_arrows.asy for further examples):

arrowhead DotHead;
DotHead.head=new path(path g, position position=EndPoint, pen p=currentpen,
                      real size=0, real angle=arrowangle) {
  if(size == 0) size=DotHead.size(p);
  bool relative=position.relative;
  real position=position.position.x;
  if(relative) position=reltime(g,position);
  path r=subpath(g,position,0);
  pair x=point(r,0);
  real t=arctime(r,size);
  pair y=point(r,t);
  return circle(0.5(x+y),0.5size);
};

size(100);
draw((0,0)..(1,1)..(2,0),Arrow(DotHead));
dot((2,0),red);
If you submit your alternate arrowheads to the Forum or the Patch
Tracking System, we'll consider including them in a future release.


File: asy-faq.info, Node: Section 6, Next: Section 7, Previous: Section 5, Up: Top

Questions about 2D graphs

* Menu:
* Question 6.1::    How can I draw x axis ticks on the right side, with
                    the tick labels on the left side (relative to the axis
                    path)?
* Question 6.2::    How can I reposition the x axis label to
                    three-quarters along the axis length?
* Question 6.3::    How can I move the x axis label down 10bp?
* Question 6.4::    Can I use different pens for the axis, the axis label,
                    and the tick labels?
* Question 6.5::    How can I change the font type of the axes label?
* Question 6.6::    How can I change the font type of the tick labels on
                    an axis?
* Question 6.7::    How can I prevent axes tick labels from rendering on
                    top of each other?
* Question 6.8::    How do I make the plot region of a graph, ignoring
                    labels and legends, have a fixed size?
* Question 6.9::    How can I plot a function f(x) within [0,1]x[0,2]
                    without explicitly calculating the x values for which
                    f(x) hits the boundary?
* Question 6.10::   Is it possible to define customized palettes?
* Question 6.11::   Is there an easy way to graph factorial functions
                    nicely?
* Question 6.12::   How do I indicate that a certain length should be
                    exactly the size I prescribe with no rescaling, within
                    a picture which has its own size?
* Question 6.13::   How can I make the y axis display base-2 logarithmic
                    values?
* Question 6.14::   How can I align the x axes of two graphs on the same
                    figure?
* Question 6.15::   How can I change the direction of the y-axis, such
                    that negatives values are on the upper y-axis?
* Question 6.16::   How can I fill a path with a function that defines the
                    color of each location?
* Question 6.17::   Is there a way to draw a function that is not
                    explicitly given, such as (y - 2)^2 = x - 1 ?
* Question 6.18::   Is it possible to reverse or stretch an axis?
* Question 6.19::   Why can't I use the UnFill option to draw graphs with
                    empty markers?
* Question 6.20::   How can I force several images to use the same palette
                    range (e.g. the entire 0-255 grayscale range)?



File: asy-faq.info, Node: Question 6.1, Next: Question 6.2, Previous: Question 5.4, Up: Section 6

Question 6.1.  How can I draw x axis ticks on the right side, with the tick labels on the left side (relative to the axis path)?

import graph;

size(250,200,IgnoreAspect);

draw(graph(exp,-1,1),red);

xaxis("$x$",RightTicks(Label(align=left)));
yaxis("$y$",RightTicks);

File: asy-faq.info, Node: Question 6.2, Next: Question 6.3, Previous: Question 6.1, Up: Section 6

Question 6.2.  How can I reposition the x axis label to three-quarters along the axis length?

import graph;

size(250,200,IgnoreAspect);

draw(graph(exp,-1,1),red);

xaxis(Label("$x$",0.75),LeftTicks);
yaxis("$y$",RightTicks);

File: asy-faq.info, Node: Question 6.3, Next: Question 6.4, Previous: Question 6.2, Up: Section 6

Question 6.3.  How can I move the x axis label down 10bp?

import graph;
size(250,200,IgnoreAspect);

draw(graph(exp,-1,1),red);

xaxis(shift(0,-10)*"$x$",LeftTicks);
yaxis("$y$",RightTicks);

File: asy-faq.info, Node: Question 6.4, Next: Question 6.5, Previous: Question 6.3, Up: Section 6

Question 6.4.  Can I use different pens for the axis, the axis label, and the tick labels?

Yes:

import graph;
size(300,200,IgnoreAspect);

xlimits(-50,50);
ylimits(0,100);

xaxis(Label("$x$",MidPoint,red),Bottom,blue,LeftTicks(green));
yaxis("$y$",Left,RightTicks);

File: asy-faq.info, Node: Question 6.5, Next: Question 6.6, Previous: Question 6.4, Up: Section 6

Question 6.5.  How can I change the font type of the axes label?

import graph;
size(300,200,IgnoreAspect);

xlimits(-50,50);
ylimits(0,100);

xaxis("x",Bottom,Courier("m","n"),LeftTicks);
yaxis("$y$",Left,RightTicks);

File: asy-faq.info, Node: Question 6.6, Next: Question 6.7, Previous: Question 6.5, Up: Section 6

Question 6.6.  How can I change the font type of the tick labels on an axis?

Tick labels are by default typeset in (TeX) math mode, so to use other
fonts you need to override the default tick format:

import graph;
size(300,200,IgnoreAspect);

xlimits(-50,50);
ylimits(0,100);

xaxis("$x$",Bottom,LeftTicks("%.4g",Courier("m","n")+fontsize(12)));
yaxis("$y$",Left,RightTicks);

File: asy-faq.info, Node: Question 6.7, Next: Question 6.8, Previous: Question 6.6, Up: Section 6

Question 6.7.  How can I prevent axes tick labels from rendering on top of each other?

Either:

(i) give LeftTicks/RightTicks/Ticks the arguments beginlabel=false and/or
endlabel=false;

(ii) explicitly remove specific ticks and their labels (drawing them
manually; see
http://www.github.com/vectorgraphics/asymptote/base/graph.asy for the
definition of NoZero):

import graph;

size(10cm);

real f(real x) {return x^2;}
 
draw(graph(f,-2,2));

xaxis(Ticks(NoZero));
yaxis(Ticks(NoZero));

label("$0$",(0,0),SW);
(iii) explicitly remove specific tick labels and draw them manually (see
http://www.github.com/vectorgraphics/asymptote/base/graph.asy for the
definition of NoZeroFormat):

import graph;

size(10cm);

real f(real x) {return x^2;}
 
draw(graph(f,-2,2));

xaxis(Ticks(NoZeroFormat));
yaxis(Ticks(NoZeroFormat));

label("$0$",(0,0),SW);
(iv) use the xasy GUI to move overlapping labels;

(v) change the Label argument of LeftTicks, RightTicks, or Ticks to:

Label(currentpen+overwrite(Move))
Solution (v) will move labels that might otherwise overwrite a previous
label. Other possible overwrite arguments are Allow (allows overlapping
labels; the default), Suppress (an overlapping label will not be written
at all), SuppressQuiet, and MoveQuiet. The last two achieve the same
result as the non-quiet types, but will not notify you which labels are
overlapping. See:  https://asymptote.sourceforge.io/doc/Pens.html.

In the case of a user-specified tick array, you can change which labels
get suppressed/moved by changing the order of array entries.


File: asy-faq.info, Node: Question 6.8, Next: Question 6.9, Previous: Question 6.7, Up: Section 6

Question 6.8.  How do I make the plot region of a graph, ignoring labels and legends, have a fixed size?

Either:

i) Specify an explicit unitsize, which overrides any call to size:
unitsize(x=1cm,y=2cm);
ii) Explicitly tell Asymptote to map the plot region to a specific size:
import graph;
real[] x={0,1,2,3};
real[] y=x^2;
draw(graph(x,y),red);
xaxis("$x$",BottomTop,LeftTicks);
yaxis("$y$",LeftRight,RightTicks);

size(5cm,5cm,point(SW),point(NE));

label("$f_\mathrm{T}$",point(N),2N);
iii) Specify the points in user coordinates that should correspond to a
given picture size:

import graph;

size(250,200,IgnoreAspect);

draw(graph(exp,-1,1),red);

xaxis("$x$",BottomTop,LeftTicks);
yaxis("$y$",LeftRight,RightTicks);

fixedscaling((-1.5,-0.5),(1.5,3.5));
In this example, the user coordinate (-1.5,-0.5) will end up being the
lower left corner of the figure and (1.5,3.5) will be the upper right
corner. You can use this option to ensure multiple figures have the same
scaling and same resulting figure size (just ensure the two coordinates
given to fixedscaling() leaves room for any labels).

See also https://asymptote.sourceforge.io/doc/Frames-and-pictures.html.


File: asy-faq.info, Node: Question 6.9, Next: Question 6.10, Previous: Question 6.8, Up: Section 6

Question 6.9.  How can I plot a function f(x) within [0,1]x[0,2] without explicitly calculating the x values for which f(x) hits the boundary?

Call limits with the Crop option before drawing the graph:
import graph;

size(250,200,IgnoreAspect);

draw(graph(exp,-1,1),red);

limits((0,0),(1,2),Crop);

xaxis("$x$",BottomTop,LeftTicks);
yaxis("$y$",LeftRight,RightTicks);
See also https://asymptote.sourceforge.io/doc/graph.html.


File: asy-faq.info, Node: Question 6.10, Next: Question 6.11, Previous: Question 6.9, Up: Section 6

Question 6.10.  Is it possible to define customized palettes?

Yes, you may generate your own pen[] array. For example:

int NColors=32768;
pen[] MyPalette=new pen[NColors];
real step=1/(NColors-1.0);
// Start at black: rgb(0,0,0) 
// End at yellow: rgb(1,1,0) 
for(int i=0; i < NColors; ++i) { 
  real rgval=i*step;
  MyPalette[i]=rgb(rgval,rgval,0.0);
} 

File: asy-faq.info, Node: Question 6.11, Next: Question 6.12, Previous: Question 6.10, Up: Section 6

Question 6.11.  Is there an easy way to graph factorial functions nicely?

The example below shows a continuous function and two methods for placing
markers at integer values of x:

import graph;
 
size(200,200,IgnoreAspect);
 
real factorial(real t) {return gamma(t+1);} 
 
scale(Linear,Log);
 
// Graph the factorial function.
draw(graph(factorial,0,10));
 
// Method 1: Draw nodes, but hide line
pair F(int t) {return (t,factorial(t));} 
// Graph of factorial function from 0 to 10
pair[] z=sequence(F,11);
draw(graph(z),invisible,marker(scale(0.8mm)*unitcircle,blue,Fill));
 
// Method 2: Nongraphing routines require explicit scaling:
pair dotloc(int t) {return Scale(F(t));} 
pair[] dotlocs=sequence(dotloc,11);
dot(dotlocs);
 
xaxis("$x$",BottomTop,LeftTicks);
yaxis("$y$",LeftRight,RightTicks);

File: asy-faq.info, Node: Question 6.12, Next: Question 6.13, Previous: Question 6.11, Up: Section 6

Question 6.12.  How do I indicate that a certain length should be exactly the size I prescribe with no rescaling, within a picture which has its own size?

Here's an easy way to do this.

size(12cm,0);
 
void distance(picture pic=currentpicture, pair A, pair B, Label L="", real n=0,
              pen p=currentpen) 
{
  real d=3mm;
  path g=A--B;
  transform T=shift(-n*d*unit(B-A)*I);
  pic.add(new void(frame f, transform t) {
    picture opic;
    path G=T*t*g;
    draw(opic,Label(L,Center,UnFill(1)),G,p,Arrows(NoFill),Bars,PenMargins);
    add(f,opic.fit());
  });
  pic.addBox(min(g),max(g),T*min(p),T*max(p));
} 
 
pair A=(0,0), B=(3,3);
 
dot(A);
dot(B);
 
distance(A,B,"$\ell$",1);

File: asy-faq.info, Node: Question 6.13, Next: Question 6.14, Previous: Question 6.12, Up: Section 6

Question 6.13.  How can I make the y axis display base-2 logarithmic values?

See the example https://asymptote.sourceforge.io/gallery/2D
graphs/log2graph.asy.


File: asy-faq.info, Node: Question 6.14, Next: Question 6.15, Previous: Question 6.13, Up: Section 6

Question 6.14.  How can I align the x axes of two graphs on the same figure?

An easy way to do this, if the axes to be aligned have the same scaling
and size, is illustrated in the example
https://asymptote.sourceforge.io/gallery/2D graphs/alignedaxis.asy.

Here is a more general solution to the problem of aligning two arbitrary
axes.  One fits the second picture to a frame based on the horizontal
scaling for the first picture:

import graph;

real width=15cm;
real aspect=0.3;

picture pic1,pic2;

size(pic1,width,aspect*width,IgnoreAspect);
size(pic2,width,aspect*width,IgnoreAspect);

scale(pic1,false);
scale(pic2,false);

real xmin1=6;
real xmax1=9;
real xmin2=8;
real xmax2=16;

real a1=1;
real a2=0.001;

real f1(real x) {return a1*sin(x/2*pi);}
real f2(real x) {return a2*sin(x/4*pi);}

draw(pic1,graph(pic1,f1,xmin1,xmax1));
draw(pic2,graph(pic2,f2,xmin2,xmax2));

xaxis(pic1,Bottom,LeftTicks());
yaxis(pic1,"$f_1(x)$",Left,RightTicks);

xaxis(pic2,"$x$",Bottom,LeftTicks(Step=4));
yaxis(pic2,"$f_2(x)$",Left,RightTicks);

yequals(pic1,0,Dotted);
yequals(pic2,0,Dotted);

pair min1=point(pic1,SW);
pair max1=point(pic1,NE);

pair min2=point(pic2,SW);
pair max2=point(pic2,NE);

real scale=(max1.x-min1.x)/(max2.x-min2.x);
real shift=min1.x/scale-min2.x;

transform t1=pic1.calculateTransform();
transform t2=pic2.calculateTransform();
transform T=xscale(scale*t1.xx)*yscale(t2.yy);

add(pic1.fit());
real height=truepoint(N,user=false).y-truepoint(S,user=false).y;
add(shift(0,-height)*(shift(shift)*pic2).fit(T));

File: asy-faq.info, Node: Question 6.15, Next: Question 6.16, Previous: Question 6.14, Up: Section 6

Question 6.15.  How can I change the direction of the y-axis, such that negatives values are on the upper y-axis?

Here is a simple example (see also the example
https://asymptote.sourceforge.io/gallery/2D graphs/diatom.asy or the
discussion of Linear(-1) in the documentation):

import graph;
size(250,200,IgnoreAspect);

scale(Linear,Linear(-1));

draw(graph(log,0.1,10),red);

xaxis("$x$",LeftTicks);
yaxis("$y$",RightTicks);

File: asy-faq.info, Node: Question 6.16, Next: Question 6.17, Previous: Question 6.15, Up: Section 6

Question 6.16.  How can I fill a path with a function that defines the color of each location?

Use functionshade with a PDF tex engine, as illustrated by the example
{functionshading.asy}.

If you want to produce PostScript output, an approximate solution for now
would be to superimpose a fine grid and specify colors to  latticeshade
that depend on position as a single pen[][] lattice. Alternatively, it may
be more efficient to use tensorshade}.


File: asy-faq.info, Node: Question 6.17, Next: Question 6.18, Previous: Question 6.16, Up: Section 6

Question 6.17.  Is there a way to draw a function that is not explicitly given, such as (y - 2)^2 = x - 1 ?

Yes, use the parametric form

y=t 
x=(t-2)^2+1 
See the example https://asymptote.sourceforge.io/gallery/2D
graphs/parametricgraph.asy.


File: asy-faq.info, Node: Question 6.18, Next: Question 6.19, Previous: Question 6.17, Up: Section 6

Question 6.18.  Is it possible to reverse or stretch an axis?

The real scaling argument to Linear is used to stretch (or reverse) the
axis.  To see the effect of axis stretching, be sure not to specify
IgnoreAspect in  the picture size command.

A secondary axis has the same length as the primary axis, so stretching
cannot  have any effect. But one can still reverse the axis, with
Linear(-1).


File: asy-faq.info, Node: Question 6.19, Next: Question 6.20, Previous: Question 6.18, Up: Section 6

Question 6.19.  Why can't I use the UnFill option to draw graphs with empty markers?

UnFill won't work here because it only affects the local frame the markers
are initially drawn on, before being added to currentpicture.  Here is a
way of achieving the desired effect (assuming a white background):

import graph;
size(10cm,0);
pair[] z={(0,0),(0.5,0.5),(1,1)};
path g=graph(z);
 
draw(shift(0,.5)*g,marker(scale(5)*unitcircle,FillDraw(white)));
 
xaxis(BottomTop,LeftTicks);
yaxis(LeftRight,RightTicks);

File: asy-faq.info, Node: Question 6.20, Next: Question 7.1, Previous: Question 6.19, Up: Section 6

Question 6.20.  How can I force several images to use the same palette range (e.g. the entire 0-255 grayscale range)?

The palette color space corresponds to a range of values specified by the
argument range, which can be Full, Automatic or an explicit range
Range(pair min, pair max). Here Full} specifies a range varying from the
minimum to maximum values of the function over the sampling interval,
while Automatic selects "nice" limits.


File: asy-faq.info, Node: Section 7, Next: Section 8, Previous: Section 6, Up: Top

Questions about programming

* Menu:
* Question 7.1::    Is Asymptote an interpreter or a compiler?
* Question 7.2::    What is the difference between a frame and a picture?
* Question 7.3::    What is the difference between a path and a guide?
* Question 7.4::    What is a convenient way to declare and initialize an
                    array of pictures?
* Question 7.5::    Is there a way to define functions that act on arrays
                    in general (i.e. work for arrays of any type)?
* Question 7.6::    Is there any way to declare structures ahead of their
                    definition, e.g. where struct A performs some
                    operation on struct B, but B contains an A member?
* Question 7.7::    Where are static variables in for loops allocated?
* Question 7.8::    Is there a debugger for asy?
* Question 7.9::    Do you accept patches for Asymptote?



File: asy-faq.info, Node: Question 7.1, Next: Question 7.2, Previous: Question 6.20, Up: Section 7

Question 7.1.  Is Asymptote an interpreter or a compiler?

Asymptote compiles Asymptote commands into its own virtual machine code.
It  then runs this pseudocode on a virtual machine to produce PostScript
code.


File: asy-faq.info, Node: Question 7.2, Next: Question 7.3, Previous: Question 7.1, Up: Section 7

Question 7.2.  What is the difference between a frame and a picture?

Frames are canvases for drawing in PostScript coordinates. While working
with frames directly is occasionally necessary for constructing deferred
drawing routines, pictures are usually more convenient to work with.  See
*Note Question 8.8:: `In MetaPost, it is possible to have a drawing remain
the same size in different pictures by defining a unit u and explicitly
multiply all the coordinates by u. Is there a better way to do this in
Asymptote?'.


File: asy-faq.info, Node: Question 7.3, Next: Question 7.4, Previous: Question 7.2, Up: Section 7

Question 7.3.  What is the difference between a path and a guide?

A path is a cubic spline with fixed endpoint conditions.

A guide is an unresolved cubic spline (list of cubic-spline nodes and
control points). A guide is like a path except that the computation of the
cubic spline is deferred until drawing time (when it is resolved into a
path); this allows two guides with free endpoint conditions to be joined
together smoothly.


File: asy-faq.info, Node: Question 7.4, Next: Question 7.5, Previous: Question 7.3, Up: Section 7

Question 7.4.  What is a convenient way to declare and initialize an array of pictures?

You could write yourself a routine such as:
picture[] picture(int n) { 
  picture[] pic;
  for(int i=0; i < n; ++i) { 
    pic[i]=new picture;
    size(pic[i],19cm,0);
  } 
  return pic;
} 
 
picture[] pic=picture(6);

File: asy-faq.info, Node: Question 7.5, Next: Question 7.6, Previous: Question 7.4, Up: Section 7

Question 7.5.  Is there a way to define functions that act on arrays in general (i.e. work for arrays of any type)?

Generic types aren't yet implemented.

But for now you can at least say
typedef string T;
include F;
 
typedef real T;
include F;
where F.asy contains some type-dependent code like
T[] operator $(T A, T B) {return new T[] {A,B};}

File: asy-faq.info, Node: Question 7.6, Next: Question 7.7, Previous: Question 7.5, Up: Section 7

Question 7.6.  Is there any way to declare structures ahead of their definition, e.g. where struct A performs some operation on struct B, but B contains an A member?

Asymptote does not support forward declaration of types. You can, however,
nest structures, so that both types are visible for parts of the bodies of
both structure definitions. For example:

struct B { 
  typedef void someroutine(B b);
 
  static struct A { 
    someroutine routine;
    void operator init(someroutine routine) { 
      this.routine=routine;
    } 
  } 
 
  string test="Testing";
} 
 
typedef B.A A;
 
A a=B.A(new void(B b){write(b.test);});
 
B b;
a.routine(b);

File: asy-faq.info, Node: Question 7.7, Next: Question 7.8, Previous: Question 7.6, Up: Section 7

Question 7.7.  Where are static variables in for loops allocated?

In the example

void f() { 
  for(int i=0; i < 3; ++i) { 
    static int n;
    ++n;
    write(n);
  }
} 

f(); // Writes 1, 2, 3
the static qualifier means that n is allocated not just outside of the for
loop, but also outside the function. This is clear if you call  f multiple
times; there is still only one instance of n.

The "level" of a variable (where it is allocated) has nothing to do with
the "scope" of a variable (how long it can be referred to by name).  The
curly braces enclosing a block affect only a variable's scope, not its
level.

Static modifiers are meaningless at the top level; they generate a warning
and are simply ignored:

for(int i=0; i < 3; ++i) { 
  static int n;
  ++n;
  write(n);
}
// Writes warning about top-level static modifier and then 1, 1, 1
Since version 1.22, non-static variables allocated in a loop body are
allocated anew every iteration.  This is only noticable in obscure cases
where a variable in a loop is accessed in the closure of a function
defined in the loop:

int f();
 
for(int i=0; i < 10; ++i) { 
  int j=10*i;
  if(i == 5)
    f=new int() {return j;};
} 
 
write(f()); // Writes 50
Variables in the body of a loop last as long as that iteration of the
loop, unless they are kept alive by a function closure as in the example
above.  In a function body, variables will last at least as long as the
function call, though because of closures and garbage collection, they may
last longer than that.  If defined at the top level of a file or at the
interactive prompt, they will last at least until the end of the file or
prompt's run.


File: asy-faq.info, Node: Question 7.8, Next: Question 7.9, Previous: Question 7.7, Up: Section 7

Question 7.8.  Is there a debugger for asy?

Yes, Asymptote includes a line-based debugger:

https://asymptote.sourceforge.io/doc/Debugger.html


File: asy-faq.info, Node: Question 7.9, Next: Question 8.1, Previous: Question 7.8, Up: Section 7

Question 7.9.  Do you accept patches for Asymptote?

Yes, in fact we would prefer that users submit patches for customized
features (to http://sourceforge.net/tracker/?atid=685685&group_id=120000)
instead of relying on us to do all of the coding. Development will proceed
faster that way.


File: asy-faq.info, Node: Section 8, Next: Section 9, Previous: Section 7, Up: Top

Questions about differences between Asymptote and MetaPost

* Menu:
* Question 8.1::    What is the equivalent of the MetaPost c[a,b]
                    interpolation operator?
* Question 8.2::    How does picture scaling differ in Asymptote and
                    MetaPost?
* Question 8.3::    How can I avoid automatic scaling of a picture?
* Question 8.4::    What is the equivalent of MetaPost ... command?
* Question 8.5::    What is the equivalent of the MetaPost pickup command?
* Question 8.6::    What is the equivalent of the MetaPost whatever
                    command?
* Question 8.7::    What is the equivalent for the MetaPost command for
                    lray - horiz*v - verti*u = whatever*(LightSource - R),
                    a system of three linear equations for three unknowns:
                    horiz, verti, whatever?
* Question 8.8::    In MetaPost, it is possible to have a drawing remain
                    the same size in different pictures by defining a unit
                    u and explicitly multiply all the coordinates by u. Is
                    there a better way to do this in Asymptote?
* Question 8.9::    In MetaPost, one could produce tiling pictures by
                    generating a picture, and then clipping the picture to
                    a rectangle of fixed dimensions around the center of
                    the picture. How is that done in Asymptote?



File: asy-faq.info, Node: Question 8.1, Next: Question 8.2, Previous: Question 7.9, Up: Section 8

Question 8.1.  What is the equivalent of the MetaPost c[a,b] interpolation operator?

interp(a,b,c);

File: asy-faq.info, Node: Question 8.2, Next: Question 8.3, Previous: Question 8.1, Up: Section 8

Question 8.2.  How does picture scaling differ in Asymptote and MetaPost?

Asymptote includes an optional facility to do automatic scaling of
pictures to achieve a given overall picture size, whereas Metapost only
supports manual scaling. Asymptote defers drawing of objects drawn to
pictures and distinguishes between true-size objects and objects that
should scale with the picture size. The resulting linear programming
problem is solved via the Simplex method.

See the https://asymptote.sourceforge.io/gallery/dimension.asy example for
an example of how deferred drawing is used to accomodate both user and
true-size (PostScript) coordinates.


File: asy-faq.info, Node: Question 8.3, Next: Question 8.4, Previous: Question 8.2, Up: Section 8

Question 8.3.  How can I avoid automatic scaling of a picture?

If you really like Metapost-style manual (hard-wired) scaling either:

(i) use the default size(0,0) for the entire picture and do all of the
scaling by hand, just like in MetaPost;

(ii) draw to a separate picture pic and add(pic.fit());

(iii) use frames.


File: asy-faq.info, Node: Question 8.4, Next: Question 8.5, Previous: Question 8.3, Up: Section 8

Question 8.4.  What is the equivalent of MetaPost ... command?

The connector :: is a macro for tension atleast 1:

size(100);
pair z0=(0,0);
pair z1=(1,0.25);
pair z2=(2,0);
draw(z0{up}::z1{right}::z2{down});

File: asy-faq.info, Node: Question 8.5, Next: Question 8.6, Previous: Question 8.4, Up: Section 8

Question 8.5.  What is the equivalent of the MetaPost pickup command?

Just say, for example:

currentpen=red;

File: asy-faq.info, Node: Question 8.6, Next: Question 8.7, Previous: Question 8.5, Up: Section 8

Question 8.6.  What is the equivalent of the MetaPost whatever command?

Asymptote does not implicitly solve linear equations and therefore does
not have the notion of a whatever unknown. Such a facility could certainly
be added (perhaps using the notation ?= since = means assignment).
However, the most common uses of whatever in MetaPost are covered by
functions like extension in math.asy:
pair extension(pair P, pair Q, pair p, pair q);
this returns the intersection point of the extensions of the line segments
PQ and pq. We find using routines like extension more explicit and less
confusing to new users. But we could be persuaded to add something similar
if someone can justify the need. In the meantime, one can always use the
explicit built-in linear solver solve (see
https://asymptote.sourceforge.io/doc/solve.html), which uses LU
decomposition.


File: asy-faq.info, Node: Question 8.7, Next: Question 8.8, Previous: Question 8.6, Up: Section 8

Question 8.7.  What is the equivalent for the MetaPost command for lray - horiz*v - verti*u = whatever*(LightSource - R), a system of three linear equations for three unknowns: horiz, verti, whatever?

Since horiz*v+verti*u spans a plane, you could use
real intersect(vector P, vector Q, vector n, vector Z);
to find the intersection time for the line  lray-whatever*(LightSource -
R) and then extract the three desired values from there. (You'll still
need to use the built-in explicit linear solver to solve a 2x2 system to
get  horiz and verti.)


File: asy-faq.info, Node: Question 8.8, Next: Question 8.9, Previous: Question 8.7, Up: Section 8

Question 8.8.  In MetaPost, it is possible to have a drawing remain the same size in different pictures by defining a unit u and explicitly multiply all the coordinates by u. Is there a better way to do this in Asymptote?

Yes, Asymptote has a better way: you definitely don't want to manually
scale  all of your coordinates. To make the user coordinates represent
multiples of exactly 1cm:

unitsize(1cm);
draw(unitsquare);
One can also specify different x and y unit sizes:

unitsize(x=1cm,y=2cm);
draw(unitsquare);
Another way is to draw your fixed size object to a frame and add it to
currentpicture like this:

path p=(0,0)--(1,0);
frame object;
draw(object,scale(100)*p);
 
add(object);
add(object,(0,-10));
To understand the difference between frames and pictures, try this:

size(300,300);
 
path p=(0,0)--(1,0);
picture object;
draw(object,scale(100)*p);
 
add(object);
add(object,(0,-10)); // Adds truesize object to currentpicture 

File: asy-faq.info, Node: Question 8.9, Next: Question 9.1, Previous: Question 8.8, Up: Section 8

Question 8.9.  In MetaPost, one could produce tiling pictures by generating a picture, and then clipping the picture to a rectangle of fixed dimensions around the center of the picture. How is that done in Asymptote?

If you are using currentpicture the way one would in MetaPost (drawing in
raw PostScript coordinates), you can simply do something like:

fill((0,0)--(100,100)--(200,0)--cycle);
 
pair center(picture pic=currentpicture) {return 0.5*(pic.min()+pic.max());} 
 
real height=100;
real width=100;
pair delta=0.5(width,height);
pair c=center();
clip(box(c-delta,c+delta));
However, drawing in PostScript coordinates is often inconvenient. Here's
the  Asymptote way of doing the same thing, using deferred drawing:

size(200,100);
fill((0,0)--(1,1)--(2,0)--cycle);
 
void clip(picture pic=currentpicture, real width, real height) 
{
  pic.clip(new void (frame f, transform) { 
    pair center=0.5(min(f)+max(f));
    pair delta=0.5(width,height);
    clip(f,box(center-delta,center+delta));
  });
} 
 
clip(100,100);
See also the discussion of tilings in the documentation:
https://asymptote.sourceforge.io/doc/Pens.html.


File: asy-faq.info, Node: Section 9, Previous: Section 8, Up: Top

Questions about output

* Menu:
* Question 9.1::    How can I disable automatic invocation of the PS
                    viewer after an asy file is done processing?
* Question 9.2::    How do I output jpeg images?
* Question 9.3::    Can I embed bitmaps (photos) into my drawings and
                    position and scale them?
* Question 9.4::    Does Asymptote support direct PDF output?
* Question 9.5::    How to I produce large pictures of high quality in
                    raster format (e.g. png, giff etc).
* Question 9.6::    Is it possible to produce multi-page documents with
                    asymptote?



File: asy-faq.info, Node: Question 9.1, Next: Question 9.2, Previous: Question 8.9, Up: Section 9

Question 9.1.  How can I disable automatic invocation of the PS viewer after an asy file is done processing?

It's actually not on by default, unless you happen to be using Microsoft
Windows (because that is what most Microsoft Windows users expect).
Microsoft Windows users can turn this feature off with the command-line
option -noV or by putting

import settings;
interactiveView=false;
batchView=false;
in their config.asy file. See
https://asymptote.sourceforge.io/doc/Options.html.


File: asy-faq.info, Node: Question 9.2, Next: Question 9.3, Previous: Question 9.1, Up: Section 9

Question 9.2.  How do I output jpeg images?

If you have the ImageMagick convert program installed, simply type

asy -f jpg test.asy 

File: asy-faq.info, Node: Question 9.3, Next: Question 9.4, Previous: Question 9.2, Up: Section 9

Question 9.3.  Can I embed bitmaps (photos) into my drawings and position and scale them?

Convert them to eps format and use the graphic(string) function just like
a Label:

label(graphic("file"),(0,0));
See the example https://asymptote.sourceforge.io/gallery/orthocenter.asy
and https://asymptote.sourceforge.io/doc/label.html.


File: asy-faq.info, Node: Question 9.4, Next: Question 9.5, Previous: Question 9.3, Up: Section 9

Question 9.4.  Does Asymptote support direct PDF output?

Yes, PDF output can be produced by the -f pdf option or -tex pdflatex
option.  This supports transparency, annotations, embedded movies, and
U3D/PRC content.


File: asy-faq.info, Node: Question 9.5, Next: Question 9.6, Previous: Question 9.4, Up: Section 9

Question 9.5.  How to I produce large pictures of high quality in raster format (e.g. png, giff etc).

Try using some of the options to convert, mainly -geometry and -density.
For example:
convert -geometry 1000x3000 example.eps example.png 
You can also change the default resolution of the image with:
convert -geometry 1000x3000 -density 300 -units PixelsPerInch example.eps example.png 
This does not change the number of pixels in the image, but just gives a
hint  as to how large each pixel should be displayed.

If you include the -density option without the -geometry option, convert
will  keep the image size constant (so a 4cm x 3cm eps figure will
generate a 4cm x 3cm png  image).


File: asy-faq.info, Node: Question 9.6, Previous: Question 9.5, Up: Section 9

Question 9.6.  Is it possible to produce multi-page documents with asymptote?

Yes, simply call the newpage() function. This is used by the slide.asy
package to produce high-quality slide presentations (easier to use than
Prosper).