-
Notifications
You must be signed in to change notification settings - Fork 18
/
chapter28.tex
768 lines (702 loc) · 27.4 KB
/
chapter28.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
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
% -*- coding: utf-8 -*-
\documentclass{book}
\input{preamble}
\setcounter{chapter}{27}
\begin{document}
%\chapter{Output Routines}\label{output}
%\index{output routine|(}
\chapter{Output Routines}\label{output}
\index{output routine|(}
%The final stages of page processing are performed by the
%output routine. The page builder cuts off a certain portion
%of the main vertical list and hands it to the output routine
%in \cs{box255}. This chapter treats the commands and parameters
%that pertain to the output routine, and it explains how
%output routines can receive information through marks.
The final stages of page processing are performed by the
output routine. The page builder cuts off a certain portion
of the main vertical list and hands it to the output routine
in \cs{box255}. This chapter treats the commands and parameters
that pertain to the output routine, and it explains how
output routines can receive information through marks.
%\label{cschap:output}\label{cschap:shipout}\label{cschap:mark}\label{cschap:topmark}\label{cschap:botmark}\label{cschap:firstmark}\label{cschap:splitbotmark}\label{cschap:splitfirstmark}\label{cschap:deadcycles}\label{cschap:maxdeadcycles}\label{cschap:outputpenalty2}
%\begin{inventory}
%\item [\cs{output}]
% Token list with instructions for shipping out pages.
\label{cschap:output}\label{cschap:shipout}\label{cschap:mark}\label{cschap:topmark}\label{cschap:botmark}\label{cschap:firstmark}\label{cschap:splitbotmark}\label{cschap:splitfirstmark}\label{cschap:deadcycles}\label{cschap:maxdeadcycles}\label{cschap:outputpenalty2}
\begin{inventory}
\item [\cs{output}]
Token list with instructions for shipping out pages.
%\item [\cs{shipout}]
% Ship a box to the \n{dvi} file.
\item [\cs{shipout}]
Ship a box to the \n{dvi} file.
%\item [\cs{mark}]
% Specify a mark text.
\item [\cs{mark}]
Specify a mark text.
%\item [\cs{topmark}]
% The last mark on the previous page.
\item [\cs{topmark}]
The last mark on the previous page.
%\item [\cs{botmark}]
% The last mark on the current page.
\item [\cs{botmark}]
The last mark on the current page.
%\item [\cs{firstmark}]
% The first mark on the current page.
\item [\cs{firstmark}]
The first mark on the current page.
%\item [\cs{splitbotmark}]
% The last mark on a split-off page.
\item [\cs{splitbotmark}]
The last mark on a split-off page.
%\item [\cs{splitfirstmark}]
% The first mark on a split-off page.
\item [\cs{splitfirstmark}]
The first mark on a split-off page.
%\item [\cs{deadcycles}]
% Counter that keeps track of how many times
% the output routine has been called without a \cs{shipout}
% taking place.
\item [\cs{deadcycles}]
Counter that keeps track of how many times
the output routine has been called without a \cs{shipout}
taking place.
%\item [\cs{maxdeadcycles}]
% The maximum number of times that the output routine is allowed to
% be called without a \cs{shipout} occurring.
\item [\cs{maxdeadcycles}]
The maximum number of times that the output routine is allowed to
be called without a \cs{shipout} occurring.
%\item [\cs{outputpenalty}]
% Value of the penalty at the current page break,
% \alt
% or $10\,000$ if the break was not at a penalty.
\item [\cs{outputpenalty}]
Value of the penalty at the current page break,
\alt
or $10\,000$ if the break was not at a penalty.
%\end{inventory}
\end{inventory}
%%\point The \cs{output} token list
%\section{The \protect\cs{output} token list}
%\point The \cs{output} token list
\section{The \protect\cs{output} token list}
%Common parlance has it that
%`the output routine is called' when \TeX\ has found a place
%to break the main vertical list.
%Actually, \cs{output} is not a macro but a token list that
%is inserted into \TeX's command stream.
Common parlance has it that
`the output routine is called' when \TeX\ has found a place
to break the main vertical list.
Actually, \cs{output} is not a macro but a token list that
is inserted into \TeX's command stream.
%Insertion of the \cs{output} token list happens
%\cstoidx output\par
%inside a group that is implicitly opened.
%Also, \TeX\ enters internal vertical mode.
%Because of the group, non-local assignments
%(to the page number, for instance)
%have to be prefixed with \cs{global}.
%The vertical mode implies that during the workings of the
%output routine
%spaces are mostly harmless.
Insertion of the \cs{output} token list happens
\cstoidx output\par
inside a group that is implicitly opened.
Also, \TeX\ enters internal vertical mode.
Because of the group, non-local assignments
(to the page number, for instance)
have to be prefixed with \cs{global}.
The vertical mode implies that during the workings of the
output routine
spaces are mostly harmless.
%The \cs{output} token list belongs
%to the class of the
%\gr{token parameter}s. These behave the same as
%\cs{toks}$nnn$ token lists; see Chapter~\ref{token}.
%Assigning an output routine can therefore take the following
%forms:
%\begin{disp}\cs{output}\gr{equals}\gr{general text}\quad
%or\quad
%\cs{output}\gr{equals}\gr{filler}\gr{token variable}
%\end{disp}
The \cs{output} token list belongs
to the class of the
\gr{token parameter}s. These behave the same as
\cs{toks}$nnn$ token lists; see Chapter~\ref{token}.
Assigning an output routine can therefore take the following
forms:
\begin{disp}\cs{output}\gr{equals}\gr{general text}\quad
or\quad
\cs{output}\gr{equals}\gr{filler}\gr{token variable}
\end{disp}
%%\point[output255] Output and \cs{box255}
%\section{Output and \protect\cs{box255}}
%\label{output255}
%\point[output255] Output and \cs{box255}
\section{Output and \protect\cs{box255}}
\label{output255}
%\TeX's page builder breaks the current page at the optimal point,
%and stores everything above that in \cs{box255};
%then, the \cs{output} tokens are inserted into the input stream.
%Any remaining material on the main vertical list
%is pushed back to the recent
%contributions.
%If the page is broken at a penalty,
%\alt
%that value is recorded in \cs{outputpenalty}, and
%a penalty of size $10\,000$ is placed on top of the
%recent contributions; otherwise, \cs{outputpenalty}
%is set to~$10\,000$.
%When the output routine is finished, \cs{box255} is
%supposed to be empty.
%If it is not, \TeX\ gives an error message.
\TeX's page builder breaks the current page at the optimal point,
and stores everything above that in \cs{box255};
then, the \cs{output} tokens are inserted into the input stream.
Any remaining material on the main vertical list
is pushed back to the recent
contributions.
If the page is broken at a penalty,
\alt
that value is recorded in \cs{outputpenalty}, and
a penalty of size $10\,000$ is placed on top of the
recent contributions; otherwise, \cs{outputpenalty}
is set to~$10\,000$.
When the output routine is finished, \cs{box255} is
supposed to be empty.
If it is not, \TeX\ gives an error message.
%Usually, the output routine will take the pagebox,
%\cstoidx shipout\par
%\mdqon
%append a headline and/""or footline,
%\mdqoff
%maybe merge in some insertions such as footnotes,
%and ship the page to the \n{dvi} file:
%\begin{verbatim}
%\output={\setbox255=\vbox
% {\someheadline
% \vbox to \vsize{\unvbox255 \unvbox\footins}
% \somefootline}
% \shipout\box255}
%\end{verbatim}
%When box 255 reaches the output routine, its height has
%been set to \cs{vsize}.
%However, the material in it can have considerably
%smaller height.
%Thus, the above output routine may lead to underfull boxes.
%This can be remedied with a \cs{vfil}.
Usually, the output routine will take the pagebox,
\cstoidx shipout\par
\mdqon
append a headline and/""or footline,
\mdqoff
maybe merge in some insertions such as footnotes,
and ship the page to the \n{dvi} file:
\begin{verbatim}
\output={\setbox255=\vbox
{\someheadline
\vbox to \vsize{\unvbox255 \unvbox\footins}
\somefootline}
\shipout\box255}
\end{verbatim}
When box 255 reaches the output routine, its height has
been set to \cs{vsize}.
However, the material in it can have considerably
smaller height.
Thus, the above output routine may lead to underfull boxes.
This can be remedied with a \cs{vfil}.
%The output routine is under no obligation to
%\cstoidx deadcycles\par
%do anything useful with \cs{box255}; it can empty it, or
%unbox it to let \TeX\ have another go at finding a page
%break. The number of times
%that the output routing postpones the \cs{shipout}
%is recorded in \cs{deadcycles}: this parameter is set to~0
%by \cs{shipout}, and increased by~1 just before
%every \cs{output}.
The output routine is under no obligation to
\cstoidx deadcycles\par
do anything useful with \cs{box255}; it can empty it, or
unbox it to let \TeX\ have another go at finding a page
break. The number of times
that the output routing postpones the \cs{shipout}
is recorded in \cs{deadcycles}: this parameter is set to~0
by \cs{shipout}, and increased by~1 just before
every \cs{output}.
%When the number of dead cycles reaches
%\csidx{maxdeadcycles}, \TeX\ gives an error message,
%and performs the default output routine
%\begin{verbatim}
%\shipout\box255
%\end{verbatim}
%instead of the routine it was about
%to start.
%The \LaTeX\ format has a much higher value for \cs{maxdeadcycles}
%than plain \TeX, because the output routine in \LaTeX\
%is often called for
%intermediate handling of floats and marginal notes.
When the number of dead cycles reaches
\csidx{maxdeadcycles}, \TeX\ gives an error message,
and performs the default output routine
\begin{verbatim}
\shipout\box255
\end{verbatim}
instead of the routine it was about
to start.
The \LaTeX\ format has a much higher value for \cs{maxdeadcycles}
than plain \TeX, because the output routine in \LaTeX\
is often called for
intermediate handling of floats and marginal notes.
%The \cs{shipout} command can send any \gr{box} to the \n{dvi} file;
%this need not be box 255, or even a box
%containing the current page.
%It does not have to be called inside the output routine, either.
The \cs{shipout} command can send any \gr{box} to the \n{dvi} file;
this need not be box 255, or even a box
containing the current page.
It does not have to be called inside the output routine, either.
%If the output routine produces any material, for instance
%by calling
%\begin{verbatim}
%\unvbox255
%\end{verbatim}
%this is put on top
%of the recent contributions.
If the output routine produces any material, for instance
by calling
\begin{verbatim}
\unvbox255
\end{verbatim}
this is put on top
of the recent contributions.
%After the output routine finishes, the page builder is
%activated. In particular, because the current page
%has been emptied, the \cs{vsize} is read again.
%Changes made to this parameter inside the output
%routine (using \cs{global}) will therefore take effect.
After the output routine finishes, the page builder is
activated. In particular, because the current page
has been emptied, the \cs{vsize} is read again.
Changes made to this parameter inside the output
routine (using \cs{global}) will therefore take effect.
%%\point Marks
%\section{Marks}
%\point Marks
\section{Marks}
%Information can be passed to the output routine through the
%\cstoidx mark\par
%mechanism of \indexterm{marks}. The user can specify a token list
%with
%\begin{disp}\cs{mark}\lb\gr{mark text}\rb\end{disp}
%which is put in a mark item on the current vertical list.
%The mark text is subject to expansion as in \cs{edef}.
Information can be passed to the output routine through the
\cstoidx mark\par
mechanism of \indexterm{marks}. The user can specify a token list
with
\begin{disp}\cs{mark}\lb\gr{mark text}\rb\end{disp}
which is put in a mark item on the current vertical list.
The mark text is subject to expansion as in \cs{edef}.
%If the mark is given in horizontal mode it migrates to
%the surrounding vertical lists like an insertion item
%(see page~\pageref{migrate});
%however, if this is not the external vertical list, the
%output routine will not find the mark.
If the mark is given in horizontal mode it migrates to
the surrounding vertical lists like an insertion item
(see page~\pageref{migrate});
however, if this is not the external vertical list, the
output routine will not find the mark.
%Marks are the main mechanism through which the output routine
%can obtain information about the contents of the currently
%broken-off page, in particular its top and bottom.
%\TeX\ sets three variables:
%\begin{description}
%\item [\csidx{botmark}]
% the last mark occurring on the current page;
%\item [\csidx{firstmark}]
% the first mark occurring on the current page;
%\item [\csidx{topmark}]
% the last mark of the previous page,
% that is, the value of \cs{botmark}
% on the previous page.
%\end{description}
%If no marks have occurred yet, all three are empty;
%if no marks occurred on the current page,
%all three mark variables are equal
%to the \cs{botmark} of the previous page.
Marks are the main mechanism through which the output routine
can obtain information about the contents of the currently
broken-off page, in particular its top and bottom.
\TeX\ sets three variables:
\begin{description}
\item [\csidx{botmark}]
the last mark occurring on the current page;
\item [\csidx{firstmark}]
the first mark occurring on the current page;
\item [\csidx{topmark}]
the last mark of the previous page,
that is, the value of \cs{botmark}
on the previous page.
\end{description}
If no marks have occurred yet, all three are empty;
if no marks occurred on the current page,
all three mark variables are equal
to the \cs{botmark} of the previous page.
%For boxes generated by a \cs{vsplit} command (see previous chapter),
%the \cs{splitbotmark} and \cs{splitfirstmark}
%\cstoidx splitbotmark\par\cstoidx splitfirstmark\par
%contain the marks of the split-off part; \cs{firstmark}
%and \cs{botmark} reflect the state of what remains in the register.
For boxes generated by a \cs{vsplit} command (see previous chapter),
the \cs{splitbotmark} and \cs{splitfirstmark}
\cstoidx splitbotmark\par\cstoidx splitfirstmark\par
contain the marks of the split-off part; \cs{firstmark}
and \cs{botmark} reflect the state of what remains in the register.
%\begin{example} Marks can be used to get a section heading into
%\howto Do tricks with headlines\par
%the headline or footline of the page.
%\begin{verbatim}
%\def\section#1{ ... \mark{#1} ... }
%\def\rightheadline{\hbox to \hsize
% {\headlinefont \botmark\hfil\pagenumber}}
%\def\leftheadline{\hbox to \hsize
% {\headlinefont \pagenumber\hfil\firstmark}}
%\end{verbatim}
%This places the title of the first section that starts on a
%left page in the left headline, and the title of the last section
%that starts on the right page in the right headline.
%Placing the headlines on the page is the job of the output routine;
%see below.
\begin{example} Marks can be used to get a section heading into
\howto Do tricks with headlines\par
the headline or footline of the page.
\begin{verbatim}
\def\section#1{ ... \mark{#1} ... }
\def\rightheadline{\hbox to \hsize
{\headlinefont \botmark\hfil\pagenumber}}
\def\leftheadline{\hbox to \hsize
{\headlinefont \pagenumber\hfil\firstmark}}
\end{verbatim}
This places the title of the first section that starts on a
left page in the left headline, and the title of the last section
that starts on the right page in the right headline.
Placing the headlines on the page is the job of the output routine;
see below.
%It is important that no page breaks can occur in between the
%mark and the box that places the title:
%\begin{verbatim}
%\def\section#1{ ...
% \penalty\beforesectionpenalty
% \mark{#1}
% \hbox{ ... #1 ...}
% \nobreak
% \vskip\aftersectionskip
% \noindent}
%\end{verbatim}
%\end{example}
It is important that no page breaks can occur in between the
mark and the box that places the title:
\begin{verbatim}
\def\section#1{ ...
\penalty\beforesectionpenalty
\mark{#1}
\hbox{ ... #1 ...}
\nobreak
\vskip\aftersectionskip
\noindent}
\end{verbatim}
\end{example}
%Let us consider
%another example with headlines: often a page looks better if
%the headline is omitted on pages where a chapter starts.
%This can be implemented as follows:
%\begin{verbatim}
%\def\endofchapter
%\chapter#1{ ... \def\chtitle{#1}\mark{1}\mark{0} ... }
%\def\theheadline{\expandafter\ifx\firstmark1
% \else \chapheadline \fi}
%\end{verbatim}
%Only on the page where a chapter starts will the mark be~1,
%and on all other pages a headline is placed.
Let us consider
another example with headlines: often a page looks better if
the headline is omitted on pages where a chapter starts.
This can be implemented as follows:
\begin{verbatim}
\def\endofchapter
\chapter#1{ ... \def\chtitle{#1}\mark{1}\mark{0} ... }
\def\theheadline{\expandafter\ifx\firstmark1
\else \chapheadline \fi}
\end{verbatim}
Only on the page where a chapter starts will the mark be~1,
and on all other pages a headline is placed.
%%\point Assorted remarks
%\section{Assorted remarks}
%\point Assorted remarks
\section{Assorted remarks}
%%\spoint Hazards in non-trivial output routines
%\subsection{Hazards in non-trivial output routines}
%\spoint Hazards in non-trivial output routines
\subsection{Hazards in non-trivial output routines}
%If the final call to the output routine does not
%perform a \cs{shipout}, \TeX\ will call the output
%routine endlessly, since a run will only stop if both
%the vertical list is empty, and \cs{deadcycles}
%is zero. The output routine can set \cs{deadcycles}
%to zero to prevent this.
If the final call to the output routine does not
perform a \cs{shipout}, \TeX\ will call the output
routine endlessly, since a run will only stop if both
the vertical list is empty, and \cs{deadcycles}
is zero. The output routine can set \cs{deadcycles}
to zero to prevent this.
%%\spoint Page numbering
%\subsection{Page numbering}
%\index{page!numbering|(}
%\spoint Page numbering
\subsection{Page numbering}
\index{page!numbering|(}
%The page number is not an intrinsic property of the output
%routine; in plain \TeX\ it is the value of \cs{count0}.
%The output routine is responsible for increasing the
%page number when a shipout of a page occurs.
The page number is not an intrinsic property of the output
routine; in plain \TeX\ it is the value of \cs{count0}.
The output routine is responsible for increasing the
page number when a shipout of a page occurs.
%Apart from \cs{count0}, counter registers~1--9 are also used
%for page identification: at shipout \TeX\ writes the values
%of these ten counters to the \n{dvi} file (see Chapter~\ref{TeXcomm}).
%Terminal and log file output display only the non-zero counters,
%and the zero counters for which a non-zero counter with
%a higher number exists, that is, if \cs{count0}${}=1$ and
%\cs{count3}${}=5$ are the only non-zero counters, the
%displayed list of counters is~\n{[1.0.0.5]}.
Apart from \cs{count0}, counter registers~1--9 are also used
for page identification: at shipout \TeX\ writes the values
of these ten counters to the \n{dvi} file (see Chapter~\ref{TeXcomm}).
Terminal and log file output display only the non-zero counters,
and the zero counters for which a non-zero counter with
a higher number exists, that is, if \cs{count0}${}=1$ and
\cs{count3}${}=5$ are the only non-zero counters, the
displayed list of counters is~\n{[1.0.0.5]}.
%\index{page!numbering|)}
\index{page!numbering|)}
%\subsection{Headlines and footlines in plain \TeX}
\subsection{Headlines and footlines in plain \TeX}
%Plain \TeX\ has token lists \cs{headline} and
%\cs{footline}; these are used in the macros
%\handbreak \cs{makeheadline} and \cs{makefootline}.
%The page is shipped out as (more or less)
%\begin{verbatim}
%\vbox{\makeheadline\pagebody\makefootline}
%\end{verbatim}
Plain \TeX\ has token lists \cs{headline} and
\cs{footline}; these are used in the macros
\handbreak \cs{makeheadline} and \cs{makefootline}.
The page is shipped out as (more or less)
\begin{verbatim}
\vbox{\makeheadline\pagebody\makefootline}
\end{verbatim}
%Both headline and footline are inserted inside a \cs{line}.
%For non-standard headers and footers it is easier to
%redefine the macros \cs{makeheadline} and \cs{makefootline}
%than to tinker with the token lists.
Both headline and footline are inserted inside a \cs{line}.
For non-standard headers and footers it is easier to
redefine the macros \cs{makeheadline} and \cs{makefootline}
than to tinker with the token lists.
%%\spoint Example: no widow lines
%\subsection{Example: no widow lines}
%\spoint Example: no widow lines
\subsection{Example: no widow lines}
%Suppose that one does not want to allow widow lines,
%but pages have in general no stretch or shrink,
%for instance because they only contain plain text.
%A~solution would be to increase the page length
%by one line if a page turns out to be broken
%at a widow line.
Suppose that one does not want to allow widow lines,
but pages have in general no stretch or shrink,
for instance because they only contain plain text.
A~solution would be to increase the page length
by one line if a page turns out to be broken
at a widow line.
%\TeX's output routine can perform this sort of
%trick: if the \cs{widowpenalty} is set to
%some recognizable value, the output routine
%can see by the \cs{outputpenalty} if a widow
%line occurred. In that case, the output routine
%can temporarily increase the \cs{vsize}, and
%let the page builder have another go at
%finding a break point.
\TeX's output routine can perform this sort of
trick: if the \cs{widowpenalty} is set to
some recognizable value, the output routine
can see by the \cs{outputpenalty} if a widow
line occurred. In that case, the output routine
can temporarily increase the \cs{vsize}, and
let the page builder have another go at
finding a break point.
%Here is the skeleton of such an output routine.
%No headers or footers are provided for.
%\begin{verbatim}
%\newif\ifLargePage \widowpenalty=147
%\newdimen\oldvsize \oldvsize=\vsize
%\output={
% \ifLargePage \shipout\box255
% \global\LargePagefalse
% \global\vsize=\oldvsize
% \else \ifnum \outputpenalty=\widowpenalty
% \global\LargePagetrue
% \global\advance\vsize\baselineskip
% \unvbox255 \penalty\outputpenalty
% \else \shipout\box255
% \fi \fi}
%\end{verbatim}
%The test \cs{ifLargePage} is set to true by the
%output routine if the \cs{outputpenalty}
%equals the \cs{widowpenalty}. The page box
%is then \cs{unvbox}$\,$ed, so that the page builder
%will tackle the same material once more.
Here is the skeleton of such an output routine.
No headers or footers are provided for.
\begin{verbatim}
\newif\ifLargePage \widowpenalty=147
\newdimen\oldvsize \oldvsize=\vsize
\output={
\ifLargePage \shipout\box255
\global\LargePagefalse
\global\vsize=\oldvsize
\else \ifnum \outputpenalty=\widowpenalty
\global\LargePagetrue
\global\advance\vsize\baselineskip
\unvbox255 \penalty\outputpenalty
\else \shipout\box255
\fi \fi}
\end{verbatim}
The test \cs{ifLargePage} is set to true by the
output routine if the \cs{outputpenalty}
equals the \cs{widowpenalty}. The page box
is then \cs{unvbox}$\,$ed, so that the page builder
will tackle the same material once more.
%%\spoint Example: no indentation top of page
%\subsection{Example: no indentation top of page}
%\spoint Example: no indentation top of page
\subsection{Example: no indentation top of page}
%Some output routines can be classified
%\howto Prevent indentation on top of page\par
%as abuse of the output routine mechanism.
%The output routine in this section is a good example of this.
Some output routines can be classified
\howto Prevent indentation on top of page\par
as abuse of the output routine mechanism.
The output routine in this section is a good example of this.
%It is imaginable that one wishes paragraphs not to indent
%if they start at the top of a page. (There are plenty of objections
%to this layout, but occasionally it is used.)
%This problem can be solved using the output routine to
%investigate whether the page is still empty and, if so,
%to give a signal that a paragraph should not indent.
It is imaginable that one wishes paragraphs not to indent
if they start at the top of a page. (There are plenty of objections
to this layout, but occasionally it is used.)
This problem can be solved using the output routine to
investigate whether the page is still empty and, if so,
to give a signal that a paragraph should not indent.
%Note that we cannot use the fact here
%that the page builder comes into play after
%the insertion of \cs{everypar}: even if we could
%force the output routine to be activated here,
%there is no way for it to remove the indentation box.
Note that we cannot use the fact here
that the page builder comes into play after
the insertion of \cs{everypar}: even if we could
force the output routine to be activated here,
there is no way for it to remove the indentation box.
%The solution given here lets the \cs{everypar}
%terminate the paragraph immediately
%with
%\begin{verbatim}
%\par\penalty-\specialpenalty
%\end{verbatim}
%which activates the output routine.
%Seeing whether the pagebox is empty (after removing
%the empty line and any \cs{parskip} glue),
%the output routine then can set a switch
%signalling whether the retry of the paragraph
%should indent.
The solution given here lets the \cs{everypar}
terminate the paragraph immediately
with
\begin{verbatim}
\par\penalty-\specialpenalty
\end{verbatim}
which activates the output routine.
Seeing whether the pagebox is empty (after removing
the empty line and any \cs{parskip} glue),
the output routine then can set a switch
signalling whether the retry of the paragraph
should indent.
%There are some minor matters in the following
%routines, the sense of which is left
%for the reader to ponder.
%\begin{verbatim}
%\mathchardef\specialpenalty=10001
%\newif\ifPreventSwitch
%\newbox\testbox
%\topskip=10pt
%\everypar{\begingroup \par
% \penalty-\specialpenalty
% \everypar{\endgroup}\parskip0pt
% \ifPreventSwitch \noindent \else \indent \fi
% \global\PreventSwitchfalse
% }
%\output{
% \ifnum\outputpenalty=-\specialpenalty
% \setbox\testbox\vbox{\unvbox255
% {\setbox0=\lastbox}\unskip}
% \ifdim\ht\testbox=0pt \global\PreventSwitchtrue
% \else \topskip=0pt \unvbox\testbox \fi
% \else \shipout\box255 \global\advance\pageno1 \fi}
%\end{verbatim}
There are some minor matters in the following
routines, the sense of which is left
for the reader to ponder.
\begin{verbatim}
\mathchardef\specialpenalty=10001
\newif\ifPreventSwitch
\newbox\testbox
\topskip=10pt
\everypar{\begingroup \par
\penalty-\specialpenalty
\everypar{\endgroup}\parskip0pt
\ifPreventSwitch \noindent \else \indent \fi
\global\PreventSwitchfalse
}
\output{
\ifnum\outputpenalty=-\specialpenalty
\setbox\testbox\vbox{\unvbox255
{\setbox0=\lastbox}\unskip}
\ifdim\ht\testbox=0pt \global\PreventSwitchtrue
\else \topskip=0pt \unvbox\testbox \fi
\else \shipout\box255 \global\advance\pageno1 \fi}
\end{verbatim}
%%\spoint More examples of output routines
%\subsection{More examples of output routines}
%\spoint More examples of output routines
\subsection{More examples of output routines}
%A large number of examples of output routines
%can be found in~\cite{Sal1} and~\cite{Sal2}.
A large number of examples of output routines
can be found in~\cite{Sal1} and~\cite{Sal2}.
%\index{output routine|)}
\index{output routine|)}
%\endofchapter
\endofchapter
\end{document}