Debian Codegraph @

texmf-dist/source/luatex/lua-widow-control/lwc-zpravodaj.ltx

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 % This is the LaTeX source for the following article:
7 % @article{zpravodaj-lwc,
8 % title={Automatically Removing Widows and Orphans with
9 % \textsf{lua-widow-control}},
10 % author={Chernoff, Max},
11 % journal={Zpravodaj Československého sdružení uživatelů TeXu},
12 % number={1--4},
13 % pages={49--76},
14 % year={2022},
15 % month=nov,
16 % DOI={10.5300/2022-1-4/49},
17 % }
18 % Please refer to the PDF on cstug.cz for the authoritative version.
19
20 % Compiling:
21 % context lwc-zpravodaj-figure.ctx
22 % lualatex lwc-zpravodaj.ltx
23 % biber lwc-zpravodaj
24 % lualatex lwc-zpravodaj.ltx
25 % lualatex lwc-zpravodaj.ltx
26
27 \RequirePackage{luatex85}
28 \PassOptionsToPackage{main=english}{babel}
29 \PassOptionsToPackage{shorthands=off}{babel}
30
31 \makeatletter
32 \disable@package@load{fontenc}
33 \makeatother
34
35 \let\oldlooseness=\looseness
36
37 \documentclass{csbulletin}
38
39 % Load lwc
40 \usepackage[balanced, draftoffset=\oddsidemargin + 1in + 10pt]{lua-widow-control}
41
42 % Table Stuff
43 \usepackage{tabularx}
44 \usepackage{longtable}
45 \usepackage{hhline}
46 \usepackage{booktabs}
47 \usepackage{graphicx}
48 \AddToHook{env/tabularx/before}{\nobreak\smallskip\noindent}
49 \AddToHook{env/tabularx/after}{\smallskip\pagebreak[1]}
50 \AddToHook{env/tabular/before}{\nobreak\smallskip\noindent}
51 \AddToHook{env/tabular/after}{\smallskip\pagebreak[1]}
52 \AddToHook{env/longtable/before}{\nobreak\smallskip\noindent}
53 \AddToHook{env/longtable/after}{\smallskip\pagebreak[1]}
54 \setlength{\LTleft}{0pt}
55 \renewcommand{\arraystretch}{1.15}
56
57 % For the sideways figure
58 \usepackage{rotating}
59
60 % Rotate the sideways figure in the PDF viewer too
61 \AddToHook{env/sidewaysfigure/end}{%
62 \latelua{pdf.setpageattributes('/Rotate 90')}%
63 \AddToHookNext{shipout/after}{%
64 \AddToHookNext{shipout/after}{%
65 \directlua{pdf.setpageattributes('/Rotate 0')}%
66 }%
67 }%
68 }%
69 % Let the macro names in section headings be in boldface
70 \usepackage{lmodern}
71 \AtBeginDocument{\def\cs#1{\texttt{\textbackslash#1}}}
72
73 \directlua{
74 local percent = string.char(37)
75 luatexbase.add_to_callback("process_input_buffer", function(line) return line:gsub(percent .. "-" .. percent .. "-" ..percent .. "-", "\\kern0.1em---\\kern0.1em") end, "emdash")
76 } % Add a little more kerning to em-dashes
77
78 \makeatletter
79 \DeclareRobustCommand{\eTeX}{%
80 \ifx\f@series\bfseries@rm%
81 \ensuremath{\boldsymbol{\varepsilon}}\mbox{-}\kern-.125em\TeX%
82 \else%
83 \ensuremath{\varepsilon}\mbox{-}\kern-.125em\TeX%
84 \fi%
85 }
86 \let\goodeTeX=\eTeX
87 \makeatother
88
89 % Other commands
90 \usepackage{hologo}
91 \def\ConTeXt{\Hologo{ConTeXt}}
92
93 \usepackage{mathtools}
94
95 % Abbreviations Most of these are just typewriter commands with `\allowbreak`s
96 % added.
97 \def\lwc/{\textsf{lua-\allowbreak widow-\allowbreak control}}
98 \def\Lwc/{\textsf{lua-\allowbreak widow-\allowbreak control}}
99 \def\estretch/{%
100 \texorpdfstring{\cs{emergency}\-\mbox{\ttfamily stretch}}{\textbackslash{}emergencystretch}%
101 }
102 \def\openalty/{\cs{output}\-\mbox{\ttfamily penalty}}
103 \def\waos/{widows and orphans}
104 \def\wao/{widow and orphan}
105 \def\woo/{widow or orphan}
106 \def\woos/{widows or orphans}
107 \def\latexuse/{%
108 \cs{use\-package\{lua-\allowbreak widow-\allowbreak control\}}
109 }
110 \def\lsness/{\texorpdfstring{%
111 \cs{loose}\-\mbox{\ttfamily ness}}{\textbackslash{}looseness}%
112 }
113 \def\plainop/{Plain~\TeX\slash\OpTeX{}}
114 \newcommand{\LuaMeta}{Lua\-Meta\-}
115 \newcommand{\q}[1]{\texorpdfstring{``#1''}{“#1”}}
116
117 \def\inlineurl[#1]#2{\href{https://#1}{#2}\footnote{\raggedright\href{https://#1}{\ttfamily #1}}}
118
119 \def\longs/{\char"017F}
120 \def\endofline#1{\unskip\nobreak\hskip\fontdimen2\font plus 1fill\hbox{#1}}
121
122 % TUGboat compatibility
123 \def\tubsentencespace{\spacefactor=3000{}\space\ignorespaces}
124 \DeclareRobustCommand\OpTeX{Op\kern-.05em\TeX}
125 \DeclareRobustCommand\acro[1]{\textsc{\MakeLowercase{#1}}}
126 \DeclareRobustCommand\meta[1]{%
127 \ensuremath{\langle}%
128 \ifmmode \expandafter\mbox \fi%
129 {\it #1\/}%
130 \ensuremath{\rangle}%
131 }
132
133 % Bibliography
134 \usepackage[
135 backend=biber,
136 style=iso-authoryear,
137 sortlocale=en,
138 autolang=other,
139 bibencoding=UTF8,
140 mincitenames=2,
141 maxcitenames=2,
142 ]{biblatex}
143
144 % Remove the "also" from "available also from"
145 \DefineBibliographyStrings{english}{
146 urlalso = {available from},
147 }
148
149 \protected\def\titlecite#1{\citetitle{#1}~\cite{#1}}
150
151 \let\cite=\parencite
152
153 \addbibresource{lwc-zpravodaj.bib}
154 \addbibresource{tugboat.bib}
155
156 % Figures
157 \makeatletter
158 \renewcommand*{\fps@figure}{tb}
159 \renewcommand*{\fps@table}{tb}
160 \g@addto@macro\@floatboxreset\centering
161 \makeatother
162
163 % pgfplots
164 \usepackage{pgfplots}
165 \usepackage{pgfplotstable}
166 \usetikzlibrary{patterns}
167
168 \pgfkeys{
169 /pgf/number format/.cd,
170 sci generic={%
171 mantissa sep={\times},
172 exponent={10^{##1}}
173 },
174 1000 sep={\,},
175 }
176
177 \pgfplotsset{
178 compat=1.18,
179 lua backend=true,
180 unbounded coords=discard,
181 filter discard warning=false,
182 }
183
184
185 \pgfplotstableread{tb133chernoff-widows-plot.dat}{\plotdata}
186
187 % Final adjustments
188 \def\spoj{\discretionary{-}{-}{-}}
189
190 \makeatletter
191 \csbul@start@page {49}
192 \def\doi{10.5300/2022-1-4/\thepage}
193 \csbul@webtrue
194 \csbul@colortrue
195 \makeatother
196
197 % Hyperlinks
198 \usepackage[hidelinks, bookmarks=true]{hyperref}
199 \setcounter{secnumdepth}{5}
200
201 \begin{document}
202 \title{Automatically Removing Widows and Orphans\\ with \lwc/}
203 \EnglishTitle{Automatically Removing Widows and Orphans\\ with \lwc/}
204 \author{Max Chernoff}
205 \podpis{Max Chernoff, mseven at telus dot net}
206
207 \maketitle
208
209 \begin{abstract}
210 The \textsf{lua-widow-control} package, for
211 plain~Lua\TeX\slash{}Lua\LaTeX\slash{}\ConTeXt\slash{}\OpTeX{},
212 removes widows and orphans without any user intervention.
213 Using the power of Lua\TeX{}, it does so without stretching any vertical glue
214 or shortening any pages or columns. Instead, \textsf{lua-widow-control}
215 automatically lengthens a paragraph on a page or column where a widow or
216 orphan would otherwise occur.
217
218 To use the \textsf{lua-widow-control} package, all that most \LaTeX{} users
219 need do is place \verb|\usepackage{lua-widow-control}| in their preamble.
220 No further changes are required.
221 \end{abstract}
222 \keywords: Lua\TeX{}, widows, orphans
223
224 \hypersetup{bookmarksdepth=10}
225 \section{Motivation}
226
227 {\let\thefootnote\relax\footnotetext{First published in \textsl{TUGboat} \textbf{43}:1 \cite{tb133chernoff-widows}, pp.~28--39. Reprinted, with additions and corrections, with permission.}}
228
229 \TeX{} provides top-notch typesetting: even 40 years after its first
230 release, no other program produces higher quality mathematical
231 typesetting, and its paragraph\spoj breaking algorithm is still
232 state-of-the-art. However, its page breaking is not quite as sophisticated
233 as its paragraph breaking and thus suffers from some minor issues.
234 \oldlooseness=-1
235
236 Unmodified \TeX{} has only two familiar ways of dealing with \waos/: it can
237 either shorten a page by one line, or it can stretch vertical
238 whitespace. \TeX{} was designed for mathematical and scientific typesetting,
239 where a typical page has multiple section headings, tables, figures, and
240 equations. For this style of document, \TeX's default behaviour works quite
241 well, since the slight stretching of whitespace between the various document
242 elements is nearly imperceptible; however, for prose or other documents
243 composed almost entirely of paragraphs, there is little vertical whitespace
244 to stretch.
245
246 Since no ready-made, fully-automated solution to remove
247 \waos/ from all types of documents was available, I decided to
248 create \lwc/.
249 \oldlooseness=-1
250
251 \section{What are \waos/?}
252
253 \subsection{Widows}
254
255 A \q{widow} occurs when the majority of a paragraph is on one page
256 or column,
257 but the last line is on the following page or column. It not only looks
258 quite odd for a lone line to be at the start of the page, but it makes a
259 paragraph harder to read since the separation of a paragraph and
260 its last line disconnects the two, causing the reader to lose context for
261 the widowed line.
262
263 \subsection{Orphans}
264
265 An \q{orphan} occurs when the first line of a paragraph is at the end
266 of the page or column preceding the remainder of the paragraph. They are not
267 as distracting for the reader, but they are still not ideal.
268 Visually, \waos/ are about equally disruptive; however, orphans tend not to
269 decrease the legibility of a text as much as widows, so many authors choose
270 to ignore them.
271
272 See Figure~\ref{tab:widow} for a visual reference.
273
274 \begin{figure}
275 \def\firstpage#1{%
276 \parfillskip=0pt\relax
277 \spaceskip=0.2em plus 1fill\relax
278 \hskip 3em\relax
279 #1%
280 }
281
282 \def\lastpage#1{%
283 \parfillskip=3em plus 1fill\relax
284 \spaceskip=0.2em plus 1fil\relax
285 #1%
286 }
287
288 \renewcommand{\arraystretch}{1}
289 \renewcommand{\doublerulesep}{0.5em}
290 \begin{tabularx}{\linewidth}{|X|@{\hskip\doublerulesep}|X|}
291 \multicolumn1c{\bfseries Widow} &
292 \multicolumn1c{\bfseries Orphan}
293 \\\hhline{-||-}%
294 \firstpage{A widow is when a paragraph's last line is
295 placed on a different page}%
296 &\vskip4pt\leavevmode\firstpage{An orphan is when the first}%
297 \\ \hhline{-||-}
298 \lastpage{than where it begins.}
299 & \lastpage{line of a paragraph occurs on the
300 page before all the other lines.} \\ \hhline{-||-}
301 \end{tabularx}
302 \caption{The difference between \waos/. If we imagine that each box is a
303 different page, then this roughly simulates how \waos/ appear.\oldlooseness=-1}
304 \label{tab:widow}
305 \end{figure}
306
307 \subsection{Broken hyphens}
308
309 \q{Broken} hyphens occur whenever a page break occurs in a
310 hyphenated word. These are not related to \waos/; however,
311 breaking a word across two pages is at least as disruptive for the reader
312 as \waos/. \TeX{} identifies broken hyphens in the same ways as \waos/, so
313 \lwc/ treats broken hyphens in the same way.
314
315 \section{History and etymology}
316
317 The concept of \waos/ is nearly as old as printing itself. In \titlecite{old},
318 a printers manual from 1683, we have:
319 \begin{quote}
320 Nor do good \emph{Compo\longs/iters} account it good Workman\longs/hip
321 to begin a \emph{Page} with a \emph{Break-line}, unle\longs/s it be a
322 very \longs/hort \emph{Break}, and cannot be gotten in the foregoing
323 \emph{Page}\,; but if it be a long \emph{Break}, he will let it be the
324 \emph{Direction-line} of the fore-going \emph{Page}, and \emph{Set} his
325 \emph{Direction} at the end of it. \endofline{(p.~226)}
326 \end{quote}
327 However, the terms \q{widow} and \q{orphan} are much newer.
328
329 \subsection{Widows}
330
331 The earliest published source that I could find referencing \q{widows} in
332 typography is \textsl{Webster's New International Dictionary} from~1934.
333 However, no one---not even the editors of the
334 dictionary~\cite{widowhistory}---seems to know how it got there. Even then,
335 the definition is somewhat different than it is now:
336 \begin{quote}
337 widow, n.~c.~\emph{Print}\@. A short line or single word carried over
338 from the foot of one column or page to the head of a succeeding column
339 or page.
340 \endofline{\cite{widowhistory}}
341 \end{quote}
342 Contrast this with the modern definition:
343 \begin{quote}
344 The stub-ends left when paragraphs end on the first line of a page are called
345 widows. They have a past but not a future, and they look foreshortened and forlorn.
346 \endofline{\cite{elements}}
347 \end{quote}
348 which includes a single lone line of any length.
349
350 \subsection{Orphans}
351
352 The term \q{orphan} is even more confusing. Its initial usage seems to have
353 occurred some time after \q{widow}~\cite{widowhistory}, and it is given many
354 contradictory definitions. Most sources define an orphan as a first line at
355 the bottom of the page and a widow as the last line at the
356 top~\cite{elements, widowhistory, widowhistory2, Isambert:TB31-1-12,
357 texbook, widows-and-orphans, oed-line, oed-widow}; however, some sources
358 define these two terms as \emph{exact opposites} of each other, with a widow
359 as a first line at the bottom of the page and an orphan as the last
360 line!~\cite{backwards1, widowhistory, backwards3, oed-line,
361 backwards2}\tubsentencespace
362 This usage is plain wrong; nevertheless, it is sufficiently common that you
363 need to be careful when you see the terms \q{widow} and \q{orphan}.
364
365 Similarly to the term \q{widow}, \titlecite{elements} provides a succinct
366 definition of the term \q{club}, along with a helpful mnemonic:
367 \begin{quote}
368 Isolated lines created when paragraphs begin on the last line of a page
369 are known as orphans. They have no past, but they do have a future.
370 \endofline{\cite{elements}}
371 \end{quote}
372
373 \subsection{Clubs}
374
375 \textsl{The \TeX{}book} never refers to \q{orphans} as such; rather, it
376 refers to them as \q{clubs}. This term is remarkably rare: I could only find
377 a \emph{single} source published before \textsl{The \TeX{}book}---a
378 compilation article about the definition of \q{widow}---that mentions
379 a \q{club line}:
380 \begin{quotation}
381 \noindent
382 The Dictionary staff informs me that they have no example of the use of
383 the word widow in the typographical sense.~[\dots]
384
385 Mr.~Watson of the technical staff says that
386 the Edinburgh printing houses referred to it as a \q{clubline}.
387 \endofline{\cite[p.~4]{widowhistory}}
388 \end{quotation}\medskip
389 \begin{quotation}
390 \noindent
391 To my knowledge, a `widow', or `widow-line,' is a short line, forming
392 the end of a paragraph, which is carried over from the foot of a page or
393 column to the top of the succeeding one.~[\dots]
394
395 To my personal knowledge, in typographical parlance in Edinburgh,
396 Scotland, the `widow' is called a `club-line.'
397 \endofline{\cite[p.~23]{widowhistory}}
398 \end{quotation}
399
400 Both quotes above are from separate authors, and they each define a \q{club}
401 like we define \q{widow}, not an \q{orphan}. In addition, they both mention
402 that the term is only used in Scotland. Even the extensive
403 \acro{OED}---which lists 17~full definitions and
404 103~subdefinitions for the noun \q{club}---doesn't recognize the
405 phrase.~\cite{oed-club}
406
407 I spent a few hours searching through Google Books and my university library
408 catalogue, but I could not find a single additional source. However, Don
409 Knuth---the creator of \TeX{}---read the original article
410 \cite{tb133chernoff-widows} and sent me this reply:
411 \oldlooseness=-1
412
413 \begin{quote}
414 I cannot remember where I found the term \q{club line}. Evidently
415 the books that I scoured in 1977 and 1978 had taught me only that an
416 isolated line, caused by breaking between pages in the midst of a
417 paragraph, was called a \q{widow}; hence \TeX78 had only
418 \q{\cs{chpar4}} to
419 change the \q{\texttt{widowpenalty}}. Sometime between then and \TeX82
420 I must
421 have come across what appeared to be an authoritative source that
422 distinguished between widows at the beginning of a paragraph and
423 orphans or club lines at the end. I may have felt that the term
424 \q{orphan} was somewhat pejorative, who knows?\footnotemark
425 \end{quote}
426
427 \footnotetext{
428 Note that this definition is somewhat mistaken. Widows are located
429 either at the \emph{end} of a paragraph, or the beginning of a
430 \emph{page or column}. Likewise, orphans\slash{}clubs appear at the
431 \emph{beginning} of a paragraph or at the end of a \emph{page or column}.
432 }
433
434 \noindent
435 So this (somewhat) resolves the question of where the term \q{club} came
436 from.
437
438 \section{Pagination in \TeX}
439
440 Let's move on to looking at how \TeX{} treats these \waos/.
441
442 \subsection{Algorithm}
443
444 It is tricky to understand how \lwc/ works if you aren't familiar with how
445 \TeX{} breaks pages and columns. For a full description, you should consult
446 Chapter~15 of~\titlecite{texbook} (\q{How \TeX{} Makes
447 Lines into Pages}); however, this goes into much more detail than most users
448 require, so here is a \emph{very} simplified summary of \TeX{}'s page
449 breaking algorithm:
450
451 \TeX{} fills the page with lines and other objects until the next object
452 will no longer fit. Once no more objects will fit, \TeX{} will align the
453 bottom of the last line with the bottom of the page by stretching any
454 available vertical spaces if (in \LaTeX) \cs{flushbottom} is set;
455 otherwise, it will
456 break the page and leave the bottom empty.
457
458 However, some objects have penalties attached. Penalties encourage or
459 discourage page breaks from occurring at specific places. For example,
460 \LaTeX{} sets a negative penalty before section headings to encourage a
461 page break there; conversely, it sets a positive penalty after section
462 headings to discourage breaking.
463
464 To reduce \waos/, \TeX{} sets weakly-positive penalties between the
465 first and second lines of a paragraph to prevent orphans, and between the
466 penultimate and final lines to prevent widows.
467
468 One important note: once \TeX{} begins breaking a page, it never goes
469 back to modify any content on the page. Page breaking is a localized
470 algorithm, without any backtracking.
471
472 \subsection{Behaviour}
473
474 Merely describing the algorithm doesn't allow us to intuitively
475 understand how
476 \TeX{} deals with \waos/.
477
478 Due to the penalties attached to \waos/, \TeX{} tries to avoid
479 them. Widows and orphans with small penalties attached---like
480 \LaTeX's default values of 150---are only lightly coupled to the rest
481 of the paragraph, while \waos/ with large penalties---values of
482 10\,000 or more---are treated as infinitely bad and are thus
483 unbreakable. Intermediate values behave just as you would expect,
484 discouraging page breaks proportional to their value.
485
486 When \TeX{} goes to break a page, it tries to avoid breaking at a
487 location with a high penalty. How it does so depends on a few settings:
488
489 \subsubsection{\cs{flushbottom} and \cs{normalbottom}}
490
491 With the settings \cs{normalbottom} (Plain \TeX{}) or \cs{flushbottom}
492 (\LaTeX{}), \TeX{} is willing to stretch any glue on the page by an amount
493 roughly commensurate to the magnitude of the penalty: for small
494 \cs{clubpenalty} and \cs{widowpenalty} values, \TeX{} will only slightly
495 stretch the glue on the page before creating a \woo/; for very large
496 penalties, \TeX{} will stretch the glue by a near-infinite amount.
497 \oldlooseness=-1
498
499 This corresponds to the \q{Stretch} column in
500 Figure~\ref{fig:demo}. It is
501 the default behaviour of Plain~\TeX{}, and of the standard \LaTeX{} classes
502 when the \verb|twocolumn| option is given.
503
504 \subsubsection{\cs{raggedbottom}}
505
506 When \cs{raggedbottom} is set, \TeX{} won't stretch any glue. Instead, for
507 sufficiently high \cs{clubpenalty} and
508 \cs{widowpenalty} values, \TeX{} will shorten the page or column by
509 one~line in order to prevent the \woo/ from being created.
510
511 This corresponds to the \q{Shorten} column in Figure~\ref{fig:demo} and is
512 the default behaviour of the \LaTeX{} classes when the
513 \verb|twocolumn| option is not given.
514
515 \section{\lsness/}\label{sec:looseness} Before we can continue further, we
516 need to discuss one more \TeX{} command: \lsness/. The following is
517 excerpted from Chapter~14 of~\titlecite{texbook} (\q{How \TeX{} Breaks
518 Paragraphs into Lines}):
519
520 \begin{quotation}
521 \noindent
522 If you set \lsness/\verb|=1|, \TeX{} will try to make the current
523 paragraph one line longer than its optimum length, provided that
524 there is a way to choose such breakpoints without exceeding the
525 tolerance you have specified for the badnesses of individual lines.
526 Similarly, if you set \lsness/\verb|=2|, \TeX{} will try to make the
527 paragraph two lines longer; and \lsness/\verb|=-1| causes an attempt
528 to make it shorter.~[\dots]
529
530 For example, you can set \lsness/\verb|=1| if you want to avoid a
531 lonely \q{club line} or \q{widow line} on some page that does not
532 have sufficiently flexible glue, or if you want the total number of
533 lines in some two-column document to come out to be an even number.
534
535 It's usually best to choose a paragraph that is already pretty
536 \q{full}, i.e., one whose last line doesn't have much white space,
537 since such paragraphs can generally be loosened without much harm.
538 You might also want to insert a tie between the last two words of
539 that paragraph, so that the loosened version will not end with only
540 one \q{widow word} on the orphans line; this tie will cover your
541 tracks, so that people will find it hard to detect the fact that you
542 have tampered with the spacing. On the other hand, \TeX{} can take
543 almost any sufficiently long paragraph and stretch it a bit, without
544 substantial~harm.
545 \oldlooseness=1
546 \end{quotation}
547
548 The \wao/ removal strategy suggested in the second paragraph works quite
549 well; however, it requires manual editing each and every time a page
550 or paragraph is rewritten or repositioned.
551
552 \begin{sidewaysfigure}[p!]
553 \includegraphics{lwc-zpravodaj-figure}
554 \caption{A visual comparison of various automated widow-handling
555 techniques.
556 }\label{fig:demo}
557 \end{sidewaysfigure}
558
559 \section{Alternate removal strategies}
560
561 There have been a few previous attempts to improve upon \TeX's
562 previously discussed \wao/-handling abilities; however, none of these
563 have been able to automatically remove \waos/ without stretching any vertical glue
564 or shortening any pages.
565
566 The articles \titlecite{Isambert:TB31-1-12} and \titlecite{mittelbach} both
567 begin with comprehensive discussions of the methods of preventing \waos/.
568 They agree that \waos/ are bad and ought to be avoided; however, they
569 differ in their solutions. \textsl{Strategies}~proposes an output routine
570 that reduces the length of facing pages by one line when necessary to
571 remove \waos/, while \textsl{Managing}~proposes that the author manually
572 rewrites or adjusts \lsness/ when needed.
573
574 The post \titlecite{widow-assist} contains a file
575 \verb|widow-assist.lua| that
576 automatically detects which paragraphs can be safely shortened or
577 lengthened by one line. The \textsf{widows-and-orphans}
578 package~\cite{widows-and-orphans} alerts the author to
579 the pages that contain widows or orphans. Combined, these packages make
580 it simple for the author to quickly remove \waos/ by adjusting the
581 values of \lsness/; however, it still requires the author to make manual
582 source changes after each revision.
583
584 Another article suggests a fully-automated solution to remove
585 \waos/~\cite{global}. This would seem to offer a complete solution; however,
586 it requires multiple passes, an external tool, and has not yet been publicly
587 released.
588
589 \Lwc/ is essentially a combination of
590 \verb|widow-assist.lua|~\cite{widow-assist} and
591 \textsf{widows-and-orphans}~\cite{widows-and-orphans}, although its
592 implementation is independent of both: when the \openalty/
593 value indicates
594 that a \woo/ has occurred, Lua is used to find a stretchable paragraph. What
595 \lwc/ mainly adds on top of these packages is automation: it eliminates the
596 requirement for any manual adjustments or changes to your document's
597 source.
598
599 \section{Visual comparison}
600
601 Although \TeX{}'s page breaking algorithm is reasonably
602 straightforward, it can lead to
603 complex behaviour when \waos/ are involved. The usual
604 choices, when rewriting is not possible, are to ignore them,
605 stretch some glue, or shorten the
606 page. Figure~\ref{fig:demo} has a visual comparison of these
607 options, which we'll discuss in the following:
608
609 \subsection{Ignore}
610
611 As you can see, the last line of the page is on a separate page from the
612 rest of its paragraph, creating a widow. This is usually highly
613 distracting for the reader, so it is best avoided for the reasons previously
614 discussed.
615
616 \subsection{Shorten}
617
618 This page did not leave any widows, but it did shorten the previous page
619 by one line. Sometimes this is acceptable, but usually it looks bad because
620 pages will then have different text-block heights. This can make the pages
621 look quite uneven, especially when typesetting with columns or in a book
622 with~facing~pages.
623 \oldlooseness=1
624
625 \subsection{Stretch}
626
627 This page also has no widows and it has a flush bottom margin. However,
628 the space between each pair of paragraphs had to be stretched.
629
630 If this page had many equations, headings, and other elements with
631 natural space between them, the stretched out space would be much less
632 noticeable. \TeX{} was designed for mathematical typesetting, so it makes
633 sense that this is its default behaviour. However, in a page with mostly
634 text, these paragraph gaps look unsightly.
635
636 Also, this method is incompatible with grid typesetting, where
637 all vertical glue stretching must be quantised to the height of a line.
638
639 \subsection{\lwc/}
640
641 \Lwc/ has none of these issues: it eliminates the widows in a document
642 while keeping a flush bottom margin and constant paragraph spacing.
643
644 To do so, \lwc/ lengthened the second paragraph in Figure~\ref{fig:demo} by
645 one line. If you look closely, you can see that this stretched the
646 interword spaces. This stretching is noticeable when typesetting in a
647 narrow text block, but is mostly imperceptible with larger widths.
648
649 \Lwc/ automatically finds the \q{best} paragraph to stretch, so the
650 increase in interword spaces should almost always be minimal.
651
652 \section{Installation and standard usage}
653
654 The \lwc/ package was first released in
655 October~2021. It is available in the default installations of both
656 MiK\TeX{} and \TeX{}~Live, although you will need recent versions
657 of either.
658
659 You may also download \lwc/ manually from either
660 \inlineurl[ctan.org/pkg/lua-widow-control]{\acro{CTAN},}
661 the \inlineurl%
662 [modules.contextgarden.net/cgi-bin/module.cgi/action=view/id=127]%
663 {\ConTeXt{} Garden,} or \inlineurl%
664 [github.com/gucci-on-fleek/lua-widow-control/releases/latest/]%
665 {GitHub,} although it is best if you can install it through your
666 \TeX~distribution.
667
668 As its name may suggest, \lwc/ \textit{requires} Lua\TeX{} or
669 \LuaMeta\TeX{} regardless of the format used.
670 With that in mind, using \lwc/ is quite simple:
671
672 \begin{tabular}{rl}
673 Plain \TeX{} &
674 \cs{input lua-widow-control}\phantom{\tt]} \\
675 \OpTeX {} &
676 \cs{load[lua-widow-control]} \\
677 \LaTeX{} &
678 \latexuse/ \\
679 \ConTeXt{} &
680 \cs{usemodule[lua-widow-control]} \\
681 \end{tabular}
682
683 And that's usually enough. Most users won't need to do anything else since
684 \lwc/ comes preconfigured and ready-to-go.
685
686 \section{Options}
687
688 Nevertheless, \lwc/ does have a few options.
689
690 \Lwc/ tries very hard to have a \q{natural} user interface with each
691 format, so how you set an option heavily depends on how you are running
692 \lwc/. Also note that not every option is available in every format.
693
694 Some general guidelines:
695
696 \begin{tabularx}\linewidth{rX}
697 \plainop/ & Specially-named \cs{lwc}\meta{option} commands and
698 registers are provided for all options. \\[4pt]
699 \LaTeX{} & Options can be set either as package options or at
700 any point in the document with \cs{lwcsetup}. \\[4pt]
701 \ConTeXt{} & Always use \cs{setuplwc}.
702 \end{tabularx}
703
704 \subsection{Disabling}
705
706 You may want to disable \lwc/ for certain portions of your
707 document. You can do so with the following commands:
708
709 \begin{tabular}{rl}
710 \plainop/ &
711 \cs{lwcdisable} \\
712 \LaTeX{} &
713 \cs{lwcsetup\{disable\}} \\
714 \ConTeXt{} &
715 \cs{setuplwc[state=stop]}\hphantom{\texttt{a}} \\
716 \end{tabular}
717
718 This prevents \lwc/ from stretching any paragraphs that follow. If a page
719 has earlier paragraphs where \lwc/ was still enabled and a \woo/ is
720 detected, \lwc/ will still attempt to remove the \woo/.
721
722 \subsection{Enabling}
723
724 \Lwc/ is enabled as soon as the package is loaded. If you have previously
725 disabled it, you will need to re-enable it to save new paragraphs.
726
727 \begin{tabular}{rl}
728 \plainop/ &
729 \cs{lwcenable} \\
730 \LaTeX{} &
731 \cs{lwcsetup\{enable\}} \\
732 \ConTeXt{} &
733 \cs{setuplwc[state=start]} \\
734 \end{tabular}
735
736 \subsection{Automatically disabling}
737
738 You may want to disable \lwc/ for certain commands where
739 stretching is undesirable such as section headings. Of course, manually
740 disabling and
741 then enabling \lwc/ multiple times
742 throughout a document would quickly become tedious, so \lwc/ provides
743 some options to do this automatically for you.
744
745 \Lwc/ automatically patches the default \LaTeX{}, \ConTeXt{},
746 Plain \TeX{}, \OpTeX{}, \textsf{\mbox{memoir}},
747 \textsf{KOMA-Script}, and \textsf{titlesec} section commands, so you don't
748 need to patch these. Any others, though, you'll need to patch yourself.
749
750 \begin{tabular}{rl}
751 \plainop/ & \cs{lwcdisablecmd\{\meta{\texttt{\char`\\}macro}\}} \\[4pt]
752 \LaTeX{} & \cs{lwcsetup\{disablecmds=\{\texttt{\meta{csnameone},%
753 \meta{csnametwo}\}\}}} \\[4pt]
754 \ConTeXt{} &
755 \cs{prependtoks\textbackslash{}lwc@patch@pre}\cs{to\textbackslash{}everybefore\meta{hook}} \\
756 & \cs{prependtoks\textbackslash{}lwc@patch@post}\cs{to\textbackslash{}everyafter\meta{hook}} \\
757 \end{tabular}
758
759 \subsection{\estretch/}
760
761 \Lwc/ defaults to an \estretch/ value of 3~em for stretched paragraphs,
762 but you can configure this.
763
764 \Lwc/ will only use the \estretch/ when it cannot extend a paragraph in
765 any other way, so it is fairly safe to set this to a large value. \TeX{}
766 accumulates badness when \estretch/ is used~\cite{Knuth:TB10-3-325}, so
767 it's pretty rare that a paragraph that requires any \estretch/ will
768 actually be used on the page.
769
770 \begin{tabular}{rr@=l}
771 \plainop/ & \cs{lwcemergencystretch} & \meta{dimension} \\
772 \LaTeX{} &
773 \cs{lwcsetup\{emergencystretch} & \meta{dimension}\texttt{\}} \\
774 \ConTeXt{} &
775 \cs{setuplwc[emergencystretch} & \meta{dimension}\texttt{]} \\
776 \end{tabular}
777
778 \subsection{Penalties}
779
780 You can also manually adjust the penalties that \TeX{} assigns to \waos/.
781 Usually, the defaults are fine, but there are a few circumstances where you
782 may want to change them.
783
784 \begin{longtable}{rr@{\texttt{=\meta{integer}}}l}
785 \plainop/ & \cs{widowpenalty} \\*
786 & \cs{clubpenalty} \\*
787 & \cs{brokenpenalty} \\[4pt]
788 \LaTeX{} &
789 \cs{lwcsetup\{ widowpenalty} & \texttt{\}} \\*
790 & \cs{lwcsetup\{orphanpenalty} & \texttt{\}} \\*
791 & \cs{lwcsetup\{brokenpenalty} & \texttt{\}} \\[4pt]
792 \leavevmode\hbox{\ConTeXt{}} &
793 \cs{setuplwc[ widowpenalty} & \texttt{]} \\*
794 & \cs{setuplwc[orphanpenalty} & \texttt{]} \\*
795 & \cs{setuplwc[brokenpenalty} & \texttt{]} \\
796 \end{longtable}
797
798 The value of these penalties determines how much \TeX{} should attempt to
799 stretch glue before passing the \woo/ to \lwc/. If you set the values to~1
800 (default), \TeX{} will stretch nothing and immediately trigger \lwc/; if you
801 set the values to 10\,000, \TeX{} will stretch infinitely and \lwc/ will
802 never be triggered. If you set the value to some intermediate number, \TeX{}
803 will first attempt to stretch some glue to remove the \woo/; only if it
804 fails will \lwc/ come in and lengthen a paragraph. As a special case, if you
805 set the values to~0, both \TeX{} and \lwc/ will completely ignore the \woo/.
806
807 \Lwc/ will pick up on the values of \cs{widowpenalty}, \cs{clubpenalty}, and
808 \cs{brokenpenalty} regardless of how you set them, so the use of these
809 dedicated keys is entirely optional.
810
811 \subsection{\cs{nobreak} behaviour}
812
813 When \lwc/ encounters an orphan, it removes it by moving the orphaned line
814 to the next page. The majority of the time, this is an appropriate solution.
815 However, if the orphan is immediately preceded by a section heading (or
816 \cs{nobreak}\slash\cs{penalty 10000}), \lwc/ would na\"ively separate a
817 section heading from the paragraph that follows. This is almost always
818 undesirable, so \lwc/ provides some options to configure this.
819
820 \begin{tabular}{rl}
821 \plainop/ &
822 \cs{lwcnobreak\{\meta{value}\}} \\
823 \LaTeX{} &
824 \cs{lwcsetup\{nobreak=\meta{value}\}\hphantom{"}} \\
825 \ConTeXt{} &
826 \cs{setuplwc[nobreak=\meta{value}]\hphantom{"}} \\
827 \end{tabular}
828
829 The default value, \texttt{keep}, \emph{keep}s the section heading with
830 the orphan by moving both to the next page. The advantage to this option
831 is that it removes the orphan and retains any \cs{nobreak}s; the
832 disadvantage is that moving the section heading can create a large blank
833 space at the end of the page.
834 The value \texttt{split} \emph{split}s up the section heading and the
835 orphan by moving the orphan to the next page while leaving the heading
836 behind. This is usually a bad idea, but exists for the sake of
837 flexibility.
838 The value \texttt{warn} causes \lwc/ to give up on the page and do nothing,
839 leaving an orphaned line. \Lwc/ \emph{warn}s the user so that they can
840 manually remove the orphan.
841
842 See Figure~\ref{tab:nobreak} for a visual reference.
843
844 \begin{figure}
845 \renewcommand{\arraystretch}{1}
846 \renewcommand{\doublerulesep}{0.5em}
847 \begin{tabularx}{\linewidth}{%
848 |X|@{\hskip\doublerulesep}|X|@{\hskip\doublerulesep}|X|%
849 }
850 \multicolumn1c{\ttfamily keep} &
851 \multicolumn1c{\ttfamily split} &
852 \multicolumn1c{\ttfamily warn}
853 \\ \hhline{-||-||-}
854 &
855 &
856 \textbf{Heading} \\
857 &
858 \textbf{Heading} &
859 The\hfill very\hfill first\hfill line
860 \\ \hhline{-||-||-}
861 \textbf{Heading} &
862 The\hfill very\hfill first\hfill line &
863 text\hfill text\hfill text\hfill text \\
864 The\hfill very\hfill first\hfill line &
865 text\hfill text\hfill text\hfill text &
866 last line. \\
867 text\hfill text\hfill text\hfill text &
868 last line. &
869 % Nothing
870 \\ \hhline{-||-||-}
871 \end{tabularx}
872 \caption{A visual comparison of the \texttt{nobreak} option values.}
873 \label{tab:nobreak}
874 \end{figure}
875
876 \subsection{Maximum cost}
877
878 \Lwc/ ranks each paragraph on the page by how much it would \q{cost} to
879 lengthen that paragraph. By default, \lwc/ selects the paragraph on
880 the page with the lowest cost; however, you can configure it to only
881 select paragraphs below a selected cost.
882
883 If there aren't any paragraphs below the set threshold, then \lwc/ won't
884 remove the \woo/ and will instead issue a warning.
885
886 \begin{tabular}{rr@{\texttt{=\meta{integer}}}l}
887 \plainop/ &
888 \cs{lwcmaxcost} \\
889 \LaTeX{} &
890 \cs{lwcsetup\{max-cost} & \texttt{\}} \\
891 \leavevmode\hbox{\ConTeXt{}} &
892 \cs{setuplwc[maxcost} & \texttt{]} \\
893 \end{tabular}
894
895 Based on my testing, \texttt{max-cost} values less than 1\,000 cause
896 completely imperceptible changes in interword spacing; values less than
897 5\,000 are only noticeable if you are specifically trying to pick out the
898 expanded paragraph on the page; values less than 15\,000 are typically
899 acceptable; and larger values may become distracting. \Lwc/ defaults to an
900 infinite \texttt{max-cost}, although the \q{strict} and \q{balanced} modes
901 sets the values to~5\,000 and 10\,000, respectively.
902
903 \subsection{Draft mode}
904
905 \Lwc/ has a \q{draft mode} which shows how \lwc/ processes pages.
906
907 \begin{tabular}{rl}
908 Plain \TeX{}\slash\OpTeX{} &
909 \cs{lwcdraft 1} \\
910 \LaTeX{} &
911 \cs{lwcsetup\{draft\}} \\
912 \ConTeXt{} &
913 \cs{setuplwc[draft=start]} \\
914 \end{tabular}
915
916 The draft mode has two main features:
917
918 First, it colours lines in the document according to their status. Any
919 remaining widows and orphans will be coloured red, any expanded paragraphs
920 will be coloured green, and any lines moved to the next page will be
921 coloured blue.
922
923 Second, this draft mode shows the paragraph costs at the end of each
924 paragraph, in the margin.
925
926 This draft mode leads to a neat trick: if you don't quite trust \lwc/, or
927 you're writing a document whose final version will need to be compilable by
928 both pdf\LaTeX{} and Lua\LaTeX, you can load the package with:
929
930 \smallskip
931 \cs{usepackage[draft, disable]\{lua-widow-control\}}
932 \smallskip
933
934 \noindent This way, all the widows and orphans will be coloured red and
935 listed in your log file. When you go through the document to try and
936 manually remove the widows and orphans---whether through the \cs{looseness}
937 trick or by rewriting certain lines---you can easily find the best
938 paragraphs to modify by looking at the paragraph costs in the margins. If
939 you're less cautious, you can compile your document with
940 \textsf{lua-widow-control} enabled as normal and inspect all the green
941 paragraphs to see if they look acceptable to you.
942
943 You can also toggle the paragraph colouring and the cost displays
944 individually:
945
946 \begin{tabular}{rl}
947 \plainop/ &
948 \cs{lwcshowcosts 1} \\
949 & \cs{lwcshowcolours 0} \\[4pt]
950 \LaTeX{} &
951 \cs{lwcsetup\{showcosts=true\}} \\
952 & \cs{lwcsetup\{showcolours=false\}} \\[4pt]
953 \ConTeXt{} &
954 \cs{setuplwc[showcosts=start]} \\
955 & \cs{setuplwc[showcolours=stop]} \\
956 \end{tabular}
957
958 \section{Presets}
959
960 As you can see, \lwc/ provides quite a few options. Luckily, there are a few
961 presets that you can use to set multiple options at once. These presets are
962 a good starting point for most documents, and you can always manually
963 override individual options.
964
965 These presets are only available for \LaTeX{} and \ConTeXt{}.
966
967 \begin{tabular}{@{}rl@{}}
968 \LaTeX{} &
969 \cs{lwcsetup\{\meta{preset}\}} \\
970 \ConTeXt{} &
971 \cs{setuplwc[\meta{preset}]} \\
972 \end{tabular}
973
974 \subsection{\texttt{default}}
975
976 If you use \lwc/ without any options, it defaults to this preset. In default
977 mode, \lwc/ takes all possible measures to remove \waos/ and will not
978 attempt to stretch any vertical glue. This usually
979 removes~$\mathord{>}\,95\%$ of all
980 possible \waos/. The catch here is that this mode is quite aggressive, so
981 it often leaves behind some fairly \q{spacey} paragraphs.
982
983 This mode is good if you want to remove (nearly) all \waos/ from your
984 document, without fine-tuning the results.
985
986 \subsection{\texttt{strict}}
987
988 \Lwc/ also offers a strict mode. This greatly restricts \lwc/'s tolerance
989 and makes it so that it will only lengthen paragraphs where the change will
990 be imperceptible.
991
992 The caveat with strict mode is that---depending on the document---\lwc/ will
993 be able to remove less than a third of the \waos/. For the \waos/ that can't
994 be automatically removed, a warning will be printed to your terminal and log
995 file so that a human can manually fix the situation.
996
997 This mode is good if you want the best possible typesetting and are willing
998 to do some manual editing.
999
1000 \subsection{\texttt{balanced}}
1001
1002 Balanced mode sits somewhere between default mode and strict mode. This mode
1003 first lets \TeX{} stretch a little glue to remove the \woo/; only if that
1004 fails will it then trigger \lwc/. Even then, the maximum paragraph cost is
1005 capped. Here, \lwc/ can usually remove 90\% of a document's
1006 potential \waos/, and it does so while making a minimal visual impact.
1007 \oldlooseness=-1
1008
1009 This mode is recommended for most users who care about their document's
1010 typography. This mode is not the default since it doesn't remove all
1011 \waos/: it
1012 still requires a little manual intervention.
1013
1014 \begin{table}
1015 \caption{\Lwc/ options set by each mode.}\label{tab:modes}
1016 \ttfamily\setlength{\tabcolsep}{4pt}
1017 \begin{tabular}{l*3r}\toprule
1018 \textrm{Option} & default & balanced & strict \\ \midrule
1019 max-cost & $\infty$ & 10000 & 5000 \\
1020 \rlap{emergencystretch} & 3em & 1em & 0pt \\
1021 nobreak & keep & keep & warn \\
1022 widowpenalty & 1 & 500 & 1 \\
1023 orphanpenalty & 1 & 500 & 1 \\
1024 brokenpenalty & 1 & 500 & 1 \\
1025 \bottomrule\end{tabular}
1026 \end{table}
1027
1028 \section{Compatibility}
1029
1030 The \lwc/ implementation is almost entirely in Lua, with only a minimal
1031 \TeX{} footprint. It doesn't modify the output routine or \cs{everypar} and
1032 it doesn't insert any whatsits. This means that it should be compatible with
1033 nearly any \TeX{} package, class, and format. Most changes that \lwc/ makes
1034 are not observable on the \TeX{} side.
1035
1036 However, on the Lua side, \lwc/ modifies much of a page's internal
1037 structure. This should not affect any \TeX{} code; however, it may surprise
1038 Lua code that modifies or depends on the page's low-level structure. This
1039 does not affect Plain~\TeX{} or \LaTeX{} where even most Lua-based packages
1040 don't depend on the node list structure. \ConTeXt{} \emph{does} depend on
1041 this internal node structure; however, I have carefully tested the package
1042 to ensure that this causes no issues.
1043
1044 Finally, keep in mind that adding \lwc/ to a document will almost certainly
1045 change its page break locations.
1046
1047 \subsection{Formats}
1048
1049 \Lwc/ runs on all known Lua\TeX{}-based formats: Plain~Lua\TeX{},
1050 Lua\LaTeX{}, \ConTeXt{} Mk\acro{IV}, and~\OpTeX{}. Unless otherwise
1051 documented, all features should work equally well in all formats.
1052
1053 \Lwc/ is also fully-compatible with the \LuaMeta\TeX{}-based formats:
1054 \ConTeXt{} Mk\acro{XL}\slash\acro{LMTX}, \LuaMeta\LaTeX{}, and
1055 \LuaMeta{}Plain~\cite{luametalatex}. \ConTeXt{} Mk\acro{XL} works equally
1056 well as \ConTeXt{} Mk\acro{IV} and Lua\LaTeX{}; however, \LuaMeta\LaTeX{}
1057 and \LuaMeta{}Plain support is still quite early. All features should work,
1058 although there are still a few minor bugs.
1059
1060 All told, \lwc/ supports 7 different format\slash{}engine combinations.
1061
1062 \subsection{Columns}
1063
1064 Since \TeX{} and the formats implement column breaking and page
1065 breaking through the
1066 same internal mechanisms, \lwc/ removes \waos/ between columns just
1067 as it does with \waos/ between pages.
1068
1069 \Lwc/ is known to work with the \LaTeX{} class option \verb|twocolumn|
1070 and the two-column output routine from Chapter~23 of \titlecite{texbook}.
1071 \oldlooseness=-1
1072
1073 \subsection{Performance}
1074
1075 \Lwc/ runs entirely in a single pass, without depending on any
1076 \verb|.aux| files or the like. Thus, it shouldn't meaningfully
1077 increase compile times. Although \lwc/ internally breaks each paragraph
1078 twice, modern computers break paragraphs near-instantaneously, so you
1079 are not likely to notice any slowdown.
1080
1081 \Lwc/ has been carefully tested to ensure that there are no memory leaks, so
1082 \lwc/ can now easily compile documents $>10\,000$ pages long.
1083
1084 \vspace*{-1pt}
1085
1086 \subsection{\eTeX{} penalties}
1087
1088 Knuth's original \TeX{} has three basic line penalties:
1089 \cs{interlinepenalty}, which
1090 is inserted between all lines; \cs{club\-penalty}, which is inserted after
1091 the first line; and \cs{widow\-penalty}, which is inserted before the last
1092 line. The \eTeX{} extensions~\cite{etex} generalize these commands with a
1093 syntax similar to \cs{parshape}: with \cs{widow\-penalties} you can set the
1094 penalty between the last, second last, and $n$th last lines of a paragraph;
1095 \cs{inter\-line\-penalties} and \cs{club\-penalties} behave similarly.
1096
1097 The \lwc/ package makes no explicit attempts to support these new
1098 -\texttt{penalties} commands. Specifically, if you give a line a penalty
1099 that matches either \cs{widowpenalty} or \cs{clubpenalty}, \lwc/ will treat
1100 the lines exactly as it would a \woo/. So while these commands won't break
1101 \lwc/, they are likely to lead to some unexpected behaviour.
1102
1103 \vspace*{-3pt}
1104
1105 \section{Short last lines}
1106
1107 \vspace*{-1pt}
1108
1109 When lengthening a paragraph with \lsness/, it is common advice to insert
1110 ties (\verb|~|) between the last few words of the paragraph to avoid
1111 overly-short last lines \cite{texbook}. \Lwc/ does this automatically,
1112 but instead of using ties or \cs{hbox}es, it uses the
1113 \cs{par\allowbreak fill\allowbreak skip}
1114 parameter~\cite{texbook, Wermuth:2018:ECP, naruby}. When lengthening a paragraph
1115 (and only when lengthening a paragraph---remember, \lwc/ doesn't
1116 interfere with \TeX{}'s output unless it detects a \woo/), \lwc/ sets
1117 \cs{parfillskip} to \verb|0.75\hsize plus 0.05\hsize minus 0.75\hsize|.
1118 This normally makes the last line of a paragraph be at least
1119 20\% of the overall paragraph's width, thus preventing
1120 ultra-short~lines.
1121
1122 \vspace*{-3pt}
1123
1124 \section{How it works}
1125
1126 \vspace*{-1pt}
1127
1128 \Lwc/ uses a fairly simple algorithm to eliminate \waos/, but there
1129 are a few subtleties.
1130
1131 \vspace*{-1pt}
1132
1133 \subsection{Setup}
1134
1135 \Lwc/ sets the \cs{club\-penalty}, \cs{widow\-penalty}, and
1136 \cs{broken\-penalty} parameters to sentinel values of~1. This will signal
1137 to \lwc/ when a \woo/ occurs, yet it is small enough that it won't stretch
1138 any glue.
1139
1140 \Lwc/ also enables Lua\TeX{}'s micro\-typographic
1141 extensions~\cite{thanh}. This isn't strictly necessary;
1142 however, it significantly increases the number of paragraphs that can
1143 be acceptably \q{loosened}.
1144
1145 That is all that happens on the \TeX{} end. The rest of \lwc/ is pure Lua.
1146
1147 \subsection{Paragraph breaking}
1148
1149 First, \lwc/ hooks into the paragraph breaking process, before any output
1150 routines or page breaking.
1151
1152 Before a paragraph is broken by \TeX{}, \lwc/ grabs the unbroken
1153 paragraph. Then \lwc/ breaks the paragraph one line longer than its natural
1154 length and stores it for later. It does this in the background,
1155 \emph{without} interfering with how \TeX{} breaks paragraphs into their
1156 natural length.
1157
1158 After \TeX{} has broken its paragraph into its natural length, \lwc/
1159 appears again. Before the broken paragraph is added to the main
1160 vertical list, \lwc/ \q{tags} the first and last nodes of the paragraph
1161 using a Lua\TeX{} attribute. These attributes associate the
1162 previously-saved lengthened paragraph with the naturally-typeset
1163 paragraph on the page.
1164
1165 \subsection{Page breaking}
1166
1167 \Lwc/ intercepts \cs{box255} (the \cs{vbox} output by \TeX) immediately
1168 before the output routine runs,
1169 after all the paragraphs have been typeset.
1170
1171 First, \lwc/ looks at the \openalty/ of the page or column. If the page
1172 was broken at a \woo/, the \openalty/ will be equal to either
1173 the \cs{widowpenalty} or the \cs{clubpenalty}. If the \openalty/ does not
1174 indicate a \woo/, \lwc/ will stop and return \cs{box255} unmodified to
1175 the output~routine, and \TeX{} continues as normal.
1176
1177 Otherwise, we assume that we have a \woo/ on the page,
1178 meaning that we should lengthen the page by 1~line. We iterate through
1179 the list of saved paragraphs to find the lengthened paragraph with the
1180 least cost. After we've selected a good paragraph, we traverse
1181 through the page to find the original version of this paragraph---the
1182 one that unmodified \TeX{} originally typeset. Having found the original
1183 paragraph, we splice in the lengthened paragraph in place of the original.
1184 \oldlooseness=-1
1185
1186 Since the page is now 1~line longer than it was before, we pull the last
1187 line off the page to bring it back to its original length, and place
1188 that line onto the top of \TeX's \q{recent contributions} list. When
1189 the next page begins, this line will be inserted before all other
1190 paragraphs, right at the top. Now, we can return the new, widow-free page
1191 (updated \cs{box255}) to the output routine, which proceeds
1192 as normal.
1193
1194 \subsection{Footnotes}
1195 Earlier versions of \textsf{lua-widow-control} completely ignored inserts.
1196 This meant that if a moved line had associated footnotes,
1197 \textsf{lua-widow-control} would move the \q{footnote mark} but not the
1198 associated \q{footnote text}. \textsf{lua-widow-control} now handles
1199 footnotes correctly through the mechanism detailed in the next section.
1200
1201 \subsubsection{Inserts}
1202
1203 Before we go into the details of how \textsf{lua-widow-control} handles
1204 footnotes, we need to look at what footnotes actually are to \TeX{}. Every
1205 \cs{footnote} command ultimately expands to something like
1206 \cs{insert\meta{class}}\allowbreak\verb|{|\meta{content}\verb|}|, where
1207 \meta{class} is an insertion class number, defined as \cs{footins} in this
1208 case (in Plain \TeX\ and \LaTeX). Inserts can be found in horizontal mode
1209 (footnotes) or in vertical mode (\cs{topins} in Plain \TeX{} and floats in
1210 \LaTeX{}), but they cannot be inside boxes. Each of these insert types is
1211 assigned a different class number, but the mechanism is otherwise identical.
1212 \textsf{lua-widow-control} treats all inserts identically, although it
1213 safely ignores vertical mode inserts since they are only ever found between
1214 paragraphs.
1215
1216 But what does \cs{insert} do exactly? When \TeX{} sees an \cs{insert}
1217 primitive in horizontal mode (when typesetting a paragraph), it does two
1218 things: first, it processes the insert's content and saves it invisibly just
1219 below the current line. Second, it effectively adds the insert content's
1220 height to the height of the material on the current page. Also, for the
1221 first insert on a page, the glue in \cs{skip}\meta{class} is added to the
1222 current height. All this is done to ensure that there is sufficient room for
1223 the insert on the page whenever the line is output onto the page.
1224
1225 If there is absolutely no way to make the insert fit on the page---say,
1226 if you placed an entire paragraph in a footnote on the last line of a
1227 page---then \TeX{} will begrudgingly \q{split} the insert, placing the first
1228 part on the current page and \q{holding over} the second part until the next
1229 page.
1230
1231 There are some other \TeX{}nicalities involving \cs{count}\meta{class} and
1232 \cs{dimen}\meta{class}, but they mostly don't affect
1233 \textsf{lua-widow-control}. See Chapter~15 in \textsl{The \TeX{}book} or another reference for
1234 all the details.
1235
1236 After \TeX{} has chosen the breakpoints for a paragraph, it adds the chosen
1237 lines one by one to the current page. Whenever the accumulated page height
1238 is \q{close enough} to the target page height (normally \cs{vsize}) the
1239 \cs{output} token list (often called the ``output routine'') is expanded.
1240
1241 But before \cs{output} is called, \TeX{} goes through the page contents and
1242 moves the contents of any saved inserts into \cs{vbox}es corresponding to
1243 the inserts' classes, namely \cs{box}\meta{class}, so \cs{output} can work
1244 with them.
1245
1246 And that's pretty much it on the engine side. Actually placing the inserts
1247 on the page is reserved for the output routine, which is defined by the
1248 format. This too is a complicated process, although thankfully not one that
1249 \textsf{lua-widow-control} needs to worry about.
1250
1251 \subsubsection{\LuaMeta\TeX{}}
1252
1253 The \LuaMeta\TeX{} engine treats inserts slightly differently than
1254 traditional \TeX{} engines. The first major difference is that insertions
1255 have dedicated registers; so instead of \cs{box}\meta{class}, \LuaMeta\TeX{}
1256 has \cs{insertbox}\meta{class}; instead of \cs{count}\meta{class},
1257 \LuaMeta\TeX{} has \cs{insertmultiplier}\meta{class}; etc. The second major
1258 difference is that \LuaMeta\TeX{} will pick up inserts that are inside of
1259 boxes, meaning that placing footnotes in things like tables or frames should
1260 mostly just work as expected.
1261
1262 There are also a few new parameters and other minor changes, but the overall
1263 mechanism is still quite similar to traditional \TeX{}.
1264
1265 \subsubsection{Paragraph breaking}
1266
1267 As stated in the original article~\cite{tb133chernoff-widows},
1268 \textsf{lua-widow-control} intercepts \TeX{}'s output immediately before
1269 the output routine. However, this is \emph{after} all the inserts on the
1270 page have been processed and boxed. This is a bit of a problem because if
1271 we move a line to the next page, we need to move the associated insert;
1272 however, the insert is already gone.
1273
1274 To solve this problem, immediately after \TeX{} has naturally broken a
1275 paragraph, \textsf{lua-widow-control} copies and stores all its inserts.
1276 Then, \textsf{lua-widow-control} tags the first element of each line
1277 (usually a glyph) with a Lua\TeX{} attribute that contains the indices for
1278 the first and last associated insert. \textsf{lua-widow-control} also tags
1279 each line inside the insert's content with its corresponding index so that
1280 it can be found later.
1281
1282 \subsubsection{Page breaking}
1283
1284 Here, we follow the same algorithm as in the original
1285 article~\cite{tb133chernoff-widows}. However, when we move the last line of
1286 the page to the next page, we first need to inspect the line to see if any
1287 of its contents have been marked with an insert index. If so, we need to
1288 move the corresponding insert to the next page. To do so, we unpack the
1289 attributes value to get all the inserts associated with this line.
1290
1291 Using the stored insert indices and class, we can iterate through
1292 \cs{box}\meta{class} and delete any lines that match one of the current
1293 line's indices. We also need to iterate through the internal \TeX{} box
1294 \verb|hold_head|---the box that holds any inserts split onto the next
1295 page---and delete any matching lines. We can safely delete any of these
1296 lines since they are still stored in the original \cs{insert} nodes that we
1297 copied earlier.
1298
1299 Now, we can retrieve all of our previously-stored inserts and add them to
1300 the next page, immediately after the moved line. Then, when \TeX{} builds
1301 that page, it will find these inserts and move their contents to the
1302 appropriate boxes
1303
1304 \section{Choosing the \q{best} paragraph}
1305
1306 As we discussed previously, \lwc/ lengthens the paragraph with the lowest
1307 cost. However, assigning a cost to each paragraph is not quite as simple as
1308 it sounds. Before we look at how \lwc/ assigns costs, let's look at how
1309 \TeX{} scores paragraphs when breaking them naturally.
1310
1311 \subsection{How \TeX{} scores paragraphs}
1312
1313 All glue in \TeX{} has a certain natural size: the size that it would be
1314 in an ideal scenario. However, most glue also has stretch and shrink
1315 components so that the glue can change in size to adapt to its
1316 surroundings. For each line, \TeX{} individually sums the total
1317 stretch/shrink for the line and the stretch/shrink that was actually used.
1318 We define the stretch/shrink ratio~$r$ as the quotient of the
1319 stretch/shrink used and the stretch/shrink available. Then the badness~$b$
1320 of a line is approximately defined as
1321 \begin{equation*}
1322 b = 100r^3.
1323 \end{equation*}
1324 This is the badness referenced in the commonly-seen
1325 \texttt{Underfull \cs{hbox}
1326 (badness 1234)} warnings that \TeX{} produces.
1327
1328 \TeX{} calculates the badness for each line individually; however, we also
1329 need to assess the paragraph as a whole. To do so, \TeX{} defines the
1330 demerits for a whole paragraph~$d$ as approximately\footnotemark{} the sum
1331 of the squared badnesses for each line. The natural paragraph that \TeX{}
1332 breaks is the one that minimizes~$d$.
1333
1334 \footnotetext{We ignore any additional demerits or penalties that
1335 \TeX{} may add.}
1336
1337 One important thing to realize is that demerits grow incredibly fast:
1338 demerits are proportional to the \emph{sixth} power of glue stretch. This
1339 means that you can expect to see extremely large demerit values, even for
1340 a relatively \q{good} paragraph.
1341
1342 \subsection{Possible cost functions}
1343
1344 Now, let's return to how \lwc/ assigns costs to each paragraph. This is
1345 surprisingly more complicated than it sounds, so we'll go through a few
1346 possible cost functions first.
1347
1348 Here, we use $c$~for the cost of a paragraph, $d$~for the total demerits,
1349 and $l$~for the number of lines (\cs{prevgraf}).
1350
1351 \subsubsection{The original implementation}
1352
1353 The original implementation of \lwc/ used the simple cost function
1354 \begin{equation*}
1355 c = d.
1356 \end{equation*}
1357 This cost function works reasonably well, but has one major issue: it
1358 doesn't take into account the number of lines in the paragraph. The demerits
1359 for a paragraph is the sum of the demerits for each line. This means this
1360 cost function will prefer using shorter paragraphs since they tend to have
1361 fewer demerits. However, long paragraphs tend to have much more available
1362 glue stretch, so this strategy can lead to suboptimal solutions.
1363
1364 \subsubsection{Scaling by the number of lines}
1365
1366 Once I realized this issue, I tried correcting it by dividing by the number
1367 of lines in the paragraph to get the average demerits instead of the total
1368 demerits:
1369 \begin{equation*}
1370 c = \frac{d}{l}
1371 \end{equation*}
1372 This works better than the previous function, but still has an issue.
1373 If we have a fairly bad ten-line paragraph with total demerits $10d$ and an
1374 almost-equally bad two-line paragraph with total demerits $2d + 1$, then by
1375 this cost function, the ten-line paragraph will have a lower cost and will
1376 be chosen. This means that our page now has ten bad lines instead of two bad
1377 lines, which is not ideal.
1378
1379 \subsubsection{Current implementation}
1380
1381 Our first cost function, $c=dl^0$, doesn't consider the number of lines at
1382 all, while our second cost function, $c=dl^{-1}$, considers the number of
1383 lines too much. Splitting the difference between the two functions, we get
1384 the current implementation:
1385 \begin{equation*}
1386 c = \frac{d}{\sqrt{l}}
1387 \end{equation*}
1388
1389 This solves the issue with the previous function, but it adds a new issue: given a
1390 short paragraph with a large number of demerits per line and a long
1391 paragraph with fairly few average demerits per line, this function will often
1392 choose the shorter line. Although this sounds bad, in practice it gives much
1393 better results since very bad short paragraphs are \emph{much} less noticeable than
1394 slightly bad long paragraphs.
1395
1396 Of course, this new function may still not be quite perfect. \Lwc/ uses the
1397 \texttt{lwc.paragraph\_cost(demerits, lines)} Lua function to calculate a
1398 paragraph's cost; if you want, you can redefine this function to anything
1399 that you want.
1400 \oldlooseness=-1
1401
1402 % I didn't arrive at this function through any sort of scientific testing;
1403 % rather, I picked the simplest function that I could think of that satisfies
1404 % the following two properties:
1405 % \begin{itemize}
1406 % \item Given a long paragraph and a short paragraph with different
1407 % average badnesses per line, prefer the one with the least average
1408 % badness.
1409 % \item Given two paragraphs with equal average badnesses per line,
1410 % prefer the shorter one.
1411 % \end{itemize}
1412
1413 \vspace*{-3pt}
1414
1415 \section{Quantitative analysis}
1416
1417 \vspace*{-1pt}
1418
1419 \begin{figure}
1420 \begin{tikzpicture}\begin{axis}[
1421 ybar interval,
1422 xticklabels={1, ..., 15,
1423 {$\,\ge\! 16$}},
1424 x tick label style={font=\small},
1425 y tick label style={font=\small},
1426 enlarge y limits=upper,
1427 enlarge x limits={abs=1},
1428 grid=none,
1429 scaled y ticks=base 10:-3,
1430 ytick scale label code/.code={},
1431 xlabel={Paragraph length (lines)},
1432 ylabel={Count (thousands)}
1433 ]
1434 \addplot+ [
1435 draw=black,
1436 fill=black!10,
1437 semithick,
1438 ] table {
1439 Length Count
1440 1 4429
1441 2 3704
1442 3 2045
1443 4 1320
1444 5 894
1445 6 717
1446 7 498
1447 8 406
1448 9 379
1449 10 251
1450 11 175
1451 12 152
1452 13 111
1453 14 95
1454 15 79
1455 16 437
1456 18 0
1457 };
1458
1459 \filldraw [fill=black!25, draw=black] (16, 0) rectangle (18, 437);
1460 \end{axis}\end{tikzpicture}
1461 \caption{Histogram of natural paragraph lengths in the sample text.}
1462 \label{fig:hist}
1463 \end{figure}
1464
1465 Let's look at some statistics for \lwc/. For testing, I
1466 downloaded the top~ten books on \textsl{Project Gutenberg},\footnotemark{}
1467 converted them to \LaTeX{} using \textsf{pandoc}, concatenated them into a
1468 single \textsf{article} file, and compiled twice. This gives us a \acro{PDF}
1469 with 1\,381~pages, 15\,692~paragraphs, 61\,865~lines, and 399~\waos/
1470 (if they aren't removed).
1471 \footnotetext{\textsl{Frankenstein},
1472 \textsl{Pride and Prejudice},
1473 \textsl{Alice's Adventures in Wonderland},
1474 \textsl{The Great Gatsby},
1475 \textsl{The Adventures of Sherlock Holmes},
1476 \textsl{Simple Sabotage Field Manual},
1477 \textsl{A Tale of Two Cities},
1478 \textsl{The Picture of Dorian Gray},
1479 \textsl{Moby Dick},
1480 and \textsl{A Doll's House}.
1481 }
1482
1483 This is a fairly challenging test: almost every third page has a \woo/, over
1484 half of the paragraphs have two lines or fewer, and the text block is set to
1485 the fairly wide \textsf{article} defaults. An average document is
1486 much less challenging for \lwc/, so we can consider this to be a
1487 worst-case scenario.
1488
1489 \vspace*{-1pt}
1490
1491 \subsection{Widows and orphans removed}
1492
1493 \begin{figure}
1494 \begin{tikzpicture}\begin{axis}[
1495 ybar=0pt,
1496 bar width=0.8,
1497 xtick=data,
1498 ylabel={Widows and orphans removed},
1499 xticklabels={
1500 \shortstack[c]{\hfill Maximum\\\hfill possible},
1501 \textsf{lwc} \texttt{default},
1502 \texttt{balanced},
1503 \LaTeX{},
1504 \texttt{strict},
1505 },
1506 x tick label style={
1507 font=\small,
1508 rotate=45,
1509 anchor=east,
1510 },
1511 enlarge x limits=0.2,
1512 ]
1513 \addplot+ [
1514 draw=black,
1515 fill=black!10,
1516 semithick,
1517 ] table [x expr=\coordindex, y index=0] {
1518 399
1519 392
1520 348
1521 179
1522 52
1523 };
1524
1525 \filldraw [fill=black!25, draw=black]
1526 (-0.4, 0) rectangle (0.4, 399);
1527 \end{axis}\end{tikzpicture}
1528 \divide\abovecaptionskip by 2
1529 \caption{The number of \waos/ removed by each method.}\label{fig:modes}
1530 \end{figure}
1531
1532 When we run \LaTeX{} with its default settings on the file, 179~(47\%) of
1533 the \waos/ are removed. When we add \lwc/ with default settings, we remove
1534 392~(98\%). Switching to strict mode, we can only remove 52~(13\%) of the
1535 \waos/. In balanced mode, we remove 348~(87\%). See Figure~\ref{fig:modes}
1536 for a visual comparison.
1537
1538 \subsection{Paragraph costs}
1539
1540 \begin{figure}
1541 \begin{tikzpicture}\begin{axis}[
1542 xlabel={Percentile},
1543 ylabel={Cost},
1544 ymode=log,
1545 legend entries={Long, Natural},
1546 legend pos=north west,
1547 cycle list={
1548 {black, thick},
1549 {black!35, thick},
1550 },
1551 ]
1552 \addplot+ table [x=Percentile, y=Long] {\plotdata};
1553 \addplot+ table [x=Percentile, y=Natural] {\plotdata};
1554
1555 \end{axis}\end{tikzpicture}
1556 \divide\abovecaptionskip by 2
1557 \caption{Paragraph costs by percentile rank for naturally-broken and
1558 one-line lengthened paragraphs.}\label{fig:costs}
1559 \end{figure}
1560
1561 The last section showed us that \lwc/ is quite effective at removing \waos/,
1562 so now let's look at the paragraphs that \lwc/ expands. As \TeX{}
1563 processes a document, \lwc/ is recording the costs for the naturally-broken
1564 and expanded versions of each paragraph in the document. Costs don't
1565 mean that much on their own, but a lower cost is always better.
1566
1567 As you can see in Figure~\ref{fig:costs}, the
1568 lengthened paragraphs tend to have \emph{much} higher costs than the
1569 naturally-broken paragraphs. This is not surprising, since (as we've seen)
1570 a paragraph's demerits scale with the sixth power of glue stretch, so even
1571 a small amount of glue stretch can cause a huge increase in demerits.
1572
1573 The empty space on the left of the \q{long} line is from the paragraphs
1574 that \lwc/ was unable to lengthen at any cost. Lua\TeX{} assigns these
1575 paragraphs zero~demerits, so they disappear on a logarithmic plot.
1576
1577 \subsection{Lengthening vs.\ shortening paragraphs}
1578 \begin{figure}[t]
1579 \begin{tikzpicture}\begin{axis}[
1580 xbar stacked,
1581 height=0.15\linewidth,
1582 width=\dimexpr\linewidth-1em,
1583 scale only axis,
1584 bar width=1,
1585 enlargelimits=false,
1586 xmin=0,
1587 ymin=-0.5,
1588 ymax=1,
1589 ymajorticks=false,
1590 xtick style={draw=none},
1591 xlabel={Paragraphs (thousands)},
1592 scaled x ticks=base 10:-3,
1593 xtick scale label code/.code={},
1594 legend style={at={(0.5,1)}, anchor=north},
1595 legend columns=5,
1596 legend cell align=left,
1597 legend style={
1598 /tikz/every even column/.append style={column sep=1em},
1599 draw=none,
1600 fill=none,
1601 },
1602 legend entries={
1603 {$n=1$},
1604 {$n$},
1605 {$n+1$},
1606 {$n\pm1$},
1607 {$n-1$}
1608 },
1609 ]
1610 \addplot [fill=black!10 ] coordinates {(4429, 0)}; % One
1611 \addplot [fill=white ] coordinates {(4474, 0)}; % None
1612 \addplot [pattern=north east lines] coordinates {(5457, 0)}; % Long
1613 \addplot [pattern=crosshatch ] coordinates {( 482, 0)}; % Both
1614 \addplot [pattern=north west lines] coordinates {( 850, 0)}; % Short
1615 \end{axis}\end{tikzpicture}
1616 \divide\abovecaptionskip by 2
1617 \caption{The number of paragraphs in the test sample that
1618 (respectively) have exactly
1619 one line, cannot be stretched or shrunk, can be only stretched
1620 by one~line, can be either stretched or shrunk, and can be
1621 only shrunk.}
1622 \label{fig:stretchshrink}
1623 \end{figure}
1624
1625 Figure~\ref{fig:stretchshrink} shows the number of paragraphs that \lwc/
1626 could potentially stretch or shrink. The one-line paragraphs are broken out
1627 separately since this test sample has an anomalous number of them.
1628 Otherwise, we can see that \lwc/ is capable of stretching the majority of
1629 paragraphs.
1630
1631 We can also see that of non-single-line paragraphs, only about 8\%
1632 of paragraphs can only be shrunk (the last segment of
1633 Figure~\ref{fig:stretchshrink}), and this is in a document where 13\%
1634 of paragraphs have at least eight~lines. Most documents rarely have
1635 such long paragraphs, and it is these long paragraphs that are the
1636 easiest to shrink.
1637 \oldlooseness=-1
1638
1639 Because of this, \lwc/ doesn't even attempt to shrink paragraphs; it
1640 only stretches them.
1641
1642 \vspace*{-10pt}
1643
1644 \section{Known issues}
1645
1646 \vspace*{-5pt}
1647
1648 \Lwc/ is quite stable these days. At this point, all \emph{known} bugs have
1649 been resolved; some bugs certainly still remain, but I'd feel quite
1650 confident using \textsf{lua-widow-control} in your everyday documents. There
1651 are, however, some fundamental limitations due to how \lwc/ operates:
1652
1653 \begin{itemize}
1654 \item When a three-line paragraph is at the end of a page forming a
1655 widow, \lwc/ will remove the widow; however, it will leave an orphan.
1656 This issue is inherent to any process that removes widows through
1657 paragraph expansion and is thus unavoidable. Orphans are considered
1658 to be better than widows~\cite{elements}, so this is still an
1659 improvement.
1660
1661 \item Sometimes a \woo/ cannot be eliminated because no paragraph has
1662 enough stretch. Sometimes this can be remediated by
1663 increasing \lwc/'s \estretch/; however, some pages just don't have
1664 any suitable paragraph.
1665
1666 Long paragraphs with short words tend to be stretchier than short
1667 paragraphs with long words since these long paragraphs have more
1668 interword glue. Narrow columns also stretch more easily than wide
1669 columns since you need to expand a paragraph by less to make a new line.
1670
1671 \item \Lwc/ only attempts to expand paragraphs on a page with a \woo/. A
1672 global system like in~\titlecite{global} would solve this;
1673 however, this is both \acro{NP}-complete~\cite{plass} and
1674 impossible to solve in a single pass. Very rarely would such a
1675 system remove \woos/ that \lwc/ cannot.
1676
1677 \item \textsf{lua-widow-control} won't properly move footnotes if there
1678 are multiple different ``classes'' of inserts on the same line. To the
1679 best of my knowledge, this shouldn't happen in any real-world
1680 documents. If this happens to be an issue for you, please let me know;
1681 this problem is relatively easy to fix, although it will add
1682 considerable complexity for what I think isn't a real issue.
1683 \oldlooseness=-1
1684 \end{itemize}
1685
1686 \section{Conclusion}
1687
1688 All this probably makes \lwc/ look quite complicated, and this is true to
1689 some extent. However, this complexity is hidden from the end~user:
1690 as stated at the outset, most
1691 users merely need to place \latexuse/ in their \LaTeX{} document
1692 preamble, and \lwc/ will remove all the troublesome \waos/, without needing
1693 any manual intervention.
1694
1695 Should you have any issues, questions, or suggestions for \lwc/, please
1696 visit the project's GitHub page:
1697 \href{https://github.com/gucci-on-fleek/lua-widow-control}
1698 {\ttfamily https://github.com/gucci-on-fleek\discretionary{-}{-}{-}lua-widow-control}.
1699 Any feedback is greatly appreciated!
1700
1701 \let\macro=\cs
1702 \AtNextBibliography{\small}
1703 \printbibliography
1704
1705 \section*{Automatické odstraňování vdov a sirotků pomocí balíčku \textsf{lua-widow-control}}
1706 \begin{otherlanguage}{czech}
1707 Balíček \textsf{lua-widow-control} pro
1708 Lua\TeX\slash{}Lua\LaTeX\slash{}\ConTeXt\slash{}\OpTeX{} odstraňuje vdovy
1709 a sirotky bez dalšího zásahu uživatele. Využívá přitom sílu Lua\TeX u a přitom
1710 nenatahuje žádné vertikální mezery a ani nezkracuje stránky nebo sloupce.
1711 Namísto toho balíček automaticky prodlužuje některý z odstavců na té stránce
1712 nebo sloupci, kde by se vdova nebo sirotek vyskytli.
1713
1714 Pro použití balíčku postačí většině uživatelů \LaTeX u uvést v~preambuli
1715 dokumentu \verb|\usepackage{lua-widow-control}|. Žádné další změny
1716 v~dokumentu nejsou zapotřebí.
1717 \end{otherlanguage}
1718 \klicovaslova: Lua\TeX, vdova, sirotek
1719
1720 \end{document}