2

I try to change the xcookybooky package in a way that I can create multiple \preparation sections with individual headlines.

My main problem is that the \preparation command is defined so that only the data of the last call is stored.

\newcommand{\preparation}[1]
{%
    \def\xcb@preparation
    {%
        \xcb@name@prephead
        %\\[4pt]
        \xcb@fontsize@prep\color{\xcb@color@prep}#1
    }
    \setcounter{step}{0}
}

The \xcb@preparation is later used to print the content. Is there any way to rewrite the \preparation so that it does not overwrite the \xcb@preparation content but extend this?

1
  • 3
    Welcome. // I'm afraid we need some code, which will compile. // Can you please give a few examples, how multiple preparations should look like? As I read the manual, a preparation is a series of steps which result in one meal. So, are multiple preparations alternative ways to cook the same meal? Thank you // (Please answer by EDITing your question and filling in the missing parts)
    – MS-SPO
    Jun 20, 2023 at 14:34

1 Answer 1

6

Up to three alternate preparations can be included by taking advantage of the pre-preparation (steps) hook and the post-preparation(steps) hook.

Define the heading using \setHeadlines{prephead = <your heading>}, for example

\setHeadlines{prephead = Preparation method~\thepreparationnumber}

b

% !TeX TS-program = pdflatex

\documentclass{article}

\usepackage{xcookybooky}
    
%***************************************************** added <<<<<<<<<<<
\makeatletter
\newcounter{preparationnumber}\setcounter{preparationnumber}{1}
\setHeadlines{prephead = Preparation method~\thepreparationnumber}% define the heading <<<<<<<<<

\renewcommand*{\prepreparation}[1]
{% Hook: entered before the preparation (steps)
    \def\xcb@hook@prepreparation
    {%
        \xcb@name@prephead% 
        \xcb@fontsize@prep\color{\xcb@color@prep} #1%
         \vspace*{2em}\stepcounter{preparationnumber}\setcounter{step}{0}
    }  
}
\renewcommand*{\postpreparation}[1]
{% Hook: entered after the preparation (steps)
    \def\xcb@hook@postpreparation
    {\vspace*{2em}\setcounter{step}{0}\stepcounter{preparationnumber}% 
        \xcb@name@prephead% 
        \xcb@fontsize@prep\color{\xcb@color@prep} #1%           
    }
}

\makeatother    

% fix from https://tex.stackexchange.com/a/445886/
\renewcommand{\step}
{%
    \stepcounter{step}%
    \lettrine
    [%
    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, begining with the second line
    ]{\thestep}{}%
}
%*****************************************************
    
\begin{document}

    
    \begin{recipe}
        [% 
        preparationtime = {\unit[1]{h}},
        portion = {\portion{6}},
        ]
        {Rice and Lamb}
                
        
        \introduction{%
        Introduction to the dish
        }
        
        \ingredients{%
            \unit[2]{tbsp} & Vegetable Oil\\
            3 & Onion, chopped\\
            2 pound & Stewing Lamb or Beef\\
            \unit[1]{tbsp} & Minced Garlic\\
            \unit[2]{tsp} & Salt\\
            \unit[8]{cups} & Water\\
            \unit[1.5]{tbsp} & Ground Cardamom\\
        }
        
        \prepreparation{% first variant
            \step Do some things 1
            \step Do some other things 1
            \step Finish doing things 1
        }
        \preparation{%second variant
            \step Do some things 2
            \step Do some other things 2
            \step Before finish things 2
            \step Finish doing things 2
        }
        
        \postpreparation{%third variant
            \step Do some things 3
            \step Do some other things 3
            \step And more things 3
            \step And more extra things 3
            \step Finish doing things 3 
        }

    \end{recipe}

\end{document} 

With the same technique you can use

\prepreparation{<first variant>}{<steps>}

and

\setHeadlines{prephead = <second variant>} 
\preparation{<steps>}

and

\postpreparation{<third variant>}{<steps>}

to define the headings using the following code

% !TeX TS-program = pdflatex

\documentclass{article}

\usepackage{xcookybooky}
    
%***************************************************** added <<<<<<<<<<<
\makeatletter
\newcounter{preparationnumber}\setcounter{preparationnumber}{1}

\renewcommand*{\prepreparation}[2]
{% Hook: entered before the preparation (steps) 
    \def\xcb@hook@prepreparation
    {%
        \textcolor{\xcb@color@prephead}{\textbf{\xcb@fontsize@prephead{#1}}}%   
        \xcb@fontsize@prep\color{\xcb@color@prep} #2%
         \vspace*{2em}\stepcounter{preparationnumber}\setcounter{step}{0}
    }  
}
\renewcommand*{\postpreparation}[2]
{% Hook: entered after the preparation (steps)
    \def\xcb@hook@postpreparation
    {\vspace*{2em}\setcounter{step}{0}\stepcounter{preparationnumber}%      
        \textcolor{\xcb@color@prephead}{\textbf{\xcb@fontsize@prephead{#1}}}%   
        \xcb@fontsize@prep\color{\xcb@color@prep} #2%           
    }
}

\makeatother    

% fix from https://tex.stackexchange.com/a/445886/
\renewcommand{\step}
{%
    \stepcounter{step}%
    \lettrine
    [%
    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, begining with the second line
    ]{\thestep}{}%
}
%*****************************************************
    
\begin{document}

    
    \begin{recipe}
        [% 
        preparationtime = {\unit[1]{h}},
        portion = {\portion{6}},
        ]
        {Rice and Lamb}
                
        
        \introduction{%
        Introduction to the dish
        }
        
        \ingredients{%
            \unit[2]{tbsp} & Vegetable Oil\\
            3 & Onion, chopped\\
            2 pound & Stewing Lamb or Beef\\
            \unit[1]{tbsp} & Minced Garlic\\
            \unit[2]{tsp} & Salt\\
            \unit[8]{cups} & Water\\
            \unit[1.5]{tbsp} & Ground Cardamom\\
        }
        
        \prepreparation{Using the fast track}{% first variant
            \step Do some things 1
            \step Do some other things 1
            \step Finish doing things 2
        }
    
        \setHeadlines{prephead = Make an impression}
        \preparation{%second variant
            \step Do some things 2
            \step Do some other things 2
            \step Before finish things 2
            \step Finish doing things 2
        }
    
        \postpreparation{Making things last}{%third variant
            \step Do some things 3
            \step Do some other things 3
            \step And more things 3
            \step And more extra things 3
            \step Finish doing things 3 
        }

    \end{recipe}

\end{document} 

c

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .