I tend to get \IfBooleanTF
and \IfNoValueTF
(and the other similar macros) mixed up and wondering which is the correct ones to use for the following optional parameters:
s
,
o
,
d
,
g
,
k_
(and k^
) and
t_
(and t^
).
From the documenation it seems that one should use:
\IfBooleanTF
:s
,t
\IfNoValueTF
:o
,d
,g
,k
Questions:
- Is the above list of macros to use correct?
- What is the intention of distinguishing between
\IfBooleanTF
and\IfNoValueTF
? Wouldn't it make sense to just have one macro that does both jobs? Or, is there a case where a distinction is required?t
andk
using different macros is especially confusing to me.
My reason for asking is: If I can understand the logic behind this, perhaps I'll be able to remember to use the correct ones.
Follow-up Question:
References:
s
: Defining starred versions of commands (* macro)o
: xparse: Define new command with multiple optional parametersd
: Combine todonotes with mdframed to highlight paragraphs and write notes,g
: Is it possible to use {} as delimiter for an optional xparse argument?k
: Xparse k argument to parse options at end of environmentt
: Xparse t argument type (underscore with optional parameter)
Best Answer
Yes, the above is correct.
The two cases are logically distinct as you are passing different information. The aim of
xparse
is to make this structural information clear.For
\IfBoolean(TF)
, the argument is a single token which can only be one of two values: TRUE and FALSE. A value is always returned by thet
(ands
) argument types, and the test is there to see which it is. One may also reverse the logic returned here using\ReverseBoolean
: the presence of the token does not have to map to logically TRUE.On the other hand, argument types which grab 'some tokens' may not be present (so yield
\NoValue
), be present-but-empty or be present-and-non-empty. The logic that something is present cannot be reversed so\IfNoValue
will always be true only if the optional argument was not given at all.The
k
-type argument has recently been adjusted: you now wante
-type. This one is somewhat specialised and the team have had quite a bit of discussion about the correct form here.