Some Nice Examples Of Org Babel Use

Donald Hunter over at donaldh.wtf has an interesting post about Org Babel’s many powers and uses. Hunter thinks of it as a “polyglot Jupyter Notebook ” and uses it extensively for both professional and personal projects. His post consists of several examples of how he uses it.

One trick he shows is using the dir command to specify a remote machine. That allows him to capture output from the remote host.

Another trick he uses is isolating the boilerplate for several similar source blocks into a separate block and including it in the blocks that need it with the noweb syntax. See his post for a fully worked example.

Finally he demonstrates the real power of Babel by using two different languages. The way that works is that you use a convenient language in one block to produce an intermediate result and finish the computation in a second block with another language that calls the first block to get the intermediate result.

In his example, he uses an SQL block to read data from an SQL database and processes that data in the second block using Gnuplot. Of course, you can chain more than two blocks together or have more than one block feeding the final block.

Org Babel really is a powerful system and is part of what sets Org apart from Markdown and other markup languages. You might also want to take a look at Mike Hamrick’s video on using Org and Babel for writing.

This entry was posted in General and tagged , . Bookmark the permalink.