lervag / vimtex

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

Syntax conceal: Right delimiter `\right)` missing after conceal #3013

Closed Felipe-9 closed 1 week ago

Felipe-9 commented 2 weeks ago

related to #3010

Description

this code:

\begin{flalign*}
= \left(
\dots
+ c_1\,(
  e^{-x^2}
  \,(-2\,x)
)
\right) other chars that disappear
\end{flalign*}

is being concealed into

\begin{flalign*}
= (
...
+ c_1 (
  e^{-x^2}
   (-2 x)
)
her chars that disappear
\end{flalign*}

Steps to reproduce

No response

Expected behavior

No response

Actual behavior

No response

Do you use a latexmkrc file?

no

VimtexInfo

OS: macOS 14.6.1 (23G93)
  Vim version: NVIM v0.10.1
  Has clientserver: true
  Servername: /var/folders/5f/hn34hzl13y907124_kr68p380000gn/T/nvim.felipepinto/BZxJyY/nvim.76509.0
lervag commented 2 weeks ago

Strange - I can't reproduce this in a minimal example. On my end, it looks like this:

Without conceal:

image

Concealed:

image

I use the following test.vim and test.tex files and run nvim --clean -u test.vim.

set nocompatible
set runtimepath^=~/.local/plugged/vimtex
set runtimepath+=~/.local/plugged/vimtex/after
filetype plugin indent on
syntax enable

nnoremap q :qall!<cr>

let g:vimtex_view_method = "zathura"
let g:vimtex_cache_root = "."
let g:vimtex_cache_persistent = v:false

set conceallevel=2

silent edit test.tex
\begin{flalign*}
= \left(
\dots
+ c_1\,(
  e^{-x^2}
  \,(-2\,x)
)
\right) other chars that disappear
\end{flalign*}
Felipe-9 commented 2 weeks ago

could you try indenting everything inside flalign*? removing the indentation also displays the correct syntax conceal

Felipe-9 commented 2 weeks ago

Also, i noticed that when formatting the text, everything inside c_1\,(...) stays on the same indentation, instead of increasing one indentation, is that a bug?

lervag commented 1 week ago

could you try indenting everything inside flalign*? removing the indentation also displays the correct syntax conceal

It still looks "correct" to me (except that the last line is deindented, but that is another issue).

image

Also, i noticed that when formatting the text, everything inside c_1\,(...) stays on the same indentation, instead of increasing one indentation, is that a bug?

I assume that you by formatting mean the gq operation and that you have let g:vimtex_format_enabled = 1. On my end, it works as expected. If I start with your example but remove all indents, then do gggqG, then things will look like the screeshot above. Although, it should be noted that I added the following to the minimal vimrc:

set shiftwidth=2
set expandtab

Again, it would really be good if you could use the minimal examples while reporting. It makes it much easier to work on these things when we know we are on the "same page".

Felipe-9 commented 1 week ago
Part of my vimrc is `options.lua` I already had these options (`shiftwidth` and `expandtab`) enabled ```lua 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'} } ```
my `vimtex.lua`, i already had `vim.g.vimtex_indent_enabled = 1` ```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.imaps_enabled = 0 vim.g.vimtex_log_ignore = { "Underfull", "Overfull", "specifier changed to", "Token not allowed in PDF string", } -- -- Defining custom environments -- -- vim.call( 'vimtex#syntax#core#new_region_math' ,'BM') -- -- 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, } ```

the last line not being indented should be an error shouldnt it? also its that line that have the problem when its indented:

the code ```tex \begin{flalign*} = \left( \dots + c_1\,\left( e^{-x^2} \,(-2\,x) \right) other chars that disappear \right) other chars that disappear \end{flalign*} ```
Screenshot 2024-10-10 at 18 28 42

I also noticed that its being formatted with tabs instead of spaces, even tho my config i had made sure to indent with spaces, is this a bug?


if i do that command (gggqG) the result is quite weird:

\begin{flalign*} & = \left( \dots + c_1\,\left( e^{-x^2} \,(-2\,x) \right)
other chars that disappear \right) other chars that disappear & \end{flalign*}

normally i also use this other command vim.lsp.buf.format to format the whole buffer, i bound that into a shortcut <leader>mf

lervag commented 1 week ago

Ok, now there are many things at once here, which makes it very hard for me to answer. I only have a few minutes every once in a while, which is why I much prefer to have many parallell self-contained threads instead of one thread with a lot of topics at once.

It is good that you provide your relevant config, but it is not what I mean by providing a minimal example. Based on your post, it seems the following might be a relevant minimal config:

-- Make sure the folling paths are correct
vim.opt.runtimepath:prepend "~/.local/plugged/vimtex"
vim.opt.runtimepath:append "~/.local/plugged/vimtex/after"

vim.cmd [[filetype plugin indent on]]

local opt = vim.opt

opt.updatetime = 200
opt.wrap = false
opt.relativenumber = true           -- Relative number
opt.number = true                   -- Relative number with cursor being absolute number
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
opt.ignorecase = true               -- ignore case when searching
opt.smartcase = true                -- if you include mixed case in your search, assumes you want case-sensitive
opt.splitbelow = true               -- set new split windows below
opt.splitright = true               -- set new split windows right
opt.backspace = "indent,eol,start"  -- allow backspace on indent, end of line or insert mode start position
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
opt.clipboard:append("unnamedplus") -- use system clipboard as default register
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'} }

vim.keymap.set("n", "q", "<cmd>qall!<cr>")

vim.g.vimtex_cache_root = "."
vim.g.vimtex_cache_persistent = false
vim.g.vimtex_view_method = "zathura"
vim.g.vimtex_compiler_latexmk_engines = { ["_"] = "-lualatex" }
vim.g.vimtex_compiler_latexmk = {
  aux_dir = ".build",
  options = {
    "-shell-escape",
    "-verbose",
    "-file-line-error",
    "-synctex=1",
    "-interaction=nonstopmode",
  },
}
vim.g.vimtex_quickfix_mode = 1
vim.g.vimtex_mappings_enable = 0
vim.g.vimtex_log_ignore = {
  "Underfull",
  "Overfull",
  "specifier changed to",
  "Token not allowed in PDF string",
}
vim.wo.conceallevel = 2
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,
}

