I am looking for a way to easily compile whole latex projects, based in several files through the following set of folders:
.
|- MyProjectsMainFile.tex
|- img/
| |- image1.png
| |- image2.jpg
| `- etc.whatever
`- tex/
|- part1.tex
|- part2.tex
`- conclusion.tex
The tricky bit is to do this even if I am editing a file in the tex
folder.
I will explain a bit my usage first: In larger projects I use this structure, and I reference pictures using \includegraphics{./img/name}
and insert code from the other .tex
files by \input{.tex/file.tex}
, as is the way to go for modular documents.
Up until now, this structure has only been needed in projects I have made with other people, and my own documents have always been so small that I didn't need the tex
folder. For this reason, while using Vim to write my own stuff, I compiled using the following in my .vimrc
:
" LaTeX macros for compiling and viewing
augroup latex_macros " {
autocmd!
autocmd FileType tex :nnoremap <leader>c :w<CR>:!pdflatex %<CR>
autocmd FileType tex :nnoremap <leader>v :!open %:r.pdf &<CR><CR>
augroup END " }
<leader> c
to compile, <leader> v
to view. This works well until you start going down into the folders, and the file that needs to be compiled is not the one you are working on.
I don't rely on any LaTeX-extensions, and I would like to keep things that way for the most part (I use Ultisnips as my tab-complete tool with quite personalized snippets, and I don't want any extension to mess with my clearly superior completions!). I know there are extension out there that take care of this worry, but I don't want to a whole world of stuff just because of this little thing.
A few assumptions that can be used as starting point:
I will always either be in the very file to be compiled, or in a file that is immediately inside
tex/
. That is to say,MyProjectsMainFile.tex
will always either be in.
or..
.MyProjectsMainFile.tex
will be the only.tex
file in my project main folder.I prefer using the extension
.tex
for the files in thetex/
folder as well.
It might be sufficient to include som comment at the top of every inserted file, and improve the above macro to check for this line and create a special case (I have seen extensions using this solution). I wouldn't know how to do that in Vimscript though, and perhaps there are better ways of solving this problem.