Debian Codegraph @

texmf-dist/doc/support/runtexfile/examples/test3.tex

raw
1 %! HV lualatex
2 %! HV asy <!!file!!-*.asy>
3 %! HV lualatex
4
5 \documentclass[12pt]{article}
6
7 % Use this form to include EPS (latex) or PDF (pdflatex) files:
8 %\usepackage{asymptote}
9
10 % Use this form with latex or pdflatex to include inline LaTeX code by default:
11 \usepackage[inline]{asymptote}
12
13 % Use this form with latex or pdflatex to create PDF attachments by default:
14 %\usepackage[attach]{asymptote}
15
16 % Enable this line to support the attach option:
17 %\usepackage[dvips]{attachfile2}
18
19 \begin{document}
20
21 % Optional subdirectory for latex files (no spaces):
22 \def\asylatexdir{}
23 % Optional subdirectory for asy files (no spaces):
24 \def\asydir{}
25
26 \begin{asydef}
27 // Global Asymptote definitions can be put here.
28 settings.prc=true;
29 import three;
30 usepackage("bm");
31 texpreamble("\def\V#1{\bm{#1}}");
32 // One can globally override the default toolbar settings here:
33 // settings.toolbar=true;
34 \end{asydef}
35
36 Here is a venn diagram produced with Asymptote, drawn to width 4cm:
37
38 \def\A{A}
39 \def\B{\V{B}}
40
41 %\begin{figure}
42 \begin{center}
43 \begin{asy}
44 size(4cm,0);
45 pen colour1=red;
46 pen colour2=green;
47
48 pair z0=(0,0);
49 pair z1=(-1,0);
50 pair z2=(1,0);
51 real r=1.5;
52 path c1=circle(z1,r);
53 path c2=circle(z2,r);
54 fill(c1,colour1);
55 fill(c2,colour2);
56
57 picture intersection=new picture;
58 fill(intersection,c1,colour1+colour2);
59 clip(intersection,c2);
60
61 add(intersection);
62
63 draw(c1);
64 draw(c2);
65
66 //draw("$\A$",box,z1); // Requires [inline] package option.
67 //draw(Label("$\B$","$B$"),box,z2); // Requires [inline] package option.
68 draw("$A$",box,z1);
69 draw("$\V{B}$",box,z2);
70
71 pair z=(0,-2);
72 real m=3;
73 margin BigMargin=Margin(0,m*dot(unit(z1-z),unit(z0-z)));
74
75 draw(Label("$A\cap B$",0),conj(z)--z0,Arrow,BigMargin);
76 draw(Label("$A\cup B$",0),z--z0,Arrow,BigMargin);
77 draw(z--z1,Arrow,Margin(0,m));
78 draw(z--z2,Arrow,Margin(0,m));
79
80 shipout(bbox(0.25cm));
81 \end{asy}
82 %\caption{Venn diagram}\label{venn}
83 \end{center}
84 %\end{figure}
85
86 Each graph is drawn in its own environment. One can specify the width
87 and height to \LaTeX\ explicitly. This 3D example can be viewed
88 interactively either with Adobe Reader or Asymptote's fast OpenGL-based
89 renderer. To support {\tt latexmk}, 3D figures should specify
90 \verb+inline=true+. It is sometimes desirable to embed 3D files as annotated
91 attachments; this requires the \verb+attach=true+ option as well as the
92 \verb+attachfile2+ \LaTeX\ package.
93 \begin{center}
94 \begin{asy}[height=4cm,inline=true,attach=false,viewportwidth=\linewidth]
95 currentprojection=orthographic(5,4,2);
96 draw(unitcube,blue);
97 label("$V-E+F=2$",(0,1,0.5),3Y,blue+fontsize(17pt));
98 \end{asy}
99 \end{center}
100
101 One can also scale the figure to the full line width:
102 \begin{center}
103 \begin{asy}[width=\the\linewidth,inline=true]
104 pair z0=(0,0);
105 pair z1=(2,0);
106 pair z2=(5,0);
107 pair zf=z1+0.75*(z2-z1);
108
109 draw(z1--z2);
110 dot(z1,red+0.15cm);
111 dot(z2,darkgreen+0.3cm);
112 label("$m$",z1,1.2N,red);
113 label("$M$",z2,1.5N,darkgreen);
114 label("$\hat{\ }$",zf,0.2*S,fontsize(24pt)+blue);
115
116 pair s=-0.2*I;
117 draw("$x$",z0+s--z1+s,N,red,Arrows,Bars,PenMargins);
118 s=-0.5*I;
119 draw("$\bar{x}$",z0+s--zf+s,blue,Arrows,Bars,PenMargins);
120 s=-0.95*I;
121 draw("$X$",z0+s--z2+s,darkgreen,Arrows,Bars,PenMargins);
122 \end{asy}
123 \end{center}
124 \end{document}