Wrapfigure affects the rest of the document in environments

Putting at the end of \poisonousparagraph what the content of the internal wrapfig command \WF@mypar does seems to do the trick (I've replaced the image by a rule of about the same size):

enter image description here

\documentclass[a4paper]{article}

\usepackage[czech]{babel}

\usepackage{graphicx}
\usepackage{wrapfig}

\newenvironment{myenvironment}{}{}

\makeatletter
\def\poisonousparagraph{

\begin{myenvironment}

    Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam at rhoncus libero. Nunc auctor neque ut urna sodales vestibulum. 

\end{myenvironment}
\@@par
\ifnum\@@parshape=\z@ \let\WF@pspars\@empty \fi % reset `parshape'
\global\advance\c@WF@wrappedlines-\prevgraf \prevgraf\z@
\ifnum\c@WF@wrappedlines<\tw@ \WF@finale \fi

}
\makeatother

\begin{document}

\begin{wrapfigure}{r}{0.5\textwidth}
  \begin{center}
    \rule{0.48\textwidth}{2cm}
  \end{center}

  \caption{Lorem ipsum}
\end{wrapfigure}

\poisonousparagraph
\poisonousparagraph
\poisonousparagraph
\poisonousparagraph
\poisonousparagraph
\poisonousparagraph
\poisonousparagraph
\poisonousparagraph

\end{document}

Tags:

Wrapfigure