summaryrefslogtreecommitdiff
path: root/macros/luatex/generic/lua-widow-control/lwc-zpravodaj.ltx
blob: 1a00292e2f92b15221983980b29379ed1354f859 (plain)
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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
% lua-widow-control
% https://github.com/gucci-on-fleek/lua-widow-control
% SPDX-License-Identifier: MPL-2.0+ OR CC-BY-SA-4.0+
% SPDX-FileCopyrightText: 2022 Max Chernoff

% This is the LaTeX source for the following article:
% @article{zpravodaj-lwc,
%     title={Automatically Removing Widows and Orphans with
%            \textsf{lua-widow-control}},
%     author={Chernoff, Max},
%     journal={Zpravodaj Československého sdružení uživatelů TeXu},
%     number={1--4},
%     pages={49--76},
%     year={2022},
%     month=nov,
%     DOI={10.5300/2022-1-4/49},
% }
% Please refer to the PDF on cstug.cz for the authoritative version.

% Compiling:
%     context lwc-zpravodaj-figure.ctx
%     lualatex lwc-zpravodaj.ltx
%     biber lwc-zpravodaj
%     lualatex lwc-zpravodaj.ltx
%     lualatex lwc-zpravodaj.ltx

\RequirePackage{luatex85}
\PassOptionsToPackage{main=english}{babel}
\PassOptionsToPackage{shorthands=off}{babel}

\makeatletter
\disable@package@load{fontenc}
\makeatother

\let\oldlooseness=\looseness

\documentclass{csbulletin}

% Hyperlinks
\usepackage[implicit=false, hidelinks]{hyperref}
\setcounter{secnumdepth}{3}

% Load lwc
\usepackage[balanced, draftoffset=\oddsidemargin + 1in + 10pt]{lua-widow-control}

% Table Stuff
\usepackage{tabularx}
\usepackage{longtable}
\usepackage{hhline}
\usepackage{booktabs}
\usepackage{graphicx}
\AddToHook{env/tabularx/before}{\nobreak\smallskip\noindent}
\AddToHook{env/tabularx/after}{\smallskip\pagebreak[1]}
\AddToHook{env/tabular/before}{\nobreak\smallskip\noindent}
\AddToHook{env/tabular/after}{\smallskip\pagebreak[1]}
\AddToHook{env/longtable/before}{\nobreak\smallskip\noindent}
\AddToHook{env/longtable/after}{\smallskip\pagebreak[1]}
\setlength{\LTleft}{0pt}
\renewcommand{\arraystretch}{1.15}

% For the sideways figure
\usepackage{rotating}

