I'm writing my thesis with classicthesis. It defines the \graffito command for marginal notes as follows:
% Graffiti as in GKP's book "Concrete Mathematics" % thanks to Lorenzo Pantieri and Enrico Gregorio \def\graffito@setup{% % \slshape\footnotesize% this was due to \slhape in above book \itshape\footnotesize\leavevmode\color{Black}% \parindent=0pt \lineskip=0pt \lineskiplimit=0pt % \tolerance=2000 \hyphenpenalty=300 \exhyphenpenalty=300% \doublehyphendemerits=100000% \finalhyphendemerits=\doublehyphendemerits} %\DeclareRobustCommand{\graffito}[1]{\marginpar% % [\graffito@setup\raggedleft\hspace{0pt}{#1}]% % {\graffito@setup\raggedright\hspace{0pt}{#1}}} \RequirePackage{mparhack} % get marginpar right \let\oldmarginpar\marginpar \renewcommand{\marginpar}[2][]{% always add optional parameter, make it empty by default \if\relax\detokenize{#1}\relax% optional parameter empty, in all normal document calls \oldmarginpar[\graffito@setup\raggedleft\hspace{0pt}{#2}]{\graffito@setup\raggedright\hspace{0pt}#2}% \else%two parameters, let them use their styling \oldmarginpar[{#1}]{#2}% \fi% } and I added the \graffitox on top to include an optional vertical offset (original thread: Including default parameter into \def, code adopted from user egreg):
\makeatletter \usepackage{suffix} \newcommand{\graffitox}[1]{% \marginpar [\graffitox@setup{\graffitooffset}\raggedleft\hspace{0pt}#1] {\graffitox@setup{\graffitooffset}\raggedright\hspace{0pt}#1}% } \WithSuffix\newcommand\graffitox*[1]{% \marginpar [\graffitox@setup{\graffitoaftercaptionoffset}\raggedleft\hspace{0pt}#1] {\graffitox@setup{\graffitoaftercaptionoffset}\raggedright\hspace{0pt}#1}% } \newcommand\graffitox@setup[1]{% \vspace{#1}% \parindent=0pt \lineskip=0pt \lineskiplimit=0pt \tolerance=2000 \hyphenpenalty=300 \exhyphenpenalty=300 \doublehyphendemerits=100000 \finalhyphendemerits=\doublehyphendemerits \itshape\footnotesize \leavevmode\color{black} % } \makeatother I insert marginal notes in the beginning of paragraphs, but for notes that are longer than a single line, I sometimes arrive at the following situation where the note exceeds the main text:
This isn't too bad if the note is short, but very unappealing for longer notes. I consequently check each note manually and insert a "\clearpage" before the "\graffitox" command to move the entire paragraph to the next page. However, this requires quite some manual effort whenever something in the overall document changes.
Can this process be automatised? I.e.: if the marginal note is longer than the paragraph segment on that page, replace "\graffitox{...}" with "\clearpage\graffitox{...}"? I appreciate any help in facilitating this - my present problem is to obtain the measurements for the calculation (remaining vertical space until end of main text, vertical space required by marginal note, etc.).
It would be great to find a solution using that can be wrapped into the \graffitox command to spare me from substantial changes to the whole thesis.

\marginpar. Mind telling me where this code came from?