I now use vimtex to edit my latex source files. Usually, I use the xelatex engine. So I have the following line at the beginning of my .tex file.

% !TeX program = xelatex

Sometimes I need to switch the engine. I think it is not very convenient to edit this line and reload vim every time when switch the engine.

Are there some method, e.g. \pdf or \lua, to make vimtex to switch the engine to pdflatex or lualatex dynamically?

Any suggestion is welcome. Thank you very much!

1 Answer 1


Sometimes I need to switch the engine.

You can do it like this:

  1. For convenience, ensure that you've stopped compilation of the document. When you change the engine, it is probably also smart to clean auxiliary files.

  2. Change the line, e.g. to %! TeX Program = lualatex.

  3. Run :VimtexReload (mapped to \lx by default).

  • After reading the help file it seems the map setting works. nnoremap \lua :let g:vimtex_compiler_latexmk_engines['_'] = '-lualatex'<CR> :VimtexCompile<CR>. Is it a good choice to set g:vimtex_compiler_latexmk_engines?
    – jiaopjie
    Mar 5, 2022 at 13:44
  • I don't quite see why you want to change the engine all the time. I would just specify your desired default (with g:vimtex_compiler_latexmk_engines as you already figured out), then use the TeX directive if you want to use a different engine in a specific document. Mar 6, 2022 at 17:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.