summaryrefslogtreecommitdiff
path: root/macros/luatex/latex/luatodonotes/luatodonotes.lua
diff options
context:
space:
mode:
Diffstat (limited to 'macros/luatex/latex/luatodonotes/luatodonotes.lua')
-rw-r--r--macros/luatex/latex/luatodonotes/luatodonotes.lua59
1 files changed, 43 insertions, 16 deletions
diff --git a/macros/luatex/latex/luatodonotes/luatodonotes.lua b/macros/luatex/latex/luatodonotes/luatodonotes.lua
index 5ef9b8f03b..1926597ab9 100644
--- a/macros/luatex/latex/luatodonotes/luatodonotes.lua
+++ b/macros/luatex/latex/luatodonotes/luatodonotes.lua
@@ -1,5 +1,5 @@
--
--- Copyright (C) 2014-2015 by Fabian Lipp <fabian.lipp@gmx.de>
+-- Copyright (C) 2014-2020 by Fabian Lipp <fabian.lipp@gmx.de>
-- ------------------------------------------------------------
--
-- This file may be distributed and/or modified under the
@@ -374,8 +374,7 @@ function luatodonotes.linePositionsNextPage()
end
function luatodonotes.linePositionsAddLine(ycoord, lineheight, linedepth)
- local baseline = ycoord - tex.pageheight
- linePositionsCurPage[#linePositionsCurPage + 1] = {baseline, baseline + lineheight, baseline - linedepth}
+ linePositionsCurPage[#linePositionsCurPage + 1] = {ycoord, lineheight, linedepth}
end
@@ -741,7 +740,7 @@ function luatodonotes.callbackOutputLinePositions(head)
end
if foundGlyph then
- local w = node.new("whatsit", "write") -- 8/1
+ local w = node.new("whatsit", "write")
w.stream = lpoFileStream
local tokenlist = {
{12, 92, 0}, -- \
@@ -770,19 +769,31 @@ function luatodonotes.callbackOutputLinePositions(head)
{12, 110, 0}, -- n
{12, 123, 0} -- {
}
- t = token.create("@todonotes@pdflastypos")
- tokenlist[#tokenlist + 1] = t
- tokenlist[#tokenlist + 1] = {12, 125, 0}
- tokenlist[#tokenlist + 1] = {12, 123, 0}
+ local t = token.create("@todonotes@pdflastypos")
+ -- the token handling changed with newer LuaTeX versions
+ if tex.luatexversion > 81 then
+ tokenlist[#tokenlist + 1] = {0, t.tok}
+ else
+ tokenlist[#tokenlist + 1] = t
+ end
+ tokenlist[#tokenlist + 1] = {12, 125, 0} -- }
+ tokenlist[#tokenlist + 1] = {12, 123, 0} -- {
appendStrToTokenlist(tokenlist, tostring(head.height))
- tokenlist[#tokenlist + 1] = {12, 125, 0}
- tokenlist[#tokenlist + 1] = {12, 123, 0}
+ tokenlist[#tokenlist + 1] = {12, 125, 0} -- }
+ tokenlist[#tokenlist + 1] = {12, 123, 0} -- {
appendStrToTokenlist(tokenlist, tostring(head.depth))
- tokenlist[#tokenlist + 1] = {12, 125, 0}
+ tokenlist[#tokenlist + 1] = {12, 125, 0} -- }
w.data = tokenlist
head.head = node.insert_before(head.head,head.head,w)
- local w = node.new("whatsit", "pdf_save_pos") -- 8/23
+ -- the name of the whatsit node changed with newer LuaTeX versions
+ local whatsitName
+ if tex.luatexversion > 80 then
+ whatsitName = "save_pos"
+ else
+ whatsitName = "pdf_save_pos"
+ end
+ local w = node.new("whatsit", whatsitName)
head.head = node.insert_before(head.head,head.head,w)
end
end
@@ -1742,7 +1753,18 @@ end
local function posPoLeaders(notes, rightSide, avoidLines)
local linePositionsCurPage
if avoidLines then
- linePositionsCurPage = linePositions[currentPage] or {}
+ linePositionsCurPage = {}
+ -- use the current pageheight to convert coordinates:
+ -- savepos yields coordinates relativ to lower left corner of page,
+ -- while our tikzpicture is anchored at the upper left corner
+ for k, v in pairs(linePositions[currentPage] or {}) do
+ local baseline = v[1] - tex.pageheight
+ linePositionsCurPage[k] = {baseline, baseline + v[2], baseline - v[3]}
+ if todonotesDebug then
+ print("linePositionsAddLine, add: " .. v[1] .. ", pageheight: " .. tex.pageheight ..
+ ", result: " .. baseline)
+ end
+ end
end
-- number of slots on the whole page
@@ -1759,11 +1781,16 @@ local function posPoLeaders(notes, rightSide, avoidLines)
-- sort notes by inputY
table.sort(notes, compareNoteIndInputYDesc)
- -- draw slots
+ -- draw slots and line positions
if todonotesDebug then
for i = 1,totalNumSlots+1 do
local pos = area.top - (i-1) * rasterHeight
- tex.print("\\draw[blue,dashed] (0," .. pos .. "sp) -- +(21cm,0);")
+ tex.print("\\draw[blue,dashed] (0," .. pos .. "sp) -- +(21cm,0);")
+ end
+ for ind, v in pairs(linePositionsCurPage) do
+ local pos = v[1]
+ tex.print("\\draw[red,dashed] (0," .. pos .. "sp) -- +(21cm,0);")
+ tex.print("\\node[red] at (1cm," .. pos .. "sp) {" .. ind .. "};")
end
end
@@ -1870,7 +1897,7 @@ local function posPoLeaders(notes, rightSide, avoidLines)
if avoidLines then
leaderArmR = labelTopR - noteInnerSep - r:getHeight() / 2 -- east anchor
- -- find first line (from the top) which lower bound is below leaderArmR
+ -- find first line (from the top) whose lower bound is below leaderArmR
local lineBelowInd
for ind, v in pairs(linePositionsCurPage) do
if v[3] <= leaderArmR then