Skip to content

yuukibarns/latex.nvim

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

84 Commits
 
 
 
 
 
 
 
 

Repository files navigation

latex.nvim

(very) minimal, opinionated neovim filetype plugin for (La)TeX and Markdown, written in Lua. There is no reason to prefer this plugin to VimTeX.

Installation

-- lazy.nvim
{
    "mathjiajia/latex.nvim",
    config = true,
}

Requirements

To use imaps, which are based on treesitter, you must have treesitter parsers for the relevant filetype installed. For example, latex for .tex files and markdown and markdown_inline for .md files.

Configuration

To use latex.nvim you need to put

require("latex").setup()

somewhere in your config. This is equivalent to the following default configuration.

require("latex").setup({
    conceals = {
        enabled = {
            "amssymb",
            "delim",
            "font",
            "greek",
            "math",
            "script",
    },
    add = {},
  },
  imaps = {
    enabled = true,
    add = {},
    default_leader = "`",
  },
  surrounds = {
    enabled = false,
    command = "c",
    environment = "e",
  },
  texlab = {
    enabled = true,
    build = "<M-b>",
    forward = "<M-f>",
    cancel_build = "<M-x>",
    close_env = "]]",
    change_env = "cse",
    toggle_star = "tse",
  },
})

See below for more about configuring imaps.

Features

Imaps

Currently latex.nvim provides user-configurable, context-aware insert-mode mappings in .tex and .md files. The mappings are directly inspired by VimTeX.

The imaps.add table in setup() expects one of the following formats

{
  ["rhs"] = "lhs",
  -- the above is equivalent to
  ["rhs"] = {
    lhs = "lhs",
    leader = nil, -- will be replaced by default_leader
    wrap_char = false,
    context = nil -- will be replaced by one of require('latex').imaps.tex_math_mode or require('latex').imaps.markdown_math_mode
  }
}

Assuming a default_leader of "`", typing "`lhs" while within math mode (e.g. between a pair of $ or a \[, \] block in a .tex file, or between a pair of $$ in a .md file) will yield an output of "rhs".

wrap_char

A mapping with wrap_char = true, for example the default mapping

{
  ["\\mathbb"] = {
    lhs = "B",
    leader = "#",
    wrap_char = true
  }
 }

yields, after inputting "#BZ" in math mode, the output "\mathbb{Z}".

Conceals

Almost all of the low-hanging fruit is done as far as concealing; hard things like using tree-sitter for \'e to é are not a priority.

You can disable conceals on a per-file basis by redefining conceals.enabled in the setup function.

Currently the conceals provided are:

  • Delim: things like \left and many instances of curly braces.
  • Font: things like \mathbb{Z} to
  • Greek: things like \sigma to σ
  • Math: things like \amalg to ⨿
  • Script: superscripts and subscripts

You can add your own concealed commands to the conceals.add table in the following format

add = {
    ["colon"] = ":",
}

The key should be the command name with the leading backslash stripped, and the value should be the single-character conceal to replace that command with. The add table is for concealing generic_command elements. Unlike most other conceals, these are not sensitive to the presence or absence of math mode.

Surrounds

Requires nvim-surround. Provides add, change and delete for commands and environments. With default settings for nvim-surround, these are mapped to, for example, csc for change surrounding command and dse for delete surrounding environment.

To enable, set surrounds.enabled to true.

Non-features

  • compilation, forward/backward search, completion, linting—use texlab
  • highlighting—use treesitter

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Scheme 74.6%
  • Lua 25.4%