Consider this code:
\documentclass{article} \usepackage{filecontents} \begin{filecontents}{foo.txt} abc \end{filecontents} \begin{filecontents}{bar.txt} abc \end{filecontents} \begin{document} \makeatletter \def\einput#1{\@@input #1 \space} \newcommand{\showexpanded}[1]{% \everyeof{\noexpand}% \long\edef\@tempcontents{#1}% \show\@tempcontents } \makeatother \showexpanded{\einput{foo.txt}\einput{bar.txt}} . \end{document} It works approximately as expected, giving
$ pdflatex foo.tex This is pdfTeX, Version 3.14159265-2.6-1.40.16 (TeX Live 2015/Debian) (preloaded format=pdflatex) restricted \write18 enabled. entering extended mode (./foo.tex LaTeX2e <2016/02/01> Babel <3.9q> and hyphenation patterns for 7 language(s) loaded. (/usr/share/texlive/texmf-dist/tex/latex/base/article.cls Document Class: article 2014/09/29 v1.4h Standard LaTeX document class (/usr/share/texlive/texmf-dist/tex/latex/base/size10.clo)) (/usr/share/texlive/texmf-dist/tex/latex/filecontents/filecontents.sty) LaTeX Warning: Writing file `./foo.txt'. LaTeX Warning: Writing file `./bar.txt'. (./foo.aux) (./foo.txt) (./bar.txt) > \@tempcontents=\long macro: ->abc \space abc \space . \showexpanded ...ontents {#1}\show \@tempcontents l.18 ...expanded{\einput{foo.txt}\einput{bar.txt}} ? However, if I change \noexpand to or \relax, then I get ! File ended while scanning definition of \@tempcontents. Why is this? Is there any way to eat the EOF without causing the subsequent \space to be left over? (I got the use of \noexpand by cargo-culting http://ctan.mirrors.hoobly.com/macros/latex/contrib/oberdiek/catchfile.pdf)
\everyeofprovides a way of hacking round that.\noexpandapplying to the EOF? (But it seems to be applying to the\space, so it probably isn't that.) I have found that\stringalso works (but leaves undesireable strings in the output), but\showdoes not. What is the category of things that work here, and what is the property they share that makes them work? It sounds like you're implying that some operations treat EOF as whitespace, but most error?\scantokens.