summaryrefslogtreecommitdiff
path: root/macros/context/contrib/context-lua-widow-control
diff options
context:
space:
mode:
authorNorbert Preining <norbert@preining.info>2023-10-14 03:01:20 +0000
committerNorbert Preining <norbert@preining.info>2023-10-14 03:01:20 +0000
commit315010c30c0dab68a71ca741364438a7a0b1261f (patch)
tree1892d65e76bc025eede34669c33667d1e8c1f218 /macros/context/contrib/context-lua-widow-control
parent7c1335b7f300ea31a40bf83026d6b7d24d7bafc5 (diff)
CTAN sync 202310140301
Diffstat (limited to 'macros/context/contrib/context-lua-widow-control')
-rw-r--r--macros/context/contrib/context-lua-widow-control/VERSION1
-rw-r--r--macros/context/contrib/context-lua-widow-control/doc/luatex/lua-widow-control/README.md51
-rw-r--r--macros/context/contrib/context-lua-widow-control/doc/luatex/lua-widow-control/lua-widow-control.pdfbin0 -> 579606 bytes
-rw-r--r--macros/context/contrib/context-lua-widow-control/doc/luatex/lua-widow-control/lwc-zpravodaj.pdfbin0 -> 377831 bytes
-rw-r--r--macros/context/contrib/context-lua-widow-control/doc/luatex/lua-widow-control/tb133chernoff-widows.pdfbin0 -> 519495 bytes
-rw-r--r--macros/context/contrib/context-lua-widow-control/source/luatex/lua-widow-control/CHANGELOG.md186
-rw-r--r--macros/context/contrib/context-lua-widow-control/source/luatex/lua-widow-control/lwc-manual-samples.tex178
-rw-r--r--macros/context/contrib/context-lua-widow-control/source/luatex/lua-widow-control/lwc-manual.bib80
-rw-r--r--macros/context/contrib/context-lua-widow-control/source/luatex/lua-widow-control/lwc-manual.mkxl371
-rw-r--r--macros/context/contrib/context-lua-widow-control/source/luatex/lua-widow-control/lwc-manual.tex949
-rw-r--r--macros/context/contrib/context-lua-widow-control/source/luatex/lua-widow-control/lwc-zpravodaj-figure.ctx161
-rw-r--r--macros/context/contrib/context-lua-widow-control/source/luatex/lua-widow-control/lwc-zpravodaj.bib237
-rw-r--r--macros/context/contrib/context-lua-widow-control/source/luatex/lua-widow-control/lwc-zpravodaj.ltx1720
-rw-r--r--macros/context/contrib/context-lua-widow-control/source/luatex/lua-widow-control/tb133chernoff-widows-figure.ctx166
-rw-r--r--macros/context/contrib/context-lua-widow-control/source/luatex/lua-widow-control/tb133chernoff-widows-plot.dat1575
-rw-r--r--macros/context/contrib/context-lua-widow-control/source/luatex/lua-widow-control/tb133chernoff-widows.bib219
-rw-r--r--macros/context/contrib/context-lua-widow-control/source/luatex/lua-widow-control/tb133chernoff-widows.ltx1465
-rw-r--r--macros/context/contrib/context-lua-widow-control/tex/context/third/lua-widow-control/t-lua-widow-control.mkiv1
-rw-r--r--macros/context/contrib/context-lua-widow-control/tex/context/third/lua-widow-control/t-lua-widow-control.mkxl171
-rw-r--r--macros/context/contrib/context-lua-widow-control/tex/lualatex/lua-widow-control/lua-widow-control-2022-02-22.sty103
-rw-r--r--macros/context/contrib/context-lua-widow-control/tex/lualatex/lua-widow-control/lua-widow-control.sty331
-rw-r--r--macros/context/contrib/context-lua-widow-control/tex/luatex/lua-widow-control/lua-widow-control.lua1781
-rw-r--r--macros/context/contrib/context-lua-widow-control/tex/luatex/lua-widow-control/lua-widow-control.tex119
-rw-r--r--macros/context/contrib/context-lua-widow-control/tex/optex/lua-widow-control/lua-widow-control.opm88
24 files changed, 9953 insertions, 0 deletions
diff --git a/macros/context/contrib/context-lua-widow-control/VERSION b/macros/context/contrib/context-lua-widow-control/VERSION
new file mode 100644
index 0000000000..ad55eb85fc
--- /dev/null
+++ b/macros/context/contrib/context-lua-widow-control/VERSION
@@ -0,0 +1 @@
+v3.0.0
diff --git a/macros/context/contrib/context-lua-widow-control/doc/luatex/lua-widow-control/README.md b/macros/context/contrib/context-lua-widow-control/doc/luatex/lua-widow-control/README.md
new file mode 100644
index 0000000000..93f94449f5
--- /dev/null
+++ b/macros/context/contrib/context-lua-widow-control/doc/luatex/lua-widow-control/README.md
@@ -0,0 +1,51 @@
+<!-- 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
+-->
+
+lua-widow-control
+=================
+
+Lua-widow-control is a Plain TeX/LaTeX/ConTeXt/OpTeX package that removes widows and orphans without any user intervention. Using the power of LuaTeX, it does so _without_ stretching any glue or shortening any pages or columns. Instead, lua-widow-control automatically lengthens a paragraph on a page or column where a widow or orphan would otherwise occur.
+
+Please see the [**package manual**](https://github.com/gucci-on-fleek/lua-widow-control/releases/latest/download/lua-widow-control.pdf) for usage details or the [***TUGboat***](https://github.com/gucci-on-fleek/lua-widow-control/releases/latest/download/tb133chernoff-widows.pdf) or [***Zpravodaj* articles**](https://github.com/gucci-on-fleek/lua-widow-control/releases/latest/download/lwc-zpravodaj.pdf) for background information and discussion.
+
+Usage
+-----
+### Installation
+Lua-widow-control is included in TeX&nbsp;Live and MikTeX. Provided that you have an up-to-date installation, you should not need to explicitly install the package.
+
+If you are using ConTeXt or want to manually install the package, you may download it from one of the below links:
+
+|Latest Release|Other Releases|
+|--------------|--------------|
+|[GitHub](https://github.com/gucci-on-fleek/lua-widow-control/releases/latest/)|[GitHub](https://github.com/gucci-on-fleek/lua-widow-control/releases)|
+|[CTAN](https://www.ctan.org/pkg/lua-widow-control)||
+|[ConTeXt Garden](https://modules.contextgarden.net/cgi-bin/module.cgi/action=view/id=127)||
+
+### Usage
+To load the package, add the relevant line to your preamble:
+
+|Macro Package|Code |
+|-------------|--------------------------------|
+|LaTeX |`\usepackage{lua-widow-control}`|
+|ConTeXt |`\usemodule[lua-widow-control]` |
+|Plain TeX |`\input lua-widow-control` |
+|OpTeX |`\load[lua-widow-control]` |
+
+
+Contributing
+------------
+
+Please see [`CONTRIBUTING.md`](https://github.com/gucci-on-fleek/lua-widow-control/blob/master/CONTRIBUTING.md).
+
+Licence
+-------
+
+Lua-widow-control is licensed under the [_Mozilla Public License_, version 2.0](https://www.mozilla.org/en-US/MPL/2.0/) or greater. The documentation is additionally licensed under [CC-BY-SA, version 4.0](https://creativecommons.org/licenses/by-sa/4.0/legalcode) or greater.
+
+Please note that a compiled document is absolutely **not** considered to be an "Executable Form" as defined by the MPL. The use of lua-widow-control in a document does not place **any** obligations on the document's author or distributors. The MPL and CC-BY-SA licenses **only** apply to you if you distribute the lua-widow-control source code or documentation.
+
+---
+_v3.0.0 (2022-11-22)_ <!--%%version %%dashdate-->
diff --git a/macros/context/contrib/context-lua-widow-control/doc/luatex/lua-widow-control/lua-widow-control.pdf b/macros/context/contrib/context-lua-widow-control/doc/luatex/lua-widow-control/lua-widow-control.pdf
new file mode 100644
index 0000000000..ba428f1f01
--- /dev/null
+++ b/macros/context/contrib/context-lua-widow-control/doc/luatex/lua-widow-control/lua-widow-control.pdf
Binary files differ
diff --git a/macros/context/contrib/context-lua-widow-control/doc/luatex/lua-widow-control/lwc-zpravodaj.pdf b/macros/context/contrib/context-lua-widow-control/doc/luatex/lua-widow-control/lwc-zpravodaj.pdf
new file mode 100644
index 0000000000..1c37d25bf2
--- /dev/null
+++ b/macros/context/contrib/context-lua-widow-control/doc/luatex/lua-widow-control/lwc-zpravodaj.pdf
Binary files differ
diff --git a/macros/context/contrib/context-lua-widow-control/doc/luatex/lua-widow-control/tb133chernoff-widows.pdf b/macros/context/contrib/context-lua-widow-control/doc/luatex/lua-widow-control/tb133chernoff-widows.pdf
new file mode 100644
index 0000000000..e77e4df285
--- /dev/null
+++ b/macros/context/contrib/context-lua-widow-control/doc/luatex/lua-widow-control/tb133chernoff-widows.pdf
Binary files differ
diff --git a/macros/context/contrib/context-lua-widow-control/source/luatex/lua-widow-control/CHANGELOG.md b/macros/context/contrib/context-lua-widow-control/source/luatex/lua-widow-control/CHANGELOG.md
new file mode 100644
index 0000000000..37eee32f11
--- /dev/null
+++ b/macros/context/contrib/context-lua-widow-control/source/luatex/lua-widow-control/CHANGELOG.md
@@ -0,0 +1,186 @@
+<!-- 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
+-->
+
+Changelog
+=========
+
+All notable changes to lua-widow-control will be listed here, in reverse chronological order. **Changes listed in bold** are important changes: they either remove options or commands, or may change the location of page breaks.
+
+## v3.0.0 (2022-11-22)
+
+- Add the new _TUGboat_ and _Zpravodaj_ articles.
+
+- Add and document the public Lua interfaces.
+
+- Change `\parfillskip` settings for lengthened paragraphs to more strongly prevent short last lines. **May affect page breaks.**
+
+- Add the ability to configure the horizontal offset for the paragraph costs printed in draft mode.
+
+- Add support for [LuaMetaLaTeX and LuaMetaPlain](https://github.com/zauguin/luametalatex). All features should work identically to the LuaTeX-based version, although there are a few minor bugs. ([#40](https://github.com/gucci-on-fleek/lua-widow-control/pull/40))
+
+- Fully support inserts/footnotes in LuaMetaTeX ([#38](https://github.com/gucci-on-fleek/lua-widow-control/issues/38)).
+
+- Add support for presets in ConTeXt.
+
+- Add support for node colouring in ConTeXt and OpTeX ([#39](https://github.com/gucci-on-fleek/lua-widow-control/issues/39)).
+
+## [v2.2.2 (2022-08-23)](https://github.com/gucci-on-fleek/lua-widow-control/releases/tag/release-6c91837c205572a78a0bcaf9c80b8e475ef71689)
+
+- Add preliminary support for inserts/footnotes in LuaMetaTeX ([#38](https://github.com/gucci-on-fleek/lua-widow-control/issues/38)).
+
+- Use the built-in LaTeX key–value interface where available.
+
+ This means that lua-widow-control now also reads the global class options.
+
+- Add support for split footnotes ([#37](https://github.com/gucci-on-fleek/lua-widow-control/issues/37)).
+
+## [v2.2.1 (2022-07-28)](https://github.com/gucci-on-fleek/lua-widow-control/releases/tag/release-45c3146d5fc5a86606a931212395a28ffb48f925)
+
+- Fix crashes with recent LuaMetaTeX (ConTeXt MkXL). See also [this thread](https://mailman.ntg.nl/pipermail/ntg-context/2022/106331.html).
+- No longer show "left parfill skip" warnings with ConTeXt LMTX/MkXL ([#7](https://github.com/gucci-on-fleek/lua-widow-control/issues/7)).
+
+## [v2.2.0 (2022-06-17)](https://github.com/gucci-on-fleek/lua-widow-control/releases/tag/release-9a5deba53545adc5ab25a5caa0b8ebf4104843f9)
+
+- Fix paragraphs not being properly saved for potential expansion. **May affect page breaks.**
+- Add a new `draft` option ([#36](https://github.com/gucci-on-fleek/lua-widow-control/issues/36)).
+- Fix a node memory leak ([#29](https://github.com/gucci-on-fleek/lua-widow-control/issues/29)). You should now be able to use lua-widow-control on documents with > 10 000 pages.
+- Use `\lua_load_module:n` when available.
+- Add additional metadata to the documentation.
+
+
+## [v2.1.2 (2022-05-27)](https://github.com/gucci-on-fleek/lua-widow-control/releases/tag/release-3744f3e78bdf02fc63d508a0f80595260191607c)
+
+- Fully-support footnotes/inserts: lua-widow-control now moves the "footnote text" with the "footnote mark" when it moves a line to the next page.
+- No longer attempt to expand paragraphs in `\vbox`es
+- Minor documentation updates
+
+
+## [v2.1.1 (2022-05-20)](https://github.com/gucci-on-fleek/lua-widow-control/releases/tag/release-980f24ac64816bd0d453754f8f1af676f0f7ee99)
+
+- Prevent spurious `under/overfull \vbox` warnings when widows/orphans are removed
+- Add TUGboat article to the distributed documentation
+- Rewrite many portions of the manual
+- Add support for `luahbtex` and `mmoptex` ([#35](https://github.com/gucci-on-fleek/lua-widow-control/pull/35) [@vlasakm](https://github.com/vlasakm))
+- Fix the (undocumented) `microtype` LaTeX option
+
+
+## [v2.1.0 (2022-05-14)](https://github.com/gucci-on-fleek/lua-widow-control/releases/tag/release-82563aa0396805008059e3a96c2bf30b59c58026)
+
+- Fully support grid snapping in ConTeXt
+- New warnings when a new widow/orphan is inadvertently created
+- Significant internal rewrites
+- Add Plain and OpTeX interfaces to `\nobreak` behaviour and debug mode
+
+
+## [v2.0.6 (2022-04-23)](https://github.com/gucci-on-fleek/lua-widow-control/releases/tag/release-2aa9269b33a03f66d2ece634c3dcba6b258fddf0)
+
+- Emergency fix for renamed LMTX engine Lua functions
+- Internal LaTeX refactoring
+
+
+## [v2.0.5 (2022-04-13)](https://github.com/gucci-on-fleek/lua-widow-control/releases/tag/release-e3234ac7dfb31118d08fcb5ed0fe03f394df2b57)
+
+- Support nested `\lwcdisablecmd` macros
+- Fix `\lwcdisablecmd` in Plain TeX
+- Support command patching in OpTeX
+- Patch memoir to prevent spurious asterisks at broken two-line paragraphs ([#32](https://github.com/gucci-on-fleek/lua-widow-control/issues/32))
+
+
+## [v2.0.4 (2022-04-07)](https://github.com/gucci-on-fleek/lua-widow-control/releases/tag/release-8a0e97e448976280a38d41f92c2781320b1a91f0)
+
+- Don't expand paragraphs typeset during output routines ([#31](https://github.com/gucci-on-fleek/lua-widow-control/issues/31))
+
+
+## [v2.0.3 (2022-03-28)](https://github.com/gucci-on-fleek/lua-widow-control/releases/tag/release-d6622dd9fd04a4bc7678ff18420c1b4bdf077844)
+
+- Automatically patch section commands provided by memoir, KOMA-Script, and titlesec.
+
+
+## [v2.0.2 (2022-03-20)](https://github.com/gucci-on-fleek/lua-widow-control/releases/tag/release-7e79189406a2318c33dcaceb85d9d1021b357a3f)
+
+_Final release present in TeX Live 2021_
+
+- Add `balanced` mode preset.
+
+
+## [v2.0.1 (2022-03-18)](https://github.com/gucci-on-fleek/lua-widow-control/releases/tag/release-f3048dbcbfaf4d7d6f6a57e236cdb9684ff5d18d)
+
+- Documentation updates ([#25](https://github.com/gucci-on-fleek/lua-widow-control/issues/25))
+- Bug fixes ([#28](https://github.com/gucci-on-fleek/lua-widow-control/issues/28))
+
+
+## [v2.0.0 (2022-03-07)](https://github.com/gucci-on-fleek/lua-widow-control/releases/tag/release-cea06ddad8dfcf15fa9ba2a86c6640648b9df523)
+
+- **Page breaks may be slightly different**
+- **Removed `\lwcemergencystretch` and `\lwcdisablecmd` in LaTeX. Please use the new key–value interface**
+- Use expl3 for the LaTeX files ([#20](https://github.com/gucci-on-fleek/lua-widow-control/pull/20))
+- Use a key–value interface for configuration with LaTeX ([#11](https://github.com/gucci-on-fleek/lua-widow-control/issues/11))
+- Silence some extraneous `luatexbase` info messages
+- Add a "debug mode" to print extra information ([#12](https://github.com/gucci-on-fleek/lua-widow-control/issues/12))
+- Fix error message line wrapping
+- Don't reset `\interlinepenalty` and `\brokenpenalty`
+- Set and analyze `\displaywidowpenalty`
+- Keep section headings with moved orphans ([#17](https://github.com/gucci-on-fleek/lua-widow-control/issues/17))
+- Add the ability to configure the maximum paragraph cost ([#22](https://github.com/gucci-on-fleek/lua-widow-control/issues/22))
+- Add a "strict" mode
+- Use an improved cost function to select the best paragraph to lengthen ([#23](https://github.com/gucci-on-fleek/lua-widow-control/issues/23))
+- Dozens of bug fixes
+- Miscellaneous documentation updates
+
+
+## [v1.1.6 (2022-02-22)](https://github.com/gucci-on-fleek/lua-widow-control/releases/tag/release-2c7201854d89535ef7c02f6c38486205677f1aa1)
+
+- Add support for the OpTeX format/macro package.
+- Add support for the LuaTeX/MKIV version of ConTeXt.
+- Ensure compatibility with the new `linebreaker` package.
+- Fix a small bug with `\lwcdisablecmd`.
+- Test the `\outputpenalty` for the specific values that indicate a widow or orphan.
+
+
+## [v1.1.5 (2022-02-15)](https://github.com/gucci-on-fleek/lua-widow-control/releases/tag/release-5cc95212c8141006ae3a600d26a4e0cd63b368c0)
+
+- Improve the appearance of the demo table in the documentation ([#4](https://github.com/gucci-on-fleek/lua-widow-control/issues/4))
+- Improve compatibility with microtype
+- Block loading the package without LuaTeX
+- Improve logging
+- Bug fix to prevent crashing
+
+
+## [v1.1.4 (2022-02-04)](https://github.com/gucci-on-fleek/lua-widow-control/releases/tag/release-a8caba8e689ce5c743a88dcf1dcd8e4a0db67fb2)
+
+- Enable protrusion/expansion in the demo table in the documentation ([#3](https://github.com/gucci-on-fleek/lua-widow-control/issues/3))
+- Fix `\prevdepth` bug
+
+
+## [v1.1.3 (2022-01-30)](https://github.com/gucci-on-fleek/lua-widow-control/releases/tag/release-8d1228bf1697e2720062b0c2a40f306005da72e8)
+
+- Fix bug when used with the LaTeX `calc` package. ([#2](https://github.com/gucci-on-fleek/lua-widow-control/issues/2))
+
+
+## [v1.1.2 (2021-12-14)](https://github.com/gucci-on-fleek/lua-widow-control/releases/tag/release-61a684d92f1a38ecf0ff53c6da22b2a973fae530)
+
+- Fix crash under ConTeXt LMTX
+
+
+## [v1.1.1 (2021-11-26)](https://github.com/gucci-on-fleek/lua-widow-control/releases/tag/v1.1.1)
+
+- Minor documentation updates
+
+
+## [v1.1.0 (2021-11-08)](https://github.com/gucci-on-fleek/lua-widow-control/releases/tag/release-8c958011bb4bd7f6e4ad843321c0d2643645a08f)
+
+- Extensive documentation updates
+- Clarify that lua-widow-control *does* in fact support columns
+- Add `\lwcdisablecmd` macro to disable lua-widow-control for certain commands
+- Automatically disable lua-widow-control inside section headings (uses `\lwcdisablecmd`)
+- Add automated tests to prevent regressions
+- Fix a rare issue that would cause indefinite hangs
+
+
+
+## [v1.0.0 (2021-10-09)](https://github.com/gucci-on-fleek/lua-widow-control/releases/tag/release-bae44a6858432e095597521bf1ef7df2104b6b9c)
+
+Initial release
diff --git a/macros/context/contrib/context-lua-widow-control/source/luatex/lua-widow-control/lwc-manual-samples.tex b/macros/context/contrib/context-lua-widow-control/source/luatex/lua-widow-control/lwc-manual-samples.tex
new file mode 100644
index 0000000000..6951f7a5bb
--- /dev/null
+++ b/macros/context/contrib/context-lua-widow-control/source/luatex/lua-widow-control/lwc-manual-samples.tex
@@ -0,0 +1,178 @@
+% 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
+
+\startbuffer[demo-text]
+ \definepapersize[smallpaper][
+ width=6cm,
+ height=8.3cm
+ ]\setuppapersize[smallpaper]
+
+ \setuplayout[
+ topspace=0.1cm,
+ backspace=0.1cm,
+ width=middle,
+ height=middle,
+ header=0pt,
+ footer=0pt,
+ ]
+
+ \def\lwc/{\sans{lua-\allowbreak widow-\allowbreak control}}
+ \def\Lwc/{\sans{Lua-\allowbreak widow-\allowbreak control}}
+
+ \setupbodyfont[9pt]
+ \setupindenting[yes, 2em]
+
+ \definepalet[layout][grid=middlegray]
+ \showgrid[nonumber, none, lines]
+
+ \definefontfeature[default][default][expansion=quality,protrusion=quality]
+
+ \usetypescript[modern-base]
+ \setupbodyfont[reset,modern]
+
+ \setupalign[hz,hanging,tolerant]
+
+ \setuplanguage[en][spacing=packed]
+
+ \starttext
+ \Lwc/ can remove most widows and orphans from a document, \emph{without} stretching any glue or shortening any pages.
+
+ It does so by automatically lengthening a paragraph on a page where a widow or orphan would otherwise occur. While \TeX{} breaks paragraphs into their natural length, \lwc/ is breaking the paragraph 1~line longer than its natural length. \TeX{}'s paragraph is output to the page, but \lwc/'s paragraph is just stored for later. When a widow or orphan occurs, \lwc/ can take over. It selects the previously-saved paragraph with the least badness; then, it replaces \TeX{}'s paragraph with its saved paragraph. This increases the text block height of the page by 1~line.
+
+ Now, the last line of the current page can be pushed to the top of the next page. This removes the widow or the orphan without creating any additional work.
+ \stoptext
+\stopbuffer
+\savebuffer[list=demo-text]
+
+\startbuffer[shorten]
+ \parskip=0pt
+ \input lwc-manual-demo-text.tmp
+\stopbuffer
+
+\startbuffer[shorten-code]
+ \parskip=0pt
+
+ \clubpenalty=10000
+ \widowpenalty=10000
+\stopbuffer
+
+\startbuffer[stretch]
+ \parskip=0pt plus 1fill
+ \input lwc-manual-demo-text.tmp
+\stopbuffer
+
+\startbuffer[stretch-code]
+ \parskip=0pt plus 1fill
+
+ \clubpenalty=10000
+ \widowpenalty=10000
+\stopbuffer
+
+\startbuffer[ignore]
+ \startsetups[*default]
+ \clubpenalty=0
+ \widowpenalty=0
+ \displaywidowpenalty=0
+ \interlinepenalty=0
+ \brokenpenalty=0
+ \stopsetups
+
+ \setups[*default]
+
+ \input lwc-manual-demo-text.tmp
+\stopbuffer
+
+\startbuffer[ignore-code]
+ \parskip=0pt
+
+ \clubpenalty=0
+ \widowpenalty=0
+\stopbuffer
+
+\startbuffer[lwc]
+ \usemodule[lua-widow-control]
+ \input lwc-manual-demo-text.tmp
+\stopbuffer
+
+\startbuffer[lwc-code]
+ \usepackage{lua-widow-control}
+\stopbuffer
+
+\startbuffer[widow-orphan]
+ % TODO This is all really quite hacky
+ \define[1]\rulewords{\dorecurse{#1}{\blackrule[height=1.5ex, width=1em] \blackrule[height=1.5ex, width=2em] \blackrule[height=1.5ex, width=1.5em] \blackrule[height=1.5ex, width=3em] }}
+
+ \define[2]\fakestart{\framed[width=broad, align=normal, frame=off]{\parfillskip=0pt\spaceskip=0.2em plus 1fill\hskip 5em\rulewords{#1}\blackrule[height=1.5ex, width=#2]}}
+
+ \define[2]\fakeend{\framed[width=broad, align=normal, frame=off]{\parfillskip=5em\spaceskip=0.2em plus 1fill\rulewords{#1}\blackrule[height=1.5ex, width=#2]}}
+
+ \setupTABLE[width=broad, frame=off]
+ \setupTABLE[row][1][align=middle, style=\ssbf]
+ \setupTABLE[row][2][align=low, frame=on]
+ \setupTABLE[row][3][align=high, frame=on]
+ \setupTABLE[column][2][frame=off, width=1em]
+ \startTABLE
+ \NC Widow \NC\NC Orphan \NC\NR
+ \NC\fakestart{5}{1.5em}\NC\NC\fakestart{1}{2em}\NC\NR
+ \NC\fakeend{1}{2em}\NC\NC\fakeend{5}{1.5em}\NC\NR
+ \stopTABLE
+\stopbuffer
+
+\startbuffer[nobreak]
+ % This is also really hacky and terrible
+ \parfillskip=0pt
+ \define\lineone{%
+ \hbox to 0.3\textwidth{\blackrule[height=1.5ex, width=1em]\hfill%
+ \blackrule[height=1.5ex, width=3em]\hfill%
+ \blackrule[height=1.5ex, width=1em]\hfill%
+ \blackrule[height=1.5ex, width=3em]\hfill%
+ \blackrule[height=1.5ex, width=1em]}%
+ }
+
+ \define\linetwo{%
+ \hbox to 0.3\textwidth{\blackrule[height=1.5ex, width=2em]\hfill%
+ \blackrule[height=1.5ex, width=1em]\hfill%
+ \blackrule[height=1.5ex, width=2.5em]\hfill%
+ \blackrule[height=1.5ex, width=1em]\hfill%
+ \blackrule[height=1.5ex, width=2.5em]}%
+ }
+
+ \define\linethree{%
+ \hbox to 0.3\textwidth{\blackrule[height=1.5ex, width=1em]\hfill%
+ \blackrule[height=1.5ex, width=3em]\hfill%
+ \blackrule[height=1.5ex, width=1em]\hfill%
+ \blackrule[height=1.5ex, width=3em]\hfill%
+ \hskip1em\relax}%
+ }
+
+ \define\heading{\bold{Heading}}
+
+ \setupTABLE[
+ width=broad,
+ topframe=off,
+ bottomframe=off,
+ leftframe=on,
+ rightframe=on,
+ height=1.2\baselineskip
+ ]
+ \setupTABLE[row][1][
+ align=middle,
+ style=\ttbf,
+ bottomframe=on,
+ leftframe=off,
+ rightframe=off
+ ]
+ \setupTABLE[row][3][bottomframe=on]
+ \setupTABLE[row][5][bottomframe=on]
+ \setupTABLE[column][2][bottomframe=off, width=1em]
+ \setupTABLE[column][4][bottomframe=off, width=1em]
+ \startTABLE
+ \NC keep \NC\NC split \NC\NC warn \NC\NR
+ \NC \NC\NC \NC\NC \heading \NC\NR
+ \NC \NC\NC \heading \NC\NC \lineone \NC\NR
+ \NC \heading \NC\NC \lineone \NC\NC \linetwo \NC\NR
+ \NC \lineone \NC\NC \linetwo \NC\NC \linethree \NC\NR
+ \stopTABLE
+\stopbuffer
diff --git a/macros/context/contrib/context-lua-widow-control/source/luatex/lua-widow-control/lwc-manual.bib b/macros/context/contrib/context-lua-widow-control/source/luatex/lua-widow-control/lwc-manual.bib
new file mode 100644
index 0000000000..9a8d174df7
--- /dev/null
+++ b/macros/context/contrib/context-lua-widow-control/source/luatex/lua-widow-control/lwc-manual.bib
@@ -0,0 +1,80 @@
+% 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
+
+@book{texbook,
+ author = {Donald E. Knuth},
+ title = {The \TeX{}Book},
+ year = {2020},
+ publisher = {Addison--Wesley},
+ url = {https://ctan.org/pkg/texbook}
+}
+
+@book{elements,
+ title = {The Elements of Typographic Style},
+ author = {Robert Bringhurst},
+ edition = {3rd},
+ publisher = {Hartley \& Marks},
+ year = {2004},
+}
+
+@article{global,
+ doi = {10.1111/coin.12165},
+ year = {2018},
+ month = mar,
+ publisher = {Wiley},
+ volume = {35},
+ number = {2},
+ pages = {242--284},
+ author = {Frank Mittelbach},
+ title = {A general framework for globally optimized pagination},
+ journal = {Computational Intelligence}
+}
+
+@phdthesis{plass,
+ title={Optimal pagination techniques for automatic typesetting systems},
+ author={Plass, Michael Frederick},
+ year={1981},
+ school={Stanford University},
+ urlnewline=1,
+ url={https://tug.org/docs/plass/plass-thesis.pdf}
+}
+
+@article{tugboat1,
+ title={Automatically removing widows and orphans with
+ {\tt lua-widow-control}},
+ author={Chernoff, Max},
+ journal={TUGboat},
+ volume={43},
+ number={1},
+ year={2022},
+ month=may,
+ pages={28--39},
+ DOI={10.47397/tb/43-1/tb133chernoff-widows},
+}
+
+@article{tugboat2,
+ title={Updates to \sans{lua-widow-control}},
+ author={Chernoff, Max},
+ journal={TUGboat},
+ volume={43},
+ number={3},
+ pages={340--342},
+ year={2022},
+ month=nov,
+ DOI={10.47397/tb/43-3/tb135chernoff-lwc},
+}
+
+@article{zpravodaj,
+ title={Automatically removing widows and orphans with
+ \sans{lua-widow-control}},
+ author={Chernoff, Max},
+ journal={Zpravodaj Československého sdružení uživatelů TeXu},
+ volume={2022},
+ number={1--4},
+ pages={49--76},
+ year={2022},
+ month=nov,
+ DOI={10.5300/2022-1-4/49},
+}
diff --git a/macros/context/contrib/context-lua-widow-control/source/luatex/lua-widow-control/lwc-manual.mkxl b/macros/context/contrib/context-lua-widow-control/source/luatex/lua-widow-control/lwc-manual.mkxl
new file mode 100644
index 0000000000..9d74e40590
--- /dev/null
+++ b/macros/context/contrib/context-lua-widow-control/source/luatex/lua-widow-control/lwc-manual.mkxl
@@ -0,0 +1,371 @@
+% lua-widow-control
+% https://github.com/gucci-on-fleek/lua-widow-control
+% SPDX-License-Identifier: MPL-2.0+
+% SPDX-FileCopyrightText: 2022 Max Chernoff
+
+\startenvironment[lwc-manual]
+\unprotect
+
+\mainlanguage[en]
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%
+%%%%% Font Selection %%%%%
+%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+\startluacode
+fonts.handlers.otf.addfeature {
+ name = "emdash_kern", -- Increase sidebearings on em-dash
+ type = "single",
+ data = {
+ ["—"] = { 100, 0, 200, 0 },
+ }
+}
+\stopluacode
+
+\definefontfeature[default][default][
+ protrusion=quality,
+ expansion=quality,
+ onum=yes,
+ script=latn,
+ emdash_kern=yes,
+ trep=yes,
+]
+\setupalign[hz, hanging]
+
+\definefontfeature[lining][onum=no,lnum=yes]
+\definefontfeature[allsmall][c2sc=yes, smcp=yes]
+\define\lining{\feature[+][lining]}
+
+\starttypescript[lwc-fonts]
+ \definetypeface[lwc-fonts] [rm] [serif][pagella] [default]
+ \definetypeface[lwc-fonts] [ss] [sans] [libertinus] [default] [rscale=1.07]
+ \definetypeface[lwc-fonts] [tt] [mono] [plex] [default] [rscale=0.89]
+ \definetypeface[lwc-fonts] [mm] [math] [pagella] [default]
+\stoptypescript
+
+\setupbodyfont[lwc-fonts, 11pt]
+
+\setupbodyfontenvironment[default][em=italic]
+
+
+%%%%%%%%%%%%%%%%%%%%%%%
+%%%%% Page Layout %%%%%
+%%%%%%%%%%%%%%%%%%%%%%%
+
+\setuppapersize[letter]
+
+\setupindenting[yes, 3em]
+\setupinterlinespace[2.75ex]
+
+\input lang-frq.mkxl % For \averagecharwidth
+
+\setuplayout[
+ width=75\averagecharwidth,
+ backspace=\dimexpr(\paperwidth - \makeupwidth) / 2,
+ topspace=\dimexpr\backspace - \headerheight,
+ footerdistance=3\baselineskip,
+ footer=\baselineskip,
+ height=8.75in,
+ margin=\dimexpr\backspace - \margindistance - 0.25cm,
+]
+
+%%%%%%%%%%%%%%%%%%%%%%%%
+%%%%% PDF Settings %%%%%
+%%%%%%%%%%%%%%%%%%%%%%%%
+
+% PDF/UA
+\setupbackend[format=PDF/UA-1]
+\setupinteraction[state=start, focus=standard]
+\setuptagging[state=start]
+\setupstructure[state=start, method=auto]
+
+% Bookmarks
+\placebookmarks[section, subsection][section, subsection][number=no]
+\setupinteractionscreen[option=bookmark]
+
+%%%%%%%%%%%%%%%%%%%%%%
+%%%%% Formatting %%%%%
+%%%%%%%%%%%%%%%%%%%%%%
+
+\setuppagenumbering[location=footer, style=\ss\lining]
+\let\old@tex=\tex
+\def\tex#1{\expandafter\old@tex\normalexpanded{{#1}}} % Allow expansion in the \tex macro (for \allowbreak)
+
+% Acronym styling
+\definecharacterkerning[acronymkerning][factor=0.05]
+\definealternativestyle[acronymstyle][{\feature[+][allsmall]\switchtobodyfont[1.2em]\setcharacterkerning[acronymkerning]}][]
+\definehighlight[acronym][style=acronymstyle]
+
+\startsetups[commandtable]
+ \setupTABLE[frame=off]
+ \setupTABLE[column][first][roffset=1.5em]
+ \setupTABLE[row][first][toffset=0.25ex]
+\stopsetups
+
+\startsetups[booktabs]
+ \setupTABLE[each][each][frame=off]
+ \setupTABLE[row][first][topframe=on, rulethickness=1.2bp]
+ \setupTABLE[row][2] [topframe=on, rulethickness=0.6bp]
+ \setupTABLE[row][last] [bottomframe=on, rulethickness=1.2bp]
+ \setupTABLE[column][first][loffset=0.5em]
+ \setupTABLE[column][last][roffset=0.5em]
+\stopsetups
+
+\setupitemize[each][
+ style=\lining,
+ inbetween={\blank[quarterline]},
+]
+\setupcaptions[
+ headstyle=\ssbf\lining,
+ style=\ss,
+]
+
+\setupdelimitedtext[blockquote][
+ style=\ss,
+ before=\noindentation,
+ after={\blank[medium]}
+]
+
+\define[1]\meta{\m{\langle}\italic{#1}\m{\rangle}}
+\define[1]\githubissue{\goto{(Issue~\##1)}[url(https://github.com/gucci-on-fleek/lua-widow-control/issues/#1)]}
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%%%%% Section Commands %%%%%
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+\definecharacterkerning[titlekern][factor=0.2]
+
+\protected\def\interwordspace{\scaledfontdimen2\font}
+
+% Section
+\startsetups[style:section]
+ \setcharacterkerning[titlekern]
+ \switchtobodyfont[adventor]
+ \WORD
+ \bfb
+ \feature[+][allsmall]
+ \interwordspace=0.4em
+ \veryraggedcenter
+\stopsetups
+
+\setuphead[section][
+ before={\blank[big, preference]},
+ after={\blank[medium, samepage]},
+ textstyle=\setups{style:section},
+ number=no,
+]
+
+% Subsection
+\setuphead[subsection][
+ before={\blank[medium, preference]},
+ after=,
+ textstyle=\ss,
+ alternative=margintext,
+ number=no,
+]
+
+% TOC
+\def\secondleveltoc{subsection}
+\starttexdefinition protected SectionTOCcommand #1#2#3
+ \startcurrentlistentrywrapper % Make the whole line a link
+ \midaligned{ % Have the title and page number "glued" to the middle
+ \llap{\currentlistentrytitle}
+ \hskip 1em
+ \rlap{\color[\interactionparameter{color}]{\bf \currentlistentrypagenumber}}
+ }
+ \stopcurrentlistentrywrapper
+
+ \par
+ \nobreak
+
+ \setbox0=\vbox{\framedtext[ % Align the subsection titles under the section title
+ frame=off,
+ width=\dimexpr\textwidth/2 - 0.5em,
+ align={flushright, wide},
+ offset=none,
+ toffset=-\lineheight,
+ ]{
+ \global\firstsubsectiontrue
+ \placelist[\secondleveltoc][criterium=local]
+ }}
+ \iffirstsubsection
+ \blank[quarterline] % No subsections here
+ \else
+ \box0
+ \fi
+
+ \goodbreak
+\stoptexdefinition
+
+\newif\iffirstsubsection
+
+\define\tocspace{\hskip 0.5em plus 0.5em minus 0.2em\relax}
+
+\unexpanded\def\toc_link#1{%
+ \startcurrentlistentrywrapper%
+ \hbox{#1}%
+ \stopcurrentlistentrywrapper%
+}
+
+\starttexdefinition protected SubsectionTOCcommand #1#2#3
+ \ss\itx
+ \dontleavehmode
+ \iffirstsubsection
+ \global\firstsubsectionfalse
+ \toc_link{#2}
+ \else
+ \discretionary{}{
+ \toc_link{#2} % No interpunct if the line splits here
+ }{
+ \tocspace{\bfa·}\tocspace\toc_link{#2}
+ }
+ \fi
+\stoptexdefinition
+
+\setupcombinedlist[content][list=section]
+\setuplist[section][
+ alternative=command,
+ command=\SectionTOCcommand,
+]
+
+\setuplist[subsection][
+ alternative=command,
+ command=\SubsectionTOCcommand,
+]
+
+%%%%%%%%%%%%%%%%%%%%%%%
+%%%%% Title Block %%%%%
+%%%%%%%%%%%%%%%%%%%%%%%
+
+\setupdocument[
+ title={},
+ author={},
+ version={},
+ ctan={},
+ github={},
+]
+
+\startluacode
+local function strip_url(str)
+ local url_table = url.hashed(str)
+ url_table.fragment = nil
+ url_table.scheme = nil
+ url_table.authority = url_table.authority:gsub("^www%.", "")
+ tex.sprint(-2, url.decode(url.construct(url_table)))
+end
+
+interfaces.implement {
+ name = "strip_url",
+ actions = strip_url,
+ arguments = "1 string"
+}
+\stopluacode
+
+\define[1]\strippedurl{%
+ \goto{\tt\hyphenatedurl{\clf_strip_url{#1}}}[url(#1)]
+}
+
+\startsetups[titleblock]
+ \startalignment [middle]
+ \begingroup
+ \setups[style:section]\bfc
+ \documentvariable{title}
+ \par
+ \endgroup
+
+ \blank[big]
+
+ \begingroup
+ \ssa\lining
+ \documentvariable{author}
+ \blank[medium]
+ v\,\documentvariable{version}
+ \par
+ \endgroup
+
+ \dontleavehmode
+ \blackrule[depth=-0.25\baselineskip, height=\dimexpr0.25\baselineskip + 0.4pt, width=8em]
+ \par
+
+ \doifdocumentvariable{ctan}{
+ \strippedurl{\documentvariable{ctan}}
+ }
+ \doifdocumentvariable{github}{
+ \strippedurl{\documentvariable{github}}
+ }
+ \blank[big]
+
+ \noindentation
+ \stopalignment
+\stopsetups
+
+\startsetups[document:start]
+ \setup[titleblock]
+
+ \setupinteraction[
+ title=\documentvariable{title},
+ author=\documentvariable{author},
+ ]
+\stopsetups
+
+%%%%%%%%%%%%%%%%%%%%%%%%
+%%%%% Bibliography %%%%%
+%%%%%%%%%%%%%%%%%%%%%%%%
+\usebtxdefinitions[apa]
+
+\resetsetups[apa:list:sameauthor]
+
+\setupbtx[apa:list][
+ stopper:initials=,
+ separator:initials=\btxnbsp,
+ interaction=start,
+]
+
+\setupbtxlabeltext[en][
+ apa:Retrieved={}
+]
+
+\setupbtxrendering[apa][
+ numbering=yes,
+ sorttype=used,
+]
+
+\setupbtx[apa:cite][alternative=num]
+
+\defineshift[citeshift][
+ method=0,
+ dy=-1,
+ unit=ex,
+ continue=yes,
+ style=\tfx\lining,
+]
+
+\setupbtx[apa:cite:num][
+ command=\citeshift,
+ left=,
+ right=,
+ separator:2=\citeshift{,\,},
+ separator:3=\citeshift{--}
+]
+
+\setupbtxlist[apa][
+ alternative=a,
+ before=,
+ after={\blank[quarterline]},
+ style=\lining,
+ margin=0pt,
+ width=1.5em,
+]
+
+\starttexdefinition mutable protected btx:apa:url
+ \strippedurl{\clf_btxflush{\currentbtxdataset}{\currentbtxtag}{url}
+ }
+\stoptexdefinition
+
+\define[1]\lwc_doi{\goto{\acronym{DOI:}\,\tt\hyphenatedurl{#1}}[url(https://dx.doi.org/#1)]}
+\starttexdefinition mutable protected btx:apa:doi
+ \lwc_doi{\clf_btxflush{\currentbtxdataset}{\currentbtxtag}{doi}}
+\stoptexdefinition
+
+\protect
+\stopenvironment
diff --git a/macros/context/contrib/context-lua-widow-control/source/luatex/lua-widow-control/lwc-manual.tex b/macros/context/contrib/context-lua-widow-control/source/luatex/lua-widow-control/lwc-manual.tex
new file mode 100644
index 0000000000..ef46472225
--- /dev/null
+++ b/macros/context/contrib/context-lua-widow-control/source/luatex/lua-widow-control/lwc-manual.tex
@@ -0,0 +1,949 @@
+% 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
+
+\doifnot{\contextmark}{LMTX}{
+ \errhelp{LMTX/MkXL is required to compile this file.}
+ \errmessage{Fatal error, exiting.}
+}
+
+\environment lwc-manual
+
+\usemodule[lua-widow-control]
+\usebtxdataset[\jobname.bib]
+
+\useURL[projecturl][https://github.com/gucci-on-fleek/lua-widow-control]
+\useURL[download][https://github.com/gucci-on-fleek/lua-widow-control/releases/latest]
+\useURL[ctan][https://www.ctan.org/pkg/lua-widow-control]
+
+% Abbreviations
+\def\lwc/{\sans{lua-\allowbreak widow-\allowbreak control}}
+\def\Lwc/{\sans{Lua-\allowbreak widow-\allowbreak control}}
+\def\estretch/{\tex{emergency\allowbreak stretch}}
+\def\openalty/{\tex{output\allowbreak penalty}}
+\def\waos/{widows and orphans}
+\def\wao/{widow and orphan}
+\def\woo/{widow or orphan}
+\def\mkxl/{\ConTeXt~Mk\acronym{XL}}
+\def\mkiv/{\ConTeXt~Mk\acronym{IV}}
+\define\OpTeX{Op\kern-.05em\TeX}
+\def\LuaMeta{Lua\-Meta\-}
+\def\LuaMetaTeX{\LuaMeta\TeX}
+\def\plainop/{Plain~\TeX{}/\OpTeX{}}
+\let\q=\quotation
+
+\def\titlecite[#1]{\cite[title][#1]\cite[#1]}
+
+\definetype[inlineTEX][option=tex, escape={$,$}, lines=hyphenated]
+\definetype[inlineLUA][option=lua, escape={$,$}, lines=hyphenated]
+
+\input lwc-manual-samples
+
+\definecolor[expanded][r=0.00, g=0.70, b=0.25]
+\definecolor[failure] [r=0.90, g=0.00, b=0.25]
+\definecolor[moved] [r=0.25, g=0.25, b=1.00]
+\definecolor[cost] [r=0.50, g=0.50, b=0.50]
+
+\usemodule[markdown]
+\define[4]\markdownRendererLinkPrototype{\goto{#1}[url(#3)]}
+\def\markdownOptionHtml{true}
+\def\markdownOptionShiftHeadings{1}
+\startluacode
+ interfaces.implement {
+ name = "markdownRendererHeadingThreePrototype",
+ public = true,
+ arguments = { "string" },
+ actions = function (str)
+ context.subsection {
+ title = str,
+ list = str:match "v%d+%.%d+%.%d+"
+ }
+ end
+ }
+\stopluacode
+
+\startdocument[
+ title=lua-widow-control,
+ author=Max Chernoff,
+ version=3.0.0, %%version
+ github=https://github.com/gucci-on-fleek/lua-widow-control,
+ ctan=https://www.ctan.org/pkg/lua-widow-control,
+]
+
+\Lwc/ is a Plain~\TeX/\LaTeX/\ConTeXt{}/\OpTeX{} package that removes \waos/ without any user intervention. Using the power of \LuaTeX{}, it does so \emph{without} stretching any glue or shortening any pages or columns. Instead, \lwc/ automatically lengthens a paragraph on a page or column where a \woo/ would otherwise occur.
+
+\section{Quick Start}
+Ensure that your \TeX~Live/Mik\TeX{} distribution is up-to-date. Then, \LaTeX{} users just need to place \inlineTEX{\usepackage{lua-widow-control}} in the preamble of their document. For more details, see the \goto{Usage sections}[sec:usage].
+
+\subject{Contents}
+\placecontent[criterium=all]
+
+\section{Preliminaries}
+
+This manual begins with a brief introduction to widows, orphans, and \lwc/. For an extended introduction and discussion of these topics, please see the \emph{Zpravodaj} article\cite[zpravodaj] distributed with this manual (Links: \goto{local}[lwc-zpravodaj::], \goto{\acronym{CTAN}}[url(http://mirrors.ctan.org/macros/luatex/generic/lua-widow-control/lwc-zpravodaj.pdf)], \goto{GitHub}[url(https://github.com/gucci-on-fleek/lua-widow-control/releases/latest/download/lwc-zpravodaj.pdf)]). This same material is also available in two \emph{TUGboat} articles\cite[tugboat1, tugboat2] (Links: \goto{local}[tb133chernoff-widows::], \goto{\acronym{CTAN}}[url(http://mirrors.ctan.org/macros/luatex/generic/lua-widow-control/tb133chernoff-widows.pdf)], \goto{GitHub}[url(https://github.com/gucci-on-fleek/lua-widow-control/releases/latest/download/tb133chernoff-widows.pdf)]) if you prefer. You can also skip ahead to the \goto{installation instructions on \at{page}[sec:install]}[sec:install] or the \goto{usage section starting at \at{page}[sec:usage]}[sec:usage].
+
+\section[sec:motivation]{Motivation}
+
+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.
+
+\Lwc/ offers an alternative method of removing \waos/: instead of shortening a page or stretching vertical whitespace, \lwc/ simply chooses a paragraph to lengthen by one~line such that the \woo/ is eliminated.
+
+\section{Widows and Orphans}
+\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 some authors choose
+to ignore them.
+
+\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.
+
+\startplacefigure[location={here, top, bottom}, title={A visual comparison of \waos/.}, reference=tab:widow]
+ \getbuffer[widow-orphan]
+\stopplacefigure
+
+\section{\TeX's Pagination}
+\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) \tex{flushbottom} is set;
+otherwise, it will
+break the page and leave the bottom empty.
+
+However, some objects have \q{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.
+
+\subsection{Behaviour}
+
+Due to these \q{penalties} attached to \waos/, \TeX{} tries to avoid
+creating 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.
+
+However, when these lines are moved as a group, \TeX{} will have to make a page or column with less lines. \about[sec:demo] goes into further detail about how \TeX{} deals with these too-short pages or columns.
+
+\startpostponing
+\startTEXpage[
+ align=normal,
+ width=100cm,
+ autowidth=force,
+ offset=5pt,
+ pagestate=start,
+]
+ \veryraggedcenter
+ \setupTABLE[row][first][style=\ssbf, align=middle]
+ \setupTABLE[frame=off, offset=5pt]
+ \startTABLE
+ \NC Ignore
+ \NC Shorten
+ \NC Stretch
+ \NC \Lwc/ \NC\NR
+
+ \NC \typesetbuffer[ignore][frame=on,page=1]
+ \NC \typesetbuffer[shorten][frame=on,page=1]
+ \NC \typesetbuffer[stretch][frame=on,page=1]
+ \NC \typesetbuffer[lwc][frame=on,page=1]
+ \NC\NR
+
+ \NC \typesetbuffer[ignore][frame=on,page=2]
+ \NC \typesetbuffer[shorten][frame=on,page=2]
+ \NC \typesetbuffer[stretch][frame=on,page=2]
+ \NC \typesetbuffer[lwc][frame=on,page=2]
+ \NC\NR
+
+ \NC \typebuffer[ignore-code][option=TEX]
+ \NC \typebuffer[shorten-code][option=TEX]
+ \NC \typebuffer[stretch-code][option=TEX]
+ \NC \typebuffer[lwc-code][option=TEX]
+ \NC\NR
+ \stopTABLE
+
+ \placefloatcaption[table][reference=tab:demo, title={A visual comparison of various automated widow handling techniques.}]
+\stopTEXpage
+\stoppostponing
+
+\section[sec:demo]{Demonstration}
+
+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. \in{Table}[tab:demo] has a visual comparison of these
+options, which we'll discuss in the following:
+
+\subsection{\q{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{\q{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.
+
+\subsection{\q{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 glue stretching must be quantised to the height of a line.
+
+\subsection{\q{\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 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[sec:install]{Installation}
+Most up-to-date \TeX~Live and Mik\TeX{} systems should already have \lwc/ installed. However, a manual installation may occasionally be required.
+
+\subsection{\TeX~Live}
+Run \type{tlmgr install lua-widow-control} in a terminal, or install using the \q{\TeX~Live Manager} \acronym{GUI}.
+
+\subsection{Mik\TeX}
+Run \type{mpm --install=lua-widow-control} in a terminal, or install using the \q{Mik\TeX{} Maintenance} \acronym{GUI}.
+
+\subsection{Manual}
+Currently, \mkxl/ (\LuaMetaTeX{}) users must manually install the package. Most other users will be better served by using the \lwc/ supplied by \TeX~Live and Mik\TeX{}; however, all users may manually install the package if desired. The procedure should be fairly similar regardless of your \acronym{OS}, \TeX{} distribution, or format.
+
+\subsection{Steps}
+\startitemize[N]
+ \item Download \type{lua-widow-control.tds.zip} from \goto{\acronym{CTAN}}[url(ctan)], \goto{GitHub}[url(download)] or the \goto{\ConTeXt{}~Garden}[url(https://modules.contextgarden.net/cgi-bin/module.cgi/action=view/id=127)].
+ \item Unzip the release into your \type{TEXMFLOCAL/} directory. (You can find its location by running \type{kpsewhich --var-value TEXMFHOME} in a terminal)
+ \item Refresh the filename database: \startitemize[1]
+ \item \ConTeXt: \type{mtxrun --generate}
+ \item \TeX~Live: \type{mktexlsr}
+ \item Mik\TeX: \type{initexmf --update-fndb}
+ \stopitemize
+\stopitemize
+
+\section{Dependencies}
+\Lwc/ does have a few dependencies; however, these will almost certainly be met by all but the most minimal of \TeX{} installations.
+
+\subsection{Plain~\TeX{}}
+\Lwc/ requires \LuaTeX{} ($\ge$ 0.85) and the most recent version of \sans{luatexbase} (2015/10/04). Any version of \TeX~Live $\ge$ 2016 will meet these requirements.
+
+\subsection{\LaTeX{}}
+\Lwc/ requires \LuaTeX{} ($\ge$ 0.85), \LaTeX{} ($\ge$ 2020/10/01), and \sans{microtype} (any version). Any version of \TeX~Live $\ge$ 2021 will meet these requirements.
+
+\Lwc/ also supports a \q{legacy} mode for older \LaTeX{} kernels. This uses an older version of the \LaTeX{} code while still using the most recent Lua code. This mode requires \LuaTeX{} ($\ge$ 0.85), \LaTeX{} ($\ge$ 2015/01/01), \sans{microtype} (any version), and \sans{etoolbox} (any version). Any version of \TeX~Live $\ge$ 2016 will meet these requirements.
+
+Please note that when running in legacy mode, you cannot use the key--value interface. This legacy interface is undocumented, but mostly the same as the \q{Plain~\TeX{}} interface.
+
+\subsection{\ConTeXt{}}
+\Lwc/ supports both \mkxl/ (\LuaMetaTeX{}) and \mkiv/ (\LuaTeX{}).
+
+\subsection{\OpTeX{}}
+\Lwc/ works with any version of \OpTeX{} and has no dependencies.
+
+\subsection{LuaMeta\TeX{}}
+
+\Lwc/ has preliminary support for LuaMeta\LaTeX{} and LuaMetaPlain. All features should work identically to the \LuaTeX{}-based version, although there are a few minor bugs. You should always make sure to use the latest engine, format, and \lwc/ since these formats are under rapid development.
+
+
+\section[sec:usage]{Loading the Package}
+
+\startTABLE[setups=commandtable]
+ \NC Plain~\TeX{}
+ \NC\inlineTEX{\input lua-widow-control}
+ \NC\NR
+ \NC \LaTeX{}
+ \NC\inlineTEX{\usepackage{lua-widow-control}}
+ \NC\NR
+ \NC \ConTeXt{}
+ \NC\inlineTEX{\usemodule[lua-widow-control]}
+ \NC\NR
+ \NC \OpTeX{}
+ \NC\inlineTEX{\load[lua-widow-control]}
+ \NC\NR
+\stopTABLE
+
+\section{Options}
+
+\Lwc/ is automatically enabled with the default settings as soon as you load it. Most users should not need to configure \lwc/; however, the packages provides a few commands.
+
+\subsection{Overview}
+
+\LaTeX{} users can set the options either when loading the package (\inlineTEX{\usepackage[$\meta{options}$]{lua-widow-control}}) or at any point using \inlineTEX{\lwcsetup{$\meta{options}$}}.
+
+\ConTeXt{} users should use the \inlineTEX{\setuplwc[$\meta{options}$]} command for setting options at any point.
+
+Plain~\TeX{} and \OpTeX{} are a little different. Some options require you to set a register (i.e., \inlineTEX{\lwcemergencystretch = $\meta{dimension}$}), while others use macro arguments (i.e., \inlineTEX{\lwcnobreak{$\meta{option}$}}).
+
+\subsection{Disabling}
+
+You may want to disable \lwc/ for certain portions of your
+document. You can do so with the following commands:
+
+\startTABLE[setups=commandtable]
+ \NC \plainop/
+ \NC\inlineTEX{\lwcdisable}
+ \NC\NR
+ \NC \LaTeX{}
+ \NC\inlineTEX{\lwcsetup{disable}}
+ \NC\NR
+ \NC \ConTeXt{}
+ \NC\inlineTEX{\setuplwc[state = stop]}
+ \NC\NR
+\stopTABLE
+
+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.
+
+\startTABLE[setups=commandtable]
+ \NC \plainop/
+ \NC\inlineTEX{\lwcenable}
+ \NC\NR
+ \NC \LaTeX{}
+ \NC\inlineTEX{\lwcsetup{enable}}
+ \NC\NR
+ \NC \ConTeXt{}
+ \NC\inlineTEX{\setuplwc[state = start]}
+ \NC\NR
+\stopTABLE
+
+\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{}, \sans{memoir}, \sans{\acronym{KOMA}-Script}, and
+\sans{titlesec} section commands, so you don't need to patch these.
+Any others, though, you'll need to patch yourself.
+
+\startTABLE[setups=commandtable]
+ \NC \plainop/
+ \NC \inlineTEX{\lwcdisablecmd $\meta{\backslash macro}$}
+ \NC\NR
+ \NC \LaTeX{}
+ \NC \inlineTEX{\lwcsetup{disablecmds = {$\meta{macronameone}$, $\meta{macronametwo}$}}}
+ \NC\NR
+ \NC \ConTeXt{}
+ \NC \inlineTEX{\prependtoks\lwc$\hskip-0.5em\relax$@patch@pre\to\everybefore$\hskip-0.5em\relax\meta{hook}$}
+ \NC\NR\NC\NC \inlineTEX{\prependtoks\lwc$\hskip-0.5em\relax$@patch@pre\to\everyafter$\hskip-0.5em\relax\meta{hook}$}
+ \NC\NR
+\stopTABLE
+
+The Plain~\TeX{}, \OpTeX{}, and \ConTeXt{} commands \emph{append} to the list of patched commands: they simply patch the provided commands while leaving the original patches in place. The \LaTeX{} option \emph{sets} the list of patched commands: it replaces the default list with the provided list.
+
+\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 lengthen 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, so it's pretty rare that a paragraph that
+requires any \estretch/ will actually be used on the page.
+
+\startTABLE[setups=commandtable]
+ \NC \plainop/
+ \NC\inlineTEX{\lwcemergencystretch = $\meta{dimension}$}
+ \NC\NR
+ \NC \LaTeX{}
+ \NC\inlineTEX{\lwcsetup{emergencystretch = $\meta{dimension}$}}
+ \NC\NR
+ \NC \ConTeXt{}
+ \NC\inlineTEX{\setuplwc[emergencystretch = $\meta{dimension}$]}
+ \NC\NR
+\stopTABLE
+
+\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.
+
+\startTABLE[setups=commandtable]
+ \NC \plainop/
+ \NC\inlineTEX{\widowpenalty = $\meta{integer}$}
+ \NC\NR\NC\NC\inlineTEX{\clubpenalty = $\meta{integer}$}
+ \NC\NR\NC\NC\inlineTEX{\brokenpenalty = $\meta{integer}$}
+ \NC\NR
+ \NC \LaTeX{}
+ \NC\inlineTEX{\lwcsetup{widowpenalty = $\meta{integer}$}}
+ \NC\NR\NC\NC\inlineTEX{\lwcsetup{orphanpenalty = $\meta{integer}$}}
+ \NC\NR\NC\NC\inlineTEX{\lwcsetup{brokenpenalty = $\meta{integer}$}}
+ \NC\NR
+ \NC \ConTeXt{}
+ \NC\inlineTEX{\setuplwc[widowpenalty = $\meta{integer}$]}
+ \NC\NR\NC\NC\inlineTEX{\setuplwc[orphanpenalty = $\meta{integer}$]}
+ \NC\NR\NC\NC\inlineTEX{\setuplwc[brokenpenalty = $\meta{integer}$]}
+ \NC\NR
+\stopTABLE
+
+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 \tex{widowpenalty}, \tex{clubpenalty}, and
+\tex{brokenpenalty} regardless of how you set them, so the use of these
+dedicated keys is entirely optional.
+
+\subsection{\tex{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 \tex{nobreak}\slash\tex{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.
+
+\startTABLE[setups=commandtable]
+ \NC \plainop/
+ \NC\inlineTEX{\lwcnobreak{$\meta{value}$}}
+ \NC\NR
+ \NC \LaTeX{}
+ \NC\inlineTEX{\lwcsetup{nobreak = $\meta{value}$}}
+ \NC\NR
+ \NC \ConTeXt{}
+ \NC\inlineTEX{\setuplwc[nobreak = $\meta{value}$]}
+ \NC\NR
+\stopTABLE
+
+The default value, \type{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 \tex{nobreak}s; the
+disadvantage is that moving the section heading can create a large blank
+space at the end of the page.
+
+The value \type{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 \type{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.
+
+\startplacefigure[location={here, top, bottom}, title={A visual comparison of the various \type{nobreak} options, where each box represents a different page.}, reference=tab:nobreak]
+ \getbuffer[nobreak]
+\stopplacefigure
+
+\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.
+
+\startTABLE[setups=commandtable]
+ \NC \plainop/
+ \NC\inlineTEX{\lwcmaxcost = $\meta{integer}$}
+ \NC\NR
+ \NC \LaTeX{}
+ \NC\inlineTEX{\lwcsetup{max-cost = $\meta{integer}$}}
+ \NC\NR
+ \NC \ConTeXt{}
+ \NC\inlineTEX{\setuplwc[maxcost = $\meta{integer}$]}
+ \NC\NR
+\stopTABLE
+
+Based on my testing, \type{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 \type{max-cost}, although the \q{strict} and \q{balanced} modes
+sets the values to~5\,000 and 10\,000 respectively.
+
+\Lwc/ uses a \q{cost function} $C$ that is initially defined as \startformula
+ C = \frac{d}{\sqrt{l}}
+\stopformula where $d$ is the total demerits of the paragraph, and $l$ is the number of lines in the paragraph.
+
+\subsection{Draft Mode}
+
+\setuplwc[draft=start]
+\definecolor[lwc_expanded][s=0]
+\definecolor[lwc_failure][s=0]
+\definecolor[lwc_moved][s=0]
+You can use the draft mode to visualize how \lwc/ processes pages. Any \color[failure]{remaining widows and orphans will be coloured red}, any \color[expanded]{expanded paragraphs will be coloured green}, and any \color[moved]{lines moved to the next page will be coloured blue}. In addition, the \color[cost]{cost of each paragraph is shown in the right margin} as it is here.
+
+\startTABLE[setups=commandtable]
+ \NC \plainop/
+ \NC\inlineTEX{\lwcdraft 1}
+ \NC\NR
+ \NC \LaTeX{}
+ \NC\inlineTEX{\lwcsetup{draft}}
+ \NC\NR
+ \NC \ConTeXt{}
+ \NC\inlineTEX{\setuplwc[draft = start]}
+ \NC\NR
+\stopTABLE
+
+Advanced users may also customize the colours used by modifying the \inlineLUA{lwc.colours} table. The table keys are currently \type{expanded}, \type{failure}, \type{moved}, and \type{cost}. The table values are \acronym{RGB} 3-tuples, where each element is a float between zero and one.
+
+You can also show or hide the costs and colours independently of each other.
+
+\startTABLE[setups=commandtable]
+ \NC \plainop/
+ \NC\inlineTEX{\lwcshowcosts 1}
+ \NC\NR\NC\NC\inlineTEX{\lwcshowcolours 1}
+ \NC\NR
+ \NC \LaTeX{}
+ \NC\inlineTEX{\lwcsetup{showcosts = true}}
+ \NC\NR\NC\NC\inlineTEX{\lwcsetup{showcolours = true}}
+ \NC\NR
+ \NC \ConTeXt{}
+ \NC\inlineTEX{\setuplwc[showcosts = start]}
+ \NC\NR\NC\NC\inlineTEX{\setuplwc[showcolours = start]}
+ \NC\NR
+\stopTABLE
+
+Plain~\TeX{} users will need to modify their output routines to be able to see the costs. Before you ship out the page, you should call \inlineTEX{\lwcpreshipout} with a box number as its argument. For example, here is some sample code to correctly reproduce the standard Plain~\TeX{} output routine:
+
+\startTEX
+\newbox\tempshipoutbox
+\output={
+ \setbox\tempshipoutbox=\vbox{
+ \makeheadline
+ \pagebody
+ \makefootline
+ }
+ \lwcpreshipout\the\tempshipoutbox
+ \shipout\box\tempshipoutbox
+ \advancepageno
+}
+\stopTEX
+
+Setting the output routine like this is automatic in all other formats. \Lwc/ does not modify the output routine in Plain~\TeX{} since most of its users likely have their own output routines.
+
+\subsection{Draft Offset}
+
+In draft mode, the paragraph costs are printed in the margins, offset a certain distance from the page edge. By default, this offset is set to \unit{1 inch}; however, you can change this to any value that you want:
+
+\startTABLE[setups=commandtable]
+ \NC \plainop/
+ \NC\inlineTEX{\lwcdraftoffset = $\meta{dimension}$}
+ \NC\NR
+ \NC \LaTeX{}
+ \NC\inlineTEX{\lwcsetup{draftoffset = $\meta{dimension}$}}
+ \NC\NR
+ \NC \ConTeXt{}
+ \NC\inlineTEX{\setuplwc[draftoffset = $\meta{dimension}$]}
+ \NC\NR
+\stopTABLE
+
+\setuplwc[draft=stop]
+\subsection{Debug Mode}
+
+\Lwc/ offers a \q{debug} mode that prints extra information in the log files. This may be helpful to understand how \lwc/ is processing paragraphs and pages, although the information is likely inscrutable unless you are the package's author. If you are reporting an issue with \lwc/, make sure to compile your document with debug mode enabled!
+
+\startTABLE[setups=commandtable]
+ \NC \plainop/
+ \NC\inlineTEX{\lwcdebug 1}
+ \NC\NR\NC\NC\inlineTEX{\lwcdebug 0}
+ \NC\NR
+ \NC \LaTeX{}
+ \NC\inlineTEX{\lwcsetup{debug = true}}
+ \NC\NR\NC\NC\inlineTEX{\lwcsetup{debug = false}}
+ \NC\NR
+ \NC \ConTeXt{}
+ \NC\inlineTEX{\setuplwc[debug = start]}
+ \NC\NR\NC\NC\inlineTEX{\setuplwc[debug = stop]}
+ \NC\NR
+\stopTABLE
+
+\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.
+
+Presets are available only with \LaTeX{} and \ConTeXt{}.
+
+\startTABLE[setups=commandtable]
+ \NC \LaTeX{}
+ \NC\inlineTEX{\lwcsetup{$\meta{preset}$}}\NC\NR
+ \NC \ConTeXt{}
+ \NC\inlineTEX{\setuplwc[$\meta{preset}$]}\NC\NR
+\stopTABLE
+
+\subsection{\type{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{\type{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{\type{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.
+
+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.
+
+% %
+\startplacetable[location={here, top, bottom}, title={\Lwc/ options set by each mode.}, reference=tab:modes]
+ \startTABLE[setups=booktabs, style=tt, loffset=0.5em]
+ \NC {\rm Option} \NC default \NC balanced \NC strict \NC\NR
+ \NC max-cost \NC $\infty$ \NC 10000 \NC 5000 \NC\NR
+ \NC emergencystretch \NC 3em \NC 1em \NC 0pt \NC\NR
+ \NC nobreak \NC keep \NC keep \NC warn \NC\NR
+ \NC widowpenalty \NC 1 \NC 500 \NC 1 \NC\NR
+ \NC orphanpenalty \NC 1 \NC 500 \NC 1 \NC\NR
+ \NC brokenpenalty \NC 1 \NC 500 \NC 1 \NC\NR
+ \stopTABLE
+\stopplacetable
+
+\section{Lua Interface}
+
+\Lwc/ provides a few public functions and tables that you can safely use or modify as documented. Any Lua interfaces that aren't documented below are subject to change at any time, but ff you do want to use an undocumented interface, please let me know and can easily document it.
+
+\subsection{Costs}
+
+\Lwc/ uses a \q{cost function} to select which paragraph to expand. Typically, this depends on the number of lines and demerits in the broken paragraph; however, you can redefine this function to do something else if you want. The default function is defined as:
+
+\startLUA
+--- The "cost function" to use.
+---
+--- @param demerits number The demerits of the broken paragraph
+--- @param lines number The number of lines in the broken paragraph
+--- @param nat_demerits number The demerits of the naturally-broken paragraph
+--- @param nat_lines number The number of lines in the naturally-broken paragraph
+--- @param head node The head of the broken paragraph
+--- @return number cost The cost of the broken paragraph
+function lwc.paragraph_cost(demerits, lines, nat_demerits, nat_lines, head)
+ return demerits / math.sqrt(lines)
+end
+\stopLUA
+
+\subsection{Activation}
+
+Typically, \lwc/ determines if there are \waos/ at the end of a page by checking the \tex{outputpenalty} register. However, you can use a custom check if you want. The default check is defined as:
+
+\startLUA
+--- Determines if we should "activate" lwc for the current page/column.
+---
+--- @param penalty number The \outputpenalty for the current page/column
+--- @param paragraphs table<table<string, node|number>> The `paragraphs` table
+--- @param head node The head of the current page/column
+--- @return boolean activate True if lwc should move the last line on this page
+function lwc.should_remove_widows(penalty, paragraphs, head)
+ return is_matching_penalty(penalty)
+end
+\stopLUA
+
+By setting a custom activation and cost function, you can transform \lwc/ from a \wao/ remover into a custom layout customization tool.
+
+\section{Compatibility}
+
+The \lwc/ implementation is almost entirely in Lua, with only a minimal
+\TeX{} footprint. It
+doesn't modify the output routine, \tex{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 matter for Plain~\TeX{} or \LaTeX{}, where even most Lua-based
+packages don't depend on the node list structure; nevertheless, there are
+a few issues with \ConTeXt{}.
+
+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\acronym{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\acronym{XL}\slash\acronym{LMTX}, \LuaMeta\LaTeX{}, and
+\LuaMeta{}Plain. \ConTeXt{} Mk\acronym{XL} works equally
+well as \ConTeXt{} Mk\acronym{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 \type{twocolumn}
+and the two-column output routine from Chapter~23 of \titlecite[texbook].
+
+\subsection{Performance}
+
+\Lwc/ runs entirely in a single pass, without depending on any
+\type{.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.
+
+\subsection{\eTeX{} penalties}
+
+Knuth's original \TeX{} has three basic line penalties:
+\tex{interlinepenalty}, which
+is inserted between all lines; \tex{club\-penalty}, which is inserted after
+the first line; and \tex{widow\-penalty}, which is inserted before the last
+line. The \eTeX{} extensions generalize these commands with a
+syntax similar to \tex{parshape}: with \tex{widow\-penalties} you can set the
+penalty between the last, second last, and $n$th last lines of a paragraph;
+\tex{inter\-line\-penalties} and \tex{club\-penalties} behave similarly.
+
+\Lwc/ makes no explicit attempts to support these new -\type{penalties}
+commands. Specifically, if you give a line a penalty that matches either
+\tex{widowpenalty} or \tex{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.
+
+\subsection{Grids}
+
+\Lwc/ is fully compatible with the grid snapping features of \ConTeXt{} \mkiv/ and \mkxl/.
+
+\subsection{Footnotes}
+
+If there are footnotes (or any other type of inline \tex{insert}) present in the moved line, \lwc/ will move both the \q{footnote mark} and the \q{footnote text} such that both are on the same page. However, this may lead to an odd blank space at the bottom of the page since \lwc/ needs to move both the line and its footnotes. Footnotes cause the same page-breaking issues in unmodified Plain~\TeX{} and \LaTeX{}, so this is mostly unavoidable.
+
+\section{Stability}
+
+The documented interfaces of \lwc/ can be considered stable: I'm not planning on removing or modifying any existing options or commands in any way that would break documents.
+
+However, \lwc/'s page breaking \emph{is} subject to change. I will attempt to keep page breaks the same whenever reasonable; however, I will \emph{rarely} make modifications to the algorithm when I can improve the output quality. Any such changes will be clearly noted in the release notes.
+
+\section{Short last lines}
+
+When lengthening a paragraph with \tex{looseness}, it is common advice to insert
+ties (\type{~}) 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 \tex{hbox}es, it uses the
+\tex{par\allowbreak fill\allowbreak skip}
+parameter. 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
+\tex{parfillskip} to \type{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.
+
+\section[sec:issues]{Known Issues}
+
+\startitemize
+ \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 \Lwc/ only attempts to expand paragraphs; it never attempts to shrink them. See the \emph{TUGboat}~article\cite[article] §15.3 for further discussion. \githubissue{33}
+
+ \item \Lwc/ can only expand paragraphs that fit completely on a page. This is unavoidable due to the one-page-at-a-time model: you can't modify the bottom half of a paragraph since its top half has already shipped out, and you can't expand the top half of a paragraph since that can't remove orphans. This only causes issues if your document has paragraphs so long that a page only has two half-paragraphs and zero whole paragraphs.
+
+ \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 \acronym{NP}-complete\cite[plass] and
+ impossible to solve in a single pass. Very rarely would such a
+ system remove widows or orphans that \lwc/ cannot.
+\stopitemize
+
+\section{Contributions}
+
+If you have any issues with \lwc/, please create an issue at the \goto{project's GitHub page}[url(projecturl)]. Or, if you think that you can solve any of the \about[sec:issues] or add any new features, \goto{submit a \acronym{PR}}[url(projecturl)]. Thanks!
+
+\section{License}
+
+\Lwc/ is licensed under the \goto{\emph{Mozilla Public License}, version 2.0}[url(https://www.mozilla.org/en-US/MPL/2.0/)] or greater. The documentation is licensed under \goto{\acronym{CC-BY-SA}, version 4.0}[url(https://creativecommons.org/licenses/by-sa/4.0/legalcode)] or greater as well as the \acronym{MPL}.
+
+Please note that a compiled document is \bold{not} considered to be an \q{Executable Form} as defined by the \acronym{MPL}. The \acronym{MPL} and \acronym{CC-BY-SA} licenses \bold{only} apply to you if you distribute the \lwc/ source code or documentation.
+
+\section{References}
+
+\placelistofpublications
+
+\page
+
+\setuphead[subsection][
+ alternative=normal,
+ style=\ssitb,
+ after={\blank[disable, penalty:10000]}
+]
+\markdownInput{../../CHANGELOG.md}
+
+\page
+
+\setuplayout[
+ width=middle,
+ backspace=1in,
+ height=9.25in,
+]
+\section[sec:implementation]{Implementation}
+
+From here and until the end of this manual is the raw source code of \lwc/. This is primarily of interest to developers; most users need not read further.
+
+This code vaguely resembles the typical \LaTeX{} literate programming style, although I use extensive inline comments instead of arcane \sans{docstrip} macros. Hopefully this is useful as a reference for advanced \lwc/ users as well as anyone doing extensive node manipulation in \LuaTeX{}.
+
+If want to offer any improvements to the code below, please open an issue or a \acronym{PR} on \goto{GitHub}[url(projecturl)].
+
+\usemodule[scite]
+\setupbodyfont[10pt]
+\setuphead[subsection][
+ page=yes,
+ continue=yes,
+]
+
+\subsection{lua-widow-control.lua}
+
+\typeLUAfile{../source/lua-widow-control.lua}
+
+\subsection{lua-widow-control.tex}
+
+\typeTEXfile{../source/lua-widow-control.tex}
+
+\subsection{lua-widow-control.sty}
+
+\typeTEXfile{../source/lua-widow-control.sty}
+
+\subsection{lua-widow-control-2022-02-22.sty}
+
+\typeTEXfile{../source/lua-widow-control-2022-02-22.sty}
+
+\subsection{t-lua-widow-control.mkxl}
+
+\typeTEXfile{../source/t-lua-widow-control.mkxl}
+
+\subsection{lua-widow-control.opm}
+
+\typeTEXfile{../source/lua-widow-control.opm}
+
+\subsection{Demo from \in{Table}[tab:demo]}
+
+\typeTEXfile{\jobname-demo-text.tmp}
+
+\stopdocument
diff --git a/macros/context/contrib/context-lua-widow-control/source/luatex/lua-widow-control/lwc-zpravodaj-figure.ctx b/macros/context/contrib/context-lua-widow-control/source/luatex/lua-widow-control/lwc-zpravodaj-figure.ctx
new file mode 100644
index 0000000000..9ab907dea2
--- /dev/null
+++ b/macros/context/contrib/context-lua-widow-control/source/luatex/lua-widow-control/lwc-zpravodaj-figure.ctx
@@ -0,0 +1,161 @@
+% 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
+
+\startbuffer[demo-text]
+ \definepapersize[smallpaper][
+ width=6cm,
+ height=8.3cm
+ ]
+ \setuppapersize[smallpaper]
+
+ \def\lwc/{\sans{lua-\allowbreak widow-\allowbreak control}}
+ \def\Lwc/{\sans{lua-\allowbreak widow-\allowbreak control}}
+
+ \setupbodyfont[9pt]
+ \setupindenting[yes, 2em]
+ \setupalign[tolerant]
+
+ \definecolor[midlightgray][s=0.75]
+ \definepalet[layout][grid=midlightgray]
+ \showgrid[nonumber, none, lines]
+
+ \definefontfeature[default][default][expansion=quality,protrusion=quality]
+
+ \usetypescript[modern-base]
+ \setupbodyfont[reset,modern]
+
+ \setupalign[hz,hanging,tolerant]
+
+ \setuplanguage[en][spacing=packed]
+
+ \setuplayout[
+ topspace=0.1cm,
+ backspace=0.1cm,
+ width=middle,
+ height=\dimexpr 21\baselineskip + 1.1pt,
+ header=0pt,
+ footer=0pt,
+ ]
+
+ \starttext
+ % This text has been carefully adjusted to produce a good demonstration. Be careful before modifying it.
+ \Lwc/ can remove most widows and orphans from a document, \emph{without}
+ stretching any glue or shortening any pages.
+
+ \ifx\uselooseness\undefined\else\uselooseness\fi It does so by automatically lengthening a paragraph on a page where a
+ widow or orphan would otherwise occur. While \TeX{} breaks paragraphs
+ into their natural length, \lwc/ is breaking the paragraph 1~line
+ longer than its natural length. \TeX{}'s paragraph is output to the
+ page, but \lwc/'s paragraph is just stored for later. When a widow or
+ orphan occurs, \lwc/ can take over. It selects the previously-saved
+ paragraph with the least badness; then, it replaces \TeX{}'s paragraph
+ with its saved paragraph. This increases the text block height of the
+ page by 1~line.
+
+ Now, the last line of the current page can be pushed to the top of the
+ next page. This removes the widow or the orphan without creating any
+ additional work.
+ \stoptext
+ \stoptext
+\stopbuffer
+\savebuffer[list=demo-text]
+
+\startbuffer[shorten]
+ \parskip=0pt
+ \input lwc-zpravodaj-figure-demo-text.tmp
+\stopbuffer
+
+\startbuffer[shorten-code]
+ \parskip=0pt
+ \clubpenalty=10000
+ \widowpenalty=10000
+\stopbuffer
+
+\startbuffer[stretch]
+ \parskip=0pt plus 1fill
+ \input lwc-zpravodaj-figure-demo-text.tmp
+\stopbuffer
+
+\startbuffer[stretch-code]
+ \parskip=0pt plus 1fill
+ \clubpenalty=10000
+ \widowpenalty=10000
+\stopbuffer
+
+\startbuffer[ignore]
+ \startsetups[*default]
+ \clubpenalty=0
+ \widowpenalty=0
+ \displaywidowpenalty=0
+ \interlinepenalty=0
+ \brokenpenalty=0
+ \stopsetups
+
+ \setups[*default]
+
+ \input lwc-zpravodaj-figure-demo-text.tmp
+\stopbuffer
+
+\startbuffer[ignore-code]
+ \parskip=0pt
+ \clubpenalty=0
+ \widowpenalty=0
+\stopbuffer
+
+\startbuffer[lwc]
+ \def\uselooseness{\looseness=1}
+ \input lwc-zpravodaj-figure-demo-text.tmp
+\stopbuffer
+
+% We're pretending that we're using LaTeX for the demo since that's what
+% 99% of users will be using.
+\startbuffer[lwc-code]
+ \usepackage
+ {lua-widow-control}
+\stopbuffer
+
+\setupbodyfont[9pt]
+
+\setupbackend[format=PDF/A-1b:2005] % Force PDF version <1.5
+
+\startTEXpage[
+ align=normal,
+ width=492.5733pt,
+ offset=0pt,
+]
+ \veryraggedcenter
+ \setupTABLE[row][1][style=\bfa, align=middle, offset=0pt]
+ % \setupTABLE[row][4][toffset=2ex]
+ \setupTABLE[frame=off, distance=0em]
+ \startTABLE
+ \NC Ignore
+ \NC Shorten
+ \NC Stretch
+ \NC \sans{lua-widow-control}
+ \NC\NR
+
+ \NC \typesetbuffer[ignore][frame=on, page=1, scale=700]
+ \NC \typesetbuffer[shorten][frame=on, page=1, scale=700]
+ \NC \typesetbuffer[stretch][frame=on, page=1, scale=700]
+ \NC \typesetbuffer[lwc][frame=on, page=1, scale=700]
+ \NC\NR
+
+ \NC \clip[height=2cm]{\typesetbuffer[ignore]
+ [frame=on, page=2, scale=700]}
+ \NC \clip[height=2cm]{\typesetbuffer[shorten]
+ [frame=on, page=2, scale=700]}
+ \NC \clip[height=2cm]{\typesetbuffer[stretch]
+ [frame=on, page=2, scale=700]}
+ \NC \clip[height=2cm]{\typesetbuffer[lwc]
+ [frame=on, page=2, scale=700]}
+ \NC\NR
+
+ \NC \typebuffer[ignore-code]
+ \NC \typebuffer[shorten-code]
+ \NC \typebuffer[stretch-code]
+ \NC \typebuffer[lwc-code]
+ \NC\NR
+ \stopTABLE
+\stopTEXpage
diff --git a/macros/context/contrib/context-lua-widow-control/source/luatex/lua-widow-control/lwc-zpravodaj.bib b/macros/context/contrib/context-lua-widow-control/source/luatex/lua-widow-control/lwc-zpravodaj.bib
new file mode 100644
index 0000000000..6bbe904c0d
--- /dev/null
+++ b/macros/context/contrib/context-lua-widow-control/source/luatex/lua-widow-control/lwc-zpravodaj.bib
@@ -0,0 +1,237 @@
+% 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
+
+@book{texbook,
+ author = {Donald E. Knuth},
+ title = {The \TeX{}book},
+ publisher = {Addison--Wesley},
+ year = {2021},
+}
+
+@online{widows-and-orphans,
+ author = {Frank Mittelbach},
+ year = {2021},
+ month = {03},
+ title = {The \textsf{widows-and-orphans} package},
+ url = {https://ctan.org/pkg/widows-and-orphans},
+ urldate = {2022-11-08},
+}
+
+@online{widow-assist,
+ author = {jeremie},
+ title = {Paragraph callback to help with widows\slash orphans hand tuning},
+ url = {https://tex.stackexchange.com/q/372062},
+ year = {2017},
+ month = {07},
+ urldate = {2022-11-08},
+}
+
+@book{elements,
+ title = {The Elements of Typographic Style},
+ author = {Bringhurst, R.},
+ edition = {3rd},
+ publisher = {Hartley \& Marks},
+ year = {2004},
+}
+
+@online{oed-club,
+ title={club, n.},
+ journal={OED Online},
+ publisher={Oxford University Press},
+ month={09},
+ year={2021},
+ url={https://www.oed.com/view/Entry/34788},
+ author={{Oxford English Dictionary}},
+ urldate = {2022-11-08},
+}
+
+@online{oed-line,
+ title={line at end of paragraph},
+ journal={OED Online},
+ publisher={Oxford University Press},
+ month={12},
+ year={2021},
+ url={https://www.oed.com/view/th/class/195380},
+ author={{Oxford English Dictionary}},
+ urldate = {2022-11-08},
+}
+
+@online{oed-widow,
+ title={widow, n.},
+ journal={OED Online},
+ publisher={Oxford University Press},
+ month={12},
+ year={2021},
+ url={https://www.oed.com/view/Entry/228912},
+ author={{Oxford English Dictionary}},
+ urldate = {2022-11-08},
+}
+
+@article{widowhistory,
+ title={The Typographical Widow},
+ subtitle={Who is she? What is she?},
+ author={Karl Brown},
+ journal={Bulletin of the {New York} Public Library},
+ publisher={The {New York} Public Library},
+ location={New York},
+ volume={52},
+ number={1},
+ year={1948},
+ month={01},
+ pages={3--25},
+ url={https://hdl.handle.net/2027/uc1.b3310084}
+}
+
+@article{widowhistory2,
+ title={The Typographical Widow: Encore},
+ subtitle={Encore},
+ author={Karl Brown},
+ journal={Bulletin of the {New York} Public Library},
+ publisher={The {New York} Public Library},
+ location={New York},
+ volume={52},
+ number={9},
+ year={1948},
+ month={09},
+ pages={458-466},
+ urlnewline=1,
+ url={https://hdl.handle.net/2027/uc1.b3310084}
+}
+
+@book{old,
+ title={Mechanick exercises},
+ subtitle={The doctrine of handy-works applied to the art of printing},
+ volume={2},
+ author={Moxon, Joseph},
+ year={1683},
+ location={London},
+ pages={394},
+ url={https://archive.org/details/mechanickexercis00moxo_0}
+}
+
+@article{global,
+ url = {https://doi.org/10.1111/coin.12165},
+ year = {2018},
+ month = {03},
+ publisher = {Wiley},
+ volume = {35},
+ number = {2},
+ pages = {242--284},
+ author = {Frank Mittelbach},
+ title = {A general framework for globally optimized pagination},
+ journal = {Computational Intelligence}
+}
+
+@book{backwards1,
+ title={The Layout Book},
+ author={Ambrose, G. and Harris, P.},
+ isbn={9782940373536},
+ series={Advanced Level Series},
+ year={2007},
+ publisher={Bloomsbury Academic}
+}
+
+@book{backwards2,
+ title={Typography Essentials Revised and Updated},
+ subtitle={100 Design Principles for Working with Type},
+ author={Saltz, I.},
+ isbn={9781631596483},
+ year={2019},
+ publisher={Rockport Publishers}
+}
+
+@book{backwards3,
+ title={Advanced Typography: From Knowledge to Mastery},
+ author={Hunt, R.},
+ isbn={9781350055926},
+ lccn={2020024110},
+ year={2020},
+ publisher={Bloomsbury Publishing}
+}
+
+@article{gutenberg,
+ title={All Books (sorted by popularity)},
+ url={https://www.gutenberg.org/ebooks/search/?sort_order=downloads},
+ year={2022},
+ month={03},
+ journal={Project Gutenberg}
+}
+
+@online{etex,
+ title={The {\eTeX} manual},
+ author={{The \NTS{} Team}},
+ url={https://ctan.org/pkg/etex},
+ year={1998},
+ % month={02},
+ urldate = {2022-11-08},
+}
+
+@phdthesis{plass,
+ title={Optimal pagination techniques for automatic typesetting systems},
+ author={Plass, Michael Frederick},
+ year={1981},
+ school={Stanford University},
+ urlnewline=1,
+ url={https://tug.org/docs/plass/plass-thesis.pdf}
+}
+
+@article{tb133chernoff-widows,
+ title={Automatically removing widows and orphans with
+ \texttt{lua-widow-control}},
+ author={Chernoff, Max},
+ journal={TUGboat},
+ volume={43},
+ number={1},
+ pages={28--39},
+ year={2022},
+ month={05},
+ DOI={10.47397/tb/43-1/tb133chernoff-widows},
+}
+
+@online{luametalatex,
+ year={2022},
+ month={10},
+ url={https://github.com/zauguin/luametalatex},
+ author={Marcel Krüger},
+ title={\texttt{luametalatex}},
+ urldate = {2022-11-08},
+}
+
+@Book{naruby,
+ author = "Petr Ol{\v{s}}{\'a}k",
+ title = "{\TeX}book naruby. [{\TeX}book inside out]",
+ publisher = "Konvoj",
+ address = "Brno, Czech Republic",
+ pages = "467",
+ year = "1997",
+ ISBN = "80-85615-64-9",
+ ISBN-13 = "978-80-85615-64-7",
+ bibsource = "http://www.math.utah.edu/pub/tex/bib/texbook3.bib",
+ URL = "https://petr.olsak.net/ftp/olsak/tbn/tbn.pdf",
+}
+
+@article{mittelbach,
+ author = "Frank Mittelbach",
+ title = "Managing forlorn paragraph lines (a.k.a.~widows and
+ orphans) in {\LaTeX}",
+ journal = "TUGboat",
+ volume = "39",
+ number = "3",
+ pages = "246--251",
+ year = "2018",
+ ISSN = "0896-3207",
+ ISSN-L = "0896-3207",
+ URL = "https://tug.org/TUGboat/tb39-3/tb123mitt-widows.pdf",
+ issue = "123",
+}
+
+@PHDTHESIS{thanh,
+ author = {Thành, Hàn Thế},
+ title = {Micro-typographic extensions to the \TeX{} typesetting system},
+ date = {2001},
+ institution = {The Faculty of Informatics, Masaryk University},
+ location = {Brno},
+ url = {http://www.pragma-ade.nl/pdftex/thesis.pdf},
+}
diff --git a/macros/context/contrib/context-lua-widow-control/source/luatex/lua-widow-control/lwc-zpravodaj.ltx b/macros/context/contrib/context-lua-widow-control/source/luatex/lua-widow-control/lwc-zpravodaj.ltx
new file mode 100644
index 0000000000..1a00292e2f
--- /dev/null
+++ b/macros/context/contrib/context-lua-widow-control/source/luatex/lua-widow-control/lwc-zpravodaj.ltx
@@ -0,0 +1,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}
diff --git a/macros/context/contrib/context-lua-widow-control/source/luatex/lua-widow-control/tb133chernoff-widows-figure.ctx b/macros/context/contrib/context-lua-widow-control/source/luatex/lua-widow-control/tb133chernoff-widows-figure.ctx
new file mode 100644
index 0000000000..e61637e2a8
--- /dev/null
+++ b/macros/context/contrib/context-lua-widow-control/source/luatex/lua-widow-control/tb133chernoff-widows-figure.ctx
@@ -0,0 +1,166 @@
+% 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
+
+\startbuffer[demo-text]
+ \definepapersize[smallpaper][
+ width=6cm,
+ height=8.3cm
+ ]
+ \setuppapersize[smallpaper]
+
+ \def\lwc/{\sans{lua-\allowbreak widow-\allowbreak control}}
+ \def\Lwc/{\sans{lua-\allowbreak widow-\allowbreak control}}
+
+ \setupbodyfont[9pt]
+ \setupindenting[yes, 2em]
+ \setupalign[tolerant]
+
+ \definecolor[midlightgray][s=0.75]
+ \definepalet[layout][grid=midlightgray]
+ \showgrid[nonumber, none, lines]
+
+ \definefontfeature[default][default][expansion=quality,protrusion=quality]
+
+ \usetypescript[modern-base]
+ \setupbodyfont[reset,modern]
+
+ \setupalign[hz,hanging,tolerant]
+
+ \setuplanguage[en][spacing=packed]
+
+ \setuplayout[
+ topspace=0.1cm,
+ backspace=0.1cm,
+ width=middle,
+ height=\dimexpr 21\baselineskip + 1.1pt,
+ header=0pt,
+ footer=0pt,
+ ]
+
+ \starttext
+ \Lwc/ can remove most widows and orphans from a document, \emph{without}
+ stretching any glue or shortening any pages.
+
+ \ifx\uselooseness\undefined\else\uselooseness\fi It does so by automatically lengthening a paragraph on a page where a
+ widow or orphan would otherwise occur. While \TeX{} breaks paragraphs
+ into their natural length, \lwc/ is breaking the paragraph 1~line
+ longer than its natural length. \TeX{}'s paragraph is output to the
+ page, but \lwc/'s paragraph is just stored for later. When a widow or
+ orphan occurs, \lwc/ can take over. It selects the previously-saved
+ paragraph with the least badness; then, it replaces \TeX{}'s paragraph
+ with its saved paragraph. This increases the text block height of the
+ page by 1~line.
+
+ Now, the last line of the current page can be pushed to the top of the
+ next page. This removes the widow or the orphan without creating any
+ additional work.
+ \stoptext
+ \stoptext
+\stopbuffer
+\savebuffer[list=demo-text]
+
+\startbuffer[shorten]
+ \parskip=0pt
+ \input tb133chernoff-widows-figure-demo-text.tmp
+\stopbuffer
+
+\startbuffer[shorten-code]
+ \parskip=0pt
+ \clubpenalty=10000
+ \widowpenalty=10000
+\stopbuffer
+
+\startbuffer[stretch]
+ \parskip=0pt plus 1fill
+ \input tb133chernoff-widows-figure-demo-text.tmp
+\stopbuffer
+
+\startbuffer[stretch-code]
+ \parskip=0pt plus 1fill
+ \clubpenalty=10000
+ \widowpenalty=10000
+\stopbuffer
+
+\startbuffer[ignore]
+ \startsetups[*default]
+ \clubpenalty=0
+ \widowpenalty=0
+ \displaywidowpenalty=0
+ \interlinepenalty=0
+ \brokenpenalty=0
+ \stopsetups
+
+ \setups[*default]
+
+ \input tb133chernoff-widows-figure-demo-text.tmp
+\stopbuffer
+
+\startbuffer[ignore-code]
+ \parskip=0pt
+ \clubpenalty=0
+ \widowpenalty=0
+\stopbuffer
+
+\startbuffer[lwc]
+ \def\uselooseness{\looseness=1}
+ \input tb133chernoff-widows-figure-demo-text.tmp
+\stopbuffer
+
+% We're pretending that we're using LaTeX for the demo since that's what
+% 99% of users will be using.
+\startbuffer[lwc-code]
+ \usepackage{lua-widow-control}
+\stopbuffer
+
+\setupbodyfont[10pt]
+
+\setupbackend[format=PDF/A-1b:2005] % Force PDF version <1.5
+
+\startTEXpage[
+ align=normal,
+ width=39pc,
+ offset=0pt,
+]
+ \veryraggedcenter
+ \setupTABLE[row][1, 5][style=\bfa, align=middle, offset=0pt]
+ \setupTABLE[row][5][toffset=2ex]
+ \setupTABLE[frame=off, distance=5em]
+ \startTABLE
+ \NC Ignore
+ \NC Shorten
+ \NC\NR
+
+ \NC \typesetbuffer[ignore][frame=on, page=1, scale=925]
+ \NC \typesetbuffer[shorten][frame=on, page=1, scale=925]
+ \NC\NR
+
+ \NC \clip[height=1cm]{\typesetbuffer[ignore]
+ [frame=on, page=2, scale=925]}
+ \NC \clip[height=1cm]{\typesetbuffer[shorten]
+ [frame=on, page=2, scale=925]}
+ \NC\NR
+
+ \NC \typebuffer[ignore-code]
+ \NC \typebuffer[shorten-code]
+ \NC\NR
+
+ \NC Stretch
+ \NC \sans{lua-widow-control} \NC\NR
+
+ \NC \typesetbuffer[stretch][frame=on, page=1, scale=925]
+ \NC \typesetbuffer[lwc][frame=on, page=1, scale=925]
+ \NC\NR
+
+ \NC \clip[height=1cm]{\typesetbuffer[stretch]
+ [frame=on, page=2, scale=925]}
+ \NC \clip[height=1cm]{\typesetbuffer[lwc]
+ [frame=on, page=2, scale=925]}
+ \NC\NR
+
+ \NC \typebuffer[stretch-code]
+ \NC \typebuffer[lwc-code]
+ \NC\NR
+ \stopTABLE
+\stopTEXpage
diff --git a/macros/context/contrib/context-lua-widow-control/source/luatex/lua-widow-control/tb133chernoff-widows-plot.dat b/macros/context/contrib/context-lua-widow-control/source/luatex/lua-widow-control/tb133chernoff-widows-plot.dat
new file mode 100644
index 0000000000..e6705bd361
--- /dev/null
+++ b/macros/context/contrib/context-lua-widow-control/source/luatex/lua-widow-control/tb133chernoff-widows-plot.dat
@@ -0,0 +1,1575 @@
+% 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
+
+Percentile Natural Long
+0.063734863 nan nan
+0.127469726 nan nan
+0.191204589 nan nan
+0.254939452 nan nan
+0.318674315 nan nan
+0.382409178 nan nan
+0.446144041 100 nan
+0.509878904 100 nan
+0.573613767 100 nan
+0.63734863 100 nan
+0.701083493 100 nan
+0.764818356 100 nan
+0.828553219 100 nan
+0.892288082 100 nan
+0.956022945 100 nan
+1.019757808 100 nan
+1.08349267 100 nan
+1.147227533 100 nan
+1.210962396 100 nan
+1.274697259 100 nan
+1.338432122 100 nan
+1.402166985 100 nan
+1.465901848 100 nan
+1.529636711 100 nan
+1.593371574 100 nan
+1.657106437 100 nan
+1.7208413 100 nan
+1.784576163 100 nan
+1.848311026 100 nan
+1.912045889 100 nan
+1.975780752 100 nan
+2.039515615 100 nan
+2.103250478 100 nan
+2.166985341 100 nan
+2.230720204 100 nan
+2.294455067 100 nan
+2.35818993 100 nan
+2.421924793 100 nan
+2.485659656 100 nan
+2.549394519 100 nan
+2.613129382 100 nan
+2.676864245 100 nan
+2.740599108 100 nan
+2.804333971 100 nan
+2.868068834 100 nan
+2.931803697 100 nan
+2.99553856 100 nan
+3.059273423 100 nan
+3.123008286 100 nan
+3.186743149 100 nan
+3.250478011 100 nan
+3.314212874 100 nan
+3.377947737 100 nan
+3.4416826 100 nan
+3.505417463 100 nan
+3.569152326 100 nan
+3.632887189 100 nan
+3.696622052 100 nan
+3.760356915 100 nan
+3.824091778 100 nan
+3.887826641 100 nan
+3.951561504 100 nan
+4.015296367 100 nan
+4.07903123 100 nan
+4.142766093 100 nan
+4.206500956 100 nan
+4.270235819 100 nan
+4.333970682 100 nan
+4.397705545 100 nan
+4.461440408 100 nan
+4.525175271 100 nan
+4.588910134 100 nan
+4.652644997 100 nan
+4.71637986 100 nan
+4.780114723 100 nan
+4.843849586 100 nan
+4.907584449 100 nan
+4.971319312 100 nan
+5.035054175 100 nan
+5.098789038 100 nan
+5.162523901 100 nan
+5.226258764 100 nan
+5.289993627 100 nan
+5.353728489 100 nan
+5.417463352 100 nan
+5.481198215 100 nan
+5.544933078 100 nan
+5.608667941 100 nan
+5.672402804 100 nan
+5.736137667 100 nan
+5.79987253 100 nan
+5.863607393 100 nan
+5.927342256 100 nan
+5.991077119 100 nan
+6.054811982 100 nan
+6.118546845 100 nan
+6.182281708 100 nan
+6.246016571 100 nan
+6.309751434 100 nan
+6.373486297 100 nan
+6.43722116 100 nan
+6.500956023 100 nan
+6.564690886 100 nan
+6.628425749 100 nan
+6.692160612 100 nan
+6.755895475 100 nan
+6.819630338 100 nan
+6.883365201 100 nan
+6.947100064 100 nan
+7.010834927 100 nan
+7.07456979 100 nan
+7.138304653 100 nan
+7.202039516 100 nan
+7.265774379 100 nan
+7.329509242 100 nan
+7.393244105 100 nan
+7.456978967 100 nan
+7.52071383 100 nan
+7.584448693 100 nan
+7.648183556 100 nan
+7.711918419 100 nan
+7.775653282 100 nan
+7.839388145 100 nan
+7.903123008 100 nan
+7.966857871 100 nan
+8.030592734 100 nan
+8.094327597 100 nan
+8.15806246 100 nan
+8.221797323 100 nan
+8.285532186 100 nan
+8.349267049 100 nan
+8.413001912 100 nan
+8.476736775 100 nan
+8.540471638 100 nan
+8.604206501 100 nan
+8.667941364 100 nan
+8.731676227 100 nan
+8.79541109 100 nan
+8.859145953 100 nan
+8.922880816 100 nan
+8.986615679 100 nan
+9.050350542 100 nan
+9.114085405 100 nan
+9.177820268 100 nan
+9.241555131 100 nan
+9.305289994 100 nan
+9.369024857 100 nan
+9.43275972 100 nan
+9.496494583 100 nan
+9.560229446 100 nan
+9.623964308 100 nan
+9.687699171 100 nan
+9.751434034 100 nan
+9.815168897 100 nan
+9.87890376 100 nan
+9.942638623 100 nan
+10.00637349 100 nan
+10.07010835 100 nan
+10.13384321 100 nan
+10.19757808 100 nan
+10.26131294 100 nan
+10.3250478 100 nan
+10.38878266 100 nan
+10.45251753 100 nan
+10.51625239 100 nan
+10.57998725 100 nan
+10.64372212 100 nan
+10.70745698 100 nan
+10.77119184 100 nan
+10.8349267 100 nan
+10.89866157 100 nan
+10.96239643 100 nan
+11.02613129 100 nan
+11.08986616 100 nan
+11.15360102 100 nan
+11.21733588 100 nan
+11.28107075 100 nan
+11.34480561 100 nan
+11.40854047 100 nan
+11.47227533 100 nan
+11.5360102 100 nan
+11.59974506 100 nan
+11.66347992 100 nan
+11.72721479 100 nan
+11.79094965 100 nan
+11.85468451 100 nan
+11.91841938 100 nan
+11.98215424 100 nan
+12.0458891 100 nan
+12.10962396 100 nan
+12.17335883 100 nan
+12.23709369 100 nan
+12.30082855 100 nan
+12.36456342 100 nan
+12.42829828 100 nan
+12.49203314 100 nan
+12.55576801 100 nan
+12.61950287 100 nan
+12.68323773 100 nan
+12.74697259 100 nan
+12.81070746 100 nan
+12.87444232 100 nan
+12.93817718 100 nan
+13.00191205 100 nan
+13.06564691 100 nan
+13.12938177 100 nan
+13.19311663 100 nan
+13.2568515 100 nan
+13.32058636 100 nan
+13.38432122 100 nan
+13.44805609 100 nan
+13.51179095 100 nan
+13.57552581 100 nan
+13.63926068 100 nan
+13.70299554 100 nan
+13.7667304 100 nan
+13.83046526 100 nan
+13.89420013 100 nan
+13.95793499 100 nan
+14.02166985 100 nan
+14.08540472 100 nan
+14.14913958 100 nan
+14.21287444 100 nan
+14.27660931 100 nan
+14.34034417 100 nan
+14.40407903 100 nan
+14.46781389 100 nan
+14.53154876 100 nan
+14.59528362 100 nan
+14.65901848 100 nan
+14.72275335 100 nan
+14.78648821 100 nan
+14.85022307 100 nan
+14.91395793 100 nan
+14.9776928 100 nan
+15.04142766 100 nan
+15.10516252 100 nan
+15.16889739 100 nan
+15.23263225 100 nan
+15.29636711 100 nan
+15.36010198 100 nan
+15.42383684 100 nan
+15.4875717 100 nan
+15.55130656 100 nan
+15.61504143 100 nan
+15.67877629 100 nan
+15.74251115 100 nan
+15.80624602 100 nan
+15.86998088 100 nan
+15.93371574 100 nan
+15.99745061 100 nan
+16.06118547 100 nan
+16.12492033 100 nan
+16.18865519 100 nan
+16.25239006 100 nan
+16.31612492 100 nan
+16.37985978 100 nan
+16.44359465 100 nan
+16.50732951 100 nan
+16.57106437 100 nan
+16.63479924 100 nan
+16.6985341 100 nan
+16.76226896 100 nan
+16.82600382 100 nan
+16.88973869 100 nan
+16.95347355 100 nan
+17.01720841 100 nan
+17.08094328 100 nan
+17.14467814 100 nan
+17.208413 100 nan
+17.27214786 100 nan
+17.33588273 100 nan
+17.39961759 100 nan
+17.46335245 100 nan
+17.52708732 100 nan
+17.59082218 100 nan
+17.65455704 100 nan
+17.71829191 100 nan
+17.78202677 100 nan
+17.84576163 100 nan
+17.90949649 100 nan
+17.97323136 100 nan
+18.03696622 100 nan
+18.10070108 100 nan
+18.16443595 100 nan
+18.22817081 100 nan
+18.29190567 100 nan
+18.35564054 100 nan
+18.4193754 100 nan
+18.48311026 100 nan
+18.54684512 100 nan
+18.61057999 100 nan
+18.67431485 100 nan
+18.73804971 100 nan
+18.80178458 100 nan
+18.86551944 100 nan
+18.9292543 100 nan
+18.99298917 100 nan
+19.05672403 100 nan
+19.12045889 100 nan
+19.18419375 100 nan
+19.24792862 100 nan
+19.31166348 100 nan
+19.37539834 100 nan
+19.43913321 100 nan
+19.50286807 100 nan
+19.56660293 100 nan
+19.63033779 100 nan
+19.69407266 100 nan
+19.75780752 100 nan
+19.82154238 100 nan
+19.88527725 100 nan
+19.94901211 100 nan
+20.01274697 100 nan
+20.07648184 100 nan
+20.1402167 100 nan
+20.20395156 100 nan
+20.26768642 100 nan
+20.33142129 100 nan
+20.39515615 100 nan
+20.45889101 100 nan
+20.52262588 100 nan
+20.58636074 100 nan
+20.6500956 100 nan
+20.71383047 100 nan
+20.77756533 100 nan
+20.84130019 100 nan
+20.90503505 100 nan
+20.96876992 100 nan
+21.03250478 100 nan
+21.09623964 100 nan
+21.15997451 100 nan
+21.22370937 100 nan
+21.28744423 100 nan
+21.35117909 100 nan
+21.41491396 100 nan
+21.47864882 100 nan
+21.54238368 100 nan
+21.60611855 100 nan
+21.66985341 100 nan
+21.73358827 100 nan
+21.79732314 100 nan
+21.861058 100 nan
+21.92479286 100 nan
+21.98852772 100 nan
+22.05226259 100 nan
+22.11599745 100 nan
+22.17973231 100 nan
+22.24346718 100 nan
+22.30720204 100 nan
+22.3709369 100 nan
+22.43467177 100 nan
+22.49840663 100 nan
+22.56214149 100 nan
+22.62587635 100 nan
+22.68961122 100 nan
+22.75334608 100 nan
+22.81708094 100 nan
+22.88081581 100 nan
+22.94455067 100 nan
+23.00828553 100 nan
+23.0720204 100 nan
+23.13575526 100 nan
+23.19949012 100 nan
+23.26322498 100 nan
+23.32695985 100 nan
+23.39069471 100 nan
+23.45442957 100 nan
+23.51816444 100 nan
+23.5818993 100 nan
+23.64563416 100 nan
+23.70936902 100 nan
+23.77310389 100 nan
+23.83683875 100 nan
+23.90057361 100 nan
+23.96430848 100 nan
+24.02804334 100 nan
+24.0917782 100 nan
+24.15551307 100 nan
+24.21924793 100 nan
+24.28298279 100 nan
+24.34671765 100 nan
+24.41045252 100 nan
+24.47418738 100 nan
+24.53792224 100 nan
+24.60165711 100 nan
+24.66539197 100 nan
+24.72912683 100 nan
+24.7928617 100 nan
+24.85659656 100 nan
+24.92033142 100 nan
+24.98406628 100 nan
+25.04780115 100 nan
+25.11153601 100 nan
+25.17527087 100 nan
+25.23900574 100 nan
+25.3027406 100 nan
+25.36647546 100 nan
+25.43021033 100 nan
+25.49394519 100 nan
+25.55768005 100 nan
+25.62141491 100 nan
+25.68514978 100 nan
+25.74888464 100 nan
+25.8126195 100 nan
+25.87635437 100 nan
+25.94008923 100 nan
+26.00382409 100 nan
+26.06755895 100 nan
+26.13129382 100 nan
+26.19502868 100 nan
+26.25876354 100 nan
+26.32249841 100 nan
+26.38623327 100 nan
+26.44996813 100 nan
+26.513703 100 nan
+26.57743786 100 nan
+26.64117272 100 nan
+26.70490758 100 nan
+26.76864245 100 nan
+26.83237731 100 nan
+26.89611217 100 nan
+26.95984704 100 nan
+27.0235819 100 nan
+27.08731676 100 nan
+27.15105163 100 nan
+27.21478649 100 nan
+27.27852135 100 nan
+27.34225621 100 nan
+27.40599108 100 nan
+27.46972594 100 nan
+27.5334608 100 nan
+27.59719567 100 nan
+27.66093053 100 nan
+27.72466539 100 nan
+27.78840025 100 nan
+27.85213512 100 nan
+27.91586998 100 nan
+27.97960484 121 nan
+28.04333971 141.4213562 nan
+28.10707457 141.4213562 nan
+28.17080943 141.4213562 nan
+28.2345443 141.4213562 nan
+28.29827916 141.4213562 nan
+28.36201402 141.4213562 nan
+28.42574888 141.4213562 nan
+28.48948375 141.4213562 nan
+28.55321861 141.4213562 nan
+28.61695347 141.4213562 nan
+28.68068834 141.4213562 nan
+28.7444232 141.4213562 nan
+28.80815806 141.4213562 nan
+28.87189293 141.4213562 nan
+28.93562779 141.4213562 140.8734657
+28.99936265 141.4213562 141.4213562
+29.06309751 141.4213562 141.4213562
+29.12683238 141.4213562 141.4213562
+29.19056724 141.4213562 141.4213562
+29.2543021 141.4213562 155.3072224
+29.31803697 141.4213562 170.8956797
+29.38177183 141.4213562 172.5340546
+29.44550669 141.4213562 172.5340546
+29.50924156 141.4213562 172.5340546
+29.57297642 141.4213562 187.383297
+29.63671128 141.4213562 187.383297
+29.70044614 141.4213562 190.2117241
+29.76418101 141.4213562 190.2117241
+29.82791587 141.4213562 190.2117241
+29.89165073 141.4213562 190.2117241
+29.9553856 141.4213562 190.2117241
+30.01912046 141.4213562 205.0609665
+30.08285532 141.4213562 205.0609665
+30.14659018 141.4213562 209.3036072
+30.21032505 141.4213562 209.3036072
+30.27405991 141.4213562 209.3036072
+30.33779477 141.4213562 209.3036072
+30.40152964 141.4213562 213.0422493
+30.4652645 141.4213562 221.3244225
+30.52899936 141.4213562 224.1528496
+30.59273423 141.4213562 229.8097039
+30.65646909 141.4213562 229.8097039
+30.72020395 141.4213562 229.8097039
+30.78393881 141.4213562 229.8097039
+30.84767368 141.4213562 233.5
+30.91140854 141.4213562 240.4163056
+30.9751434 141.4213562 244.6589463
+31.03887827 141.4213562 244.6589463
+31.10261313 141.4213562 251.7300141
+31.16634799 141.4213562 251.7300141
+31.23008286 141.4213562 251.7300141
+31.29381772 141.4213562 251.7300141
+31.35755258 141.4213562 260.9224023
+31.42128744 141.4213562 266.1584741
+31.48502231 141.4213562 266.5792565
+31.54875717 141.4213562 275.0645379
+31.61249203 141.4213562 275.0645379
+31.6762269 141.4213562 275.0645379
+31.73996176 141.4213562 278.6000718
+31.80369662 141.4213562 280.5922308
+31.86743149 141.4213562 282.8427125
+31.93116635 141.4213562 288.6751346
+31.99490121 141.4213562 289.9137803
+32.05863607 141.4213562 297.3353886
+32.12237094 141.4213562 299.8132752
+32.1861058 141.4213562 299.8132752
+32.24984066 141.4213562 300.520382
+32.31357553 141.4213562 306.1772363
+32.37731039 141.4213562 314.6558967
+32.44104525 141.4213562 314.6625176
+32.50478011 141.4213562 319.6122651
+32.56851498 141.4213562 325.9762261
+32.63224984 141.4213562 325.9762261
+32.6959847 141.4213562 325.9762261
+32.75971957 141.4213562 330.9259736
+32.82345443 141.4213562 340.0593086
+32.88718929 141.4213562 340.1183618
+32.95092416 141.4213562 346.4101615
+33.01465902 141.4213562 349.2969129
+33.07839388 141.4213562 353.5533906
+33.14212874 141.4213562 357.0889245
+33.20586361 141.4213562 363.4528855
+33.26959847 141.4213562 368.402633
+33.33333333 141.4213562 372.3909236
+33.3970682 141.4213562 379.3191269
+33.46080306 141.4213562 382.5447686
+33.52453792 141.4213562 382.5447686
+33.58827279 141.4213562 384.666089
+33.65200765 141.4213562 391.5
+33.71574251 141.4213562 396.0622847
+33.77947737 141.4213562 404.7225387
+33.84321224 141.4213562 409.9186911
+33.9069471 141.4213562 412.9503602
+33.97068196 141.4213562 412.9503602
+34.03441683 141.4213562 419.1562954
+34.09815169 141.4213562 433.0127019
+34.16188655 141.4213562 437.631504
+34.22562141 141.4213562 444.7701654
+34.28935628 141.4213562 444.7701654
+34.35309114 141.4213562 448.5
+34.416826 141.4213562 459.6194078
+34.48056087 141.4213562 461.7407281
+34.54429573 141.4213562 467.653718
+34.60803059 141.4213562 473.4272207
+34.67176546 141.4213562 476.3139721
+34.73550032 141.4213562 478.0041841
+34.79923518 141.4213562 480.8326112
+34.86297004 141.4213562 484.9742261
+34.92670491 141.4213562 492.8534265
+34.99043977 141.4213562 497.0985818
+35.05417463 141.4213562 508.6455872
+35.1179095 141.4213562 512.6524164
+35.18164436 141.4213562 516.1511407
+35.24537922 141.4213562 520.5
+35.30911409 141.4213562 527.5016588
+35.37284895 141.4213562 536.3584001
+35.43658381 141.4213562 543.2866033
+35.50031867 141.4213562 545.8864351
+35.56405354 141.4213562 548.7148622
+35.6277884 141.4213562 550.7921568
+35.69152326 141.4213562 557.72036
+35.75525813 141.4213562 563.5641046
+35.81899299 141.4213562 568.1126649
+35.88272785 141.4213562 577.3502692
+35.94646272 141.4213562 582.5
+36.01019758 141.4213562 586.1915216
+36.07393244 141.4213562 586.5878735
+36.1376673 141.4213562 594.093427
+36.20140217 141.4213562 600.5
+36.26513703 141.4213562 601.040764
+36.32887189 141.4213562 605.6404324
+36.39260676 141.4213562 612.5686356
+36.45634162 141.4213562 617.30422
+36.52007648 141.4213562 625.0823946
+36.58381134 141.4213562 625.2703415
+36.64754621 141.4213562 634.9818895
+36.71128107 141.4213562 639.931637
+36.77501593 141.4213562 647.2096518
+36.8387508 141.4213562 656.1950929
+36.90248566 141.4213562 661.0660582
+36.96622052 141.4213562 665.3874811
+37.02995539 141.4213562 669
+37.09369025 141.4213562 673.8727625
+37.15742511 141.4213562 680.2367235
+37.22115997 141.4213562 692.9646456
+37.28489484 141.4213562 698.0164755
+37.3486297 141.4213562 707.1067812
+37.41236456 141.4213562 713.0275824
+37.47609943 141.4213562 716.4916841
+37.53983429 141.4213562 721.6878365
+37.60356915 141.4213562 727.4613392
+37.66730402 141.4213562 728.6160397
+37.73103888 141.4213562 733.5
+37.79477374 141.4213562 742.4724462
+37.8585086 141.4213562 746.5138981
+37.92224347 141.4213562 750.5
+37.98597833 141.4213562 756.3288526
+38.04971319 141.4213562 764.9891067
+38.11344806 141.4213562 769.6079088
+38.17718292 141.4213562 774.9890322
+38.24091778 141.4213562 775.4683746
+38.30465264 141.4213562 781.3529932
+38.36838751 141.4213562 787.9903553
+38.43212237 141.4213562 794.7880221
+38.49585723 141.4213562 795
+38.5595921 141.4213562 799.6301228
+38.62332696 141.4213562 808.2903769
+38.68706182 141.4213562 809.6372645
+38.75079669 141.4213562 816.3732806
+38.81453155 141.4213562 822.7241336
+38.87826641 141.4213562 825.9007204
+38.94200127 141.4213562 836.2894236
+39.00573614 141.4213562 840.7499628
+39.069471 141.4213562 843.57839
+39.13320586 141.4213562 849
+39.19694073 141.4213562 853.5
+39.26067559 141.4213562 856.7877995
+39.32441045 141.4213562 864.9110937
+39.38814532 141.4213562 871.8626612
+39.45188018 141.4213562 877
+39.51561504 141.4213562 888.1261172
+39.5793499 141.4213562 893.1608664
+39.64308477 141.4213562 903.5
+39.70681963 141.4213562 906.5108935
+39.77055449 141.4213562 917.986928
+39.83428936 141.4213562 922
+39.89802422 141.4213562 930.1112837
+39.96175908 141.4213562 936.9164851
+40.02549395 141.4213562 936.9164851
+40.08922881 141.4213562 945.6997409
+40.15296367 141.4213562 952.0505939
+40.21669853 141.4213562 961.0620167
+40.2804334 141.4213562 972.8352036
+40.34416826 141.4213562 976.267279
+40.40790312 141.4213562 987.1210665
+40.47163799 141.4213562 998.434775
+40.53537285 141.4213562 1001.970309
+40.59910771 141.4213562 1008.05357
+40.66284257 141.4213562 1019.023225
+40.72657744 141.4213562 1025
+40.7903123 141.4213562 1035.911434
+40.85404716 141.4213562 1039.230485
+40.91778203 141.4213562 1044.426637
+40.98151689 141.4213562 1053.589104
+41.04525175 141.4213562 1058.283043
+41.10898662 141.4213562 1062.5
+41.17272148 141.4213562 1069.85256
+41.23645634 141.4213562 1079.067653
+41.3001912 141.4213562 1084.5
+41.36392607 141.4213562 1091.77287
+41.42766093 141.4213562 1097.542862
+41.49139579 141.4213562 1103.5
+41.55513066 141.4213562 1112.728594
+41.61886552 141.4213562 1124.294979
+41.68260038 141.4213562 1127.244654
+41.74633525 141.4213562 1133.239251
+41.81007011 141.4213562 1141.263435
+41.87380497 141.4213562 1147.5
+41.93753983 141.4213562 1156.941572
+42.0012747 141.4213562 1161.069335
+42.06500956 141.4213562 1172.383043
+42.12874442 141.4213562 1177.332791
+42.19247929 141.4213562 1189.341555
+42.25621415 141.4213562 1199.733859
+42.31994901 141.4213562 1202.081528
+42.38368388 141.4213562 1202.081528
+42.44741874 141.4213562 1209
+42.5111536 141.4213562 1217.050468
+42.57488846 141.4213562 1225.416052
+42.63862333 141.4213562 1233.5
+42.70235819 141.4213562 1245.344531
+42.76609305 141.4213562 1252.272734
+42.82982792 141.4213562 1257.5
+42.89356278 141.4213562 1259.357177
+42.95729764 141.4213562 1262.665039
+43.0210325 141.4213562 1274.20642
+43.08476737 141.4213562 1279.985547
+43.14850223 141.4213562 1290.469876
+43.21223709 141.4213562 1296.025
+43.27597196 141.4213562 1308.147545
+43.33970682 141.4213562 1318.04704
+43.40344168 141.4213562 1323.703894
+43.46717655 141.4213562 1332.896283
+43.53091141 141.4213562 1343
+43.59464627 141.4213562 1354.5
+43.65838113 141.4213562 1363.301874
+43.722116 141.4213562 1373
+43.78585086 141.4213562 1378.151117
+43.84958572 141.4213562 1387.343505
+43.91332059 141.4213562 1399.47514
+43.97705545 141.4213562 1409.312007
+44.04079031 141.4213562 1423
+44.10452518 141.4213562 1438.686137
+44.16826004 141.4213562 1442.798323
+44.2319949 141.4213562 1446.033368
+44.29572976 141.4213562 1454.518649
+44.35946463 141.4213562 1473
+44.42319949 141.4213562 1481.618642
+44.48693435 141.4213562 1500.128436
+44.55066922 141.4213562 1508.616253
+44.61440408 141.4213562 1517.853858
+44.67813894 141.4213562 1540.947868
+44.7418738 141.4213562 1548.453422
+44.80560867 141.4213562 1555.6703
+44.86934353 141.4213562 1566.948627
+44.93307839 141.4213562 1572
+44.99681326 141.4213562 1581.79787
+45.06054812 141.4213562 1596.4
+45.12428298 141.4213562 1600.360317
+45.18801785 141.4213562 1612.539302
+45.25175271 156.2705986 1618.567422
+45.31548757 156.2705986 1627.5
+45.37922243 156.2705986 1632.709558
+45.4429573 156.2705986 1639.5
+45.50669216 156.2705986 1646.025617
+45.57042702 156.2705986 1654.5
+45.63416189 156.2705986 1668.402565
+45.69789675 156.2705986 1683.553385
+45.76163161 156.2705986 1690.760295
+45.82536648 156.2705986 1699.884702
+45.88910134 156.2705986 1701
+45.9528362 156.2705986 1707.799336
+46.01657106 156.2705986 1714.733944
+46.08030593 156.2705986 1730.006613
+46.14404079 156.2705986 1743.941617
+46.20777565 156.2705986 1751.503497
+46.27151052 156.2705986 1768.47406
+46.33524538 156.2705986 1789.318306
+46.39898024 156.2705986 1801.708078
+46.46271511 156.2705986 1815.5
+46.52644997 156.2705986 1831.355054
+46.59018483 156.2705986 1839.914186
+46.65391969 156.2705986 1850.479855
+46.71765456 169 1868.176116
+46.78138942 172.5340546 1879.467576
+46.84512428 172.5340546 1899.482386
+46.90885915 172.5340546 1911
+46.97259401 172.5340546 1924.744658
+47.03632887 172.5340546 1934.123402
+47.10006373 172.5340546 1943
+47.1637986 172.5340546 1969.292386
+47.22753346 172.5340546 1982.727414
+47.29126832 172.5340546 1995.5
+47.35500319 172.5340546 2006.597404
+47.41873805 172.5340546 2020.204074
+47.48247291 173.2050808 2032.789485
+47.54620778 173.2050808 2050.5
+47.60994264 173.2050808 2056.973626
+47.6736775 173.2050808 2071.115762
+47.73741236 173.2050808 2087.966061
+47.80114723 173.2050808 2098.692927
+47.86488209 173.2050808 2111.420849
+47.92861695 173.2050808 2120.680042
+47.99235182 173.2050808 2132.731894
+48.05608668 173.2050808 2151.584955
+48.11982154 173.2050808 2174.801328
+48.18355641 173.2050808 2187.163294
+48.24729127 173.2050808 2209.708691
+48.31102613 173.2050808 2227.222493
+48.37476099 173.2050808 2258.499059
+48.43849586 173.2050808 2269.105661
+48.50223072 173.2050808 2286.609368
+48.56596558 173.2050808 2298.44668
+48.62970045 173.2050808 2314.597229
+48.69343531 173.2050808 2330.381182
+48.75717017 173.2050808 2346.333333
+48.82090504 173.2050808 2359.629096
+48.8846399 173.2050808 2379.068009
+48.94837476 173.2050808 2388.498064
+49.01210962 173.2050808 2398.506202
+49.07584449 173.2050808 2414.059089
+49.13957935 173.2050808 2421.840726
+49.20331421 173.2050808 2455.470695
+49.26704908 173.2050808 2467.0177
+49.33078394 173.2050808 2492.421112
+49.3945188 173.2050808 2508.58692
+49.45825366 173.2050808 2532.149383
+49.52198853 173.2050808 2541.495885
+49.58572339 173.2050808 2558.665888
+49.64945825 173.2050808 2566.899297
+49.71319312 173.2050808 2586.410889
+49.77692798 173.2050808 2600.031634
+49.84066284 173.2050808 2616.29509
+49.90439771 173.2050808 2631.144333
+49.96813257 173.2050808 2647.407789
+50.03186743 173.2050808 2665.085458
+50.09560229 173.2050808 2687.619783
+50.15933716 173.2050808 2704.683438
+50.22307202 173.2050808 2728.557372
+50.28680688 173.2050808 2741.666667
+50.35054175 173.2050808 2756.302233
+50.41427661 173.2050808 2775.900094
+50.47801147 173.2050808 2790.243359
+50.54174634 173.2050808 2812.163669
+50.6054812 173.2050808 2828.427125
+50.66921606 173.2050808 2838.253923
+50.73295092 173.2050808 2855.5
+50.79668579 173.2050808 2877.217493
+50.86042065 173.2050808 2886.409881
+50.92415551 173.2050808 2895.44235
+50.98789038 173.2050808 2919.6439
+51.05162524 173.2050808 2938.571195
+51.1153601 173.2050808 2945.099744
+51.17909496 173.2050808 2956.610729
+51.24282983 173.2050808 2973.384015
+51.30656469 173.2050808 2999.740179
+51.37029955 173.2050808 3021.467276
+51.43403442 173.2050808 3048.333333
+51.49776928 173.2050808 3059.114969
+51.56150414 173.2050808 3089.349527
+51.62523901 173.2050808 3117.691454
+51.68897387 173.2050808 3140.261215
+51.75270873 173.2050808 3168.545486
+51.81644359 173.2050808 3189.642188
+51.88017846 173.2050808 3218.750068
+51.94391332 173.2050808 3242.791699
+52.00764818 173.2050808 3269.661756
+52.07138305 173.2050808 3312.79527
+52.13511791 173.2050808 3334.305565
+52.19885277 173.2050808 3340.372434
+52.26258764 173.2050808 3352.94321
+52.3263225 173.2050808 3355.221677
+52.39005736 173.2050808 3366.675674
+52.45379222 173.2050808 3387.195772
+52.51752709 173.2050808 3401.183618
+52.58126195 173.2050808 3413.362506
+52.64499681 173.2050808 3436.677477
+52.70873168 173.2050808 3457.045053
+52.77246654 173.2050808 3468.358762
+52.8362014 173.2050808 3486.036431
+52.89993627 173.2050808 3506.248185
+52.96367113 173.2050808 3508.989028
+53.02740599 173.2050808 3525.634411
+53.09114085 173.2050808 3541.177876
+53.15487572 173.2050808 3560.282643
+53.21861058 173.2050808 3576.677808
+53.28234544 173.2050808 3595.442694
+53.34608031 173.2050808 3617.676787
+53.40981517 173.2050808 3626.043574
+53.47355003 173.2050808 3652.206525
+53.53728489 173.2050808 3677.721215
+53.60101976 173.2050808 3713.724815
+53.66475462 173.2050808 3734.230911
+53.72848948 173.2050808 3752.969241
+53.79222435 173.2050808 3773.828891
+53.85595921 173.2050808 3804.630531
+53.91969407 173.2050808 3825.447686
+53.98342894 173.2050808 3845.788513
+54.0471638 173.2050808 3867.958148
+54.11089866 173.2050808 3892.331277
+54.17463352 173.2050808 3906.764966
+54.23836839 173.2050808 3927.271063
+54.30210325 185.3294364 3947.460956
+54.36583811 185.3294364 3975.113604
+54.42957298 185.3294364 4002.178607
+54.49330784 185.3294364 4022.730478
+54.5570427 185.3294364 4042
+54.62077757 185.3294364 4057.838952
+54.68451243 185.3294364 4087.876331
+54.74824729 185.3294364 4101.219331
+54.81198215 185.3294364 4125.191208
+54.87571702 185.3294364 4145
+54.93945188 185.3294364 4164.505388
+55.00318674 185.3294364 4180.061737
+55.06692161 185.3294364 4190.870077
+55.13065647 185.3294364 4194.665192
+55.19439133 185.3294364 4219.604393
+55.2581262 185.3294364 4232.741192
+55.32186106 185.3294364 4260.852919
+55.38559592 185.3294364 4279.234664
+55.44933078 185.3294364 4311.937152
+55.51306565 185.3294364 4327.847054
+55.57680051 190.2117241 4339.696985
+55.64053537 190.2117241 4362.84884
+55.70427024 190.2117241 4387.894598
+55.7680051 190.2117241 4411.939275
+55.83173996 190.2117241 4432.852411
+55.89547482 190.2117241 4461.136683
+55.95920969 190.2117241 4474.819237
+56.02294455 196 4476.233254
+56.08667941 197.4537921 4497.906235
+56.15041428 198.6084926 4520.861101
+56.21414914 198.6084926 4532.54996
+56.277884 198.6084926 4546.34305
+56.34161887 198.6084926 4571.564357
+56.40535373 198.6084926 4592.385019
+56.46908859 198.6084926 4596.194078
+56.53282345 198.6084926 4599.729612
+56.59655832 198.6084926 4622
+56.66029318 198.6084926 4633.670737
+56.72402804 200 4647.380992
+56.78776291 200 4667.838054
+56.85149777 200 4669.497093
+56.91523263 200 4698.246778
+56.9789675 200 4712.083085
+57.04270236 200 4745.630085
+57.10643722 200 4776.688414
+57.17017208 200 4806.39695
+57.23390695 200 4834.842616
+57.29764181 200 4850.666667
+57.36137667 200 4868.360864
+57.42511154 200 4882.5
+57.4888464 200 4912.026291
+57.55258126 200 4931.009139
+57.61631612 200 4950.213255
+57.68005099 200 4981.567273
+57.74378585 200 5013.387079
+57.80752071 200 5033.293173
+57.87125558 200 5053.546906
+57.93499044 200 5072.784048
+57.9987253 200 5104
+58.06246017 200 5119.453096
+58.12619503 200 5143.938071
+58.18992989 200 5169.412003
+58.25366475 200 5183.092706
+58.31739962 200 5199.039174
+58.38113448 200 5218.666667
+58.44486934 200 5232.590181
+58.50860421 200 5245.390956
+58.57233907 200 5264.409986
+58.63607393 200 5277.525187
+58.6998088 200 5308.957713
+58.76354366 200 5330.720572
+58.82727852 200 5367.666667
+58.89101338 200 5394.549403
+58.95474825 200 5429.620263
+59.01848311 200 5463.814098
+59.08221797 200 5483.70569
+59.14595284 200 5505.597152
+59.2096877 200 5538.293167
+59.27342256 200 5561.394834
+59.33715743 200 5585.697808
+59.40089229 200 5601.699921
+59.46462715 200 5625.499818
+59.52836201 209.3036072 5656.854249
+59.59209688 209.3036072 5684.20771
+59.65583174 209.3036072 5694
+59.7195666 209.3036072 5715
+59.78330147 209.3036072 5733.928889
+59.84703633 209.3036072 5754.131137
+59.91077119 210.5 5769.63569
+59.97450605 210.5 5784.13347
+60.03824092 210.5 5805.279683
+60.10197578 210.5 5830.095411
+60.16571064 210.5 5847.340264
+60.22944551 210.5 5866.506231
+60.29318037 210.5 5881.305994
+60.35691523 210.5 5905.5
+60.4206501 210.5 5919.333333
+60.48438496 210.5 5936.74664
+60.54811982 210.5 5951.722784
+60.61185468 210.5 5967.77351
+60.67558955 210.5 5988.48733
+60.73932441 210.5 6000.025125
+60.80305927 210.5 6011.80606
+60.86679414 210.5 6043.5
+60.930529 210.7328483 6071.5
+60.99426386 213.0422493 6101.480488
+61.05799873 213.0422493 6122.354122
+61.12173359 213.0422493 6145.361516
+61.18546845 213.0422493 6169.506666
+61.24920331 213.0422493 6180.820374
+61.31293818 213.0422493 6199.722074
+61.37667304 221 6217.465437
+61.4404079 221 6244
+61.50414277 222 6275.540017
+61.56787763 222 6309.885577
+61.63161249 222 6333.555439
+61.69534736 222 6350
+61.75908222 222 6366.430044
+61.82281708 222 6389.416875
+61.88655194 222 6411.864455
+61.95028681 222 6452.349378
+62.01402167 223.6067977 6468.050232
+62.07775653 223.6067977 6482.090712
+62.1414914 223.6067977 6502.333333
+62.20522626 223.6067977 6523.060056
+62.26896112 223.6067977 6538.026209
+62.33269598 223.6067977 6555
+62.39643085 223.6067977 6561
+62.46016571 223.6067977 6587.406774
+62.52390057 223.6067977 6598.720482
+62.58763544 223.6067977 6618.519472
+62.6513703 223.6067977 6642.347649
+62.71510516 223.6067977 6659.885219
+62.77884003 223.6067977 6687.91986
+62.84257489 223.6067977 6725.999703
+62.90630975 223.6067977 6725.999703
+62.97004461 223.6067977 6760.923084
+63.03377948 223.6067977 6786.457332
+63.09751434 223.6067977 6823.666667
+63.1612492 223.6067977 6840.197448
+63.22498407 223.6067977 6861
+63.28871893 223.6067977 6877.250672
+63.35245379 223.6067977 6893.350361
+63.41618866 223.6067977 6913
+63.47992352 225.166605 6949.610649
+63.54365838 228.6307066 6970.640016
+63.60739324 228.6307066 6995.407386
+63.67112811 228.6307066 6995.407386
+63.73486297 228.6307066 7027
+63.79859783 228.6307066 7052.329482
+63.8623327 228.6307066 7091
+63.92606756 228.6307066 7125
+63.98980242 229.8097039 7147.333333
+64.05353728 229.8097039 7182.458881
+64.11727215 229.8097039 7204.052206
+64.18100701 232.5 7216.878365
+64.24474187 232.9982833 7242.859127
+64.30847674 232.9982833 7281.333333
+64.3722116 232.9982833 7302.5
+64.43594646 232.9982833 7332.132812
+64.49968133 232.9982833 7350.275107
+64.56341619 232.9982833 7367.656898
+64.62715105 232.9982833 7385.285316
+64.69088591 232.9982833 7414.666667
+64.75462078 232.9982833 7442.62232
+64.81835564 234.5 7462.451415
+64.8820905 234.5 7492
+64.94582537 234.5 7509.979852
+65.00956023 234.5 7546.729424
+65.07329509 242.3897688 7572.40652
+65.13702996 242.3897688 7597.929543
+65.20076482 243.284196 7629.240332
+65.26449968 243.284196 7640.288771
+65.32823454 243.284196 7659.985176
+65.39196941 243.284196 7682.715178
+65.45570427 244.9489743 7686.841484
+65.51943913 244.9489743 7721.959604
+65.583174 244.9489743 7750.5
+65.64690886 244.9489743 7771.32753
+65.71064372 244.9489743 7796.651149
+65.77437859 244.9489743 7825.754414
+65.83811345 244.9489743 7861.489431
+65.90184831 244.9489743 7884.666667
+65.96558317 244.9489743 7915.353309
+66.02931804 244.9489743 7962
+66.0930529 244.9489743 7964.5
+66.15678776 244.9489743 7988.602548
+66.22052263 244.9489743 8041.5
+66.28425749 244.9489743 8072.205399
+66.34799235 244.9489743 8097
+66.41172721 245 8137.031285
+66.47546208 245.3738644 8181.225458
+66.53919694 245.3738644 8203
+66.6029318 245.3738644 8238.450502
+66.66666667 248 8240.231717
+66.73040153 248 8305.129986
+66.79413639 251.7300141 8333.253416
+66.85787126 251.7300141 8376
+66.92160612 251.7300141 8411.666667
+66.98534098 251.7300141 8430.5
+67.04907584 252.6756815 8466.5
+67.11281071 253.5221884 8495.534423
+67.17654557 253.5221884 8521.073383
+67.24028043 253.5221884 8536.900169
+67.3040153 253.5221884 8550.557487
+67.36775016 253.5221884 8589.455184
+67.43148502 253.5221884 8616.096129
+67.49521989 253.5221884 8639.758571
+67.55895475 253.5221884 8664
+67.62268961 254.0341184 8688.652417
+67.68642447 254.4645358 8728.753426
+67.75015934 254.4645358 8764.996129
+67.8138942 254.4645358 8789.088792
+67.87762906 256.5 8831.895841
+67.94136393 261.1727398 8859.175647
+68.00509879 262.0954025 8877.637084
+68.06883365 262.5 8916.5
+68.13256851 262.5 8929
+68.19630338 262.5 8946.331096
+68.26003824 262.9118991 8975.890588
+68.3237731 262.9118991 9010.272637
+68.38750797 262.9118991 9051.115263
+68.45124283 262.9118991 9076.199921
+68.51497769 263.2717228 9123.306449
+68.57871256 263.2717228 9153.311168
+68.64244742 263.2717228 9193.786722
+68.70618228 263.8560213 9227.389941
+68.76991714 263.8560213 9276
+68.83365201 264.5751311 9295.339334
+68.89738687 264.5751311 9318.36371
+68.96112173 264.5751311 9353
+69.0248566 264.5751311 9384.14057
+69.08859146 264.5751311 9411.964088
+69.15232632 264.5751311 9455.537221
+69.21606119 266.5393029 9478.971019
+69.27979605 266.5393029 9514.469244
+69.34353091 266.5393029 9539
+69.40726577 270.6686166 9557
+69.47100064 271.4851132 9588.342093
+69.5347355 271.4851132 9624.453448
+69.59847036 272.512385 9664.843506
+69.66220523 272.512385 9685.666667
+69.72594009 272.512385 9704.913422
+69.78967495 272.512385 9730.333333
+69.85340982 273 9759.949953
+69.91714468 273.1181063 9809.630217
+69.98087954 273.1181063 9843.432332
+70.0446144 275.0645379 9869.225502
+70.10834927 275.0645379 9923.222471
+70.17208413 275.0645379 9943
+70.23581899 275.9307884 9966.5
+70.29955386 278 9997.075672
+70.36328872 278 10015.1069
+70.42702358 278 10073.6075
+70.49075844 279.5084972 10117.76038
+70.55449331 280.449639 10155.59124
+70.61822817 280.449639 10182.5
+70.68196303 281.2055679 10233.38811
+70.7456979 281.2055679 10255.5
+70.80943276 281.6913204 10281.38959
+70.87316762 282.3242816 10315.20956
+70.93690249 282.3242816 10353.44195
+71.00063735 282.5 10384.5
+71.06437221 282.8427125 10412.92123
+71.12810707 282.8427125 10434.5676
+71.19184194 282.8427125 10454.65867
+71.2555768 284.1408102 10496.22789
+71.31931166 284.1408102 10497.33333
+71.38304653 284.5 10525.28444
+71.44678139 288.3868929 10567.35729
+71.51051625 289 10600.94486
+71.57425112 289.1428219 10621.75
+71.63798598 290.2645345 10671.41082
+71.70172084 290.2673337 10708.42509
+71.7654557 290.2673337 10744.77404
+71.82919057 290.2673337 10784.10864
+71.89292543 290.6546797 10818.5797
+71.95666029 290.6546797 10845.11584
+72.02039516 291.0810311 10894.51388
+72.08413002 293.3721186 10937.95012
+72.14786488 293.3721186 10961.66667
+72.21159975 294.5 11021.06607
+72.27533461 294.5 11057.35615
+72.33906947 295 11101.5
+72.40280433 296 11131.27495
+72.4665392 297.0800758 11159.60335
+72.53027406 297.6919549 11211.19763
+72.59400892 298.2914682 11246.53335
+72.65774379 298.3990617 11261
+72.72147865 298.5919337 11289.66687
+72.78521351 299.8132752 11327.92037
+72.84894837 299.8132752 11370.98415
+72.91268324 300 11383.5
+72.9764181 300 11413.39319
+73.04015296 300 11443.33333
+73.10388783 300.8597205 11473.5
+73.16762269 302.5315411 11507.29456
+73.23135755 302.5315411 11514.30971
+73.29509242 302.5315411 11542.40392
+73.35882728 305.0173297 11544.11863
+73.42256214 306.5291876 11570.9813
+73.486297 307 11602.91517
+73.55003187 307 11629.2761
+73.61376673 307.2378964 11660.19082
+73.67750159 307.7276935 11719.66667
+73.74123646 308.1301673 11738.10832
+73.80497132 308.6357076 11756.79821
+73.86870618 308.6357076 11779.80051
+73.93244105 311.8206902 11796.33435
+73.99617591 312 11829.40246
+74.05991077 312.5 11872.5
+74.12364563 313.2483041 11896.71804
+74.1873805 314 11931.10542
+74.25111536 314.6666667 11968.47108
+74.31485022 316.227766 11988.28837
+74.37858509 316.783838 12026.20611
+74.44231995 317.2089217 12051.95919
+74.50605481 319.7579442 12075.96961
+74.56978967 321.380032 12104.72574
+74.63352454 322.0871388 12143.98556
+74.6972594 322.1614502 12174.96456
+74.76099426 322.8685491 12210.38084
+74.82472913 322.8685491 12229.4764
+74.88846399 323 12249.18038
+74.95219885 323.7826431 12268.72679
+75.01593372 323.893501 12271.5
+75.07966858 323.893501 12313.13192
+75.14340344 324.2084592 12342.57057
+75.2071383 325.9762261 12365.45592
+75.27087317 327.0368863 12397
+75.33460803 328.6666667 12431.19631
+75.39834289 330.1417877 12462.59556
+75.46207776 330.5 12493
+75.52581262 330.6811153 12528.51795
+75.58954748 331.662479 12570
+75.65328235 333.1741286 12610.08175
+75.71701721 335.4101966 12650.5
+75.78075207 336.1501153 12678.50543
+75.84448693 336.3965913 12718.30744
+75.9082218 336.7825708 12753
+75.97195666 337.6666667 12798.63274
+76.03569152 337.6666667 12816.95508
+76.09942639 338.0474819 12836.80589
+76.16316125 340.3295462 12856.46155
+76.22689611 341 12882.27481
+76.29063098 342.4358125 12905.21897
+76.35436584 344.3259555 12949
+76.4181007 344.9289782 12979.65208
+76.48183556 346.4101615 13002.50541
+76.54557043 346.4101615 13034.45285
+76.60930529 346.4101615 13076.05891
+76.67304015 348.1052796 13113.47739
+76.73677502 349.7210317 13158.23734
+76.80050988 350 13201.86467
+76.86424474 351.2607164 13256.50264
+76.9279796 351.5017781 13304.6508
+76.99171447 352 13372.38306
+77.05544933 352.8462838 13408.33333
+77.11918419 353.5533906 13465.60136
+77.18291906 353.5533906 13529.5
+77.24665392 353.5533906 13559.0975
+77.31038878 355.7562368 13575.74309
+77.37412365 357.176427 13634.70396
+77.43785851 357.7708764 13662.99412
+77.50159337 358.6653036 13679.73728
+77.56532823 360.0069444 13709.08367
+77.6290631 360.9780118 13763.89283
+77.69279796 362.038672 13793.47528
+77.75653282 363.2238586 13832.74378
+77.82026769 365 13861.60261
+77.88400255 366.3794796 13894.03198
+77.94773741 367.1623619 13933.9224
+78.01147228 369.1097398 13959.17481
+78.07520714 370.0815226 14006.67644
+78.138942 370.5 14018.39194
+78.20267686 370.5 14040.31225
+78.26641173 370.8589538 14100.04827
+78.33014659 372.2000806 14133.66667
+78.39388145 372.7585319 14163.34883
+78.45761632 374.413675 14199.35252
+78.52135118 375.9948138 14255.93285
+78.58508604 376.1066338 14318.91232
+78.64882091 377.4482746 14400.2296
+78.71255577 379.0304517 14443.00956
+78.77629063 379.6922843 14492.40378
+78.84002549 381 14526.71012
+78.90376036 382.2058782 14557.30969
+78.96749522 382.5447686 14630.80223
+79.03123008 384.1616413 14693.52315
+79.09496495 385.6666667 14708.98971
+79.15869981 387 14731.43965
+79.22243467 387.7435891 14759.43984
+79.28616953 389.3034072 14778.17326
+79.3499044 391.5377194 14812.5
+79.41363926 392 14866.21297
+79.47737412 393.4610164 14914.4781
+79.54110899 394.6666667 14943.5
+79.60484385 394.9075841 15015.14845
+79.66857871 395.3368184 15057
+79.73231358 396.3333509 15096.97453
+79.79604844 398.6590858 15104.06039
+79.8597833 400.969762 15145.05226
+79.92351816 401.7163178 15173.5
+79.98725303 403.4044187 15211.50423
+80.05098789 404.7283039 15233.38685
+80.11472275 406.3526793 15275.5
+80.17845762 407.3013626 15328.0723
+80.24219248 409.6666667 15362.71331
+80.30592734 411 15402.55048
+80.36966221 412.3307734 15440.4966
+80.43339707 412.9503602 15479
+80.49713193 414.2490624 15518.59789
+80.56086679 415.4614302 15545.5
+80.62460166 416.3333333 15627.05986
+80.68833652 419.039139 15673.49488
+80.75207138 420.3749814 15733.79372
+80.81580625 421.3805881 15817.05045
+80.87954111 423.3534772 15872.69353
+80.94327597 426 15902.09079
+81.00701083 427.6738513 15951.61059
+81.0707457 428.6666667 15990.26904
+81.13448056 430.6280297 16043.78774
+81.19821542 433.0127019 16086.67927
+81.26195029 434.2995181 16139
+81.32568515 435.5 16198.07643
+81.38942001 436.4804692 16279.54554
+81.45315488 438 16329.05315
+81.51688974 439.2751605 16391
+81.5806246 440.5053916 16443.06109
+81.64435946 442.2503062 16474.88138
+81.70809433 442.9201652 16524.37837
+81.77182919 444.4862203 16589.00528
+81.83556405 444.7701654 16638.22256
+81.89929892 444.8483824 16685.59872
+81.96303378 446.2917581 16748.53122
+82.02676864 448.0238089 16801.5
+82.09050351 448.6592527 16849.5
+82.15423837 451.5732499 16918.17114
+82.21797323 453.6666667 16994.15159
+82.28170809 455.3333333 17048.5761
+82.34544296 457.6666667 17099.06776
+82.40917782 459.2793268 17134.98891
+82.47291268 461.3008238 17186.23032
+82.53664755 462.5 17225.5
+82.60038241 465.6666667 17270
+82.66411727 467.044029 17327
+82.72785214 468.6759465 17373.98821
+82.791587 472.6666667 17422.69907
+82.85532186 474.0254213 17483.21516
+82.91905672 476.0974319 17533.01597
+82.98279159 478.0041841 17628.17205
+83.04652645 478.0041841 17680.41696
+83.11026131 478.0041841 17749.96972
+83.17399618 480.0337488 17829.95884
+83.23773104 481.2018288 17866.68143
+83.3014659 482.2473432 17909.60055
+83.36520076 484 17970.5
+83.42893563 486.9499828 17999.47199
+83.49267049 487.8609775 18029.66129
+83.55640535 489.0860281 18085.67014
+83.62014022 491.868885 18126.79816
+83.68387508 497.5492605 18159.5
+83.74760994 499.9847998 18232.42808
+83.81134481 501.7173839 18235.22639
+83.87507967 502.9618939 18284.2757
+83.93881453 504.5 18306.55948
+84.00254939 505.7588358 18345.32139
+84.06628426 506.5 18391.2119
+84.13001912 509.5116126 18448.6505
+84.19375398 509.6666667 18502.63275
+84.25748885 511.3632404 18567.5
+84.32122371 512.6524164 18613
+84.38495857 514.0739895 18614.36669
+84.44869344 516.25 18651.2314
+84.5124283 519.7543651 18699.79787
+84.57616316 523.9453693 18753.88605
+84.63989802 525.0073015 18815.26792
+84.70363289 527.25 18879.93115
+84.76736775 528.7328248 18943.52069
+84.83110261 529.6229791 19017.99043
+84.89483748 532.6666667 19076.34313
+84.95857234 536.3584001 19121.53343
+85.0223072 536.3933125 19194.5
+85.08604207 538.5450095 19251
+85.14977693 540.1170244 19318.14001
+85.21351179 542 19399.55051
+85.27724665 543.5807646 19445.68257
+85.34098152 544.1186681 19530.5
+85.40471638 545.7355337 19606.5
+85.46845124 548 19658.27562
+85.53218611 548.7148622 19730.94545
+85.59592097 550.1290758 19774.78465
+85.65965583 553.390233 19825.15282
+85.72339069 556.9724281 19919.78797
+85.78712556 560.7356775 19975.41302
+85.85086042 563.25 20107.93406
+85.91459528 565.7942001 20176.5
+85.97833015 568.1126649 20239.20948
+86.04206501 569.3997514 20284.04701
+86.10579987 571.5476066 20316
+86.16953474 573.5012674 20389.67146
+86.2332696 577.0589586 20441
+86.29700446 581.3776741 20540.39053
+86.36073932 584.0702013 20605
+86.42447419 586.1915216 20630.41037
+86.48820905 588.4998726 20663.05697
+86.55194391 590.7584713 20711.35603
+86.61567878 590.7691597 20796
+86.67941364 594.8818829 20895.5
+86.7431485 598.9324431 20985.51505
+86.80688337 601.0216302 21080.96848
+86.87061823 602.1181551 21146.02829
+86.93435309 604.5 21200.87923
+86.99808795 608 21310.57579
+87.06182282 613.1459859 21405.27437
+87.12555768 616.25 21473.67357
+87.18929254 619.6666667 21573.47266
+87.25302741 622.6075208 21673.5
+87.31676227 625 21731.66667
+87.38049713 625.6666667 21827.5
+87.44423199 628.9770266 21884.55786
+87.50796686 631.3325194 21976.5233
+87.57170172 632.5 22089.99865
+87.63543658 635.0852961 22224.31101
+87.69917145 636.6286615 22288.60714
+87.76290631 638 22318.0462
+87.82664117 639.8070732 22396.50121
+87.89037604 643.7455501 22535.13571
+87.9541109 648.063365 22566.31262
+88.01784576 648.6666667 22648.00919
+88.08158062 650.723082 22725.6613
+88.14531549 654.5 22795.00131
+88.20905035 660.424507 22887.63229
+88.27278521 665.3874811 22957.43437
+88.33652008 665.3874811 23012.01499
+88.40025494 669.0238479 23097.24057
+88.4639898 674.7116733 23186.03136
+88.52772467 676.9368919 23305.28941
+88.59145953 680.3360514 23429.18951
+88.65519439 687.3863542 23491.23574
+88.71892925 694.1199464 23595.5
+88.78266412 698 23655.36313
+88.84639898 705.6925676 23719.31468
+88.91013384 707.1067812 23808.28532
+88.97386871 713.2189606 23899.99174
+89.03760357 719.7417361 23992.13309
+89.10133843 723.0077224 24107.87805
+89.1650733 726.7220927 24214.64764
+89.22880816 729 24296.05403
+89.29254302 733.8683596 24405.78755
+89.35627788 740.2187276 24460.23777
+89.42001275 747.8786666 24593.38942
+89.48374761 754.3041345 24698.5
+89.54748247 762.5 24736
+89.61121734 768.162181 24806.7201
+89.6749522 770.3091525 24848
+89.73868706 779.0665202 24903
+89.80242192 782.886965 25003.29578
+89.86615679 787.9848016 25048.34143
+89.92989165 794.7880221 25140.74622
+89.99362651 798 25278.36032
+90.05736138 803 25365.5
+90.12109624 811 25494.75265
+90.1848311 818.2930841 25583.0504
+90.24856597 822.7241336 25706.28468
+90.31230083 824.6618701 25708.76549
+90.37603569 828.7291476 25829.80153
+90.43977055 834.5 25896.84044
+90.50350542 840.7499628 25933.99674
+90.56724028 841.810623 26039.20722
+90.63097514 849.4709465 26235
+90.69471001 857.6666667 26425.32182
+90.75844487 863.7160027 26579.4368
+90.82217973 878.1497594 26681.26808
+90.8859146 881.3267839 26791.56883
+90.94964946 886.7046537 26949.55587
+91.01338432 890.3895215 27078.70086
+91.07711918 901.4452681 27147.95065
+91.14085405 907.8832983 27213.82002
+91.20458891 917.4095777 27328.29764
+91.26832377 926 27441.452
+91.33205864 934.7322989 27552.41573
+91.3957935 937.7002816 27644.33333
+91.45952836 943.9662713 27776.56858
+91.52326322 949.1638425 27881.97883
+91.58699809 954.6862461 27980.21533
+91.65073295 960.7876797 28115.22606
+91.71446781 970.3333333 28291.34232
+91.77820268 982.1713191 28454.5
+91.84193754 987.1210665 28597
+91.9056724 990.5 28743.5
+91.96940727 994.1921343 28882.66667
+92.03314213 1001 29009.0557
+92.09687699 1005.744169 29146.66667
+92.16061185 1011.597153 29258.66439
+92.22434672 1015.174862 29286.24156
+92.28808158 1029.19392 29467
+92.35181644 1038.062504 29575.72001
+92.41555131 1038.739862 29745
+92.47928617 1039.230485 29950.21482
+92.54302103 1053 30146.0834
+92.6067559 1069.261494 30338.41645
+92.67049076 1076.142891 30381
+92.73422562 1085.513966 30546.03021
+92.79796048 1087.883783 30626.69973
+92.86169535 1092.759387 30714.18253
+92.92543021 1102.5 30748.53838
+92.98916507 1118.842551 30914.56118
+93.05289994 1133.915929 31042.96927
+93.1166348 1146.220092 31152.2023
+93.18036966 1152.376359 31274.67679
+93.24410453 1162.5 31405.44058
+93.30783939 1171 31538.33333
+93.37157425 1181.950827 31733.53813
+93.43530911 1188.333333 31927.99249
+93.49904398 1202.081528 32131.27453
+93.56277884 1209.265562 32335.9931
+93.6265137 1217.423568 32433.28544
+93.69024857 1225.425946 32581.67147
+93.75398343 1245.344531 32661.5
+93.81771829 1259.357177 32813.74165
+93.88145315 1265.5697 32904.86651
+93.94518802 1265.5697 33088.52128
+94.00892288 1275 33278.3594
+94.07265774 1276.333333 33381.80403
+94.13639261 1284.604349 33477
+94.20012747 1293.738832 33657.49997
+94.26386233 1304.761536 33791.33333
+94.3275972 1317 33890.32904
+94.39133206 1318.04704 34035.19069
+94.45506692 1323.864167 34257.90306
+94.51880178 1338.908361 34513.71872
+94.58253665 1345.553524 34651.76781
+94.64627151 1356.666667 34668.66667
+94.71000637 1372.498525 34790.91931
+94.77374124 1381.89001 34948.40085
+94.8374761 1390.836798 35111.26795
+94.90121096 1428.717047 35111.80247
+94.96494583 1439.669406 35212.6398
+95.02868069 1445.685074 35365.5
+95.09241555 1450 35642.47635
+95.15615041 1450 35903.20187
+95.21988528 1460.5 36057.49609
+95.28362014 1468.469101 36262.79306
+95.347355 1486.432026 36445.52442
+95.41108987 1501.68805 36637.07938
+95.47482473 1518.502742 36806.5
+95.53855959 1546.144021 37014.81677
+95.60229446 1566.948627 37158.46135
+95.66602932 1587.219022 37256.33074
+95.72976418 1603 37372.27325
+95.79349904 1612.988996 37550.90561
+95.85723391 1616.580754 37679.98149
+95.92096877 1616.580754 37858.49706
+95.98470363 1628.705109 38188.01613
+96.0484385 1631.88241 38396.56821
+96.11217336 1662.5 38557.11856
+96.17590822 1683.639348 38697.77503
+96.23964308 1684.840695 38923.53736
+96.30337795 1702.570292 39073.49905
+96.36711281 1737.24696 39219
+96.43084767 1768.47406 39418.01228
+96.49458254 1818.364673 39598.68685
+96.5583174 1838.477631 39743.34916
+96.62205226 1863.666667 39889.21665
+96.68578713 1900 40089.47064
+96.74952199 1930.947975 40439.28937
+96.81325685 1982.453698 40778.27728
+96.87699171 1984.5 41378.69379
+96.94072658 2005.001278 41600.5
+97.00446144 2054.713646 41807.52426
+97.0681963 2057.676359 41973
+97.13193117 2106.076922 42156.64546
+97.19566603 2141 42378.5
+97.25940089 2147.794256 42546.61502
+97.32313576 2186.427268 42719.5
+97.38687062 2220 42943.5
+97.45060548 2269.67666 43233.67291
+97.51434034 2296.5 43516.04449
+97.57807521 2370.232056 43516.5
+97.64181007 2442.680659 43691.5
+97.70554493 2462 43978
+97.7692798 2554.774941 44300.23984
+97.83301466 2591.365002 44461.5
+97.89674952 2624.628259 44746.95526
+97.96048438 2690.358311 45179.49893
+98.02421925 2801.91062 45461.7149
+98.08795411 2877.217493 45573.03205
+98.15168897 2979.336973 45824.64586
+98.21542384 3064.913912 46076.49208
+98.2791587 3169.606147 46409.53937
+98.34289356 3283.132752 46662.71377
+98.40662843 3386.483146 46949.54654
+98.47036329 3462.5 47461.7548
+98.53409815 3642.107522 47929.69381
+98.59783301 3714.108911 48113.47467
+98.66156788 3739.580496 48526.84129
+98.72530274 3838.882715 48891.62633
+98.7890376 3942.827412 49484.69157
+98.85277247 4260.793504 49846.07833
+98.91650733 4483.7641 50164.98348
+98.98024219 4520.53332 50480.35311
+99.04397706 4762 51305.5
+99.10771192 5060.056126 51933
+99.17144678 5376.986352 52460.31357
+99.23518164 5444.722215 52979.97558
+99.29891651 5444.722215 53372.60612
+99.36265137 5444.722215 53969.54846
+99.42638623 5444.722215 54938.34222
+99.4901211 5444.722215 55449.5
+99.55385596 5459.571458 56188.84521
+99.61759082 5748.071024 56830.8964
+99.68132569 6122.222254 57893.14158
+99.74506055 6614.5 59304.59616
+99.80879541 7690.305586 60478.13589
+99.87253027 8976.666667 62969.57313
+99.93626514 10304.69567 64989.04536
+100 14746.74475 70892.72389
diff --git a/macros/context/contrib/context-lua-widow-control/source/luatex/lua-widow-control/tb133chernoff-widows.bib b/macros/context/contrib/context-lua-widow-control/source/luatex/lua-widow-control/tb133chernoff-widows.bib
new file mode 100644
index 0000000000..b18838d626
--- /dev/null
+++ b/macros/context/contrib/context-lua-widow-control/source/luatex/lua-widow-control/tb133chernoff-widows.bib
@@ -0,0 +1,219 @@
+% 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
+
+@book{texbook,
+ author = {Donald E. Knuth},
+ title = {The \TeX{}book},
+ publisher = {Addison--Wesley},
+ xurl = {https://ctan.org/pkg/texbook},
+ year = {2021},
+}
+
+@misc{widows-and-orphans,
+ urlnewline = 1,
+ author = {Frank Mittelbach},
+ year = {2021},
+ month = {March},
+ title = {The \textsf{widows-and-orphans} package},
+ url = {https://ctan.org/pkg/widows-and-orphans},
+}
+
+@misc{widow-assist,
+ author = {jeremie},
+ title = {Paragraph callback to help with widows\slash orphans hand tuning},
+ url = {https://tex.stackexchange.com/q/372062},
+ year = {2017},
+ month = {August},
+}
+
+@book{elements,
+ title = {The Elements of Typographic Style},
+ author = {Robert Bringhurst},
+ edition = {3rd},
+ publisher = {Hartley \& Marks},
+ year = {2004},
+}
+
+@misc{oed-club,
+ title={club, n.},
+ journal={OED Online},
+ publisher={Oxford University Press},
+ month=sep,
+ year={2021},
+ url={www.oed.com/view/Entry/34788},
+ author={{Oxford English Dictionary}}
+}
+
+@misc{oed-line,
+ title={line at end of paragraph},
+ journal={OED Online},
+ publisher={Oxford University Press},
+ urlnewline=1,
+ url={https://www.oed.com/view/th/class/195380},
+ author={{Oxford English Dictionary}}
+}
+
+@misc{oed-widow,
+ title={widow, n.},
+ journal={OED Online},
+ publisher={Oxford University Press},
+ month=dec,
+ year={2021},
+ url={www.oed.com/view/Entry/228912},
+ author={{Oxford English Dictionary}}
+}
+
+@article{widowhistory,
+ title={The Typographical Widow},
+ subtitle={Who is she? What is she?},
+ author={Karl Brown},
+ journal={Bulletin of the {New York} Public Library},
+ publisher={The {New York} Public Library},
+ location={New York},
+ volume={52},
+ number={1},
+ year={1948},
+ month=jan,
+ pages={3--25},
+ url={https://hdl.handle.net/2027/uc1.b3310084}
+}
+
+@article{widowhistory2,
+ title={The Typographical Widow: Encore},
+ subtitle={Encore},
+ author={Karl Brown},
+ journal={Bulletin of the {New York} Public Library},
+ publisher={The {New York} Public Library},
+ location={New York},
+ volume={52},
+ number={9},
+ year={1948},
+ month=sep,
+ pages={458-466},
+ urlnewline=1,
+ url={https://hdl.handle.net/2027/uc1.b3310084}
+}
+
+@book{old,
+ title={Mechanick exercises},
+ subtitle={The doctrine of handy-works applied to the art of printing},
+ volume={\unskip~2,\gobble},
+ author={Moxon, Joseph},
+ year={1683},
+ location={London},
+ pages={394},
+ publisher={\hspace*{-.66em}\gobble},
+ url={https://archive.org/details/mechanickexercis00moxo_0}
+}
+
+@article{global,
+ url = {https://doi.org/10.1111/coin.12165},
+ year = {2018},
+ month = mar,
+ publisher = {Wiley},
+ volume = {35},
+ number = {2},
+ pages = {242--284},
+ author = {Frank Mittelbach},
+ title = {A general framework for globally optimized pagination},
+ journal = {Computational Intelligence}
+}
+
+@book{backwards1,
+ title={The Layout Book},
+ author={Ambrose, G. and Harris, P.},
+ isbn={9782940373536},
+ series={Advanced Level Series},
+ year={2007},
+ publisher={Bloomsbury Academic}
+}
+
+@book{backwards2,
+ title={Typography Essentials Revised and Updated},
+ subtitle={100 Design Principles for Working with Type},
+ author={Saltz, I.},
+ isbn={9781631596483},
+ year={2019},
+ publisher={Rockport Publishers}
+}
+
+@book{backwards3,
+ title={Advanced Typography: From Knowledge to Mastery},
+ author={Hunt, R.},
+ isbn={9781350055926},
+ lccn={2020024110},
+ year={2020},
+ publisher={Bloomsbury Publishing}
+}
+
+@article{gutenberg,
+ title={All Books (sorted by popularity)},
+ url={https://www.gutenberg.org/ebooks/search/?sort_order=downloads},
+ year={2022},
+ month=mar,
+ journal={Project Gutenberg}
+}
+
+@misc{etex,
+ title={The {\eTeX} manual},
+ author={{The \NTS{} Team}},
+ url={ctan.org/pkg/etex},
+ year={1998},
+ month=feb,
+}
+
+@String{j-TUGboat = "TUGboat"}
+@Article{xIsambert:TB31-1-12,
+urlnewline = 1,
+ author = "Paul Isambert",
+ title = "Strategies against widows",
+ journal = j-TUGboat,
+ volume = "31",
+ number = "1",
+ pages = "12--17",
+ year = "2010",
+ ISSN = "0896-3207",
+ ISSN-L = "0896-3207",
+ bibdate = "Sun Nov 27 15:57:23 MST 2011",
+ bibsource = "http://www.math.utah.edu/pub/tex/bib/index-table-t.html#tugboat;
+ http://www.math.utah.edu/pub/tex/bib/tugboat.bib",
+ URL = "https://tug.org/TUGboat/tb31-1/tb97isambert.pdf",
+ acknowledgement = ack-bnb # " and " # ack-nhfb,
+ fjournal = "TUGboat",
+ issue = "97",
+ journal-URL = "https://tug.org/TUGboat/",
+}
+
+@Article{xThanh:2000:MTE,
+urlnewline = 1,
+ author = "\Thanh",
+ title = "Micro-typographic extensions to the {\TeX} typesetting
+ system",
+ journal = j-TUGboat,
+ volume = "21",
+ number = "4",
+ pages = "317--317",
+ month = dec,
+ year = "2000",
+ CODEN = "????",
+ ISSN = "0896-3207",
+ ISSN-L = "0896-3207",
+ bibdate = "Mon Aug 10 16:37:32 MDT 2020",
+ bibsource = "http://www.math.utah.edu/pub/tex/bib/tugboat.bib",
+ URL = "https://tug.org/TUGboat/tb21-4/tb69thanh.pdf",
+ acknowledgement = ack-nhfb,
+ fjournal = "TUGboat",
+ issue = "69",
+ journal-URL = "https://tug.org/TUGboat/",
+}
+
+@phdthesis{plass,
+ title={Optimal pagination techniques for automatic typesetting systems},
+ author={Plass, Michael Frederick},
+ year={1981},
+ school={Stanford University},
+ urlnewline=1,
+ url={tug.org/docs/plass/plass-thesis.pdf}
+}
diff --git a/macros/context/contrib/context-lua-widow-control/source/luatex/lua-widow-control/tb133chernoff-widows.ltx b/macros/context/contrib/context-lua-widow-control/source/luatex/lua-widow-control/tb133chernoff-widows.ltx
new file mode 100644
index 0000000000..bcae2c01c6
--- /dev/null
+++ b/macros/context/contrib/context-lua-widow-control/source/luatex/lua-widow-control/tb133chernoff-widows.ltx
@@ -0,0 +1,1465 @@
+% 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
+
+\documentclass[final]{ltugboat}
+
+% This is the LaTeX source for the following article:
+% @article{tb133chernoff-widows,
+% title={Automatically removing widows and orphans with
+% \texttt{lua-widow-control}},
+% author={Chernoff, Max},
+% journal={TUGboat},
+% volume={43},
+% number={1},
+% pages={28--39},
+% year={2022},
+% month=may,
+% DOI={10.47397/tb/43-1/tb133chernoff-widows},
+% }
+% Please refer to the PDF on tug.org for the authoritative version.
+
+% Compiling:
+% context tb133chernoff-widows-figure.ctx
+% lualatex tb133chernoff-widows.ltx
+% bibtex tb133chernoff-widows
+% lualatex tb133chernoff-widows.ltx
+% lualatex tb133chernoff-widows.ltx
+% The original article was built with the final/frozen TeX Live 2021.
+
+% Set the publication info
+\vol 43, 1.
+\issyear 2022.
+\issueseqno=133
+\setcounter{page}{28}
+\PrelimDraftfalse
+
+% Load lwc
+\usepackage[balanced]{lua-widow-control}
+
+% Table Stuff
+\usepackage{tabularx}
+\usepackage{hhline}
+\usepackage{booktabs}
+\AddToHook{env/tabularx/before}{\smallskip\noindent}
+\AddToHook{env/tabularx/after}{\smallskip}
+\AddToHook{env/tabular/before}{\smallskip\noindent}
+\AddToHook{env/tabular/after}{\smallskip}
+\renewcommand{\arraystretch}{1.15}
+
+\usepackage{graphicx}
+
+% Let the macro names in section headings be in boldface
+\usepackage{lmodern}
+\DeclareRobustCommand{\cs}[1]{\texttt{\textbackslash#1}}
+
+\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
+
+\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/{widow 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{\LuaMetaTeX}{Lua\-Meta\-\TeX{}}
+\newcommand{\q}[1]{\texorpdfstring{``#1''}{“#1”}}
+
+\def\inlineurl[#1]#2{\href{https://#1}{#2}\footnote{\raggedright\tbsurl{#1}}}
+
+\def\longs/{\char"017F}
+\def\endofline#1{\unskip\nobreak\hskip\fontdimen2\font plus 1fill\hbox{#1}}
+
+% Additional macros
+\def\dots{\ensuremath{\mathellipsis}}
+\def\ttbs{{\tt\char`\\}}
+
+\ifdefined\tubsentencespace\else
+ \def\tubsentencespace{\spacefactor=3000{}\space\ignorespaces}
+\fi
+
+% 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{\jobname-plot.dat}{\plotdata}
+
+% Metadata
+\title{Automatically removing \waos/ with \lwc/}
+\author{Max Chernoff}
+\address{Calgary, Alberta\\Canada}
+
+% Load last
+\AddToHookNext{shipout/foreground}{%
+ \put(1in, \dimexpr-2\baselineskip){%
+ \fbox{\parbox[t]{\textwidth}{%
+ This document is a part of the \lwc/ documentation. For the
+ authoritative version of the article, please see
+ \tbsurl{https://tug.org/TUGboat/tb43-1/tb133chernoff-widows.html}.
+ }%
+ }}%
+ \put(\dimexpr1in + 0.4\textwidth, \dimexpr-\paperheight + 4\baselineskip){%
+ \fbox{\parbox[t]{0.6\textwidth}{%
+ Some commands may have changed since publication. Please see the
+ \lwc/ manual for the current syntax. (Links:
+ \href{lua-widow-control.pdf}{local},
+ \href{http://mirrors.ctan.org/macros/luatex/generic/lua-widow-control/lua-widow-control.pdf}{\acro{CTAN}},
+ \href{https://github.com/gucci-on-fleek/lua-widow-control/releases/latest/download/lua-widow-control.pdf}{GitHub}.)
+ }%
+ }}%
+}
+
+\usepackage[hidelinks,pdfa]{hyperref}
+
+\usepackage{hyperxmp}
+\hypersetup{
+ pdfdisplaydoctitle=true,
+ pdftitle={Automatically removing widows and orphans with lua-widow-control},
+ pdfauthor={Max Chernoff},
+ pdflang={en},
+ pdfcontacturl={https://github.com/gucci-on-fleek/lua-widow-control},
+ pdfcopyright={SPDX-License-Identifier: MPL-2.0+ OR CC-BY-SA-4.0+},
+ pdflicenseurl={https://creativecommons.org/licenses/by-sa/4.0/},
+ pdfdoi={10.47397/tb/43-1/tb133chernoff-widows},
+ pdfpublication={TUGboat},
+ pdfpubtype={journal},
+ pdfvolumenum={43},
+ pdfissuenum={1},
+ pdfpagerange={28-39},
+ pdfdate={2022-05}
+}
+
+% TODO: Temporary fix
+\def\Thanh{H{\`a}n Th\^e\llap{\raise0.5ex\hbox{\'{\relax}}} Th{\`a}nh}
+
+\begin{document}
+ \maketitle
+
+ \begin{abstract}
+ The \textsf{lua-widow-control} package, for
+ plain~Lua\TeX\slash{}\LuaLaTeX\slash{}\ConTeXt\slash{}\OpTeX{},
+ removes widows and orphans without any user intervention.
+ Using the power of Lua\TeX{}, it does so \emph{without} stretching any 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 \textsf{lua-widow-control}, all that most users need do is
+ place \verb|\usepackage{lua-widow-control}| in their preamble. No further
+ changes are required.
+ \end{abstract}
+
+ \section{Motivation}
+
+ \TeX{} provides top-notch typesetting: even 40 years after its first
+ release, no other program produces higher quality mathematical
+ typesetting, and its paragraph-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.
+
+ 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 and fully-automated solution to remove
+ \waos/ from all types of documents was available, I decided to
+ create \lwc/.
+
+ \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%
+ \spaceskip=0.2em plus 1fill%
+ \hskip 3em%
+ #1%
+ }
+
+ \def\lastpage#1{%
+ \parfillskip=3em%
+ \spaceskip=0.2em plus 1fill%
+ #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 occurs when the last line of a paragraph is
+ placed on a page separate from}
+ & \vskip2.25\baselineskip\relax\firstpage{An orphan is}
+ \\ \hhline{-||-}
+ \lastpage{where it begins.}
+ & \lastpage{when the first line of a paragraph occurs on the
+ page before all of 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.}
+ \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 \cite{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}
+
+ \subsection{Widows}
+
+ However, the terms \q{widow} and \q{orphan} are much newer. 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 \Dash not even the editors of the dictionary~\cite{widowhistory} \Dash
+ 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}
+ \emph{Typography}\@. A short line of text (usually one consisting of one
+ word or part of a word) which falls undesirably at the end of a
+ paragraph, esp.\ one set at the top of a page or column.
+ \endofline{\cite{oed-widow}}
+ \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, xIsambert: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}.
+
+ \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} \Dash a
+ compilation article about the definition of \q{widow} \Dash that mentions
+ a \q{club line}:
+ \begin{quote}
+ 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 ``clubline''.
+ \endofline{\cite[p.~4]{widowhistory}}
+ \end{quote}\medskip
+ \begin{quote}
+ 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{quote}
+
+ 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}\Dash which lists 17~full definitions and
+ 103~subdefinitions for the noun \q{club}\Dash 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. If anyone has
+ any more information on the definition of a \q{club line} or why Knuth chose
+ to use this archaic Scottish term in \TeX{}, please let me know!
+
+ \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 \textit{\TB}~\cite{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\hyph 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 \Dash like
+ \LaTeX's default values of 150 \Dash are only lightly coupled to the rest
+ of the paragraph, while \waos/ with large penalties \Dash values of
+ 10\,000 or more \Dash 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.
+
+ 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
+ \cite{texbook} (\q{How \TeX{} Breaks Paragraphs into Lines}):
+
+ \begin{quote}\parskip=0pt
+ 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.
+ \end{quote}
+
+ 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{figure*}[p]
+ % Note: this figure may appear incorrect on some systems.
+ \divide\abovecaptionskip by 2
+ \includegraphics{\jobname-figure}
+ \caption{A visual comparison of various automated widow-handling
+ techniques.
+ }\label{fig:demo}
+ \end{figure*}
+
+ \section{Alternate removal strategies}
+
+ \looseness=1 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 glue
+ or shortening any pages.
+
+ The articles \q{Strategies against
+ widows} by Paul Isambert~\cite{xIsambert:TB31-1-12} and
+ \q{Managing forlorn paragraph lines} by Frank
+ Mittelbach~\cite{Mittelbach:2018:MFP} 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.
+
+ \looseness=1 The post \q{Paragraph callback \dots} by
+ jeremie~\cite{widow-assist} contains a file
+ \verb|widow-assist.lua| that
+ automatically detects which paragraphs can be safely shortened or
+ lengthened by one line. Mittelbach's \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 by Mittelbach~\cite{global} suggests an fully-automated
+ solution to remove \waos/. This would seem to offer a complete solution;
+ however, it requires multiple passes, an external tool, and has not yet been
+ publicly released.
+
+ \pagebreak
+
+ \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{\q{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{\q{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.
+
+ \subsection{\q{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 glue stretching must be quantised to the height of a line.
+
+ \subsection{\q{\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 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} \LuaTeX{}\footnote{Or
+ \LuaMetaTeX{} in the case of \ConTeXt{}.} regardless of the format used.
+ With that in mind, using \lwc/ is quite simple:
+
+ \begin{tabularx}{\linewidth}{@{}l@{}>{\raggedleft\arraybackslash}X@{}}
+ Plain \TeX{} &
+ \cs{input lua-widow-control}\phantom{\tt]} \\
+ \OpTeX {} &
+ \cs{load[lua-widow-control]} \\
+ \LaTeX{} &
+ \latexuse/ \\
+ \ConTeXt{} &
+ \cs{usemodule[lua-widow-control]} \\
+ \end{tabularx}
+
+ 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{description}
+ \item[\rm \plainop/\ ] Some options are set
+ by modifying a register, while others must be set manually using
+ \cs{directlua}.
+
+ \item[\rm \LaTeX{}\ ] Options can be set either as package options
+ or at any point in the document with \cs{lwcsetup}.
+
+ \item[\rm \ConTeXt{}\ ] Always use \cs{setuplwc}.
+ \end{description}
+
+ \subsection{Disabling}
+
+ You may want to disable \lwc/ for certain portions of your
+ document. You can do so with the following commands:
+
+ \begin{tabularx}{\linewidth}{@{}Xl@{}}
+ \plainop/ &
+ \cs{lwcdisable} \\
+ \LaTeX{} &
+ \cs{lwcsetup\{disable\}} \\
+ \ConTeXt{} &
+ \cs{setuplwc[state=stop]}\hphantom{\texttt{a}} \\
+ \end{tabularx}
+
+ 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{tabularx}{\linewidth}{@{}Xl@{}}
+ \plainop/ &
+ \cs{lwcenable} \\
+ \LaTeX{} &
+ \cs{lwcsetup\{enable\}} \\
+ \ConTeXt{} &
+ \cs{setuplwc[state=start]} \\
+ \end{tabularx}
+
+ \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}}, \KOMAScript, and
+ \textsf{titlesec} section commands, so you don't need to patch these.
+ Any others, though, you'll need to patch yourself.
+
+ \begin{tabularx}{\linewidth}{@{}Xl@{}}
+ \leavevmode\rlap{\plainop/} & \texttt{ }%
+ \cs{lwcdisablecmd\{\meta{\ttbs macro}\}} \\
+ \LaTeX{} & \texttt{ }%
+ \cs{lwcsetup\{disablecmds=\{} \\
+ & \hfill\texttt{\meta{csnameone},
+ \meta{csnametwo}\}\}} \\
+ \ConTeXt{} &
+ \cs{prependtoks\textbackslash{}lwc@patch@pre} \\
+ & \hfill\cs{to\textbackslash{}everybefore\meta{hook}} \\
+ & \cs{prependtoks\textbackslash{}lwc@patch@post} \\
+ & \hfill\cs{to\textbackslash{}everyafter\meta{hook}} \\
+ \end{tabularx}
+
+ \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 lengthen 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{tabularx}{\linewidth}{@{}Xl@{}}
+ \leavevmode\rlap{\plainop/} &
+ \hskip2em\cs{lwcemergencystretch=} \\
+ & \hfill\texttt{\meta{dimension}} \\
+ \LaTeX{} &
+ \cs{lwcsetup\{emergencystretch=\hphantom{\}}}\\
+ & \hfill\texttt{\meta{dimension}\}} \\
+ \ConTeXt{} &
+ \cs{setuplwc[emergencystretch=\hphantom{]}} \\
+ & \hfill\texttt{\meta{dimension}]} \\
+ \end{tabularx}
+
+ \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{tabular}{@{}p{.175\linewidth}@{}r@{\texttt{=\meta{integer}}}l@{}}
+ \leavevmode\rlap{\plainop/} &
+ \hskip6em\cs{widowpenalty} \\
+ & \hskip6em\cs{clubpenalty} \\
+ & \hskip6em\cs{brokenpenalty} \\
+ \LaTeX{} &
+ \cs{lwcsetup\{ widowpenalty} & \texttt{\}} \\
+ & \cs{lwcsetup\{orphanpenalty} & \texttt{\}} \\
+ & \cs{lwcsetup\{brokenpenalty} & \texttt{\}} \\
+ \leavevmode\hbox{\ConTeXt{}} &
+ \cs{setuplwc[ widowpenalty} & \texttt{]} \\
+ & \cs{setuplwc[orphanpenalty} & \texttt{]} \\
+ & \cs{setuplwc[brokenpenalty} & \texttt{]} \\
+ \end{tabular}
+
+ 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/.
+
+ \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{tabularx}{\linewidth}{@{}Xr@{}}
+ \leavevmode\rlap{\plainop/} &
+ \cs{directlua\{lwc.}\hskip4em\null \\
+ & \hfill\texttt{nobreak\_behaviour="\meta{value}"\}} \\
+ \LaTeX{} &
+ \cs{lwcsetup\{nobreak=\meta{value}\}\hphantom{"}} \\
+ \ConTeXt{} &
+ \cs{setuplwc[nobreak=\meta{value}]\hphantom{"}} \\
+ \end{tabularx}
+
+ 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 first\hfill line
+ \\ \hhline{-||-||-}
+ \textbf{Heading} &
+ The\hfill first\hfill line &
+ text\hfill text\hfill text \\
+ The\hfill first\hfill line &
+ text\hfill text\hfill text &
+ last line. \\
+ 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{tabularx}{\linewidth}{@{}Xr@{\texttt{=\meta{integer}}}l@{}}
+ \leavevmode\rlap{\plainop/} &
+ \cs{lwcmaxcost} \\
+ \LaTeX{} &
+ \cs{lwcsetup\{max-cost} & \texttt{\}} \\
+ \leavevmode\hbox{\ConTeXt{}} &
+ \cs{setuplwc[maxcost} & \texttt{]} \\
+ \end{tabularx}
+
+ 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.
+
+ \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.
+
+ Currently, these presets are \LaTeX{}-only.
+
+ \begin{tabular}{@{}rl@{}}
+ \LaTeX{} &
+ \cs{lwcsetup\{\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\Dash depending on the document\Dash
+ \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.
+
+ 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, inserts\slash floats, \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 matter for Plain~\TeX{} or \LaTeX{}, where even most Lua-based
+ packages don't depend on the node list structure; nevertheless, there are
+ a few issues with \ConTeXt{}.
+
+ Simple \ConTeXt{} documents tend to be fine, but many advanced
+ \ConTeXt{} features rely heavily on Lua and can thus be disturbed by
+ \lwc/. This is not a huge issue\Dash the \lwc/ manual is
+ written in \ConTeXt{}\Dash but \lwc/ is inevitably more reliable
+ with Plain \TeX{} and \LaTeX{} than with \ConTeXt{}.
+
+ 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 \LuaTeX{}-based formats: Plain~\LuaTeX{},
+ \LuaLaTeX{}, \CMkIV{}, \ConTeXt{} Mk\acro{XL}\slash\acro{LMTX},
+ and~\OpTeX{}. Unless otherwise documented, all features should work
+ equally well in all formats.
+
+ \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 \cite{texbook}.
+
+ \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.
+
+ \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.
+
+ \Lwc/ 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.
+
+ \section{Short last lines}
+
+ \looseness=1
+ 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}. When lengthening a paragraph
+ (and only when lengthening a paragraph\Dash remember, \lwc/ doesn't
+ interfere with \TeX{}'s output unless it detects a \woo/), \lwc/ sets
+ \cs{parfillskip} to \verb|0pt plus 0.8\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.
+
+ \section{How it works}
+
+ \Lwc/ uses a fairly simple algorithm to eliminate \waos/, but there
+ are a few subtleties.
+
+ \subsection{Setup}
+
+ \Lwc/ sets the parameters \cs{clubpenalty}, \cs{widowpenalty}, and
+ \cs{brokenpenalty} 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 \LuaTeX{}'s micro\-typographic
+ extensions~\cite{xThanh:2000:MTE}. 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 \LuaTeX{} 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\Dash the
+ one that unmodified \TeX{} originally typeset. Having found the original
+ paragraph, we splice in the lengthened paragraph in place of the original.
+
+ 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.
+
+ \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 very 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*}
+
+ 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}
+
+ \section{Quantitative analysis}
+
+ \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.
+
+ \subsection{Widows and orphans removed}
+
+ \begin{figure}
+ \begin{tikzpicture}\begin{axis}[
+ ybar=0pt,
+ bar width=0.8,
+ xtick=data,
+ ylabel={Widows and orphans removed},
+ width=\linewidth,
+ height=0.8\linewidth,
+ 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}[
+ width=\linewidth,
+ height=0.8\linewidth,
+ 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. \LuaTeX{} assigns these
+ paragraphs zero~demerits, so they disappear on a logarithmic plot.
+
+ \subsection{Lengthening vs.\ shortening paragraphs}
+ \begin{figure}
+ \begin{tikzpicture}\begin{axis}[
+ xbar stacked,
+ height=0.2\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.
+
+ Because of this, \lwc/ doesn't even attempt to shrink paragraphs; it
+ only stretches them.
+
+ \section{Known issues}
+
+ \Lwc/ is quite stable these days, a few issues remain:
+
+ \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 When running under \LuaMetaTeX{} (\ConTeXt{}), the log may
+ contain many lines like \q{\texttt{%
+ \spaceskip=\fontdimen2\font plus1.25pt minus1.25pt
+ luatex warning > tex: left parfill skip is gone}}. These messages
+ are completely harmless (although admittedly quite annoying).
+
+ \item \TeX{} may warn about overfull \cs{vbox}es on pages where
+ \lwc/ removed a \woo/. This happens due to the way that \lwc/
+ corrects for the \cs{prevdepth} when replacing paragraphs. It
+ does not actually produce an overfull \texttt{vbox}, but there
+ is a warning nevertheless. You can set \cs{vfuzz=2.5pt} to
+ hide the
+ warning.
+
+ \item \Lwc/ only attempts to expand paragraphs on a page with
+ a \woo/. A global system like in~\cite{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.
+ \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 github.com/gucci-on-fleek/lua-widow-control}.
+ Any feedback is greatly appreciated!
+
+ \bibliographystyle{tugboat}
+ \AddToHook{env/thebibliography/begin}{%
+ \let\eTeX=\goodeTeX%
+ \let\tubeTeX=\goodeTeX%
+ }
+ \let\macro=\cs
+\SetBibJustification{\raggedright \advance\itemsep by 1pt plus1pt minus1pt
+\def\url{\tbsurl}
+}
+\smallskip
+ \bibliography{\jobname.bib, tugboat.bib}
+
+ \makesignature
+\end{document}
diff --git a/macros/context/contrib/context-lua-widow-control/tex/context/third/lua-widow-control/t-lua-widow-control.mkiv b/macros/context/contrib/context-lua-widow-control/tex/context/third/lua-widow-control/t-lua-widow-control.mkiv
new file mode 100644
index 0000000000..5f277c2b14
--- /dev/null
+++ b/macros/context/contrib/context-lua-widow-control/tex/context/third/lua-widow-control/t-lua-widow-control.mkiv
@@ -0,0 +1 @@
+\input t-lua-widow-control.mkxl
diff --git a/macros/context/contrib/context-lua-widow-control/tex/context/third/lua-widow-control/t-lua-widow-control.mkxl b/macros/context/contrib/context-lua-widow-control/tex/context/third/lua-widow-control/t-lua-widow-control.mkxl
new file mode 100644
index 0000000000..b4d35eb15f
--- /dev/null
+++ b/macros/context/contrib/context-lua-widow-control/tex/context/third/lua-widow-control/t-lua-widow-control.mkxl
@@ -0,0 +1,171 @@
+%D \module
+%D [ file=t-lua-widow-control,
+%D version=3.0.0, %%version
+%D title=lua-widow-control,
+%D subtitle=\ConTeXt module for lua-widow-control,
+%D author=Max Chernoff,
+%D date=2022-11-22, %%dashdate
+%D copyright=Max Chernoff,
+%D license=MPL-2.0+,
+%D url=https://github.com/gucci-on-fleek/lua-widow-control]
+\startmodule[lua-widow-control]
+\unprotect
+
+% Preliminaries
+\installnamespace{lwc}
+
+\installswitchcommandhandler \????lwc {lwc} \????lwc
+
+% Set up the options
+\newdimen\lwc_emergency_stretch
+\newdimen\lwc_draft_offset
+\newcount\lwc_max_cost
+
+\starttexdefinition lwc_set_parameters
+ \lwc_emergency_stretch=\lwcparameter{emergencystretch}
+ \lwc_draft_offset=\lwcparameter{draftoffset}
+
+ \doifelse{\lwcparameter{\c!state}}\v!start{
+ \lwc_enable
+ }{
+ \lwc_disable
+ }
+
+ \lwc_debug{\lwcparameter{debug}}
+
+ \doif{\lwcparameter{draft}}\v!start{
+ \setlwcparameter{showcosts}{\v!start}
+ \setlwcparameter{showcolours}{\v!start}
+ }
+
+ \doif{\lwcparameter{draft}}\v!stop{
+ \setlwcparameter{showcosts}{\v!stop}
+ \setlwcparameter{showcolours}{\v!stop}
+ }
+
+ \lwc_show_costs{\lwcparameter{showcosts}}
+ \lwc_show_colours{\lwcparameter{showcolours}}
+
+ \lwc_nobreak{\lwcparameter{nobreak}}
+
+ \lwc_max_cost=\lwcparameter{maxcost}
+
+ % We can't just set the penalties because they will be reset automatically
+ % at \\starttext.
+ \startsetups[*default]
+ \directsetup{*reset}
+
+ \clubpenalty=\lwcparameter{orphanpenalty}
+ \widowpenalty=\lwcparameter{widowpenalty}
+ \displaywidowpenalty=\lwcparameter{widowpenalty}
+ \brokenpenalty=\lwcparameter{brokenpenalty}
+ \stopsetups
+
+ \startsetups[grid][*default]
+ \directsetup{*reset}
+
+ \clubpenalty=\lwcparameter{orphanpenalty}
+ \widowpenalty=\lwcparameter{widowpenalty}
+ \displaywidowpenalty=\lwcparameter{widowpenalty}
+ \brokenpenalty=\lwcparameter{brokenpenalty}
+ \stopsetups
+
+ \setups[*default]
+\stoptexdefinition
+
+% Load the main Lua file
+\ctxloadluafile{lua-widow-control}
+
+% Define the presets
+\definelwc[default][
+ emergencystretch=3em,
+ maxcost=2147483647,
+ nobreak=keep,
+ orphanpenalty=1,
+ widowpenalty=1,
+ brokenpenalty=1,
+]
+
+\definelwc[strict][
+ emergencystretch=0pt,
+ maxcost=5000,
+ nobreak=warn,
+ widowpenalty=1,
+ orphanpenalty=1,
+ brokenpenalty=1,
+]
+
+\definelwc[balanced][
+ emergencystretch=1em,
+ maxcost=10000
+ nobreak=keep,
+ widowpenalty=500,
+ orphanpenalty=500,
+ brokenpenalty=500,
+]
+
+% Set up the default options
+\setuplwc[
+ \c!state=\v!start,
+ debug=\v!stop,
+ draft=,
+ showcosts=\v!stop,
+ showcolours=\v!stop,
+ draftoffset=1in,
+]
+
+\setuplwc[default]
+
+\appendtoks
+ \ifcase\lwcsetupmode
+ % can't happen
+ \or % \setuplwc[name][key=value]
+ \ifx\previouslwc\currentlwc
+ \let\currentlwc\currentlwc
+ \lwc_set_parameters
+ \fi
+ \or % \setuplwc[key=value]
+ \let\currentlwc\previouslwc
+ \lwc_set_parameters
+ \or % \setuplwc[name]
+ \glet\currentlwc\currentlwc % global
+ \lwc_set_parameters
+ \fi
+\to \everysetuplwc
+
+\lwc_set_parameters
+
+% Here, we enable font expansion/contraction. It isn't strictly necessary for
+% \lwc/'s functionality; however, it is required for the
+% lengthened paragraphs to not have terrible spacing.
+\definefontfeature[default][default][expansion=quality]
+\setupalign[hz]
+
+% Expansion of some parts of the document, such as section headings, is quite
+% undesirable, so we'll disable \lwc/ for certain commands.
+% We should only reenable \lwc/ at the end if it was already enabled.
+\newcount\lwc_disable_count
+
+\define\lwc_patch_pre{%
+ \lwc_if_enabled%
+ \advance\lwc_disable_count by 1%
+ \setuplwc[\c!state=\v!stop]%
+ \fi%
+}
+
+\define\lwc_patch_post{
+ \ifnum\lwc_disable_count>0\relax%
+ \setuplwc[\c!state=\v!start]%
+ \advance\lwc_disable_count by -1%
+ \fi%
+}
+
+% Add the default patches
+\prependtoks\lwc_patch_pre\to\everybeforesectionheadhandle % Sectioning
+\prependtoks\lwc_patch_post\to\everyaftersectionheadhandle
+
+% Make the commands public
+\let\iflwc=\lwc_if_enabled
+
+\protect
+\stopmodule
diff --git a/macros/context/contrib/context-lua-widow-control/tex/lualatex/lua-widow-control/lua-widow-control-2022-02-22.sty b/macros/context/contrib/context-lua-widow-control/tex/lualatex/lua-widow-control/lua-widow-control-2022-02-22.sty
new file mode 100644
index 0000000000..d7f8601e60
--- /dev/null
+++ b/macros/context/contrib/context-lua-widow-control/tex/lualatex/lua-widow-control/lua-widow-control-2022-02-22.sty
@@ -0,0 +1,103 @@
+% lua-widow-control
+% https://github.com/gucci-on-fleek/lua-widow-control
+% SPDX-License-Identifier: MPL-2.0+
+% SPDX-FileCopyrightText: 2022 Max Chernoff
+
+\NeedsTeXFormat{LaTeX2e}[2015/01/01] % Formats built after 2015 include \LuaTeX{}Base
+\ProvidesPackage{lua-widow-control}%
+ [2022/02/22 v1.1.6]
+
+% The version number above is somewhat-misleading: I will make bugfixes to this file
+% from time to time, but the core of the file will not change. Therefore, we should
+% report a real version number here for debugging.
+\PackageInfo{lua-widow-control}{%
+ Real version:
+ 2022/11/22 %%slashdate
+ v3.0.0 %%version
+}
+
+\PackageWarning{lua-widow-control}{%
+ Old LaTeX format detected!\MessageBreak\MessageBreak
+ Lua-widow-control prefers a LaTeX format\MessageBreak
+ newer than November 2020. I'll still run\MessageBreak
+ the latest Lua code, but I'm using an older\MessageBreak
+ version of the LaTeX code. This means that\MessageBreak
+ the key-value interface is *UNSUPPORTED*.\MessageBreak
+}
+
+\ifdefined\directlua\else
+ \PackageError{lua-widow-control}{%
+ LuaTeX is required for this package.\MessageBreak
+ Make sure to compile with `lualatex'%
+ }{}
+\fi
+
+\clubpenalty=1
+\widowpenalty=1
+\displaywidowpenalty=1
+
+% We can't use \\newlength since that makes a \TeX{} "skip", not a "dimen"
+\newdimen\lwcemergencystretch
+\lwcemergencystretch=3em
+
+\newcount\lwcmaxcost
+\lwcmaxcost=2147483647
+
+\directlua{require "lua-widow-control"}
+
+% Here, we enable font expansion/contraction. It isn't strictly necessary for
+% \lwc/'s functionality; however, it is required for the
+% lengthened paragraphs to not have terrible spacing.
+\RequirePackage{etoolbox}
+\AtEndPreamble{
+ \@ifpackageloaded{microtype}{}{ % Only load if not already loaded
+ \RequirePackage[
+ final,
+ activate={true,nocompatibility}
+ ]{microtype}
+ }
+}
+
+% Define \TeX{} wrappers for Lua functions
+\newcommand{\lwcenable}{\directlua{lwc.enable_callbacks()}}
+\newcommand{\lwcdisable}{\directlua{lwc.disable_callbacks()}}
+\newcommand{\iflwc}{\directlua{lwc.if_lwc_enabled()}}
+
+% Enable \lwc/ by default when the package is loaded.
+\lwcenable
+
+% Expansion of some parts of the document, such as section headings, is quite
+% undesirable, so we'll disable \lwc/ for certain commands.
+\newcommand{\lwc@patch@warning}[1]{\PackageWarning{lua-widow-control}{%
+ Patching the \protect#1 command failed%
+}}
+
+% We should only reenable \lwc/ at the end if it was already enabled.
+\newif\iflwc@should@reenable
+
+\newcommand{\lwc@patch@pre}{%
+ \iflwc%
+ \lwc@should@reenabletrue%
+ \lwcdisable%
+ \else%
+ \lwc@should@reenablefalse%
+ \fi%
+}
+
+\newcommand{\lwc@patch@post}{%
+ \iflwc@should@reenable%
+ \lwcenable%
+ \fi%
+}
+
+\newcommand{\lwcdisablecmd}[1]{%
+ \ifdefined#1
+ \pretocmd{#1}{\lwc@patch@pre}{}{\lwc@patch@warning{#1}}%
+ \apptocmd{#1}{\lwc@patch@post}{}{\lwc@patch@warning{#1}}%
+ \fi
+}
+
+\lwcdisablecmd{\@sect} % Sectioning
+
+
+\endinput
diff --git a/macros/context/contrib/context-lua-widow-control/tex/lualatex/lua-widow-control/lua-widow-control.sty b/macros/context/contrib/context-lua-widow-control/tex/lualatex/lua-widow-control/lua-widow-control.sty
new file mode 100644
index 0000000000..ad3e95a28a
--- /dev/null
+++ b/macros/context/contrib/context-lua-widow-control/tex/lualatex/lua-widow-control/lua-widow-control.sty
@@ -0,0 +1,331 @@
+% lua-widow-control
+% https://github.com/gucci-on-fleek/lua-widow-control
+% SPDX-License-Identifier: MPL-2.0+
+% SPDX-FileCopyrightText: 2022 Max Chernoff
+
+% Formats built after 2015 include \LuaTeX{}Base, so this is the absolute
+% minimum version that we will run under.
+\NeedsTeXFormat{LaTeX2e}[2015/01/01]
+
+% For _really_ old formats
+\providecommand\DeclareRelease[3]{}
+\providecommand\DeclareCurrentRelease[2]{}
+
+\DeclareRelease{}{0000-00-00}{lua-widow-control-2022-02-22.sty}
+\DeclareRelease{v1.1.6}{2022-02-22}{lua-widow-control-2022-02-22.sty}
+\DeclareCurrentRelease{v3.0.0}{2022-11-22} %%version %%dashdate
+
+% If this version of LaTeX doesn't support command hooks, then we load
+% the last v1.1.X version of the package.
+\providecommand\IfFormatAtLeastTF{\@ifl@t@r\fmtversion}
+\IfFormatAtLeastTF{2020/10/01}{}{\input{lua-widow-control-2022-02-22.sty}}
+\IfFormatAtLeastTF{2020/10/01}{}{\endinput}
+
+\ProvidesExplPackage
+ {lua-widow-control}
+ {2022/11/22} %%slashdate
+ {v3.0.0} %%version
+ {Use Lua to remove widows and orphans}
+
+% Message and String Constants
+\str_const:Nn \c__lwc_name_str { lua-widow-control }
+
+\msg_new:nnn
+ { \c__lwc_name_str }
+ { no-luatex }
+ {
+ LuaTeX~ is~ REQUIRED! \\
+ Make~ sure~ to~ compile~ your~ document~ with~ `lualatex'.
+ }
+
+\msg_new:nnn
+ { \c__lwc_name_str }
+ { patch-failed }
+ {
+ Patching~ \c_backslash_str #1~ failed. \\
+ Please~ ensure~ that~ \c_backslash_str #1~ exists.
+ }
+
+\msg_new:nnn
+ { \c__lwc_name_str }
+ { old-format-patch }
+ {
+ Patching~ not~ supported~ with~ old~ LaTeX. \\
+ Please~ use~ a~ LaTeX~ format~ >=~ 2021/06/01.
+ }
+
+\msg_new:nnn
+ { \c__lwc_name_str }
+ { old-command }
+ {
+ \c_backslash_str #1~ has~ been~ REMOVED! \\
+ Please~ use~ \c_backslash_str setuplwc \c_left_brace_str #2
+ \c_right_brace_str\ instead.
+ }
+
+% Don't let the user proceed unless they are using \LuaTeX{}.
+\sys_if_engine_luatex:F {
+ \msg_critical:nn { \c__lwc_name_str } { no-luatex }
+}
+
+% Define (most of) the keys
+\cs_generate_variant:Nn \keys_define:nn { Vn }
+
+\keys_define:Vn { \c__lwc_name_str } {
+ emergencystretch .dim_gset:N = \g__lwc_emergencystretch_dim,
+ emergencystretch .value_required:n = true,
+ emergencystretch .initial:x = \dim_max:nn { 3em } { 30pt },
+
+ draftoffset .dim_gset:N = \g__lwc_draftoffset_dim,
+ draftoffset .value_required:n = true,
+ draftoffset .initial:x = 1in,
+
+ max-cost .int_gset:N = \g__lwc_maxcost_int,
+ max-cost .value_required:n = true,
+ max-cost .initial:x = \c_max_int,
+
+ widowpenalty .code:n = \int_gset:Nn \tex_widowpenalty:D { #1 }
+ \int_gset:Nn \tex_displaywidowpenalty:D { #1 },
+ widowpenalty .value_required:n = true,
+ widowpenalty .initial:n = 1,
+
+ orphanpenalty .code:n = \int_gset:Nn \tex_clubpenalty:D { #1 }
+ \int_gset:Nn \@clubpenalty { #1 },
+ orphanpenalty .value_required:n = true,
+ orphanpenalty .initial:n = 1,
+
+ brokenpenalty .int_gset:N = \tex_brokenpenalty:D,
+ brokenpenalty .value_required:n = true,
+ brokenpenalty .initial:n = 1,
+
+ microtype .bool_gset:N = \g__lwc_use_microtype_bool,
+ microtype .value_required:n = true,
+ microtype .initial:n = true,
+ microtype .usage:n = preamble,
+
+ disablecmds .clist_gset:N = \g__lwc_disablecmds_cl,
+ disablecmds .value_required:n = false,
+ disablecmds .initial:n = { \@sect, % LaTeX default
+ \@ssect, % LaTeX starred
+ \M@sect, % Memoir
+ \@mem@old@ssect, % Memoir Starred
+ \ttl@straight@ii, % titlesec normal
+ \ttl@top@ii, % titlesec top
+ \ttl@part@ii, % titlesec part
+ },
+ disablecmds .usage:n = preamble,
+}
+
+% Load the Lua code
+\cs_if_exist:NTF \lua_load_module:n {
+ \lua_load_module:n { lua-widow-control }
+} {
+ \lua_now:n { require "lua-widow-control" }
+}
+
+% Here, we enable font expansion/contraction. It isn't strictly necessary for
+% \lwc/'s functionality; however, it is required for the
+% lengthened paragraphs to not have terrible spacing.
+\hook_gput_code:nnn { begindocument / before } { \c__lwc_name_str } {
+ \bool_if:NT \g__lwc_use_microtype_bool {
+ \@ifpackageloaded { microtype } {} {
+ \RequirePackage[
+ final,
+ activate = { true, nocompatibility }
+ ]
+ { microtype }
+ }
+ }
+}
+
+% Core Function Definitions
+\cs_new_eq:NN \iflwc \__lwc_iflwc:
+
+\prg_new_conditional:Nnn \__lwc_if_enabled: { T, F, TF } {
+ \__lwc_if_enabled:
+ \prg_return_true:
+ \else
+ \prg_return_false:
+ \fi
+}
+
+\prg_new_conditional:Nnn \__lwc_if_lmtx: { T, F, TF } {
+ \int_compare:nNnTF { \tex_luatexversion:D } > { 200 } {
+ \prg_return_true:
+ } {
+ \prg_return_false:
+ }
+}
+
+% Expansion of some parts of the document, such as section headings, is quite
+% undesirable, so we'll disable \lwc/ for certain commands.
+\int_new:N \g__lwc_disable_int
+
+\cs_new:Npn \__lwc_patch_pre: {
+ % We should only reenable \lwc/ at the end if it was already enabled.
+ \__lwc_if_enabled:T {
+ \int_gincr:N \g__lwc_disable_int
+ \__lwc_disable:
+ }
+}
+
+\cs_new:Npn \__lwc_patch_post: {
+ \int_compare:nT { \g__lwc_disable_int > 0 } {
+ \__lwc_enable:
+ \int_gdecr:N \g__lwc_disable_int
+ }
+}
+
+\cs_new:Npn \__lwc_patch_cmd:c #1 {
+ \IfFormatAtLeastTF { 2021/06/01 } {
+ \hook_gput_code:nnn { cmd / #1 / before } { \c__lwc_name_str } {
+ \__lwc_patch_pre:
+ }
+ \hook_gput_code:nnn { cmd / #1 / after } { \c__lwc_name_str } {
+ \__lwc_patch_post:
+ }
+ } {
+ \msg_warning:nn
+ { \c__lwc_name_str }
+ { old-format-patch }
+ }
+}
+
+\cs_new:Npn \__lwc_patch_cmd:N #1 {
+ \__lwc_patch_cmd:c { \cs_to_str:N #1 }
+}
+
+\cs_new:Npn \__lwc_patch_cmd:n #1 {
+ % If the item provided is a single token, we'll assume that it's a \macro.
+ % If it is multiple tokens, we'll assume that it's a `csname`.
+ \tl_if_single:nTF { #1 } {
+ \__lwc_patch_cmd:c { \cs_to_str:N #1 }
+ } {
+ \__lwc_patch_cmd:c { #1 }
+ }
+}
+
+\hook_gput_code:nnn { begindocument / before } { \c__lwc_name_str } {
+ \clist_map_function:NN \g__lwc_disablecmds_cl \__lwc_patch_cmd:n
+}
+
+\__lwc_if_lmtx:T {
+ \int_gset:Nn \normalizelinemode {
+ \numexpression\normalizelinemode bor 2\relax
+ }
+}
+
+%%% Class and package-specifc patches
+
+% KOMA-Script
+\cs_if_exist:NT \AddtoDoHook {
+ \AddtoDoHook { heading / begingroup } { \__lwc_patch_pre: \use_none:n }
+ \AddtoDoHook { heading / endgroup } { \__lwc_patch_post: \use_none:n }
+}
+
+% Memoir
+\cs_gset_nopar:Npn \pen@ltyabovepfbreak { 23 } % Issue #32
+
+% Define some final keys
+\keys_define:Vn { \c__lwc_name_str } {
+ enable .choice:,
+ enable / true .code:n = \__lwc_enable:,
+ enable / false .code:n = \__lwc_disable:,
+ enable .initial:n = true,
+ enable .default:n = true,
+ enable .value_required:n = false,
+
+ disable .code:n = \__lwc_disable:,
+ disable .value_forbidden:n = true,
+
+ debug .choice:,
+ debug / true .code:n = \__lwc_debug:n { true },
+ debug / false .code:n = \__lwc_debug:n { false },
+ debug .default:n = true,
+ debug .value_required:n = false,
+
+ showcolours .choice:,
+ showcolours / true .code:n = \__lwc_show_colours:n { true },
+ showcolours / false .code:n = \__lwc_show_colours:n { false },
+ showcolours .default:n = true,
+ showcolours .value_required:n = false,
+
+ showcosts .choice:,
+ showcosts / true .code:n = \__lwc_show_costs:n { true },
+ showcosts / false .code:n = \__lwc_show_costs:n { false },
+ showcosts .default:n = true,
+ showcosts .value_required:n = false,
+
+ draft .meta:n = {
+ showcolours = { #1 },
+ showcosts = { #1 },
+ },
+ draft .default:n = true,
+ draft .value_required:n = false,
+
+ nobreak .code:n = \__lwc_nobreak:n { #1 },
+ nobreak .value_required:n = true,
+ nobreak .initial:n = keep,
+
+ strict .meta:n = { emergencystretch = 0pt,
+ max-cost = 5000,
+ nobreak = warn,
+ widowpenalty = 1,
+ orphanpenalty = 1,
+ brokenpenalty = 1,
+ },
+ strict .value_forbidden:n = true,
+
+ default .meta:n = { emergencystretch = 3em,
+ max-cost = \c_max_int,
+ nobreak = keep,
+ widowpenalty = 1,
+ orphanpenalty = 1,
+ brokenpenalty = 1,
+ },
+ default .value_forbidden:n = true,
+
+ balanced .meta:n = { emergencystretch = 1em,
+ max-cost = 10000,
+ nobreak = keep,
+ widowpenalty = 500,
+ orphanpenalty = 500,
+ brokenpenalty = 500,
+ },
+ balanced .value_forbidden:n = true,
+}
+
+% Add the user interface for the keys
+\IfFormatAtLeastTF { 2022-06-01 } {
+ \ProcessKeyOptions [ \c__lwc_name_str ]
+}{
+ \RequirePackage { l3keys2e }
+ \exp_args:NV \ProcessKeysOptions { \c__lwc_name_str }
+}
+
+\cs_generate_variant:Nn \keys_set:nn { Vn }
+\NewDocumentCommand \lwcsetup {m} {
+ \keys_set:Vn { \c__lwc_name_str }{ #1 }
+}
+
+% Legacy Commands
+\NewDocumentCommand \lwcemergencystretch { } {
+ \msg_error:nnnnn
+ { \c__lwc_name_str }
+ { old-command }
+ { lwcemergencystretch }
+ { emergencystretch=XXXpt }
+}
+
+\NewDocumentCommand \lwcdisablecmd { m } {
+ \msg_error:nnxx
+ { \c__lwc_name_str }
+ { old-command }
+ { lwcdisablecmd }
+ { disablecmds={\c_backslash_str aaa,~ \c_backslash_str bbb} }
+}
+
+\cs_new_eq:NN \lwcenable \__lwc_enable:
+\cs_new_eq:NN \lwcdisable \__lwc_disable:
+
+\endinput
diff --git a/macros/context/contrib/context-lua-widow-control/tex/luatex/lua-widow-control/lua-widow-control.lua b/macros/context/contrib/context-lua-widow-control/tex/luatex/lua-widow-control/lua-widow-control.lua
new file mode 100644
index 0000000000..59ae84ee3e
--- /dev/null
+++ b/macros/context/contrib/context-lua-widow-control/tex/luatex/lua-widow-control/lua-widow-control.lua
@@ -0,0 +1,1781 @@
+--[[
+ lua-widow-control
+ https://github.com/gucci-on-fleek/lua-widow-control
+ SPDX-License-Identifier: MPL-2.0+
+ SPDX-FileCopyrightText: 2022 Max Chernoff
+ ]]
+
+--- Tell the linter about node attributes
+--- @class node
+--- @field depth integer
+--- @field height integer
+--- @field id integer
+--- @field list node
+--- @field next node
+--- @field penalty integer
+--- @field prev node
+--- @field subtype integer
+
+-- Initial setup
+lwc = lwc or {}
+lwc.name = "lua-widow-control"
+
+-- Locals for `debug_print`
+local debug_lib = debug
+local string_rep = string.rep
+local write_nl = texio.write_nl
+
+local write_log
+if status.luatex_engine == "luametatex" then
+ write_log = "logfile"
+else
+ write_log = "log"
+end
+
+--- Prints debugging messages to the log, only if `debug` is set to `true`.
+---
+--- @param title string The "title" to use
+--- @param text string? The "content" to print
+--- @return nil
+local function debug(title, text)
+ if not lwc.debug then return end
+
+ -- The number of spaces we need
+ local filler = 15 - #title
+
+ if text then
+ write_nl(
+ write_log,
+ "LWC (" ..
+ title ..
+ string_rep(" ", filler) ..
+ "): " ..
+ text
+ )
+ else
+ write_nl(write_log, "LWC: " .. string_rep(" ", 18) .. title)
+ end
+end
+
+
+--[[
+ \lwc/ is intended to be format-agonistic. It only runs on Lua\TeX{} and
+ LuaMeta\TeX{}, but there are still some slight differences between formats.
+ Here, we detect the format name then set some flags for later processing.
+ ]]
+local format = tex.formatname
+local context, latex, plain, optex, lmtx
+
+if status.luatex_engine == "luametatex" then
+ lmtx = true
+end
+
+if format:find("cont") then -- cont-en, cont-fr, cont-nl, ...
+ context = true
+elseif format:find("latex") then -- lualatex, lualatex-dev, ...
+ latex = true
+elseif format == "luatex" or
+ format == "luahbtex" or
+ format:find("plain")
+then -- Plain
+ plain = true
+elseif format:find("optex") then -- OpTeX
+ optex = _G.optex
+end
+
+--[[
+ Save some local copies of the node library to reduce table lookups.
+ This is probably a useless micro-optimization, but it is done in all of the
+ ConTeXt and expl3 Lua code, so I should probably do it here too.
+ ]]
+-- Node ID's
+-- (We need to hardcode the subid's sadly)
+local id_from_name = node.id
+local baselineskip_subid = 2
+local glue_id = id_from_name("glue")
+local glyph_id = id_from_name("glyph")
+local hlist_id = id_from_name("hlist")
+local insert_id = id_from_name("insert") or id_from_name("ins")
+local line_subid = 1
+local linebreakpenalty_subid = 1
+local par_id = id_from_name("par") or id_from_name("local_par")
+local penalty_id = id_from_name("penalty")
+local parfill_subids = {
+ parfillleftskip = 17,
+ parfillrightskip = 16,
+ parinitleftskip = 19,
+ parinitrightskip = 18,
+}
+local vlist_id = id_from_name("vlist")
+
+-- Local versions of globals
+local abs = math.abs
+local copy = node.copy
+local copy_list = node.copy_list or node.copylist
+local effective_glue = node.effective_glue or node.effectiveglue
+local find_attribute = node.find_attribute or node.findattribute
+local free = node.free
+local free_list = node.flush_list or node.flushlist
+local get_attribute = node.get_attribute or node.getattribute
+local hpack = node.hpack
+local insert_token = token.put_next or token.putnext
+local is_node = node.is_node or node.isnode
+local last = node.slide
+local linebreak = tex.linebreak
+local new_node = node.new
+local remove = node.remove
+local set_attribute = node.set_attribute or node.setattribute
+local str_byte = string.byte
+local str_char = string.char
+local str_format = string.format
+local subtype = node.subtype
+local tex_box = tex.box
+local tex_count = tex.count
+local tex_dimen = tex.dimen
+local tex_lists = tex.lists
+local traverse = node.traverse
+local traverse_id = node.traverse_id or node.traverseid
+local vpack = node.vpack
+
+-- Misc. Constants
+local iffalse = token.create("iffalse")
+local iftrue = token.create("iftrue")
+local INFINITY = 10000
+local INSERT_CLASS_MULTIPLE = 1000 * 1000
+local INSERT_FIRST_MULTIPLE = 1000
+local PAGE_MULTIPLE = 100
+local SINGLE_LINE = 50
+
+lwc.colours = {
+ expanded = {0.00, 0.70, 0.25},
+ failure = {0.90, 0.00, 0.25},
+ moved = {0.25, 0.25, 1.00},
+ cost = {0.50, 0.50, 0.50},
+}
+
+
+--[[ Package/module initialization.
+
+ Here, we replace any format/engine-specific variables/functions with some
+ generic equivalents. This way, we can write the rest of the module without
+ worrying about any format/engine differences.
+ ]]
+local contrib_head,
+ draft_offset,
+ emergencystretch,
+ hold_head,
+ info,
+ insert_attribute,
+ max_cost,
+ page_head,
+ paragraph_attribute,
+ set_whatsit_field,
+ shrink_order,
+ stretch_order,
+ warning
+
+if lmtx then
+ -- LMTX has removed underscores from most of the Lua parts
+ debug("LMTX")
+ contrib_head = "contributehead"
+ shrink_order = "shrinkorder"
+ stretch_order = "stretchorder"
+ hold_head = "holdhead"
+ page_head = "pagehead"
+ set_whatsit_field = node.setwhatsitfield
+else
+ contrib_head = "contrib_head"
+ shrink_order = "shrink_order"
+ stretch_order = "stretch_order"
+ hold_head = "hold_head"
+ page_head = "page_head"
+ set_whatsit_field = node.setfield
+end
+
+if context then
+ debug("ConTeXt")
+
+ warning = logs.reporter(lwc.name, "warning")
+ local _info = logs.reporter(lwc.name, "info")
+ --[[ We don't want the info messages on the terminal, but ConTeXt doesn't
+ provide any logfile-only reporters, so we need this hack.
+ ]]
+ info = function (text)
+ logs.pushtarget("logfile")
+ _info(text)
+ logs.poptarget()
+ end
+ paragraph_attribute = attributes.public(lwc.name .. "_paragraph")
+ insert_attribute = attributes.public(lwc.name .. "_insert")
+
+ -- Dimen/count names
+ emergencystretch = "lwc_emergency_stretch"
+ draft_offset = "lwc_draft_offset"
+ max_cost = "lwc_max_cost"
+elseif plain or latex or optex then
+ -- Dimen names
+ if tex.isdimen("g__lwc_emergencystretch_dim") then
+ emergencystretch = "g__lwc_emergencystretch_dim"
+ draft_offset = "g__lwc_draftoffset_dim"
+ max_cost = "g__lwc_maxcost_int"
+ else
+ emergencystretch = "lwcemergencystretch"
+ draft_offset = "lwcdraftoffset"
+ max_cost = "lwcmaxcost"
+ end
+
+ if plain or latex then
+ debug("Plain/LaTeX")
+ luatexbase.provides_module {
+ name = lwc.name,
+ date = "2022/11/22", --%%slashdate
+ version = "3.0.0", --%%version
+ description = [[
+
+This module provides a LuaTeX-based solution to prevent
+widows and orphans from appearing in a document. It does
+so by increasing or decreasing the lengths of previous
+paragraphs.]],
+ }
+ warning = function(str) luatexbase.module_warning(lwc.name, str) end
+ info = function(str) luatexbase.module_info(lwc.name, str) end
+ paragraph_attribute = luatexbase.new_attribute(lwc.name .. "_paragraph")
+ insert_attribute = luatexbase.new_attribute(lwc.name .. "_insert")
+ elseif optex then
+ debug("OpTeX")
+
+ warning = function(str) write_nl(lwc.name .. " Warning: " .. str) end
+ info = function(str) write_nl("log", lwc.name .. " Info: " .. str) end
+ paragraph_attribute = alloc.new_attribute(lwc.name .. "_paragraph")
+ insert_attribute = alloc.new_attribute(lwc.name .. "_insert")
+ end
+else -- This shouldn't ever happen
+ error [[Unsupported format.
+
+Please use LaTeX, Plain TeX, ConTeXt or OpTeX.]]
+end
+
+-- We can't get the value of \\horigin from Lua, but we can guess it
+-- based on the format.
+local horigin
+if optex or (lmtx and context) then
+ horigin = 0
+else
+ horigin = tex.sp("1in")
+end
+
+-- Plain is the only format without a `pre_shipout_filter`
+if plain then
+ luatexbase.create_callback('pre_shipout_filter', 'list')
+end
+
+
+--[[ Select the fonts
+
+ We want to use cmr6 for the draft mode cost displays, and the easiest
+ way to do so is to just hardcode the font id's. This relies on some
+ implementation details; however, it is very unlikely to ever be an issue.
+ ]]
+local SMALL_FONT
+if plain then
+ SMALL_FONT = 5
+elseif latex then
+ SMALL_FONT = 6
+elseif optex then
+ SMALL_FONT = 8
+elseif context then
+ SMALL_FONT = fonts.definers.define({
+ name = "LMRoman6-Regular",
+ size = tex.sp("6pt"),
+ })
+end
+
+-- Global variables
+local paragraphs = {} -- The expanded paragraphs on each page
+local inserts = {} -- Copies of all the inserts on each page
+local costs = {} -- All of the paragraph costs for the document
+local pagenum = 1 -- The current page/column number
+
+--[[ Function definitions
+ ]]
+
+--- Gets the current paragraph and page locations
+--- @return string
+local function get_location()
+ return "At " .. pagenum .. "/" .. #paragraphs
+end
+
+
+--- Prints the starting glyphs and glue of an `hlist`.
+---
+--- Useful for debugging purposes.
+---
+--- @param head node
+--- @return nil
+local function get_chars(head)
+ if not lwc.debug then return end
+
+ local chars = ""
+ for n in traverse(head) do
+ if n.id == glyph_id then
+ if n.char < 127 then -- Only ASCII
+ chars = chars .. str_char(n.char)
+ else
+ chars = chars .. "#" -- Replacement for an unknown glyph
+ end
+ elseif n.id == glue_id then
+ chars = chars .. " " -- Any glue goes to a space
+ end
+ if #chars > 25 then
+ break
+ end
+ end
+
+ debug(get_location(), chars)
+end
+
+
+--- The "cost function" to use. Users can redefine this if they wish.
+---
+--- @param demerits number The demerits of the broken paragraph
+--- @param lines number The number of lines in the broken paragraph
+--- @param nat_demerits number The demerits of the naturally-broken paragraph
+--- @param nat_lines number The number of lines in the naturally-broken paragraph
+--- @param head node The head of the broken paragraph
+--- @return number cost The cost of the broken paragraph
+function lwc.paragraph_cost(demerits, lines, nat_demerits, nat_lines, head)
+ return demerits / math.sqrt(lines)
+end
+
+
+--- Checks if the ConTeXt "grid snapping" is active
+---
+--- @return boolean
+local function grid_mode_enabled()
+ -- Compare the token "mode" to see if `\\ifgridsnapping` is `\\iftrue`
+ return token.create("ifgridsnapping").mode == iftrue.mode
+end
+
+
+--- Gets the next node of a specified type/subtype in a node list
+---
+--- @param head node The head of the node list
+--- @param id number The node type
+--- @param args table?
+--- subtype: number = The node subtype
+--- reverse: bool = Whether we should iterate backwards
+--- @return node?
+local function next_of_type(head, id, args)
+ args = args or {}
+
+ if lmtx or not args.reverse then
+ for n, subtype in traverse_id(id, head, args.reverse) do
+ if (subtype == args.subtype) or (args.subtype == nil) then
+ return n
+ end
+ end
+ else
+ -- Only LMTX has the built-in backwards traverser, so we need to do
+ -- it manually otherwise.
+ while head do
+ if head.id == id and
+ (head.subtype == args.subtype or args.subtype == nil)
+ then
+ return head
+ end
+ head = head.prev
+ end
+ end
+
+ -- Needed for the special `tex.lists` nodes
+ if head and head.id == id and
+ (head.subtype == args.subtype or args.subtype == nil)
+ then
+ return head
+ end
+end
+
+
+--- Ensures that a paragraph is ready to be broken
+---
+--- Only applies to LuaMetaTeX
+---
+--- @param head node
+--- @return nil
+local function prepare_linebreak(head)
+ if not lmtx then
+ return
+ end
+
+ -- See how many of the par[left/right][init/fill]skips we have
+ local parfills = {}
+ local count = 0
+ for name, subid in pairs(parfill_subids) do
+ parfills[name] = next_of_type(head, glue_id, { subtype = subid })
+ if parfills[name] then
+ count = count + 1
+ end
+ end
+
+ if count == 0 then
+ -- Usual case
+ tex.preparelinebreak(head)
+ elseif count == 4 then
+ -- Already prepared for some reason, ignored
+ else
+ -- Uh oh
+ warning("Weird par(fill/init)skips found!")
+ tex.preparelinebreak(head) -- Try to fix it
+ end
+end
+
+
+--- Breaks a paragraph one line longer than natural
+---
+--- @param head node The unbroken paragraph
+--- @param parfillskip table<number> The {width, stretch, shrink,
+--- stretch_order, shrink_order} to set
+--- for the \\parfillskip
+--- @return node long_node The broken paragraph
+--- @return table long_info An info table about the broken paragraph
+local function long_paragraph(head, parfillskip)
+ -- We can't modify the original paragraph
+ head = copy_list(head)
+
+ prepare_linebreak(head)
+
+ -- TODO node.setglue is broken in LMTX, so we have to do this manually
+ local n = last(head)
+ n.width = parfillskip[1]
+ n.stretch = parfillskip[2]
+ n.shrink = parfillskip[3]
+ n[stretch_order] = parfillskip[4]
+ n[shrink_order] = parfillskip[5]
+
+ -- Break the paragraph 1 line longer than natural
+ local long_node, long_info = linebreak(head, {
+ looseness = 1,
+ emergencystretch = tex_dimen[emergencystretch],
+ })
+
+ -- Mark the last line for the costs display
+ set_attribute(
+ last(long_node),
+ paragraph_attribute,
+ -1 * (#paragraphs + 1 + (PAGE_MULTIPLE * pagenum))
+ )
+
+ return long_node, long_info
+end
+
+
+--- Breaks a paragraph at its natural length
+---
+--- @param head node The unbroken paragraph
+--- @return table natural_info An info table about the broken paragraph
+local function natural_paragraph(head)
+ -- We can't modify the original paragraph
+ head = copy_list(head)
+
+ prepare_linebreak(head)
+
+ -- Break the paragraph naturally to get \\prevgraf
+ local natural_node, natural_info = linebreak(head)
+ free_list(natural_node)
+
+ return natural_info
+end
+
+
+local show_colours = false
+--- Changes the text colour in a node list if draft mode is active
+---
+--- @param head node The first node to colour
+--- @param colour string The name of a colour in `lwc.colours`
+--- @return node head The coloured node
+local function colour_list(head, colour)
+ if not show_colours then
+ return head
+ end
+
+ local pdf_colour = str_format(
+ "%.2f %.2f %.2f rg",
+ table.unpack(lwc.colours[colour])
+ )
+
+ if optex and optex.set_node_color then
+ for n in node.traverse(head) do
+ optex.set_node_color(n, pdf_colour)
+ end
+
+ return head
+ end
+
+ if context then
+ nodes.tracers.colors.setlist(head, "lwc_" .. colour)
+ return head
+ end
+
+ -- Adapted from https://tex.stackexchange.com/a/372437 and
+ -- https://github.com/zauguin/luametalatex/issues/8.
+ local start_colour = new_node("whatsit", subtype("pdf_colorstack"))
+ set_whatsit_field(start_colour, "stack", 0)
+ set_whatsit_field(start_colour, "command", 1)
+ set_whatsit_field(start_colour, "data", pdf_colour)
+
+ local end_colour = new_node("whatsit", subtype("pdf_colorstack"))
+ set_whatsit_field(end_colour, "stack", 0)
+ set_whatsit_field(end_colour, "command", 2)
+
+ start_colour.next = head
+ last(head).next = end_colour
+
+ return start_colour
+end
+
+
+--- Saves each paragraph, but lengthened by 1 line
+---
+--- Called by the `pre_linebreak_filter` callback
+---
+--- @param head node The pre-broken paragraph
+--- @return node head The unmodified `head` argument
+function lwc.save_paragraphs(head)
+ if (head.id ~= par_id and context) or -- Make sure that `head` is a paragraph
+ status.output_active or -- Don't run during the output routine
+ tex.nest.ptr > 1 -- Don't run inside boxes
+ then
+ return head
+ end
+
+ -- Prevent the "underfull hbox" warnings when we store a potential paragraph
+ local renable_box_warnings
+ if (context or optex) or
+ #luatexbase.callback_descriptions("hpack_quality") == 0
+ then -- See #18 and michal-h21/linebreaker#3
+ renable_box_warnings = true
+ lwc.callbacks.disable_box_warnings.enable()
+ end
+
+ natural_info = natural_paragraph(head)
+
+ -- Prevent ultra-short last lines (\TeX{}book p. 104). Equivalent to
+ -- \\parfillskip=0.75\\hsize plus 0.05\\hsize minus 0.75\\hsize.
+ -- From http://petr.olsak.net/ftp/olsak/tbn/tbn.pdf p. 234 (via Jan Sustek)
+ long_node, long_info = long_paragraph(
+ head,
+ {0.75 * tex.hsize, 0.05 * tex.hsize, 0.75 * tex.hsize, 0, 0}
+ )
+
+ if long_info.prevgraf ~= natural_info.prevgraf + 1 then
+ -- The \\parfillskip settings with \\looseness=1 can sometimes
+ -- lengthen paragraphs by two lines instead of one. If this happens,
+ -- we fall back to a slightly-worse \\parfillskip setting.
+ free_list(long_node)
+ long_node, long_info = long_paragraph(
+ head,
+ {0, 0.8 * tex.hsize, false, 0, false}
+ )
+ end
+
+ if renable_box_warnings then
+ lwc.callbacks.disable_box_warnings.disable()
+ end
+
+ if not grid_mode_enabled() then
+ -- Offset the \\prevdepth differences between natural and long
+ local prevdepth = new_node("glue")
+ prevdepth.width = natural_info.prevdepth - long_info.prevdepth
+ last(long_node).next = prevdepth
+ end
+
+ local long_cost = lwc.paragraph_cost(
+ long_info.demerits,
+ long_info.prevgraf,
+ natural_info.demerits,
+ natural_info.prevgraf,
+ long_node
+ )
+
+ if long_info.prevgraf ~= natural_info.prevgraf + 1 or
+ long_cost < 10 -- Any paragraph that is "free" to expand is suspicious
+ then
+ -- This paragraph is infinitely bad
+ long_cost = math.maxinteger
+ end
+
+ -- The initial glue can disappear in ConTeXt's grid mode, so we
+ -- save starting at the first hlsit
+ local saved_node = next_of_type(long_node, hlist_id, { subtype = line_subid })
+
+ for n in traverse_id(hlist_id, saved_node) do
+ n.list = colour_list(n.list, "expanded")
+ end
+
+ table.insert(paragraphs, {
+ cost = long_cost,
+ node = copy_list(saved_node)
+ })
+
+ free_list(long_node)
+
+ costs[#paragraphs + (PAGE_MULTIPLE * pagenum)] = long_cost
+
+ -- Print some debugging information
+ if lwc.debug then
+ get_chars(head)
+ debug(get_location(), "nat lines " .. natural_info.prevgraf)
+ debug(
+ get_location(),
+ "nat cost " ..
+ lwc.paragraph_cost(natural_info.demerits, natural_info.prevgraf)
+ )
+ debug(get_location(), "long lines " .. long_info.prevgraf)
+ debug(
+ get_location(),
+ "long cost " ..
+ lwc.paragraph_cost(long_info.demerits, long_info.prevgraf)
+ )
+ end
+
+ -- \ConTeXt{} crashes if we return `true`
+ return head
+end
+
+
+--- Tags the beginning and the end of each paragraph as it is added to the page.
+---
+--- We add an attribute to the first and last node of each paragraph. The ID is
+--- some arbitrary number for \lwc/, and the value corresponds to the
+--- paragraphs index, which is negated for the end of the paragraph.
+---
+--- @param head node
+--- @return nil
+local function mark_paragraphs(head)
+ -- Tag the paragraphs
+ if status.output_active then
+ -- Don't run during the output routine
+ return
+ end
+
+ -- Get the start and end of the paragraph
+ local top = next_of_type(head, hlist_id, { subtype = line_subid })
+ local bottom = last(head)
+
+ -- The inserts disappear before `pre_output_routine`, so we shouldn't
+ -- mark them.
+ while bottom.id == insert_id do
+ bottom = bottom.prev
+ end
+
+ if top ~= bottom then
+ set_attribute(
+ top,
+ paragraph_attribute,
+ #paragraphs + (PAGE_MULTIPLE * pagenum)
+ )
+ set_attribute(
+ bottom,
+ paragraph_attribute,
+ -1 * (#paragraphs + (PAGE_MULTIPLE * pagenum))
+ )
+ else
+ -- We need a special tag for a 1-line paragraph since the node can only
+ -- have a single attribute value
+ set_attribute(
+ top,
+ paragraph_attribute,
+ #paragraphs + (PAGE_MULTIPLE * pagenum) + SINGLE_LINE
+ )
+ end
+end
+
+
+--- Tags the each line with the indices of any corresponding inserts.
+---
+--- We need to tag the first element of the hlist before the any insert nodes
+--- since the insert nodes are removed before `pre_output_filter` gets called.
+---
+--- @param head node
+--- @return nil
+local function mark_inserts(head)
+ local insert_indices = {}
+ for insert in traverse_id(insert_id, head) do
+ -- Save the found insert nodes for later
+ inserts[#inserts+1] = copy(insert)
+
+ -- Tag the insert's content so that we can find it later
+ set_attribute(insert.list, insert_attribute, #inserts)
+
+ -- We need to tag all lines---not just the start and the end---since
+ -- \TeX{} can split the insert between pages at any point.
+ for n in traverse(insert.list.next) do
+ set_attribute(n, insert_attribute, -1 * #inserts)
+ end
+
+ -- Each hlist/line can have multiple inserts, but so we can't just tag
+ -- the hlist as we go. Instead, we need save up all of their indices,
+ -- then tag the hlist with the first and last indices.
+ insert_indices[#insert_indices+1] = #inserts
+
+ if not insert.next or
+ insert.next.id ~= insert_id
+ then
+ local hlist_before = next_of_type(insert, hlist_id, { reverse = true} )
+
+ local insert_class
+ if lmtx then
+ insert_class = insert.index
+ else
+ insert_class = insert.subtype
+ end
+
+ -- We tag the first element of the hlist/line with an integer
+ -- that holds the insert class and the first and last indices
+ -- of the inserts contained in the line. This won't work if
+ -- the line has multiple classes of inserts, but I don't think
+ -- that happens in real-world documents. If this does turn out
+ -- to be an issue, we can get the insert's class from it's copy
+ -- at `pre_output_filter` instead of saving it now.
+ set_attribute(
+ hlist_before.list,
+ insert_attribute,
+ insert_class * INSERT_CLASS_MULTIPLE +
+ insert_indices[1] * INSERT_FIRST_MULTIPLE +
+ insert_indices[#insert_indices]
+ )
+
+ -- Clear the indices to prepare for the next line
+ insert_indices = {}
+ end
+ end
+end
+
+
+--- Saves the inserts and tags a typeset paragraph. Called by the
+--- `post_linebreak_filter` callback.
+---
+--- @param head node The head of the broken paragraph
+--- @return node head The unmodified `head` parameter
+function lwc.mark_paragraphs(head)
+ mark_paragraphs(head)
+ mark_inserts(head)
+
+ return head
+end
+
+
+--- Checks to see if a penalty matches the widow/orphan/broken penalties
+---
+--- @param penalty number
+--- @return boolean
+local function is_matching_penalty(penalty)
+ local widowpenalty = tex.widowpenalty
+ local clubpenalty = tex.clubpenalty
+ local displaywidowpenalty = tex.displaywidowpenalty
+ local brokenpenalty = tex.brokenpenalty
+
+ penalty = penalty - tex.interlinepenalty
+
+ -- Adapted from https://tug.org/TUGboat/tb39-3/tb123mitt-widows-code.pdf.
+ -- This only takes into account the original \TeX{} penalties, not the
+ -- "new" \eTeX{} \\(club/widow/broken)penalties commands.
+ return penalty ~= 0 and
+ penalty < INFINITY and (
+ penalty == widowpenalty or
+ penalty == displaywidowpenalty or
+ penalty == clubpenalty or
+ penalty == clubpenalty + widowpenalty or
+ penalty == clubpenalty + displaywidowpenalty or
+ penalty == brokenpenalty or
+ penalty == brokenpenalty + widowpenalty or
+ penalty == brokenpenalty + displaywidowpenalty or
+ penalty == brokenpenalty + clubpenalty or
+ penalty == brokenpenalty + clubpenalty + widowpenalty or
+ penalty == brokenpenalty + clubpenalty + displaywidowpenalty
+ )
+end
+
+
+--- Determines if we should "activate" \lwc/ for the current page/column.
+---
+--- Users can redefine this if they wish.
+---
+--- @param penalty number The \\outputpenalty for the current page/column
+--- @param paragraphs table<table<string, node|number>> The `paragraphs` table
+--- @param head node The head of the current page/column
+--- @return boolean activate True if \lwc/ should move the last line on this page
+function lwc.should_remove_widows(penalty, paragraphs, head)
+ return is_matching_penalty(penalty)
+end
+
+--- Reset any state saved between pages
+---
+--- This function is *vital* to ensure that we don't leak any nodes.
+--- If we do leak nodes, then very large documents will slow down and
+--- eventually fail to compile.
+---
+--- @return nil
+local function reset_state()
+ for _, paragraph in ipairs(paragraphs) do
+ free_list(paragraph.node)
+ end
+ paragraphs = {}
+
+ for _, insert in ipairs(inserts) do
+ free(insert)
+ end
+ inserts = {}
+
+ pagenum = pagenum + 1
+end
+
+
+--- When we are unable to remove a widow/orphan, print a warning
+---
+--- @return nil
+local function remove_widows_fail()
+ warning("Widow/Orphan/Broken Hyphen NOT removed on page " .. pagenum)
+
+ local last_line = next_of_type(
+ last(tex_lists[page_head]),
+ hlist_id,
+ { subtype = line_subid, reverse = true }
+ )
+ if last_line then
+ last_line.list = colour_list(last_line.list, "failure")
+ end
+
+ local next_first_line = next_of_type(
+ tex_lists[contrib_head],
+ hlist_id,
+ { subtype = line_subid }
+ )
+ if next_first_line then
+ next_first_line.list = colour_list(next_first_line.list, "failure")
+ end
+
+ reset_state()
+end
+
+
+--- Finds the first and last paragraphs present on a page
+---
+--- @param head node The node representing the start of the page
+--- @return number first_index The index of the first paragraph on the page in
+--- the `paragraphs` table
+--- @return number last_index The index of the last paragraph on the page in the
+--- `paragraphs` table
+local function first_last_paragraphs(head)
+ local first_index, last_index
+
+ -- Find the last paragraph on the page, starting at the end, heading in reverse
+ local n = last(head)
+ while n do
+ local value = get_attribute(n, paragraph_attribute)
+ if value then
+ last_index = value % PAGE_MULTIPLE
+ break
+ end
+
+ n = n.prev
+ end
+
+ -- Find the first paragraph on the page, from the top
+ local first_val, first_head = find_attribute(head, paragraph_attribute)
+ while abs(first_val) // PAGE_MULTIPLE == pagenum - 1 do
+ -- If the first complete paragraph on the page was initially broken on the
+ -- previous page, then we can't expand it here. Why can't we expand it?
+ -- Well, expanding it will nearly always change how the first few lines
+ -- are printed, but we can't modify those since they've already been
+ -- shipped out. So, we need to skip these paragraphs.
+ first_val, first_head = find_attribute(
+ first_head.next,
+ paragraph_attribute
+ )
+ end
+
+ first_index = first_val % PAGE_MULTIPLE
+
+ if first_index >= SINGLE_LINE then
+ first_index = first_index - SINGLE_LINE
+ end
+
+ debug("first/last", first_index .. "/" .. last_index)
+
+ return first_index, last_index
+end
+
+
+--- Selects the "best" paragraph on the page to expand
+---
+--- @param head node The node representing the start of the page
+--- @return number? best_index The index of the paragraph to expand in the
+--- `paragraphs` table
+local function best_paragraph(head)
+ local first_paragraph_index, last_paragraph_index = first_last_paragraphs(head)
+
+ -- Find the paragraph on the page with the least cost.
+ local best_index = 1
+ local best_cost = paragraphs[best_index].cost
+
+ -- We find the current "best" replacement
+ for index, paragraph in pairs(paragraphs) do
+ if paragraph.cost < best_cost and
+ index < last_paragraph_index and
+ index >= first_paragraph_index
+ then
+ best_index, best_cost = index, paragraph.cost
+ end
+ end
+
+ debug(
+ "selected para",
+ pagenum .. "/" .. best_index .. " (" .. best_cost .. ")"
+ )
+
+ if best_cost > tex_count[max_cost] or
+ best_index == last_paragraph_index or -- Shouldn't happen
+ best_cost == math.maxinteger
+ then
+ return nil
+ else
+ return best_index
+ end
+end
+
+
+--- Gets any inserts present in the moved line
+---
+--- @param last_line node The moved last line
+--- @return table<node> inserts A list of the present inserts
+local function get_inserts(last_line)
+ local selected_inserts = {}
+
+ local n = last_line.list
+ while n do -- Iterate through the last line
+ local line_value
+ line_value, n = find_attribute(n, insert_attribute)
+
+ if not n then
+ break
+ end
+
+ -- Demux the insert values
+ local class = line_value // INSERT_CLASS_MULTIPLE
+ local first_index = (line_value % INSERT_CLASS_MULTIPLE)
+ // INSERT_FIRST_MULTIPLE
+ local last_index = line_value % INSERT_FIRST_MULTIPLE
+
+ -- Get the output box containing the insert boxes
+ local insert_box
+
+ if lmtx then
+ insert_box = tex.getinsertcontent(class)
+ -- `getinsertcontent` resets the insert box, so we need to
+ -- re-set it.
+ tex.setinsertcontent(class, insert_box)
+ else
+ insert_box = tex_box[class]
+ end
+
+ -- Get any portions of the insert "held over" until the next page
+ local split_insert
+ if lmtx then
+ split_insert = next_of_type(
+ tex_lists[hold_head],
+ insert_id,
+ { index = class }
+ )
+ else
+ split_insert = next_of_type(
+ tex_lists[hold_head],
+ insert_id,
+ { subtype = class }
+ )
+ end
+
+ -- We use the same procedure for this page and the next page
+ for i, insert in ipairs { insert_box, split_insert } do
+ local m = insert and insert.list
+
+ while m do -- Iterate through the insert box
+ local box_value
+ box_value, m = find_attribute(m, insert_attribute)
+ local next = m.next
+
+ if not m then
+ break
+ end
+
+ if abs(box_value) >= first_index and
+ abs(box_value) <= last_index
+ then
+ -- Remove the respective contents from the insert box
+ insert.list = remove(insert.list, m)
+
+ if box_value > 0 and i == 1 then
+ table.insert(selected_inserts, copy(inserts[box_value]))
+ end
+
+ free(m)
+ end
+
+ m = next
+ end
+ end
+
+ -- If the box has no contents, then void it so that any \\ifvoid
+ -- tests work correctly in the output routine.
+ if not insert_box.list then
+ tex_box[class] = nil
+ end
+
+ if split_insert and not split_insert.list then
+ remove(tex_lists[hold_head], split_insert)
+ end
+
+ n = n.next
+ end
+
+ if #selected_inserts ~= 0 then
+ -- This is a somewhat-risky process, so we print an info
+ -- message just in case something goes wrong. We can probably
+ -- remove this in the future if we're sure that everything
+ -- is working correctly.
+ info("Moving footnotes on page " .. pagenum)
+ end
+
+ return selected_inserts
+end
+
+
+lwc.nobreak_behaviour = "keep"
+--- Moves the last line of the page onto the following page.
+---
+--- This is the most complicated function of the module since it needs to
+--- look back to see if there is a heading preceding the last line, then it does
+--- some low-level node shuffling.
+---
+--- @param head node The node representing the start of the page
+--- @return boolean success Set to false if something went wrong
+local function move_last_line(head)
+ -- Start of final paragraph
+ debug("remove_widows", "moving last line")
+
+ -- Here we check to see if the widow/orphan was preceded by a large penalty
+ local big_penalty_found, last_line, hlist_head
+ local n = last(head).prev
+ while n do
+ if n.id == glue_id then
+ -- Ignore any glue nodes
+ elseif n.id == penalty_id and n.penalty >= INFINITY then
+ -- Infinite break penalty
+ big_penalty_found = true
+ elseif big_penalty_found and n.id == hlist_id then
+ -- Line before the penalty
+ if lwc.nobreak_behaviour == "keep" then
+ hlist_head = n
+ big_penalty_found = false
+ elseif lwc.nobreak_behaviour == "split" then
+ n = last(head)
+ break
+ elseif lwc.nobreak_behaviour == "warn" then
+ debug("last line", "heading found")
+ return false
+ end
+ else
+ -- Not found
+ if hlist_head then
+ n = hlist_head
+ else
+ n = last(head)
+ end
+ break
+ end
+ n = n.prev
+ end
+
+ local potential_penalty = n.prev.prev
+
+ if potential_penalty and
+ potential_penalty.id == penalty_id and
+ potential_penalty.subtype == linebreakpenalty_subid and
+ is_matching_penalty(potential_penalty.penalty)
+ then
+ warning("Making a new widow/orphan/broken hyphen on page " .. pagenum)
+
+ local second_last_line = next_of_type(
+ potential_penalty,
+ hlist_id,
+ { subtype = line_subid, reverse = true }
+ )
+ second_last_line.list = colour_list(second_last_line.list, "failure")
+ end
+
+ last_line = copy_list(n)
+
+ last_line.list = colour_list(last_line.list, "moved")
+
+ -- Reinsert any inserts originally present in this moved line
+ local selected_inserts = get_inserts(last_line)
+ for _, insert in ipairs(selected_inserts) do
+ last(last_line).next = insert
+ end
+
+ -- Add back in the content from the next page
+ last(last_line).next = copy_list(tex_lists[contrib_head])
+
+ free_list(n.prev.prev.next)
+ n.prev.prev.next = nil
+
+ -- Set the content of the next page
+ free_list(tex_lists[contrib_head])
+ tex_lists[contrib_head] = last_line
+
+ return true
+end
+
+
+--- Replace the chosen paragraph with its expanded version.
+---
+--- This is the "core function" of the module since it is what ultimately causes
+--- the expansion to occur.
+---
+--- @param head node
+--- @param paragraph_index number
+local function replace_paragraph(head, paragraph_index)
+ -- Remove any inserts. They are completely ignored after
+ -- the page has been broken, but they can upset LuaMetaLaTeX if
+ -- they're found somewhere unexpected.
+ local target_node, last_target_node
+ for n in traverse(paragraphs[paragraph_index].node) do
+ -- Just removing the inserts from the list doesn't work properly,
+ -- so we instead copy over everything that isn't an insert.
+ if n.id ~= insert_id then
+ if not target_node then
+ target_node = copy(n)
+ last_target_node = target_node
+ else
+ last_target_node.next = copy(n)
+ last_target_node = last_target_node.next
+ end
+ end
+ end
+
+ local start_found = false
+ local end_found = false
+ local free_nodes_begin
+
+ -- Loop through all of the nodes on the page with the \lwc/ attribute
+ local n = head
+ while n do
+ local value
+ value, n = find_attribute(n, paragraph_attribute)
+
+ if not n then
+ break
+ end
+
+ debug("remove_widows", "found " .. value)
+
+ -- Insert the start of the replacement paragraph
+ if value == paragraph_index + (PAGE_MULTIPLE * pagenum) or
+ value == paragraph_index + (PAGE_MULTIPLE * pagenum) + SINGLE_LINE
+ then
+ debug("remove_widows", "replacement start")
+ start_found = true
+
+ -- Fix the `\\baselineskip` glue between paragraphs
+ height_difference = (
+ next_of_type(n, hlist_id, { subtype = line_subid }).height -
+ next_of_type(
+ target_node, hlist_id, { subtype = line_subid }
+ ).height
+ )
+
+ local prev_bls = next_of_type(
+ n,
+ glue_id,
+ { subtype = baselineskip_subid, reverse = true }
+ )
+
+ if prev_bls then
+ prev_bls.width = prev_bls.width + height_difference
+ end
+
+ n.prev.next = target_node
+ free_nodes_begin = n
+ end
+
+ -- Insert the end of the replacement paragraph
+ if value == -(paragraph_index + (PAGE_MULTIPLE * pagenum)) or
+ value == paragraph_index + (PAGE_MULTIPLE * pagenum) + SINGLE_LINE
+ then
+ debug("remove_widows", "replacement end")
+ end_found = true
+
+ local target_node_last = last(target_node)
+
+ if grid_mode_enabled() then
+ -- Account for the difference in depth
+ local after_glue = new_node("glue")
+ after_glue.width = n.depth - target_node_last.depth
+ target_node_last.next = after_glue
+
+ after_glue.next = n.next
+ else
+ target_node_last.next = n.next
+ end
+
+ n.next = nil
+
+ break
+ end
+
+ n = n.next
+ end
+
+ if start_found and end_found then
+ free_list(free_nodes_begin)
+ else
+ warning("Paragraph NOT expanded on page " .. pagenum)
+ end
+end
+
+
+--- Remove the widows and orphans from the page, just after the output routine.
+---
+--- This is called just after the end of the output routine, before the page is
+--- shipped out. If the output penalty indicates that the page was broken at a
+--- widow or an orphan, we replace one paragraph with the same paragraph, but
+--- lengthened by one line. Then, we can push the bottom line of the page to the
+--- next page.
+---
+--- @param head node
+--- @return node
+function lwc.remove_widows(head)
+ debug("outputpenalty", tex.outputpenalty .. " " .. #paragraphs)
+
+ -- See if there is a widow/orphan for us to remove
+ if not lwc.should_remove_widows(tex.outputpenalty, paragraphs, head) then
+ reset_state()
+ return head
+ end
+
+ info("Widow/orphan/broken hyphen detected. Attempting to remove")
+
+ -- Nothing that we can do if there aren't any paragraphs available to expand
+ if #paragraphs == 0 then
+ debug("failure", "no paragraphs to expand")
+ remove_widows_fail()
+ return head
+ end
+
+ -- Check the original height of \\box255
+ local vsize = tex_dimen.vsize
+ local orig_vpack = vpack(head)
+ local orig_height_diff = orig_vpack.height - vsize
+ orig_vpack.list = nil
+ free(orig_vpack)
+
+ -- Find the paragraph to expand
+ local paragraph_index = best_paragraph(head)
+
+ if not paragraph_index then
+ debug("failure", "no good paragraph")
+ remove_widows_fail()
+ return head
+ end
+
+ -- Move the last line of the page to the next page
+ if not move_last_line(head) then
+ debug("failure", "can't move last line")
+ remove_widows_fail()
+ return head
+ end
+
+ -- Replace the chosen paragraph with its expanded version
+ replace_paragraph(head, paragraph_index)
+
+ -- The final \\box255 needs to be exactly \\vsize tall to avoid
+ -- over/underfull box warnings, so we correct any discrepancies
+ -- here.
+ local new_vpack = vpack(head)
+ local new_height_diff = new_vpack.height - vsize
+ new_vpack.list = nil
+ free(new_vpack)
+ -- We need the original height discrepancy in case there are \\vfill's
+ local net_height_diff = orig_height_diff - new_height_diff
+ local bls = tex.skip.baselineskip
+ local bls_width = bls.width
+ free(bls)
+
+ if abs(net_height_diff) > 0 and
+ -- A difference larger than 0.25\\baselineskip is probably not from
+ -- \lwc/, so we let those warnings surface
+ abs(net_height_diff) < bls_width / 4
+ then
+ local bottom_glue = new_node("glue")
+ bottom_glue.width = net_height_diff
+ last(head).next = bottom_glue
+ end
+
+ info(
+ "Widow/orphan/broken hyphen successfully removed at paragraph "
+ .. paragraph_index
+ .. " on page "
+ .. pagenum
+ )
+
+ reset_state()
+
+ return head
+end
+
+
+local show_costs = false
+--- Add the paragraph to the list of paragraphs on the page.
+---
+--- Called immediately before the page is shipped out so that we can get
+--- the costs on the correct side in multi-column layouts.
+---
+--- To evenly align all of the costs in the margins, we need to know the
+--- the exact position of the start and end of the paragraph on the page.
+--- This is surprisingly complicated.
+---
+--- @param head node The box to be shipped out
+--- @return true
+function lwc.show_costs (head)
+ if not show_costs then
+ return true
+ end
+
+ local pagewidth = tex.pagewidth or layouts.getpagedimensions()
+
+ --- Loop over each sublist, add up the total width, and show the costs.
+ ---
+ --- @param n node The node to loop over
+ --- @param width number The accumulated width so far
+ --- @param parent node The parent node of the current list
+ --- @return nil
+ local function recurse(n, width, parent)
+ for m in traverse(n) do
+ -- Anything with an \\hbox parent and a width is actual width.
+ -- (If it had a \\vbox parent, then n.width would actually be height.)
+ local self_width = 0
+ if m.id == glue_id and parent.id == hlist_id then
+ self_width = effective_glue(m, parent)
+ elseif m.width and parent.id == hlist_id then
+ self_width = m.width
+ end
+
+ -- A node's "shift" attribute is horizontal only if the parent is
+ -- a \\vbox. This corresponds to the primatives \\moveleft and
+ -- \\moveright. (If the parent is a \\hbox, then n.shift is
+ -- vertical and corresponds to \\raise.)
+ local shift = 0
+ if m.shift and
+ (parent.id == vlist_id or
+ not is_node(parent))
+ then
+ shift = m.shift
+ end
+
+ width = width + self_width
+
+ local attr = get_attribute(m, paragraph_attribute)
+ if attr and abs(attr) % PAGE_MULTIPLE >= SINGLE_LINE then
+ attr = -1 * (abs(attr) - SINGLE_LINE)
+ end
+
+ local cost = costs[abs(attr or 0)]
+
+ if attr and attr < 0 and cost and m.list then
+ -- We've found the end of a marked paragraph!
+
+ -- Generate the \\hbox containing the formatted cost
+ local cost_str
+ if not cost then
+ return
+ elseif cost < math.maxinteger then
+ cost_str = str_format("%.0f", cost)
+ else
+ cost_str = "infinite"
+ end
+
+ local prev, first
+ for letter in cost_str:gmatch(".") do
+ local curr = new_node("glyph")
+ curr.font = SMALL_FONT
+ curr.char = str_byte(letter)
+
+ if not first then
+ first = curr
+ else
+ prev.next = curr
+ end
+ prev = curr
+ end
+
+ local text = hpack(colour_list(first, "cost"))
+
+ -- Make an \\hss to make sure that our `\\hbox`es aren't overfull
+ local hss = new_node("glue")
+ hss.stretch = 1
+ hss[stretch_order] = 1
+ hss.shrink = 1
+ hss[shrink_order] = 1
+
+ local hbox
+ local offset = new_node("glue")
+
+ if (width >= pagewidth / 2) or
+ (m.width >= 0.4 * pagewidth)
+ then -- Right column or single-column
+ -- Costs in the right margin
+ offset.width = (
+ pagewidth -
+ width -
+ m.width -
+ shift -
+ tex_dimen[draft_offset]
+ )
+ text.next = hss
+ hbox = hpack(text, 0, "exactly")
+ else -- Left column
+ -- Costs in the left margin
+ offset.width = (
+ tex_dimen[draft_offset] -
+ m.width -
+ width -
+ shift
+ )
+ hss.next = text
+ hbox = hpack(hss, 0, "exactly")
+ end
+
+ last(m.list).next = offset
+ offset.next = hbox
+ elseif m.list then
+ recurse(m.list, width - self_width + shift, m)
+ end
+ end
+ end
+
+ -- Start at the root of the page
+ recurse(head.list, (tex.hoffset or 0) + horigin, {})
+
+ -- LaTeX requires us to always return true here
+ return true
+end
+
+
+--- Create a table of functions to enable or disable a given callback
+---
+--- @param t table Parameters of the callback to create
+--- callback: string = The \LuaTeX{} callback name
+--- func: function = The function to call
+--- name: string = The name/ID of the callback
+--- category: string = The category for a \ConTeXt{} "Action"
+--- position: string = The "position" for a \ConTeXt{} "Action"
+--- lowlevel: boolean = If we should use a lowlevel \LuaTeX{} callback
+--- instead of a \ConTeXt{} "Action"
+--- @return table t Enablers/Disablers for the callback
+--- enable: function = Enable the callback
+--- disable: function = Disable the callback
+local function register_callback(t)
+ if plain or latex then -- Both use \LuaTeX{}Base for callbacks
+ return {
+ enable = function()
+ luatexbase.add_to_callback(t.callback, t.func, t.name)
+ end,
+ disable = function()
+ luatexbase.remove_from_callback(t.callback, t.name)
+ end,
+ }
+ elseif context and not t.lowlevel then
+ return {
+ -- Register the callback when the table is created,
+ -- but activate it when `enable()` is called.
+ enable = nodes.tasks.appendaction(t.category, t.position, "lwc." .. t.name)
+ or function()
+ nodes.tasks.enableaction(t.category, "lwc." .. t.name)
+ end,
+ disable = function()
+ nodes.tasks.disableaction(t.category, "lwc." .. t.name)
+ end,
+ }
+ elseif context and t.lowlevel then
+ -- Some of the callbacks in \ConTeXt{} have no associated "actions".
+ -- Unlike with \LuaTeX{}base, \ConTeXt{} leaves some \LuaTeX{} callbacks
+ -- unregistered and unfrozen. Because of this, we need to register some
+ -- callbacks at the engine level. This is fragile though, because a
+ -- future \ConTeXt{} update may decide to register one of these
+ -- functions, in which case \lwc/ will crash with a cryptic error
+ -- message.
+ return {
+ enable = function() callback.register(t.callback, t.func) end,
+ disable = function() callback.register(t.callback, nil) end,
+ }
+ elseif optex then -- Op\TeX{} is luckily very similar to luatexbase
+ return {
+ enable = function()
+ callback.add_to_callback(t.callback, t.func, t.name)
+ end,
+ disable = function()
+ callback.remove_from_callback(t.callback, t.name)
+ end,
+ }
+ end
+end
+
+
+-- Add all of the callbacks
+lwc.callbacks = {
+ disable_box_warnings = register_callback({
+ callback = "hpack_quality",
+ func = function() end,
+ name = "disable_box_warnings",
+ lowlevel = true,
+ }),
+ remove_widows = register_callback({
+ callback = "pre_output_filter",
+ func = lwc.remove_widows,
+ name = "remove_widows",
+ lowlevel = true,
+ }),
+ save_paragraphs = register_callback({
+ callback = "pre_linebreak_filter",
+ func = lwc.save_paragraphs,
+ name = "save_paragraphs",
+ category = "processors",
+ position = "after",
+ }),
+ mark_paragraphs = register_callback({
+ callback = "post_linebreak_filter",
+ func = lwc.mark_paragraphs,
+ name = "mark_paragraphs",
+ category = "finalizers",
+ position = "after",
+ }),
+ show_costs = register_callback({
+ callback = "pre_shipout_filter",
+ func = lwc.show_costs,
+ name = "show_costs",
+ category = "shipouts",
+ position = "finishers",
+ }),
+}
+
+
+local lwc_enabled = false
+--- Enables the paragraph callbacks
+function lwc.enable_callbacks()
+ debug("callbacks", "enabling")
+ if not lwc_enabled then
+ lwc.callbacks.save_paragraphs.enable()
+ lwc.callbacks.mark_paragraphs.enable()
+
+ lwc_enabled = true
+ else
+ info("Already enabled")
+ end
+end
+
+
+--- Disables the paragraph callbacks
+function lwc.disable_callbacks()
+ debug("callbacks", "disabling")
+ if lwc_enabled then
+ lwc.callbacks.save_paragraphs.disable()
+ lwc.callbacks.mark_paragraphs.disable()
+
+ -- We do *not* disable `remove_widows` callback, since we still want
+ -- to expand any of the previously-saved paragraphs if we hit an orphan
+ -- or a widow.
+ lwc_enabled = false
+ else
+ info("Already disabled")
+ end
+end
+
+function lwc.if_lwc_enabled()
+ debug("iflwc")
+ if lwc_enabled then
+ insert_token(iftrue)
+ else
+ insert_token(iffalse)
+ end
+end
+
+
+--- Mangles a macro name so that it's suitable for a specific format
+---
+--- @param name string The plain name
+--- @param args table<string> The TeX types of the function arguments
+--- @return string name The mangled name
+local function mangle_name(name, args)
+ if plain then
+ return "lwc@" .. name:gsub("_", "@")
+ elseif optex then
+ return "_lwc_" .. name
+ elseif context then
+ return "lwc_" .. name
+ elseif latex then
+ return "__lwc_" .. name .. ":" .. string_rep("n", #args)
+ end
+end
+
+
+--- Creates a TeX command that evaluates a Lua function
+---
+--- @param name string The name of the csname to define
+--- @param func function
+--- @param args table<string> The TeX types of the function arguments
+--- @return nil
+local function register_tex_cmd(name, func, args)
+ local scanning_func
+ name = mangle_name(name, args)
+
+ if not context then
+ local scanners = {}
+ for _, arg in ipairs(args) do
+ scanners[#scanners+1] = token['scan_' .. arg]
+ end
+
+ -- An intermediate function that properly "scans" for its arguments
+ -- in the \TeX{} side.
+ scanning_func = function()
+ local values = {}
+ for _, scanner in ipairs(scanners) do
+ values[#values+1] = scanner()
+ end
+
+ func(table.unpack(values))
+ end
+ end
+
+ if optex then
+ define_lua_command(name, scanning_func)
+ return
+ elseif plain or latex then
+ local index = luatexbase.new_luafunction(name)
+ lua.get_functions_table()[index] = scanning_func
+ token.set_lua(name, index)
+ elseif context then
+ interfaces.implement {
+ name = name,
+ public = true,
+ arguments = args,
+ actions = func
+ }
+ end
+end
+
+--[[ Make all of the \lwc/ Lua commands available from \TeX{}
+ ]]
+register_tex_cmd("if_enabled", lwc.if_lwc_enabled, {})
+register_tex_cmd("enable", lwc.enable_callbacks, {})
+register_tex_cmd("disable", lwc.disable_callbacks, {})
+register_tex_cmd(
+ "nobreak",
+ function(str)
+ lwc.nobreak_behaviour = str
+ end,
+ { "string" }
+)
+register_tex_cmd(
+ "debug",
+ function(str)
+ lwc.debug = str ~= "0" and str ~= "false" and str ~= "stop"
+ end,
+ { "string" }
+)
+register_tex_cmd(
+ "show_costs",
+ function(str)
+ show_costs = str ~= "0" and str ~= "false" and str ~= "stop"
+ end,
+ { "string" }
+)
+register_tex_cmd(
+ "show_colours",
+ function(str)
+ show_colours = str ~= "0" and str ~= "false" and str ~= "stop"
+ end,
+ { "string" }
+)
+register_tex_cmd(
+ "pre_shipout",
+ function(box)
+ luatexbase.call_callback('pre_shipout_filter', tex_box[box])
+ end,
+ { "int" }
+)
+
+--- Silence the luatexbase "Enabling/Removing <callback>" info messages
+---
+--- Every time that a paragraph is typeset, \lwc/ hooks in
+--- and typesets the paragraph 1 line longer. Some of these longer paragraphs
+--- will have pretty bad badness values, so TeX will issue an over/underfull
+--- hbox warning. To block these warnings, we hook into the `hpack_quality`
+--- callback and disable it so that no warning is generated.
+---
+--- However, each time that we enable/disable the null `hpack_quality` callback,
+--- luatexbase puts an info message in the log. This completely fills the log file
+--- with useless error messages, so we disable it here.
+---
+--- This uses the Lua `debug` library to internally modify the log upvalue in the
+--- `add_to_callback` function. This is almost certainly a terrible idea, but I
+--- don't know of a better way to do it.
+---
+--- @return nil
+local function silence_luatexbase()
+ local nups = debug_lib.getinfo(luatexbase.add_to_callback).nups
+
+ for i = 1, nups do
+ local name, func = debug_lib.getupvalue(luatexbase.add_to_callback, i)
+ if name == "luatexbase_log" then
+ debug_lib.setupvalue(
+ luatexbase.add_to_callback,
+ i,
+ function(text)
+ if text:match("^Inserting") or text:match("^Removing") then
+ return
+ else
+ func(text)
+ end
+ end
+ )
+ return
+ end
+ end
+end
+
+
+-- Call `silence_luatexbase` in Plain and LaTeX, unless the undocmented global
+-- `LWC_NO_DEBUG` is set. We provide this opt-out in case something goes awry
+-- with the `debug` library calls.
+if (plain or latex) and
+ not LWC_NO_DEBUG --- @diagnostic disable-line
+then
+ silence_luatexbase()
+end
+
+-- Register colours for ConTeXt
+if context then
+ for colour, values in pairs(lwc.colours) do
+ attributes.colors.defineprocesscolor(
+ "lwc_" .. colour,
+ str_format("r=%.2f, g=%.2f, b=%.2f", table.unpack(values))
+ )
+ end
+end
+
+-- Activate \lwc/
+lwc.callbacks.remove_widows.enable()
+lwc.callbacks.show_costs.enable()
+
+return lwc
+
diff --git a/macros/context/contrib/context-lua-widow-control/tex/luatex/lua-widow-control/lua-widow-control.tex b/macros/context/contrib/context-lua-widow-control/tex/luatex/lua-widow-control/lua-widow-control.tex
new file mode 100644
index 0000000000..e25342ee4b
--- /dev/null
+++ b/macros/context/contrib/context-lua-widow-control/tex/luatex/lua-widow-control/lua-widow-control.tex
@@ -0,0 +1,119 @@
+% lua-widow-control
+% https://github.com/gucci-on-fleek/lua-widow-control
+% SPDX-License-Identifier: MPL-2.0+
+% SPDX-FileCopyrightText: 2022 Max Chernoff
+
+\wlog{lua-widow-control v3.0.0} %%version
+
+\ifx\directlua\undefined
+ \errmessage{%
+ LuaTeX is required for this package.
+ Make sure to compile with `luatex'%
+ }
+\fi
+
+\catcode`@=11
+
+% We need to change some code if we're using LuaMetaTeX
+\def\lwc@iflmtx{\ifnum\luatexversion>200\relax}
+
+\input ltluatex % \LuaTeX{}Base
+
+\clubpenalty=1
+\widowpenalty=1
+\displaywidowpenalty=1
+\brokenpenalty=1
+
+\newdimen\lwcemergencystretch
+\lwcemergencystretch=3em
+
+\newdimen\lwcdraftoffset
+\lwcdraftoffset=1in
+
+\newcount\lwcmaxcost
+\lwcmaxcost=2147483647
+
+\directlua{require "lua-widow-control"}
+
+% Here, we enable font expansion/contraction. It isn't strictly necessary for
+% \lwc/'s functionality; however, it is required for the
+% lengthened paragraphs to not have terrible spacing.
+\lwc@iflmtx\else
+ \expandglyphsinfont\the\font 20 20 5
+ \adjustspacing=2
+\fi
+
+% Enable \lwc/ by default when the package is loaded.
+\lwc@enable
+
+% Fix some strange LMTX bugs
+\lwc@iflmtx
+ \normalizelinemode=\numexpression\normalizelinemode bor 2\relax
+\fi
+
+
+% Expansion of some parts of the document, such as section headings, is quite
+% undesirable, so we'll disable \lwc/ for certain commands.
+
+% We should only reenable \lwc/ at the end if it was already enabled.
+\newcount\lwc@disable@count
+
+\def\lwc@patch@pre{%
+ \lwc@if@enabled%
+ \advance\lwc@disable@count by 1%
+ \lwc@disable%
+ \fi%
+}
+
+\def\lwc@patch@post{
+ \ifnum\lwc@disable@count>0%
+ \lwc@enable%
+ \advance\lwc@disable@count by -1%
+ \fi
+}
+
+\def\lwc@extractcomponents #1:#2->#3\STOP{%
+ \def\lwc@params{#2}%
+ \def\lwc@body{#3}%
+}
+
+\def\lwcdisablecmd#1{%
+ \ifdefined#1%
+ \expandafter\lwc@extractcomponents\meaning#1\STOP%
+ \begingroup%
+ \catcode`@=11%
+ \expanded{%
+ \noexpand\scantokens{%
+ \gdef\noexpand#1\lwc@params{%
+ \noexpand\lwc@patch@pre\lwc@body\noexpand\lwc@patch@post%
+ }%
+ }%
+ }%
+ \endgroup%
+ \fi%
+}
+
+\begingroup
+ \lwc@iflmtx\else
+ \suppressoutererror=1
+ \fi
+ \lwcdisablecmd{\beginsection} % Sectioning
+\endgroup
+
+% Make the commands public
+\let\lwcenable=\lwc@enable
+\let\lwcdisable=\lwc@disable
+\let\lwcdebug=\lwc@debug
+\def\lwcdraft#1{%
+ \lwc@show@costs{#1}%
+ \lwc@show@colours{#1}%
+}
+\let\lwcshowcosts=\lwc@show@costs
+\let\lwcshowcolours=\lwc@show@colours
+\let\iflwc=\lwc@if@enabled
+\let\lwcnobreak=\lwc@nobreak
+\let\lwcpreshipout=\lwc@pre@shipout
+
+
+\catcode`@=12
+\endinput
diff --git a/macros/context/contrib/context-lua-widow-control/tex/optex/lua-widow-control/lua-widow-control.opm b/macros/context/contrib/context-lua-widow-control/tex/optex/lua-widow-control/lua-widow-control.opm
new file mode 100644
index 0000000000..fa2be77863
--- /dev/null
+++ b/macros/context/contrib/context-lua-widow-control/tex/optex/lua-widow-control/lua-widow-control.opm
@@ -0,0 +1,88 @@
+% lua-widow-control
+% https://github.com/gucci-on-fleek/lua-widow-control
+% SPDX-License-Identifier: MPL-2.0+
+% SPDX-FileCopyrightText: 2022 Max Chernoff
+
+\_codedecl\lwcenable{lua-widow-control <v3.0.0>} %%version
+\_namespace{lwc}
+
+\_clubpenalty=1
+\_widowpenalty=1
+\_displaywidowpenalty=1
+\_brokenpenalty=1
+
+\_newdimen\lwcemergencystretch
+\lwcemergencystretch=3em
+
+\_newdimen\lwcdraftoffset
+\lwcdraftoffset=1in
+
+\_newcount\lwcmaxcost
+\lwcmaxcost=2147483647
+
+\_directlua{require "lua-widow-control"}
+
+% Enable \lwc/ by default when the package is loaded.
+\.enable
+
+% Expansion of some parts of the document, such as section headings, is quite
+% undesirable, so we'll disable \lwc/ for certain commands.
+
+% We should only reenable \lwc/ at the end if it was already enabled.
+\_newcount\.disable_count
+
+\_def\.patch_pre{%
+ \.if_enabled%
+ \_advance\.disable_count by 1%
+ \.disable%
+ \_fi%
+}
+
+\_def\.patch_post{
+ \_ifnum\.disable_count>0%
+ \.enable%
+ \_advance\.disable_count by -1%
+ \_fi
+}
+
+\_def\.extractcomponents #1:#2->#3\STOP{%
+ \_def\.params{#2}%
+ \_def\.body{#3}%
+}
+
+\def\.disable_cmd#1{%
+ \_ifdefined#1%
+ \_ea\.extractcomponents\_meaning#1\STOP%
+ \_begingroup%
+ \_catcode`_=11%
+ \_expanded{%
+ \_noexpand\_scantokens{%
+ \_gdef\_noexpand#1\.params{%
+ \_noexpand\.patch_pre\.body\_noexpand\.patch_post%
+ }%
+ }%
+ }%
+ \_endgroup%
+ \_fi%
+}
+
+\.disable_cmd{\_printchap}
+\.disable_cmd{\_printsec}
+\.disable_cmd{\_printsecc}
+
+% Make the commands public
+\_let\lwcenable=\.enable
+\_let\lwcdisable=\.disable
+\_let\lwcdisablecmd=\.disable_cmd
+\_let\lwcdebug=\.debug
+\_def\lwcdraft#1{%
+ \.show_costs{#1}%
+ \.show_colours{#1}%
+}
+\_let\lwcshowcosts=\.show_costs
+\_let\lwcshowcolours=\.show_colours
+\_let\iflwc=\.if_enabled
+\_let\lwcnobreak=\.nobreak
+
+\_endnamespace
+\_endcode