Debian Codegraph @

texmf-dist/tex/lualatex/lua-widow-control/lua-widow-control-2022-02-22.sty

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 \NeedsTeXFormat{LaTeX2e}[2015/01/01] % Formats built after 2015 include \LuaTeX{}Base
7 \ProvidesPackage{lua-widow-control}%
8 [2022/02/22 v1.1.6]
9
10 % The version number above is somewhat-misleading: I will make bugfixes to this file
11 % from time to time, but the core of the file will not change. Therefore, we should
12 % report a real version number here for debugging.
13 \PackageInfo{lua-widow-control}{%
14 Real version:
15 2024/03/11 %%slashdate
16 v3.0.1 %%version
17 }
18
19 \PackageWarning{lua-widow-control}{%
20 Old LaTeX format detected!\MessageBreak\MessageBreak
21 Lua-widow-control prefers a LaTeX format\MessageBreak
22 newer than November 2020. I'll still run\MessageBreak
23 the latest Lua code, but I'm using an older\MessageBreak
24 version of the LaTeX code. This means that\MessageBreak
25 the key-value interface is *UNSUPPORTED*.\MessageBreak
26 }
27
28 \ifdefined\directlua\else
29 \PackageError{lua-widow-control}{%
30 LuaTeX is required for this package.\MessageBreak
31 Make sure to compile with `lualatex'%
32 }{}
33 \fi
34
35 \clubpenalty=1
36 \widowpenalty=1
37 \displaywidowpenalty=1
38
39 % We can't use \\newlength since that makes a \TeX{} "skip", not a "dimen"
40 \newdimen\lwcemergencystretch
41 \lwcemergencystretch=3em
42
43 \newcount\lwcmaxcost
44 \lwcmaxcost=2147483647
45
46 \directlua{require "lua-widow-control"}
47
48 % Here, we enable font expansion/contraction. It isn't strictly necessary for
49 % \lwc/'s functionality; however, it is required for the
50 % lengthened paragraphs to not have terrible spacing.
51 \RequirePackage{etoolbox}
52 \AtEndPreamble{
53 \@ifpackageloaded{microtype}{}{ % Only load if not already loaded
54 \RequirePackage[
55 final,
56 activate={true,nocompatibility}
57 ]{microtype}
58 }
59 }
60
61 % Define \TeX{} wrappers for Lua functions
62 \newcommand{\lwcenable}{\directlua{lwc.enable_callbacks()}}
63 \newcommand{\lwcdisable}{\directlua{lwc.disable_callbacks()}}
64 \newcommand{\iflwc}{\directlua{lwc.if_lwc_enabled()}}
65
66 % Enable \lwc/ by default when the package is loaded.
67 \lwcenable
68
69 % Expansion of some parts of the document, such as section headings, is quite
70 % undesirable, so we'll disable \lwc/ for certain commands.
71 \newcommand{\lwc@patch@warning}[1]{\PackageWarning{lua-widow-control}{%
72 Patching the \protect#1 command failed%
73 }}
74
75 % We should only reenable \lwc/ at the end if it was already enabled.
76 \newif\iflwc@should@reenable
77
78 \newcommand{\lwc@patch@pre}{%
79 \iflwc%
80 \lwc@should@reenabletrue%
81 \lwcdisable%
82 \else%
83 \lwc@should@reenablefalse%
84 \fi%
85 }
86
87 \newcommand{\lwc@patch@post}{%
88 \iflwc@should@reenable%
89 \lwcenable%
90 \fi%
91 }
92
93 \newcommand{\lwcdisablecmd}[1]{%
94 \ifdefined#1
95 \pretocmd{#1}{\lwc@patch@pre}{}{\lwc@patch@warning{#1}}%
96 \apptocmd{#1}{\lwc@patch@post}{}{\lwc@patch@warning{#1}}%
97 \fi
98 }
99
100 \lwcdisablecmd{\@sect} % Sectioning
101
102
103 \endinput