# Itemize with a variable number of parameters using xparse

I'm trying to write a command that gives an itemlist (itemize) which takes a variable number of parameters: It can accept up to 3 parameters, but should be able to work similarly with 1 or 2 parameters. This means that only the first parameters is mandatory while the second and last are optional.

\documentclass{article}

% customize sections style
\usepackage{xparse}
\NewDocumentCommand{\customitemize}{moo}{
\begin{itemize}
\item #1
\IfNoValueT{#2} {\item #2}
\IfNoValueT{#3} {\item #3}
\end{itemize}
}

\begin{document}
\customitemize{parameter1}{parameter2}{parameter3}
\customitemize{parameter1}{parameter2}
\customitemize{parameter1}
\end{document}


The issue I have with the code above is that even if the second and third parameters are not given, it outputs a No-Value which obviously isn't what I was looking to get. I can't tell what's the problem with the previous code from its results:

• Arguments defined with o should be in brackets [...], not in braces {...}. Also the test is wrong, it should be \IfValueT or \IfNoValueF. – egreg Dec 17 '16 at 22:31

Arguments defined with o should be enclosed in brackets [...], not braces.

\documentclass{article}

% customize sections style
\usepackage{xparse}
\NewDocumentCommand{\customitemize}{moo}{%
\begin{itemize}
\item #1
\IfValueT{#2} {\item #2}
\IfValueT{#3} {\item #3}
\end{itemize}
}

\begin{document}

\customitemize{parameter1}[parameter2][parameter3]

\customitemize{parameter1}[parameter2]

\customitemize{parameter1}

\end{document}


Note that your test is wrong: it should be \IfValueT.

You might define the arguments with mgg and the braces notation would be the right one, but I'd not recommend it.

Much better:

\documentclass{article}
\usepackage{xparse}

\ExplSyntaxOn
\NewDocumentCommand{\customitemize}{m}
{
\begin{itemize}
\clist_map_inline:nn { #1 } { \item ##1 }
\end{itemize}
}
\ExplSyntaxOff

\begin{document}

\customitemize{parameter1, parameter2, parameter3}

\customitemize{parameter1, parameter2}

\customitemize{parameter1}

\end{document}