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 Answer 1

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 }
1
  • 1
    I may add the one or both of these to expl3, as I've also needed them from time to time.
    – Joseph Wright
    Commented May 13, 2012 at 7:11

You must log in to answer this question.

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