% lua-widow-control
% https://github.com/gucci-on-fleek/lua-widow-control
% SPDX-License-Identifier: MPL-2.0+
% SPDX-FileCopyrightText: 2021 gucci-on-fleek

\NeedsTeXFormat{LaTeX2e}[2015/01/01] % Formats built after 2015 include \LuaTeX{}Base
\ProvidesPackage{lua-widow-control}%
    [2021/10/09 v1.0.0] %%version %%date

\setlength{\clubpenalty}{1}
\setlength{\widowpenalty}{1}
\setlength{\displaywidowpenalty}{0}
\setlength{\interlinepenalty}{0}
\setlength{\brokenpenalty}{0}

% We can't use \\newlength since that makes a \TeX{} "skip", not a "dimen"
\newdimen\lwcemergencystretch
\setlength{\lwcemergencystretch}{3em}

\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[final]{microtype}

\newcommand{\lwcenable}{\directlua{lwc.enable_callbacks()}}
\newcommand{\lwcdisable}{\directlua{lwc.disable_callbacks()}}

% Enable \lwc/ by default when the package is loaded.
\lwcenable

\endinput
