TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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
up vote 10 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.