How gucci-on-fleek/lua-widow-control works
Purpose and entry points
lua-widow-control is a LuaTeX package for Plain TeX, LaTeX, ConTeXt, and OpTeX. It automatically removes widows and orphans by making affected paragraphs longer, rather than stretching glue or reducing page/column length. User-facing loaders are format-specific wrappers: source/lua-widow-control.sty, source/t-lua-widow-control.mkxl, source/lua-widow-control.tex, and source/lua-widow-control.opm.
Core Lua engine
The format-independent implementation is source/lua-widow-control.lua. It runs inside the LuaTeX/LuaMetaTeX node-processing and line-breaking environment, examines pagination outcomes, and alters paragraph-breaking behavior when a page or column would leave an orphan or widow. The TeX wrappers provide the engine with macro-level integration points rather than duplicating the algorithm.
Format adaptation boundary
Each supported macro format has its own entry module and installation location:
• LaTeX: source/lua-widow-control.sty, including compatibility release source/lua-widow-control-2022-02-22.sty
• ConTeXt: source/t-lua-widow-control.mkxl
• Plain TeX: source/lua-widow-control.tex
• OpTeX: source/lua-widow-control.opm
These files isolate format conventions, option/interface syntax, and callback setup from the shared Lua logic.
Runtime and distribution
The required runtime is LuaTeX-family engines; tests explicitly cover LuaMetaTeX variants. The installable TDS tree mirrors source files into TeX search paths: texmf/tex/luatex/lua-widow-control/lua-widow-control.lua, texmf/tex/lualatex/lua-widow-control/lua-widow-control.sty, and texmf/tex/context/third/lua-widow-control/t-lua-widow-control.mkxl. The package is distributed through TeX Live/MiKTeX and external package channels referenced by the README (CTAN and ConTeXt Garden).
Build, documentation, and release artifacts
build.lua is the repository-level build entry point, producing package/distribution material. Source documentation includes the manual at docs/manual/lwc-manual.tex and background articles such as docs/articles/tb133chernoff-widows.ltx. Compiled deliverables are staged in the TDS doc tree, notably texmf/doc/luatex/lua-widow-control/lua-widow-control.pdf.
Verification flow
The test suite compiles fixture documents through format-specific suites, validating output behavior across LaTeX, ConTeXt, Plain TeX, and OpTeX: tests/latex/build.lua, tests/context/build.lua, and tests/plain/build.lua. Cases cover normal documents plus structural pressure points—columns, headings, footnotes, grids, floats, and draft modes—where pagination intervention is consequential. Shared test configuration and transformation support reside in tests/test-config.lua and tests/transform.xslt.
Primary flow
A document loads a format wrapper, which loads/configures the Lua engine. During typesetting, the engine observes paragraph/page or column breaking through LuaTeX facilities, detects potential widow/orphan layouts, and requests an alternate paragraph length/breaking result. The resulting node list returns to the host TeX engine for normal page construction and PDF output. The main boundary is therefore TeX macro setup → Lua node/line-break control → TeX pagination.
Main entry points: lua-widow-control.lua Widow control engine · build.lua Build entry point · test-config.lua Shared test support · lua-widow-control.sty LaTeX loader
Components 20
Format adapters
Format-specific macro integration and callback setup.
- LaTeX loader
source/lua-widow-control.sty - LaTeX compatibility loader · Compatibility release for older LaTeX environments.
source/lua-widow-control-2022-02-22.sty - ConTeXt loader
source/t-lua-widow-control.mkxl - Plain TeX loader
source/lua-widow-control.tex - OpTeX loader
source/lua-widow-control.opm
Verification
Cross-format fixture compilation and output checks.
- Shared test support · Shared test configuration and output transformation support.
tests/test-config.lua - LaTeX test suite · Exercises normal and pagination-pressure cases.
tests/latex/build.lua - ConTeXt test suite
tests/context/build.lua - Plain/OpTeX test suite
tests/plain/build.lua
Build and distribution
Package assembly, documentation, and installable TDS artifacts.
- Build entry point · Builds package and distribution material.
build.lua - Package manual
docs/manual/lwc-manual.tex - Background article
docs/articles/tb133chernoff-widows.ltx - Installed runtime tree · Engine and format loaders installed in TeX search paths.
texmf/tex/luatex/lua-widow-control/lua-widow-control.lua - Installed LaTeX loader
texmf/tex/lualatex/lua-widow-control/lua-widow-control.sty - Installed ConTeXt loader
texmf/tex/context/third/lua-widow-control/t-lua-widow-control.mkxl - Compiled manual
texmf/doc/luatex/lua-widow-control/lua-widow-control.pdf
Other components
- TeX document
- Widow control engine · Detects widow/orphan outcomes and changes paragraph breaking.
source/lua-widow-control.lua - LuaTeX-family runtime · LuaTeX/LuaMetaTeX node, line-breaking, and pagination facilities.
- Paginated PDF output
Connections 22
- TeX document → LaTeX loader: loads
- TeX document → ConTeXt loader: loads
- TeX document → Plain TeX loader: loads
- TeX document → OpTeX loader: loads
- LaTeX compatibility loader → Widow control engine: configures
- LaTeX loader → Widow control engine: loads and configures
- ConTeXt loader → Widow control engine: loads and configures
- Plain TeX loader → Widow control engine: loads and configures
- OpTeX loader → Widow control engine: loads and configures
- Widow control engine → LuaTeX-family runtime: controls node breaking
- LuaTeX-family runtime → Paginated PDF output: constructs pages
- Build entry point → Installed runtime tree: stages
- Build entry point → Installed LaTeX loader: stages
- Build entry point → Installed ConTeXt loader: stages
- Build entry point → Compiled manual: produces
- Package manual → Compiled manual: compiled into
- Shared test support → LaTeX test suite: supports
- Shared test support → ConTeXt test suite: supports
- Shared test support → Plain/OpTeX test suite: supports
- LaTeX test suite → LuaTeX-family runtime: compiles with
- ConTeXt test suite → LuaTeX-family runtime: compiles with
- Plain/OpTeX test suite → LuaTeX-family runtime: compiles with