From e3ea4af2c431dac8003971d3687223c50329fdad Mon Sep 17 00:00:00 2001 From: Stephen Hicks Date: Wed, 6 May 2020 18:17:37 -0700 Subject: [PATCH] Stop dropping notes on the floor Fixes #15 (which has been open for years) by ensuring the margin piece count is properly reset to zero on every page. Many thanks to casackett for providing a minimal repro, and to UlrikBuchholtz for pointing me in the right direction for the fix (and pointing out a few typos). --- Makefile | 10 ++++++++-- marginfix.dtx | 21 ++++++++++++--------- test/issue-15.tex | 15 +++++++++++++++ 3 files changed, 35 insertions(+), 11 deletions(-) create mode 100644 test/issue-15.tex diff --git a/Makefile b/Makefile index ef86d60..5a5f466 100644 --- a/Makefile +++ b/Makefile @@ -10,9 +10,9 @@ marginfix.sty:marginfix.dtx marginfix.ins marginfix.pdf:marginfix.dtx pdflatex marginfix.dtx -.PHONY: test +.PHONY: test clean -test:margintest.pdf tufte.pdf ragged.pdf defer.pdf phantom.pdf float.pdf stretch.pdf +test:margintest.pdf tufte.pdf ragged.pdf defer.pdf phantom.pdf float.pdf stretch.pdf issue-15.pdf margintest.pdf:marginfix.sty test/margintest.tex pdflatex test/margintest.tex @@ -34,3 +34,9 @@ float.pdf:marginfix.sty test/float.tex stretch.pdf:marginfix.sty test/stretch.tex pdflatex test/stretch.tex + +issue-15.pdf:marginfix.sty test/issue-15.tex + pdflatex test/issue-15.tex + +clean: + rm *.log *.aux *.pdf tufte.out marginfix.sty diff --git a/marginfix.dtx b/marginfix.dtx index 2774ef0..914f95b 100644 --- a/marginfix.dtx +++ b/marginfix.dtx @@ -12,10 +12,10 @@ % %\NeedsTeXFormat{LaTeX2e} %\ProvidesPackage{marginfix}% - [2013/09/08 v1.1 Fix Margin Paragraphs] + [2020/05/06 v1.2 Fix Margin Paragraphs] %<*driver> \documentclass{ltxdoc} -\CheckSum{1158} +\CheckSum{1159} %\OnlyDescription % (un)comment this line to show (hide) source code \RecordChanges \EnableCrossrefs @@ -70,6 +70,9 @@ % {(SDH) Globally calculate margin phantoms over 4 passes.} % \changes{v1.1}{2013/09/08} % {(SDH) Add \cs{topskip} to notes at the top of the margin.} +% \changes{v1.2}{2020/05/06} +% {(SDH) Fix long-standing bug where margin notes called out in +% the last few points of a page were being entirely dropped.} % % \GetFileInfo{marginfix.dtx} % \title{\Lopt{marginfix} package documentation} @@ -512,7 +515,7 @@ % In passing we'll define the cons macro, which fully-expands % its second argument, but makes sure to only expand the first % one once, so that any fragile control sequences in it are -% corectly protected. We also define snoc, which prepends. +% correctly protected. We also define snoc, which prepends. % Note that we could put the \cs{temp@} definition into a group % if it was really gonna matter\ldots % \begin{macrocode} @@ -691,7 +694,7 @@ % line up the notes with their callouts). This procedure happens in % four passes. But first, we initialize \cs{Mfx@marginheight} to % \cs{@colroom}, which is the height of the page minus any floats that -% have been added to the top of bottom (these floats may extend into the +% have been added to the top or bottom (these floats may extend into the % margins: in the future we may look into detecting this and using the % whole page, with overwide floats blocked off as phantoms). We add % \cs{@colroom} rather than assigning it because any global or per-page @@ -784,7 +787,7 @@ % We now define the various |\MFX@margin@...@down| macros. % At this stage in the game, the only difference between notes % and skips is that we ignore skips before any notes by setting -% \cs{mfx@build@note} initially to \cs{@gobble}. Once we've +% \cs{mfx@build@skip} initially to \cs{@gobble}. Once we've % seen the first note, skips are treated exactly the same: as % fixed-height material. If there is room in the current piece % for the given height, then we prepend it to \cs{mfx@marginout}, @@ -928,8 +931,8 @@ % \end{macros} % % \begin{macros}{\MFX@leftmargin} -% And here is the logic to figure out which margin were in, based -% on the page number and other flags. This is another conditional-like +% And here is the logic to figure out which margin we're in, based on +% the page number and other flags. This is another conditional-like % macro, and should be used after an \cs{if}, as in % \cs{if}\cs{MFX@leftmargin}\ldots\cs{else}\ldots\cs{fi}. % @@ -1039,7 +1042,7 @@ % look for a piece that can fit this note, making sure to decrement % the piece count and pop off a phantom for each new piece we check. % Once it's found, we add the note back to \cs{mfx@marginout} with -% the corect piece. +% the correct piece. % \begin{macrocode} \if\MFX@check@fit{\advance\Mfx@piece@count\m@ne \MFX@popdimen\dimen@\mfx@phantomheights}{\ht#1+\dp#1}% @@ -1111,7 +1114,7 @@ \let\@elt\MFX@buildmargin@piece \MFX@run@clear\mfx@marginpieces \let\@elt\relax - \Mfx@piece@count\z@ + \global\Mfx@piece@count\z@ } % \end{macrocode} % \end{macros} diff --git a/test/issue-15.tex b/test/issue-15.tex new file mode 100644 index 0000000..53788b7 --- /dev/null +++ b/test/issue-15.tex @@ -0,0 +1,15 @@ +\documentclass{tufte-book} +\usepackage{marginfix} +\geometry{paperheight=10in,paperwidth=8in,textheight=8in,left=0.6in} + +\begin{document} +\chapter{Test} +\newpage +%\vspace*{34547299sp} % same +\vspace*{34547300sp} % [ +%\vspace*{34744565sp} % ] +%\vspace*{34744566sp} % break +\[ x \] +% Make sure that the note actually appears anywhere! +Lorem ipsum dolor sit amet \marginnote{Ut vero duis quaeque mea} +\end{document}