shicks/marginfix

Some margin notes don't appear at all

Closed this issue · 14 comments

Someone seems to have produced a minimal example here: https://tex.stackexchange.com/questions/352596/package-marginfix-swallows-some-margin-notes

I've had this happen when using the tufte-handout class.

I have encountered this problem with tufte-book, any help would be appreciated!

I also encountered this with my book http://introtcs.org (don't have MWE at the moment)

Thanks you Amy!
Let me see if I am able to replicate it - this is a 600 page book and at some point I saw comments disappearing, but not sure this still happens. I still have other issues with the combination of marginfix and tufte-book - sidenotes and margin captions overlapping each other (though marginfix definitely helps) and for some reason some sidenotes are orange. At the moment I am more focused on the contents of the book than its style, but at some point I hope to debug these issues.

Here is an example that demonstrates the problem on my system. The note doesn't show up when I compile with pdflatex.

`
\documentclass{tufte-book}
\usepackage{marginfix}
\geometry{paperheight=10in,paperwidth=8in,textheight=8in,left=0.6in,bindingoffset=0.3in}

\begin{document}
\chapter{Test}

\newpage

\vspace*{6.7in}

Lorem ipsum dolor sit amet, labore blandit perfecto vel eu, volumus fabellas te nam, te dicta blandit his. Ea pri equidem
\begin{equation}
\int \prod_{i}
\end{equation}
Lorem ipsum dolor sit amet, labore blandit perfecto vel eu,

Lorem ipsum dolor sit amet,
\marginnote{Ut vero duis quaeque mea, te iudico diceret mnesarchum vix, has et virtute deleniti ponderum.}
labore blandit perfecto vel eu, volumus fabellas te nam, te dicta blandit his.

\end{document}
`

Here I simplified a bit more. Sorry I can't seem to get the formatting to work nicely.

\documentclass{tufte-book}
\usepackage{marginfix}
\geometry{paperheight=10in,paperwidth=8in,textheight=8in,left=0.6in}

\begin{document}
\chapter{Test}
\newpage
\vspace*{7.3in} \[ x \]
Lorem ipsum dolor sit amet
\marginnote{Ut vero duis quaeque mea}
\end{document}

@TeXniques thanks for looking into this. Please feel free to send a Pull Request if you find a solution.

Interesting that you don't see a problem... I'm running MikTex 2.9, Tufte-book 3.5.2, and I just made sure all my packages are up to date. I still see the note dropped when marginfix is included, so maybe it is a MikTex quirk.

Anyway I understand if you can't spend a lot of time on it gratis. If you were able to share your code to flag missing notes that would be great, otherwise I can just fix positioning by hand as I have been.
test3.pdf

--
Note added: I also see the same behavior in Overleaf.

Thanks everyone for continuing investigation. I copied @casackett's simpler repro and tinkered with it - it seems like the problem arises when the margin note comes exactly at the end of a page. It looks like there's a ~3bp range of vspace above which the note appears on the previous page and below which the whole line is wrapped to the next (specifically, the closed interval [34547300sp, 34744565sp] is the broken range). The next step is to look at what's happening to the inserts and see where it's being dropped.

The relevant fix from #16 seems to be resetting \Mfx@piece@count to 1, rather than incrementing it by 1. When it's incremented, all the notes show up as being in piece 2, rather than piece 1. In this tiny 3bp window, it's measuring the note's position as being greater than the margin's height (this could have something to do with the small vertical variation we generally see, IIRC due to lining up a baseline with a top, or some such, or else measuring from the bottom of the box, I don't really know right now). It then compares the note's piece (2) with the number of pieces (1) and punts it to the next piece - except there is no next piece. I think what's happening is that an earlier pass concluded definitively that the note would fit in the margin (so it was removed from the queue, to never be revisited on future pages), but then the piecewise pass passed up on rendering it, expecting a future piece (that didn't exist) to pick it up. So that's why the notes are disappearing.

Alright, I know what's happening. As I suspected, resetting \Mfx@piece@count to 1 in \Mfx@buildmargin is problematic, since it fails to properly account for margin blocks/phantoms (areas of the margin that aren't allowed to have notes), and essentially reverts the whole thing to a single continuous margin. I assume this is why #16 also reset the margin height since otherwise if there were multiple margin pieces, only one would be used (maybe?).

In any case, the way the piece count works is that every time you add a phantom, it increments the counter, and then at the end of the page, it increments it one more time. Assuming it started the page at zero, it will end with the total number of pieces available to place notes in. Unfortunately, that assumption was wrong: all of the routines to increment the count were done globally, which is correct, since who knows whether you're calling \blockmargin in a group or not. In the output routine, we reset the count to zero and increment/decrement it as we move down and up the margin, through each piece (remember, there's a limited number of counters in some TeX definitions, so reusing the few we allocate can make a lot of sense). At the end of all the passes, we reset it to zero, but we didn't do it globally. I'm not sure if I was aware before that the output routine runs in a group. The upshot is that even though the counter is reset to zero at the end of the output routine, the previous number ended up getting restored upon exiting back to the normal parts. This meant that notes were getting placed in much later pieces than they necessarily needed to be in, which generally didn't matter, unless there were some rare constraints, such as being right at the end of the page, or maybe if there were multiple crowded pieces with unfortunate sizes.

Changing the final counter reset to be \global seems to fix the issue once and for all.