GithubHelp home page GithubHelp logo

leanprover-community / lean4web Goto Github PK

View Code? Open in Web Editor NEW
57.0 10.0 15.0 9.86 MB

The Lean 4 web editor

Home Page: https://live.lean-lang.org/

License: Apache License 2.0

HTML 0.38% CSS 61.00% JavaScript 2.25% TypeScript 34.60% Shell 0.71% Lean 1.05%
lean4

lean4web's Introduction

Lean 4 Web

This is a web version of Lean 4. The official lean playground is hosted at live.lean-lang.org, while lean.math.hhu.de hosts a development server testing newer features.

In contrast to the Lean 3 web editor, in this web editor, the Lean server is running on a web server, and not in the browser.

Contribution

If you experience any problems, or have feature requests, please open an issue here! PRs are welcome as well.

To add new themes, please read Adding Themes.

Security

Providing the use access to a Lean instance running on the server is a severe security risk. That is why we start the Lean server using Bubblewrap.

Build Instructions

We have set up the project on a Ubuntu Server 22.10. Here are the installation instructions:

Install NPM (don't use apt-get since it will give you an outdated version of npm):

curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.2/install.sh | bash
source ~/.bashrc
nvm install node npm

Now, install git and clone this repository:

sudo apt-get install git
git clone --recurse-submodules https://github.com/leanprover-community/lean4web.git

note that --recurse-submodules is needed to load the predefined projects in Projects/. (on an existing clone, you can call git submodule init and git submodule update)

Install Bubblewrap:

sudo apt-get install bubblewrap

Navigate into the cloned repository, install, and compile:

cd lean4web
npm install
npm run build

Now the server can be started using

PORT=8080 npm run production

To set the locations of SSL certificates, use the following environment variables:

SSL_CRT_FILE=/path/to/crt_file.cer SSL_KEY_FILE=/path/to/private_ssl_key.pem PORT=8080 npm run production

Cronjob

Optionally, you can set up a cronjob to regularly update the mathlib version. To do so, run

crontab -e

and add the following lines, where all paths must be adjusted appropriately:

# Need to set PATH manually:
SHELL=/usr/bin/bash
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/home/USER/.elan/bin:/home/USER/.nvm/versions/node/v20.8.0/bin/

# Update server (i.e. mathlib) of lean4web and delete mathlib cache
*  */6 * * * cd /home/USER/lean4web && npm run build_server 2>&1 1>/dev/null | logger -t lean4web
40 2   * * * rm -rf /home/USER/.cache/mathlib/

Note that with this setup, you will still have to manage the lean toolchains manually, as they will slowly fill up your space (~0.9GB per new toolchain): see elan toolchain --help for infos.

In addition, we use Nginx and pm2 to manage our server.

Managing toolchains

Running and updating the server periodically might accumulate lean toolchains.

To delete unused toolchains automatically, you can use the elan-cleanup tool and set up a cron-job with crontab -e and adding the following line, which runs once a month and deletes any unused toolchains:

30 2 1 * * /PATH/TO/elan-cleanup/build/bin/elan-cleanup | logger -t lean-cleanup

You can see installed lean toolchains with elan toolchain list and check the size of ~/.elan.

Legal information

For legal purposes, we need to display contact details. When setting up your own server, you will need to modify the following files:

  • client/src/config/text.tsx: Update contact information & server location. (set them to null if you don't need to display them in your country)
  • client/public/index.html: Update the noscript page with the correct contact details.

Development Instructions

Install npm and clone this repository. Inside the repository, run:

  1. npm install, to install dependencies
  2. npm run build_server, to build contained lean projects under Projects/ (or run lake build manually inside any lean project)
  3. npm start, to start the server.

The project can be accessed via http://localhost:3000. (Internally, websocket requests to ws://localhost:3000/websockets will be forwarded to a Lean server running on port 8080.)

Running different projects

You can run any lean project through the webeditor by cloning them to the Projects/ folder. See Adding Projects for further instructions.

lean4web's People

Contributors

abentkamp avatar joneugster avatar vtec234 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

lean4web's Issues

Off-by-one line status colors

This is very minor, but thought I'd mention that the color status to the left of the line number seems to be off by one:

import Lean

elab "#wait" : command => IO.sleep 10000

-- yellow appears here
#wait

Link to live code; noticed on Firefox and Safari.

(Also thanks for lean4web; it's extremely useful! :) )

docker version

maybe construct a docker image is easiler for us to deployment

feature request: import package

Current situation

  • Packages other than mathlib cannot be used.
  • To add more packages that can be used with lean4 web, changes need to be made to the lean4 web code

I want a feature such that...

  • Import packages in-place on the lean4 web based on GitHub repository URLs.

[Windows] [Chrome] Cursor display position and input position are mismatched

I just can't solve it. I'm so confused.

When you try to define longlonglong....name, there was a problem with the cursor "lagging" behind the displayed character.

see #7 (comment)

The bug seems to be caused by a difference between the character width used to calculate the assumed cursor position and the actual character width of the font.

But I don't know how to solve it...

Test Result

  • It cannot be reproduced if the OS is Mac.
  • Clearing the cache and reloading doesn't help.
  • If font is consolas, alphabetic characters are not mismatched, but double-byte characters are mismatched.
  • If the font is JuliaMono, full-width characters are not mismatched, but alphabetic characters are mismatched.
  • No problem in firefox.

My Environment

  • OS: Windows 11 Home
  • Browser: latest Chrome

no imports in dev-version

Starting with npm start (on macOS, no bubblewrap) starts the server as expected but mathlib can't be imported. It looks like some path is off.

Copy-Paste on mobile

On mobile I can't paste code, nor can I select code in the editor to copy it.

Comment highlighting

Example, where the comment highlighting is off: demo

/- ## Wichtig:
- Bei der Verwendung von `calc` müssen alle `_` gleich weit eingerückt sein, sonst gibt es
  verwirrende Fehlermeldungen.
- Sehen Sie die Fehlermeldung `fail to show termination for ...`? Das weist darauf hin, dass
  Induktion verwendet wurde, die Argumente aber nicht strukturell kleiner sind. Eventuell wurden
  in Kombination mit `rw` auch Argumente nicht explizit angegeben? -/

For me, only the last line is marked green (i.e. the colour of comments in the theme)

bug: `.so` files not supported

Somehow it seems that the web editor cannot handle .so files. A workaround is to add precompileModules := false in all dependencies.

Hover help for 'obtain' sometimes fail

Hovering help for 'obtain' tactic unexpectedly fail in one of the two example lemmas in the same window. Tested in Firefox and Chromium.

import Mathlib.Data.Complex.Basic

example (a b a' b' : ℂ) (h : (fun z => a * z + b) = fun z => a' * z + b') : a = a' := by
apply congr_fun at h
obtain rfl: b = b' := by  -- Hovering over obtain unexpectedly displays "x✝ : b = b'"
  specialize h 0
  simp at h; exact h

specialize h 1
simp at h
exact h

example (a: Prop) : a -> a := by

obtain h: 3 = 3 -- Hovering over obtain displays useful help "The obtain tactic is a combination..."

admit 

https://live.lean-lang.org/#code=import%20Mathlib.Data.Complex.Basic%0A%0Aexample%20(a%20b%20a'%20b'%20%3A%20%E2%84%82)%20(h%20%3A%20(fun%20z%20%3D%3E%20a%20*%20z%20%2B%20b)%20%3D%20fun%20z%20%3D%3E%20a'%20*%20z%20%2B%20b')%20%3A%20a%20%3D%20a'%20%3A%3D%20by%0Aapply%20congr_fun%20at%20h%0Aobtain%20rfl%3A%20b%20%3D%20b'%20%3A%3D%20by%20%20--%20Hovering%20over%20obtain%20unexpectedly%20displays%20%22x%E2%9C%9D%20%3A%20b%20%3D%20b'%22%0A%20%20specialize%20h%200%0A%20%20simp%20at%20h%3B%20exact%20h%0A%0Aspecialize%20h%201%0Asimp%20at%20h%0Aexact%20h%0A%0Aexample%20(a%3A%20Prop)%20%3A%20a%20-%3E%20a%20%3A%3D%20by%0A%0Aobtain%20h%3A%203%20%3D%203%20--%20Hovering%20over%20obtain%20displays%20useful%20help%20%22The%20obtain%20tactic%20is%20a%20combination...%22%0A%0Aadmit%20

Zulip discussion:
https://leanprover.zulipchat.com/#narrow/stream/113489-new-members/topic/Stuck.20on.20fun.20in.20hypothesis

bug: editor not updating until reloading page

The remaining part about changing lean projects is that after changing project (i.e. lean version) the editor messages (squigglies, yellow task bar, ...) do not update unless the site is reloaded.

add non-linux support

bubblewrap seems to be the major limiting factor that this cannot be run on anything but linux. Probably would be good to default to not using bubblewrap if it does not exist.

display versions

reimplement a way to display the versions of lean (&mathlib) that are run on the server.

Separate packages

client and server could be two independent npm packages, LeanProject does not need to live in the server. Instead, one should be able to specify any lake package as input to the server.

program should be stored in localstore not URL

As far as I can see the current code is stored in the URL.

I don't believe this will scale to medium-to-longer code.

The web service for prolog https://swish.swi-prolog.org doesn't store code in the URL but appears to store it locally using the web local storage API https://www.w3schools.com/html/html5_webstorage.asp

This has 3 benefits:

  • larger storage capacity
  • increased performance
  • no passing of code to server

Sadly I am no expert at coding so this is a suggestion, not a PR.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.