Generalexpl3: don't understand behavior of tl_if_novalue:nTF

LaTeX specific issues not fitting into one of the other forums of this category.
Post Reply
erwann
Posts: 75
Joined: Thu Aug 25, 2016 2:24 am

expl3: don't understand behavior of tl_if_novalue:nTF

Post by erwann »

Before opening a ticket bug I'd like to make sure it is one indeed.

Code: Select all

\documentclass{minimal}
\usepackage{expl3}
\ExplSyntaxOn
\begin{document}
\tl_if_novalue:nTF{\c_novalue_tl}{PASS}{FAIL} % prints FAIL
\ExplSyntaxOff
\end{document}
Attachments
Screenshot from 2018-05-05 20-13-18.png
Screenshot from 2018-05-05 20-13-18.png (27.7 KiB) Viewed 4990 times
x_86 / Linux Mint 18.3 / texlive 2015.20160320-1ubuntu0.1 / TeXworks 0.5r1361 (Debian)

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org
LaTeX books
zauguin
Posts: 4
Joined: Thu Jan 24, 2019 9:50 pm

expl3: don't understand behavior of tl_if_novalue:nTF

Post by zauguin »

Actually this is the expected behaviour even if the documentation is a bit misleading:

\tl_if_novalue:nTF tests if the token list is exactly equal to \c_novalue_tl, meaning equal to the special token list which is stored inside \c_novalue_tl. This is not the same as {c_novalue_tl}, the token list consisting of exactly one token, \c_novalue_tl itself.

So if you would use a V style argument instead to compare the value of \c_novalue_tl, you get the expected behaviour:

Code: Select all

\documentclass{minimal}
\usepackage{expl3}
\ExplSyntaxOn
\begin{document}
\cs_generate_variant:Nn \tl_if_novalue:nTF { VTF }
\tl_if_novalue:VTF \c_novalue_tl {PASS}{FAIL} % prints PASS
\ExplSyntaxOff
\end{document}
In most actual use cases the normal behaviour is fine: The novalue marker is passed mostly passed as an argument to your macro, then you can write e.g. \tl_if_novalue:nTF{#1}{PASS}{FAIL} because the argument is not wrapped in a macro/variable.
Post Reply