Float page always *before* reference and without page break

I'm trying to create a layout where images are *always without exception* displayed before their reference, and on a page by themselves without any text above or below the image. I've tried a number of different approaches, but have not been successful.

The text needs to "flow" around the images on the alternate side, so using \FloatBarrier to force a new page is not an option.

The example below is as close as I've been able to get, but I (a) want to get rid of the text underneath the image on page 1, (b) want to move the leftover text on page 4 to page 5 (leaving the image on a page by itself).

The section that references the image will not always be at the top of the page - because of how I'd like to lay this out, there may be some leftover bits of the previous section(s) that have flowed over. An alternate way of thinking of this would be that the image is inserted as an entire page on the page before the reference would appear, pushing the contents of the book one page out.

\documentclass[]{book}
\usepackage{lipsum}
\usepackage[pagestyles]{titlesec}
\usepackage{float}
\usepackage{placeins}
\usepackage[demo]{graphicx}

\renewcommand{\thesection}{\arabic{section}}

\begin{document}

\begin{figure}[H]
\includegraphics[width=\textwidth,height=0.8\textheight]{dummy}
\end{figure} % must appear before the section on a line below (1)
\section{}
\lipsum[1-2]
\section{}
\lipsum[1]
\section{}
\lipsum[1-6]
\begin{figure}[H]
\includegraphics[width=\textwidth,height=0.8\textheight]{dummy}
\end{figure} % must appear before the section on the line below (4)
\section{}
\lipsum[1-2]

\end{document}


• i'd always use {figure}[p] (not [H]), and put the input for the figure before its reference. – barbara beeton May 19 '16 at 19:58
• @barbarabeeton They are placed before the reference (I just updated the sample to make that clearer). When using [p], the figures will often drift down further into the document which is undesirable. If I use a \FloatBarrier immediately after a {figure}[p] the pages are positioned before the reference, but text before the reference doesn't correctly flow (ie: it inserts a page break). – slipheed May 19 '16 at 20:04
• oh. i've often been forced to move a figure around in the input file to get exactly the placement i want. (this is for tugboat. i don't write much else, although i answer questions for ams authors that often involve advice about such adjustments) – barbara beeton May 19 '16 at 20:14
• "before their reference" I could imagine implementing if you meant before a \ref if you had a \label but you don't have that and seem to mean before the \section following the figure? – David Carlisle May 19 '16 at 21:53
• @DavidCarlisle Yes, I meant that the text in section 4 references the image placed before the section. – slipheed May 19 '16 at 23:15

p figures will not drift into the document and will always be placed at the next page break if they are larger than \floatpagefraction

\documentclass[]{book}
\usepackage{lipsum}
\usepackage[pagestyles]{titlesec}
\usepackage{float}
\usepackage{placeins}
\usepackage[demo]{graphicx}

\renewcommand{\thesection}{\arabic{section}}
\renewcommand\floatpagefraction{.1}
\begin{document}

\begin{figure}[p]
\includegraphics[width=\textwidth,height=0.8\textheight]{dummy}
\end{figure} % must appear before the section on a line below (1)
\clearpage
\section{}
\lipsum[1-2]
\section{}
\lipsum[1]
\section{}

\lipsum[1-4]
\begin{figure}[p]
\includegraphics[width=\textwidth,height=0.8\textheight]{dummy}
\end{figure} % must appear before the section on the line below (4)
\lipsum[5-6]
\section{}
\lipsum[1-2]

\end{document}

• I noticed that you moved the figure before section 4 up between the sample paragraphs - is it possible to avoid manually re-positioning it, or is this beyond the capabilities of the layout engine? – slipheed May 19 '16 at 23:14
• @slipheed it's possibly beyond the capabilities of the amount of code expected in a free stack exchange answer:-) Nothing's impossible (but it would probably take two passes or more) but I don't have any code suggestion and it would take some major re-engineering of latex's output routine, I think. – David Carlisle May 20 '16 at 6:57