3

Im sure this must be something very simple but it is eluding me.

The following code outputs F. Shouldn't it output T?

\documentclass{article}
\usepackage{expl3}
\begin{document}

\ExplSyntaxOn


\tl_new:N \otherlist
\tl_clear_new:N \otherlist

\tl_if_empty:nTF {\otherlist} {T} {F}


\ExplSyntaxOff

\end{document}
  • 3
    \tl_if_empty:NTF \otherlist would give T, but ìn \tl_if_empty:nTF {\otherlist} the "n" contains \otherlist. – Ulrike Fischer Feb 3 '16 at 19:06
  • Off-topic: \tl_clear_new:N \otherlist isn't necessary – user31729 Feb 3 '16 at 19:15
5

The test \tl_if_empty:NTF \l_bob_otherlist_tl {}{} sees just the empty token list \l_bob_otherlist_tl, but \tl_if_empty:nTF {\l_bob_otherlist_tl} {}{} sees one token in the 'list' delimited by {...}.

See the difference for example with the \tl_count:n and \tl_count:N macros:

\documentclass{article}
\usepackage{expl3}
\begin{document}

\ExplSyntaxOn


\tl_new:N \l_bob_otherlist_tl


First:  \tl_if_empty:nTF \l_bob_otherlist_tl {T} {F}
\par
Second: \tl_if_empty:NTF \l_bob_otherlist_tl {T} {F}
\par
Third: \tl_if_empty:nTF {\l_bob_otherlist_tl} {T} {F}
\par
\par
Counting~with~n: \tl_count:n {\l_bob_otherlist_tl}
\par
Counting~with~N: \tl_count:N \l_bob_otherlist_tl
\tl_set:Nn \l_bob_otherlist_tl {Foo}
\par
After~setting:\par
First:  \tl_if_empty:nTF \l_bob_otherlist_tl {T} {F}
\par
Second: \tl_if_empty:NTF \l_bob_otherlist_tl {T} {F}
\par
Third: \tl_if_empty:nTF {\l_bob_otherlist_tl} {T} {F}
\par
Counting~with~n: \tl_count:n {\l_bob_otherlist_tl}
\par
Counting~with~N: \tl_count:N \l_bob_otherlist_tl


\ExplSyntaxOff

\end{document}

The \tl_clear_new:N isn't necessary since \tl_new:N already provides an empty, clean list.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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