Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 34 additions & 12 deletions plugin/latexlivepreview.vim
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,31 @@ function! s:Compile()
lcd -
endfunction

" Modify a path to allow it to be a path component
function! s:ToInterPath(path)
if has('win32')
" Replace ':' after the drive letter with an underscope
" to allow l:src_file_tail be used as a path component.
return substitute(a:path, '\v(.):', '\1_', '')
else
" There's no such limitation on other platforms
return a:path
endif
endfunction

" Get the command prefix to set some environment variables
function! s:EnvCommand(vars)
let l:result = has('win32') ? '' : 'env '
for [key, value] in items(a:vars)
if has('win32')
let l:result .= 'set ' . key . '=' . value . ' && '
else
let l:result .= key . '=' . value . ' '
endif
endfor
return l:result
endfunction

function! s:StartPreview(...)
let b:livepreview_buf_data = {}

Expand All @@ -100,7 +125,7 @@ EEOOFF

let b:livepreview_buf_data['tmp_src_file'] =
\ b:livepreview_buf_data['tmp_dir'] .
\ expand('%:p:r')
\ s:ToInterPath(expand('%:p:r'))

" Guess the root file which will be compiled, using first the argument
" passed, then the first line declaration of the source file and
Expand Down Expand Up @@ -128,7 +153,8 @@ EEOOFF
if (l:root_file == b:livepreview_buf_data['tmp_src_file']) " if root file is the current file
let l:tmp_root_dir = l:tmp_src_dir
else
let l:tmp_root_dir = b:livepreview_buf_data['tmp_dir'] . fnamemodify(l:root_file, ':p:h')
let l:tmp_root_dir = b:livepreview_buf_data['tmp_dir'] .
\ s:ToInterPath(fnamemodify(l:root_file, ':p:h'))
if (!isdirectory(l:tmp_root_dir))
silent call mkdir(l:tmp_root_dir, 'p')
endif
Expand All @@ -155,12 +181,12 @@ EEOOFF
let l:tmp_out_file = l:tmp_root_dir . '/' .
\ fnamemodify(l:root_file, ':t:r') . '.pdf'

let l:tex_env_vars_cmd = s:EnvCommand(#{
\ TEXMFOUTPUT: l:tmp_root_dir,
\ TEXINPUTS: l:tmp_root_dir . ':' . b:livepreview_buf_data['root_dir'] . ':',
\ })
let b:livepreview_buf_data['run_cmd'] =
\ 'env ' .
\ 'TEXMFOUTPUT=' . l:tmp_root_dir . ' ' .
\ 'TEXINPUTS=' . l:tmp_root_dir
\ . ':' . b:livepreview_buf_data['root_dir']
\ . ': ' .
\ l:tex_env_vars_cmd .
\ s:engine . ' ' .
\ '-shell-escape ' .
\ '-interaction=nonstopmode ' .
Expand All @@ -186,11 +212,7 @@ EEOOFF

" Update compile command with bibliography
let b:livepreview_buf_data['run_cmd'] =
\ 'env ' .
\ 'TEXMFOUTPUT=' . l:tmp_root_dir . ' ' .
\ 'TEXINPUTS=' . l:tmp_root_dir
\ . ':' . b:livepreview_buf_data['root_dir']
\ . ': ' .
\ l:tex_env_vars_cmd .
\ 'bibtex ' . l:tmp_root_dir . '/*.aux' .
\ ' && ' .
\ b:livepreview_buf_data['run_cmd']
Expand Down