Insert an EPS file into an Asymptote Vector Graphics document

It’s surprisingly difficult to find out whether it is possible to include an image from an Encapsulated PostScript (EPS) file into an Asymptote vector graphics document. It turns out that it is easy, but difficult to find in the Asymptote docs (I finally found the answer, via Google, in the FAQ). It turns out that you use the label function to insert an image into an Asymptote document. Here is a snippet of code that I used to assemble a multi-part figure from several EPS documents:

unitsize(1 inch);
size(3.33 inches);

pen label_pen = black + fontsize(16pt) + Helvetica();

label("(A)", (0.0, 0.3),p=label_pen, align=NE);
label(graphic("subfig1.eps"), (0.35, 0.0), align=NE);

label("(B)", (0.0, 1.1), align=NE, p=label_pen);
label(graphic("subfig2.eps"), (0.35, 0.75), align=NE);

label("+", (0.0, 0.0), align=NE);
label("+", (3.33, 2.0), align=SW);

The alignment is tricky! Note that I used an alignment of NE, which means that the label (text or graphic) will be placed to the UPPER RIGHT (NorthEast) of the specified point. This allows me use the left boundary of the image as 0.0 and insert everything to the right. I added two + signs, which would not normally be present, to show the extents of the image. If you create something that extends beyond the limits, Asymptote will silently increase the size of the canvas to accommodate it, despite the “size” directive! This is dangerous when you are working within a journal’s style guide. Thus, I used SW as the alignment for the upper right + sign, so that the + will lie entirely within the desired dimensions. You can check the actual dimensions of the final EPS file by opening it (I used Document Viewer in Linux) and checking the Properties.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.