I have the following code in which I try to check whether a letter exists in a string:
\documentclass{article}
\ExplSyntaxOn
\begin{document}
\str_gset:Nn \ABCstring {ABC} % Setting the test string to 'ABC'
\tl_gset:Nn \my_tl {C} % Setting the token list to the single letter 'C'
C\ in\ ABC:~
\str_if_in:NnTF \ABCstring {C}{yes!}{no!}\\ % just the letter 'C'
\textbackslash my_tl(\my_tl)\ in\ ABC:~
\str_if_in:NnTF \ABCstring {\my_tl}{yes!}{no!}\\ % the letter 'C' from the tl
\end{document}
\ExplSyntaxOff
It generates this output:
C in ABC: yes!
\my_tl(C) in ABC: no!
When I put just a C
into the second argument of \str_if_in:NnTF
, the code works as expected (yielding yes!
), while the same character in a token list does not work.
The LaTeX3 documentation gives the following signature:
\str_if_in:NnTF ⟨str var⟩ {⟨token list⟩} {⟨true code⟩} {⟨false code⟩}
accompanied with the following description:
Converts the ⟨token list⟩ to a ⟨string⟩ and tests if that ⟨string⟩ is found in the content of the ⟨str var⟩.
From my understanding of the doc, both ifs above should yield yes!
What is the problem?
I figured out that it works with
\cs_generate_variant:Nn \str_if_in:NnTF {NVTF}
but why is that necessary?
\my_tl
is converted into the string\ m y _ t l