轉念一想…

轉念一想…

一段時間以來,我一直在嘗試使用 ShareLaTeX 創建一本好看的食譜書。我嘗試過使用cookybookycuisine包,但似乎無法讓它們工作。我希望每個頁面都有:

  1. 食譜的標題並將該標題放置在內容頁面中。
  2. 符號表示:

    (a) 餐食是否可以冷凍;

    (b) 是否為素食;

    (c) 製作需要多長時間(準備和烹飪時間);

    (d) 它服務了多少人。

  3. 成分錶為

    (a) 有自己的副標題;

    (b) 可選擇為醃料等添加副標題;

    (c)排列為:數量測定成分(製劑)。

  4. 說明(同樣帶有自己的副標題)可以選擇在“說明”和第一個說明之間放置“將烤箱預熱到 x 度”。

  5. 將影像新增至相同位置的每個相同大小的食譜的選項。

目前,典型的食譜如下所示:

在此輸入影像描述

我對它的外觀非常滿意(儘管有些顏色可能不錯)。然而,我都是「手工」完成的,所以需要做很多工作才能確保所有食譜都具有相同的格式。

可以製作這樣的模板嗎?

我上述的食譜的代碼:

\newpage
\section{Raspberry Chocolate Tiramisu}
\lhead{}\chead{Serves 4}\rhead{V}
\lfoot{Prep time:}\rfoot{Cook time:}
\begin{multicols}{2}
{\Large Instructions}
\begin{itemize}
    \item 100ml Double Strength Coffee
    \item 400g Raspberries (blitzed)
    \item 200g Mascarpone
    \item 2 tbsp Sweetener
    \item 1 tsp Vanilla Extract
    \item 700g Vanilla Yogurt
    \item 15g Dark Chocolate (finely grated)
\end{itemize}
\columnbreak
\textit{For the Crumble Mixture}:
\begin{itemize}
    \item 80g Wholemeal Flour
    \item 80g Plain Flour
    \item 80g Butter (diced)
    \item 70g Demerara Sugar
\end{itemize}
\end{multicols}
{\Large Instructions}\\
Preheat the over to Gas Mark 4, Electric $180^\circ$C, Fan $160^\circ$C.
\begin{enumerate}
    \item Stir the two kinds of flour together in a bowl, add the butter and rub it into the flour. When the mixture looks like breadcrumbs, mix in the brown sugar. Lay the mixture on a shallow baking tray and bake for 25-30 minutes until golden brown. Leave on the side to cool.
    \item Mix together the mascarpone, sweetener, vanilla extract, and three quarters of the chocolate. Put half the crumble mixture in each of the glasses and pour over half the quark mixture along with half the raspberries.
    \item Put the other half of the crumble mixture on top, followed by the remaining quark mixture and raspberries. Sprinkle over the last of the chocolate. Chill for 3 hours before serving.
\end{enumerate}

答案1

感謝 @alephzero 使其成為一個真正的 LaTeX 項目。也就是說,專注於配方的語義而不是 LaTeX 標記。

為此,我更喜歡乾淨整潔的輸入和輸出。我曾經\obeylines在沒有附帶標記的情況下模擬列表環境。我還使用了一些顏色來表示一些可能性。我已經在非常簡單的程式碼中添加了註釋,這些註釋應該可以指明方向。 Computer Modern 不會是我的選擇,但我不知道您的 TeXing 環境是什麼,所以我不想做出任何不利的假設。我會盡量減少裝飾(規則等),以幫助使食譜的呈現盡可能清晰。祝你胃口好。

之後:

我已經提供了一些缺失的%。此外,我還提供了標題註釋作為 的可選參數的可能性\recipe。此外,為了我自己的利益,我已經獲得了geometry.sty生產 5.5 英寸 x 8.5 英寸輸出的幫助。當然,可以根據情況進行更改。

再後來:

我還應該指出,這使用\frontmatter\backmatterfrom創建了一個目錄book.cls。有點像花生:你不能只吃一個...

% !TEX encoding = UTF-8 Unicode
% !TEX TS-program = XeLaTeX

%% pagestyle alterations per user request 14 xii 2020

\documentclass{article}
\usepackage{fancyhdr}
\usepackage{multicol}
\usepackage[%
    %a5paper,
    papersize={5.5in,8.5in},
    margin=0.75in,
    top=0.75in,
    bottom=0.75in,
    %twoside
    ]{geometry}
\usepackage{xcolor}
\usepackage{graphicx}

\raggedcolumns
\setlength{\multicolsep}{0pt}
\setlength{\columnseprule}{1pt}

\makeatletter

