diff --git a/autoload/vimtex.vim b/autoload/vimtex.vim index 03cc8ad..be1c9ab 100644 --- a/autoload/vimtex.vim +++ b/autoload/vimtex.vim @@ -485,8 +485,17 @@ endfunction " }}}1 function! s:init_local_options() " {{{1 - let b:vimtex.sources = [] + let b:vimtex.packages = {} + for l:line in vimtex#parser#tex(b:vimtex.tex, { + \ 'detailed' : 0, + \ 're_stop' : '\\begin\s*{document}', + \}) + if l:line =~# '\\usepackage.*{tikz}' + let b:vimtex.packages.tikz = 1 + endif + endfor + let b:vimtex.sources = [] for [l:file, l:lnum, l:line] in vimtex#parser#tex(b:vimtex.tex) let l:cand = substitute(l:file, '\M' . b:vimtex.root, '', '') if l:cand[0] ==# '/' | let l:cand = l:cand[1:] | endif diff --git a/indent/tex.vim b/indent/tex.vim index 36ad3fe..2c4188a 100644 --- a/indent/tex.vim +++ b/indent/tex.vim @@ -138,6 +138,8 @@ let s:re_delims = vimtex#delim#get_delim_regexes() " }}}1 function! s:indent_tikz(lnum, prev) " {{{1 + if !has_key(b:vimtex.packages, 'tikz') | return 0 | endif + let l:env_lnum = vimtex#env#is_inside('tikzpicture') if l:env_lnum > 0 && l:env_lnum < a:lnum let l:prev_starts = a:prev =~# s:tikz_commands diff --git a/test/vader/indentation.vader b/test/vader/indentation.vader index 257a085..004fa97 100644 --- a/test/vader/indentation.vader +++ b/test/vader/indentation.vader @@ -141,8 +141,9 @@ Given tex (Indent: tikz): \end{axis} \end{tikzpicture} -Do (Indent): - gg=G +Execute (Indent): + let b:vimtex.packages.tikz = 1 + normal gg=G Expect tex (Verify): \tikz \fill[green] rectangle (0.5,0.5); Something