Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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}
share|improve this question

1 Answer 1

up vote 9 down vote accepted

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 }
share|improve this answer
    
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

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.