diff --git a/autoload/vimtex/compiler.vim b/autoload/vimtex/compiler.vim index 18927ef763..a0bbbb3e6b 100644 --- a/autoload/vimtex/compiler.vim +++ b/autoload/vimtex/compiler.vim @@ -142,7 +142,7 @@ function! vimtex#compiler#compile_selected(type) abort range " {{{1 " Create and initialize temporary compiler let l:compiler = s:init_compiler({ \ 'state': l:file, - \ 'build_dir': '', + \ 'out_dir': '', \ 'continuous': 0, \ 'callback': 0, \}) @@ -266,7 +266,7 @@ function! vimtex#compiler#clean(full) abort " {{{1 call b:vimtex.compiler.clean(a:full) sleep 100m - call b:vimtex.compiler.remove_build_dir() + call b:vimtex.compiler.remove_dirs() call vimtex#log#info('Compiler clean finished' . (a:full ? ' (full)' : '')) diff --git a/autoload/vimtex/compiler/_template.vim b/autoload/vimtex/compiler/_template.vim index 3bf45d86fb..2f5af6293c 100644 --- a/autoload/vimtex/compiler/_template.vim +++ b/autoload/vimtex/compiler/_template.vim @@ -14,7 +14,7 @@ endfunction let s:compiler = { \ 'name': '__template__', \ 'enabled': v:true, - \ 'build_dir': '', + \ 'out_dir': '', \ 'continuous': 0, \ 'hooks': [], \ 'output': tempname(), @@ -30,9 +30,21 @@ function! s:compiler.new(options) abort dict " {{{1 call l:compiler.__check_requirements() - call s:build_dir_materialize(l:compiler) + call vimtex#util#materialize_property(l:compiler, 'out_dir') call l:compiler.__init() - call s:build_dir_respect_envvar(l:compiler) + + " $VIMTEX_OUTPUT_DIRECTORY overrides configured compiler.out_dir + if !empty($VIMTEX_OUTPUT_DIRECTORY) + if !empty(l:compiler.out_dir) + \ && (l:compiler.out_dir !=# $VIMTEX_OUTPUT_DIRECTORY) + call vimtex#log#warning( + \ 'Setting VIMTEX_OUTPUT_DIRECTORY overrides out_dir!', + \ 'Changed out_dir from: ' . l:compiler.out_dir, + \ 'Changed out_dir to: ' . $VIMTEX_OUTPUT_DIRECTORY) + endif + + let l:compiler.out_dir = $VIMTEX_OUTPUT_DIRECTORY + endif " Remove init methods unlet l:compiler.new @@ -74,8 +86,8 @@ function! s:compiler.__pprint() abort dict " {{{1 call add(l:list, ['options', self.options]) endif - if !empty(self.build_dir) - call add(l:list, ['build_dir', self.build_dir]) + if !empty(self.out_dir) + call add(l:list, ['out_dir', self.out_dir]) endif if has_key(self, '__pprint_append') @@ -98,16 +110,75 @@ endfunction " }}}1 +function! s:compiler._create_build_dir(path) abort dict " {{{1 + " Create build dir "path" if it does not exist + " Note: This may need to create a hierarchical structure! + if empty(a:path) | return | endif + + if has_key(self.state, 'get_sources') + let l:dirs = self.state.get_sources() + call filter(map( + \ l:dirs, "fnamemodify(v:val, ':h')"), + \ {_, x -> x !=# '.'}) + call filter(l:dirs, {_, x -> stridx(x, '../') != 0}) + else + let l:dirs = glob(self.state.root . '/**/*.tex', v:false, v:true) + call map(l:dirs, "fnamemodify(v:val, ':h')") + call map(l:dirs, 'strpart(v:val, strlen(self.state.root) + 1)') + endif + call uniq(sort(filter(l:dirs, '!empty(v:val)'))) + + call map(l:dirs, {_, x -> + \ (vimtex#paths#is_abs(a:path) ? '' : self.state.root . '/') + \ . a:path . '/' . x}) + call filter(l:dirs, '!isdirectory(v:val)') + if empty(l:dirs) | return | endif + + " Create the non-existing directories + call vimtex#log#warning(["Creating directorie(s):"] + \ + map(copy(l:dirs), {_, x -> '* ' . x})) + + for l:dir in l:dirs + call mkdir(l:dir, 'p') + endfor +endfunction + +" }}}1 +function! s:compiler._remove_dir(path) abort dict " {{{1 + if empty(a:path) | return | endif + + let l:out_dir = vimtex#paths#is_abs(a:path) + \ ? a:path + \ : self.state.root . '/' . a:path + if !isdirectory(l:out_dir) | return | endif + + let l:tree = glob(l:out_dir . '/**/*', 0, 1) + let l:files = filter(copy(l:tree), 'filereadable(v:val)') + + if empty(l:files) + for l:dir in sort(l:tree) + [l:out_dir] + call delete(l:dir, 'd') + endfor + endif +endfunction + +" }}}1 + +function! s:compiler.create_dirs() abort dict " {{{1 + call self._create_build_dir(self.out_dir) +endfunction + +" }}}1 +function! s:compiler.remove_dirs() abort dict " {{{1 + call self._remove_dir(self.out_dir) +endfunction + +" }}}1 + function! s:compiler.get_file(ext) abort dict " {{{1 - " Check for various output directories - " * Environment variable VIMTEX_OUTPUT_DIRECTORY. Note that this overrides - " any VimTeX settings like g:vimtex_compiler_latexmk.build_dir! - " * Compiler settings, such as g:vimtex_compiler_latexmk.build_dir, which is - " available as b:vimtex.compiler.build_dir. - " * Fallback to the main root directory for l:root in [ \ $VIMTEX_OUTPUT_DIRECTORY, - \ self.build_dir, + \ self.out_dir, \ self.state.root \] if empty(l:root) | continue | endif @@ -143,7 +214,7 @@ endfunction function! s:compiler.start(...) abort dict " {{{1 if self.is_running() | return | endif - call self.create_build_dir() + call self.create_dirs() " Initialize output file call writefile([], self.output, 'a') @@ -211,62 +282,6 @@ endfunction " }}}1 -function! s:compiler.create_build_dir() abort dict " {{{1 - " Create build dir if it does not exist - " Note: This may need to create a hierarchical structure! - if empty(self.build_dir) | return | endif - - if has_key(self.state, 'get_sources') - let l:dirs = self.state.get_sources() - call filter(map( - \ l:dirs, "fnamemodify(v:val, ':h')"), - \ {_, x -> x !=# '.'}) - call filter(l:dirs, {_, x -> stridx(x, '../') != 0}) - else - let l:dirs = glob(self.state.root . '/**/*.tex', v:false, v:true) - call map(l:dirs, "fnamemodify(v:val, ':h')") - call map(l:dirs, 'strpart(v:val, strlen(self.state.root) + 1)') - endif - call uniq(sort(filter(l:dirs, '!empty(v:val)'))) - - call map(l:dirs, {_, x -> - \ (vimtex#paths#is_abs(self.build_dir) ? '' : self.state.root . '/') - \ . self.build_dir . '/' . x}) - call filter(l:dirs, '!isdirectory(v:val)') - if empty(l:dirs) | return | endif - - " Create the non-existing directories - call vimtex#log#warning(["Creating build_dir directorie(s):"] - \ + map(copy(l:dirs), {_, x -> '* ' . x})) - - for l:dir in l:dirs - call mkdir(l:dir, 'p') - endfor -endfunction - -" }}}1 -function! s:compiler.remove_build_dir() abort dict " {{{1 - " Remove auxilliary output directories (only if they are empty) - if empty(self.build_dir) | return | endif - - if vimtex#paths#is_abs(self.build_dir) - let l:build_dir = self.build_dir - else - let l:build_dir = self.state.root . '/' . self.build_dir - endif - - let l:tree = glob(l:build_dir . '/**/*', 0, 1) - let l:files = filter(copy(l:tree), 'filereadable(v:val)') - - if empty(l:files) - for l:dir in sort(l:tree) + [l:build_dir] - call delete(l:dir, 'd') - endfor - endif -endfunction - -" }}}1 - let s:compiler_jobs = {} function! s:compiler_jobs.exec(cmd) abort dict " {{{1 @@ -461,38 +476,6 @@ endfunction " }}}1 -function! s:build_dir_materialize(compiler) abort " {{{1 - if type(a:compiler.build_dir) != v:t_func | return | endif - - try - let a:compiler.build_dir = a:compiler.build_dir() - catch - call vimtex#log#error( - \ 'Could not expand build_dir function!', - \ v:exception) - let a:compiler.build_dir = '' - endtry -endfunction - -" }}}1 -function! s:build_dir_respect_envvar(compiler) abort " {{{1 - " Specifying the build_dir by environment variable should override the - " current value. - if empty($VIMTEX_OUTPUT_DIRECTORY) | return | endif - - if !empty(a:compiler.build_dir) - \ && (a:compiler.build_dir !=# $VIMTEX_OUTPUT_DIRECTORY) - call vimtex#log#warning( - \ 'Setting VIMTEX_OUTPUT_DIRECTORY overrides build_dir!', - \ 'Changed build_dir from: ' . a:compiler.build_dir, - \ 'Changed build_dir to: ' . $VIMTEX_OUTPUT_DIRECTORY) - endif - - let a:compiler.build_dir = $VIMTEX_OUTPUT_DIRECTORY -endfunction - -" }}}1 - function! s:check_callback(line) abort " {{{1 let l:status = get(s:callbacks, substitute(a:line, '\r', '', '')) if l:status <= 0 | return | endif diff --git a/autoload/vimtex/compiler/latexmk.vim b/autoload/vimtex/compiler/latexmk.vim index 86b384c72d..838f59a037 100644 --- a/autoload/vimtex/compiler/latexmk.vim +++ b/autoload/vimtex/compiler/latexmk.vim @@ -82,6 +82,7 @@ endfunction let s:compiler = vimtex#compiler#_template#new({ \ 'name' : 'latexmk', + \ 'aux_dir': '', \ 'callback' : 1, \ 'continuous': 1, \ 'executable' : 'latexmk', @@ -102,17 +103,22 @@ endfunction " }}}1 function! s:compiler.__init() abort dict " {{{1 - " Check if .latexmkrc sets the build_dir - if so this should be respected - let l:out_dir = - \ vimtex#compiler#latexmk#get_rc_opt(self.state.root, 'out_dir', 0, '')[0] - if !empty(l:out_dir) - if !empty(self.build_dir) && (self.build_dir !=# l:out_dir) + call vimtex#util#materialize_property(self, 'aux_dir') + + call s:compare_with_latexmkrc(self, 'out_dir') + call s:compare_with_latexmkrc(self, 'aux_dir') + + " $VIMTEX_OUTPUT_DIRECTORY overrides configured compiler.aux_dir + if !empty($VIMTEX_OUTPUT_DIRECTORY) + if !empty(self.aux_dir) + \ && (self.aux_dir !=# $VIMTEX_OUTPUT_DIRECTORY) call vimtex#log#warning( - \ 'Setting out_dir from latexmkrc overrides build_dir!', - \ 'Changed build_dir from: ' . self.build_dir, - \ 'Changed build_dir to: ' . l:out_dir) + \ 'Setting VIMTEX_OUTPUT_DIRECTORY overrides aux_dir!', + \ 'Changed aux_dir from: ' . self.aux_dir, + \ 'Changed aux_dir to: ' . $VIMTEX_OUTPUT_DIRECTORY) endif - let self.build_dir = l:out_dir + + let self.aux_dir = $VIMTEX_OUTPUT_DIRECTORY endif endfunction @@ -125,8 +131,13 @@ function! s:compiler.__build_cmd() abort dict " {{{1 let l:cmd .= ' ' . join(self.options) let l:cmd .= ' ' . self.get_engine() - if !empty(self.build_dir) - let l:cmd .= ' -outdir=' . fnameescape(self.build_dir) + if !empty(self.out_dir) + let l:cmd .= ' -outdir=' . fnameescape(self.out_dir) + endif + + if !empty(self.aux_dir) + let l:cmd .= ' -emulate-aux-dir' + let l:cmd .= ' -auxdir=' . fnameescape(self.aux_dir) endif if self.continuous @@ -148,21 +159,70 @@ endfunction " }}}1 function! s:compiler.__pprint_append() abort dict " {{{1 - return [ - \ ['callback', self.callback], - \ ['continuous', self.continuous], - \ ['executable', self.executable], + let l:list = [] + + if !empty(self.aux_dir) + call add(l:list, ['aux_dir', self.aux_dir]) + endif + + call add(l:list, ['callback', self.callback]) + call add(l:list, ['continuous', self.continuous]) + call add(l:list, ['executable', self.executable]) + + return l:list +endfunction + +" }}}1 + +function! s:compiler.get_file(ext) abort dict " {{{1 + for l:root in [ + \ $VIMTEX_OUTPUT_DIRECTORY, + \ self.aux_dir, + \ self.out_dir, + \ self.state.root \] + if empty(l:root) | continue | endif + + let l:cand = printf('%s/%s.%s', l:root, self.state.name, a:ext) + if !vimtex#paths#is_abs(l:root) + let l:cand = self.state.root . '/' . l:cand + endif + + if filereadable(l:cand) + return fnamemodify(l:cand, ':p') + endif + endfor + + return '' +endfunction + +" }}}1 +function! s:compiler.create_dirs() abort dict " {{{1 + call self._create_build_dir(self.out_dir) + call self._create_build_dir(self.aux_dir) +endfunction + +" }}}1 +function! s:compiler.remove_dirs() abort dict " {{{1 + call self._remove_dir(self.out_dir) + call self._remove_dir(self.aux_dir) endfunction " }}}1 function! s:compiler.clean(full) abort dict " {{{1 - let l:cmd = self.executable . ' ' . (a:full ? '-C ' : '-c ') - if !empty(self.build_dir) - let l:cmd .= printf(' -outdir=%s ', fnameescape(self.build_dir)) + let l:cmd = self.executable + let l:cmd .= a:full ? ' -C' : ' -c' + + if !empty(self.out_dir) + let l:cmd .= ' -outdir=' . fnameescape(self.out_dir) + endif + if !empty(self.aux_dir) + let l:cmd .= ' -emulate-aux' + let l:cmd .= ' -auxdir=' . fnameescape(self.aux_dir) endif - let l:cmd .= vimtex#util#shellescape(self.state.base) + + let l:cmd .= ' ' . vimtex#util#shellescape(self.state.base) call vimtex#jobs#run(l:cmd, {'cwd': self.state.root}) endfunction @@ -173,7 +233,6 @@ function! s:compiler.get_engine() abort dict " {{{1 let l:tex_program_directive = self.state.get_tex_program() let l:tex_program = l:tex_program_directive - " Parse tex_program from from pdf_mode option in .latexmkrc let [l:pdf_mode, l:is_local] = \ vimtex#compiler#latexmk#get_rc_opt(self.state.root, 'pdf_mode', 1, -1) @@ -209,6 +268,23 @@ endfunction " }}}1 +function! s:compare_with_latexmkrc(dict, option) abort " {{{1 + " Check if option is specified in .latexmkrc. + " If it is, .latexmkrc should be respected! + let l:value = vimtex#compiler#latexmk#get_rc_opt( + \ a:dict.state.root, a:option, 0, '')[0] + if !empty(l:value) + if !empty(a:dict[a:option]) && (a:dict[a:option] !=# l:value) + call vimtex#log#warning( + \ 'Option "' . a:option . '" is overriden by latexmkrc', + \ 'Changed from: ' . a:dict[a:option], + \ 'Changed to: ' . l:value) + endif + let a:dict[a:option] = l:value + endif +endfunction + +" }}}1 function! s:wrap_option_appendcmd(name, value) abort " {{{1 " Note: On Linux, we use double quoted perl strings; these interpolate " variables. One should therefore NOT pass values that contain `$`. diff --git a/autoload/vimtex/compiler/latexrun.vim b/autoload/vimtex/compiler/latexrun.vim index 751b09bcee..109c1182fd 100644 --- a/autoload/vimtex/compiler/latexrun.vim +++ b/autoload/vimtex/compiler/latexrun.vim @@ -30,7 +30,7 @@ function! s:compiler.__build_cmd() abort dict " {{{1 return 'latexrun ' . join(self.options) \ . ' --latex-cmd ' . self.get_engine() \ . ' -O ' - \ . (empty(self.build_dir) ? '.' : fnameescape(self.build_dir)) + \ . (empty(self.out_dir) ? '.' : fnameescape(self.out_dir)) \ . ' ' . vimtex#util#shellescape(self.state.base) endfunction @@ -38,7 +38,7 @@ endfunction function! s:compiler.clean(...) abort dict " {{{1 let l:cmd = printf('latexrun --clean-all -O %s', - \ empty(self.build_dir) ? '.' : fnameescape(self.build_dir)) + \ empty(self.out_dir) ? '.' : fnameescape(self.out_dir)) call vimtex#jobs#run(l:cmd, {'cwd': self.state.root}) endfunction diff --git a/autoload/vimtex/compiler/tectonic.vim b/autoload/vimtex/compiler/tectonic.vim index bc188f537a..ec621faeb9 100644 --- a/autoload/vimtex/compiler/tectonic.vim +++ b/autoload/vimtex/compiler/tectonic.vim @@ -27,7 +27,7 @@ function! s:compiler.__check_requirements() abort dict " {{{1 for l:opt in self.options if l:opt =~# '^-\%(o\|-outdir\)' call vimtex#log#warning("Don't use --outdir or -o in compiler options," - \ . ' use build_dir instead, see :help g:vimtex_compiler_tectonic' + \ . ' use out_dir instead, see :help g:vimtex_compiler_tectonic' \ . ' for more details') break endif @@ -36,8 +36,8 @@ endfunction " }}}1 function! s:compiler.__build_cmd() abort dict " {{{1 - let l:outdir = !empty(self.build_dir) - \ ? self.build_dir + let l:outdir = !empty(self.out_dir) + \ ? self.out_dir \ : fnamemodify(self.state.tex, ':p:h') return 'tectonic ' . join(self.options) diff --git a/autoload/vimtex/parser.vim b/autoload/vimtex/parser.vim index 3d2aff86a6..eaa4ec1364 100644 --- a/autoload/vimtex/parser.vim +++ b/autoload/vimtex/parser.vim @@ -131,22 +131,22 @@ function! vimtex#parser#selection_to_texfile(opts) range abort " {{{1 \ + ['\end{document}'] endif - " Respect the compiler build_dir option - if empty(b:vimtex.compiler.build_dir) - let l:build_dir = b:vimtex.root + " Respect the compiler out_dir option + if empty(b:vimtex.compiler.out_dir) + let l:out_dir = b:vimtex.root else - let l:build_dir = vimtex#paths#is_abs(b:vimtex.compiler.build_dir) - \ ? b:vimtex.compiler.build_dir - \ : b:vimtex.root . '/' . b:vimtex.compiler.build_dir + let l:out_dir = vimtex#paths#is_abs(b:vimtex.compiler.out_dir) + \ ? b:vimtex.compiler.out_dir + \ : b:vimtex.root . '/' . b:vimtex.compiler.out_dir endif " Write content to temporary file let l:file = {} let l:file.base = l:opts.name - let l:file.root = l:build_dir - let l:file.tex = l:build_dir . '/' . l:file.base . '.tex' - let l:file.pdf = l:build_dir . '/' . l:file.base . '.pdf' - let l:file.log = l:build_dir . '/' . l:file.base . '.log' + let l:file.root = l:out_dir + let l:file.tex = l:out_dir . '/' . l:file.base . '.tex' + let l:file.pdf = l:out_dir . '/' . l:file.base . '.pdf' + let l:file.log = l:out_dir . '/' . l:file.base . '.log' let l:file.base .= '.tex' call writefile(l:lines, l:file.tex) diff --git a/autoload/vimtex/qf/bibtex.vim b/autoload/vimtex/qf/bibtex.vim index 5d0e68a599..3fadd8fc44 100644 --- a/autoload/vimtex/qf/bibtex.vim +++ b/autoload/vimtex/qf/bibtex.vim @@ -73,15 +73,15 @@ endfunction " }}}1 function! s:qf.get_db_files() abort " {{{1 if empty(self.db_files) - let l:build_dir = fnamemodify( + let l:out_dir = fnamemodify( \ b:vimtex.compiler.get_file('log'), ':.:h') . '/' for l:file in map( \ filter(readfile(self.file), 'v:val =~# ''Database file #\d:'''), \ 'matchstr(v:val, '': \zs.*'')') if filereadable(l:file) call add(self.db_files, l:file) - elseif filereadable(l:build_dir . l:file) - call add(self.db_files, l:build_dir . l:file) + elseif filereadable(l:out_dir . l:file) + call add(self.db_files, l:out_dir . l:file) endif endfor endif diff --git a/autoload/vimtex/util.vim b/autoload/vimtex/util.vim index 37106a02aa..113c27f7b0 100644 --- a/autoload/vimtex/util.vim +++ b/autoload/vimtex/util.vim @@ -125,6 +125,20 @@ function! vimtex#util#extend_recursive(dict1, dict2, ...) abort " {{{1 return a:dict1 endfunction +" }}}1 +function! vimtex#util#materialize_property(dict, name) abort " {{{1 + if type(get(a:dict, a:name)) != v:t_func | return | endif + + try + let a:dict[a:name] = a:dict[a:name]() + catch + call vimtex#log#error( + \ 'Could not materialize property: ' . a:name, + \ v:exception) + let a:dict[a:name] = '' + endtry +endfunction + " }}}1 function! vimtex#util#shellescape(cmd) abort " {{{1 " diff --git a/doc/vimtex.txt b/doc/vimtex.txt index 4d211a3e8c..85a99899d2 100644 --- a/doc/vimtex.txt +++ b/doc/vimtex.txt @@ -993,7 +993,8 @@ OPTIONS *vimtex-options* Default value: >vim let g:vimtex_compiler_latexmk = { - \ 'build_dir' : '', + \ 'aux_dir' : '', + \ 'out_dir' : '', \ 'callback' : 1, \ 'continuous' : 1, \ 'executable' : 'latexmk', @@ -1009,23 +1010,49 @@ OPTIONS *vimtex-options* The default value shows which entries may be changed. Here the different keys are explained in more detail: - build_dir ~ - This option sets the compilation build directory. It corresponds to the - `-output-directory` option in `latexmk`. If the path is a relative path, - then it will be considered relative to the main project file. + aux_dir ~ + This option sets the directory for auxiliary output files. It corresponds + to the `$aux_dir` option of `latexmk`. If the path is a relative path, + then it is considered relative to the main project file. - Although the value of this option should be a string that represents - a path, it is also possible to make it a function. This makes it possible - to specify a dynamic `build_dir`. It may be easier to understand from an - example: >vim + The value of this option should be either: + 1) a string that represents a path, or + 2) a |Funcref|. The |Funcref| type makes it possible to specify + a dynamic `aux_dir`. It may be easier to understand from an example: >vim - let g:vimtex_compiler_latexmk = {'build_dir': {-> expand("%:t:r")}} + let g:vimtex_compiler_latexmk = {'aux_dir': {-> expand("%:t:r")}} < - With the above setting, the `build_dir` is set to the base name of the - current file. E.g., If you do `vim test.tex`, the value becomes `test`. + With the above setting, the `aux_dir` is set to the base name of the + current file. E.g., If you do `vim test.tex`, the value becomes + `test`. - If `build_dir` is specified, then the specified build directory is created - if it does not exist. + The specified auxiliary directory is created if it does not exist. + + Note 1: This option only works with `latexmk` version 4.27 and later. + Note 2: If `$aux_dir` is added to `.latexmkrc`, then the `.latexmkrc` setting + will have priority. + Note 3: If |$VIMTEX_OUTPUT_DIRECTORY| is defined, it will have the highest + priority. + Note 4: The `-emulate_aux` option will be automatically passed to + `latexmk` if this option is not empty. + + out_dir ~ + This option sets the directory for the compilation output files. It + corresponds to the `$out_dir` option in `latexmk`. If the path is + a relative path, then it is considered relative to the main project file. + + The value of this option should be either: + 1) a string that represents a path, or + 2) a |Funcref|. The |Funcref| type makes it possible to specify + a dynamic `out_dir`. It may be easier to understand from an example: >vim + + let g:vimtex_compiler_latexmk = {'out_dir': {-> expand("%:t:r")}} +< + With the above setting, the `out_dir` is set to the base name of the + current file. E.g., If you do `vim test.tex`, the value becomes + `test`. + + The specified output directory is created if it does not exist. Note 1: This option only works with `latexmk` version 4.27 and later. Note 2: If `$out_dir` is added to `.latexmkrc`, then the `.latexmkrc` setting @@ -1116,7 +1143,7 @@ OPTIONS *vimtex-options* Default value: >vim let g:vimtex_compiler_latexrun = { - \ 'build_dir' : '', + \ 'out_dir' : '', \ 'options' : [ \ '-verbose-cmds', \ '--latex-args="-synctex=1"', @@ -1126,8 +1153,8 @@ OPTIONS *vimtex-options* The default value shows which entries may be changed. Here the different keys are explained in more detail: - build_dir ~ - Same as |g:vimtex_compiler_latexmk| / `build_dir`. + out_dir ~ + See `out_dir` key of |g:vimtex_compiler_latexmk|. options ~ This is a list of options that are passed to `latexrun`. The default @@ -1163,7 +1190,7 @@ OPTIONS *vimtex-options* Default value: >vim let g:vimtex_compiler_tectonic = { - \ 'build_dir' : '', + \ 'out_dir' : '', \ 'hooks' : [], \ 'options' : [ \ '--keep-logs', @@ -1174,8 +1201,8 @@ OPTIONS *vimtex-options* The default value shows which entries may be changed. Here the different keys are explained in more detail: - build_dir ~ - Same as |g:vimtex_compiler_latexmk| / `build_dir`. + out_dir ~ + See `out_dir` key of |g:vimtex_compiler_latexmk|. hooks ~ Same as |g:vimtex_compiler_latexmk| / `hooks`. @@ -1184,7 +1211,7 @@ OPTIONS *vimtex-options* This is a list of options that are passed to `tectonic`. The default options should work well for most people. For anyone who wishes to modify these, please note: - - Don't use `--outdir` or `-o` here. Use the `build_dir` option instead. + - Don't use `--outdir` or `-o` here. Use the `out_dir` option instead. - Without `--keep-logs` (or `--keep-intermediates` or `-k)`, you won't see errors/warnings in the quickfix list when compilations finish. - By default, `tectonic` cleans all auxiliary files (such as `.aux`, @@ -3256,17 +3283,18 @@ OPTIONS *vimtex-options* *$VIMTEX_OUTPUT_DIRECTORY* This environment variable allows to specify the output directory of - auxiliary LaTeX files. If it exists and is a valid path, this path will be - used as the output directory (aka build directory). That is, it overrides - options such as |g:vimtex_compiler_latexmk| / `build_dir`. This has two main - use cases: + generated LaTeX files. If it exists and is a valid path, this path will be + used as the output directory. This has two main use cases: - 1. It allows to use a custom build directory for different projects. + 1. It allows to use a custom output directory for different projects. 2. It allows to specify an output directory for projects where one uses compiler backends such as |vimtex-compiler-arara|. This makes it possible to make e.g. the |vimtex-view| feature to work as expected if output directories are used with arara. + Note: This will override `out_dir` (and `aux_dir`) of options like + |g:vimtex_compiler_latexmk| and |g:vimtex_compiler_latexrun|. + ------------------------------------------------------------------------------ COMMANDS *vimtex-commands* diff --git a/test/example-book-multifile/chapters.tex b/test/example-book-multifile/content/chapters.tex similarity index 98% rename from test/example-book-multifile/chapters.tex rename to test/example-book-multifile/content/chapters.tex index 8da4369ed6..5e178ffdd4 100644 --- a/test/example-book-multifile/chapters.tex +++ b/test/example-book-multifile/content/chapters.tex @@ -84,4 +84,4 @@ \subsection{Testing TOC sub levels} \section{Testing included section contents} -\input{sections} +\input{content/sections} diff --git a/test/example-book-multifile/sections.tex b/test/example-book-multifile/content/sections.tex similarity index 100% rename from test/example-book-multifile/sections.tex rename to test/example-book-multifile/content/sections.tex diff --git a/test/example-book-multifile/main.tex b/test/example-book-multifile/main.tex index b44360a4d4..f9c2d8399b 100644 --- a/test/example-book-multifile/main.tex +++ b/test/example-book-multifile/main.tex @@ -15,7 +15,7 @@ \mainmatter % Todo This should NOT match -\input{chapters} +\include{content/chapters} \todo[inline]{Match more things} \appendix diff --git a/test/example-book-multifile/minivimrc b/test/example-book-multifile/minivimrc index 7b1336798d..f7ff44e1b6 100644 --- a/test/example-book-multifile/minivimrc +++ b/test/example-book-multifile/minivimrc @@ -17,7 +17,7 @@ let g:vimtex_toc_todo_labels = { \ 'IMPORTANTE': 'IMPORTANT: ', \} -" let g:vimtex_compiler_latexmk = {'build_dir': 'out'} +" let g:vimtex_compiler_latexmk = {'out_dir': 'out'} let g:vimtex_view_automatic = 0 let g:vimtex_quickfix_mode = 0 diff --git a/test/test-compiler/test-backend.vim b/test/test-compiler/test-backend.vim index 85696e807b..da379141fa 100644 --- a/test/test-compiler/test-backend.vim +++ b/test/test-compiler/test-backend.vim @@ -80,8 +80,8 @@ function! RunTests(comp, list_opts) cquit endif - if !empty(get(l:opts, 'build_dir', '')) - call delete(l:opts.build_dir, 'rf') + if !empty(get(l:opts, 'out_dir', '')) + call delete(l:opts.out_dir, 'rf') endif echo "\n" @@ -92,14 +92,14 @@ endfunction for [s:comp, s:opts] in items({ \ 'latexmk' : [ \ {}, - \ {'build_dir' : 'out'}, + \ {'out_dir' : 'out'}, \ {'callback' : 0}, \ {'callback' : 0, 'continuous' : 0}, \ {'continuous' : 0}, \ ], \ 'latexrun' : [ \ {}, - \ {'build_dir' : 'out'}, + \ {'out_dir' : 'out'}, \ ], \}) call RunTests(s:comp, s:opts) diff --git a/test/test-compiler/test-builddir.vim b/test/test-compiler/test-builddir.vim index 2439a3d945..b138012c44 100644 --- a/test/test-compiler/test-builddir.vim +++ b/test/test-compiler/test-builddir.vim @@ -5,7 +5,7 @@ filetype plugin on let g:status = 0 nnoremap q :qall! -let g:vimtex_compiler_latexmk = {'build_dir': 'build'} +let g:vimtex_compiler_latexmk = {'out_dir': 'build'} call vimtex#log#set_silent() diff --git a/test/test-getfile/Makefile b/test/test-getfile/Makefile new file mode 100644 index 0000000000..0891f11987 --- /dev/null +++ b/test/test-getfile/Makefile @@ -0,0 +1,14 @@ +MYVIM ?= nvim --clean --headless + +INMAKE := 1 +export INMAKE + +TESTS := $(wildcard test*.vim) +TESTS := $(TESTS:.vim=) + +.PHONY: default $(TESTS) + +default: $(TESTS) + +$(TESTS): + @$(MYVIM) -u $@.vim diff --git a/test/test-getfile/test_auxdir.vim b/test/test-getfile/test_auxdir.vim new file mode 100644 index 0000000000..fbc3c77ad8 --- /dev/null +++ b/test/test-getfile/test_auxdir.vim @@ -0,0 +1,46 @@ +set nocompatible +let &rtp = '../..,' . &rtp +filetype plugin on + +nnoremap q :qall! + +function! Test(file, expected) abort + silent edit test_auxdir/test.tex + let l:file = vimtex#paths#shorten_relative( + \ b:vimtex.compiler.get_file(a:file)) + call assert_equal(a:expected, l:file) + bwipeout +endfunction + +call Test('pdf', 'test.pdf') + +let g:vimtex_compiler_latexmk = {'out_dir': 'out'} +call Test('pdf', 'out/test.pdf') +call Test('aux', 'out/test.aux') +call Test('fls', 'out/test.fls') +call Test('log', 'out/test.log') +call Test('blg', 'out/test.blg') + +let g:vimtex_compiler_latexmk = {'aux_dir': 'aux'} +call Test('pdf', 'test.pdf') +call Test('fls', 'test.fls') +call Test('aux', 'aux/test.aux') +call Test('log', 'aux/test.log') +call Test('blg', 'aux/test.blg') + +let g:vimtex_compiler_latexmk = { + \ 'out_dir': 'out', + \ 'aux_dir': 'aux' + \} +call Test('pdf', 'out/test.pdf') +call Test('fls', 'out/test.fls') +call Test('aux', 'aux/test.aux') +call Test('log', 'aux/test.log') +call Test('blg', 'aux/test.blg') + +call vimtex#log#set_silent() +let $VIMTEX_OUTPUT_DIRECTORY = 'out' +call Test('aux', 'out/test.aux') +call Test('log', 'out/test.log') + +call vimtex#test#finished() diff --git a/test/test-getfile/test_auxdir/aux/test.aux b/test/test-getfile/test_auxdir/aux/test.aux new file mode 100644 index 0000000000..e69de29bb2 diff --git a/test/test-getfile/test_auxdir/aux/test.blg b/test/test-getfile/test_auxdir/aux/test.blg new file mode 100644 index 0000000000..e69de29bb2 diff --git a/test/test-getfile/test_auxdir/aux/test.log b/test/test-getfile/test_auxdir/aux/test.log new file mode 100644 index 0000000000..e69de29bb2 diff --git a/test/test-getfile/test_auxdir/out/test.aux b/test/test-getfile/test_auxdir/out/test.aux new file mode 100644 index 0000000000..e69de29bb2 diff --git a/test/test-getfile/test_auxdir/out/test.blg b/test/test-getfile/test_auxdir/out/test.blg new file mode 100644 index 0000000000..e69de29bb2 diff --git a/test/test-getfile/test_auxdir/out/test.fls b/test/test-getfile/test_auxdir/out/test.fls new file mode 100644 index 0000000000..e69de29bb2 diff --git a/test/test-getfile/test_auxdir/out/test.log b/test/test-getfile/test_auxdir/out/test.log new file mode 100644 index 0000000000..e69de29bb2 diff --git a/test/test-getfile/test_auxdir/out/test.pdf b/test/test-getfile/test_auxdir/out/test.pdf new file mode 100644 index 0000000000..e69de29bb2 diff --git a/test/test-getfile/test_auxdir/out/test.synctex.gz b/test/test-getfile/test_auxdir/out/test.synctex.gz new file mode 100644 index 0000000000..e69de29bb2 diff --git a/test/test-getfile/test_auxdir/test.fls b/test/test-getfile/test_auxdir/test.fls new file mode 100644 index 0000000000..e69de29bb2 diff --git a/test/test-getfile/test_auxdir/test.pdf b/test/test-getfile/test_auxdir/test.pdf new file mode 100644 index 0000000000..e69de29bb2 diff --git a/test/test-getfile/test_auxdir/test.tex b/test/test-getfile/test_auxdir/test.tex new file mode 100644 index 0000000000..527545ebc3 --- /dev/null +++ b/test/test-getfile/test_auxdir/test.tex @@ -0,0 +1,6 @@ +\documentclass{minimal} +\begin{document} + +Dummy file + +\end{document} diff --git a/test/test-state/test_builddir.vim b/test/test-state/test_builddir.vim index 6830dc7763..2fd06d3dcc 100644 --- a/test/test-state/test_builddir.vim +++ b/test/test-state/test_builddir.vim @@ -8,15 +8,15 @@ call vimtex#log#set_silent() function! TestBuildDir(expected) abort silent edit test.tex - " let l:build_dir = vimtex#paths#shorten_relative( + " let l:out_dir = vimtex#paths#shorten_relative( " \ fnamemodify(b:vimtex.compiler.get_file('pdf'), ':h')) - call assert_equal(a:expected, b:vimtex.compiler.build_dir) + call assert_equal(a:expected, b:vimtex.compiler.out_dir) bwipeout endfunction call TestBuildDir('') -let g:vimtex_compiler_latexmk = {'build_dir': 'out'} +let g:vimtex_compiler_latexmk = {'out_dir': 'out'} call TestBuildDir('out') let $VIMTEX_OUTPUT_DIRECTORY = 'out' @@ -27,7 +27,7 @@ let $VIMTEX_OUTPUT_DIRECTORY = 'build' call TestBuildDir('build') let s:warning = get(map(vimtex#log#get(), {_, x -> x.msg[0]}), 0, 'NONE') call assert_equal( - \ 'Setting VIMTEX_OUTPUT_DIRECTORY overrides build_dir!', + \ 'Setting VIMTEX_OUTPUT_DIRECTORY overrides out_dir!', \ s:warning) let $VIMTEX_OUTPUT_DIRECTORY = ''