# How can I replace footnotes for non-floating marginal notes?

How can I replace footnotes for non-floating marginal notes?

I have tried to replace my footnotes for sidenotes with footmisc package's side option, but they continue to be floats, like every \marginpar. I don't want them to float around an anchor: I want these marginal notes flowing from the top of the page to the bottom, and with the capacity of being splitted between pages when needed (because some of them might be too long, or there might be too many of them).

-
An interesting problem. So if there are only (say) three notes at the bottom of the page, they should still appear at the top of the page in the margin with no empty space in between the notes? – jon Sep 5 '12 at 18:20
@jon Yes, like in this book, for example. – henrique Sep 5 '12 at 18:25
Maybe also this answer could be an alternative. Here, marginnotes which don't fit in the margin turn into footnotes, but maybe this is better than displaying them on another page? – Stephan Lehmke Sep 5 '12 at 18:54
This doesn't answer your problem but the memoir class provides for footnotes that are set in a column in the outer margin with the bottom of the column aligned with the bottom of the page, whereas you would like the head of the column aligned at the top of the page. – Peter Wilson Sep 10 '12 at 19:28

EDIT Original version using a newly allocated box register is at the end. This version uses the \footins insertion register to take advantage of the primitive insert capability to pick up the correct notes for each page.

\documentclass[twoside]{article}
\newcounter{f}
\def\z{\stepcounter{f}\Roman{f}
\roman{f} \alph{f} \roman{f} \roman{f} \roman{f}
\roman{f} \roman{f} \alph{f} \roman{f} \roman{f}
\roman{f} \roman{f} \roman{f} \alph{f} \roman{f}
\roman{f} \roman{f} \roman{f} \roman{f} \alph{f}}

\def\a{One two three.}
\def\b{\a\ \a\ Four five. \a}
\def\c{\b\ \b\ Red green blue. \b\footnote{\z} \a}
\def\d{\c\ \c\ \c\ \c}

\makeatletter
\skip\footins\z@
\count\footins\z@
\dimen\footins\textheight

\long\def\@footnotetext#1{%
\insert\footins{%
\reset@font\footnotesize
\interlinepenalty\interfootnotelinepenalty
\splitmaxdepth \dp\strutbox \floatingpenalty \@MM
\hsize\marginparwidth \@parboxrestore
\protected@edef\@currentlabel{%
\csname p@footnote\endcsname\@thefnmark
}%
\color@begingroup
\@makefntext{%
\rule\z@\footnotesep\ignorespaces#1\@finalstrut\strutbox}%
\color@endgroup}}%

\gdef \@makecol {%
\ifvoid\footins
\setbox\@outputbox \box\@cclv
\else
\setbox\@outputbox \vbox {%
\hbox{\color@begingroup
\if@twoside\ifodd\c@page
\box\@cclv\rlap{\kern\marginparsep\vbox to \textheight{\unvbox\footins}}
\else
\llap{\vbox to \textheight{\unvbox\footins}\kern\marginparsep}\box\@cclv
\fi
\color@endgroup}}%
\let\@elt\relax
\xdef\@freelist{\@freelist\@midlist}%
\global \let \@midlist \@empty
\@combinefloats
\ifvbox\@kludgeins
\@makespecialcolbox
\else
\setbox\@outputbox \vbox to\@colht {%
\@texttop
\dimen@ \dp\@outputbox
\unvbox \@outputbox
\vskip -\dimen@
\@textbottom
}%
\fi
\global \maxdepth \@maxdepth
}

\makeatother

\begin{document}

\d\ Nine ten. \d

Five four three two one. \d\ \d

Red blue green. \d\ Yellow blue. \d
\end{document}


I think something like this (updated for twoside) ....

\documentclass[twoside]{article}
\newcounter{f}
\def\z{\stepcounter{f}\Roman{f}
\roman{f} \alph{f} \roman{f} \roman{f} \roman{f}
\roman{f} \roman{f} \alph{f} \roman{f} \roman{f}
\roman{f} \roman{f} \roman{f} \alph{f} \roman{f}
\roman{f} \roman{f} \roman{f} \roman{f} \alph{f}}

