summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/luatex
diff options
context:
space:
mode:
authorKarl Berry <karl@freefriends.org>2022-02-16 22:45:21 +0000
committerKarl Berry <karl@freefriends.org>2022-02-16 22:45:21 +0000
commit9a2e259625722487a887ac1c24e4aaec11e718fe (patch)
treea16e76927917d86381655c60cc32b217267a151f /Master/texmf-dist/tex/luatex
parent28da595db46ec1bef5fdb9a83d37bc5d9b98db76 (diff)
lua-widow-control (15feb22)
git-svn-id: svn://tug.org/texlive/trunk@62050 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/tex/luatex')
-rw-r--r--Master/texmf-dist/tex/luatex/lua-widow-control/lua-widow-control.lua46
-rw-r--r--Master/texmf-dist/tex/luatex/lua-widow-control/lua-widow-control.tex9
2 files changed, 38 insertions, 17 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 9a8b2efa781..9304bf9a4d1 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
@@ -59,14 +59,16 @@ assert(lwc.context or luatexbase, [[
]]
if lwc.context then
lwc.warning = logs.reporter("module", lwc.name)
+ lwc.info = logs.reporter("module", lwc.name)
lwc.attribute = attributes.public(lwc.name)
lwc.contrib_head = 'contributehead' -- For \LuaMetaTeX{}
lwc.stretch_order = "stretchorder"
+ lwc.pagenum = function () return tex.count["realpageno"] end
elseif lwc.plain or lwc.latex then
luatexbase.provides_module {
name = lwc.name,
- date = "2022/02/04", --%%date
- version = "1.1.4", --%%version
+ date = "2022/02/15", --%%date
+ version = "1.1.5", --%%version
description = [[
This module provides a LuaTeX-based solution to prevent
@@ -76,9 +78,11 @@ elseif lwc.plain or lwc.latex then
]],
}
lwc.warning = function(str) luatexbase.module_warning(lwc.name, str) end
+ lwc.info = function(str) luatexbase.module_info(lwc.name, str) end
lwc.attribute = luatexbase.new_attribute(lwc.name)
lwc.contrib_head = 'contrib_head' -- For \LuaTeX{}
lwc.stretch_order = "stretch_order"
+ lwc.pagenum = function () return tex.count[0] end
else -- uh oh
error [[
Unsupported format.
@@ -222,20 +226,28 @@ end
---
--- Sometimes the node list can form a loop. Since there is no last element
--- of a looped linked-list, the `last()` function will never terminate. This
---- function provides a "safe" version of the `last()` function that returns
---- `nil` if the list is circular.
+--- function provides a "safe" version of the `last()` function that will break
+--- the loop at the end if the list is circular.
local function safe_last(head)
local ids = {}
+ local prev
while head.next do
local id = node.is_node(head) -- Returns the internal node id
if ids[id] then
- lwc.warning("Circular node list detected!")
- return nil
+ lwc.warning [[Circular node list detected!
+This should never happen. I'll try and recover, but your output may be
+corrupted. As a workaround, disable lua-widow-control for the
+affected paragraph or change the page breaks in your document.]]
+
+ prev.next = nil
+ return prev
end
ids[id] = true
+ head.prev = prev
+ prev = head
head = head.next
end
@@ -265,6 +277,8 @@ function lwc.remove_widows(head)
return head
end
+ lwc.info("Widow/orphan detected. Attempting to remove.")
+
local head_save = head -- Save the start of the `head` linked-list
--[[
@@ -296,22 +310,15 @@ function lwc.remove_widows(head)
while head do
-- Insert the start of the replacement paragraph
if has_attribute(head, lwc.attribute, paragraph_index) then
- local current = head
- head.prev.next = target_node
-
- -- Abort if we've created a loop
- if not safe_last(target_node) then
- head.prev.next = current
- lwc.warning("Widow/Orphan NOT removed!")
- break
- end
+ safe_last(target_node) -- Remove any loops
+ head.prev.next = target_node
clear_flag = true
end
-- Insert the end of the replacement paragraph
if has_attribute(head, lwc.attribute, -1 * paragraph_index) then
- last(target_node).next = head.next
+ safe_last(target_node).next = head.next
clear_flag = false
end
@@ -324,6 +331,13 @@ function lwc.remove_widows(head)
last(head).prev.prev.next = nil
-- Move the last line to the next page
tex.lists[lwc.contrib_head] = last_line
+ lwc.info(
+ "Widow/orphan successfully removed at paragraph "
+ .. paragraph_index
+ .. " on page "
+ .. lwc.pagenum()
+ .. "."
+ )
end
if clear_flag then
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 a9b236f966b..efab23b8b4b 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,14 @@
% SPDX-License-Identifier: MPL-2.0+
% SPDX-FileCopyrightText: 2021 Max Chernoff
-\wlog{lua-widow-control v1.1.4} %%version
+\wlog{lua-widow-control v1.1.5} %%version
+
+\ifx\directlua\undefined
+ \errmessage{%
+ LuaTeX is required for this package.
+ Make sure to compile with `luatex'%
+ }
+\fi
\input ltluatex % \LuaTeX{}Base