No description
  • Python 97.4%
  • Makefile 2.6%
Find a file
2026-04-21 12:04:56 +08:00
input Fix problems with stage 1 2026-04-20 23:03:52 +08:00
src Finalize 2026-04-21 12:03:36 +08:00
.gitignore change stuff 2026-04-20 03:21:29 +08:00
.python-version Vibecoded stuff, don't look at it 2026-04-17 14:44:47 +08:00
Makefile Completed the 4 stages 2026-04-20 20:15:38 +08:00
OPEN_PROBLEMS.md Finalize 2026-04-21 12:03:36 +08:00
pyproject.toml yeah 2026-04-20 12:02:51 +08:00
README.md Change name 2026-04-21 12:04:56 +08:00
uv.lock yeah 2026-04-20 12:02:51 +08:00

Book formalizer

Converts an OCR'd mathematics book (Markdown) into a clean, per-section Markdown collection plus structured JSON for downstream Isabelle/HOL autoformalization.

Hand-edits before running

Strip cover, preface, acknowledgements, and TOC/index. The book should begin at # Chapter 1. These are marked keep=false downstream anyway, but pre-trimming speeds up stage 1.

Pipeline

Stage Script Output
1 segment.py 01_classified.json — blocks typed, labelled, deps + notation extracted
2 notation.py 02_notation.json — flattened notation table
3 normalize.py 03_normalized.json — LaTeX standardised, filler stripped
4 assemble.py sections/*.md, definitions.md, deps.json, notation.json, proofs.json

Usage

make all INPUT=input/boools.md     # full run
make stage1-test                   # quick run on input/test.md
make dry                           # NO_LLM=1 smoke test
make clean

Requires DASHSCOPE_API_KEY (Qwen 3.6 plus). Managed with uv, type-checked with ty.

Env vars

  • FORCE=1 — overwrite existing intermediate output
  • NO_LLM=1 — skip LLM calls (dry run)
  • MAX_WORKERS — parallel LLM threads (default 8)
  • CHUNK_CHAR_CEILING — stage-1 chunk size (default 20000)
  • SPLIT_DEPTH — stage-4 section-split heading depth (default 2)

Outputs

  • output/sections/NN_<slug>.md — one file per top-level section.
  • output/definitions.md — all definitions, labelled.
  • output/deps.json — cross-reference graph, keyed by section → label.
  • output/notation.json — symbol table {block_id, label, symbol, reads, kind, section}.
  • output/proofs.json — flat array of {label, statement_id, proof_id, section, statement, proof} pairing each formal result with its informal proof.

Open issues

See OPEN_PROBLEMS.md.