1

I have a document.tex file:

\documentclass{article}
\usepackage{asymptote}

\begin{document}

\begin{figure}
  \centering
  \asyinclude{test.asy}
  \caption{A test with \textsf{asymptote}}
\end{figure}

\end{document}

And a test.asy file:

unitsize(1cm);
draw((0,0)--(5,5));

This is the output when compiling via Sharelatex:

compiled with sharelatex

This is the output when compiling via local pdflatex:

compiled with pdflatex

(the second screenshot has the caption at the exact center of the screen)

Why doesn't it work locally?

  • The compilation is (PDF)latex -> asy -> (PDF)latex. Is it your case ? – O.G. May 8 '15 at 7:40
  • I compiled by issuing pdflatex document.tex – wil93 May 8 '15 at 7:42
  • 1
    First pdflatex compilation produces also an asy file, second asy compilation produces the PDF picture, third pdflatex compilation you obtain the final document. – O.G. May 8 '15 at 8:34
  • Oh OK, I'll try. Can I automate this process in some way? latexmk? – wil93 May 8 '15 at 8:37
  • 1
    You can also use the asypictureB package, which calls asy directly from latex. But you need to enable shell-escape for this to work. – Charles Staats May 8 '15 at 16:33
2

Thanks to user O.G. I've found out how to make it work.

It's enough to create (in the same folder as the document.tex file) a file named latexmkrc with the following content:

sub compile_asy { return system("asy \"$_[0]\""); }
add_cus_dep("asy", "eps", 0, "compile_asy");
add_cus_dep("asy", "pdf", 0, "compile_asy");
add_cus_dep("asy", "tex", 0, "compile_asy");

Once this is done, it's enough to issue:

$ latexmk -pdf document.tex

Note: if you don't have latexmk, install it. If you can't install it, you will have to issue 3 commands instead of 1:

$ pdflatex document.tex
$ asy *.asy
$ pdflatex document.tex
0

By default, asymptote produces PostScript output. You have to configure the package for pdflatex by setting some variables (cut from the asymptote manual p. 162)

outformat="pdf";

See the asymptote documentation for the details where to put this (under Linux, it would be the file ~/.asy/config.asy )

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.