I am currently using latex on vim with the vimtex plugin (with mac big sur os), and there are two features I would like to have:

  1. Asymptote compiles automatically when I compile latex
  2. All auxiliary files (.aux, .fls, etc. and also asymptote files like file-1.asy, file-1.pdf etc.) would be organized in a separate "build" directory

In my .vimrc file, I have the following specified under the vimtex plugin, which moves all auxiliary files (.aux, .fls, etc. as well as the .asy files) to a separate "build" directory.

Plug 'lervag/vimtex'
    let g:tex_flavor='latex'
    let g:vimtex_view_method='skim'
    let g:vimtex_quickfix_mode=0
    let g:vimtex_compiler_latexmk = {
                \ 'build_dir' : 'build',
    set conceallevel=1
    let g:tex_conceal='abdmg'

The asymptote files (file-1.asy, file-1.pdf, etc.) are automatically moved to the build directory as desired. However, the asymptote doesn't compile automatically when latex is compiled.

So, in my .latexmkrc file, I have the following which enables the asy to automatically compile when I compile the tex document (successfully).

sub asy {return system("asy \"$_[0]\"");}

However, this only works when I don't specify the build directory in the .vimrc file, i.e. when working with conjunction with the following line, it fails.

let g:vimtex_compiler_latexmk = {
            \ 'build_dir' : 'build',

Essentially, I am able to get each of the two features I desire on their own, but I can't get both to work at the same time. Is there any way I can have both features work together?

1 Answer 1


Ran into this issue too on Linux.

In your .latexmkrc, use

sub asy {return system("asy -outname \$(dirname '$_[0]')/build '$_[0]'");}

instead of

sub asy {return system("asy \"$_[0]\"");}

It might be a good idea to configure the build directory of latexmk directly in your .latexmkrc instead of .vimrc with


This way we can instead do

sub asy {return system("asy -outname \$(dirname '$_[0]')/$out_dir '$_[0]'");}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .