2

I'm a newbie to asymptote, using it to create geometry figures. I'm creating an eps file from asymptote code, and include that in tex document instead of including the entire code in asy environment.

This works fine as long as I do not use labels on points. The moment I use labels on points, the pdf file is messed up. The image is completely shifted to right. I tried using \centering as well. Nothing worked.

The sample asy file is here.

    import math;
    import geometry;
    import patterns;
    import settings;

    settings.outformat="eps";
    settings.render=0;
    settings.prc=false;
    unitsize(1cm);

    real r = 2.0;
    point o = (0,0);
    circle c = circle(o, r);
    point a = angpoint(c,0);
    point first=a;
    point last;
    draw(c);
    for(int i = 1; i<=6; ++i) {
      real ang = i*60;
      point p = angpoint(c, ang);
      draw(compassmark(a,p,0.5));
      dot(a);
      if (i==3){
        last=p;
      }
      draw(a--p);
      a=p;
    }

    draw(first--last);
    dot(a);
    dot(o);
//    label("$O$",o,N);

If I uncomment the label statement, the image in pdf is messed up. What am I missing ?

My tex file looks like this

\documentclass[12pt]{book}

\usepackage{graphicx}

\begin{document}
  \begin{figure}[htbp]
    \centering
      \includegraphics{test.eps}{\caption{}}
  \end{figure}
\end{document}

I'm using asymptote 2.35 and lualatex.

6
  • lualatex is throwing up an error message about float being too long. Latex Warning: Float too large for page by 273.30138pt on input line 9
    – Surya
    Jun 5, 2015 at 10:01
  • 1
    It looks like a problem with the EPS figure's bounding box, when a label is introduced in it. I've no idea about where it comes from… A workaround is to convert this figure to the PDF format before including it in your LaTeX file, i.e. inserting settings.outformat="pdf"; in your asy file. Jun 5, 2015 at 10:11
  • I too suspected the bounding box of the generated eps. The settings.outformat="pdf" works though. Thanks.
    – Surya
    Jun 5, 2015 at 10:18
  • You're welcome! It would certainly interest Asymptote's developers if you tell them about this weird bug, e.g. on their forum: sourceforge.net/p/asymptote/discussion/409349 Jun 5, 2015 at 10:27
  • I'll definitely.
    – Surya
    Jun 5, 2015 at 10:30

1 Answer 1

1

The issue is:

  1. When Asymptote generates eps figures with labels, it calls latex to typeset the label and then dvips to generate the eps file. Asymptote used to call dvips without the option '-E', and this used to work. But with changes in dvips, it fails with some invalid setpagedevice code into the eps file, including a bounding box value for letter (or A4) size paper. So the resulting eps file has two bounding box lines, and the first one is incorrect.

  2. When lualatex compiles the tex file, it calls epstopdf to automatically convert the eps figure to pdf for inclusion. epstopdf somehow uses the incorrect bounding box values and generates a pdf figure with letter (or A4) page size. Including such a big figure results in "Float too large" warning, and the real figure object shifts to right since to its left is blank spaces treated as part of figure.

So the real fix is either:

  1. Make dvips do not generate those bound box lines, or let Asymptote remove them automatically afterwards, resulting an eps figure with only the correct bounding box line. The issue has been fixed in Asymptote by calling dvips with '-E'.

  2. Make epstopdf smarter to detect the right bounding box even the eps file may have wrong bounding box lines. This might not happen.

Before that happens, the possible walkarounds are:

  1. Use pdf figures directly. Asymptote can generate pdf figures with -f pdf option and lualatex/pdflatex can include them directly.

  2. If one has to use eps figures, consider to

    1. Use asymptote to generate pdf directly, and then use pdftops to convert it back to eps. Or,
    2. Use asymptote to generate the eps figure, and edit the eps figure with an text editor to manually remove the wrong bounding box lines.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .