How to configure vim-latex to use portable MiKTeX to compile

2.2k views Asked by At

Recently I have installed vim-latex plugin in gVim. I use portable MiKTeX to compile tex document into pdf documents. Till now, I have used command prompt to compile the tex files. After installing vim-latex plugin I found that there's a compile option under Tex-Suite>Compile menu. But clicking it doesn't do anything. So how can I configure vim-latex to use the portable MiKTeX compiler?

2

There are 2 answers

0
th1rdey3 On BEST ANSWER

Initial googling let me to this link: http://vim-latex.sourceforge.net/documentation/latex-suite/customizing-compiling.html#Tex_CompileRule_format. However, I couldn't find any clue to where actually configure this variables. But finally I found the location. For my case it was

C:\Program Files (x86)\Vim\vimfiles\ftplugin\latex-suite\texrc

The texrc file has all the variables described in the link. As I said in my question, I use miktex portable so first I needed to change the compiler. So I searched for g:Tex_CompileRule_pdf in the file and found this line

TexLet g:Tex_CompileRule_pdf = 'pdflatex -interaction=nonstopmode $*'

So, I just replaced pdflatex with the full path

TexLet g:Tex_CompileRule_pdf = 'E:\full\path\of\miktex\pdflatex -interaction=nonstopmode $*'

Next thing that needed to be changed is telling vim-latex to use pdflatex to compile by default. So, I searched for the g:Tex_DefaultTargetFormat variable in the file and found this line

if has('macunix')
    TexLet g:Tex_DefaultTargetFormat = 'pdf'
else
    TexLet g:Tex_DefaultTargetFormat = 'dvi'
endif

No need to keep all this checking. so I commented out most of the lines

"if has('macunix')
    TexLet g:Tex_DefaultTargetFormat = 'pdf'
"else
"   TexLet g:Tex_DefaultTargetFormat = 'dvi'
"endif

After this, vim-latex was able to compile my files. But the viewer wasn't working. So, needed to make a little more change. Searched for g:Tex_ViewRule_ps and changed the lines under if has('win32') to look like this.

if has('win32')
    TexLet g:Tex_ViewRule_ps = 'gsview32'
    TexLet g:Tex_ViewRule_pdf = 'E:\Share\PortableApps\SumatraPDF-2.4\SumatraPDF.exe'
    TexLet g:Tex_ViewRule_dvi = 'yap -1'

I had to use SumatraPDF because for some reason Adobe Reader 11 was giving the error Unable to find the file. But Sumatra in not so bad. Now I can use vim-latex in peace :)

0
rustushki On

You need to set a few variables in vim to configure vim-latex.

This one sets the order in which you want to export your tex file:

let g:Tex_FormatDependency_pdf = 'dvi,ps,pdf'

Notice that it converts the *.tex to *.dvi, then the *.dvi to *.ps, then *.ps to *.pdf.

The next ones you need to set are the compile rules for vim-latex. Each of these rules define the program (and arguments) used to compile each output file:

let g:Tex_CompileRule_dvi = 'latex --interaction=nonstopmode $*'
let g:Tex_CompileRule_ps = 'dvips -Ppdf -o $*.ps $*.dvi'
let g:Tex_CompileRule_pdf = 'ps2pdf $*.ps'

When you convert from *.tex to *.dvi, vim-latex will use the 'latex' command. Then, when it converts from *.dvi to *.ps, it will use dvips. Finally it will use ps2pdf to convert from *.ps to *.pdf.

It looks like MikTex's executable is named 'latex', so you should be OK to use the above settings. Just be sure that you have 'dvips' and 'ps2pdf' installed on your system.

The output *.pdf file will be in the directory which contains your source *.tex file.