5

I was following page 216 of Knuth, but cannot get the following code to run. The error message is:

! Emergency stop.
<read 1> 

l.12 \read\fid to\temp

*** (cannot \read from terminal in nonstop modes)

I might mention that I cannot find \openin in the log file at all.

\begin{filecontents}{address.txt}
test
\end{filecontents}
%
\documentclass{article}
\tracingmacros=1
\newread\fid
\begin{document}
\the\fid

\openin\fid={address.txt}
\read\fid to\temp
\closein\fid
\temp
\end{document}
7
  • I'm confused: you say you're following The TeXbook, but show a LaTeX document… For all I know, LaTeX might have redefined some plain TeX macros, or even primitives. Is this reproducible with a plain TeX file? Jul 4, 2017 at 17:37
  • @ShreevatsaR - most TeX macros still work. Whether LaTeX disables \openin is sort of what I am trying to find out, I also tried using the plain package. Jul 4, 2017 at 17:40
  • 1
    For contrast, can you give a plain TeX version that works, and a LaTeX version that doesn't? It would make it easier to understand the question (at least for me). (Because even when I try to turn your example into a plain equivalent, it tries to read from the terminal, and whatever I type in the terminal ends up in the final output dvi file.) Jul 4, 2017 at 17:44
  • You've got the syntax of \openin wrong: \openin\fid=address.txt % with no braces. I also agree that this is quite confusing as-written (plain-tex is for things that only apply to plain: perhaps you mean tex-core?)
    – Joseph Wright
    Jul 4, 2017 at 17:47
  • Yes I figured out the same: \openin\fid=address.txt works if you have a file named address.txt. With the brace it tries to read from the terminal, which is rather confusing. Jul 4, 2017 at 17:49

1 Answer 1

10

The syntax with curly braces in

\openin\fid={address.txt}

is only supported by LuaTeX. The syntax for other TeX engines:

\openin\fid=address.txt

Where the file name can be ended by a space or \relax. Spaces in file names are supported in some cases with quotes:

\openin\fid="address.txt"

(But that means, that quotes in file names are not supported ...)

2
  • As Windows forbids " anyway, for safe cross-platform work it's ruled out anyway ... (this is the thinking in l3file, for example).
    – Joseph Wright
    Jul 4, 2017 at 17:53
  • Heiko is this still the case? Looks like pdflatex now also supports the braces. Oct 10, 2022 at 14:04

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .