1 #+OPTIONS: H:3 num:nil toc:2 \n:nil @:t ::t |:t ^:{} -:t f:t *:t TeX:t LaTeX:t skip:nil d:(HIDE) tags:not-in-toc
2 #+STARTUP: align fold nodlcheck hidestars oddeven lognotestate hideblocks
3 #+SEQ_TODO: TODO(t) INPROGRESS(i) WAITING(w@) | DONE(d) CANCELED(c@)
4 #+TAGS: Write(w) Update(u) Fix(f) Check(c) noexport(n)
5 #+TITLE: Asymptote Source Code Blocks in Org Mode
6 #+AUTHOR: Thomas S. Dye
7 #+EMAIL: tsd[at]tsdye[dot]com
9 #+STYLE: <style type="text/css">#outline-container-introduction{ clear:both; }</style>
10 #+LINK_UP: ../languages.html
11 #+LINK_HOME: http://orgmode.org/worg/
12 #+EXPORT_EXCLUDE_TAGS: noexport
16 <div id="subtitle" style="float: center; text-align: center;">
18 Org Mode support for <a href="http://asymptote.sourceforge.net/">Asymptote</a>
21 <a href="http://asymptote.sourceforge.net/">
22 <img src="images/asymptote.png" width=200/>
28 * Template Checklist [12/12] :noexport:
30 - [X] Indicate #+AUTHOR:
32 - [X] Revise banner source block [3/3]
33 - [X] Add link to a useful language web site
34 - [X] Replace "Language" with language name
35 - [X] Find a suitable graphic and use it to link to the language
37 - [X] Write an [[Introduction]]
38 - [X] Describe [[Requirements%20and%20Setup][Requirements and Setup]]
39 - [X] Replace "Language" with language name in [[Org%20Mode%20Features%20for%20Language%20Source%20Code%20Blocks][Org Mode Features for Language Source Code Blocks]]
40 - [X] Describe [[Header%20Arguments][Header Arguments]]
41 - [X] Describe support for [[Sessions]]
42 - [X] Describe [[Result%20Types][Result Types]]
43 - [X] Describe [[Other]] differences from supported languages
44 - [X] Provide brief [[Examples%20of%20Use][Examples of Use]]
47 Asymptote is a powerful descriptive vector graphics language with a
48 coordinate-based framework for technical drawing. Labels and equations
49 are typeset with LaTeX. It is distributed with the GNU Lesser
50 General Public License.
52 Asymptote can produce graphics in any format supported by [[http://www.imagemagick.org/script/index.php][ImageMagick]],
53 but it excels at producing PostScript files suited for typesetting
56 * Requirements and Setup
58 Asymptote is distributed as source code at [[http://sourceforge.net/projects/asymptote/][SourceForge]]. Binary files
59 are available for Linux and Windows. OS X users can install
60 Asymptote with =brew= or MacPorts.
62 There is an Emacs mode, [[http://asymptote.sourceforge.net/doc/Editing-modes.html][asy-mode]], for editing Asymptote files. The
63 file asy-mode.el is distributed with Asymptote. Instructions for
64 enabling asy-mode are [[http://asymptote.sourceforge.net/doc/Editing-modes.html][here]].
66 To configure Asymptote source code blocks in Org mode, add the
67 appropriate dotted pair to =org-babel-load-languages=
69 #+begin_src emacs-lisp :exports code
70 (org-babel-do-load-languages
71 'org-babel-load-languages
75 * Org Mode Features for Asymptote Source Code Blocks
78 Asymptote is a language designed to produce graphics files. The
79 default =:results= header argument is "file". The default =:exports=
80 header argument is "results".
82 The =:file= header argument is required. The extension of the file
83 name passed to =:file= determines the graphics format produced by the
84 Asymptote source code block. The default output file format is =pdf=.
86 The language-specific header argument, =:cmdline=, can be used to pass
87 options to Asymptote. The full set of options are described in =info
91 Asymptote does not support sessions.
94 Asymptote produces graphic files.
98 The following source code block produced the Asymptote logo used at
102 ,#+begin_src asymptote :file images/asymptote.png
105 size(560,320,IgnoreAspect);
107 currentprojection=perspective(-2,20,10,up=Y);
114 path A=(a,0){dir(10)}::{dir(89.5)}(0,y2);
115 path B=(0,y1){dir(88.3)}::{dir(20)}(b,0);
118 transform t=scale(1,15);
119 transform T=inverse(scale(t.yy,t.xx));
120 path[] g=shift(0,1.979)*scale(0.01)*t*
121 texpath(Label("{\it symptote}",z,0.25*E+0.169S,fontsize(24pt)));
123 pair u=intersectionpoint(A,w-1--w);
125 real h=0.25*linewidth();
127 g.push(t*((a,hy)--(b,hy)..(b+hy,0)..(b,-hy)--(a,-hy)..(a-hy,0)..cycle));
128 g.push(T*((h,y1)--(h,y2)..(0,y2+h)..(-h,y2)--(-h,y1)..(0,y1-h)..cycle));
129 g.push(shift(0,w.y)*t*((u.x,hy)--(w.x,hy)..(w.x+hy,0)..(w.x,-hy)--(u.x,-hy)..(u.x-hy,0)..cycle));
131 g.push(point(A,0)--shift(-f*hy,f*h)*A--point(A,1)--shift(f*hy,-f*h)*reverse(A)--cycle);
132 g.push(point(B,0)--shift(f*hy,-f*h)*B--point(B,1)--shift(-f*hy,f*h)*reverse(B)--cycle);
135 material m=material(lightgray,shininess=1.0);
138 draw(extrude(p,H),m);
140 surface s=surface(g);
146 #+begin_src asymptote :file images/asymptote.png
149 size(560,320,IgnoreAspect);
151 currentprojection=perspective(-2,20,10,up=Y);
158 path A=(a,0){dir(10)}::{dir(89.5)}(0,y2);
159 path B=(0,y1){dir(88.3)}::{dir(20)}(b,0);
162 transform t=scale(1,15);
163 transform T=inverse(scale(t.yy,t.xx));
164 path[] g=shift(0,1.979)*scale(0.01)*t*
165 texpath(Label("{\it symptote}",z,0.25*E+0.169S,fontsize(24pt)));
167 pair u=intersectionpoint(A,w-1--w);
169 real h=0.25*linewidth();
171 g.push(t*((a,hy)--(b,hy)..(b+hy,0)..(b,-hy)--(a,-hy)..(a-hy,0)..cycle));
172 g.push(T*((h,y1)--(h,y2)..(0,y2+h)..(-h,y2)--(-h,y1)..(0,y1-h)..cycle));
173 g.push(shift(0,w.y)*t*((u.x,hy)--(w.x,hy)..(w.x+hy,0)..(w.x,-hy)--(u.x,-hy)..(u.x-hy,0)..cycle));
175 g.push(point(A,0)--shift(-f*hy,f*h)*A--point(A,1)--shift(f*hy,-f*h)*reverse(A)--cycle);
176 g.push(point(B,0)--shift(f*hy,-f*h)*B--point(B,1)--shift(-f*hy,f*h)*reverse(B)--cycle);
179 material m=material(lightgray,shininess=1.0);
182 draw(extrude(p,H),m);
184 surface s=surface(g);
190 [[file:images/asymptote.png]]
192 The following source code block was adapted from code found in
193 [[http://marris.org/asymptote/][the gallery of Asymptote examples by Gaétan Marris]].
197 ,#+begin_src asymptote :file images/asy-tile.png
203 // on définit une courbe reliant les points (0,1) et (1,0)
204 path c=(0,1){dir(-5)}..{dir(-5)}(1,0);
205 // à l'aide de trois rotations, on définit
206 // le motif (dans un carré de 2 sur 2) ...
207 path motif=buildcycle(c,rotate(90)*c,
208 rotate(180)*c,rotate(-90)*c);
209 filldraw(pic,motif,lightred+white,black);
210 // ... et une double boucle pour "paver"
211 // suivant (Ox) et suivant (Oy)
212 for(int i=0; i<n; ++i)
214 for(int j=0; j<n; ++j)
216 add(shift(2*i,2*j)*pic);
223 #+begin_src asymptote :file images/asy-tile.png
229 // on définit une courbe reliant les points (0,1) et (1,0)
230 path c=(0,1){dir(-5)}..{dir(-5)}(1,0);
231 // à l'aide de trois rotations, on définit
232 // le motif (dans un carré de 2 sur 2) ...
233 path motif=buildcycle(c,rotate(90)*c,
234 rotate(180)*c,rotate(-90)*c);
235 filldraw(pic,motif,lightred+white,black);
236 // ... et une double boucle pour "paver"
237 // suivant (Ox) et suivant (Oy)
238 for(int i=0; i<n; ++i)
240 for(int j=0; j<n; ++j)
242 add(shift(2*i,2*j)*pic);
248 [[file:images/asy-tile.png]]