summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/lualatex/luatodonotes/luatodonotes.lua
diff options
context:
space:
mode:
Diffstat (limited to 'Master/texmf-dist/tex/lualatex/luatodonotes/luatodonotes.lua')
-rw-r--r--Master/texmf-dist/tex/lualatex/luatodonotes/luatodonotes.lua114
1 files changed, 67 insertions, 47 deletions
diff --git a/Master/texmf-dist/tex/lualatex/luatodonotes/luatodonotes.lua b/Master/texmf-dist/tex/lualatex/luatodonotes/luatodonotes.lua
index f84fc9415de..5ef9b8f03bc 100644
--- a/Master/texmf-dist/tex/lualatex/luatodonotes/luatodonotes.lua
+++ b/Master/texmf-dist/tex/lualatex/luatodonotes/luatodonotes.lua
@@ -91,6 +91,8 @@ end
-- stores the notes for the current page
luatodonotes.notesForPage = {}
local notesForPage = luatodonotes.notesForPage
+luatodonotes.notesForNextPage = {}
+local notesForNextPage = luatodonotes.notesForNextPage
-- Fields for each note:
-- index: numbers notes in whole document
-- indexOnPage: index of the note in the notesForPage array
@@ -106,6 +108,7 @@ local notesForPage = luatodonotes.notesForPage
-- otherwise left side is meant
-- fontsize: fontsize used for paragraph in that the note was defined
-- baselineskip: \baselineskip in the paragraph in that the note was defined
+-- normalbaselineskip: \normalbaselineskip in the paragraph in that the note was defined
-- outputX, outputY: position on which the north west anchor of the note should
-- be placed
-- lineColor: color of line connecting note to text
@@ -311,8 +314,8 @@ end
-- valid values for noteType: nil/"" (for point in text), "area"
function luatodonotes.addNoteToList(index, drawLeader, noteType)
if next(notesForPage) ~= nil
- and index == notesForPage[#notesForPage].index then
- -- Index is the same as for the previous note.
+ and index <= notesForPage[#notesForPage].index then
+ -- Index is the same as for one of the previous note.
-- This can happen when commands are read multiple times
-- => don't add anything to list in this case
return
@@ -321,6 +324,7 @@ function luatodonotes.addNoteToList(index, drawLeader, noteType)
newNote.index = index
newNote.textbox = node.copy_list(tex.box["@todonotes@notetextbox"])
newNote.baselineskip = tex.dimen["@todonotes@baselineskip"]
+ newNote.normalbaselineskip = tex.dimen["@todonotes@normalbaselineskip"]
newNote.fontsize = tex.dimen["@todonotes@fontsize"]
newNote.lineColor = tex.toks["@todonotes@toks@currentlinecolor"]
newNote.backgroundColor = tex.toks["@todonotes@toks@currentbackgroundcolor"]
@@ -495,20 +499,34 @@ end
local inputShiftX = string.todimen("-0.05cm") -- sensible value depends on shape of mark
function luatodonotes.printNotes()
- print("drawing labels for page " .. currentPage)
+ print("Drawing notes for page " .. currentPage)
-- seperate notes that should be placed on another page
-- This can occur when note is in a paragraph which doesn't fit on the
-- current page and is thus moved to the next one. But the \todo-command is
-- still read before the shipout of the current page is done
- notesForNextPage = {}
+ luatodonotes.notesForNextPage = {}
+ notesForNextPage = luatodonotes.notesForNextPage
local k=1
while k <= #notesForPage do
local v = notesForPage[k]
- if v.pageNr ~= currentPage then
+ if v.pageNr == 0 then
+ -- Notes without a page number occur when the zref label is not
+ -- defined correctly. This happens with notes in a
+ -- \caption-command, e.g.
+ -- In this case two version of the note are stored and we drop the
+ -- note that does not have a valid page number (the other note
+ -- seems to have one).
+ table.remove(notesForPage, k)
+ if todonotesDebug then
+ print("deleting note: " .. k .. " (" .. v.index .. ")")
+ end
+ elseif v.pageNr ~= currentPage then
table.insert(notesForNextPage, v)
table.remove(notesForPage, k)
- print("moving " .. k)
+ if todonotesDebug then
+ print("moving note to next page: " .. k .. " (" .. v.index .. ")")
+ end
else
-- update index here (needed if a note was deleted before)
v.indexOnPage = k
@@ -520,7 +538,11 @@ function luatodonotes.printNotes()
for _, v in pairs(notesForPage) do
if v.noteType ~= "area" then
v.inputX = v.origInputX + inputShiftX
- v.inputY = v.origInputY - 1.3 * (v.baselineskip - v.fontsize)
+ local bls = v.baselineskip
+ if v.baselineskip == 0 then
+ bls = v.normalbaselineskip
+ end
+ v.inputY = v.origInputY - 1.3 * (bls - v.fontsize)
else
v.inputX = v.origInputX
v.inputY = v.origInputY
@@ -570,6 +592,7 @@ function luatodonotes.printNotes()
print("rasterSlots: " .. v.rasterSlots)
end
print("baselineskip: " .. outputWithPoints(v.baselineskip))
+ print("nbaselineskip:" .. outputWithPoints(v.normalbaselineskip))
print("fontsize: " .. outputWithPoints(v.fontsize))
print("textbox: " .. inspect(v.textbox))
print("height: " .. outputWithPoints(v:getHeight()))
@@ -1006,7 +1029,7 @@ local function checkCurveApproximation(curve1, curve2)
local sectionsCurve2 = {}
-- get line segments of the first curve
- local numberOfSectionsCurve1 = numberOfCurvePartitions
+ local numberOfSectionsCurve1 = luatodonotes.numberOfCurvePartitions
local temp1X, temp1Y = getPointOnCurve(0, curve1)
local i = 1
while i <= numberOfSectionsCurve1 do
@@ -1023,7 +1046,7 @@ local function checkCurveApproximation(curve1, curve2)
end
-- get line segments of the second curve
- local numberOfSectionsCurve2 = numberOfCurvePartitions
+ local numberOfSectionsCurve2 = luatodonotes.numberOfCurvePartitions
temp1X, temp1Y = getPointOnCurve(0, curve2)
i = 1
while i <= numberOfSectionsCurve2 do
@@ -1220,7 +1243,7 @@ local function drawSBezierLeaders()
v.forceLimitInc = math.huge
end
- numberOfCurvePartitions = #notesForPage * 3
+ luatodonotes.numberOfCurvePartitions = #notesForPage * 3
for _, v in pairs(notesForPage) do
computeOptimalPosition(v)
@@ -1230,9 +1253,9 @@ local function drawSBezierLeaders()
local proceed = true
local loopCounter = 0
while (proceed and loopCounter < maxIterations) do
- --print("")
- --print("--------------------------------------------------")
- print("iteration " .. loopCounter .. ":")
+ if todonotesDebug then
+ print("Iteration " .. loopCounter)
+ end
-- compute forces
computeRepulsiveControlPointForces()
@@ -1250,10 +1273,9 @@ local function drawSBezierLeaders()
loopCounter = loopCounter + 1
end
- print("")
- print("End of Force-directed algo")
- print("number of iterations: " .. loopCounter)
- print("")
+ if todonotesDebug then
+ print("End of Force-directed algo, number of iterations: " .. loopCounter)
+ end
-- draw
for _, v in pairs(notesForPage) do
@@ -1564,7 +1586,6 @@ local function posSLeaderEast(notes, rightSide)
-- build a array with all distinct heights of the notes
-- first create a set and then convert to sorted array
local heights = {}
- print(#heights)
for _, v in pairs(notes) do
heights[notesForPage[v]:getHeight()] = true
end
@@ -1574,7 +1595,9 @@ local function posSLeaderEast(notes, rightSide)
local chosenIndex = -1
local chosenH = -1
for _, h in pairs(heights) do
- print("testing height: " .. h) -- DEBUG
+ if todonotesDebug then
+ print("testing height: " .. h)
+ end
leaderPosY = noteY - noteInnerSep - h/2
-- find point with highest angle
@@ -1584,6 +1607,9 @@ local function posSLeaderEast(notes, rightSide)
if notesForPage[notes[minIndex]]:getHeight() <= h then
chosenIndex = minIndex
chosenH = h
+ if todonotesDebug then
+ print("placed note " .. notesForPage[notes[chosenIndex]].index)
+ end
break
end
end
@@ -1595,8 +1621,7 @@ local function posSLeaderEast(notes, rightSide)
note.outputY = noteY - (chosenH - note:getHeight()) / 2
-- no extraordinary free space below note (even if chosenH ~= note:getHeight())
noteY = note.outputY - note:getHeight() - 2 * noteInnerSep - noteInterSpace
- -- DEBUG
- if chosenH ~= note:getHeight() then
+ if todonotesDebug and chosenH ~= note:getHeight() then
print("Creating free space above note " .. note.index)
end
@@ -1616,8 +1641,7 @@ local function posSLeaderEast(notes, rightSide)
aimedPos = prevNote.outputY - prevNote:getHeight() - 2 * noteInnerSep - noteInterSpace
end
- -- DEBUG
- if aimedPos ~= note.outputY then
+ if todonotesDebug and aimedPos ~= note.outputY then
print("note " .. note.index .. " got moved:")
print("aimed: " .. aimedPos)
print("real: " .. note.outputY)
@@ -1658,7 +1682,9 @@ local function posSLeaderEast(notes, rightSide)
minAngle = otherNoteAngle
minAngleIndex = otherInd
end
- print(otherNote.index .. " is in triangle for " .. note.index) -- DEBUG
+ if todonotesDebug then
+ print(otherNote.index .. " is in triangle for " .. note.index)
+ end
end
end
end
@@ -1714,8 +1740,6 @@ local function getPosBelowLine(linePositionsCurPage, lineInd)
return posBelow
end
local function posPoLeaders(notes, rightSide, avoidLines)
- print("rasterHeight: " .. rasterHeight)
-
local linePositionsCurPage
if avoidLines then
linePositionsCurPage = linePositions[currentPage] or {}
@@ -2025,29 +2049,24 @@ local function posPoLeaders(notes, rightSide, avoidLines)
print("WARNING: could not fit all labels on page")
end
- print("Using result: opt[1][" .. #notes ..
- "][1][" .. totalNumSlots .. "][" .. maxPlaced .. "]")
local res = opt[1][#notes][1][totalNumSlots][maxPlaced]
- local length = res.totalLength
local positions = res.positions
local leaderShiftY = res.leaderShiftY
-
- print("")
- print("----------------")
- print("resulting length: " .. length)
- print("")
- print("resulting positions:")
- print(inspect(positions))
- print("")
- print("resulting leaderShifts:")
- print(inspect(leaderShiftY))
- print("")
- print("")
- print("")
-
-
- -- DEBUG on page
if todonotesDebug then
+ local length = res.totalLength
+ -- in console
+ print("----------------")
+ print("po-leader algorithm: Using result: opt[1][" .. #notes ..
+ "][1][" .. totalNumSlots .. "][" .. maxPlaced .. "]")
+
+ print("resulting length: " .. length)
+ print("resulting positions:")
+ print(inspect(positions))
+ print("resulting leaderShifts:")
+ print(inspect(leaderShiftY))
+ print("----------------")
+
+ -- on page
tex.print("\\node[text=blue,fill=white,rectangle,align=center] at (10.5cm,-27cm) {" ..
"total length: " .. number.tocentimeters(length, "%s%s") .. "\\\\ " ..
"rasterHeight: " .. number.tocentimeters(rasterHeight, "%s%s") ..
@@ -2096,8 +2115,9 @@ local function splitNone()
local rightSideSelected = false
if labelArea.left == nil and labelArea.right == nil then
error("Cannot place labels on any side of text (not enough space). " ..
- "Consider using the minNoteWidth option of the package to " ..
- "decrease the minimum width required")
+ "Consider using the additionalMargin option of the package to " ..
+ "extend the page margins " ..
+ "or minNoteWidth to decrease the minimum width required")
elseif labelArea.left == nil then
rightSideSelected = true
elseif labelArea.right ~= nil and