0

I ran into a problem when creating a new condition. The meaning of the condition \foo_if_eq is to check the global variable \g_my_tl for compliance with a certain string bar, the result is true/false. The condition is created and works, but when inserting it into another condition, an error is generated at the build stage - Missing number, treated as zero. I can't understand the reason for the error.

\documentclass{article}
\usepackage {expl3}

\ExplSyntaxOn
\tl_new:N \g_my_tl
\tl_gset:Nn \g_my_tl {bar}

\prg_new_conditional:Npnn \foo_if_eq:n #1 {p, T, F, TF}
{
  \tl_if_eq:NnTF \g_my_tl {#1}
    { \prg_return_true:  }
    { \prg_return_false: }
}

\NewDocumentCommand {\testNewConditional} {}
{
  \foo_if_eq:nTF {bar} % OK
    {TRUE}{FALSE} \\

  \bool_if:nTF { \foo_if_eq_p:n {bar} } % FAIL (Missing number, treated as zero)
    {TRUE}{FALSE} \\
}
\ExplSyntaxOff

\begin{document}
  \testNewConditional
\end{document}

\endinput

If I use \str_if_eq instead of \tl_if_eq in the new check, then the build goes without errors and everything works correctly. Why?

\documentclass{article}
\usepackage {expl3}

\ExplSyntaxOn
\tl_new:N \g_my_tl
\tl_gset:Nn \g_my_tl {bar}

\prg_new_conditional:Npnn \foo_if_eq:n #1 {p, T, F, TF}
{
  \str_if_eq:VnTF \g_my_tl {#1}
    { \prg_return_true:  }
    { \prg_return_false: }
}

\NewDocumentCommand {\testNewConditional} {}
{
 \foo_if_eq:nTF {bar} % OK
    {TRUE}{FALSE} \\

  \bool_if:nTF { \foo_if_eq_p:n {bar} } % OK
    {TRUE}{FALSE} \\
}
\ExplSyntaxOff

\begin{document}
  \testNewConditional
\end{document}

\endinput
3
  • 1
    the argument to \bool_if:nTF needs to expand to a boolean but you have \tl_set:Nn which is a non-expandable assignment Oct 6, 2022 at 14:02
  • Depending on what you want to compare, you might try with \str_if_eq:nnTF
    – egreg
    Oct 6, 2022 at 14:10
  • I corrected the example by removing the setting of the temporary variable \l_tmpa_tl from it, but this did not change the result Oct 6, 2022 at 16:27

1 Answer 1

0

You cannot create predicates which use functions which are not fully expandable (marked with a star in interface3). Here, \tl_if_eq:nn is not expandable, so it cannot be used inside the definition of a predicate. In contrast, \str_if_eq:nn is expandable so can be.

You must log in to answer this question.

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