# How to redefine environment that has arguments?

To produce html and pdf files from the same set of sources I need to transform all wrapfigure environments (package wrapfig) to standard figure environments. One example is:

\begin{wrapfigure}[15]{i}{0pt}
\includegraphics[width=0.40\textwidth]{parabola}
\caption{La traiettoria bla bla.}
\label{fig:parabola}
\end{wrapfigure}


\newenvironment{wrapfigure}[3]{\begin{figure}[htb]\centering}{\end{figure}}


works but leaves an annoying ']i0pt' between image and caption. Any idea (except manual editing of the resulting html...) Thanks!

-
try: \newenvironment{wrapfigure}[3][]{\begin{figure}[htb]\centering}{\end{figure}} but I suppose that it has more optional arguments – Herbert Jul 29 '11 at 15:49
You might also want to look at the xparse package. – mbork Jul 29 '11 at 16:47

The wrapfig manual states that the syntax is:

\begin{wrapfigure}[<number of narrow lines>]{<placement>}[<overhang>]{<width>}
<figure>
\end{wrapfigure}


Note the two optional and two mandatory arguments. You need to define a replacement which removes all of this possible arguments. This is possible by removing the first two with as environment arguments and then use a gobble macro to remove the other two:

\newcommand{\gobbleom}[2][]{}
\newenvironment{wrapfigure}[2][]
{\begin{figure}[htb]\centering\gobbleom}
{\end{figure}}


You could also use the xparse package to define an environment with two such optional arguments:

\usepackage{xparse}
\DeclareDocumentEnvironment{wrapfigure}{omom}
{\begin{figure}[htb]\centering}
{\end{figure}}


Using xparse is very useful if you want to redefine very complicated macros or environments. However, if you want to reduce the number of used packages I would go with the first method.

-