When writing about programming languages or tools one often wants to include output from them in the document. Then it is useful if such output can be created as the document is compiled. For instance, if one describes a Lua function, then one may want the returned value of that function to be shown in the document. In this case it would be useful if the Lua function could be evaluated as the document is compiled so that the returned value is automatically included in the text.
Another situation of when one wants to use functionality external to TeX and friends is when they are not fit to create or manipulate the content one wants in the document. For example, TeX and friends might not be ideal for analyzing data.
These are two examples of when content for TeX documents are created by other programming languages and tools. How can such approaches be effectively implemented?
Best Answer
Org-mode
In Org-mode, which is a mode available for Emacs, you can mix text with output from code blocks in many different languages and export it all to LaTeX. It is possible to use different languages in the same document and also to send the output from one code block to another. This makes possible for interaction between different languages.
Here is a very simple example in which the first code block is shown as well as its output and the second code block uses the output from the first code block. In this example the code blocks are written in Emacs Lisp. The following is the content of an Org-mode buffer:
When pressing C-c C-e d Org-mode will export to LaTeX, compile it and show the resulting document. Here is part of the LaTeX output, note that the Lisp code is followed by its returned value:
And here is part of the resulting document:
This example is very simple and it does not show the full potential of this approach. It is possible to make much more complex interactions between languages and tools. Both of the following articles are written in Org-mode and exported to LaTeX and they show complex examples of how it can be used to analyze data and such:
A Multi-Language Computing Environment for Literate Programming and Reproducible Research. Contains three examples. The first example gets the values of Pascal's triangle using Python, draws it using dot and tests if it is correct using Emacs Lisp. The second is an example of literate programming for C. The third example collects temperatures using shell commands, creates a database using sqlite, analyzes the data using R and draws a graph of it.
Active Documents with Org-Mode. Contains an example that collects baseball data using shell commands, analyzes it using Python, awk and R and draws a diagram. The source for this article is available at https://raw.github.com/eschulte/CiSE/master/org-mode-active-doc.org.