I need to pass 1,2,3,...,\Num to the variable list argument of the \DefineArrayVar command from the forarray package. If I pass it manually, everything works fine, but, when I pass a command instead, \DefineArrayVar gets confused and fails.
Here is my MWE:
\documentclass{article}
\usepackage{forloop}
\usepackage{forarray}
\newcommand{\Num}{4}
\newcounter{ct}
\setcounter{ct}{1}
\newcommand{\test}{%
\forloop{ct}{1}{\value{ct}<\Num}{\thect,}\thect%
}
\DefineArrayVar{ArrayName}{@}
{,}{1,2,3,4} % <---- This works
% {,}{\test} % <---- This doesn't work
% {,}{\forloop{ct}{1}{\value{ct} < \Num}{\thect,}\thect} % <---- This doesn't work either
{,}{4cm,0.8cm,0.6cm,1.6cm}
% This doesn't work
% \expandafter\DefineArrayVar\expandafter{ArrayName}{@}{,}{\test}{,}{4cm,0.8cm,0.6cm,1.6cm}
\DefineArrayDefault{,}{@}{2}{2}{ArrayName}
\begin{document}
\test % To see what 'forloop' is generating
\ArrayName % Proof that it's working (must print "0.8cm")
\end{document}
Based on this answer and this answer (which are very much related to my problem), I also tried to use (separately) \expandafter or \edef like so:
\expandafter\DefineArrayVar\expandafter{ArrayName}{@}{,}{\test}{,}{4cm,0.8cm,0.6cm,1.6cm}
\edef\test{\unexpanded\expandafter{\forloop{ct}{1}{\value{ct}<\Num}{\thect,}\thect}}
but it didn't work.
Well, since I do not understand big picture of what I am doing, I can't go further. How do I make it work?


\DefineArrayVar's argument though :) – Leone Mar 17 '21 at 20:04