summaryrefslogtreecommitdiff
path: root/macros/luatex/generic/lua-widow-control/lua-widow-control.opm
diff options
context:
space:
mode:
Diffstat (limited to 'macros/luatex/generic/lua-widow-control/lua-widow-control.opm')
-rw-r--r--macros/luatex/generic/lua-widow-control/lua-widow-control.opm61
1 files changed, 56 insertions, 5 deletions
diff --git a/macros/luatex/generic/lua-widow-control/lua-widow-control.opm b/macros/luatex/generic/lua-widow-control/lua-widow-control.opm
index 6ff6281583..d96bab6c02 100644
--- a/macros/luatex/generic/lua-widow-control/lua-widow-control.opm
+++ b/macros/luatex/generic/lua-widow-control/lua-widow-control.opm
@@ -3,7 +3,8 @@
% SPDX-License-Identifier: MPL-2.0+
% SPDX-FileCopyrightText: 2022 Max Chernoff
-\_codedecl\lwcenable{lua-widow-control <v2.0.4>} %%version
+\_codedecl\lwcenable{lua-widow-control <v2.0.5>} %%version
+\_namespace{lwc}
\_clubpenalty=1
\_widowpenalty=1
@@ -19,11 +20,61 @@
\_directlua{require "lua-widow-control"}
% Define \TeX{} wrappers for Lua functions
-\_def\lwcenable{\_directlua{lwc.enable_callbacks()}}
-\_def\lwcdisable{\_directlua{lwc.disable_callbacks()}}
-\_def\iflwc{\_directlua{lwc.if_lwc_enabled()}}
+\_def\.enable{\_directlua{lwc.enable_callbacks()}}
+\_def\.disable{\_directlua{lwc.disable_callbacks()}}
+\_def\.iflwc{\_directlua{lwc.if_lwc_enabled()}}
+
+\_let\lwcenable=\.enable
+\_let\lwcdisable=\.disable
% Enable \lwc/ by default when the package is loaded.
-\lwcenable
+\.enable
+
+% 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.
+\_newcount\.disable_count
+
+\_def\.patch_pre{%
+ \.iflwc%
+ \_advance\.disable_count by 1%
+ \.disable%
+ \_fi%
+}
+
+\_def\.patch_post{
+ \_ifnum\.disable_count>0%
+ \.enable%
+ \_advance\.disable_count by -1%
+ \_fi
+}
+
+\_def\.extractcomponents #1:#2->#3\STOP{%
+ \_def\.params{#2}%
+ \_def\.body{#3}%
+}
+
+\def\.disable_cmd#1{%
+ \_ifdefined#1%
+ \_ea\.extractcomponents\_meaning#1\STOP%
+ \_begingroup%
+ \_catcode`_=11%
+ \_expanded{%
+ \_noexpand\_scantokens{%
+ \_gdef\_noexpand#1\.params{%
+ \_noexpand\.patch_pre\.body\_noexpand\.patch_post%
+ }%
+ }%
+ }%
+ \_endgroup%
+ \_fi%
+}
+\_let\lwcdisablecmd=\.disable_cmd
+
+\.disable_cmd{\_printchap}
+\.disable_cmd{\_printsec}
+\.disable_cmd{\_printsecc}
+\_endnamespace
\_endcode