0

I already set everything up so that I can use Asymptote in LaTeX (specifically, pdfTeX), but for some reason, my code doesn't output.

The entire LaTeX file creates a pdf, as usual, However, the Asymptote, which should have outputted a pdf just for each drawing, doesn't create the needed pdfs. The output pdf doesn't even show the pictures, it just skips to the LaTeX right after the Asymptote code.

I'm trying to draw 8 pictures in Asymptote. The first 2 and last 2 seem fine, but the other 4 (file-3, -4, -5, -6) are messed up. Here's what the console says when trying to parse the code:

...(other stuff that I don't think is helpful)
Output written on "file.pdf".
SyncTeX written on "file.synctex.gz"
Transcript written on "file.log".
Processing file-1
file-3.asy: 17.10: no matching variable 'graph'
This is pdfTeX, Version 3.14159265-2.6-1.40.20 (TeX Live 2019)
(preloaded format=pdflatex)
...(more stuff that I don't think is helpful)

How can I fix this? I know my code works fine, I tried it online and it seems good.

EDIT: Thanks, everyone! I solved the problem with Schrödinger's cat's solution.

  • Good evening and welcome. Can you give the full code that produces this error? – AndréC Jan 3 at 18:52
  • I added it. Thanks in advance! – user202112 Jan 3 at 19:52
  • This code is an asymptote code that runs on the command line. Give the complete code you compiled with pdftex. – AndréC Jan 3 at 19:55
  • Why don't you just present an example that yields the error. Using the asymptote package and \begin{asy} and \end{asy} is fine, but one needs the exact code to reproduce the error. My code below does not yield an error, at least not when compiled on an updated TeXLive 2019 installation when compiled with pdflatex -shell-escape. – Schrödinger's cat Jan 3 at 23:43
  • I'm a little confused. Do you have file-3.asy? If so, why do you have \begin{asy}? Or do you have file.tex, and the asymptote package pulls the part between {asy} into a separate file that it calls file-3.asy? If so, please post a minimal example that has the error (and also has the documentclass and packages, just like with Schrödinger'scat's example). Don't tell us that you have to surround the code, just show us what you've done. – Teepeemm Jan 3 at 23:58
1

Welcome! The error message is (IMHO) very clear: it does not recognize graph. This is because you forgot to add import graph;. In what follows I add a complete code example so that others can compile it with the -shell-escape flag, but you may only need the code between \begin{asypicture}{name=graph1} and \end{asypicture}. I also added size(200,200);, change it to whatever you find appropriate.

\documentclass[border=3mm]{standalone}
\usepackage{asypictureB}
\begin{document}
\begin{asypicture}{name=graph1}
import graph;
size(200,200);
real xmin=-2,xmax=8;
real ymin=-2,ymax=10;

real f(real x) {return 2*((2*x)-1+(x^2)+(4/((x^2)+1)^2))/3;}
real g(real x) {return ((1/2*((x-1)^(2))) - (1/10*((x-2)^(3)))+1)/2;}

path Cf4=graph(f,xmin-3,-0.2376821809755,n=100);
path Cg4=graph(g,-0.2376821809755,xmax-3,n=100);
draw(Cf4,blue);
draw(Cg4,blue);

xlimits(xmin-3,xmax-3,Crop);
ylimits(ymin-4,ymax-4,Crop);

label("min($f\left(x\right)$, $g\left(x\right)$)",(-4.5,5),W,fontsize(12));

draw((5,0)--(-5,0));
\end{asypicture}
\end{document}

enter image description here

Needless to say that

\documentclass[border=3mm]{standalone}
\usepackage{asymptote}
\begin{document}
\begin{asy}
import graph;
size(200,200);
real xmin=-2,xmax=8;
real ymin=-2,ymax=10;

real f(real x) {return 2*((2*x)-1+(x^2)+(4/((x^2)+1)^2))/3;}
real g(real x) {return ((1/2*((x-1)^(2))) - (1/10*((x-2)^(3)))+1)/2;}

path Cf4=graph(f,xmin-3,-0.2376821809755,n=100);
path Cg4=graph(g,-0.2376821809755,xmax-3,n=100);
draw(Cf4,blue);
draw(Cg4,blue);

xlimits(xmin-3,xmax-3,Crop);
ylimits(ymin-4,ymax-4,Crop);

label("min($f\left(x\right)$, $g\left(x\right)$)",(-4.5,5),W,fontsize(12));

draw((5,0)--(-5,0));
\end{asy}
\end{document}

also works.

  • Thanks for your answer! However, I'm still getting an error. I edited my post above with more information. – user202112 Jan 3 at 23:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.