I need to insert images wrapped in text. wrapfig obviously comes to mind. The problem is the wrapped figure, by default, ignores margins and even page ends.
I mean, if I put the image less than its height from the page end, the image trespasses margins and even page dimensions, getting cut out, instead of going in the next page like graphicx does.
Here's an example:
\documentclass[a4paper]{article}
\usepackage{graphicx}
\usepackage{lipsum}
\usepackage{wrapfig}
\begin{document}
Text at the top
\vspace{17cm}
\begin{wrapfigure}{r}{9cm}
\includegraphics[width=9cm]{zappa}
\end{wrapfigure}
\lipsum[5]
\end{document}
Which, looking where the first page ends and the second begins, results in this
As you can see, the image goes beyond the lower margin, where the text ends, gets cut out where the page ends.
Also, the rest of the text, which gets in the next page as the first is finished, presents the shape of the part of the image which wasn't counted in the indentation of text in page 1.
This forces me to manually adjust the block by putting, for example, a newpage before \begin{wrapfigure}. If I latter change something above it, I may have to manually change my adjustment maybe by removing the newpage and so on.
Is there a way to make wrapfig automatically adjust the layout, like graphicx does when it has the [H] option?

Rrather thanr? (also not important for the question but[H]is from thefloatpackage notgraphicx) – David Carlisle Feb 05 '16 at 11:20Hmistake as well, forgot I had to includefloatto use it. – Jeffrey Lebowski Feb 05 '16 at 11:40lipsumwithblindtextsoftened the problem (a few lines were still a little incoherent and some overfull hbox warnings still stood), but reducing image width to a realistic one in an article finally solved it: I guess that where lines are too short some problem can still occur. Well, thanks for everything! – Jeffrey Lebowski Feb 05 '16 at 16:09