Closed userrand closed 1 year ago
The following command works in a vimrc file without vimtex
syntax match TexMathSymbol '\%(\\frac\)\@<={\%([^}]\{-}}{[^}]\{-}}\)\@=' conceal cchar=❬
But I cannot get it to work with vimtex in neovim. I tried the following, (According to the documentation, it seems the regex is expected to be in very magic mode)
let g:tex_conceal='abdmg' set concealcursor=nvic set conceallevel=2 let g:vimtex_syntax_custom_cmds = [ \ {'name': 'frac', 'cmdre': '(\\frac)@<={([^}]{-}}{[^}]{-}})@=' , 'mathmode': 1, 'concealchar': '❬'}, \]
A couple of initial comments:
g:tex_conceal
is not relevant to VimTeX and you can safely remove itset concealcursor
and set conceallevel
are window local options. If you set these in your vimrc, they will specify an initial value, but the values may be overridden by other plugins. In general, you should be aware of this and know the difference between global options, buffer options and window local options (see :help local-options
).The g:vimtex_syntax_custom_cmds
is probably too specific for your need, because it is meant to match the command. You are using an advanced regex to ignore the initial \frac
part. Notice that cmdre
does not include the initial \
and that it will only match on the command name itself - you don't match on the following argument groups.
It seems to me that you want a very specific customization of your \frac
s, and I would advice to instead use an after/syntax/tex.vim
file to specify your rules on top of VimTeX. Your existing rules will work, but you should make some adjustments:
syntax match texMathSymbol contained '\%(\\frac\)\@<={\%([^}]\{-}}{[^}]\{-}}\)\@=' conceal cchar=❬
I.e.: use texMathSymbol
as the group name (with lower t) and add contained
to avoid having it match outside mathmode.
Thank you very much for your general help given in the comments and the help with syntax. I am using neovim (specifically Astronvim), what would be the equivalent of after/syntax/tex.vim
in that case ?
Sorry, I don't know. I don't use AstroNvim. But for neovim, after/syntax/tex.vim
works perfectly fine. (i.e. ~/.config/nvim/after/syntax/tex.vim
)
I tried your suggestion to use
syntax match texMathSymbol contained '\%(\\frac\)\@<={\%([^}]\{-}}{[^}]\{-}}\)\@=' conceal cchar=❬
and add it to ~/.config/nvim/after/syntax/tex.vim
but that did not work.
Is it possible to use g:vimtex_syntax_custom_cmds
for that? In the worst-case scenario where i decide to turn off vim conceal and reimplement all of the conceals relevant to my use case, how can i deactivate the conceals of vimtex such that it no longer disables custom conceals?
No, you can't use g:vimtex_syntax_custom_cmds
for this. You can deactivate conceals with let g:vimtex_syntax_conceal_disable = 1
.
Seems like I made a mistake somewhere when I tried your suggestion and my issue was mainly that I did not place the conceal code in ~/.config/nvim/after/syntax/tex.vim
. The code works in the way it was originally written in that location.
My apologies the issue might not have been related to vimtex. Thank you for your time and help.
Seems like I made a mistake somewhere when I tried your suggestion and my issue was mainly that I did not place the conceal code in
~/.config/nvim/after/syntax/tex.vim
.
We all make mistakes :)
The code works in the way it was originally written in that location.
My apologies the issue might not have been related to vimtex. Thank you for your time and help.
No problem, glad to hear it works as expected now!
Description
The following command works in a vimrc file without vimtex
But I cannot get it to work with vimtex in neovim. I tried the following, (According to the documentation, it seems the regex is expected to be in very magic mode)
Steps to reproduce
No response
Expected behavior
No response
Actual behavior
No response
Do you use a latexmkrc file?
No
VimtexInfo