I have many asymptote drawings in a .asy file whose generated pdf is included in a main.tex. I have many user-defined commands, like \vec or \vxi which I use in my current main.tex and I want to use them in the asymptote draw too. For example this curve uses them

settings.outformat = "pdf";
import graph;
// here I want to import my commands
defaultpen(font("T1", "fut\textfamilyextension","m","n"));

void pathlabel(picture pic = currentpicture, Label L, path g, 
real position=0.5, align align=NoAlign, bool sloped=false,
pen p=currentpen, filltype filltype=NoFill) {
Label L2 = Label(L, align, p, filltype, position=Relative(position));
if (sloped) {
    pair direction = dir(g, reltime(g, position));
    real angle = degrees(atan2(direction.y, direction.x));
    L2 = rotate(angle)*L2;
label(pic, L2, g);

pair F(real s) { return (s, 0.1 + s^4-3*s^3+2*s^2+s); }
path g = graph(F, 0.1, 1.9);
draw((-.1,0) -- (2.3,0), arrow=Arrow(TeXHead));
draw((0,-.1) -- (0,1.9), arrow=Arrow(TeXHead));
draw((0,0) -- (0.5,0.7875), arrow=ArcArrow(), lightgreen);
draw((0,0) -- (1.5,1.0375), arrow=ArcArrow(), lightgreen);
draw((0,0) -- (1.9,1.6751), arrow=ArcArrow(), lightgreen);
draw((0,0) -- (0.1,0.2171), arrow=ArcArrow(), lightgreen);
dot((0.1,0.2171), red);
dot((1.9,1.6751), red);
dot((0.5,0.7875), heavygreen);
dot((1.5,1.0375), heavygreen);
pathlabel("$\vxi^k(0,t) = \vec{x}_1^{(k)}(t)$", g, (0.01));
pathlabel("$\vxi^k(1,t)= \vec{x}_n^{(k)}(t)$", g, (1.9));
pathlabel("$\vxi^k(s,t)$", g, (0.6));
pathlabel("$\vec{x}_i^{(k)}(t)$", g, (0.28), deepgreen);
pathlabel("$\vec{x}_j^{(k)}(t)$", g, (0.74), deepgreen);

I have separated the commands from main.tex to a file called commands.tex, so for example in main.tex i use include{commands} to load them. What should I do to import the commands into the .asy?

  • 2
    You have (at least) two options: 1) Use the asymptote package with the inline option. 2) Near the beginning of your Asymptote file, include the line texpreamble("\include{commands}");. May 30, 2015 at 1:50
  • @CharlesStaats There are many drawings involved, so a texpreamble is short and better. Thanks! Please consider to put your comment as answer. May 30, 2015 at 1:58
  • Although @CharlesStaats was able to answer your question, please consider including a minimal working example (meta.tex.stackexchange.com/questions/228/…) to make it easier for people to help you. And welcome to TeX.SE! May 30, 2015 at 2:01

1 Answer 1


Well, I will answer this question. In my asymptote file, at the very first lines, I added as recommended a texpreamble which includes my custom commands like this

settings.outformat = "pdf";
import graph;
defaultpen(font("T1", "fut\textfamilyextension","m","n"));
// ... more lines

You must log in to answer this question.

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