16

Is there a way to compare a LaTeX3 token list to string without having to create a temporary token list? I though I'd use \tl_use:N to get the contents of the token list for the comparison, but that doesn’t seem to work.

\documentclass{article}
\usepackage{expl3}


\begin{document}
\ExplSyntaxOn
\tl_new:N \my_tl
\tl_set:Nn \my_tl {foo}
\tl_if_eq:nnTF {\tl_use:N \my_tl} {foo} {True} {False}

\tl_new:N \my_ii_tl
\tl_set:Nn \my_ii_tl {foo}
\tl_if_eq:NNTF \my_tl \my_ii_tl {True} {False}
\ExplSyntaxOff
\end{document}

1 Answers1

13

You want to create a variant of \tl_if_eq:nn(TF) which will take the value of one variable and a literal second argument:

\cs_generate_variant:Nn \tl_if_eq:nnTF { V }

You can then do

\tl_if_eq:VnTF \my_tl { foo } { True } { False }

An alternative would be to use the lower-level o-type expansion, which here will have the same effect

\cs_generate_variant:Nn \tl_if_eq:nnTF { o }
\tl_if_eq:onTF { \my_tl } { foo } { True } { False }
Joseph Wright
  • 259,911
  • 34
  • 706
  • 1,036