Skip to content

About

Lean comments TeX rendering in neovim

Resources

Stars

1 star

Watchers

0 watching

Forks

Latest commit

 

History

1 Commit

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

lean-tex.nvim

Render LaTeX math in Lean comments as Unicode, right in the buffer.

/-- Gauss: $$\sum_{i=1}^n i = \frac{n(n+1)}{2}$$ for all $n \in \mathbb{N}$. -/

is displayed as

/-- Gauss: ∑ᵢ₌₁ⁿ i = (n(n+1))/2 for all n ∈ ℕ. -/

Math on the cursor line is shown raw so you can edit it. The buffer text is never modified; rendering uses concealed extmarks with inline virtual text.

  • Works in any terminal: no TeX install, no image protocol, no tree-sitter parser.
  • Loads automatically for .lean files; zero configuration required.
  • Recognizes $…$, $$…$$, \(…\), \[…\] in --, /- -/, /-- -/ and /-! -/ comments (nested block comments too). Inline code in backticks, string literals, and dollar amounts like $5 are left alone.

Requires Neovim 0.10+.

Install

lazy.nvim — create ~/.config/nvim/lua/plugins/lean-tex.lua:

return {
  { "tlehman/lean-tex.nvim", ft = "lean", opts = {} },
  -- or, for a local checkout:
  -- { dir = "~/src/tlehman/lean-tex.nvim", ft = "lean", opts = {} },
}

vim.pack (Neovim 0.12+):

vim.pack.add({ "https://github.com/tlehman/lean-tex.nvim" })

Manually: clone into ~/.local/share/nvim/site/pack/plugins/start/lean-tex.nvim.

That's it: plugin/lean-tex.lua registers a FileType lean autocommand, so there is nothing to call. setup() is only needed to change options.

Uninstall

The plugin keeps no state on disk, so removing it is enough:

  • lazy.nvim: delete the spec file, then run :Lazy clean.
  • vim.pack: :lua vim.pack.del({ "lean-tex.nvim" }).
  • Manually: delete the cloned directory.

Usage

Command Effect
:LeanTex Toggle rendering in all Lean buffers
:LeanTex enable Turn rendering on
:LeanTex disable Turn rendering off and remove all marks
:LeanTex refresh Re-render the current buffer

The rendered math uses the LeanTexMath highlight group (linked to Special by default):

vim.api.nvim_set_hl(0, "LeanTexMath", { link = "@markup.math" })

Configuration

Defaults:

require("lean-tex").setup({
  enabled = true,              -- render on startup
  filetypes = { "lean" },      -- filetypes to attach to
  reveal_cursor_line = true,   -- show raw LaTeX on the cursor line
  hl_group = "LeanTexMath",
  debounce_ms = 100,           -- delay before re-rendering after edits
})

Rendering needs conceallevel >= 2. The plugin sets it on windows showing Lean buffers when it is lower, and restores the old value when disabled.

require("lean-tex").render(tex) converts a LaTeX string to Unicode, if you want to reuse the renderer elsewhere.

What gets rendered

Greek letters, relations, arrows, logic and set notation, big operators, \mathbb / \mathcal / \mathfrak / \mathbf / \mathsf / \mathtt, super/subscripts (x^2 → x², a_n → aₙ, falling back to x^(…) when Unicode has no glyph), \frac (½, ³⁄₁₇, (a+b)/c), \sqrt, accents (\bar, \hat, \vec, …), \text, \operatorname, \pmod, \left/\right, and matrix/cases environments flattened onto one line. Unknown commands are shown as written.

Unicode can't express 2D layout, so this is an approximation. A multi-line $$ … $$ block is rendered on its first line, and the lines below it stay blank.

Development

make test   # nvim --headless -u NONE -l tests/test.lua

Open examples/demo.lean to see it in action.

About

Lean comments TeX rendering in neovim

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages