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.


\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}

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

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.