# Error Inserting Custom Symbols (Graphics) into the Section

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".

\documentclass[12pt]{memoir}
\usepackage{tikz}
\usepackage{pgffor}
\usepackage{xstring}
\noexpandarg

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

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

\begin{document}

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

\end{document}


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}