Skip to content

Commit

Permalink
Stop dropping notes on the floor
Browse files Browse the repository at this point in the history
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).
  • Loading branch information
shicks committed May 7, 2020
1 parent 01a3de9 commit e3ea4af
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 11 deletions.
10 changes: 8 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
21 changes: 12 additions & 9 deletions marginfix.dtx
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
%
%<package>\NeedsTeXFormat{LaTeX2e}
%<package>\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
Expand Down Expand Up @@ -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}
Expand Down Expand Up @@ -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}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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},
Expand Down Expand Up @@ -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}.
%
Expand Down Expand Up @@ -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}%
Expand Down Expand Up @@ -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}
Expand Down
15 changes: 15 additions & 0 deletions test/issue-15.tex
Original file line number Diff line number Diff line change
@@ -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}

0 comments on commit e3ea4af

Please sign in to comment.