summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/luatex/lua-widow-control
diff options
context:
space:
mode:
Diffstat (limited to 'Master/texmf-dist/tex/luatex/lua-widow-control')
-rw-r--r--Master/texmf-dist/tex/luatex/lua-widow-control/lua-widow-control.lua31
-rw-r--r--Master/texmf-dist/tex/luatex/lua-widow-control/lua-widow-control.tex5
2 files changed, 22 insertions, 14 deletions
diff --git a/Master/texmf-dist/tex/luatex/lua-widow-control/lua-widow-control.lua b/Master/texmf-dist/tex/luatex/lua-widow-control/lua-widow-control.lua
index 5801feef129..be9cab16cb9 100644
--- a/Master/texmf-dist/tex/luatex/lua-widow-control/lua-widow-control.lua
+++ b/Master/texmf-dist/tex/luatex/lua-widow-control/lua-widow-control.lua
@@ -107,8 +107,8 @@ elseif plain or latex or optex then
debug_print("Plain/LaTeX")
luatexbase.provides_module {
name = lwc.name,
- date = "2022/03/07", --%%slashdate
- version = "2.0.0", --%%version
+ date = "2022/03/18", --%%slashdate
+ version = "2.0.1", --%%version
description = [[
This module provides a LuaTeX-based solution to prevent
@@ -182,7 +182,7 @@ local function register_callback(t)
with \LuaTeX{}base, \ConTeXt{} leaves some \LuaTeX{} callbacks unregistered
and unfrozen. Because of this, we need to register some callbacks at the
engine level. This is fragile though, because a future \ConTeXt{} update
- may decide to register one of these functions, in which case
+ may decide to register one of these functions, in which case
\lwc/ will crash with a cryptic error message.
]]
return {
@@ -225,7 +225,7 @@ end
function lwc.paragraph_cost(demerits, lines)
- return demerits / (2 * math.sqrt(lines))
+ return demerits / math.sqrt(lines)
end
@@ -299,14 +299,17 @@ function lwc.save_paragraphs(head)
return head
end
+
+local last_paragraph = 0
--- Tags the beginning and the end of each paragraph as it is added to the page.
---
--- We add an attribute to the first and last node of each paragraph. The ID is
--- some arbitrary number for \lwc/, and the value corresponds to the
--- paragraphs index, which is negated for the end of the paragraph.
function lwc.mark_paragraphs(head)
- set_attribute(head, attribute, #paragraphs)
- set_attribute(last(head), attribute, -1 * #paragraphs)
+ set_attribute(head, attribute, #paragraphs + (100 * pagenum()))
+ set_attribute(last(head), attribute, -1 * (#paragraphs + (100 * pagenum())))
+ last_paragraph = #paragraphs
return head
end
@@ -326,7 +329,7 @@ local function safe_last(head)
if ids[id] then
warning [[Circular node list detected!
-This should never happen. I'll try and
+This should never happen. I'll try and
recover, but your output may be corrupted.
(Internal Error)]]
prev.next = nil
@@ -385,7 +388,7 @@ function lwc.remove_widows(head)
#paragraphs >= 1 then
else
paragraphs = {}
- return head
+ return head_save
end
info("Widow/orphan detected. Attempting to remove.")
@@ -398,7 +401,9 @@ function lwc.remove_widows(head)
-- We find the current "best" replacement, then free the unused ones
for i, paragraph in pairs(paragraphs) do
- if paragraph.cost < best_cost and i <= #paragraphs - 1 then
+ if paragraph.cost < best_cost and
+ i ~= last_paragraph
+ then
-- Clear the old best paragraph
flush_list(paragraphs[paragraph_index].node)
paragraphs[paragraph_index].node = nil
@@ -421,7 +426,9 @@ function lwc.remove_widows(head)
")"
)
- if best_cost > tex.getcount(max_cost) then
+ if best_cost > tex.getcount(max_cost) or
+ paragraph_index == last_paragraph
+ then
-- If the best replacement is too bad, we can't do anything
warning("Widow/Orphan NOT removed on page " .. pagenum())
paragraphs = {}
@@ -488,7 +495,7 @@ function lwc.remove_widows(head)
debug_print("remove_widows", "found " .. value)
-- Insert the start of the replacement paragraph
- if value == paragraph_index then
+ if value == paragraph_index + (100 * pagenum()) then
debug_print("remove_widows", "replacement start")
safe_last(target_node) -- Remove any loops
@@ -497,7 +504,7 @@ function lwc.remove_widows(head)
end
-- Insert the end of the replacement paragraph
- if value == -1 * paragraph_index then
+ if value == -1 * (paragraph_index + (100 * pagenum())) then
debug_print("remove_widows", "replacement end")
safe_last(target_node).next = head.next
break
diff --git a/Master/texmf-dist/tex/luatex/lua-widow-control/lua-widow-control.tex b/Master/texmf-dist/tex/luatex/lua-widow-control/lua-widow-control.tex
index 7a75e52132f..6d4f0722e35 100644
--- a/Master/texmf-dist/tex/luatex/lua-widow-control/lua-widow-control.tex
+++ b/Master/texmf-dist/tex/luatex/lua-widow-control/lua-widow-control.tex
@@ -3,7 +3,7 @@
% SPDX-License-Identifier: MPL-2.0+
% SPDX-FileCopyrightText: 2022 Max Chernoff
-\wlog{lua-widow-control v2.0.0} %%version
+\wlog{lua-widow-control v2.0.1} %%version
\ifx\directlua\undefined
\errmessage{%
@@ -17,6 +17,7 @@
\clubpenalty=1
\widowpenalty=1
\displaywidowpenalty=1
+\brokenpenalty=1
\newdimen\lwcemergencystretch
\lwcemergencystretch=3em
@@ -28,7 +29,7 @@
% 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.
+% lengthened paragraphs to not have terrible spacing.
\expandglyphsinfont\the\font 20 20 5
\adjustspacing=2