%% Used for the headnote and in \showit
%% If the text is small it is placed on one line;
%% otherwise it is put into a raggedright paragraph.
\long\def\testoneline#1{%
  \sbox\@tempboxa{#1}%
  \ifdim \wd\@tempboxa <0.75\linewidth
        \begingroup
            \itshape
            #1\par
        \endgroup
  \else
    \parbox{0.75\linewidth}{\raggedright\itshape#1}%
    \par
  \fi
}

\newif\if@mainmatter \@mainmattertrue

%% Borrowed from book.cls
\newcommand\frontmatter{%
    \cleardoublepage
  \@mainmatterfalse
  \pagenumbering{roman}}
\newcommand\mainmatter{%
    \cleardoublepage
  \@mainmattertrue
  \pagenumbering{arabic}}
\makeatother

%% Vary the colors at will

\definecolor{vegcolor}{rgb}{0,0.5,0.2}
\definecolor{frzcolor}{rgb}{0,0,1}
\definecolor{dessertcolor}{rgb}{0.5,0.2,0.1}
\definecolor{makeaheadcolor}{rgb}{0.5,0.5,0.6}

%% Thanks to alephzero for the excellent start:
\newcommand{\recipe}[2][]{%
    \newpage
    \thispagestyle{fancy}
    \lhead{}%
    \chead{}%
    \rhead{}%
    \lfoot{}%
    \rfoot{}%
    \section{#2}%
    \if###1##%
    \else
        \begin{center}
            \testoneline{#1}%
        \end{center}
    \fi
}
\newcommand{\serves}[2][Serves]{%
    \chead{#1 #2}}
\newcommand{\dishtype}[1]{%
    \rhead{#1}%
}
\newcommand{\dishother}[1]{%
    \lhead{#1}%
}
\newcommand{\vegetarian}{%
    {\large\color{vegcolor}\textbf{V}}%
}
\newcommand{\freeze}{%
    {\large\color{frzcolor}\textbf{F}}%
}
\newcommand{\dessert}{%
    {\large\color{dessertcolor}\textbf{D}}%
}
\newcommand{\makeahead}{%
    {\large\color{makeaheadcolor}\textbf{M}}%
}
%% Optional arguments for alternate names for these:
\newcommand{\preptime}[2][Prep time]{%
    \lfoot{#1: #2}%
}
\newcommand{\cooktime}[2][Cook time]{%
    \rfoot{#1: #2}%
}
\newcommand{\temp}[1]{%
    $#1^\circ$C}
%% Optional argument is the width of the graphic, default = 1in
\newcommand{\showit}[3][1in]{%
    \begin{center}
        \bigskip
            \includegraphics[width=#1]{#2}%
            \par
            \medskip
            \testoneline{#3}%
            \par
    \end{center}%
}

%% Optional argument for a  heading within the ingredients section
\newcommand{\ingredients}[1][]{%
    \if###1##%
        {\color{red}\Large\textbf{Ingredients}}%
    \else
        \emph{#1}%
    \fi
}

%% Use \obeylines to minimize markup
\newenvironment{ingreds}{%
    \parindent0pt
    \noindent
    \ingredients
    \par
    \smallskip
    \begin{multicols}{2}
    \leftskip1em
    \rightskip0pt plus 3em
    \parskip=0.25em
    \obeylines
    \everypar={\hangindent2em}
}{%
    \end{multicols}%
    \medskip
}

\newcounter{stepnum}

%% Optional argument for an italicized pre-step
%% Also use obeylines to minimize markup here as well
\newenvironment{method}[1][]{%
    \setcounter{stepnum}{0}
    \noindent
    {\color{red}\Large\textbf{Instructions}}%
    \par
    \smallskip
    \if###1##%
    \else
        \noindent
        \emph{#1}
        \par
    \fi
    \begingroup
    \parindent0pt
    \parskip0.25em
        \leftskip2em
    \everypar={\llap{\stepcounter{stepnum}\hbox to2em{\thestepnum.\hfill}}}
}{%
    \par
    \endgroup
    }

\pagestyle{plain}

\begin{document}

\frontmatter
\tableofcontents

\mainmatter

\recipe[This is a simple headnote that describes the product for the user. A simple but elegant dessert.]{Raspberry Chocolate Tiramisu}
\serves{4}
\preptime{1 hour}
\cooktime[Chill time]{1$\frac{1}{2}$ hours}
\dishtype{\dessert,\vegetarian}
\dishother{\makeahead, \freeze}
\begin{ingreds}
     100ml double strength coffee
     400g raspberries (blitzed)
     200g mascarpone
     2 tbsp sweetener
     1 tsp vanilla extract
     700g vanilla yogurt
     15g dark chocolate (finely grated) and a really long one
\columnbreak
\ingredients[For the Crumble Mixture:]
     80g wholemeal flour
     80g plain flour
     80g butter (diced)
     70g demerara sugar
\end{ingreds}

\begin{method}[Preheat the oven to Gas Mark 4, Electric \temp{180}, Fan \temp{160}.]
     Stir the two kinds of flour together in a bowl, add the butter and rub it into the flour. When the mixture looks like breadcrumbs, mix in the brown sugar. Lay the mixture on a shallow baking tray and bake for 25--30 minutes until golden brown. Leave on the side to cool.

     Mix together the mascarpone, sweetener, vanilla extract, and three quarters of the chocolate. Put half the crumble mixture in each of the glasses, sprinkling over with half the coffee, and pour over half the mascarpone mixture along with half the raspberries.

     Put the other half of the crumble mixture on top, sprinkling over with the remaining half of the coffee, followed by the remaining quark mixture and raspberries. Sprinkle over the last of the chocolate. Chill for 3 hours before serving.

\end {method}

\showit[1.25in]{example-image-b}{This is a picture}

\end{document}

第一個版本

轉念一想…

我不太喜歡這種格式,兩方,其中成分本身呈現在視覺上不同的區域,並且與方法完全分開。表面上看,這樣做的目的是讓使用者一開始就知道需要什麼原料。伊莎貝拉·比頓 (家事書、1861)敦促她的讀者「嚴格遵循食譜給出的順序。因此,讓他們先將所有必要的食材放在桌上;那麼操作方式或準備模式將很容易管理,」在現在通常稱為的實踐中錯誤到位。 但很多時候,特別是在較長的食譜中,當眼睛在成分和方法之間來回移動時,某些東西(通常是成分)會丟失或誤讀,或者跳過或誤解某個步驟。其效果類似於閱讀過長的文本行:眼睛無法正確定位下一行的開頭,並且要么再次閱讀同一行,要么跳過一行。 (https://www.fonts.com/content/learning/fontology/level-2/text-typography/length-column-width)無論如何,只要說我會以不同的方式格式化這個食譜(見下文)就足夠了。

目前,我將堅持按原樣使用這個食譜,並解決另一個問題:成分的規格。自從印刷版(19 世紀早期的英語)中的雙向格式出現以來,成分就以一種明顯的方式給出了。敘述格式:1 茶匙鹽、1 杯麵粉、2 盎司可可等。數量成分是熱門話題,而不是身分成分本身。幸運的是,TeX 提供了透過解析成分來糾正此問題的工具,而不會用不必要的標記過度幹擾這種慣用的(如果不令人滿意)格式。此外,成分只有在前面沒有數量時才應大寫(Whitman,食譜類型,第 124--125 頁),如此處。此外,測量單位最好不要縮寫(Whitman,食譜類型,第 15--16 頁),空間有限的情況除外。

此外,我還讓 OpenType 字型 (STIX Two) 處理度數符號 (°) 和分數 (½),進一步減少編碼。

\documentclass{article}
\usepackage{fancyhdr,multicol,xcolor,graphicx,xparse,fontspec}
\usepackage[%
    %a5paper,
    papersize={5.5in,8.5in},
    margin=0.75in,
    top=0.75in,
    bottom=0.75in,
    %twoside
    ]{geometry}

\makeatletter

%% Used for the headnote and in \showit
%% If the text is small it is placed on one line;
%% otherwise it is put into a raggedright paragraph.
\long\def\testoneline#1{%
  \sbox\@tempboxa{#1}%
  \ifdim \wd\@tempboxa <0.75\linewidth
        \begingroup
            \itshape
            #1\par
        \endgroup
  \else
    \parbox{0.75\linewidth}{\raggedright\itshape#1}%
    \par
  \fi
}

\newif\if@mainmatter \@mainmattertrue

%% Borrowed from book.cls
\newcommand\frontmatter{%
    \cleardoublepage
  \@mainmatterfalse
  \pagenumbering{roman}}
\newcommand\mainmatter{%
    \cleardoublepage
  \@mainmattertrue
  \pagenumbering{arabic}}
\makeatother

%% Vary the colors at will

\definecolor{vegcolor}{rgb}{0,0.5,0.2}
\definecolor{frzcolor}{rgb}{0,0.8,0.8}
\definecolor{dessertcolor}{rgb}{0.5,0.2,0.1}
\definecolor{makeaheadcolor}{rgb}{0.5,0.5,0.6}

%% Thanks to alephzero for the excellent start:
\newcommand{\recipe}[2][]{%
    \newpage
    \thispagestyle{fancy}
    \lhead{}%
    \chead{}%
    \rhead{}%
    \lfoot{}%
    \rfoot{}%
    \section{#2}%
    \if###1##%
    \else
        \begin{center}
            \testoneline{#1}%
        \end{center}
    \fi
}
\newcommand{\serves}[2][Serves]{%
    \chead{#1 #2}}
\newcommand{\dishtype}[1]{%
    \rhead{#1}%
}
\newcommand{\dishother}[1]{%
    \lhead{#1}%
}
\newcommand{\vegetarian}{%
    {\large\color{vegcolor}\textbf{V}}%
}
\newcommand{\freeze}{%
    {\large\color{frzcolor}\textbf{F}}%
}
\newcommand{\dessert}{%
    {\large\color{dessertcolor}\textbf{D}}%
}
\newcommand{\makeahead}{%
    {\large\color{makeaheadcolor}\textbf{M}}%
}
%% Optional arguments for alternate names for these:
\newcommand{\preptime}[2][Prep time]{%
    \lfoot{#1: #2}%
}
\newcommand{\cooktime}[2][Cook time]{%
    \rfoot{#1: #2}%
}
\newcommand{\temp}[1]{%
    #1°C}
%% Optional argument is the width of the graphic, default = 1in
\newcommand{\showit}[3][1in]{%
    \begin{center}
        \bigskip
            \includegraphics[width=#1]{#2}%
            \par
            \medskip
            \testoneline{#3}%
            \par
    \end{center}%
}

%% Optional argument for a  heading within the ingredients section
\newcommand{\ingredients}[1][]{%
    \if###1##%
        {\color{red}\Large\textbf{Ingredients}}%
    \else
        \emph{#1}%
    \fi
}

\def\ucit#1{\uppercase{#1}}
\begingroup
    \lccode`~=`\^^M
    \lowercase{%
\endgroup%% Ingredient first, then measure; empty measure and/or unit = " . "
    %% *=column break; amount<space>ingredient
    \NewDocumentCommand{\ing}{s u{ } u{~}}{% %% basically the same as: \def\ing#1 #2~{%
         %% or: \bfseries\ucit#3\if#1#2---\else,\ \fi
        \if.#2%
            \emph{#3}~ % A heading
        \else % Amounts containing spaces <1 teaspoon> have to use '~' <1~teaspoon>
            \textbf{\ucit#3, }#2 \IfBooleanT{#1}{\columnbreak}~ %
        \fi
    }%
}%


%% Use \obeylines to minimize markup
\newenvironment{ingreds}{%
    \parindent0pt
    \noindent
    \ingredients
    \par
    \smallskip
    \begin{multicols}{2}
    \leftskip1em
    \parindent-1em
    \rightskip0pt plus 3em
    \parskip=0.25em
    \obeylines
    \everypar={\ing}
}{%
    \end{multicols}%
    \medskip
}

\newcounter{stepnum}

%% Optional argument for an italicized pre-step
%% Also use obeylines to minimize markup here as well
\newenvironment{method}[1][]{%
    \setcounter{stepnum}{0}
    \noindent
    {\color{red}\Large\textbf{Instructions}}%
    \par
    \smallskip
    \if###1##%
    \else
        \noindent
        \emph{#1}
        \par
    \fi
    \begingroup
    \rightskip0pt plus 3em
    \parindent0pt
    \parskip0.25em
        \leftskip2em
    \everypar={\llap{\stepcounter{stepnum}\hbox to2em{\thestepnum.\hfill}}}
}{%
    \par
    \endgroup
    }

\setmainfont{STIX Two Text}

\pagestyle{plain}
\raggedcolumns
\setlength{\multicolsep}{0pt}
\setlength{\columnseprule}{1pt}

\begin{document}

\frontmatter
\tableofcontents

\mainmatter

\recipe[This is a simple headnote that describes the product for the user. A simple but elegant dessert.]{Raspberry Chocolate Tiramisu}
\serves{4}
\preptime{1 hour}
\cooktime[Chill time]{1½ hours}
\dishtype{\dessert,\vegetarian}
\dishother{\makeahead, \freeze}
\begin{ingreds}% amount<space>ingredient; initial <.>=comment;*=column break
     100ml double strength coffee
     400g raspberries (blitzed)
     200g mascarpone
     2~tablespoons sweetener
     1~teaspoon vanilla extract
     700g vanilla yogurt
     *15g dark chocolate (finely grated) 
     . for the crumble mixture:
     80g wholemeal flour
     80g plain flour
     80g butter (diced)
     70g demerara sugar
\end{ingreds}

\begin{method}[Preheat the oven to Gas Mark 4, Electric \temp{180}, Fan \temp{160}.]
     Stir the two kinds of flour together in a bowl, add the butter and rub it into the flour. When the mixture looks like breadcrumbs, mix in the brown sugar. Lay the mixture on a shallow baking tray and bake for 25--30 minutes until golden brown. Leave on the side to cool.

     Mix together the mascarpone, sweetener, vanilla extract, and three quarters of the chocolate. Put half the crumble mixture in each of the glasses and pour over half the quark mixture along with half the raspberries.

     Put the other half of the crumble mixture on top, followed by the remaining quark mixture and raspberries. Sprinkle over the last of the chocolate. Chill for 3 hours before serving.
\end {method}

\showit[1.25in]{example-image-b}{This is a picture}

\end{document}

第二版

最後...

這是相同的食譜協調的雙邊格式,也就是說,每個步驟的成分已與該步驟一起顯示(協調)。當我發現原來的食譜其實並沒有,一個謎出現了使用成分錶中要求的“雙倍濃度咖啡”。我試圖在所有三個版本中修復這一遺漏。

\documentclass{article}
\usepackage{fancyhdr,wrapfig,xcolor,graphicx,xparse,fontspec}
\usepackage[%
    %a5paper,
    papersize={5.5in,8.5in},
    margin=0.75in,
    top=0.75in,
    bottom=0.75in,
    %twoside
    ]{geometry}

\newcounter{stepnum}

%% |=====8><-----| %%


\makeatletter

%% From Donald Arseneau. Add after the wrapping text. Whew!
\def\wrapfill{% Just glad it works.
    \par
  \ifx\parshape\WF@fudgeparshape
    \nobreak
    \ifnum\c@WF@wrappedlines>\@ne
      \advance\c@WF@wrappedlines\m@ne
      \vskip\c@WF@wrappedlines\baselineskip
      \global\c@WF@wrappedlines\z@
    \fi
    \allowbreak
    \WF@finale
  \fi
}


%% Used for the headnote and in \showit
%% If the text is small it is placed on one line;
%% otherwise it is put into a raggedright paragraph.
\long\def\testoneline#1{%
  \sbox\@tempboxa{#1}%
  \ifdim \wd\@tempboxa <0.75\linewidth
        \begingroup
            \itshape
            #1\par
        \endgroup
  \else
    \parbox{0.75\linewidth}{\raggedright\itshape#1}%
    \par
  \fi
}

\newif\if@mainmatter \@mainmattertrue

%% Borrowed from book.cls
\newcommand\frontmatter{%
    \cleardoublepage
  \@mainmatterfalse
  \pagenumbering{roman}}
\newcommand\mainmatter{%
    \cleardoublepage
  \@mainmattertrue
  \pagenumbering{arabic}}
\makeatother

%% Vary the colors at will

\definecolor{vegcolor}{rgb}{0,0.5,0.2}
\definecolor{frzcolor}{rgb}{0,0.8,0.8}
\definecolor{dessertcolor}{rgb}{0.5,0.2,0.1}
\definecolor{makeaheadcolor}{rgb}{0.5,0.5,0.6}

%% Thanks to alephzero for the excellent start:
%% #1 [optional headnote]; #2 Title of recipe; #3 [Initial instructions]
\NewDocumentCommand{\recipe}{o m o}{%
    \setcounter{stepnum}{0}%
    \newpage
    \thispagestyle{fancy}
    \lhead{}%
    \chead{}%
    \rhead{}%
    \lfoot{}%
    \rfoot{}%
    \section{#2}%
    \IfNoValueF{#1}{\begin{center}\testoneline{#1}\end{center}}
    \IfNoValueF{#3}{\noindent\emph{#3}\par\medskip}
}
\newcommand{\serves}[2][Serves]{%
    \chead{#1 #2}}
\newcommand{\dishtype}[1]{%
    \rhead{#1}%
}
\newcommand{\dishother}[1]{%
    \lhead{#1}%
}
\newcommand{\vegetarian}{%
    {\large\color{vegcolor}\textbf{V}}%
}
\newcommand{\freeze}{%
    {\large\color{frzcolor}\textbf{F}}%
}
\newcommand{\dessert}{%
    {\large\color{dessertcolor}\textbf{D}}%
}
\newcommand{\makeahead}{%
    {\large\color{makeaheadcolor}\textbf{M}}%
}
%% Optional arguments for alternate names for these:
\newcommand{\preptime}[2][Prep time]{%
    \lfoot{#1: #2}%
}
\newcommand{\cooktime}[2][Cook time]{%
    \rfoot{#1: #2}%
}
\newcommand{\temp}[1]{%
    #1°C}
%% Optional argument is the width of the graphic, default = 1in
\newcommand{\showpic}[3][1in]{%
    \begin{center}
        \bigskip
            \includegraphics[width=#1]{#2}%
            \par
            \medskip
            \testoneline{#3}%
            \par
    \end{center}%
}

\def\ucit#1{\uppercase{#1}}
\begingroup
    \lccode`~=`\^^M
    \lowercase{%
\endgroup%% Ingredient first, then measure; empty measure and/or unit = " . "
    %% *=column break; amount<space>ingredient
    \NewDocumentCommand{\ing}{u{ } u{~}}{% %% basically the same as: \def\ing#1 #2~{% requires xparse
        \noindent
        \if.#1% Is a heading, a non-ingredient, in the ingredients block
            \emph{#2}~ % A heading
        \else % Amounts containing spaces <1 teaspoon> have to use '~' <1~teaspoon>
            \textbf{\ucit#2, }#1~ %
        \fi
    }%
}%

\NewDocumentEnvironment{step}{}{%
    \parindent0pt
    \leftskip0pt
    \begin{minipage}{\textwidth}
        \begin{wrapfigure}{r}{0pt}
            \kern-0.5em
            \vrule width 1pt\enskip
            \begin{minipage}{0.5\textwidth}
                \leftskip=1.5em
                \parindent=-1.5em
                \parskip=0.25em
                \obeylines
                    \everypar={\ing}
}{%
        \wrapfill
    \end{minipage}
    \medskip
}

\NewDocumentCommand{\method}{}{%
            \end{minipage}
        \end{wrapfigure}
        \rightskip0pt plus 2em
        \parskip0.25em
        \everypar={\llap{\stepcounter{stepnum}\hbox to 1.5em{\thestepnum.\hfill}}}
}

\setmainfont{STIX Two Text}

\pagestyle{plain}
\setlength{\intextsep}{0pt}

\begin{document}

\frontmatter
\tableofcontents

\mainmatter

\recipe[This is a simple headnote that describes the product for the user. A simple but elegant dessert.]{Raspberry Chocolate Tiramisu}[Preheat the oven to Gas Mark 4, Electric \temp{180}, Fan \temp{160}.]
\serves{4}
\preptime{1 hour}
\cooktime[Chill time]{1½ hours}
\dishtype{\dessert,\vegetarian}
\dishother{\makeahead, \freeze}

\begin{step}
     100ml double strength coffee
     400g raspberries 
\method
Prepare the coffee and set aside to cool; mash the raspberries with a fork and set aside.
\end{step}

\begin{step}
     . For the crumble mixture:
     80g wholemeal flour
     80g plain flour
     80g butter (diced)
     70g demerara sugar
    \method
    Stir the two kinds of flour together in a bowl, add the butter and rub it into the flour. When the mixture looks like breadcrumbs, mix in the brown sugar. Lay the mixture on a shallow baking tray and bake for 25--30 minutes until golden brown. Leave on the side to cool.
\end{step}

\begin{step}
     200g mascarpone
     2~tablespoons sweetener
     1~teaspoon vanilla extract
     700g vanilla yogurt
     15g dark chocolate (finely grated)
     \method
         Mix together the mascarpone, sweetener, vanilla extract, and three quarters of the chocolate.

    Put half the crumble mixture in each of the glasses, sprinkling over half the coffee, and pour over half the quark mixture along with half the raspberries.

     Put the other half of the crumble mixture on top, sprinkling over the remaining half of the coffee, followed by the remaining quark mixture and raspberries. Sprinkle over the last of the chocolate. Chill for 3 hours before serving.
\end{step}

\showpic[1.25in]{example-image-b}{This is a picture}

\end{document}

第三版

最後一件事...

正如@Alborz 非常正確地指出的那樣,這裡有一些事情需要修復。對於成分清單比其相應方法長的問題,我們可以感謝 Donald Arseneau 提供的解決方案,\wrapfill該解決方案可以在下面找到wrapfig.sty並已在下面使用。在以下程式碼中輸入成分也更簡單:

\documentclass{article}
\usepackage{fancyhdr,wrapfig,xcolor,graphicx,xparse,fontspec}
\usepackage[%
    %a5paper,
    papersize={5.5in,8.5in},
    margin=0.75in,
    top=0.75in,
    bottom=0.75in,
    %twoside
    ]{geometry}

\newcounter{stepnum}

%% |=====8><-----| %%


\makeatletter

%% From Donald Arseneau. Add after the wrapping text. Whew!
\def\wrapfill{% Just glad it works.
    \par
  \ifx\parshape\WF@fudgeparshape
    \nobreak
    \ifnum\c@WF@wrappedlines>\@ne
      \advance\c@WF@wrappedlines\m@ne
      \vskip\c@WF@wrappedlines\baselineskip
      \global\c@WF@wrappedlines\z@
    \fi
    \allowbreak
    \WF@finale
  \fi
}


%% Used for the headnote and in \showit
%% If the text is small it is placed on one line;
%% otherwise it is put into a raggedright paragraph.
\long\def\testoneline#1{%
  \sbox\@tempboxa{#1}%
  \ifdim \wd\@tempboxa <0.75\linewidth
        \begingroup
            \itshape
            #1\par
        \endgroup
  \else
    \parbox{0.75\linewidth}{\raggedright\itshape#1}%
    \par
  \fi
}

\newif\if@mainmatter \@mainmattertrue

%% Borrowed from book.cls
\newcommand\frontmatter{%
    \cleardoublepage
  \@mainmatterfalse
  \pagenumbering{roman}}
\newcommand\mainmatter{%
    \cleardoublepage
  \@mainmattertrue
  \pagenumbering{arabic}}
\makeatother

%% Vary the colors at will

\definecolor{vegcolor}{rgb}{0,0.5,0.2}
\colorlet{gfcolor}{brown}
\definecolor{frzcolor}{rgb}{0,0.8,0.8}
\definecolor{dessertcolor}{rgb}{0.5,0.2,0.1}
\definecolor{makeaheadcolor}{rgb}{0.5,0.5,0.6}

%% Thanks to alephzero for the excellent start:
%% #1 [optional headnote]; #2 Title of recipe; #3 [Initial instructions]
\NewDocumentCommand{\recipe}{o m o}{%
    \setcounter{stepnum}{0}%
    \newpage
    \thispagestyle{fancy}
    \lhead{}%
    \chead{}%
    \rhead{}%
    \lfoot{}%
    \rfoot{}%
    \section{#2}%
    \IfNoValueF{#1}{\begin{center}\testoneline{#1}\end{center}}
    \IfNoValueF{#3}{\noindent\emph{#3}\par\medskip}
}
\newcommand{\serves}[2][Serves]{%
    \chead{#1 #2}}
\newcommand{\dishtype}[1]{%
    \rhead{#1}%
}
\newcommand{\dishother}[1]{%
    \lhead{#1}%
}
\newcommand{\vegetarian}{%
    {\large\color{vegcolor}\textbf{V}}%
}
\newcommand{\glutenfree}{%
    {\large\color{gfcolor}\textbf{GF}}%
}
\newcommand{\freeze}{%
    {\large\color{frzcolor}\textbf{F}}%
}
\newcommand{\dessert}{%
    {\large\color{dessertcolor}\textbf{D}}%
}
\newcommand{\makeahead}{%
    {\large\color{makeaheadcolor}\textbf{M}}%
}
%% Optional arguments for alternate names for these:
\newcommand{\preptime}[2][Prep time]{%
    \lfoot{#1: #2}%
}
\newcommand{\cooktime}[2][Cook time]{%
    \rfoot{#1: #2}%
}
\newcommand{\temp}[1]{%
    #1°C}
%% Optional argument is the width of the graphic, default = 1in
\newcommand{\showpic}[3][1in]{%
    \begin{center}
        \bigskip
            \includegraphics[width=#1]{#2}%
            \par
            \medskip
            \testoneline{#3}%
            \par
    \end{center}%
}

\def\ucit#1{\uppercase{#1}}
\begingroup
    \lccode`~=`\^^M
    \lowercase{%
\endgroup%% Ingredient first, then measure; empty measure and/or unit = " . "
    %% *=column break; amount<space>ingredient
    \NewDocumentCommand{\ing}{u{ } u{ } u{~}}{% %% basically the same as: \def\ing#1 #2~{% requires xparse
        \noindent
        \if#1#2% Is a heading, a non-ingredient, in the ingredients block
            \emph{#3}~ % A heading
        \else % Amounts containing spaces <1 teaspoon> have to use '~' <1~teaspoon>
            \textbf{\ucit#3, }#1\if.#2\else\ #2\fi~ %
        \fi
    }%
}%

\NewDocumentEnvironment{step}{}{%
    \parindent0pt
    \leftskip0pt
    \begin{minipage}{\textwidth}
        \begin{wrapfigure}{r}{0pt}
            \kern-0.5em
            \vrule width 1pt\enskip
            \begin{minipage}{0.5\textwidth}
                \leftskip=1.5em
                \parindent=-1.5em
                \parskip=0.25em
                \obeylines
                    \everypar={\ing}
}{%
        \wrapfill
    \end{minipage}
    \medskip
}

\NewDocumentCommand{\method}{}{%
            \end{minipage}
        \end{wrapfigure}
        \rightskip0pt plus 2em
        \parskip0.25em
        \everypar={\llap{\stepcounter{stepnum}\hbox to 1.5em{\thestepnum.\hfill}}}
}

\setmainfont{STIX Two Text}

\pagestyle{plain}
\setlength{\intextsep}{0pt}

\begin{document}

\frontmatter
\tableofcontents

\mainmatter

\recipe[Some would say this is better than pie. It is certainly easier. And delicious. The original recipe came from Dorie Greenspan; this version also includes almond flour, suggested by King Arthur Baking.]{French Apple Cake}[Center a rack in the oven and preheat the oven to 350°F. Generously butter an 8-inch springform pan and put it on a baking sheet lined with a silicone baking mat or parchment paper.]
\serves{6-8}
\preptime{1 hour}
\cooktime{1 hour}
\dishtype{\dessert}
\dishother{\glutenfree}

\begin{step}
. . Batter, the dry:
1 cup AP (or GF) flour
½ cup almond flour
1 teaspoon baking powder
½ teaspoon cinnamon
¼ teaspoon nutmeg
¼ teaspoon salt
\method
Whisk the flour, baking powder, spices, and salt together in small bowl.
\end{step}

\begin{step}
4 large apples (if you can, choose 4 different kinds)
\method
Peel the apples, cut them in half and remove the cores. Cut the apples into 1- to 2-inch chunks.
\end{step}

\begin{step}
. . Batter, the wet:
2 large eggs
¾ cup maple or brown sugar
3 tablespoons dark rum
½ teaspoon pure vanilla extract
2--3 drops lemon extract
8 tablespoons unsalted butter, melted and cooled
\method
In a medium bowl, beat the eggs with a whisk until they’re foamy. Pour in the sugar and whisk for a minute or so to blend. Whisk in the rum, vanilla, and lemon oil. Whisk in  the flour and when it is incorporated, add the melted butter, mixing gently so that you have a smooth, rather thick batter.

Use a rubber spatula to fold-in the apples--it might look as if there isn't enough batter, but there is. Put the batter into the prepared pan, smoothing the top as much as possible. Bake for 55--65 minutes, or until a toothpick inserted  in the middle comes out clean.

Let cool 30 minutes. Before removing the side of the springform pan, run a knife around the edge of the cake to make sure no apples stuck to the pan.
\end{step}


\end{document}

新例子

最近有一天,我很想開始寫一個類似「TeX in the Kitchen」或「TeX en Cuisine」的部落格——可能會很有趣...

答案2

我要採取的第一步是定義一些巨集來捕獲語意你的食譜,而不是乳膠句法

完成此操作後,您可以開始調整每個語義項目的格式(套用顏色等),而無需編輯內容的食譜。

這並不完整(無論如何,我不知道你想要這本書是什麼樣子!),但它可以運行,並給出基本的想法。

\documentclass{article}
\usepackage{fancyhdr}
\usepackage{multicol}

% Your "recipes.sty" package starts here:
\newcommand{\recipe}{%
    \newpage\lhead{}\chead{}\rhead{}\lfoot{}\rfoot{}\section}
\newcommand{\serves}[1]{%
    \chead{Serves #1}}
\newcommand{\vegetarian}{%
    \rhead{V}}
\newcommand{\preptime}[1]{%
    \lfoot{Prep time: #1}}
\newcommand{\cooktime}[1]{%
    \rfoot{Cook time: #1}}
\newcommand{\ingredients}[1][\Large\emph{Ingredients}]{%
    \emph{#1}\\}
\newcommand{\instructions}[1][\Large\emph{Instructions}]{%
    \emph{#1}\\}
\newcommand{\temp}[1]{%
    $#1^\circ$C}

\pagestyle{fancy}
% End of "recipes.sty"

\begin{document}
\recipe{Raspberry Chocolate Tiramisu}
\serves{4}
\vegetarian

\begin{multicols}{2}
\ingredients
\begin{itemize}
    \item 100ml Double Strength Coffee
    \item 400g Raspberries (blitzed)
    \item 200g Mascarpone
    \item 2 tbsp Sweetener
    \item 1 tsp Vanilla Extract
    \item 700g Vanilla Yogurt
    \item 15g Dark Chocolate (finely grated)
\end{itemize}
\columnbreak
\ingredients[For the Crumble Mixture:]
\begin{itemize}
    \item 80g Wholemeal Flour
    \item 80g Plain Flour
    \item 80g Butter (diced)
    \item 70g Demerara Sugar
\end{itemize}
\end{multicols}

\instructions
Preheat the over to Gas Mark 4, Electric \temp{180}, Fan \temp{160}.
\begin{enumerate}
    \item Stir the two kinds of flour together in a bowl, add the butter and rub it into the flour. When the mixture looks like breadcrumbs, mix in the brown sugar. Lay the mixture on a shallow baking tray and bake for 25--30 minutes until golden brown. Leave on the side to cool.
    \item Mix together the mascarpone, sweetener, vanilla extract, and three quarters of the chocolate. Put half the crumble mixture in each of the glasses and pour over half the quark mixture along with half the raspberries.
    \item Put the other half of the crumble mixture on top, followed by the remaining quark mixture and raspberries. Sprinkle over the last of the chocolate. Chill for 3 hours before serving.
\end{enumerate}

\end{document}

\instructions請注意和宏具有可選參數的方式\ingredients。如果沒有參數,它們會自動建立預設文字「說明」和「成分」。使用方括號中的參數,您可以覆寫它,如“對於碎屑混合物:”等。

相關內容