Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions autoload/vimtex/options.vim
Original file line number Diff line number Diff line change
Expand Up @@ -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' : {
Expand Down
37 changes: 37 additions & 0 deletions autoload/vimtex/syntax/core.vim
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
22 changes: 22 additions & 0 deletions autoload/vimtex/syntax/p/biblatex.vim
Original file line number Diff line number Diff line change
Expand Up @@ -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
38 changes: 33 additions & 5 deletions doc/vimtex.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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]`
Comment on lines +2100 to +2101
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe it would be worth our while to replace x with xyz and show that the "brackets" concealment still shows the full key that's in there (as opposed to replacing \cite{arbitrary_long_identifier} with just [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
Expand Down
3 changes: 3 additions & 0 deletions test/test-syntax/test-biblatex.tex
Original file line number Diff line number Diff line change
Expand Up @@ -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}
16 changes: 16 additions & 0 deletions test/test-syntax/test-biblatex.vim
Original file line number Diff line number Diff line change
@@ -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!