Here is an attempt to answer both questions using the asypictureB
package (which is an alternative interface to Asymptote). It takes advantage of the fact that when using asypictureB
you can name your Asymptote pictures, and use that name to recall the graphics produced. Note that \jobname
is essentially the name of your master tex
file; for instance, if this file were called foo.tex
, then \jobname
would expand to foo
.
For the second question, I take advantage of the include
command in Asymptote, which directly includes the code from a specified Asymptote file. Also note that within an asypicture
environment, @jobname
behaves like \jobname
would outside the environment (with a number of very strong caveats explained in the package documentation).
\documentclass{article}
\usepackage{asypictureB}
\begin{document}
A red disk:
\begin{center}
\begin{asypicture}{name=red_disk}
size(3cm);
fill(unitcircle, red);
\end{asypicture}
\end{center}
%
A green disk:
\begin{center}
\begin{asypicture}{name=green_disk}
size(4cm);
fill(unitcircle, green);
\end{asypicture}
\end{center}
%
A red disk and a green disk:
\begin{center}
\includegraphics{\jobname-red_disk}
\hspace{1cm}
\includegraphics{\jobname-green_disk}
\end{center}
%
A red disk and a green disk in the same \verb!asypicture!:
\begin{center}
\begin{asypicture}{name=overlay}
// Execute all the code from the red_disk asypicture.
include "@jobname-red_disk";
// Save the resulting picture and start a new one.
picture reddisk = currentpicture;
currentpicture = new picture;
// Execute all the code from the green_disk asypicture.
include "@jobname-green_disk";
// Save the resulting picture and start a new one.
// Note that the scale information from the previous
// pictures is lost. If you want to retain it, look into
// using frames instead of pictures.
picture greendisk = currentpicture;
currentpicture = new picture;
unitsize(1cm);
add(shift(-0.3,0)*greendisk);
add(shift(0.3,0)*reddisk);
\end{asypicture}
\end{center}
\end{document}
The result:
