lervag / vimtex

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

Need some help with custom syntax conceal commands #3010

Open Felipe-9 opened 1 day ago

Felipe-9 commented 1 day ago

Related to #2964

Right delimiter `\right)` missing after conceal this code: ```lua = \left( ... + c_1\,( e^{-x^2} \,(-2\,x) ) \right) ``` is being concealed into ```lua = ( ... + c_1 ( e^{-x^2} (-2 x) ) ```
starred commands returning error defining `\myrange{}` like this ```lua { mathmode= true, name = "myrange*", nargs = 2, cchar_open = "]", cchar_close = "[" } ``` results in error: `Vim(syntax):E5248: Invalid character in group name`
im having trouble concealing `\,` into ` ` (double spaces) ``` { mathmode=true, name = ",", concealchar = " " }, ``` i get the error `Vim(syntax):E5248: Invalid character in group name`
closing char incorrect this ```lua { mathmode = true, nargs= 1, name = "myVert", cchar_open = "‖", cchar_close = "‖" }, ``` results in this `\myVert{...}` -> `‖ ...|` also another problem with this (which is not exclusive to it, my others customs have the same problem) the spacing is wrong its only added to the first delimiter, instead of both. eg: `\myvert{x^2}` -> `| x^2|` instead of `| x^2 |`

Do you use a latexmkrc file?

no

### vimtex.lua ```lua return { "lervag/vimtex", lazy = false, init = function() vim.g.vimtex_view_method = "zathura" vim.g.latex_view_general_viewer = "zathura" -- vim.g.vimtex_view_method = "zathura_simple" 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", }, } vim.g.vimtex_quickfix_mode = 1 vim.g.vimtex_mappings_enable = 0 vim.g.vimtex_indent_enabled = 1 vim.g.imaps_enabled = 0 vim.o.conceallevel = 1 vim.vimtex_syntax_conceal = 1 vim.g.vimtex_syntax_conceal = { accents = 1, ligatures = 1, cites = 1, fancy = 1, spacing = 1, greek = 1, math_bounds = 1, math_delimiters = 1, math_fracs = 1, math_super_sub = 0, math_symbols = 1, sections = 0, styles = 1, } vim.g.vimtex_log_ignore = { "Underfull", "Overfull", "specifier changed to", "Token not allowed in PDF string", } vim.g.vimtex_syntax_custom_cmds = { -- { -- mathmode = true, -- name = ",", -- concealchar = " ", -- }, { -- mdif mathmode = true, name = "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 = "∇", }, } vim.g.vimtex_syntax_custom_cmds_with_concealed_delims = { { mathmode = true, name = "myrange", nargs = 1, cchar_open = "[", cchar_close = "]", }, { mathmode = true, name = "myrangel", nargs = 1, cchar_open = "]", cchar_close = "]", }, { mathmode = true, name = "myranger", nargs = 1, cchar_open = "[", cchar_close = "[", }, { mathmode = true, name = "myrangelr", nargs = 1, cchar_open = "]", cchar_close = "[", }, { mathmode = true, nargs= 1, name = "myVert", cchar_open = "‖", cchar_close = "‖" }, { mathmode = true, nargs= 1, name = "myvert", cchar_open = "|", cchar_close = "|" } -- { -- mathmode= true, -- name = "myrange*", -- nargs = 2, -- cchar_open = "]", -- cchar_close = "[" -- } } end, } ```
### VimtexInfo ```yaml 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 21 hours ago

You are raising multiple issues in a single post. I strongly prefer multiple issues opened as multiple posts/threads, because it makes it much easier to answer one thing at a time. My time for maintaining VimTeX is quite restricted. So, I'm therefore scoping this particular issue and I'm kindly asking you to open new issues for a couple of your problems.

Related to #2964: Right delimiter \right) missing after conceal

Can you open a new issue for this?

starred commands returning error …

The name is assumed to be only characters. I can update the docs. If you want to match a starred command, then you need to use the cmdre key, e.g. `cmdre = "myrange*"``.

Notice, name is required, because it is used to defined the syntax group names.

im having trouble concealing \, into (double spaces)

No, that is not possible. Conceals can only replace a match with a single character.

closing char incorrect …

Can you open a new issue for this as well?

Felipe-9 commented 16 hours ago

alright thank you, will create the issues for the others.

No, that is not possible. Conceals can only replace a match with a single character.

Well, its alright, instead would it be possible for me in my config to change how vimtex highlights characters like \, into something closer to background?

Felipe-9 commented 15 hours ago

The name is assumed to be only characters. I can update the docs. If you want to match a starred command, then you need to use the cmdre key, e.g. `cmdre = "myrange*"``.

its not working i tried two different ways...

    vim.g.vimtex_syntax_custom_cmds = {
      { -- myrange*
        mathmode= true,
        name = "myrangestar",
        cmdre = "myrange*",
        -- cmdre = "myrange\\*", -- because i read on the docs that its a regex
        nargs = 1,
        cchar_open = "]",
        cchar_close = "["
      },
      { -- myrange
        mathmode = true,
        name = "myrange",
        nargs = 1,
        cchar_open = "[",
        cchar_close = "]",
      },
    }

both just conceal: \myrange*{123} -> [*{123}

probably because its detecting myrange instead of myrange*

lervag commented 11 hours ago

No, that is not possible. Conceals can only replace a match with a single character.

Well, its alright, instead would it be possible for me in my config to change how vimtex highlights characters like \, into something closer to background?

Well, yes and no. \, is matched with the texSpecialChar group, and you can customize how this looks on your end. See :help vimtex-syntax-core if you want some relevant docs on these things. I've tried to provide good references for how to customize your colorschemes and I've tried to explain the base core groups.

However, texSpecialChar includes a lot of things, and so I am not sure if it is precisely what you want here. A possibility would be to create a new group to match the spacing commands, e.g. texCmdSpacing - this would allow you to add a different highlight closer to the background for such commands. I'm not sure if it's worth the effort.

Another way here would be to use the custom syntax mechanism and define your own custom groups and highlights.

The name is assumed to be only characters. I can update the docs. If you want to match a starred command, then you need to use the cmdre key, e.g. `cmdre = "myrange*"``.

its not working i tried two different ways...

Here's a version that should work. Notice you need the custom variant with concealed delimiters for this. Also, notice the order of the definitions matter. The last defined syntax rule has priority.

vim.g.vimtex_syntax_custom_cmds_with_concealed_delims = {
  {
    name = "myrange",
    mathmode = true,
    nargs = 1,
    conceal = true,
    cchar_open = "[",
    cchar_close = "]",
  },
  {
    name = "myrangestar",
    cmdre = "myrange\\*",
    mathmode = true,
    nargs = 1,
    conceal = true,
    cchar_open = "[",
    cchar_close = "]"
  },
}