I am making a cookbook, and want to use a single macro \recipe (in the minimal example below) to insert the name of the recipe, the tags for the food (custom symbols denoting dietary restrictions), and also a brief description. I have a folder called "foodtags" where various symbols are. When I call up these symbols in the text through a command (below, \foodtags), it displays the correct symbols.

However, when using the \recipe command, rather than having the symbols appear right aligned on the same line and the same size as the section, I get the error "undefined control sequence. \foreach ... reach \let \pgffor@assign@before@code".


%Kosher, Vegetarian, Vegan symbols
\newcommand*\foodtags[1]{\foreach \x in {#1} {\foodtag{\x}}}

\newcommand{\recipe}[3]{\section{#1 \hfill \foodtags{#2}} #3}


\recipe{Turkish Style Charoset}{vegan,kosher}{A delicious smooth charoset made with apples, dates, chopped almonds, and wine}


Any idea what the root of this problem is? Is it an issue with the interaction of the Section environment and the graphics? How do I solve this?


The reason behind the issue is discussed in How to include graphics inside the section name which suggests using \protect to avoid expansion of commands like \includegraphics when that's written to the auxiliary files. Why? Because \sections are eventually included in the ToC, which is read from the .toc file.

In your particular case, you also have an automated sequence of graphics going into the sectional title. This type of list processing usually requires assignments, which is also problematic when dealing with sectional units. As such, I'd suggest the following for your \recipe macro:

\newcommand{\recipe}[3]{\section[#1]{#1 \hfill \foodtags{#2}} #3}

This avoids fragile content from getting into the ToC while still allowing for a contextually-appropriate ToC (if that's ever needed).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.