The main issue might be that | within the replacement text of the definition of \subsumed is not active. You can do \scantokens{|}.
\documentclass{minimal} \def\transfigured#1{\catcode`|=\active% allows | as command \begingroup\endlinechar-1\relax \everyeof{{#1}\endgroup}\scantokens{\gdef|}}% % This entire definition is tokenized while | is _not_ active: \def\subsumed#1{\begingroup \transfigured{#1}% \scantokens{|}% \endgroup}% should simply do the same \begin{document} \begingroup \transfigured{test}% gets desired output |% \endgroup \subsumed{test}% \end{document} By the way: Using the fact that in LaTeX ~ usually is active you can get active | also via \lccode and \lowercase:
\documentclass{minimal} \def\transfigured{% \begingroup \lccode`\~=`\|\relax \lowercase{\endgroup\def~}% }% \def\subsumed#1{% \transfigured{#1}% \begingroup \lccode`\~=`\|\relax \lowercase{\endgroup~}% }% \begin{document} \transfigured{test}% \begingroup\lccode`\~=`\|\relax\lowercase{\endgroup~}% \subsumed{test}% \end{document} Academic info:
You can (ab)use \futurelet for getting rid of end-of-file-markers that come into being due to \scantokens or the \input-primitive— in LaTeX \input is redefined and the \input-primitive is renamed to \@@input:
\documentclass{minimal} \begingroup\catcode`\%=12\relax \def\percentchar{\endgroup\def\percentchar{%}}\percentchar \def\neutralizeoutertoken{% \expandafter\transfiguredRemoveEOFMarkerwithArgAsRelax\noexpand }% \def\transfiguredRemoveEOFMarkerwithArgAsRelax#1{\let#1=\relax\transfiguredRemoveEOFMarker{#1}}% \def\transfiguredRemoveEOFMarker#1{% \endgroup % <- undo \transfigured's catcode-change before \futurelet % "looks ahead" and probably triggers tokenization \begingroup \let#1=\relax \def\transfiguredRemoveEOFMarker{\endgroup\def#1}% \futurelet\scratchy\transfiguredRemoveEOFMarker }% \def\transfigured{% \begingroup \catcode`|=\active % allows | as command \expandafter\transfiguredRemoveEOFMarker\scantokens\expandafter\catcode`\%=14 % allows % as comment % active | might be defined \outer ... \expandafter\neutralizeoutertoken\scantokens\expandafter{\expandafter|\percentchar}% }% \begingroup \catcode`|=\active \csname @firstofone\endcsname{% \endgroup \def\subsumed#1{\transfigured{#1}|}% }% \begin{document} {\catcode`|=\active \outer\gdef|{Huh?}} \transfigured{test}% define active | with <replacement text> "test" \begingroup\catcode`|=\active\csname @firstofone\endcsname{\endgroup|}% \subsumed{test}% \end{document}