I'd like to get the name of a control sequence token as sequence of character tokens.
With \relax I'd like to get relax.
The preceeding escape character is to be removed from the result of \string\relax.
One can probably do
\def\gobble#1{}%
\expandafter\gobble\string\relax
But do I understand correctly?:
Actually behavior of \string depends on the value of the integer parameter \escapechar.
If \escapechar < 0 or \escapechar > 255/1114111 no escape character is prepended by \string.
If value of \escapechar is 32, then space token (charcode 32, catcode 10) is prepended by \string.
Space token cannot be handled as undelimited argument. So we have a case that needs special handling.
In all other cases character token is prepended with character code=value of \escapechar and category code=12/other.
So if you cannot rely on \escapechar=92 you need to do like this:
\lowercase{\def\spacetokengobble} {}%
\def\gobble#1{}
\def\empty{}
\csname\ifnum\escapechar<0 empty\else
\ifnum\escapechar=32 spacetokengobble\else
\ifnum\expandafter\ifx\csname XeTeXrevision\endcsname\relax
\expandafter\ifx\csname directlua\endcsname\relax
255\else 1114111\fi\else 1114111\fi<\escapechar
empty\else gobble\fi
\fi
\fi
\expandafter
\endcsname\string\relax
Question:
With the value of \escapechar, besides the value 32, are there more special values where removing cannot be done by \gobble?
\stringmakes space characters have catcode 10, which is ignored by TeX when grabbing arguments. I suggest you take a look atexpl3's\cs_to_str:N: it does precisely what you want – Phelype Oleinik Feb 22 '21 at 13:53\stringthen there is no need to gobble anything, as you say,or do you really need an expandable construct here? – David Carlisle Feb 22 '21 at 13:54\csname..\endcsnameto extend a macro name by a prefix before defining the macro. So I think an expandable solution is needed. – JamieLittleJoeHossAdamBen Feb 22 '21 at 14:11\stringalso depends on the age of the LuaTeX-engine in use. E.g., with LuaTeX older than luatex 1.10.0 in texlive 2019 the behavior of\stringis not well defined for values of\escapecharexceeding 1114111. – Ulrich Diez Feb 22 '21 at 14:32expl3implementation,_and:removed for your convenience, is\chardef\czeroint=0 \def\cstostr{\romannumeral\if\string\ \cstostrw\fi\expandafter\cstostrN\string} \def\cstostrN#1{\czeroint} \def\cstostrw#1\cstostrN{-\number\fi\expandafter\czeroint}. Use as\cstostr\macro. – Phelype Oleinik Feb 22 '21 at 15:00\csname?? look how latex2e defines\newcomandand friends, before processing the argument it does\begingroup \escapechar\m@ne...so\stringacts in a known way. – David Carlisle Feb 22 '21 at 17:36\csstringprimitive which does the same as\stringbut without any escapechar. The\escapecharwith\stringis bad concept which brings only problems for macro programmers. If you are using modern TeX engine LuaTeX then you can throw these problems behind your hand and focus to real problems you are solving. The\csstringprimitive is menitoned in tex-nuthsell.pdf and in LuaTeX manual, for example. – wipet Feb 24 '21 at 20:00