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)
6 #+AUTHOR: Eric Schulte, Dan Davison
7 #+EMAIL: schulte.eric at gmail dot com, davison at stats dot ox dot ac dot uk
11 # #+INFOJS_OPT: view:content
15 <p>executable source code blocks in org-mode</p>
19 <img src="images/tower-of-babel.png" alt="images/tower-of-babel.png"/>
22 <a href="http://commons.wikimedia.org/wiki/Pieter_Brueghel_the_Elder" title="">
23 <b>Pieter Brueghel the Elder</b>
27 And the Lord said, Behold, the people is one, and they have all
28 one language; and this they begin to do; and now nothing will be
29 restrained from them, which they have imagined to do. Genesis
43 :CUSTOM_ID: introduction
45 Org-babel is an extension to the very excellent [[http://orgmode.org/][Org-mode]], providing
46 the ability to execute source code in many different languages
47 within org-mode documents. The results of code execution --- text,
48 tables and graphics --- can be integrated into the powerful
49 publishing facilities of org-mode. Org-mode is an [[http://www.gnu.org/software/emacs/][Emacs]] major mode
50 for doing almost anything with plain text. If you are not familiar
51 with Org-mode please take a moment to read [[http://orgmode.org/][the Org-mode homepage]]
54 Org-babel provides the following modifications to [[http://orgmode.org/manual/Literal-examples.html][the existing
55 support]] for blocks of source code examples in the org-mode core.
57 1. Interactive source code execution
58 2. Arguments to source code blocks
59 3. Exportation of source code blocks to files (literate programming)
63 :CUSTOM_ID: getting-started
66 1) Grab the latest code from the git repo at [[http://github.com/eschulte/org-babel/tree/master][github/org-babel]]
68 git clone git://github.com/eschulte/org-babel.git
71 2) Add the following lines to your .emacs, replacing the path as
72 appropriate. A good place to check that things are up and running
73 would the examples in [[* Basic org-babel functionality][Basic org-babel functionality]].
74 #+begin_src emacs-lisp
75 (add-to-list 'load-path "/path/to/org-babel/lisp")
76 (require 'org-babel-init)
79 3) Finally, activate the subset of supported Org-babel languages
80 which you want to be able to execute on your system. As an
81 example, the following activates python, ruby and R. For a full
82 list of languages, with notes on their dependencies see the
83 [[#reference-and-documentation][Reference / Documentation]] section below.
84 #+begin_src emacs-lisp
85 (require 'org-babel-python)
86 (require 'org-babel-ruby)
87 (require 'org-babel-R)
89 ;; Once you've activated languages, load the library of babel to
90 ;; make pre-built helper functions available in the languages you will be using.
91 (org-babel-load-library-of-babel)
94 * Basic org-babel functionality
96 :CUSTOM_ID: basic-functionality
98 *** Source code blocks
100 :CUSTOM_ID: source-code-blocks
103 Org-babel is all about *source code blocks* in org mode. These are
104 blocks of code (in whatever language), that can occur anywhere in
105 an org-mode file. For example, the following is a source block
106 containing [[http://www.ruby-lang.org/][ruby]] code:
109 : "This file was last evaluated on #{Date.today}"
112 If you are unfamiliar with the notion of a source code block in
113 org-mode, please have a look at the [[http://orgmode.org/manual/Literal-examples.html][relevant manual section]] before
116 Note that above is what the source block looks like in the org-mode
117 file. We had to take [[http://orgmode.org/manual/Literal-examples.html#Literal-examples][special steps]] to make it look that way in the
118 HTML output. Normally, when exported to HTML, source blocks are
119 fontified according to their language, and the begin_src...end_src
120 mark-up is omitted, like this:
123 "This file was last evaluated on #{Date.today}"
126 From now on, if you are viewing the HTML version, you will see the
127 HTML output only. However, much of this document consists of
128 interactive examples, and therefore in order to get a feeling for the
129 mechanics of Org-babel it might make most sense to grab the plain text
131 #+HTML: <a href="org-babel-worg.org">org-babel-worg.org</a>
132 and work through it in Emacs. Alternatively the htmlized
133 version of the plain text of this file at
134 #+HTML: <a href="org-babel-worg.org.html">org-babel-worg.html</a>
135 allows the plain text version to be viewed (non-interactively) in a web browser.
136 *** Source code execution
138 :CUSTOM_ID: source-code-execution
140 For interpreted languages such as shell, python, R, etc, org-babel
141 allows source blocks to be executed: the code is passed to the
142 interpreter and you have control over what is done with the results of
143 execution. Here are three examples of code blocks in three different
144 languages, followed by their output. If you are viewing the plain text
145 version of this document in emacs, place point anywhere inside the
146 blocks and use =C-c C-c= to run the code[fn:1] (and feel free to alter
151 "This file was last evaluated on #{Date.today}"
155 : This file was last evaluated on 2009-08-09
157 **** [[http://www.r-project.org/][R]]
158 #+begin_src R :results value
159 matrix(rnorm(6), nrow=2)
163 | -0.138279734486552 | -2.2476234005706 | -0.0839549402407832 |
164 | 0.0730510956002737 | 0.0634015508602321 | 0.174013159381603 |
166 **** [[http://ditaa.sourceforge.net/][ditaa]]
167 #+begin_src ditaa :file images/blue.png :cmdline -r
178 [[file:images/blue.png]]
180 *** Source code block syntax
182 The basic syntax of source-code blocks in Org-babel is as follows:
184 : #+srcname: name(arguments)
185 : #+begin_src language header-arguments
189 - name :: This name is associated with the source-code block. This is
190 similar to the =#+tblname= lines which can be used to name tables
191 in org-mode files. By referencing the srcname of a source-code
192 block it is possible to evaluate the block from other places,
193 files, or from inside tables.
194 - arguments :: Code blocks can have arguments (see [[#arguments-to-source-code-blocks][below]]) which are
195 provided using a familiar function-call syntax similar
196 to (e.g.) python or R.
197 - language :: The language of the code in the source-code block. Valid
198 values must be members of `org-babel-interpreters'.
199 - header-arguments :: Header arguments control many facets of the
200 evaluation and output of source-code blocks. See the [[* Header Arguments][Header
201 Arguments]] section for a complete review of available header
203 - body :: The actual source code which will be evaluated. An
204 important key-binding to become familiar with is =C-c
205 '=. This calls `org-edit-special' which brings up an edit
206 buffer containing the code using the emacs major mode
207 appropriate to the language.
209 *** What happens to the results?
213 Org-babel provides two fundamentally different modes for capturing
214 the results of code evaluation, specified by the =:results= header
216 **** =:results value= (functional mode)
217 This means that the 'result' of code evaluation is defined to be
218 the *value* of the last statement in the block. Thus with this
219 setting, one can view the code block as a function with a return
220 value. And not only can you view it that way, but you can
221 actually use the return value of one source block as input for
222 another (see [[meta-programming-language]]). This setting is the
225 As an example, consider the following block of python code and its
228 #+begin_src python :results value
230 print("Hello, today's date is %s" % time.ctime())
231 print('Two plus two is')
238 Notice that in functional mode, the output consists of the value of
239 the last statement, and nothing else.
241 **** =:results output= (scripting mode)
242 With this setting, org-babel captures all the text output of the
243 code block and places it in the org buffer. One can think of this
244 as a 'scripting' mode: the code block contains a series of
245 commands, and you get the output of all the commands. Unlike in
246 the 'functional' mode, the code block has no return value. (This
247 mode will be more familiar to Sweave users).
249 Now consider the result of evaluating the same source block as
250 before, but under scripting mode.
253 #+begin_src python :results output
255 print("Hello, today's date is %s" % time.ctime())
256 print('Two plus two is')
261 : Hello, today's date is Fri Sep 4 19:49:06 2009
264 Again, we got what we asked for: all the text output (stdout) from
265 python. Since we didn't print the last value (2 + 2), we didn't get it
268 *** Arguments to source code blocks
270 :CUSTOM_ID: arguments-to-source-code-blocks
272 In addition to evaluation of code blocks, org-babel allows them to
273 be parameterised (i.e. have arguments). Thus source code blocks
274 now have the status of *functions*. Arguments to code blocks can
275 be used in both functional and scripting mode.
277 **** Simple example of using a source block as a function
279 First let's look at a very simple example. The following source
280 block defines an org-babel function that will square its input.
287 In the org-mode file that looks like this:
288 : #+srcname: square(x)
294 Now we use the source block:
297 (/for information on the/ =lob= /syntax see [[library-of-babel]]/)
301 #+resname: square(x=6)
304 **** A more complex example: using an org-table as input
306 In this example we're going to define a function to compute a
307 Fibonacci sequence, and we're going to make it take its input
308 from a table in the org-mode buffer.
310 Here are the inputs for fibonacci-seq:
312 #+tblname: fibonacci-inputs
313 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 |
314 | 2 | 4 | 6 | 8 | 10 | 12 | 14 | 16 | 18 | 20 |
316 in the Org-mode buffer this looks like
317 : #+tblname: fibonacci-inputs
318 : | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 |
319 : | 2 | 4 | 6 | 8 | 10 | 12 | 14 | 16 | 18 | 20 |
321 [[http://www.gnu.org/software/emacs/manual/elisp.html][Emacs Lisp]] source code
322 #+srcname: fibonacci-seq(fib-inputs=fibonacci-inputs)
323 #+begin_src emacs-lisp
325 (if (or (= n 0) (= n 1))
327 (+ (fibonacci (- n 1)) (fibonacci (- n 2)))))
329 (mapcar (lambda (row)
330 (mapcar #'fibonacci row)) fib-inputs)
333 in the Org-mode buffer this looks like
334 : #+srcname: fibonacci-seq(fib-inputs=fibonacci-inputs)
335 : #+begin_src emacs-lisp
336 : (defun fibonacci (n)
337 : (if (or (= n 0) (= n 1))
339 : (+ (fibonacci (- n 1)) (fibonacci (- n 2)))))
341 : (mapcar (lambda (row)
342 : (mapcar #'fibonacci row)) fib-inputs)
345 Results of Emacs Lisp code evaluation
347 | 1 | 1 | 2 | 3 | 5 | 8 | 13 | 21 | 34 | 55 |
348 | 1 | 3 | 8 | 21 | 55 | 144 | 377 | 987 | 2584 | 6765 |
350 * A meta-programming language for org-mode
352 :CUSTOM_ID: meta-programming-language
355 Since information can pass freely between source-code blocks and
356 org-mode tables you can mix and match languages using each language
357 for those tasks to which it is suited. This makes Org-mode files with
358 Org-babel into a kind of meta-functional programming language in which
359 functions from many languages can work together.
361 As an example, lets take some system diagnostics in the shell, and
362 then graph them with R.
364 1. First we create a code block containing shell code creating a list
365 of the directories in our home directory, together with their
366 sizes. Org-babel automatically converts the output into an org
369 #+srcname: directories
370 #+begin_src bash :results replace
371 cd ~ && du -sc * |grep -v total
374 #+resname: directories
376 | 12156104 | "Documents" |
377 | 3482440 | "Downloads" |
378 | 2901720 | "Library" |
380 | 16548024 | "Music" |
382 | 7649472 | "Pictures" |
390 2. Now we use a single line of R code to plot the data as a
391 pie-chart. Note the way that this source block uses the =srcname=
392 of the previous source block to obtain the data.
393 #+srcname: directory-pie-chart(dirs = directories)
394 #+begin_src R :session R-pie-example
395 pie(dirs[,1], labels = dirs[,2])
397 [[file:images/dirs.png]]
399 * Multilingual spreadsheet plugins for org-mode
401 :CUSTOM_ID: spreadsheet
404 *** Example 1: data summaries using R
405 As a simple example, we'll fill in a cell in an org-table with the
406 average value of a few numbers. First, let's make some data. The
407 following source block creates an org table filled with five random
408 numbers between 0 and 1.
410 #+srcname: tbl-example-data()
412 runif(n=5, min=0, max=1)
415 #+resname: tbl-example-data
416 | 0.850250755203888 |
417 | 0.745323235634714 |
418 | 0.845673063071445 |
419 | 0.761818468105048 |
420 | 0.525476417969912 |
422 Now we define a source block to do the calculation we want.
428 Finally we create the table which is going to make use of the R
429 code. This is done using the =sbe= ('source block evaluate') macro in
430 the table formula line.
433 |-------------------|
434 | 0.533130449522286 |
435 #+TBLFM: @2$1='(sbe "R-mean" (x "generate-data()"))
437 To recalculate the table formula, use =C-u C-c C-c= in the
438 table. Notice that as things stand the calculated value doesn't
439 change, because the data (held in the table above named
440 "tbl-example-data") are static. However, if you delete that data table
441 then the reference will be interpreted as a reference to the source
442 block responsible for generating the data; each time the table formula
443 is recalculated the source block will be evaluated again, and
444 therefore the calculated average value will change.
446 *** Example 2: Org-babel test suite
447 Not only can Org-babel pass entire tables of data to source code
448 blocks (see [[arguments-to-source-code-blocks]]), Org-babel can also be
449 used to call source code blocks from *within* tables using the
450 Org-mode's [[http://orgmode.org/manual/The-spreadsheet.html#The-spreadsheet][existing spreadsheet functionality]].
452 In fact the functional test suite for Org-babel is implemented as a
453 large Org-mode table. To run the entire test suite you simple
454 evaluate the table =C-u C-c C-c=, and all of the tests are run
455 updating the table with pass/fail statistics.
457 Here's a sample of our test suite.
459 #+TBLNAME: org-babel-tests
460 | functionality | block | arg | expected | results | pass |
461 |------------------+--------------+-----+-------------+-------------+------|
462 | basic evaluation | | | | | pass |
463 |------------------+--------------+-----+-------------+-------------+------|
464 | emacs lisp | basic-elisp | 2 | 4 | 4 | pass |
465 | shell | basic-shell | | 6 | 6 | pass |
466 | ruby | basic-ruby | | org-babel | org-babel | pass |
467 | python | basic-python | | hello world | hello world | pass |
468 | R | basic-R | | 13 | 13 | pass |
469 #+TBLFM: $5='(if (= (length $3) 1) (sbe $2 (n $3)) (sbe $2)) :: $6='(if (string= $4 $5) "pass" (format "expected %S but was %S" $4 $5))
471 **** code blocks for tests
473 #+srcname: basic-elisp(n)
474 #+begin_src emacs-lisp
478 #+srcname: basic-shell
479 #+begin_src sh :results silent
483 #+srcname: date-simple
484 #+begin_src sh :results silent
488 #+srcname: basic-ruby
489 #+begin_src ruby :results silent
493 #+srcname: basic-python
494 #+begin_src python :results silent
499 #+begin_src R :results silent
504 * The Library of Babel
506 :CUSTOM_ID: library-of-babel
511 <img src="images/library-of-babel-clayette.png" />
513 The Library of Babel, by Pierre Clayette
515 <a href="http://downlode.org/Etext/library_of_babel.html">Full text of the Borges short story</a>
522 As we saw above with the [[*Simple%20example%20of%20using%20a%20source%20block%20as%20a%20function][=square=]] example, once a source block
523 function has been defined it can be called using the following short
528 But what about those source code blocks which are so useful you want
529 to have them available in every org-mode buffer?
531 In addition to the current buffer, Org-babel searches for
532 pre-defined source block functions in the Library of Babel. This is
533 a user-extensible collection of ready-made source-code blocks for
534 handling common tasks. One use for the LoB (not yet done!) will be
535 to provide a choice of data graphing procedures for data held in
536 org-mode tables, using languages such as R, gnuplot, asymptote,
537 etc. If you implement something that might be of use to other org
538 users, please consider adding it to the LoB; similarly, feel free to
539 request help solving a problem using external code via org-babel --
540 there's always a chance that other org users will be able to
541 contribute some helpful code. Org-mode demonstrates that an enormous
542 amount can be achieved using plain text and emacs lisp; the LoB is
543 intended to fill in the gaps.
545 Org-babel comes pre-populated with the source-code blocks located in
546 the [[file:library-of-babel.org][library-of-babel.org]] file. It is possible to add source-code
547 blocks from any org-mode file to the library by calling
549 #+srcname: add-file-to-lob
550 #+begin_src emacs-lisp
551 (org-babel-lob-ingest "path/to/file.org")
554 Note that it is also possible to pass table values or the output of
555 a source-code block to lob functions, and it is possible to
556 reference lob functions in source block arguments.
558 * Reproducible Research
560 :CUSTOM_ID: reproducable-research
563 An article about computational science in a scientific publication is
564 not the scholarship itself, it is merely advertising of the
565 scholarship. The actual scholarship is the complete software
566 development environment and the complete set of instructions which
567 generated the figures.
572 [[http://reproducibleresearch.net/index.php/Main_Page][Reproducible Research]] (RR) is the practice of distributing along with
573 an article of research all data, code, and tools required to reproduce
574 the results discussed in the paper. As such the paper becomes not
575 only a document describing the research but a complete laboratory in
576 which the research can be reproduced and extended.
578 Org-mode already has exceptional support for [[http://orgmode.org/manual/Exporting.html#Exporting][exporting to html and
579 LaTeX]]. Org-babel makes Org-mode a tool for RR by *activating* the
580 data and source code embedded into Org-mode documents making the
581 entire document executable. This makes it not only possible, but
582 natural to distribute research in a format that encourages readers to
583 recreate your results, and perform their own analysis.
585 One notable existing RR tool is [[http://en.wikipedia.org/wiki/Sweave][Sweave]] which provides for the
586 embedding of [[http://www.r-project.org/][R]] code into LaTeX documents. While Sweave is a mature
587 and very useful tool, we believe that Org-babel has several
589 - It supports multiple languages (we're not aware of other RR tools that do this)
590 - The [[http://orgmode.org/manual/Exporting.html#Exporting][export process]] is flexible and powerful, including HTML as a target in addition to LaTeX
591 - The document can make native use of all the features of Org-mode,
592 such as those for [[http://orgmode.org/manual/Agenda-Views.html#Agenda-Views][project planning]] and [[http://orgmode.org/manual/TODO-Items.html#TODO-Items][task management]]
594 * Literate programming
596 :CUSTOM_ID: literate-programming
600 Let us change our traditional attitude to the construction of
601 programs: Instead of imagining that our main task is to instruct a
602 /computer/ what to do, let us concentrate rather on explaining to
603 /human beings/ what we want a computer to do.
605 The practitioner of literate programming can be regarded as an
606 essayist, whose main concern is with exposition and excellence of
607 style. Such an author, with thesaurus in hand, chooses the names of
608 variables carefully and explains what each variable means. He or she
609 strives for a program that is comprehensible because its concepts have
610 been introduced in an order that is best for human understanding,
611 using a mixture of formal and informal methods that reinforce each
617 Org-babel supports [[http://en.wikipedia.org/wiki/Literate_programming][Literate Programming]] (LP) by allowing the act of
618 programming to take place inside of Org-mode documents. The Org-mode
619 file can then be exported (*woven* in LP speak) to html or LaTeX for
620 consumption by a human, and the embedded source code can be extracted
621 (*tangled* in LP speak) into structured source code files for
622 consumption by a computer.
624 To support these operations Org-babel relies on Org-mode's [[http://orgmode.org/manual/Exporting.html#Exporting][existing
625 exporting functionality]] for *weaving* of documentation, and on the
626 =org-babel-tangle= function which makes use of [[http://www.cs.tufts.edu/~nr/noweb/][Noweb]] [[reference-expansion][reference syntax]]
627 for *tangling* of code files.
629 The [[literate-programming-example][following example]] demonstrates the process of *tangling* in
632 *** Simple Literate Programming Example (Noweb syntax)
634 :CUSTOM_ID: literate-programming-example
637 Tangling functionality is controlled by the =tangle= family of
638 [[header-arguments]]. These arguments can be used to turn tangling on or
639 off (the default) on the source code block, or the outline heading
642 The following demonstrates the combination of three source code blocks
643 into a single source code file using =org-babel-tangle=.
645 The following two blocks will not be tangled by default since they
646 have no =tangle= header arguments.
648 #+srcname: hello-world-prefix
649 #+begin_src sh :exports none
650 echo "/-----------------------------------------------------------\\"
653 : #+srcname: hello-world-prefix
654 : #+begin_src sh :exports none
655 : echo "/-----------------------------------------------------------\\"
658 #+srcname: hello-world-postfix
659 #+begin_src sh :exports none
660 echo "\-----------------------------------------------------------/"
663 : #+srcname: hello-world-postfix
664 : #+begin_src sh :exports none
665 : echo "\-----------------------------------------------------------/"
669 The third block does have a =tangle= header argument indicating the
670 name of the file to which it should be written. It also has [[http://www.cs.tufts.edu/~nr/noweb/][Noweb]]
671 style references to the two previous source code blocks which will be
672 expanded during tangling to include them in the output file as well.
674 #+srcname: hello-world
675 #+begin_src sh :tangle hello :exports none
676 # <<hello-world-prefix>>
677 echo "| hello world |"
678 # <<hello-world-postfix>>
681 : #+srcname: hello-world
682 : #+begin_src sh :tangle hello :exports none
683 : # <<hello-world-prefix>>
684 : echo "| hello world |"
685 : # <<hello-world-postfix>>
688 Calling =org-babel-tangle= will result in the following being written
689 to the =hello.sh= file.
691 #+srcname: hello-world-output
694 # generated by org-babel-tangle
696 # [[file:~/src/org-babel/org-babel-worg.org::#literate-programming-example][block-16]]
697 # <<hello-world-prefix>>
698 echo "/-----------------------------------------------------------\\"
700 echo "| hello world |"
701 # <<hello-world-postfix>>
702 echo "\-----------------------------------------------------------/"
706 *** Emacs Initialization with Org-babel
707 Org-babel has special support for embedding your emacs initialization
708 into Org-mode files. The =org-babel-load-file= function can be used
709 to load the emacs lisp embedded in a literate Org-mode file in the
710 same way that you might load a regular elisp file.
712 This allows you to have all the niceness of Org-mode (folding, tags,
713 notes, html export, etc...) available in your emacs initialization.
715 To try this out either see the simple [[literate-emacs-init][Literate Emacs Initialization]]
716 example directly below, or check out the Org-babel Literate
717 Programming version of Phil Hagelberg's excellent [[http://github.com/technomancy/emacs-starter-kit/tree/master][emacs-starter-kit]]
718 available at [[http://github.com/eschulte/emacs-starter-kit/tree/master][Org-babel-emacs-starter-kit]].
720 ***** Literate Emacs Initialization
722 :CUSTOM_ID: literate-emacs-init
725 For a simple example of usage follow these 4 steps.
727 1) create a directory named =.emacs.d= in the base of your home
732 2) checkout the latest versions of Org-mode and Org-babel into the src
733 subdirectory of this new directory
738 git clone git://repo.or.cz/org-mode.git
739 git clone git://github.com/eschulte/org-babel.git
741 3) place the following in a file called =init.el= in your emacs
742 initialization directory (=~/.emacs.d=).
743 #+srcname: emacs-init
744 #+begin_src emacs-lisp
745 ;;; init.el --- Where all the magic begins
747 ;; This file loads both
748 ;; - Org-mode : http://orgmode.org/ and
749 ;; - Org-babel: http://eschulte.github.com/org-babel/
751 ;; It then loads the rest of our Emacs initialization from Emacs lisp
752 ;; embedded in literate Org-mode files.
754 ;; Load up Org Mode and Org Babel for elisp embedded in Org Mode files
755 (setq dotfiles-dir (file-name-directory (or (buffer-file-name) load-file-name)))
756 (add-to-list 'load-path (expand-file-name
757 "lisp" (expand-file-name
758 "org" (expand-file-name
759 "src" dotfiles-dir))))
760 (add-to-list 'load-path (expand-file-name
761 "lisp" (expand-file-name
762 "org-babel" (expand-file-name
763 "src" dotfiles-dir))))
764 (require 'org-babel-init)
766 ;; load up all literate org-mode files in this directory
767 (mapc #'org-babel-load-file (directory-files dotfiles-dir t "\\.org$"))
769 ;;; init.el ends here
771 4) Implement all of your emacs customizations inside of elisp
772 source-code blocks located in Org-mode files in this directory.
773 They will be loaded by emacs on startup.
775 * Reference / Documentation
777 :CUSTOM_ID: reference-and-documentation
780 The following can be added to your .emacs and used to activate
781 languages. It includes a brief list of the requirements for each
782 language. *Note*: this also serves as the list of languages
783 currently supported by Org-babel.
784 #+begin_src emacs-lisp
785 ;; Uncomment each of the following require lines if you want org-babel
786 ;; to support that language. Each language has a comment explaining
787 ;; it's dependencies. See the related files in lisp/langs for more
788 ;; detailed explanations of requirements.
789 ;; (require 'org-babel-R) ;; R and ess-mode
790 ;; (require 'org-babel-asymptote) ;; asymptote
791 ;; (require 'org-babel-css) ;; none
792 ;; (require 'org-babel-ditaa) ;; ditaa
793 ;; (require 'org-babel-dot) ;; dot
794 ;; (require 'org-babel-gnuplot) ;; gnuplot, and gnuplot-mode
795 ;; (require 'org-babel-haskell) ;; haskell, haskell-mode, inf-haskell
796 ;; (require 'org-babel-ocaml) ;; ocaml, and tuareg-mode
797 ;; (require 'org-babel-python) ;; python, and python-mode
798 ;; (require 'org-babel-ruby) ;; ruby, irb, ruby-mode, and inf-ruby
799 ;; (require 'org-babel-sass) ;; sass, sass-mode
800 ;; (require 'org-babel-sql) ;; none
805 :CUSTOM_ID: header-arguments
808 - results :: results arguments specify what should be done with the
809 output of source-code blocks
810 - The following options are mutually exclusive, and specify how the
811 results should be collected from the source-code block
814 - The following options are mutually exclusive and specify what type
815 of results the code block will return
816 - vector :: specifies that the results should be interpreted as a
817 multidimensional vector (even if the vector is
818 trivial), and will be inserted into the org-mode file
820 - scalar :: specifies that the results should be interpreted as a
821 scalar value, and will be inserted into the org-mode
823 - file :: specifies that the results should be interpreted as the
824 path to a file, and will be inserted into the org-mode
826 - The following options specify how the results should be inserted
827 into the org-mode file
828 - replace :: the current results replace any previously inserted
829 results from the code block
830 - silent :: rather than being inserted into the org-mode file the
831 results are echoed into the message bar
832 - exports :: exports arguments specify what should be included in html
833 or latex exports of the org-mode file
834 - code :: the body of code is included into the exported file
835 - results :: the results of evaluating the code is included in the
837 - both :: both the code and results are included in the exported
839 - none :: nothing is included in the exported file
840 - tangle :: tangle arguments specify whether or not the source-code
841 block should be included in tangled extraction of
843 - yes :: the source-code block is exported to a source-code file
844 named after the basename (name w/o extension) of the
846 - no :: (default) the source-code block is not exported to a
848 - other :: any other string passed to the =tangle= header argument
849 is interpreted as a file basename to which the block will
852 *** Noweb reference syntax
853 The [[http://www.cs.tufts.edu/~nr/noweb/][Noweb]] Literate Programming system allows named blocks of code to
854 be referenced by using a =<<code-block-name>>= syntax. When a
855 document is tangled these references are replaced with the named code.
856 An example is provided in the [[literate-programming-example]] in this
861 [fn:1] Calling =C-c C-o= on a source-code block will open the
862 block's results in a separate buffer.