lervag / vimtex

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

Question: Is it possible to disable the conceal only for `\\`? #2940

Closed camoz closed 5 months ago

camoz commented 5 months ago

Description

Hey :)

at first thank you very much for this super helpful plugin!

I tried to disable the \\ conceals using (in lua/neovim)

vim.g.vimtex_syntax_custom_cmds = {
  {name = '\\', mathmode = 0, conceal = 0},
}

... but it didn't work, I also tried in vimscript. Disabling other conceals like alpha in mathmode works fine.

Could it be that it's not possible at all, maybe because \\ is perhaps not a real command?

Do you use a latexmkrc file?

No

VimtexInfo

System info:
  OS: Linux 6.3.5-arch1-1
  Vim version: NVIM v0.9.5
  Has clientserver: true
  Servername: /run/user/1000/nvim.24720.0

VimTeX project: main
  base: main.tex
  root: /home/merlin/downloads/testlatex
  tex: /home/merlin/downloads/testlatex/main.tex
  main parser: current file verified
  document class: scrletter
  packages: amsmath babel csquotes etoolbox footmisc keyval lmodern scrbase scrkbase scrlayer scrlayer-scrpage scrletter scrlfile scrlfile-hook scrlogo tocbasic typearea
  compiler: latexmk
    engine: -pdf
    options:
      -verbose
      -file-line-error
      -synctex=1
      -interaction=nonstopmode
    out_dir: build
    callback: 1
    continuous: 1
    executable: latexmk
  viewer: Zathura
    xwin id: 0
  qf method: LaTeX logfile
lervag commented 5 months ago

at first thank you very much for this super helpful plugin!

Glad you like it!

There is not currently any good way to disable a single conceal command. But you can disable all conceals with vim.g.vimtex_syntax_conceal_disable = true. Or you can disable some of them with the help g:vimtex_syntax_conceal option. E.g., to disable the one that adds conceal for \\, use:

vim.g.vimtex_syntax_conceal = { fancy = false }
camoz commented 5 months ago

Hmm, but e.g. disabling conceal for \colon, which also belongs to "fancy", works fine:

vim.g.vimtex_syntax_custom_cmds = {
  {name = 'colon', mathmode = 0, conceal = 0},
}

I see that \\ is defined here: https://github.com/lervag/vimtex/blob/master/autoload/vimtex/syntax/core.vim#L2192 It seems to belong to the texTabularChar group, whereas \colon belongs to the texCmd group. Could it be that vimtex's g:vimtex_syntax_custom_cmds only works for the texCmd group?

Btw, I have now created ~/.config/nvim/after/syntax/tex.lua with:

vim.cmd[[syntax match texTabularChar '\\\\']]

It's probably a hack but it works for now. (Without specifying conceal and cchar=, it seems to disable the conceal.)

camoz commented 5 months ago

Oh, btw, maybe I should have included that "didn't work" in my first post means there is an error message printed...

With let g:vimtex_syntax_custom_cmds = [ {'name': '\\', 'mathmode': 0, 'conceal': 0} ] I get:

Error detected while processing BufReadPost Autocommands for "*":
Error executing lua callback: /usr/share/nvim/runtime/filetype.lua:24: Error executing lua: /usr/share/nvim/runtime/filetype.lua:25: BufReadPost Autocommands for "*"..FileType Autocommands for
 "*"..Syntax Autocommands for "*"..function <SNR>12_SynSet[25]..script /home/merlin/.local/share/nvim/site/pack/main/opt/vimtex/syntax/tex.vim[34]..function vimtex#syntax#core#init_post[12]..v
imtex#syntax#packages#init[20]..vimtex#syntax#core#init_custom[4]..vimtex#syntax#core#new_cmd[51]..vimtex#syntax#core#new_opt, line 7: Vim(syntax):E409: Unknown group name: texC\\Arg skipwhite
 skipnl
stack traceback:
        [C]: in function 'nvim_cmd'
        /usr/share/nvim/runtime/filetype.lua:25: in function </usr/share/nvim/runtime/filetype.lua:24>
        [C]: in function 'nvim_buf_call'
        /usr/share/nvim/runtime/filetype.lua:24: in function </usr/share/nvim/runtime/filetype.lua:10>
