Ok, in lua it’s indeed simple:
\startluacode
list = {"foo", "bar", "baz"}
\stopluacode
\starttext
\startluacode
for i, v in ipairs(list) do
if i == #list then
tex.print("last:")
tex.print(v)
elseif i == 1 then
tex.print("first:")
tex.print(v)
else
tex.print("in between:")
tex.print(v)
end
end
\stopluacode
\stoptext
But, it’d still love to hear whether there is a solution on the tex side.
Denis
Von: Maier, Denis Christian (UB)
Gesendet: Montag, 2. Mai 2022 09:15
An: 'mailing list for ConTeXt users' <ntg-context@ntg.nl>
Betreff: process list items differently depending on position in list
Hi,
I need to process a comma separated list, and adapt the formatting according to the position of an item in the list (example below). Expected output would be:
{\bf foo
}, {\em bar} and baz.
Is that possible? Can I somehow get the position of an item in the list? (My understanding is that \processcommalist and \processcommacommand apply a command to each list item, but there is no such thing as «position
in the list»... I hope I’m wrong here.)
Or is that something where using Lua would be a better choice?
Best,
Denis
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\define[1]\command
{#1}
\define\somelist
{foo, bar, baz}
\starttext
\processcommacommand
[\somelist]
\command
\stoptext
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%