1

I am trying to put two floats in a row using float row. Everything works fine with a structure:

\documentclass[12pt,letterpaper]{article}
\usepackage[inline]{asymptote}
\usepackage{floatrow,calc}
\begin{document}
\begin{figure}[!h]

   \floatsetup{heightadjust=object,valign=c}
   \begin{floatrow}
    \ffigbox{\caption{}\label{}}
            {}
    \ffigbox{\caption{}\label{}}
            {}         
    \end{floatrow}
\end{figure}
\begin{asy}
settings.outformat = "pdf";
settings.prc = false;  
settings.render = 0;  
import three;
size(5cm, 0);
currentprojection=orthographic((7,2,3));
real xmin=-1.5;
real xmax=4;
real ymin=-1.3;
real ymax=4;
path3 p=(xmin,ymin,0)--(xmin,ymax,0)--(xmax,ymax,0)--(xmax,ymin,0)--cycle;
draw(p);
\end{asy}
\end{document}`

This Asy-example also works and no problem. BUT! Then I move asy-code into the floats like this:

\documentclass[12pt,letterpaper]{article}
\usepackage[inline]{asymptote}
\usepackage{floatrow,calc}
\begin{document}
\begin{figure}[!h]
   \floatsetup{heightadjust=object,valign=c}
   \begin{floatrow}
    \ffigbox{\caption{}\label{}}
            {\begin{asy}
            settings.outformat = "pdf";
            settings.prc = false;  
            settings.render = 0;  
            import three;
            size(5cm, 0);
            currentprojection=orthographic((7,2,3));
            real xmin=-1.5;
            real xmax=4;
            real ymin=-1.3;
            real ymax=4;
            path3 p=(xmin,ymin,0)--(xmin,ymax,0)--(xmax,ymax,0)--(xmax,ymin,0)--cycle;
            draw(p);
            \end{asy}}
    \ffigbox{\caption{}\label{}}
            {\begin{asy}
            settings.outformat = "pdf";
            settings.prc = false;  
            settings.render = 0;  
            import three;
            size(5cm, 0);
            currentprojection=orthographic((7,2,3));
            real xmin=-1.5;
            real xmax=4;
            real ymin=-1.3;
            real ymax=4;
            path3 p=(xmin,ymin,0)--(xmin,ymax,0)--(xmax,ymax,0)--(xmax,ymin,0)--cycle;
            draw(p);
            \end{asy}}         
    \end{floatrow}
\end{figure}

\end{document}

it refuses to work and says:

! Argument of \ProcessAsymptoteLine has an extra }. \par l.22 \end{asy}}

I have just copy-pasted the working code! How comes it doesn't work? The only reason I find might be Asymptote and floatrow incompatibility. And my dullness, of course.

Why doesn't it work? Thanks to everyone.

2

TL;DR Use the subcaption package instead of floatrow.


Verbatim-like environments such as asy do not work when you put them inside commands.

Works:

\begin{figure}
\begin{asy}
...asymptote code...
\end{asy}
\end{figure}

Now suppose you like commands better than environments. You might try something like this:

\newcommand{\figurecmd}[1]{\begin{figure}#1\end{figure}}  % BAD

% Doesn't work
\figurecmd{  
\begin{asy}
...asymptote code...
\end{asy}
}

Simplified explanation: in order to correctly export Asymptote code, the meaning of \ and % (among other things) has to be changed for everything from \begin{asy} to \end{asy}. Unfortunately, in the "BAD" code example I gave, the meaning of all the characters is fixed at the time the \figurecmd command is read, so it doesn't work as expected. Fortunately there are alternatives such as the subcaption package that use environments rather than commands, for precisely this sort of reason.

Note that some TeX gurus are able to do some sort of magic to create commands that behave like environments in this respect. For instance, it is possible to put an asy environment inside a TikZ \node command. But for most commands you shouldn't expect this, which is a large part of why environments exist.

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.