xcookybooky 中的多种准备工作

xcookybooky 中的多种准备工作

我尝试xcookybooky以一种可以创建具有单独标题的多个部分的方式来改变包\preparation

我的主要问题是\preparation命令的定义使得只存储最后一次调用的数据。

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

稍后\xcb@preparation将使用 来打印内容。有没有办法重写 ,\preparation以便它不会覆盖\xcb@preparation内容,而是扩展它?

答案1

通过利用预准备(步骤)挂钩和后准备(步骤)挂钩,最多可以包含三种替代准备。

\setHeadlines{prephead = <your heading>}例如使用 定义标题

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

您可以使用相同的技术

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

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

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

使用以下代码定义标题

% !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

相关内容