0

I have a problem regarding the combination of lettrine and wrapfig inside an xcookybooky recipe.

My issue stems from the interaction between the two packages. If I create a recipe such as that shown below, the paragraph maintains that width even when the ingredients wraptable has finished. This creates unsightly white-space in the document.

Example Recipe with no wrapping

To fix this, I stumbled across a solution by David Carlisle which uses some fancy LaTeX to combine the two paragraph shapes (see Lettrine and Wrapfig). This works well, however there is still an issue. Whenever the end of the ingredients list coincides with the start of a new preparation step, an error is thrown.

Error from wflettrine code

This can be replicated in the following MWE by reducing the length of the ingredients list (i.e. the height of the wrapfig). I have managed to reduce the number of lines affected by 1 with the shift the valign command inside the conditional, however the issue still remains for the first two lines of each paragraph.

To get to my question, is there a way to fix the \wflettrine command to make this work? Or is there another approach which will solve the root issue?

\documentclass{article}

\usepackage{graphicx}
\usepackage{lettrine}
\usepackage{wrapfig}
\usepackage{lipsum}
\usepackage{xcookybooky}

%------------------------------------------------
%   Modification of lettrine for wrapfig
%------------------------------------------------
% Courtesy of David Carlisle: https://tex.stackexchange.com/questions/119688/lettrine-and-wrapfig

\newdimen\tttaa
\newdimen\tttbb

\makeatletter
\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
        \afterassignment\reset@WF@ps\dimen@\WF@ps\valign  % <-- moving to here increases the lines available by one
        \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\copy\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{\wf@get@ffset\dimen@}
\def\wf@get@ffset#1\hoffset{}

\makeatother

%------------------------------------------------
%   Update of xcookybook for wrapping steps
%------------------------------------------------
\renewcommand{\step}{%
    \par
    \stepcounter{step}  % <-- moved here, since shouldn't be in the argument of lettrine
    \wflettrine[%
        lines=2,
        lhang=0,          % space into margin, value between 0 and 1
        loversize=0.15,   % enlarges the height of the capital
        slope=0em,
        findent=1em,      % gap between capital and intended text
        nindent=0em       % shifts all intended lines, beginning with the second line
    ]{\thestep}{}%
}
\newcommand{\ing}{1 tsp & some ingredient}

%------------------------------------------------
%   Document
%------------------------------------------------
\begin{document}
\begin{recipe}{Example Recipe}

    \ingredients[5]{%%%% <-- CHANGE TO 4 TO SEE ERROR  %%%%
        \ing\\\ing\\\ing\\\ing
    }

    \preparation{%
        \step xxx
        \step yyy
        \step \lipsum[1]
        \step \lipsum[1]
        \step \lipsum[1]
    }

\end{recipe}
\end{document}

Example Recipe with wrapping, but missing \valign error

epR8GaYuh
  • 2,432
Patrick
  • 31
  • are you sure about % <-- moving to here increases the lines available by one .... – David Carlisle Jan 28 '20 at 08:06
  • Doing this decreased the minimum number of lines a step is required to be before the end of a wrapfig, going from three to two. Effectively increasing the number of lines available by one. It seemed to hold up under any of the tests I threw at it. However, I'll defer to your judgement if you think that this will end up causing other issues? – Patrick Jan 28 '20 at 12:11
  • don't ask me, I have no idea how this works:-) – David Carlisle Jan 28 '20 at 12:12

0 Answers0