blob: 66eeadec579e6ba458df4856d6b4e874afb4b6d3 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
|
%D \module
%D [ file=t-lua-widow-control,
%D version=1.0.0, %%version
%D title=lua-widow-control,
%D subtitle=\ConTeXt module for lua-widow-control,
%D author=gucci-on-fleek,
%D date=2021-10-09, %%date
%D copyright=gucci-on-fleek,
%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
\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]
\protect
\stopmodule
|