I have come across an interesting problem with floats. As I was writing some wrapper environments, I noticed that the optional position argument cannot be processed correctly, if it is first stored and then retrieved from a temporary `storage' macro. In th MWE below, myfloatone ignores the position, and myfloattwo is fine with it. The only difference is how the optional argument is passed to the figure environment.
Code: Select all
\documentclass{article}
\newenvironment{myfloatone}[3][tbp]{%
\def\postemp{#1}\def\captemp{#2}\def\labtemp{#3}%
\begin{figure}[\postemp]}% <- Difference here
{\caption{\captemp}\label{\labtemp}\end{figure}}
\newenvironment{myfloattwo}[3][tbp]{%
\def\postemp{#1}\def\captemp{#2}\def\labtemp{#3}%
\begin{figure}[#1]}% <- Difference here
{\caption{\captemp}\label{\labtemp}\end{figure}}
\begin{document}
One
Two
\begin{myfloatone}[b]{caption one}{labelone}
\rule{1em}{1em}
\end{myfloatone}
Three
\clearpage
One
Two
\begin{myfloattwo}[b]{caption two}{labeltwo}
\rule{1em}{1em}\ \rule{1em}{1em}
\end{myfloattwo}
Three
\end{document}
Can anyone offer an explanation? And, more importantly, suggest how I could pass the position argument via another macro so that the float takes it in? Thank you in advance for any advice.