1

I'm trying to test the value of an item in a sequence. The approach below doesn't seem to work. Could someone suggest a fix or alternative?

\documentclass{article}

\ExplSyntaxOn

\tl_new:N \l_test_tl
\seq_new:N \l_test_seq

\tl_set:Nn \l_test_tl { a }
\seq_set_from_clist:Nn \l_test_seq { a,b }

\begin{document}

\str_if_eq:VnTF { \l_test_tl } { a } { 1 } { 0 } \hspace{1em} % returns 1, as expected

\seq_item:Nn { \l_test_seq } { 1 } \hspace{1em} % returns a, as expected

\str_if_eq:VnTF { \seq_item:Nn { \l_test_seq } { 1 } } { a } { 1 } { 0 } \hspace{1em} % returns 0

\str_if_eq:nnTF { \seq_item:Nn { \l_test_seq } { 1 } } { a } { 1 } { 0 } % returns 0

\end{document}
2
  • Try \str_if_eq:eeTF May 8, 2021 at 21:16
  • @PhelypeOleinik That's got it, thanks!
    – mjc
    May 8, 2021 at 21:17

1 Answer 1

2

\str_if_eq:nnTF (emphasis on :nn) will treat the arguments literally (without expansion), so it compares the characters \seq_item:Nn { \l_test_seq } { 1 } with a which is obviously wrong.

\str_if_eq:VnTF expands the Value of the first argument, but the argument for V must be a single variable, and not arbitrary commands. For example, you could use \str_if_eq:VnTF \l_tmpa_str ..., but not \str_if_eq:VnTF { \str_use:N \l_tmpa_str } ....

What you want here is the full expansion of \seq_item:Nn, so you have to use the e variant: \str_if_eq:eeTF (e is an exhaustive expansion: it expands everything that can be expanded).

0

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.