Emacs powering research
by Thibault Lestang
org-babel is a set of features on top of org-mode
org
is for organise!
*
for levels as #
is for markdown.
use multiple *
for subheadings (e.g. **
etc)
You can create tables M-x org-table-create-or-convert-from-region (?) You can use it as a spreadsheet, with rows and columns operations.
headlines can have properties key-values pairs (C-c C-x p)
org also as todo lists (C-c C-t), with schedule (C-c C-s) and deadlines (C-c C-d) that you can see in the agenda. (C-c a a)
Org-mode is incredibly broad, from task management to writing literate code and papers. The basic principle is that it has functionality related to hierarchical organisation of text (under headings).
All documents can be exported to all sorts of outputs by calling org-export
. You can export to all sorts of html, pdf or other markup langages (Markdown, latex etc).
#+begin_src python
import numpy
#+end_src
(You can use <s tab
and it will create the source block)
C-c '
will open another buffer with the major mode of the language used in that language (as if visiting a python file); C-c '
will take you back to the org file.
C-c C-c
will run that code block, and it shows the result below.
C-c C-c
will write the stdout of the#+NAME: initial-data
above the code blockpython :var timeseries=initial-data
and a variable timeseries
will be read instead.:results output
.exports won’t show the output, unless :exports both
Then we can have inline results within the text:
src_python[:var timeseries=initial_data]{}
the code will be inserted within the {}
to simplify things we can create a code block that then we can call, we have to name the code block, and then use it as a function with: #+CALL: mean(initial_data)
where mean
is the name of the block.
Inline calls can be used with call_mean(input_data)
inside the text. Then use C-c C-c
to evaluate the function as an inline codeblock
you can include functions from separate files using #INCLUDE:
A :prologue
header argument can pre-pend code to a code block. For example: :prologue "import numpy"
. You can add this at all kind of levels. On the code block #+begin_src
line, or in a property drawer at the document level or any subsection. You can also restrict headers to one language.
you can also use it to show figures.
org-babel-tangle
extracts all the code from an org mode that then it can be used (e.g., by emacs to use to load the configuration file).(org-babel-load-file "file")
it’s a org-bable helper function that will untangle the org-mode file when load.