I have a question concerning the decomposition of macro definitions:
In chapter XV, section 7 in the interface3 manual is a list of possible decompositions:
For example, there is a command \token_get_prefix_spec:N
listed in the interface3 manual. As described, it leaves the prefixes in the input-stream.
A token defined by \cs_new_protected:Nn \someToken:n { do~something }
would thereby leave "\protected".
The other two, \token_get_arg_spec:N
and \token_get_replacement_spec:N
, leave the raw arguments or the replacement. All three of them work well with a \l_peek_token
as "input".
But is there a method to leave the token name? The \token_to_str:N
macro is not an option, as i want to know the (once expanded) name of a \l_peek_token
: \token_to_str:N \l_peek_token
just returns "\l_peek_token" and not "\someToken:n" (if the peeked at token is "\someToken:n").
Here is a small example showing what I want (compile with XeTeX):
\documentclass[varwidth,border=10pt]{standalone}
\usepackage{expl3}
\usepackage{newunicodechar}
\ExplSyntaxOn
\cs_new_protected:Nn \someToken:n {
\peek_catcode:NF ## {
char: #1\\
-~Meaning~of~next~token:~\token_to_meaning:N \l_peek_token\\
-~Prefix~of~next~token:~\token_get_prefix_spec:N \l_peek_token\\
-~Name~of~next~token:~\token_to_str:N \l_peek_token\\ % this is not working as wanted, I want \someToken:n !
}
}
\newunicodechar{➀}{\someToken:n{a}}
\newunicodechar{➁}{\someToken:n{b}}
\ExplSyntaxOff
\begin{document}
➁➀
…
\end{document}
(This question came up while I was searching for solutions for my other questions Compare macro names instead of meaning and Peek ahead and process characters.)
\l_peek_token
is just\let
to the next token, i.e. it is assigned the same\meaning
but the original “name” is lost.\token_to_meaning:N \l_peek_token
return the meaning (which includes the macro name: "\protected macro:->\someToken:n {a}") if it's lost? Could I somehow parse the meaning in such a way, that everything between ">" and "{" is "returned"?\let\peektoken➀
; the info that's inside ➀ is what you now have, and inside it you have\sometoken:n {a}
. It's not clear to me what you want to do with that?\someToken:n
. The use case is mentioned in the link below the source code: unicode replacement of composite-emoji (like flags or skin color variations). Other methods (also mentioned in my other questions/link below) don't work in some cases.