I want to define a conditional function \if_is_int:n(TF) to test if the parameter is an integer, so I wrote:

    \prg_new_conditional:Npnn \my_cond:n #1 { p, T, F, TF } 
        \regex_match:nnTF { [\+\-]?\d+ } { #1 }
          { \prg_return_true: }
          { \prg_return_false: } 
    \bool_if:nTF { \my_cond_p:n { hello } } { true } { false } % missing number
    % \my_cond:nTF { hello } { true } { false } % output false

After pdflatex, it returns

! Missing number, treated as zero.
<to be read again> 
l.11     \bool_if:nTF { \my_cond_p:n { hello } }
                                                 { true } { false } % missin.

If I use \if_is_int:nTF directly, it works fine.

I found this answer https://tex.stackexchange.com/a/630105/180617 which says:

Boolean expressions in expl3 work by expansion, and so they can only contain expandable functions in their implementation: those are marked with a star in interface3.pdf

So I can't use \regex_match:nnTF in \prg_new_conditional:Npnn since \regex_match:nnTF is \protected?

enter image description here

However, if I use \prg_new_protected_conditional:Npnn, I can't use the p parameter that I need.

Is there any way to use \if_is_int_p:n to test "if is integer" in a \bool_if:nTF ?

1 Answer 1


You cannot use any non-expandable functions in defining a predicate, ad the linked answer suggests. That means that you cannot use for example any regex functions in a predicate. Instead, you will need to rework your approach to use a TF branch - this may mean you have to be a bit more 'repetitive'.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .