[texhax] asymptote in latex - how?

Philip TAYLOR P.Taylor at Rhul.Ac.Uk
Thu Sep 17 19:45:15 CEST 2009

Bo Thide' wrote:

> A related question:  I would like to have the asymptote code being read
> in into my latex file (preferable via an \input mechanism), rather than
> having the code embedded in the .tex file, but am not sure how to do it.
> Dario Teixeira's "ASYMPTOTE and LaTeX:  An Integration Guide" is unclear
> and ambgious on this point.  Everything I have tried in this direcation
> has failed so far.  Perhaps there is an Asymptote FAQ somewhere that I
> have missed?

I knew (and know) nothing about Asymptote, but including an Asymptote
file via \input (or \include) seemed to me a not-unreasonable desideratum,
so I looked into the problem.  After a few iterations, here is what
appears to be a usable solution.

Philip Taylor
\documentclass [10pt]{article}
\usepackage {graphicx}
\usepackage {asymptote}
\usepackage {catchfile}

\catcode `\^^M = 12 \endlinechar = -1 %
\global \def \IncludeAsymptoteFile #1%
     {\def \BeginAsy {\begin {asy}}
      \def \DoAsy {\detokenize \expandafter {\AsymptoteFileContents}}
             \lccode `\/ = `\\
             \lccode `\( = `\{
             \lccode `\) = `\}
             \lowercase {\gdef \EndAsy {^^M/end(asy)^^M}}
      \CatchFileEdef \AsymptoteFileContents {#1} {\def \par {^^J}}
      \expandafter \expandafter \expandafter \BeginAsy \expandafter \DoAsy \EndAsy

\begin {document}
\begin {figure}
\IncludeAsymptoteFile {eetomumu.asy}
\caption {This is a caption.  Let's see if it appears...}
\label {fig:1}
\end {figure}
\end {document}

More information about the texhax mailing list