o-b-worg.org: changes to function arguments section
[org-mode.git] / org-babel-worg.org
blob17463f1a3f1d504322c49fb45526c19b4ad51ec2
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) 
5 #+TITLE:      Org-babel
6 #+AUTHOR:     Dan Davison, Eric Schulte
7 #+EMAIL:      davison at stats dot ox dot ac dot uk
8 #+LANGUAGE:   en
9 #+CATEGORY:   worg
11 #+begin_html
12   <div id="subtitle">
13     <p>executable source code blocks in org-mode</p>
14   </div>
15   <div id="logo">
16     <p>
17       <img src="images/tower-of-babel.png"  alt="images/tower-of-babel.png"
18            title="And the Lord said, Behold, the people is one, and they have all one language; and this they begin to do; and now nothing will be restrained from them, which they have imagined to do. Genesis 11:1-9"/>
19       <div id="attr">
20         from
21         <a href="http://www.flickr.com/photos/23379658@N05/" title=""><b>Martijn Streefkerk</b></a>
22       </div>
23     </p>
24   </div>
25 #+end_html
27 #+begin_html
28   <p>
29   </p>
30 #+end_html
32 * Introduction
33   :PROPERTIES:
34   :CUSTOM_ID: introduction
35   :END:
36   Org-babel is an extension to the very excellent [[http://orgmode.org/][Org-mode]]; an [[http://www.gnu.org/software/emacs/][Emacs]]
37   major mode for doing almost anything with plain text.  If you are
38   not familiar with Org-mode please take a moment to read [[http://orgmode.org/][the Org-mode
39   homepage]] before continuing.
41   Org-babel provides the following modifications to [[http://orgmode.org/manual/Literal-examples.html][the existing
42   support]] for blocks of source code examples in the org-mode core.
44   1. Interactive source code execution
45   2. Arguments to source code blocks
46   3. Exportation of source code blocks to files (literate programming)
48 * Getting started
49   :PROPERTIES:
50   :CUSTOM_ID: getting-started
51   :END:
53   1) Grab the latest code from the git repo at [[http://github.com/eschulte/org-babel/tree/master][github/org-babel]]
54      #+begin_src sh
55      git clone git://github.com/eschulte/org-babel.git
56      #+end_src
58   2) Add the following lines to your .emacs, replacing the path as
59      appropriate. A good place to check that things are up and running
60      would the examples in [[* Basic org-babel functionality][Basic org-babel functionality]].
61      #+begin_src emacs-lisp
62        (add-to-list 'load-path "/path/to/org-babel/lisp")
63        (require 'org-babel-init)
64      #+end_src
66   3) Finally, activate the subset of supported Org-babel languages
67      which you want to be able to execute on your system. As an
68      example, the following activates python, ruby and R. For a full
69      list of languages and notes on their dependencies see the
70      [[#reference-and-documentation][Reference / Documentation]] section below.
71 #+begin_src emacs-lisp
72   (require 'org-babel-python)
73   (require 'org-babel-ruby)
74   (require 'org-babel-R)
75   ;;
76   ;; Once you've activated languages, load the library of babel to
77   ;; make pre-built helper functions available in the languages you will be using.
78   (org-babel-load-library-of-babel)
79 #+end_src
80   
81 * Basic org-babel functionality
82   :PROPERTIES:
83   :CUSTOM_ID: basic-functionality
84   :END:
85 *** Source code blocks
86     :PROPERTIES:
87     :CUSTOM_ID: source-code-blocks
88     :END:
90     Org-babel is all about *source code blocks* in org mode. These are
91     blocks of code (in whatever language), surrounded by special
92     starting and ending lines. For example, the following is a source
93     block containing [[http://www.ruby-lang.org/][ruby]] code:
95 : #+begin_src ruby
96 : "This file was last evaluated on #{Date.today}"
97 : #+end_src
99 If you are unfamiliar with the notion of source code blocks in
100 org-mode, please have a look at the [[http://orgmode.org/manual/Literal-examples.html][relevant manual section]] before
101 proceding.
103 Note that above is what the source block looks like in the org-mode
104 file. We had to take [[http://orgmode.org/manual/Literal-examples.html#Literal-examples][special steps]] to make it look that way in the
105 HTML output. Normally, when exported to HTML, source blocks are
106 fontified according to their language, and the begin_src...end_src
107 mark-up is omitted, like this:
109 #+begin_src ruby
110 "This file was last evaluated on #{Date.today}"
111 #+end_src
113 From now on, if you are viewing the HTML version, you will see the
114 HTML output only. However, much of this document consists of
115 interactive examples, and therefore in order to get a feeling for the
116 mechanics of Org-babel it might make most sense to grab the plain text
117 version of this file
118 #+HTML: <a href="org-babel-worg.org">org-babel-worg.org</a>
119 and work through it in Emacs. Alternatively the htmlized
120 version of the plain text of this file at
121 #+HTML: <a href="org-babel-worg.org.html">org-babel-worg.html</a>
122 allows the plain text version to be viewed (non-interactively) in a web browser.
123 *** Source code execution
124     :PROPERTIES:
125     :CUSTOM_ID: source-code-execution
126     :END:
127 For interpreted languages such as shell, python, R, etc, org-babel
128 allows source blocks to be executed: the code is passed to the
129 interpreter and you have control over what is done with the results of
130 excecution. E.g. place point anywhere in the following blocks and use
131 =C-c C-c= to run the code[fn:1]. In each case the code comes first,
132 followed by the results of evlauting the block.
134 **** Ruby
135 #+begin_src ruby
136 "This file was last evaluated on #{Date.today}"
137 #+end_src
139 #+resname:
140 : This file was last evaluated on 2009-08-09
142 **** [[http://www.r-project.org/][R]] 
143 #+begin_src R :results value
144 matrix(rnorm(6), nrow=2)
145 #+end_src
147 #+resname:
148 |   0.496600061063252 | "-1.44355317891110" |   0.106411785870013 |
149 | "-1.81619611674921" | "-1.25542979009380" | 0.00969467528507845 |
151 **** [[http://ditaa.sourceforge.net/][ditaa]]
152 #+begin_src ditaa :file images/blue.png :cmdline -r
153 +---------+
154 | cBLU    |
155 |         |
156 |    +----+
157 |    |cPNK|
158 |    |    |
159 +----+----+
160 #+end_src
162 #+resname:
163 [[file:images/blue.png]]
165 *** New source block syntax
166     Org-babel adds some new syntactical elements to source blocks in
167     org-mode, illustrated here:
169 : #+srcname: source-block-name(arg1=value1, arg2=value2)
170 : #+begin_src language :var1 var1-value :var2 var2-value ...
172 : <code goes here>
174 : #+end_src
175     
176   Note the following two new features
177 **** =srcname= with optional arguments
178      The optional =srcname= line allows a name to be given to the
179      source block, together with any arguments to the source block
180      (see [[#arguments-to-source-code-blocks][below]])
181 **** Header arguments
182      An arbitrary series of :variable value pairs can be specified
183      after the language, controlling various aspects of org-babel
184      operation. The available header arguments are documented [[#header-arguments][below.]]
185 *** What happens to the results?
186     :PROPERTIES:
187     :CUSTOM_ID: results
188     :END:
189     Org-babel provides two fundamentally different modes for capturing
190     the results of code evaluation, specified by the =:results= header
191     argument.
192 **** =:results value= (functional mode)
193      This means that the 'result' of code evaluation is defined to be
194      the *value* of the last statement in the block. Thus with this
195      setting, one can view the code block as a function with a return
196      value. And not only can you view it that way, but you can
197      actually use the return value of one source block as input for
198      another (see later). This setting is the default.
199      
200      As an example, consider the following block of python code and its
201      output.
203 #+begin_src python :results value
204 import time
205 print("Hello, today's date is %s" % time.ctime())
206 print('Two plus two is')
207 2 + 2
208 #+end_src
210 #+resname:
211 : 4
213 Notice that in functional mode, the output consists of the value of
214 the last statement, and nothing else.
216 **** =:results output= (scripting mode)
217      With this setting, org-babel captures all the text output of the
218      code block and places it in the org buffer. One can think of this
219      as a 'scripting' mode: the code block contains a series of
220      commands, and you get the output of all the commands. Unlike in
221      the 'functional' mode, the code block has no return value. (This
222      mode will be familiar to Sweave users).
224      Now consider the result of evaluating the same source block as
225      before, but under scripting mode.
227 #+srcname: name
228 #+begin_src python :results output
229 import time
230 print("Hello, today's date is %s" % time.ctime())
231 print('Two plus two is')
232 2 + 2
233 #+end_src
235 #+resname: name
236 : Hello, today's date is Fri Sep  4 19:49:06 2009
237 : Two plus two is
239 So, we got what we asked for: all the text output by python
240 (stdout). Since we didn't print the last value (2 + 2), we didn't get
241 it in our output.
243 *** Arguments to source code blocks
244     :PROPERTIES:
245     :CUSTOM_ID: arguments-to-source-code-blocks
246     :END:
247     In addition to evaluation of code blocks, org-babel allows them to
248     be parameterised (i.e. have arguments). Thus source code blocks
249     now have the status of *functions*. Arguments to code blocks can
250     be used in both functional and scripting mode.
252 **** Simple example of using a source block as a function
254      First let's look at a very simple example. The following source
255      block defines an org-babel function that will square its input.
257 #+srcname: square(x)
258 #+begin_src python
260 #+end_src
262 In the org-mode file that looks like this:
263 : #+srcname: square(x)
264 : #+begin_src python
265 : x*x
266 : #+end_src
269 Now we use the source block:
271 : #+lob: square(x=6)
273 #+lob: square(x=6)
275 #+resname: square(x=6)
276 : 36
278 **** A more complex example: using an org-table as input
280      In this example we're going to define a function to compute a
281      Fibonacci sequence, and we're going to make it take its input
282      from a table in the org-mode buffer.
284      Here are the inputs for fibonacci-seq:
286 #+tblname: fibonacci-inputs
287 | 1 | 2 | 3 | 4 |  5 |  6 |  7 |  8 |  9 | 10 |
288 | 2 | 4 | 6 | 8 | 10 | 12 | 14 | 16 | 18 | 20 |
290 in the Org-mode buffer this looks like
291 : #+tblname: fibonacci-inputs
292 : | 1 | 2 | 3 | 4 |  5 |  6 |  7 |  8 |  9 | 10 |
293 : | 2 | 4 | 6 | 8 | 10 | 12 | 14 | 16 | 18 | 20 |
295 [[http://www.gnu.org/software/emacs/manual/elisp.html][Emacs Lisp]] source code
296 #+srcname: fibonacci-seq(fib-inputs=fibonacci-inputs)
297 #+begin_src emacs-lisp
298   (defun fibonacci (n)
299     (if (or (= n 0) (= n 1))
300         n
301       (+ (fibonacci (- n 1)) (fibonacci (- n 2)))))
302   
303   (mapcar (lambda (row)
304             (mapcar #'fibonacci row)) fib-inputs)
305 #+end_src
307 in the Org-mode buffer this looks like
308 : #+srcname: fibonacci-seq(fib-inputs=fibonacci-inputs)
309 : #+begin_src emacs-lisp
310 :   (defun fibonacci (n)
311 :     (if (or (= n 0) (= n 1))
312 :         n
313 :       (+ (fibonacci (- n 1)) (fibonacci (- n 2)))))
314 :   
315 :   (mapcar (lambda (row)
316 :             (mapcar #'fibonacci row)) fib-inputs)
317 : #+end_src
319 Results of Emacs Lisp code evaluation
320 #+resname:
321 | 1 | 1 | 2 |  3 |  5 |   8 |  13 |  21 |   34 |   55 |
322 | 1 | 3 | 8 | 21 | 55 | 144 | 377 | 987 | 2584 | 6765 |
324 * A meta-programming language for org-mode
325   :PROPERTIES:
326   :CUSTOM_ID: meta-programming-language
327   :END:
329 Since information can pass freely between source-code blocks and
330 org-mode tables you can mix and match languages using each language
331 for those tasks to which it is suited.  This makes Org-mode files with
332 Org-babel into a kind of meta-functional programming language in which
333 functions from many languages can work together.
335 As an example, lets take some system diagnostics in the shell, and
336 then graph them with R.
338 1. Shell source code
339 #+srcname: directories
340    #+begin_src bash :results replace
341    cd ~ && du -sc * |grep -v total
342    #+end_src
343 2. Results of the shell source code (on my system, grab this org-mode
344    files and try running it on your own)
345 #+resname: directories
346 |       72 | "Desktop"   |
347 | 12156104 | "Documents" |
348 |  3482440 | "Downloads" |
349 |  2901720 | "Library"   |
350 |    57344 | "Movies"    |
351 | 16548024 | "Music"     |
352 |      120 | "News"      |
353 |  7649472 | "Pictures"  |
354 |        0 | "Public"    |
355 |   152224 | "Sites"     |
356 |        8 | "System"    |
357 |       56 | "bin"       |
358 |  3821872 | "mail"      |
359 | 10605392 | "src"       |
360 |     1264 | "tools"     |
361 3. R source code (which calls the previous shell source code)
362 #+srcname: directory-pie
363    #+begin_src R :var dirs = directories :session R-pie-example
364    pie(dirs[,1], labels = dirs[,2])
365    #+end_src
366 4. Results of R code [[file:images/dirs.png]]
368 * Spreadsheet plugins for org-mode in any language
369   :PROPERTIES:
370   :CUSTOM_ID: spreadsheet
371   :END:
373 *NOTE*: Maybe in-addition-to/in-stead-of this example we should do a
374 more traditional "spreadsheet" example with R [Eric]
376 Not only can Org-babel pass entire tables of data to source code
377 blocks (see [[arguments-to-source-code-blocks]]), Org-babel can also be
378 used to call source code blocks from *within* tables using the
379 Org-mode's [[http://orgmode.org/manual/The-spreadsheet.html#The-spreadsheet][existing spreadsheet functionality]].
381 In fact the functional test suite for Org-babel is implemented as a
382 large Org-mode table.  To run the entire test suite you simple
383 evaluate the table =C-u C-c C-c=, and all of the tests are run
384 updating the table with pass/fail statistics.
386 Here's a sample of our test suite.
388 #+TBLNAME: org-babel-tests
389 | functionality    | block        | arg |    expected |     results | pass |
390 |------------------+--------------+-----+-------------+-------------+------|
391 | basic evaluation |              |     |             |             | pass |
392 |------------------+--------------+-----+-------------+-------------+------|
393 | emacs lisp       | basic-elisp  |   2 |           4 |           4 | pass |
394 | shell            | basic-shell  |     |           6 |           6 | pass |
395 | ruby             | basic-ruby   |     |   org-babel |   org-babel | pass |
396 | python           | basic-python |     | hello world | hello world | pass |
397 | R                | basic-R      |     |          13 |          13 | pass |
398 #+TBLFM: $5='(if (= (length $3) 1) (progn (message (format "running %S" '(sbe $2 (n $3)))) (sbe $2 (n $3))) (sbe $2))::$6='(if (string= $4 $5) "pass" (format "expected %S but was %S" $4 $5))
399 #+TBLFM: $5=""::$6=""
401 *** code blocks for tests
403 #+srcname: basic-elisp
404 #+begin_src emacs-lisp :var n=7
405 (* 2 n)
406 #+end_src
408 #+srcname: basic-shell
409 #+begin_src sh :results silent
410 expr 1 + 5
411 #+end_src
413 #+srcname: date-simple
414 #+begin_src sh :results silent
415 date
416 #+end_src
418 #+srcname: basic-ruby
419 #+begin_src ruby :results silent
420 "org-babel"
421 #+end_src
423 #+srcname: basic-python
424 #+begin_src python :results silent
425 'hello world'
426 #+end_src
428 #+srcname: basic-R
429 #+begin_src R :results silent
430 b <- 9
431 b + 4
432 #+end_src
434 * Library of Babel
435   :PROPERTIES:
436   :CUSTOM_ID: library-of-babel
437   :END:
438   What about those source code blocks which are so useful you want to
439   have them available in every org-mode buffer?
441   The [[file:library-of-babel.org][Library of Babel]] is an extensible collection of ready-made and
442   easily-shortcut-callable source-code blocks for handling common
443   tasks.  Org-babel comes pre-populated with the source-code blocks
444   located in the [[file:library-of-babel.org][library-of-babel.org]] file. It is possible to add
445   source-code blocks from any org-mode file to the library by calling
447 #+srcname: add-file-to-lob
448 #+begin_src emacs-lisp 
449 (org-babel-lob-ingest "path/to/file.org")
450 #+end_src
452 * Reproducible Research
453   :PROPERTIES:
454   :CUSTOM_ID: reproducable-research
455   :END:
456 #+begin_quote 
457 An article about computational science in a scientific publication is
458 not the scholarship itself, it is merely advertising of the
459 scholarship. The actual scholarship is the complete software
460 development environment and the complete set of instructions which
461 generated the figures.
463 -- D. Donoho
464 #+end_quote
466 [[http://reproducibleresearch.net/index.php/Main_Page][Reproducible Research]] (RR) is the practice of distributing along with
467 an article of research all data, code, and tools required to reproduce
468 the results discussed in the paper.  As such the paper becomes not
469 only a document describing the research but a complete laboratory
470 reproducing the research.
472 Org-mode already has exceptional support for [[http://orgmode.org/manual/Exporting.html#Exporting][exporting to html and
473 LaTeX]].  Org-babel makes Org-mode a tool for RR by *activating* the
474 data and source code embedded into Org-mode documents making the
475 entire document executable.  This makes it not only possible, but
476 natural to distribute research in a format that encourages readers to
477 recreate your results, and perform their own analysis.
479 Existing RR tools like [[http://en.wikipedia.org/wiki/Sweave][Sweave]] provide for the embedding of [[http://www.r-project.org/][R]] code into
480 LaTeX documents.  While this is very useful, such documents often
481 still require a large degree of "glue code" in the form of external
482 shell scripts, python scripts, and Makefiles.  To our knowledge
483 Org-babel is the only RR tool which allows multiple languages and data
484 to coexist and cooperate inside of a single document.
486 * Literate programming
487   :PROPERTIES:
488   :CUSTOM_ID: literate-programming
489   :END:
491 #+begin_quote 
492 Let us change our traditional attitude to the construction of
493 programs: Instead of imagining that our main task is to instruct a
494 /computer/ what to do, let us concentrate rather on explaining to
495 /human beings/ what we want a computer to do.
497 The practitioner of literate programming can be regarded as an
498 essayist, whose main concern is with exposition and excellence of
499 style. Such an author, with thesaurus in hand, chooses the names of
500 variables carefully and explains what each variable means. He or she
501 strives for a program that is comprehensible because its concepts have
502 been introduced in an order that is best for human understanding,
503 using a mixture of formal and informal methods that reinforce each
504 other.
506  -- Donald Knuth
507 #+end_quote
509 Org-babel supports [[http://en.wikipedia.org/wiki/Literate_programming][Literate Programming]] (LP) by allowing the act of
510 programming to take place inside of Org-mode documents.  The Org-mode
511 file can then be exported (*woven* in LP speak) to html or LaTeX for
512 consumption by a human, and the embedded source code can be extracted
513 (*tangled* in LP speak) into structured source code files for
514 consumption by a computer.
516 To support these operations Org-babel relies on Org-mode's [[http://orgmode.org/manual/Exporting.html#Exporting][existing
517 exporting functionality]] for *weaving* of documentation, and on the
518 =org-babel-tangle= function which makes use of [[http://www.cs.tufts.edu/~nr/noweb/][Noweb]] [[reference-expansion][reference syntax]]
519 for *tangling* of code files.
521 The [[literate-programming-example][following example]] demonstrates the process of *tangling* in
522 Org-babel.
524 *** Simple Literate Programming Example (Noweb syntax)
525     :PROPERTIES:
526     :CUSTOM_ID: literate-programming-example
527     :END:
529 Tangling functionality is controlled by the =tangle= family of
530 [[header-arguments]].  These arguments can be used to turn tangling on or
531 off (the default) on the source code block, or the outline heading
532 level.
534 The following demonstrates the combination of three source code blocks
535 into a single source code file using =org-babel-tangle=.
537 The following two blocks will not be tangled by default since they
538 have no =tangle= header arguments.
540 #+srcname: hello-world-prefix
541 #+begin_src sh :exports none
542   echo "/-----------------------------------------------------------\\"
543 #+end_src
545 : #+srcname: hello-world-prefix
546 : #+begin_src sh :exports none
547 :   echo "/-----------------------------------------------------------\\"
548 : #+end_src
550 #+srcname: hello-world-postfix
551 #+begin_src sh :exports none
552   echo "\-----------------------------------------------------------/"
553 #+end_src
555 : #+srcname: hello-world-postfix
556 : #+begin_src sh :exports none
557 :   echo "\-----------------------------------------------------------/"
558 : #+end_src
561 The third block does have a =tangle= header argument indicating the
562 name of the file to which it should be written.  It also has [[http://www.cs.tufts.edu/~nr/noweb/][Noweb]]
563 style references to the two previous source code blocks which will be
564 expanded during tangling to include them in the output file as well.
566 #+srcname: hello-world
567 #+begin_src sh :tangle hello :exports none
568   # <<hello-world-prefix>>
569   echo "|                       hello world                         |"
570   # <<hello-world-postfix>>
571 #+end_src
573 : #+srcname: hello-world
574 : #+begin_src sh :tangle hello :exports none
575 :   # <<hello-world-prefix>>
576 :   echo "|                       hello world                         |"
577 :   # <<hello-world-postfix>>
578 : #+end_src
580 Calling =org-babel-tangle= will result in the following being written
581 to the =hello.sh= file.
583 #+srcname: hello-world-output
584 #+begin_src sh 
585   #!/usr/bin/env sh
586   # generated by org-babel-tangle
587   
588   # [[file:~/src/org-babel/org-babel-worg.org::#literate-programming-example][block-16]]
589   # <<hello-world-prefix>>
590   echo "/-----------------------------------------------------------\\"
591   
592   echo "|                       hello world                         |"
593   # <<hello-world-postfix>>
594   echo "\-----------------------------------------------------------/"
595   # block-16 ends here
596 #+end_src
598 *** Emacs Initialization with Org-babel
599 Org-babel has special support for embedding your emacs initialization
600 into Org-mode files.  The =org-babel-load-file= function can be used
601 to load the emacs lisp embedded in a literate Org-mode file in the
602 same way that you might load a regular elisp file.
604 This allows you to have all the niceness of Org-mode (folding, tags,
605 notes, html export, etc...) available in your emacs initialization.
607 To try this out either see the simple [[literate-emacs-init][Literate Emacs Initialization]]
608 example directly below, or check out the Org-babel Literate
609 Programming version of Phil Hagelberg's excellent [[http://github.com/technomancy/emacs-starter-kit/tree/master][emacs-starter-kit]]
610 available at [[http://github.com/eschulte/emacs-starter-kit/tree/master][Org-babel-emacs-starter-kit]].
612 ***** Literate Emacs Initialization
613       :PROPERTIES:
614       :CUSTOM_ID: literate-emacs-init
615       :END:
617 For a simple example of usage follow these 4 steps.
619 1) create a directory named =.emacs.d= in the base of your home
620    directory.
621    #+begin_src sh 
622    mkdir ~/.emacs.d
623    #+end_src
624 2) checkout the latest versions of Org-mode and Org-babel into the src
625    subdirectory of this new directory
626    #+begin_src sh
627    cd ~/.emacs.d
628    mkdir src
629    cd src
630    git clone git://repo.or.cz/org-mode.git
631    git clone git://github.com/eschulte/org-babel.git
632    #+end_src
633 3) place the following in a file called =init.el= in your emacs
634    initialization directory (=~/.emacs.d=).
635    #+srcname: emacs-init
636    #+begin_src emacs-lisp 
637      ;;; init.el --- Where all the magic begins
638      ;;
639      ;; This file loads both
640      ;; - Org-mode : http://orgmode.org/ and
641      ;; - Org-babel: http://eschulte.github.com/org-babel/
642      ;;
643      ;; It then loads the rest of our Emacs initialization from Emacs lisp
644      ;; embedded in literate Org-mode files.
645      
646      ;; Load up Org Mode and Org Babel for elisp embedded in Org Mode files
647      (setq dotfiles-dir (file-name-directory (or (buffer-file-name) load-file-name)))
648      (add-to-list 'load-path (expand-file-name
649                               "lisp" (expand-file-name
650                                       "org" (expand-file-name
651                                              "src" dotfiles-dir))))
652      (add-to-list 'load-path (expand-file-name
653                               "lisp" (expand-file-name
654                                       "org-babel" (expand-file-name
655                                                    "src" dotfiles-dir))))
656      (require 'org-babel-init)
657      
658      ;; load up all literate org-mode files in this directory
659      (mapc #'org-babel-load-file (directory-files dotfiles-dir t "\\.org$"))
660      
661      ;;; init.el ends here
662    #+end_src
663 4) Implement all of your emacs customizations inside of elisp
664    source-code blocks located in Org-mode files in this directory.
665    They will be loaded by emacs on startup.
667 * Reference / Documentation
668   :PROPERTIES:
669   :CUSTOM_ID: reference-and-documentation
670   :END:
671 *** Languages
672     The following can be added to your .emacs and used to activate
673     languages.  It includes a brief list of the requirements for each
674     language.  *Note*: this also serves as the list of languages
675     currently supported by Org-babel.
676      #+begin_src emacs-lisp 
677        ;; Uncomment each of the following require lines if you want org-babel
678        ;; to support that language.  Each language has a comment explaining
679        ;; it's dependencies.  See the related files in lisp/langs for more
680        ;; detailed explanations of requirements.
681        ;; (require 'org-babel-R)         ;; R and ess-mode
682        ;; (require 'org-babel-asymptote) ;; asymptote
683        ;; (require 'org-babel-css)       ;; none
684        ;; (require 'org-babel-ditaa)     ;; ditaa
685        ;; (require 'org-babel-dot)       ;; dot
686        ;; (require 'org-babel-gnuplot)   ;; gnuplot, and gnuplot-mode
687        ;; (require 'org-babel-haskell)   ;; haskell, haskell-mode, inf-haskell
688        ;; (require 'org-babel-ocaml)     ;; ocaml, and tuareg-mode
689        ;; (require 'org-babel-python)    ;; python, and python-mode
690        ;; (require 'org-babel-ruby)      ;; ruby, irb, ruby-mode, and inf-ruby
691        ;; (require 'org-babel-sass)      ;; sass, sass-mode
692        ;; (require 'org-babel-sql)       ;; none
693      #+end_src
695 *** Source Code block syntax
697 The basic syntax of source-code blocks is as follows:
699 : #+srcname: name
700 : #+begin_src language header-arguments
701 : body
702 : #+end_src
704 - name :: This name is associated with the source-code block.  This is
705      similar to the =#+TBLNAME= lines which can be used to name tables
706      in org-mode files.  By referencing the srcname of a source-code
707      block it is possible to evaluate the block for other places,
708      files, or from inside tables.
709 - language :: The language of the code in the source-code block, valid
710      values must be members of `org-babel-interpreters'.
711 - header-arguments :: Header arguments control many facets of the
712      input to, evaluation of, and output of source-code blocks.  See
713      the [[* Header Arguments][Header Arguments]] section for a complete review of available
714      header arguments.
715 - body :: The actual source code which will be evaluated.  This can be
716           edited with `org-edit-special'.
718 *** Header Arguments
719      :PROPERTIES:
720      :CUSTOM_ID: header-arguments
721      :END:
723 - results :: results arguments specify what should be done with the
724              output of source-code blocks
725   - The following options are mutually exclusive, and specify how the
726     results should be collected from the source-code block
727     - value ::
728     - output :: 
729   - The following options are mutually exclusive and specify what type
730     of results the code block will return
731     - vector :: specifies that the results should be interpreted as a
732                 multidimensional vector (even if the vector is
733                 trivial), and will be inserted into the org-mode file
734                 as a table
735     - scalar :: specifies that the results should be interpreted as a
736                 scalar value, and will be inserted into the org-mode
737                 file as quoted text
738     - file :: specifies that the results should be interpreted as the
739               path to a file, and will be inserted into the org-mode
740               file as a link
741   - The following options specify how the results should be inserted
742     into the org-mode file
743     - replace :: the current results replace any previously inserted
744                  results from the code block
745     - silent :: rather than being inserted into the org-mode file the
746                 results are echoed into the message bar
747 - exports :: exports arguments specify what should be included in html
748              or latex exports of the org-mode file
749   - code :: the body of code is included into the exported file
750   - results :: the results of evaluating the code is included in the
751                exported file
752   - both :: both the code and results are included in the exported
753             file
754   - none :: nothing is included in the exported file
755 - tangle :: tangle arguments specify whether or not the source-code
756             block should be included in tangled extraction of
757             source-code files
758   - yes :: the source-code block is exported to a source-code file
759            named after the basename (name w/o extension) of the
760            org-mode file
761   - no :: (default) the source-code block is not exported to a
762           source-code file
763   - other :: any other string passed to the =tangle= header argument
764              is interpreted as a file basename to which the block will
765              be exported
767 *** Noweb reference syntax
768 The [[http://www.cs.tufts.edu/~nr/noweb/][Noweb]] Literate Programming system allows named blocks of code to
769 be referenced by using a =<<code-block-name>>= syntax.  When a
770 document is tangled these references are replaced with the named code.
771 An example is provided in the [[literate-programming-example]] in this
772 document.