# Weird xparse issue involving splitlist

\DeclareDocumentCommand\test{o}{\IfNoValueOrEmptyTF{#1}{No value or     empty!}{-#1-}}


works, but when we try to use a split list the NoValueOrEmpty test fails:

\DeclareDocumentCommand\test{ > { \SplitList { , } }o}{\IfNoValueOrEmptyTF{#1}{No value or empty!}{-#1-}}


It seems an empty splitlist is not the same as empty?

\makeatletter
\newcommand{\IfNoValueOrEmptyTF}[3]
{
\IfNoValueTF{#1}{#2}
{
\def\@tempa{#1}
\ifx\@tempa\@empty#2\else#3\fi
}
}
\makeatother

-
I think that has to do with the fact each element is wrapped in a brace group {}, so just using \IfNoValueTF #1 (without the braces) should work. – Peter Grill Jul 13 '12 at 23:05
Seems that both \IfNoValueTF{#1} and \IfNoValueTF #1  seem to work just fine for me. And even using \IfNoValueOrEmptyTF, so perhaps I did not properly set up the test case. Can you post a complete MWE. – Peter Grill Jul 13 '12 at 23:10
@PeterGrill try \IfNoValueTF #1 with \test{a,b,c}, it will fail, since \SplitList causes #1 to be {a}{b}{c}. – Bruno Le Floch Jul 14 '12 at 0:49
As I commented elsewhere, empty arguments and missing (NoValue) arguments are not the same. Trying to test as you are suggests that your input syntax is not well-behaved. – Joseph Wright Jul 14 '12 at 8:06
@JosephWright Yes, but there is also a difference between an empty argument, novalue, and empty list. – AbstractDissonance Jul 14 '12 at 13:47

After \SplitList, an initially empty arguments yields {}, the token list with one item, which is empty. So replace the emptyness test with \tl_if_eq:nnTF {#1} { {} }. Namely,

\documentclass{article}
\usepackage{xparse}
\ExplSyntaxOn
\NewDocumentCommand{\IfNoValueOrSplitEmptyTF}{mmm}
{
\IfNoValueTF {#1}
{#2}
{ \tl_if_eq:nnTF {#1} { {} } {#2} {#3} }
}
\ExplSyntaxOff
\NewDocumentCommand{\test} { > { \SplitList { , } } o }
{\IfNoValueOrSplitEmptyTF {#1} {No value} {-#1-}}
\begin{document}
\test
\test[]
\test[,]
\test[a,b,{c=d,e,f},g]
\end{document}


I'm not sure you should be ignoring the user's will to have an empty argument: typically, no argument and an empty optional argument should behave differently.

-
I think his working case \DeclareDocumentCommand\test{o}{\IfNoValueOrEmptyTF{#1}{No value or empty!}{-#1-}} now fails with this for \test[]. An empty test in place of #3 fixes it. – Scott H. Jul 14 '12 at 1:09
Thanks Bruno, Another way is simply to do  \IfNoValueOrEmptyTF{#1} {No value or empty!} { \IfNoValueOrEmptyTF #1 {No value or empty!} { xxx#1xxx } } Where we first check the value to be empty and if not then we check the list to be empty. – AbstractDissonance Jul 14 '12 at 13:50
@ScottH. That's why I included the word Split in the command name for my test: presumably, AbstractDissonance knows if he has split the argument or not. – Bruno Le Floch Jul 14 '12 at 14:50
@AbstractDissonance No, try with an argument such as a,b,c: \SplitList produces {a}{b}{c}, and \IfNoValueOrEmptyTF would take a, b, and c as its argument. Try it. If you really want, use \tl_if_empty:nTF {#1} {#2} {#3} in place of #3 in the code. – Bruno Le Floch Jul 14 '12 at 14:52
Yes, your right. – AbstractDissonance Jul 14 '12 at 14:58