# Can't draw two pictures in Asymptote

For some reason I can't draw two pictures onto currentpicture in Asymptote. Currently I have

\documentclass{article}

\usepackage[inline]{asymptote}

\begin{document}

\begin{asy}[width=0.7\textwidth]
import three;

string d = "$"; triple A = (0,0,0); // Vertices of a cube triple B = (0,1,0); triple C = (-1,1,0); triple D = (-1,0,0); transform3 sd = shift(0,0,-1); triple Ap = sd * A; triple Bp = sd * B; triple Cp = sd * C; triple Dp = sd * D; void drawCube(picture pic, string[] labels) { draw(pic,A--B--C--Cp--Bp--Ap--A--B--Bp); draw(pic,B--C); draw(pic,A--D--C); draw(pic,Ap--Dp--D,dashed); // behind the cube draw(pic,Dp--Cp,dashed); if (labels.length > 0) { label(pic, d + labels + d, A, NW); label(pic, d + labels + d, B, N); label(pic, d + labels + d, C, NE); label(pic, d + labels + d, D, N); label(pic, d + labels + d, Ap, SW); label(pic, d + labels + d, Bp, S); label(pic, d + labels + d, Cp, SE); label(pic, d + labels + d, Dp, S); } } picture start; // first picture (the one with the cube) size(start, 100); string[] start_labels = {"A","B","C","D","A'","B'","C'","D'"}; drawCube(start, start_labels); picture step1; // second figure, the one with the dashed line size(step1, 100); triple corner1 = (0,0,0); triple corner2 = (-1,1,-1); draw(step1, corner1--corner2,dashed); dot(step1, corner1); dot(step1, corner2); add(step1.fit(), (-2,0), N); // LINE 1 add(start.fit(), (0,0), N); // LINE 2 label("Starting position", (0,0),S); label("Choose a pair of vertices:$2$ways", (-2,0), S); \end{asy} \end{document}  If this is the file "test.tex", then the building script file is pdflatex test.tex asy *.asy pdflatex test.tex pdflatex test.tex  I'd like there to be a figure with a dashed line on the left and a cube on the right. However, when I run Asymptote on this file, I get two cubes! I tried switching the lines labeled "LINE 1" and "LINE 2", which leads to the other picture being drawn twice instead: Obviously this is quite frustrating. How can this be fixed? Edit: This is compiled with pdflatex, which outputs an .asy file in the same directory, then with asy. The file is the same except for some asydef code which doesn't affect it and the following added to the beginning: if(!settings.multipleView) settings.batchView=false; settings.tex="pdflatex"; settings.inlinetex=true; deletepreamble(); defaultfilename="test-1"; if(settings.render < 0) settings.render=4; settings.outformat=""; settings.inlineimage=true; settings.embed=true; settings.toolbar=false; viewportmargin=(2,2);  Also, this line is at the end: size(241.49895pt,0,keepAspect=true);  • Welcome to TeX-SE! I ran your code with asy and fail to reproduce your observation. How do you compile your code? – user121799 Jun 5, 2019 at 20:45 • It's inside a \begin{asy} ... \end{asy} environment, which is compiled with pdflatex, then asy, then pdflatex. I examined the intermediate asy file and it's a bit different. The main differences are 1. some settings modifications which I assume are prepended by the asy environment 2. a bunch of stuff from asydef on top 3. a final command specifying the figure size. I'm guessing that's because I specifies the asy's width. I've put the header stuff outputted by pdflatex into the question now. Jun 5, 2019 at 20:52 • Well, in that case please post the full code, i.e. including the embedding LaTeX document, and specify in detail how you compile. – user121799 Jun 5, 2019 at 20:59 • I have edited the question as you asked Jun 5, 2019 at 21:20 ## 1 Answer I will be happy to delete this, but maybe it helps. I could not compile your file but when I use the asypictureB package, which has the additional advantage that one only needs to run pdflatex -shell-escape <file> (and no separate asy), \documentclass{article} \usepackage{asypictureB} \begin{document} \begin{asypicture}{name=Ovinus} import three; string d = "$";

triple A = (0,0,0); // Vertices of a cube
triple B = (0,1,0);
triple C = (-1,1,0);
triple D = (-1,0,0);

transform3 sd = shift(0,0,-1);

triple Ap = sd * A;
triple Bp = sd * B;
triple Cp = sd * C;
triple Dp = sd * D;

void drawCube(picture pic, string[] labels) {
draw(pic,A--B--C--Cp--Bp--Ap--A--B--Bp);
draw(pic,B--C);
draw(pic,A--D--C);
draw(pic,Ap--Dp--D,dashed); // behind the cube
draw(pic,Dp--Cp,dashed);

if (labels.length > 0) {
label(pic, d + labels + d, A, NW);
label(pic, d + labels + d, B, N);
label(pic, d + labels + d, C, NE);
label(pic, d + labels + d, D, N);
label(pic, d + labels + d, Ap, SW);
label(pic, d + labels + d, Bp, S);
label(pic, d + labels + d, Cp, SE);
label(pic, d + labels + d, Dp, S);
}
}

picture start; // first picture (the one with the cube)
size(start, 100);

string[] start_labels = {"A","B","C","D","A'","B'","C'","D'"};
drawCube(start, start_labels);

picture step1; // second figure, the one with the dashed line
size(step1, 100);

triple corner1 = (0,0,0);
triple corner2 = (-1,1,-1);

draw(step1, corner1--corner2,dashed);
dot(step1, corner1);
dot(step1, corner2);

add(step1.fit(), (-2,0), N); // LINE 1
add(start.fit(), (0,0), N); // LINE 2

label("Starting position", (0,0),S);
label("Choose a pair of vertices: $2$ ways", (-2,0), S);

\end{asypicture}

\end{document}


I get I know that the overlapping text should not be there but at least the issue you refer to does not arise.

• Thank you so much! If I had known about this package a month ago it would have saved me so much time... Do you know if asydef works with asypicture? Jun 5, 2019 at 22:12
• @OvinusReal Sorry, I do not. (And you're welcome. ;-)
– user121799
Jun 5, 2019 at 22:13
• One more question: how should I set the width of the figure to specified width? with the asy environment you can do [width=x], but it looks like you can't do that here. Should I use a resizebox? Jun 5, 2019 at 22:18
• @OvinusReal This is explained in section 3.2 of the asypictureB manual. (texdoc asypictureB). This is one of the reason why I really like asypictureB so much: you can control this from the embedding document (if you want). All you need to do is \asyset{mysize/.style = {width=6cm, height=4cm}} and then \begin{asypicture}{name=picturename, mysize} or, equivalently, \begin{asypicture}{name=picturename, width=6cm, height=4cm}. (There is one more thing: the latest TikZ version has also perspective views (but not the other 3d features of asymptote)).
– user121799
Jun 5, 2019 at 22:21
• Thanks again, I'll peruse through that manual Jun 5, 2019 at 22:22