# Undefined control sequence error?

I am playing with the code adapted from here.

\documentclass{article}
\usepackage{tikz}
\tikzset{
nodeline/.style={midway, rotate=#1, minimum height=3.5mm, minimum       width=2.5mm},
}

\newcommand\trigram[2]{%
\begin{scope}[rotate=#1]% around={#1:(0,0)}
\def\alenanno{w}  %if it is ying
\clip (-1.1,3) -- (1.1,3) -- (0,0) -- cycle;
\foreac \x [count=\xx starting from 0, evaluate=\xx as \y using (1.75+.5*\xx)] in #2{%
\ifx\x\alenanno
\draw[line width=3mm] (-1.2,\y) -- (1.2,\y) node[nodeline=#1,fill=white] {};
\else
\draw[line width=3mm] (-1.2,\y) -- (1.2,\y);
\fi
}
\end{scope}
}

\begin{document}
\begin{tikzpicture}
\trigram{0}{b,w,w};
\end{tikzpicture}
\end{document}


When I compile, I am getting following error without output. Can anybody help with this?

ERROR: Undefined control sequence.
--- TeX said ---
\trigram ...-- (1.1,3) -- (0,0) -- cycle; \foreac
\x [count=\xx starting    fro...l.23   \trigram{0}{b,w,w}
;

• Welcome to TeX.SE! You have a typo in the code. It's \foreach, not \foreac. – Phelype Oleinik Jan 24 at 20:18

You spelled \foreach wrong and you are missing a set of braces around #2.

\documentclass{article}
\usepackage{tikz}
\tikzset{
nodeline/.style={midway, rotate=#1, minimum height=3.5mm, minimum       width=2.5mm},
}

\newcommand\trigram[2]{%
\begin{scope}[rotate=#1]% around={#1:(0,0)}
\def\alenanno{w}  %if it is ying
\clip (-1.1,3) -- (1.1,3) -- (0,0) -- cycle;
\foreach \x [count=\xx starting from 0, evaluate=\xx as \y using (1.75+.5*\xx)] in {#2} {%
\ifx\x\alenanno
\draw[line width=3mm] (-1.2,\y) -- (1.2,\y) node[nodeline=#1,fill=white] {};
\else
\draw[line width=3mm] (-1.2,\y) -- (1.2,\y);
\fi
}
\end{scope}
}

\begin{document}
\begin{tikzpicture}
\trigram{0}{b,w,w};
\end{tikzpicture}
\end{document}


• Thanks for the quick fix. I messed up the spelling for foreach. But the curly bracket was the devil! – Tony Tan Jan 24 at 20:42
• @TonyTan You can also leave out the braces around #2, but then you have to use \trigram{0}{{b,w,w}}; – Henri Menke Jan 24 at 20:56
• @marmot Sorry but I no longer waste my time drawing other people's pictures. – Henri Menke Jan 24 at 22:53