$ show avigad/mathematics_in_lean_source
This repository is the content generation and build system for the interactive textbook *Mathematics in Lean*. It is a hybrid project: primarily a set of Python scripts and a Lean 4 project that together produce the textbook in multiple formats (Sphinx RST/HTML/PDF), as well as a separate user repository with exercise stubs and solutions. The core pipeline parses Lean source files annotated with custom directives (`TEXT`, `EXAMPLES`, `SOLUTIONS`) via `scripts/mkdoc.py` to generate textbook prose and Lean exercise files. A Sphinx build then produces the final HTML/PDF documentation. The Lean source files themselves cover mathematics from basic arithmetic to measure theory, heavily leveraging the Mathlib library. The repository includes CI/CD workflows (GitHub Actions), developer environments (Devcontainers, Gitpod), and testing scripts that verify the generated Lean files compile. While not a traditional application, it functions as a specialized toolchain for creating and deploying formal mathematics educational content.
The LLM identified 4 files worth highlighting for reuse:
The core generation script that parses Lean source files with custom markup (TEXT, EXAMPLES, SOLUTIONS, QUOTE, TAG) and produces separate RST files for Sphinx, Lean exercise stubs, and Lean solution files. It uses regex to extract content blocks and organizes output into corresponding directory structures. This component is self-contained and could be adapted for other literate programming or tutorial projects that need to generate multiple output formats from annotated source code.
A test harness that compiles generated Lean exercise files using `lake build` and optionally runs them. It supports directory, file, or pattern-based selection and provides clear pass/fail output. This script is reusable for any Lean project requiring batch compilation checks, and its structure (argument parsing, subprocess invocation, result logging) serves as a template for similar validation tasks.
Identical in structure to `examples_test.py` but targets generated solution files instead of exercise stubs. It validates that all provided solutions compile correctly, ensuring the textbook's answers remain intact after refactoring or updates. This component demonstrates a reusable pattern for dual-testing exercise and solution artifacts in educational content pipelines.
A self-contained Lean file that builds the Gaussian integers from scratch, defining the structure, arithmetic operations, norm, conjugate, division algorithm, and proving it is a Euclidean domain. It shows how to create custom algebraic types with proper typeclass instances (`CommRing`, `Group`, `AddGroup`, `EuclideanDomain`). This file can be extracted as a template for constructing new algebraic structures in Mathlib, demonstrating non-obvious skill in instance design and proof organization.