Next: , Previous: , Up: Input/output   [Contents][Index]


27.2 \read

Synopsis:

\readnumber tomacro

Make the command macro contain the next line of input from text stream number, as in \read5 to\data.

This opens the file email.tex for reading, puts the contents of the first line into the command \email, and then closes the file.

\newread\recipientfile
\openin\recipientfile=email
\read\file to\email
\typeout{Email address: \email}
\closein\recipientfile

If number is outside the range from 0 to 15 or if no file of that number is open, or if the file has ended, then \read will take input from the terminal. Note, though, that the natural way in LaTeX to take input from the terminal is \typein (see \typein).

To read in an entire file at once use \input (see \input) or \include (see \include & \includeonly).

A common reason to want to read from a data file is to do mail merge. CTAN has a number of packages for that; one is datatool.


Unofficial LaTeX2e reference manual