-
Notifications
You must be signed in to change notification settings - Fork 18
/
chapter30.tex
734 lines (660 loc) · 26.1 KB
/
chapter30.tex
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
% -*- coding: utf-8 -*-
\documentclass{book}
\input{preamble}
\setcounter{chapter}{29}
\begin{document}
%\chapter{File Input and Output}\label{io}
%\index{I/O!file|(}
\chapter{File Input and Output}\label{io}
\index{I/O!file|(}
%This chapter discusses the various ways in which \TeX\ can read from
%and write to external \indexterm{files}.
This chapter discusses the various ways in which \TeX\ can read from
and write to external \indexterm{files}.
%\label{cschap:input}\label{cschap:endinput}\label{cschap:inputlineno}\label{cschap:message}\label{cschap:write}\label{cschap:read}\label{cschap:newread}\label{cschap:newwrite}\label{cschap:openin}\label{cschap:closein}\label{cschap:openout}\label{cschap:closeout}\label{cschap:ifeof}\label{cschap:immediate}\label{cschap:newlinechar}
%\begin{inventory}
%\item [\cs{input}]
% Read a specified file as \TeX\ input.
\label{cschap:input}\label{cschap:endinput}\label{cschap:inputlineno}\label{cschap:message}\label{cschap:write}\label{cschap:read}\label{cschap:newread}\label{cschap:newwrite}\label{cschap:openin}\label{cschap:closein}\label{cschap:openout}\label{cschap:closeout}\label{cschap:ifeof}\label{cschap:immediate}\label{cschap:newlinechar}
\begin{inventory}
\item [\cs{input}]
Read a specified file as \TeX\ input.
%\item [\cs{endinput}]
% Terminate inputting the current file after the current line.
\item [\cs{endinput}]
Terminate inputting the current file after the current line.
%\item [\cs{pausing}]
% Specify that \TeX\ should pause after each line that is
% read from a file.
\item [\cs{pausing}]
Specify that \TeX\ should pause after each line that is
read from a file.
%\item [\cs{inputlineno}]
% Number of the current input line.
\item [\cs{inputlineno}]
Number of the current input line.
%\item [\cs{message}]
% Write a message to the terminal.
\item [\cs{message}]
Write a message to the terminal.
%\item [\cs{write}]
% Write a \gr{general text} to the terminal or to a file.
\item [\cs{write}]
Write a \gr{general text} to the terminal or to a file.
%\item [\cs{read}]
% Read a line from a stream into a control sequence.
\item [\cs{read}]
Read a line from a stream into a control sequence.
%\item [\cs{newread \cs{newwrite}}]
%\mdqon
% Macro for allocating a new input/""output stream.
%\mdqoff
\item [\cs{newread \cs{newwrite}}]
\mdqon
Macro for allocating a new input/""output stream.
\mdqoff
%\item [\cs{openin \cs{closein}}]
% Open/close an input stream.
\item [\cs{openin \cs{closein}}]
Open/close an input stream.
%\item [\cs{openout \cs{closeout}}]
% Open/close an output stream.
\item [\cs{openout \cs{closeout}}]
Open/close an output stream.
%\item [\cs{ifeof}]
% Test whether a file has been fully read, or does not exist.
\item [\cs{ifeof}]
Test whether a file has been fully read, or does not exist.
%\item [\cs{immediate}]
% Prefix to have output operations executed right away.
\item [\cs{immediate}]
Prefix to have output operations executed right away.
%\item [\cs{escapechar}]
% Number of the character that is used
% when control sequences are being converted
% into character tokens.
% \IniTeX\ default:~92.
\item [\cs{escapechar}]
Number of the character that is used
when control sequences are being converted
into character tokens.
\IniTeX\ default:~92.
%\item [\cs{newlinechar}]
% Number of the character that triggers a new line in
% \cs{write} and \cs{message} statements.
\item [\cs{newlinechar}]
Number of the character that triggers a new line in
\cs{write} and \cs{message} statements.
%\end{inventory}
\end{inventory}
%%\point Including files: \cs{input} and \cs{endinput}
%\section{Including files: \protect\cs{input} and \protect\cs{endinput}}
%\point Including files: \cs{input} and \cs{endinput}
\section{Including files: \protect\cs{input} and \protect\cs{endinput}}
%Large documents can be segmented in \TeX\ by putting
%\cstoidx input\par
%parts in separate \indexterm{input files}, and loading these with \cs{input}
%into the master file. The exact syntax for
%file names is implementation dependent; most of the
%time a \n{.tex} file extension is assumed if no explicit
%extension is given.
%File names can be delimited with a space or with \cs{relax}.
%The \cs{input} command is expandable.
Large documents can be segmented in \TeX\ by putting
\cstoidx input\par
parts in separate \indexterm{input files}, and loading these with \cs{input}
into the master file. The exact syntax for
file names is implementation dependent; most of the
time a \n{.tex} file extension is assumed if no explicit
extension is given.
File names can be delimited with a space or with \cs{relax}.
The \cs{input} command is expandable.
%If \TeX\ encounters in an input file the
%\csidx{endinput} statement, it acts as if the file
%ends after the line on which the statement occurs.
%Any statements on the same line as \cs{endinput} are
%still executed.
%The \cs{endinput} statement is expandable.
If \TeX\ encounters in an input file the
\csidx{endinput} statement, it acts as if the file
ends after the line on which the statement occurs.
Any statements on the same line as \cs{endinput} are
still executed.
The \cs{endinput} statement is expandable.
%%\point File I{/}O
%\section{File I{/}O}
%\point File I{/}O
\section{File I{/}O}
%\TeX\ supports input and output streams for reading and writing
%\altt
%files one line at a time.
\TeX\ supports input and output streams for reading and writing
\altt
files one line at a time.
%%\spoint Opening and closing streams
%\subsection{Opening and closing streams}
%\spoint Opening and closing streams
\subsection{Opening and closing streams}
%\TeX\ supports up to 16 simultaneous input and 16 output
%\indexterm{streams}.
%The plain \TeX\ macros
%\csidx{newread} and \csidx{newwrite} give the number of an unused
%stream. This number is assigned by a \cs{chardef} command.
%Input streams are completely independent of output
%streams.
\TeX\ supports up to 16 simultaneous input and 16 output
\indexterm{streams}.
The plain \TeX\ macros
\csidx{newread} and \csidx{newwrite} give the number of an unused
stream. This number is assigned by a \cs{chardef} command.
Input streams are completely independent of output
streams.
%Input streams are opened by
%\cstoidx openin\par
%\begin{disp}\cs{openin}\gr{4-bit number}\gr{equals}\gr{filename}\end{disp}
%and closed by
%\cstoidx closein\par
%\begin{disp}\cs{closein}\gr{4-bit number}\end{disp}
Input streams are opened by
\cstoidx openin\par
\begin{disp}\cs{openin}\gr{4-bit number}\gr{equals}\gr{filename}\end{disp}
and closed by
\cstoidx closein\par
\begin{disp}\cs{closein}\gr{4-bit number}\end{disp}
%Output streams are opened by
%\cstoidx openout\par
%\begin{disp}\cs{openout}\gr{4-bit number}\gr{equals}\gr{filename}\end{disp}
%and closed by
%\cstoidx closeout\par
%\begin{disp}\cs{closeout}\gr{4-bit number}\end{disp}
Output streams are opened by
\cstoidx openout\par
\begin{disp}\cs{openout}\gr{4-bit number}\gr{equals}\gr{filename}\end{disp}
and closed by
\cstoidx closeout\par
\begin{disp}\cs{closeout}\gr{4-bit number}\end{disp}
%If an output file does not yet exist, it is created
%by \cs{openout}; if it did exist, an \cs{openout} will
%cause it to be overwritten.
If an output file does not yet exist, it is created
by \cs{openout}; if it did exist, an \cs{openout} will
cause it to be overwritten.
%The output operations \cs{openout}, \cs{closeout},
%and \cs{write} can all three be prefixed by \cs{immediate};
%see below.
The output operations \cs{openout}, \cs{closeout},
and \cs{write} can all three be prefixed by \cs{immediate};
see below.
%%\spoint Input with \cs{read}
%\subsection{Input with \cs{read}}
%\spoint Input with \cs{read}
\subsection{Input with \cs{read}}
%In addition to the \cs{input} command, which reads a whole
%file, \TeX\ has the \csidx{read} operation, which
%reads one line from a file (or from the user terminal).
%The syntax of the read command is
%
%\begin{disp}\cs{read}\gr{number}\n{to}\gr{control sequence}\end{disp}
%The effect of this statement is that one input line
%is read from the designated stream, and the control
%sequence is defined as a macro without parameters, having
%that line as replacement text.
In addition to the \cs{input} command, which reads a whole
file, \TeX\ has the \csidx{read} operation, which
reads one line from a file (or from the user terminal).
The syntax of the read command is
\begin{disp}\cs{read}\gr{number}\n{to}\gr{control sequence}\end{disp}
The effect of this statement is that one input line
is read from the designated stream, and the control
sequence is defined as a macro without parameters, having
that line as replacement text.
%If the input line is not balanced with respect to braces,
%\TeX\ will read more than one line, continuing for as long
%as is necessary to get a balanced token list.
%\TeX\ implicitly appends an empty line to each input stream,
%\alt
%so the last \cs{read} operation on a stream will always
%yield a single \cs{par} token.
If the input line is not balanced with respect to braces,
\TeX\ will read more than one line, continuing for as long
as is necessary to get a balanced token list.
\TeX\ implicitly appends an empty line to each input stream,
\alt
so the last \cs{read} operation on a stream will always
yield a single \cs{par} token.
%Read operations from any stream outside the range 0--15 \ldash or
%streams not associated with an open file, or on which the file
%end has been reached \rdash
%read from the terminal. If the stream number is positive
%the user is prompted with the name of the control sequence
%being defined by the \cs{read} statement.
Read operations from any stream outside the range 0--15 \ldash or
streams not associated with an open file, or on which the file
end has been reached \rdash
read from the terminal. If the stream number is positive
the user is prompted with the name of the control sequence
being defined by the \cs{read} statement.
%\begin{example}
%\begin{verbatim}
%\read16 to \data
%\end{verbatim}
%displays a prompt
%\begin{verbatim}
%\data=
%\end{verbatim}
%and typing `my name'
%in response makes the read statement equivalent
%to
%\begin{verbatim}
%\def\data{my name }
%\end{verbatim}
%The space at the end of the input derives from the line end;
%to prevent this one could write
%\begin{verbatim}
%{\endlinechar=-1 \global\read16 to \data}
%\end{verbatim}
%\end{example}
\begin{example}
\begin{verbatim}
\read16 to \data
\end{verbatim}
displays a prompt
\begin{verbatim}
\data=
\end{verbatim}
and typing `my name'
in response makes the read statement equivalent
to
\begin{verbatim}
\def\data{my name }
\end{verbatim}
The space at the end of the input derives from the line end;
to prevent this one could write
\begin{verbatim}
{\endlinechar=-1 \global\read16 to \data}
\end{verbatim}
\end{example}
%%\spoint Output with \cs{write}
%\subsection{Output with \cs{write}}
%\spoint Output with \cs{write}
\subsection{Output with \cs{write}}
%\TeX's \csidx{write} command
%
%\begin{disp}\cs{write}\gr{number}\gr{general text}\end{disp}
%writes a balanced token list to a file which has been opened
%by \cs{openout}, to the log file, or to the terminal.
\TeX's \csidx{write} command
\begin{disp}\cs{write}\gr{number}\gr{general text}\end{disp}
writes a balanced token list to a file which has been opened
by \cs{openout}, to the log file, or to the terminal.
%Write operations to a stream outside 0--15 \ldash or to a
%stream that is not associated with an open file \rdash go to the log file;
%if the stream number is positive they
%go to the terminal as well as to the log file.
Write operations to a stream outside 0--15 \ldash or to a
stream that is not associated with an open file \rdash go to the log file;
if the stream number is positive they
go to the terminal as well as to the log file.
%The token list argument of \cs{write}, defined as
%
%\begin{disp}\gr{general text} $\longrightarrow$ \gr{filler}%
% \lb\gr{balanced text}\gr{right brace}\end{disp}
%can have an implicit opening brace.
%This argument is expanded as if it were the replacement
%text of an \cs{edef}, so, for instance,
%any macros and conditionals appearing are expanded.
%No commands are executed, however.
%This expansion occurs
%at the time of shipping out; see below.
%Until that time the argument token list is stored
%in a whatsit item on the current list.
%See further Chapter~\ref{expand} for
%a discussion of expansion during writing.
The token list argument of \cs{write}, defined as
\begin{disp}\gr{general text} $\longrightarrow$ \gr{filler}%
\lb\gr{balanced text}\gr{right brace}\end{disp}
can have an implicit opening brace.
This argument is expanded as if it were the replacement
text of an \cs{edef}, so, for instance,
any macros and conditionals appearing are expanded.
No commands are executed, however.
This expansion occurs
at the time of shipping out; see below.
Until that time the argument token list is stored
in a whatsit item on the current list.
See further Chapter~\ref{expand} for
a discussion of expansion during writing.
%A control sequence output by \cs{write} (or \cs{message})
%is represented with a trailing space, and using
%character number \cs{escapechar}
%for the escape character.
%The \IniTeX\ default for this is~92,
%the code for the backslash.
%The trailing space can be prevented by prefixing the control
%sequence with \cs{string}.
A control sequence output by \cs{write} (or \cs{message})
is represented with a trailing space, and using
character number \cs{escapechar}
for the escape character.
The \IniTeX\ default for this is~92,
the code for the backslash.
The trailing space can be prevented by prefixing the control
sequence with \cs{string}.
%%\point Whatsits
%\section{Whatsits}
%\point Whatsits
\section{Whatsits}
%\index{whatsits|(}
\index{whatsits|(}
%There is an essential difference
%in execution between input and output:
%operations concerning output
%(\cs{openout}, \cs{closeout}, \cs{write})
%are executed \emph{asynchronously}\index{I/O!asynchronous}.
%That is, instead of being done immediately they are saved until
%the box in which they appear is shipped out
%to the \n{dvi} file.
There is an essential difference
in execution between input and output:
operations concerning output
(\cs{openout}, \cs{closeout}, \cs{write})
are executed \emph{asynchronously}\index{I/O!asynchronous}.
That is, instead of being done immediately they are saved until
the box in which they appear is shipped out
to the \n{dvi} file.
%Writes and the other two output operations are placed
%in `whatsit' items on whichever list is currently being built.
%The actual operation occurs when the part of the page
%that has the item is shipped out to the \n{dvi} file.
%This delayed output is made necessary by \TeX's
%asynchronous output routine behaviour.
%See a worked-out example on page~\pageref{expand:write}.
Writes and the other two output operations are placed
in `whatsit' items on whichever list is currently being built.
The actual operation occurs when the part of the page
that has the item is shipped out to the \n{dvi} file.
This delayed output is made necessary by \TeX's
asynchronous output routine behaviour.
See a worked-out example on page~\pageref{expand:write}.
%An \verb.\immediate\write. \ldash or any other \csidx{immediate} output
%operation \rdash is executed on the spot, and
%does not place a whatsit item on the current list.
An \verb.\immediate\write. \ldash or any other \csidx{immediate} output
operation \rdash is executed on the spot, and
does not place a whatsit item on the current list.
%The argument of a \cs{special} command
%(see page~\pageref{special}) is also placed in a whatsit.
The argument of a \cs{special} command
(see page~\pageref{special}) is also placed in a whatsit.
%Whatsit items in leader boxes are ignored.
Whatsit items in leader boxes are ignored.
%\index{whatsits|)}
\index{whatsits|)}
%\section{Assorted remarks}
\section{Assorted remarks}
%%\spoint Inspecting input
%\subsection{Inspecting input}
%\spoint Inspecting input
\subsection{Inspecting input}
%\TeX\ records the current line number in the current input file
%in the \gr{internal integer} parameter \csidx{inputlineno}
%(in \TeX3).
\TeX\ records the current line number in the current input file
in the \gr{internal integer} parameter \csidx{inputlineno}
(in \TeX3).
%If the parameter \csidx{pausing} is positive, \TeX\ shows
%every line that is input on the terminal \emph{screen}\index{I/O!screen},
%and gives the user the opportunity
%to insert commands. These can for instance be \cs{show} commands.
%Inserted commands are treated as if they were directly
%in the source file: it is for instance not necessary
%to prefix them with~`i', as would be necessary when
%\TeX\ pauses for an error.
If the parameter \csidx{pausing} is positive, \TeX\ shows
every line that is input on the terminal \emph{screen}\index{I/O!screen},
and gives the user the opportunity
to insert commands. These can for instance be \cs{show} commands.
Inserted commands are treated as if they were directly
in the source file: it is for instance not necessary
to prefix them with~`i', as would be necessary when
\TeX\ pauses for an error.
%%\spoint Testing for existence of files
%\subsection{Testing for existence of files}
%\spoint Testing for existence of files
\subsection{Testing for existence of files}
%\TeX\ is not the friendliest of systems when you
%\howto Test whether a file exists\par
%ask it to input a non-existing file. Therefore the following
%sequence of commands can be used to prevent trouble\label{ex:eof}:
%\begin{verbatim}
%\newread\instream \openin\instream= fname.tex
%\ifeof\instream \message{File 'fname' does not exist!}
%\else \closein\instream \input fname.tex
%\fi
%\end{verbatim}
%Here an input stream is opened with the given file name.
%The end-of-file test is also true
%if an input stream does not correspond to a physical file,
%so if this conditional is not true,
%the file exists and an \cs{input} command can safely be given.
\TeX\ is not the friendliest of systems when you
\howto Test whether a file exists\par
ask it to input a non-existing file. Therefore the following
sequence of commands can be used to prevent trouble\label{ex:eof}:
\begin{verbatim}
\newread\instream \openin\instream= fname.tex
\ifeof\instream \message{File 'fname' does not exist!}
\else \closein\instream \input fname.tex
\fi
\end{verbatim}
Here an input stream is opened with the given file name.
The end-of-file test is also true
if an input stream does not correspond to a physical file,
so if this conditional is not true,
the file exists and an \cs{input} command can safely be given.
%%\spoint Timing problems
%\subsection{Timing problems}
%\spoint Timing problems
\subsection{Timing problems}
%The synchronization between write operations on the
%one hand, and opening/closing operations
%of files on the other hand,
%can be a crucial point. Auxiliary files, such as are
%used by various formats to implement cross-references,
%are a good illustration of this.
The synchronization between write operations on the
one hand, and opening/closing operations
of files on the other hand,
can be a crucial point. Auxiliary files, such as are
used by various formats to implement cross-references,
are a good illustration of this.
%Suppose that during a run of \TeX\ the auxiliary file is written, and
%\howto Input a file that was created in the same run of \TeX\par
%at the end of the run it has to be input again for a variety
%of purposes (such as seeing whether references have changed).
%An \cs{input} command is executed right away, so
%the file must have been closed with an \verb=\immediate\closeout=.
%However, now it becomes possible that the file is closed
%before all writes to it have been performed.
%The following sequence remedies this:
%\begin{verbatim}
%\par\vfil\penalty -10000 \immediate\closeout\auxfile
%\end{verbatim}
%The first three commands activate the output routine
%in order to close off the last page,
%so all writes will indeed have been performed before the
%file is closed.
Suppose that during a run of \TeX\ the auxiliary file is written, and
\howto Input a file that was created in the same run of \TeX\par
at the end of the run it has to be input again for a variety
of purposes (such as seeing whether references have changed).
An \cs{input} command is executed right away, so
the file must have been closed with an \verb=\immediate\closeout=.
However, now it becomes possible that the file is closed
before all writes to it have been performed.
The following sequence remedies this:
\begin{verbatim}
\par\vfil\penalty -10000 \immediate\closeout\auxfile
\end{verbatim}
The first three commands activate the output routine
in order to close off the last page,
so all writes will indeed have been performed before the
file is closed.
%%\spoint \cs{message} versus \cs{immediate}\cs{write}16
%\subsection{\cs{message} versus \cs{immediate}\cs{write}16}
%\spoint \cs{message} versus \cs{immediate}\cs{write}16
\subsection{\cs{message} versus \cs{immediate}\cs{write}16}
%Messages to the user can be given using
%\csidx{message}\gr{general text}, which writes to the terminal.
%Messages are appended to one another;
%the line is wrapped when the line
%length (a~\TeX\ compile-time constant) has been reached.
%In \TeX\ version2,
%a~maximum of 1000 characters is written per message;
%this is not a compile-time constant, but is hard-wired
%into the \TeX\ program.
Messages to the user can be given using
\csidx{message}\gr{general text}, which writes to the terminal.
Messages are appended to one another;
the line is wrapped when the line
length (a~\TeX\ compile-time constant) has been reached.
In \TeX\ version2,
a~maximum of 1000 characters is written per message;
this is not a compile-time constant, but is hard-wired
into the \TeX\ program.
%Each message given with \verb=\immediate\write=
%starts on a new line; the user can force a new line
%in the message by including the character with
%number~\csidx{newlinechar}. This parameter also works
%in \cs{message}. The plain \TeX\ default for \cs{newlinechar} is~\n{-1};
%the \LaTeX\ default of~\n{10} allows you to write
%\verb+\message{two^^Jlines}+.
Each message given with \verb=\immediate\write=
starts on a new line; the user can force a new line
in the message by including the character with
number~\csidx{newlinechar}. This parameter also works
in \cs{message}. The plain \TeX\ default for \cs{newlinechar} is~\n{-1};
the \LaTeX\ default of~\n{10} allows you to write
\verb+\message{two^^Jlines}+.
%%\spoint Write inside a vertical box
%\subsection{Write inside a vertical box}
%\spoint Write inside a vertical box
\subsection{Write inside a vertical box}
%Since a write operation winds up on the vertical list in a whatsit,
%issuing one at the start of a \cs{vtop}
%will probably influence the height of that box
%(see Chapter~\ref{boxes}). As an example,
%\begin{verbatim}
%have the \vtop{\write\terminal{Hello!}\hbox{more text}}
%dangling from
%\end{verbatim}
%will have the~\vtop{\write-1{vtop gezien}\hbox{more text}}~dangling
%from the baseline (and when this book is \TeX ed the
%message `Hello!' appears on the screen).
Since a write operation winds up on the vertical list in a whatsit,
issuing one at the start of a \cs{vtop}
will probably influence the height of that box
(see Chapter~\ref{boxes}). As an example,
\begin{verbatim}
have the \vtop{\write\terminal{Hello!}\hbox{more text}}
dangling from
\end{verbatim}
will have the~\vtop{\write-1{vtop gezien}\hbox{more text}}~dangling
from the baseline (and when this book is \TeX ed the
message `Hello!' appears on the screen).
%%\spoint Expansion and spaces in \cs{write} and \cs{message}
%\subsection{Expansion and spaces in \cs{write} and \cs{message}}
%\spoint Expansion and spaces in \cs{write} and \cs{message}
\subsection{Expansion and spaces in \cs{write} and \cs{message}}
%Both \cs{write} and \cs{message} expand their argument
%as if it were the replacement text of an \cs{edef}.
%Therefore
%\begin{verbatim}
%\def\a{b}\message{\a}
%\end{verbatim}
%will
%write out~`\n b'.
Both \cs{write} and \cs{message} expand their argument
as if it were the replacement text of an \cs{edef}.
Therefore
\begin{verbatim}
\def\a{b}\message{\a}
\end{verbatim}
will
write out~`\n b'.
%Unexpandable control sequences are displayed with a trailing
%space (and prefixed with the \cs{escapechar}):
%\begin{verbatim}
%\message{\hbox\vbox!}
%\end{verbatim}
%will write out
%`\verb>\hbox \vbox !>'. Undefined control sequences give an error here.
Unexpandable control sequences are displayed with a trailing
space (and prefixed with the \cs{escapechar}):
\begin{verbatim}
\message{\hbox\vbox!}
\end{verbatim}
will write out
`\verb>\hbox \vbox !>'. Undefined control sequences give an error here.
%Expandable control sequences can be written out with some
%care:
%\begin{verbatim}
%\message{\noexpand\ifx}
%\message{\string\ifx}
%{\let\ifx\relax \message{\ifx}}
%\end{verbatim}
%all write out `\verb>\ifx>'.
Expandable control sequences can be written out with some
care:
\begin{verbatim}
\message{\noexpand\ifx}
\message{\string\ifx}
{\let\ifx\relax \message{\ifx}}
\end{verbatim}
all write out `\verb>\ifx>'.
%Note, however, that spaces after expandable control sequences
%are removed in the input processor, which goes into state~$S$
%after a control sequence. Therefore
%\begin{verbatim}
%\def\a{b}\def\c{d}
%\message{\a \c}
%\end{verbatim}
%writes out `\n{bd}'.
%Inserting a space can be done as follows:
%\begin{verbatim}
%\def\space{ } % in plain TeX
%\message{\a\space\c}
%\end{verbatim}
%displays `\n{b d}'.
%Note that
%\begin{verbatim}
%
%\message{\a{ }\c}
%\end{verbatim}
%does not work: it displays `\verb=b{ }d='
%since braces are unexpandable character tokens.
Note, however, that spaces after expandable control sequences
are removed in the input processor, which goes into state~$S$
after a control sequence. Therefore
\begin{verbatim}
\def\a{b}\def\c{d}
\message{\a \c}
\end{verbatim}
writes out `\n{bd}'.
Inserting a space can be done as follows:
\begin{verbatim}
\def\space{ } % in plain TeX
\message{\a\space\c}
\end{verbatim}
displays `\n{b d}'.
Note that
\begin{verbatim}
\message{\a{ }\c}
\end{verbatim}
does not work: it displays `\verb=b{ }d='
since braces are unexpandable character tokens.
%\index{I/O!file|)}
%\endofchapter
\index{I/O!file|)}
\endofchapter
\end{document}