25

I have recently started using LaTeX and have found it amazing. I now use LaTeX for all my documents :). However, now that I need to include some graphs and diagrams in my documents, I have found the Asymptote package, and seen that it is very powerful. I am having some issues using it though.

Firstly I would like to know the syntax for embedding asymptote code into LaTeX, and secondly if there is any convenient way to compile the whole document, in one command, I used to do my diagrams in mathematica, where I would import the picture and compile the whole document with a single pdflatex command.

doncherry
  • 54,637
RayQuang
  • 353

3 Answers3

24

For embedding Asymptote code in a LaTeX file, you can use the asymptote LaTeX package:

\usepackage[inline]{asymptote}

For document global Asymptote definitions use the asydef environment:

\begin{asydef}
...
\end{asydef}

For your Asymptote code use the asy environment, possibly within a figure environment with caption:

\begin{asy}
...
\end{asy}

Run (pdf)LaTeX, then Asymptote, then (pdf)LaTeX again, such as:

pdflatex filename
asy filename-1.asy
pdflatex filename

For a convenient way, you can use latexmk.

For more information, have a look at 7 LaTeX usage in the Asymptote documentation. There's a complete LaTeX example with several Asymptote graphs and a How-to for compiling and using latexmk.

Stefan Kottwitz
  • 231,401
  • could you please elaborate on how to configure latexmk for smooth compilation? It seems the links to latexmkrc are broken. – juliohm Oct 22 '13 at 10:57
  • @juliohm Perhaps post it as a new question - I don't use latexmk myself. – Stefan Kottwitz Oct 22 '13 at 12:05
  • My mistake, the file latexmkrc is still there in the repository under the doc/ directory. All the user has to do is copy it to the project directory. – juliohm Oct 22 '13 at 22:04
5

You will find a guide to using Asymptote in LaTeX documents at Art of Problem Solving Wiki. They also have an Asymptote forum which allows you to render Asymptote code in the posts.

stevem
  • 615
0

If you don't must use asymptote you can find many other solution to use graphics in LaTeX. Please check TikZ and PSTricks. I think you'll find many useful examples and packages.

uzsolt
  • 1,431