Debian Codegraph @

texmf-dist/source/luatex/lua-widow-control/lwc-zpravodaj-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 % This text has been carefully adjusted to produce a good demonstration. Be careful before modifying it.
44 \Lwc/ can remove most widows and orphans from a document, \emph{without}
45 stretching any glue or shortening any pages.
46
47 \ifx\uselooseness\undefined\else\uselooseness\fi It does so by automatically lengthening a paragraph on a page where a
48 widow or orphan would otherwise occur. While \TeX{} breaks paragraphs
49 into their natural length, \lwc/ is breaking the paragraph 1~line
50 longer than its natural length. \TeX{}'s paragraph is output to the
51 page, but \lwc/'s paragraph is just stored for later. When a widow or
52 orphan occurs, \lwc/ can take over. It selects the previously-saved
53 paragraph with the least badness; then, it replaces \TeX{}'s paragraph
54 with its saved paragraph. This increases the text block height of the
55 page by 1~line.
56
57 Now, the last line of the current page can be pushed to the top of the
58 next page. This removes the widow or the orphan without creating any
59 additional work.
60 \stoptext
61 \stoptext
62 \stopbuffer
63 \savebuffer[list=demo-text]
64
65 \startbuffer[shorten]
66 \parskip=0pt
67 \input lwc-zpravodaj-figure-demo-text.tmp
68 \stopbuffer
69
70 \startbuffer[shorten-code]
71 \parskip=0pt
72 \clubpenalty=10000
73 \widowpenalty=10000
74 \stopbuffer
75
76 \startbuffer[stretch]
77 \parskip=0pt plus 1fill
78 \input lwc-zpravodaj-figure-demo-text.tmp
79 \stopbuffer
80
81 \startbuffer[stretch-code]
82 \parskip=0pt plus 1fill
83 \clubpenalty=10000
84 \widowpenalty=10000
85 \stopbuffer
86
87 \startbuffer[ignore]
88 \startsetups[*default]
89 \clubpenalty=0
90 \widowpenalty=0
91 \displaywidowpenalty=0
92 \interlinepenalty=0
93 \brokenpenalty=0
94 \stopsetups
95
96 \setups[*default]
97
98 \input lwc-zpravodaj-figure-demo-text.tmp
99 \stopbuffer
100
101 \startbuffer[ignore-code]
102 \parskip=0pt
103 \clubpenalty=0
104 \widowpenalty=0
105 \stopbuffer
106
107 \startbuffer[lwc]
108 \def\uselooseness{\looseness=1}
109 \input lwc-zpravodaj-figure-demo-text.tmp
110 \stopbuffer
111
112 % We're pretending that we're using LaTeX for the demo since that's what
113 % 99% of users will be using.
114 \startbuffer[lwc-code]
115 \usepackage
116 {lua-widow-control}
117 \stopbuffer
118
119 \setupbodyfont[9pt]
120
121 \setupbackend[format=PDF/A-1b:2005] % Force PDF version <1.5
122
123 \startTEXpage[
124 align=normal,
125 width=492.5733pt,
126 offset=0pt,
127 ]
128 \veryraggedcenter
129 \setupTABLE[row][1][style=\bfa, align=middle, offset=0pt]
130 % \setupTABLE[row][4][toffset=2ex]
131 \setupTABLE[frame=off, distance=0em]
132 \startTABLE
133 \NC Ignore
134 \NC Shorten
135 \NC Stretch
136 \NC \sans{lua-widow-control}
137 \NC\NR
138
139 \NC \typesetbuffer[ignore][frame=on, page=1, scale=700]
140 \NC \typesetbuffer[shorten][frame=on, page=1, scale=700]
141 \NC \typesetbuffer[stretch][frame=on, page=1, scale=700]
142 \NC \typesetbuffer[lwc][frame=on, page=1, scale=700]
143 \NC\NR
144
145 \NC \clip[height=2cm]{\typesetbuffer[ignore]
146 [frame=on, page=2, scale=700]}
147 \NC \clip[height=2cm]{\typesetbuffer[shorten]
148 [frame=on, page=2, scale=700]}
149 \NC \clip[height=2cm]{\typesetbuffer[stretch]
150 [frame=on, page=2, scale=700]}
151 \NC \clip[height=2cm]{\typesetbuffer[lwc]
152 [frame=on, page=2, scale=700]}
153 \NC\NR
154
155 \NC \typebuffer[ignore-code]
156 \NC \typebuffer[shorten-code]
157 \NC \typebuffer[stretch-code]
158 \NC \typebuffer[lwc-code]
159 \NC\NR
160 \stopTABLE
161 \stopTEXpage