Wrapfigure wraps and then floats again

(My first post - please let me know if/how I can improve my questions in the future!) (Modified to include a complete example file)

The code in question is automatically generated via a script. There are about a dozen other identical code snippets (only the file names change). Three of the twelve code segments demonstrate an unexpected additional indentation at the end of the section.


\documentclass[11pt, oneside,american]{book}
\usepackage[margin=1in]{geometry}                               % See geometry.pdf to learn the layout options. There are lots.
\geometry{letterpaper}                                  % ... or a4paper or a5paper or ...
\usepackage{graphicx}
\usepackage{float}
\usepackage[verbose]{wrapfig}
\usepackage[american]{babel}
\usepackage[babel]{csquotes}
\usepackage{etoolbox,xkeyval,ifthen,url}
\usepackage{enumitem}
\usepackage[
backend=biber,
annotation,
loadfiles=true % this forces load of external annotations - based on naming convention
]{biblatex-chicago}
\usepackage{filecontents}
\usepackage[all]{nowidow}
\usepackage{titlesec}
\newcommand{\sectionbreak}{\clearpage}
\usepackage{hyperref}
\input{bibs_index.tex}
\renewcommand*{\finentrypunct}{}%
\DeclareFieldFormat{citehyperref}{%
\bibhyperref{#1}}
\savebibmacro{cite}
\renewbibmacro*{cite}{%
\printtext[citehyperref]{%
\restorebibmacro{cite}%
\usebibmacro{cite}}}
\usepackage{fontspec}
\input{fonts.tex}
\providecommand{\tightlist}{%
\setlength{\itemsep}{0pt}\setlength{\parskip}{0pt}}
\setcounter{secnumdepth}{-1}
\setlist{nosep} %tighten up lists

\begin{document}
\mainmatter
\section{The Contributors}
\subsection{Jane~Smith}
\textsf{Washington, DC, USA}
\par \setlength{\columnsep}{0pt}
\begin{wrapfigure}{l}{0.25\textwidth} \centering \includegraphics[width=0.18\textwidth]{bios/iglazer.jpg}
\end{wrapfigure}
\textsf{ \input{random.txt} }
\WFclear
\subsubsection{Recommendations}\begin{enumerate}
\item \cite{Clippinger2007}
\item \cite{Richer2017}
\end{enumerate}\noindent\rule{\textwidth}{0.2pt}
\printbibliography
\end{document}



• wrapfigure doesn't have that much documentation but the one thing it does document is that it doesn't work near lists... It's usually possible to do something but it would be much easier to answer if you provided a complete small document that showed the problem, not a fragment. (you can use example-image as the image as it is available for such tests. – David Carlisle Mar 8 '19 at 16:06
• Thanks for the feedback (and the welcome!) Hopefully the revised post is better (but please tell me if I can improve it). – Heather Flanagan Mar 8 '19 at 16:23
• All you need to do is add a % immediately after \setlength{\columnsep}{0pt}. Wrapfigure needs to start in vmode, either between paragraphs or at the end of a line. Almost every time you end a line with } you add an extra space, taking you out of vmode. – John Kormylo Mar 8 '19 at 18:08
• Tried that (made sure there were no spaces between 0pt} and %). Did that for every line that had a space after a command as well, just on general principles. No change to the output. – Heather Flanagan Mar 8 '19 at 18:17

The simplest is to not have a float. Here is a possibility with the plain text macro package insbox, which defines \InsertBoxL and \InsertBoxR commands, with two mandatory arguments: the number of lines at the beginning of a paragraph which will remain untouched, and the box to be inserted. Also a final optional argument: the number of supplementary lines which should be shortened, in case the calculations of TeX would be wrong.

\documentclass[english]{article}

\usepackage{geometry}
\usepackage{graphicx}
\usepackage{lipsum}
\input{insbox}
\makeatletter
\@InsertBoxMargin = 10pt
\makeatother

\begin{document}

\subsection*{Ian~Glazer} \textsf{Washington, DC, USA} \smallskip

\InsertBoxL{0}{\includegraphics[width=0.18\textwidth]{PepeLePew}}[-1]
\sffamily \lipsum[2-10]

\subsubsection{Recommendations}
\begin{enumerate}
\item \cite{Clippinger2007}
\item \cite{Richer2017}
\end{enumerate}\noindent\rule{\textwidth}{0.2pt}

\end{document}


• Hmm. Can't quite get that to work. (and can't figure out how to better format the comments so this is readable - grr) /usr/local/texlive/2018basic/texmf-dist/tex/generic/oberdiek/se-ascii-print.def)) Runaway argument? {\includegraphics [width=0.18\textwidth ]{bios/iglazer.jpg}[-1] \sffamily \ETC. ! File ended while scanning use of \InsertBoxL. <inserted text> \par <*> anbib-test.tex – Heather Flanagan Mar 8 '19 at 17:08
• Can you compile my code? (add the [demo]option to graphicx, as I suppose you don't have my image) – Bernard Mar 8 '19 at 17:22
• Yes. When I substitute a new image in the \InsertBoxL, is when I get the error. No other changes made. My line: \InsertBoxL{0}{\includegraphics[width=0.18\textwidth]{bios/iglazer.jpg}[-1] – Heather Flanagan Mar 8 '19 at 17:34
• AhHA! Found it! Missing a closing curly bracket! Score!!! – Heather Flanagan Mar 8 '19 at 18:08
• All but one of the entries now format correctly and all entries are automatically generating. The one that is not generating properly in my production file seems identical to the others but shows a mostly blank page then text and image partially overlapped. The code for that entry works when extracted into a test file. I need a drink. – Heather Flanagan Mar 8 '19 at 18:54

The package lettrine is mainly designed for dropped capitals, but it also allow put a left wrapped image at the start of a paragraph, with a very simple code. Moreover, \lettrine have several options that allow a fine-tuning of the image position.

Unfortunately for this case, it is designed for a single paragraph, with no indentation of the first line,. But for the fist problem is easy make a \fakepar and for the second the \lettrine options are enough, as show the example:

\documentclass[11pt]{article}
\usepackage[margin=1in]{geometry}
\usepackage{lettrine}
\usepackage{graphicx}
\usepackage{lipsum} % only for dummy text
\renewcommand\familydefault{\sfdefault}
\parskip1em
\parindent2em

\def\fakepar{\hfill\mbox{}\vspace{\parskip}\newline\mbox{}\hspace{\parindent}}
\begin{document}

\subsection*{Robert Conway}
Shangri-La, Lost Horizons, Kunlun Mountains\par\bigskip

\lettrine[
lines=13,
lraise=-.1,
findent=5em,
nindent=-2em,
lhang=-.2,
depth=1,
image=true]{example-image-golden-upright}{}%
\lipsum[1][1-4]
\lipsum[2][1-4]\fakepar
\lipsum[3-7]

\end{document}