UP | HOME

Support via Liberapay

Org Source Code Blocks in Babel

Babel support for Org

Introduction

Org is a GNU Emacs major mode for keeping notes, authoring documents, computational notebooks, literate programming, maintaining to-do lists, planning projects, and more—in a fast and effective plain text system.

Requirements and Setup

To configure Babel to use Org, you'll need to ensure that org-babel-load-languages includes an entry for it. Typically, org-babel-load-languages will contain many entries. The example below omits other languages.

(org-babel-do-load-languages
 'org-babel-load-languages
 '((org . t)))

Babel Features for Org Source Code Blocks

Header Arguments

Org code blocks yield raw, silent results by default. They export code by default.

Variables passed to an Org code block are referenced with a preceding $: e.g., the variable foo is referenced as $foo.

Sessions

Org does not support sessions.

Result Types

Org source blocks can return raw, ascii, latex, or html results.

Examples of Use

One use of an Org source block might be as a template. An Org source block as it appears in an Org mode buffer:

#+name: org-hello
#+begin_src org :var addressee="" 
Hello $addressee
#+end_src

HTML export of the source block:

Hello $addressee

Now, evaluate the Org source block in the header of a simple Emacs Lisp source block.

The Emacs Lisp source block in the Org mode buffer:

#+name: print-org
#+begin_src elisp :var x=org-hello[](addressee="World!") 
  (print x)
#+end_src

HTML export of the Emacs Lisp source block:

(print x)

HTML export of the Emacs Lisp source block results:

Hello World!

Now, instruct the Org source block to return HTML and the Emacs Lisp source block to return HTML with the inner and outer arguments to an #+call: line.

In the Org mode buffer:

#+call: print-org(x=org-hello[:results html](addressee="HTML!")):results html

Hello HTML!

Documentation from the orgmode.org/worg/ website (either in its HTML format or in its Org format) is licensed under the GNU Free Documentation License version 1.3 or later. The code examples and css stylesheets are licensed under the GNU General Public License v3 or later.