I'm trying to write a macro (ideally an environment, but a command would do) that takes a piece of Asymptote code, displays it in a verbatim environment, and then runs it through an asy environment. Unfortunately, my every attempt at the latter seems to go wrong. Here's a MWE:
\documentclass{article}
\usepackage{asymptote}
\newcommand{\asycode}[1]{\begin{asy}
#1
\end{asy}}
\begin{document}
\asycode{label("$x^2 = x \cdot x$");}
\end{document}
If I attempt to compile this, I get the following:
Runaway argument?
! File ended while scanning use of \next.
<inserted text>
\par
<*> problem.tex
?
What am I doing wrong here, and can it be fixed in any remotely reasonable fashion?
[Note: I've tried a number of different permutations regarding line break placement, etc., and none of them seem to work.]
asyenvironment. For example,\newcommand{\asycode}[1]{\asy #1\endasy}. – Werner Aug 06 '13 at 18:29\asyand\endasyin the actual document does not work. As far as I can tell from the source, the environment keeps going with\nextuntil it encounters the string\end{asy}. – Charles Staats Aug 06 '13 at 19:06asyenvironment writes line by line; the line is absorbed using the end-of-line as delimiter; by hiding the environment in a macro, it's impossible to make the needed category code change. – egreg Aug 06 '13 at 20:03