I would like to achieve automatic clearing of a {floatingfigure} at the beginning of a new \section for texts automatically created by Pandoc. For this to work, I am in need of a way to measure the vertical space that was typeset by LaTeX since placing the {floatingfigure}.
I tried out the placeins package to no effect.
The ideal solution would involve placing a starting marker. An environment or any other block/braced/bracketed structure should not be used as the text that follows the {floatingfigure} is generally unknown. Everything needs to be implemented by renewing commands and environments in the preamble.
Should a second starting marker follow upon a first starting marker without taking a measurement, than the vertical measurement should be reset to 0pt.
Here is a minimum working example. I have placed comments from where to where I would like to measure.
\documentclass{article}
\usepackage{mwe}
\makeatletter
\def\maxwidth{\ifdim\Gin@nat@width>\linewidth\linewidth
\else\Gin@nat@width\fi}
\makeatother
\let\Oldincludegraphics\includegraphics
\renewcommand{\includegraphics}[1]{\Oldincludegraphics[width=\maxwidth]{#1}}
\setlength{\parindent}{0pt}
\usepackage{calc}
\newlength\imgheight
\usepackage{floatflt}
\renewenvironment{description}{%
\renewcommand{\includegraphics}[1]{\vspace{-1ex}\Oldincludegraphics[width=4cm]{##1}}
\renewcommand{\item}[1][]{
\settototalheight\imgheight{##1}%
\global\imgheight=\imgheight%
##1%
\end{floatingfigure}%
% I would like to measure vertical space from here...
}%
\hspace{0pt}%
\begin{floatingfigure}[l]{4cm}}%
{}
% end preamble.tex
\begin{document}
\begin{description}
\itemsep1pt\parskip0pt\parsep0pt
\item[\includegraphics{example-image-a}]
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Etiam lobortis facilisis
sem. Nullam nec mi et neque pharetra sollicitudin.
\end{description}
% ... to here.
\vspace{\dimexpr\imgheight-3\baselineskip}
\section{Section title}
\begin{description}
\itemsep1pt\parskip0pt\parsep0pt
\item[\includegraphics{example-image-b}]
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Etiam lobortis facilisis
sem. Nullam nec mi et neque pharetra sollicitudin.
\end{description}
\blindtext
\end{document}
In below document, the first paragraph is too short to wrap completely around floatingfigure A. Hence, I would like to achieve automatic floatingfigure clearing at the beginning of a new section or a new floatingfigure. Right now, I have done it manually by adding \vspace{\dimexpr\imgheight-3\baselineskip}.


\pagetotalmeasures the distance from the baseline of the first line of the page. Probably you can play with it for a solution. – karlkoeller Aug 29 '13 at 09:25