% Rotate the sideways figure in the PDF viewer too
\AddToHook{env/sidewaysfigure/end}{%
    \latelua{pdf.setpageattributes('/Rotate 90')}%
    \AddToHookNext{shipout/after}{%
        \AddToHookNext{shipout/after}{%
            \directlua{pdf.setpageattributes('/Rotate 0')}%
        }%
    }%
}%
% Let the macro names in section headings be in boldface
\usepackage{lmodern}
\AtBeginDocument{\def\cs#1{\texttt{\textbackslash#1}}}

\directlua{
    local percent = string.char(37)
    luatexbase.add_to_callback("process_input_buffer", function(line) return line:gsub(percent .. "-" .. percent .. "-" ..percent .. "-", "\\kern0.1em---\\kern0.1em") end, "emdash")
} % Add a little more kerning to em-dashes

\makeatletter
\DeclareRobustCommand{\eTeX}{%
    \ifx\f@series\bfseries@rm%
        \ensuremath{\boldsymbol{\varepsilon}}\mbox{-}\kern-.125em\TeX%
    \else%
        \ensuremath{\varepsilon}\mbox{-}\kern-.125em\TeX%
    \fi%
}
\let\goodeTeX=\eTeX
\makeatother

% Other commands
\usepackage{hologo}
\def\ConTeXt{\Hologo{ConTeXt}}

\usepackage{mathtools}

% Abbreviations Most of these are just typewriter commands with `\allowbreak`s
% added.
\def\lwc/{\textsf{lua-\allowbreak widow-\allowbreak control}}
\def\Lwc/{\textsf{lua-\allowbreak widow-\allowbreak control}}
\def\estretch/{%
     \texorpdfstring{\cs{emergency}\-\mbox{\ttfamily stretch}}{\textbackslash{}emergencystretch}%
    }
\def\openalty/{\cs{output}\-\mbox{\ttfamily penalty}}
\def\waos/{widows and orphans}
\def\wao/{widow and orphan}
\def\woo/{widow or orphan}
\def\woos/{widows or orphans}
\def\latexuse/{%
    \cs{use\-package\{lua-\allowbreak widow-\allowbreak control\}}
}
\def\lsness/{\texorpdfstring{%
    \cs{loose}\-\mbox{\ttfamily ness}}{\textbackslash{}looseness}%
}
\def\plainop/{Plain~\TeX\slash\OpTeX{}}
\newcommand{\LuaMeta}{Lua\-Meta\-}
\newcommand{\q}[1]{\texorpdfstring{``#1''}{“#1”}}

\def\inlineurl[#1]#2{\href{https://#1}{#2}\footnote{\raggedright\href{https://#1}{\ttfamily #1}}}

\def\longs/{\char"017F}
\def\endofline#1{\unskip\nobreak\hskip\fontdimen2\font plus 1fill\hbox{#1}}

% TUGboat compatibility
\def\tubsentencespace{\spacefactor=3000{}\space\ignorespaces}
\DeclareRobustCommand\OpTeX{Op\kern-.05em\TeX}
\DeclareRobustCommand\acro[1]{\textsc{\MakeLowercase{#1}}}
\DeclareRobustCommand\meta[1]{%
  \ensuremath{\langle}%
  \ifmmode \expandafter\mbox \fi%
  {\it #1\/}%
  \ensuremath{\rangle}%
}

% Bibliography
\usepackage[
  backend=biber,
  style=iso-authoryear,
  sortlocale=en,
  autolang=other,
  bibencoding=UTF8,
  mincitenames=2,
  maxcitenames=2,
]{biblatex}

% Remove the "also" from "available also from"
\DefineBibliographyStrings{english}{
    urlalso = {available from},
}

\protected\def\titlecite#1{\citetitle{#1}~\cite{#1}}

\let\cite=\parencite

\addbibresource{lwc-zpravodaj.bib}
\addbibresource{tugboat.bib}

% Figures
\makeatletter
\renewcommand*{\fps@figure}{tb}
\renewcommand*{\fps@table}{tb}
\g@addto@macro\@floatboxreset\centering
\makeatother

% pgfplots
\usepackage{pgfplots}
\usepackage{pgfplotstable}
\usetikzlibrary{patterns}

\pgfkeys{
    /pgf/number format/.cd,
    sci generic={%
        mantissa sep={\times},
        exponent={10^{##1}}
    },
    1000 sep={\,},
}

\pgfplotsset{
    compat=1.18,
    lua backend=true,
    unbounded coords=discard,
    filter discard warning=false,
}


\pgfplotstableread{tb133chernoff-widows-plot.dat}{\plotdata}

% Final adjustments
\def\spoj{\discretionary{-}{-}{-}}

\makeatletter
\csbul@start@page {49}
\def\doi{10.5300/2022-1-4/\thepage}
\csbul@webtrue
\csbul@colortrue
\makeatother

\begin{document}
    \title{Automatically Removing Widows and Orphans\\ with \lwc/}
    \EnglishTitle{Automatically Removing Widows and Orphans\\ with \lwc/}
    \author{Max Chernoff}
    \podpis{Max Chernoff, mseven at telus dot net}

    \maketitle

    \begin{abstract}
    The \textsf{lua-widow-control} package, for
    plain~Lua\TeX\slash{}Lua\LaTeX\slash{}\ConTeXt\slash{}\OpTeX{},
    removes widows and orphans without any user intervention.
    Using the power of Lua\TeX{}, it does so without stretching any vertical glue
    or shortening any pages or columns. Instead, \textsf{lua-widow-control}
    automatically lengthens a paragraph on a page or column where a widow or
    orphan would otherwise occur.

    To use the \textsf{lua-widow-control} package, all that most \LaTeX{} users
    need do is place \verb|\usepackage{lua-widow-control}| in their preamble.
    No further changes are required.
    \end{abstract}
    \keywords: Lua\TeX{}, widows, orphans

    \hypersetup{bookmarksdepth=10}
    \section{Motivation}

    {\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.}}

    \TeX{} provides top-notch typesetting: even 40 years after its first
    release, no other program produces higher quality mathematical
    typesetting, and its paragraph\spoj breaking algorithm is still
    state-of-the-art. However, its page breaking is not quite as sophisticated
    as its paragraph breaking and thus suffers from some minor issues.
    \oldlooseness=-1

    Unmodified \TeX{} has only two familiar ways of dealing with \waos/: it can
    either shorten a page by one line, or it can stretch vertical
    whitespace. \TeX{} was designed for mathematical and scientific typesetting,
    where a typical page has multiple section headings, tables, figures, and
    equations. For this style of document, \TeX's default behaviour works quite
    well, since the slight stretching of whitespace between the various document
    elements is nearly imperceptible; however, for prose or other documents
    composed almost entirely of paragraphs, there is little vertical whitespace
    to stretch.

    Since no ready-made, fully-automated solution to remove
    \waos/ from all types of documents was available, I decided to
    create \lwc/.
    \oldlooseness=-1

    \section{What are \waos/?}

    \subsection{Widows}

    A \q{widow} occurs when the majority of a paragraph is on one page
    or column,
    but the last line is on the following page or column. It not only looks
    quite odd for a lone line to be at the start of the page, but it makes a
    paragraph harder to read since the separation of a paragraph and
    its last line disconnects the two, causing the reader to lose context for
    the widowed line.

    \subsection{Orphans}

    An \q{orphan} occurs when the first line of a paragraph is at the end
    of the page or column preceding the remainder of the paragraph. They are not
    as distracting for the reader, but they are still not ideal.
    Visually, \waos/ are about equally disruptive; however, orphans tend not to
    decrease the legibility of a text as much as widows, so many authors choose
    to ignore them.

    See Figure~\ref{tab:widow} for a visual reference.

    \begin{figure}
        \def\firstpage#1{%
            \parfillskip=0pt\relax
            \spaceskip=0.2em plus 1fill\relax
            \hskip 3em\relax
            #1%
        }

        \def\lastpage#1{%
            \parfillskip=3em plus 1fill\relax
            \spaceskip=0.2em plus 1fil\relax
            #1%
        }

        \renewcommand{\arraystretch}{1}
        \renewcommand{\doublerulesep}{0.5em}
        \begin{tabularx}{\linewidth}{|X|@{\hskip\doublerulesep}|X|}
            \multicolumn1c{\bfseries Widow} &
            \multicolumn1c{\bfseries Orphan}
            \\\hhline{-||-}%
            \firstpage{A widow is when a paragraph's last line is
            placed on a different page}%
            &\vskip4pt\leavevmode\firstpage{An orphan is when the first}%
            \\ \hhline{-||-}
            \lastpage{than where it begins.}
            & \lastpage{line of a paragraph occurs on the
                page before all the other lines.} \\ \hhline{-||-}
        \end{tabularx}
        \caption{The difference between \waos/. If we imagine that each box is a
                different page, then this roughly simulates how \waos/ appear.\oldlooseness=-1}
        \label{tab:widow}
    \end{figure}

    \subsection{Broken hyphens}

    \q{Broken} hyphens occur whenever a page break occurs in a
    hyphenated word. These are not related to \waos/; however,
    breaking a word across two pages is at least as disruptive for the reader
    as \waos/. \TeX{} identifies broken hyphens in the same ways as \waos/, so
    \lwc/ treats broken hyphens in the same way.

    \section{History and etymology}

    The concept of \waos/ is nearly as old as printing itself. In \titlecite{old},
    a printers manual from 1683, we have:
    \begin{quote}
        Nor do good \emph{Compo\longs/iters} account it good Workman\longs/hip
        to begin a \emph{Page} with a \emph{Break-line}, unle\longs/s it be a
        very \longs/hort \emph{Break}, and cannot be gotten in the foregoing
        \emph{Page}\,; but if it be a long \emph{Break}, he will let it be the
        \emph{Direction-line} of the fore-going \emph{Page}, and \emph{Set} his
        \emph{Direction} at the end of it. \endofline{(p.~226)}
    \end{quote}
    However, the terms \q{widow} and \q{orphan} are much newer.

    \subsection{Widows}

    The earliest published source that I could find referencing \q{widows} in
    typography is \textsl{Webster's New International Dictionary} from~1934.
    However, no one---not even the editors of the
    dictionary~\cite{widowhistory}---seems to know how it got there. Even then,
    the definition is somewhat different than it is now:
    \begin{quote}
        widow, n.~c.~\emph{Print}\@. A short line or single word carried over
        from the foot of one column or page to the head of a succeeding column
        or page.
        \endofline{\cite{widowhistory}}
    \end{quote}
    Contrast this with the modern definition:
    \begin{quote}
        The stub-ends left when paragraphs end on the first line of a page are called
        widows. They have a past but not a future, and they look foreshortened and forlorn.
        \endofline{\cite{elements}}
    \end{quote}
    which includes a single lone line of any length.

    \subsection{Orphans}

    The term \q{orphan} is even more confusing. Its initial usage seems to have
    occurred some time after \q{widow}~\cite{widowhistory}, and it is given many
    contradictory definitions. Most sources define an orphan as a first line at
    the bottom of the page and a widow as the last line at the
    top~\cite{elements, widowhistory, widowhistory2, Isambert:TB31-1-12,
    texbook, widows-and-orphans, oed-line, oed-widow}; however,  some sources
    define these two terms as \emph{exact opposites} of each other, with a widow
    as a first line at the bottom of the page and an orphan as the last
    line!~\cite{backwards1, widowhistory, backwards3, oed-line,
    backwards2}\tubsentencespace
    This usage is plain wrong; nevertheless, it is sufficiently common that you
    need to be careful when you see the terms \q{widow} and \q{orphan}.

    Similarly to the term \q{widow}, \titlecite{elements} provides a succinct
    definition of the term \q{club}, along with a helpful mnemonic:
    \begin{quote}
        Isolated lines created when paragraphs begin on the last line of a page
        are known as orphans. They have no past, but they do have a future.
        \endofline{\cite{elements}}
    \end{quote}

    \subsection{Clubs}

    \textsl{The \TeX{}book} never refers to \q{orphans} as such; rather, it
    refers to them as \q{clubs}. This term is remarkably rare: I could only find
    a \emph{single} source published before \textsl{The \TeX{}book}---a
    compilation article about the definition of \q{widow}---that mentions
    a \q{club line}:
    \begin{quotation}
        \noindent
        The Dictionary staff informs me that they have no example of the use of
        the word widow in the typographical sense.~[\dots]

        Mr.~Watson of the technical staff says that
        the Edinburgh printing houses referred to it as a \q{clubline}.
        \endofline{\cite[p.~4]{widowhistory}}
    \end{quotation}\medskip
    \begin{quotation}
        \noindent
        To my knowledge, a `widow', or `widow-line,' is a short line, forming
        the end of a paragraph, which is carried over from the foot of a page or
        column to the top of the succeeding one.~[\dots]

        To my personal knowledge, in typographical parlance in Edinburgh,
        Scotland, the `widow' is called a `club-line.'
        \endofline{\cite[p.~23]{widowhistory}}
    \end{quotation}

    Both quotes above are from separate authors, and they each define a \q{club}
    like we define \q{widow}, not an \q{orphan}. In addition, they both mention
    that the term is only used in Scotland. Even the extensive
    \acro{OED}---which lists 17~full definitions and
    103~subdefinitions for the noun \q{club}---doesn't recognize the
    phrase.~\cite{oed-club}

    I spent a few hours searching through Google Books and my university library
    catalogue, but I could not find a single additional source. However, Don
    Knuth---the creator of \TeX{}---read the original article
    \cite{tb133chernoff-widows} and sent me this reply:
    \oldlooseness=-1

    \begin{quote}
    I cannot remember where I found the term \q{club line}. Evidently
    the books that I scoured in 1977 and 1978 had taught me only that an
    isolated line, caused by breaking between pages in the midst of a
    paragraph, was called a \q{widow}; hence \TeX78 had only
    \q{\cs{chpar4}} to
    change the \q{\texttt{widowpenalty}}. Sometime between then and \TeX82
    I must
    have come across what appeared to be an authoritative source that
    distinguished between widows at the beginning of a paragraph and
    orphans or club lines at the end. I may have felt that the term
    \q{orphan} was somewhat pejorative, who knows?\footnotemark
    \end{quote}

    \footnotetext{
        Note that this definition is somewhat mistaken. Widows are located
        either at the \emph{end} of a paragraph, or the beginning of a
        \emph{page or column}. Likewise, orphans\slash{}clubs appear at the
        \emph{beginning} of a paragraph or at the end of a \emph{page or column}.
    }

    \noindent
    So this (somewhat) resolves the question of where the term \q{club} came
    from.

    \section{Pagination in \TeX}

    Let's move on to looking at how \TeX{} treats these \waos/.

    \subsection{Algorithm}

    It is tricky to understand how \lwc/ works if you aren't familiar with how
    \TeX{} breaks pages and columns. For a full description, you should consult
    Chapter~15 of~\titlecite{texbook} (\q{How \TeX{} Makes
    Lines into Pages}); however, this goes into much more detail than most users
    require, so here is a \emph{very} simplified summary of \TeX{}'s page
    breaking algorithm:

    \TeX{} fills the page with lines and other objects until the next object
    will no longer fit. Once no more objects will fit, \TeX{} will align the
    bottom of the last line with the bottom of the page by stretching any
    available vertical spaces if (in \LaTeX) \cs{flushbottom} is set;
    otherwise, it will
    break the page and leave the bottom empty.

    However, some objects have penalties attached. Penalties encourage or
    discourage page breaks from occurring at specific places. For example,
    \LaTeX{} sets a negative penalty before section headings to encourage a
    page break there; conversely, it sets a positive penalty after section
    headings to discourage breaking.

    To reduce \waos/, \TeX{} sets weakly-positive penalties between the
    first and second lines of a paragraph to prevent orphans, and between the
    penultimate and final lines to prevent widows.

    One important note: once \TeX{} begins breaking a page, it never goes
    back to modify any content on the page. Page breaking is a localized
    algorithm, without any backtracking.

    \subsection{Behaviour}

    Merely describing the algorithm doesn't allow us to intuitively
    understand how
    \TeX{} deals with \waos/.

    Due to the penalties attached to \waos/, \TeX{} tries to avoid
    them. Widows and orphans with small penalties attached---like
    \LaTeX's default values of 150---are only lightly coupled to the rest
    of the paragraph, while \waos/ with large penalties---values of
    10\,000 or more---are treated as infinitely bad and are thus
    unbreakable. Intermediate values behave just as you would expect,
    discouraging page breaks proportional to their value.

    When \TeX{} goes to break a page, it tries to avoid breaking at a
    location with a high penalty. How it does so depends on a few settings:

    \subsubsection{\cs{flushbottom} and \cs{normalbottom}}

    With the settings \cs{normalbottom} (Plain \TeX{}) or \cs{flushbottom}
    (\LaTeX{}), \TeX{} is willing to stretch any glue on the page by an amount
    roughly commensurate to the magnitude of the penalty: for small
    \cs{clubpenalty} and \cs{widowpenalty} values, \TeX{} will only slightly
    stretch the glue on the page before creating a \woo/; for very large
    penalties, \TeX{} will stretch the glue by a near-infinite amount.
    \oldlooseness=-1

    This corresponds to the \q{Stretch} column in
    Figure~\ref{fig:demo}. It is
    the default behaviour of Plain~\TeX{}, and of the standard \LaTeX{} classes
    when the \verb|twocolumn| option is given.

    \subsubsection{\cs{raggedbottom}}

    When \cs{raggedbottom} is set, \TeX{} won't stretch any glue. Instead, for
    sufficiently high \cs{clubpenalty} and
    \cs{widowpenalty} values, \TeX{} will shorten the page or column by
    one~line in order to prevent the \woo/ from being created.

    This corresponds to the \q{Shorten} column in Figure~\ref{fig:demo} and is
    the default behaviour of the \LaTeX{} classes when the
    \verb|twocolumn| option is not given.

    \section{\lsness/}\label{sec:looseness} Before we can continue further, we
    need to discuss one more \TeX{} command: \lsness/. The following is
    excerpted from Chapter~14 of~\titlecite{texbook} (\q{How \TeX{} Breaks
    Paragraphs into Lines}):

    \begin{quotation}
        \noindent
        If you set \lsness/\verb|=1|, \TeX{} will try to make the current
        paragraph one line longer than its optimum length, provided that
        there is a way to choose such breakpoints without exceeding the
        tolerance you have specified for the badnesses of individual lines.
        Similarly, if you set \lsness/\verb|=2|, \TeX{} will try to make the
        paragraph two lines longer; and \lsness/\verb|=-1| causes an attempt
        to make it shorter.~[\dots]

        For example, you can set \lsness/\verb|=1| if you want to avoid a
        lonely \q{club line} or \q{widow line} on some page that does not
        have sufficiently flexible glue, or if you want the total number of
        lines in some two-column document to come out to be an even number.

        It's usually best to choose a paragraph that is already pretty
        \q{full}, i.e., one whose last line doesn't have much white space,
        since such paragraphs can generally be loosened without much harm.
        You might also want to insert a tie between the last two words of
        that paragraph, so that the loosened version will not end with only
        one \q{widow word} on the orphans line; this tie will cover your
        tracks, so that people will find it hard to detect the fact that you
        have tampered with the spacing. On the other hand, \TeX{} can take
        almost any sufficiently long paragraph and stretch it a bit, without
        substantial~harm.
        \oldlooseness=1
    \end{quotation}

    The \wao/ removal strategy suggested in the second paragraph works quite
    well; however, it requires manual editing each and every time a page
    or paragraph is rewritten or repositioned.

    \begin{sidewaysfigure}[p!]
        \includegraphics{lwc-zpravodaj-figure}
        \caption{A visual comparison of various automated widow-handling
                  techniques.
        }\label{fig:demo}
    \end{sidewaysfigure}

    \section{Alternate removal strategies}

    There have been a few previous attempts to improve upon \TeX's
    previously discussed \wao/-handling abilities; however, none of these
    have been able to automatically remove \waos/ without stretching any vertical glue
    or shortening any pages.

    The articles \titlecite{Isambert:TB31-1-12} and \titlecite{mittelbach} both
    begin with comprehensive discussions of the methods of preventing \waos/.
    They agree that \waos/ are bad and ought to be avoided; however, they
    differ in their solutions. \textsl{Strategies}~proposes an output routine
    that reduces the length of facing pages by one line when necessary to
    remove \waos/, while \textsl{Managing}~proposes that the author manually
    rewrites or adjusts \lsness/ when needed.

    The post \titlecite{widow-assist} contains a file
    \verb|widow-assist.lua| that
    automatically detects which paragraphs can be safely shortened or
    lengthened by one line. The \textsf{widows-and-orphans}
    package~\cite{widows-and-orphans} alerts the author to
    the pages that contain widows or orphans. Combined, these packages make
    it simple for the author to quickly remove \waos/ by adjusting the
    values of \lsness/; however, it still requires the author to make manual
    source changes after each revision.

    Another article suggests a fully-automated solution to remove
    \waos/~\cite{global}. This would seem to offer a complete solution; however,
    it requires multiple passes, an external tool, and has not yet been publicly
    released.

    \Lwc/ is essentially a combination of
    \verb|widow-assist.lua|~\cite{widow-assist} and
    \textsf{widows-and-orphans}~\cite{widows-and-orphans}, although its
    implementation is independent of both: when the \openalty/
    value indicates
    that a \woo/ has occurred, Lua is used to find a stretchable paragraph. What
    \lwc/ mainly adds on top of these packages is automation: it eliminates the
    requirement for any manual adjustments or changes to your document's
    source.

    \section{Visual comparison}

    Although \TeX{}'s page breaking algorithm is reasonably
    straightforward, it can lead to
    complex behaviour when \waos/ are involved. The usual
    choices, when rewriting is not possible, are to ignore them,
    stretch some glue, or shorten the
    page. Figure~\ref{fig:demo} has a visual comparison of these
    options, which we'll discuss in the following:

    \subsection{Ignore}

    As you can see, the last line of the page is on a separate page from the
    rest of its paragraph, creating a widow. This is usually highly
    distracting for the reader, so it is best avoided for the reasons previously
    discussed.

    \subsection{Shorten}

    This page did not leave any widows, but it did shorten the previous page
    by one line. Sometimes this is acceptable, but usually it looks bad because
    pages will then have different text-block heights. This can make the pages
    look quite uneven, especially when typesetting with columns or in a book
    with~facing~pages.
    \oldlooseness=1

    \subsection{Stretch}

    This page also has no widows and it has a flush bottom margin. However,
    the space between each pair of paragraphs had to be stretched.

    If this page had many equations, headings, and other elements with
    natural space between them, the stretched out space would be much less
    noticeable. \TeX{} was designed for mathematical typesetting, so it makes
    sense that this is its default behaviour. However, in a page with mostly
    text, these paragraph gaps look unsightly.

    Also, this method is incompatible with grid typesetting, where
    all vertical glue stretching must be quantised to the height of a line.

    \subsection{\lwc/}

    \Lwc/ has none of these issues: it eliminates the widows in a document
    while keeping a flush bottom margin and constant paragraph spacing.

    To do so, \lwc/ lengthened the second paragraph in Figure~\ref{fig:demo} by
    one line. If you look closely, you can see that this stretched the
    interword spaces. This stretching is noticeable when typesetting in a
    narrow text block, but is mostly imperceptible with larger widths.

    \Lwc/ automatically finds the \q{best} paragraph to stretch, so the
    increase in interword spaces should almost always be minimal.

    \section{Installation and standard usage}

    The \lwc/ package was first released in
    October~2021. It is available in the default installations of both
    MiK\TeX{} and \TeX{}~Live, although you will need recent versions
    of either.

    You may also download \lwc/ manually from either
    \inlineurl[ctan.org/pkg/lua-widow-control]{\acro{CTAN},}
    the \inlineurl%
    [modules.contextgarden.net/cgi-bin/module.cgi/action=view/id=127]%
    {\ConTeXt{} Garden,} or \inlineurl%
    [github.com/gucci-on-fleek/lua-widow-control/releases/latest/]%
    {GitHub,} although it is best if you can install it through your
    \TeX~distribution.

    As its name may suggest, \lwc/ \textit{requires} Lua\TeX{} or
    \LuaMeta\TeX{} regardless of the format used.
    With that in mind, using \lwc/ is quite simple:

    \begin{tabular}{rl}
        Plain \TeX{} &
        \cs{input lua-widow-control}\phantom{\tt]} \\
        \OpTeX {} &
        \cs{load[lua-widow-control]} \\
        \LaTeX{} &
        \latexuse/ \\
        \ConTeXt{} &
        \cs{usemodule[lua-widow-control]} \\
    \end{tabular}

    And that's usually enough. Most users won't need to do anything else since
    \lwc/ comes preconfigured and ready-to-go.

    \section{Options}

    Nevertheless, \lwc/ does have a few options.

    \Lwc/ tries very hard to have a \q{natural} user interface with each
    format, so how you set an option heavily depends on how you are running
    \lwc/. Also note that not every option is available in every format.

    Some general guidelines:

    \begin{tabularx}\linewidth{rX}
        \plainop/ & Specially-named \cs{lwc}\meta{option} commands and
                    registers are provided for all options. \\[4pt]
        \LaTeX{} & Options can be set either as package options or at
                   any point in the document with \cs{lwcsetup}. \\[4pt]
        \ConTeXt{} & Always use \cs{setuplwc}.
    \end{tabularx}

    \subsection{Disabling}

    You may want to disable \lwc/ for certain portions of your
    document. You can do so with the following commands:

    \begin{tabular}{rl}
        \plainop/ &
        \cs{lwcdisable} \\
        \LaTeX{} &
        \cs{lwcsetup\{disable\}} \\
        \ConTeXt{} &
        \cs{setuplwc[state=stop]}\hphantom{\texttt{a}} \\
    \end{tabular}

    This prevents \lwc/ from stretching any paragraphs that follow. If a page
    has earlier paragraphs where \lwc/ was still enabled and a \woo/ is
    detected, \lwc/ will still attempt to remove the \woo/.

    \subsection{Enabling}

    \Lwc/ is enabled as soon as the package is loaded. If you have previously
    disabled it, you will need to re-enable it to save new paragraphs.

    \begin{tabular}{rl}
        \plainop/ &
        \cs{lwcenable} \\
        \LaTeX{} &
        \cs{lwcsetup\{enable\}} \\
        \ConTeXt{} &
        \cs{setuplwc[state=start]} \\
    \end{tabular}

    \subsection{Automatically disabling}

    You may want to disable \lwc/ for certain commands where
    stretching is undesirable such as section headings. Of course, manually
    disabling and
    then enabling \lwc/ multiple times
    throughout a document would quickly become tedious, so \lwc/ provides
    some options to do this automatically for you.

    \Lwc/ automatically patches the default \LaTeX{}, \ConTeXt{},
    Plain \TeX{}, \OpTeX{}, \textsf{\mbox{memoir}},
    \textsf{KOMA-Script}, and \textsf{titlesec} section commands, so you don't
    need to patch these.  Any others, though, you'll need to patch yourself.

    \begin{tabular}{rl}
        \plainop/ & \cs{lwcdisablecmd\{\meta{\texttt{\char`\\}macro}\}} \\[4pt]
        \LaTeX{} & \cs{lwcsetup\{disablecmds=\{\texttt{\meta{csnameone},%
        \meta{csnametwo}\}\}}} \\[4pt]
        \ConTeXt{} &
        \cs{prependtoks\textbackslash{}lwc@patch@pre}\cs{to\textbackslash{}everybefore\meta{hook}} \\
        & \cs{prependtoks\textbackslash{}lwc@patch@post}\cs{to\textbackslash{}everyafter\meta{hook}} \\
    \end{tabular}

    \subsection{\estretch/}

    \Lwc/ defaults to an \estretch/ value of 3~em for stretched paragraphs,
    but you can configure this.

    \Lwc/ will only use the \estretch/ when it cannot extend a paragraph in
    any other way, so it is fairly safe to set this to a large value.  \TeX{}
    accumulates badness when \estretch/ is used~\cite{Knuth:TB10-3-325}, so
    it's pretty rare that a paragraph that requires any \estretch/ will
    actually be used on the page.

    \begin{tabular}{rr@=l}
        \plainop/ & \cs{lwcemergencystretch} & \meta{dimension} \\
        \LaTeX{} &
        \cs{lwcsetup\{emergencystretch} & \meta{dimension}\texttt{\}} \\
        \ConTeXt{} &
        \cs{setuplwc[emergencystretch} & \meta{dimension}\texttt{]} \\
    \end{tabular}

    \subsection{Penalties}

    You can also manually adjust the penalties that \TeX{} assigns to \waos/.
    Usually, the defaults are fine, but there are a few circumstances where you
    may want to change them.

    \begin{longtable}{rr@{\texttt{=\meta{integer}}}l}
        \plainop/ & \cs{widowpenalty} \\*
        & \cs{clubpenalty} \\*
        & \cs{brokenpenalty} \\[4pt]
        \LaTeX{} &
        \cs{lwcsetup\{ widowpenalty} & \texttt{\}} \\*
        & \cs{lwcsetup\{orphanpenalty} & \texttt{\}} \\*
        & \cs{lwcsetup\{brokenpenalty} & \texttt{\}} \\[4pt]
        \leavevmode\hbox{\ConTeXt{}} &
        \cs{setuplwc[ widowpenalty} & \texttt{]} \\*
        & \cs{setuplwc[orphanpenalty} & \texttt{]} \\*
        & \cs{setuplwc[brokenpenalty} & \texttt{]} \\
    \end{longtable}

    The value of these penalties determines how much \TeX{} should attempt to
    stretch glue before passing the \woo/ to \lwc/. If you set the values to~1
    (default), \TeX{} will stretch nothing and immediately trigger \lwc/; if you
    set the values to 10\,000, \TeX{} will stretch infinitely and \lwc/ will
    never be triggered. If you set the value to some intermediate number, \TeX{}
    will first attempt to stretch some glue to remove the \woo/; only if it
    fails will \lwc/ come in and lengthen a paragraph. As a special case, if you
    set the values to~0, both \TeX{} and \lwc/ will completely ignore the \woo/.

    \Lwc/ will pick up on the values of \cs{widowpenalty}, \cs{clubpenalty}, and
    \cs{brokenpenalty} regardless of how you set them, so the use of these
    dedicated keys is entirely optional.

    \subsection{\cs{nobreak} behaviour}

    When \lwc/ encounters an orphan, it removes it by moving the orphaned line
    to the next page. The majority of the time, this is an appropriate solution.
    However, if the orphan is immediately preceded by a section heading (or
    \cs{nobreak}\slash\cs{penalty 10000}), \lwc/ would na\"ively separate a
    section heading from the paragraph that follows. This is almost always
    undesirable, so \lwc/ provides some options to configure this.

    \begin{tabular}{rl}
        \plainop/ &
        \cs{lwcnobreak\{\meta{value}\}} \\
        \LaTeX{} &
        \cs{lwcsetup\{nobreak=\meta{value}\}\hphantom{"}} \\
        \ConTeXt{} &
        \cs{setuplwc[nobreak=\meta{value}]\hphantom{"}} \\
    \end{tabular}

    The default value, \texttt{keep}, \emph{keep}s the section heading with
    the orphan by moving both to the next page. The advantage to this option
    is that it removes the orphan and retains any \cs{nobreak}s; the
    disadvantage is that moving the section heading can create a large blank
    space at the end of the page.
    The value \texttt{split} \emph{split}s up the section heading and the
    orphan by moving the orphan to the next page while leaving the heading
    behind. This is usually a bad idea, but exists for the sake of
    flexibility.
    The value \texttt{warn} causes \lwc/ to give up on the page and do nothing,
    leaving an orphaned line. \Lwc/ \emph{warn}s the user so that they can
    manually remove the orphan.

    See Figure~\ref{tab:nobreak} for a visual reference.

    \begin{figure}
        \renewcommand{\arraystretch}{1}
        \renewcommand{\doublerulesep}{0.5em}
        \begin{tabularx}{\linewidth}{%
            |X|@{\hskip\doublerulesep}|X|@{\hskip\doublerulesep}|X|%
        }
            \multicolumn1c{\ttfamily keep} &
            \multicolumn1c{\ttfamily split} &
            \multicolumn1c{\ttfamily warn}
            \\ \hhline{-||-||-}
            &
            &
            \textbf{Heading} \\
            &
            \textbf{Heading} &
            The\hfill very\hfill first\hfill line
            \\ \hhline{-||-||-}
            \textbf{Heading} &
            The\hfill very\hfill first\hfill line &
            text\hfill text\hfill text\hfill text \\
            The\hfill very\hfill first\hfill line &
            text\hfill text\hfill text\hfill text &
            last line. \\
            text\hfill text\hfill text\hfill text &
            last line. &
            % Nothing
            \\ \hhline{-||-||-}
        \end{tabularx}
        \caption{A visual comparison of the \texttt{nobreak} option values.}
        \label{tab:nobreak}
    \end{figure}

    \subsection{Maximum cost}

    \Lwc/ ranks each paragraph on the page by how much it would \q{cost} to
    lengthen that paragraph. By default, \lwc/ selects the paragraph on
    the page with the lowest cost; however, you can configure it to only
    select paragraphs below a selected cost.

    If there aren't any paragraphs below the set threshold, then \lwc/ won't
    remove the \woo/ and will instead issue a warning.

    \begin{tabular}{rr@{\texttt{=\meta{integer}}}l}
        \plainop/ &
        \cs{lwcmaxcost} \\
        \LaTeX{} &
        \cs{lwcsetup\{max-cost} & \texttt{\}} \\
        \leavevmode\hbox{\ConTeXt{}} &
        \cs{setuplwc[maxcost} & \texttt{]} \\
    \end{tabular}

    Based on my testing, \texttt{max-cost} values less than 1\,000 cause
    completely imperceptible changes in interword spacing; values less than
    5\,000 are only noticeable if you are specifically trying to pick out the
    expanded paragraph on the page; values less than 15\,000 are typically
    acceptable; and larger values may become distracting. \Lwc/ defaults to an
    infinite \texttt{max-cost}, although the \q{strict} and \q{balanced} modes
    sets the values to~5\,000 and 10\,000, respectively.

    \subsection{Draft mode}

    \Lwc/ has a \q{draft mode} which shows how \lwc/ processes pages.

    \begin{tabular}{rl}
        Plain \TeX{}\slash\OpTeX{} &
        \cs{lwcdraft 1} \\
        \LaTeX{} &
        \cs{lwcsetup\{draft\}} \\
        \ConTeXt{} &
        \cs{setuplwc[draft=start]} \\
    \end{tabular}

    The draft mode has two main features:

    First, it colours lines in the document according to their status. Any
    remaining widows and orphans will be coloured red, any expanded paragraphs
    will be coloured green, and any lines moved to the next page will be
    coloured blue.

    Second, this draft mode shows the paragraph costs at the end of each
    paragraph, in the margin.

    This draft mode leads to a neat trick: if you don't quite trust \lwc/, or
    you're writing a document whose final version will need to be compilable by
    both pdf\LaTeX{} and Lua\LaTeX, you can load the package with:

    \smallskip
    \cs{usepackage[draft, disable]\{lua-widow-control\}}
    \smallskip

    \noindent This way, all the widows and orphans will be coloured red and
    listed in your log file. When you go through the document to try and
    manually remove the widows and orphans---whether through the \cs{looseness}
    trick or by rewriting certain lines---you can easily find the best
    paragraphs to modify by looking at the paragraph costs in the margins. If
    you're less cautious, you can compile your document with
    \textsf{lua-widow-control} enabled as normal and inspect all the green
    paragraphs to see if they look acceptable to you.

    You can also toggle the paragraph colouring and the cost displays
    individually:

    \begin{tabular}{rl}
        \plainop/ &
        \cs{lwcshowcosts 1} \\
        & \cs{lwcshowcolours 0} \\[4pt]
        \LaTeX{} &
        \cs{lwcsetup\{showcosts=true\}} \\
        & \cs{lwcsetup\{showcolours=false\}} \\[4pt]
        \ConTeXt{} &
        \cs{setuplwc[showcosts=start]} \\
        & \cs{setuplwc[showcolours=stop]} \\
    \end{tabular}

    \section{Presets}

    As you can see, \lwc/ provides quite a few options. Luckily, there are a few
    presets that you can use to set multiple options at once. These presets are
    a good starting point for most documents, and you can always manually
    override individual options.

    These presets are only available for \LaTeX{} and \ConTeXt{}.

    \begin{tabular}{@{}rl@{}}
        \LaTeX{} &
        \cs{lwcsetup\{\meta{preset}\}} \\
        \ConTeXt{} &
        \cs{setuplwc[\meta{preset}]} \\
    \end{tabular}

    \subsection{\texttt{default}}

    If you use \lwc/ without any options, it defaults to this preset. In default
    mode, \lwc/ takes all possible measures to remove \waos/ and will not
    attempt to stretch any vertical glue. This usually
    removes~$\mathord{>}\,95\%$ of all
    possible \waos/. The catch here is that this mode is quite aggressive, so
    it often leaves behind some fairly \q{spacey} paragraphs.

    This mode is good if you want to remove (nearly) all \waos/ from your
    document, without fine-tuning the results.

    \subsection{\texttt{strict}}

    \Lwc/ also offers a strict mode. This greatly restricts \lwc/'s tolerance
    and makes it so that it will only lengthen paragraphs where the change will
    be imperceptible.

    The caveat with strict mode is that---depending on the document---\lwc/ will
    be able to remove less than a third of the \waos/. For the \waos/ that can't
    be automatically removed, a warning will be printed to your terminal and log
    file so that a human can manually fix the situation.

    This mode is good if you want the best possible typesetting and are willing
    to do some manual editing.

    \subsection{\texttt{balanced}}

    Balanced mode sits somewhere between default mode and strict mode. This mode
    first lets \TeX{} stretch a little glue to remove the \woo/; only if that
    fails will it then trigger \lwc/. Even then, the maximum paragraph cost is
    capped. Here, \lwc/ can usually remove 90\% of a document's
    potential \waos/, and it does so while making a minimal visual impact.
    \oldlooseness=-1

    This mode is recommended for most users who care about their document's
    typography. This mode is not the default since it doesn't remove all
    \waos/: it
    still requires a little manual intervention.

    \begin{table}
        \caption{\Lwc/ options set by each mode.}\label{tab:modes}
        \ttfamily\setlength{\tabcolsep}{4pt}
        \begin{tabular}{l*3r}\toprule
            \textrm{Option} & default & balanced & strict \\ \midrule
            max-cost & $\infty$ & 10000 & 5000 \\
            \rlap{emergencystretch} & 3em & 1em & 0pt \\
            nobreak & keep & keep & warn \\
            widowpenalty & 1 & 500 & 1 \\
            orphanpenalty & 1 & 500 & 1 \\
            brokenpenalty & 1 & 500 & 1 \\
        \bottomrule\end{tabular}
    \end{table}

    \section{Compatibility}

    The \lwc/ implementation is almost entirely in Lua, with only a minimal
    \TeX{} footprint. It doesn't modify the output routine or \cs{everypar} and
    it doesn't insert any whatsits. This means that it should be compatible with
    nearly any \TeX{} package, class, and format. Most changes that \lwc/ makes
    are not observable on the \TeX{} side.

    However, on the Lua side, \lwc/ modifies much of a page's internal
    structure. This should not affect any \TeX{} code; however, it may surprise
    Lua code that modifies or depends on the page's low-level structure. This
    does not affect Plain~\TeX{} or \LaTeX{} where even most Lua-based packages
    don't depend on the node list structure. \ConTeXt{} \emph{does} depend on
    this internal node structure; however, I have carefully tested the package
    to ensure that this causes no issues.

    Finally, keep in mind that adding \lwc/ to a document will almost certainly
    change its page break locations.

    \subsection{Formats}

    \Lwc/ runs on all known Lua\TeX{}-based formats: Plain~Lua\TeX{},
    Lua\LaTeX{}, \ConTeXt{} Mk\acro{IV}, and~\OpTeX{}. Unless otherwise
    documented, all features should work equally well in all formats.

    \Lwc/ is also fully-compatible with the \LuaMeta\TeX{}-based formats:
    \ConTeXt{} Mk\acro{XL}\slash\acro{LMTX}, \LuaMeta\LaTeX{}, and
    \LuaMeta{}Plain~\cite{luametalatex}. \ConTeXt{} Mk\acro{XL} works equally
    well as \ConTeXt{} Mk\acro{IV} and Lua\LaTeX{}; however, \LuaMeta\LaTeX{}
    and \LuaMeta{}Plain support is still quite early. All features should work,
    although there are still a few minor bugs.

    All told, \lwc/ supports 7 different format\slash{}engine combinations.

    \subsection{Columns}

    Since \TeX{} and the formats implement column breaking and page
    breaking through the
    same internal mechanisms, \lwc/ removes \waos/ between columns just
    as it does with \waos/ between pages.

    \Lwc/ is known to work with the \LaTeX{} class option \verb|twocolumn|
    and the two-column output routine from Chapter~23 of \titlecite{texbook}.
    \oldlooseness=-1

    \subsection{Performance}

    \Lwc/ runs entirely in a single pass, without depending on any
    \verb|.aux| files or the like. Thus, it shouldn't meaningfully
    increase compile times. Although \lwc/ internally breaks each paragraph
    twice, modern computers break paragraphs near-instantaneously, so you
    are not likely to notice any slowdown.

    \Lwc/ has been carefully tested to ensure that there are no memory leaks, so
    \lwc/ can now easily compile documents $>10\,000$ pages long.

    \vspace*{-1pt}

    \subsection{\eTeX{} penalties}

    Knuth's original \TeX{} has three basic line penalties:
    \cs{interlinepenalty}, which
    is inserted between all lines; \cs{club\-penalty}, which is inserted after
    the first line; and \cs{widow\-penalty}, which is inserted before the last
    line. The \eTeX{} extensions~\cite{etex} generalize these commands with a
    syntax similar to \cs{parshape}: with \cs{widow\-penalties} you can set the
    penalty between the last, second last, and $n$th last lines of a paragraph;
    \cs{inter\-line\-penalties} and \cs{club\-penalties} behave similarly.

    The \lwc/ package makes no explicit attempts to support these new
    -\texttt{penalties} commands. Specifically, if you give a line a penalty
    that matches either \cs{widowpenalty} or \cs{clubpenalty}, \lwc/ will treat
    the lines exactly as it would a \woo/. So while these commands won't break
    \lwc/, they are likely to lead to some unexpected behaviour.

    \vspace*{-3pt}

    \section{Short last lines}

    \vspace*{-1pt}

    When lengthening a paragraph with \lsness/, it is common advice to insert
    ties (\verb|~|) between the last few words of the paragraph to avoid
    overly-short last lines \cite{texbook}. \Lwc/ does this automatically,
    but instead of using ties or \cs{hbox}es, it uses the
    \cs{par\allowbreak fill\allowbreak skip}
    parameter~\cite{texbook, Wermuth:2018:ECP, naruby}. When lengthening a paragraph
    (and only when lengthening a paragraph---remember, \lwc/ doesn't
    interfere with \TeX{}'s output unless it detects a \woo/), \lwc/ sets
    \cs{parfillskip} to \verb|0.75\hsize plus 0.05\hsize minus 0.75\hsize|.
    This normally makes the last line of a paragraph be at least
    20\% of the overall paragraph's width, thus preventing
    ultra-short~lines.

    \vspace*{-3pt}

    \section{How it works}

    \vspace*{-1pt}

    \Lwc/ uses a fairly simple algorithm to eliminate \waos/, but there
    are a few subtleties.

    \vspace*{-1pt}

    \subsection{Setup}

    \Lwc/ sets the \cs{club\-penalty}, \cs{widow\-penalty}, and
    \cs{broken\-penalty} parameters to sentinel values of~1. This  will signal
    to \lwc/ when a \woo/ occurs, yet it is small enough that it won't stretch
    any glue.

    \Lwc/ also enables Lua\TeX{}'s micro\-typographic
    extensions~\cite{thanh}. This isn't strictly necessary;
    however, it significantly increases the number of paragraphs that can
    be acceptably \q{loosened}.

    That is all that happens on the \TeX{} end. The rest of \lwc/ is pure Lua.

    \subsection{Paragraph breaking}

    First, \lwc/ hooks into the paragraph breaking process, before any output
    routines or page breaking.

    Before a paragraph is broken by \TeX{}, \lwc/ grabs the unbroken
    paragraph. Then \lwc/ breaks the paragraph one line longer than its natural
    length and stores it for later. It does this in the background,
    \emph{without} interfering with how \TeX{} breaks paragraphs into their
    natural length.

    After \TeX{} has broken its paragraph into its natural length, \lwc/
    appears again. Before the broken paragraph is added to the main
    vertical list, \lwc/ \q{tags} the first and last nodes of the paragraph
    using a Lua\TeX{} attribute. These attributes associate the
    previously-saved lengthened paragraph with the naturally-typeset
    paragraph on the page.

    \subsection{Page breaking}

    \Lwc/ intercepts \cs{box255} (the \cs{vbox} output by \TeX) immediately
    before the output routine runs,
    after all the paragraphs have been typeset.

    First, \lwc/ looks at the \openalty/ of the page or column. If the page
    was broken at a \woo/, the \openalty/ will be equal to either
    the \cs{widowpenalty} or the \cs{clubpenalty}. If the \openalty/ does not
    indicate a \woo/, \lwc/ will stop and return \cs{box255} unmodified to
    the output~routine, and \TeX{} continues as normal.

    Otherwise, we assume that we have a \woo/ on the page,
    meaning that we should lengthen the page by 1~line. We iterate through
    the list of saved paragraphs to find the lengthened paragraph with the
    least cost. After we've selected a good paragraph, we traverse
    through the page to find the original version of this paragraph---the
    one that unmodified \TeX{} originally typeset. Having found the original
    paragraph, we splice in the lengthened paragraph in place of the original.
    \oldlooseness=-1

    Since the page is now 1~line longer than it was before, we pull the last
    line off the page to bring it back to its original length, and place
    that line onto the top of \TeX's \q{recent contributions} list. When
    the next page begins, this line will be inserted before all other
    paragraphs, right at the top. Now, we can return the new, widow-free page
    (updated \cs{box255}) to the output routine, which proceeds
    as normal.

    \subsection{Footnotes}
    Earlier versions of \textsf{lua-widow-control} completely ignored inserts.
    This meant that if a moved line had associated footnotes,
    \textsf{lua-widow-control} would move the \q{footnote mark} but not the
    associated \q{footnote text}. \textsf{lua-widow-control} now handles
    footnotes correctly through the mechanism detailed in the next section.

    \subsubsection{Inserts}

    Before we go into the details of how \textsf{lua-widow-control} handles
    footnotes, we need to look at what footnotes actually are to \TeX{}. Every
    \cs{footnote} command ultimately expands to something like
    \cs{insert\meta{class}}\allowbreak\verb|{|\meta{content}\verb|}|, where
    \meta{class} is an insertion class number, defined as \cs{footins} in this
    case (in Plain \TeX\ and \LaTeX). Inserts can be found in horizontal mode
    (footnotes) or in vertical mode (\cs{topins} in Plain \TeX{} and floats in
    \LaTeX{}), but they cannot be inside boxes. Each of these insert types is
    assigned a different class number, but the mechanism is otherwise identical.
    \textsf{lua-widow-control} treats all inserts identically, although it
    safely ignores vertical mode inserts since they are only ever found between
    paragraphs.

    But what does \cs{insert} do exactly? When \TeX{} sees an \cs{insert}
    primitive in horizontal mode (when typesetting a paragraph), it does two
    things: first, it processes the insert's content and saves it invisibly just
    below the current line. Second, it effectively adds the insert content's
    height to the height of the material on the current page. Also, for the
    first insert on a page, the glue in \cs{skip}\meta{class} is added to the
    current height. All this is done to ensure that there is sufficient room for
    the insert on the page whenever the line is output onto the page.

    If there is absolutely no way to make the insert fit on the page---say,
    if you placed an entire paragraph in a footnote on the last line of a
    page---then \TeX{} will begrudgingly \q{split} the insert, placing the first
    part on the current page and \q{holding over} the second part until the next
    page.

    There are some other \TeX{}nicalities involving \cs{count}\meta{class} and
    \cs{dimen}\meta{class}, but they mostly don't affect
    \textsf{lua-widow-control}. See Chapter~15 in \textsl{The \TeX{}book} or another reference for
    all the details.

    After \TeX{} has chosen the breakpoints for a paragraph, it adds the chosen
    lines one by one to the current page. Whenever the accumulated page height
    is \q{close enough} to the target page height (normally \cs{vsize}) the
    \cs{output} token list (often called the ``output routine'') is expanded.

    But before \cs{output} is called, \TeX{} goes through the page contents and
    moves the contents of any saved inserts into \cs{vbox}es corresponding to
    the inserts' classes, namely \cs{box}\meta{class}, so \cs{output} can work
    with them.

    And that's pretty much it on the engine side. Actually placing the inserts
    on the page is reserved for the output routine, which is defined by the
    format. This too is a complicated process, although thankfully not one that
    \textsf{lua-widow-control} needs to worry about.

    \subsubsection{\LuaMeta\TeX{}}

    The \LuaMeta\TeX{} engine treats inserts slightly differently than
    traditional \TeX{} engines. The first major difference is that insertions
    have dedicated registers; so instead of \cs{box}\meta{class}, \LuaMeta\TeX{}
    has \cs{insertbox}\meta{class}; instead of \cs{count}\meta{class},
    \LuaMeta\TeX{} has \cs{insertmultiplier}\meta{class}; etc. The second major
    difference is that \LuaMeta\TeX{} will pick up inserts that are inside of
    boxes, meaning that placing footnotes in things like tables or frames should
    mostly just work as expected.

    There are also a few new parameters and other minor changes, but the overall
    mechanism is still quite similar to traditional \TeX{}.

    \subsubsection{Paragraph breaking}

    As stated in the original article~\cite{tb133chernoff-widows},
    \textsf{lua-widow-control} intercepts \TeX{}'s output immediately before
    the output routine. However, this is \emph{after} all the inserts on the
    page have been processed and boxed. This is a bit of a problem because if
    we move a line to the next page, we need to move the associated insert;
    however, the insert is already gone.

    To solve this problem, immediately after \TeX{} has naturally broken a
    paragraph, \textsf{lua-widow-control} copies and stores all its inserts.
    Then, \textsf{lua-widow-control} tags the first element of each line
    (usually a glyph) with a Lua\TeX{} attribute that contains the indices for
    the first and last associated insert. \textsf{lua-widow-control} also tags
    each line inside the insert's content with its corresponding index so that
    it can be found later.

    \subsubsection{Page breaking}

    Here, we follow the same algorithm as in the original
    article~\cite{tb133chernoff-widows}. However, when we move the last line of
    the page to the next page, we first need to inspect the line to see if any
    of its contents have been marked with an insert index. If so, we need to
    move the corresponding insert to the next page. To do so, we unpack the
    attributes value to get all the inserts associated with this line.

    Using the stored insert indices and class, we can iterate through
    \cs{box}\meta{class} and delete any lines that match one of the current
    line's indices. We also need to iterate through the internal \TeX{} box
    \verb|hold_head|---the box that holds any inserts split onto the next
    page---and delete any matching lines. We can safely delete any of these
    lines since they are still stored in the original \cs{insert} nodes that we
    copied earlier.

    Now, we can retrieve all of our previously-stored inserts and add them to
    the next page, immediately after the moved line. Then, when \TeX{} builds
    that page, it will find these inserts and move their contents to the
    appropriate boxes

    \section{Choosing the \q{best} paragraph}

    As we discussed previously, \lwc/ lengthens the paragraph with the lowest
    cost. However, assigning a cost to each paragraph is not quite as simple as
    it sounds. Before we look at how \lwc/ assigns costs, let's look at how
    \TeX{} scores paragraphs when breaking them naturally.

    \subsection{How \TeX{} scores paragraphs}

    All glue in \TeX{} has a certain natural size: the size that it would be
    in an ideal scenario. However, most glue also has stretch and shrink
    components so that the glue can change in size to adapt to its
    surroundings. For each line, \TeX{} individually sums the total
    stretch/shrink for the line and the stretch/shrink that was actually used.
    We define the stretch/shrink ratio~$r$ as the quotient of the
    stretch/shrink used and the stretch/shrink available. Then the badness~$b$
    of a line is approximately defined as
    \begin{equation*}
        b = 100r^3.
    \end{equation*}
    This is the badness referenced in the commonly-seen
    \texttt{Underfull \cs{hbox}
    (badness 1234)} warnings that \TeX{} produces.

    \TeX{} calculates the badness for each line individually; however, we also
    need to assess the paragraph as a whole. To do so, \TeX{} defines the
    demerits for a whole paragraph~$d$ as approximately\footnotemark{} the sum
    of the squared badnesses for each line. The natural paragraph that \TeX{}
    breaks is the one that minimizes~$d$.

    \footnotetext{We ignore any additional demerits or penalties that
                  \TeX{} may add.}

    One important thing to realize is that demerits grow incredibly fast:
    demerits are proportional to the \emph{sixth} power of glue stretch. This
    means that you can expect to see extremely large demerit values, even for
    a relatively \q{good} paragraph.

    \subsection{Possible cost functions}

    Now, let's return to how \lwc/ assigns costs to each paragraph. This is
    surprisingly more complicated than it sounds, so we'll go through a few
    possible cost functions first.

    Here, we use $c$~for the cost of a paragraph, $d$~for the total demerits,
    and $l$~for the number of lines (\cs{prevgraf}).

    \subsubsection{The original implementation}

    The original implementation of \lwc/ used the simple cost function
    \begin{equation*}
        c = d.
    \end{equation*}
    This cost function works reasonably well, but has one major issue: it
    doesn't take into account the number of lines in the paragraph. The demerits
    for a paragraph is the sum of the demerits for each line. This means this
    cost function will prefer using shorter paragraphs since they tend to have
    fewer demerits. However, long paragraphs tend to have much more available
    glue stretch, so this strategy can lead to suboptimal solutions.

    \subsubsection{Scaling by the number of lines}

    Once I realized this issue, I tried correcting it by dividing by the number
    of lines in the paragraph to get the average demerits instead of the total
    demerits:
    \begin{equation*}
        c = \frac{d}{l}
    \end{equation*}
    This works better than the previous function, but still has an issue.
    If we have a fairly bad ten-line paragraph with total demerits $10d$ and an
    almost-equally bad two-line paragraph with total demerits $2d + 1$, then by
    this cost function, the ten-line paragraph will have a lower cost and will
    be chosen. This means that our page now has ten bad lines instead of two bad
    lines, which is not ideal.

    \subsubsection{Current implementation}

    Our first cost function, $c=dl^0$, doesn't consider the number of lines at
    all, while our second cost function, $c=dl^{-1}$, considers the number of
    lines too much. Splitting the difference between the two functions, we get
    the current implementation:
    \begin{equation*}
        c = \frac{d}{\sqrt{l}}
    \end{equation*}

    This solves the issue with the previous function, but it adds a new issue: given a
    short paragraph with a large number of demerits per line and a long
    paragraph with fairly few average demerits per line, this function will often
    choose the shorter line. Although this sounds bad, in practice it gives much
    better results since very bad short paragraphs are \emph{much} less noticeable than
    slightly bad long paragraphs.

    Of course, this new function may still not be quite perfect. \Lwc/ uses the
    \texttt{lwc.paragraph\_cost(demerits, lines)} Lua function to calculate a
    paragraph's cost; if you want, you can redefine this function to anything
    that you want.
    \oldlooseness=-1

    % I didn't arrive at this function through any sort of scientific testing;
    % rather, I picked the simplest function that I could think of that satisfies
    % the following two properties:
    % \begin{itemize}
    %     \item Given a long paragraph and a short paragraph with different
    %           average badnesses per line, prefer the one with the least average
    %           badness.
    %     \item Given two paragraphs with equal average badnesses per line,
    %           prefer the shorter one.
    % \end{itemize}

    \vspace*{-3pt}

    \section{Quantitative analysis}

    \vspace*{-1pt}

    \begin{figure}
        \begin{tikzpicture}\begin{axis}[
                ybar interval,
                xticklabels={1, ..., 15,
                             {$\,\ge\! 16$}},
                x tick label style={font=\small},
                y tick label style={font=\small},
                enlarge y limits=upper,
                enlarge x limits={abs=1},
                grid=none,
                scaled y ticks=base 10:-3,
                ytick scale label code/.code={},
                xlabel={Paragraph length (lines)},
                ylabel={Count (thousands)}
            ]
            \addplot+ [
                draw=black,
                fill=black!10,
                semithick,
            ] table {
                Length Count
                1      4429
                2      3704
                3      2045
                4      1320
                5      894
                6      717
                7      498
                8      406
                9      379
                10     251
                11     175
                12     152
                13     111
                14     95
                15     79
                16     437
                18     0
            };

            \filldraw [fill=black!25, draw=black] (16, 0) rectangle (18, 437);
        \end{axis}\end{tikzpicture}
        \caption{Histogram of natural paragraph lengths in the sample text.}
        \label{fig:hist}
    \end{figure}

    Let's look at some statistics for \lwc/. For testing, I
    downloaded the top~ten books on \textsl{Project Gutenberg},\footnotemark{}
    converted them to \LaTeX{} using \textsf{pandoc}, concatenated them into a
    single \textsf{article} file, and compiled twice. This gives us a \acro{PDF}
    with 1\,381~pages, 15\,692~paragraphs, 61\,865~lines, and 399~\waos/
    (if they aren't removed).
    \footnotetext{\textsl{Frankenstein},
                  \textsl{Pride and Prejudice},
                  \textsl{Alice's Adventures in Wonderland},
                  \textsl{The Great Gatsby},
                  \textsl{The Adventures of Sherlock Holmes},
                  \textsl{Simple Sabotage Field Manual},
                  \textsl{A Tale of Two Cities},
                  \textsl{The Picture of Dorian Gray},
                  \textsl{Moby Dick},
                  and \textsl{A Doll's House}.
    }

    This is a fairly challenging test: almost every third page has a \woo/, over
    half of the paragraphs have two lines or fewer, and the text block is set to
    the fairly wide \textsf{article} defaults. An average document is
    much less challenging for  \lwc/, so we can consider this to be a
    worst-case scenario.

    \vspace*{-1pt}

    \subsection{Widows and orphans removed}

    \begin{figure}
        \begin{tikzpicture}\begin{axis}[
                ybar=0pt,
                bar width=0.8,
                xtick=data,
                ylabel={Widows and orphans removed},
                xticklabels={
                    \shortstack[c]{\hfill Maximum\\\hfill possible},
                    \textsf{lwc} \texttt{default},
                    \texttt{balanced},
                    \LaTeX{},
                    \texttt{strict},
                },
                x tick label style={
                    font=\small,
                    rotate=45,
                    anchor=east,
                },
                enlarge x limits=0.2,
            ]
            \addplot+ [
                draw=black,
                fill=black!10,
                semithick,
            ] table [x expr=\coordindex, y index=0] {
                399
                392
                348
                179
                52
            };

            \filldraw [fill=black!25, draw=black]
                      (-0.4, 0) rectangle (0.4, 399);
        \end{axis}\end{tikzpicture}
        \divide\abovecaptionskip by 2
        \caption{The number of \waos/ removed by each method.}\label{fig:modes}
    \end{figure}

    When we run \LaTeX{} with its default settings on the file, 179~(47\%) of
    the \waos/ are removed. When we add \lwc/ with default settings, we remove
    392~(98\%). Switching to strict mode, we can only remove 52~(13\%) of the
    \waos/. In balanced mode, we remove 348~(87\%). See Figure~\ref{fig:modes}
    for a visual comparison.

    \subsection{Paragraph costs}

    \begin{figure}
        \begin{tikzpicture}\begin{axis}[
                xlabel={Percentile},
                ylabel={Cost},
                ymode=log,
                legend entries={Long, Natural},
                legend pos=north west,
                cycle list={
                    {black, thick},
                    {black!35, thick},
                },
            ]
            \addplot+ table [x=Percentile, y=Long] {\plotdata};
            \addplot+ table [x=Percentile, y=Natural] {\plotdata};

        \end{axis}\end{tikzpicture}
        \divide\abovecaptionskip by 2
        \caption{Paragraph costs by percentile rank for naturally-broken and
                 one-line lengthened paragraphs.}\label{fig:costs}
    \end{figure}

    The last section showed us that \lwc/ is quite effective at removing \waos/,
    so now let's look at the paragraphs that \lwc/ expands. As \TeX{}
    processes a document, \lwc/ is recording the costs for the naturally-broken
    and expanded versions of each paragraph in the document. Costs don't
    mean that much on their own, but a lower cost is always better.

    As you can see in Figure~\ref{fig:costs}, the
    lengthened paragraphs tend to have \emph{much} higher costs than the
    naturally-broken paragraphs. This is not surprising, since (as we've seen)
    a paragraph's demerits scale with the sixth power of glue stretch, so even
    a small amount of glue stretch can cause a huge increase in demerits.

    The empty space on the left of the \q{long} line is from the paragraphs
    that \lwc/ was unable to lengthen at any cost. Lua\TeX{} assigns these
    paragraphs zero~demerits, so they disappear on a logarithmic plot.

    \subsection{Lengthening vs.\ shortening paragraphs}
    \begin{figure}[t]
        \begin{tikzpicture}\begin{axis}[
                xbar stacked,
                height=0.15\linewidth,
                width=\dimexpr\linewidth-1em,
                scale only axis,
                bar width=1,
                enlargelimits=false,
                xmin=0,
                ymin=-0.5,
                ymax=1,
                ymajorticks=false,
                xtick style={draw=none},
                xlabel={Paragraphs (thousands)},
                scaled x ticks=base 10:-3,
                xtick scale label code/.code={},
                legend style={at={(0.5,1)}, anchor=north},
                legend columns=5,
                legend cell align=left,
                legend style={
                    /tikz/every even column/.append style={column sep=1em},
                    draw=none,
                    fill=none,
                },
                legend entries={
                    {$n=1$},
                    {$n$},
                    {$n+1$},
                    {$n\pm1$},
                    {$n-1$}
                },
            ]
            \addplot [fill=black!10           ] coordinates {(4429, 0)}; % One
            \addplot [fill=white              ] coordinates {(4474, 0)}; % None
            \addplot [pattern=north east lines] coordinates {(5457, 0)}; % Long
            \addplot [pattern=crosshatch      ] coordinates {( 482, 0)}; % Both
            \addplot [pattern=north west lines] coordinates {( 850, 0)}; % Short
        \end{axis}\end{tikzpicture}
        \divide\abovecaptionskip by 2
        \caption{The number of paragraphs in the test sample that
                 (respectively) have exactly
                 one line, cannot be stretched or shrunk, can be only stretched
                 by one~line, can be either stretched or shrunk, and can be
                 only shrunk.}
                 \label{fig:stretchshrink}
    \end{figure}

    Figure~\ref{fig:stretchshrink} shows the number of paragraphs that \lwc/
    could potentially stretch or shrink. The one-line paragraphs are broken out
    separately since this test sample has an anomalous number of them.
    Otherwise, we can see that \lwc/ is capable of stretching the majority of
    paragraphs.

    We can also see that of non-single-line paragraphs, only about 8\%
    of paragraphs can only be shrunk (the last segment of
    Figure~\ref{fig:stretchshrink}), and this is in a document where 13\%
    of paragraphs have at least eight~lines. Most documents rarely have
    such long paragraphs, and it is these long paragraphs that are the
    easiest to shrink.
    \oldlooseness=-1

    Because of this, \lwc/ doesn't even attempt to shrink paragraphs; it
    only stretches them.

    \vspace*{-10pt}

    \section{Known issues}

    \vspace*{-5pt}

    \Lwc/ is quite stable these days. At this point, all \emph{known} bugs have
    been resolved; some bugs certainly still remain, but I'd feel quite
    confident using \textsf{lua-widow-control} in your everyday documents. There
    are, however, some fundamental limitations due to how \lwc/ operates:

    \begin{itemize}
        \item When a three-line paragraph is at the end of a page forming a
        widow, \lwc/ will remove the widow; however, it will leave an orphan.
        This issue is inherent to any process that removes widows through
        paragraph expansion and is thus unavoidable. Orphans are considered
        to be better than widows~\cite{elements}, so this is still an
        improvement.

        \item Sometimes a \woo/ cannot be eliminated because no paragraph has
        enough stretch. Sometimes this can be remediated by
        increasing \lwc/'s \estretch/; however, some pages just don't have
        any suitable paragraph.

        Long paragraphs with short words tend to be stretchier than short
        paragraphs with long words since these long paragraphs have more
        interword glue. Narrow columns also stretch more easily than wide
        columns since you need to expand a paragraph by less to make a new line.

        \item \Lwc/ only attempts to expand paragraphs on a page with a \woo/. A
              global system like in~\titlecite{global} would solve this;
              however, this is both \acro{NP}-complete~\cite{plass} and
              impossible to solve in a single pass. Very rarely would such a
              system remove \woos/ that \lwc/ cannot.

        \item \textsf{lua-widow-control} won't properly move footnotes if there
          are multiple different ``classes'' of inserts on the same line. To the
          best of my knowledge, this shouldn't happen in any real-world
          documents. If this happens to be an issue for you, please let me know;
          this problem is relatively easy to fix, although it will add
          considerable complexity for what I think isn't a real issue.
          \oldlooseness=-1
    \end{itemize}

    \section{Conclusion}

    All this probably makes \lwc/ look quite complicated, and this is true to
    some extent. However, this complexity is hidden from the end~user:
    as stated at the outset, most
    users merely need to place \latexuse/ in their \LaTeX{} document
    preamble, and \lwc/ will remove all the troublesome \waos/, without needing
    any manual intervention.

    Should you have any issues, questions, or suggestions for \lwc/, please
    visit the project's GitHub page:
    \href{https://github.com/gucci-on-fleek/lua-widow-control}
         {\ttfamily https://github.com/gucci-on-fleek\discretionary{-}{-}{-}lua-widow-control}.
    Any feedback is greatly appreciated!

    \let\macro=\cs
    \AtNextBibliography{\small}
    \printbibliography

    \section*{Automatické odstraňování vdov a sirotků pomocí balíčku \textsf{lua-widow-control}}
    \begin{otherlanguage}{czech}
    Balíček \textsf{lua-widow-control} pro
    Lua\TeX\slash{}Lua\LaTeX\slash{}\ConTeXt\slash{}\OpTeX{} odstraňuje vdovy
    a sirotky bez dalšího zásahu uživatele. Využívá přitom sílu Lua\TeX u a přitom
    nenatahuje žádné vertikální mezery a ani nezkracuje stránky nebo sloupce.
    Namísto toho balíček automaticky prodlužuje některý z odstavců na té stránce
    nebo sloupci, kde by se vdova nebo sirotek vyskytli.

    Pro použití balíčku postačí většině uživatelů \LaTeX u uvést v~preambuli
    dokumentu \verb|\usepackage{lua-widow-control}|. Žádné další změny
    v~dokumentu nejsou zapotřebí.
    \end{otherlanguage}
    \klicovaslova: Lua\TeX, vdova, sirotek

\end{document}