xparse optional parameter IfValueT true without parameter

I created a custom commadn with one mandatory and 4 optional parameters with

\DeclareDocumentCommand \quote { m o o o o} {%
\glqq\textit{#1}\grqq\
\IfValueT {#2 \OR #3 \OR #4 \OR #5} {(}%
\IfValueT {#2}{p. #2}%
\IfValueT {#3}{, ll. #3}%
\IfValueT {#4}{, \textsc{#4}}%
\IfValueT {#5}{, #5}%
\IfValueT {#2 \OR #3 \OR #4 \OR #5} {)}%
}


But using

\quote{something}


returns

What am i doing wrong, and yes I know the code has some other flaws cosidering it should be a quote.

• Welcome to TeX.SX! Please help us (and also you) and add a minimal working example (MWE), that illustrates your problem. Reproducing the problem and finding out what the issue is will be much easier when we see compilable code, starting with \documentclass and ending with \end{document}. – Bobyandbob Dec 16 '17 at 17:28
• I've no idea where you are getting \OR from but it's clear that #2 \OR #3 \OR #4 \OR #5 is never going to be exactly equal to -NoValue- (a marker for exactly one optional argument being absent). – Joseph Wright Dec 16 '17 at 17:39
• So I need to nest all of them as in \IfValueT {#2}{\IfValueT {#3}{\IfValueT {#4}{\IfValueT {#5}{(}}}}? – Berserkker Dec 16 '17 at 17:47
• First of all you should never use \DeclareDocumentCommand if you don't know what you're doing (\quote is already defined in LaTeX). Second, a command with four optional arguments will be a nightmare for users. – egreg Dec 16 '17 at 17:50
• apart from the syntax not being correct what do you want \IfValueT {#2 \OR #3 \OR #4 \OR #5} {(}% to do? you only need to test #2 as it is not possible #3 to be supplied but not #2 (which is why having consecutive optional arguments is almost never a good choice) – David Carlisle Dec 16 '17 at 17:52

There is no \OR for multiple tests of \IfValueTF. You could implement one:

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage[ngerman]{babel}
\usepackage{xparse}

\ExplSyntaxOn
\NewDocumentCommand{\QUOTE}{moooo}
{
\glqq\textit{#1}\grqq
\berserker_quote_if_novalue:nnnnF { #2 } { #3 } { #4 } { #5 } { ~( }
\IfValueT{#2}{p.~#2}%
\IfValueT{#3}{,~ll.~#3}%
\IfValueT{#4}{,~\textsc{#4}}%
\IfValueT{#5}{,~#5}%
\berserker_quote_if_novalue:nnnnF { #2 } { #3 } { #4 } { #5 } { ) }
}

\prg_new_conditional:Nnn \berserker_quote_if_novalue:nnnn { TF,T,F,p }
{
\bool_lazy_all:nTF
{
{\tl_if_novalue_p:n { #1 }}
{\tl_if_novalue_p:n { #2 }}
{\tl_if_novalue_p:n { #3 }}
{\tl_if_novalue_p:n { #4 }}
}
{ \prg_return_true: }
{ \prg_return_false: }
}
\ExplSyntaxOff

\begin{document}

\QUOTE{I said}

\QUOTE{I said}[a]

\QUOTE{I said}[a][b]

\QUOTE{I said}[a][b][c]

\QUOTE{I said}[a][b][c][d]

\end{document}


Caveat This doesn't work with the present release of expl3, due to a definition that unfortunately slipped out. A fix should be on its way.

A better way to go would be with a key-value syntax. Use more meaningful names, as it's not really clear what the arguments are supposed to contain.

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage[ngerman]{babel}
\usepackage{xparse}

\ExplSyntaxOn
\NewDocumentCommand{\QUOTE}{mo}
{
\glqq\textit{#1}\grqq
\group_begin:
\IfValueT{#2}{ ~( \berserker_quote_options:n { #2 } ) }
\group_end:
}

\keys_define:nn { berserker/quote }
{
p .tl_set:N = \l__berserker_quote_page_tl,
l .tl_set:N = \l__berserker_quote_lines_tl,
n .tl_set:N = \l__berserker_quote_note_tl,
c .tl_set:N = \l__berserker_quote_comment_tl,
}

\cs_new_protected:Nn \berserker_quote_options:n
{
\keys_set:nn { berserker/quote } { #1 }
\tl_if_empty:NF \l__berserker_quote_page_tl {p.~\l__berserker_quote_page_tl}
\tl_if_empty:NF \l__berserker_quote_lines_tl {,~ll.~\l__berserker_quote_lines_tl}
\tl_if_empty:NF \l__berserker_quote_note_tl {,~\textsc{\l__berserker_quote_note_tl}}
\tl_if_empty:NF \l__berserker_quote_comment_tl {,~\l__berserker_quote_comment_tl}
}
\ExplSyntaxOff

\begin{document}

\QUOTE{I said}

\QUOTE{I said}[p=a]

\QUOTE{I said}[p=a,l=b]

\QUOTE{I said}[p=a,l=b,n=c]

\QUOTE{I said}[p=a,l=b,n=c,c=d]

\end{document}