While trying to answer another question on this site, I was experimenting with \peek_after:Nw
and \l_peek_token
.
I can set \l_peek_token
OK, but then I want to test if this token is one of several characters, rather than just one character. (Just one character is easy and I could use \peek_meaning:NTF
.)
I thought that I would be able to easily convert l_peek_token
to a string and then use \str_if_in:nnTF
for the test. But, I don't know how to do this.
I know I could use a bunch of nested \token_if_eq_meaning:NNTF
, but I find this syntax clumsy.
How can I do this?
MWE
\documentclass{article}
\usepackage{xparse}
\ExplSyntaxOn
\cs_new:Nn \__dcp_test_punct:
{
% What goes here to convert \l_peek_token to the right format?
\str_if_in:nnTF {.,} { \l_peek_token }
{ ~Punctuation~found:~ }
{ ~Punctuation~not~found~ }
---
% This works, but I find the syntax clumsy.
\token_if_eq_meaning:NNTF \l_peek_token .
{ ~Punctuation~found:~ }
{
\token_if_eq_meaning:NNTF \l_peek_token ,
{ ~Punctuation~found:~ }
{ ~Punctuation~not~found~ }
}
}
\cs_new:Nn \__dcp_test_punct:n
{
\peek_after:Nw \__dcp_test_punct:
}
\DeclareDocumentCommand {\testpunct} { m }
{
\__dcp_test_punct:n {#1}
}
\ExplSyntaxOff
\begin{document}
\testpunct{A}.
\testpunct{A},
\testpunct{A}
\end{document}
\l_peek_token
is defined with\futurelet
, so in case the next token is a character\l_peek_token
is an “implicit character”, which is not the same as a character; in particular, it is not expandable.\__dcp_test_punct:
? (I have now come up with a slightly different way of doing it, that I'm just as happy with.)\str_if_in:nnTF
nor\peek_after:Nw
are expandable, so\cs_new_protected:Nn
should be used.\cs_new_protected:Nn \__realscripts_footnote_with_punct:
and\cs_new_protected:Nn \__realscripts_footnote_with_punct:n
?_protected