I have this function to compile my tex files:
function! CompileTex()
silent write!
call setqflist([])
echon "compiling with arara ..."
exec 'lcd %:h'
if expand("%:p") =~# '\(figuras\|figures\)'
let mainfile = fnameescape(expand("%:p"))
else
let mainfile = fnameescape(Tex_GetMainFileName())
endif
let &l:makeprg = 'arara -v ' . mainfile
silent make!
if !empty(getqflist())
copen
wincmd J
else
cclose
redraw
echon "successfully compiled"
endif
endfunction
The first conditional is there because when creating figures I want to compile the current buffer even if there is a main file. However when I call the function in a path that contains "figures" I get
Error detected while processing function CompileTex:
line 4:
E499: Empty file name for '%' or '#', only works with ":p:h": lcd %:h
and the mainfile
variable is set to the main tex file and not to the current buffer as I want.