Literate Programming

Table of Contents

Literate programming (LP) is a programming paradigm introduced in 1984 by Donald Knuth. A computer program is given as an explanation of how it works in a natural language, such as English, interspersed (embedded) with snippets of macros and traditional source code, from which compilable source code can be generated.

Terminologies

Tangling (org-babel-tangle): Org Babel extracts the code blocks from Org mode file and writes them into pure source code files (like .el, .py, or .sh) that the computer can execute.

Weaving: The file is also exported into a format suitable for reading (like HTML, PDF, or LaTeX) where the prose and code are cleanly presented for humans.

Usage

For scripts that need executable permission, the :tangle-mode (identity #o755) is added to the header args. Otherwise every tangle will reset the permissions and the script permission needs to be changed every time to make it an executable.

Instead of org-babel running through every org file, I maintain a list of literate files in Emacs config file that needs to be tangled.

Examples

I use Org mode to create and maintain the following files as literate programs and org-babel tangle them.

Date: 2026-05-29 Fri 23:16

Author: Prabu Anand Kalivaradhan

Created: 2026-10-11 Sun 15:24