# wrapfigure in a newtheorem environment: Why not put in correct place?

This must be easy but I can't figure out why the "figure" is not put at the correct spot (in the example) with wrapfigure'.

\documentclass{article}

\usepackage{graphicx}
\usepackage{wrapfig}
\usepackage{blindtext}
\newtheorem{example}{Example}[section]

\begin{document}
\begin{example}
\blindtext[1]
\begin{wrapfigure}{r}{0.5\textwidth}
\framebox[0.5\textwidth]{\rule{0pt}{100pt} Figure}
\end{wrapfigure}
\blindtext[1]
\end{example}
\blindtext[2]
\end{document}

-
internally theorem is implemented as a one item list and the wrapfig doc says: You must not specify a wrapfigure in any type of list environment or or immediately before or immediately after one. –  David Carlisle Mar 31 '13 at 9:48
Hi David, many thanks. I tried an alternative with a minipage but that didn't come out nice. Do you have a suggestion in this case? I just have an example environment and would like to let text float around a (right-aligned, 50% textwidth) figure. –  Marius Hofert Mar 31 '13 at 9:49

Internally theorems are a one item list and it is a documented restriction that wrapfig does not work in lists.

However theorems don't usually use too much of the list structure so with care you can make it work, especially if, as here, it is not the first paragraph (where you have the extra complication of the heading which is implemented as a list item)

\documentclass{article}

\usepackage{graphicx}
\usepackage{wrapfig}
\usepackage{blindtext}
\newtheorem{example}{Example}[section]

\begin{document}
\begin{example}
\blindtext[1]

{\makeatletter
\let\par\@@par
\par\parshape0
\everypar{}\begin{wrapfigure}{r}{0.5\textwidth}
\framebox[0.5\textwidth]{\rule{0pt}{100pt} Figure}
\end{wrapfigure}
\blindtext[1]\par}%
\end{example}
\blindtext[2]
\end{document}

-
Perfect as usual, many thanks for sharing, David. One comment (for future reference): the \blindtext[1] right after \end{wrapfigure}` is crucial. –  Marius Hofert Mar 31 '13 at 10:23