[Tex/LaTex] How to dynamically change the output filename in Vim LaTeX Suite

vimvim-latex

Say, my .tex files are organized like this ~/Projects/proj_name/articles.tex.

After compiling with LaTeX Suite, I want the output PDF file to be proj_name.pdf instead of articles.pdf. Since I have several projects in ~/Projects/ I want a systematic configuration in .vimrc.

Here is my current solution

let g:Tex_CompileRule_pdf='pdflatex -interaction=nonstopmode -jobname=%:p:h:t $*'

This method is not satisfying since the name of .aux and .bbl are also changed to proj_name while Vim-LaTeX is still looking for articles.aux.

My question is, is there any other methods for doing this?

Best Answer

I know this is an old question but I ran into the same problem as the OP and had to solve it.

As a note to other users: the OP's "current solution" does not work well because latex-suite checks the aux and bbl files with the same name as the tex file to see if it needs to run bibtex or recompile the pdf; it won't find them, since the command used also names these files according to the jobname. Hence it never runs multiple compilations to get the bib.

That said, I found no easy solution so here is a shell script I use as the new compile rule (e.g. named tex2pdf):

#!/bin/bash

# Get the passed file name
fullName=$1

# Cut of the extension
filename="${fullName%.*}"

# Get the name of the current dir
dirName="${PWD##*/}"

# The usual command
pdflatex -interaction=nonstopmode ${fullName}

# Rename the pdf
if [ -e ${fileName}.pdf ]
  then
    mv ${filename}.pdf ${dirName}.pdf
fi

Then use this as the compile rule:

let g:Tex_CompileRule_pdf='tex2pdf $*'
Related Question