Setting up Asymptote

Of all the hubs, this seemed to me the most suitable for this topic. So.



Copied from my blog in order to create another Russian-language source of information on this topic.



I will describe this process for Asymptote 2.35. So, here I downloaded this program, installed. If we want to use this program in full, then the next step for this is to connect it with  TeX (I am making a description for the implementation I am using  TeX 'a - MiKTeX2.9, assuming that this program is installed and configured properly: a repository is connected to it, installation of packages on the fly is selected, etc.). I assume that during the installation of Asymptote and MiKTeX, the folders in which it was suggested by the installers of these programs to create files of these programs were not changed by the user. Then open the folder C:\Program Files\Asymptote



, it contains the files asycolors.sty and asymptote.sty . Open the folder C:\Program Files\MiKTeX 2.9\tex\latex



, create the asycolors and asymptote folders in it and copy the sty files of the same name mentioned above to these folders. Do not forget to go to Start> MiKTeX2.9> Maintenance (Admin)> Settings (Admin) and there, click Refresh FNDB , Update Formats , Ok . That's it, Asymptote knows where TeX is . I will make a small digression from listing the necessary third-party components for Asymptote. In TeXworks, purely on intuition, I created such an Asymptote layout tool:



image



And now I can open .asy files in TeXworks and process these files with mine tool. All the resulting files, including the final .pdf with the created images, animations, .mpg files (see below) are formed in one folder with the processed .asy file, regardless of the presence / absence of animated graphics codes in this file.



I note that in the window shown in the photo titled “TeXworks Settings” in the “Paths to TeX and related programs” section, the path to the Asymptote program folder was not added either manually or by the system automatically while using the Asymptote tool I created. When opening .asy files in Explorer:



image



these files, as you would expect from the title bar of the command line window, which displays information about the progress of processing, are formed in the C:\Windows\System32



, also regardless of the presence / absence of animation in this file. Next, you need the ghostscript program. This program is necessary for the normal construction of graphics even from .asy files, in which there is no animation. I am generally silent about animation. I am using ghostscript version 9.23 with Asymptote 2.35. As for the version of Asymptote itself, I was overclocked and installed version 2.45. So what? When testing the codes from the Asymptote examples folder that did not even contain animation (I simply couldn’t turn the animation files into .pdf), I could not get .pdf from a larger number of .asy files than when using version 2.35, even when installing a newer one ghostscript versions. I tinkered, tinkered, spat, deleted all these updated versions and did as it was. So, then you need to install imagemagick . I gave the link not to the project home page, but to the page from which you directly need to download the installation file. Here was the problem too: for a long time I could not decide which file to download for Windows7. And so, and so, and there’s nowhere to read what exactly needs to be installed for Asymptote. Then at random I downloaded ImageMagick-7.0.8-42-Q16-x86-dll.exe . When it was not there, processing .asy files with animations, the output format of which is .pdf, did not cause any errors at all. The absence of this program made itself felt when trying to get the animated .gif file from the wheel.asy file with the following error on the command line (for example, I took the processing of the wheel.asy file, descriptions of errors when getting .gif from other .asy files also look, differences only in, perhaps, the values ​​of an invalid parameter):



image



An attempt to process this file in TeXworks with the Asymptote tool mentioned above gave the following error:



image



After quite a long search of information on the Internet, and even then only on English-language sites, forums, I managed to find out that I do not have ImageMagick on my computer.



IMPORTANT MOMENT: IN PATH, THE PATH TO THIS PROGRAM MUST STAND BEFORE THE SYSTEM32 FOLDER.



, because ImageMagick uses the convert.exe utility when processing .asy files with animation, and a file with exactly the same name exists in the system32 folder and when system32 is in front of ImageMagick in the PATH, the system, when this file is called, ImageMagick does not look for the convert.exe file in the ImageMagick program folder, and in the system32 folder and successfully finds it, only the use of this file for these purposes does not end in success, but in the error described above. John Bowman himself speaks about this problem here , in the second replica of 2016-05-12:



image



I took this picture after translating this page into Russian in the Google browser. I found this now and the answer below the interlocutor confirms the correctness of my guess on how to weave the convert.exe file from the ImageMagick program folder into Asymptote. Yes, if it were not for the translator of this browser, I doubt that I would write this article. If we want to use well, to the fullest, then we still need to download ffmpeg . The absence of this program made itself felt only when I tried to process the earthmoon.asy file, from which I conclude that Asymptote only needs this program to process .asy files with animations, the output format of which is .mpg. So, if you do not use it other than Asymptote, then most likely you will use it quite rarely. Nevertheless, I’ll tell you how to do it, especially since at the same time I will touch upon the moment that we will need in the future. So, click on the link above. Next, click on the buttons circled in orange rectangles in the following photo:



image



Download this archive, unpack it. I, because I needed to add the bin folder of this program to PATH, so as not to clog it with unnecessary letters, unpacked it directly to :\



. If you did this too, then add the line C: \ ffmpeg-4.1.3-win32-shared \ bin to PATH. Unlike ImageMagick, the position of ffmpeg in PATH relative to the path to the system32 folder does not matter, just as, by the way, this position does not matter with respect to the path to the ImageMagick program folder. I understand that when Asymptote includes ffmpeg, the file ...\ffmpeg-4.1.3-win32-shared\bin\ffmpeg.exe



. The file ffmpeg.exe is also located in the ImageMagick program folder, however, when requesting, for example, a version, an error is generated, so I got the impression that this file in this particular version of ImageMagick is defective and that’s why we needed it install also the ffmpeg program: we just added a workable ffmpeg.exe file to the computer, which is necessary to get the .mpg format, and if this ImageMagick file worked, the ffmpeg program would not be needed at all. However, this is my personal opinion, which at the moment I can’t confirm with anything. However, the presence of the ffmpeg.exe file in the ImageMagick program folder initially caused a problem: on the one hand, it seems that obtaining .mpg without ImageMagick is impossible at all, because when it was excluded from PATH (but with the presence of ffmpeg in PATH) nothing happened. So, first, this program comes into play. Well, since she got down to business, she pulls her ffmpeg.exe file (even if the path to ffmpeg.exe is located in the PATH before the path to ImageMagick), but it does not work. And so nothing happened. And again, this is just my conclusion. And the way out of this problem was a simple deletion of the ffmpeg.exe file from the ImageMagick program folder.



While studying earthmoon.asy file processing technology from the animations subfolder of the examples folder, the following detail was identified. After installing the ffmpeg program by the steps described above and adding it to PATH, opening this file to get .mpg from it in the explorer (see above) turned out at a time, and processing in TeXworks - well, not at all! And so, and so - no way! It turned out that the point is the secret config.asy file, even for an English-speaking user. What it is? This is an ordinary file with the extension .asy and the name config . The creators of Asymptote assumed that if the user reaches such a level of ownership of their program when he needs this file, then most of his needs will be satisfied if this file is in the same folder. This folder is created when you install Asymptote. For example, if the user installed this program while in the IVAN account, the absolute path to this folder will be as follows: C:\Users\\.asy



. This is not a problem for English-speaking users: all the letters in the full path to this folder most likely contain only Latin letters and the Asymptote program can easily find the config.asy file. However, if the user is Russian-speaking, then, most likely, the name of the account under which he uses the computer is written in Cyrillic letters. And therefore Asymptote cannot find this folder, which means it cannot find the config.asy file either. But again, this is my explanation of the behavior of Asymptote, and I'm not a programmer or even a fan of programming (although I can’t say that I really don’t like programming). It would seem a dead end. But, fortunately, the creators of Asymptote have addressed this possible problem. They made sure that this program before looking for the config.asy file in the C:\Users\...\.asy



, where the C:\Users\...\.asy



is instead of the ellipsis, looks for it in the folder with the .asy file being processed. So, when processing the earthmoon.asy file, I began to create a config.asy file with the following contents in the same folder with it:

 import settings; convert ="C:\Program Files\ImageMagick-7.0.8-Q16\convert.exe";
      
      





and only after that everything started to work out for me. In truth, I later realized that you can do without the config.asy file: if I included the lines in the earthmoon.asy file

 settings.convert ="C:\Program Files\ImageMagick-7.0.8-Q16\convert.exe";
      
      





or if I inserted the lines from the config.asy file that I brought directly into the earthmoon.asy file and if the config.asy file was not in the folder with this file, it would not change anything: when processing such an earthmoon.asy file, it turns out exactly the same workable .mpg file. At some stage of processing in TeXworks files with the output .mpg format in the folder with this .asy file, the following disgrace is observed (when I took the picture, the earthmoon.asy file was processed, in which I speed up the process and reduce the number of generated files set earthmoon.asy to n equal to 4):



image



This indicates that Asymptote has connected ImageMagick to the process and everything is going as it should. And when Asymptote ends, all files with these terrible names disappear and only 3 files remain in the folder - 2 files that were there from the very beginning: the config.asy file and the .asy file, from which the .mpg file was made and, in fact, the .mpg file itself. I note that, in addition to the environment variable convert, there are other environment variables gs, pdfviewer, texpath, dvips and, for example, python , the values ​​of which can be specified in the config.asy configuration file and, apparently, these are not all such variables (values these variables are paths, and that's why I mention them along with the mention of the variable convert).



Fuh, I don’t seem to have missed anything.



All Articles