# Asymptote in LaTeX - a peculiar problem

I wonder if someone can explain what follows to me and how to remedy it. The following piece of Asymptote code:

import graph;
import graph3;

currentprojection=perspective(4,5,5);

real f(pair z) {return z.x^2-z.y^2;}
triple c(real t) {return (cos(t),sin(t),f((cos(t),sin(t))));}
triple n(real t) {triple w=cross((1,0,2*cos(t)),(0,1,-2*sin(t))); return unit(w);}

picture pic;
size(pic,150,150,IgnoreAspect);

draw(pic,surface(f,(-2,-2),(2,2),nx=10,Spline),green,render(merge=true));

draw(pic,graph(c,0,2*pi,operator ..),red+2);

picture pic2;
size(pic2,150);

draw(pic2,unitsphere,opacity(0.1));

draw(pic2,graph(n,0,2*pi,operator ..),red+2);

int antal=10;
for(int i=0;i < antal;++i){
real t=2*pi*i/antal;

draw(pic,shift(c(t))*((0,0,0)--n(t)),blue+1,Arrow3);

draw(pic2,(0,0,0)--n(t),blue+1,Arrow3);
}



works fine when I run it through Asymptote. It gives me two pictures, call them A and B, side by side.

If I now include the code in an asy-environment in my LaTeX-document a peculiar thing happens: I get two copies of B side by side. If I change the order of the add-commands at the end I get two copies of A instead.

Why do I not get A and B, as when I run it alone?

The code above is inserted into a LaTeX-file that looks like

\documentclass[12pt,a4paper]{article}
\usepackage[inline]{asymptote}
\title{A test example}
\author{Me}
\date{\today}
\begin{document}
\maketitle
\section{Introduction}
Some introductory text.
\begin{center}
\begin{asy}[inline=true]
CODE
\end{asy}
\end{center}
More text
\end{document}

• It might be helpful to see a complete (non)-working .tex file. For instance, do you use the inline option when including the asymptote package? – Charles Staats May 19 '15 at 15:37
• \documentclass[12pt,a4paper]{article} \usepackage[inline]{asymptote} \title{A test example} \author{Me} \date{\today} \begin{document} \maketitle \section{Introduction} Some introductory text. \begin{center} \begin{asy}[inline=true] – Anders Källén May 20 '15 at 9:40
• sorry CODE\end{asy} \end{center} More text \end{document} – Anders Källén May 20 '15 at 9:42
• You should be able to edit the question itself. – Charles Staats May 20 '15 at 16:17
• If you remove the two instances of inline, it will solve this problem. (Of course, there may be other reasons you want to use inline, which is why I'm making this a comment rather than an answer.) – Charles Staats May 21 '15 at 15:47