2

Consider the following LaTeX code, the bottom half of which was generated from MarkDown by Pandoc.

\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}

% begin preamble.tex
\usepackage{wrapfig}
\renewenvironment{description}{}{}
\renewcommand{\item}[1][]{%
    \renewcommand{\includegraphics}[1]{\Oldincludegraphics[width=4cm]{##1}}%
    \begin{wrapfigure}{l}{4cm}%
    #1%
    \end{wrapfigure}%
    }
% end preamble.tex

\begin{document}
\begin{wrapfigure}{l}{4cm}%
\Oldincludegraphics[width=4cm]{example-image-a}%
\end{wrapfigure}%
A.0 Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Etiam lobortis facilisis
sem. Nullam nec mi et neque pharetra sollicitudin.

A.1 \blindtext

\begin{description}
\itemsep1pt\parskip0pt\parsep0pt
\item[\includegraphics{example-image-b}]
B.0 Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Etiam lobortis facilisis
sem. Nullam nec mi et neque pharetra sollicitudin.
\end{description}

B.1 \blindtext
\end{document}

What I would like to do, is to redefine the description environment and the \item command as normal text for the wrapfigure to work properly.

\renewenvironment{description}{}{} appears to do fine. It is the \renewcommand{\item}[1][] block that still seems to provoke unexpected wrapfig behaviour. Something similar happens when replacing wrapfig by picins.

Note: Since we are dealing here with a Pandoc-generated document, above should only be achieved by changing the preamble and/or adding a header and/or footer to the document. enter image description here

1 Answers1

2

Originally intended to be an edit to this question, here is a solution using the floatflt package; a floating package I had not tried yet. The trick is in the \hspace{0pt}.

The issue of clearing the float is dealt with here and here.

\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}

% begin preamble.tex
\usepackage{floatflt}
\renewenvironment{description}{%
    \renewcommand{\includegraphics}[1]{\vspace{-1ex}\Oldincludegraphics[width=4cm]{##1}}
    \renewcommand{\item}[1][]{##1\end{floatingfigure}}%
    \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}

\blindtext

\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}

floatflt solution