diff --git a/autoload/vimtex/compiler/latexmk.vim b/autoload/vimtex/compiler/latexmk.vim index 75a1e47ab0..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 out_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.out_dir) && (self.out_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 out_dir!', - \ 'Changed out_dir from: ' . self.out_dir, - \ 'Changed out_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.out_dir = l:out_dir + + let self.aux_dir = $VIMTEX_OUTPUT_DIRECTORY endif endfunction @@ -129,6 +135,11 @@ function! s:compiler.__build_cmd() abort dict " {{{1 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 let l:cmd .= ' -pvc -view=none' @@ -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 ') + let l:cmd = self.executable + let l:cmd .= a:full ? ' -C' : ' -c' + if !empty(self.out_dir) - let l:cmd .= printf(' -outdir=%s ', fnameescape(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 `$`.