\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?

  • 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. Jul 13, 2012 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. Jul 13, 2012 at 23:10
  • @PeterGrill try \IfNoValueTF #1 with \test{a,b,c}, it will fail, since \SplitList causes #1 to be {a}{b}{c}. Jul 14, 2012 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, 2012 at 8:06
  • @JosephWright Yes, but there is also a difference between an empty argument, novalue, and empty list. Jul 14, 2012 at 13:47

1 Answer 1


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,

    \IfNoValueTF {#1}
      { \tl_if_eq:nnTF {#1} { {} } {#2} {#3} }
\NewDocumentCommand{\test} { > { \SplitList { , } } o }
  {\IfNoValueOrSplitEmptyTF {#1} {No value} {-#1-}}

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, 2012 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. Jul 14, 2012 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. Jul 14, 2012 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. Jul 14, 2012 at 14:52
  • Yes, your right. Jul 14, 2012 at 14:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.