Textwidth wrong after wrapfigure

I have included a picture with wrapfigure and everything is fine - the problem is that in my next formula environment, the formula is totally wrong! It seems to me, that the width which I set in the wrapfigure environment also effects the formula. How can I set the width back again to standard?

Here is my code:

\documentclass{book}
\usepackage{graphicx}
\usepackage{amsthm}
\usepackage{wrapfig}
\usepackage{mdframed}

\newtheoremstyle{mystyle}{}{}{}{}{}{}{0.5em}{}
\theoremstyle{mystyle}
\newmdtheoremenv{formel}{Formel}

\begin{document}
\begin{wrapfigure}{l}{8cm}
\includegraphics[scale=0.48]{example-image-a}
\end{wrapfigure}
text text text text text text text text text text text text text text text text
text text text text text text text text text text text text text text text text
\begin{formel}[Formel]
$1+1=2$
\end{formel}
\end{document}


So the text wrapping around the figure is OK, but then width of the formula is wrong. It seems to me, that textwidth is set to the wrapfigure's textwidth, what results in a wrong display.

-
Welcome to TeX.SE! Your MWE contains a couple of typos (e.g., "docuemnt") and generates some option clashes. Please edit your MWE to eliminate these problems, so that it becomes compilable -- and still generates the error you're trying to fix. Please also consider eliminating all code that's not pertinent to the problem you're facing, so as to make the example code truly "minimalist". At the moment you're loading lots and lots of packages that don't seem to be related to the problem. –  Mico Aug 18 '12 at 13:23
Just a note: \usepackage{mwe} and \includegraphics[scale=0.48]{example-image-a} make your MWE compilable without using your picture.png (which is not generally available). See also New support package for MWEs. –  Stephen Aug 18 '12 at 14:07

To cite the manual of the wrapfig package, page 1:

You must not specify a wrapfigure in any type of list environment or or immediately before or immediately after one. It is OK to follow a list if there is a blank line (\par) in between.

[...]

\linewidth is now adjusted within the wrapped text, but since it can only be set for whole paragraphs at a time, it will persist with the wrong value after the wrapping, until the paragraph is finished.

And at page 2:

For esthetic reasons, only plain text should wrap around the figure. Section titles and big equations look bad; lists are bad if the figure is on the left. (All these function properly, they just don’t look very good.) Small equations look fine.

Thus: Put a \par before \begin{formel}:

\documentclass{book}
\usepackage{graphicx}
\usepackage{amsthm}
\usepackage{wrapfig}
\usepackage{mdframed}

\newtheoremstyle{mystyle}{}{}{}{}{}{}{0.5em}{}
\theoremstyle{mystyle}
\newmdtheoremenv{formel}{Formel}

%\usepackage{picins}

\begin{document}
\begin{wrapfigure}{l}{8cm}
\includegraphics[scale=0.48]{example-image-a}
\end{wrapfigure}
text
\par
\makeatletter
\loop
\ifnum\c@WF@wrappedlines>3
\hspace*{1sp}\newline
\repeat
\makeatother
\par
\begin{formel}[Formel]
$1+1=2$
\end{formel}
\end{document}


If the text to be wrapped is too short, the formula would be placed in the wrapped text, where it has the smaller width, of course. (And an additional \usepackage{picins} is needed, otherwise the formula is printed "over" the picture.) Using \c@WF@wrappedlines of the wrapfig package and automatically inserting the appropriate number of empty lines fixes this.

-
\par or a blank line before \begin{formel} does changing nothing for me in the edited MWE. I think you have to play with the definition of the formel environment. –  Kurt Aug 18 '12 at 15:14
@Kurt: Well, yes and no: There is a change, but when the wrapped text is so short, that the formula is inside of the wrapped text, it is still as small as the text (which it is supposed to be!). –  Stephen Aug 18 '12 at 18:09

Enclose the wrapfig in a minipage. Usualy

\begin{minipage}
\begin{wrapfig}
...
\end{wrapfig}
...text... to be wrapped
\end{minipage}
..more text which should be normal

-
Welcome to TeX.SX! You can have a look at our starter guide to familiarize yourself further with our format. –  Pier Paolo Dec 21 '14 at 16:03