diff options
author | Karl Berry <karl@freefriends.org> | 2022-03-08 21:26:08 +0000 |
---|---|---|
committer | Karl Berry <karl@freefriends.org> | 2022-03-08 21:26:08 +0000 |
commit | 9eb4d1f8b8e3f67cd2757a3879166dcb035ddb49 (patch) | |
tree | e298b53cf6ff3f9b8a8b8f4ab1222702af2e2d6b /Master/texmf-dist/tex/lualatex/lua-widow-control/lua-widow-control-2022-02-22.sty | |
parent | 9dc2bd4e59906fc0b4f24a6d2c4e5accb80c9649 (diff) |
lua-widow-control (8mar22) (branch)
git-svn-id: svn://tug.org/texlive/branches/branch2021.final@62526 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/tex/lualatex/lua-widow-control/lua-widow-control-2022-02-22.sty')
-rw-r--r-- | Master/texmf-dist/tex/lualatex/lua-widow-control/lua-widow-control-2022-02-22.sty | 94 |
1 files changed, 94 insertions, 0 deletions
diff --git a/Master/texmf-dist/tex/lualatex/lua-widow-control/lua-widow-control-2022-02-22.sty b/Master/texmf-dist/tex/lualatex/lua-widow-control/lua-widow-control-2022-02-22.sty new file mode 100644 index 00000000000..783db59ed22 --- /dev/null +++ b/Master/texmf-dist/tex/lualatex/lua-widow-control/lua-widow-control-2022-02-22.sty @@ -0,0 +1,94 @@ +% lua-widow-control +% https://github.com/gucci-on-fleek/lua-widow-control +% SPDX-License-Identifier: MPL-2.0+ +% SPDX-FileCopyrightText: 2022 Max Chernoff + +\NeedsTeXFormat{LaTeX2e}[2015/01/01] % Formats built after 2015 include \LuaTeX{}Base +\ProvidesPackage{lua-widow-control}% + [2022/02/22 v1.1.6] + +\PackageWarning{lua-widow-control}{% + Old LaTeX format detected!\MessageBreak\MessageBreak + Lua-widow-control prefers a LaTeX format\MessageBreak + newer than November 2020. I'll still run\MessageBreak + the latest Lua code, but I'm using an older\MessageBreak + version of the LaTeX code. This means that\MessageBreak + the key-value interface is *UNSUPPORTED*.\MessageBreak +} + +\ifdefined\directlua\else + \PackageError{lua-widow-control}{% + LuaTeX is required for this package.\MessageBreak + Make sure to compile with `lualatex'% + }{} +\fi + +\clubpenalty=1 +\widowpenalty=1 +\displaywidowpenalty=1 + +% We can't use \\newlength since that makes a \TeX{} "skip", not a "dimen" +\newdimen\lwcemergencystretch +\lwcemergencystretch=3em + +\newcount\lwcmaxcost +\lwcmaxcost=2147483647 + +\directlua{require "lua-widow-control"} + +% 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. +\RequirePackage{etoolbox} +\AtEndPreamble{ + \@ifpackageloaded{microtype}{}{ % Only load if not already loaded + \RequirePackage[ + final, + activate={true,nocompatibility} + ]{microtype} + } +} + +% Define \TeX{} wrappers for Lua functions +\newcommand{\lwcenable}{\directlua{lwc.enable_callbacks()}} +\newcommand{\lwcdisable}{\directlua{lwc.disable_callbacks()}} +\newcommand{\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. +\newcommand{\lwc@patch@warning}[1]{\PackageWarning{lua-widow-control}{% + Patching the \protect#1 command failed% +}} + +% We should only reenable \lwc/ at the end if it was already enabled. +\newif\iflwc@should@reenable + +\newcommand{\lwc@patch@pre}{% + \iflwc% + \lwc@should@reenabletrue% + \lwcdisable% + \else% + \lwc@should@reenablefalse% + \fi% +} + +\newcommand{\lwc@patch@post}{% + \iflwc@should@reenable% + \lwcenable% + \fi% +} + +\newcommand{\lwcdisablecmd}[1]{% + \ifdefined#1 + \pretocmd{#1}{\lwc@patch@pre}{}{\lwc@patch@warning{#1}}% + \apptocmd{#1}{\lwc@patch@post}{}{\lwc@patch@warning{#1}}% + \fi +} + +\lwcdisablecmd{\@sect} % Sectioning + + +\endinput |