diff --git a/autoload/vimtex/compiler.vim b/autoload/vimtex/compiler.vim index fc576c5380..789184338c 100644 --- a/autoload/vimtex/compiler.vim +++ b/autoload/vimtex/compiler.vim @@ -426,7 +426,7 @@ endfunction " {{{1 Initialize module -if !g:vimtex_compiler_enabled | finish | endif +if !get(g:, 'vimtex_compiler_enabled') | finish | endif augroup vimtex_compiler autocmd! diff --git a/autoload/vimtex/options.vim b/autoload/vimtex/options.vim index f670cde374..5c01c1683f 100644 --- a/autoload/vimtex/options.vim +++ b/autoload/vimtex/options.vim @@ -273,24 +273,25 @@ function! vimtex#options#init() abort " {{{1 call s:init_option('vimtex_subfile_start_local', 0) call s:init_option('vimtex_syntax_enabled', 1) - call s:init_option('vimtex_syntax_conceal_default', 1) call s:init_option('vimtex_syntax_conceal', { - \ 'accents': g:vimtex_syntax_conceal_default, - \ 'cites': g:vimtex_syntax_conceal_default, - \ 'fancy': g:vimtex_syntax_conceal_default, - \ 'greek': g:vimtex_syntax_conceal_default, - \ 'math_bounds': g:vimtex_syntax_conceal_default, - \ 'math_delimiters': g:vimtex_syntax_conceal_default, - \ 'math_fracs': g:vimtex_syntax_conceal_default, - \ 'math_super_sub': g:vimtex_syntax_conceal_default, - \ 'math_symbols': g:vimtex_syntax_conceal_default, - \ 'styles': g:vimtex_syntax_conceal_default, + \ 'accents': 1, + \ 'cites': 1, + \ 'fancy': 1, + \ 'greek': 1, + \ 'math_bounds': 1, + \ 'math_delimiters': 1, + \ 'math_fracs': 1, + \ 'math_super_sub': 1, + \ 'math_symbols': 1, + \ 'sections': 0, + \ 'styles': 1, \}) call s:init_option('vimtex_syntax_conceal_cites', { \ 'type': 'brackets', \ 'icon': '📖', \ 'verbose': v:true, \}) + call s:init_option('vimtex_syntax_conceal_disable', 0) call s:init_option('vimtex_syntax_custom_cmds', []) call s:init_option('vimtex_syntax_nested', { \ 'aliases' : { @@ -323,10 +324,17 @@ function! vimtex#options#init() abort " {{{1 call s:init_option('vimtex_syntax_nospell_comments', 0) call s:init_option('vimtex_syntax_packages', { \ 'amsmath': {'load': 2}, - \ 'babel': {'conceal': g:vimtex_syntax_conceal_default}, - \ 'hyperref': {'conceal': g:vimtex_syntax_conceal_default}, + \ 'babel': {'conceal': 1}, + \ 'hyperref': {'conceal': 1}, \}) + " Disable conceals if chosen + if g:vimtex_syntax_conceal_disable + call map(g:vimtex_syntax_conceal, {k, v -> 0}) + let g:vimtex_syntax_packages.babel.conceal = 0 + let g:vimtex_syntax_packages.hyperref.conceal = 0 + endif + call s:init_option('vimtex_texcount_custom_arg', '') call s:init_option('vimtex_text_obj_enabled', 1) @@ -464,6 +472,7 @@ function! s:check_for_deprecated_options() abort " {{{1 \ 'g:vimtex_quickfix_latexlog', \ 'g:vimtex_quickfix_warnings', \ 'g:vimtex_syntax_autoload_packages', + \ 'g:vimtex_syntax_conceal_default', \ 'g:vimtex_textidote_jar', \ 'g:vimtex_toc_fold', \ 'g:vimtex_toc_fold_level_start', diff --git a/autoload/vimtex/syntax/core.vim b/autoload/vimtex/syntax/core.vim index 681abf21a4..3e35260908 100644 --- a/autoload/vimtex/syntax/core.vim +++ b/autoload/vimtex/syntax/core.vim @@ -614,6 +614,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 @@ -785,6 +790,8 @@ function! vimtex#syntax#core#init_highlights() abort " {{{1 highlight def link texParboxOptHeight texError highlight def link texParboxOptIPos texError highlight def link texParboxOptPos texError + highlight def link texPartConcealed texCmdPart + highlight def link texPartConcArgTitle texPartArgTitle highlight def link texRefOpt texOpt highlight def link texRefConcealedOpt1 texRefOpt highlight def link texRefConcealedOpt2 texRefOpt @@ -1927,6 +1934,18 @@ function! s:match_conceal_cites_icon() abort " {{{1 \ 'conceal cchar=' . g:vimtex_syntax_conceal_cites.icon endfunction +" }}}1 +function! s:match_conceal_sections() abort " {{{1 + syntax match texCmdPart "\v\\%(sub)*section>\*?" contains=texPartConcealed nextgroup=texPartConcArgTitle + 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('texPartConcArgTitle', { + \ 'opts': 'contained keepend concealends' + \}) +endfunction + " }}}1 function! s:gather_newtheorems() abort " {{{1 diff --git a/doc/vimtex.txt b/doc/vimtex.txt index 095e7aa4b8..18ed652f9c 100644 --- a/doc/vimtex.txt +++ b/doc/vimtex.txt @@ -2133,13 +2133,6 @@ 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|. For more info, see |vimtex-syntax-conceal|. - - 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 @@ -2183,6 +2176,13 @@ 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. The titles are replaced with Markdown + style ATX headers, e.g.: + + `\section{Test}` --> `# Test` + `\subsection{Test}` --> `## Test` + styles~ Conceal the LaTeX command "boundaries" for italicized and bolded style commands, i.e. `\emph`, `\textit`, and `\textbf`. This means that one @@ -2190,7 +2190,28 @@ OPTIONS *vimtex-options* `\emph{text here}` --> `text here` - Default value: All keys set to |g:vimtex_syntax_conceal_default|. + Default value: > + + let g:vimtex_syntax_conceal = { + \ 'accents': 1, + \ 'cites': 1, + \ 'fancy': 1, + \ 'greek': 1, + \ 'math_bounds': 1, + \ 'math_delimiters': 1, + \ 'math_fracs': 1, + \ 'math_super_sub': 1, + \ 'math_symbols': 1, + \ 'sections': 0, + \ 'styles': 1, + \} + +*g:vimtex_syntax_conceal_disable* + The option |g:vimtex_syntax_conceal| allows to selectively disable conceal + features. For convenience, this option allows to disable all conceal + features in one go. For more info, see |vimtex-syntax-conceal|. + + Default value: 0 *g:vimtex_syntax_conceal_cites* A simple dictionary to control how citation conceal should work. It has @@ -2351,8 +2372,7 @@ OPTIONS *vimtex-options* array~ asymptote~ babel~ - `conceal` whether to enable conceal - Default: |g:vimtex_syntax_conceal_default| + `conceal` whether to enable conceal; enabled by default beamer~ biblatex~ booktabs~ @@ -4076,7 +4096,8 @@ are several major differences that users may want to be aware of: Associated settings: * |g:vimtex_syntax_enabled| * |g:vimtex_syntax_conceal| -* |g:vimtex_syntax_conceal_default| +* |g:vimtex_syntax_conceal_cites| +* |g:vimtex_syntax_conceal_disable| * |g:vimtex_syntax_nested| * |g:vimtex_syntax_nospell_commands| * |g:vimtex_syntax_packages| @@ -4088,9 +4109,9 @@ VimTeX utilizes the |syn-conceal| feature of Vim to allow displaying commands like `\alpha` as `α`. That is, various elements/commands can be concealed or substituted with a unicode symbol. -This feature is enabled by default. It can be fully disabled with -|g:vimtex_syntax_conceal_default| or specific types of concealments can be -disabled with |g:vimtex_syntax_conceal|. +This feature is mostly enabled by default. Various types of concealments can +be enabled/disabled with |g:vimtex_syntax_conceal|. The entire feature can be +fully disabled with |g:vimtex_syntax_conceal_disable|. For conceals to work properly, one must set the option 'conceallevel' to 2. It is also good to be aware of the 'concealcursor' option. @@ -5781,6 +5802,10 @@ The following changelog only logs particularly important changes, such as changes that break backwards compatibility. See the git log for the detailed changelog. +2021-10-09: Better options for syntax conceal~ +Deprecated *g:vimtex_syntax_conceal_default* in favour of +|g:vimtex_syntax_conceal_disable|. + 2020-11-16: More flexible package syntax options~ Deprecate *g:vimtex_syntax_autoload_packages* in favor of |g:vimtex_syntax_packages|, which allows more fine grained control over each diff --git a/test/test-syntax/test-conceal.tex b/test/test-syntax/test-conceal.tex index ef9628042a..758226720e 100644 --- a/test/test-syntax/test-conceal.tex +++ b/test/test-syntax/test-conceal.tex @@ -63,4 +63,12 @@ $$\lVert \mathrm{w} \rVert_2^2$$ +\chapter{test} + +\section{test} + +\subsection{testing} + +\subsubsection{testing} + \end{document}