Dave Jarvis' Repositories

git clone https://repo.autonoma.ca/repo/recipe-fiddle.git
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% Ingredients definition
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% Ingredients are itemized in a bullet list by default.
\startnotmode[RecipeModeTabularIngredients,RecipeModeCompactIngredients]
\defineitemgroup[RecipeIngredients]
\setupitemgroup[RecipeIngredients][each][packed][
  width=1em,
  symbol=RecipeStyleBulletUnnumbered,
  % No space between item and symbol.
  distance=0pt,
]

% Places the given parameter into the index, organized by section.
% #1 - The ingredient name (singular)
% #2 - The ingredient name (inflected)
%
% If the singular name (for the index) is blank, then don't write to
% the index.
\define[2]\IngredientName{%
  \if\relax\detokenize{#1}\relax
    #2%
  \else
    \expanded{\index{#1+\namedstructurevariable{section}{title}}{#2}}%
  \fi
}

% Helper macro for the ingredient quantity.
\define[1]\IngredientQuantity{#1}

% Helper macro for the unit of measurement.
% If the measure is non-empty, this will ensure a space is added after
% the measure (e.g., "cup "). Without this, the document would include
% erroneous text such as "1  avocado" instead of "1 avocado".
\define[1]\IngredientMeasure{
  \if\relax\detokenize{#1}\relax
    %
  \else
    #1
  \fi
}

% Adds an ingredient to the recipe's list of ingredients.
% #1 - quantity
% #2 - unit of measurement
% #3 - indexed name
% #4 - written name
\define[4]\ingredient{%
  \startitem
    \IngredientQuantity{#1}\IngredientMeasure{#2}\IngredientName{#3}{#4}
  \stopitem
}
\stopnotmode

% Ingredients in a compact list are not listed in a bullet style.
\startmode[RecipeModeCompactIngredients]
  \defineitemgroup[RecipeIngredients]

  % #1 - ingredient unit
  % #2 - ingredient measurement
  % #3 - ingredient name
  \define[3]\ingredient{#1 #2 #3 \RecipeStyleBulletUnnumbered{}}
\stopmode

% Ingredients in a tabular environment are listed as a table.
\startmode[RecipeModeTabularIngredients]
  \defineitemgroup[RecipeIngredients]
  \setupitemgroup[RecipeIngredients][
    before={\bTABLE[split=no]},
    after={\eTABLE},
  ]
\stopmode