# latexmkrc, asymptote and subfolders on Mac OS

I just started to learn asymptote (actually because TikZ is not that great for 3D surfaces and curves on these). To set up my system i would like asymptote to work in a subdirectory in order to keep my LaTeX-Project nice and tidy, i.e.

\usepackage{asymptote}
\def\asydir{asypdf}


stores the asy-file that is defined in my document as

\begin{asy}
settings.outformat = "pdf";
defaultpen(fontsize(10pt));
label("Hello world!");
\end{asy}


in the subfolder asypdf

I am working on Mac OS with my favourite editor TextMate2, and that uses latexmk in order to determine the workflow (pdflatex, bibtex calls etc.). And I read about the configuration of latexmk using these lines. So the complete MWE is

%!TEX TS-options = --shell-escape
\documentclass{scrartcl}
\usepackage[utf8]{inputenc}
\usepackage{asymptote}
\def\asydir{asypdf}
\begin{document}
\begin{asy}
settings.outformat = "pdf";
defaultpen(fontsize(10pt));
label("Hello world!");
\end{asy}
\end{document}


And my problem/question here: latexmk does not recognize the folder structure? The .asy file is created in the specified subfolder (by asymptote I suppose), but latexmk creates a .tex file in the main directory, which is then not compiled at all.

Is there a way to let latexmk now the folder structure? Is there another way to keep asymptote files in a subfolder?

The error message (even without the folder structure sadly) is

cusdep asy pdf asypdf/asyt-1: Command for 'cusdep asy pdf asypdf/asyt-1' gave return code 256 cusdep asy pdf asyt-1: Command for 'cusdep asy pdf asyt-1' (when naming the MWE asyt.tex with and without the folder def line)

on Mac OS 10.10 Yosemite using MacTeX 2014.

sub asy {return system("asy -o asypdf/ '$_'");} add_cus_dep("asy","eps",0,"asy"); add_cus_dep("asy","pdf",0,"asy"); add_cus_dep("asy","tex",0,"asy");  I hope it works. You can also see the discussion on http://sourceforge.net/p/asymptote/discussion/409349/thread/e35300dd/ • My first line in the original file was a little different, sub asy {return system("asy -o asypdf/ \"$_[0]\"");}bu i don't now what these few characters [0] change - it works both nevertheless. – Ronny Oct 25 '14 at 12:02
• $_[0] is definitely the correct thing to use. It denotes the first argument to the subroutine, and this argument is set to the base name of the file when the subroutine is called by latexmk. $_ is a Perl variable with a different meaning; only by accident will it equal the desired name, and normally it doesn't. See the latexmk documentation for examples. – John Collins Oct 26 '14 at 15:12