Skip to content

Commit

Permalink
feat(syntax): conceal for \cite
Browse files Browse the repository at this point in the history
refer: #1965
  • Loading branch information
lervag committed Mar 24, 2021
1 parent 46fd035 commit bac5ea6
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 0 deletions.
2 changes: 2 additions & 0 deletions autoload/vimtex/options.vim
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,9 @@ 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,
\ 'citations': g:vimtex_syntax_conceal_default,
\})
call s:init_option('vimtex_syntax_conceal_citesign', '📖')
call s:init_option('vimtex_syntax_nested', {
\ 'aliases' : {
\ 'C' : 'c',
Expand Down
15 changes: 15 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.citations
call s:match_conceal_citations()
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 texRefArg
highlight def link texCmdSize texCmdType
highlight def link texCmdSpaceCode texCmd
highlight def link texCmdStyle texCmd
Expand Down Expand Up @@ -1505,3 +1511,12 @@ function! s:match_conceal_greek() abort " {{{1
endfunction

" }}}1
function! s:match_conceal_citations() abort " {{{1
if empty(g:vimtex_syntax_conceal_citesign) | return | endif

execute 'syntax match texCmdRefConcealed'
\ '"\\cite[tp]\?\*\?\%(\[[^]]*\]\)\{,2}{[^}]*}"'
\ 'conceal cchar=' . g:vimtex_syntax_conceal_citesign
endfunction

" }}}1
8 changes: 8 additions & 0 deletions autoload/vimtex/syntax/p/biblatex.vim
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,14 @@ 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.citations
\ && !empty(g:vimtex_syntax_conceal_citesign)
execute 'syntax match texCmdRefConcealed'
\ '"\v\\%(cite[tp]?\*?|%([Tt]ext|[Ss]mart|[Aa]uto)cite)'
\ . '%(\[[^]]*\]){,2}\{[^}]*\}"'
\ 'conceal cchar=' . g:vimtex_syntax_conceal_citesign
endif
endfunction

" }}}1
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}

0 comments on commit bac5ea6

Please sign in to comment.