#
#
Literate programming is a programming paradigm introduced by Donald Knuth in which a computer program is given an explanation of its logic in a natural language, such as English, interspersed with snippets of macros and traditional source code, from which compilable source code can be generated [cite:@Knuth:1984]. The approach is used in scientific computing and in data science routinely for reproducible research and open access purposes. — Wikipedia
Emacs is an extensible, customizable, self-documenting, real-time display editor whose development started in the mid-seventies. It is still under heavy development thanks to a large community of Emacs hackers. Among the many packages that come with Emacs, there is org-mode which is a 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 (orgmode website). The goal of the notebook mode is to provide new users with an easy access to org-mode using a clean and legible interface such that people not familiar with GNU Emacs can nonetheless execute the whole document (using the button at the top) or run individual code cells using the run button in the margin as illustrated on figure fig:teaser. The populated notebook can then be exported to HTML using the export button at the top. The HTML document you’re currently reading is actually an export of the file notebook.org.
Since a notebook is a regular org-mode document, this means you can use any org command to execute individual code blocks or to export the notebook to HTML or PDF. Let’s now experiment a bit with the notebook and for that, we’ll use the Python language and starts with the mandatory “Hello world” program (see listing src:hello and the corresponding output).
print("Hello world!")
Hello world!
The inline equivalent would result in: src_python{return “Hello world!”}
What is more interesting is the ability for the notebook to produce figures from code and to associate a caption and a label such that they can be inserted directly into the document and referenced elsewhere in the text. Let’s try that with Python and matplotlib in order to produce the figure fig:oscillations below.
From this simple example, you can start experimenting with literate programming in any language or combinations of languages. For example, the environment that is declared in the top box of this document is automatically generated when the document is exported and it mixes code in Python (to get Python version) and code in Emacs lisp (to get Emacs version). Possibilities are infinite.
This section is used for configuring various settings in the notebook appearance as well as defining various options for the export in HTML or PDF formats. You can change any of these settings.
(format "[[https://www.gnu.org/software/emacs/][Emacs]] %d.%d"
emacs-major-version emacs-minor-version)
(format "[[https://www.gnu.org/software/emacs/][Org mode]] %s"
(org-version nil nil))
import platform
version = platform.python_version()
return f"[[https://www.python.org/][Python]] {version}"