# How to avoid long margin notes running into the footer in ConTeXt?

it's me again. :) Still trying to set up a ConTeXt environment file for a book layout.

I have now run into a problem that I wouldn't have thought would appear. Here's a MWE:

``````\usemodule[visual]

\mainlanguage[de]
\language[de]
\definecolor[lightbrown] [r=0.83, g=0.76, b=0.71]

\setuppapersize[A4][A4]
\setuplayout
[
backspace=11.67mm,        width=131.25mm,
topspace=21.21mm,         height=254.57mm,
footerdistance=13pt,      footer=13pt,
rightmargindistance=13pt, rightmargin=39.5mm,
]

\setuppagenumbering[alternative=doublesided, location=]

\setupmargindata[
style=\ss\tf,
color=lightbrown,
stack=continue,
]

\starttext

\chapter{Testing Margin Notes}

\input{knuth}

\input{knuth}

\input{knuth}

\inouter{\input{knuth}}

\input{knuth}

\input{knuth}

\input{knuth}

\stoptext
``````

And here's how this looks like:

I'm sure, you can see the problem: The margin note that I placed in the outer margin on the first page is too long for the margin area and reaches into the footer, down to the end of the page.

Now, I do realize that this is one long margin note, and margin notes won't usually be that long. However, if I understand it correctly, this problem can occur, even if the margin notes are as short as, say, two or three lines: As soon as they are placed close enough to the end of the text area, they will run into the footer.

Frankly, I wouldn't have thought that I would have to deal with a low-level typesetting problem such as this. In my opinion, unless the system can solve situations like this (maybe by shifting the margin notes upwards a bit or by breaking them across pages), margin notes are pretty unusable. So, I'm thinking I must be missing something. Is there a good solution for this?

UPDATE: As I mentioned in a comment below, I do realize that margin notes crossing pages is difficult to achieve for various reasons. But that's not what I need, anyway. All I need is a somewhat automatic way for preventing really short margin notes (say, three or four lines) to extend below the end of the text area. The way margin notes currently work (please correct me, if I'm wrong) means, I will always have to manually tweak their position, if, by chance, they end up too far down on the page. It's this manual intervention that I would like to avoid.

• \marginpar is better at this, but can't be used inside floats. I have created some elaborate solutions such as tex.stackexchange.com/questions/215322/… and tex.stackexchange.com/questions/320065/… – John Kormylo Oct 18 '16 at 1:34
• Oh wow, that looks like an elaborate solution. Thanks for pointing me to this. Is there a simple way for me to try this out in ConTeXt? (Actually, all I need is a somewhat automatic procedure for shifting one or two short notes up or down a bit, if they would otherwise end up in the footer. No need for more complex opimizations.) – Marcus C. Oct 18 '16 at 9:56

AFAIK, it is not possible to split margin notes across pages. So, if you have a big margin note (or if margin note occurs near a page boundary), there are two possibilities:

1. Shift the margin note up using `voffset` key or using `line` key. For example:

``````\inouter[voffset=-25\lineheight]{\input{knuth}}
``````

or

``````\inouter[line=-25]{...}
``````

It may be possible to automate this (typeset the margin note, measure its height and if the height is greater than the number of lines left on the page, shift the note up), but such a method will not work if there are multiple long margin notes.

2. Place the margin notes to the top of where they are anchored (rather than to the bottom). For example, use

``````\inouter[method=top]{....}
``````

or set it globally using `\setupmargindata[inouter][method=top]`. Variants such as `method=depth` or `method=height` also work. But this just moves the problem to a different area. Now margin notes that appear too close to the top may overflow.

In short, you need manual intervention. If you can come up with a robust algorithm on how to place margin notes, then it should be relatively simple to implement it (see `typo-mar.lua` for current implementation).

Note: In general, you may want to add `dy=\lineheight` or something similar so that there is some space between the stacked notes.

• Thank you for your help. I was afraid, this would need manual intervention. `method=top` works well in those problematic cases that I experienced so far. However, the book I'm writing will be published in different forms (e.g., full version in smaller size, abridged version for students in A4 and so on), so I really need a more automatic solution. (Also, thanks for mentioning `dy=\lineheight`. That will come in handy.) – Marcus C. Oct 18 '16 at 9:37
• There is this comment by Hans Hagen in the file typo-mar.lua (which defines margin data): "The continue option uses position tracking and works on larger range. However, crossing pages is not part of it. Anyway, when you have such messed up margin data you'd better think twice." Which would mean that this is not a priority for him and ConTeXt margin notes are just not meant for what you want to do. – Thomas Oct 18 '16 at 17:28
• Thank you, @Thomas, for your help. Actually, I don't really need margin notes to cross pages. And I won't have too many of them. All I need is really short margin notes (say, three or four lines) not extending below the end of the text area. And the way margin notes currently work (please correct me, if I'm wrong) means, I will always have to manually tweak their position, if, by chance, they end up too far down on the page. It's this manual intervention that I would like to avoid. – Marcus C. Oct 19 '16 at 8:02