vim.cmd.edit "test.tex"

Save the above to a file test.lua, then run nvim --clean -u test.lua to load the config and open the test.tex file.

I also noticed that its being formatted with tabs instead of spaces, even tho my config i had made sure to indent with spaces, is this a bug?

No, it is not a bug. This is bad config on your part, but it's hard for me to say exactly what is happening. I can help debug it, but let's take one thing at a time here.

if i do that command (gggqG) the result is quite weird:

For this to work, you need vim.g.vimtex_format_enabled = 1 in your config. But if you only wanted to format by indents, then gg=G is probably enough.

Felipe-9 commented 1 week ago

Ok, now there are many things at once here, which makes it very hard for me to answer. I only have a few minutes every once in a while, which is why I much prefer to have many parallell self-contained threads instead of one thread with a lot of topics at once.

Sorry for not creating a new issue for these, i will try to be more careful in the future


For this to work, you need vim.g.vimtex_format_enabled = 1 in your config. But if you only wanted to format by indents, then gg=G is probably enough.

No, it is not a bug. This is bad config on your part, but it's hard for me to say exactly what is happening. I can help debug it, but let's take one thing at a time here.

Im still having some trouble with this, will open an issue to focus better


It is good that you provide your relevant config, but it is not what I mean by providing a minimal example. Based on your post, it seems the following might be a relevant minimal config:

i tried using this code but this is all i get:

`test.tex` ```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) other chars that disappear \right) other chars that disappear & \end{flalign*} \end{document} ```
`$ nvim test.tex` Screenshot 2024-10-12 at 17 17 54
`$ nvim --clean -u test.lua` Screenshot 2024-10-12 at 17 19 49
user202729 commented 1 week ago

