diff --git a/autoload/vimtex/options.vim b/autoload/vimtex/options.vim index 40f5df4906..5c74538cfb 100644 --- a/autoload/vimtex/options.vim +++ b/autoload/vimtex/options.vim @@ -278,6 +278,11 @@ function! vimtex#options#init() abort " {{{1 \ 'math_super_sub': g:vimtex_syntax_conceal_default, \ 'math_symbols': g:vimtex_syntax_conceal_default, \ 'styles': g:vimtex_syntax_conceal_default, + \ 'cites': g:vimtex_syntax_conceal_default, + \}) + call s:init_option('vimtex_syntax_conceal_cites', { + \ 'type': 'icon', + \ 'icon': '📖', \}) call s:init_option('vimtex_syntax_nested', { \ 'aliases' : { diff --git a/autoload/vimtex/syntax/core.vim b/autoload/vimtex/syntax/core.vim index deca5163bc..261aa97549 100644 --- a/autoload/vimtex/syntax/core.vim +++ b/autoload/vimtex/syntax/core.vim @@ -464,6 +464,11 @@ function! vimtex#syntax#core#init() abort " {{{1 if g:vimtex_syntax_conceal.accents call s:match_conceal_accents() endif + + " Conceal cite commands + if g:vimtex_syntax_conceal.cites + call s:match_conceal_cites_{g:vimtex_syntax_conceal_cites.type}() + endif endif " }}}2 @@ -531,6 +536,7 @@ function! vimtex#syntax#core#init_highlights() abort " {{{1 highlight def link texCmdPackage texCmd highlight def link texCmdPart texCmd highlight def link texCmdRef texCmd + highlight def link texCmdRefConcealed texCmdRef highlight def link texCmdSize texCmdType highlight def link texCmdSpaceCode texCmd highlight def link texCmdStyle texCmd @@ -590,6 +596,10 @@ function! vimtex#syntax#core#init_highlights() abort " {{{1 highlight def link texNewenvParm texParm highlight def link texOptEqual texSymbol highlight def link texRefOpt texOpt + highlight def link texRefConcealedOpt texRefOpt + highlight def link texRefConcealedArg texRefArg + highlight def link texRefConcealedPre texDelim + highlight def link texRefConcealedPost texDelim highlight def link texTabularArg texOpt highlight def link texTabularAtSep texMathDelim highlight def link texTabularChar texSymbol @@ -1505,3 +1515,30 @@ function! s:match_conceal_greek() abort " {{{1 endfunction " }}}1 +function! s:match_conceal_cites_brackets() abort " {{{1 + syntax match texCmdRefConcealed + \ "\\cite[tp]\?\>\*\?" + \ conceal skipwhite nextgroup=texRefConcealedOpt,texRefConcealedPre + call vimtex#syntax#core#new_opt('texRefConcealedOpt', { + \ 'opts': 'conceal', + \ 'next': 'texRefConcealedOpt,texRefConcealedPre', + \}) + syntax match texRefConcealedPre contained "{" + \ conceal cchar=[ + \ skipwhite nextgroup=texRefConcealedArg + syntax match texRefConcealedArg contained "[^}]*" + \ skipwhite nextgroup=texRefConcealedPost + syntax match texRefConcealedPost contained "}" + \ conceal cchar=] +endfunction + +" }}}1 +function! s:match_conceal_cites_icon() abort " {{{1 + if empty(g:vimtex_syntax_conceal_cites.icon) | return | endif + + execute 'syntax match texCmdRefConcealed' + \ '"\\cite[tp]\?\*\?\%(\[[^]]*\]\)\{,2}{[^}]*}"' + \ 'conceal cchar=' . g:vimtex_syntax_conceal_cites.icon +endfunction + +" }}}1 diff --git a/autoload/vimtex/syntax/p/biblatex.vim b/autoload/vimtex/syntax/p/biblatex.vim index 6f593c4caa..fe3211000a 100644 --- a/autoload/vimtex/syntax/p/biblatex.vim +++ b/autoload/vimtex/syntax/p/biblatex.vim @@ -33,6 +33,28 @@ function! vimtex#syntax#p#biblatex#load(cfg) abort " {{{1 syntax match texCmdRef nextgroup=texRefOpts,texRefArgs skipwhite skipnl "\\cite\%(field\|list\|name\)>" call vimtex#syntax#core#new_arg('texRefArgs', {'next': 'texRefOpts,texRefArgs', 'contains': 'texComment,@NoSpell'}) call vimtex#syntax#core#new_opt('texRefOpts', {'next': 'texRefOpt,texRefArg'}) + + if g:vimtex_syntax_conceal.cites + call s:match_conceal_cites_{g:vimtex_syntax_conceal_cites.type}() + endif +endfunction + +" }}}1 + +function! s:match_conceal_cites_brackets() abort " {{{1 + syntax match texCmdRefConcealed + \ "\v\\%(cite[tp]?>\*?|%([Tt]ext|[Ss]mart|[Aa]uto)cite>)" + \ conceal skipwhite nextgroup=texRefConcealedOpt,texRefConcealedPre +endfunction + +" }}}1 +function! s:match_conceal_cites_icon() abort " {{{1 + if empty(g:vimtex_syntax_conceal_cites.icon) | return | endif + + execute 'syntax match texCmdRefConcealed' + \ '"\v\\%(cite[tp]?\*?|%([Tt]ext|[Ss]mart|[Aa]uto)cite)' + \ . '%(\[[^]]*\]){,2}\{[^}]*\}"' + \ 'conceal cchar=' . g:vimtex_syntax_conceal_cites.icon endfunction " }}}1 diff --git a/doc/vimtex.txt b/doc/vimtex.txt index af91ec944e..3e5894b516 100644 --- a/doc/vimtex.txt +++ b/doc/vimtex.txt @@ -2025,6 +2025,13 @@ OPTIONS *vimtex-options* Default value: 1. +*g:vimtex_syntax_conceal_default* + Specify the default flag for the conceal feature. This is used e.g. in + |vimtex_syntax_conceal| and for package specific options in + |vimtex_syntax_packages|. + + Default value: 1 + *g:vimtex_syntax_conceal* A dictionary for specifying which core conceal features to activate. This mostly implies concealing particular elements with a replacement unicode @@ -2070,18 +2077,39 @@ OPTIONS *vimtex-options* `\emph{text here}` --> `text here` + cites~ + Conceal LaTeX cite commands such as `\citet[...]{ref00}`. The conceal + style is specified by |g:vimtex_syntax_conceal_cites|. + Note: Not all fonts have all the characters used for concealing! So, for this feature to work properly, you need to install and use a font that includes the unicode characters. Default value: All keys set to |g:vimtex_syntax_conceal_default|. -*g:vimtex_syntax_conceal_default* - Specify the default flag for the conceal feature. This is used e.g. in - |vimtex_syntax_conceal| and for package specific options in - |vimtex_syntax_packages|. +*g:vimtex_syntax_conceal_cites* + A simple dictionary to control how citation conceal should work. It has two + keys: - Default value: 1 + type~ + Specify the type of concealment. There are two options, and the + difference is best explained by example: + + Value LaTeX Concealed + ----- ----- --------- + 'icon' `\cite{x}` `📖` + 'brackets' `\cite{x}` `[x]` + + icon~ + Specify an icon for `icon` conceal. This must be a single (possibly + multibyte) character. + + Default value: > + + let g:vimtex_syntax_conceal_cites = { + \ 'type': 'icon', + \ 'icon': '📖', + \} *g:vimtex_syntax_nested* A dictionary for configuring nested syntaxes. The following keys are diff --git a/test/test-syntax/test-biblatex.tex b/test/test-syntax/test-biblatex.tex index 2f99bf3297..852a8f6e3b 100644 --- a/test/test-syntax/test-biblatex.tex +++ b/test/test-syntax/test-biblatex.tex @@ -23,4 +23,7 @@ \citeyearpar{} \bibentry{} +% Conceal example +Bla bla bla, see Ref.~\cite{John2012Measurement,Anne2017Bifurcation}. For more info, see also \cite{Bob2025Mystery}. + \end{document} diff --git a/test/test-syntax/test-biblatex.vim b/test/test-syntax/test-biblatex.vim new file mode 100644 index 0000000000..b1761fd1bb --- /dev/null +++ b/test/test-syntax/test-biblatex.vim @@ -0,0 +1,16 @@ +source common.vim + +highlight Conceal ctermfg=4 ctermbg=7 guibg=NONE guifg=blue + +let g:vimtex_syntax_conceal_cites = { + \ 'type': 'brackets', + \} + +silent edit test-biblatex.tex + +split +silent wincmd w +set conceallevel=2 + +if empty($INMAKE) | finish | endif +quit!