Hub documentation

Formal Proofs (Lean 4)

Hugging Face's logo
Join the Hugging Face community

and get access to the augmented documentation experience

to get started

Formal Proofs (Lean 4)

The Hub natively renders Lean 4 (.lean) files in all repos, with a Statements view, an Outline sidebar, and Lean 4 syntax highlighting.

A Lean 4 file on the Hub in Statements view (light mode), showing KaTeX-rendered docstrings, highlighted theorem signatures, folded proof toggles, and the Outline sidebar.

Statements view

Opening a .lean file in Files and versions or a Storage Bucket shows its Statements view by default, so you can read what a file defines and proves without scrolling past long proofs:

  • KaTeX docstrings: /-- ... -/ docstrings render inline ($...$) and display ($$...$$) math, code, and links.
  • Foldable proofs and bodies: proofs (theorem, lemma, example) and definitions (def, abbrev, structure, inductive, …) stay folded behind a toggle.
  • Unfinished proofs: sorry, admit, and #exit are highlighted in red so gaps stand out immediately.

Click any proof or body toggle to expand it inline:

Expanded proofs inside Statements view (light mode), showing sorry highlighted in red and a 17-line Lean 4 proof expanded inline.

Try it on a public file:

Outline

On desktop, a sticky Outline sidebar lists every declaration with its kind and line number. Click any entry to jump straight to it (#L<line>), or click a declaration’s line number for a shareable link.

Full view

Click Full in the top-right switcher—or append ?code=true to the URL—to view the complete file with Lean 4 syntax highlighting, line numbers, and the Outline sidebar. Line links copied from Full view preserve ?code=true (for example, 1.lean?code=true#L54).

A Lean 4 file on the Hub in Full view (light mode), showing Lean 4 syntax highlighting, red sorry highlighting, line numbers, and the Outline sidebar.

Markdown code blocks

Lean 4 syntax highlighting also works in Model Cards, Dataset Cards, Space Cards, Discussions, and Pull Requests using lean or lean4 code fences:

```lean
/-- Every natural number plus zero is itself. -/
theorem add_zero_example (n : ℕ) : n + 0 = n := by
  exact Nat.add_zero n
```
Update on GitHub