Lean projects #

In general, if you just open a single .lean file in your text editor and try to compile it, you'll get a bunch of confusing errors. Every non-trivial piece of Lean code needs to live inside a Lean project (sometimes also called a Lean package). A "Lean project" is more than just a folder that you've named "My Lean stuff". Rather, it's a folder containing some very specific things: in particular, a git repository and a file lakefile.lean that gathers information about dependencies of the project, including for instance the version of Lean that should be used.

If you're interested in contributing to mathlib you only need to set up a Lean project once, which you can use for all your contributions — you don't need to set up a new Lean project for each new contribution.

Setting up and managing all this is done by a program called lake (this is a portmanteau of lean and make). This page describes the basic use of this tool, and should be sufficient for everyday use. If this is not enough for your purposes, you can read the full lake documentation.

Working on an existing project #

Suppose you want to work on an existing project. As example, we will take the Mathematics in Lean book. Open a terminal.

Creating a Lean project #

We will now create a new project depending on mathlib. The following commands should be typed in a terminal.

If you want to make sure everything is working, you can start by creating, say my_project/MyProject/Test.lean containing:

import Mathlib.Topology.Basic

#check TopologicalSpace

When the cursor is on the last line, the right hand part of VS Code should display a "Lean Infoview" area saying: TopologicalSpace.{u} (α : Type u) : Type u.

Note that you can import your own files in the project. For instance if you created a file my_project/MyProject/Definitions.lean, you can start a new file my_project/MyProject/Lemmas.lean with import MyProject.Definitions.

If, for some reason, you happen to lose the "Lean Infoview" area, you can get it back with Ctrl-Shift-Enter (Cmd-Shift-Enter on MacOS). Also, you can get the Lean documentation inside VS Code using Ctrl-Shift-p (Cmd-Shift-p on MacOS) and then, inside the text field that appears, type "lean doc" and hit Enter. Then click "Mathematics in Lean" or "Theorem Proving in Lean" and enjoy.

Hosting your project on GitHub #

Your project is already a git repository, and as it grows, you may want to host it on GitHub. If you take this step, the community offers some GitHub Actions scripts that could help manage your repository. But don't worry if you don't know what this means. It's not necessary for using Lean.

Contributing to mathlib #

See How to contribute to mathlib.

InitializeSecurityContext error on Windows #

Some Windows users have reported an error like this when running lake exe cache get:

  curl: (35) schannel: next InitializeSecurityContext failed: Unknown error (0x80092012) - The revocation function was unable to check revocation for the certificate

If you see this error, you likely have an antivirus program that scans each downloaded file, which results in errors. Please disable your antivirus program and then run lake exe cache get!. The exclamation mark forces lake to re-download the cache files it failed to download before running this command. (If you are uncomfortable disabling your antivirus, try to follow these instructions and then run lake exe cache get!). You can turn on your antivirus program on afterwards. However, some users also reported that the antivirus programs significantly slow down Lean during normal usage. If Lean is slower than what is expected, either turn off your antivirus program or tell it to ignore/allow the operation of lean.exe.