[Solved] Automatically compiling asymptote on vim, with .asy files in another directory?

Michael Zhou Asks: Automatically compiling asymptote on vim, with .asy files in another directory?
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?

Ten-tools.com may not be responsible for the answers or solutions given to any question asked by the users. All Answers or responses are user generated answers and we do not have proof of its validity or correctness. Please vote for the answer that helped you in order to help others find out which is the most helpful answer. Questions labeled as solved may be solved or may not be solved depending on the type of question and the date posted for some posts may be scheduled to be deleted periodically. Do not hesitate to share your response here to help other visitors like you. Thank you, Ten-tools.