summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/lualatex
diff options
context:
space:
mode:
authorKarl Berry <karl@freefriends.org>2015-12-05 23:01:08 +0000
committerKarl Berry <karl@freefriends.org>2015-12-05 23:01:08 +0000
commit5384f92b5a44dd9e84f1bab69420edf32e99c696 (patch)
tree47ce270ba97f34e690da94927a29740d58dcf3d5 /Master/texmf-dist/tex/lualatex
parenta3e2c07a7a98d9b5afdd8940333dae4a7e3e6196 (diff)
luatodonotes (5dec15)
git-svn-id: svn://tug.org/texlive/trunk@39019 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/tex/lualatex')
-rw-r--r--Master/texmf-dist/tex/lualatex/luatodonotes/luatodonotes.lua114
-rw-r--r--Master/texmf-dist/tex/lualatex/luatodonotes/luatodonotes.sty88
2 files changed, 142 insertions, 60 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
diff --git a/Master/texmf-dist/tex/lualatex/luatodonotes/luatodonotes.sty b/Master/texmf-dist/tex/lualatex/luatodonotes/luatodonotes.sty
index d300a1ba5ad..8663c610eb8 100644
--- a/Master/texmf-dist/tex/lualatex/luatodonotes/luatodonotes.sty
+++ b/Master/texmf-dist/tex/lualatex/luatodonotes/luatodonotes.sty
@@ -24,8 +24,20 @@
%%
\NeedsTeXFormat{LaTeX2e}[1999/12/01]
\ProvidesPackage{luatodonotes}
- [2015/03/13 v0.2 luatodonotes source and documentation.]
+ [2015/12/03 v0.3 luatodonotes source and documentation.]
+\@ifpackageloaded{todonotes}{
+ \PackageError{luatodonotes}{%
+ Conflicting packages todonotes and luatodonotes\MessageBreak
+ loaded. Aborting.}{%
+ The package luatodonotes was designed as a replacement for todonotes. So it
+ is not possible (and not reasonable) to include both of them in the same
+ document.%
+ If you want to use luatodonotes you should delete the todonotes
+ package from\MessageBreak
+ your preamble.\MessageBreak}
+}{}
+\expandafter\def\csname ver@todonotes.sty\endcsname{2014/07/14}
\RequirePackage{ifluatex}
\ifluatex\else
\PackageError{luatodonotes}{LuaTeX is required for this package. Aborting.}{%
@@ -41,31 +53,35 @@
\usetikzlibrary{intersections}
\usetikzlibrary{decorations.pathmorphing}
\RequirePackage{luacode}
-\RequirePackage{luatex}
\RequirePackage{atbegshi}
\RequirePackage{xstring}
\RequirePackage{zref-abspage}
\RequirePackage{ifoddpage}
\RequirePackage{soul}
\RequirePackage{soulpos}
+\@ifpackagelater{luatexbase}{2013/05/04}{}{
+ \RequirePackage{luatex}
+}
\newcommand{\@todonotes@text}{}%
\newcommand{\@todonotes@backgroundcolor}{orange}
\newcommand{\@todonotes@linecolor}{black!30}
\newcommand{\@todonotes@bordercolor}{black}
\newcommand{\@todonotes@leaderwidth}{1.6pt}
\newcommand{\@todonotes@textsize}{\normalsize}
-\newcommand{\@todonotes@figwidth}{\columnwidth}
+\newcommand{\@todonotes@figwidth}{\linewidth}
\newcommand{\@todonotes@figheight}{4cm}
+\newcommand{\@todonotes@figcolor}{black!40}
\newcommand{\@todonotes@positioning}{inputOrderStacks}
\newcommand{\@todonotes@splitting}{none}
\newcommand{\@todonotes@leadertype}{opo}
\newcommand{\@todonotes@interNoteSpace}{5pt}
\newcommand{\@todonotes@noteInnerSep}{5pt}
\newcommand{\@todonotes@routingAreaWidth}{0.4cm}
-\newcommand{\@todonotes@minNoteWidth}{1.0cm}
+\newcommand{\@todonotes@minNoteWidth}{2.0cm}
\newcommand{\@todonotes@distanceNotesPageBorder}{0.5cm}
\newcommand{\@todonotes@distanceNotesText}{0.2cm}
\newcommand{\@todonotes@rasterHeight}{1cm}
+\newcommand{\@todonotes@additionalMargin}{2cm}
\AtBeginDocument{
\ifx\undefined\phantomsection
\newcommand{\phantomsection}{}
@@ -90,6 +106,12 @@
\@todonotes@SetMissingFigureUp{Figura}%
\@todonotes@SetMissingFigureDown{pendent}%
}
+\DeclareOptionX{croatian}{%
+ \@todonotes@SetTodoListName{Popis obveza}%
+ \@todonotes@SetMissingFigureText{Slika}%
+ \@todonotes@SetMissingFigureUp{Nedostaje}%
+ \@todonotes@SetMissingFigureDown{slika}%
+}
\DeclareOptionX{danish}{%
\@todonotes@SetTodoListName{G\o{}rem\aa{}lsliste}%
\@todonotes@SetMissingFigureText{Figur}%
@@ -199,6 +221,16 @@
\define@key{luatodonotes.sty}%
{figheight}{\renewcommand{\@todonotes@figheight}{#1}}
\define@key{luatodonotes.sty}%
+ {figcolor}{\renewcommand{\@todonotes@figcolor}{#1}}
+\DeclareOptionX{po}%
+ {\setkeys{luatodonotes.sty}{leadertype=po,positioning=poLeadersAvoidLines}}
+\DeclareOptionX{s}%
+ {\setkeys{luatodonotes.sty}{leadertype=s,positioning=sLeaderNorthEastBelowStacks}}
+\DeclareOptionX{bezier}%
+ {\setkeys{luatodonotes.sty}{leadertype=sBezier,positioning=sLeaderNorthEastBelowStacks}}
+\DeclareOptionX{opo}%
+ {\setkeys{luatodonotes.sty}{leadertype=opo,positioning=inputOrderStacks}}
+\define@key{luatodonotes.sty}%
{positioning}{\renewcommand{\@todonotes@positioning}{#1}}
\define@key{luatodonotes.sty}%
{splitting}{\renewcommand{\@todonotes@splitting}{#1}}
@@ -219,6 +251,12 @@
{distanceNotesText}{\renewcommand{\@todonotes@distanceNotesText}{#1}}
\define@key{luatodonotes.sty}%
{rasterHeight}{\renewcommand{\@todonotes@rasterHeight}{#1}}
+\newif{\if@todonotes@additionalMarginEnabled}
+\@todonotes@additionalMarginEnabledfalse
+\define@key{luatodonotes.sty}%
+ {additionalMargin}[\@todonotes@additionalMargin]{%
+ \@todonotes@additionalMarginEnabledtrue
+ \renewcommand{\@todonotes@additionalMargin}{#1}}
\newif{\if@todonotes@debugenabled}
\@todonotes@debugenabledfalse
\DeclareOptionX{debug}{\@todonotes@debugenabledtrue}
@@ -238,6 +276,16 @@
\fi
\fi
\fi
+\if@todonotes@additionalMarginEnabled
+ \newlength{\@todonotes@modpaperwidth}
+ \AtBeginDocument{%
+ \setlength{\@todonotes@modpaperwidth}{\paperwidth}%
+ \addtolength{\@todonotes@modpaperwidth}{\@todonotes@additionalMargin}%
+ \addtolength{\@todonotes@modpaperwidth}{\@todonotes@additionalMargin}%
+ \pdfpagewidth=\@todonotes@modpaperwidth%
+ \addtolength{\hoffset}{\@todonotes@additionalMargin}%
+ }%
+\fi%
\newdimen\@todonotes@extractx
\newdimen\@todonotes@extracty
\newsavebox\@todonotes@heightcalcbox
@@ -245,6 +293,7 @@
\newdimen\@todonotes@heightcalcboxheight
\newsavebox\@todonotes@notetextbox
\newdimen\@todonotes@baselineskip
+\newdimen\@todonotes@normalbaselineskip
\newdimen\@todonotes@fontsize
\newdimen\@todonotes@currentsidemargin
\directlua{require("luatodonotes")}
@@ -400,6 +449,9 @@
\newcommand{\@todonotes@currentfigheight}{\@todonotes@figheight}
\define@key{todonotes}%
{figheight}{\renewcommand{\@todonotes@currentfigheight}{#1}}
+\newcommand{\@todonotes@currentfigcolor}{\@todonotes@figcolor}
+\define@key{todonotes}%
+ {figcolor}{\renewcommand{\@todonotes@currentfigcolor}{#1}}
\presetkeys%
{todonotes}%
{linecolor=\@todonotes@linecolor,%
@@ -412,6 +464,7 @@
noauthor,%
figwidth=\@todonotes@figwidth,%
figheight=\@todonotes@figheight,%
+ figcolor=\@todonotes@figcolor,%
line, list, size=\@todonotes@textsize}{}%
\newif\if@todonotes@areaselected%
\newtoks\@todonotes@toks@currentlinecolor%
@@ -425,8 +478,13 @@
\newcommand{\@todoarea}[3][]{}
\newcommand{\missingfigure}[2][]{}
\else % \if@todonotes@disabled
-\newcommand{\listoftodos}[1][\@todonotes@todolistname]
- {\@ifundefined{chapter}{\section*{#1}}{\chapter*{#1}} \@starttoc{tdo}}
+\newcounter{todonotes@oldtocdepth}
+\newcommand{\listoftodos}[1][\@todonotes@todolistname]{%
+ \setcounter{todonotes@oldtocdepth}{\value{tocdepth}}%
+ \setcounter{tocdepth}{1}%
+ \@ifundefined{chapter}{\section*{#1}}{\chapter*{#1}} \@starttoc{tdo}%
+ \setcounter{tocdepth}{\value{todonotes@oldtocdepth}}%
+}
\newcommand{\l@todo}
{\@dottedtocline{1}{0em}{2.3em}}
\tikzset{@todonotes@todoarea/.style={
@@ -501,6 +559,7 @@
inText) {};%
\end{tikzpicture}%
\@todonotes@baselineskip=\baselineskip%
+ \@todonotes@normalbaselineskip=\normalbaselineskip%
\@todonotes@fontsize=\f@size pt%
\zref@label{@todonotes@\arabic{@todonotes@numberoftodonotes}}%
\if@todonotes@authorgiven%
@@ -563,7 +622,7 @@
\par
\noindent
\begin{tikzpicture}
-\draw[fill=black!40, draw = white, line width=0pt]
+\draw[fill=\@todonotes@currentfigcolor, draw = black!40, line width=2pt]
(-2, -2.5) rectangle +(\@todonotes@currentfigwidth, \@todonotes@currentfigheight);
\draw (2, -0.3) node[right, text
width=\@todonotes@currentfigwidth-4.5cm] {#2};
@@ -571,9 +630,9 @@
(30:2cm) -- (150:2cm) -- (270:2cm) -- cycle;
\draw (0, 0.3) node {\@todonotes@MissingFigureUp};
\draw (0, -0.3) node {\@todonotes@MissingFigureDown};
-\end{tikzpicture}
+\end{tikzpicture}\hfill
}% Ending \missingfigure command
-\fi % Ending \@todonotes@ifdisabled
+\fi% Ending \@todonotes@ifdisabled
\newcommand{\todototoc}
{
\if@todonotes@disabled
@@ -597,10 +656,13 @@
\BeginCatcodeRegime\CatcodeTableLaTeX
\directlua{luatodonotes.calcLabelAreaDimensions()}%
\directlua{luatodonotes.calcHeightsForNotes()}% has to be outside of tikzpicture
- \begin{tikzpicture}[remember picture,overlay]
- \directlua{luatodonotes.getInputCoordinatesForNotes()}
- \directlua{luatodonotes.printNotes()}
- \end{tikzpicture}%
+ \raisebox{\voffset}{%
+ \hspace{-\hoffset}%
+ \begin{tikzpicture}[remember picture,overlay]
+ \directlua{luatodonotes.getInputCoordinatesForNotes()}
+ \directlua{luatodonotes.printNotes()}
+ \end{tikzpicture}%
+ }%
\directlua{luatodonotes.clearNotes()}%
\EndCatcodeRegime
}%