This syntax evaluate={...} is documented on page 704/1318 of the math library . I'm quoting from the manual:
/tikz/evaluate=<statements>(no default) This key simply executes\tikzmath{<statements>}.The following sections describe the miniature language that this library provides and can be used in the
\tikzmathcommand and theevaluatekey. The language consists only of simple keywords and expressions but the mini-parser allows you to format code in a reasonably versatile way (much like the tikz parser) except that all the keywords must be followed by at least one space. This is the second most important thing to remember (after remembering to insert semi-colons at the end of every statement).
And yet it works within a foreach loop without the need to load the math library.
Many answers here use the syntax evaluate={...} within a foreach loop instead of using the syntax documented on page 1003/1318 of the manual, which is I recall:
/pgf/foreach/evaluate=<variable> as <macro> using <formula>
For example here, Peter Grill uses it here.
The manual shows its use on page 1045/1318 to illustrate the macro
\pgfmathtodigitlist{<macro>}{<number>}
with this code:
\documentclass[margin=2mm,tikz]{standalone}
\begin{document}
\pgfmathsetbasenumberlength{8}
\begin{tikzpicture}[x=0.25cm, y=0.25cm]
\foreach \n [count=\y] in {0, 60, 102, 102, 126, 102, 102, 102, 0}{
\pgfmathdectobase{\binary}{\n}{2}
\pgfmathtodigitlist{\digitlist}{\binary}
\foreach \digit [count=\x, evaluate={\c=\digit*50+15;}] in \digitlist
\fill [fill=black!\c] (\x, -\y) rectangle ++(1,1);
}
\end{tikzpicture}
\end{document}
that produces this result
- Why does this syntax
evaluate={...}, which is defined (unless I am mistaken) in themathlibrary, work without this library being loaded in aforeachloop?
Translated with www.DeepL.com/Translator (free version)


evaluateare different things. Intikzlibrarymath.code.tex, there is\tikzset{evaluate/.code={\tikz@math{#1}}}. And inpgffor.code.tex, there isevaluate/.code=\pgffor@assign@evaluatetrue\pgffor@assign@oncefalse\pgffor@assign@parse{#1}, so statements of twoevaluateare actually processed in different ways. But as you say, to explain clearly need dive deeper into the source code. – ZhiyuanLck Aug 11 '20 at 07:50