Skip to content

Commit

Permalink
feat: add conceals for (sub)*sections
Browse files Browse the repository at this point in the history
refer: #1978
  • Loading branch information
lervag committed Apr 6, 2021
1 parent be2d3b7 commit 948f04b
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 0 deletions.
1 change: 1 addition & 0 deletions autoload/vimtex/options.vim
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,7 @@ function! vimtex#options#init() abort " {{{1
\ 'math_fracs': g:vimtex_syntax_conceal_default,
\ 'math_super_sub': g:vimtex_syntax_conceal_default,
\ 'math_symbols': g:vimtex_syntax_conceal_default,
\ 'sections': g:vimtex_syntax_conceal_default,
\ 'styles': g:vimtex_syntax_conceal_default,
\})
call s:init_option('vimtex_syntax_conceal_cites', {
Expand Down
18 changes: 18 additions & 0 deletions autoload/vimtex/syntax/core.vim
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,11 @@ function! vimtex#syntax#core#init() abort " {{{1
if g:vimtex_syntax_conceal.cites
call s:match_conceal_cites_{g:vimtex_syntax_conceal_cites.type}()
endif

" Conceal section commands
if g:vimtex_syntax_conceal.sections
call s:match_conceal_sections()
endif
endif

" }}}2
Expand Down Expand Up @@ -596,6 +601,7 @@ function! vimtex#syntax#core#init_highlights() abort " {{{1
highlight def link texNewenvOpt texOpt
highlight def link texNewenvParm texParm
highlight def link texOptEqual texSymbol
highlight def link texPartConcealed texCmdPart
highlight def link texRefOpt texOpt
highlight def link texRefConcealedOpt1 texRefOpt
highlight def link texRefConcealedOpt2 texRefOpt
Expand Down Expand Up @@ -1548,3 +1554,15 @@ function! s:match_conceal_cites_icon() abort " {{{1
endfunction

" }}}1
function! s:match_conceal_sections() abort " {{{1
syntax match texCmdPart "\v\\%(sub)*section>\*?" contains=texPartConcealed nextgroup=texPartArgTitle
syntax match texPartConcealed "\\" contained conceal cchar=#
syntax match texPartConcealed "sub" contained conceal cchar=#
syntax match texPartConcealed "section" contained conceal cchar=

call vimtex#syntax#core#new_arg('texPartArgTitle', {
\ 'opts': 'contained keepend concealends'
\})
endfunction

" }}}1
3 changes: 3 additions & 0 deletions doc/vimtex.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2076,6 +2076,9 @@ OPTIONS *vimtex-options*
Replace various math symbol commands to an equivalent unicode character.
This includes quite a lot of replacements, so be warned!

sections~
Conceal `\(sub)*section` commands.

styles~
Conceal the LaTeX command "boundaries" for italized and bolded style
commands, i.e. `\emph`, `\textit`, and `\textbf`. This means that one
Expand Down
8 changes: 8 additions & 0 deletions test/test-syntax/test-conceal.tex
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,12 @@
$4 \mathit{x} = \mathbf{test}$
$\mathrm{Re} = \cdots$

\chapter{test}

\section{test}

\subsection{testing}

\subsubsection{testing}

\end{document}

0 comments on commit 948f04b

Please sign in to comment.