Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!wuarchive!zaphod.mps.ohio-state.edu!think.com!mintaka!daemon From: dmjones@theory.lcs.mit.edu (David M. Jones) Newsgroups: comp.text.tex Subject: Question about \endlinechar Message-ID: <1991Feb25.175423.18161@mintaka.lcs.mit.edu> Date: 25 Feb 91 17:54:23 GMT Sender: daemon@mintaka.lcs.mit.edu (Lucifer Maleficius) Reply-To: dmjones@theory.lcs.mit.edu (David M. Jones) Organization: Laboratory for Computer Science, MIT Lines: 63 I have a question about the behaviour of \endlinechar that has come up while I was designing some macros to help run a refereed journal. The basic problem is this: I have a number of files containing a single line, the formal salutation of one of the editors of the journal. For example, I have file Meyer.tex containing the line "Professor Meyer". At an appropriate time, I wish to open Meyer.tex for reading and store its first line in the control sequence \EditorSalutation. If the file is unreadable or nonexistient, I want \EditorSalutation defined to be a no-op. \EditorSalutation will then be used in contexts such as Dear \EditorSalutation, Normally, the end of line character at the end of the file Meyer.tex would get translated into an unwanted space, and the line above would expand to Dear Professor Meyer , The simplest solution seems to be to set \endlinechar to -1 when reading Meyer.tex, so that new line characters get thrown away. So, I wrote the following code: {\endlinechar=-1 \openin0=Meyer.tex \ifeof0 \global\let\EditorSalutation\relax \else \global\read0 to\EditorSalutation \fi \closein0} The problem is that \ifeof0 always tests true now, so \EditorSalutation is always set to \relax. Note that removing the conditional gives the correct behavior when the file exists and is not empty: {\endlinechar=-1 \openin0=Meyer.tex \global\read0 to\EditorSalutation \closein0} The workaround is to move the \endlinechar inside the conditional, like so: {\openin0=Meyer.tex \ifeof0 \global\let\EditorSalutation\relax \else {\endlinechar=-1 \global\read0 to\EditorSalutation} \fi \closein0} This works, but it puzzles me. Why should the value of \endlinechar affect TeX's judgement of whether the file is empty or not? Can anyone explain this? I hesitate to mention the word "bug", but this is certainly non-intuitive behaviour. ------------------------------------------------------------------------------ David M. Jones |"The earth's a prison -- one can't 17 Simpson Ave #1; Somerville, MA 02144 | get away from it.... I'm still ARPANET: dmjones@theory.lcs.mit.edu | too young to lack desires, Not UUCP: ...!mit-eddie!mit-athena!dmjones | young enough now for mere play." ------------------------------------------------------------------------------