diff --git a/README.md b/README.md index 5b1b802..736a2cd 100644 --- a/README.md +++ b/README.md @@ -49,6 +49,9 @@ disabled if desired. - Support for `listings` package - Support for `minted` package - Support for `dot2tex` with nested syntax highlighting +- Support for multi-file project packages + - [import](http://ctan.uib.no/macros/latex/contrib/import/import.pdf) + - [subfiles](http://ctan.uib.no/macros/latex/contrib/import/import.pdf) (partly) See the documentation for a more thorough introduction of the plugin (e.g. `:h vimtex`). diff --git a/autoload/vimtex.vim b/autoload/vimtex.vim index 54f1c42..49927fd 100644 --- a/autoload/vimtex.vim +++ b/autoload/vimtex.vim @@ -468,7 +468,7 @@ function! s:get_main() " {{{1 endif " - " Search for main file recursively through \input and \include specifiers + " Search for main file recursively through include specifiers " let main = s:get_main_recurse(expand('%:p')) if filereadable(main) @@ -528,15 +528,20 @@ function! s:get_main_recurse(file) " {{{1 let l:candidates = split(globpath(fnameescape(l:dirs), '*.tex'), '\n') " - " Search through candidates for \include{current file} + " Search through candidates " for l:file in l:candidates " Avoid infinite recursion (checking the same file repeatedly) if l:file == a:file | continue | endif - if len(filter(readfile(l:file), 'v:val =~ ''\v\\(input|include)\{' - \ . '\s*((.*)\/)?' - \ . fnamemodify(a:file, ':t:r') . '(\.tex)?\s*''')) > 0 + let l:file_re = '\s*((.*)\/)?' . fnamemodify(a:file, ':t:r') + + let l:filter = 'v:val =~# ''\v' + let l:filter .= '\\%(input|include)\{' . l:file_re + let l:filter .= '|\\subimport\{[^\}]*\}\{' . l:file_re + let l:filter .= '''' + + if len(filter(readfile(l:file), l:filter)) > 0 return s:get_main_recurse(l:file) endif endfor diff --git a/autoload/vimtex/parser.vim b/autoload/vimtex/parser.vim index 4eadcc6..f904d68 100644 --- a/autoload/vimtex/parser.vim +++ b/autoload/vimtex/parser.vim @@ -9,7 +9,7 @@ endfunction " }}}1 function! vimtex#parser#init_script() " {{{1 - let s:input_line_tex = '\v^\s*\\%(input|include)\s*\{' + let s:input_line_tex = '\v^\s*\\%(input|include|subimport)\s*\{' let s:input_line_aux = '\\@input{' endfunction @@ -83,7 +83,15 @@ endfunction " Input line parsers " function! s:input_line_parser_tex(line, file) " {{{1 + " Handle \space commands let l:file = substitute(a:line, '\\space\s*', ' ', 'g') + + " Hande subimport commands + if a:line =~# '\\subimport' + let l:file = substitute(l:file, '}\s*{', '', 'g') + endif + + " Parse file name let l:file = matchstr(l:file, s:input_line_tex . '\zs[^\}]+\ze}') " Trim whitespaces and quotes from beginning/end of string diff --git a/doc/vimtex.txt b/doc/vimtex.txt index a5a99fc..44dc682 100644 --- a/doc/vimtex.txt +++ b/doc/vimtex.txt @@ -112,6 +112,9 @@ Feature overview~ - Support for `listings` package - Support for `minted` package - Support for `dot2tex` with nested syntax highlighting +- Support for multi-file project packages + - `import` + - `subfiles` (partly) ------------------------------------------------------------------------------ Requirements~ @@ -201,6 +204,17 @@ Subfiles~ Note that this is a special case in that it is only relevant for users who use the `subfiles` package. + *vimtex-import* +Import~ + |vimtex| also supports the `import` package, in that it should correctly + recognize the main file from sub files that are included through the + `subimport` command, e.g. > + + \subimport{chapters/}{chapter1.tex} +< + The support also extends into correctly parsing the project for table of + contents. + *b:vimtex_main* Buffer variable~ Finally, the main file may be specified through the buffer variable diff --git a/test/issue/241/main.pdf b/test/issue/241/main.pdf index 965f0eb..afa73e0 100644 Binary files a/test/issue/241/main.pdf and b/test/issue/241/main.pdf differ diff --git a/test/issue/241/main.tex b/test/issue/241/main.tex index 984a192..fa7d06e 100644 --- a/test/issue/241/main.tex +++ b/test/issue/241/main.tex @@ -4,5 +4,5 @@ \begin{document} \subimport{preamble/}{preamble.tex} \cleardoublepage -\subimport{chapter/}{chapter.tex} +\subimport{parts/}{chapter.tex} \end{document} diff --git a/test/issue/241/chapter/chapter.tex b/test/issue/241/parts/chapter.tex similarity index 100% rename from test/issue/241/chapter/chapter.tex rename to test/issue/241/parts/chapter.tex diff --git a/test/issue/241/chapter/section.tex b/test/issue/241/parts/section.tex similarity index 100% rename from test/issue/241/chapter/section.tex rename to test/issue/241/parts/section.tex