Debian Codegraph @

texmf-dist/tex/luatex/lua-widow-control/lua-widow-control.tex

raw
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 \wlog{lua-widow-control v3.0.1} %%version
7
8 \ifx\directlua\undefined
9 \errmessage{%
10 LuaTeX is required for this package.
11 Make sure to compile with `luatex'%
12 }
13 \fi
14
15 \catcode`@=11
16
17 % We need to change some code if we're using LuaMetaTeX
18 \def\lwc@iflmtx{\ifnum\luatexversion>200\relax}
19
20 \input ltluatex % \LuaTeX{}Base
21
22 \clubpenalty=1
23 \widowpenalty=1
24 \displaywidowpenalty=1
25 \brokenpenalty=1
26
27 \newdimen\lwcemergencystretch
28 \lwcemergencystretch=3em
29
30 \newdimen\lwcdraftoffset
31 \lwcdraftoffset=1in
32
33 \newcount\lwcmaxcost
34 \lwcmaxcost=2147483647
35
36 \directlua{require "lua-widow-control"}
37
38 % Here, we enable font expansion/contraction. It isn't strictly necessary for
39 % \lwc/'s functionality; however, it is required for the
40 % lengthened paragraphs to not have terrible spacing.
41 \lwc@iflmtx\else
42 \expandglyphsinfont\the\font 20 20 5
43 \adjustspacing=2
44 \fi
45
46 % Enable \lwc/ by default when the package is loaded.
47 \lwc@enable
48
49 % Fix some strange LMTX bugs
50 \lwc@iflmtx
51 \normalizelinemode=\numexpression\normalizelinemode bor 2\relax
52 \fi
53
54
55 % Expansion of some parts of the document, such as section headings, is quite
56 % undesirable, so we'll disable \lwc/ for certain commands.
57
58 % We should only reenable \lwc/ at the end if it was already enabled.
59 \newcount\lwc@disable@count
60
61 \def\lwc@patch@pre{%
62 \lwc@if@enabled%
63 \advance\lwc@disable@count by 1%
64 \lwc@disable%
65 \fi%
66 }
67
68 \def\lwc@patch@post{
69 \ifnum\lwc@disable@count>0%
70 \lwc@enable%
71 \advance\lwc@disable@count by -1%
72 \fi
73 }
74
75 \def\lwc@extractcomponents #1:#2->#3\STOP{%
76 \def\lwc@params{#2}%
77 \def\lwc@body{#3}%
78 }
79
80 \def\lwcdisablecmd#1{%
81 \ifdefined#1%
82 \expandafter\lwc@extractcomponents\meaning#1\STOP%
83 \begingroup%
84 \catcode`@=11%
85 \expanded{%
86 \noexpand\scantokens{%
87 \gdef\noexpand#1\lwc@params{%
88 \noexpand\lwc@patch@pre\lwc@body\noexpand\lwc@patch@post%
89 }%
90 }%
91 }%
92 \endgroup%
93 \fi%
94 }
95
96 \begingroup
97 \lwc@iflmtx\else
98 \suppressoutererror=1
99 \fi
100 \lwcdisablecmd{\beginsection} % Sectioning
101 \endgroup
102
103 % Make the commands public
104 \let\lwcenable=\lwc@enable
105 \let\lwcdisable=\lwc@disable
106 \let\lwcdebug=\lwc@debug
107 \def\lwcdraft#1{%
108 \lwc@show@costs{#1}%
109 \lwc@show@colours{#1}%
110 }
111 \let\lwcshowcosts=\lwc@show@costs
112 \let\lwcshowcolours=\lwc@show@colours
113 \let\iflwc=\lwc@if@enabled
114 \let\lwcnobreak=\lwc@nobreak
115 \let\lwcpreshipout=\lwc@pre@shipout
116
117
118 \catcode`@=12
119 \endinput