# Running asymptote code in latex

Using some tutorial on the Art of Problem solving forum on Asymptote, I was able to use Asymptote code inline with my Latex like so

\begin{figure}[h]
\centering
\begin{asy}
include graph;
size(1inch);
filldraw(circle((0,0),1),yellow,black);
fill(circle((-.3,.4),.1),black);
fill(circle((.3,.4),.1),black);
draw(arc((0,0),.5,-140,-40));
\end{asy}
\end{figure}


However, many of my diagrams will be far more complex than this meaning the asymptote will be longer. Is there a way I can include a link in the latex code to the asymptote script so that the latex system will automatically insert the generated picture there.

i.e. I would like something like

  \begin{figure}[h]
\centering
\compile-code{smiley.asy}
\end{figure}


so that the usual compilation process of latex using asymptote

#!/bin/bash
xelatex -shell-escape synopses.tex
asy syn*.asy
xelatex -shell-escape synopses.tex


works as before.

Note: I know a long way around, would be to generate the pictures separately and then include them using includegraphics, but this method would be neater.

Of course. I prefer to use the asypictureB package. One very simple-minded possibility is

\documentclass{article}
\usepackage{filecontents}
\begin{filecontents*}{myasy-1.tex}
\begin{asypicture}{}
include graph;
size(1inch);
filldraw(circle((0,0),1),yellow,black);
fill(circle((-.3,.4),.1),black);
fill(circle((.3,.4),.1),black);
draw(arc((0,0),.5,-140,-40));
\end{asypicture}
\end{filecontents*}
\usepackage{asypictureB}
\begin{document}
\begin{figure}[h]
\centering
\input{myasy-1.tex}
\end{figure}
\end{document}


If you run this with pdflatex -shell-escape (say), you'll get

As long as you do not change the file myasy-1.tex, the picture won't be recompiled.