@Felipe-9

$ nvim --clean -u test.lua [...]

Remember to change the first two lines according to your configuration. Looks like vimtex wasn't loaded at all.

(Assume you already did, as you can see the problem is not reproducible with a minimal configuration --- so the issue is the interference with some other plugins you have, and nobody knows what they are. Try uninstalling them one by one)

Felipe-9 commented 1 week ago

I tried leaving only vimtex plugin, this is the config

`init.lua` ```lua vim.g.mapleader = " " -- Leader key into space vim.g.maplocalleader = "\\" -- local keymap = vim.keymap -- -- keymap.set('i', "jk", "gcc", { desc = "Exit insert mode with jk" }) -- -- -- keymap.set('n', "/", "gcc", { desc = "comment out line" }) -- keymap.set('n', "nh", ":nohl", { desc = "Clear search highlights" }) -- keymap.set('n', "+", "", { desc = "Increment number" }) -- keymap.set('n', "-", "", { desc = "Decrement number" }) -- -- window management -- keymap.set("n", "sv", "v", { desc = "Split window vertically" }) -- split window vertically -- keymap.set("n", "sh", "s", { desc = "Split window horizontally" }) -- split window horizontally -- keymap.set("n", "se", "=", { desc = "Make splits equal size" }) -- make split windows equal width & height -- keymap.set("n", "sx", "close", { desc = "Close current split" }) -- close current split window -- -- tab management -- keymap.set("n", "to", "tabnew", { desc = "Open new tab" }) -- open new tab -- keymap.set("n", "tx", "tabclose", { desc = "Close current tab" }) -- close current tab -- keymap.set("n", "tn", "tabn", { desc = "Go to next tab" }) -- go to next tab -- keymap.set("n", "tp", "tabp", { desc = "Go to previous tab" }) -- go to previous tab -- keymap.set("n", "tf", "tabnew %", { desc = "Open current buffer in new tab" }) -- move current buffer to new tab -- -- 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 = "plugins.latex.vimtex" } -- { 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" }, }) ```

opening test.tex we can see the concealed chars but the indentation is all broken which is an error on its own

image1

i tried then toggling on and off my plugins one by one and found out that this plugin

{ import = "plugins.indent-blankline" }, -- Indenting help linesg

was causing the problem, probably, since the indentation is removed, those lines are overitting the characters, which means that if we fix the indentation, the problem will be resolved

user202729 commented 1 week ago

Concealing the blank space before the \right is more of a bug than a feature, so that $\left( 123 \right)$ will get concealed to (123) without any space before the ).

On the other hand concealing the blank space for the indentation doesn't seem that desirable. Maybe the regex can be modified a bit…? (is lookbehind allowed? I haven't taken a look)

Felipe-9 commented 1 week ago

how is the current regex configured? i could take a look

lervag commented 1 week ago

Sorry for not creating a new issue for these, i will try to be more careful in the future

Thanks, and no problem. I hope you don't mind the feedback on such things and that I don't come off too rude!

i tried using this code but this is all i get: …

I think user202729 is correct that you did not update the paths to VimTeX in the first lines.

Do you know the paths to VimTeX on your system? Do you need help finding them?

I tried leaving only vimtex plugin, this is the config …

i tried then toggling on and off my plugins one by one and found out that this plugin

Ok; simplifying your own config to the point where your problems resolve themselves is also a good way to find the cause of the problems.

{ import = "plugins.indent-blankline" }, -- Indenting help linesg

I don't use that plugin myself.

was causing the problem, probably, since the indentation is removed, those lines are overitting the characters, which means that if we fix the indentation, the problem will be resolved

I don't quite understand this part. On my end, the indentation is good.

Concealing the blank space before the \right is more of a bug than a feature, so that $\left( 123 \right)$ will get concealed to (123) without any space before the ).

Yes; I think you are right. I've included the preceding white space for right delimiters and the whitespace after for the left delimiters in the conceals. I think that was a mistake.

