I am trying to compile the following document, a sligtly modified version of the sample document in chapter 7 of the asymptote documentation (https://asymptote.sourceforge.io/doc/LaTeX-usage.html#LaTeX-usage ).


% Use this form to include EPS (latex) or PDF (pdflatex) files:
% \usepackage{asymptote}

% Use this form with latex or pdflatex to include inline LaTeX code by default:

% Use this form with latex or pdflatex to create PDF attachments by default:
% \usepackage[attach]{asymptote}

% Enable this line to support the attach option:
% \usepackage[dvips]{attachfile2}


% Optional subdirectory for latex files (no spaces):
% Optional subdirectory for asy files (no spaces):

  // Global Asymptote definitions can be put here.
  import three;
  // One can globally override the default toolbar settings here:
  // settings.toolbar=true;

Here is a venn diagram produced with Asymptote, drawn to width 4cm:

      pen colour1=red;
      pen colour2=green;

      pair z0=(0,0);
      pair z1=(-1,0);
      pair z2=(1,0);
      real r=1.5;
      path c1=circle(z1,r);
      path c2=circle(z2,r);

      picture intersection=new picture;



      draw("$\A$",box,z1);              // Requires [inline] package option.
      draw(Label("$\B$","$B$"),box,z2); // Requires [inline] package option.

      pair z=(0,-2);
      real m=3;
      margin BigMargin=Margin(0,m*dot(unit(z1-z),unit(z0-z)));

      draw(Label("$A\cap B$",0),conj(z)--z0,Arrow,BigMargin);
      draw(Label("$A\cup B$",0),z--z0,Arrow,BigMargin);

    \caption{Venn diagram}\label{venn}

Each graph is drawn in its own environment. One can specify the width
and height to \LaTeX\ explicitly. This 3D example can be viewed
interactively either with Adobe Reader or Asymptote's fast
OpenGL-based renderer. To support {\tt latexmk}, 3D figures should
specify \verb+inline=true+. It is sometimes desirable to embed 3D
files as annotated attachments; this requires the \verb+attach=true+
option as well as the \verb+attachfile2+ \LaTeX\ package.

One can also scale the figure to the full line width:
% \begin{center}
%   \begin{asy}[width=\the\linewidth,inline=true]
%     pair z0=(0,0);
%     pair z1=(2,0);
%     pair z2=(5,0);
%     pair zf=z1+0.75*(z2-z1);

%     draw(z1--z2);
%     dot(z1,red+0.15cm);
%     dot(z2,darkgreen+0.3cm);
%     label("$m$",z1,1.2N,red);
%     label("$M$",z2,1.5N,darkgreen);
%     label("$\hat{\ }$",zf,0.2*S,fontsize(24pt)+blue);

%     pair s=-0.2*I;
%     draw("$x$",z0+s--z1+s,N,red,Arrows,Bars,PenMargins);
%     s=-0.5*I;
%     draw("$\bar{x}$",z0+s--zf+s,blue,Arrows,Bars,PenMargins);
%     s=-0.95*I;
%     draw("$X$",z0+s--z2+s,darkgreen,Arrows,Bars,PenMargins);
%   \end{asy}
% \end{center}

testing, testing, testing


%%% Local Variables:
%%% mode: latex
%%% TeX-master: t
%%% End:

I have this in my latexmkrc file:


sub asy2eps { return asy2x( $_[0], 'eps' ); }
sub asy2pdf { return asy2x( $_[0], 'pdf' ); }
sub asy2tex { return asy2x( $_[0], 'tex' ); }

sub asy2x   {
   # system("echo > '$_[0].log'");
   # print "$_[1] $_[0]\n";
   system("/tmp/printargs.sh -vv -f '$_[1]' '$_[0]'");
   # system("asy --help");
   my $ret = system("asy -vv -f '$_[1]' '$_[0]' &> '$_[0].log'");
   # print "$ret\n";
   my $FH = new FileHandle;
   open $FH, "$_[0].log";
   %imp = ();

   while (<$FH>) {
       if (/^(Including|Loading) .* from (.*)\s*$/) {
          my $import = $2;
          $imp{$import} = 1;
       elsif ( /^error/ || /^.*\.asy: \d/ ) {
           warn "==Message from asy: $_";
           $ret = 1;
       elsif ( /^kpsewhich / || /^Processing / || /^Using /
               || /^Welcome / || /^Wrote /|| /^cd /|| /^gs /
             ) {
       else {
           warn "==Message from asy: $_";
   close $FH;
# For latexmk 4.48
   rdb_set_source( $rule, keys %imp );
   return $ret;

push @generated_exts, "asy";
push @generated_exts, "prc";
push @generated_exts, "pre";

I am compiling using:

I run it using:

latexmk -diagnostics -dvi- -ps- -pdf latexusage

I have pasted the output here: https://justpaste.it/23t6e

I don't understand why latexmk can't compile this simple document that is easily created by running pdflatex, asy, pdflatex (of course I am trying to get it to work for other more complicated document).

Another thing that I don't understand is why latexmk insists in generating dvi and ps documents if I explicitly disabled them.

Thanks, Edwin.

  • I've compiled your document with the same latexmkrc and I don't see the problems you mention. My system is an up-to-date TeXLive 2019, in apparently the same version as yours. Latexmk definitely did not generate a dvi file. But in the processing by asymptote, asymptote did run pdflatex with a command line that generated a dvi file latexusage-2_.dvi. (Note that asy later deletes that file.) Is it possible you have an obsolete version of asymptote that is invoked instead of the current version? – John Collins Jan 16 at 16:16
  • The output you link to appears to correspond not to the output of the run of latexmk, but to a log file generated by an invocation of pdflatex from asy applied to its generated file latexusage-2_.tex. (This file is normally deleted by asy unless you give it a -keep option.) The line with \usagepackage{ifluatex} shows that, since it's not in your document, but is in latexusage-2_.tex. But the details of the log file show that the command line was not the one used by the current version of asymptote. Again this suggests a culprit might be an out-of-date asy somewhere. – John Collins Jan 16 at 16:23

I have used the much simpler latexmkrc file:

sub asy2x {return system("asy '$_[0]'"); }

The command line I used is

latexmk -pdf test.tex

where test.tex is that sample file.

| improve this answer | |
  • I also reproduce this. But note that the latexmkrc given in the question is almost the same as asymptote-latexmkrc in the latexmkrc distribution, the modifications are only about extra diagnostics. That elaborate version enables latexmk to extract dependency information. – John Collins Jan 16 at 16:38

A couple of things were preventing latexmk from running correctly.

My system does have an older version of asymptote installed. Because of this, I changed the system call in the latexmkrc file to include the full path to the new asymptote binary, although it is first in the PATH environment variable so the new asymptote should have already been used.

Also, I was initially running latexmk through an ssh connection and, since asy needs to create a window to generate a figure, this will cause problems especially with 3D plots that seem to need OpenGL libraries. To be able to run asy (and thus latexmk) through an ssh connection, asy has to be called with the option -offscreen, which in turns requires the OSMesa library to be installed on the system.

I also had to do another change to the system call of asy in the latexmkrc file because '&>' was being misinterpreted. It was causing asy to be executed in the background while the log file was created but remained empty. This caused the execution to finish just after running asy. I know very little Perl but it seems that the code inside the while loop didn't execute because of this. So I changed that line to:

my $ret = system("/home/adf/usrnam/opt/bin/asy -vv -f '$_[1]' '$_[0]' > '$_[0].log' 2>&1");


I am running Ubuntu 18.04. I don't know if the misinterpretation of '&>' has something to do with the configuration of bash or Perl on my system.

| improve this answer | |

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.