I am trying to display a Hilbert-matrix and to color the antidiagonals by varying colors choosen from an array, so that cell (i,j) gets color \Colors[i+j-1 mod 3] (so in order that nearby cells with equal value get the same color). The coloring on the Hilbert-matrix I got does not work (yet).
I tried to follow (Changing color in foreach using arrayjob) but I can't figure out, how to compute the color in fashion that I can use it later in the draw-command.
I tried to define it by use of execute at begin cell:
\documentclass[tikz,border=2mm]{standalone}
\usepackage{tikz}\usetikzlibrary{matrix}
\begin{document}
\newcommand{\Colors}{{%
"FF0000","00FF00","0000FF",%
%"FF0000","00FF00","0000FF",
}}
%hilbert matrix
\begin{tikzpicture}[
mygridmatrix/.style={matrix of nodes,
nodes={rectangle,
draw,
execute at begin cell=\pgfmathsetmacro{\thecurrentcolor}{\Colors[\the\pgfmatrixcurrentcolumn]}\definecolor{currentcolor}{HTML}{\thecurrentcolor},
fill=currentcolor,
minimum width=8mm,
minimum height=8mm,
node contents={$\frac{1}{\the\pgfmatrixcurrentrow+\the\pgfmatrixcurrentcolumn-1}$},
},
nodes in empty cells,
},
]
\matrix (m) [mygridmatrix]
{
&&&\\
&&&\\
&&&\\
&&&\\
};
\end{tikzpicture}
\end{document}
but this yields only ! Package xcolor Error: Undefined color 'currentcolor'. :(
Replacing currentcolor by any real color like red makes it working, but then all antidiagonals get the color (and not the ones according to \Colors-array).
Any help appreciated.
