diff options
Diffstat (limited to 'macros/luatex/generic/lua-widow-control/lua-widow-control.lua')
-rw-r--r-- | macros/luatex/generic/lua-widow-control/lua-widow-control.lua | 28 |
1 files changed, 25 insertions, 3 deletions
diff --git a/macros/luatex/generic/lua-widow-control/lua-widow-control.lua b/macros/luatex/generic/lua-widow-control/lua-widow-control.lua index 45360db209..2af5575799 100644 --- a/macros/luatex/generic/lua-widow-control/lua-widow-control.lua +++ b/macros/luatex/generic/lua-widow-control/lua-widow-control.lua @@ -62,9 +62,9 @@ if format:find("cont") then -- cont-en, cont-fr, cont-nl, ... end elseif format:find("latex") then -- lualatex, lualatex-dev, ... latex = true -elseif format == "luatex" then -- Plain +elseif format == "luatex" or format == "luahbtex" then -- Plain plain = true -elseif format == "optex" then -- OpTeX +elseif format:find("optex") then -- OpTeX optex = true end @@ -83,6 +83,7 @@ local par_id = node.id("par") or node.id("local_par") local penalty_id = node.id("penalty") -- Local versions of globals +local abs = math.abs local copy = node.copy_list or node.copylist local find_attribute = node.find_attribute or node.findattribute local flush_list = node.flush_list or node.flushlist @@ -96,6 +97,7 @@ local set_attribute = node.set_attribute or node.setattribute local string_char = string.char local traverse = node.traverse local traverseid = node.traverse_id or node.traverseid +local vpack = node.vpack -- Misc. Constants local iffalse = token.create("iffalse") @@ -160,7 +162,7 @@ elseif plain or latex or optex then luatexbase.provides_module { name = lwc.name, date = "2022/05/14", --%%dashdate - version = "2.1.0", --%%version + version = "2.1.1", --%%version description = [[ This module provides a LuaTeX-based solution to prevent @@ -502,6 +504,9 @@ function lwc.remove_widows(head) info("Widow/orphan/broken hyphen detected. Attempting to remove") + local vsize = tex.dimen.vsize + local orig_height_diff = vpack(head).height - vsize + --[[ Find the paragraph on the page with the least cost. ]] @@ -698,6 +703,23 @@ function lwc.remove_widows(head) end end + local new_height_diff = vpack(head_save).height - vsize + -- We need the original height discrepancy in case there are \\vfill's + local net_height_diff = orig_height_diff - new_height_diff + + --[[ The final \\box255 needs to be exactly \\vsize tall to avoid + over/underfull box warnings, so we correct any discrepancies + here. + ]] + if abs(net_height_diff) > 0 and + -- A difference larger than 0.25\\baselineskip is probably not from \lwc/ + abs(net_height_diff) < tex.skip.baselineskip.width / 4 + then + local bottom_glue = new_node("glue") + bottom_glue.width = net_height_diff + last(head_save).next = bottom_glue + end + info( "Widow/orphan/broken hyphen successfully removed at paragraph " .. paragraph_index |