LitPro is a modern literate programming system where the document is primary and the runnable code is derived. It follows the tradition of Knuth's WEB and noweb systems, where code blocks are named and expanded in dependency order.
Unlike notebooks, LitPro produces deterministic output with no hidden state. The narrative order is chosen for human understanding, not execution order.
An ideal Python literate program is not a notebook. It is a single narrative document that derives runnable Python. The document is primary. The script is generated.
.py file in dependency order| Aspect | Literate Programming (LPMD) | Notebook (Jupyter) |
|---|---|---|
| Primary artifact | Document with narrative | Executable cells |
| Execution model | Deterministic, dependency-ordered | Interactive, cell-by-cell | State management | No hidden state | Mutable kernel state |
| Output reproducibility | Identical every time | Depends on execution history |
| Document structure | Narrative-driven | Linear execution flow |
Here's how a literate program might look:
LPMD uses HTML comments as cell markers to keep the markdown readable while enabling execution. These markers allow for dependency management similar to noweb's named chunks:
Parameters:
cell_id: Unique identifier for the celldepends: Comma-separated list of cells this cell depends onDuring execution, LPMD resolves dependencies using topological sorting, ensuring that code blocks are evaluated in the correct order regardless of their position in the narrative.
Try executing LitPro code directly in your browser. Enter your LitPro code below and click Run:
depends parameterThis workflow ensures that your code is both well-documented and functionally correct, following the true spirit of literate programming.
While Jupyter and Colab are popular tools, they have fundamental limitations that make them unsuitable for true literate programming:
Jupyter notebooks maintain mutable kernel state. Cell execution order affects results, making notebooks non-reproducible. You can run cells in any order, leading to inconsistent states that are hard to reproduce.
Results depend on execution history. A cell that worked yesterday might fail today if previous cells were modified or skipped. This makes debugging and verification difficult.
Notebooks force a top-down narrative that may not match the logical flow of ideas. The presentation order is tied to execution order, limiting pedagogical flexibility.
Notebooks contain binary outputs mixed with code, causing massive diffs in version control. Collaboration becomes difficult as output changes clutter commits.
Cells often rely on variables from other cells without explicit declaration. This creates fragile dependencies that break silently when cells are reordered or deleted.
Notebooks are not directly executable as programs. Converting to scripts requires manual extraction and reorganization, often breaking the logical flow.
These simple commands make it easy to integrate LitPro into your development workflow.
Embed LitPro execution directly in your website or blog:
Or use the JavaScript API:
This allows readers to execute your literate programs directly in their browsers.
LitPro's architecture makes it easy to extend to other programming languages:
Each language requires a simple adapter that implements:
Planned adapters for:
The same literate programming principles apply across all languages, making it easy to switch between ecosystems while maintaining the same workflow.