Evaluate macros on \foreach arguments

\documentclass{article}
\usepackage{tikz}
\usepackage{etoolbox}
\newcommand\process[1]{\expandafter\ifstrequal\expandafter{#1}{Fridge}{EQUAL}{UNEQUAL}}
\begin{document}
\foreach \a in {Fridge,Badger} {\process{\a} }
\end{document}

enter image description here


The manual of etoolbox says (section 3.6.3)

\ifstrequal{⟨string⟩}{⟨string⟩}{⟨true⟩}{⟨false⟩}
Compares two strings and executes ⟨true⟩ if they are equal, and ⟨false⟩ otherwise. The strings are not expanded in the test and the comparison is category code agnostic. Control sequence tokens in any of the ⟨string⟩ arguments will be detokenized and treated as strings.

In other words, you are comparing

\a

(a two character string) with Fridge and they're not equal at all. With expl3 you can access an expanding string comparison function:

\documentclass{article}
\usepackage{xparse}
\usepackage{tikz}

\ExplSyntaxOn
\NewExpandableDocumentCommand{\xifstrequal}{mmmm}
 {
  \str_if_eq_x:nnTF { #1 } { #2 } { #3 } { #4 }
 }
\ExplSyntaxOff

\newcommand\process[1]{\xifstrequal{#1}{Fridge}{EQUAL}{UNEQUAL}}

\begin{document}

\foreach \a in {Fridge,Badger} {\process{\a} }

\end{document}

A full expl3 version:

\documentclass{article}
\usepackage{xparse}

\ExplSyntaxOn
\NewExpandableDocumentCommand{\xifstrequal}{mmmm}
 {
  \str_if_eq_x:nnTF { #1 } { #2 } { #3 } { #4 }
 }
\NewDocumentCommand{\listforeach}{mm}
 {
  \clist_map_inline:nn { #1 } { #2 }
 }
\ExplSyntaxOff

\newcommand\process[1]{\xifstrequal{#1}{Fridge}{EQUAL}{UNEQUAL}}

\begin{document}

\listforeach{Fridge,Badger}{\process{#1} }

\end{document}

Instead of using some dummy control sequence, the current item is denoted by #1.

Both codes produce the same output.

enter image description here