[texhax] Handling arrays or lists in LaTeX command arguments

Brandon Kuczenski brandon at 301south.net
Thu Apr 22 01:49:37 CEST 2010


Hi TeXers,

I'm hunting for a TeX or LaTeX macro which processes an argument as a 
[c-style] array with a (possibly arbitrary, possibly fixed) number of 
entries.

For instance, I imagine three hypothetical LaTeX commands:

\defarray{\arrayname}{num}{[element1,element2,element3...]}

creates an array called \arrayname with num elements.  Here I assume the 
elements are comma-separated and enclosed in brackets, but that is just 
for example.

\arraydo{\arrayname}{operation}

performs 'operation' once for each element in the array in succession.

\thearrayelement

(within \arraydo) expands to the current element in the array.

Is such a thing remotely possible?  Anything that points in this 
direction would be appreciated.  The ability to index into the array 
would be extra-special.



%%-----------------------
%% code sample

\newcommand{\boxnumbers}[1]{ %
   \arraydo{#1}{% hypothetical array expander
	\fbox{\thearrayelement}\;%
	} %
}

% The Sequence
\defarray{\foo}{6}{[4,8,15,16,23,42]} % hypothetical array constructor

\boxnumbers{\foo}

%% end code sample
%%-----------------------

would create a series of boxes, each containing a number from The Sequence.

thanks for any pointers,
Brandon

--



More information about the texhax mailing list