stack traceback:
        [C]: in function 'nvim_buf_call'
        /usr/share/nvim/runtime/filetype.lua:24: in function </usr/share/nvim/runtime/filetype.lua:10>

With let g:vimtex_syntax_custom_cmds = [ {'name': '\\', 'mathmode': 0, 'concealchar': 'x'} ] I get slightly different:

Error detected while processing BufReadPost Autocommands for "*"..FileType Autocommands for "*"..Syntax Autocommands for "*"..function <SNR>12_SynSet[25]..script /home/merlin/.local/share/nvim
/site/pack/main/opt/vimtex/syntax/tex.vim[34]..function vimtex#syntax#core#init_post[12]..vimtex#syntax#packages#init[20]..vimtex#syntax#core#init_custom[4]..vimtex#syntax#core#new_cmd:
line  100:
Error detected while processing BufReadPost Autocommands for "*":
Error executing lua callback: /usr/share/nvim/runtime/filetype.lua:24: Error executing lua: /usr/share/nvim/runtime/filetype.lua:25: BufReadPost Autocommands for "*"..FileType Autocommands for
 "*"..Syntax Autocommands for "*"..function <SNR>12_SynSet[25]..script /home/merlin/.local/share/nvim/site/pack/main/opt/vimtex/syntax/tex.vim[34]..function vimtex#syntax#core#init_post[12]..v
imtex#syntax#packages#init[20]..vimtex#syntax#core#init_custom[4]..vimtex#syntax#core#new_cmd, line 100: Vim(syntax):E5248: Invalid character in group name
stack traceback:
        [C]: in function 'nvim_cmd'
        /usr/share/nvim/runtime/filetype.lua:25: in function </usr/share/nvim/runtime/filetype.lua:24>
        [C]: in function 'nvim_buf_call'
        /usr/share/nvim/runtime/filetype.lua:24: in function </usr/share/nvim/runtime/filetype.lua:10>
stack traceback:
        [C]: in function 'nvim_buf_call'
        /usr/share/nvim/runtime/filetype.lua:24: in function </usr/share/nvim/runtime/filetype.lua:10>
lervag commented 5 months ago

Hmm, but e.g. disabling conceal for \colon, which also belongs to "fancy", works fine:

vim.g.vimtex_syntax_custom_cmds = {
  {name = 'colon', mathmode = 0, conceal = 0},
}

Well, ok, yes. If you make a new syntax rule it should override the existing ones. And yes, that is a method to disable the conceal for the specific command. Good point.

I see that \\ is defined here: https://github.com/lervag/vimtex/blob/master/autoload/vimtex/syntax/core.vim#L2192 It seems to belong to the texTabularChar group, whereas \colon belongs to the texCmd group. Could it be that vimtex's g:vimtex_syntax_custom_cmds only works for the texCmd group?

No. But the vimtex_syntax_custom_cmds option is intended to be used with the classical \<word> type command, so the regex is probably ending up being wrong.

Btw, I have now created ~/.config/nvim/after/syntax/tex.lua with:

vim.cmd[[syntax match texTabularChar '\\\\']]

I actually think that this looks like a very good solution. Notice, if you are only adding a couple of syntax rules, it might be clearer to just use a tex.vim file with vimscript instead of using Lua with vim.cmd.

Oh, btw, maybe I should have included that "didn't work" in my first post means there is an error message printed...

Yes; the error message is not unexpected. As mentioned above, the problem here is that I've build this option under the assumption that people insert a "word" as the name. I think your "hack" is actually a much better and simpler way to achieve what you want. It's so good I would almost be tempted to not call it a hack. :)

camoz commented 4 months ago

A bit late, but wanted to say thanks for your verbose answer! :)

lervag commented 4 months ago

Glad to hear you find it useful! <3

firubat commented 4 months ago

Wanted to say thanks for this issue - I wanted to disable conceal for displayed math, but keep the conceal for inline math, so I added a syntax file with

syntax region texMathZoneLD matchgroup=texMathDelimZoneLD start='\\\[' end='\\]' contains=@texClusterMath

and it did the trick.