1

I have several commands I would like to use for different diagrams. For example, I have defined a right 3d angle:

path3 RightAngle(real radius, triple A, triple B, triple C)
{
return B+radius*unit(A-B)--B+radius*(unit(A-B)+unit(C-B))--B+radius*unit(C-B);
} 

Now in the same file I can write

draw(RightAngle(0.3,A,H1,C));

This works. Fine. But now I want to draw a right angle in another diagram. Do I have to copy the first code every single time into the new asy-picture or there is the way to put all commands like that into a file MyAsyCommands.asy (or MyAsyCommands.tex, or MyAsyCommands.Idontknowwhat) and then use it like

input MyAsyCommands;

Here they suggest:

You can create your own package by simply creating a new .asy file (say MyMacros.asy) with your own definitions in it, and saving it in the directory in which Asymptote is installed (C:\Program Files\Asymptote by default). Then import MyMacros; in your document, and you'll be set!

I am using ubuntu and have no idea where asymptote is. Yes, I know, shame on me, but shouldn't it be easier than that? I tried to put the file MyAsyCommands.asy into the folder where my file with asy-picture is. (test.tex with \begin{asy}\end{asy}). It didn't work. Namely, this works:

\documentclass{article}
\usepackage{asymptote}
\begin{document}
\begin{asy}
settings.outformat = "pdf";
settings.render = 0;
import three;
//import MyAsyCommands;
size(7cm, 0);
currentprojection=orthographic((5,2,3));
triple A=(0,0,1);
triple B=(0,1,0);
triple C=(1,0,0);
draw (A--B--C);
dot(Label("$A$",align=N),A);
dot(Label("$B$",align=E),B);
dot(Label("$C$",align=W),C);
//draw(RightAngle(0.3,A,B,C));
\end{asy}
\end{document}

But when I take comments out, inputing the file MyAsyCommands.asy:

path3 RightAngle(real radius, triple A, triple B, triple C)
{
return B+radius*unit(A-B)--B+radius*(unit(A-B)+unit(C-B))--B+radius*unit(C-B);
}

it doesn't. Probably MyAsyCommands.asy should be somehow specially desined (you know when we do the same in LaTeX we use \RequirePackage instead of \usepackage) or something like that.

enter image description here

What do I do wrong?

4
  • Note that what you did really ought to have worked. What error message do you get when you uncomment the import line? Jul 31, 2016 at 21:11
  • @Charles, I had to put the name of MyAsyCommands.asy into the quotation marks and write the full path to this file. And after this, it worked out! Jul 31, 2016 at 23:10
  • My point is that you shouldn't have to do that -- import MyAsyCommands; ought to work fine as is. So I'm trying to figure out why it doesn't; if it's a bug in Asymptote, we should probably report it. Aug 1, 2016 at 2:17
  • @Charles! It does work without "". But I have a very strange effect. To force it to work I need to delete all auxiliary files from the folder where all the stuff is. Generally, it looks loke that Asymptote doesn't track any mistakes. It just shows the previous version of the file. If I really want it to show whether my code works or not, I need to delete all the files that are not *.tex and start it over again. I work with TexStudio. Quick build is adjusted to do Asy cycle: pdflate->asy->pdflatex->pdfview. Aug 1, 2016 at 10:48

1 Answer 1

2

This answer contains untested code fragments. I just follow the Asymptote documentation on import.

Within the asy environment, you could try

import "./MyAsyCommands.asy" as MyAsyCommands;

Omitting the ./ may work as well. Alternatively, you can specify an absolute path to your .asy file if you do not want to depend on the current directory.

In your case, the following lower-level command may work as well:

include "./MyAsyCommands.asy";

You can tune the path there as well.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .