The code below illustrates the trouble I’m having. It seems I cannot directly use a token-list variable where a token list is called for, but why, and how can I get the result I want?
\documentclass{article}
\usepackage{xparse}
\ExplSyntaxOn
\bool_new:N \found_bool
\cs_new_protected:Npn \find_token_in_tl:Nn #1#2
{
\bool_set_false:N \found_bool
\tl_map_inline:nn { #2 }
{
\token_if_eq_charcode:NNT ##1 #1
{
\bool_set_true:N \found_bool
\tl_map_break:
}
}
}
\NewDocumentCommand { \FindTokInList } { m m }
{
\find_token_in_tl:Nn #1 {#2}
\bool_if:NTF \found_bool { ! } { ? }
}
\tl_const:Nn \punct_tl {,.;:}
\NewDocumentCommand { \FindTokInPunctList } { m }
{
\find_token_in_tl:Nn #1 \punct_tl
\bool_if:NTF \found_bool { ! } { ? }
}
\ExplSyntaxOff
\begin{document}
dot: \FindTokInList{.}{,.;:} % finds token & prints “!”
x: \FindTokInList{x}{,.;:} % doesn’t find token & prints “?”
dot: \FindTokInPunctList{.} % doesn’t find token & prints “?”, but why?
x: \FindTokInPunctList{x} % doesn’t find token & prints “?”
\end{document}
\cs_generate_variant:Nn \find_token_in_tl:Nn {NV}
and using that in\FindTokInPunctList
fixes the problem but I'm not completely sure why.\tl_if_in:NnTF
to begin with?\tl_if_in:NnTF
. For instance, one wants to put a given space both before an active:
or an other:
.