I am trying to work with \scantokens, but apparently, I don't really understand it. I want to detokenize some sequence into a register \S:
\let\ea\expandafter
\newtoks\S
\ea\S\ea{\detokenize{\textbf{f}}}
manipulate it (omitted), and retokenize. My first attempt
\ea\def\ea\T\ea{\ea\scantokens\ea{\the\S}}
yields \T=macro: \scantokens {\textbf {f}}.. That's not wrong, but probably we can get the \scantokens out of \T. I thought, expanding once more should do it, but apparently not. So far, also what's written here about \everyeof{\noexpand} does not help me:
\documentclass{article}
\let\ea\expandafter
\newtoks\S
\ea\S\ea{\detokenize{\textbf{f}}}
\ea\def\ea\T\ea{\ea\scantokens\ea{\the\S}}%
\show\T %\T=macro: \scantokens {\textbf {f}}.
%Runaway definition?
%->\textbf {f}
% ! File ended while scanning definition of \R.
\ea\ea\ea\def\ea\ea\ea\R\ea\ea\ea{\T}
%Runaway definition?
%->\textbf {f} \noexpand
%! File ended while scanning definition of \R.
\everyeof{\noexpand}%
\ea\ea\ea\def\ea\ea\ea\R\ea\ea\ea{\T}
\show\R
\everyeof{}
\begin{document}
\R
\end{document}
