UP | HOME

Support via Liberapay

Babel: Languages

Language Support

Babel supports a growing number of programming languages; more than ten dozen languages currently have some Babel support. Babel support for more than three dozen widely used languages is distributed with Emacs, and the various Emacs Lisp Package Archives include support for more than four dozen languages. In addition, for various historical reasons, Babel support for more than two dozen languages is distributed in the Org-contrib package.

This page provides pointers to sources of Babel language support, instructions to activate a supported language, and a brief guide to developing support for a language in case you'd like to use a new language with Babel or contribute to existing Babel language support.

Language Support Distributed with Emacs

Table 1 lists the Babel language support distributed with Emacs. The table provides a link to a web page with information about the language, indicates how the language is identified in Babel, provides a link to existing documentation, and indicates the generosity of your colleagues who have volunteered to maintain a bit of Babel language support.

If you would like to maintain a Babel language support file, then please review how Org is maintained and send an email to the mailing list.

Note that there are some inconsistencies among supported languages.

Table 1: Core languages supported by Babel
Language Identifier Documentation Maintainer
Apache Groovy groovy   Palak Mathur
AWK awk ob-doc-awk Tyler Smith
C C ob-doc-c Thierry Banel
C++ cpp ob-doc-c Thierry Banel
Calc calc   Tom Gillespie
CLI shell ob-doc-shell  
Clojure clojure ob-doc-clojure Daniel Kraus
Comint mode comint    
CSS css ob-doc-css  
D D ob-doc-c Thierry Banel
ditaa ditaa ob-doc-ditaa  
Emacs Lisp emacs-lisp, elisp ob-doc-elisp  
Eshell eshell ob-doc-eshell stardiviner
Fortran F90    
Gforth forth    
Gnuplot gnuplot ob-doc-gnuplot Ihor Radchenko
GNU Screen screen ob-doc-screen Ken Mankoff
GNU sed sed    
Graphviz dot ob-doc-dot Justin Abrahms
Haskell haskell   Lawrence Bottorff
Java java ob-doc-java Ian Martins
Julia julia ob-doc-julia Pedro Bruel
LaTeX latex ob-doc-LaTeX  
LilyPond ly ob-doc-lilypond  
Lisp lisp ob-doc-lisp  
Lua lua ob-doc-lua  
Make makefile ob-doc-makefile  
MATLAB® matlab ob-doc-octave-matlab  
Maxima max ob-doc-maxima  
Node.js js ob-doc-js  
OCaml ocaml    
Octave octave ob-doc-octave  
Org mode org ob-doc-org  
Perl perl ob-doc-perl Corwin Brust
PlantUML plantuml ob-doc-plantuml  
Processing processing   Jarmo Hurri
Python python ob-doc-python Jack Kamm
R R ob-doc-R Jeremie Juste
Ruby ruby    
Sass sass    
Scheme scheme ob-doc-scheme  
SQL sql ob-doc-sql Daniel Kraus
SQLite sqlite ob-doc-sqlite Nick Savage

Language Support Distributed with Org-contrib

Once upon a time, Babel language support that was not released under the GPL was kept in Org-contrib. Later, with the goal of easing the burden of Org-mode maintenance, lesser-known languages distributed with Emacs were also moved to Org-contrib. Table 2 includes pointers to these languages and some documentation of their Babel integration.

Table 2: Contributed languages supported by Babel
Language Identifier Documentation
abc abc ob-doc-abc
Arduino arduino  
Asymptote asymptote ob-doc-asymptote
Coq coq  
ebnf2ps ebnf  
FOMUS fomus  
hledger hledger  
io io  
J J ob-doc-J
ledger ledger ob-doc-ledger
Mathematica mathematica  
Mathomatic™ mathomatic ob-doc-mathomatic
Mono csharp  
Mono vbnet  
Mozart oz ob-doc-oz
Mscgen mscgen ob-doc-mscgen
PHP php  
PicoLisp picolisp ob-doc-picolisp
Redis redis  
Shen shen  
SMILES smiles  
SPICE spice  
Stan stan ob-doc-stan
Stata stata ob-doc-stata
SuperCollider sclang  
Tcl tcl ob-doc-tcl
Vala vala ob-doc-vala
ΕΥΚΛΕΙΔΗΣ eukleides ob-doc-eukleides

Language Support Distributed via an Emacs Lisp Package Archive

Most language support is distributed through an Emacs Lisp Package Archive. You can find the Babel language support available on your setup with M-x list-packages. In theory, it ought to be possible to identify all the Babel language support packages with a keyword search using M-x package-menu-filter, but this method is unreliable because package developers do not subscribe to a keyword authority list. In practice, you can search for package names that start with ob- and go from there.

Activate a Language

To add support for a particular language to your Babel installation first make sure that the requirements of the language are met, then customize the org-babel-load-languages variable with the appropriate language identifier, <lang>, from Table 1 or Table 2, as follows:

(<lang> . t)

To remove support for a language, customize the org-babel-load-languages variable, as follows:

(<lang> . nil)

Here is an example manual configuration of this variable, which enables support for R, and disables support for emacs-lisp.

;; active Babel languages
(org-babel-do-load-languages
 'org-babel-load-languages
 '((R . t)
   (emacs-lisp . nil)))

Develop Support for a Language

The core Babel functions (viewing, export, tangling, etc.) are language agnostic and will work even for languages that are not explicitly supported. Explicit language-specific support is required only for evaluation of code blocks in a language.

Babel is designed to be easily extended to support new languages. Language support is added by defining language-specific functions using a simple naming convention. The full suite of possible language specific functions need not be implemented all at once, but rather it is possible (and encouraged) to develop language-specific functionality in an incremental fashion—Babel will make use of those functions which are available, and will fail gracefully when functionality has not yet been implemented.

There is a short Emacs Lisp template (ob-template.el) which can be used as a starting point for implementing support for new languages. To fetch a copy of this file, please clone Worg:

~$ git clone https://git.sr.ht/~bzg/worg

You should find org-contrib/babel/ob-template.el.

Developers are encouraged to read the Org-mode contribution instructions in the hope that the language support can be added to the Org-mode core.

Some additional comments/development tips

Although most of the instructions in ob-template.el should be useful, and explain clearly how to use the code, some explanations for more advanced functionalities could be a little outdated (contributions are very welcome. The thread here may contain some extra useful information, although most of the suggestions provided by Eric should have been implemented). If some of the instructions seem clear, then here are some suggestions to gain clarity:

  • start with instrumenting see edebug the org-babel-execute:template function, and subsequently evaluate some test-code block. In this way you can easily figure out how Babel processes header arguments. Then in the end, the result printed by a code block simply consists of the output of that function.
  • The trick is to process the vars, result-params, and the full-body variable (let form within org-babel-execute:template function) and send the appropriate lines to some inferior process (or as an argument to some shell command). The inferior process can be created in the function org-babel-template-initiate-session. The result returned by the inferior process (or by the shell command), should be returned by org-babel-execute:template (of course you might further process it before you return it).
  • Don't forget to read the comments in the ob-template file, e.g. for sending/receiving output to/from an inferior process. The functions in org-babel-comint might also be useful.

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.