LaTeX forum ⇒ Generalexpl3: don't understand behavior of tl_if_novalue:nTF

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

expl3: don't understand behavior of tl_if_novalue:nTF

Postby erwann » Sun May 06, 2018 2:13 am

Before opening a ticket bug I'd like to make sure it is one indeed.
Code: [Select all] [Expand/Collapse] [Download] ({untitled.tex})
  1. \documentclass{minimal}
  2. \usepackage{expl3}
  3. \ExplSyntaxOn
  4. \begin{document}
  5. \tl_if_novalue:nTF{\c_novalue_tl}{PASS}{FAIL} % prints FAIL
  6. \ExplSyntaxOff
  7. \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 1362 times
x_86 / Linux Mint 18.3 / texlive 2015.20160320-1ubuntu0.1 / TeXworks 0.5r1361 (Debian)

zauguin
Posts: 2
Joined: Thu Jan 24, 2019 9:50 pm

Postby zauguin » Thu Jan 24, 2019 10:06 pm

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] [Expand/Collapse] [Download] ({untitled.tex})
  1. \documentclass{minimal}
  2. \usepackage{expl3}
  3. \ExplSyntaxOn
  4. \begin{document}
  5. \cs_generate_variant:Nn \tl_if_novalue:nTF { VTF }
  6. \tl_if_novalue:VTF \c_novalue_tl {PASS}{FAIL} % prints PASS
  7. \ExplSyntaxOff
  8. \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.


Return to “General”

Who is online

Users browsing this forum: No registered users and 17 guests