| 1 |
% lua-widow-control |
| 2 |
% https://github.com/gucci-on-fleek/lua-widow-control |
| 3 |
% SPDX-License-Identifier: MPL-2.0+ |
| 4 |
% SPDX-FileCopyrightText: 2022 Max Chernoff |
| 5 |
|
| 6 |
\_codedecl\lwcenable{lua-widow-control <v3.0.1>} %%version |
| 7 |
\_namespace{lwc} |
| 8 |
|
| 9 |
\_clubpenalty=1 |
| 10 |
\_widowpenalty=1 |
| 11 |
\_displaywidowpenalty=1 |
| 12 |
\_brokenpenalty=1 |
| 13 |
|
| 14 |
\_newdimen\lwcemergencystretch |
| 15 |
\lwcemergencystretch=3em |
| 16 |
|
| 17 |
\_newdimen\lwcdraftoffset |
| 18 |
\lwcdraftoffset=1in |
| 19 |
|
| 20 |
\_newcount\lwcmaxcost |
| 21 |
\lwcmaxcost=2147483647 |
| 22 |
|
| 23 |
\_directlua{require "lua-widow-control"} |
| 24 |
|
| 25 |
% Enable \lwc/ by default when the package is loaded. |
| 26 |
\.enable |
| 27 |
|
| 28 |
% Expansion of some parts of the document, such as section headings, is quite |
| 29 |
% undesirable, so we'll disable \lwc/ for certain commands. |
| 30 |
|
| 31 |
% We should only reenable \lwc/ at the end if it was already enabled. |
| 32 |
\_newcount\.disable_count |
| 33 |
|
| 34 |
\_def\.patch_pre{% |
| 35 |
\.if_enabled% |
| 36 |
\_advance\.disable_count by 1% |
| 37 |
\.disable% |
| 38 |
\_fi% |
| 39 |
} |
| 40 |
|
| 41 |
\_def\.patch_post{ |
| 42 |
\_ifnum\.disable_count>0% |
| 43 |
\.enable% |
| 44 |
\_advance\.disable_count by -1% |
| 45 |
\_fi |
| 46 |
} |
| 47 |
|
| 48 |
\_def\.extractcomponents #1:#2->#3\STOP{% |
| 49 |
\_def\.params{#2}% |
| 50 |
\_def\.body{#3}% |
| 51 |
} |
| 52 |
|
| 53 |
\def\.disable_cmd#1{% |
| 54 |
\_ifdefined#1% |
| 55 |
\_ea\.extractcomponents\_meaning#1\STOP% |
| 56 |
\_begingroup% |
| 57 |
\_catcode`_=11% |
| 58 |
\_expanded{% |
| 59 |
\_noexpand\_scantokens{% |
| 60 |
\_gdef\_noexpand#1\.params{% |
| 61 |
\_noexpand\.patch_pre\.body\_noexpand\.patch_post% |
| 62 |
}% |
| 63 |
}% |
| 64 |
}% |
| 65 |
\_endgroup% |
| 66 |
\_fi% |
| 67 |
} |
| 68 |
|
| 69 |
\.disable_cmd{\_printchap} |
| 70 |
\.disable_cmd{\_printsec} |
| 71 |
\.disable_cmd{\_printsecc} |
| 72 |
|
| 73 |
% Make the commands public |
| 74 |
\_let\lwcenable=\.enable |
| 75 |
\_let\lwcdisable=\.disable |
| 76 |
\_let\lwcdisablecmd=\.disable_cmd |
| 77 |
\_let\lwcdebug=\.debug |
| 78 |
\_def\lwcdraft#1{% |
| 79 |
\.show_costs{#1}% |
| 80 |
\.show_colours{#1}% |
| 81 |
} |
| 82 |
\_let\lwcshowcosts=\.show_costs |
| 83 |
\_let\lwcshowcolours=\.show_colours |
| 84 |
\_let\iflwc=\.if_enabled |
| 85 |
\_let\lwcnobreak=\.nobreak |
| 86 |
|
| 87 |
\_endnamespace |
| 88 |
\_endcode |