Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Quickstart

Language server

Requirescargo
Platformslinux, macOS, Windows
Successfully tested onArch
Documentationspectralflux.dev/decs/m2-ls.html
Repositorygithub.com/AlexanderGolys/m2-ls.git
crates.iocrates.io/crates/m2-ls

The m2-ls language server is cross platform binary Rust crate with no additional dependencies needed to run the binary. To install it from cargo toolchain run

cargo install m2-ls

To run it from source code, clone the repository and run

cargo run --bin m2-ls

To configure the client in code editors, see LSP setup

Linting and formatting

Linter and formatter used in m2-ls are also available as standalone binaries. After installing the crate, you can run them in terminal using

m2-fmt [file] 
m2-lint [file]

VS Code extension

Search for the Macaulay2 LSP extension and you’re done.

Documentation · Marketplace · Repository

m2.nvim

RequiresNeovim 0.11+, M2 for running code
Platformslinux, macOS, Windows
Successfully tested onArch
DocumentationNvim plugin
Repositorygithub.com/AlexanderGolys/m2.nvim

With lazy.nvim add

{
  "AlexanderGolys/m2.nvim",
  dependencies = { "nvim-treesitter/nvim-treesitter" },
  opts = {},
}

The plugin doesn’t start the language server by itself, see LSP in Nvim for the few lines that do.

Running code

<leader>mo opens M2 in a split, <leader>mc sends the expression under the cursor (or the selection) to it.

spectral-m2

Requirescargo, M2
Platformslinux, macOS
Successfully tested onArch
Documentationspectral-m2
Repositorygithub.com/AlexanderGolys/spectral-m2
crates.iocrates.io/crates/spectral-m2

spectral-m2 runs your installed M2 underneath, so M2 needs to be on the PATH. To install it run

cargo install spectral-m2 --locked

and start it with spectral-m2 (or just sp2) instead of M2. Typing / on an empty line lists all commands.

Fonts

Icons need a Nerd Font. Without one, set SPECTRAL_M2_BASIC_GLYPHS=1.

MarkdownDocs

RequiresM2, mdbook
Platformslinux, macOS
Successfully tested onArch
DocumentationMarkdownDocs
Repositorygithub.com/AlexanderGolys/MarkdownDocs

Clone the repository and install the package from M2

installPackage("MarkdownDocs", FileName => "/path/to/MarkdownDocs.m2")

mdbook-tsitter

Requirescargo, mdbook 0.5, git, C compiler
Platformslinux, macOS, Windows
Successfully tested onArch
Documentationspectralflux.dev/mdbook-tsitter
Repositorygithub.com/AlexanderGolys/mdbook-tsitter
crates.iocrates.io/crates/mdbook-tsitter

To install it run

cargo install mdbook-tsitter

and enable it in book.toml

[preprocessor.tsitter]

First build

Grammars are compiled on first use, which is why git and a C compiler are needed. After that they’re cached.

ProceduralMacros

RequiresM2 1.26.05+
Platformslinux, macOS
Successfully tested onArch
DocumentationProceduralMacros
Repositorygithub.com/AlexanderGolys/ProceduralMacros

Clone the repository and install the package from M2

installPackage("ProceduralMacros", FileName => "/path/to/ProceduralMacros.m2")

m2-syn

Requirescargo
Platformslinux, macOS, Windows
Successfully tested onArch
Documentationdocs.rs/m2-syn
Repositorygithub.com/AlexanderGolys/m2-syn
crates.iocrates.io/crates/m2-syn

m2-syn is a library crate. To add it to your Rust project run

cargo add m2-syn

Inspecting a file

To see the syntax tree of a file, clone the repository and run

cargo run --example inspect -- file.m2

tree-sitter-macaulay2

Requirescargo, npm or pip
Platformslinux, macOS, Windows
Successfully tested onArch
Documentationtree-sitter-macaulay2
Repositorygithub.com/AlexanderGolys/tree-sitter-macaulay2
crates.iocrates.io/crates/tree-sitter-macaulay2
npmnpmjs.com/package/tree-sitter-macaulay2
PyPIpypi.org/project/tree-sitter-macaulay2

The grammar is published for Rust, Node and Python

cargo add tree-sitter tree-sitter-macaulay2
npm install tree-sitter-macaulay2
pip install tree-sitter-macaulay2

Editors

To use the grammar for highlighting in an editor, see Setting up tree-sitter.