|
|
Line 1: |
Line 1: |
− | {{Asymptote}}
| + | [asy] |
| + | size(150); |
| + | real ticklen=3; |
| + | real tickspace=2; |
| | | |
− | ==Troubleshooting== | + | real ticklength=0.1cm; |
− | '''Problem 1:''' You have added the Asymptote tool to TeXnicCenter, but when you hit your hotkey, you get an 'Cannot execute the command' error.
| + | real axisarrowsize=0.14cm; |
| + | pen axispen=black+1.3bp; |
| + | real vectorarrowsize=0.2cm; |
| + | real tickdown=-0.5; |
| + | real tickdownlength=-0.15inch; |
| + | real tickdownbase=0.3; |
| + | real wholetickdown=tickdown; |
| + | void rr_cartesian_axes(real xleft, real xright, real ybottom, real ytop, real xstep=1, real ystep=1, bool useticks=false, bool complexplane=false, bool usegrid=true) { |
| + | import graph; |
| + | real i; |
| + | if(complexplane) { |
| + | label("<math>\textnormal{Re}</math>",(xright,0),SE); |
| + | label("<math>\textnormal{Im}</math>",(0,ytop),NW); |
| + | } else { |
| + | label("<math>x</math>",(xright+0.4,-0.5)); |
| + | label("<math>y</math>",(-0.5,ytop+0.2)); |
| + | } |
| | | |
− | '''What might be going on:''' TeXnicCenter doesn't see the Asymptote executable.
| + | ylimits(ybottom,ytop); |
| + | xlimits( xleft, xright); |
| + | real[] TicksArrx,TicksArry; |
| | | |
− | '''Possible Solution:''' Go back to the Tools -> Customize window (click Tools, then Customize in TeXnicCenter). Then, click the Tools tab, then select Asymptote. Instead of cutting and pasting the text for the Command line, click the ... button after the Command entry box. Then, navigate to the asy.exe executable. You'll probably have to go up several levels to C:, then click Program Files, then Asymptote, then the file asy with the stylized red A next to it.
| + | for(i=xleft+xstep; i<xright; i+=xstep) { |
| + | if(abs(i) >0.1) { |
| + | TicksArrx.push(i); |
| + | } |
| + | } |
| + | for(i=ybottom+ystep; i<ytop; i+=ystep) { |
| + | if(abs(i) >0.1) { |
| + | TicksArry.push(i); |
| + | } |
| + | } |
| | | |
| + | if(usegrid) { |
| + | xaxis(BottomTop(extend=false), Ticks("%", TicksArrx ,pTick=gray(0.22),extend=true),p=invisible);//,above=true); |
| + | yaxis(LeftRight(extend=false),Ticks("%", TicksArry ,pTick=gray(0.22),extend=true), p=invisible);//,Arrows); |
| + | } |
| + | if(useticks) { |
| + | xequals(0, ymin=ybottom, ymax=ytop, p=axispen, Ticks("%",TicksArry , pTick=black+0.8bp,Size=ticklength), above=true, Arrows(size=axisarrowsize)); |
| + | yequals(0, xmin=xleft, xmax=xright, p=axispen, Ticks("%",TicksArrx , pTick=black+0.8bp,Size=ticklength), above=true, Arrows(size=axisarrowsize)); |
| | | |
− | '''Problem 2:''' I have everything installed and the hotkey doesn't give me an error in TeXnicCenter, but when I hit the hotkey to compile my code, all that happens is that a window flashes briefly then disappears. Nothing else seems to happen.
| + | } else { |
− | | + | xequals(0, ymin=ybottom, ymax=ytop, p=axispen, above=true, Arrows(size=axisarrowsize)); |
− | '''What might be going on:''' Your file is saved as a .tex file, not a .asy file. (TeXnicCenter will even make it look like it's an .asy file, but it's really saved as an .asy.tex file.)
| + | yequals(0, xmin=xleft, xmax=xright, p=axispen, above=true, Arrows(size=axisarrowsize)); |
− | | + | } |
− | '''Solution:''' Click file, then Save As, then type your filename with the .asy extension (such as test.asy), the set the 'Save as type' field to 'All files'. This should make it a .asy file.
| + | }; |
− | | + | rr_cartesian_axes(-5,5,-5,6); |
− | If this does not work then (for Windows XP) go to My Computer, Tools, Folder Options..., File Types. Click on New and type ASY, then OK. Making sure that the file type ASY is highlighted, click the Change button to the right of "Opens with:". From here go to browse and find the Asymptote executable program file click Open then OK. Now, retry the File, Save As extension change method outlined above.
| + | draw((-4,4)--(-1,0)--(0,2)--(4,-4),red); |
− | | + | [/asy] |
− | It would also help to show file extensions so that <tt>file.tex, file.asy, file.pdf</tt> aren't all listed in Explorer and Save boxes as <tt>file</tt>.
| |
− | | |
− | [http://teamtutorials.com/windows-tutorials/show-file-extension-in-windows-xp Show File Extension in Windows XP] gives a simple walkthrough to show how to do this.
| |
− | | |
− | | |
− | '''Problem 3:''' You can draw images with Asymptote, but it doesn't compile your file whenever you have a label containing LaTeX code (for example, the line <tt>label("<math>P</math>",(50,50),S);</tt> as in test.asy.)
| |
− | | |
− | '''What might be going on:''' Either Asymptote is not finding your LaTeX compiler, or you have installed your TeX distribution (such as MikTeX) in a folder that Asymptote cannot find.
| |
− | | |
− | '''Solution:''' Let's say you installed miktex in the folder <tt>C:\Program Files\MiKTeX 2.6</tt> (the default). (If you have a different version of MiKTeX, change the 2.6 to the appropriate number. Look in C:\Program Files for the MiKTeX directory to see what this number should be.) Then there should be a subfolder miktex, containing the folder bin, which contains your latex compiler.
| |
− | When Asymptote is run, it looks for a file called config.asy in the folder
| |
− | <tt>C:\Documents and Settings\%USERNAME%\.asy\</tt>
| |
− | where <tt>%USERNAME%</tt> is your Windows user name. (In Windows Vista, this folder is <tt>C:\Users\%USERNAME%\.asy\</tt>, where <tt>%USERNAME%</tt> is your Windows username.)
| |
− | Double-click on the .asy folder, right click and choose New <math>\rightarrow</math> Text Document. This will create a file called New Text Document.txt. Right-click on this file to rename it as config.asy, then open this file with Notepad or a similar editor. Type or copy-and-paste the following lines into the document:
| |
− | import settings;
| |
− | texpath="C:\Program Files\MiKTeX 2.6\miktex\bin";
| |
− | dvips="C:\Program Files\MiKTeX 2.6\miktex\bin\dvips";
| |
− | When you have finished, save the file config.asy.
| |
− | | |
− | As mentioned in the solution to Problem 1, you must make sure that the config.asy file is an ASY file, and not a TXT file that is named config.asy. Look in the File Type column in the Details view to see what type of file config.asy is. If your regular text editor insists on making config.asy a TXT document, use TeXnicCenter to create config.asy.
| |
− | | |
− | | |
− | '''Problem 4:''' You run Asymptote and get <tt>error: could not load module 'plain'</tt>.
| |
− | | |
− | '''What might be going on:''' Asymptote cannot find the files it needs to run. It may need telling which directory it is installed in.
| |
− | | |
− | '''Solution:''' You need to create or edit the config.asy file. See the solution to Problem 3 for how to find or create it. Assuming that Asymptote is installed at <tt>C:\Program Files\Asymptote</tt> then
| |
− | | |
− | a) if you already have a config.asy file add the following line somewhere after "import settings;":
| |
− | dir="C:\Program Files\Asymptote";
| |
− | ''or''
| |
− | | |
− | b) if you have created a new config.asy file then add the following lines:
| |
− | import settings;
| |
− | dir="C:\Program Files\Asymptote";
| |
− | | |
− | See the note at the end of Problem 3 regarding creating config.asy.
| |
− | | |
− | | |
− | '''Problem 4b:''' You run Asymptote and get<br/>
| |
− | <tt>error: could not load module 'plain'<br/>
| |
− | error: could not load module 'file'</tt>.
| |
− | | |
− | '''What might be going on:''' Asymptote does not like file names that contain spaces.
| |
− | | |
− | '''Solution:''' Replace all spaces in the file name with underscores.
| |
− | | |
− | | |
− | '''Problem 5:''' Asymptote suddenly starts misbehaving giving strange errors, going into infinite loops, and not recognizing standard package commands.
| |
− | | |
− | '''What might be going on:''' A file with the same name as one of the standard package files (like graph.asy or math.asy) was created either by you or by <math>\LaTeX</math> in your working directory or some other directory which Asymptote searches before going to its own directory, so that file is imported instead of the package file.
| |
− | | |
− | '''Prevention:''' Never name your asy or tex files graph.asy, math.tex and such (these two names seem to be the most common)
| |
− | | |
− | '''Solution:''' Find all extra files with the same name as standard packages and either .asy or .tex extension and rename or delete them.
| |
− | | |
− | ==External Sources==
| |
− | The following are excellent resources on Asymptote for topics not covered in this guide:
| |
− | | |
− | *[http://asymptote.sourceforge.net The Asymptote home page]
| |
− | * [http://asymptote.sourceforge.net/doc/ Asymptote documentation]
| |
− | * [http://asymptote.sourceforge.net/FAQ/ Asymptote FAQ]
| |
− | * [http://sourceforge.net/forum/forum.php?forum_id=409349 Asymptote forum]
| |
− | | |
− | [[Asymptote: Useful functions|Next: Useful functions]]
| |
[asy]
size(150);
real ticklen=3;
real tickspace=2;
real ticklength=0.1cm;
real axisarrowsize=0.14cm;
pen axispen=black+1.3bp;
real vectorarrowsize=0.2cm;
real tickdown=-0.5;
real tickdownlength=-0.15inch;
real tickdownbase=0.3;
real wholetickdown=tickdown;
void rr_cartesian_axes(real xleft, real xright, real ybottom, real ytop, real xstep=1, real ystep=1, bool useticks=false, bool complexplane=false, bool usegrid=true) {
import graph;
real i;
if(complexplane) {
label("",(xright,0),SE);
label("",(0,ytop),NW);
} else {
label("",(xright+0.4,-0.5));
label("",(-0.5,ytop+0.2));
}
ylimits(ybottom,ytop);
xlimits( xleft, xright);
real[] TicksArrx,TicksArry;
for(i=xleft+xstep; i<xright; i+=xstep) {
if(abs(i) >0.1) {
TicksArrx.push(i);
}
}
for(i=ybottom+ystep; i<ytop; i+=ystep) {
if(abs(i) >0.1) {
TicksArry.push(i);
}
}
if(usegrid) {
xaxis(BottomTop(extend=false), Ticks("%", TicksArrx ,pTick=gray(0.22),extend=true),p=invisible);//,above=true);
yaxis(LeftRight(extend=false),Ticks("%", TicksArry ,pTick=gray(0.22),extend=true), p=invisible);//,Arrows);
}
if(useticks) {
xequals(0, ymin=ybottom, ymax=ytop, p=axispen, Ticks("%",TicksArry , pTick=black+0.8bp,Size=ticklength), above=true, Arrows(size=axisarrowsize));
yequals(0, xmin=xleft, xmax=xright, p=axispen, Ticks("%",TicksArrx , pTick=black+0.8bp,Size=ticklength), above=true, Arrows(size=axisarrowsize));
} else {
xequals(0, ymin=ybottom, ymax=ytop, p=axispen, above=true, Arrows(size=axisarrowsize));
yequals(0, xmin=xleft, xmax=xright, p=axispen, above=true, Arrows(size=axisarrowsize));
}
};
rr_cartesian_axes(-5,5,-5,6);
draw((-4,4)--(-1,0)--(0,2)--(4,-4),red);
[/asy]