# Formal Proofs (Lean 4)

The Hub natively renders [Lean 4](https://lean-lang.org/) (`.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.](https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/hub/lean-statements.png)

## Statements view

Opening a `.lean` file in **Files and versions** or a [Storage Bucket](./storage-buckets) 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.](https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/hub/lean-proof-expanded.png)

Try it on a public file:

- [ErdosProblems/1.lean](https://huggingface.co/datasets/nielsr/formal-conjectures/blob/main/lean_project/FormalConjectures/ErdosProblems/1.lean) — KaTeX docstrings, folded proofs, and `sorry`
- [CubicQuartic.lean](https://huggingface.co/datasets/humanfia-lab/lean-eval-source/blob/main/problems/abel_ruffini/Submission/CubicQuartic.lean) — multi-line proofs of the cubic and quartic formulas
- [ChallengeDeps.lean](https://huggingface.co/datasets/humanfia-lab/lean-eval-source/blob/main/problems/annulus_theorem_dim_four/ChallengeDeps.lean) — `abbrev`, `def`, and `structure` declarations

## 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.](https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/hub/lean-full-view.png)

## 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:

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