\def\a{One two three.}
\def\b{\a\ \a\ Four five. \a}
\def\c{\b\ \b\ Red green blue. \b\footnote{\z} \a}
\def\d{\c\ \c\ \c\ \c}

\newbox\ftbox
\setbox\ftbox\vbox{}

\makeatletter
\long\def\@footnotetext#1{%
\global\setbox\ftbox\vbox{%
\unvbox\ftbox
\reset@font\footnotesize
\interlinepenalty\interfootnotelinepenalty
\splitmaxdepth \dp\strutbox \floatingpenalty \@MM
\hsize\marginparwidth \@parboxrestore
\protected@edef\@currentlabel{%
\csname p@footnote\endcsname\@thefnmark
}%
\color@begingroup
\@makefntext{%
\rule\z@\footnotesep\ignorespaces#1\@finalstrut\strutbox}%
\color@endgroup}}%

\gdef \@makecol {%
\ifvoid\footins
\setbox\@outputbox \box\@cclv
\else
\setbox\@outputbox \vbox {%
\boxmaxdepth \@maxdepth
\unvbox \@cclv
\vskip \skip\footins
\color@begingroup
\normalcolor
\footnoterule
\unvbox \footins
\color@endgroup
}%
\fi
\global\setbox\@ne\vsplit\ftbox to \textheight
\if@twoside\ifodd\c@page
\setbox\@outputbox\vbox{\hbox{\box\@outputbox\rlap{\kern\marginparsep\box\@ne}}}%
\else
\setbox\@outputbox\vbox{\hbox{\llap{\box\@ne\kern\marginparsep}\box\@outputbox}}%
\fi
\else
\setbox\@outputbox\vbox{\hbox{\box\@outputbox\rlap{\kern\marginparsep\box\@ne}}}%
\fi
\let\@elt\relax
\xdef\@freelist{\@freelist\@midlist}%
\global \let \@midlist \@empty
\@combinefloats
\ifvbox\@kludgeins
\@makespecialcolbox
\else
\setbox\@outputbox \vbox to\@colht {%
\@texttop
\dimen@ \dp\@outputbox
\unvbox \@outputbox
\vskip -\dimen@
\@textbottom
}%
\fi
\global \maxdepth \@maxdepth
}

\makeatother

\begin{document}

\d\ Nine ten. \d

Five four three two one. \d\ \d

Red blue green. \d\ Yellow blue. \d
\end{document}

-
Thank you! The only problem I've seen so far is that some notes are being placed in the page prior to the footnote marker (although there's enough space for it in the current page)... – henrique Sep 6 '12 at 13:58
yes that's a bug really (no time to fix today) tex reads at least a paragraph at a time before deciding where the page breaks and any footnotes seen in the part that is not placed on the shipped out page will be grabbed early. – David Carlisle Sep 6 '12 at 14:39
The edited version gives the following error at \end{document}: ! Extra \else. <output> ...utpenalty <-\@M \@specialoutput \else \@makecol \@opcol \@startc..., an error that, if ignored, will result in an emergency stop: ! Incomplete \ifvoid; all text was ignored after line 65. [where the \end{document} is --henrique] <inserted text> \fi. – henrique Sep 18 '12 at 13:14
I just copied the file back from this web page and re-ran and it runs without error and makes a three page pdf however it warns (\end occurred when \ifvoid on line 75 was incomplete) which is clearly a bug so I'll update in a bit. – David Carlisle Sep 18 '12 at 13:19
@Mårten the width is the standard LaTeX \marginparwidth length which you can set as usual. The code does `@parboxrestore, I'd have thought any code inflicting double spacing on the main document would have added single spacing to that so parboxes are not spaced out, anyway you could add single spacing to the code just after the call to that (of course the correct fix is not to double space the main text) – David Carlisle Apr 24 '13 at 8:10