So, I propose we change that now. I'll drop the concealing of the white spaces for delimiters. And that might also ultimately fix the conflict with the indent-lines plugin as well

user202729 commented 1 week ago

how is the current regex configured? i could take a look

I… don't know where is it in the source code at the moment. You can find it yourself.

user202729 commented 1 week ago

@lervag

I've included the preceding white space for right delimiters and the whitespace after for the left delimiters in the conceals. I think that was a mistake.

Is it? It feels so intentional for me.

For example $\left\langle a\right\rangle$ gets concealed to $⟨a⟩$ which makes perfect sense. (You can't remove the space after the langle. In this specific case you can also replace it with \left<a\right>, but you get the point.)

Felipe-9 commented 1 week ago

Thanks, and no problem. I hope you don't mind the feedback on such things and that I don't come off too rude!

I would never, if anything im glad you express well how we can interact better and be efficient in resolving these issues!


Do you know the paths to VimTeX on your system? Do you need help finding them?

ah for some reason i only understood what those lines meant later, yeah i do know the path, on my computer its `~/.local/share/nvim/lazy/vimtex`, after fixing that i get: Screenshot 2024-10-13 at 16 42 26 which as you can see have no indentation, the expected would be this Screenshot 2024-10-13 at 16 44 07

I don't quite understand this part. On my end, the indentation is good.

since vimtex is acting before insert-blankspace plugin, which means that first, vimtex writes those lines: ```tex \begin{flalign*} & = ( \dots + c_1\,( e^{-x^2} \,(-2\,x) ) other chars that disappear ) other chars that disappear & \end{flalign*} ``` and then insert-blankspace overwrites based on indentation ```tex \begin{flalign*} | & | = ( | | \dots | | + c_1\,( | | | e^{-x^2} | | | \,(-2\,x) | | er chars that disappear | ther chars that disappear | & \end{flalign*} ``` Screenshot 2024-10-13 at 16 52 07

Yes; I think you are right. I've included the preceding white space for right delimiters and the whitespace after for the left delimiters in the conceals. I think that was a mistake.

For example $\left\langle a\right\rangle$ gets concealed to $⟨a⟩$ which makes perfect sense. (You can't remove the space after the langle. In this specific case you can also replace it with \left<a\right>, but you get the point.)

in this case a regex like this \\left[{(<]\ * would allow for that, although i normally leave space intentionally and that wouldnt be much desirable for me

lervag commented 1 week ago

I've included the preceding white space for right delimiters and the whitespace after for the left delimiters in the conceals. I think that was a mistake.

Is it? It feels so intentional for me.

Yes, it was intentional. And more or less for the specific reason to handle the example you provide:

For example $\left\langle a\right\rangle$ gets concealed to $⟨a⟩$ which makes perfect sense.

When I say mistake, I mean that the solution became too general.

But I think we might want to still conceal a single whitespace after the opening delimiter. But not more than one.

lervag commented 1 week ago

I've pushed an update now that I think is more in line with the current discussion. Can you please check if you agree with the updated behaviour?

lervag commented 1 week ago

Thanks, and no problem. I hope you don't mind the feedback on such things and that I don't come off too rude!

I would never, if anything im glad you express well how we can interact better and be efficient in resolving these issues!

Great, glad to hear it.

Do you know the paths to VimTeX on your system? Do you need help finding them?

ah for some reason i only understood what those lines meant later, yeah i do know the path, on my computer its ~/.local/share/nvim/lazy/vimtex, after fixing that i get: …

Great; I believe my latest update should fix that.

I don't quite understand this part. On my end, the indentation is good.

since vimtex is acting before insert-blankspace plugin, which means that first, vimtex writes those lines: …

and then insert-blankspace overwrites based on indentation …

Ah, I see. Then I believe my latest update should fix this.

Felipe-9 commented 1 week ago

Yes perfectly, thank you!

Screenshot 2024-10-13 at 18 14 22
lervag commented 1 week ago

Great, glad to hear it's working better now!