[Tex/LaTex] Using Asymptote with MiKTeX

asymptoteinstallingmiktex

Asymptote is shipped out with TeX Live, but not with MiKTeX, not even with a full installation.

Do you nonetheless know a way for manual installation? MiKTeX needs to know the path of the sty files, and the Asymptote binary file needs to know the path of the asy scripts. Thought of adding the Asymptote folder to the list of registered root directories in MiKTeX, but MiKTeX complains, that this would be “Not a TDS-compliant root directory”.

There is already a similar question: Using MikTex Portable, TexMaker, and Asymptote from a USB drive.

Best Answer

First, there is a description in the Art of Problem Solving Wiki, Asymptote: Advanced Configuration – Using Asymptote in LaTeX (also linked in the question regarding portable use), we can partly adapt, but in one point I want to strongly discourage you following this: Instead you should install the sty files in a local texmf tree, about the reasons you can read in Purpose of local texmf trees.

This will be successful (WinEdt users read Harish Kumar’s answer first, please):

  • Download Asymptote from http://sourceforge.net/projects/asymptote/files/ and install, where you want. I will use here C:\Program Files\Asymptote.

    The binary in TeX Live is newly built from sources, has some dependencies of other TeX Live binaries and find its asy scripts with the builtin kpsewhich mechanism. Hence in difference to How to use Xindy with MiKTeX? the installation from TeX Live files is not recommended.

  • If not already done Create a local texmf tree in MiKTeX.

  • Create a subfolder <localtexmf>\tex\latex\asymptote and copy the three sty files from the Asymptote main directory in it.

  • Create an empty file in <localtexmf>\bin\ with the name asymptote.bat (or with extension .cmd).

    Copy the following, paste it into the batch file and adjust the path according to your setting:

    @echo off
    SETLOCAL
    
    SET AsyPATH=C:\Program Files\Asymptote
    SET PATH=%AsyPATH%;%PATH%
    
    asy.exe %*
    

    This will also ensure, that the Asymptote binary finds the preshipped script files. A remark: When you save the file in Notepad or Wordpad, make sure, that there is no automatic appending of TXT extension – save the file name with double quotes: "asymptote.bat".

  • Refresh the file name database (FNDB). BTW I assume here, that you followed the instructions and added <localtexmf>\bin to the system path. Actually the batch script could be put elsewhere, as long as it was in the system path.

  • Asymptote needs also Ghostscript. You have 3 specific opportunities to make it known (adjust path, of course):

    • Directly adding the command line option
      -gs="<path\to\ghostscript>\bin\gswinc32.exe".
    • Adding the environment variable

      ASYMPTOTE_GS=<path\to\ghostscript>\bin\gswinc32.exe.
      (Note, that this did actually not work in my computer, but I didn’t restart.)

    • The preferred variant for frequent users: Create a file config.asy in Asymptote’s main directory with following content

      import settings;
      gs="<path\to\ghostscript>\bin\gswinc32.exe";
      

Now you can execute Asymptote in your actual work folder. Let’s make a test: Copy the file latexusage.tex from Asymptote’s examples subfolder into a test folder, I will use c:\test here. Open the Command Prompt and execute

cd /d c:\test,

the /d switch ensures, that you can also change in one step to another drive.

Then compile with your TeX editor or execute

latex latexusage.

This will create 3 asy script files. These 3 files must now be executed with

asymptote latexusage-1.asy

(you could also omit the file extension) and so on for the others.

Then again compile with your TeX editor or execute

latex latexusage.

The result must look as shown below (I cropped it a bit). In Adobe Reader the interactive example works fine as well.

example output