lervag / vimtex

VimTeX: A modern Vim and neovim filetype plugin for LaTeX files.
MIT License
5.51k stars 389 forks source link

Problem formatting with `vim.lsp.buf.format` #3029

Closed Felipe-9 closed 1 week ago

Felipe-9 commented 1 week ago

Description

Following #3013

when i use my default formatting shortcut its not behaving as expected Expected behaviour would be formatting into the original file (test.tex) (no changes)

text.tex (original) ```tex % !TEX root = ./test.tex \documentclass[ class=article, multi={minipage}, border={3mm}, ]{standalone} \usepackage{amsmath, amssymb} \usepackage{mathtools} \begin{document} \begin{flalign*} & = \left( \dots + c_1\,\left( e^{-x^2} \,(-2\,x) \right) \right) & \end{flalign*} \end{document} ```
test.tex after `vim.lsp.buf.format` (actual behaviour) Notice: - is using tabs - no indentation regarding delimiters `\left(...\right)` ```tex ... \begin{flalign*} & = \left( \dots + c_1\,\left( e^{-x^2} \,(-2\,x) \right) \right) & \end{flalign*} ... ```

Config

init.lua ```lua -- KEYMAP vim.g.mapleader = " " -- Leader key into space vim.g.maplocalleader = "\\" -- OPTIONS local opt = vim.opt -- Options opt.updatetime = 200 opt.wrap = false -- Linenumber opt.relativenumber = true -- Relative number opt.number = true -- Relative number with cursor being absolute number -- tabs & indentation opt.tabstop = 2 -- 2 spaces for tabs (prettier default) opt.softtabstop = 2 -- opt.shiftwidth = 2 -- 2 spaces for indent width opt.expandtab = true -- expand tab to spaces opt.autoindent = true -- copy indent from current line when starting new one -- search settings opt.ignorecase = true -- ignore case when searching opt.smartcase = true -- if you include mixed case in your search, assumes you want case-sensitive -- Splits opt.splitbelow = true -- set new split windows below opt.splitright = true -- set new split windows right -- backspace opt.backspace = "indent,eol,start" -- allow backspace on indent, end of line or insert mode start position -- Theme opt.cursorline = true -- Highlight cursor line opt.termguicolors = true opt.background = "dark" -- colorschemes that can be light or dark theme opt.signcolumn = "yes" -- show sign column so taht text doesnt shift -- clipboard opt.clipboard:append("unnamedplus") -- use system clipboard as default register -- ui vim.lsp.handlers["textDocument/hover"] = vim.lsp.with( vim.lsp.handlers.hover, { border = "rounded" } ) vim.lsp.handlers["textDocument/signatureHelp"] = vim.lsp.with( vim.lsp.handlers.signature_help, { border = "rounded" } ) vim.diagnostic.config{ float={border= 'rounded'} } -- LAZY -- Bootstrap lazy.nvim local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim" if not (vim.uv or vim.loop).fs_stat(lazypath) then local lazyrepo = "https://github.com/folke/lazy.nvim.git" local out = vim.fn.system({ "git", "clone", "--filter=blob:none", "--branch=stable", lazyrepo, lazypath }) if vim.v.shell_error ~= 0 then vim.api.nvim_echo({ { "Failed to clone lazy.nvim:\n", "ErrorMsg" }, { out, "WarningMsg" }, { "\nPress any key to exit..." }, }, true, {}) vim.fn.getchar() os.exit(1) end end vim.opt.rtp:prepend(lazypath) require("lazy").setup({ { import = "profiles.felipe.plugins" }, }, { install = { colorscheme = { "catppuccin-mocha" } }, -- automatically check for plugin updates checker = { enabled = true, notify = false, }, change_detection = { notify = false }, ui = { border = "rounded" }, }) ```
vimtex.lua ```lua return { "lervag/vimtex", lazy = false, init = function() -- Preview vim.g.vimtex_view_method = "zathura" vim.g.latex_view_general_viewer = "zathura" -- vim.g.vimtex_view_method = "zathura_simple" -- Compiling vim.g.vimtex_compiler_latexmk_engines = { ["_"] = "-lualatex" } vim.g.vimtex_compiler_latexmk = { aux_dir = ".build", -- out_dir = "", options = { "-shell-escape", "-verbose", "-file-line-error", "-synctex=1", "-interaction=nonstopmode", }, } -- Features vim.g.vimtex_quickfix_mode = 1 vim.g.vimtex_mappings_enable = 0 vim.g.vimtex_indent_enabled = 1 vim.g.vimtex_format_enabled = 1 vim.g.imaps_enabled = 0 vim.g.vimtex_log_ignore = { "Underfull", "Overfull", "specifier changed to", "Token not allowed in PDF string", } -- -- Syntax conceal -- vim.wo.conceallevel = 2 vim.vimtex_syntax_conceal = 1 vim.g.vimtex_syntax_conceal = { accents = 1, ligatures = 1, cites = 1, fancy = 1, spacing = 0, greek = 1, math_bounds = 1, math_delimiters = 1, math_fracs = 1, math_super_sub = 0, math_symbols = 1, sections = 0, styles = 1, } -- -- Defining custom syntax conceal -- -- Simple commands vim.g.vimtex_syntax_custom_cmds = { -- { -- mathmode = true, -- name = ",", -- concealchar = " ", -- }, { -- mdif mathmode = true, name = "mdif", concealchar = "D", }, { -- mdif* mathmode = true, name = "mdifstar", cmdre = "mdif\\*", concealchar = "D", }, { -- odif mathmode = true, name = "odif", concealchar = "d", }, { -- fdif mathmode = true, name = "fdif", concealchar = "δ", }, { -- adif mathmode = true, name = "adif", concealchar = "Δ", }, { -- jdif mathmode = true, name = "jdif", concealchar = "∂", }, { -- gdif mathmode = true, name = "gdif", concealchar = "∇", }, } -- Commands with variables vim.g.vimtex_syntax_custom_cmds_with_concealed_delims = { { -- myrange mathmode = true, opt = false, name = "myrange", nargs = 1, cchar_open = "[", cchar_close = "]", }, { -- myrange* mathmode= true, opt = false, conceal=true, name = "myrangestar", cmdre = "myrange\\*", nargs = 1, cchar_open = "]", cchar_close = "[" }, { -- myranger mathmode = true, opt = false, name = "myranger", nargs = 1, cchar_open = "[", cchar_close = "[", }, { -- myrangel mathmode = true, opt = false, name = "myrangel", nargs = 1, cchar_open = "]", cchar_close = "]", }, { -- myrangelr mathmode = true, opt = false, name = "myrangelr", nargs = 1, cchar_open = "]", cchar_close = "[", }, { -- myvert mathmode = true, opt = false, nargs= 1, name = "myvertsingle", cmdre = "myvert", cchar_open = "|", cchar_close = "|" }, { -- myVert mathmode = true, opt = false, nargs= 1, name = "myVertdouble", cmdre = "myVert", cchar_open = "‖", cchar_close = "‖" }, { -- myvert* mathmode = true, opt = false, nargs= 1, name = "myvertsinglestar", cmdre = "myvert\\*", cchar_open = "|", cchar_close = "|" }, { -- myVert mathmode = true, opt = false, nargs= 1, name = "myVertdoublestar", cmdre = "myVert\\*", cchar_open = "‖", cchar_close = "‖" }, } vim.g.vimtex_syntax_custom_envs = { { name = "BM", math = true } } end, } ```

