Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I used to have a definition like the following to check if all optional arguments were missing:

\NewDocumentCommand \question {o o o m} {
    \bool_if:nTF {
        \str_if_eq_p:nn { \NoValue } { #1 } &&
        \str_if_eq_p:nn { \NoValue } { #2 } &&
        \str_if_eq_p:nn { \NoValue } { #3 }
     } {
         <DO STUFF 1>
     } {
         <DO STUFF 2>
     }
}

But that broke with the latest xparse update. Now there seems to be only the \IfNoValueTF{}{}{} macro but then I have to repeat one the DO STUFF x things. I read the xparse.sty but there seems to be no such easy solution anymore due to the QNoValue- "hack".

Any ideas?

share|improve this question
2  
The reason for removing the token was precisely because it should not be used in this way! You could use the fact that the new definition is the text -NoValue-, but I would not encourage relying on this. Instead, I'd ask what your overall input is here. The test you want suggests that your syntax choice is poor: could you explain what it is you actually want to achieve? –  Joseph Wright Aug 25 '12 at 16:13
    
You may very well have a point here. The optional part is a location made up of three parts that I want to use differently. The three arguments just save me from parsing a comma-separated list, I was too lazy to write it. –  MiB Aug 25 '12 at 16:41
    
@JosephWright The -NoValue you wrote should be -NoValue- at the moment (it might have changed since). MiB, it might be useful to ask a question on how to parse a comma-separated list (but first check whether that's been covered before). Also: note that the three arguments are all "no value" if and only if the third argument is "no value", since arguments with identical delimiters are populated from left to right. –  Bruno Le Floch Aug 25 '12 at 18:49
    
@BrunoLeFloch Fixed: I'd forgotten that other people can't sort typos in comments :-) –  Joseph Wright Aug 25 '12 at 18:56

1 Answer 1

up vote 4 down vote accepted

Edit: Since blank values aren't “no values” it is sufficient to check if the first option is given:

\ExplSyntaxOn
\NewDocumentCommand \question { o o o m } {
    \IfNoValueTF { #1 } {
         <DO STUFF 1>
     } {
         <DO STUFF 2>
     }
}
\ExplSyntaxOff

Depending on the type of expected input an overall different syntax might be a better way, though. Three optional arguments make a command unnecessary complicated for most cases. Maybe one optional argument expecting a keyval-like input would be a better choice?

Old answer:

Here's an idea:

\documentclass{article}
\usepackage{expl3,xparse}

\ExplSyntaxOn
\NewDocumentCommand \question {O{\NoValue} O{\NoValue} O{\NoValue} m} {
    \bool_if:nTF {
        \str_if_eq_p:nn { \NoValue } { #1 } &&
        \str_if_eq_p:nn { \NoValue } { #2 } &&
        \str_if_eq_p:nn { \NoValue } { #3 }
     } {
         <DO STUFF 1>
     } {
         <DO STUFF 2>
     }
}
\ExplSyntaxOff

\begin{document}

\question{}

\question[]{}

\question[][]{}

\question[][][]{}
\end{document}
share|improve this answer
    
hey, that was smart! thanks! –  MiB Aug 25 '12 at 16:11

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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