Debian Codegraph @

texmf-dist/source/luatex/lua-widow-control/lwc-manual-samples.tex

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 ]\setuppapersize[smallpaper]
11
12 \setuplayout[
13 topspace=0.1cm,
14 backspace=0.1cm,
15 width=middle,
16 height=middle,
17 header=0pt,
18 footer=0pt,
19 ]
20
21 \def\lwc/{\sans{lua-\allowbreak widow-\allowbreak control}}
22 \def\Lwc/{\sans{Lua-\allowbreak widow-\allowbreak control}}
23
24 \setupbodyfont[9pt]
25 \setupindenting[yes, 2em]
26
27 \definepalet[layout][grid=middlegray]
28 \showgrid[nonumber, none, lines]
29
30 \definefontfeature[default][default][expansion=quality,protrusion=quality]
31
32 \usetypescript[modern-base]
33 \setupbodyfont[reset,modern]
34
35 \setupalign[hz,hanging,tolerant]
36
37 \setuplanguage[en][spacing=packed]
38
39 \starttext
40 \Lwc/ can remove most widows and orphans from a document, \emph{without} stretching any glue or shortening any pages.
41
42 It does so by automatically lengthening a paragraph on a page where a widow or orphan would otherwise occur. While \TeX{} breaks paragraphs into their natural length, \lwc/ is breaking the paragraph 1~line longer than its natural length. \TeX{}'s paragraph is output to the page, but \lwc/'s paragraph is just stored for later. When a widow or orphan occurs, \lwc/ can take over. It selects the previously-saved paragraph with the least badness; then, it replaces \TeX{}'s paragraph with its saved paragraph. This increases the text block height of the page by 1~line.
43
44 Now, the last line of the current page can be pushed to the top of the next page. This removes the widow or the orphan without creating any additional work.
45 \stoptext
46 \stopbuffer
47 \savebuffer[list=demo-text]
48
49 \startbuffer[shorten]
50 \parskip=0pt
51 \input lwc-manual-demo-text.tmp
52 \stopbuffer
53
54 \startbuffer[shorten-code]
55 \parskip=0pt
56
57 \clubpenalty=10000
58 \widowpenalty=10000
59 \stopbuffer
60
61 \startbuffer[stretch]
62 \parskip=0pt plus 1fill
63 \input lwc-manual-demo-text.tmp
64 \stopbuffer
65
66 \startbuffer[stretch-code]
67 \parskip=0pt plus 1fill
68
69 \clubpenalty=10000
70 \widowpenalty=10000
71 \stopbuffer
72
73 \startbuffer[ignore]
74 \startsetups[*default]
75 \clubpenalty=0
76 \widowpenalty=0
77 \displaywidowpenalty=0
78 \interlinepenalty=0
79 \brokenpenalty=0
80 \stopsetups
81
82 \setups[*default]
83
84 \input lwc-manual-demo-text.tmp
85 \stopbuffer
86
87 \startbuffer[ignore-code]
88 \parskip=0pt
89
90 \clubpenalty=0
91 \widowpenalty=0
92 \stopbuffer
93
94 \startbuffer[lwc]
95 \usemodule[lua-widow-control]
96 \input lwc-manual-demo-text.tmp
97 \stopbuffer
98
99 \startbuffer[lwc-code]
100 \usepackage{lua-widow-control}
101 \stopbuffer
102
103 \startbuffer[widow-orphan]
104 % TODO This is all really quite hacky
105 \define[1]\rulewords{\dorecurse{#1}{\blackrule[height=1.5ex, width=1em] \blackrule[height=1.5ex, width=2em] \blackrule[height=1.5ex, width=1.5em] \blackrule[height=1.5ex, width=3em] }}
106
107 \define[2]\fakestart{\framed[width=broad, align=normal, frame=off]{\parfillskip=0pt\spaceskip=0.2em plus 1fill\hskip 5em\rulewords{#1}\blackrule[height=1.5ex, width=#2]}}
108
109 \define[2]\fakeend{\framed[width=broad, align=normal, frame=off]{\parfillskip=5em\spaceskip=0.2em plus 1fill\rulewords{#1}\blackrule[height=1.5ex, width=#2]}}
110
111 \setupTABLE[width=broad, frame=off]
112 \setupTABLE[row][1][align=middle, style=\ssbf]
113 \setupTABLE[row][2][align=low, frame=on]
114 \setupTABLE[row][3][align=high, frame=on]
115 \setupTABLE[column][2][frame=off, width=1em]
116 \startTABLE
117 \NC Widow \NC\NC Orphan \NC\NR
118 \NC\fakestart{5}{1.5em}\NC\NC\fakestart{1}{2em}\NC\NR
119 \NC\fakeend{1}{2em}\NC\NC\fakeend{5}{1.5em}\NC\NR
120 \stopTABLE
121 \stopbuffer
122
123 \startbuffer[nobreak]
124 % This is also really hacky and terrible
125 \parfillskip=0pt
126 \define\lineone{%
127 \hbox to 0.3\textwidth{\blackrule[height=1.5ex, width=1em]\hfill%
128 \blackrule[height=1.5ex, width=3em]\hfill%
129 \blackrule[height=1.5ex, width=1em]\hfill%
130 \blackrule[height=1.5ex, width=3em]\hfill%
131 \blackrule[height=1.5ex, width=1em]}%
132 }
133
134 \define\linetwo{%
135 \hbox to 0.3\textwidth{\blackrule[height=1.5ex, width=2em]\hfill%
136 \blackrule[height=1.5ex, width=1em]\hfill%
137 \blackrule[height=1.5ex, width=2.5em]\hfill%
138 \blackrule[height=1.5ex, width=1em]\hfill%
139 \blackrule[height=1.5ex, width=2.5em]}%
140 }
141
142 \define\linethree{%
143 \hbox to 0.3\textwidth{\blackrule[height=1.5ex, width=1em]\hfill%
144 \blackrule[height=1.5ex, width=3em]\hfill%
145 \blackrule[height=1.5ex, width=1em]\hfill%
146 \blackrule[height=1.5ex, width=3em]\hfill%
147 \hskip1em\relax}%
148 }
149
150 \define\heading{\bold{Heading}}
151
152 \setupTABLE[
153 width=broad,
154 topframe=off,
155 bottomframe=off,
156 leftframe=on,
157 rightframe=on,
158 height=1.2\baselineskip
159 ]
160 \setupTABLE[row][1][
161 align=middle,
162 style=\ttbf,
163 bottomframe=on,
164 leftframe=off,
165 rightframe=off
166 ]
167 \setupTABLE[row][3][bottomframe=on]
168 \setupTABLE[row][5][bottomframe=on]
169 \setupTABLE[column][2][bottomframe=off, width=1em]
170 \setupTABLE[column][4][bottomframe=off, width=1em]
171 \startTABLE
172 \NC keep \NC\NC split \NC\NC warn \NC\NR
173 \NC \NC\NC \NC\NC \heading \NC\NR
174 \NC \NC\NC \heading \NC\NC \lineone \NC\NR
175 \NC \heading \NC\NC \lineone \NC\NC \linetwo \NC\NR
176 \NC \lineone \NC\NC \linetwo \NC\NC \linethree \NC\NR
177 \stopTABLE
178 \stopbuffer