Leanify

Documentation, tutorial and live demo

One LaTeX source, read twice: typeset as the paper you submit, and compiled by Lean into kernel-checked statements and proofs.

Leanify compiles an ordinary mathematical article, written in good mathematical English, to Lean. Every symbol must be defined in the article before it is used, every sentence has one fixed reading, and a proof step may use only the results it cites. The kernel checks the readable Lean form of every definition and claim, every justification and the final certificate; the compilation of the file takes a second, and leanify audit has the kernel check that too. There is no second, hand-written formal version that could drift away from the paper.

Define $f:(0,\infty)\to\mathbb{R}$ by $f(x)\coloneqq x+\frac1x$.

becomes the Lean definition f := fun x => x + 1 / x, with the obligation that it is well defined, ∀ (x : ℝ), 0 < x → ¬x = 0, and the theorem

\begin{theorem}\label{thm:bound}
For every $x\in(0,\infty)$, $f(x)\ge2$.
\end{theorem}

becomes claim2 : ∀ (x : ℝ), 0 < x → 2 ≤ f x, derived in Lean from exactly the sentences of its proof and the lemma they cite.

Exemplars

Two articles are compiled in lean-verifications:

  • Rank weighting and asymmetry in Blest's rank correlation: two exact regions (arXiv:2609.27634), Papers/Rockel2026ExactBlest/Source: 37 definitions and 48 claims, all certified. The proof of Corollary 3.2 is checked sentence by sentence against what it cites; the other results are proved through bridges to the companion development.
  • The exact region determined by Spearman's rho and Gini's gamma (arXiv:2609.19890), Papers/AnsariRockelSteinmassl2026RhoGamma/Source: 11 definitions and 8 claims, all certified.

Each folder's article-edits.diff lists every edit the conventions asked for, and its README the coverage: which sentences compiled, and which are still prose.

Use

Getting started takes a one-page note from a first draft with four mistakes to a certificate, step by step:

lake exe leanify check Note/article.tex --claims   # undefined symbols, unread statements, the reading of every claim
lake exe leanify init Note/article.tex             # the Lean files, with a stub proof of every claim
lake build Note.Certified                            # the kernel checks the statements and your proofs

The project needs Leanify in its lakefile.toml:

[[require]]
name = "leanify"
git = "https://github.com/Corrram/leanify.git"
rev = "main"

Or start from the article alone: with the checker on the PATH, leanify certify article.tex makes its folder a Lean project that requires the Leanify of the checker, writes the Lean files, fetches mathlib and builds the certificate.

leanify init writes four files next to the article, and adds the article's library to lakefile.toml:

FileContents
Compiled.lean#leanify_article Note "article.tex" "fnv1a64:…": the article compiled to a Lean document, pinned by its hash (leanify prepare updates the pin after an edit; leanify audit has the kernel evaluate the compiler)
Article.lean#leanify_semantics: every definition and claim as readable Lean (claimK, meaningfulK, obligationK)
Proofs.leanyour proofs proofK : obligationK and definedI : wellDefinedI, or refuteK : meaningfulK ∧ ¬ claimK for a claim that is false as stated, and satisfiedK : satisfiableK: the hypotheses of statement K can hold together
Certified.lean#leanify_certify: the certificate Note.certificate, each verified claim Note.verifiedK, and the reports

A proof that still uses sorry leaves its claim unverified, so an article can be certified while its proofs are written. The certificate also reports what a proof alone does not show: whether the hypotheses of every claim are shown to hold together, and whether each step of a printed proof is closed by one fixed tactic (leanify_step) or needed a longer Lean argument. A result is marked derived only without either reservation. Two scripts take a command of yours (a model, usually): scripts/leanify_suggest.py proposes rewrites of the sentences Leanify cannot read, and keeps one only if the check then reads it; scripts/leanify_prove.py proves the open obligations, and writes a proof only if Lean accepts it. The check reads an article with the files it inputs (\input, \include, the article's own .sty files). Articles about probability on the unit square use --vocab unitsquare (Vocabularies and models).

The same source gives the two readable outputs:

  • the PDF, with \usepackage{leanify}, unchanged, or with \usepackage[status]{leanify} marking every result in the margin with its verification status (read from article.leanify.tex). Compiled with shell escape, the package also checks the article on every compile, with the findings as LaTeX warnings at their lines, and with certify it builds the certificate first. \leanifyreadings prints the formal reading of every definition and statement, so that a reader of the PDF sees what Lean was asked to prove;
  • the web reader, node reader/build.mjs article.tex, which renders the article from its source with the status of every sentence and, for each claim, its formal reading, Lean statement, premises and justification.

The examples are short papers in the usual style, each certified by CI:

  • examples/Demo, the note of the guide (draft.tex and the certified article.tex), and tests/Refuted, the same note with its theorem refuted;
  • examples/Means, the harmonic, geometric and arithmetic mean of two numbers, with symbols defined inside a theorem, in a where-clause and in apposition. Five steps of its proofs use rules for square roots that the standard tactic does not know, so its results are marked argued, not derived;
  • tests/Arguments, proofs with assumptions, cases, contradictions and inductions, each step closed by the standard tactic;
  • tests/TailDependence, two notions of positive dependence of copulas, with the field unitsquare; the independence copula shows that the hypotheses of its proofs can be met.

bash scripts/ci.sh runs every check of the repository, as CI does.

Documentation

Layout

PathContents
Leanify/Lex.lean, Segment.lean, Math.leanLexing (macros, blocks), sentence segmentation, formulas
Leanify/Grammar.lean, Elab.lean, Doc.leanSentence constructions and their readings, compilation of an article (compileArticle)
Leanify/Syntax.lean, Denote.leanThe core language and its Lean denotation
Leanify/Vocab.lean, Library/Vocabularies, phrase!, and the fields: each is data (phrases, types and the names of their Lean meanings)
Leanify/Meta.lean, Readable.lean, Certify.leanThe commands #leanify_article, #leanify_semantics, #leanify_certify
Leanify/Check.lean, LeanifyCli.leanThe command line lake exe leanify: check (the native checker, with the files the article inputs), certify (from an article to its certificate), audit (the kernel evaluates the compiler), init (the Lean files of an article, and its project), prepare (the pin), flatten (the article and its inputs as one file), tex (what leanify.sty runs)
examples/, tests/The example articles of the documentation, and the test articles (a refuted theorem, notions in the running text), certified in CI
reader/The web reader: the article rendered from its source with the status of every sentence
tex/leanify.styThe check on every compile (with shell escape), the certificate with certify, and margin marks with status
docs/, mkdocs.ymlThe documentation site, https://corrram.github.io/leanify/
scripts/leanify_diagnostics.pyFindings from the certificate report, for editors and CI
scripts/leanify_suggest.py, scripts/leanify_prove.pyA hook proposes rewrites of unread sentences, or proofs of open obligations; the checker and Lean decide

Build

lake exe cache get
lake build
npm ci && npm test

The documentation site is docs/ with mkdocs.yml:

npm run demos                          # the readers of the example articles, into docs/demo/
pip install -r requirements-docs.txt
mkdocs serve

.github/workflows/pages.yml publishes it from main.

Lean 4.34.0 with the mathlib revision in lake-manifest.json. The generic code is licensed under Apache-2.0.