I am trying to create an environment that essentially centers and creates an asymptote diagram, given the diagram's code. Here is a minimal working example:
\documentclass{article}
\usepackage{asymptote}
\newenvironment{diagram}{\begin{center}\begin{asy}}{\end{asy}\end{center}}
\begin{document}
\begin{diagram}
draw((0, 0) -- (1, 1));
\end{diagram}
\end{document}
The code above gives the Runaway argument? File ended while scanning use of \next error. This also seems to be an Asymptote-specific error; if I replace the \begin{asy} and \end{asy} with something else, it works fine. This is similar to this question, but following the answer there doesn't work. Is there a workaround?