I am given a token list (parameter-less macro) \myTokenList, defined, e.g. by
\def\myTokenList{$(x + y)^2$, \ie, \(x^2+y^2+2xy\)}
and I want to split it as the first token, and the rest, obtaining the same result as
\def\head{$}
\def\tail{(x + y)^2$, \ie, \(x^2+y^2+2xy\)}
In most cases, this is easy using the \split macro below:
\def\split#1#2\EndMark{\def\head{#1}\def\tail{#2}}
\expandafter\split\myTokenList\EndMark
But this fails when the first token is a space. In fact, it even gobbles an arbitrary number of spaces.
Using \futurelet seems to help, but
I would much prefer
\headto be a macro which expands to exactly the token (not something let to it)I don't know how to just remove the first token, even after
\futurelet-ting
Note that I have no control on the token list that I am given (braces will be treated differently): this is in the context of a generic debugging package for TeX's stomach.

\futurelet\next, check the category code using\ifcat\next\bgroup,\ifcat\next\egroupetc., grab the last character of\meaning\next(this has the right character code), and build the right explicit character <token> (character code and catcode) using a\lowercasetrick. – Bruno Le Floch Feb 4 '11 at 7:09\mytest#1<token>{...}where...tests whether#1is empty or not. Then\mytest\tokenList<token>with the right amount of expansion will tell me whether the first occurence of <token> was at the start of \tokenList or not (<token> at the end just prevents runaway arguments). Does it seem realistic? – Bruno Le Floch Feb 4 '11 at 7:11