summaryrefslogtreecommitdiff
path: root/macros/luatex/generic/lua-widow-control/lua-widow-control.tex
diff options
context:
space:
mode:
Diffstat (limited to 'macros/luatex/generic/lua-widow-control/lua-widow-control.tex')
-rw-r--r--macros/luatex/generic/lua-widow-control/lua-widow-control.tex34
1 files changed, 32 insertions, 2 deletions
diff --git a/macros/luatex/generic/lua-widow-control/lua-widow-control.tex b/macros/luatex/generic/lua-widow-control/lua-widow-control.tex
index fc10ff0ebb..904ee03c69 100644
--- a/macros/luatex/generic/lua-widow-control/lua-widow-control.tex
+++ b/macros/luatex/generic/lua-widow-control/lua-widow-control.tex
@@ -1,9 +1,9 @@
% lua-widow-control
% https://github.com/gucci-on-fleek/lua-widow-control
% SPDX-License-Identifier: MPL-2.0+
-% SPDX-FileCopyrightText: 2021 gucci-on-fleek
+% SPDX-FileCopyrightText: 2021 Max Chernoff
-\wlog{lua-widow-control v1.0.0} %%version
+\wlog{lua-widow-control v1.1.0} %%version
\input ltluatex % \LuaTeX{}Base
@@ -24,10 +24,40 @@
\expandglyphsinfont\the\font 20 20 5
\adjustspacing=2
+% 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()}}
% Enable \lwc/ by default when the package is loaded.
\lwcenable
+% Expansion of some parts of the document, such as section headings, is quite
+% undesirable, so we'll disable \lwc/ for certain commands.
+\catcode`@=11
+
+% We should only reenable \lwc/ at the end if it was already enabled.
+\newif\iflwc@should@reenable
+
+\def\lwc@patch@pre{\iflwc%
+ \lwc@should@reenabletrue%
+ \lwcdisable%
+\fi}
+
+\def\lwc@patch@post{\iflwc@should@reenable%
+ \lwcenable%
+\fi}
+
+\def\lwcdisablecmd#1{%
+ \ifdefined#1
+ \expandafter\def\expandafter#1\expandafter{\lwc@patch@pre #1\lwc@patch@post}
+ \fi
+}
+\catcode`@=12
+
+\begingroup
+ \suppressoutererror=1
+ \lwcdisablecmd{\beginsection} % Sectioning
+\endgroup
+
\endinput