I'm trying to expand a macro argument with a counter inside a for loop with the next code:
\documentclass{article}
\usepackage{xparse}
\usepackage{forloop}
\NewDocumentCommand\test{m O{II} O{III} O{IV}}{
\newcounter{i}
\forloop{i}{1}{\thei < 5}{
#1\thei : #\thei \quad
}
}
\begin{document}
\test{A}
\end{document}
This yield two errors:
! Illegal parameter number in definition of \test code.
! You can't use `macro parameter character #' in horizontal mode.
I'm trying to achieve an output like this:
A1:A A2:II A3:III A4:IV
i.e., I want to iterate through the macro parameters.
It seems that the problem is in the #\thei
part. So some of the things I've tried so far are \expandafter #\thei
or \expandafter #\numexpr\thei\relax
without success.
I've been searching for information in TeX by Topic but I can't find anything helpful in this regard. I would appreciate some help if posssible!
Here I leave a fully compiling variant for testing purposes, this of course is not the desired behavior:
\documentclass{article}
\usepackage{xparse}
\usepackage{forloop}
\NewDocumentCommand\test{m O{II} O{III} O{IV}}{
\newcounter{i}
\forloop{i}{1}{\thei < 5}{
#1\thei : #1 \quad
}
}
\begin{document}
\test{A}
\end{document}
which outputs:
A1:A A2:A A3:A A4:A
#
, so this cannot really work. See e.g. tex.stackexchange.com/q/200283/82917. There might be other ways, but a detailed example of what the input and expected output should be would be helpful.