Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

It seems to be impossible to combine \obeyspaces and \read in the following manner:

\newread\myread
\openin\myread=myfile.txt
  \obeyspaces  % Deleting this line removes the error
  \read\myread to \myinput
  \myinput
\closein\myread

The \tracingall doesn't really help me for understanding the problem.

share|improve this question
2  
Your example has no \obeyspaces: please edit your example so we can see what you are doing (probably including an example myfile.txt). –  Joseph Wright Jan 6 '13 at 10:03
add comment

1 Answer 1

up vote 6 down vote accepted

You just need to preserve normal spaces around the \read syntax:

\newread\myread
  \def\doread#1#2{\immediate\read#1 to #2}
\immediate\openin\myread=myfile.txt
  {\obeyspaces
   \doread\myread\myinput\immediate\write20{\myinput}%
   \doread\myread\myinput\immediate\write20{\myinput}%
   \doread\myread\myinput\immediate\write20{\myinput}%
   \doread\myread\myinput\immediate\write20{\myinput}%
}
\immediate\closein\myread

\bye

00
1 1
2  2
3   3

produces

This is TeX, Version 3.1415926 (TeX Live 2012)
(./rd55.tex
00 
1 1 
2  2 
3   3 
 )
No pages of output.
share|improve this answer
    
Thanks for your answer, which answers my question. How could I have found out that I need to preserve "normal" (what is the differences to the \obeyspaces?) spaces around the \read syntax to solve problems like this on my own in the future? –  Penguin Nurse Jan 6 '13 at 12:07
    
obeyspaces makes space into an active character with a definition similar to ~ so that it always typesets as a real space and is never dropped by the input scanner. spaces around tex primitives need to delimit the arguments but be dropped... not sure where best to learn these things other than asking here (after 25 years of using tex it's not always easy to remember how you pick these things up at the start:-) –  David Carlisle Jan 6 '13 at 12:20
    
from the TeXbook perhaps? ;-) –  jfbu Jan 6 '13 at 16:20
    
@jfbu not really. TeXBook, or actually more simply just looking at the plain or latex sources will tell you the definition of \obeyspaces, but it takes some experience to spot the implications of that definition on other macros. –  David Carlisle Jan 6 '13 at 16:29
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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