1

I am compiling my LaTeX files from terminal and it gets a little annoying to go every time in terminal and use:

xelatex "file-path"

Is there a way to do this from inside Vim?

muru
  • 197,895
  • 55
  • 485
  • 740
Adam
  • 2,638

2 Answers2

3

Try something like:

command C !xelatex %

in your ~/.vimrc.

Then you can do:

:C

in vim to compile the file.

You can do more complex operations using functions:

function WriteCompileTex()
  write
  :! xelatex %
endfunction
command WC :call WriteCompileTex()

Note that user-defined commands and functions must begin with a capital letter.

You can also do:

au BufWritePost *.tex ! xelatex %

This will run this command whenever a .tex file is written to, so that you can simply do :w, and your Tex file will be compiled after saving.

muru
  • 197,895
  • 55
  • 485
  • 740
3

If you are serious about the couple vim + latex, my preferred option is to use the couple latexxmk + LaTeXBox.

latexmk is independent of the editor, really --- it's a script that watches the files needed to compile a latex document and re-run the compilation when needed. Configuration is a bit complex, but it is a really useful tool. For example, my setup for xelatex is having a latexmkrc file (in the same directory) like this:

$pdf_previewer = "start evince";
$pdf_pdf_update_method = 0;
$dvi_mode = 0;
$pdf_mode = 1;
$preview_continuous_mode = 1;
$pdflatex = "xelatex %O %S";

now you can run latexmk file-name (from the same directory!) and you will have automatic, background compilation every time you modify the file (or any dependent file --- like a drawing or a bibliography). Just save the file and watch the preview automatically update.

latexmk is in the universe repository, so if you have that enabled you can simply install it by sudo apt-get install latexmk.

LaTeX-BoX is a plugin for vim that simplify the editing of the LaTeX files, and uses latexmk to compile. Install it following the instruction on the linked page, and add this to your .vimrc:

" add a <comment> vim: set spelllang=es: to change language
" LaTeX:
let g:tex_flavor='latex'
autocmd FileType tex set spell wrap linebreak
let g:LatexBox_latexmk_async=1
let g:LatexBox_latexmk_preview_continuously=1
let g:LatexBox_quickfix=2
let g:LaTeXBox_output_type='' "Let latexmkrc choose the type 

(change to your taste). Now you start the background compilation from vim with the command \ll.

Rmano
  • 31,947