I have been trying to fill an grid with "binary" type data, so you iterate through an array that is 2D and these 1s and 0s decide if a location is filled or not. This is my first foray into programming, as such, in LaTeX.
I can successfully create fill a single box with the macro that I made, but I have not been able to automate it. \gridbox is my macro, and it will put a box where I want it. As an example of what I want to do, I have an array here:
\def\BITARRAY{{
{1,0,0,1},
{1,0,0,0},
{0,1,0,0},
{0,1,1,0},
{0,0,0,1}
}}
I have the \foreach working so I can look at each piece of data. I want to test it so that if there's a "1", I put the the box at the location.
The problem: my \ifthenelse does not like my macro. The minimal TeX code follows, sorry that it's long, but I decided to leave my comments in it.
\documentclass[journal,letterpaper]{IEEEtran}
\usepackage{fp}
\usepackage{tikz,ifthen}
\begin{document}
\newcommand\bitfieldwidth{4}
\newcommand\numberofrounds{5}
\makeatletter
%divide the column width by the bitfield width to figure out how many boxes we need
\FPeval{\blockwidth}{((\strip@pt\columnwidth) / \bitfieldwidth)}
%truncate the decimals
\FPtrunc\blockwidth{\blockwidth}{0}
%get a whole number, but then truncate it anyway
\FPmul\gridwidth{\bitfieldwidth}{\blockwidth}
\FPtrunc\gridwidth{\gridwidth}{0}
\FPmul\gridheight{\numberofrounds}{\blockwidth}
\FPtrunc\gridheight{\gridheight}{0}
\makeatother
% this creates a box at the appropriate location
% It just uses the index and not a location, so it can scale with
% the type of grid width
\newcommand{\gridbox}[2]{ %you pass the x,y of the lower location.
\fill [orange] ( #1 * \blockwidth pt , - #2 * \blockwidth pt ) rectangle (#1 * \blockwidth + \blockwidth pt, - #2 * \blockwidth + \blockwidth pt)
}
\def\BITARRAY{{
{1,0,0,1},
{1,0,0,0},
{0,1,0,0},
{0,1,1,0},
{0,0,0,1}
}}
\begin{tikzpicture}
\draw[step=\blockwidth pt,gray,very thin] (0pt,0pt) grid (\gridwidth pt,- \gridheight pt);
\foreach \y in {1,...,\numberofrounds}{ %the y is going down the array, the x is left to right
\foreach \x in {1,...,\bitfieldwidth}{
%\pgfmathtruncatemacro{\resultbit}{int(\BITARRAY[\y-1][\x-1])}
%\ifthenelse{\value{1}<1}{\gridbox{\y}{\x};}{\gridbox{\y}{\x};};
}
}
\gridbox{1}{2};
\end{tikzpicture}
\end{document}
question: How must I format the \ifthenelse macro to take my macro that will draw a box. With that \ifthenelse commented out, I can show that the grid box macro works. The image follows.
Any suggestions would be greatly appreciated.



(\x - .5, -\y + .5) node[text=black] {\cell}between\fiand\pgfextra. – Heiko Oberdiek Aug 09 '19 at 19:51