Skip to content

Commit

Permalink
Add support for footnotes in LMTX
Browse files Browse the repository at this point in the history
See #38
  • Loading branch information
gucci-on-fleek committed Aug 16, 2022
1 parent e557da4 commit 2bca909
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 12 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,12 @@ All notable changes to lua-widow-control will be listed here, in reverse chronol

## Unreleased

- Add support for inserts/footnotes in LuaMetaTeX ([#38](https://github.com/gucci-on-fleek/lua-widow-control/issues/38)).

- Use the built-in LaTeX key–value interface where available.

This means that lua-widow-control now also reads the global class options.

- Add support for split footnotes ([#37](https://github.com/gucci-on-fleek/lua-widow-control/issues/37)).

## [v2.2.1 (2022-07-28)](https://github.com/gucci-on-fleek/lua-widow-control/releases/tag/release-45c3146d5fc5a86606a931212395a28ffb48f925)
Expand Down
27 changes: 16 additions & 11 deletions source/lua-widow-control.lua
Original file line number Diff line number Diff line change
Expand Up @@ -640,6 +640,14 @@ local function mark_inserts(head)
then
local hlist_before = next_of_type(insert, hlist_id, { reverse = true} )

local insert_class
if lmtx then
-- FIXME: temporarily hardcode the main "footnote" class
insert_class = 4 -- insert.index
else
insert_class = insert.subtype
end

--[[ We tag the first element of the hlist/line with an integer
that holds the insert class and the first and last indices
of the inserts contained in the line. This won't work if
Expand All @@ -649,7 +657,7 @@ local function mark_inserts(head)
set_attribute(
hlist_before.list,
insert_attribute,
insert.subtype * INSERT_CLASS_MULTIPLE +
insert_class * INSERT_CLASS_MULTIPLE +
insert_indices[1] * INSERT_FIRST_MULTIPLE +
insert_indices[#insert_indices]
)
Expand Down Expand Up @@ -848,22 +856,19 @@ local function get_inserts(last_line)
break
end

--[[ With LuaMetaTeX, the subtype of `insert` nodes is always zero,
so we cannot detect their class therefore we can't fix any moved
footnotes.
]]
if lmtx then
warning("!!!Incorrect footnotes on page " .. pagenum() .. "!!!")
return {}
end

-- Demux the insert values
local class = line_value // INSERT_CLASS_MULTIPLE
local first_index = (line_value % INSERT_CLASS_MULTIPLE) // INSERT_FIRST_MULTIPLE
local last_index = line_value % INSERT_FIRST_MULTIPLE

-- Get the output box containing the insert boxes
local insert_box = tex_box[class]
local insert_box

if lmtx then
insert_box = tex.getinsertcontent(class)
else
insert_box = tex_box[class]
end

-- Get any portions of the insert held over until the next page
local split_insert = next_of_type(
Expand Down
2 changes: 1 addition & 1 deletion tests/context/footnotes.tltext

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 2bca909

Please sign in to comment.