0

I'm trying to get lettrine and wrapfig to play nicely together. I tried using the answer given by David Carlisle here. Here's an example. Sorry it's so long, but I couldn't minimize it any more. (The last time I tried, it completely obfuscated the problem, see earlier revisions of this question):

MWE:

\documentclass{article}
\usepackage[demo]{graphicx}
\usepackage{blindtext}
\usepackage{wrapfig}
\usepackage{lettrine}
\makeatletter
% code by David Carlisle
% https://tex.stackexchange.com/a/121555/4888
\newdimen\tttaa
\newdimen\tttbb
\def\merge@ps{\afterassignment\merge@ps@\tttbb}
\def\merge@ps@{\afterassignment\merge@ps@@\tttaa}
\def\merge@ps@@{%
\afterassignment\reset@WF@ps\dimen@\WF@ps\valign
\ifnum\count@>\@ne
\advance\count@\m@ne
\expandafter\merge@ps
\fi
}
\def\reset@WF@ps{\afterassignment\reset@WF@ps@\dimen@ii}
\def\reset@WF@ps@#1\valign{%
\edef\new@wf@ps{\new@wf@ps
  \the\dimexpr\dimen@+\tttbb\relax\space
  \the\dimexpr\dimen@ii-\tttbb\relax\space}%
 \def\WF@ps{#1}}
\newcommand\wflettrine[3][]{%
  \setbox\tw@\hbox{\lettrine[#1]{#2}{#3}\global\let\gtmp\L@parshape}%
  \afterassignment\wf@getoffset\count@\gtmp\hoffset
  \setbox\WF@box\hbox{\kern-\dimen@\box\WF@box\kern\dimen@}%
  \noindent\box\tw@
    \def\new@wf@ps{}%
    \afterassignment\merge@ps\count@\gtmp
    \edef\WF@ps{\new@wf@ps\space\WF@ps}%
    \@@parshape\c@WF@wrappedlines\WF@ps\z@\columnwidth}
\def\wf@getoffset{\afterassignment\wf@get@ffset\dimen@}
\def\wf@get@ffset#1\hoffset{}
\makeatother
\usepackage{xparse}
\NewDocumentEnvironment{Env}{m}{%
%
%
\begin{wrapfigure}{r}{.4\textwidth}\includegraphics[width=\linewidth,height=1.15in]{#1}\end{wrapfigure}%
}{}
%\columnsep0pt
\intextsep0pt
\newcounter{mystep}
\NewDocumentCommand{\Step}{m}{%
    \stepcounter{mystep}%
    \wflettrine[nindent=0pt]{\hbox to \baselineskip{\hfill\Alph{mystep}\hfill}}#1\par
}
\begin{document}
\begin{Env}{image}
\Step{This is the first step. It probably will not provide enough of this absolutely meaningless text to completely wrap the figure, but it will be enough to properly showcase the lettrine display.}
\Step{This is a second paragraph of meaningless text. Adding this will produce two warnings in the log file: \textit{Package wrapfig Warning: wrapfigure used inside a conflicting environment on input line 50.} and \textit{Package wrapfig Warning: Stationary wrapfigure forced to float on input line 50.} Both of these are not critical, but a bit of a nuisance nevertheless.}
\Step{This third paragraph will not add any further warnings, but for some reason the text length is slightly too short. Here is another sentence to show this fact a bit better, as the previous sentence was a bit too short to demonstrate this thoroughly enough. That can be fixed by setting \texttt{\textbackslash columnsep} to \texttt{0pt}.}
\Step{If the size of the figure is reduced below \texttt{1.15in}, compiling this throws an error: \texttt{! Missing number, treated as zero.
<to be read again> 
                   \textbackslash valign 
l.54 ...al, but a bit of a nuisance nevertheless.\}}}
\end{Env}
\end{document}

Output: enter image description here

I see three problems with this:

  • The second paragraph that completes wrapping the figure gives two warnings. That's probably not serious though.

  • The third paragraph has a shortened line size. This problem disappears if I set \columnsep to 0pt.

  • Compilation will fail with ! Missing number, treated as zero if the height of the image is reduced below 1.15in. I suppose this last one comes up randomly at various sizes of the figure included, as my real document has figures that are much higher than this. This goes away for this particular example if I don't set \intextsep to 0pt.

  • you get an error without the group at all don't you Undefined control sequence. \merge@ps@@ ...gnment \reset@WF@ps \dimen@ \WF@ps ? – David Carlisle Oct 2 '17 at 11:12
  • @DavidCarlisle Sorry, I was a bit too eager to minimalize the example. The current edit should reflect the problems I see. The third bullet point is actually the killer one, because I assume that one will come up at various sizes of the wrapped figure. I'll experiment a bit more to see if I find other sizes where this happens. – takrl Oct 2 '17 at 13:47
  • @DavidCarlisle I haven't yet found another image size that causes this particular example to fail, but I tried the other way round. My "real" document throws errors in three different places when setting \intextsep to 0pt, 10pt or 20pt respectively. – takrl Oct 2 '17 at 14:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.