Debian Codegraph @

texmf-dist/source/luatex/lua-widow-control/tb133chernoff-widows-figure.ctx

raw
1 % lua-widow-control
2 % https://github.com/gucci-on-fleek/lua-widow-control
3 % SPDX-License-Identifier: MPL-2.0+ OR CC-BY-SA-4.0+
4 % SPDX-FileCopyrightText: 2022 Max Chernoff
5
6 \startbuffer[demo-text]
7 \definepapersize[smallpaper][
8 width=6cm,
9 height=8.3cm
10 ]
11 \setuppapersize[smallpaper]
12
13 \def\lwc/{\sans{lua-\allowbreak widow-\allowbreak control}}
14 \def\Lwc/{\sans{lua-\allowbreak widow-\allowbreak control}}
15
16 \setupbodyfont[9pt]
17 \setupindenting[yes, 2em]
18 \setupalign[tolerant]
19
20 \definecolor[midlightgray][s=0.75]
21 \definepalet[layout][grid=midlightgray]
22 \showgrid[nonumber, none, lines]
23
24 \definefontfeature[default][default][expansion=quality,protrusion=quality]
25
26 \usetypescript[modern-base]
27 \setupbodyfont[reset,modern]
28
29 \setupalign[hz,hanging,tolerant]
30
31 \setuplanguage[en][spacing=packed]
32
33 \setuplayout[
34 topspace=0.1cm,
35 backspace=0.1cm,
36 width=middle,
37 height=\dimexpr 21\baselineskip + 1.1pt,
38 header=0pt,
39 footer=0pt,
40 ]
41
42 \starttext
43 \Lwc/ can remove most widows and orphans from a document, \emph{without}
44 stretching any glue or shortening any pages.
45
46 \ifx\uselooseness\undefined\else\uselooseness\fi It does so by automatically lengthening a paragraph on a page where a
47 widow or orphan would otherwise occur. While \TeX{} breaks paragraphs
48 into their natural length, \lwc/ is breaking the paragraph 1~line
49 longer than its natural length. \TeX{}'s paragraph is output to the
50 page, but \lwc/'s paragraph is just stored for later. When a widow or
51 orphan occurs, \lwc/ can take over. It selects the previously-saved
52 paragraph with the least badness; then, it replaces \TeX{}'s paragraph
53 with its saved paragraph. This increases the text block height of the
54 page by 1~line.
55
56 Now, the last line of the current page can be pushed to the top of the
57 next page. This removes the widow or the orphan without creating any
58 additional work.
59 \stoptext
60 \stoptext
61 \stopbuffer
62 \savebuffer[list=demo-text]
63
64 \startbuffer[shorten]
65 \parskip=0pt
66 \input tb133chernoff-widows-figure-demo-text.tmp
67 \stopbuffer
68
69 \startbuffer[shorten-code]
70 \parskip=0pt
71 \clubpenalty=10000
72 \widowpenalty=10000
73 \stopbuffer
74
75 \startbuffer[stretch]
76 \parskip=0pt plus 1fill
77 \input tb133chernoff-widows-figure-demo-text.tmp
78 \stopbuffer
79
80 \startbuffer[stretch-code]
81 \parskip=0pt plus 1fill
82 \clubpenalty=10000
83 \widowpenalty=10000
84 \stopbuffer
85
86 \startbuffer[ignore]
87 \startsetups[*default]
88 \clubpenalty=0
89 \widowpenalty=0
90 \displaywidowpenalty=0
91 \interlinepenalty=0
92 \brokenpenalty=0
93 \stopsetups
94
95 \setups[*default]
96
97 \input tb133chernoff-widows-figure-demo-text.tmp
98 \stopbuffer
99
100 \startbuffer[ignore-code]
101 \parskip=0pt
102 \clubpenalty=0
103 \widowpenalty=0
104 \stopbuffer
105
106 \startbuffer[lwc]
107 \def\uselooseness{\looseness=1}
108 \input tb133chernoff-widows-figure-demo-text.tmp
109 \stopbuffer
110
111 % We're pretending that we're using LaTeX for the demo since that's what
112 % 99% of users will be using.
113 \startbuffer[lwc-code]
114 \usepackage{lua-widow-control}
115 \stopbuffer
116
117 \setupbodyfont[10pt]
118
119 \setupbackend[format=PDF/A-1b:2005] % Force PDF version <1.5
120
121 \startTEXpage[
122 align=normal,
123 width=39pc,
124 offset=0pt,
125 ]
126 \veryraggedcenter
127 \setupTABLE[row][1, 5][style=\bfa, align=middle, offset=0pt]
128 \setupTABLE[row][5][toffset=2ex]
129 \setupTABLE[frame=off, distance=5em]
130 \startTABLE
131 \NC Ignore
132 \NC Shorten
133 \NC\NR
134
135 \NC \typesetbuffer[ignore][frame=on, page=1, scale=925]
136 \NC \typesetbuffer[shorten][frame=on, page=1, scale=925]
137 \NC\NR
138
139 \NC \clip[height=1cm]{\typesetbuffer[ignore]
140 [frame=on, page=2, scale=925]}
141 \NC \clip[height=1cm]{\typesetbuffer[shorten]
142 [frame=on, page=2, scale=925]}
143 \NC\NR
144
145 \NC \typebuffer[ignore-code]
146 \NC \typebuffer[shorten-code]
147 \NC\NR
148
149 \NC Stretch
150 \NC \sans{lua-widow-control} \NC\NR
151
152 \NC \typesetbuffer[stretch][frame=on, page=1, scale=925]
153 \NC \typesetbuffer[lwc][frame=on, page=1, scale=925]
154 \NC\NR
155
156 \NC \clip[height=1cm]{\typesetbuffer[stretch]
157 [frame=on, page=2, scale=925]}
158 \NC \clip[height=1cm]{\typesetbuffer[lwc]
159 [frame=on, page=2, scale=925]}
160 \NC\NR
161
162 \NC \typebuffer[stretch-code]
163 \NC \typebuffer[lwc-code]
164 \NC\NR
165 \stopTABLE
166 \stopTEXpage