[Tex/LaTex] How to make vim short key for xelatex and pdflatex both

vimxetex

I have learned that the following setting in _vimrc will let \ll compile by engine pdflatex:

let g:Tex_DefaultTargetFormat='pdf'
let g:Tex_CompileRule_pdf = 'pdflatex -aux-directory=F:/Vim/my_latex_doc/temp --synctex=-1 -src-specials -interaction=nonstopmode $*'

My problem is can be make some modification such that it will compiled by xelatex when I press \lx?

Best Answer

You can use this in your vimrc to quickly switch the compiler to xelatex with \lx. Then use \ll to compile.

function SetXeTex()
    let g:Tex_CompileRule_pdf = 'xelatex -aux-directory=F:/Vim/my_latex_doc/temp --synctex=-1 -src-specials -interaction=nonstopmode $*'
endfunction
map <Leader>lx :<C-U>call SetXeTex()<CR>

If you want to set xelatex temporarily and use \lx to compile you could use

function CompileXeTex()
    let oldCompileRule=g:Tex_CompileRule_pdf
    let g:Tex_CompileRule_pdf = 'xelatex -aux-directory=F:/Vim/my_latex_doc/temp --synctex=-1 -src-specials -interaction=nonstopmode $*'
    call Tex_RunLaTeX()
    let g:Tex_CompileRule_pdf=oldCompileRule
endfunction
map <Leader>lx :<C-U>call CompileXeTex()<CR>
Related Question