Tex2Lean user guide

Tex2Lean translates results from LaTeX papers into Lean 4 projects. The primary use case is for formalizing Computer Science papers but the tool should work for other domains as well. The tool is available via CLI or VS Code extension.

Formalization structure

The formalization connects the algorithm, its mathematical meaning, and its resource bounds through three layers.

Stage 01

Model the algorithm

Define the inputs, operations, algorithm, and theorem. For time-complexity claims, write the algorithm using the Charged interface: each computation carries its result and a tally of the operations it performs.

Model/Definitions, program, and theorem
Stage 02

Prove the interface

Prove the connection between the implemented program and the mathematical representation used in the analysis. This lets the proof reason about the algorithm at a convenient level while keeping the theorem tied to the modeled program.

Interface/Program-to-analysis connection
Stage 03

Analyze the same program

Prove correctness and resource bounds for the modeled program. The time theorem bounds its accumulated charges; for a randomized algorithm, expected time is stated over the distribution of charged runs.

Analysis/Proofs and resource bounds
Meta/

Mechanical checks run across the development: the model boundary, program constraints, and audit evidence.

How time is counted

Time complexity with Charged

Standard charged operations come from arlib. When a paper needs operations that arlib does not support, Model/Operations.lean defines those additional primitives and their cost model. In Model/Program.lean, the algorithm calls its operations through Charged. Sequential steps add their charges, loops accumulate the charges of their iterations, and a branch contributes the work it executes.

Sealed data interfaces and program checks require work such as dictionary updates, size tests, and scan visits to go through charged operations. The time bound is then proved about the tally produced by this program.

What does “proved” mean?

Read the formal statement, the proof evidence, and what the development assumes.

Statement and proof review

A machine-checked proof establishes the encoded theorem under its stated hypotheses. It does not, by itself, establish that the translation says exactly what the paper says.

  1. The statement matches your paper

    Inspect the model definitions and program as well as the theorem. Check every assumption and conclusion.

  2. The current Lean evidence is complete

    Lean’s standard axioms—propext, Classical.choice, and Quot.sound—can appear in a valid proof. Additional axioms need scrutiny. Read Model/Prior.lean: its hypotheses remain conditions of the result even when the proof is sorry-free.

  3. The handoff findings are resolved

    Review the mechanical checks and the paper comparison. Treat ambiguities, changed hypotheses, and reported defects as findings to inspect.

Other extension features

Explore the Blueprint

Click Blueprint at the top of the sidebar to explore two maps: your paper’s statements and the Lean modules that formalize them. Follow their dependencies and connections between LaTeX source locations and Lean files. Click a node to inspect its details.

See the Blueprint button

Configure your run

Click Settings to change your model connection, choose a model, and set Agents at once for parallel work. Agent-count changes during a run apply at the next round. Use Auto-answer routine decisions to let Tex2Lean handle routine choices automatically.

See the Settings controls

Prove a Lean statement

Save a theorem or lemma with a sorry proof under your project’s Model/. It appears in Lean statements; choose Prove to work on the declaration directly. No paper scan is required.

Select several results

Use Formalize several… to choose a group. Tex2Lean writes the selected statements and shared vocabulary before entering the long proof phase. Each theorem keeps its own checkpoint.

Explore & ask questions

Click Open Chat in the Tex2Lean sidebar to ask questions about your paper, understand the formalization, and explore the current proof state.

Share a Lean development

When ready, use Donate Lean in Settings to propose the project to arlib-community. Review the material and acknowledgement before publishing. Community contributions go through a pull request.

Frequently asked questions

Setup, model connections, and proof workflow.

Browse reported issues
Do I need to know Lean to get started?

You can start with a paper and the guided workflow. You still need to review the generated statement and assumptions. If you cannot assess the Lean translation, work with someone who can before relying on the result.

Can I use a PDF instead of LaTeX?

Yes, through Tex2Lean: Import from PDF (discouraged), when pdftotext or mutool is installed. LaTeX is preferred: PDF extraction can lose notation and mathematical structure, so review the extracted statement carefully.

Which model connections can I use?

Connect supports a signed-in Claude Code or Codex CLI, or API providers including Anthropic, OpenAI, and OpenRouter.

Where are my API keys and paper sent?

API keys entered in the extension are stored in VS Code SecretStorage, rather than plain-text settings. The selected model connection receives paper excerpts and relevant development context. Coding agents can inspect project files. Review your provider’s data policies and only use material you are permitted to share.

How long does a run take, and what does it cost?

It depends on the paper, model connection, library reuse, and proof difficulty. Initial setup needs downloads and builds; formalization can run for hours. The sidebar shows usage where available.

How do I pause and come back later?

Choose Pause in the pinned run control. Tex2Lean stops active work, keeps generated files, and records a paused checkpoint. Allow cleanup to finish. Use the result’s Resume control when you are ready to continue; reopen the same project folder if you closed VS Code.

Why does a proved theorem still have assumptions?

Papers often use results from prior work. Tex2Lean can record those as explicit hypotheses in Model/Prior.lean. A proof can be complete relative to these hypotheses without proving them here. Read the Prior Work entries, citations, and theorem binders; use the assumptions command if you want to discharge more of them.

Can I use an existing Lean project?

Yes. Open its folder and use the Lean statements list for saved theorem and lemma declarations under Model/. Choose Prove for a statement with sorry. Tex2Lean checks and proves the existing declaration without restating it from TeX.

What if setup fails or the scan finds nothing?

For setup, follow the reported action and check Git, disk space, network access, and the toolchain information. For an empty scan, check the selected root paper and its included files. Try the selected-statement context menu for a specific result. Use Tex2Lean: Show extension log for details.

Reporting issues

Report an issue with your Tex2Lean version and the relevant output from Tex2Lean: Show extension log.