Lean 4 proofs
TeXRA runs a Lean 4 language server for your project so the assistant can read compiler diagnostics, inspect tactic goal states at any cursor position, search Mathlib via Loogle, and run project builds.
Prerequisites
Every build (VS Code, the desktop app and the CLI) drives Lean the same way: it spawns its own headless server process (lake env lean --server), one per Lake project, which stops when the last run using it ends. So the one thing TeXRA needs is lake on your PATH.
You always need a Lake project
Lean tools only work on .lean files that live inside a Lake project: a folder (or ancestor folder) containing a lakefile.lean or lakefile.toml. If there's no lakefile, the language server has nothing to attach to. Create one with lake new myproject or lake init.
- Install elan (the Lean version manager):bashIn VS Code, the official Lean 4 extension (
curl https://elan.lean-lang.org/elan-init.sh -sSf | shleanprover.lean4) can install elan and the Lean toolchain for you when you first open a Lean file; it is also the editor you will want for reading proofs, but TeXRA's tools do not go through it. - Confirm it works in a fresh shell:bash
lake --version - Open a folder containing a
lakefile.leanorlakefile.toml.
No extension underneath: TeXRA talks to Lake directly, and the same lean_* tools run against its own server process in every build.
If you don't have elan yet, follow the Lean community install guide.
Activating Lean
There is no switch to flip. Lean support turns on the moment the assistant runs a Lean tool on a .lean file in a Lake project: ask it to work on your proof.
Check that it's working
Open Settings → Plugins () → Lean 4 Proof Assistant () to confirm your setup is detected. The panel shows whether lake was found and lists any active language servers.
Working on proofs
Ask the assistant: it uses the Lean tools below whenever lake is found, so the same conversation can search Mathlib, write and debug a proof, clean it up to Mathlib style, and edit the LaTeX paper it formalizes. For a whole formalization project it can split the work across helper agents (Multi-agent workflows), and for a job with a built-in check it starts one of the Lean programs.
Lean programs
The Lean plugin also ships four programs. Three are fixed procedures that check their own work with Lean's tools before they hand it back: each runs a helper agent on the files you name, then checks the result, and when the check fails the helper gets another round with the findings. The fourth, lean-search, hands one search to a helper agent and answers with what it found.
| Program | What it does | How it checks each round |
|---|---|---|
prove | Completes the proofs in the .lean files you pass, keeping their statements. | Lean's diagnostics for every file: no error and no sorry, and no axiom declared in a file that was not there before. Up to three rounds. |
lean-simplify | Brings the .lean files you pass toward Mathlib quality (names, style, generality, simpler proofs, library lemmas in place of hand-written ones) without changing what they state. | The same check as prove. Up to two rounds. |
blueprint | Writes or brings up to date a LeanBlueprint document (its .tex files). | leanblueprint web builds it and leanblueprint checkdecls finds every \lean declaration in the built project. Up to two rounds. Needs the leanblueprint CLI. |
lean-search | Finds what Mathlib and the project already have for the statement, API or formalization question in the instruction: exact and close matches with their names, types and imports, and what is missing. It edits no file unless the instruction asks for a draft. | No check: one helper agent, whose report is the answer. |
Key details for running Lean programs:
- Narrowing scope: Pass an instruction to limit the job (for example
"prove only oddSum_eq_sq"or"add entries for the new lemmas in Basic.lean"). Forlean-search, the instruction is the question itself. - Verdict and checks: Each checked program returns its verification verdict alongside the helper agent's summary.
proveandlean-simplifycheck for newaxiomdeclarations only in the files you pass, not in imported files; run#print axiomson a theorem for the full axiom audit. - Blueprints: Initialize a new blueprint with
leanblueprint new, then pass the generated files toblueprint. It stops immediately if theleanblueprintCLI is not installed (pip install leanblueprint). - Availability: The assistant is told about all four programs only when
lakeis onPATH, matching how Lean tools are offered.
texra run prove --input Proofs/Basic.lean --instruction "Prove the two lemmas about oddSum"
texra run lean-simplify --input Proofs/Basic.lean
texra run blueprint --input blueprint/src/content.tex
texra run lean-search --input Proofs/Basic.lean --instruction "Does Mathlib have the sum of the first n odd numbers?"All four are always registered: texra run lists them beside the LaTeX programs, with or without Lean installed. prove and lean-simplify need lake on your PATH, since their check is Lean's own diagnostics. Like every program, lean-search needs an --input file; pass the file the question is about. In the app, ask the assistant for the job (for example "finish the proofs in Proofs/Basic.lean") and it proposes the program.
What you can do
Describe the task in plain language; the assistant decides which tools to call. Below are the five Lean tools it reaches for, as they surface in the tool-call log.
goal⊢ Continuous (f + g)The agent picks the tool (read diagnostics, inspect the proof state, search Mathlib, refresh a file, or manage the build) and you watch each call land in the run log.
Read diagnostics
Check Proofs/GroupTheory.lean for errors and fix the first one.The lean_diagnostics tool reports compilation errors, type mismatches, unsolved goals, warnings, and hints with their locations. Use it to check whether a file compiles after each change.
Inspect the proof state
What's the goal state at line 42 of Analysis/Limits.lean?The lean_inspect tool reads the tactic proof state (goal), the expected type in term mode (term_goal), or the type signature and docs of an identifier (hover) at a given position: the same information Lean shows in its infoview.
The agent reads the unsolved-goals diagnostic, inspects the goal state, finds the right lemma, and iterates the proof until it compiles with 0 errors and 0 sorry.
Search Mathlib
Find a Mathlib lemma that says the sum of two continuous functions is continuous.The lean_loogle tool queries Loogle to find lemmas by name, type signature, or the constants they mention, so the agent cites real Mathlib lemmas instead of inventing them. Like the other Lean tools, it is offered only when Lean support is available (lake on your PATH).
Refresh a stuck file
The diagnostics for this file look stale. Restart the Lean server for it.The lean_file tool restarts the language server's state for one file: it closes the file and opens it again, so Lean re-elaborates it and re-reads its imports. Use it when results look out of date.
Manage the project
Download the Mathlib build cache, then build the project.The lean_project tool runs project-wide commands without a target file, grouped into server control and project operations:
restart_serverstop_serverbuildcleanfetch_cacheBoth groups run in every build. fetch_cache pulls the Mathlib build cache for the whole project.
Toolchain setup
In VS Code, the setup assistant can run the Lean 4 extension's installers (install or update elan, install dependencies, select the default toolchain). In any build, you can manage your toolchain with elan and lake directly (for example elan self update, elan toolchain install, or lake update). Follow the Lean install guide.
Build output
lean_project's build command starts a build but doesn't capture its output. To see errors afterward, the agent runs lean_diagnostics on the relevant files (or lake build directly via the bash tool when it needs the raw log).
Troubleshooting
"No Lean project found": the file isn't inside a Lake project. Make sure a lakefile.lean or lakefile.toml exists in the file's folder or an ancestor. Create one with lake new / lake init.
"Failed to spawn lake env lean --server": lake isn't on your PATH. Install elan and confirm lake --version works in a fresh shell.
Lean shows "Needs setup" in VS Code with the Lean 4 extension installed: the extension is not what TeXRA's tools run on. Make sure lake --version works in a fresh login shell. The TeXRA service reads its PATH from your login shell when it starts, so after installing elan run texra service restart (see the CLI guide) and reload the VS Code window.
Diagnostics look stale: ask the agent to run lean_file on the file, or lean_project with restart_server. A missing Mathlib cache can also cause long stalls; run fetch_cache.
Next steps
- The assistant and programs: every program, Lean's included
- Research tools: literature search, citations, and Wolfram verification
- Multi-agent workflows: how the assistant splits a large job