%D \module %D [ file=t-lua-widow-control, %D version=1.1.0, %%version %D title=lua-widow-control, %D subtitle=\ConTeXt module for lua-widow-control, %D author=Max Chernoff, %D date=2021-11-08, %%date %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 \installnamespace{lwc} \installcommandhandler \????lwc {lwc} \????lwc \newdimen\lwcemergencystretch \appendtoks \lwcemergencystretch=\lwcparameter{emergencystretch} \to\everysetuplwc \appendtoks \doifelse{\lwcparameter{\c!state}}\v!start{ \ctxlua{lwc.enable_callbacks()} }{ \ctxlua{lwc.disable_callbacks()} } \to\everysetuplwc \define\iflwc{\ctxlua{lwc.if_lwc_enabled()}} \ctxloadluafile{lua-widow-control} \setuplwc[emergencystretch=3em, \c!state=\v!start] % We can't just set the penalties because they will be reset automatically % at \\starttext. \startsetups[*default] \clubpenalty=1 \widowpenalty=1 \displaywidowpenalty=0 \interlinepenalty=0 \brokenpenalty=0 \stopsetups \setups[*default] % 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. \newif\iflwc@should@reenable \define\lwc@patch@pre{\iflwc% \lwc@should@reenabletrue% \setuplwc[state=stop]% \fi} \define\lwc@patch@post{\iflwc@should@reenable% \setuplwc[state=start]% \fi} \prependtoks\lwc@patch@pre\to\everybeforesectionheadhandle % Sectioning \prependtoks\lwc@patch@post\to\everyaftersectionheadhandle \protect \stopmodule