Skip to content

Commit 47d66ff

Browse files
committed
Should fix issue LaTeX-Box-Team#2
Updated s:ReadTOC such that it allows for the aux-file to be separated from the main tex file through a build directory. Added options g:LatexBox_build_dir (and b:build_dir) with short documentation. Also fixed build dir problem for log files, which allows the log file to be parsed and the quickfix window to be opened with <leader>le. Thanks to @hengsku for filereadable -> isdirectory!
1 parent 46b82c9 commit 47d66ff

3 files changed

Lines changed: 38 additions & 14 deletions

File tree

doc/latex-box.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -523,6 +523,15 @@ Compilation ~
523523

524524
A list of warnings to be ignored.
525525

526+
*g:LatexBox_build_dir* Default: ""
527+
528+
Set output directory for build files.
529+
530+
*b:build_dir* Default: ""
531+
532+
Set output directory for build files. This overrides the global
533+
setting.
534+
526535
------------------------------------------------------------------------------
527536

528537
*latex-box-settings-windows*

ftplugin/latex-box/common.vim

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -135,21 +135,32 @@ function! LatexBox_GetTexBasename(with_dir)
135135
endfunction
136136

137137
function! LatexBox_GetAuxFile()
138-
" 1. check for b:aux_dir variable
139-
if exists('b:aux_dir') && filereadable(b:aux_dir)
140-
return b:aux_dir . '/' . LatexBox_GetTexBasename(0) . '.aux'
138+
" 1. check for b:build_dir variable
139+
if exists('b:build_dir') && isdirectory(b:build_dir)
140+
return b:build_dir . '/' . LatexBox_GetTexBasename(0) . '.aux'
141141
endif
142142

143-
" 2. check for g:LatexBox_aux_file variable
144-
if exists('g:LatexBox_aux_dir') && filereadable(g:LatexBox_aux_dir)
145-
return g:LatexBox_aux_dir . '/' . LatexBox_GetTexBasename(0) . '.aux'
143+
" 2. check for g:LatexBox_build_dir variable
144+
if exists('g:LatexBox_build_dir') && isdirectory(g:LatexBox_build_dir)
145+
return g:LatexBox_build_dir . '/' . LatexBox_GetTexBasename(0) . '.aux'
146146
endif
147147

148148
" 3. use the base name of main tex file
149149
return LatexBox_GetTexBasename(1) . '.aux'
150150
endfunction
151151

152152
function! LatexBox_GetLogFile()
153+
" 1. check for b:build_dir variable
154+
if exists('b:build_dir') && isdirectory(b:build_dir)
155+
return b:build_dir . '/' . LatexBox_GetTexBasename(0) . '.log'
156+
endif
157+
158+
" 2. check for g:LatexBox_build_dir variable
159+
if exists('g:LatexBox_build_dir') && isdirectory(g:LatexBox_build_dir)
160+
return g:LatexBox_build_dir . '/' . LatexBox_GetTexBasename(0) . '.log'
161+
endif
162+
163+
" 3. use the base name of main tex file
153164
return LatexBox_GetTexBasename(1) . '.log'
154165
endfunction
155166

ftplugin/latex-box/motion.vim

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ function! s:FindMatchingPair(mode)
6868
let dollar_pat = '\$'
6969
let notbslash = '\%(\\\@<!\%(\\\\\)*\)\@<='
7070
let notcomment = '\%(\%(\\\@<!\%(\\\\\)*\)\@<=%.*\)\@<!'
71-
let anymatch = '\('
71+
let anymatch = '\('
7272
\ . join(g:LatexBox_open_pats + g:LatexBox_close_pats, '\|')
7373
\ . '\|' . dollar_pat . '\)'
7474

@@ -337,8 +337,8 @@ function! s:ConvertBack(line)
337337
return line
338338
endfunction
339339

340-
function! s:ReadTOC(auxfile, ...)
341-
let texfile = fnamemodify(substitute(a:auxfile, '\.aux$', '.tex', ''), ':p')
340+
function! s:ReadTOC(auxfile, texfile, ...)
341+
let texfile = a:texfile
342342
let prefix = fnamemodify(a:auxfile, ':p:h')
343343

344344
if a:0 != 2
@@ -354,7 +354,10 @@ function! s:ReadTOC(auxfile, ...)
354354
let included = matchstr(line, '^\\@input{\zs[^}]*\ze}')
355355
if included != ''
356356
" append the input TOX to `toc` and `fileindices`
357-
call s:ReadTOC(prefix . '/' . included, toc, fileindices)
357+
let newaux = prefix . '/' . included
358+
call s:ReadTOC(newaux,
359+
\ fnamemodify(substitute(newaux, '\.aux$', '.tex', ''), ':p'),
360+
\ toc, fileindices)
358361
continue
359362
endif
360363

@@ -363,7 +366,7 @@ function! s:ReadTOC(auxfile, ...)
363366
" \@writefile{toc}{\contentsline {section}{\tocsection {}{1}{Section Title}}{pagenumber}}
364367
" \@writefile{toc}{\contentsline {section}{\numberline {secnum}Section Title}{pagenumber}{otherstuff}}
365368

366-
let line = matchstr(line,
369+
let line = matchstr(line,
367370
\ '\\@writefile{toc}{\\contentsline\s*\zs.*\ze}\s*$')
368371
if empty(line)
369372
continue
@@ -405,8 +408,8 @@ function! s:ReadTOC(auxfile, ...)
405408

406409
" add TOC entry
407410
call add(fileindices[texfile], len(toc))
408-
call add(toc, {'file': texfile,
409-
\ 'level': level,
411+
call add(toc, {'file': texfile,
412+
\ 'level': level,
410413
\ 'number': secnum,
411414
\ 'text': text,
412415
\ 'page': page})
@@ -432,7 +435,8 @@ function! LatexBox_TOC(...)
432435
endif
433436

434437
" Read TOC
435-
let [toc, fileindices] = s:ReadTOC(LatexBox_GetAuxFile())
438+
let [toc, fileindices] = s:ReadTOC(LatexBox_GetAuxFile(),
439+
\ LatexBox_GetMainTexFile())
436440
let calling_buf = bufnr('%')
437441

438442
" Find closest section in current buffer

0 commit comments

Comments
 (0)