In Knuthian-TeX I'd like to have a macro which switches to verbatim-category-code-régime and then calls another macro which processes characters from the current input-file one by one until reaching the end of the current input-file.

Something like:

    \catcode`\\=12 \catcode`\{=12 \catcode`\}=12 \catcode`\$=12 %
    \catcode`\&=12 \catcode`\#=12 \catcode`\^=12 \catcode`\^^M=12 %
    \catcode`\^^I=12 \catcode`\_=12 \catcode`\^^A=12 \catcode`\%=12 %
    \catcode`\~=12 \catcode`\ =12 \processloop
\def\processloop #1%
    There is the character ``\string#1.''
    \if⟨end of current input-file is not reached⟩%


Is it possible in Knuthian-TeX to implement a test \if⟨end of current input-file is not reached⟩..\else..\fi?

I think in eTeX I could use \everyeof for this, but I am explicitly asking for Knuthian-TeX.

I don't want to use \read because \read successively reads brace-balanced sets of lines with as few lines as possible and whenever such a set is read a macro is defined which I don't really need and therefore see as waste of memory.

  • but with verbatim catcodes there are no balanced braces so read will read a line at a time Jan 20 at 16:57
  • @DavidCarlisle I suppose Jim Beam has large input-files with many lines and doesn't want so many macro-assignments... Jan 20 at 17:04
  • 2
    @UlrichDiez I used to worry about that sort of thing but then I ran a beamer document with \tracingall and gave up worrying. Jan 20 at 17:05
  • @JimBeam Is the question "academical"? In use-cases nowadays -i'd stick to TeX-engines with eTeX-extensions and do s.th. with \everyeof. Jan 20 at 17:05
  • @DavidCarlisle :-))))) Jan 20 at 17:05

2 Answers 2


As the end of file is \outer (grrr) you can't get past it with a macro argument but you can consume it with \let so, with some undocumented restrictions you could report the file



the letter a
the letter b
the letter c
the character ^^M
the character 1
the character 2
the character 3
the character ^^M
the character \
the letter h
the letter b
the letter o
the letter x
the character {
the character 1
the character 2
the character 3
the character }
the character ^^M


\def\zz{\afterassignment\zzz\let\tmp= }

\catcode`\^^M=12 %
\catcode`\\=12 %
\catcode`\{=12 %
\catcode`\}=12 %
\catcode`\ =12 %
\catcode`\%=12 %
\expandafter\zz\input #1 %


  • You may need to make more characters catcode 12, depending.. Jan 20 at 17:21

You wish a macro to detect the end of an \input-file?

TeXbook, Chapter 20: Definitions (also called Macros), says:

[...] When a macro definition is preceded by \outer, the corresponding control sequence will not be allowed to appear in any place where tokens are being absorbed at high speed. An \outer macro cannot appear in an argument [...], nor can it appear in the parameter text or the replacement text of a definition, nor in the preamble to an alignment, nor in conditional text that is being skipped over.
If an \outer macro does show up in such places, TeX stops what it is doing and reports either a "runaway" situation or an "incomplete" conditional. The end of an input file or alignment template is also considered to be \outer in this sense; [...]

I doubt detecting the end of an input-file only by means of purely expandable routines (e.g., fully expandable macros or \if..-conditionals) is possible in Knuthian-TeX.

I suggest using an engine where you can take avantage of ε-TeX-extensions and where \everyeof can be used to drop in tokens which definitely are not verbatim-régime and therefore can be cranked out.

I think processing large input-files character-wise might take time.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.