Steps to reproduce

No response

Expected behavior

No response

Actual behavior

No response

Do you use a latexmkrc file?

no

VimtexInfo

System info:
  OS: macOS 14.6.1 (23G93)
  Vim version: NVIM v0.10.2
  Has clientserver: true
  Servername: /var/folders/5f/hn34hzl13y907124_kr68p380000gn/T/nvim.felipepinto/Nb3Bw9/nvim.36780.0

VimTeX project: test
  base: test.tex
  root: /Users/felipepinto/.config/nvim/lua/issues.vimtex/vimtex.3013
  tex: /Users/felipepinto/.config/nvim/lua/issues.vimtex/vimtex.3013/test.tex
  main parser: texroot specifier
  document class: minipage
  packages: amsbsy amsfonts amsgen amsmath amsopn amssymb amstext calc epstopdf-base graphics graphicx ifluatex iftex infwarerr ltxcmds luatex85 mathtools mhsetup pdftexcmds shellesc trig xkeyval
  compiler: latexmk
    engine: -lualatex
    options:
      -shell-escape
      -verbose
      -file-line-error
      -synctex=1
      -interaction=nonstopmode
    aux_dir: .build
    callback: 1
    continuous: 1
    executable: latexmk
  viewer: Zathura
    xwin id: 0
  qf method: LaTeX logfile
lervag commented 1 week ago

when i use my default formatting shortcut

You should state explicitly what this is. Did you configure it manually?

its not behaving as expected Expected behaviour would be formatting into the original file (test.tex) (no changes) …

test.tex after vim.lsp.buf.format (actual behaviour)

I believe this issue is not a VimTeX issue. VimTeX is not a language server. Are you using texlab; if so, then perhaps this is an issue you should post on the texlab project?

Felipe-9 commented 1 week ago

ah yes sorry, i should have been more clear in the question, the default is vim.lsp.buf.format

I believe this issue is not a VimTeX issue. VimTeX is not a language server. Are you using texlab; if so, then perhaps this is an issue you should post on the texlab project?

you are right, i didnt noticed that before

lervag commented 1 week ago

No problem :)