2

I have diagrams generated in Asymptote stored in external files. Is it possible to input the files into my current LaTeX document and to choose the scale factor within the current document?

The following naive approach does not work:

\documentclass{article}
\usepackage{asymptote}
\begin{document}

A unit sphere, 1/4 size:
\begin{asy}[width=0.25\textwidth]
\input{asyfile}
\end{asy} 

\end{document}

Contents of asyfile:

import solids;
draw(unitsphere,gray);

(I use these diagrams in different contexts, so I do not want to pick the scaling within the Asymptote file.)

  • 3
    Don't use TeX \input command inside the asy environment, instead of \input{asyfile} use the Asymptote code include asyfile; – g.kov Oct 21 '13 at 21:42
  • I've wondered the same thing. When I need to do this, I usually just compile the image separately and use includegraphics (no need for the asymptote package). You could make your asy environment consist of something like size(5cm, 0); include asyfile; which would set the sizing separately each time, but you can't use the \textwidth macro this way. – Charles Staats Oct 22 '13 at 1:41
5

It is tempting to use the TeX commands inside the asy environment, but it would result in a syntax error. Inside the Asymptote code TeX commands are allowed and useful only surrounded by string delimiters for example, in a label or texpreamble command, so don't use TeX \input command inside the asy environment, instead of \input{asyfile} use the Asymptote code include asyfile; to include the external .asy file.

For example:

\documentclass{article}
\usepackage{asymptote}
\begin{document}

A unit sphere, 1/4 size:
\begin{asy}[width=0.25\textwidth]
include asyfile; // but not `\input{asyfile}` 
\end{asy} 

\end{document}

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.