I encountered a strange behaviour I can’t explain. In my code for a highlighting macro I tried to use \tl_if_in
to do a basic math class test. But when \mathrm
is part of the tokens to be tested some extra tokes (i.e. what follows \mathrm{…}
) are inserted.
\documentclass{article}
\usepackage{xparse}
\ExplSyntaxOn
\tl_const:Nn \c_pirkl_math_rel_symbols_tl { +-=/ }
\NewDocumentCommand{ \highlight }{ m }{
\tl_if_in:NnT \c_pirkl_math_rel_symbols_tl { #1 } {
% ...
}
#1
}
\ExplSyntaxOff
\begin{document}
Inserts what comes after \verb|\mathrm{...}|
\[ \highlight{x} + \highlight{\mathrm{d}x} \]
works with additional group
\[ \highlight{x} + \highlight{{\mathrm{d}x}} \]
\end{document}
It is the same with \clist_is_in
, except that there is also an additional comma in the output.
note: Actually my question is kind of xy problem, I came to this while working on a solution for capturing the math class: http://tex.stackexchange.com/q/369903/4918.
update: with \tl_to_string
added the test is allay true …
\NewDocumentCommand{ \highlight }{ m }{
\tl_if_in:NnT \c_pirkl_math_rel_symbols_tl { \tl_to_string:n { #1 } } {
T
}
#1
}
update 2: with most TL stringified I can’t make it work either …
\tl_const:Nn \c_pirkl_math_rel_symbols_tl { \tl_to_string:n { +-=/ } }
\cs_generate_variant:Nn \tl_if_in:NnT { NfT }
\NewDocumentCommand{ \highlight }{ m }{
\tl_if_in:NfT \c_pirkl_math_rel_symbols_tl { \tl_to_string:n { #1 } } {
T
}
#1
}