-
Notifications
You must be signed in to change notification settings - Fork 18
/
chapter19.tex
1323 lines (1206 loc) · 52.4 KB
/
chapter19.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
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
% -*- coding: utf-8 -*-
\documentclass{book}
\input{preamble}
\setcounter{chapter}{18}
\begin{document}
%\chapter{Line Breaking}\label{line:break}
%\index{paragraph!breaking into lines|(}
%\index{line breaking|(}
\chapter{Line Breaking}\label{line:break}
\index{paragraph!breaking into lines|(}
\index{line breaking|(}
%This chapter treats line breaking and the concept of `badness' that \TeX\
%uses to decide how to break a paragraph into lines,
%or where to break a page.
%The various penalties contributing to the cost of line breaking
%are treated here, as is hyphenation.
%Page breaking is treated in Chapter~\ref{page:break}.
This chapter treats line breaking and the concept of `badness' that \TeX\
uses to decide how to break a paragraph into lines,
or where to break a page.
The various penalties contributing to the cost of line breaking
are treated here, as is hyphenation.
Page breaking is treated in Chapter~\ref{page:break}.
%\label{cschap:penalty}\label{cschap:linepenalty}\label{cschap:hyphenpenalty}\label{cschap:exhyphenpenalty}\label{cschap:adjdemerits}\label{cschap:doublehyphendemerits}\label{cschap:finalhyphendemerits}\label{cschap:allowbreak}\label{cschap:pretolerance}\label{cschap:tolerance}\label{cschap:emergencystretch}\label{cschap:looseness}\label{cschap:prevgraf}\label{cschap:discretionary}\label{cschap:-}\label{cschap:hyphenchar2}\label{cschap:defaulthyphenchar2}\label{cschap:uchyph}\label{cschap:lefthyphenmin}\label{cschap:righthyphenmin}\label{cschap:patterns}\label{cschap:hyphenation}\label{cschap:language}\label{cschap:setlanguage}
%\begin{inventory}
%\item [\cs{penalty}]
% Specify desirability of not breaking at this point.
\label{cschap:penalty}\label{cschap:linepenalty}\label{cschap:hyphenpenalty}\label{cschap:exhyphenpenalty}\label{cschap:adjdemerits}\label{cschap:doublehyphendemerits}\label{cschap:finalhyphendemerits}\label{cschap:allowbreak}\label{cschap:pretolerance}\label{cschap:tolerance}\label{cschap:emergencystretch}\label{cschap:looseness}\label{cschap:prevgraf}\label{cschap:discretionary}\label{cschap:-}\label{cschap:hyphenchar2}\label{cschap:defaulthyphenchar2}\label{cschap:uchyph}\label{cschap:lefthyphenmin}\label{cschap:righthyphenmin}\label{cschap:patterns}\label{cschap:hyphenation}\label{cschap:language}\label{cschap:setlanguage}
\begin{inventory}
\item [\cs{penalty}]
Specify desirability of not breaking at this point.
%\item [\cs{linepenalty}]
% Penalty value associated with each line break.
% Plain \TeX\ default:~\n{10}.
\item [\cs{linepenalty}]
Penalty value associated with each line break.
Plain \TeX\ default:~\n{10}.
%\item [\cs{hyphenpenalty}]
% Penalty associated with break at a discretionary item
% in the general case.
% Plain \TeX\ default:~\n{50}.
\item [\cs{hyphenpenalty}]
Penalty associated with break at a discretionary item
in the general case.
Plain \TeX\ default:~\n{50}.
%\item [\cs{exhyphenpenalty}]
% Penalty for breaking a horizontal line at a discretionary
% item in the special case where the prebreak text is empty.
% Plain \TeX\ default:~\n{50}.
\item [\cs{exhyphenpenalty}]
Penalty for breaking a horizontal line at a discretionary
item in the special case where the prebreak text is empty.
Plain \TeX\ default:~\n{50}.
%\item [\cs{adjdemerits}]
% Penalty for adjacent visually incompatible lines.
% Plain \TeX\ default:~\n{10$\,$000}.
\item [\cs{adjdemerits}]
Penalty for adjacent visually incompatible lines.
Plain \TeX\ default:~\n{10$\,$000}.
%\item [\cs{doublehyphendemerits}]
% Penalty for consecutive lines ending with a hyphen.
% Plain \TeX\ default: \n{10$\,$000}.
\item [\cs{doublehyphendemerits}]
Penalty for consecutive lines ending with a hyphen.
Plain \TeX\ default: \n{10$\,$000}.
%\item [\cs{finalhyphendemerits}]
% Penalty added when the penultimate line of a
% paragraph ends with a hyphen.
% Plain \TeX\ default:~\n{5000}.
\item [\cs{finalhyphendemerits}]
Penalty added when the penultimate line of a
paragraph ends with a hyphen.
Plain \TeX\ default:~\n{5000}.
%\item [\cs{allowbreak}]
% Macro for creating a breakpoint by inserting a
% \cs{penalty0}.
\item [\cs{allowbreak}]
Macro for creating a breakpoint by inserting a
\cs{penalty0}.
%\item [\cs{pretolerance}]
% Tolerance value for a paragraph without hyphenation.
% Plain \TeX\ default:~\n{100}.
\item [\cs{pretolerance}]
Tolerance value for a paragraph without hyphenation.
Plain \TeX\ default:~\n{100}.
%\item [\cs{tolerance}]
% Tolerance value for lines in a paragraph with hyphenation.
% Plain \TeX\ default:~\n{200}.
\item [\cs{tolerance}]
Tolerance value for lines in a paragraph with hyphenation.
Plain \TeX\ default:~\n{200}.
%\item [\cs{emergencystretch}]
% (\TeX3 only)
% Assumed extra stretchability in lines of a paragraph.
\item [\cs{emergencystretch}]
(\TeX3 only)
Assumed extra stretchability in lines of a paragraph.
%\item [\cs{looseness}]
% Number of lines by which this paragraph has to be made longer
% than it would be ideally.
\item [\cs{looseness}]
Number of lines by which this paragraph has to be made longer
than it would be ideally.
%\item [\cs{prevgraf}]
% The number of lines in the paragraph last
% added to the vertical list.
\item [\cs{prevgraf}]
The number of lines in the paragraph last
added to the vertical list.
%\item [\cs{discretionary}]
% Specify the way a character sequence is split up at a line break.
\item [\cs{discretionary}]
Specify the way a character sequence is split up at a line break.
%\item [\cs{-}]
% Discretionary hyphen; this is
% equivalent to \verb|\discretionary{-}{}{}|.
\item [\cs{-}]
Discretionary hyphen; this is
equivalent to \verb|\discretionary{-}{}{}|.
%\item [\cs{hyphenchar}]
% Number of the hyphen character of a font.
\item [\cs{hyphenchar}]
Number of the hyphen character of a font.
%\item [\cs{defaulthyphenchar}]
% Value of \cs{hyphenchar} when a font is loaded.
% Plain \TeX\ default:~\n{`\cs{-}}.
\item [\cs{defaulthyphenchar}]
Value of \cs{hyphenchar} when a font is loaded.
Plain \TeX\ default:~\n{`\cs{-}}.
%\item [\cs{uchyph}]
% Positive to allow hyphenation of words starting with a capital
% letter.
% Plain \TeX\ default:~\n{1}.
\item [\cs{uchyph}]
Positive to allow hyphenation of words starting with a capital
letter.
Plain \TeX\ default:~\n{1}.
%\item [\cs{lefthyphenmin}]
% (\TeX3 only)
% Minimal number of characters before a hyphenation.
% Plain \TeX\ default:~\n{2}.
\item [\cs{lefthyphenmin}]
(\TeX3 only)
Minimal number of characters before a hyphenation.
Plain \TeX\ default:~\n{2}.
%\item [\cs{righthyphenmin}]
% (\TeX3 only)
% Minimum number of characters after a hyphenation.
% Plain \TeX\ default:~\n{3}.
\item [\cs{righthyphenmin}]
(\TeX3 only)
Minimum number of characters after a hyphenation.
Plain \TeX\ default:~\n{3}.
%\item [\cs{patterns}]
% Define a list of hyphenation patterns for the current
% value of \cs{language}; allowed only in \IniTeX.
\item [\cs{patterns}]
Define a list of hyphenation patterns for the current
value of \cs{language}; allowed only in \IniTeX.
%\item [\cs{hyphenation}]
% Define hyphenation exceptions for the current value of \cs{language}.
\item [\cs{hyphenation}]
Define hyphenation exceptions for the current value of \cs{language}.
%\item [\cs{language}]
% Choose a set of hyphenation patterns and exceptions.
\item [\cs{language}]
Choose a set of hyphenation patterns and exceptions.
%\item [\cs{setlanguage}]
% Reset the current language.
\item [\cs{setlanguage}]
Reset the current language.
%\end{inventory}
\end{inventory}
%%\point Paragraph break cost calculation
%\section{Paragraph break cost calculation}
%\point Paragraph break cost calculation
\section{Paragraph break cost calculation}
%A paragraph is broken such that the amount $d$ of {\em demerits\/}
%associated with breaking it is minimized.
%The total amount of demerits for a paragraph is the sum
%of those for the individual lines, plus possibly some extra
%penalties. Considering a paragraph as a whole instead of
%breaking it on a line-by-line basis can lead to better
%line breaking: \TeX\ can choose to take a slightly less beautiful
%line in the beginning of the paragraph in order to avoid
%bigger trouble later on.
A paragraph is broken such that the amount $d$ of {\em demerits\/}
associated with breaking it is minimized.
The total amount of demerits for a paragraph is the sum
of those for the individual lines, plus possibly some extra
penalties. Considering a paragraph as a whole instead of
breaking it on a line-by-line basis can lead to better
line breaking: \TeX\ can choose to take a slightly less beautiful
line in the beginning of the paragraph in order to avoid
bigger trouble later on.
%For each line demerits are calculated from the {\em badness\/}~$b$
%of stretching or shrinking the line to the break, and
%the {\em penalty\/}~$p$ associated with the break.
%The badness is not allowed to exceed a certain prescribed
%tolerance.
For each line demerits are calculated from the {\em badness\/}~$b$
of stretching or shrinking the line to the break, and
the {\em penalty\/}~$p$ associated with the break.
The badness is not allowed to exceed a certain prescribed
tolerance.
%In addition to the demerits for breaking individual lines,
%\TeX\ assigns demerits for the way lines combine; see below.
In addition to the demerits for breaking individual lines,
\TeX\ assigns demerits for the way lines combine; see below.
%The
%\mdqon
%implementation of \TeX's paragraph"-breaking algorithm
%\mdqoff
%is explained in~\cite{K:break}.
The
\mdqon
implementation of \TeX's paragraph"-breaking algorithm
\mdqoff
is explained in~\cite{K:break}.
%%\spoint Badness
%\subsection{Badness}
%\spoint Badness
\subsection{Badness}
%From the ratio between the stretch or shrink present in a
%line, and the actual stretch or shrink taken,
%the \emph{badness}\index{badness! and line breaking}\index{line breaking!badness}
%of breaking a line at a certain point is calculated.
%This badness is an important
%factor in the process of line breaking.
%See page~\pageref{bad:form} for the formula for badness.
From the ratio between the stretch or shrink present in a
line, and the actual stretch or shrink taken,
the \emph{badness}\index{badness! and line breaking}\index{line breaking!badness}
of breaking a line at a certain point is calculated.
This badness is an important
factor in the process of line breaking.
See page~\pageref{bad:form} for the formula for badness.
%In this chapter
%badness will only be discussed in the context of line breaking.
%Badness is also computed when a vertical list is stretched
%or shrunk (see Chapter~\ref{page:break}).
In this chapter
badness will only be discussed in the context of line breaking.
Badness is also computed when a vertical list is stretched
or shrunk (see Chapter~\ref{page:break}).
%The following terminology is used to describe badness:
%\begin{description} \item [tight (3)]
%is any line that has shrunk with a badness~$b\geq13$,
%that is, by using at least one-half of its amount of shrink
%(see page~\pageref{bad:form} for the computation).
%\item [decent (2)]
%is any line with a badness~$b\leq12$.
%\item [loose (1)]
%is any line that has stretched with a badness~$b\geq13$,
%that is, by using at least one-half of its amount of stretch.
%\item [very loose (0)]
%is any line that has stretched with a badness~$b\geq100$,
%that is, by using its full amount of stretch or more. Recall
%that glue can stretch, but not shrink more than its
%allowed amount.
%\end{description}
%The numbering is used in trace output (Chapter~\ref{trace}), and
%it is also used in the following definition:
%if the classifications of two adjacent lines differ by more than~1,
%the lines are said to be {\em visually incompatible\/}.
%See below for the \cs{adjdemerits} parameter associated with this.
The following terminology is used to describe badness:
\begin{description} \item [tight (3)]
is any line that has shrunk with a badness~$b\geq13$,
that is, by using at least one-half of its amount of shrink
(see page~\pageref{bad:form} for the computation).
\item [decent (2)]
is any line with a badness~$b\leq12$.
\item [loose (1)]
is any line that has stretched with a badness~$b\geq13$,
that is, by using at least one-half of its amount of stretch.
\item [very loose (0)]
is any line that has stretched with a badness~$b\geq100$,
that is, by using its full amount of stretch or more. Recall
that glue can stretch, but not shrink more than its
allowed amount.
\end{description}
The numbering is used in trace output (Chapter~\ref{trace}), and
it is also used in the following definition:
if the classifications of two adjacent lines differ by more than~1,
the lines are said to be {\em visually incompatible\/}.
See below for the \cs{adjdemerits} parameter associated with this.
%Overfull horizontal and vertical
%boxes are passed unnoticed if their excess width
%or height is less than \cs{hfuzz} or \cs{vfuzz} respectively;
%they are not reported if the badness is less than
%\cs{hbadness} or \cs{vbadness} (see Chapter~\ref{boxes}).
Overfull horizontal and vertical
boxes are passed unnoticed if their excess width
or height is less than \cs{hfuzz} or \cs{vfuzz} respectively;
they are not reported if the badness is less than
\cs{hbadness} or \cs{vbadness} (see Chapter~\ref{boxes}).
%%\spoint Penalties and other break locations
%\subsection{Penalties and other break locations}
%
%Line breaks can occur at the following \emph{breakpoints}
%\index{lists !horizontal! breakpoints in}
%in horizontal lists:
%\begin{enumerate} \item At a penalty. The penalty value is the
%`aesthetic cost' of breaking the line at that place.
%Negative penalties are considered as bonuses.
%A~penalty of $10\,000$ or more inhibits, and a penalty
%of $-10\,000$ or less forces, a~break.
%\spoint Penalties and other break locations
\subsection{Penalties and other break locations}
Line breaks can occur at the following \emph{breakpoints}
\index{lists !horizontal! breakpoints in}
in horizontal lists:
\begin{enumerate} \item At a penalty. The penalty value is the
`aesthetic cost' of breaking the line at that place.
Negative penalties are considered as bonuses.
A~penalty of $10\,000$ or more inhibits, and a penalty
of $-10\,000$ or less forces, a~break.
%Putting more than one penalty
%in a row is equivalent to putting just the one with the
%minimal value, because that one is the best candidate for line breaking.
Putting more than one penalty
in a row is equivalent to putting just the one with the
minimal value, because that one is the best candidate for line breaking.
%Penalties in horizontal mode are inserted by the user (or a
%user macro). The only exception is the \cs{nobreak}
%inserted before the \cs{parfillskip} glue.
Penalties in horizontal mode are inserted by the user (or a
user macro). The only exception is the \cs{nobreak}
inserted before the \cs{parfillskip} glue.
%\item At a glue, if it is not part of a math formula, and
%if it is preceded by a non-discardable item (see Chapter~\ref{hvmode}).
%There is no penalty associated with breaking at glue.
\item At a glue, if it is not part of a math formula, and
if it is preceded by a non-discardable item (see Chapter~\ref{hvmode}).
There is no penalty associated with breaking at glue.
%The condition about the non-discardable precursor is necessary,
%because otherwise breaking in between two pieces of glue would
%be possible, which would cause ragged edges to the paragraph.
The condition about the non-discardable precursor is necessary,
because otherwise breaking in between two pieces of glue would
be possible, which would cause ragged edges to the paragraph.
%\item At a kern, if it is not part of a math formula
%and if it is followed by glue.
%There is no penalty associated with breaking at a~kern.
\item At a kern, if it is not part of a math formula
and if it is followed by glue.
There is no penalty associated with breaking at a~kern.
%\item At a math-off, if that is followed by glue.
%Since math-off
%(and math-on) act as kerns (see Chapter~\ref{math}),
%this is very much like the previous case.
%There is no penalty associated with breaking at a~math-off.
\item At a math-off, if that is followed by glue.
Since math-off
(and math-on) act as kerns (see Chapter~\ref{math}),
this is very much like the previous case.
There is no penalty associated with breaking at a~math-off.
%\item At a discretionary break. The penalty
%is the \cs{hyphenpenalty} or the \cs{exhyphenpenalty}.
%This is treated below.
%\end{enumerate}
\item At a discretionary break. The penalty
is the \cs{hyphenpenalty} or the \cs{exhyphenpenalty}.
This is treated below.
\end{enumerate}
%Any discardable material following the break \ldash glue, kerns,
%\mdqon
%math-on/""off and penalties \rdash is discarded. If one considers
%\mdqoff
%a line break at glue (kern, math-on{/}off) to occur at the
%front end of the glue item, this implies that that piece
%of glue disappears in the break.
Any discardable material following the break \ldash glue, kerns,
\mdqon
math-on/""off and penalties \rdash is discarded. If one considers
\mdqoff
a line break at glue (kern, math-on{/}off) to occur at the
front end of the glue item, this implies that that piece
of glue disappears in the break.
%%\spoint Demerits
%\subsection{Demerits}
%\spoint Demerits
\subsection{Demerits}
%From the badness of a line and the penalty, if any, the demerits
%of the line are calculated. Let $l$ be the value of
%\csidx{linepenalty}, $b$~the badness of the line,
%$p$~the penalty at the break; then the \indexterm{demerits}~$d$
%are given by
%\begin{disp}$\displaystyle d=\cases{(l+b)^2+p^2&if $0\leq p<10\,000$\cr
% (l+b)^2-p^2&if $-10\,000<p<0$\cr
% (l+b)^2 &if $p\leq-10\,000$\cr}$\end{disp}
From the badness of a line and the penalty, if any, the demerits
of the line are calculated. Let $l$ be the value of
\csidx{linepenalty}, $b$~the badness of the line,
$p$~the penalty at the break; then the \indexterm{demerits}~$d$
are given by
\begin{disp}$\displaystyle d=
\begin{cases} (l+b)^2+p^2& \text{if } 0\leq p<10\,000 \\
(l+b)^2-p^2&\text{if } -10\,000<p<0 \\
(l+b)^2 &\text{if } p\leq-10\,000 \end{cases}$\end{disp}
%Both this formula and the one for the badness are described
%\alt
%in \cite{K:break} as `quite arbitrary',
%but they have been shown to lead to
%good results in practice.
Both this formula and the one for the badness are described
\alt
in \cite{K:break} as `quite arbitrary',
but they have been shown to lead to
good results in practice.
%The demerits for a paragraph are the sum of the demerits for
%the lines, plus
%\begin{itemize}
%\item the \csidx{adjdemerits} for any two
% adjacent lines that are not visually compatible (see above),
%\item \csidx{doublehyphendemerits} for any two
% consecutive lines ending with a hyphen, and the
%\item \csidx{finalhyphendemerits}
% if the penultimate line of a paragraph
% ends with a hyphen.\end{itemize}
The demerits for a paragraph are the sum of the demerits for
the lines, plus
\begin{itemize}
\item the \csidx{adjdemerits} for any two
adjacent lines that are not visually compatible (see above),
\item \csidx{doublehyphendemerits} for any two
consecutive lines ending with a hyphen, and the
\item \csidx{finalhyphendemerits}
if the penultimate line of a paragraph
ends with a hyphen.\end{itemize}
%At the start of a paragraph \TeX\ acts as if
%there was a preceding line which was `decent'.
%Therefore \cs{adjdemerits} will be added if the first
%line is `very loose'. Also, the last line
%of a paragraph is ordinarily also `decent'
%\ldash all spaces are set at natural width
%owing to the infinite stretch in the \cs{parfillskip} \rdash
%so \cs{adjdemerits} are added if
%the preceding line is `very loose'.
At the start of a paragraph \TeX\ acts as if
there was a preceding line which was `decent'.
Therefore \cs{adjdemerits} will be added if the first
line is `very loose'. Also, the last line
of a paragraph is ordinarily also `decent'
\ldash all spaces are set at natural width
owing to the infinite stretch in the \cs{parfillskip} \rdash
so \cs{adjdemerits} are added if
the preceding line is `very loose'.
%Note that the penalties at which a line break
%is chosen weigh about as heavily as the badness of
%the line, so they can be relatively small.
%However, the three extra demerit parameters
%have to be of the order of the square of
%penalties and badnesses to weigh equally heavily.
Note that the penalties at which a line break
is chosen weigh about as heavily as the badness of
the line, so they can be relatively small.
However, the three extra demerit parameters
have to be of the order of the square of
penalties and badnesses to weigh equally heavily.
%%\spoint The number of lines of a paragraph
%\subsection{The number of lines of a paragraph}
%\spoint The number of lines of a paragraph
\subsection{The number of lines of a paragraph}
%After a paragraph has been completed (or partially
%completed prior to a display), the variable \csidx{prevgraf}
%records the number of lines in the paragraph.
%By assigning to this variable \ldash and
%because this is a \gr{special integer}
%such an assignment is automatically global \rdash
%\TeX's decision processes can be influenced.
%This may be useful in combination with hanging indentation
%or \cs{parshape} specifications (see Chapter~\ref{par:shape}).
After a paragraph has been completed (or partially
completed prior to a display), the variable \csidx{prevgraf}
records the number of lines in the paragraph.
By assigning to this variable \ldash and
because this is a \gr{special integer}
such an assignment is automatically global \rdash
\TeX's decision processes can be influenced.
This may be useful in combination with hanging indentation
or \cs{parshape} specifications (see Chapter~\ref{par:shape}).
%\mdqon
%Some direct influence of the line"-breaking process
%\mdqoff
%on the resulting number of lines exists. One factor
%is the \cs{linepenalty} which is included in the demerits
%of each line. By increasing the line penalty \TeX\ can be
%made to minimize the number of lines in a paragraph.
\mdqon
Some direct influence of the line"-breaking process
\mdqoff
on the resulting number of lines exists. One factor
is the \cs{linepenalty} which is included in the demerits
of each line. By increasing the line penalty \TeX\ can be
made to minimize the number of lines in a paragraph.
%Deviations from the optimal number of lines, that is, the
%number of lines stemming from the optimal way of breaking a
%paragraph into lines, can be forced by the user by means
%of the \csidx{looseness} parameter. This parameter, which is
%reset every time the shape parameters
%are cleared (see Chapter~\ref{par:shape}),
%indicates by how many lines the current
%paragraph should be made longer than is optimal. A~negative
%value of \cs{looseness} will attempt to make the paragraph shorter
%by a number of lines that is the absolute value of the parameter.
Deviations from the optimal number of lines, that is, the
number of lines stemming from the optimal way of breaking a
paragraph into lines, can be forced by the user by means
of the \csidx{looseness} parameter. This parameter, which is
reset every time the shape parameters
are cleared (see Chapter~\ref{par:shape}),
indicates by how many lines the current
paragraph should be made longer than is optimal. A~negative
value of \cs{looseness} will attempt to make the paragraph shorter
by a number of lines that is the absolute value of the parameter.
%\TeX\ will still observe the values
%of \cs{pretolerance} and \cs{tolerance} (see below)
%when lengthening or shortening a paragraph under influence
%of \cs{looseness}.
%Therefore,
%\TeX\ will only lengthen or shorten a paragraph for as far
%as is possible without exceeding these parameters.
\TeX\ will still observe the values
of \cs{pretolerance} and \cs{tolerance} (see below)
when lengthening or shortening a paragraph under influence
of \cs{looseness}.
Therefore,
\TeX\ will only lengthen or shorten a paragraph for as far
as is possible without exceeding these parameters.
%%\spoint[between:lines] Between the lines
%\subsection{Between the lines}
%\label{between:lines}
%\spoint[between:lines] Between the lines
\subsection{Between the lines}
\label{between:lines}
%\TeX's
%paragraph mechanism packages lines into horizontal boxes
%that are appended to the surrounding vertical list.
%The resulting sequence of vertical items is then a
%repeating sequence of
%\begin{itemize}\item a box containing a line of text,
%\item possibly migrated vertical material (see page~\pageref{migrate}),
%\item a penalty item reflecting the cost of a page break
% at that point, which is normally the \cs{interlinepenalty}
% (see Chapter~\ref{page:break}), and
%\item interline glue, which is calculated automatically
% on basis of the \cs{prevdepth} (see Chapter~\ref{baseline}).
%\end{itemize}
\TeX's
paragraph mechanism packages lines into horizontal boxes
that are appended to the surrounding vertical list.
The resulting sequence of vertical items is then a
repeating sequence of
\begin{itemize}\item a box containing a line of text,
\item possibly migrated vertical material (see page~\pageref{migrate}),
\item a penalty item reflecting the cost of a page break
at that point, which is normally the \cs{interlinepenalty}
(see Chapter~\ref{page:break}), and
\item interline glue, which is calculated automatically
on basis of the \cs{prevdepth} (see Chapter~\ref{baseline}).
\end{itemize}
%%\point The process of breaking
%\section{The process of breaking}
%\point The process of breaking
\section{The process of breaking}
%\TeX\ tries to break paragraphs in such a way that
%the badness of each line does not exceed a certain tolerance.
%If there exists more than one solution to this, the one with
%the fewest demerits is taken.
\TeX\ tries to break paragraphs in such a way that
the badness of each line does not exceed a certain tolerance.
If there exists more than one solution to this, the one with
the fewest demerits is taken.
%By setting \csidx{tracingparagraphs} to a positive value,
%\TeX\ can be made to report the calculations of the
%paragraph mechanism in the log file. Some implementations of \TeX\
%may have this option disabled to make \TeX\ run faster.
By setting \csidx{tracingparagraphs} to a positive value,
\TeX\ can be made to report the calculations of the
paragraph mechanism in the log file. Some implementations of \TeX\
may have this option disabled to make \TeX\ run faster.
%%\spoint Three passes
%\subsection{Three passes}
%\spoint Three passes
\subsection{Three passes}
%First an attempt is made to split the paragraph into lines
%without hyphenating, that is, without inserting discretionary
%hyphens. This attempt succeeds if none of the
%lines has a badness exceeding \csidx{pretolerance}.
First an attempt is made to split the paragraph into lines
without hyphenating, that is, without inserting discretionary
hyphens. This attempt succeeds if none of the
lines has a badness exceeding \csidx{pretolerance}.
%Otherwise, a second pass is made, inserting discretionaries
%and using \csidx{tolerance}.
%\handbreak If \cs{pretolerance} is negative, the first pass is omitted.
Otherwise, a second pass is made, inserting discretionaries
and using \csidx{tolerance}.
\handbreak If \cs{pretolerance} is negative, the first pass is omitted.
%\TeX\ can be made to make a third pass if the first and
%second pass fail.
%If \csidx{emergencystretch} is a positive dimension,
%\TeX\ will assume this much extra stretchability
%in each line when badness and demerits are calculated.
%Thus solutions that only slightly exceeded the given
%tolerances will now become feasible.
%However, no glue of size \cs{emergencystretch} is
%actually present, so underfull box messages
%may still occur.
\TeX\ can be made to make a third pass if the first and
second pass fail.
If \csidx{emergencystretch} is a positive dimension,
\TeX\ will assume this much extra stretchability
in each line when badness and demerits are calculated.
Thus solutions that only slightly exceeded the given
tolerances will now become feasible.
However, no glue of size \cs{emergencystretch} is
actually present, so underfull box messages
may still occur.
%%\spoint Tolerance values
%\subsection{Tolerance values}
%\spoint Tolerance values
\subsection{Tolerance values}
%How much
%trouble \TeX\ will have typesetting a piece of text
%depends partly on the tolerance value.
%Therefore it is sensible to have some idea of
%what badness values mean in visual terms.
How much
trouble \TeX\ will have typesetting a piece of text
depends partly on the tolerance value.
Therefore it is sensible to have some idea of
what badness values mean in visual terms.
%For lines that are stretched, the badness is
%100 times the cube of the stretch ratio.
%A~badness of 800 thus means that the stretch ratio
%is~2.
%If the space is,
%\alt
%as in the ten-point Computer Modern Font,
%\begin{verbatim}
%3.33pt plus 1.67pt minus 1.11pt
%\end{verbatim}
%a badness of 800 means that spaces have been stretched to
%\begin{disp} \n{3.33pt}${}+2\times{}$\n{1.67pt}${}={}$\n{6.66pt}\end{disp}
%that is, to exactly double their natural size.
%It is up to you to decide whether this is too large.
For lines that are stretched, the badness is
100 times the cube of the stretch ratio.
A~badness of 800 thus means that the stretch ratio
is~2.
If the space is,
\alt
as in the ten-point Computer Modern Font,
\begin{verbatim}
3.33pt plus 1.67pt minus 1.11pt
\end{verbatim}
a badness of 800 means that spaces have been stretched to
\begin{disp} \n{3.33pt}${}+2\times{}$\n{1.67pt}${}={}$\n{6.66pt}\end{disp}
that is, to exactly double their natural size.
It is up to you to decide whether this is too large.
%%\point Discretionaries
%\section{Discretionaries}
%\point Discretionaries
\section{Discretionaries}
%A \indexterm{discretionary item} \verb-\discretionary{..}{..}{..}-
%\cstoidx discretionary\par
%marks a place where a word can be broken.
%Each of the three arguments is a \gr{general text}
%(see Chapter~\ref{gramm}):
%they are, in sequence,
%\begin{itemize} \item the {\em pre-break\/} text, which is appended
%to the part of the word before the break,
%\item the {\em post-break\/} text, which is prepended to the part
%of the word after the break, and
%\item the {\em no-break\/} text, which is used if the word
%is not broken at the discretionary item.\end{itemize}
%For example: \verb>ab\discretionary{g}{h}{cd}ef>
%is the word \hbox{\n{abcdef}}, but it can be hyphenated
%\alt
%with \n{abg} before the break and \n{hef} after.
%Note that there is no automatic hyphen character.
A \indexterm{discretionary item} \verb-\discretionary{..}{..}{..}-
\cstoidx discretionary\par
marks a place where a word can be broken.
Each of the three arguments is a \gr{general text}
(see Chapter~\ref{gramm}):
they are, in sequence,
\begin{itemize} \item the {\em pre-break\/} text, which is appended
to the part of the word before the break,
\item the {\em post-break\/} text, which is prepended to the part
of the word after the break, and
\item the {\em no-break\/} text, which is used if the word
is not broken at the discretionary item.\end{itemize}
For example: \verb>ab\discretionary{g}{h}{cd}ef>
is the word \hbox{\n{abcdef}}, but it can be hyphenated
\alt
with \n{abg} before the break and \n{hef} after.
Note that there is no automatic hyphen character.
%All three texts may contain any sorts of tokens,
%but any primitive commands and macros
%should expand to boxes, kerns, and characters.
All three texts may contain any sorts of tokens,
but any primitive commands and macros
should expand to boxes, kerns, and characters.
%%\spoint Hyphens and discretionaries
%\subsection{Hyphens and discretionaries}
%\spoint Hyphens and discretionaries
\subsection{Hyphens and discretionaries}
%Internally, \TeX\ inserts the equivalent of
%\cstoidx hyphenchar\par
%\begin{verbatim}
%\discretionary{\char\hyphenchar\font}{}{}
%\end{verbatim}
%at every place where a word can be broken. This causes a \indextermbus{hyphen}{character} to be placed before any break.
%No
%such discretionary is inserted if \verb>\hyphenchar\font>
%is not in the range 0--255, or if its position in the
%font is not filled.
%When a font is loaded, its \cs{hyphenchar} value
%is set to \csidx{defaulthyphenchar}. The \cs{hyphenchar}
%value can be changed after this.
Internally, \TeX\ inserts the equivalent of
\cstoidx hyphenchar\par
\begin{verbatim}
\discretionary{\char\hyphenchar\font}{}{}
\end{verbatim}
at every place where a word can be broken. This causes a \indextermbus{hyphen}{character} to be placed before any break.
No
such discretionary is inserted if \verb>\hyphenchar\font>
is not in the range 0--255, or if its position in the
font is not filled.
When a font is loaded, its \cs{hyphenchar} value
is set to \csidx{defaulthyphenchar}. The \cs{hyphenchar}
value can be changed after this.
%In plain \TeX\ the \cs{defaulthyphenchar} has the value~\verb>`\->, so
%for all fonts character~45 (the \ascii\ hyphen character)
%is the hyphen sign, unless
%it is specified otherwise.
In plain \TeX\ the \cs{defaulthyphenchar} has the value~\verb>`\->, so
for all fonts character~45 (the \ascii\ hyphen character)
is the hyphen sign, unless
it is specified otherwise.
%The primitive command \verb|\-| (called a `discretionary hyphen')
%\csterm -\par\indexterm{discretionary hyphen}
%is equivalent to the above
%\handbreak
%\verb|\discretionary{\char\hyphenchar\font}{}{}|.
%Breaking at such a discretionary, whether inserted implicitly
%by \TeX\ or explicitly by the user, has
%a cost of \csidx{hyphenpenalty}.
The primitive command \verb|\-| (called a `discretionary hyphen')
\csterm -\par\indexterm{discretionary hyphen}
is equivalent to the above
\handbreak
\verb|\discretionary{\char\hyphenchar\font}{}{}|.
Breaking at such a discretionary, whether inserted implicitly
by \TeX\ or explicitly by the user, has
a cost of \csidx{hyphenpenalty}.
%In unrestricted horizontal mode an empty discretionary
%\cs{disc\-re\-tio\-na\-ry}\verb-{}{}{}-
%is automatically inserted after characters
%whose character code is the \cs{hyphenchar} value
%of the font, thus enabling hyphenation at that point.
%The penalty for breaking a line at
%such a discretionary with an empty pre-break text
%is \csidx{exhyphenpenalty}, that is, the `explicit hyphen' penalty.
In unrestricted horizontal mode an empty discretionary
\cs{disc\-re\-tio\-na\-ry}\verb-{}{}{}-
is automatically inserted after characters
whose character code is the \cs{hyphenchar} value
of the font, thus enabling hyphenation at that point.
The penalty for breaking a line at
such a discretionary with an empty pre-break text
is \csidx{exhyphenpenalty}, that is, the `explicit hyphen' penalty.
%If a word contains
%discretionary breaks, for instance
%because of explicit hyphen characters,
%\TeX\ will not consider it for further hyphenation.
%People have solved the ensuing problems by tricks
%such as
%\howto Enable hyphenation of a word containing a hyphen\par
%\begin{verbatim}
%\def\={\penalty10000 \hskip0pt -\penalty0 \hskip0pt\relax}
%... integro\=differential equations...
%\end{verbatim}
%The skips before and after the hyphen lead \TeX\ into
%treating the first and second half of the
%compound expression as separate words; the penalty
%before the first skip inhibits breaking before the hyphen.
If a word contains
discretionary breaks, for instance
because of explicit hyphen characters,
\TeX\ will not consider it for further hyphenation.
People have solved the ensuing problems by tricks
such as
\howto Enable hyphenation of a word containing a hyphen\par
\begin{verbatim}
\def\={\penalty10000 \hskip0pt -\penalty0 \hskip0pt\relax}
... integro\=differential equations...
\end{verbatim}
The skips before and after the hyphen lead \TeX\ into
treating the first and second half of the
compound expression as separate words; the penalty
before the first skip inhibits breaking before the hyphen.
%%\spoint Examples of discretionaries
%\subsection{Examples of discretionaries}
%\spoint Examples of discretionaries
\subsection{Examples of discretionaries}
%\emph{Languages}\index{languages} such as German or Dutch have words
%that change spelling when hyphenated (German: `\hbox{backen}' becomes
%`\hbox{bak-ken}'; Dutch: `\hbox{autootje}' becomes
%`\hbox{auto-tje}'). This problem can be solved with \TeX's
%discretionaries.
\emph{Languages}\index{languages} such as German or Dutch have words
that change spelling when hyphenated (German: `\hbox{backen}' becomes
`\hbox{bak-ken}'; Dutch: `\hbox{autootje}' becomes
`\hbox{auto-tje}'). This problem can be solved with \TeX's
discretionaries.
%For instance, for German (this is inspired by~\cite{Partl}):
%\begin{verbatim}
%\catcode`\"=\active
%\def"#1{\ifx#1k\discretionary{k-}{k}{ck}\fi}
%\end{verbatim}
%which enables the user to write \verb>ba"ken>.
For instance, for German (this is inspired by~\cite{Partl}):
\begin{verbatim}
\catcode`\"=\active
\def"#1{\ifx#1k\discretionary{k-}{k}{ck}\fi}
\end{verbatim}
which enables the user to write \verb>ba"ken>.
%In Dutch there is a further problem which allows a nice
%systematic solution. Umlaut characters (`trema' is the
%Dutch term) should often
%disappear in a break, for instance `\hbox{na"apen}'
%hyphenates as `\hbox{na-apen}', and `\hbox{onbe"invloedbaar}'
%hyphenates as `\hbox{onbe-invloedbaar}'. A solution
%(inspired by~\cite{Babel}) is
%\begin{verbatim}
%\catcode`\"=\active
%\def"#1{\ifx#1i\discretionary{-}{i}{\"\i}%
% \else \discretionary{-}{#1}{\"#1}\fi}
%\end{verbatim}
%which enables the user to type \verb>na"apen> and
%\verb>onbe"invloedbaar>.
In Dutch there is a further problem which allows a nice
systematic solution. Umlaut characters (`trema' is the
Dutch term) should often
disappear in a break, for instance `\hbox{na"apen}'
hyphenates as `\hbox{na-apen}', and `\hbox{onbe"invloedbaar}'
hyphenates as `\hbox{onbe-invloedbaar}'. A solution
(inspired by~\cite{Babel}) is
\begin{verbatim}
\catcode`\"=\active
\def"#1{\ifx#1i\discretionary{-}{i}{\"\i}%
\else \discretionary{-}{#1}{\"#1}\fi}
\end{verbatim}
which enables the user to type \verb>na"apen> and
\verb>onbe"invloedbaar>.
%%\point Hyphenation
%\section{Hyphenation}
%\point Hyphenation
\section{Hyphenation}
%\TeX's \indexterm{hyphenation}
%algorithm uses a list of patterns to
%determine at what places a word that is a candidate for
%hyphenation can be broken.
%Those aspects of hyphenation connected with these
%patterns are
%treated in appendix~H of \TeXbook;
%the method of generating hyphenation patterns automatically
%is described in~\cite{Liang}. People have been known
%to generate lists of patterns by hand;
%see for instance~\cite{Vas:add}. Such hand-generated lists
%may be superior to automatically generated lists.
\TeX's \indexterm{hyphenation}
algorithm uses a list of patterns to
determine at what places a word that is a candidate for
hyphenation can be broken.
Those aspects of hyphenation connected with these
patterns are
treated in appendix~H of \TeXbook;
the method of generating hyphenation patterns automatically
is described in~\cite{Liang}. People have been known
to generate lists of patterns by hand;
see for instance~\cite{Vas:add}. Such hand-generated lists
may be superior to automatically generated lists.
%Here it will mainly be described how \TeX\ declares a word to
%be a candidate for hyphenation. The problem here is
%how to cope with punctuation and things such as quotation marks
%that can be attached to a word. Also, {\em implicit kerns\/},
%that is, kerns inserted because of font information,
%must be handled properly.
Here it will mainly be described how \TeX\ declares a word to
be a candidate for hyphenation. The problem here is
how to cope with punctuation and things such as quotation marks
that can be attached to a word. Also, {\em implicit kerns\/},
that is, kerns inserted because of font information,
must be handled properly.
%%\spoint Start of a word
%\subsection{Start of a word}
%\spoint Start of a word
\subsection{Start of a word}
%\TeX\ starts at glue items (if they are not in math mode)
%looking for a {\em starting letter\/} of a word: